diff options
author | 2022-09-30 23:58:46 -0400 | |
---|---|---|
committer | 2022-09-30 23:59:21 -0400 | |
commit | e25c84c0463f5a43d3b2bb836850f5c5963a2846 (patch) | |
tree | 504c65782410c5ead34b0941449a9abaa9c23001 /qdeduper/utilities.cpp | |
parent | b6c8082dfc854b58cae798a6150681f7b9a343d3 (diff) | |
download | deduper-e25c84c0463f5a43d3b2bb836850f5c5963a2846.tar.xz |
Add context menu for the image view.
Shortcuts are currently broken. Will be fixed in future commits.
Diffstat (limited to 'qdeduper/utilities.cpp')
-rw-r--r-- | qdeduper/utilities.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/qdeduper/utilities.cpp b/qdeduper/utilities.cpp new file mode 100644 index 0000000..a2af953 --- /dev/null +++ b/qdeduper/utilities.cpp @@ -0,0 +1,65 @@ +#include "utilities.hpp" + +#include <QDesktopServices> +#include <QProcess> +#include <QUrl> +#include <QDebug> +#ifdef HAS_QTDBUS +#include <QDBusConnection> +#include <QDBusMessage> +#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(fileInfo.absoluteFilePath())); +#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 +#endif + auto par = (path / "../").lexically_normal(); + QDesktopServices::openUrl(QUrl::fromLocalFile(fspath_to_qstring(par))); +} + +}; |