diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2019-07-16 11:35:16 -0500 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2019-07-16 11:35:16 -0500 |
| commit | beb94783c6536e58f4dd9505cd5c7430d8ca278c (patch) | |
| tree | e59e9bf4eaff9296b9c10a9d9a7207b565a2ae1c /src/qt/utils.cpp | |
| parent | cfec9dde968cb89f8fe5293958b82181348111ea (diff) | |
| parent | 0b6132897101c4cd1618c79049d5685c5e9874fa (diff) | |
| download | monzero-gui-beb94783c6536e58f4dd9505cd5c7430d8ca278c.tar.gz monzero-gui-beb94783c6536e58f4dd9505cd5c7430d8ca278c.tar.xz monzero-gui-beb94783c6536e58f4dd9505cd5c7430d8ca278c.zip | |
Merge pull request #2258
0b61328 Detect tails, support data persistence (xmrdsc)
Diffstat (limited to 'src/qt/utils.cpp')
| -rw-r--r-- | src/qt/utils.cpp | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/src/qt/utils.cpp b/src/qt/utils.cpp index 2407a50e..4418a050 100644 --- a/src/qt/utils.cpp +++ b/src/qt/utils.cpp @@ -27,15 +27,35 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QtCore> +#include <QApplication> +#include "src/qt/TailsOS.h" #include "utils.h" bool fileExists(QString path) { QFileInfo check_file(path); - if (check_file.exists() && check_file.isFile()) + return check_file.exists() && check_file.isFile(); +} + +QByteArray fileOpen(QString path) { + QFile file(path); + if(!file.open(QFile::ReadOnly | QFile::Text)) + return QByteArray(); + + QByteArray data = file.readAll(); + file.close(); + return data; +} + +bool fileWrite(QString path, QString data) { + QFile file(path); + if(file.open(QIODevice::WriteOnly)){ + QTextStream out(&file); out << data << endl; + file.close(); return true; - else - return false; + } + + return false; } QString getAccountName(){ @@ -47,6 +67,53 @@ QString getAccountName(){ return accountName; } +QString xdgMime(QApplication &app){ + return QString( + "[Desktop Entry]\n" + "Name=Monero GUI\n" + "GenericName=Monero-GUI\n" + "X-GNOME-FullName=Monero-GUI\n" + "Comment=Monero GUI\n" + "Keywords=Monero;\n" + "Exec=%1 %u\n" + "Terminal=false\n" + "Type=Application\n" + "Icon=monero\n" + "Categories=Network;GNOME;Qt;\n" + "MimeType=x-scheme-handler/monero;x-scheme-handler/moneroseed\n" + "StartupNotify=true\n" + "X-GNOME-Bugzilla-Bugzilla=GNOME\n" + "X-GNOME-UsesNotifications=true\n" + ).arg(app.applicationFilePath()); +} + +void registerXdgMime(QApplication &app){ +#ifdef Q_OS_LINUX + // 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 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; + } + + QFileInfo file(filePath); + QDir().mkpath(file.path()); // ensure directory exists + +#ifdef QT_DEBUG + qDebug() << "Writing xdg mime: " << filePath; +#endif + + fileWrite(filePath, mime); +#endif +} + QString randomUserAgent(){ QStringList urand; urand << "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1" |
