PageRenderTime 299ms CodeModel.GetById 81ms app.highlight 11ms RepoModel.GetById 69ms app.codeStats 0ms

/src/libtomahawk/Result.h

http://github.com/tomahawk-player/tomahawk
C Header | 202 lines | 106 code | 45 blank | 51 comment | 0 complexity | 342dc4644ba2ff08b9d81736cfd99ef5 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-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *   Copyright 2015,      Dominik Schmidt <domme@tomahawk-player.org>
  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#ifndef RESULT_H
 22#define RESULT_H
 23
 24#include "DownloadJob.h"
 25#include "utils/TomahawkUtils.h"
 26#include "Typedefs.h"
 27
 28#include "DllMacro.h"
 29
 30#include <QObject>
 31#include <QPixmap>
 32#include <QPointer>
 33#include <QVariant>
 34#include <QMutex>
 35
 36class MetadataEditor;
 37
 38namespace Tomahawk
 39{
 40
 41class Resolver;
 42
 43class DLLEXPORT Result : public QObject
 44{
 45Q_OBJECT
 46
 47friend class ::MetadataEditor;
 48
 49public:
 50    /**
 51     * Get a Result instance for an URL if it is cached, otherwise create a new
 52     * instance using the supplied Track object.
 53     */
 54    static Tomahawk::result_ptr get( const QString& url,
 55                                     const Tomahawk::track_ptr& track );
 56
 57    /**
 58     * Get a Result instance for an URL if it is already cached.
 59     *
 60     * This will not create a new Result instance if there is no matching
 61     * Result in the cache, use Result::get for this.
 62     *
 63     * @param url Unique result identifier
 64     * @return nullptr if the Result is not yet cached
 65     */
 66    static Tomahawk::result_ptr getCached( const QString& url );
 67
 68    virtual ~Result();
 69
 70    QWeakPointer< Tomahawk::Result > weakRef();
 71    void setWeakRef( QWeakPointer< Tomahawk::Result > weakRef );
 72
 73    QVariant toVariant() const;
 74    QString toString() const;
 75    Tomahawk::query_ptr toQuery();
 76
 77    /**
 78     * Associate the used collection for this result.
 79     *
 80     * @param emitOnlineEvents disableing this will not emit statusChanged anymore thus the query will not update (use with care!, only when this is the sole result)
 81     */
 82    void setResolvedByCollection( const Tomahawk::collection_ptr& collection, bool emitOnlineEvents = true );
 83    collection_ptr resolvedByCollection() const;
 84
 85    QPointer< Tomahawk::Resolver > resolvedByResolver() const;
 86    void setResolvedByResolver( Tomahawk::Resolver* resolver );
 87
 88    /**
 89     *  TODO: Make this a smart pointer
 90     */
 91    Resolver* resolvedBy() const;
 92
 93    RID id() const;
 94    bool isOnline() const;
 95    bool playable() const;
 96
 97    /**
 98     * @brief whether this result isLocal, i.e. resolved by a local collection
 99     * @return isLocal
100     */
101    bool isLocal() const;
102
103    QString url() const;
104    /**
105     * Has the given url been checked that it is accessible/valid.
106     *
107     * Results marked as true will bypass the ResultUrlChecker.
108     */
109    bool checked() const;
110    QString mimetype() const;
111    QString friendlySource() const;
112    bool isPreview() const;
113    QString purchaseUrl() const;
114    QString linkUrl() const;
115
116    QPixmap sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize = QSize() ) const;
117
118    unsigned int bitrate() const;
119    unsigned int size() const;
120    unsigned int modificationTime() const;
121
122    void setFileId( unsigned int id );
123    void setRID( RID id ) { m_rid = id; }
124
125    void setFriendlySource( const QString& s );
126    void setPreview( bool isPreview );
127    void setPurchaseUrl( const QString& u );
128    void setLinkUrl( const QString& u );
129    void setChecked( bool checked );
130    void setMimetype( const QString& mimetype );
131    void setBitrate( unsigned int bitrate );
132    void setSize( unsigned int size );
133    void setModificationTime( unsigned int modtime );
134
135    void setTrack( const track_ptr& track );
136
137    unsigned int fileId() const;
138
139    track_ptr track() const;
140
141    QList< DownloadFormat > downloadFormats() const;
142    void setDownloadFormats( const QList<DownloadFormat>& formats );
143
144    downloadjob_ptr downloadJob() const { return m_downloadJob; }
145    downloadjob_ptr toDownloadJob( const DownloadFormat& format );
146
147public slots:
148    void deleteLater();
149
150signals:
151    // emitted when the collection this result comes from is going offline/online:
152    void statusChanged();
153    void updated();
154
155private slots:
156    void onOffline();
157    void onOnline();
158
159    void onResolverRemoved( Tomahawk::Resolver* resolver );
160    void doneEditing();
161
162    void onDownloadJobStateChanged( DownloadJob::TrackState newState, DownloadJob::TrackState oldState );
163
164    void onSettingsChanged();
165
166private:
167    // private constructor
168    explicit Result( const QString& url, const Tomahawk::track_ptr& track );
169    explicit Result();
170
171    mutable QMutex m_mutex;
172
173    mutable RID m_rid;
174    collection_wptr m_collection;
175    QPointer< Tomahawk::Resolver > m_resolver;
176
177    QString m_url;
178    bool m_isPreview;
179    QString m_purchaseUrl;
180    QString m_linkUrl;
181    QString m_mimetype;
182    QString m_friendlySource;
183
184    QList<DownloadFormat> m_formats;
185    downloadjob_ptr m_downloadJob;
186
187    bool m_checked;
188    unsigned int m_bitrate;
189    unsigned int m_size;
190    unsigned int m_modtime;
191    unsigned int m_fileId;
192
193    track_ptr m_track;
194    query_wptr m_query;
195    QWeakPointer< Tomahawk::Result > m_ownRef;
196};
197
198} //ns
199
200Q_DECLARE_METATYPE( Tomahawk::result_ptr )
201
202#endif // RESULT_H