forked from Shazib/CometFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomFileModel.cpp
More file actions
84 lines (70 loc) · 2.51 KB
/
CustomFileModel.cpp
File metadata and controls
84 lines (70 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* This Class is a reimplementation of QFileSystemModel.
* The default class provides all required functionality by default, and as such,
* handles drop events internally.
*
* Files draged from the server technically do not exist on the local system
* The default model does not know how to handle the custom mime type
* It does not need to try and move/copy the files
* It just needs to send the data to the downloader class to add to the queue.
*/
#include "CustomFileModel.h"
CustomFileModel::CustomFileModel(QObject *parent) :
QFileSystemModel(parent)
{
}
// Returns the mime types that this class supports for drops
QStringList CustomFileModel::mimeTypes() const
{
QStringList Temp = QStringList(QLatin1String("text/uri-list"));
Temp << "text/comet-upload-download";
return Temp;
}
// Called when data is dropped
bool CustomFileModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
if(data->data("text/comet-upload-download").count() > 0) {
qDebug() << "Comet file";
// Emit the signal
emit sendDropData("Download",QString(data->data("text/comet-upload-download")),filePath(parent),data->text());
return true;
} else {
// The Default Implementation from QFileSystemModel.cpp for copying normal mime types.
Q_UNUSED(row);
Q_UNUSED(column);
if (!parent.isValid() || isReadOnly())
return false;
bool success = true;
QString to = filePath(parent) + QDir::separator();
QList<QUrl> urls = data->urls();
QList<QUrl>::const_iterator it = urls.constBegin();
switch (action) {
case Qt::CopyAction:
for (; it != urls.constEnd(); ++it) {
QString path = (*it).toLocalFile();
success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
}
break;
case Qt::LinkAction:
for (; it != urls.constEnd(); ++it) {
QString path = (*it).toLocalFile();
success = QFile::link(path, to + QFileInfo(path).fileName()) && success;
}
break;
case Qt::MoveAction:
for (; it != urls.constEnd(); ++it) {
QString path = (*it).toLocalFile();
success = QFile::copy(path, to + QFileInfo(path).fileName())
&& QFile::remove(path) && success;
}
break;
default:
return false;
}
return success;
}
}
Qt::DropActions CustomFileModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
}