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/>.
30
#include "infosystem/InfoSystem.h"
34
class DatabaseCommand_LogPlayback;
35
class DatabaseCommand_PlaybackHistory;
36
class DatabaseCommand_LoadPlaylistEntries;
48
Tomahawk::source_ptr source;
50
// Make explicit so compiler won't auto-generate, since destructor of
51
// source_ptr is not defined yet (only typedef included in header)
54
SocialAction& operator=( const SocialAction& other );
55
SocialAction( const SocialAction& other );
60
Tomahawk::source_ptr source;
61
unsigned int timestamp;
62
unsigned int secsPlayed;
64
// Make explicit so compiler won't auto-generate, since destructor of
65
// source_ptr is not defined yet (only typedef included in header)
68
PlaybackLog& operator=( const PlaybackLog& other );
69
PlaybackLog( const PlaybackLog& other );
73
class DLLEXPORT Query : public QObject
77
friend class ::DatabaseCommand_LogPlayback;
78
friend class ::DatabaseCommand_PlaybackHistory;
79
friend class ::DatabaseCommand_LoadPlaylistEntries;
80
friend class Pipeline;
84
{ Detailed = 0, Short = 1 };
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 );
91
/// returns list of all results so far
92
QList< result_ptr > results() const;
94
/// how many results found so far?
95
unsigned int numResults() const;
99
/// sorter for list of results
100
static bool resultSorter( const result_ptr& left, const result_ptr& right );
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; }
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 );
112
QPair< Tomahawk::source_ptr, unsigned int > playedBy() const;
113
Tomahawk::Resolver* currentResolver() const;
114
QList< QWeakPointer< Tomahawk::Resolver > > resolvedBy() const { return m_resolvers; }
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; }
125
bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false ) const;
127
QVariant toVariant() const;
128
QString toString() const;
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; }
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; }
144
query_ptr displayQuery() const;
146
#ifndef ENABLE_HEADLESS
147
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
149
bool coverLoaded() const;
151
void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
152
void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
154
void setLoved( bool loved );
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() );
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;
167
void setSaveHTTPResultHint( bool saveResultHint );
168
bool saveHTTPResultHint() const { return m_saveResultHint; }
170
QList<Tomahawk::query_ptr> similarTracks() const;
171
QStringList lyrics() const;
173
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
174
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
177
void resultsAdded( const QList<Tomahawk::result_ptr>& );
178
void resultsRemoved( const Tomahawk::result_ptr& );
180
void albumsAdded( const QList<Tomahawk::album_ptr>& );
181
void artistsAdded( const QList<Tomahawk::artist_ptr>& );
183
void resultsChanged();
184
void solvedStateChanged( bool state );
185
void playableStateChanged( bool state );
186
void resolvingFinished( bool hasResults );
190
void socialActionsLoaded();
192
void similarTracksLoaded();
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& );
202
void addAlbums( const QList< Tomahawk::album_ptr >& );
203
void addArtists( const QList< Tomahawk::artist_ptr >& );
205
void onResolvingFinished();
206
void onResolverAdded();
209
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
210
void infoSystemFinished( QString target );
212
void onResultStatusChanged();
213
void refreshResults();
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 );
222
void setCurrentResolver( Tomahawk::Resolver* resolver );
226
void updateSortNames();
228
void parseSocialActions();
230
QList< Tomahawk::artist_ptr > m_artists;
231
QList< Tomahawk::album_ptr > m_albums;
232
QList< Tomahawk::result_ptr > m_results;
235
bool m_resolveFinished;
238
QString m_artistSortname;
239
QString m_composerSortname;
240
QString m_albumSortname;
241
QString m_trackSortname;
247
QString m_fullTextQuery;
250
unsigned int m_albumpos;
251
unsigned int m_discnumber;
252
QString m_resultHint;
254
mutable Tomahawk::artist_ptr m_artistPtr;
255
mutable Tomahawk::album_ptr m_albumPtr;
257
QPair< Tomahawk::source_ptr, unsigned int > m_playedBy;
258
QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
260
bool m_saveResultHint;
262
mutable QMutex m_mutex;
263
QWeakPointer< Tomahawk::Query > m_ownRef;
265
bool m_playbackHistoryLoaded;
266
QList< PlaybackLog > m_playbackHistory;
268
bool m_socialActionsLoaded;
269
QHash< QString, QVariant > m_currentSocialActions;
270
QList< SocialAction > m_allSocialActions;
272
bool m_simTracksLoaded;
273
QList<Tomahawk::query_ptr> m_similarTracks;
276
QStringList m_lyrics;
278
mutable int m_infoJobs;
283
Q_DECLARE_METATYPE( Tomahawk::query_ptr );