-
-
Notifications
You must be signed in to change notification settings - Fork 893
/
Copy pathDesktopServices.cpp
65 lines (55 loc) · 1.93 KB
/
DesktopServices.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
58
59
60
61
62
63
64
65
#include "DesktopServices.h"
#include <QDir>
#include <QDesktopServices>
#include <QProcess>
#include <QDebug>
#include "FileSystem.h"
namespace DesktopServices {
bool openDirectory(const QString &path)
{
QUrl url = QUrl::fromLocalFile(path);
QString urlString = url.toString(QUrl::FullyEncoded);
qDebug() << "Opening directory" << path << "url" << urlString;
if(!FS::ensureFolderPathExists(path))
{
qDebug() << "Failed to create directory for opening:" << path << "url" << urlString;
return false;
}
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
return QProcess::startDetached("xdg-open", QStringList() << urlString);
#else
return QDesktopServices::openUrl(url);
#endif
}
bool openFile(const QString &path)
{
QUrl url = QUrl::fromLocalFile(path);
QString urlString = url.toString(QUrl::FullyEncoded);
qDebug() << "Opening file" << path << " url " << urlString;
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
return QProcess::startDetached("xdg-open", QStringList() << urlString);
#else
return QDesktopServices::openUrl(url);
#endif
}
bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid)
{
qDebug() << "Opening file" << path << "using" << application;
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
}
bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid)
{
qDebug() << "Running" << application << "with args" << args.join(' ');
return QProcess::startDetached(application, args, workingDirectory, pid);
}
bool openUrl(const QUrl &url)
{
QString urlString = url.toString(QUrl::FullyEncoded);
qDebug() << "Opening URL" << urlString;
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
return QProcess::startDetached("xdg-open", QStringList() << urlString);
#else
return QDesktopServices::openUrl(url);
#endif
}
}