PageRenderTime 173ms CodeModel.GetById 81ms app.highlight 12ms RepoModel.GetById 48ms app.codeStats 0ms

/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
 21#ifndef SOURCE_H
 22#define SOURCE_H
 23
 24#include <QObject>
 25#include <QSharedPointer>
 26#include <QVariantMap>
 27
 28#include "accounts/AccountManager.h"
 29#include "collection/Collection.h"
 30#include "network/DBSyncConnectionState.h"
 31#include "utils/TomahawkUtils.h"
 32#include "DllMacro.h"
 33#include "Typedefs.h"
 34
 35class ControlConnection;
 36class DBSyncConnection;
 37class MusicScanner;
 38
 39namespace Tomahawk
 40{
 41class DatabaseCommand;
 42class DatabaseCommand_AddFiles;
 43class DatabaseCommand_DeleteFiles;
 44class DatabaseCommand_LoadAllSources;
 45class DatabaseCommand_LogPlayback;
 46class DatabaseCommand_SocialAction;
 47class DatabaseCommand_UpdateSearchIndex;
 48
 49struct PlaybackLog;
 50class Resolver;
 51class SourcePrivate;
 52
 53class DLLEXPORT Source : public QObject
 54{
 55Q_OBJECT
 56
 57friend class ::DBSyncConnection;
 58friend class ::ControlConnection;
 59friend class DatabaseCommand_AddFiles;
 60friend class DatabaseCommand_DeleteFiles;
 61friend class DatabaseCommand_LoadAllSources;
 62friend class DatabaseCommand_LogPlayback;
 63friend class DatabaseCommand_SocialAction;
 64friend class ::MusicScanner;
 65
 66public:
 67    explicit Source( int id, const QString& nodeId = QString() );
 68    virtual ~Source();
 69
 70    bool isLocal() const;
 71    bool isOnline() const;
 72
 73    QString nodeId() const;
 74
 75    QString friendlyName() const;
 76    void setFriendlyName( const QString& fname );
 77
 78    // fallback when the normal friendlyname from cache is not available
 79    // this is usually the jabber id or whatever was used when first connected
 80    QString dbFriendlyName() const;
 81    void setDbFriendlyName( const QString& dbFriendlyName );
 82
 83    QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize(), bool defaultAvatarFallback = false );
 84
 85    collection_ptr dbCollection() const;
 86    QList< Tomahawk::collection_ptr > collections() const;
 87    void addCollection( const Tomahawk::collection_ptr& c );
 88    void removeCollection( const Tomahawk::collection_ptr& c );
 89
 90    int id() const;
 91    ControlConnection* controlConnection() const;
 92    bool setControlConnection( ControlConnection* cc );
 93
 94    const QSet< Tomahawk::peerinfo_ptr > peerInfos() const;
 95
 96    void scanningFinished( bool updateGUI );
 97
 98    unsigned int trackCount() const;
 99
100    Tomahawk::query_ptr currentTrack() const;
101    QString textStatus() const;
102    Tomahawk::DBSyncConnectionState state() const;
103
104    Tomahawk::playlistinterface_ptr playlistInterface();
105
106    QSharedPointer<QMutexLocker> acquireLock();
107
108signals:
109    void syncedWithDatabase();
110    void synced();
111
112    void online();
113    void offline();
114
115    void collectionAdded( const Tomahawk::collection_ptr& collection );
116    void collectionRemoved( const Tomahawk::collection_ptr& collection );
117
118    void stats( const QVariantMap& );
119
120    void playbackStarted( const Tomahawk::track_ptr& track );
121    void playbackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
122
123    void stateChanged();
124    void commandsFinished();
125
126    void socialAttributesChanged( const QString& action );
127
128    void latchedOn( const Tomahawk::source_ptr& to );
129    void latchedOff( const Tomahawk::source_ptr& from );
130
131public slots:
132    void setStats( const QVariantMap& m );
133    QString lastCmdGuid() const;
134
135private slots:
136    void setLastCmdGuid( const QString& guid );
137    void dbLoaded( unsigned int id, const QString& fname );
138    void updateIndexWhenSynced();
139
140    void handleDisconnect( Tomahawk::Accounts::Account*, Tomahawk::Accounts::AccountManager::DisconnectReason reason );
141    void setOffline();
142    void setOnline( bool force = false );
143
144    void onStateChanged( Tomahawk::DBSyncConnectionState newstate, Tomahawk::DBSyncConnectionState oldstate, const QString& info );
145
146    void onPlaybackStarted( const Tomahawk::track_ptr& track, unsigned int duration );
147    void onPlaybackFinished( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
148    void trackTimerFired();
149
150    void executeCommands();
151    void addCommand( const dbcmd_ptr& command );
152
153private:
154    Q_DECLARE_PRIVATE( Source )
155    SourcePrivate* d_ptr;
156
157    static bool friendlyNamesLessThan( const QString& first, const QString& second ); //lessThan for sorting
158    QString prettyName( const QString& name ) const;
159
160    void updateTracks();
161    void reportSocialAttributesChanged( DatabaseCommand_SocialAction* action );
162};
163
164} //ns
165
166#endif // SOURCE_H