From 0ed8ea9599a0a65e846dffd94a720cd015f69d55 Mon Sep 17 00:00:00 2001 From: ngosang Date: Wed, 8 Jul 2015 09:53:01 +0200 Subject: [PATCH] [Web UI] Additional checks in Options dialog --- src/webui/extra_translations.h | 3 + src/webui/prefjson.cpp | 2 - src/webui/www/public/preferences_content.html | 107 +++++++++--------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/src/webui/extra_translations.h b/src/webui/extra_translations.h index 9a6cd7f64..f0a11ea58 100644 --- a/src/webui/extra_translations.h +++ b/src/webui/extra_translations.h @@ -46,6 +46,9 @@ static const char *__TRANSLATIONS__[] = { QT_TRANSLATE_NOOP("HttpServer", "Global download rate limit must be greater than 0 or disabled."), QT_TRANSLATE_NOOP("HttpServer", "Alternative upload rate limit must be greater than 0 or disabled."), QT_TRANSLATE_NOOP("HttpServer", "Alternative download rate limit must be greater than 0 or disabled."), + QT_TRANSLATE_NOOP("HttpServer", "Maximum active downloads must be greater than -1."), + QT_TRANSLATE_NOOP("HttpServer", "Maximum active uploads must be greater than -1."), + QT_TRANSLATE_NOOP("HttpServer", "Maximum active torrents must be greater than -1."), QT_TRANSLATE_NOOP("HttpServer", "Maximum number of connections limit must be greater than 0 or disabled."), QT_TRANSLATE_NOOP("HttpServer", "Maximum number of connections per torrent limit must be greater than 0 or disabled."), QT_TRANSLATE_NOOP("HttpServer", "Maximum number of upload slots per torrent limit must be greater than 0 or disabled."), diff --git a/src/webui/prefjson.cpp b/src/webui/prefjson.cpp index be6c77003..50e940f95 100644 --- a/src/webui/prefjson.cpp +++ b/src/webui/prefjson.cpp @@ -68,9 +68,7 @@ QByteArray prefjson::getPreferences() var_list << b; } data["download_in_scan_dirs"] = var_list; - data["export_dir_enabled"] = pref->isTorrentExportEnabled(); data["export_dir"] = Utils::Fs::toNativePath(pref->getTorrentExportDir()); - data["export_dir_fin_enabled"] = pref->isFinishedTorrentExportEnabled(); data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir()); // Email notification upon download completion data["mail_notification_enabled"] = pref->isMailNotificationEnabled(); diff --git a/src/webui/www/public/preferences_content.html b/src/webui/www/public/preferences_content.html index b297b7a1c..7dc4536a3 100644 --- a/src/webui/www/public/preferences_content.html +++ b/src/webui/www/public/preferences_content.html @@ -20,7 +20,7 @@ - +
QBT_TR(Watched Folder)QBT_TRQBT_TR(Download here)QBT_TR
Add
Add

   @@ -182,7 +182,7 @@
QBT_TR(Options)QBT_TR - +

@@ -585,13 +585,11 @@ updateDlLimitEnabled = function() { } } -setuTPSettingsVisible = function(visible) { - if(visible) { - $('enable_utp_checkbox').removeClass('invisible'); - $('limit_utp_rate_checkbox').removeClass('invisible'); +updateUTPEnabled = function() { + if($('enable_utp_checkbox').getProperty('checked')) { + $('limit_utp_rate_checkbox').setProperty('disabled', false); } else { - $('enable_utp_checkbox').addClass('invisible'); - $('limit_utp_rate_checkbox').addClass('invisible'); + $('limit_utp_rate_checkbox').setProperty('disabled', true); } } @@ -710,12 +708,7 @@ loadPreferences = function() { $('temppath_text').setProperty('value', pref.temp_path); updateTempDirEnabled(); $('preallocateall_checkbox').setProperty('checked', pref.preallocate_all); - if($defined(pref.incomplete_files_ext)) { - $('appendexttr').removeClass('invisible'); - $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); - } else { - $('appendexttr').addClass('invisible'); - } + $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); var i; for(i=0; i"; @@ -725,17 +718,23 @@ loadPreferences = function() { var mycb = ""; WatchedFoldersTable.push([myinput, mycb]); } - $('exportdir_checkbox').setProperty('checked', pref.export_dir_enabled); - if(pref.export_dir_enabled) + if(pref.export_dir != '') { + $('exportdir_checkbox').setProperty('checked', true); $('exportdir_text').setProperty('value', pref.export_dir); - else + } + else { + $('exportdir_checkbox').setProperty('checked', false); $('exportdir_text').setProperty('value', ''); + } updateExportDirEnabled(); - $('exportdirfin_checkbox').setProperty('checked', pref.export_dir_fin_enabled); - if(pref.export_dir_fin_enabled) + if(pref.export_dir_fin != '') { + $('exportdirfin_checkbox').setProperty('checked', true); $('exportdirfin_text').setProperty('value', pref.export_dir_fin); - else + } + else { + $('exportdirfin_checkbox').setProperty('checked', false); $('exportdirfin_text').setProperty('value', ''); + } updateExportDirFinEnabled(); // Email notification upon download completion @@ -848,13 +847,10 @@ loadPreferences = function() { $('dl_limit_value').setProperty('value', dl_limit); } updateDlLimitEnabled(); - utp_supported = $defined(pref.enable_utp); - setuTPSettingsVisible(utp_supported); - if(utp_supported) { - $('enable_utp_checkbox').setProperty('checked', pref.enable_utp); - $('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate); - } + $('enable_utp_checkbox').setProperty('checked', pref.enable_utp); + $('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate); $('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead); + updateUTPEnabled(); // Alternative Global Rate Limits var alt_up_limit = pref.alt_up_limit.toInt(); @@ -890,11 +886,7 @@ loadPreferences = function() { $('lsd_checkbox').setProperty('checked', pref.lsd); var encryption = pref.encryption.toInt(); $('encryption_select').getChildren('option')[encryption].setAttribute('selected', ''); - if($defined(pref.anonymous_mode)) { - $('anonymous_mode_checkbox').setProperty('checked', pref.anonymous_mode); - } else { - $('anonymous_mode_checkbox').addClass('invisible'); - } + $('anonymous_mode_checkbox').setProperty('checked', pref.anonymous_mode); // Torrent Queueing $('queueing_checkbox').setProperty('checked', pref.queueing_enabled); @@ -951,9 +943,7 @@ applyPreferences = function() { settings.set('temp_path_enabled', $('temppath_checkbox').getProperty('checked')); settings.set('temp_path', $('temppath_text').getProperty('value')); settings.set('preallocate_all', $('preallocateall_checkbox').getProperty('checked')); - if(!$('appendexttr').hasClass('invisible')) { - settings.set('incomplete_files_ext', $('appendext_checkbox').getProperty('checked')); - } + settings.set('incomplete_files_ext', $('appendext_checkbox').getProperty('checked')); var watched_folders = getWatchedFolders(); settings.set('scan_dirs', watched_folders[0]); settings.set('download_in_scan_dirs', watched_folders[1]); @@ -982,7 +972,7 @@ applyPreferences = function() { // Connection tab // Listening Port var listen_port = $('port_value').getProperty('value').toInt(); - if(listen_port <= 1024 || listen_port > 65535) { + if(isNaN(listen_port) || listen_port <= 1024 || listen_port > 65535) { alert("QBT_TR(The port used for incoming connections must be greater than 1024 and less than 65535.)QBT_TR"); return; } @@ -994,7 +984,7 @@ applyPreferences = function() { var max_connec = -1; if($('max_connec_checkbox').getProperty('checked')) { max_connec = $('max_connec_value').getProperty('value').toInt(); - if(max_connec <= 0) { + if(isNaN(max_connec) || max_connec <= 0) { alert("QBT_TR(Maximum number of connections limit must be greater than 0 or disabled.)QBT_TR"); return; } @@ -1003,7 +993,7 @@ applyPreferences = function() { var max_connec_per_torrent = -1; if($('max_connec_per_torrent_checkbox').getProperty('checked')) { max_connec_per_torrent = $('max_connec_per_torrent_value').getProperty('value').toInt(); - if(max_connec_per_torrent <= 0) { + if(isNaN(max_connec_per_torrent) || max_connec_per_torrent <= 0) { alert("QBT_TR(Maximum number of connections per torrent limit must be greater than 0 or disabled.)QBT_TR"); return; } @@ -1012,7 +1002,7 @@ applyPreferences = function() { var max_uploads = -1; if($('max_uploads_checkbox').getProperty('checked')) { max_uploads = $('max_uploads_value').getProperty('value').toInt(); - if(max_uploads <= 0) { + if(isNaN(max_uploads) || max_uploads <= 0) { alert("QBT_TR(Global number of upload slots limit must be greater than 0 or disabled.)QBT_TR"); return; } @@ -1021,7 +1011,7 @@ applyPreferences = function() { var max_uploads_per_torrent = -1; if($('max_uploads_per_torrent_checkbox').getProperty('checked')) { max_uploads_per_torrent = $('max_uploads_per_torrent_value').getProperty('value').toInt(); - if(max_uploads_per_torrent <= 0) { + if(isNaN(max_uploads_per_torrent) || max_uploads_per_torrent <= 0) { alert("QBT_TR(Maximum number of upload slots per torrent limit must be greater than 0 or disabled.)QBT_TR"); return; } @@ -1087,10 +1077,8 @@ applyPreferences = function() { } } settings.set('dl_limit', dl_limit); - if(!$('enable_utp_checkbox').hasClass('invisible')) { - settings.set('enable_utp', $('enable_utp_checkbox').getProperty('checked')); - settings.set('limit_utp_rate', $('limit_utp_rate_checkbox').getProperty('checked')); - } + settings.set('enable_utp', $('enable_utp_checkbox').getProperty('checked')); + settings.set('limit_utp_rate', $('limit_utp_rate_checkbox').getProperty('checked')); settings.set('limit_tcp_overhead', $('limit_tcp_overhead_checkbox').getProperty('checked')); // Alternative Global Rate Limits @@ -1130,22 +1118,37 @@ applyPreferences = function() { settings.set('pex', $('pex_checkbox').getProperty('checked')); settings.set('lsd', $('lsd_checkbox').getProperty('checked')); settings.set('encryption', $('encryption_select').getSelected()[0].getProperty('value')); - if(!$('anonymous_mode_checkbox').hasClass('invisible')) { - settings.set('anonymous_mode', $('anonymous_mode_checkbox').getProperty('checked')); - } + settings.set('anonymous_mode', $('anonymous_mode_checkbox').getProperty('checked')); // Torrent Queueing settings.set('queueing_enabled', $('queueing_checkbox').getProperty('checked')); - settings.set('max_active_downloads', $('max_active_dl_value').getProperty('value').toInt()); - settings.set('max_active_uploads', $('max_active_up_value').getProperty('value').toInt()); - settings.set('max_active_torrents', $('max_active_to_value').getProperty('value').toInt()); - settings.set('dont_count_slow_torrents', $('dont_count_slow_torrents_checkbox').getProperty('checked')); + if($('queueing_checkbox').getProperty('checked')) { + var max_active_downloads = $('max_active_dl_value').getProperty('value').toInt(); + if(isNaN(max_active_downloads) || max_active_downloads < -1) { + alert("QBT_TR(Maximum active downloads must be greater than -1.)QBT_TR"); + return; + } + settings.set('max_active_downloads', max_active_downloads); + var max_active_uploads = $('max_active_up_value').getProperty('value').toInt(); + if(isNaN(max_active_uploads) || max_active_uploads < -1) { + alert("QBT_TR(Maximum active uploads must be greater than -1.)QBT_TR"); + return; + } + settings.set('max_active_uploads', max_active_uploads); + var max_active_torrents = $('max_active_to_value').getProperty('value').toInt(); + if(isNaN(max_active_torrents) || max_active_torrents < -1) { + alert("QBT_TR(Maximum active torrents must be greater than -1.)QBT_TR"); + return; + } + settings.set('max_active_torrents', max_active_torrents); + settings.set('dont_count_slow_torrents', $('dont_count_slow_torrents_checkbox').getProperty('checked')); + } // Share Ratio Limiting var max_ratio = -1; if($('max_ratio_checkbox').getProperty('checked')) { max_ratio = $('max_ratio_value').getProperty('value').toInt(); - if(max_ratio < 0 || max_ratio > 9998) { + if(isNaN(max_ratio) || max_ratio < 0 || max_ratio > 9998) { alert("QBT_TR(Share ratio limit must be between 0 and 9998.)QBT_TR"); return; } @@ -1160,7 +1163,7 @@ applyPreferences = function() { // HTTP Server var web_ui_port = $('webui_port_value').getProperty('value').toInt(); - if(web_ui_port <= 1024 || web_ui_port > 65535) { + if(isNaN(web_ui_port) || web_ui_port <= 1024 || web_ui_port > 65535) { alert("QBT_TR(The port used for the Web UI must be greater than 1024 and less than 65535.)QBT_TR"); return; }