forked from Public/monero-gui
Merge pull request #2580
ba24fd7SettingsInfo: open containing folder on wallet log path click (xiphon)088d32eOSHelper: file preselection support (Windows and Mac) (xiphon)
This commit is contained in:
@@ -132,14 +132,21 @@ Rectangle {
|
|||||||
|
|
||||||
MoneroComponents.TextBlock {
|
MoneroComponents.TextBlock {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.maximumWidth: 360
|
|
||||||
color: MoneroComponents.Style.dimmedFontColor
|
color: MoneroComponents.Style.dimmedFontColor
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
text: {
|
property string walletPath: (isIOS ? moneroAccountsDir : "") + appWindow.walletPath()
|
||||||
var wallet_path = walletPath();
|
text: "\
|
||||||
if(isIOS)
|
<style type='text/css'>\
|
||||||
wallet_path = moneroAccountsDir + wallet_path;
|
a {cursor:pointer;text-decoration: none; color: #FF6C3C}\
|
||||||
return wallet_path;
|
</style>\
|
||||||
|
<a href='#'>%1</a>".arg(walletPath)
|
||||||
|
textFormat: Text.RichText
|
||||||
|
onLinkActivated: oshelper.openContainingFolder(walletPath)
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
acceptedButtons: Qt.NoButton
|
||||||
|
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +268,19 @@ Rectangle {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
color: MoneroComponents.Style.dimmedFontColor
|
color: MoneroComponents.Style.dimmedFontColor
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
text: walletLogPath
|
text: "\
|
||||||
|
<style type='text/css'>\
|
||||||
|
a {cursor:pointer;text-decoration: none; color: #FF6C3C}\
|
||||||
|
</style>\
|
||||||
|
<a href='#'>%1</a>".arg(walletLogPath)
|
||||||
|
textFormat: Text.RichText
|
||||||
|
onLinkActivated: oshelper.openContainingFolder(walletLogPath)
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
acceptedButtons: Qt.NoButton
|
||||||
|
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|||||||
@@ -30,11 +30,15 @@
|
|||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QUrl>
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include "qt/macoshelper.h"
|
#include "qt/macoshelper.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN
|
||||||
|
#include <Shlobj.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||||
@@ -46,11 +50,61 @@
|
|||||||
// #undef those Xlib #defines that conflict with QEvent::Type enum
|
// #undef those Xlib #defines that conflict with QEvent::Type enum
|
||||||
#endif
|
#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)
|
OSHelper::OSHelper(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSHelper::openContainingFolder(const QString &filePath) const
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
if (openFolderAndSelectItem(QDir::toNativeSeparators(filePath)))
|
||||||
|
{
|
||||||
|
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(url);
|
||||||
|
}
|
||||||
|
|
||||||
QString OSHelper::temporaryFilename() const
|
QString OSHelper::temporaryFilename() const
|
||||||
{
|
{
|
||||||
QString tempFileName;
|
QString tempFileName;
|
||||||
@@ -76,7 +130,7 @@ bool OSHelper::removeTemporaryWallet(const QString &fileName) const
|
|||||||
bool OSHelper::isCapsLock() const
|
bool OSHelper::isCapsLock() const
|
||||||
{
|
{
|
||||||
// platform dependent method of determining if CAPS LOCK is on
|
// 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;
|
return GetKeyState(VK_CAPITAL) == 1;
|
||||||
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) // X11 version
|
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) // X11 version
|
||||||
Display * d = XOpenDisplay((char*)0);
|
Display * d = XOpenDisplay((char*)0);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class OSHelper : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit OSHelper(QObject *parent = 0);
|
explicit OSHelper(QObject *parent = 0);
|
||||||
|
|
||||||
|
Q_INVOKABLE bool openContainingFolder(const QString &filePath) const;
|
||||||
Q_INVOKABLE QString temporaryFilename() const;
|
Q_INVOKABLE QString temporaryFilename() const;
|
||||||
Q_INVOKABLE QString temporaryPath() const;
|
Q_INVOKABLE QString temporaryPath() const;
|
||||||
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
|
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class MacOSHelper
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static bool isCapsLock();
|
static bool isCapsLock();
|
||||||
|
static bool openFolderAndSelectItem(const QUrl &path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MACOSHELPER_H
|
#endif //MACOSHELPER_H
|
||||||
|
|||||||
@@ -47,3 +47,11 @@ bool MacOSHelper::isCapsLock()
|
|||||||
return (flags & NSAlphaShiftKeyMask);
|
return (flags & NSAlphaShiftKeyMask);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MacOSHelper::openFolderAndSelectItem(const QUrl &path)
|
||||||
|
{
|
||||||
|
NSURL *nspath = path.toNSURL();
|
||||||
|
NSArray *fileURLs = [NSArray arrayWithObjects:nspath, nil];
|
||||||
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user