~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/Source.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *
 
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 SOURCE_H
 
21
#define SOURCE_H
 
22
 
 
23
#include <QtCore/QObject>
 
24
#include <QtCore/QSharedPointer>
 
25
#include <QtCore/QVariantMap>
 
26
 
 
27
#include "Typedefs.h"
 
28
#include "network/DbSyncConnection.h"
 
29
#include "Collection.h"
 
30
#include "Query.h"
 
31
#include "utils/TomahawkUtils.h"
 
32
 
 
33
#include "DllMacro.h"
 
34
 
 
35
class ControlConnection;
 
36
class DatabaseCommand_LogPlayback;
 
37
class DatabaseCommand_SocialAction;
 
38
class DatabaseCommand_UpdateSearchIndex;
 
39
class DatabaseCommand_DeleteFiles;
 
40
class MusicScanner;
 
41
 
 
42
namespace Tomahawk
 
43
{
 
44
 
 
45
class DLLEXPORT Source : public QObject
 
46
{
 
47
Q_OBJECT
 
48
 
 
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;
 
56
 
 
57
public:
 
58
    explicit Source( int id, const QString& username = QString() );
 
59
    virtual ~Source();
 
60
 
 
61
    bool isLocal() const { return m_isLocal; }
 
62
    bool isOnline() const { return m_online || m_isLocal; }
 
63
 
 
64
    QString userName() const { return m_username; }
 
65
    QString friendlyName() const;
 
66
    void setFriendlyName( const QString& fname );
 
67
 
 
68
#ifndef ENABLE_HEADLESS
 
69
    void setAvatar( const QPixmap& avatar );
 
70
    QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
 
71
#endif
 
72
 
 
73
    collection_ptr collection() const;
 
74
    void addCollection( const Tomahawk::collection_ptr& c );
 
75
    void removeCollection( const Tomahawk::collection_ptr& c );
 
76
 
 
77
    int id() const { return m_id; }
 
78
    ControlConnection* controlConnection() const { return m_cc; }
 
79
    void setControlConnection( ControlConnection* cc );
 
80
 
 
81
    void scanningProgress( unsigned int files );
 
82
    void scanningFinished( bool updateGUI );
 
83
 
 
84
    unsigned int trackCount() const;
 
85
 
 
86
    Tomahawk::query_ptr currentTrack() const { return m_currentTrack; }
 
87
    QString textStatus() const;
 
88
    DBSyncConnection::State state() const { return m_state; }
 
89
 
 
90
    Tomahawk::playlistinterface_ptr playlistInterface();
 
91
 
 
92
signals:
 
93
    void syncedWithDatabase();
 
94
    void synced();
 
95
 
 
96
    void online();
 
97
    void offline();
 
98
 
 
99
    void collectionAdded( const collection_ptr& collection );
 
100
    void collectionRemoved( const collection_ptr& collection );
 
101
 
 
102
    void stats( const QVariantMap& );
 
103
    void usernameChanged( const QString& );
 
104
 
 
105
    void playbackStarted( const Tomahawk::query_ptr& query );
 
106
    void playbackFinished( const Tomahawk::query_ptr& query );
 
107
 
 
108
    void stateChanged();
 
109
    void commandsFinished();
 
110
 
 
111
    void socialAttributesChanged( const QString& action );
 
112
 
 
113
    void latchedOn( const Tomahawk::source_ptr& to );
 
114
    void latchedOff( const Tomahawk::source_ptr& from );
 
115
 
 
116
public slots:
 
117
    void setStats( const QVariantMap& m );
 
118
 
 
119
private slots:
 
120
    void dbLoaded( unsigned int id, const QString& fname );
 
121
    QString lastCmdGuid() const;
 
122
    void updateIndexWhenSynced();
 
123
 
 
124
    void setOffline();
 
125
    void setOnline();
 
126
 
 
127
    void onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info );
 
128
 
 
129
    void onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration );
 
130
    void onPlaybackFinished( const Tomahawk::query_ptr& query );
 
131
    void trackTimerFired();
 
132
 
 
133
    void executeCommands();
 
134
    void addCommand( const QSharedPointer<DatabaseCommand>& command );
 
135
 
 
136
private:
 
137
    void updateTracks();
 
138
    void reportSocialAttributesChanged( DatabaseCommand_SocialAction* action );
 
139
 
 
140
    QList< QSharedPointer<Collection> > m_collections;
 
141
    QVariantMap m_stats;
 
142
 
 
143
    bool m_isLocal;
 
144
    bool m_online;
 
145
    QString m_username;
 
146
    QString m_friendlyname;
 
147
    int m_id;
 
148
    bool m_scrubFriendlyName;
 
149
    bool m_updateIndexWhenSynced;
 
150
    bool m_avatarUpdated;
 
151
 
 
152
    Tomahawk::query_ptr m_currentTrack;
 
153
    QString m_textStatus;
 
154
    DBSyncConnection::State m_state;
 
155
    QTimer m_currentTrackTimer;
 
156
 
 
157
    ControlConnection* m_cc;
 
158
    QList< QSharedPointer<DatabaseCommand> > m_cmds;
 
159
    int m_commandCount;
 
160
    QString m_lastCmdGuid;
 
161
    mutable QMutex m_cmdMutex;
 
162
 
 
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;
 
167
 
 
168
    Tomahawk::playlistinterface_ptr m_playlistInterface;
 
169
};
 
170
 
 
171
} //ns
 
172
 
 
173
#endif // SOURCE_H