diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index d1469d5fb..6e4d7a5ea 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -42,10 +42,9 @@ const char* Mpris2::kMprisObjectPath = "/org/mpris/MediaPlayer2"; const char* Mpris2::kServiceName = "org.mpris.MediaPlayer2.clementine"; const char* Mpris2::kFreedesktopPath = "org.freedesktop.DBus.Properties"; -Mpris2::Mpris2(MainWindow* main_window, Player* player, ArtLoader* art_loader, +Mpris2::Mpris2(Player* player, ArtLoader* art_loader, Mpris1* mpris1, QObject* parent) : QObject(parent), - ui_(main_window), player_(player), mpris1_(mpris1) { @@ -205,8 +204,7 @@ QStringList Mpris2::SupportedMimeTypes() const { } void Mpris2::Raise() { - ui_->show(); - ui_->activateWindow(); + emit RaiseMainWindow(); } void Mpris2::Quit() { diff --git a/src/core/mpris2.h b/src/core/mpris2.h index 53dee71f5..298a7e3c4 100644 --- a/src/core/mpris2.h +++ b/src/core/mpris2.h @@ -72,7 +72,7 @@ class Mpris2 : public QObject { Q_PROPERTY( bool CanEditTracks READ CanEditTracks ) public: - Mpris2(MainWindow* main_window, Player* player, ArtLoader* art_loader, + Mpris2(Player* player, ArtLoader* art_loader, Mpris1* mpris1, QObject* parent); // Root Properties @@ -140,6 +140,8 @@ signals: void TrackRemoved(const QDBusObjectPath& trackId); void TrackMetadataChanged(const QDBusObjectPath& trackId, const TrackMetadata& metadata); + void RaiseMainWindow(); + private slots: void ArtLoaded(const Song& song, const QString& art_uri); void EngineStateChanged(Engine::State newState); @@ -165,7 +167,6 @@ private: QVariantMap last_metadata_; - MainWindow* ui_; Player* player_; Mpris1* mpris1_; }; diff --git a/src/core/player.cpp b/src/core/player.cpp index 184fa38fa..3fc4019ea 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -23,19 +23,11 @@ #include "playlist/playlist.h" #include "playlist/playlistitem.h" #include "playlist/playlistmanager.h" -#include "mpris_common.h" #ifdef HAVE_LIBLASTFM # include "radio/lastfmservice.h" #endif -#ifdef HAVE_DBUS -# include "mpris.h" -# include "mpris2.h" -# include -# include -#endif - #include #include @@ -44,15 +36,12 @@ using boost::shared_ptr; -Player::Player(MainWindow* main_window, PlaylistManager* playlists, +Player::Player(PlaylistManager* playlists, #ifdef HAVE_LIBLASTFM LastFMService* lastfm, #endif QObject* parent) : QObject(parent), - art_loader_(new mpris::ArtLoader(this)), - mpris1_(NULL), - mpris2_(NULL), playlists_(playlists), #ifdef HAVE_LIBLASTFM lastfm_(lastfm), @@ -62,24 +51,6 @@ Player::Player(MainWindow* main_window, PlaylistManager* playlists, last_state_(Engine::Empty), volume_before_mute_(50) { - // Loads album art and saves it to a file in /tmp for MPRIS clients and those - // objects which need cover art's filepath, not the image itself - connect(playlists, SIGNAL(CurrentSongChanged(Song)), - art_loader_, SLOT(LoadArt(Song))); - -#ifdef HAVE_DBUS - // MPRIS DBus interface. - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - - //MPRIS 1.0 implementation - mpris1_ = new mpris::Mpris1(this, art_loader_, this); - - //MPRIS 2.0 implementation - mpris2_ = new mpris::Mpris2(main_window, this, art_loader_, mpris1_, this); -#endif - settings_.beginGroup("Player"); SetVolume(settings_.value("volume", 50).toInt()); diff --git a/src/core/player.h b/src/core/player.h index 18a1bfc44..94fca00a6 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -37,23 +37,11 @@ class MainWindow; class LastFMService; #endif -namespace mpris { - class Mpris1; - class Mpris2; - class ArtLoader; -} - -#ifdef HAVE_DBUS -# include - QDBusArgument& operator<< (QDBusArgument& arg, const QImage& image); - const QDBusArgument& operator>> (const QDBusArgument& arg, QImage& image); -#endif - class Player : public QObject { Q_OBJECT public: - Player(MainWindow* main_window, PlaylistManager* playlists, + Player(PlaylistManager* playlists, #ifdef HAVE_LIBLASTFM LastFMService* lastfm, #endif @@ -69,7 +57,6 @@ class Player : public QObject { PlaylistItemPtr GetCurrentItem() const { return current_item_; } PlaylistItemPtr GetItemAt(int pos) const; PlaylistManager* playlists() const { return playlists_; } - mpris::ArtLoader* ArtLoader() const { return art_loader_; } public slots: void ReloadSettings(); @@ -124,11 +111,6 @@ class Player : public QObject { void NextInternal(Engine::TrackChangeType); private: - mpris::ArtLoader* art_loader_; - - mpris::Mpris1* mpris1_; - mpris::Mpris2* mpris2_; - PlaylistManager* playlists_; #ifdef HAVE_LIBLASTFM LastFMService* lastfm_; diff --git a/src/main.cpp b/src/main.cpp index c58073c9c..ab3bde7a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,16 +33,21 @@ #include "core/player.h" #include "core/potranslator.h" #include "core/song.h" +#include "core/taskmanager.h" #include "core/utilities.h" #include "engines/enginebase.h" #include "library/directory.h" #include "playlist/playlist.h" +#include "playlist/playlistmanager.h" +#include "radio/radiomodel.h" #include "remote/httpserver.h" #include "remote/zeroconf.h" #include "smartplaylists/generator.h" #include "ui/equalizer.h" #include "ui/iconloader.h" #include "ui/mainwindow.h" +#include "ui/systemtrayicon.h" +#include "widgets/osd.h" #include "qtsingleapplication.h" #include "qtsinglecoreapplication.h" @@ -59,6 +64,9 @@ #include #include +#include +using boost::scoped_ptr; + #include #ifdef Q_OS_DARWIN @@ -70,6 +78,18 @@ #include "radio/lastfmservice.h" #endif +#ifdef HAVE_DBUS + #include "core/mpris_common.h" + #include "core/mpris.h" + #include "core/mpris2.h" + #include + #include + #include + + QDBusArgument& operator<< (QDBusArgument& arg, const QImage& image); + const QDBusArgument& operator>> (const QDBusArgument& arg, QImage& image); +#endif + class GstEnginePipeline; // Load sqlite plugin on windows and mac. @@ -267,6 +287,36 @@ int main(int argc, char *argv[]) { // Seed the random number generator srand(time(NULL)); + scoped_ptr > database( + new BackgroundThreadImplementation(NULL)); + database->Start(true); + TaskManager task_manager; + PlaylistManager playlists(&task_manager, NULL); + + RadioModel radio_model(database.get(), &task_manager, NULL); + Player player(&playlists, +#ifdef HAVE_LIBLASTFM + radio_model.GetLastFMService() +#endif + ); + + scoped_ptr tray_icon(SystemTrayIcon::CreateSystemTrayIcon()); + OSD osd(tray_icon.get()); + +#ifdef HAVE_DBUS + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + + mpris::ArtLoader art_loader; + mpris::Mpris1 mpris1(&player, &art_loader); + mpris::Mpris2 mpris2(&player, &art_loader, &mpris1); + + QObject::connect(&playlists, SIGNAL(CurrentSongChanged(Song)), &art_loader, SLOT(LoadArt(Song))); + QObject::connect(&art_loader, SIGNAL(ThumbnailLoaded(Song, QString)), + &osd, SLOT(CoverArtPathReady(Song, QString))); +#endif + Zeroconf* zeroconf = Zeroconf::GetZeroconf(); if (zeroconf) { HttpServer* server = new HttpServer; @@ -276,8 +326,17 @@ int main(int argc, char *argv[]) { } // Window - MainWindow w; - + MainWindow w( + database.get(), + &task_manager, + &playlists, + &radio_model, + &player, + tray_icon.get(), + &osd); +#ifdef HAVE_DBUS + QObject::connect(&mpris2, SIGNAL(RaiseMainWindow()), &w, SLOT(Raise())); +#endif QObject::connect(&a, SIGNAL(messageReceived(QByteArray)), &w, SLOT(CommandlineOptionsReceived(QByteArray))); w.CommandlineOptionsReceived(options); diff --git a/src/radio/icecastfilterwidget.cpp b/src/radio/icecastfilterwidget.cpp index 8f42b7c23..f94d17a67 100644 --- a/src/radio/icecastfilterwidget.cpp +++ b/src/radio/icecastfilterwidget.cpp @@ -55,7 +55,6 @@ IcecastFilterWidget::IcecastFilterWidget(QWidget *parent) MacLineEdit* lineedit = new MacLineEdit(this); ui_->horizontalLayout->insertWidget(1, lineedit); filter_ = lineedit; - ui_->clear->setHidden(true); #else filter_ = ui_->filter; #endif diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index a8926e38b..608f4ce0e 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -136,17 +136,25 @@ const char* MainWindow::kMusicFilterSpec = const char* MainWindow::kAllFilesFilterSpec = QT_TR_NOOP("All Files (*)"); -MainWindow::MainWindow(QWidget* parent) +MainWindow::MainWindow( + BackgroundThread* database, + TaskManager* task_manager, + PlaylistManager* playlist_manager, + RadioModel* radio_model, + Player* player, + SystemTrayIcon* tray_icon, + OSD* osd, + QWidget* parent) : QMainWindow(parent), ui_(new Ui_MainWindow), - tray_icon_(SystemTrayIcon::CreateSystemTrayIcon(this)), - osd_(new OSD(tray_icon_, this)), - task_manager_(new TaskManager(this)), - database_(new BackgroundThreadImplementation(this)), - radio_model_(NULL), + tray_icon_(tray_icon), + osd_(osd), + task_manager_(task_manager), + database_(database), + radio_model_(radio_model), playlist_backend_(NULL), - playlists_(new PlaylistManager(task_manager_, this)), - player_(NULL), + playlists_(playlist_manager), + player_(player), library_(NULL), global_shortcuts_(new GlobalShortcuts(this)), devices_(NULL), @@ -176,21 +184,12 @@ MainWindow::MainWindow(QWidget* parent) track_position_timer_(new QTimer(this)), was_maximized_(false) { - // Wait for the database thread to start - lots of stuff depends on it. - database_->Start(true); - // Create some objects in the database thread playlist_backend_ = new PlaylistBackend; playlist_backend_->moveToThread(database_); playlist_backend_->SetDatabase(database_->Worker()); // Create stuff that needs the database - radio_model_ = new RadioModel(database_, task_manager_, this); - player_ = new Player(this, playlists_, -#ifdef HAVE_LIBLASTFM - radio_model_->GetLastFMService(), -#endif - this); library_ = new Library(database_, task_manager_, this); devices_ = new DeviceManager(database_, task_manager_, this); @@ -389,8 +388,6 @@ MainWindow::MainWindow(QWidget* parent) connect(playlists_, SIGNAL(SummaryTextChanged(QString)), ui_->playlist_summary, SLOT(setText(QString))); connect(playlists_, SIGNAL(PlayRequested(QModelIndex)), SLOT(PlayIndex(QModelIndex))); - connect(player_->ArtLoader(), SIGNAL(ThumbnailLoaded(Song,QString)), osd_, SLOT(CoverArtPathReady(Song,QString))); - connect(ui_->playlist->view(), SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex))); connect(ui_->playlist->view(), SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex))); connect(ui_->playlist->view(), SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex))); @@ -1802,6 +1799,11 @@ void MainWindow::PlaylistCurrentChanged(const QModelIndex& proxy_current) { playlist_menu_index_ = QModelIndex(); } +void MainWindow::Raise() { + show(); + activateWindow(); +} + void MainWindow::ShowScriptDialog() { if (!script_dialog_) { script_dialog_.reset(new ScriptDialog); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 92e796e50..60d58a74f 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -79,7 +79,14 @@ class MainWindow : public QMainWindow, public PlatformInterface { Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(BackgroundThread* database, + TaskManager* task_manager, + PlaylistManager* playlists, + RadioModel* radio_model, + Player* player, + SystemTrayIcon* tray_icon, + OSD* osd, + QWidget *parent = 0); ~MainWindow(); static const char* kSettingsGroup; @@ -216,6 +223,8 @@ class MainWindow : public QMainWindow, public PlatformInterface { void DeleteFinished(const SongList& songs_with_errors); + void Raise(); + private: void AddFilesToPlaylist(bool clear_first, const QList& urls); void AddLibraryItemToPlaylist(bool clear_first, bool enqueue, const QModelIndexList& indexes);