-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (46 loc) · 1.29 KB
/
main.cpp
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
#include <QDebug>
#include <QDrag>
#include <QMimeData>
#include <QList>
#include <QUrl>
#include <QDir>
#include <QFile>
#include <QCoreApplication>
#include <QMainWindow>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
auto name = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
auto args = QCoreApplication::arguments();
args.removeAt(0);
if (args.length() < 1) {
qWarning() << "Error: No files provided";
return 1;
}
QDir dir = QDir::current();
QList<QUrl> files;
foreach (QString arg, args) {
auto filePath = QDir::cleanPath(dir.absoluteFilePath(arg));
QFile file;
file.setFileName(filePath);
if (!file.exists()) {
qWarning().noquote() << name + ": cannot access"
<< "'" + dir.relativeFilePath(filePath) + "':"
<< "No such file or directory";
continue;
}
files.append(QUrl::fromLocalFile(filePath));
}
if (files.length() < 1) {
qWarning() << "Error: No files to drag";
return 1;
}
QMainWindow w;
QDrag drag(&w);
QMimeData *mimeData = new QMimeData;
mimeData->setUrls(files);
drag.setMimeData(mimeData);
drag.exec();
return 0;
}