File indexing completed on 2025-01-19 04:24:38

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_META_FILE_H
0018 #define AMAROK_META_FILE_H
0019 
0020 #include "amarok_export.h"
0021 #include "core/meta/Meta.h"
0022 #include "core/meta/Statistics.h"
0023 #include "core/meta/TrackEditor.h"
0024 
0025 namespace MetaFile
0026 {
0027     class Track;
0028 
0029     typedef AmarokSharedPointer<Track> TrackPtr;
0030 
0031     class AMAROK_EXPORT Track : public Meta::Track, public Meta::Statistics, Meta::TrackEditor
0032     {
0033         public:
0034             explicit Track( const QUrl &url );
0035             ~Track() override;
0036 
0037         //methods inherited from Meta::Base
0038             QString name() const override;
0039 
0040         //methods inherited from Meta::Track
0041             QUrl playableUrl() const override;
0042             QString prettyUrl() const override;
0043             QString uidUrl() const override;
0044             QString notPlayableReason() const override;
0045 
0046             Meta::AlbumPtr album() const override;
0047             Meta::ArtistPtr artist() const override;
0048             Meta::GenrePtr genre() const override;
0049             Meta::ComposerPtr composer() const override;
0050             Meta::YearPtr year() const override;
0051 
0052             qreal bpm() const override;
0053             QString comment() const override;
0054 
0055             int trackNumber() const override;
0056             int discNumber() const override;
0057 
0058             qint64 length() const override;
0059             int filesize() const override;
0060             int sampleRate() const override;
0061             int bitrate() const override;
0062             QDateTime createDate() const override;
0063 
0064             qreal replayGain( Meta::ReplayGainTag mode ) const override;
0065 
0066             QString type() const override;
0067 
0068             bool inCollection() const override;
0069             Collections::Collection *collection() const override;
0070 
0071             bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override;
0072             Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override;
0073 
0074             Meta::TrackEditorPtr editor() override;
0075             Meta::StatisticsPtr statistics() override;
0076 
0077         // Meta::TrackEditor methods:
0078             void setAlbum( const QString &newAlbum ) override;
0079             void setAlbumArtist( const QString &newAlbumArtist ) override;
0080             void setArtist( const QString &newArtist ) override;
0081             void setComposer( const QString &newComposer ) override;
0082             void setGenre( const QString &newGenre ) override;
0083             void setYear( int newYear ) override;
0084             void setTitle( const QString &newTitle ) override;
0085             void setComment( const QString &newComment ) override;
0086             void setTrackNumber( int newTrackNumber ) override;
0087             void setDiscNumber( int newDiscNumber ) override;
0088             void setBpm( const qreal newBpm ) override;
0089 
0090         // Meta::Statistics methods:
0091             double score() const override;
0092             void setScore( double newScore ) override;
0093 
0094             int rating() const override;
0095             void setRating( int newRating ) override;
0096 
0097             int playCount() const override;
0098             void setPlayCount( int newPlayCount ) override;
0099 
0100         // combined Meta::TrackEditor, Meta::Statistics methods:
0101             void beginUpdate() override;
0102             void endUpdate() override;
0103 
0104         // MetaFile::Track own methods:
0105             bool isEditable() const;
0106 
0107             /**
0108              * Return true if file at @param url is a track.
0109              *
0110              * This method does only basic checking of the mime type and is pretty
0111              * optimistic, so it may be possible that is the song is not playable with
0112              * current backend even if isTrack() returns true.
0113              */
0114             static bool isTrack( const QUrl &url );
0115 
0116             virtual QImage getEmbeddedCover() const;
0117             virtual void setCollection( Collections::Collection *newCollection );
0118 
0119             // publish method so that it can be called by Private.
0120             using Meta::Track::notifyObservers;
0121 
0122             class Private;
0123 
0124         private:
0125             Private * const d;
0126 
0127             /**
0128              * Must be called at end of every set*() method, with d->lock locked for
0129              * writing. Takes care of writing back the fields, re-reading them and
0130              * notifying observers.
0131              */
0132             void commitIfInNonBatchUpdate( qint64 field, const QVariant &value );
0133             void commitIfInNonBatchUpdate();
0134     };
0135 }
0136 
0137 #endif