Warning, file /multimedia/amarok/src/amarokurls/BookmarkModel.h 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) 2008 Nikolaj Hald Nielsen <nhn@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 BOOKMARKMODEL_H 0018 #define BOOKMARKMODEL_H 0019 0020 #include "BookmarkViewItem.h" 0021 0022 #include "AmarokSharedPointer.h" 0023 0024 #include <QAbstractItemModel> 0025 #include <QModelIndex> 0026 #include <QVariant> 0027 0028 0029 class BookmarkGroup; 0030 0031 typedef AmarokSharedPointer<BookmarkViewItem> BookmarkViewItemPtr; 0032 0033 class BookmarkGroup; 0034 typedef AmarokSharedPointer<BookmarkGroup> BookmarkGroupPtr; 0035 typedef QList<BookmarkGroupPtr> BookmarkGroupList; 0036 0037 0038 //#define BOOKMARK_DB_VERSION 1 0039 0040 0041 /** 0042 @author Nikolaj Hald Nielsen <nhn@kde.org> 0043 */ 0044 0045 class BookmarkModel : public QAbstractItemModel 0046 { 0047 Q_OBJECT 0048 public: 0049 0050 enum Column 0051 { 0052 Name = 0, 0053 Command, 0054 Url, 0055 Description 0056 }; 0057 0058 static BookmarkModel * instance(); 0059 0060 ~BookmarkModel() override; 0061 0062 QVariant data( const QModelIndex &index, int role ) const override; 0063 Qt::ItemFlags flags( const QModelIndex &index ) const override; 0064 QVariant headerData( int section, Qt::Orientation orientation, 0065 int role = Qt::DisplayRole ) const override; 0066 QModelIndex index( int row, int column, 0067 const QModelIndex &parent = QModelIndex() ) const override; 0068 QModelIndex parent( const QModelIndex &index ) const override; 0069 int rowCount( const QModelIndex &parent = QModelIndex() ) const override; 0070 int columnCount( const QModelIndex &parent = QModelIndex() ) const override; 0071 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override; 0072 0073 Qt::DropActions supportedDropActions() const override 0074 { 0075 return Qt::MoveAction; 0076 } 0077 0078 QStringList mimeTypes() const override; 0079 QMimeData* mimeData( const QModelIndexList &indexes ) const override; 0080 bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override; 0081 0082 void reloadFromDb(); 0083 void editBookmark( int id ); 0084 0085 QModelIndex createIndex( int row, int column, const BookmarkViewItemPtr &item ) const; 0086 //only use the above method 0087 QModelIndex createIndex( int, int, void * ptr = nullptr ) const 0088 { 0089 Q_UNUSED( ptr ); 0090 Q_ASSERT( 0 ); 0091 return QModelIndex(); 0092 } 0093 0094 QModelIndex createIndex( int, int, quint32 ) const 0095 { 0096 Q_ASSERT( 0 ); 0097 return QModelIndex(); 0098 } 0099 0100 public Q_SLOTS: 0101 void createNewGroup(); 0102 void createNewBookmark(); 0103 void deleteBookmark( const QString &name ); 0104 void renameBookmark( const QString &oldName , const QString &newName ); 0105 0106 /** 0107 * Sets the bookmark's (whose name is @param name ) url argument named @param key 0108 * to @param value . Overrides any possible previous value. 0109 */ 0110 void setBookmarkArg(const QString &name, const QString &key, const QString &value); 0111 0112 Q_SIGNALS: 0113 void editIndex( const QModelIndex &index ); 0114 0115 private: 0116 BookmarkModel(); 0117 0118 void checkTables(); 0119 void createTables(); 0120 void deleteTables(); 0121 void upgradeTables( int from ); 0122 0123 bool setBookmarkArgRecursively( BookmarkGroupPtr group, const QString &name, const QString &key, const QString &value ); 0124 bool deleteBookmarkRecursively( BookmarkGroupPtr group, const QString &name ); 0125 bool renameBookmarkRecursively( BookmarkGroupPtr group, const QString &oldName, const QString &newName ); 0126 0127 static BookmarkModel * s_instance; 0128 0129 BookmarkGroupPtr m_root; 0130 mutable QHash<quint32, BookmarkViewItemPtr> m_viewItems; ///the hash of the pointer mapped to the AmarokSharedPointer 0131 0132 }; 0133 0134 0135 #endif