2 Copyright (C) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "meta/EditCapability.h"
25 #include "MetaUtility.h"
31 #include <kfilemetainfo.h>
32 #include <kfilemetainfoitem.h>
34 using namespace MetaFile
;
36 class EditCapabilityImpl
: public Meta::EditCapability
40 EditCapabilityImpl( MetaFile::Track
*track
)
41 : Meta::EditCapability()
44 virtual bool isEditable() const { return m_track
->isEditable(); }
45 virtual void setAlbum( const QString
&newAlbum
) { m_track
->setAlbum( newAlbum
); }
46 virtual void setArtist( const QString
&newArtist
) { m_track
->setArtist( newArtist
); }
47 virtual void setComposer( const QString
&newComposer
) { m_track
->setComposer( newComposer
); }
48 virtual void setGenre( const QString
&newGenre
) { m_track
->setGenre( newGenre
); }
49 virtual void setYear( const QString
&newYear
) { m_track
->setYear( newYear
); }
50 virtual void setTitle( const QString
&newTitle
) { m_track
->setTitle( newTitle
); }
51 virtual void setComment( const QString
&newComment
) { m_track
->setComment( newComment
); }
52 virtual void setTrackNumber( int newTrackNumber
) { m_track
->setTrackNumber( newTrackNumber
); }
53 virtual void setDiscNumber( int newDiscNumber
) { m_track
->setDiscNumber( newDiscNumber
); }
54 virtual void beginMetaDataUpdate() { m_track
->beginMetaDataUpdate(); }
55 virtual void endMetaDataUpdate() { m_track
->endMetaDataUpdate(); }
56 virtual void abortMetaDataUpdate() { m_track
->abortMetaDataUpdate(); }
59 KSharedPtr
<MetaFile::Track
> m_track
;
62 Track::Track( const KUrl
&url
)
64 , d( new Track::Private( this ) )
67 d
->metaInfo
= KFileMetaInfo( url
.path() );
68 d
->album
= Meta::AlbumPtr( new MetaFile::FileAlbum( QPointer
<MetaFile::Track::Private
>( d
) ) );
69 d
->artist
= Meta::ArtistPtr( new MetaFile::FileArtist( QPointer
<MetaFile::Track::Private
>( d
) ) );
70 d
->genre
= Meta::GenrePtr( new MetaFile::FileGenre( QPointer
<MetaFile::Track::Private
>( d
) ) );
71 d
->composer
= Meta::ComposerPtr( new MetaFile::FileComposer( QPointer
<MetaFile::Track::Private
>( d
) ) );
72 d
->year
= Meta::YearPtr( new MetaFile::FileYear( QPointer
<MetaFile::Track::Private
>( d
) ) );
83 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::TITLE
) );
85 return item
.value().toString();
91 Track::prettyName() const
97 Track::fullPrettyName() const
103 Track::sortableName() const
110 Track::playableUrl() const
116 Track::prettyUrl() const
118 return d
->url
.path();
128 Track::isPlayable() const
130 //simple implementation, check internet connectivity or ping server?
135 Track::isEditable() const
137 //not this probably needs more work on *nix
138 return QFile::permissions( d
->url
.path() ) & QFile::WriteUser
;
148 Track::artist() const
160 Track::composer() const
172 Track::setAlbum( const QString
&newAlbum
)
174 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::ALBUM
) ).setValue( newAlbum
);
175 if( !d
->batchUpdate
)
177 d
->metaInfo
.applyChanges();
183 Track::setArtist( const QString
& newArtist
)
185 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::ARTIST
) ).setValue( newArtist
);
186 if( !d
->batchUpdate
)
188 d
->metaInfo
.applyChanges();
194 Track::setGenre( const QString
& newGenre
)
196 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::GENRE
) ).setValue( newGenre
);
197 if( !d
->batchUpdate
)
199 d
->metaInfo
.applyChanges();
205 Track::setComposer( const QString
& newComposer
)
207 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::COMPOSER
) ).setValue( newComposer
);
208 if( !d
->batchUpdate
)
210 d
->metaInfo
.applyChanges();
216 Track::setYear( const QString
& newYear
)
218 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::YEAR
) ).setValue( newYear
);
219 if( !d
->batchUpdate
)
221 d
->metaInfo
.applyChanges();
227 Track::setTitle( const QString
&newTitle
)
229 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::TITLE
) ).setValue( newTitle
);
230 if( !d
->batchUpdate
)
232 d
->metaInfo
.applyChanges();
238 Track::comment() const
240 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::COMMENT
) );
242 return item
.value().toString();
248 Track::setComment( const QString
& newComment
)
250 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::COMMENT
) ).setValue( newComment
);
251 if( !d
->batchUpdate
)
253 d
->metaInfo
.applyChanges();
265 Track::setScore( double newScore
)
271 Track::rating() const
277 Track::setRating( int newRating
)
279 Q_UNUSED( newRating
)
283 Track::trackNumber() const
285 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::TRACKNUMBER
) );
287 return item
.value().toInt();
293 Track::setTrackNumber( int newTrackNumber
)
295 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::TRACKNUMBER
) ).setValue( newTrackNumber
);
296 if( !d
->batchUpdate
)
298 d
->metaInfo
.applyChanges();
304 Track::discNumber() const
306 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::DISCNUMBER
) );
308 return item
.value().toInt();
314 Track::setDiscNumber( int newDiscNumber
)
316 d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::DISCNUMBER
) ).setValue( newDiscNumber
);
317 if( !d
->batchUpdate
)
319 d
->metaInfo
.applyChanges();
325 Track::length() const
327 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::LENGTH
) );
329 return item
.value().toInt();
335 Track::filesize() const
337 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::FILESIZE
) );
339 return item
.value().toInt();
345 Track::sampleRate() const
347 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::SAMPLERATE
) );
349 return item
.value().toInt();
355 Track::bitrate() const
357 KFileMetaInfoItem item
= d
->metaInfo
.item( Meta::Field::xesamPrettyToFullFieldName( Meta::Field::BITRATE
) );
359 return item
.value().toInt();
365 Track::lastPlayed() const
371 Track::playCount() const
383 Track::beginMetaDataUpdate()
385 d
->batchUpdate
= true;
389 Track::endMetaDataUpdate()
391 d
->metaInfo
.applyChanges();
392 d
->batchUpdate
= false;
399 Track::abortMetaDataUpdate()
401 //KFileMetaInfo does not have a method to reset the items
402 d
->metaInfo
= KFileMetaInfo( d
->url
.path() );
403 d
->batchUpdate
= false;
407 Track::finishedPlaying( double playedFraction
)
409 Q_UNUSED( playedFraction
);
414 Track::inCollection() const
420 Track::collection() const
426 Track::hasCapabilityInterface( Meta::Capability::Type type
) const
428 return type
== Meta::Capability::Editable
;
432 Track::asCapabilityInterface( Meta::Capability::Type type
)
436 case Meta::Capability::Editable
:
437 return new EditCapabilityImpl( this );