PageRenderTime 201ms CodeModel.GetById 91ms app.highlight 13ms RepoModel.GetById 56ms app.codeStats 1ms

/src/libtomahawk/Query.h

http://github.com/tomahawk-player/tomahawk
C Header | 170 lines | 88 code | 43 blank | 39 comment | 0 complexity | be1dc0ad259b0676ba6243b9ef0b38e6 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2015, 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#pragma once
 22#ifndef TOMAHAWK_QUERY_H
 23#define TOMAHAWK_QUERY_H
 24
 25#include <QObject>
 26#include <QList>
 27#include <QVariant>
 28
 29#include "DllMacro.h"
 30#include "Typedefs.h"
 31
 32
 33namespace Tomahawk
 34{
 35
 36class DatabaseCommand_LoadPlaylistEntries;
 37class Resolver;
 38class QueryPrivate;
 39
 40class DLLEXPORT Query : public QObject
 41{
 42Q_OBJECT
 43
 44friend class DatabaseCommand_LoadPlaylistEntries;
 45friend class Pipeline;
 46
 47public:
 48    static query_ptr get( const QString& artist, const QString& title, const QString& album, const QID& qid = QString(), bool autoResolve = true );
 49    static query_ptr get( const Tomahawk::track_ptr& track, const QID& qid = QString() );
 50    static query_ptr get( const QString& query, const QID& qid );
 51
 52    /**
 53     * Get a Query object with a fixed Result reference which is not re-resolved.
 54     */
 55    static query_ptr getFixed( const Tomahawk::track_ptr& track, const Tomahawk::result_ptr& result );
 56
 57    virtual ~Query();
 58
 59    bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false, bool ignoreAlbum = false ) const;
 60    float howSimilar( const Tomahawk::result_ptr& r );
 61
 62    QVariant toVariant() const;
 63    QString toString() const;
 64
 65    QID id() const;
 66
 67    track_ptr queryTrack() const;
 68    track_ptr track() const;
 69
 70    /// returns list of all results so far
 71    QList< result_ptr > results() const;
 72
 73    /// how many results found so far?
 74    unsigned int numResults( bool onlyPlayableResults = false ) const;
 75
 76    bool resolvingFinished() const;
 77    /// true when a perfect result has been found (score of 1.0)
 78    bool solved() const;
 79    /// true when any result has been found (score may be less than 1.0)
 80    bool playable() const;
 81
 82    float score() const;
 83
 84    Tomahawk::Resolver* currentResolver() const;
 85    QList< QPointer< Tomahawk::Resolver > > resolvedBy() const;
 86
 87    QString fullTextQuery() const;
 88    bool isFullTextQuery() const;
 89
 90    void setResolveFinished( bool resolved );
 91
 92    /**
 93     * Allow contacting the Pipeline if the state of this Query changes to
 94     * not solved.
 95     */
 96    void allowReresolve();
 97
 98    /**
 99     * Disallow contacting the Pipeline if the state of this Query changes to
100     * not solved.
101     */
102    void disallowReresolve();
103
104    void setSaveHTTPResultHint( bool saveResultHint );
105    bool saveHTTPResultHint() const;
106
107    QString resultHint() const;
108    void setResultHint( const QString& resultHint );
109
110    QWeakPointer< Tomahawk::Query > weakRef();
111    void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef );
112
113    /// sorter for list of results
114    bool resultSorter( const result_ptr& left, const result_ptr& right );
115    result_ptr preferredResult() const;
116    void setPreferredResult( const result_ptr& result );
117
118signals:
119    void resultsAdded( const QList<Tomahawk::result_ptr>& );
120    void resultsRemoved( const Tomahawk::result_ptr& );
121
122    void albumsAdded( const QList<Tomahawk::album_ptr>& );
123    void artistsAdded( const QList<Tomahawk::artist_ptr>& );
124
125    void resultsChanged();
126    void solvedStateChanged( bool state );
127    void playableStateChanged( bool state );
128    void resolvingFinished( bool hasResults );
129
130public slots:
131    /// (indirectly) called by resolver plugins when results are found
132    void addResults( const QList< Tomahawk::result_ptr >& );
133    void removeResult( const Tomahawk::result_ptr& );
134
135    void addAlbums( const QList< Tomahawk::album_ptr >& );
136    void addArtists( const QList< Tomahawk::artist_ptr >& );
137
138    void onResolvingFinished();
139    void onResolverAdded();
140
141protected:
142    QScopedPointer<QueryPrivate> d_ptr;
143
144private slots:
145    void onResultStatusChanged();
146    void refreshResults();
147
148private:
149    explicit Query( const track_ptr& track, const QID& qid, bool autoResolve );
150    /**
151     * Respective constructor for getFixed
152     */
153    explicit Query( const track_ptr& track, const result_ptr& result );
154    explicit Query( const QString& query, const QID& qid );
155
156    Q_DECLARE_PRIVATE( Query )
157
158    void init();
159
160    void setCurrentResolver( Tomahawk::Resolver* resolver );
161    void clearResults();
162    void checkResults();
163    void sortResults();
164};
165
166} //ns
167
168Q_DECLARE_METATYPE( Tomahawk::query_ptr )
169
170#endif // TOMAHAWK_QUERY_H