/src/libtomahawk/Source.h

http://github.com/tomahawk-player/tomahawk · C Header · 166 lines · 104 code · 41 blank · 21 comment · 0 complexity · 0d55c49a8f0731c999090f074c00b2c2 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 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef SOURCE_H
  21. #define SOURCE_H
  22. #include <QObject>
  23. #include <QSharedPointer>
  24. #include <QVariantMap>
  25. #include "accounts/AccountManager.h"
  26. #include "collection/Collection.h"
  27. #include "network/DBSyncConnectionState.h"
  28. #include "utils/TomahawkUtils.h"
  29. #include "DllMacro.h"
  30. #include "Typedefs.h"
  31. class ControlConnection;
  32. class DBSyncConnection;
  33. class MusicScanner;
  34. namespace Tomahawk
  35. {
  36. class DatabaseCommand;
  37. class DatabaseCommand_AddFiles;
  38. class DatabaseCommand_DeleteFiles;
  39. class DatabaseCommand_LoadAllSources;
  40. class DatabaseCommand_LogPlayback;
  41. class DatabaseCommand_SocialAction;
  42. class DatabaseCommand_UpdateSearchIndex;
  43. struct PlaybackLog;
  44. class Resolver;
  45. class SourcePrivate;
  46. class DLLEXPORT Source : public QObject
  47. {
  48. Q_OBJECT
  49. friend class ::DBSyncConnection;
  50. friend class ::ControlConnection;
  51. friend class DatabaseCommand_AddFiles;
  52. friend class DatabaseCommand_DeleteFiles;
  53. friend class DatabaseCommand_LoadAllSources;
  54. friend class DatabaseCommand_LogPlayback;
  55. friend class DatabaseCommand_SocialAction;
  56. friend class ::MusicScanner;
  57. public:
  58. explicit Source( int id, const QString& nodeId = QString() );
  59. virtual ~Source();
  60. bool isLocal() const;
  61. bool isOnline() const;
  62. QString nodeId() const;
  63. QString friendlyName() const;
  64. void setFriendlyName( const QString& fname );
  65. // fallback when the normal friendlyname from cache is not available
  66. // this is usually the jabber id or whatever was used when first connected
  67. QString dbFriendlyName() const;
  68. void setDbFriendlyName( const QString& dbFriendlyName );
  69. QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize(), bool defaultAvatarFallback = false );
  70. collection_ptr dbCollection() const;
  71. QList< Tomahawk::collection_ptr > collections() const;
  72. void addCollection( const Tomahawk::collection_ptr& c );
  73. void removeCollection( const Tomahawk::collection_ptr& c );
  74. int id() const;
  75. ControlConnection* controlConnection() const;
  76. bool setControlConnection( ControlConnection* cc );
  77. const QSet< Tomahawk::peerinfo_ptr > peerInfos() const;
  78. void scanningFinished( bool updateGUI );
  79. unsigned int trackCount() const;
  80. Tomahawk::query_ptr currentTrack() const;
  81. QString textStatus() const;
  82. Tomahawk::DBSyncConnectionState state() const;
  83. Tomahawk::playlistinterface_ptr playlistInterface();
  84. QSharedPointer<QMutexLocker> acquireLock();
  85. signals:
  86. void syncedWithDatabase();
  87. void synced();
  88. void online();
  89. void offline();
  90. void collectionAdded( const Tomahawk::collection_ptr& collection );
  91. void collectionRemoved( const Tomahawk::collection_ptr& collection );
  92. void stats( const QVariantMap& );
  93. void playbackStarted( const Tomahawk::track_ptr& track );
  94. void playbackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
  95. void stateChanged();
  96. void commandsFinished();
  97. void socialAttributesChanged( const QString& action );
  98. void latchedOn( const Tomahawk::source_ptr& to );
  99. void latchedOff( const Tomahawk::source_ptr& from );
  100. public slots:
  101. void setStats( const QVariantMap& m );
  102. QString lastCmdGuid() const;
  103. private slots:
  104. void setLastCmdGuid( const QString& guid );
  105. void dbLoaded( unsigned int id, const QString& fname );
  106. void updateIndexWhenSynced();
  107. void handleDisconnect( Tomahawk::Accounts::Account*, Tomahawk::Accounts::AccountManager::DisconnectReason reason );
  108. void setOffline();
  109. void setOnline( bool force = false );
  110. void onStateChanged( Tomahawk::DBSyncConnectionState newstate, Tomahawk::DBSyncConnectionState oldstate, const QString& info );
  111. void onPlaybackStarted( const Tomahawk::track_ptr& track, unsigned int duration );
  112. void onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
  113. void trackTimerFired();
  114. void executeCommands();
  115. void addCommand( const dbcmd_ptr& command );
  116. private:
  117. Q_DECLARE_PRIVATE( Source )
  118. SourcePrivate* d_ptr;
  119. static bool friendlyNamesLessThan( const QString& first, const QString& second ); //lessThan for sorting
  120. QString prettyName( const QString& name ) const;
  121. void updateTracks();
  122. void reportSocialAttributesChanged( DatabaseCommand_SocialAction* action );
  123. };
  124. } //ns
  125. #endif // SOURCE_H