From 72b4cf55ffada8def81efc9750d6907d8e07f892 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 3 Mar 2018 12:29:35 +0100 Subject: [PATCH] DesktopFile: Add tryExec --- src/lib/tools/desktopfile.cpp | 11 +++++++++++ src/lib/tools/desktopfile.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/lib/tools/desktopfile.cpp b/src/lib/tools/desktopfile.cpp index b7b23b0ea..e185979c8 100644 --- a/src/lib/tools/desktopfile.cpp +++ b/src/lib/tools/desktopfile.cpp @@ -18,6 +18,7 @@ #include "desktopfile.h" #include +#include DesktopFile::DesktopFile() { @@ -80,3 +81,13 @@ QVariant DesktopFile::value(const QString &key, bool localized) const } return m_settings->value(key); } + +bool DesktopFile::tryExec() const +{ + if (!m_settings) { + return false; + } + + const QString exec = m_settings->value(QSL("TryExec")).toString(); + return exec.isEmpty() || !QStandardPaths::findExecutable(exec).isEmpty(); +} diff --git a/src/lib/tools/desktopfile.h b/src/lib/tools/desktopfile.h index ec561ef82..baf231a68 100644 --- a/src/lib/tools/desktopfile.h +++ b/src/lib/tools/desktopfile.h @@ -37,6 +37,8 @@ public: QString icon() const; QVariant value(const QString &key, bool localized = false) const; + bool tryExec() const; + private: QSharedPointer m_settings; };