Warning, file /multimedia/amarok/src/services/ServiceMetaBase.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "ServiceMetaBase.h" 0019 0020 #include "core/meta/Statistics.h" 0021 #include "core/support/Amarok.h" 0022 #include "core/support/Debug.h" 0023 #include "core-impl/meta/default/DefaultMetaTypes.h" 0024 0025 using namespace Meta; 0026 0027 ServiceMetaFactory::ServiceMetaFactory(const QString &dbPrefix) 0028 : m_dbTablePrefix( dbPrefix ) 0029 { 0030 } 0031 0032 QString 0033 ServiceMetaFactory::tablePrefix() const 0034 { 0035 return m_dbTablePrefix; 0036 } 0037 0038 int 0039 ServiceMetaFactory::getTrackSqlRowCount() 0040 { 0041 return 7; 0042 } 0043 0044 QString 0045 ServiceMetaFactory::getTrackSqlRows() 0046 { 0047 //subclasses must not change the order of these items, but only append new ones 0048 return m_dbTablePrefix + "_tracks.id, " + 0049 m_dbTablePrefix + "_tracks.name, " + 0050 m_dbTablePrefix + "_tracks.track_number, " + 0051 m_dbTablePrefix + "_tracks.length, " + 0052 m_dbTablePrefix + "_tracks.preview_url, " + 0053 m_dbTablePrefix + "_tracks.album_id, " + 0054 m_dbTablePrefix + "_tracks.artist_id "; 0055 } 0056 0057 TrackPtr 0058 ServiceMetaFactory::createTrack(const QStringList & rows) 0059 { 0060 return TrackPtr( new ServiceTrack( rows ) ); 0061 } 0062 0063 int 0064 ServiceMetaFactory::getAlbumSqlRowCount() 0065 { 0066 return 4; 0067 } 0068 0069 QString 0070 ServiceMetaFactory::getAlbumSqlRows() 0071 { 0072 //subclasses must not change the order of these items, but only append new ones 0073 return m_dbTablePrefix + "_albums.id, " + 0074 m_dbTablePrefix + "_albums.name, " + 0075 m_dbTablePrefix + "_albums.description, " + 0076 m_dbTablePrefix + "_albums.artist_id "; 0077 } 0078 0079 AlbumPtr 0080 ServiceMetaFactory::createAlbum(const QStringList & rows) 0081 { 0082 return AlbumPtr( new ServiceAlbum( rows ) ); 0083 } 0084 0085 int 0086 ServiceMetaFactory::getArtistSqlRowCount() 0087 { 0088 return 3; 0089 } 0090 0091 QString 0092 ServiceMetaFactory::getArtistSqlRows() 0093 { 0094 //subclasses must not change the order of these items, but only append new ones 0095 return m_dbTablePrefix + "_artists.id, " + 0096 m_dbTablePrefix + "_artists.name, " + 0097 m_dbTablePrefix + "_artists.description "; 0098 } 0099 0100 ArtistPtr 0101 ServiceMetaFactory::createArtist(const QStringList & rows) 0102 { 0103 return ArtistPtr( new ServiceArtist ( rows ) ); 0104 } 0105 0106 int 0107 ServiceMetaFactory::getGenreSqlRowCount() 0108 { 0109 return 2; 0110 } 0111 0112 QString 0113 ServiceMetaFactory::getGenreSqlRows() 0114 { 0115 //subclasses must not change the order of these items, but only append new ones 0116 return m_dbTablePrefix + "_genre.id, " + 0117 m_dbTablePrefix + "_genre.name " ; 0118 } 0119 0120 GenrePtr 0121 ServiceMetaFactory::createGenre(const QStringList & rows) 0122 { 0123 return GenrePtr( new ServiceGenre ( rows ) ); 0124 } 0125 0126 ServiceTrack::ServiceTrack( const QString & name ) 0127 : Meta::Track() 0128 , ServiceDisplayInfoProvider() 0129 , ActionsProvider() 0130 , SourceInfoProvider() 0131 , BookmarkThisProvider() 0132 , m_genre( nullptr ) 0133 , m_composer( nullptr ) 0134 , m_year( nullptr ) 0135 , m_id( 0 ) 0136 , m_trackNumber( 0 ) 0137 , m_length( 0 ) 0138 , m_albumId( 0 ) 0139 , m_albumName( '0' ) 0140 , m_artistId( 0 ) 0141 , m_name( name ) 0142 { 0143 } 0144 0145 ServiceTrack::ServiceTrack( const QStringList & resultRow ) 0146 : Meta::Track() 0147 , ServiceDisplayInfoProvider() 0148 , ActionsProvider() 0149 , SourceInfoProvider() 0150 , BookmarkThisProvider() 0151 , m_genre( nullptr ) 0152 , m_composer( nullptr ) 0153 , m_year( nullptr ) 0154 { 0155 m_id = resultRow[0].toInt(); 0156 m_name = resultRow[1]; 0157 m_trackNumber = resultRow[2].toInt(); 0158 m_length = resultRow[3].toInt(); 0159 m_displayUrl = resultRow[4]; 0160 m_playableUrl = resultRow[4]; 0161 m_downloadableUrl = resultRow[4]; 0162 m_albumId = resultRow[5].toInt(); 0163 //m_albumName = resultRow[6]; 0164 m_artistId = resultRow[6].toInt(); 0165 //m_artistName = resultRow[8].toInt(); 0166 } 0167 0168 ServiceTrack::~ServiceTrack() 0169 { 0170 } 0171 0172 void 0173 ServiceTrack::setId(int id) 0174 { 0175 m_id = id; 0176 } 0177 0178 int 0179 ServiceTrack::id() const 0180 { 0181 return m_id; 0182 } 0183 0184 void 0185 ServiceTrack::setAlbumId(int albumId) 0186 { 0187 m_albumId = albumId; 0188 } 0189 0190 int 0191 ServiceTrack::albumId() const 0192 { 0193 return m_albumId; 0194 } 0195 0196 void 0197 ServiceTrack::setArtistId(int id) 0198 { 0199 m_artistId = id; 0200 } 0201 0202 int 0203 ServiceTrack::artistId() const 0204 { 0205 return m_artistId; 0206 } 0207 0208 QString 0209 ServiceTrack::name() const 0210 { 0211 return m_name; 0212 } 0213 0214 QUrl 0215 ServiceTrack::playableUrl() const 0216 { 0217 QUrl url( m_playableUrl ); 0218 return url; 0219 } 0220 0221 QUrl 0222 ServiceTrack::downloadableUrl() const 0223 { 0224 QUrl url( m_downloadableUrl ); 0225 return url; 0226 } 0227 0228 QString 0229 ServiceTrack::uidUrl() const 0230 { 0231 return m_playableUrl; 0232 } 0233 0234 QString 0235 ServiceTrack::prettyUrl() const 0236 { 0237 return m_displayUrl; 0238 } 0239 0240 QString 0241 ServiceTrack::notPlayableReason() const 0242 { 0243 if( !m_playableUrl.isEmpty() && playableUrl().isLocalFile() ) 0244 return localFileNotPlayableReason( m_playableUrl ); 0245 0246 if( !m_downloadableUrl.isEmpty() ) 0247 return networkNotPlayableReason(); 0248 0249 return i18n( "Neither playable nor downloadable url specified." ); 0250 } 0251 0252 void 0253 ServiceTrack::setUidUrl(const QString & url) 0254 { 0255 m_playableUrl = url; 0256 m_displayUrl = url; 0257 m_downloadableUrl = url; 0258 } 0259 0260 void 0261 ServiceTrack::setDownloadableUrl(const QString & url) 0262 { 0263 m_downloadableUrl = url; 0264 } 0265 0266 AlbumPtr 0267 ServiceTrack::album() const 0268 { 0269 if ( !m_album == 0 ) 0270 return AlbumPtr::staticCast( m_album ); 0271 else 0272 //FIXME: always return the same default object. this applies to the other methods too 0273 return Meta::AlbumPtr( new Meta::DefaultAlbum() ); 0274 } 0275 0276 ArtistPtr 0277 ServiceTrack::artist() const 0278 { 0279 if ( !m_artist == 0 ) 0280 return ArtistPtr::staticCast( m_artist ); 0281 else 0282 return Meta::ArtistPtr( new Meta::DefaultArtist() ); 0283 } 0284 0285 GenrePtr 0286 ServiceTrack::genre() const 0287 { 0288 if ( !m_genre == 0 ) 0289 return GenrePtr::staticCast( m_genre ); 0290 else 0291 return Meta::GenrePtr( new DefaultGenre() ); 0292 } 0293 0294 ComposerPtr 0295 ServiceTrack::composer() const 0296 { 0297 if ( !m_composer == 0 ) 0298 return ComposerPtr::staticCast( m_composer ); 0299 else 0300 return Meta::ComposerPtr( new DefaultComposer() ); 0301 } 0302 0303 YearPtr 0304 ServiceTrack::year() const 0305 { 0306 if( m_year ) 0307 return YearPtr::staticCast( m_year ); 0308 else 0309 return Meta::YearPtr( new DefaultYear() ); 0310 } 0311 0312 void 0313 ServiceTrack::setAlbum( const QString &newAlbum ) 0314 { 0315 Q_UNUSED( newAlbum ) 0316 } 0317 0318 void 0319 ServiceTrack::setArtist( const QString &newArtist ) 0320 { 0321 Q_UNUSED( newArtist ) 0322 } 0323 0324 void 0325 ServiceTrack::setComposer( const QString &newComposer ) 0326 { 0327 Q_UNUSED( newComposer ) 0328 } 0329 0330 void 0331 ServiceTrack::setGenre( const QString &newGenre ) 0332 { 0333 Q_UNUSED( newGenre ) 0334 } 0335 0336 void 0337 ServiceTrack::setYear( int newYear ) 0338 { 0339 Q_UNUSED( newYear ) 0340 } 0341 0342 /* At time of writing, the services (Jamendo & Magnatune.com) I've seen can't handle BPM yet. */ 0343 qreal 0344 ServiceTrack::bpm() const 0345 { 0346 return -1.0; 0347 } 0348 0349 QString 0350 ServiceTrack::comment() const 0351 { 0352 return QString(); 0353 } 0354 0355 void 0356 ServiceTrack::setComment( const QString &newComment ) 0357 { 0358 Q_UNUSED( newComment ) 0359 } 0360 0361 QString 0362 ServiceTrack::description() const 0363 { 0364 return m_description; 0365 } 0366 0367 void 0368 ServiceTrack::setDescription( const QString &newDescription ) 0369 { 0370 m_description = newDescription; 0371 } 0372 0373 qint64 0374 ServiceTrack::length() const 0375 { 0376 return m_length; 0377 } 0378 0379 int 0380 ServiceTrack::filesize() const 0381 { 0382 return 0; 0383 } 0384 0385 int 0386 ServiceTrack::sampleRate() const 0387 { 0388 return 0; 0389 } 0390 0391 int 0392 ServiceTrack::bitrate() const 0393 { 0394 return 0; 0395 } 0396 0397 int 0398 ServiceTrack::trackNumber() const 0399 { 0400 return m_trackNumber; 0401 } 0402 0403 void 0404 ServiceTrack::setTrackNumber( int newTrackNumber ) 0405 { 0406 m_trackNumber = newTrackNumber; 0407 } 0408 0409 int 0410 ServiceTrack::discNumber() const 0411 { 0412 return 0; 0413 } 0414 0415 void 0416 ServiceTrack::setDiscNumber( int newDiscNumber ) 0417 { 0418 Q_UNUSED( newDiscNumber ) 0419 } 0420 0421 QString 0422 ServiceTrack::type() const 0423 { 0424 // return m_type; 0425 return Amarok::extension( uidUrl() ); 0426 } 0427 0428 void 0429 ServiceTrack::setAlbumPtr( const AlbumPtr &album ) 0430 { 0431 m_album = album; 0432 } 0433 0434 void 0435 ServiceTrack::setArtist( const ArtistPtr &artist ) 0436 { 0437 m_artist = artist; 0438 } 0439 0440 void 0441 ServiceTrack::setGenre( const GenrePtr &genre ) 0442 { 0443 m_genre = genre; 0444 } 0445 0446 void 0447 ServiceTrack::setComposer( const ComposerPtr &composer ) 0448 { 0449 m_composer = composer; 0450 } 0451 0452 void 0453 ServiceTrack::setYear( const YearPtr &year ) 0454 { 0455 m_year = year; 0456 } 0457 0458 void 0459 ServiceTrack::setStatisticsProvider( const StatisticsPtr &provider ) 0460 { 0461 m_statsStore = provider; 0462 } 0463 0464 void 0465 ServiceTrack::setTitle( const QString &title ) 0466 { 0467 m_name = title; 0468 } 0469 0470 void 0471 ServiceTrack::setLength( qint64 length ) 0472 { 0473 m_length = length; 0474 } 0475 0476 0477 void ServiceTrack::processInfoOf(InfoParserBase * infoParser) 0478 { 0479 infoParser->getInfo( TrackPtr( this ) ); 0480 } 0481 0482 StatisticsPtr 0483 ServiceTrack::statistics() 0484 { 0485 if( m_statsStore ) 0486 return m_statsStore; 0487 return Meta::Track::statistics(); 0488 } 0489 0490 0491 0492 //ServiceArtist 0493 ServiceArtist::ServiceArtist( const QString & name ) 0494 : Meta::Artist() 0495 , ServiceDisplayInfoProvider() 0496 , ActionsProvider() 0497 , SourceInfoProvider() 0498 , BookmarkThisProvider() 0499 , m_id( 0 ) 0500 , m_name( name ) 0501 , m_tracks() 0502 { 0503 //nothing to do 0504 } 0505 0506 ServiceArtist::ServiceArtist(const QStringList & resultRow) 0507 : Meta::Artist() 0508 , ServiceDisplayInfoProvider() 0509 , ActionsProvider() 0510 , SourceInfoProvider() 0511 , BookmarkThisProvider() 0512 , m_tracks() 0513 { 0514 m_id = resultRow[0].toInt(); 0515 m_name = resultRow[1]; 0516 m_description = resultRow[2]; 0517 } 0518 0519 ServiceArtist::~ServiceArtist() 0520 { 0521 //nothing to do 0522 } 0523 0524 0525 void 0526 ServiceArtist::setId(int id) 0527 { 0528 m_id = id; 0529 } 0530 0531 int 0532 ServiceArtist::id() const 0533 { 0534 return m_id; 0535 } 0536 0537 QString 0538 ServiceArtist::name() const 0539 { 0540 return m_name; 0541 } 0542 0543 void 0544 ServiceArtist::setTitle(const QString & title) 0545 { 0546 m_name = title; 0547 } 0548 0549 TrackList 0550 ServiceArtist::tracks() 0551 { 0552 return m_tracks; 0553 } 0554 0555 void 0556 ServiceArtist::addTrack( const TrackPtr &track ) 0557 { 0558 m_tracks.append( track ); 0559 } 0560 0561 0562 void 0563 ServiceArtist::setDescription(const QString &description) 0564 { 0565 m_description = description; 0566 } 0567 0568 QString 0569 ServiceArtist::description() const 0570 { 0571 return m_description; 0572 } 0573 0574 void 0575 ServiceArtist::processInfoOf(InfoParserBase * infoParser) 0576 { 0577 infoParser->getInfo( ArtistPtr ( this ) ); 0578 } 0579 0580 0581 0582 ServiceAlbum::ServiceAlbum( const QString & name ) 0583 : Meta::Album() 0584 , ServiceDisplayInfoProvider() 0585 , ActionsProvider() 0586 , SourceInfoProvider() 0587 , BookmarkThisProvider() 0588 , m_id( 0 ) 0589 , m_name( name ) 0590 , m_tracks() 0591 , m_isCompilation( false ) 0592 , m_albumArtist( nullptr ) 0593 , m_artistId( 0 ) 0594 { 0595 //nothing to do 0596 } 0597 0598 ServiceAlbum::ServiceAlbum(const QStringList & resultRow) 0599 : Meta::Album() 0600 , ServiceDisplayInfoProvider() 0601 , ActionsProvider() 0602 , SourceInfoProvider() 0603 , BookmarkThisProvider() 0604 , m_id( resultRow[0].toInt() ) 0605 , m_name( resultRow[1] ) 0606 , m_isCompilation( false ) 0607 , m_albumArtist( nullptr ) 0608 , m_description( resultRow[2] ) 0609 , m_artistId( resultRow[3].toInt() ) 0610 , m_artistName() 0611 { 0612 } 0613 0614 ServiceAlbum::~ServiceAlbum() 0615 { 0616 //nothing to do 0617 } 0618 0619 void 0620 ServiceAlbum::setId(int id) 0621 { 0622 m_id = id; 0623 } 0624 0625 int 0626 ServiceAlbum::id() const 0627 { 0628 return m_id; 0629 } 0630 0631 void 0632 ServiceAlbum::setArtistId(int artistId) 0633 { 0634 m_artistId = artistId; 0635 } 0636 0637 int 0638 ServiceAlbum::artistId() const 0639 { 0640 return m_artistId; 0641 } 0642 0643 void 0644 ServiceAlbum::setArtistName(const QString & name) 0645 { 0646 m_artistName = name; 0647 } 0648 0649 QString 0650 ServiceAlbum::artistName() const 0651 { 0652 return m_artistName; 0653 } 0654 0655 QString 0656 ServiceAlbum::name() const 0657 { 0658 return m_name; 0659 } 0660 0661 void 0662 ServiceAlbum::setTitle(const QString & title) 0663 { 0664 m_name = title; 0665 } 0666 0667 bool 0668 ServiceAlbum::isCompilation() const 0669 { 0670 return m_isCompilation; 0671 } 0672 0673 bool ServiceAlbum::canUpdateCompilation() const 0674 { 0675 return true; 0676 } 0677 0678 void 0679 ServiceAlbum::setCompilation( bool compilation ) 0680 { 0681 m_isCompilation = compilation; 0682 } 0683 0684 bool 0685 ServiceAlbum::hasAlbumArtist() const 0686 { 0687 return !m_albumArtist.isNull(); 0688 } 0689 0690 ArtistPtr 0691 ServiceAlbum::albumArtist() const 0692 { 0693 return ArtistPtr::staticCast( m_albumArtist ); 0694 } 0695 0696 TrackList 0697 ServiceAlbum::tracks() 0698 { 0699 return m_tracks; 0700 } 0701 0702 void 0703 ServiceAlbum::addTrack( const TrackPtr &track ) 0704 { 0705 m_tracks.append( track ); 0706 } 0707 0708 void 0709 ServiceAlbum::setAlbumArtist( const ArtistPtr &artist ) 0710 { 0711 m_albumArtist = artist; 0712 } 0713 0714 void ServiceAlbum::setDescription(const QString &description) 0715 { 0716 m_description = description; 0717 } 0718 0719 QString 0720 ServiceAlbum::description() const 0721 { 0722 return m_description; 0723 } 0724 0725 void 0726 ServiceAlbum::processInfoOf(InfoParserBase * infoParser) 0727 { 0728 infoParser->getInfo( AlbumPtr( this ) ); 0729 } 0730 0731 0732 //ServiceGenre 0733 0734 ServiceGenre::ServiceGenre( const QString &name ) 0735 : Meta::Genre() 0736 , ServiceDisplayInfoProvider() 0737 , ActionsProvider() 0738 , SourceInfoProvider() 0739 , BookmarkThisProvider() 0740 , m_id( 0 ) 0741 , m_albumId( 0 ) 0742 , m_name( name ) 0743 , m_tracks() 0744 { 0745 //nothing to do 0746 } 0747 0748 ServiceGenre::ServiceGenre(const QStringList & row) 0749 : Meta::Genre() 0750 , ServiceDisplayInfoProvider() 0751 , ActionsProvider() 0752 , SourceInfoProvider() 0753 , BookmarkThisProvider() 0754 , m_id( 0 ) 0755 , m_albumId( 0 ) 0756 , m_name( row[1] ) 0757 , m_tracks() 0758 { 0759 } 0760 0761 ServiceGenre::~ServiceGenre() 0762 { 0763 //nothing to do 0764 } 0765 0766 void 0767 ServiceGenre::setId(int id) 0768 { 0769 m_id = id; 0770 } 0771 0772 int 0773 ServiceGenre::id() const 0774 { 0775 return m_id; 0776 } 0777 0778 QString 0779 ServiceGenre::name() const 0780 { 0781 return m_name; 0782 } 0783 0784 int 0785 ServiceGenre::albumId() 0786 { 0787 return m_albumId; 0788 } 0789 0790 void 0791 ServiceGenre::setAlbumId(int albumId) 0792 { 0793 m_albumId = albumId; 0794 } 0795 0796 0797 TrackList 0798 ServiceGenre::tracks() 0799 { 0800 return m_tracks; 0801 } 0802 0803 void 0804 ServiceGenre::addTrack( const TrackPtr &track ) 0805 { 0806 m_tracks.append( track ); 0807 } 0808 0809 void 0810 ServiceGenre::processInfoOf(InfoParserBase * infoParser) 0811 { 0812 Q_UNUSED( infoParser ); 0813 return; // do nothing 0814 } 0815 0816 //ServiceComposer 0817 0818 ServiceComposer::ServiceComposer( const QString &name ) 0819 : Meta::Composer() 0820 , ServiceDisplayInfoProvider() 0821 , ActionsProvider() 0822 , SourceInfoProvider() 0823 , BookmarkThisProvider() 0824 , m_name( name ) 0825 , m_tracks() 0826 { 0827 //nothing to do 0828 } 0829 0830 ServiceComposer::~ServiceComposer() 0831 { 0832 //nothing to do 0833 } 0834 0835 QString 0836 ServiceComposer::name() const 0837 { 0838 return m_name; 0839 } 0840 0841 TrackList 0842 ServiceComposer::tracks() 0843 { 0844 return m_tracks; 0845 } 0846 0847 void 0848 ServiceComposer::addTrack( const ServiceTrackPtr &track ) 0849 { 0850 m_tracks.append( TrackPtr::staticCast( track ) ); 0851 } 0852 0853 void 0854 ServiceComposer::processInfoOf(InfoParserBase * infoParser) 0855 { 0856 Q_UNUSED( infoParser ); 0857 return; // do nothing 0858 } 0859 0860 //ServiceYear 0861 0862 ServiceYear::ServiceYear( const QString &name ) 0863 : Meta::Year() 0864 , ServiceDisplayInfoProvider() 0865 , ActionsProvider() 0866 , SourceInfoProvider() 0867 , BookmarkThisProvider() 0868 , m_name( name ) 0869 , m_tracks() 0870 { 0871 //nothing to do 0872 } 0873 0874 ServiceYear::~ServiceYear() 0875 { 0876 //nothing to do 0877 } 0878 0879 QString 0880 ServiceYear::name() const 0881 { 0882 return m_name; 0883 } 0884 0885 TrackList 0886 ServiceYear::tracks() 0887 { 0888 return m_tracks; 0889 } 0890 0891 void 0892 ServiceYear::addTrack( const ServiceTrackPtr &track ) 0893 { 0894 m_tracks.append( TrackPtr::staticCast( track ) ); 0895 } 0896 0897 0898 void 0899 ServiceYear::processInfoOf(InfoParserBase * infoParser) 0900 { 0901 Q_UNUSED( infoParser ); 0902 return; // do nothing 0903 } 0904