1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fixed parsing arguments when starting external applications.

When starting external RSS readers and external download managers.
This commit is contained in:
nowrep 2013-02-15 12:29:13 +01:00
parent 5641d380d8
commit 68e0831bdb
6 changed files with 80 additions and 52 deletions

View File

@ -35,7 +35,6 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QDesktopServices>
#include <QProcess>
#ifdef Q_OS_WIN
#include "Shlwapi.h"

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,10 +30,9 @@
#include "downloadfilehelper.h"
#include "settings.h"
#include <QMessageBox>
#include <QCloseEvent>
#include <QDir>
#include <QProcess>
#include <QMessageBox>
DownloadManager::DownloadManager(QWidget* parent)
: QWidget(parent)
@ -102,16 +101,7 @@ void DownloadManager::keyPressEvent(QKeyEvent* e)
void DownloadManager::startExternalManager(const QUrl &url)
{
QStringList arguments = m_externalArguments.split(QLatin1Char(' '), QString::SkipEmptyParts);
arguments << url.toString();
bool success = QProcess::startDetached(m_externalExecutable, arguments);
if (!success) {
QString info = "<ul><li><b>" + tr("Executable: ") + "</b>" + m_externalExecutable + "</li><li><b>" + tr("Arguments: ") + "</b>" + arguments.join(" ") + "</li></ul>";
QMessageBox::critical(this, tr("Cannot start external download manager"), tr("Cannot start external download manager! %1").arg(info));
}
QzTools::startExternalProcess(m_externalExecutable, m_externalArguments);
m_lastDownloadOption = ExternalManager;
}

View File

@ -28,21 +28,8 @@
#include <QMessageBox>
#include <QClipboard>
#include <QProcess>
#include <QFile>
static bool startExternalProcess(const QString &program, const QStringList &arguments)
{
if (!QProcess::startDetached(program, arguments)) {
QString info = "<ul><li><b>" + RSSNotification::tr("Executable: ") + "</b>" + program + "</li><li><b>" + RSSNotification::tr("Arguments: ") + "</b>" + arguments.join(" ") + "</li></ul>";
QMessageBox::critical(0, RSSNotification::tr("Cannot start external program"), RSSNotification::tr("Cannot start external program! %1").arg(info));
return false;
}
return true;
}
RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView* parent)
: AnimatedWidget(AnimatedWidget::Down, 300, parent)
, ui(new Ui::RSSNotification)
@ -56,11 +43,37 @@ RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView*
ui->closeButton->setIcon(qIconProvider->standardIcon(QStyle::SP_DialogCloseButton));
ui->label->setText(tr("RSS feed <b>\"%1\"</b>").arg(title));
m_rssApps << RssApp("Bloglines", "http://www.bloglines.com/sub?url=", QIcon(":/icons/sites/bloglines.png"))
<< RssApp("Google Reader", "http://www.google.com/ig/add?feedurl=", QIcon(":/icons/sites/google.png"))
<< RssApp("My AOL", "http://feeds.my.aol.com/add.jsp?url=", QIcon(":/icons/sites/aol.png"))
<< RssApp("Netvibes", "http://www.netvibes.com/subscribe.php?url=", QIcon(":/icons/sites/netvibes.png"))
<< RssApp("Yahoo!", "http://add.my.yahoo.com/rss?url=", QIcon(":/icons/sites/yahoo.png"));
RssApp bloglines;
bloglines.type = WebApplication;
bloglines.title = "Bloglines";
bloglines.icon = QIcon(":/icons/sites/bloglines.png");
bloglines.address = "http://www.bloglines.com/sub?url=";
RssApp greader;
greader.type = WebApplication;
greader.title = "Google Reader";
greader.icon = QIcon(":/icons/sites/google.png");
greader.address = "http://www.google.com/ig/add?feedurl=";
RssApp myaol;
myaol.type = WebApplication;
myaol.title = "My AOL";
myaol.icon = QIcon(":/icons/sites/aol.png");
myaol.address = "http://feeds.my.aol.com/add.jsp?url=";
RssApp netvibes;
netvibes.type = WebApplication;
netvibes.title = "Netvibes";
netvibes.icon = QIcon(":/icons/sites/netvibes.png");
netvibes.address = "http://www.netvibes.com/subscribe.php?url=";
RssApp yahoo;
yahoo.type = WebApplication;
yahoo.title = "Yahoo!";
yahoo.icon = QIcon(":/icons/sites/yahoo.png");
yahoo.address = "http://add.my.yahoo.com/rss?url=";
m_rssApps << bloglines << greader << myaol << netvibes << yahoo;
#ifdef QZ_WS_X11
const QString &akregatorBin = QzTools::resolveFromPath("akregator");
@ -68,11 +81,24 @@ RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView*
const QString &lifereaAddFeedBin = QzTools::resolveFromPath("liferea-add-feed");
if (!akregatorBin.isEmpty()) {
m_rssApps << RssApp("Akregator", akregatorBin + " -a ", QIcon(":/icons/sites/akregator.png"), DesktopApplication);
RssApp akregator;
akregator.type = DesktopApplication;
akregator.title = "Akregator";
akregator.icon = QIcon(":/icons/sites/akregator.png");
akregator.executable = akregatorBin;
akregator.arguments = "-a";
m_rssApps << akregator;
}
if (!lifereaBin.isEmpty() && !lifereaAddFeedBin.isEmpty()) {
m_rssApps << RssApp("Liferea", lifereaAddFeedBin + " ", QIcon(":/icons/sites/liferea.png"), DesktopApplication);
RssApp liferea;
liferea.type = DesktopApplication;
liferea.title = "Liferea";
liferea.icon = QIcon(":/icons/sites/liferea.png");
liferea.executable = lifereaAddFeedBin;
m_rssApps << liferea;
}
#endif
@ -117,18 +143,15 @@ void RSSNotification::addRss()
case DesktopApplication: {
const RssApp app = m_rssApps.at(index);
if (app.title == QLatin1String("Akregator")) {
success = startExternalProcess("/usr/bin/akregator", QStringList() << "-a" << m_url.toEncoded());
}
else if (app.title == QLatin1String("Liferea")) {
if (app.title == QLatin1String("Liferea")) {
if (!ProcessInfo("liferea").isRunning()) {
QMessageBox::warning(this, tr("Liferea not running"), tr("Liferea must be running in order to add new feed."));
success = false;
}
else {
success = startExternalProcess("/usr/bin/liferea-add-feed", QStringList(m_url.toEncoded()));
break;
}
}
const QString &arguments = QString("%1 %2").arg(app.arguments, QString::fromUtf8(m_url.toEncoded()));
success = QzTools::startExternalProcess(app.executable, arguments);
break;
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,17 +47,12 @@ private slots:
private:
enum AppType { WebApplication, DesktopApplication, Internal, Other };
struct RssApp {
QString title;
QString address;
QIcon icon;
AppType type;
RssApp(const QString &t, const QString &a, const QIcon &i, AppType ty = WebApplication) {
title = t;
address = a;
icon = i;
type = ty;
}
QString title;
QIcon icon;
QString address;
QString executable;
QString arguments;
};
Ui::RSSNotification* ui;

View File

@ -36,6 +36,8 @@
#include <QTemporaryFile>
#include <QHash>
#include <QSysInfo>
#include <QProcess>
#include <QMessageBox>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
@ -548,6 +550,24 @@ QStringList QzTools::splitCommandArguments(const QString &command)
return r;
}
bool QzTools::startExternalProcess(const QString &executable, const QString &args)
{
const QStringList &arguments = splitCommandArguments(args);
bool success = QProcess::startDetached(executable, arguments);
if (!success) {
QString info = "<ul><li><b>%1</b>%2</li><li><b>%3</b>%4</li></ul>";
info = info.arg(QObject::tr("Executable: "), executable,
QObject::tr("Arguments: "), arguments.join(QLatin1String(" ")));
QMessageBox::critical(0, QObject::tr("Cannot start external program"),
QObject::tr("Cannot start external program! %1").arg(info));
}
return success;
}
// Qt5 migration help functions
bool QzTools::isCertificateValid(const QSslCertificate &cert)
{

View File

@ -58,6 +58,7 @@ QString QT_QUPZILLA_EXPORT applyDirectionToPage(QString &pageContents);
QString QT_QUPZILLA_EXPORT resolveFromPath(const QString &name);
QStringList QT_QUPZILLA_EXPORT splitCommandArguments(const QString &command);
bool QT_QUPZILLA_EXPORT startExternalProcess(const QString &executable, const QString &args);
QIcon QT_QUPZILLA_EXPORT iconFromFileName(const QString &fileName);
bool QT_QUPZILLA_EXPORT isUtf8(const char* string);