Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] JS playlist sync #267

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libtomahawk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/libtomahawk/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions src/libtomahawk/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public slots:
void resolve( const QList<query_ptr>& 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();
Expand Down
7 changes: 4 additions & 3 deletions src/libtomahawk/playlist/PlaylistUpdaterInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public slots:
};


class DLLEXPORT PlaylistUpdaterFactory
class DLLEXPORT PlaylistUpdaterFactory : public QObject
{
Q_OBJECT
public:
PlaylistUpdaterFactory() {}
virtual ~PlaylistUpdaterFactory() {}
Expand All @@ -122,7 +123,7 @@ class DLLEXPORT PlaylistUpdaterFactory

}

Q_DECLARE_METATYPE( Tomahawk::SerializedUpdater );
Q_DECLARE_METATYPE( Tomahawk::SerializedUpdaters );
Q_DECLARE_METATYPE( Tomahawk::SerializedUpdater )
Q_DECLARE_METATYPE( Tomahawk::SerializedUpdaters )

#endif // PLAYLISTUPDATERINTERFACE_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "ExternalResolverPlaylistUpdater.h"

namespace Tomahawk {

ExternalResolverPlaylistUpdater::ExternalResolverPlaylistUpdater( const playlist_ptr& pl, Resolver* resolver )
: PlaylistUpdaterInterface( pl )
{
// TODO
}

} // namespace Tomahawk
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2014, Uwe L. Korn <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2014, Uwe L. Korn <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/


#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 override;
PlaylistUpdaterInterface* create( const playlist_ptr&, const QVariantHash& settings ) override;

private slots:
void resolverAdded( Tomahawk::Resolver* resolver );
};

} // namespace Tomahawk

#endif // TOMAHAWK_EXTERNALRESOLVERPLAYLISTUPDATERFACTORY_H
3 changes: 2 additions & 1 deletion src/tomahawk/TomahawkApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/tomahawk/sourcetree/SourceTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -240,6 +242,27 @@ SourceTreeView::setupMenus()
{
QAction* exportPlaylist = m_playlistMenu.addAction( tr( "&Export Playlist") );
connect( exportPlaylist, SIGNAL( triggered() ), this, SLOT( exportPlaylist() ) );

const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
const playlist_ptr playlist = item->playlist();
if ( playlist )
{
QMenu* playlistSyncMenu = m_playlistMenu.addMenu( tr( "Sync with .." ) );

foreach ( const QPointer<ExternalResolver>& 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
QAction* plSync = playlistSyncMenu->addAction( resolver->icon(), resolver->name() );
NewClosure( plSync, SIGNAL( triggered() ),
Pipeline::instance(),
SLOT( startPlaylistSync( ExternalResolver* , playlist_ptr ) ),
resolver, playlist );
}
}
}
}

QAction* deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete %1" ).arg( SourcesModel::rowTypeToString( type ) ) );
Expand Down