File indexing completed on 2024-05-19 04:48:41
0001 /**************************************************************************************** 0002 * Copyright (c) 2007-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 #ifndef PLAYLISTBROWSERNSPODCASTMODEL_H 0018 #define PLAYLISTBROWSERNSPODCASTMODEL_H 0019 0020 #include "amarok_export.h" 0021 0022 #include "core/podcasts/PodcastMeta.h" 0023 #include "core/podcasts/PodcastProvider.h" 0024 0025 #include "PlaylistBrowserModel.h" 0026 #include "playlist/PlaylistModelStack.h" 0027 0028 #include <QAbstractItemModel> 0029 #include <QModelIndex> 0030 #include <QPersistentModelIndex> 0031 #include <QVariant> 0032 0033 namespace PlaylistBrowserNS { 0034 0035 /* TODO: these should be replaced with custom roles for PlaylistColumn so all data of a playlist can 0036 be fetched at once with itemData() */ 0037 enum 0038 { 0039 SubtitleColumn = PlaylistBrowserModel::CustomColumOffset, 0040 AuthorColumn, 0041 KeywordsColumn, 0042 FilesizeColumn, // episode only 0043 ImageColumn, // channel only (for now) 0044 DateColumn, 0045 IsEpisodeColumn, 0046 ColumnCount 0047 }; 0048 0049 /** 0050 * @author Bart Cerneels 0051 */ 0052 class AMAROK_EXPORT PodcastModel : public PlaylistBrowserModel 0053 { 0054 Q_OBJECT 0055 0056 public: 0057 static PodcastModel *instance(); 0058 static void destroy(); 0059 0060 /* QAbstractItemModel methods */ 0061 QVariant data(const QModelIndex &index, int role) const override; 0062 bool setData( const QModelIndex &index, const QVariant &value, 0063 int role = Qt::EditRole ) override; 0064 QVariant headerData(int section, Qt::Orientation orientation, 0065 int role = Qt::DisplayRole) const override; 0066 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0067 0068 Qt::DropActions supportedDropActions() const override { 0069 return Qt::CopyAction | Qt::MoveAction; 0070 } 0071 0072 Qt::DropActions supportedDragActions() const override { 0073 return Qt::MoveAction | Qt::CopyAction; 0074 } 0075 0076 Q_SIGNALS: 0077 void episodeMarkedAsNew( Podcasts::PodcastEpisodePtr ); 0078 0079 public Q_SLOTS: 0080 void addPodcast(); 0081 void refreshPodcasts(); 0082 0083 private: 0084 static PodcastModel *s_instance; 0085 PodcastModel(); 0086 0087 QVariant channelData( const Podcasts::PodcastChannelPtr &channel, 0088 const QModelIndex &idx, int role ) const; 0089 QVariant episodeData( const Podcasts::PodcastEpisodePtr &episode, 0090 const QModelIndex &idx, int role ) const; 0091 0092 Podcasts::PodcastChannelPtr channelForIndex( const QModelIndex &index ) const; 0093 Podcasts::PodcastEpisodePtr episodeForIndex( const QModelIndex &index ) const; 0094 0095 Q_DISABLE_COPY( PodcastModel ) 0096 0097 /** 0098 * A convenience function to convert a PodcastEpisodeList into a TrackList. 0099 */ 0100 static Meta::TrackList podcastEpisodesToTracks( Podcasts::PodcastEpisodeList episodes ); 0101 0102 bool isOnDisk( Podcasts::PodcastEpisodePtr episode ) const; 0103 QVariant icon( const Podcasts::PodcastChannelPtr &channel ) const; 0104 QVariant icon( const Podcasts::PodcastEpisodePtr &episode ) const; 0105 }; 0106 0107 } 0108 0109 namespace The { 0110 AMAROK_EXPORT PlaylistBrowserNS::PodcastModel* podcastModel(); 0111 } 0112 0113 #endif