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

« back to all changes in this revision

Viewing changes to src/libtomahawk/Query.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 QUERY_H
 
21
#define QUERY_H
 
22
 
 
23
#include <QObject>
 
24
#include <QMutex>
 
25
#include <QList>
 
26
#include <QVariant>
 
27
 
 
28
#include "Typedefs.h"
 
29
#include "Result.h"
 
30
#include "infosystem/InfoSystem.h"
 
31
 
 
32
#include "DllMacro.h"
 
33
 
 
34
class DatabaseCommand_LogPlayback;
 
35
class DatabaseCommand_PlaybackHistory;
 
36
class DatabaseCommand_LoadPlaylistEntries;
 
37
 
 
38
namespace Tomahawk
 
39
{
 
40
 
 
41
class Resolver;
 
42
 
 
43
struct SocialAction
 
44
{
 
45
    QVariant action;
 
46
    QVariant value;
 
47
    QVariant timestamp;
 
48
    Tomahawk::source_ptr source;
 
49
 
 
50
    // Make explicit so compiler won't auto-generate, since destructor of
 
51
    // source_ptr is not defined yet (only typedef included in header)
 
52
    SocialAction();
 
53
    ~SocialAction();
 
54
    SocialAction& operator=( const SocialAction& other );
 
55
    SocialAction( const SocialAction& other );
 
56
};
 
57
 
 
58
struct PlaybackLog
 
59
{
 
60
    Tomahawk::source_ptr source;
 
61
    unsigned int timestamp;
 
62
    unsigned int secsPlayed;
 
63
 
 
64
    // Make explicit so compiler won't auto-generate, since destructor of
 
65
    // source_ptr is not defined yet (only typedef included in header)
 
66
    PlaybackLog();
 
67
    ~PlaybackLog();
 
68
    PlaybackLog& operator=( const PlaybackLog& other );
 
69
    PlaybackLog( const PlaybackLog& other );
 
70
};
 
71
 
 
72
 
 
73
class DLLEXPORT Query : public QObject
 
74
{
 
75
Q_OBJECT
 
76
 
 
77
friend class ::DatabaseCommand_LogPlayback;
 
78
friend class ::DatabaseCommand_PlaybackHistory;
 
79
friend class ::DatabaseCommand_LoadPlaylistEntries;
 
80
friend class Pipeline;
 
81
 
 
82
public:
 
83
    enum DescriptionMode
 
84
    { Detailed = 0, Short = 1 };
 
85
 
 
86
    static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true );
 
87
    static query_ptr get( const QString& query, const QID& qid );
 
88
 
 
89
    virtual ~Query();
 
90
 
 
91
    /// returns list of all results so far
 
92
    QList< result_ptr > results() const;
 
93
 
 
94
    /// how many results found so far?
 
95
    unsigned int numResults() const;
 
96
 
 
97
    QID id() const;
 
98
 
 
99
    /// sorter for list of results
 
100
    static bool resultSorter( const result_ptr& left, const result_ptr& right );
 
101
 
 
102
    /// true when a perfect result has been found (score of 1.0)
 
103
    bool solved() const { return m_solved; }
 
104
    /// true when any result has been found (score may be less than 1.0)
 
105
    bool playable() const { return m_playable; }
 
106
 
 
107
    QString fullTextQuery() const { return m_fullTextQuery; }
 
108
    bool isFullTextQuery() const { return !m_fullTextQuery.isEmpty(); }
 
109
    bool resolvingFinished() const { return m_resolveFinished; }
 
110
    float howSimilar( const Tomahawk::result_ptr& r );
 
111
 
 
112
    QPair< Tomahawk::source_ptr, unsigned int > playedBy() const;
 
113
    Tomahawk::Resolver* currentResolver() const;
 
114
    QList< QWeakPointer< Tomahawk::Resolver > > resolvedBy() const { return m_resolvers; }
 
115
 
 
116
    void setArtist( const QString& artist ) { m_artist = artist; updateSortNames(); }
 
117
    void setComposer( const QString& composer ) { m_composer = composer; updateSortNames(); }
 
118
    void setAlbum( const QString& album ) { m_album = album; updateSortNames(); }
 
119
    void setTrack( const QString& track ) { m_track = track; updateSortNames(); }
 
120
    void setResultHint( const QString& resultHint ) { m_resultHint = resultHint; }
 
121
    void setDuration( int duration ) { m_duration = duration; }
 
122
    void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
 
123
    void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; }
 
124
 
 
125
    bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false ) const;
 
126
 
 
127
    QVariant toVariant() const;
 
128
    QString toString() const;
 
129
 
 
130
    QString resultHint() const { return m_resultHint; }
 
131
    QString artistSortname() const { return m_artistSortname; }
 
132
    QString composerSortname() const { return m_composerSortname; }
 
133
    QString albumSortname() const { return m_albumSortname; }
 
134
    QString trackSortname() const { return m_trackSortname; }
 
135
 
 
136
    QString artist() const { return m_artist; }
 
137
    QString composer() const { return m_composer; }
 
138
    QString album() const { return m_album; }
 
139
    QString track() const { return m_track; }
 
140
    int duration() const { return m_duration; }
 
141
    unsigned int albumpos() const { return m_albumpos; }
 
142
    unsigned int discnumber() const { return m_discnumber; }
 
143
 
 
144
    query_ptr displayQuery() const;
 
145
 
 
146
#ifndef ENABLE_HEADLESS
 
147
    QPixmap cover( const QSize& size, bool forceLoad = true ) const;
 
148
#endif
 
149
    bool coverLoaded() const;
 
150
 
 
151
    void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
 
152
    void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
 
153
 
 
154
    void setLoved( bool loved );
 
155
    bool loved();
 
156
 
 
157
    void loadStats();
 
158
    QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
 
159
    void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
 
160
    unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
 
161
 
 
162
    void loadSocialActions();
 
163
    QList< Tomahawk::SocialAction > allSocialActions() const;
 
164
    void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
 
165
    QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
 
166
 
 
167
    void setSaveHTTPResultHint( bool saveResultHint );
 
168
    bool saveHTTPResultHint() const { return m_saveResultHint; }
 
169
 
 
170
    QList<Tomahawk::query_ptr> similarTracks() const;
 
171
    QStringList lyrics() const;
 
172
 
 
173
    QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
 
174
    void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
 
175
 
 
176
signals:
 
177
    void resultsAdded( const QList<Tomahawk::result_ptr>& );
 
178
    void resultsRemoved( const Tomahawk::result_ptr& );
 
179
 
 
180
    void albumsAdded( const QList<Tomahawk::album_ptr>& );
 
181
    void artistsAdded( const QList<Tomahawk::artist_ptr>& );
 
182
 
 
183
    void resultsChanged();
 
184
    void solvedStateChanged( bool state );
 
185
    void playableStateChanged( bool state );
 
186
    void resolvingFinished( bool hasResults );
 
187
 
 
188
    void coverChanged();
 
189
 
 
190
    void socialActionsLoaded();
 
191
    void statsLoaded();
 
192
    void similarTracksLoaded();
 
193
    void lyricsLoaded();
 
194
 
 
195
    void updated();
 
196
 
 
197
public slots:
 
198
    /// (indirectly) called by resolver plugins when results are found
 
199
    void addResults( const QList< Tomahawk::result_ptr >& );
 
200
    void removeResult( const Tomahawk::result_ptr& );
 
201
 
 
202
    void addAlbums( const QList< Tomahawk::album_ptr >& );
 
203
    void addArtists( const QList< Tomahawk::artist_ptr >& );
 
204
 
 
205
    void onResolvingFinished();
 
206
    void onResolverAdded();
 
207
 
 
208
private slots:
 
209
    void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
 
210
    void infoSystemFinished( QString target );
 
211
 
 
212
    void onResultStatusChanged();
 
213
    void refreshResults();
 
214
 
 
215
private:
 
216
    Query();
 
217
    explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve );
 
218
    explicit Query( const QString& query, const QID& qid );
 
219
 
 
220
    void init();
 
221
 
 
222
    void setCurrentResolver( Tomahawk::Resolver* resolver );
 
223
    void clearResults();
 
224
    void checkResults();
 
225
 
 
226
    void updateSortNames();
 
227
 
 
228
    void parseSocialActions();
 
229
 
 
230
    QList< Tomahawk::artist_ptr > m_artists;
 
231
    QList< Tomahawk::album_ptr > m_albums;
 
232
    QList< Tomahawk::result_ptr > m_results;
 
233
    bool m_solved;
 
234
    bool m_playable;
 
235
    bool m_resolveFinished;
 
236
    mutable QID m_qid;
 
237
 
 
238
    QString m_artistSortname;
 
239
    QString m_composerSortname;
 
240
    QString m_albumSortname;
 
241
    QString m_trackSortname;
 
242
 
 
243
    QString m_artist;
 
244
    QString m_composer;
 
245
    QString m_album;
 
246
    QString m_track;
 
247
    QString m_fullTextQuery;
 
248
 
 
249
    int m_duration;
 
250
    unsigned int m_albumpos;
 
251
    unsigned int m_discnumber;
 
252
    QString m_resultHint;
 
253
 
 
254
    mutable Tomahawk::artist_ptr m_artistPtr;
 
255
    mutable Tomahawk::album_ptr m_albumPtr;
 
256
 
 
257
    QPair< Tomahawk::source_ptr, unsigned int > m_playedBy;
 
258
    QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
 
259
 
 
260
    bool m_saveResultHint;
 
261
 
 
262
    mutable QMutex m_mutex;
 
263
    QWeakPointer< Tomahawk::Query > m_ownRef;
 
264
 
 
265
    bool m_playbackHistoryLoaded;
 
266
    QList< PlaybackLog > m_playbackHistory;
 
267
 
 
268
    bool m_socialActionsLoaded;
 
269
    QHash< QString, QVariant > m_currentSocialActions;
 
270
    QList< SocialAction > m_allSocialActions;
 
271
 
 
272
    bool m_simTracksLoaded;
 
273
    QList<Tomahawk::query_ptr> m_similarTracks;
 
274
 
 
275
    bool m_lyricsLoaded;
 
276
    QStringList m_lyrics;
 
277
 
 
278
    mutable int m_infoJobs;
 
279
};
 
280
 
 
281
}; //ns
 
282
 
 
283
Q_DECLARE_METATYPE( Tomahawk::query_ptr );
 
284
 
 
285
#endif // QUERY_H