PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/libtomahawk/SourceList.h

http://github.com/tomahawk-player/tomahawk
C Header | 102 lines | 56 code | 27 blank | 19 comment | 0 complexity | aec73c27d4a078209f22860d22367da8 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2013,      Teo Mrnjavac <teo@kde.org>
  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 SOURCELIST_H
 21#define SOURCELIST_H
 22
 23#include <QObject>
 24#include <QMutex>
 25#include <QMap>
 26
 27#include "Typedefs.h"
 28#include "Source.h"
 29
 30#include "DllMacro.h"
 31
 32class DLLEXPORT SourceList : public QObject
 33{
 34Q_OBJECT
 35
 36public:
 37    static SourceList* instance();
 38
 39    explicit SourceList( QObject* parent = 0 );
 40
 41    bool isReady() const { return m_isReady; }
 42
 43    const Tomahawk::source_ptr& getLocal() const;
 44    void setLocal( const Tomahawk::source_ptr& localSrc );
 45
 46    void setWebSource( const Tomahawk::source_ptr& websrc );
 47    const Tomahawk::source_ptr webSource() const;
 48
 49    void loadSources();
 50    void removeAllRemote();
 51
 52    QList<Tomahawk::source_ptr> sources( bool onlyOnline = false ) const;
 53    unsigned int count() const;
 54
 55    void addScriptCollection( const Tomahawk::collection_ptr& collection );
 56    void removeScriptCollection( const Tomahawk::collection_ptr& collection );
 57    QList<Tomahawk::collection_ptr> scriptCollections() const;
 58
 59    Tomahawk::source_ptr get( const QString& username, const QString& friendlyName = QString(), bool autoCreate = false );
 60    Tomahawk::source_ptr get( int id ) const;
 61
 62public slots:
 63    // called by the playlist creation dbcmds
 64    void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
 65    void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
 66
 67signals:
 68    void ready();
 69
 70    void sourceAdded( const Tomahawk::source_ptr& );
 71    void sourceRemoved( const Tomahawk::source_ptr& );
 72
 73    void scriptCollectionAdded( const Tomahawk::collection_ptr& );
 74    void scriptCollectionRemoved( const Tomahawk::collection_ptr& );
 75
 76    void sourceLatchedOn( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to );
 77    void sourceLatchedOff( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to );
 78
 79private slots:
 80    void setSources( const QList<Tomahawk::source_ptr>& sources );
 81    void sourceSynced();
 82
 83    void latchedOn( const Tomahawk::source_ptr& );
 84    void latchedOff( const Tomahawk::source_ptr& );
 85
 86private:
 87    void add( const Tomahawk::source_ptr& source );
 88
 89    QMap< QString, Tomahawk::source_ptr > m_sources;
 90    QMap< int, QString > m_sources_id2name;
 91
 92    QList< Tomahawk::collection_ptr > m_scriptCollections;
 93
 94    bool m_isReady;
 95    Tomahawk::source_ptr m_local;
 96    Tomahawk::source_ptr m_dummy;
 97    mutable QMutex m_mut; // mutable so const methods can use a lock
 98
 99    static SourceList* s_instance;
100};
101
102#endif // SOURCELIST_H