File indexing completed on 2024-05-19 04:48:40
0001 /**************************************************************************************** 0002 * Copyright (c) 2009-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 AMAROK_PLAYLISTBROWSERMODEL_H 0018 #define AMAROK_PLAYLISTBROWSERMODEL_H 0019 0020 #include "core/playlists/Playlist.h" 0021 #include "core/playlists/PlaylistProvider.h" 0022 0023 #include <QAbstractItemModel> 0024 #include <QAction> 0025 //Playlist & Track index differentiator macros 0026 //QModelIndex::intenalId() is a qint64 to support 64-bit pointers in a union with the ID 0027 #define TRACK_MASK (0x1<<31) 0028 #define IS_TRACK(x) ((x.internalId()) & (TRACK_MASK))?true:false 0029 #define SET_TRACK_MASK(x) ((x) | (TRACK_MASK)) 0030 #define REMOVE_TRACK_MASK(x) ((x) & ~(TRACK_MASK)) 0031 0032 class QAction; 0033 0034 Q_DECLARE_METATYPE( QActionList ) 0035 0036 namespace PlaylistBrowserNS { 0037 0038 /** 0039 @author Bart Cerneels <bart.cerneels@kde.org> 0040 */ 0041 class PlaylistBrowserModel : public QAbstractItemModel, public Playlists::PlaylistObserver 0042 { 0043 Q_OBJECT 0044 public: 0045 enum { 0046 PlaylistItemColumn = 0, //Data form the playlist itself or it's tracks 0047 LabelColumn, //Data from the labels. Can be used as foldernames in the view. 0048 ProviderColumn, //data from the PlaylistProvider 0049 CustomColumOffset //first column that can be used by subclasses for their own data 0050 }; 0051 0052 enum 0053 { 0054 ProviderRole = Qt::UserRole + 21, // pointer to associated PlaylistProvider 0055 PlaylistRole = Qt::UserRole + 22, // PlaylistPtr for associated playlist or null 0056 TrackRole = Qt::UserRole + 23, // TrackPtr for associated track or null 0057 EpisodeIsNewRole = Qt::UserRole + 24, // for podcast episodes, supports setting, type: bool 0058 CustomRoleOffset = Qt::UserRole + 25 //first role that can be used by subclasses for their own data 0059 }; 0060 0061 PlaylistBrowserModel( int PlaylistCategory ); 0062 ~PlaylistBrowserModel() override {} 0063 0064 /* QAbstractItemModel methods */ 0065 QVariant data( const QModelIndex &index, int role ) const override; 0066 bool setData( const QModelIndex &idx, const QVariant &value, int role ) override; 0067 Qt::ItemFlags flags( const QModelIndex &index ) const override; 0068 QVariant headerData( int section, Qt::Orientation orientation, 0069 int role = Qt::DisplayRole ) const override; 0070 QModelIndex index( int row, int column, 0071 const QModelIndex &parent = QModelIndex() ) const override; 0072 QModelIndex parent( const QModelIndex &index ) const override; 0073 0074 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override; 0075 int rowCount( const QModelIndex &parent = QModelIndex() ) const override; 0076 int columnCount( const QModelIndex &parent = QModelIndex() ) const override; 0077 0078 bool canFetchMore( const QModelIndex &parent ) const override; 0079 void fetchMore( const QModelIndex &parent ) override; 0080 0081 QStringList mimeTypes() const override; 0082 QMimeData* mimeData( const QModelIndexList &indexes ) const override; 0083 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, 0084 int column, const QModelIndex &parent ) override; 0085 0086 /* Playlists::PlaylistObserver methods */ 0087 void metadataChanged( const Playlists::PlaylistPtr &playlist ) override; 0088 void trackAdded( const Playlists::PlaylistPtr &playlist, const Meta::TrackPtr &track, int position ) override; 0089 void trackRemoved( const Playlists::PlaylistPtr &playlist, int position ) override; 0090 0091 public Q_SLOTS: 0092 void slotRenamePlaylist( Playlists::PlaylistPtr playlist ); 0093 void slotUpdate( int category ); 0094 0095 Q_SIGNALS: 0096 void renameIndex( const QModelIndex &index ); 0097 0098 protected: 0099 virtual Playlists::PlaylistList loadPlaylists(); 0100 0101 Meta::TrackList tracksFromIndexes( const QModelIndexList &list ) const; 0102 Meta::TrackPtr trackFromIndex( const QModelIndex &index ) const; 0103 Playlists::PlaylistPtr playlistFromIndex( const QModelIndex &index ) const; 0104 Playlists::PlaylistProvider *providerForIndex( const QModelIndex &index ) const; 0105 0106 Playlists::PlaylistList m_playlists; 0107 QMap<Playlists::PlaylistPtr,int> m_playlistTracksLoaded; 0108 0109 Playlists::PlaylistProvider *getProviderByName( const QString &name ); 0110 0111 private Q_SLOTS: 0112 void slotPlaylistAdded( Playlists::PlaylistPtr playlist, int category ); 0113 void slotPlaylistRemoved( Playlists::PlaylistPtr playlist, int category ); 0114 void slotPlaylistUpdated( Playlists::PlaylistPtr playlist, int category ); 0115 0116 private: 0117 int m_playlistCategory; 0118 }; 0119 0120 } 0121 0122 #endif //AMAROK_PLAYLISTBROWSERMODEL_H