File indexing completed on 2025-01-19 04:24:36
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Bart Cerneels <bart.cerneels@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 #include "UmsPodcastMeta.h" 0018 0019 #include "core/support/Debug.h" 0020 0021 #include "core-impl/playlists/types/file/PlaylistFileSupport.h" 0022 0023 #include "UmsPodcastProvider.h" 0024 0025 using namespace Podcasts; 0026 0027 UmsPodcastEpisodePtr 0028 UmsPodcastEpisode::fromPodcastEpisodePtr( const PodcastEpisodePtr &episode ) 0029 { 0030 return UmsPodcastEpisodePtr::dynamicCast( episode ); 0031 } 0032 0033 UmsPodcastEpisodePtr 0034 UmsPodcastEpisode::fromTrackPtr( const Meta::TrackPtr &track ) 0035 { 0036 return UmsPodcastEpisodePtr::dynamicCast( track ); 0037 } 0038 0039 PodcastEpisodePtr 0040 UmsPodcastEpisode::toPodcastEpisodePtr( const UmsPodcastEpisodePtr &episode ) 0041 { 0042 return PodcastEpisodePtr::dynamicCast( episode ); 0043 } 0044 0045 PodcastEpisodeList 0046 UmsPodcastEpisode::toPodcastEpisodeList( UmsPodcastEpisodeList episodes ) 0047 { 0048 PodcastEpisodeList list; 0049 foreach( UmsPodcastEpisodePtr e, episodes ) 0050 list << toPodcastEpisodePtr( e ); 0051 return list; 0052 } 0053 0054 UmsPodcastEpisode::UmsPodcastEpisode( const UmsPodcastChannelPtr &channel ) 0055 : Podcasts::PodcastEpisode( UmsPodcastChannel::toPodcastChannelPtr( channel ) ) 0056 { 0057 } 0058 0059 UmsPodcastEpisode::~UmsPodcastEpisode() 0060 { 0061 } 0062 0063 void 0064 UmsPodcastEpisode::setLocalUrl( const QUrl &localUrl ) 0065 { 0066 m_localUrl = localUrl; 0067 //TODO: load local file 0068 } 0069 0070 QUrl 0071 UmsPodcastEpisode::playableUrl() const 0072 { 0073 if( m_localFile.isNull() ) 0074 return m_url; 0075 0076 return m_localFile->playableUrl(); 0077 } 0078 0079 QString 0080 UmsPodcastEpisode::notPlayableReason() const 0081 { 0082 if( m_localFile ) 0083 return m_localFile->notPlayableReason(); 0084 return PodcastEpisode::notPlayableReason(); 0085 } 0086 0087 void 0088 UmsPodcastEpisode::setLocalFile( const MetaFile::TrackPtr &localFile ) 0089 { 0090 m_localFile = localFile; 0091 } 0092 0093 QString 0094 UmsPodcastEpisode::title() const 0095 { 0096 if( m_localFile.isNull() ) 0097 return m_title; 0098 0099 return m_localFile->name(); 0100 } 0101 0102 QDateTime 0103 UmsPodcastEpisode::createDate() const 0104 { 0105 if( m_localFile ) 0106 return m_localFile->createDate(); 0107 return Meta::Track::createDate(); 0108 } 0109 0110 void 0111 UmsPodcastEpisode::setTitle( const QString &title ) 0112 { 0113 if( !m_localFile.isNull() ) 0114 { 0115 m_localFile->setTitle( title ); 0116 } 0117 0118 m_title = title; 0119 } 0120 0121 Meta::AlbumPtr 0122 UmsPodcastEpisode::album() const 0123 { 0124 if( m_localFile.isNull() ) 0125 return m_albumPtr; 0126 0127 return m_localFile->album(); 0128 } 0129 0130 Meta::ArtistPtr 0131 UmsPodcastEpisode::artist() const 0132 { 0133 if( m_localFile.isNull() ) 0134 return m_artistPtr; 0135 0136 return m_localFile->artist(); 0137 } 0138 0139 Meta::ComposerPtr 0140 UmsPodcastEpisode::composer() const 0141 { 0142 if( m_localFile.isNull() ) 0143 return m_composerPtr; 0144 0145 return m_localFile->composer(); 0146 } 0147 0148 Meta::GenrePtr 0149 UmsPodcastEpisode::genre() const 0150 { 0151 if( m_localFile.isNull() ) 0152 return m_genrePtr; 0153 0154 return m_localFile->genre(); 0155 } 0156 0157 Meta::YearPtr 0158 UmsPodcastEpisode::year() const 0159 { 0160 if( m_localFile.isNull() ) 0161 return m_yearPtr; 0162 0163 return m_localFile->year(); 0164 } 0165 0166 UmsPodcastChannelPtr 0167 UmsPodcastChannel::fromPodcastChannelPtr( const PodcastChannelPtr &channel ) 0168 { 0169 return UmsPodcastChannelPtr::dynamicCast( channel ); 0170 } 0171 0172 PodcastChannelPtr 0173 UmsPodcastChannel::toPodcastChannelPtr( const UmsPodcastChannelPtr &channel ) 0174 { 0175 return PodcastChannelPtr::dynamicCast( channel ); 0176 } 0177 0178 PodcastChannelList 0179 UmsPodcastChannel::toPodcastChannelList( UmsPodcastChannelList umsChannels ) 0180 { 0181 PodcastChannelList channels; 0182 foreach( UmsPodcastChannelPtr umsChannel, umsChannels ) 0183 channels << UmsPodcastChannel::toPodcastChannelPtr( umsChannel ); 0184 return channels; 0185 } 0186 0187 UmsPodcastChannel::UmsPodcastChannel( UmsPodcastProvider *provider ) 0188 : Podcasts::PodcastChannel() 0189 , m_provider( provider ) 0190 { 0191 0192 } 0193 0194 UmsPodcastChannel::UmsPodcastChannel( PodcastChannelPtr channel, 0195 UmsPodcastProvider *provider ) 0196 : Podcasts::PodcastChannel( channel ) 0197 , m_provider( provider ) 0198 { 0199 //Since we need to copy the tracks, make sure it's loaded. 0200 //TODO: we might also need to subscribe to get trackAdded() when channel does async loading. 0201 channel->triggerTrackLoad(); 0202 0203 foreach( PodcastEpisodePtr episode, channel->episodes() ) 0204 addEpisode( episode ); 0205 } 0206 0207 UmsPodcastChannel::~UmsPodcastChannel() 0208 { 0209 0210 } 0211 0212 PodcastEpisodePtr 0213 UmsPodcastChannel::addEpisode(const PodcastEpisodePtr &episode ) 0214 { 0215 DEBUG_BLOCK 0216 0217 if( !episode->isNew() || !episode->playableUrl().isLocalFile() ) 0218 return PodcastEpisodePtr(); //we don't care about these. 0219 0220 if( !m_provider ) 0221 return PodcastEpisodePtr(); 0222 0223 return m_provider->addEpisode( episode ); 0224 //track adding is asynchronous, provider will call addUmsEpisode once done. 0225 //TODO: change this so track can show progress once playlist-inline-progress is implemented 0226 } 0227 0228 void 0229 UmsPodcastChannel::addUmsEpisode( UmsPodcastEpisodePtr umsEpisode ) 0230 { 0231 int i = 0; 0232 foreach( UmsPodcastEpisodePtr e, m_umsEpisodes ) 0233 { 0234 if( umsEpisode->createDate() > e->createDate() ) 0235 { 0236 i = m_umsEpisodes.indexOf( e ); 0237 break; 0238 } 0239 } 0240 0241 m_umsEpisodes.insert( i, umsEpisode ); 0242 notifyObserversTrackAdded( Meta::TrackPtr::dynamicCast( umsEpisode ), i ); 0243 } 0244 0245 void 0246 UmsPodcastChannel::setPlaylistFileSource( const QUrl &playlistFilePath ) 0247 { 0248 m_playlistFilePath = playlistFilePath; 0249 m_playlistFile = Playlists::loadPlaylistFile( playlistFilePath ); 0250 0251 //now parse the playlist and use it to create out episode list 0252 } 0253 0254 Playlists::PlaylistProvider * 0255 UmsPodcastChannel::provider() const 0256 { 0257 return dynamic_cast<Playlists::PlaylistProvider *>( m_provider ); 0258 } 0259 0260 void 0261 UmsPodcastChannel::removeEpisode( const UmsPodcastEpisodePtr &episode ) 0262 { 0263 int position = m_umsEpisodes.indexOf( episode ); 0264 0265 if( position == -1 ) 0266 { 0267 error() << title() << " doesn't have this episode"; 0268 return; 0269 } 0270 0271 m_umsEpisodes.removeAt( position ); 0272 notifyObserversTrackRemoved( position ); 0273 }