1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
4
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
6
* Tomahawk is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Tomahawk is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef SPOTIFYPLAYLISTUPDATER_H
21
#define SPOTIFYPLAYLISTUPDATER_H
23
#include "playlist/PlaylistUpdaterInterface.h"
24
#include "utils/Closure.h"
37
class DLLEXPORT SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface
41
friend class Tomahawk::Accounts::SpotifyAccount;
43
SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const Tomahawk::playlist_ptr& pl );
45
virtual ~SpotifyPlaylistUpdater();
47
virtual QString type() const;
48
virtual void updateNow() {}
50
#ifndef ENABLE_HEADLESS
51
virtual QWidget* configurationWidget() const { return 0; }
52
virtual QPixmap typeIcon() const;
56
void setSync( bool sync );
57
bool subscribed() const;
58
// actually change the subscribed value in spotify
59
void setSubscribed( bool subscribed );
60
// Just set the subscribed flag
61
void setSubscribedStatus( bool subscribed );
62
bool canSubscribe() const;
63
void setCanSubscribe( bool canSub );
64
void setSubscribers( int numSubscribers );
65
int subscribers() const { return m_subscribers; }
66
// Collaborative actions
67
void setOwner( bool owner );
69
bool collaborative() const;
70
void setCollaborative( bool collaborative );
72
QString spotifyId() const { return m_spotifyId; }
74
virtual bool hasCustomDeleter() const { return true; }
75
virtual Tomahawk::PlaylistDeleteQuestions deleteQuestions() const;
76
virtual void setQuestionResults( const QMap< int, bool > results );
78
void remove( bool askToDeletePlaylist = true );
80
/// Spotify callbacks when we are directly instructed from the resolver
81
void spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev );
82
void spotifyTracksRemoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev );
83
void spotifyTracksMoved( const QVariantList& tracks, const QString& newStartPos, const QString& newRev, const QString& oldRev );
84
void spotifyPlaylistRenamed( const QString& title, const QString& newRev, const QString& oldRev );
86
void tomahawkTracksInserted( const QList<Tomahawk::plentry_ptr>& ,int );
87
void tomahawkTracksRemoved( const QList<Tomahawk::query_ptr>& );
88
void tomahawkTracksMoved( const QList<Tomahawk::plentry_ptr>& ,int );
89
void tomahawkPlaylistRenamed( const QString&, const QString& );
92
// SpotifyResolver message handlers, all take msgtype, msg as argument
93
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
94
void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
95
void onTracksMovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
97
void unsyncOrDelete( bool toDelete );
99
void playlistRevisionLoaded();
102
void saveToSettings();
104
/// Finds the nearest spotify id from pos to the beginning of the playlist
105
QString nearestSpotifyTrack( const QList< Tomahawk::plentry_ptr >& entries, int pos );
106
QVariantList plentryToVariant( const QList< Tomahawk::plentry_ptr >& entries );
108
static QVariantList queriesToVariant( const QList< Tomahawk::query_ptr >& queries );
109
static QVariant queryToVariant( const Tomahawk::query_ptr& query );
110
static QList< Tomahawk::query_ptr > variantToQueries( const QVariantList& list );
112
QWeakPointer<Tomahawk::Accounts::SpotifyAccount> m_spotify;
113
QString m_latestRev, m_spotifyId;
114
QList< Tomahawk::plentry_ptr > m_waitingForIds;
116
bool m_blockUpdatesForNextRevision;
121
bool m_collaborative;
124
QQueue<_detail::Closure*> m_queuedOps;
125
#ifndef ENABLE_HEADLESS
126
static QPixmap* s_typePixmap;
131
class DLLEXPORT SpotifyUpdaterFactory : public Tomahawk::PlaylistUpdaterFactory
134
SpotifyUpdaterFactory() {}
136
virtual Tomahawk::PlaylistUpdaterInterface* create( const Tomahawk::playlist_ptr& pl, const QVariantHash& settings );
137
virtual QString type() const { return "spotify"; }
140
QWeakPointer<Tomahawk::Accounts::SpotifyAccount> m_account;
143
#endif // SPOTIFYPLAYLISTUPDATER_H