forked from Shazib/CometFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerFileModel.cpp
More file actions
193 lines (150 loc) · 5.1 KB
/
ServerFileModel.cpp
File metadata and controls
193 lines (150 loc) · 5.1 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "ServerFileModel.h"
#include <QStringListModel>
ServerFileModel::ServerFileModel(QObject* parent, int numRows, QStringList dataList, QString _path) :
QAbstractTableModel(parent)
{
dataList_ = dataList;
row = numRows;
path = _path;
}
int ServerFileModel::columnCount(const QModelIndex &parent) const{
return 5;
}
int ServerFileModel::rowCount(const QModelIndex &parent) const{
return row;
}
QVariant ServerFileModel::data(const QModelIndex &index, int role) const{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole){
int i =(index.row()*5)+(index.column());
return dataList_.at(i);
}
else
return QVariant();
}
QVariant ServerFileModel::headerData(int section, Qt::Orientation orientation, int role) const{
if (role == Qt::DisplayRole){
if (orientation == Qt::Horizontal){
switch (section)
{
case 0:
return QString("Name");
case 1:
return QString("Size");
case 2:
return QString("Permissions");
case 3:
return QString("Owner");
case 4:
return QString("Type");
}
}
}
return QVariant();
}
Qt::DropActions ServerFileModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::DropActions ServerFileModel::supportedDragActions() const
{
return Qt::CopyAction | Qt::MoveAction | Qt::IgnoreAction | Qt::TargetMoveAction | Qt::LinkAction;
}
Qt::ItemFlags ServerFileModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}
QStringList ServerFileModel::mimeTypes() const
{
QStringList types;
types << "application/vnd.text.list";
//return types;
return QStringList(QLatin1String("text/uri-list"));
}
// The Data for our mime type is set.
// This passes just the url
// The local file widget needs to handle this specific mime type
QMimeData* ServerFileModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData* mimeData = new QMimeData;
foreach (const QModelIndex &index, indexes) {
if (index.isValid()) {
QString filename = index.model()->data(index.model()->index(index.row(),0,index),Qt::DisplayRole).toString();
QString filePath = path + filename;
QByteArray ba = filePath.toLocal8Bit().data();
mimeData->setData("text/comet-upload-download", ba);
mimeData->setText(index.model()->data(index.model()->index(index.row(),4,index),Qt::DisplayRole).toString());
return mimeData;
}
else{
return mimeData;
}
}
}
bool ServerFileModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
QString recipientPath;
// Get The Path of the destination
// Setup the recipients path
if (parent.isValid()){
// Check if item was dropped onto a folder or a file
if (parent.model()->data(parent.model()->index(parent.row(),4,parent),Qt::DisplayRole).toString() == QString("Folder")){
qDebug() << "Dropped onto Folder";
// Get path of folder
recipientPath = path + parent.model()->data(parent.model()->index(parent.row(),0,parent),Qt::DisplayRole).toString() + "/";
qDebug() << "PATH " << recipientPath;
}
// Dropped onto file
else {
recipientPath = path;
qDebug() << "PATH " << recipientPath;
}
}else {
// Dropped on blank space
recipientPath = path;
qDebug() << "PATH " << recipientPath;
}
// Get the path of the source file/folder
QList<QUrl> urls = data->urls();
QList<QUrl>::const_iterator it = urls.constBegin();
for (; it != urls.constEnd(); ++it) {
QString _path = (*it).toLocalFile();
//success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
qDebug() << "PATH OF SOURCE" << _path;
source = _path;
}
// Now The source + destination path's must be sent to the download manager, along with a flag that this is a upload action.
emit sendDropData("Upload",source,recipientPath,"");
/*
QByteArray encodedData = data->data("text/plain");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QString temp;
data->urls();
stream >> temp;
//QFile file(data->urls().b);
if (file.exists()){
qDebug() << "file exist";
}
QFileInfo info(file);
if (info.isDir()){
qDebug() << "Is a dir";
}
qDebug() << "TEMP" << data->urls() << " " << data->text();
*/
return true;
}
bool ServerFileModel::removeRows(int row, int count, const QModelIndex &parent)
{
qDebug() << "TESTING";
return true;
}
bool ServerFileModel::insertRows(int row, int count, const QModelIndex &parent)
{
qDebug() << "INSERTED";
return true;
}