Browse Source

Add Tags parameter to "Run External Program"

Closes #8586.
Also sort headers.
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
88881de8c6
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 61
      src/app/application.cpp
  2. 2
      src/app/application.h
  3. 9
      src/gui/optionsdlg.cpp
  4. 1
      src/webui/www/private/preferences_content.html

61
src/app/application.cpp

@ -27,28 +27,51 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "application.h"
#include <algorithm>
#include <QAtomicInt>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QLocale>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QSysInfo> #include <QLocale>
#include <QProcess> #include <QProcess>
#include <QAtomicInt> #include <QSysInfo>
#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 #ifndef DISABLE_GUI
#include "gui/guiiconprovider.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include <QSharedMemory>
#include <QSessionManager> #include <QSessionManager>
#include <QSharedMemory>
#endif // Q_OS_WIN #endif // Q_OS_WIN
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QFileOpenEvent> #include <QFileOpenEvent>
#include <QFont> #include <QFont>
#include <QUrl> #include <QUrl>
#endif // Q_OS_MAC #endif // Q_OS_MAC
#include "mainwindow.h"
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include "gui/guiiconprovider.h"
#include "mainwindow.h"
#include "shutdownconfirmdlg.h" #include "shutdownconfirmdlg.h"
#else // DISABLE_GUI #else // DISABLE_GUI
#include <iostream> #include <iostream>
@ -58,25 +81,6 @@
#include "webui/webui.h" #include "webui/webui.h"
#endif #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 namespace
{ {
#define SETTINGS_KEY(name) "Application/" name #define SETTINGS_KEY(name) "Application/" name
@ -269,11 +273,16 @@ void Application::processMessage(const QString &message)
m_paramsQueue.append(params); 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(); QString program = Preferences::instance()->getAutoRunProgram();
program.replace("%N", torrent->name()); program.replace("%N", torrent->name());
program.replace("%L", torrent->category()); program.replace("%L", torrent->category());
QStringList tags = torrent->tags().toList();
std::sort(tags.begin(), tags.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
program.replace("%G", tags.join(','));
program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath())); program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath()));
program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath())); program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath()));
program.replace("%D", Utils::Fs::toNativePath(torrent->savePath())); program.replace("%D", Utils::Fs::toNativePath(torrent->savePath()));

2
src/app/application.h

@ -146,7 +146,7 @@ private:
void initializeTranslation(); void initializeTranslation();
void processParams(const QStringList &params); void processParams(const QStringList &params);
void runExternalProgram(BitTorrent::TorrentHandle *const torrent) const; void runExternalProgram(const BitTorrent::TorrentHandle *torrent) const;
void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent); void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent);
void validateCommandLineParameters(); void validateCommandLineParameters();
}; };

9
src/gui/optionsdlg.cpp

@ -272,17 +272,18 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->autoRunBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->autoRunBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->autoRun_txt, &QLineEdit::textChanged, 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):") .arg(tr("Supported parameters (case sensitive):")
, tr("%N: Torrent name") , tr("%N: Torrent name")
, tr("%L: Category") , tr("%L: Category")
, tr("%G: Tags (seperated by comma)")
, tr("%F: Content path (same as root path for multifile torrent)") , tr("%F: Content path (same as root path for multifile torrent)")
, tr("%R: Root path (first torrent subdirectory path)") , tr("%R: Root path (first torrent subdirectory path)")
, tr("%D: Save path") , tr("%D: Save path")
, tr("%C: Number of files") , tr("%C: Number of files")
, tr("%Z: Torrent size (bytes)") , tr("%Z: Torrent size (bytes)"))
, tr("%T: Current tracker")) .arg(tr("%T: Current tracker")
.arg(tr("%I: Info hash") , tr("%I: Info hash")
, tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")")); , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
m_ui->autoRun_param->setText(autoRunStr); m_ui->autoRun_param->setText(autoRunStr);

1
src/webui/www/private/preferences_content.html

@ -74,6 +74,7 @@
<ul> <ul>
<li>QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%G: Tags (seperated by comma))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]</li>

Loading…
Cancel
Save