2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "library.h"
|
|
|
|
#include "libraryconfig.h"
|
|
|
|
#include "songplaylistitem.h"
|
|
|
|
#include "systemtrayicon.h"
|
2009-12-26 16:13:38 +01:00
|
|
|
#include "radiomodel.h"
|
2010-04-04 19:50:11 +02:00
|
|
|
#include "engines/enginebase.h"
|
2009-12-29 20:57:33 +01:00
|
|
|
#include "lastfmservice.h"
|
2010-01-08 15:52:05 +01:00
|
|
|
#include "osd.h"
|
2010-01-15 18:12:47 +01:00
|
|
|
#include "trackslider.h"
|
2010-01-16 17:12:47 +01:00
|
|
|
#include "edittagdialog.h"
|
2010-01-16 18:52:51 +01:00
|
|
|
#include "multiloadingindicator.h"
|
2010-02-03 17:17:04 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "libraryconfigdialog.h"
|
2010-02-03 21:45:32 +01:00
|
|
|
#include "about.h"
|
2010-02-24 23:26:01 +01:00
|
|
|
#include "addstreamdialog.h"
|
2010-02-27 17:36:25 +01:00
|
|
|
#include "stylesheetloader.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
#include "albumcovermanager.h"
|
2010-03-07 15:42:51 +01:00
|
|
|
#include "m3uparser.h"
|
2010-03-10 22:39:25 +01:00
|
|
|
#include "xspfparser.h"
|
2010-03-08 19:05:41 +01:00
|
|
|
#include "playlistsequence.h"
|
2010-04-01 01:11:45 +02:00
|
|
|
#include "groupbydialog.h"
|
2010-04-07 15:51:14 +02:00
|
|
|
#include "engines/gstengine.h"
|
2010-04-07 18:26:04 +02:00
|
|
|
#include "equalizer.h"
|
2010-04-13 00:44:29 +02:00
|
|
|
#include "commandlineoptions.h"
|
2010-04-15 17:23:12 +02:00
|
|
|
#include "mac_startup.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-21 20:02:56 +01:00
|
|
|
#include "globalshortcuts/globalshortcuts.h"
|
2009-12-30 17:24:55 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QFileSystemModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QSignalMapper>
|
2010-02-24 23:26:01 +01:00
|
|
|
#include <QFileDialog>
|
2010-03-20 23:45:54 +01:00
|
|
|
#include <QTimer>
|
2010-04-14 23:27:27 +02:00
|
|
|
#include <QShortcut>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2010-04-15 00:36:28 +02:00
|
|
|
using boost::shared_ptr;
|
|
|
|
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
// Non exported mac-specific function.
|
|
|
|
void qt_mac_set_dock_menu(QMenu*);
|
|
|
|
#endif
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
const int MainWindow::kStateVersion = 1;
|
|
|
|
const char* MainWindow::kSettingsGroup = "MainWindow";
|
2010-03-07 15:42:51 +01:00
|
|
|
const char* MainWindow::kMediaFilterSpec =
|
2010-03-10 22:39:25 +01:00
|
|
|
"Music (*.mp3 *.ogg *.flac *.mpc *.m4a *.aac *.wma);;Playlists (*.m3u *.xspf *.xml)";
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-15 14:39:34 +02:00
|
|
|
MainWindow::MainWindow(QNetworkAccessManager* network, Engine::Type engine, QWidget *parent)
|
2009-12-24 20:16:07 +01:00
|
|
|
: QMainWindow(parent),
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
tray_icon_(NULL),
|
|
|
|
#else
|
2009-12-29 20:57:33 +01:00
|
|
|
tray_icon_(new SystemTrayIcon(this)),
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2010-01-08 15:52:05 +01:00
|
|
|
osd_(new OSD(tray_icon_, this)),
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_(new TrackSlider(this)),
|
2010-03-08 19:05:41 +01:00
|
|
|
playlist_sequence_(new PlaylistSequence(this)),
|
2010-04-14 23:27:27 +02:00
|
|
|
edit_tag_dialog_(new EditTagDialog),
|
2010-01-16 18:52:51 +01:00
|
|
|
multi_loading_indicator_(new MultiLoadingIndicator(this)),
|
2010-04-14 23:27:27 +02:00
|
|
|
library_config_dialog_(new LibraryConfigDialog),
|
|
|
|
about_dialog_(new About),
|
2009-12-26 22:35:45 +01:00
|
|
|
radio_model_(new RadioModel(this)),
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_(new Playlist(this)),
|
2010-04-15 14:39:34 +02:00
|
|
|
player_(new Player(playlist_, radio_model_->GetLastFMService(), engine, this)),
|
2009-12-24 20:16:07 +01:00
|
|
|
library_(new Library(player_->GetEngine(), this)),
|
2010-03-21 20:02:56 +01:00
|
|
|
global_shortcuts_(new GlobalShortcuts(this)),
|
2010-04-14 23:27:27 +02:00
|
|
|
settings_dialog_(new SettingsDialog),
|
|
|
|
add_stream_dialog_(new AddStreamDialog),
|
2010-04-14 23:58:51 +02:00
|
|
|
cover_manager_(new AlbumCoverManager(network)),
|
2010-04-14 23:27:27 +02:00
|
|
|
group_by_dialog_(new GroupByDialog),
|
2010-04-14 23:58:51 +02:00
|
|
|
equalizer_(new Equalizer),
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_(new QMenu(this)),
|
2009-12-24 20:16:07 +01:00
|
|
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
2010-03-10 01:04:04 +01:00
|
|
|
track_position_timer_(new QTimer(this))
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
ui_.setupUi(this);
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2009-12-24 20:16:07 +01:00
|
|
|
tray_icon_->setIcon(windowIcon());
|
2010-01-08 17:21:22 +01:00
|
|
|
tray_icon_->setToolTip(QCoreApplication::applicationName());
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
ui_.volume->setValue(player_->GetVolume());
|
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
track_position_timer_->setInterval(1000);
|
|
|
|
connect(track_position_timer_, SIGNAL(timeout()), SLOT(UpdateTrackPosition()));
|
|
|
|
|
2010-02-04 00:12:21 +01:00
|
|
|
// Start initialising the player
|
|
|
|
player_->Init();
|
|
|
|
|
2010-04-07 15:51:14 +02:00
|
|
|
if (GstEngine* engine = qobject_cast<GstEngine*>(player_->GetEngine()))
|
|
|
|
settings_dialog_->SetGstEngine(engine);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Models
|
|
|
|
library_sort_model_->setSourceModel(library_);
|
|
|
|
library_sort_model_->setSortRole(Library::Role_SortText);
|
|
|
|
library_sort_model_->setDynamicSortFilter(true);
|
|
|
|
library_sort_model_->sort(0);
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->IgnoreSorting(true);
|
|
|
|
ui_.playlist->setModel(playlist_);
|
2010-03-28 00:45:46 +01:00
|
|
|
ui_.playlist->setItemDelegates(library_);
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->IgnoreSorting(false);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
ui_.library_view->setModel(library_sort_model_);
|
|
|
|
ui_.library_view->SetLibrary(library_);
|
2010-02-03 17:17:04 +01:00
|
|
|
library_config_dialog_->SetModel(library_->GetDirectoryModel());
|
|
|
|
settings_dialog_->SetLibraryDirectoryModel(library_->GetDirectoryModel());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
ui_.radio_view->setModel(radio_model_);
|
|
|
|
|
2010-03-26 13:22:19 +01:00
|
|
|
cover_manager_->Init();
|
|
|
|
|
2009-12-24 21:27:32 +01:00
|
|
|
// File view connections
|
2009-12-24 23:26:58 +01:00
|
|
|
connect(ui_.file_view, SIGNAL(Queue(QList<QUrl>)), SLOT(QueueFiles(QList<QUrl>)));
|
2009-12-24 21:27:32 +01:00
|
|
|
connect(ui_.file_view, SIGNAL(PathChanged(QString)), SLOT(FilePathChanged(QString)));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Action connections
|
|
|
|
connect(ui_.action_next_track, SIGNAL(triggered()), player_, SLOT(Next()));
|
|
|
|
connect(ui_.action_previous_track, SIGNAL(triggered()), player_, SLOT(Previous()));
|
|
|
|
connect(ui_.action_play_pause, SIGNAL(triggered()), player_, SLOT(PlayPause()));
|
|
|
|
connect(ui_.action_stop, SIGNAL(triggered()), player_, SLOT(Stop()));
|
|
|
|
connect(ui_.action_quit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
|
|
|
connect(ui_.action_stop_after_this_track, SIGNAL(triggered()), SLOT(StopAfterCurrent()));
|
|
|
|
connect(ui_.library_filter, SIGNAL(textChanged(QString)), library_, SLOT(SetFilterText(QString)));
|
2009-12-29 21:48:50 +01:00
|
|
|
connect(ui_.action_ban, SIGNAL(triggered()), radio_model_->GetLastFMService(), SLOT(Ban()));
|
|
|
|
connect(ui_.action_love, SIGNAL(triggered()), SLOT(Love()));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.action_clear_playlist, SIGNAL(triggered()), playlist_, SLOT(Clear()));
|
2010-03-24 17:36:44 +01:00
|
|
|
connect(ui_.action_remove_from_playlist, SIGNAL(triggered()), SLOT(PlaylistRemoveCurrent()));
|
2010-01-16 17:12:47 +01:00
|
|
|
connect(ui_.action_edit_track, SIGNAL(triggered()), SLOT(EditTracks()));
|
2010-03-22 23:46:53 +01:00
|
|
|
connect(ui_.action_renumber_tracks, SIGNAL(triggered()), SLOT(RenumberTracks()));
|
2010-03-24 01:12:52 +01:00
|
|
|
connect(ui_.action_selection_set_value, SIGNAL(triggered()), SLOT(SelectionSetValue()));
|
2010-03-26 00:48:58 +01:00
|
|
|
connect(ui_.action_edit_value, SIGNAL(triggered()), SLOT(EditValue()));
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(ui_.action_configure, SIGNAL(triggered()), settings_dialog_.get(), SLOT(show()));
|
|
|
|
connect(ui_.action_about, SIGNAL(triggered()), about_dialog_.get(), SLOT(show()));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.action_shuffle, SIGNAL(triggered()), playlist_, SLOT(Shuffle()));
|
2010-02-24 23:26:01 +01:00
|
|
|
connect(ui_.action_open_media, SIGNAL(triggered()), SLOT(AddMedia()));
|
|
|
|
connect(ui_.action_add_media, SIGNAL(triggered()), SLOT(AddMedia()));
|
|
|
|
connect(ui_.action_add_stream, SIGNAL(triggered()), SLOT(AddStream()));
|
2010-04-14 23:58:51 +02:00
|
|
|
connect(ui_.action_cover_manager, SIGNAL(triggered()), cover_manager_.get(), SLOT(show()));
|
|
|
|
connect(ui_.action_equalizer, SIGNAL(triggered()), equalizer_.get(), SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Give actions to buttons
|
|
|
|
ui_.forward_button->setDefaultAction(ui_.action_next_track);
|
|
|
|
ui_.back_button->setDefaultAction(ui_.action_previous_track);
|
|
|
|
ui_.pause_play_button->setDefaultAction(ui_.action_play_pause);
|
|
|
|
ui_.stop_button->setDefaultAction(ui_.action_stop);
|
2009-12-29 20:22:02 +01:00
|
|
|
ui_.love_button->setDefaultAction(ui_.action_love);
|
|
|
|
ui_.ban_button->setDefaultAction(ui_.action_ban);
|
2010-01-14 13:27:50 +01:00
|
|
|
ui_.clear_playlist_button->setDefaultAction(ui_.action_clear_playlist);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-12 02:03:43 +01:00
|
|
|
// Add the shuffle and repeat action groups to the menu
|
|
|
|
ui_.action_shuffle_mode->setMenu(playlist_sequence_->shuffle_menu());
|
|
|
|
ui_.action_repeat_mode->setMenu(playlist_sequence_->repeat_menu());
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Stop actions
|
|
|
|
QMenu* stop_menu = new QMenu(this);
|
|
|
|
stop_menu->addAction(ui_.action_stop);
|
|
|
|
stop_menu->addAction(ui_.action_stop_after_this_track);
|
|
|
|
ui_.stop_button->setMenu(stop_menu);
|
|
|
|
|
|
|
|
// Player connections
|
|
|
|
connect(ui_.volume, SIGNAL(valueChanged(int)), player_, SLOT(SetVolume(int)));
|
|
|
|
|
|
|
|
connect(player_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
|
|
|
connect(player_, SIGNAL(Paused()), SLOT(MediaPaused()));
|
|
|
|
connect(player_, SIGNAL(Playing()), SLOT(MediaPlaying()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), SLOT(MediaStopped()));
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(player_, SIGNAL(Paused()), playlist_, SLOT(Paused()));
|
|
|
|
connect(player_, SIGNAL(Playing()), playlist_, SLOT(Playing()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), playlist_, SLOT(Stopped()));
|
|
|
|
|
|
|
|
connect(player_, SIGNAL(Paused()), ui_.playlist, SLOT(StopGlowing()));
|
|
|
|
connect(player_, SIGNAL(Playing()), ui_.playlist, SLOT(StartGlowing()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), ui_.playlist, SLOT(StopGlowing()));
|
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
|
2010-01-08 17:40:34 +01:00
|
|
|
connect(player_, SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
|
2010-04-13 01:35:47 +02:00
|
|
|
connect(player_, SIGNAL(VolumeChanged(int)), ui_.volume, SLOT(setValue(int)));
|
2010-04-13 22:45:40 +02:00
|
|
|
connect(player_, SIGNAL(ForceShowOSD(Song)), SLOT(ForceShowOSD(Song)));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
2010-03-21 01:30:05 +01:00
|
|
|
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(Song)));
|
2010-03-24 21:58:17 +01:00
|
|
|
connect(playlist_, SIGNAL(PlaylistChanged()), player_, SLOT(PlaylistChanged()));
|
2010-04-11 19:58:58 +02:00
|
|
|
connect(playlist_, SIGNAL(EditingFinished(QModelIndex)), SLOT(PlaylistEditFinished(QModelIndex)));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.playlist, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
|
|
connect(ui_.playlist, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
|
|
connect(ui_.playlist, SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(track_slider_, SIGNAL(ValueChanged(int)), player_, SLOT(Seek(int)));
|
2010-03-06 16:33:57 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Library connections
|
|
|
|
connect(library_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
2010-04-04 15:31:21 +02:00
|
|
|
connect(ui_.library_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(AddLibraryItemToPlaylist(QModelIndex)));
|
|
|
|
connect(ui_.library_view, SIGNAL(AddToPlaylist(QModelIndex)), SLOT(AddLibraryItemToPlaylist(QModelIndex)));
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(ui_.library_view, SIGNAL(ShowConfigDialog()), library_config_dialog_.get(), SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
connect(library_, SIGNAL(TotalSongCountUpdated(int)), ui_.library_view, SLOT(TotalSongCountUpdated(int)));
|
2010-01-16 18:52:51 +01:00
|
|
|
connect(library_, SIGNAL(ScanStarted()), SLOT(LibraryScanStarted()));
|
|
|
|
connect(library_, SIGNAL(ScanFinished()), SLOT(LibraryScanFinished()));
|
2010-04-15 00:54:15 +02:00
|
|
|
connect(library_, SIGNAL(BackendReady(boost::shared_ptr<LibraryBackendInterface>)),
|
|
|
|
cover_manager_.get(), SLOT(SetBackend(boost::shared_ptr<LibraryBackendInterface>)));
|
|
|
|
connect(library_, SIGNAL(BackendReady(boost::shared_ptr<LibraryBackendInterface>)),
|
|
|
|
playlist_, SLOT(SetBackend(boost::shared_ptr<LibraryBackendInterface>)));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Age filters
|
|
|
|
QActionGroup* filter_age_group = new QActionGroup(this);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_all);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_today);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_week);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_month);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_three_months);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_year);
|
2010-04-08 22:48:22 +02:00
|
|
|
|
|
|
|
QMenu* filter_age_menu = new QMenu("Show", this);
|
|
|
|
filter_age_menu->addActions(filter_age_group->actions());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
QSignalMapper* filter_age_mapper = new QSignalMapper(this);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_all, -1);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_today, 60*60*24);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_week, 60*60*24*7);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_month, 60*60*24*30);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_three_months, 60*60*24*30*3);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_year, 60*60*24*365);
|
|
|
|
|
|
|
|
connect(ui_.filter_age_all, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_today, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_week, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_month, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_three_months, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_year, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(filter_age_mapper, SIGNAL(mapped(int)), library_, SLOT(SetFilterAge(int)));
|
|
|
|
connect(ui_.library_filter_clear, SIGNAL(clicked()), SLOT(ClearLibraryFilter()));
|
|
|
|
|
2010-03-31 02:30:57 +02:00
|
|
|
// "Group by ..."
|
2010-04-01 19:20:31 +02:00
|
|
|
ui_.group_by_artist->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist)));
|
|
|
|
ui_.group_by_artist_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_artist_yearalbum->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_YearAlbum)));
|
|
|
|
ui_.group_by_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_genre_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_genre_artist_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Artist, Library::GroupBy_Album)));
|
|
|
|
|
2010-03-31 17:18:39 +02:00
|
|
|
group_by_group_ = new QActionGroup(this);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist_yearalbum);
|
|
|
|
group_by_group_->addAction(ui_.group_by_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_genre_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_genre_artist_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_advanced);
|
2010-04-01 01:11:45 +02:00
|
|
|
|
2010-04-08 22:48:22 +02:00
|
|
|
QMenu* group_by_menu = new QMenu("Group by", this);
|
|
|
|
group_by_menu->addActions(group_by_group_->actions());
|
|
|
|
|
2010-03-31 17:18:39 +02:00
|
|
|
connect(group_by_group_, SIGNAL(triggered(QAction*)), SLOT(GroupByClicked(QAction*)));
|
2010-04-01 01:11:45 +02:00
|
|
|
connect(library_, SIGNAL(GroupingChanged(Library::Grouping)),
|
2010-04-14 23:27:27 +02:00
|
|
|
group_by_dialog_.get(), SLOT(LibraryGroupingChanged(Library::Grouping)));
|
2010-04-01 01:11:45 +02:00
|
|
|
connect(library_, SIGNAL(GroupingChanged(Library::Grouping)),
|
|
|
|
SLOT(LibraryGroupingChanged(Library::Grouping)));
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(group_by_dialog_.get(), SIGNAL(Accepted(Library::Grouping)),
|
2010-04-01 01:11:45 +02:00
|
|
|
library_, SLOT(SetGroupBy(Library::Grouping)));
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Library config menu
|
|
|
|
QMenu* library_menu = new QMenu(this);
|
2010-04-08 22:48:22 +02:00
|
|
|
library_menu->addMenu(filter_age_menu);
|
|
|
|
library_menu->addMenu(group_by_menu);
|
2010-03-31 02:30:57 +02:00
|
|
|
library_menu->addSeparator();
|
2010-04-14 23:27:27 +02:00
|
|
|
library_menu->addAction(tr("Configure library..."), library_config_dialog_.get(), SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
ui_.library_options->setMenu(library_menu);
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(library_config_dialog_.get(), SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
// Playlist menu
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_ = playlist_menu_->addAction(tr("Play"), this, SLOT(PlaylistPlay()));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_stop);
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), tr("Stop after this track"), this, SLOT(PlaylistStopAfter()));
|
2010-03-24 01:12:52 +01:00
|
|
|
playlist_menu_->addSeparator();
|
2010-03-24 17:36:44 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_remove_from_playlist);
|
|
|
|
playlist_menu_->addSeparator();
|
2010-01-16 17:12:47 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_edit_track);
|
2010-03-26 00:48:58 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_edit_value);
|
2010-03-22 23:46:53 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_renumber_tracks);
|
2010-03-24 01:12:52 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_selection_set_value);
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->addSeparator();
|
|
|
|
playlist_menu_->addAction(ui_.action_clear_playlist);
|
2010-02-04 00:56:41 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_shuffle);
|
2010-01-15 17:22:19 +01:00
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
// Radio connections
|
2010-02-23 19:33:09 +01:00
|
|
|
connect(radio_model_, SIGNAL(TaskStarted(MultiLoadingIndicator::TaskType)), multi_loading_indicator_, SLOT(TaskStarted(MultiLoadingIndicator::TaskType)));
|
|
|
|
connect(radio_model_, SIGNAL(TaskFinished(MultiLoadingIndicator::TaskType)), multi_loading_indicator_, SLOT(TaskFinished(MultiLoadingIndicator::TaskType)));
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamError(QString)), SLOT(ReportError(QString)));
|
2010-02-04 00:12:21 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamFinished()), player_, SLOT(NextItem()));
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamReady(QUrl,QUrl)), player_, SLOT(StreamReady(QUrl,QUrl)));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
2009-12-30 02:41:37 +01:00
|
|
|
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*)));
|
2009-12-29 21:48:50 +01:00
|
|
|
connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool)));
|
2010-04-07 21:26:49 +02:00
|
|
|
connect(radio_model_->GetLastFMService(), SIGNAL(ButtonVisibilityChanged(bool)), SLOT(LastFMButtonVisibilityChanged(bool)));
|
2009-12-30 00:17:54 +01:00
|
|
|
connect(ui_.radio_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex)));
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-04-07 21:26:49 +02:00
|
|
|
LastFMButtonVisibilityChanged(radio_model_->GetLastFMService()->AreButtonsVisible());
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Tray icon
|
|
|
|
QMenu* tray_menu = new QMenu(this);
|
|
|
|
tray_menu->addAction(ui_.action_previous_track);
|
|
|
|
tray_menu->addAction(ui_.action_play_pause);
|
|
|
|
tray_menu->addAction(ui_.action_stop);
|
|
|
|
tray_menu->addAction(ui_.action_next_track);
|
2010-01-15 17:44:54 +01:00
|
|
|
tray_menu->addSeparator();
|
2009-12-29 20:22:02 +01:00
|
|
|
tray_menu->addAction(ui_.action_love);
|
|
|
|
tray_menu->addAction(ui_.action_ban);
|
2009-12-24 20:16:07 +01:00
|
|
|
tray_menu->addSeparator();
|
|
|
|
tray_menu->addAction(ui_.action_quit);
|
2010-04-14 21:38:09 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_DARWIN
|
2010-04-15 17:23:12 +02:00
|
|
|
// Add check for updates item to application menu.
|
|
|
|
QAction* check_updates = ui_.menuSettings->addAction(tr("Check for updates..."));
|
|
|
|
check_updates->setMenuRole(QAction::ApplicationSpecificRole);
|
|
|
|
connect(check_updates, SIGNAL(triggered(bool)), SLOT(CheckForUpdates()));
|
|
|
|
// We use the dock instead of the system tray on mac.
|
2010-04-14 21:38:09 +02:00
|
|
|
qt_mac_set_dock_menu(tray_menu);
|
|
|
|
#else
|
2009-12-24 20:16:07 +01:00
|
|
|
tray_icon_->setContextMenu(tray_menu);
|
|
|
|
connect(tray_icon_, SIGNAL(WheelEvent(int)), SLOT(VolumeWheelEvent(int)));
|
|
|
|
connect(tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(TrayClicked(QSystemTrayIcon::ActivationReason)));
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-30 17:24:55 +01:00
|
|
|
// Global shortcuts
|
2010-03-21 20:02:56 +01:00
|
|
|
connect(global_shortcuts_, SIGNAL(PlayPause()), ui_.action_play_pause, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Stop()), ui_.action_stop, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Next()), ui_.action_next_track, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Previous()), ui_.action_previous_track, SLOT(trigger()));
|
2009-12-30 17:24:55 +01:00
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
// Settings
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(settings_dialog_.get(), SIGNAL(accepted()), SLOT(ReloadSettings()));
|
|
|
|
connect(settings_dialog_.get(), SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
|
|
|
|
connect(settings_dialog_.get(), SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
|
|
|
|
connect(settings_dialog_.get(), SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
|
|
|
connect(settings_dialog_.get(), SIGNAL(accepted()), player_->GetEngine(), SLOT(ReloadSettings()));
|
2010-02-03 17:51:56 +01:00
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
// Add stream dialog
|
2010-04-14 23:27:27 +02:00
|
|
|
connect(add_stream_dialog_.get(), SIGNAL(accepted()), SLOT(AddStreamAccepted()));
|
2010-02-24 23:26:01 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Analyzer
|
|
|
|
ui_.analyzer->set_engine(player_->GetEngine());
|
|
|
|
|
2010-04-07 18:26:04 +02:00
|
|
|
// Equalizer
|
2010-04-14 23:58:51 +02:00
|
|
|
connect(equalizer_.get(), SIGNAL(ParametersChanged(int,QList<int>)),
|
2010-04-12 01:24:03 +02:00
|
|
|
player_->GetEngine(), SLOT(SetEqualizerParameters(int,QList<int>)));
|
2010-04-14 23:58:51 +02:00
|
|
|
connect(equalizer_.get(), SIGNAL(EnabledChanged(bool)),
|
2010-04-12 01:24:03 +02:00
|
|
|
player_->GetEngine(), SLOT(SetEqualizerEnabled(bool)));
|
|
|
|
player_->GetEngine()->SetEqualizerEnabled(equalizer_->is_enabled());
|
|
|
|
player_->GetEngine()->SetEqualizerParameters(
|
2010-04-08 17:13:34 +02:00
|
|
|
equalizer_->preamp_value(), equalizer_->gain_values());
|
2010-04-07 18:26:04 +02:00
|
|
|
|
2010-01-15 18:12:47 +01:00
|
|
|
// Statusbar widgets
|
2010-03-10 01:09:49 +01:00
|
|
|
playlist_->set_sequence(playlist_sequence_);
|
2010-03-08 19:05:41 +01:00
|
|
|
ui_.statusBar->addPermanentWidget(playlist_sequence_);
|
2010-01-15 18:12:47 +01:00
|
|
|
ui_.statusBar->addPermanentWidget(track_slider_);
|
2010-01-16 18:52:51 +01:00
|
|
|
ui_.statusBar->addWidget(multi_loading_indicator_);
|
|
|
|
multi_loading_indicator_->hide();
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Load theme
|
2010-02-27 17:36:25 +01:00
|
|
|
StyleSheetLoader* css_loader = new StyleSheetLoader(this);
|
|
|
|
css_loader->SetStyleSheet(this, ":mainwindow.css");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-24 21:27:32 +01:00
|
|
|
// Load settings
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.beginGroup(kSettingsGroup);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-27 17:52:18 +01:00
|
|
|
restoreGeometry(settings_.value("geometry").toByteArray());
|
|
|
|
if (!restoreState(settings_.value("state").toByteArray(), kStateVersion)) {
|
2009-12-24 20:16:07 +01:00
|
|
|
tabifyDockWidget(ui_.files_dock, ui_.radio_dock);
|
|
|
|
tabifyDockWidget(ui_.files_dock, ui_.library_dock);
|
|
|
|
}
|
|
|
|
|
2010-02-27 17:52:18 +01:00
|
|
|
ui_.file_view->SetPath(settings_.value("file_path", QDir::homePath()).toString());
|
2009-12-24 21:27:32 +01:00
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
library_->SetGroupBy(Library::Grouping(
|
|
|
|
Library::GroupBy(settings_.value("group_by1", int(Library::GroupBy_Artist)).toInt()),
|
|
|
|
Library::GroupBy(settings_.value("group_by2", int(Library::GroupBy_Album)).toInt()),
|
|
|
|
Library::GroupBy(settings_.value("group_by3", int(Library::GroupBy_None)).toInt())));
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-04-14 23:27:27 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-04-07 01:46:34 +02:00
|
|
|
StartupBehaviour behaviour =
|
|
|
|
StartupBehaviour(settings_.value("startupbehaviour", Startup_Remember).toInt());
|
2010-03-31 05:07:11 +02:00
|
|
|
bool hidden = settings_.value("hidden", false).toBool();
|
|
|
|
bool show_tray = settings_.value("showtray", true).toBool();
|
2010-04-07 01:46:34 +02:00
|
|
|
|
|
|
|
switch (behaviour) {
|
|
|
|
case Startup_AlwaysHide: hide(); break;
|
|
|
|
case Startup_AlwaysShow: show(); break;
|
|
|
|
case Startup_Remember: setVisible(!hidden); break;
|
|
|
|
}
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-03-31 05:07:11 +02:00
|
|
|
if (show_tray)
|
2010-02-26 19:22:44 +01:00
|
|
|
tray_icon_->show();
|
|
|
|
|
|
|
|
// Force the window to show in case somehow the config has tray and window set to hide
|
2010-03-31 05:07:11 +02:00
|
|
|
if (hidden && !show_tray) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("hidden", false);
|
2010-02-26 19:22:44 +01:00
|
|
|
show();
|
|
|
|
}
|
2010-04-14 23:58:51 +02:00
|
|
|
#else // Q_OS_DARWIN
|
2010-04-14 21:38:09 +02:00
|
|
|
// Always show mainwindow on startup on OS X.
|
|
|
|
show();
|
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-14 23:27:27 +02:00
|
|
|
QShortcut* close_window_shortcut = new QShortcut(this);
|
|
|
|
close_window_shortcut->setKey(Qt::CTRL + Qt::Key_W);
|
|
|
|
connect(close_window_shortcut, SIGNAL(activated()), SLOT(hide()));
|
|
|
|
|
2010-03-23 18:26:54 +01:00
|
|
|
library_->Init();
|
2009-12-24 20:16:07 +01:00
|
|
|
library_->StartThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
SaveGeometry();
|
|
|
|
}
|
|
|
|
|
2010-04-07 01:46:34 +02:00
|
|
|
void MainWindow::ReloadSettings() {
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-04-07 01:46:34 +02:00
|
|
|
bool show_tray = settings_.value("showtray", true).toBool();
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-04-07 01:46:34 +02:00
|
|
|
tray_icon_->setVisible(show_tray);
|
|
|
|
if (!show_tray && !isVisible())
|
|
|
|
show();
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2010-02-26 19:22:44 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 23:26:58 +01:00
|
|
|
void MainWindow::QueueFiles(const QList<QUrl>& urls) {
|
2010-03-10 01:04:04 +01:00
|
|
|
QModelIndex playlist_index = playlist_->InsertPaths(urls);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (playlist_index.isValid() && player_->GetState() != Engine::Playing)
|
2010-04-12 03:59:21 +02:00
|
|
|
player_->PlayAt(playlist_index.row(), Engine::First);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ReportError(const QString& message) {
|
2010-04-01 18:59:32 +02:00
|
|
|
// TODO: rate limiting
|
2009-12-24 20:16:07 +01:00
|
|
|
QMessageBox::warning(this, "Error", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaStopped() {
|
|
|
|
ui_.action_stop->setEnabled(false);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(false);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-start.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Play"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(true);
|
2009-12-29 20:22:02 +01:00
|
|
|
|
2009-12-29 21:48:50 +01:00
|
|
|
ui_.action_ban->setEnabled(false);
|
|
|
|
ui_.action_love->setEnabled(false);
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
track_position_timer_->stop();
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_->SetStopped();
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-01-17 22:11:03 +01:00
|
|
|
tray_icon_->SetProgress(0);
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaPaused() {
|
|
|
|
ui_.action_stop->setEnabled(true);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(true);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-start.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Play"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(true);
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
track_position_timer_->stop();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaPlaying() {
|
|
|
|
ui_.action_stop->setEnabled(true);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(true);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-pause.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Pause"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(
|
2010-02-03 15:21:53 +01:00
|
|
|
! (player_->GetCurrentItemOptions() & PlaylistItem::PauseDisabled));
|
2009-12-29 20:22:02 +01:00
|
|
|
|
2010-02-03 15:21:53 +01:00
|
|
|
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
2009-12-29 21:48:50 +01:00
|
|
|
LastFMService* lastfm = radio_model_->GetLastFMService();
|
|
|
|
|
|
|
|
ui_.action_ban->setEnabled(lastfm->IsScrobblingEnabled() && is_lastfm);
|
|
|
|
ui_.action_love->setEnabled(lastfm->IsScrobblingEnabled());
|
2009-12-29 20:57:33 +01:00
|
|
|
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_->SetCanSeek(!is_lastfm);
|
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
track_position_timer_->start();
|
|
|
|
UpdateTrackPosition();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 21:48:50 +01:00
|
|
|
void MainWindow::ScrobblingEnabledChanged(bool value) {
|
2009-12-30 05:14:29 +01:00
|
|
|
if (!player_->GetState() == Engine::Idle)
|
|
|
|
return;
|
|
|
|
|
2010-02-03 15:21:53 +01:00
|
|
|
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
2009-12-30 05:14:29 +01:00
|
|
|
ui_.action_ban->setEnabled(value && is_lastfm);
|
2009-12-29 21:48:50 +01:00
|
|
|
ui_.action_love->setEnabled(value);
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:26:49 +02:00
|
|
|
void MainWindow::LastFMButtonVisibilityChanged(bool value) {
|
|
|
|
ui_.action_ban->setVisible(value);
|
|
|
|
ui_.action_love->setVisible(value);
|
|
|
|
ui_.last_fm_controls->setVisible(value);
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void MainWindow::resizeEvent(QResizeEvent*) {
|
|
|
|
SaveGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SaveGeometry() {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("geometry", saveGeometry());
|
|
|
|
settings_.setValue("state", saveState(kStateVersion));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlayIndex(const QModelIndex& index) {
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
2010-04-12 03:59:21 +02:00
|
|
|
player_->PlayAt(index.row(), Engine::Manual);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-04-04 15:31:21 +02:00
|
|
|
void MainWindow::AddLibraryItemToPlaylist(const QModelIndex& index) {
|
|
|
|
QModelIndex idx = index;
|
|
|
|
if (idx.model() == library_sort_model_)
|
|
|
|
idx = library_sort_model_->mapToSource(idx);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
QModelIndex first_song =
|
2010-04-14 23:03:00 +02:00
|
|
|
playlist_->InsertLibraryItems(library_->GetChildSongs(idx));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
2010-04-12 03:59:21 +02:00
|
|
|
player_->PlayAt(first_song.row(), Engine::First);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::VolumeWheelEvent(int delta) {
|
2010-04-01 01:45:52 +02:00
|
|
|
ui_.volume->setValue(ui_.volume->value() + delta / 30);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::TrayClicked(QSystemTrayIcon::ActivationReason reason) {
|
|
|
|
switch (reason) {
|
|
|
|
case QSystemTrayIcon::DoubleClick:
|
|
|
|
case QSystemTrayIcon::Trigger:
|
2010-03-29 15:24:40 +02:00
|
|
|
if(isMinimized()) {
|
|
|
|
hide();
|
|
|
|
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
|
|
|
SetHiddenInTray(false);
|
|
|
|
} else {
|
|
|
|
SetHiddenInTray(isVisible());
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QSystemTrayIcon::MiddleClick:
|
|
|
|
player_->PlayPause();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::StopAfterCurrent() {
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->StopAfter(playlist_->current_index());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 19:22:44 +01:00
|
|
|
/**
|
|
|
|
* Exit if the tray icon is not visible, otherwise ignore and set hidden in tray.
|
2010-04-14 21:38:09 +02:00
|
|
|
* On OS X, never quit when the main window is closed. This is equivalent to hiding in the tray.
|
2010-02-26 19:22:44 +01:00
|
|
|
*/
|
2009-12-24 20:16:07 +01:00
|
|
|
void MainWindow::closeEvent(QCloseEvent* event) {
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-04-09 00:08:18 +02:00
|
|
|
if (tray_icon_->isVisible() && event->spontaneous()) {
|
2010-02-26 19:22:44 +01:00
|
|
|
event->ignore();
|
|
|
|
SetHiddenInTray(true);
|
2010-04-07 18:26:04 +02:00
|
|
|
} else {
|
|
|
|
QApplication::quit();
|
2010-02-26 19:22:44 +01:00
|
|
|
}
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SetHiddenInTray(bool hidden) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("hidden", hidden);
|
2010-04-07 01:46:34 +02:00
|
|
|
setVisible(!hidden);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ClearLibraryFilter() {
|
|
|
|
ui_.library_filter->clear();
|
|
|
|
ui_.library_filter->setFocus();
|
|
|
|
}
|
2009-12-24 21:27:32 +01:00
|
|
|
|
|
|
|
void MainWindow::FilePathChanged(const QString& path) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("file_path", path);
|
2009-12-24 21:27:32 +01:00
|
|
|
}
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
void MainWindow::UpdateTrackPosition() {
|
2010-01-17 22:11:03 +01:00
|
|
|
// Track position in seconds
|
|
|
|
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
2010-02-03 15:21:53 +01:00
|
|
|
const int length = player_->GetCurrentItem().length();
|
2009-12-29 20:57:33 +01:00
|
|
|
|
2010-01-18 03:49:07 +01:00
|
|
|
if (length <= 0) {
|
|
|
|
// Probably a stream that we don't know the length of
|
|
|
|
track_slider_->SetStopped();
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-01-18 03:49:07 +01:00
|
|
|
tray_icon_->SetProgress(0);
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2010-01-18 03:49:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-17 22:11:03 +01:00
|
|
|
// Time to scrobble?
|
2009-12-29 21:48:50 +01:00
|
|
|
LastFMService* lastfm = radio_model_->GetLastFMService();
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
if (!playlist_->has_scrobbled() &&
|
|
|
|
position >= playlist_->scrobble_point()) {
|
2009-12-29 21:48:50 +01:00
|
|
|
lastfm->Scrobble();
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->set_scrobbled(true);
|
2009-12-29 20:57:33 +01:00
|
|
|
}
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2010-01-17 22:11:03 +01:00
|
|
|
// Update the slider
|
|
|
|
track_slider_->SetValue(position, length);
|
|
|
|
|
2010-04-14 21:38:09 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-01-17 22:11:03 +01:00
|
|
|
// Update the tray icon every 10 seconds
|
|
|
|
if (position % 10 == 1) {
|
|
|
|
tray_icon_->SetProgress(double(position) / length * 100);
|
|
|
|
}
|
2010-04-14 21:38:09 +02:00
|
|
|
#endif
|
2009-12-29 20:57:33 +01:00
|
|
|
}
|
2009-12-29 21:48:50 +01:00
|
|
|
|
|
|
|
void MainWindow::Love() {
|
|
|
|
radio_model_->GetLastFMService()->Love();
|
|
|
|
ui_.action_love->setEnabled(false);
|
|
|
|
}
|
2009-12-30 00:17:54 +01:00
|
|
|
|
|
|
|
void MainWindow::RadioDoubleClick(const QModelIndex& index) {
|
2009-12-30 02:41:37 +01:00
|
|
|
InsertRadioItem(radio_model_->IndexToItem(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::InsertRadioItem(RadioItem* item) {
|
2010-03-10 01:04:04 +01:00
|
|
|
QModelIndex first_song = playlist_->InsertRadioStations(
|
2009-12-30 02:41:37 +01:00
|
|
|
QList<RadioItem*>() << item);
|
2009-12-30 00:17:54 +01:00
|
|
|
|
|
|
|
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
2010-04-12 03:59:21 +02:00
|
|
|
player_->PlayAt(first_song.row(), Engine::Manual);
|
2009-12-30 00:17:54 +01:00
|
|
|
}
|
2010-01-15 17:22:19 +01:00
|
|
|
|
|
|
|
void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index) {
|
|
|
|
playlist_menu_index_ = index;
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->current_index() == index.row() && player_->GetState() == Engine::Playing) {
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_->setText(tr("Pause"));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_play_pause_->setIcon(QIcon(":media-playback-pause.png"));
|
|
|
|
} else {
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_->setText(tr("Play"));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_play_pause_->setIcon(QIcon(":media-playback-start.png"));
|
|
|
|
}
|
|
|
|
|
2010-01-17 16:48:31 +01:00
|
|
|
if (index.isValid()) {
|
|
|
|
playlist_play_pause_->setEnabled(
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->current_index() != index.row() ||
|
|
|
|
! (playlist_->item_at(index.row())->options() & PlaylistItem::PauseDisabled));
|
2010-01-17 16:48:31 +01:00
|
|
|
} else {
|
|
|
|
playlist_play_pause_->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_stop_after_->setEnabled(index.isValid());
|
|
|
|
|
2010-01-16 17:12:47 +01:00
|
|
|
// Are any of the selected songs editable?
|
2010-03-24 17:36:44 +01:00
|
|
|
QModelIndexList selection = ui_.playlist->selectionModel()->selection().indexes();
|
2010-03-24 01:12:52 +01:00
|
|
|
int editable = 0;
|
2010-03-24 17:36:44 +01:00
|
|
|
foreach (const QModelIndex& index, selection) {
|
2010-01-16 17:12:47 +01:00
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->item_at(index.row())->Metadata().IsEditable()) {
|
2010-03-24 01:12:52 +01:00
|
|
|
editable++;
|
2010-01-16 17:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ui_.action_edit_track->setEnabled(editable);
|
2010-03-31 21:09:35 +02:00
|
|
|
|
|
|
|
bool track_column = (index.column() == Playlist::Column_Track);
|
|
|
|
ui_.action_renumber_tracks->setVisible(editable >= 2 && track_column);
|
|
|
|
ui_.action_selection_set_value->setVisible(editable >= 2 && !track_column);
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setVisible(editable);
|
2010-03-24 17:36:44 +01:00
|
|
|
ui_.action_remove_from_playlist->setEnabled(!selection.isEmpty());
|
2010-03-24 01:12:52 +01:00
|
|
|
|
2010-03-24 17:13:05 +01:00
|
|
|
if (!index.isValid()) {
|
|
|
|
ui_.action_selection_set_value->setVisible(false);
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setVisible(false);
|
2010-03-24 17:13:05 +01:00
|
|
|
} else {
|
|
|
|
Playlist::Column column = (Playlist::Column)index.column();
|
2010-03-26 00:48:58 +01:00
|
|
|
bool editable = Playlist::column_is_editable(column);
|
|
|
|
|
2010-03-24 17:13:05 +01:00
|
|
|
ui_.action_selection_set_value->setVisible(
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_selection_set_value->isVisible() && editable);
|
|
|
|
ui_.action_edit_value->setVisible(
|
|
|
|
ui_.action_edit_value->isVisible() && editable);
|
2010-03-24 17:13:05 +01:00
|
|
|
|
|
|
|
QString column_name = Playlist::column_name(column);
|
|
|
|
QString column_value = playlist_->data(index).toString();
|
|
|
|
if (column_value.length() > 25)
|
|
|
|
column_value = column_value.left(25) + "...";
|
|
|
|
|
|
|
|
ui_.action_selection_set_value->setText(tr("Set %1 to \"%2\"...")
|
|
|
|
.arg(column_name.toLower()).arg(column_value));
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setText(tr("Edit tag \"%1\"...").arg(column_name));
|
2010-03-24 17:13:05 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->popup(global_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlaylistPlay() {
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->current_index() == playlist_menu_index_.row()) {
|
2010-01-15 17:22:19 +01:00
|
|
|
player_->PlayPause();
|
|
|
|
} else {
|
2010-04-12 03:59:21 +02:00
|
|
|
player_->PlayAt(playlist_menu_index_.row(), Engine::Manual);
|
2010-01-15 17:22:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlaylistStopAfter() {
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->StopAfter(playlist_menu_index_.row());
|
2010-01-15 17:22:19 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
|
|
|
void MainWindow::EditTracks() {
|
|
|
|
SongList songs;
|
|
|
|
QList<int> rows;
|
|
|
|
|
|
|
|
foreach (const QModelIndex& index,
|
2010-03-10 01:04:04 +01:00
|
|
|
ui_.playlist->selectionModel()->selection().indexes()) {
|
2010-01-16 17:12:47 +01:00
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
2010-03-10 01:04:04 +01:00
|
|
|
Song song = playlist_->item_at(index.row())->Metadata();
|
2010-01-16 17:12:47 +01:00
|
|
|
|
|
|
|
if (song.IsEditable()) {
|
|
|
|
songs << song;
|
|
|
|
rows << index.row();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edit_tag_dialog_->SetSongs(songs);
|
2010-03-29 18:59:01 +02:00
|
|
|
edit_tag_dialog_->SetTagCompleter(library_);
|
|
|
|
|
2010-01-16 17:12:47 +01:00
|
|
|
if (edit_tag_dialog_->exec() == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->ReloadItems(rows);
|
2010-01-16 17:12:47 +01:00
|
|
|
}
|
2010-01-16 18:52:51 +01:00
|
|
|
|
2010-03-22 23:46:53 +01:00
|
|
|
void MainWindow::RenumberTracks() {
|
|
|
|
QModelIndexList indexes=ui_.playlist->selectionModel()->selection().indexes();
|
|
|
|
int track=1;
|
|
|
|
|
|
|
|
// if first selected song has a track number set, start from that offset
|
|
|
|
if (indexes.size()) {
|
|
|
|
Song first_song=playlist_->item_at(indexes[0].row())->Metadata();
|
|
|
|
if (int first_track = first_song.track())
|
|
|
|
track = first_track;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QModelIndex& index, indexes) {
|
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
Song song = playlist_->item_at(row)->Metadata();
|
|
|
|
|
|
|
|
if (song.IsEditable()) {
|
|
|
|
song.set_track(track);
|
|
|
|
song.Save();
|
|
|
|
playlist_->item_at(row)->Reload();
|
|
|
|
}
|
|
|
|
track++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 01:12:52 +01:00
|
|
|
void MainWindow::SelectionSetValue() {
|
|
|
|
Playlist::Column column = (Playlist::Column)playlist_menu_index_.column();
|
|
|
|
QVariant column_value = playlist_->data(playlist_menu_index_);
|
|
|
|
|
|
|
|
QModelIndexList indexes=ui_.playlist->selectionModel()->selection().indexes();
|
|
|
|
foreach (const QModelIndex& index, indexes) {
|
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
Song song = playlist_->item_at(row)->Metadata();
|
|
|
|
|
2010-03-26 00:48:58 +01:00
|
|
|
if(Playlist::set_column_value(song, column, column_value)) {
|
2010-03-24 01:12:52 +01:00
|
|
|
song.Save();
|
|
|
|
playlist_->item_at(row)->Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-26 00:48:58 +01:00
|
|
|
void MainWindow::EditValue() {
|
|
|
|
ui_.playlist->edit(playlist_menu_index_);
|
|
|
|
}
|
|
|
|
|
2010-01-16 18:52:51 +01:00
|
|
|
void MainWindow::LibraryScanStarted() {
|
2010-02-23 19:33:09 +01:00
|
|
|
multi_loading_indicator_->TaskStarted(MultiLoadingIndicator::UpdatingLibrary);
|
2010-01-16 18:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::LibraryScanFinished() {
|
2010-02-23 19:33:09 +01:00
|
|
|
multi_loading_indicator_->TaskFinished(MultiLoadingIndicator::UpdatingLibrary);
|
2010-01-16 18:52:51 +01:00
|
|
|
}
|
2010-02-03 22:48:00 +01:00
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
void MainWindow::AddMedia() {
|
|
|
|
// Last used directory
|
2010-02-27 17:52:18 +01:00
|
|
|
QString directory = settings_.value("add_media_path", QDir::currentPath()).toString();
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
// Show dialog
|
2010-03-07 15:42:51 +01:00
|
|
|
QStringList file_names = QFileDialog::getOpenFileNames(
|
|
|
|
this, "Add media", directory, kMediaFilterSpec);
|
2010-02-24 23:26:01 +01:00
|
|
|
if (file_names.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Save last used directory
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("add_media_path", file_names[0]);
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
// Add media
|
|
|
|
QList<QUrl> urls;
|
|
|
|
foreach (const QString& path, file_names) {
|
2010-03-07 15:42:51 +01:00
|
|
|
if (path.endsWith(".m3u")) {
|
|
|
|
QFile file(path);
|
|
|
|
QFileInfo info(file);
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
M3UParser parser(&file, info.dir());
|
|
|
|
const SongList& songs = parser.Parse();
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertSongs(songs);
|
2010-03-10 22:39:25 +01:00
|
|
|
} else if (path.endsWith(".xspf") || path.endsWith(".xml")) {
|
|
|
|
QFile file(path);
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
XSPFParser parser(&file);
|
|
|
|
const SongList& songs = parser.Parse();
|
|
|
|
playlist_->InsertSongs(songs);
|
2010-03-07 15:42:51 +01:00
|
|
|
} else {
|
|
|
|
QUrl url(path);
|
|
|
|
if (url.scheme().isEmpty())
|
|
|
|
url.setScheme("file");
|
|
|
|
urls << url;
|
|
|
|
}
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertPaths(urls);
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::AddStream() {
|
|
|
|
add_stream_dialog_->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::AddStreamAccepted() {
|
|
|
|
QList<QUrl> urls;
|
|
|
|
urls << add_stream_dialog_->url();
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertStreamUrls(urls);
|
2010-03-07 21:19:35 +01:00
|
|
|
}
|
2010-03-24 17:36:44 +01:00
|
|
|
|
|
|
|
void MainWindow::PlaylistRemoveCurrent() {
|
|
|
|
ui_.playlist->RemoveSelected();
|
|
|
|
}
|
2010-03-31 02:30:57 +02:00
|
|
|
|
|
|
|
void MainWindow::GroupByClicked(QAction* action) {
|
2010-04-01 19:20:31 +02:00
|
|
|
if (action->property("group_by").isNull()) {
|
2010-04-01 01:11:45 +02:00
|
|
|
group_by_dialog_->show();
|
2010-03-31 02:30:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-01 19:20:31 +02:00
|
|
|
Library::Grouping g = action->property("group_by").value<Library::Grouping>();
|
2010-03-31 02:30:57 +02:00
|
|
|
library_->SetGroupBy(g);
|
2010-04-01 01:11:45 +02:00
|
|
|
}
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
void MainWindow::LibraryGroupingChanged(const Library::Grouping& g) {
|
|
|
|
// Save the settings
|
2010-03-31 02:30:57 +02:00
|
|
|
settings_.setValue("group_by1", int(g[0]));
|
|
|
|
settings_.setValue("group_by2", int(g[1]));
|
|
|
|
settings_.setValue("group_by3", int(g[2]));
|
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
// Now make sure the correct action is checked
|
2010-03-31 17:18:39 +02:00
|
|
|
foreach (QAction* action, group_by_group_->actions()) {
|
2010-04-01 19:20:31 +02:00
|
|
|
if (action->property("group_by").isNull())
|
|
|
|
continue;
|
2010-03-31 17:18:39 +02:00
|
|
|
|
2010-04-01 19:20:31 +02:00
|
|
|
if (g == action->property("group_by").value<Library::Grouping>()) {
|
2010-03-31 17:18:39 +02:00
|
|
|
action->setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui_.group_by_advanced->setChecked(true);
|
2010-03-31 02:30:57 +02:00
|
|
|
}
|
2010-04-11 19:58:58 +02:00
|
|
|
|
|
|
|
void MainWindow::PlaylistEditFinished(const QModelIndex& index) {
|
|
|
|
if (index == playlist_menu_index_)
|
|
|
|
SelectionSetValue();
|
|
|
|
}
|
2010-04-13 00:44:29 +02:00
|
|
|
|
|
|
|
void MainWindow::CommandlineOptionsReceived(const QByteArray& serialized_options) {
|
|
|
|
if (serialized_options == "wake up!") {
|
|
|
|
// Old versions of Clementine sent this - just ignore it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandlineOptions options;
|
|
|
|
options.Load(serialized_options);
|
|
|
|
|
2010-04-13 01:35:47 +02:00
|
|
|
if (options.is_empty()) {
|
|
|
|
show();
|
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CommandlineOptionsReceived(options);
|
2010-04-13 00:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
|
|
|
|
switch (options.player_action()) {
|
|
|
|
case CommandlineOptions::Player_Play:
|
|
|
|
player_->Play();
|
|
|
|
break;
|
|
|
|
case CommandlineOptions::Player_PlayPause:
|
|
|
|
player_->PlayPause();
|
|
|
|
break;
|
|
|
|
case CommandlineOptions::Player_Pause:
|
|
|
|
player_->Pause();
|
|
|
|
break;
|
|
|
|
case CommandlineOptions::Player_Stop:
|
|
|
|
player_->Stop();
|
|
|
|
break;
|
|
|
|
case CommandlineOptions::Player_Previous:
|
|
|
|
player_->Previous();
|
|
|
|
break;
|
|
|
|
case CommandlineOptions::Player_Next:
|
|
|
|
player_->Next(Engine::Manual);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CommandlineOptions::Player_None:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (options.url_list_action()) {
|
|
|
|
case CommandlineOptions::UrlList_Load:
|
|
|
|
playlist_->Clear();
|
|
|
|
|
|
|
|
// fallthrough
|
|
|
|
case CommandlineOptions::UrlList_Append:
|
|
|
|
playlist_->InsertPaths(options.urls(), -1);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-13 01:35:47 +02:00
|
|
|
|
|
|
|
if (options.set_volume() != -1)
|
|
|
|
player_->SetVolume(options.set_volume());
|
|
|
|
|
|
|
|
if (options.volume_modifier() != 0)
|
|
|
|
player_->SetVolume(player_->GetVolume() + options.volume_modifier());
|
|
|
|
|
|
|
|
if (options.seek_to() != -1)
|
|
|
|
player_->Seek(options.seek_to());
|
2010-04-13 22:22:29 +02:00
|
|
|
else if (options.seek_by() != 0)
|
|
|
|
player_->Seek(player_->PositionGet() / 1000 + options.seek_by());
|
2010-04-13 01:35:47 +02:00
|
|
|
|
|
|
|
if (options.play_track_at() != -1)
|
|
|
|
player_->PlayAt(options.play_track_at(), Engine::Manual);
|
|
|
|
|
|
|
|
if (options.show_osd())
|
|
|
|
player_->ShowOSD();
|
2010-04-13 00:44:29 +02:00
|
|
|
}
|
2010-04-13 22:45:40 +02:00
|
|
|
|
|
|
|
void MainWindow::ForceShowOSD(const Song &song) {
|
|
|
|
osd_->ForceShowNextNotification();
|
|
|
|
osd_->SongChanged(song);
|
|
|
|
}
|
2010-04-14 23:27:27 +02:00
|
|
|
|
|
|
|
bool MainWindow::event(QEvent* event) {
|
2010-04-14 23:58:51 +02:00
|
|
|
// ApplicationActivate is received when the dock is clicked on OS X.
|
|
|
|
if (event->type() == QEvent::ApplicationActivate) {
|
2010-04-14 23:27:27 +02:00
|
|
|
show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QMainWindow::event(event);
|
|
|
|
}
|
2010-04-15 17:23:12 +02:00
|
|
|
|
|
|
|
void MainWindow::CheckForUpdates() {
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
mac::CheckForUpdates();
|
|
|
|
#endif
|
|
|
|
}
|