PageRenderTime 143ms CodeModel.GetById 70ms app.highlight 8ms RepoModel.GetById 63ms app.codeStats 0ms

/src/libtomahawk/playlist/PlaylistUpdaterInterface.h

http://github.com/tomahawk-player/tomahawk
C Header | 128 lines | 61 code | 32 blank | 35 comment | 0 complexity | 20f6b680894a2c767602c5a100277314 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#ifndef PLAYLISTUPDATERINTERFACE_H
 20#define PLAYLISTUPDATERINTERFACE_H
 21
 22#include "DllMacro.h"
 23#include "Typedefs.h"
 24#include "Playlist.h"
 25
 26#include <QTimer>
 27#include <QMutex>
 28#include <QPair>
 29#include <QPixmap>
 30
 31namespace Tomahawk
 32{
 33/**
 34  * PlaylistUpdaters are attached to playlists. They usually manipulate the playlist in some way
 35  * due to external input (spotify syncing) or timers (xspf updating)
 36  *
 37  * Updaters have 2 modes of operation: syncing and subscribing. Syncing implies two-way sync, that is, this
 38  * playlist is reproduced on some other service (e.g. spotify or rdio).
 39  *
 40  * Subscribing implies the playlist is being updated periodically with changes from some source, and the user
 41  * is working with a copy: e.g. an xspf updater or a spotify subscribed playlist.
 42  */
 43
 44class PlaylistUpdaterFactory;
 45
 46// used when loading/saving from settings
 47
 48
 49class DLLEXPORT PlaylistUpdaterInterface : public QObject
 50{
 51    Q_OBJECT
 52public:
 53    explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
 54
 55    virtual ~PlaylistUpdaterInterface();
 56
 57    // What type you are. If you add a new updater, add the creation code as well.
 58    virtual QString type() const = 0;
 59
 60    // Small widget to show in playlist header that configures the updater
 61    virtual QWidget* configurationWidget() const = 0;
 62
 63    // Small overlay over playlist icon in the sidebar to indicate that it has this updater type
 64    // Should be around 16x16 or something
 65    virtual QPixmap typeIcon() const { return QPixmap(); }
 66
 67    void remove();
 68
 69    playlist_ptr playlist() const { return m_playlist; }
 70
 71    /// If you want to try to load updaters for a playlist
 72    static void loadForPlaylist( const playlist_ptr& pl );
 73
 74    static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
 75
 76    virtual bool sync() const { return false; }
 77    virtual void setSync( bool ) {}
 78
 79    virtual bool canSubscribe() const { return false; }
 80    virtual bool subscribed() const { return false; }
 81    virtual void setSubscribed( bool ) {}
 82    virtual void setCollaborative( bool ) {}
 83    virtual bool collaborative() const { return false; }
 84
 85    // The int data value associated with each question must be unique across *all* playlist updaters,
 86    // as setQuestionResults is called with all questions from all updaters.
 87    virtual bool hasCustomDeleter() const { return false; }
 88    virtual PlaylistDeleteQuestions deleteQuestions() const { return PlaylistDeleteQuestions(); }
 89    virtual void setQuestionResults( const QMap< int, bool > ) {}
 90
 91signals:
 92    void changed();
 93
 94public slots:
 95    virtual void updateNow() {}
 96
 97    void save();
 98
 99protected:
100    virtual void aboutToDelete() {}
101
102    QVariantHash settings() const;
103    void saveSettings( const QVariantHash& settings );
104
105private:
106    playlist_ptr m_playlist;
107    QVariantHash m_extraData;
108
109    static QMap< QString, PlaylistUpdaterFactory* > s_factories;
110};
111
112
113class DLLEXPORT PlaylistUpdaterFactory
114{
115public:
116    PlaylistUpdaterFactory() {}
117    virtual ~PlaylistUpdaterFactory() {}
118
119    virtual QString type() const = 0;
120    virtual PlaylistUpdaterInterface* create( const playlist_ptr&, const QVariantHash& settings ) = 0;
121};
122
123}
124
125Q_DECLARE_METATYPE( Tomahawk::SerializedUpdater );
126Q_DECLARE_METATYPE( Tomahawk::SerializedUpdaters );
127
128#endif // PLAYLISTUPDATERINTERFACE_H