File indexing completed on 2025-01-05 04:26:11
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_METAPROXY_H 0018 #define AMAROK_METAPROXY_H 0019 0020 #include "amarok_export.h" 0021 #include "core/capabilities/Capability.h" 0022 #include "core/meta/Meta.h" 0023 #include "core/meta/TrackEditor.h" 0024 #include "core-impl/meta/proxy/MetaProxyWorker.h" 0025 0026 #include <QObject> 0027 0028 namespace Collections 0029 { 0030 class TrackProvider; 0031 } 0032 0033 namespace MetaProxy 0034 { 0035 class Track; 0036 typedef AmarokSharedPointer<Track> TrackPtr; 0037 class AMAROK_EXPORT Track : public Meta::Track, public Meta::TrackEditor 0038 { 0039 public: 0040 class Private; 0041 0042 enum LookupType { 0043 AutomaticLookup, 0044 ManualLookup 0045 }; 0046 0047 /** 0048 * Construct a lazy-loading proxying track. You must assign this track to a 0049 * AmarokSharedPointer right after constructing it. 0050 * 0051 * If @p lookupType is AutomaticLookup (the default), an asynchronous 0052 * job employing CollectionManager to lookup the track in TrackProviders is 0053 * enqueued and started right from this constructor. 0054 * 0055 * If @p lookupType is ManualLookup, lookup is not done automatically 0056 * and you are responsible to call lookupTrack() once it is feasible. This way 0057 * you can also optionally define which TrackProvider will be used. 0058 * 0059 * @param url th URL 0060 * @param lookupType lookup type 0061 */ 0062 explicit Track( const QUrl &url, LookupType lookupType = AutomaticLookup ); 0063 ~Track() override; 0064 0065 /** 0066 * Tell MetaProxy::Track to start looking up the real track. Only valid if 0067 * this Track is constructed with lookupType = ManualLookup. This method 0068 * returns quickly and the lookup happens asynchronously in a thread (in 0069 * other words, @p provider, id supplied, must be thread-safe). 0070 * 0071 * If @p provider is null (the default), lookup happens in all 0072 * registered providers by employing CollectionManager. Otherwise lookup 0073 * only checks @param provider (still asynchronously). 0074 */ 0075 void lookupTrack( Collections::TrackProvider *provider = nullptr ); 0076 0077 // methods inherited from Meta::MetaCapability 0078 bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override; 0079 Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override; 0080 0081 // methods inherited from Meta::Base 0082 QString name() const override; 0083 QString prettyName() const override; 0084 QString sortableName() const override; 0085 0086 // methods inherited from Meta::Track 0087 QUrl playableUrl() const override; 0088 QString prettyUrl() const override; 0089 QString uidUrl() const override; 0090 QString notPlayableReason() const override; 0091 0092 Meta::AlbumPtr album() const override; 0093 Meta::ArtistPtr artist() const override; 0094 Meta::GenrePtr genre() const override; 0095 Meta::ComposerPtr composer() const override; 0096 Meta::YearPtr year() const override; 0097 0098 Meta::LabelList labels() const override; 0099 qreal bpm() const override; 0100 QString comment() const override; 0101 qint64 length() const override; 0102 int filesize() const override; 0103 int sampleRate() const override; 0104 int bitrate() const override; 0105 QDateTime createDate() const override; 0106 QDateTime modifyDate() const override; 0107 int trackNumber() const override; 0108 int discNumber() const override; 0109 qreal replayGain( Meta::ReplayGainTag mode ) const override; 0110 0111 QString type() const override; 0112 0113 void prepareToPlay() override; 0114 void finishedPlaying( double playedFraction ) override; 0115 0116 bool inCollection() const override; 0117 Collections::Collection *collection() const override; 0118 0119 QString cachedLyrics() const override; 0120 void setCachedLyrics( const QString &lyrics ) override; 0121 0122 void addLabel( const QString &label ) override; 0123 void addLabel( const Meta::LabelPtr &label ) override; 0124 void removeLabel( const Meta::LabelPtr &label ) override; 0125 0126 Meta::TrackEditorPtr editor() override; 0127 Meta::StatisticsPtr statistics() override; 0128 0129 bool operator==( const Meta::Track &track ) const override; 0130 0131 // Meta::TrackEditor methods: 0132 void setAlbum( const QString &album ) override; 0133 void setAlbumArtist( const QString &artist ) override; 0134 void setArtist( const QString &artist ) override; 0135 void setComposer( const QString &composer ) override; 0136 void setGenre( const QString &genre ) override; 0137 void setYear( int year ) override; 0138 void setComment( const QString &comment ) override; 0139 void setTitle( const QString &name ) override; 0140 void setTrackNumber( int number ) override; 0141 void setDiscNumber( int discNumber ) override; 0142 void setBpm( const qreal bpm ) override; 0143 0144 void beginUpdate() override; 0145 void endUpdate() override; 0146 0147 // custom MetaProxy methods 0148 /** 0149 * Return true if underlying track has already been found, false otherwise. 0150 */ 0151 bool isResolved() const; 0152 void setLength( qint64 length ); 0153 0154 /** 0155 * MetaProxy will update the proxy with the track. 0156 */ 0157 void updateTrack( const Meta::TrackPtr &track ); 0158 0159 private: 0160 Q_DISABLE_COPY( Track ) 0161 0162 Private *const d; // constant pointer to non-constant object 0163 }; 0164 0165 } 0166 0167 #endif