~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
Import upstream version 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
 
4
 *   Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#ifndef SPOTIFYPLAYLISTUPDATER_H
 
21
#define SPOTIFYPLAYLISTUPDATER_H
 
22
 
 
23
#include "playlist/PlaylistUpdaterInterface.h"
 
24
#include "utils/Closure.h"
 
25
#include "DllMacro.h"
 
26
#include "Typedefs.h"
 
27
 
 
28
#include <QQueue>
 
29
#include <QVariant>
 
30
 
 
31
namespace Tomahawk {
 
32
namespace Accounts {
 
33
    class SpotifyAccount;
 
34
}
 
35
}
 
36
 
 
37
class DLLEXPORT SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface
 
38
{
 
39
    Q_OBJECT
 
40
 
 
41
    friend class Tomahawk::Accounts::SpotifyAccount;
 
42
public:
 
43
    SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const Tomahawk::playlist_ptr& pl );
 
44
 
 
45
    virtual ~SpotifyPlaylistUpdater();
 
46
 
 
47
    virtual QString type() const;
 
48
    virtual void updateNow() {}
 
49
 
 
50
#ifndef ENABLE_HEADLESS
 
51
    virtual QWidget* configurationWidget() const { return 0; }
 
52
    virtual QPixmap typeIcon() const;
 
53
#endif
 
54
 
 
55
    bool sync() 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 );
 
68
    bool owner() const;
 
69
    bool collaborative() const;
 
70
    void setCollaborative( bool collaborative );
 
71
 
 
72
    QString spotifyId() const { return m_spotifyId; }
 
73
 
 
74
    virtual bool hasCustomDeleter() const { return true; }
 
75
    virtual Tomahawk::PlaylistDeleteQuestions deleteQuestions() const;
 
76
    virtual void setQuestionResults( const QMap< int, bool > results );
 
77
 
 
78
    void remove( bool askToDeletePlaylist = true );
 
79
public slots:
 
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  );
 
85
 
 
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& );
 
90
 
 
91
private slots:
 
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 );
 
96
 
 
97
    void unsyncOrDelete( bool toDelete );
 
98
 
 
99
    void playlistRevisionLoaded();
 
100
private:
 
101
    void init();
 
102
    void saveToSettings();
 
103
 
 
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 );
 
107
 
 
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 );
 
111
 
 
112
    QWeakPointer<Tomahawk::Accounts::SpotifyAccount> m_spotify;
 
113
    QString m_latestRev, m_spotifyId;
 
114
    QList< Tomahawk::plentry_ptr > m_waitingForIds;
 
115
 
 
116
    bool m_blockUpdatesForNextRevision;
 
117
    bool m_sync;
 
118
    bool m_subscribed;
 
119
    bool m_canSubscribe;
 
120
    bool m_isOwner;
 
121
    bool m_collaborative;
 
122
    int m_subscribers;
 
123
 
 
124
    QQueue<_detail::Closure*> m_queuedOps;
 
125
#ifndef ENABLE_HEADLESS
 
126
    static QPixmap* s_typePixmap;
 
127
#endif
 
128
};
 
129
 
 
130
 
 
131
class DLLEXPORT SpotifyUpdaterFactory : public Tomahawk::PlaylistUpdaterFactory
 
132
{
 
133
public:
 
134
    SpotifyUpdaterFactory()  {}
 
135
 
 
136
    virtual Tomahawk::PlaylistUpdaterInterface* create( const Tomahawk::playlist_ptr& pl, const QVariantHash& settings );
 
137
    virtual QString type() const { return "spotify"; }
 
138
 
 
139
private:
 
140
    QWeakPointer<Tomahawk::Accounts::SpotifyAccount> m_account;
 
141
};
 
142
 
 
143
#endif // SPOTIFYPLAYLISTUPDATER_H