diff options
| author | Alexander Blair <snipa@jagtech.io> | 2020-12-03 12:23:01 -0800 |
|---|---|---|
| committer | Alexander Blair <snipa@jagtech.io> | 2020-12-03 12:23:02 -0800 |
| commit | 2eeeadfd10011a771bf73ffe7c678c3532c0ca0d (patch) | |
| tree | 5848000c18f6758845b8c85c11a80249240beacc /src | |
| parent | 301b20d19ca2ff5702093c502c6048fc4a25c97e (diff) | |
| parent | ea1fee2f5f842a293458a66638c15ff79e1d101d (diff) | |
| download | monzero-gui-2eeeadfd10011a771bf73ffe7c678c3532c0ca0d.tar.gz monzero-gui-2eeeadfd10011a771bf73ffe7c678c3532c0ca0d.tar.xz monzero-gui-2eeeadfd10011a771bf73ffe7c678c3532c0ca0d.zip | |
Merge pull request #3251
ea1fee2f main: Linux - ask to create desktop entry on the first start (xiphon)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/main.cpp | 5 | ||||
| -rw-r--r-- | src/main/oshelper.cpp | 9 | ||||
| -rw-r--r-- | src/main/oshelper.h | 1 | ||||
| -rw-r--r-- | src/qt/utils.cpp | 48 | ||||
| -rw-r--r-- | src/qt/utils.h | 4 |
5 files changed, 43 insertions, 24 deletions
diff --git a/src/main/main.cpp b/src/main/main.cpp index 79e172ca..47369bd5 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -319,11 +319,6 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw return 1; } - // Desktop entry -#ifdef Q_OS_LINUX - registerXdgMime(app); -#endif - IPC *ipc = new IPC(&app); QStringList posArgs = parser.positionalArguments(); diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index 9b24262e..7584732e 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -46,11 +46,13 @@ #endif #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #include <X11/XKBlib.h> +#undef Bool #undef KeyPress #undef KeyRelease #undef FocusIn #undef FocusOut // #undef those Xlib #defines that conflict with QEvent::Type enum +#include "qt/utils.h" #endif #if defined(Q_OS_WIN) @@ -85,6 +87,13 @@ OSHelper::OSHelper(QObject *parent) : QObject(parent) } +void OSHelper::createDesktopEntry() const +{ +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + registerXdgMime(); +#endif +} + QString OSHelper::downloadLocation() const { return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); diff --git a/src/main/oshelper.h b/src/main/oshelper.h index f3bc4c04..96f58073 100644 --- a/src/main/oshelper.h +++ b/src/main/oshelper.h @@ -41,6 +41,7 @@ class OSHelper : public QObject public: explicit OSHelper(QObject *parent = 0); + Q_INVOKABLE void createDesktopEntry() const; Q_INVOKABLE QString downloadLocation() const; Q_INVOKABLE bool openContainingFolder(const QString &filePath) const; Q_INVOKABLE QString openSaveFileDialog(const QString &title, const QString &folder, const QString &filename) const; diff --git a/src/qt/utils.cpp b/src/qt/utils.cpp index 5d329f97..b7d649f4 100644 --- a/src/qt/utils.cpp +++ b/src/qt/utils.cpp @@ -27,7 +27,8 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QtCore> -#include <QApplication> +#include <QCoreApplication> +#include <QMessageBox> #include <QtGlobal> #include "TailsOS.h" @@ -88,7 +89,18 @@ QString getAccountName(){ } #ifdef Q_OS_LINUX -QString xdgMime(QApplication &app){ +bool askInstallDesktopEntry() +{ + QMessageBox msgBox( + QMessageBox::Question, + QObject::tr("Monero GUI"), + QObject::tr("Would you like to register Monero GUI Desktop entry?"), + QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + return msgBox.exec() == QMessageBox::Yes; +} + +QString xdgMime(){ return QString( "[Desktop Entry]\n" "Name=Monero GUI\n" @@ -105,32 +117,34 @@ QString xdgMime(QApplication &app){ "StartupNotify=true\n" "X-GNOME-Bugzilla-Bugzilla=GNOME\n" "X-GNOME-UsesNotifications=true\n" - ).arg(app.applicationFilePath()); + ).arg(QCoreApplication::applicationFilePath()); } -void registerXdgMime(QApplication &app){ +void registerXdgMime(){ // Register desktop entry // - MacOS handled via Info.plist // - Windows handled in the installer by rbrunner7 // - Linux written to `QStandardPaths::ApplicationsLocation` // - Tails written to persistent dotfiles - QString mime = xdgMime(app); + QString mime = xdgMime(); QString appPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); QString filePath = QString("%1/monero-gui.desktop").arg(appPath); - if (TailsOS::detect() && TailsOS::detectDotPersistence() && TailsOS::usePersistence) { - TailsOS::persistXdgMime(filePath, mime); - return; + if (TailsOS::detect()) + { + if (TailsOS::detectDotPersistence() && TailsOS::usePersistence) + { + TailsOS::persistXdgMime(filePath, mime); + } + } + else + { + if (askInstallDesktopEntry()) + { + QDir().mkpath(QFileInfo(filePath).path()); + fileWrite(filePath, mime); + } } - - QFileInfo file(filePath); - QDir().mkpath(file.path()); // ensure directory exists - -#ifdef QT_DEBUG - qDebug() << "Writing xdg mime: " << filePath; -#endif - - fileWrite(filePath, mime); } #endif diff --git a/src/qt/utils.h b/src/qt/utils.h index aace5d00..9eb58e22 100644 --- a/src/qt/utils.h +++ b/src/qt/utils.h @@ -39,8 +39,8 @@ QByteArray fileOpen(QString path); bool fileWrite(QString path, QString data); QString getAccountName(); #ifdef Q_OS_LINUX -QString xdgMime(QApplication &app); -void registerXdgMime(QApplication &app); +QString xdgMime(); +void registerXdgMime(); #endif const static QRegExp reURI = QRegExp("^\\w+:\\/\\/([\\w+\\-?\\-_\\-=\\-&]+)"); QString randomUserAgent(); |
