From 88881de8c681d53965bc5d06ff904bad2b3b7e76 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 14 Mar 2018 00:47:00 +0800 Subject: [PATCH] Add Tags parameter to "Run External Program" Closes #8586. Also sort headers. --- src/app/application.cpp | 61 +++++++++++-------- src/app/application.h | 2 +- src/gui/optionsdlg.cpp | 9 +-- .../www/private/preferences_content.html | 1 + 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 11f7f211f..4f79a600f 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -27,28 +27,51 @@ * exception statement from your version. */ +#include "application.h" + +#include + +#include #include #include -#include #include -#include +#include #include -#include +#include + +#include "base/bittorrent/session.h" +#include "base/bittorrent/torrenthandle.h" +#include "base/iconprovider.h" +#include "base/logger.h" +#include "base/net/downloadmanager.h" +#include "base/net/geoipmanager.h" +#include "base/net/proxyconfigurationmanager.h" +#include "base/net/smtp.h" +#include "base/preferences.h" +#include "base/profile.h" +#include "base/rss/rss_autodownloader.h" +#include "base/rss/rss_session.h" +#include "base/scanfoldersmodel.h" +#include "base/settingsstorage.h" +#include "base/utils/fs.h" +#include "base/utils/misc.h" +#include "base/utils/string.h" +#include "filelogger.h" #ifndef DISABLE_GUI -#include "gui/guiiconprovider.h" #ifdef Q_OS_WIN #include -#include #include +#include #endif // Q_OS_WIN #ifdef Q_OS_MAC #include #include #include #endif // Q_OS_MAC -#include "mainwindow.h" #include "addnewtorrentdialog.h" +#include "gui/guiiconprovider.h" +#include "mainwindow.h" #include "shutdownconfirmdlg.h" #else // DISABLE_GUI #include @@ -58,25 +81,6 @@ #include "webui/webui.h" #endif -#include "application.h" -#include "filelogger.h" -#include "base/logger.h" -#include "base/preferences.h" -#include "base/settingsstorage.h" -#include "base/profile.h" -#include "base/utils/fs.h" -#include "base/utils/misc.h" -#include "base/iconprovider.h" -#include "base/scanfoldersmodel.h" -#include "base/net/smtp.h" -#include "base/net/downloadmanager.h" -#include "base/net/geoipmanager.h" -#include "base/net/proxyconfigurationmanager.h" -#include "base/bittorrent/session.h" -#include "base/bittorrent/torrenthandle.h" -#include "base/rss/rss_autodownloader.h" -#include "base/rss/rss_session.h" - namespace { #define SETTINGS_KEY(name) "Application/" name @@ -269,11 +273,16 @@ void Application::processMessage(const QString &message) m_paramsQueue.append(params); } -void Application::runExternalProgram(BitTorrent::TorrentHandle *const torrent) const +void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) const { QString program = Preferences::instance()->getAutoRunProgram(); program.replace("%N", torrent->name()); program.replace("%L", torrent->category()); + + QStringList tags = torrent->tags().toList(); + std::sort(tags.begin(), tags.end(), Utils::String::naturalLessThan); + program.replace("%G", tags.join(',')); + program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath())); program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath())); program.replace("%D", Utils::Fs::toNativePath(torrent->savePath())); diff --git a/src/app/application.h b/src/app/application.h index a2239e02d..b163ea602 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -146,7 +146,7 @@ private: void initializeTranslation(); void processParams(const QStringList ¶ms); - void runExternalProgram(BitTorrent::TorrentHandle *const torrent) const; + void runExternalProgram(const BitTorrent::TorrentHandle *torrent) const; void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent); void validateCommandLineParameters(); }; diff --git a/src/gui/optionsdlg.cpp b/src/gui/optionsdlg.cpp index a8d11efe2..ab2ae662e 100644 --- a/src/gui/optionsdlg.cpp +++ b/src/gui/optionsdlg.cpp @@ -272,17 +272,18 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->autoRunBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->autoRun_txt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); - const QString autoRunStr = QString("%1\n %2\n %3\n %4\n %5\n %6\n %7\n %8\n %9\n %10\n%11") + const QString autoRunStr = QString("%1\n %2\n %3\n %4\n %5\n %6\n %7\n %8\n %9\n %10\n %11\n%12") .arg(tr("Supported parameters (case sensitive):") , tr("%N: Torrent name") , tr("%L: Category") + , tr("%G: Tags (seperated by comma)") , tr("%F: Content path (same as root path for multifile torrent)") , tr("%R: Root path (first torrent subdirectory path)") , tr("%D: Save path") , tr("%C: Number of files") - , tr("%Z: Torrent size (bytes)") - , tr("%T: Current tracker")) - .arg(tr("%I: Info hash") + , tr("%Z: Torrent size (bytes)")) + .arg(tr("%T: Current tracker") + , tr("%I: Info hash") , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")")); m_ui->autoRun_param->setText(autoRunStr); diff --git a/src/webui/www/private/preferences_content.html b/src/webui/www/private/preferences_content.html index 74ba9a91f..3c28f8320 100644 --- a/src/webui/www/private/preferences_content.html +++ b/src/webui/www/private/preferences_content.html @@ -74,6 +74,7 @@
  • QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]
  • +
  • QBT_TR(%G: Tags (seperated by comma))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]