From ba24fd79bb50ff82f0fd94a5c0bd06f2130f3bd7 Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 10 Dec 2019 00:42:48 +0000 Subject: [PATCH 1/2] SettingsInfo: open containing folder on wallet log path click --- pages/settings/SettingsInfo.qml | 33 ++++++++++++++++++++++++++------- src/main/oshelper.cpp | 16 ++++++++++++++++ src/main/oshelper.h | 1 + 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/pages/settings/SettingsInfo.qml b/pages/settings/SettingsInfo.qml index c7ca7dc0..3d5f779b 100644 --- a/pages/settings/SettingsInfo.qml +++ b/pages/settings/SettingsInfo.qml @@ -132,14 +132,21 @@ Rectangle { MoneroComponents.TextBlock { Layout.fillWidth: true - Layout.maximumWidth: 360 color: MoneroComponents.Style.dimmedFontColor font.pixelSize: 14 - text: { - var wallet_path = walletPath(); - if(isIOS) - wallet_path = moneroAccountsDir + wallet_path; - return wallet_path; + property string walletPath: (isIOS ? moneroAccountsDir : "") + appWindow.walletPath() + text: "\ + \ + %1".arg(walletPath) + textFormat: Text.RichText + onLinkActivated: oshelper.openContainingFolder(walletPath) + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.NoButton + cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor } } @@ -262,7 +269,19 @@ Rectangle { Layout.fillWidth: true color: MoneroComponents.Style.dimmedFontColor font.pixelSize: 14 - text: walletLogPath + text: "\ + \ + %1".arg(walletLogPath) + textFormat: Text.RichText + onLinkActivated: oshelper.openContainingFolder(walletLogPath) + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.NoButton + cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor + } } Rectangle { diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index c1326c0f..313fd233 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -30,7 +30,10 @@ #include #include #include +#include +#include #include +#include #ifdef Q_OS_MAC #include "qt/macoshelper.h" #endif @@ -51,6 +54,19 @@ OSHelper::OSHelper(QObject *parent) : QObject(parent) } +bool OSHelper::openContainingFolder(const QString &filePath) const +{ + QUrl prepared; + prepared.setScheme("file"); + prepared.setPath(QFileInfo(filePath).absolutePath()); + if (!prepared.isValid()) + { + qWarning() << "malformed file path" << filePath << prepared.errorString(); + return false; + } + return QDesktopServices::openUrl(prepared); +} + QString OSHelper::temporaryFilename() const { QString tempFileName; diff --git a/src/main/oshelper.h b/src/main/oshelper.h index 4d378a9d..72f284af 100644 --- a/src/main/oshelper.h +++ b/src/main/oshelper.h @@ -39,6 +39,7 @@ class OSHelper : public QObject public: explicit OSHelper(QObject *parent = 0); + Q_INVOKABLE bool openContainingFolder(const QString &filePath) const; Q_INVOKABLE QString temporaryFilename() const; Q_INVOKABLE QString temporaryPath() const; Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const; From 088d32e712a2c6e51a04f919c0ade96b643a49e3 Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 12 Dec 2019 01:21:49 +0000 Subject: [PATCH 2/2] OSHelper: file preselection support (Windows and Mac) Co-authored-by: selsta --- src/main/oshelper.cpp | 54 ++++++++++++++++++++++++++++++++++++------- src/qt/macoshelper.h | 1 + src/qt/macoshelper.mm | 8 +++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index 313fd233..4402db6d 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -37,7 +37,8 @@ #ifdef Q_OS_MAC #include "qt/macoshelper.h" #endif -#ifdef Q_OS_WIN32 +#ifdef Q_OS_WIN +#include #include #endif #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) @@ -49,6 +50,33 @@ // #undef those Xlib #defines that conflict with QEvent::Type enum #endif +#if defined(Q_OS_WIN) +bool openFolderAndSelectItem(const QString &filePath) +{ + struct scope { + ~scope() { ::CoTaskMemFree(pidl); } + PIDLIST_ABSOLUTE pidl = nullptr; + } scope; + + SFGAOF flags; + HRESULT result = ::SHParseDisplayName(filePath.toStdWString().c_str(), nullptr, &scope.pidl, 0, &flags); + if (result != S_OK) + { + qWarning() << "SHParseDisplayName failed" << result << "file path" << filePath; + return false; + } + + result = ::SHOpenFolderAndSelectItems(scope.pidl, 0, nullptr, 0); + if (result != S_OK) + { + qWarning() << "SHOpenFolderAndSelectItems failed" << result << "file path" << filePath; + return false; + } + + return true; +} +#endif + OSHelper::OSHelper(QObject *parent) : QObject(parent) { @@ -56,15 +84,25 @@ OSHelper::OSHelper(QObject *parent) : QObject(parent) bool OSHelper::openContainingFolder(const QString &filePath) const { - QUrl prepared; - prepared.setScheme("file"); - prepared.setPath(QFileInfo(filePath).absolutePath()); - if (!prepared.isValid()) +#if defined(Q_OS_WIN) + if (openFolderAndSelectItem(QDir::toNativeSeparators(filePath))) { - qWarning() << "malformed file path" << filePath << prepared.errorString(); + return true; + } +#elif defined(Q_OS_MAC) + if (MacOSHelper::openFolderAndSelectItem(QUrl::fromLocalFile(filePath))) + { + return true; + } +#endif + + QUrl url = QUrl::fromLocalFile(QFileInfo(filePath).absolutePath()); + if (!url.isValid()) + { + qWarning() << "Malformed file path" << filePath << url.errorString(); return false; } - return QDesktopServices::openUrl(prepared); + return QDesktopServices::openUrl(url); } QString OSHelper::temporaryFilename() const @@ -92,7 +130,7 @@ bool OSHelper::removeTemporaryWallet(const QString &fileName) const bool OSHelper::isCapsLock() const { // platform dependent method of determining if CAPS LOCK is on -#if defined(Q_OS_WIN32) // MS Windows version +#if defined(Q_OS_WIN) // MS Windows version return GetKeyState(VK_CAPITAL) == 1; #elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) // X11 version Display * d = XOpenDisplay((char*)0); diff --git a/src/qt/macoshelper.h b/src/qt/macoshelper.h index bddf70c6..a6caa79b 100644 --- a/src/qt/macoshelper.h +++ b/src/qt/macoshelper.h @@ -35,6 +35,7 @@ class MacOSHelper public: static bool isCapsLock(); + static bool openFolderAndSelectItem(const QUrl &path); }; #endif //MACOSHELPER_H diff --git a/src/qt/macoshelper.mm b/src/qt/macoshelper.mm index 0b29f25f..a7fb061d 100644 --- a/src/qt/macoshelper.mm +++ b/src/qt/macoshelper.mm @@ -47,3 +47,11 @@ bool MacOSHelper::isCapsLock() return (flags & NSAlphaShiftKeyMask); #endif } + +bool MacOSHelper::openFolderAndSelectItem(const QUrl &path) +{ + NSURL *nspath = path.toNSURL(); + NSArray *fileURLs = [NSArray arrayWithObjects:nspath, nil]; + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs]; + return true; +}