From bf75704cac641a0e1b8e0347f22d595ca95fe83b Mon Sep 17 00:00:00 2001 From: nowrep Date: Wed, 13 Feb 2013 21:48:06 +0100 Subject: [PATCH] [RSS] Show for akregator/liferea in PATH instead of just in /usr/bin --- src/lib/rss/rssnotification.cpp | 17 ++++++++++------- src/lib/tools/qztools.cpp | 20 ++++++++++++++++++++ src/lib/tools/qztools.h | 2 ++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/lib/rss/rssnotification.cpp b/src/lib/rss/rssnotification.cpp index 4591d3413..2381c841d 100644 --- a/src/lib/rss/rssnotification.cpp +++ b/src/lib/rss/rssnotification.cpp @@ -24,13 +24,14 @@ #include "rssmanager.h" #include "settings.h" #include "webview.h" +#include "qztools.h" #include #include #include #include -bool startExternalProcess(const QString &program, const QStringList &arguments) +static bool startExternalProcess(const QString &program, const QStringList &arguments) { if (!QProcess::startDetached(program, arguments)) { QString info = "
  • " + RSSNotification::tr("Executable: ") + "" + program + "
  • " + RSSNotification::tr("Arguments: ") + "" + arguments.join(" ") + "
"; @@ -62,14 +63,16 @@ RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView* << RssApp("Yahoo!", "http://add.my.yahoo.com/rss?url=", QIcon(":/icons/sites/yahoo.png")); #ifdef QZ_WS_X11 - // TODO: Not really clever solution. - // It should look in PATH - if (QFile("/usr/bin/akregator").exists()) { - m_rssApps << RssApp("Akregator", "/usr/bin/akregator -a ", QIcon(":/icons/sites/akregator.png"), DesktopApplication); + const QString &akregatorBin = QzTools::resolveFromPath("akregator"); + const QString &lifereaBin = QzTools::resolveFromPath("liferea"); + const QString &lifereaAddFeedBin = QzTools::resolveFromPath("liferea-add-feed"); + + if (!akregatorBin.isEmpty()) { + m_rssApps << RssApp("Akregator", akregatorBin + " -a ", QIcon(":/icons/sites/akregator.png"), DesktopApplication); } - if (QFile("/usr/bin/liferea").exists() && QFile("/usr/bin/liferea-add-feed").exists()) { - m_rssApps << RssApp("Liferea", "/usr/bin/liferea-add-feed ", QIcon(":/icons/sites/liferea.png"), DesktopApplication); + if (!lifereaBin.isEmpty() && !lifereaAddFeedBin.isEmpty()) { + m_rssApps << RssApp("Liferea", lifereaAddFeedBin + " ", QIcon(":/icons/sites/liferea.png"), DesktopApplication); } #endif diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 434a75909..650ee6acb 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -362,6 +362,26 @@ QIcon QzTools::iconFromFileName(const QString &fileName) return icon; } +QString QT_QUPZILLA_EXPORT QzTools::resolveFromPath(const QString &name) +{ + const QString &path = qgetenv("PATH").trimmed(); + + if (path.isEmpty()) { + return QString(); + } + + QStringList dirs = path.split(QLatin1Char(':'), QString::SkipEmptyParts); + + foreach(const QString & dir, dirs) { + QDir d(dir); + if (d.exists(name)) { + return d.absoluteFilePath(name); + } + } + + return QString(); +} + // Qt5 migration help functions bool QzTools::isCertificateValid(const QSslCertificate &cert) { diff --git a/src/lib/tools/qztools.h b/src/lib/tools/qztools.h index fd3c07c87..85f04ae15 100644 --- a/src/lib/tools/qztools.h +++ b/src/lib/tools/qztools.h @@ -56,6 +56,8 @@ QString QT_QUPZILLA_EXPORT fileSizeToString(qint64 size); QPixmap QT_QUPZILLA_EXPORT createPixmapForSite(const QIcon &icon, const QString &title, const QString &url); QString QT_QUPZILLA_EXPORT applyDirectionToPage(QString &pageContents); +QString QT_QUPZILLA_EXPORT resolveFromPath(const QString &name); + QIcon QT_QUPZILLA_EXPORT iconFromFileName(const QString &fileName); QString QT_QUPZILLA_EXPORT buildSystem();