From d05cf471693f398cbc2381ed4359ee2254f549ad Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 24 Oct 2018 22:15:40 -0400 Subject: [PATCH] Add WebUI Auto TMM options --- src/gui/optionsdialog.ui | 2 +- src/webui/api/appcontroller.cpp | 12 +++++ src/webui/api/torrentscontroller.cpp | 2 + src/webui/www/private/download.html | 11 ++++ .../www/private/preferences_content.html | 54 +++++++++++++++++++ src/webui/www/private/scripts/download.js | 31 ++++++++--- src/webui/www/private/upload.html | 11 ++++ 7 files changed, 115 insertions(+), 8 deletions(-) diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 7d4f83231..8d4fb7c88 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -941,7 +941,7 @@ - When Category changed: + When Category Save Path changed: diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 45d172d93..6a0d9e75e 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -87,6 +87,10 @@ void AppController::preferencesAction() data["preallocate_all"] = session->isPreallocationEnabled(); data["incomplete_files_ext"] = session->isAppendExtensionEnabled(); // Saving Management + data["auto_tmm_enabled"] = !session->isAutoTMMDisabledByDefault(); + data["torrent_changed_tmm_enabled"] = !session->isDisableAutoTMMWhenCategoryChanged(); + data["save_path_changed_tmm_enabled"] = !session->isDisableAutoTMMWhenDefaultSavePathChanged(); + data["category_changed_tmm_enabled"] = !session->isDisableAutoTMMWhenCategorySavePathChanged(); data["save_path"] = Utils::Fs::toNativePath(session->defaultSavePath()); data["temp_path_enabled"] = session->isTempPathEnabled(); data["temp_path"] = Utils::Fs::toNativePath(session->tempPath()); @@ -242,6 +246,14 @@ void AppController::setPreferencesAction() session->setAppendExtensionEnabled(it.value().toBool()); // Saving Management + if ((it = m.find(QLatin1String("auto_tmm_enabled"))) != m.constEnd()) + session->setAutoTMMDisabledByDefault(!it.value().toBool()); + if ((it = m.find(QLatin1String("torrent_changed_tmm_enabled"))) != m.constEnd()) + session->setDisableAutoTMMWhenCategoryChanged(!it.value().toBool()); + if ((it = m.find(QLatin1String("save_path_changed_tmm_enabled"))) != m.constEnd()) + session->setDisableAutoTMMWhenDefaultSavePathChanged(!it.value().toBool()); + if ((it = m.find(QLatin1String("category_changed_tmm_enabled"))) != m.constEnd()) + session->setDisableAutoTMMWhenCategorySavePathChanged(!it.value().toBool()); if (m.contains("save_path")) session->setDefaultSavePath(m["save_path"].toString()); if (m.contains("temp_path_enabled")) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 1082f829d..c25c75790 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -469,6 +469,7 @@ void TorrentsController::addAction() const QString torrentName = params()["rename"].trimmed(); const int upLimit = params()["upLimit"].toInt(); const int dlLimit = params()["dlLimit"].toInt(); + const TriStateBool autoTMM = parseTriStateBool(params()["autoTMM"]); QList cookies; if (!cookie.isEmpty()) { @@ -496,6 +497,7 @@ void TorrentsController::addAction() params.name = torrentName; params.uploadLimit = (upLimit > 0) ? upLimit : -1; params.downloadLimit = (dlLimit > 0) ? dlLimit : -1; + params.useAutoTMM = autoTMM; bool partialSuccess = false; for (QString url : asConst(urls.split('\n'))) { diff --git a/src/webui/www/private/download.html b/src/webui/www/private/download.html index b95597031..2eff552a0 100644 --- a/src/webui/www/private/download.html +++ b/src/webui/www/private/download.html @@ -20,6 +20,17 @@

QBT_TR(Only one link per line)QBT_TR[CONTEXT=HttpServer]

+ + + +
+ + + +
diff --git a/src/webui/www/private/preferences_content.html b/src/webui/www/private/preferences_content.html index 3429fe083..3c7b75c76 100644 --- a/src/webui/www/private/preferences_content.html +++ b/src/webui/www/private/preferences_content.html @@ -12,6 +12,52 @@
QBT_TR(Saving Management)QBT_TR[CONTEXT=HttpServer] + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
@@ -984,6 +1030,10 @@ $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); // Saving Managmenet + $('default_tmm_combobox').setProperty('value', pref.auto_tmm_enabled); + $('torrent_changed_tmm_combobox').setProperty('value', pref.torrent_changed_tmm_enabled); + $('save_path_changed_tmm_combobox').setProperty('value', pref.save_path_changed_tmm_enabled); + $('category_changed_tmm_combobox').setProperty('value', pref.category_changed_tmm_enabled); $('savepath_text').setProperty('value', pref.save_path); $('temppath_checkbox').setProperty('checked', pref.temp_path_enabled); $('temppath_text').setProperty('value', pref.temp_path); @@ -1228,6 +1278,10 @@ settings.set('incomplete_files_ext', $('appendext_checkbox').getProperty('checked')); // Saving Management + settings.set('auto_tmm_enabled', $('default_tmm_combobox').getProperty('value')); + settings.set('torrent_changed_tmm_enabled', $('torrent_changed_tmm_combobox').getProperty('value')); + settings.set('save_path_changed_tmm_enabled', $('save_path_changed_tmm_combobox').getProperty('value')); + settings.set('category_changed_tmm_enabled', $('category_changed_tmm_combobox').getProperty('value')); settings.set('save_path', $('savepath_text').getProperty('value')); settings.set('temp_path_enabled', $('temppath_checkbox').getProperty('checked')); settings.set('temp_path', $('temppath_text').getProperty('value')); diff --git a/src/webui/www/private/scripts/download.js b/src/webui/www/private/scripts/download.js index 3b01607a5..64910cfae 100644 --- a/src/webui/www/private/scripts/download.js +++ b/src/webui/www/private/scripts/download.js @@ -21,22 +21,39 @@ * THE SOFTWARE. */ -getSavePath = function() { - new Request({ - url: 'api/v2/app/defaultSavePath', + +getPreferences = function() { + new Request.JSON({ + url: 'api/v2/app/preferences', method: 'get', noCache: true, onFailure: function() { alert("Could not contact qBittorrent"); }, - onSuccess: function(data) { - if (data) { - $('savepath').setProperty('value', data); + onSuccess: function(pref) { + if (pref) { + $('savepath').setProperty('value', pref.save_path); + if (pref.auto_tmm_enabled == 1) { + $('autoTMM').selectedIndex = 1; + $('savepath').disabled = true; + } + else { + $('autoTMM').selectedIndex = 0; + } } } }).send(); }; +changeTMM = function(item) { + if (item.selectedIndex == 1) { + $('savepath').disabled = true; + } + else { + $('savepath').disabled = false; + } +}; + $(window).addEventListener("load", function() { - getSavePath(); + getPreferences(); }); diff --git a/src/webui/www/private/upload.html b/src/webui/www/private/upload.html index d0d9a7624..2122e6d93 100644 --- a/src/webui/www/private/upload.html +++ b/src/webui/www/private/upload.html @@ -18,6 +18,17 @@
+ + + +
+ + + +