2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 #include <QStandardItemModel>
22 #include <QFileIconProvider>
26 PathIdRole = Qt::UserRole+1,
27 FilenameIdRole = Qt::UserRole+2,
28 FileIdRole = Qt::UserRole+3,
29 JobIdRole = Qt::UserRole+4,
30 LStatRole = Qt::UserRole+5,
31 PathRole = Qt::UserRole+6,
32 TypeRole = Qt::UserRole+7
36 TYPEROLE_DIRECTORY = 0,
40 class DirectoryItem : public QStandardItem
43 DirectoryItem() : QStandardItem()
45 /* explicit set the data, so it can be serialized in Mime Data for D&D */
46 setData(QVariant(TYPEROLE_DIRECTORY), TypeRole);
48 QVariant data(int role = Qt::UserRole + 1) const
50 if (role == Qt::DecorationRole) {
51 QFileIconProvider provider;
52 return provider.icon(QFileIconProvider::Folder);
55 return QStandardItem::data(role);
59 class FileItem : public QStandardItem
62 FileItem() : QStandardItem()
64 /* explicit set the data, so it can be serialized in Mime Data for D&D */
65 setData(QVariant(TYPEROLE_FILE), TypeRole);
68 FILE_TYPE = UserType +2
71 QVariant data(int role = Qt::UserRole + 1) const
73 if (role == Qt::DecorationRole) {
74 QFileIconProvider provider;
75 return provider.icon(QFileIconProvider::File);
78 return QStandardItem::data(role);
82 #define BATCH_SIZE 100
83 class FileSourceModel : public QStandardItemModel
86 FileSourceModel() : QStandardItemModel(),
88 m_batchSize(BATCH_SIZE),
92 bool canFetchMore(const QModelIndex &parent) const
95 return false/*m_canFetchMore*/;
97 void fetchMore(const QModelIndex &parent)
103 void taskComplete(task *t)
113 u_int64_t m_batchSize;
117 class FileDestModel : public QStandardItemModel
119 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
126 if (data->hasFormat("application/x-qstandarditemmodeldatalist")) {
127 QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
128 QDataStream stream(&encoded, QIODevice::ReadOnly);
130 while (!stream.atEnd())
133 QMap<int, QVariant> roleDataMap;
134 stream >> row >> col >> roleDataMap;
136 /* do something with the data */
137 int type = roleDataMap[TypeRole].toInt();
140 case TYPEROLE_DIRECTORY:
152 bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
159 QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
160 QDataStream stream(&encoded, QIODevice::ReadOnly);
162 while (!stream.atEnd())
165 QMap<int, QVariant> roleDataMap;
166 stream >> row >> col >> roleDataMap;
169 /* do something with the data */
170 int type = roleDataMap[TypeRole].toInt();
173 case TYPEROLE_DIRECTORY:
174 item = new DirectoryItem();
177 item = new FileItem();
183 item->setData(roleDataMap[PathIdRole], PathIdRole);
184 item->setData(roleDataMap[FilenameIdRole], FilenameIdRole);
185 item->setData(roleDataMap[FileIdRole], FileIdRole);
186 item->setData(roleDataMap[JobIdRole], JobIdRole);
187 item->setData(roleDataMap[LStatRole], LStatRole);
188 item->setData(roleDataMap[PathRole], PathRole);
189 item->setData(roleDataMap[PathRole], Qt::DisplayRole);
197 #endif // FILESMODEL_H