1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
4
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
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.
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.
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/>.
23
#include <QtCore/QObject>
24
#include <QtCore/QSharedPointer>
25
#include <QtCore/QVariantMap>
28
#include "network/DbSyncConnection.h"
29
#include "Collection.h"
31
#include "utils/TomahawkUtils.h"
35
class ControlConnection;
36
class DatabaseCommand_LogPlayback;
37
class DatabaseCommand_SocialAction;
38
class DatabaseCommand_UpdateSearchIndex;
39
class DatabaseCommand_DeleteFiles;
45
class DLLEXPORT Source : public QObject
49
friend class ::DBSyncConnection;
50
friend class ::ControlConnection;
51
friend class ::DatabaseCommand_LogPlayback;
52
friend class ::DatabaseCommand_SocialAction;
53
friend class ::DatabaseCommand_AddFiles;
54
friend class ::DatabaseCommand_DeleteFiles;
55
friend class ::MusicScanner;
58
explicit Source( int id, const QString& username = QString() );
61
bool isLocal() const { return m_isLocal; }
62
bool isOnline() const { return m_online || m_isLocal; }
64
QString userName() const { return m_username; }
65
QString friendlyName() const;
66
void setFriendlyName( const QString& fname );
68
#ifndef ENABLE_HEADLESS
69
void setAvatar( const QPixmap& avatar );
70
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
73
collection_ptr collection() const;
74
void addCollection( const Tomahawk::collection_ptr& c );
75
void removeCollection( const Tomahawk::collection_ptr& c );
77
int id() const { return m_id; }
78
ControlConnection* controlConnection() const { return m_cc; }
79
void setControlConnection( ControlConnection* cc );
81
void scanningProgress( unsigned int files );
82
void scanningFinished( bool updateGUI );
84
unsigned int trackCount() const;
86
Tomahawk::query_ptr currentTrack() const { return m_currentTrack; }
87
QString textStatus() const;
88
DBSyncConnection::State state() const { return m_state; }
90
Tomahawk::playlistinterface_ptr playlistInterface();
93
void syncedWithDatabase();
99
void collectionAdded( const collection_ptr& collection );
100
void collectionRemoved( const collection_ptr& collection );
102
void stats( const QVariantMap& );
103
void usernameChanged( const QString& );
105
void playbackStarted( const Tomahawk::query_ptr& query );
106
void playbackFinished( const Tomahawk::query_ptr& query );
109
void commandsFinished();
111
void socialAttributesChanged( const QString& action );
113
void latchedOn( const Tomahawk::source_ptr& to );
114
void latchedOff( const Tomahawk::source_ptr& from );
117
void setStats( const QVariantMap& m );
120
void dbLoaded( unsigned int id, const QString& fname );
121
QString lastCmdGuid() const;
122
void updateIndexWhenSynced();
127
void onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info );
129
void onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration );
130
void onPlaybackFinished( const Tomahawk::query_ptr& query );
131
void trackTimerFired();
133
void executeCommands();
134
void addCommand( const QSharedPointer<DatabaseCommand>& command );
138
void reportSocialAttributesChanged( DatabaseCommand_SocialAction* action );
140
QList< QSharedPointer<Collection> > m_collections;
146
QString m_friendlyname;
148
bool m_scrubFriendlyName;
149
bool m_updateIndexWhenSynced;
150
bool m_avatarUpdated;
152
Tomahawk::query_ptr m_currentTrack;
153
QString m_textStatus;
154
DBSyncConnection::State m_state;
155
QTimer m_currentTrackTimer;
157
ControlConnection* m_cc;
158
QList< QSharedPointer<DatabaseCommand> > m_cmds;
160
QString m_lastCmdGuid;
161
mutable QMutex m_cmdMutex;
163
mutable QPixmap* m_avatar;
164
mutable QPixmap* m_fancyAvatar;
165
mutable QByteArray m_avatarHash;
166
mutable QHash< TomahawkUtils::ImageMode, QHash< int, QPixmap > > m_coverCache;
168
Tomahawk::playlistinterface_ptr m_playlistInterface;