blob: 29e986b32e782c5443a488169e8752ec209abeec (
plain) (
blame)
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
|
//Chris Xiong 2022
//License: MPL-2.0
#include "utilities.hpp"
#include <QDesktopServices>
#include <QProcess>
#include <QUrl>
#include <QDebug>
#ifdef HAS_QTDBUS
#include <QDBusConnection>
#include <QDBusMessage>
#endif
#ifdef _WIN32
#include <QDir>
#endif
namespace utilities
{
QString fspath_to_qstring(const fs::path &p)
{
return fsstr_to_qstring(p.native());
}
QString fsstr_to_qstring(const fs::path::string_type &s)
{
#if PATH_VALSIZE == 2 //the degenerate platform
return QString::fromStdWString(s);
#else
return QString::fromStdString(s);
#endif
}
fs::path qstring_to_path(const QString &s)
{
#if PATH_VALSIZE == 2 //the degenerate platform
return fs::path(s.toStdWString());
#else
return fs::path(s.toStdString());
#endif
}
void open_containing_folder(const fs::path &path)
{
#ifdef _WIN32
QProcess::startDetached("explorer", QStringList() << "/select," << QDir::toNativeSeparators(fspath_to_qstring(path)));
#else
#ifdef HAS_QTDBUS
auto conn = QDBusConnection::sessionBus();
auto call = QDBusMessage::createMethodCall(
"org.freedesktop.FileManager1",
"/org/freedesktop/FileManager1",
"org.freedesktop.FileManager1",
"ShowItems"
);
QVariantList args = {
QStringList({fspath_to_qstring(path)}),
QString()
};
call.setArguments(args);
auto resp = conn.call(call, QDBus::CallMode::Block, 500);
if (resp.type() != QDBusMessage::MessageType::ErrorMessage)
return;
#endif
auto par = (path / "../").lexically_normal();
QDesktopServices::openUrl(QUrl::fromLocalFile(fspath_to_qstring(par)));
#endif
}
};
|