Skip to content

Commit

Permalink
Support arguments for the external download program
Browse files Browse the repository at this point in the history
  • Loading branch information
kreed authored and icefox committed Feb 1, 2010
1 parent 58950bf commit 0405e86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/downloadmanager.cpp
Expand Up @@ -527,7 +527,15 @@ bool DownloadManager::externalDownload(const QUrl &url)
if (program.isEmpty())
return false;

return QProcess::startDetached(program, QStringList() << QString::fromUtf8(url.toEncoded()));
// Split program at every space not inside double quotes
QRegExp regex(QLatin1String("\"([^\"]+)\"|([^ ]+)"));
QStringList args;
for (int pos = 0; (pos = regex.indexIn(program, pos)) != -1; pos += regex.matchedLength())
args << regex.cap(1) + regex.cap(2);
if (args.isEmpty())
return false;

return QProcess::startDetached(args.takeFirst(), args << QString::fromUtf8(url.toEncoded()));
}

void DownloadManager::download(const QNetworkRequest &request, bool requestFileName)
Expand Down
2 changes: 2 additions & 0 deletions src/settings.cpp
Expand Up @@ -484,6 +484,8 @@ void SettingsDialog::chooseDownloadDirectory()
void SettingsDialog::chooseDownloadProgram()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Program"), externalDownloadPath->text());
if (fileName.contains(QLatin1Char(' ')))
fileName = QString(QLatin1String("\"%1\"")).arg(fileName);
externalDownloadPath->setText(fileName);
}

Expand Down

0 comments on commit 0405e86

Please sign in to comment.