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

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
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 TIMECODEMETA_H
0018 #define TIMECODEMETA_H
0019 
0020 #include "core/meta/Meta.h"
0021 #include "core/meta/TrackEditor.h"
0022 
0023 
0024 namespace Meta {
0025 
0026     class TimecodeTrack;
0027     class TimecodeAlbum;
0028     class TimecodeArtist;
0029     class TimecodeGenre;
0030     class TimecodeComposer;
0031     class TimecodeYear;
0032 
0033     typedef AmarokSharedPointer<TimecodeTrack> TimecodeTrackPtr;
0034     typedef AmarokSharedPointer<TimecodeArtist> TimecodeArtistPtr;
0035     typedef AmarokSharedPointer<TimecodeAlbum> TimecodeAlbumPtr;
0036     typedef AmarokSharedPointer<TimecodeGenre> TimecodeGenrePtr;
0037     typedef AmarokSharedPointer<TimecodeComposer> TimecodeComposerPtr;
0038     typedef AmarokSharedPointer<TimecodeYear> TimecodeYearPtr;
0039 
0040 
0041 class TimecodeTrack : public Track, public TrackEditor
0042 {
0043 public:
0044     TimecodeTrack( const QString &name, const QUrl &url, qint64 start, qint64 end );
0045     ~TimecodeTrack() override;
0046 
0047     QString name() const override;
0048 
0049     QUrl playableUrl() const override;
0050     QString uidUrl() const override;
0051     QString prettyUrl() const override;
0052     QString notPlayableReason() const override;
0053 
0054     AlbumPtr album() const override;
0055     ArtistPtr artist() const override;
0056     GenrePtr genre() const override;
0057     ComposerPtr composer() const override;
0058     YearPtr year() const override;
0059 
0060     qreal bpm() const override;
0061     QString comment() const override;
0062     qint64 length() const override;
0063     int filesize() const override;
0064     int sampleRate() const override;
0065     int bitrate() const override;
0066     int trackNumber() const override;
0067     int discNumber() const override;
0068     QString type() const override;
0069 
0070     bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override;
0071     Capabilities::Capability *createCapabilityInterface( Capabilities::Capability::Type type ) override;
0072 
0073     TrackEditorPtr editor() override;
0074 
0075     // TrackEditor methods
0076     void setAlbum( const QString &newAlbum ) override;
0077     void setAlbumArtist( const QString &newAlbumArtist ) override;
0078     void setArtist( const QString &newArtist ) override;
0079     void setComposer( const QString &newComposer ) override;
0080     void setGenre( const QString &newGenre ) override;
0081     void setYear( int newYear ) override;
0082     void setTitle( const QString &newTitle ) override;
0083     void setComment( const QString &newComment ) override;
0084     void setTrackNumber( int newTrackNumber ) override;
0085     void setDiscNumber( int newDiscNumber ) override;
0086     void setBpm( const qreal newBpm ) override;
0087 
0088     void beginUpdate() override;
0089     void endUpdate() override;
0090 
0091     //TimecodeTrack specific methods
0092     void setAlbum( const TimecodeAlbumPtr &album );
0093     void setArtist( const TimecodeArtistPtr &artist );
0094     void setComposer( const TimecodeComposerPtr &composer );
0095     void setGenre( const TimecodeGenrePtr &genre );
0096     void setYear( const TimecodeYearPtr &year );
0097 
0098     qint64 start();
0099     qint64 end();
0100 
0101 
0102 private:
0103     //TimecodeCollection *m_collection;
0104 
0105     TimecodeArtistPtr m_artist;
0106     TimecodeAlbumPtr m_album;
0107     TimecodeGenrePtr m_genre;
0108     TimecodeComposerPtr m_composer;
0109     TimecodeYearPtr m_year;
0110 
0111     QString m_name;
0112     QString m_type;
0113     qint64 m_start;
0114     qint64 m_end;
0115     qint64 m_length;
0116     qreal m_bpm;
0117     int m_trackNumber;
0118     int m_discNumber;
0119     QString m_comment;
0120     QString m_displayUrl;
0121     QUrl m_playableUrl;
0122 
0123     int m_updatedFields;
0124     QMap<int, QString> m_fields;
0125 
0126     enum
0127     {
0128         ALBUM_UPDATED       = 1 << 0,
0129         ARTIST_UPDATED      = 1 << 1,
0130         COMPOSER_UPDATED    = 1 << 2,
0131         GENRE_UPDATED       = 1 << 3,
0132         YEAR_UPDATED        = 1 << 4,
0133         TITLE_UPDATED       = 1 << 5,
0134         COMMENT_UPDATED     = 1 << 6,
0135         TRACKNUMBER_UPDATED = 1 << 7,
0136         DISCNUMBER_UPDATED  = 1 << 8,
0137         BPM_UPDATED         = 1 << 9
0138     };
0139 };
0140 
0141 class TimecodeArtist : public Meta::Artist
0142 {
0143 public:
0144     explicit TimecodeArtist( const QString &name );
0145     ~TimecodeArtist() override;
0146 
0147     QString name() const override;
0148 
0149     TrackList tracks() override;
0150 
0151     virtual AlbumList albums();
0152 
0153     bool operator==( const Meta::Artist &other ) const override
0154     {
0155         return name() == other.name();
0156     }
0157 
0158     //TimecodeArtist specific methods
0159     void addTrack( const TimecodeTrackPtr &track );
0160 
0161 private:
0162     QString m_name;
0163     TrackList m_tracks;
0164 };
0165 
0166 class TimecodeAlbum : public QObject, public Meta::Album
0167 {
0168 Q_OBJECT
0169 public:
0170     explicit TimecodeAlbum( const QString &name );
0171     ~TimecodeAlbum() override;
0172 
0173     QString name() const override;
0174 
0175     bool isCompilation() const override;
0176     bool hasAlbumArtist() const override;
0177     ArtistPtr albumArtist() const override;
0178     TrackList tracks() override;
0179 
0180     QImage image( int size = 0 ) const override;
0181     bool canUpdateImage() const override;
0182     void setImage( const QImage &image ) override;
0183 
0184     bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override;
0185     Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override;
0186 
0187     //TimecodeAlbum specific methods
0188     void addTrack( const TimecodeTrackPtr &track );
0189     void setAlbumArtist( const TimecodeArtistPtr &artist );
0190 
0191     bool operator==( const Meta::Album &other ) const override
0192     {
0193         return name() == other.name();
0194     }
0195 
0196 private:
0197     QString m_name;
0198     TrackList m_tracks;
0199     bool m_isCompilation;
0200     TimecodeArtistPtr m_albumArtist;
0201 
0202     QImage m_cover;
0203 };
0204 
0205 class TimecodeGenre : public Meta::Genre
0206 {
0207 public:
0208     explicit TimecodeGenre( const QString &name );
0209     ~TimecodeGenre() override;
0210 
0211     QString name() const override;
0212 
0213     TrackList tracks() override;
0214 
0215     bool operator==( const Meta::Genre &other ) const override
0216     {
0217         return name() == other.name();
0218     }
0219 
0220     //TimecodeGenre specific methods
0221     void addTrack( const TimecodeTrackPtr &track );
0222 
0223 private:
0224     QString m_name;
0225     TrackList m_tracks;
0226 };
0227 
0228 class TimecodeComposer : public Meta::Composer
0229 {
0230 public:
0231     explicit TimecodeComposer( const QString &name );
0232     ~TimecodeComposer() override;
0233 
0234     QString name() const override;
0235 
0236     TrackList tracks() override;
0237 
0238     bool operator==( const Meta::Composer &other ) const override
0239     {
0240         return name() == other.name();
0241     }
0242 
0243     //TimecodeComposer specific methods
0244     void addTrack( const TimecodeTrackPtr &track );
0245 
0246 private:
0247     QString m_name;
0248     TrackList m_tracks;
0249 };
0250 
0251 class TimecodeYear : public Meta::Year
0252 {
0253 public:
0254     explicit TimecodeYear( const QString &name );
0255     ~TimecodeYear() override;
0256 
0257     QString name() const override;
0258 
0259     TrackList tracks() override;
0260 
0261     bool operator==( const Meta::Year &other ) const override
0262     {
0263         return name() == other.name();
0264     }
0265 
0266     //TimecodeYear specific methods
0267     void addTrack( const TimecodeTrackPtr &track );
0268 
0269 private:
0270     QString m_name;
0271     TrackList m_tracks;
0272 };
0273 
0274 }
0275 #endif