/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. #ifndef SOURCELIST_H
  20. #define SOURCELIST_H
  21. #include <QObject>
  22. #include <QMutex>
  23. #include <QMap>
  24. #include "Typedefs.h"
  25. #include "Source.h"
  26. #include "DllMacro.h"
  27. class DLLEXPORT SourceList : public QObject
  28. {
  29. Q_OBJECT
  30. public:
  31. static SourceList* instance();
  32. explicit SourceList( QObject* parent = 0 );
  33. bool isReady() const { return m_isReady; }
  34. const Tomahawk::source_ptr& getLocal() const;
  35. void setLocal( const Tomahawk::source_ptr& localSrc );
  36. void setWebSource( const Tomahawk::source_ptr& websrc );
  37. const Tomahawk::source_ptr webSource() const;
  38. void loadSources();
  39. void removeAllRemote();
  40. QList<Tomahawk::source_ptr> sources( bool onlyOnline = false ) const;
  41. unsigned int count() const;
  42. void addScriptCollection( const Tomahawk::collection_ptr& collection );
  43. void removeScriptCollection( const Tomahawk::collection_ptr& collection );
  44. QList<Tomahawk::collection_ptr> scriptCollections() const;
  45. Tomahawk::source_ptr get( const QString& username, const QString& friendlyName = QString(), bool autoCreate = false );
  46. Tomahawk::source_ptr get( int id ) const;
  47. public slots:
  48. // called by the playlist creation dbcmds
  49. void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
  50. void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
  51. signals:
  52. void ready();
  53. void sourceAdded( const Tomahawk::source_ptr& );
  54. void sourceRemoved( const Tomahawk::source_ptr& );
  55. void scriptCollectionAdded( const Tomahawk::collection_ptr& );
  56. void scriptCollectionRemoved( const Tomahawk::collection_ptr& );
  57. void sourceLatchedOn( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to );
  58. void sourceLatchedOff( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to );
  59. private slots:
  60. void setSources( const QList<Tomahawk::source_ptr>& sources );
  61. void sourceSynced();
  62. void latchedOn( const Tomahawk::source_ptr& );
  63. void latchedOff( const Tomahawk::source_ptr& );
  64. private:
  65. void add( const Tomahawk::source_ptr& source );
  66. QMap< QString, Tomahawk::source_ptr > m_sources;
  67. QMap< int, QString > m_sources_id2name;
  68. QList< Tomahawk::collection_ptr > m_scriptCollections;
  69. bool m_isReady;
  70. Tomahawk::source_ptr m_local;
  71. Tomahawk::source_ptr m_dummy;
  72. mutable QMutex m_mut; // mutable so const methods can use a lock
  73. static SourceList* s_instance;
  74. };
  75. #endif // SOURCELIST_H