From 5da18c59ceac2db0c6f06519ba3a862cd75a2e11 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 20 Jul 2014 18:08:09 +0100 Subject: [PATCH 1/9] Add dummy Sync with menu --- src/tomahawk/sourcetree/SourceTreeView.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tomahawk/sourcetree/SourceTreeView.cpp b/src/tomahawk/sourcetree/SourceTreeView.cpp index c99d46bc84..d4591b38e9 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.cpp +++ b/src/tomahawk/sourcetree/SourceTreeView.cpp @@ -240,6 +240,10 @@ SourceTreeView::setupMenus() { QAction* exportPlaylist = m_playlistMenu.addAction( tr( "&Export Playlist") ); connect( exportPlaylist, SIGNAL( triggered() ), this, SLOT( exportPlaylist() ) ); + + QMenu* playlistSyncMenu = m_playlistMenu.addMenu( tr( "Sync with .." ) ); + // TODO: List Services that can sync a playlist + // TODO: Add a checkmark to the service that syncs this playlist } QAction* deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete %1" ).arg( SourcesModel::rowTypeToString( type ) ) ); From 0c0dfd82cc2caa90938cc30e9576981403b83767 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 20 Jul 2014 18:35:59 +0100 Subject: [PATCH 2/9] List resolvers in the menu that can sync playlists --- src/tomahawk/sourcetree/SourceTreeView.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tomahawk/sourcetree/SourceTreeView.cpp b/src/tomahawk/sourcetree/SourceTreeView.cpp index d4591b38e9..5f847036af 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.cpp +++ b/src/tomahawk/sourcetree/SourceTreeView.cpp @@ -44,6 +44,8 @@ #include "utils/TomahawkUtilsGui.h" #include "widgets/SourceTreePopupDialog.h" #include "PlaylistEntry.h" +#include "Pipeline.h" +#include "resolvers/ExternalResolver.h" #include "../../viewpages/dashboard/Dashboard.h" #include "../../viewpages/whatsnew_0_8/WhatsNew_0_8.h" @@ -242,8 +244,15 @@ SourceTreeView::setupMenus() connect( exportPlaylist, SIGNAL( triggered() ), this, SLOT( exportPlaylist() ) ); QMenu* playlistSyncMenu = m_playlistMenu.addMenu( tr( "Sync with .." ) ); - // TODO: List Services that can sync a playlist - // TODO: Add a checkmark to the service that syncs this playlist + foreach ( const QPointer& resolver, Tomahawk::Pipeline::instance()->scriptResolvers() ) + { + if ( resolver->capabilities().testFlag( ExternalResolver::PlaylistSync ) ) + { + // TODO: Add a checkmark to the service that syncs this playlist + // TODO: Actually add an action to sync + playlistSyncMenu->addAction( resolver->icon(), resolver->name() ); + } + } } QAction* deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete %1" ).arg( SourcesModel::rowTypeToString( type ) ) ); From d8eaf392320f2e485272d6dbb76bd1e44d060080 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:55:30 +0100 Subject: [PATCH 3/9] Add ExternalResolverPlaylistUpdater* skeletons --- .../ExternalResolverPlaylistUpdater.cpp | 11 ++++ .../ExternalResolverPlaylistUpdater.h | 64 +++++++++++++++++++ ...ExternalResolverPlaylistUpdaterFactory.cpp | 54 ++++++++++++++++ .../ExternalResolverPlaylistUpdaterFactory.h | 45 +++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.cpp create mode 100644 src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.h create mode 100644 src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.cpp create mode 100644 src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h diff --git a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.cpp b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.cpp new file mode 100644 index 0000000000..e0e147c8e6 --- /dev/null +++ b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.cpp @@ -0,0 +1,11 @@ +#include "ExternalResolverPlaylistUpdater.h" + +namespace Tomahawk { + +ExternalResolverPlaylistUpdater::ExternalResolverPlaylistUpdater( const playlist_ptr& pl, Resolver* resolver ) + : PlaylistUpdaterInterface( pl ) +{ + // TODO +} + +} // namespace Tomahawk diff --git a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.h b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.h new file mode 100644 index 0000000000..d8f0687a98 --- /dev/null +++ b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdater.h @@ -0,0 +1,64 @@ +#ifndef TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATER_H +#define TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATER_H + +#include "playlist/PlaylistUpdaterInterface.h" + +namespace Tomahawk { + +class ExternalResolverPlaylistUpdater : public PlaylistUpdaterInterface +{ + Q_OBJECT +public: + explicit ExternalResolverPlaylistUpdater( const playlist_ptr& pl, Resolver* resolver ); + + virtual ~ExternalResolverPlaylistUpdater(); + + // What type you are. If you add a new updater, add the creation code as well. + // virtual QString type() const = 0; + + // Small widget to show in playlist header that configures the updater + // virtual QWidget* configurationWidget() const = 0; + + // Small overlay over playlist icon in the sidebar to indicate that it has this updater type + // Should be around 16x16 or something + // virtual QPixmap typeIcon() const { return QPixmap(); } + + // void remove(); + + // playlist_ptr playlist() const { return m_playlist; } + + // virtual bool sync() const { return false; } + // virtual void setSync( bool ) {} + + // virtual bool canSubscribe() const { return false; } + // virtual bool subscribed() const { return false; } + // virtual void setSubscribed( bool ) {} + // virtual void setCollaborative( bool ) {} + // virtual bool collaborative() const { return false; } + + // The int data value associated with each question must be unique across *all* playlist updaters, + // as setQuestionResults is called with all questions from all updaters. + // virtual bool hasCustomDeleter() const { return false; } + // virtual PlaylistDeleteQuestions deleteQuestions() const { return PlaylistDeleteQuestions(); } + // virtual void setQuestionResults( const QMap< int, bool > ) {} + +public slots: + // virtual void updateNow() {} + + // void save(); + +protected: + // virtual void aboutToDelete() {} + + // QVariantHash settings() const; + // void saveSettings( const QVariantHash& settings ); + +signals: + +public slots: + +}; + +} // namespace Tomahawk + +#endif // TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATER_H diff --git a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.cpp b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.cpp new file mode 100644 index 0000000000..5b08d11c91 --- /dev/null +++ b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.cpp @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Uwe L. Korn + * + * Tomahawk 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. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + +#include "ExternalResolverPlaylistUpdaterFactory.h" + +#include "Pipeline.h" + +namespace Tomahawk { + +ExternalResolverPlaylistUpdaterFactory::ExternalResolverPlaylistUpdaterFactory() +{ + connect( Pipeline::instance(), SIGNAL( resolverAdded(Tomahawk::Resolver* ) ), + SLOT( resolverAdded( Tomahawk::Resolver* ) ) ); +} + +ExternalResolverPlaylistUpdaterFactory::~ExternalResolverPlaylistUpdaterFactory() +{ +} + + +QString +ExternalResolverPlaylistUpdaterFactory::type() const +{ +} + + +PlaylistUpdaterInterface* +ExternalResolverPlaylistUpdaterFactory::create( const playlist_ptr& playlist, const QVariantHash& settings ) +{ +} + + +void +ExternalResolverPlaylistUpdaterFactory::resolverAdded( Resolver* resolver ) +{ +} + + +} // namespace Tomahawk diff --git a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h new file mode 100644 index 0000000000..a7aab54666 --- /dev/null +++ b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h @@ -0,0 +1,45 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Uwe L. Korn + * + * Tomahawk 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. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + + +#ifndef TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATERFACTORY_H +#define TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATERFACTORY_H + +#include "playlist/PlaylistUpdaterInterface.h" + +#include "DllMacro.h" + +namespace Tomahawk { + +class DLLEXPORT ExternalResolverPlaylistUpdaterFactory : public PlaylistUpdaterFactory +{ + Q_OBJECT +public: + ExternalResolverPlaylistUpdaterFactory(); + virtual ~ExternalResolverPlaylistUpdaterFactory(); + + QString type() const Q_DECL_OVERRIDE; + PlaylistUpdaterInterface* create( const playlist_ptr&, const QVariantHash& settings ) Q_DECL_OVERRIDE; + +private slots: + void resolverAdded( Tomahawk::Resolver* resolver ); +}; + +} // namespace Tomahawk + +#endif // TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATERFACTORY_H From f5395705b5bb905483dff519e23b2fe65b84ea1d Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:56:51 +0100 Subject: [PATCH 4/9] Add files to CMakeLists --- src/libtomahawk/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 0f97802e2e..88a13f9463 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -87,6 +87,8 @@ set( libGuiSources resolvers/JSResolver.cpp resolvers/JSResolverHelper.cpp resolvers/ScriptEngine.cpp + resolvers/playlist/ExternalResolverPlaylistUpdater.cpp + resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.cpp utils/DpiScaler.cpp utils/ImageRegistry.cpp From f42ac00bcbfa9ae6d1cfccdbbcf9814e5071c2f1 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:57:29 +0100 Subject: [PATCH 5/9] Add skeleton for starting to sync a playlist --- src/libtomahawk/Pipeline.cpp | 7 +++++++ src/libtomahawk/Pipeline.h | 5 +++++ src/tomahawk/TomahawkApp.cpp | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index 162fb3d01e..8fb390add2 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -327,6 +327,13 @@ Pipeline::resolve( QID qid, bool prioritized, bool temporaryQuery ) } +void +Pipeline::startPlaylistSync( ExternalResolver* r, playlist_ptr playlist ) +{ + // TODO +} + + void Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) { diff --git a/src/libtomahawk/Pipeline.h b/src/libtomahawk/Pipeline.h index cfab80796b..f23dc81354 100644 --- a/src/libtomahawk/Pipeline.h +++ b/src/libtomahawk/Pipeline.h @@ -78,6 +78,11 @@ public slots: void resolve( const QList& qlist, bool prioritized = true, bool temporaryQuery = false ); void resolve( QID qid, bool prioritized = true, bool temporaryQuery = false ); + /** + * Initiate syncing of a playlist with a reslover. + */ + void startPlaylistSync( ExternalResolver* r, playlist_ptr playlist ); + void start(); void stop(); void databaseReady(); diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index 0cd4d81ad4..c7cc0dbb94 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -62,6 +62,7 @@ #include "jobview/ErrorStatusMessage.h" #include "jobview/JobStatusModel.h" #include "jobview/JobStatusView.h" +#include "resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h" #include "utils/XspfLoader.h" #include "utils/JspfLoader.h" #include "utils/Logger.h" @@ -655,7 +656,7 @@ TomahawkApp::onInfoSystemReady() Tomahawk::EchonestCatalogSynchronizer::instance(); PlaylistUpdaterInterface::registerUpdaterFactory( new XspfUpdaterFactory ); -// PlaylistUpdaterInterface::registerUpdaterFactory( new SpotifyUpdaterFactory ); + PlaylistUpdaterInterface::registerUpdaterFactory( new ExternalResolverPlaylistUpdaterFactory ); // Following work-around/fix taken from Clementine rev. 13e13ccd9a95 and courtesy of David Sansome // A bug in Qt means the wheel_scroll_lines setting gets ignored and replaced From d96458ec723b3f048ba569a2e9b67cac58a9b7f3 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:57:53 +0100 Subject: [PATCH 6/9] Make PlaylistUpdaterInterface a QObject --- src/libtomahawk/playlist/PlaylistUpdaterInterface.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h index 3104a485d2..f521d59674 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -110,8 +110,9 @@ public slots: }; -class DLLEXPORT PlaylistUpdaterFactory +class DLLEXPORT PlaylistUpdaterFactory : public QObject { + Q_OBJECT public: PlaylistUpdaterFactory() {} virtual ~PlaylistUpdaterFactory() {} From e6d8d1faa9b7e96c79879c662702a591e287771f Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:58:09 +0100 Subject: [PATCH 7/9] Remove trailing semicolons --- src/libtomahawk/playlist/PlaylistUpdaterInterface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h index f521d59674..f6d933180a 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -123,7 +123,7 @@ class DLLEXPORT PlaylistUpdaterFactory : public QObject } -Q_DECLARE_METATYPE( Tomahawk::SerializedUpdater ); -Q_DECLARE_METATYPE( Tomahawk::SerializedUpdaters ); +Q_DECLARE_METATYPE( Tomahawk::SerializedUpdater ) +Q_DECLARE_METATYPE( Tomahawk::SerializedUpdaters ) #endif // PLAYLISTUPDATERINTERFACE_H From 36ea2f797f897a771bed8744d41394a8a419c95d Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 31 Jul 2014 19:58:26 +0100 Subject: [PATCH 8/9] Add Menu Entry to start playlist sync --- src/tomahawk/sourcetree/SourceTreeView.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/tomahawk/sourcetree/SourceTreeView.cpp b/src/tomahawk/sourcetree/SourceTreeView.cpp index 5f847036af..61f79a8324 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.cpp +++ b/src/tomahawk/sourcetree/SourceTreeView.cpp @@ -243,14 +243,24 @@ SourceTreeView::setupMenus() QAction* exportPlaylist = m_playlistMenu.addAction( tr( "&Export Playlist") ); connect( exportPlaylist, SIGNAL( triggered() ), this, SLOT( exportPlaylist() ) ); - QMenu* playlistSyncMenu = m_playlistMenu.addMenu( tr( "Sync with .." ) ); - foreach ( const QPointer& resolver, Tomahawk::Pipeline::instance()->scriptResolvers() ) + const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); + const playlist_ptr playlist = item->playlist(); + if ( playlist ) { - if ( resolver->capabilities().testFlag( ExternalResolver::PlaylistSync ) ) + QMenu* playlistSyncMenu = m_playlistMenu.addMenu( tr( "Sync with .." ) ); + + foreach ( const QPointer& resolver, Tomahawk::Pipeline::instance()->scriptResolvers() ) { - // TODO: Add a checkmark to the service that syncs this playlist - // TODO: Actually add an action to sync - playlistSyncMenu->addAction( resolver->icon(), resolver->name() ); + if ( resolver->capabilities().testFlag( ExternalResolver::PlaylistSync ) ) + { + // TODO: Add a checkmark to the service that syncs this playlist + // TODO: Actually add an action to sync + QAction* plSync = playlistSyncMenu->addAction( resolver->icon(), resolver->name() ); + NewClosure( plSync, SIGNAL( triggered() ), + Pipeline::instance(), + SLOT( startPlaylistSync( ExternalResolver* , playlist_ptr ) ), + resolver, playlist ); + } } } } From 2ec6a06f2ae46c0a3a8e1016cf1cdd129253d6e6 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 19 Oct 2014 16:10:05 +0200 Subject: [PATCH 9/9] Use override directly --- .../playlist/ExternalResolverPlaylistUpdaterFactory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h index a7aab54666..bbdcf08d33 100644 --- a/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h +++ b/src/libtomahawk/resolvers/playlist/ExternalResolverPlaylistUpdaterFactory.h @@ -33,8 +33,8 @@ class DLLEXPORT ExternalResolverPlaylistUpdaterFactory : public PlaylistUpdaterF ExternalResolverPlaylistUpdaterFactory(); virtual ~ExternalResolverPlaylistUpdaterFactory(); - QString type() const Q_DECL_OVERRIDE; - PlaylistUpdaterInterface* create( const playlist_ptr&, const QVariantHash& settings ) Q_DECL_OVERRIDE; + QString type() const override; + PlaylistUpdaterInterface* create( const playlist_ptr&, const QVariantHash& settings ) override; private slots: void resolverAdded( Tomahawk::Resolver* resolver );