File indexing completed on 2024-05-19 04:50:24
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 #ifndef OPMLDIRECTORYMODEL_H 0018 #define OPMLDIRECTORYMODEL_H 0019 0020 #include "OpmlOutline.h" 0021 0022 #include <QUrl> 0023 0024 #include <QAbstractItemModel> 0025 0026 class OpmlParser; 0027 0028 class QAction; 0029 typedef QList<QAction *> QActionList; 0030 0031 class OpmlDirectoryModel : public QAbstractItemModel 0032 { 0033 Q_OBJECT 0034 public: 0035 //TODO: make these rols part of a common class in Amarok::. 0036 enum 0037 { 0038 ActionRole = Qt::UserRole, //list of QActions for the index 0039 DecorationUriRole, //a URI for the decoration to be fetched by the view. 0040 CustomRoleOffset //first role that can be used by subclasses for their own data 0041 }; 0042 0043 explicit OpmlDirectoryModel( QUrl outlineUrl, QObject *parent = nullptr ); 0044 ~OpmlDirectoryModel() override; 0045 0046 // QAbstractItemModel methods 0047 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override; 0048 Qt::ItemFlags flags( const QModelIndex &index ) const override; 0049 QModelIndex parent( const QModelIndex &index ) const override; 0050 int rowCount( const QModelIndex &parent = QModelIndex() ) const override; 0051 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override; 0052 int columnCount( const QModelIndex &parent = QModelIndex() ) const override; 0053 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; 0054 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override; 0055 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override; 0056 0057 // OpmlDirectoryModel methods 0058 virtual void saveOpml( const QUrl &saveLocation ); 0059 virtual OpmlNodeType opmlNodeType( const QModelIndex &idx ) const; 0060 0061 //TODO: extract these into OpmlPodcastDirectoryModel subclass 0062 void subscribe( const QModelIndexList &indexes ) const; 0063 0064 Q_SIGNALS: 0065 0066 public Q_SLOTS: 0067 void slotAddOpmlAction(); 0068 void slotAddFolderAction(); 0069 0070 protected: 0071 bool canFetchMore( const QModelIndex &parent ) const override; 0072 void fetchMore( const QModelIndex &parent ) override; 0073 0074 private Q_SLOTS: 0075 void slotOpmlHeaderDone(); 0076 void slotOpmlOutlineParsed( OpmlOutline * ); 0077 void slotOpmlParsingDone(); 0078 void slotOpmlWriterDone( int result ); 0079 0080 private: 0081 QModelIndex addOutlineToModel( const QModelIndex &parentIdx, OpmlOutline *oultine ); 0082 0083 QUrl m_rootOpmlUrl; 0084 QList<OpmlOutline *> m_rootOutlines; 0085 0086 QMap<OpmlParser *,QModelIndex> m_currentFetchingMap; 0087 QMap<OpmlOutline *,QPixmap> m_imageMap; 0088 0089 QAction *m_addOpmlAction; 0090 QAction *m_addFolderAction; 0091 }; 0092 0093 0094 #endif // OPMLDIRECTORYMODEL_H