diff --git a/src/webui/extra_translations.h b/src/webui/extra_translations.h index 1cab1be69..5a76fd53a 100644 --- a/src/webui/extra_translations.h +++ b/src/webui/extra_translations.h @@ -87,6 +87,8 @@ static const char *__TRANSLATIONS__[] = { QT_TRANSLATE_NOOP("HttpServer", "Save files to location:") QT_TRANSLATE_NOOP("HttpServer", "Label:") QT_TRANSLATE_NOOP("HttpServer", "Cookie:") + QT_TRANSLATE_NOOP("HttpServer", "Type folder here") + QT_TRANSLATE_NOOP("HttpServer", "Other...") }; static const struct { const char *source; const char *comment; } __COMMENTED_TRANSLATIONS__[] = { diff --git a/src/webui/prefjson.cpp b/src/webui/prefjson.cpp index 54583f97a..aa37464c9 100644 --- a/src/webui/prefjson.cpp +++ b/src/webui/prefjson.cpp @@ -58,21 +58,15 @@ QByteArray prefjson::getPreferences() data["temp_path"] = Utils::Fs::toNativePath(pref->getTempPath()); data["preallocate_all"] = pref->preAllocateAllFiles(); data["incomplete_files_ext"] = pref->useIncompleteFilesExtension(); - /*QVariantList scanDirs; - foreach (const QString& s, pref->getScanDirs()) { - scanDirs << Utils::Fs::toNativePath(s); + QVariantHash dirs = pref->getScanDirs(); + QVariantMap nativeDirs; + for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) { + if (i.value().type() == QVariant::Int) + nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt()); + else + nativeDirs.insert(Utils::Fs::toNativePath(i.key()), Utils::Fs::toNativePath(i.value().toString())); } - data["scan_dirs"] = scanDirs; - QVariantList ScanDirsDownloadPaths; - foreach (const QString& s, pref->getScanDirsDownloadPaths()) { - ScanDirsDownloadPaths << Utils::Fs::toNativePath(s); - } - data["scan_dirs_download_paths"] = ScanDirsDownloadPaths; - QVariantList var_list; - foreach (bool b, pref->getDownloadInScanDirs()) { - var_list << b; - } - data["download_in_scan_dirs"] = var_list;*/ + data["scan_dirs"] = nativeDirs; data["export_dir"] = Utils::Fs::toNativePath(pref->getTorrentExportDir()); data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir()); // Email notification upon download completion @@ -188,36 +182,49 @@ void prefjson::setPreferences(const QString& json) pref->preAllocateAllFiles(m["preallocate_all"].toBool()); if (m.contains("incomplete_files_ext")) pref->useIncompleteFilesExtension(m["incomplete_files_ext"].toBool()); - /*if (m.contains("scan_dirs") && m.contains("download_in_scan_dirs") && m.contains("scan_dirs_download_paths")) { - QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList(); - QList download_at_path; - foreach (QVariant var, download_at_path_tmp) { - download_at_path << var.toBool(); - } - QStringList old_folders = pref->getScanDirs(); - QStringList new_folders = m["scan_dirs"].toStringList(); - QStringList download_paths = m["scan_dirs_download_paths"].toStringList(); - if (download_at_path.size() == new_folders.size()) { - pref->setScanDirs(new_folders); - pref->setDownloadInScanDirs(download_at_path); - pref->setScanDirsDownloadPaths(download_paths); - foreach (const QString &old_folder, old_folders) { - // Update deleted folders - if (!new_folders.contains(old_folder)) { - ScanFoldersModel::instance()->removePath(old_folder); - } + if (m.contains("scan_dirs")) { + QVariantMap nativeDirs = m["scan_dirs"].toMap(); + QVariantHash oldScanDirs = pref->getScanDirs(); + QVariantHash scanDirs; + ScanFoldersModel *model = ScanFoldersModel::instance(); + for (QVariantMap::const_iterator i = nativeDirs.begin(), e = nativeDirs.end(); i != e; ++i) { + QString folder = Utils::Fs::fromNativePath(i.key()); + int downloadType; + QString downloadPath; + ScanFoldersModel::PathStatus ec; + if (i.value().type() == QVariant::String) { + downloadType = ScanFoldersModel::CUSTOM_LOCATION; + downloadPath = Utils::Fs::fromNativePath(i.value().toString()); } - int i = 0; - foreach (const QString &new_folder, new_folders) { - qDebug("New watched folder: %s", qPrintable(new_folder)); - // Update new folders - if (!old_folders.contains(Utils::Fs::fromNativePath(new_folder))) { - ScanFoldersModel::instance()->addPath(new_folder, download_at_path.at(i), download_paths.at(i)); - } - ++i; + else { + downloadType = i.value().toInt(); + downloadPath = (downloadType == ScanFoldersModel::DEFAULT_LOCATION) ? "Default folder" : "Watch folder"; + } + + if (!oldScanDirs.contains(folder)) + ec = model->addPath(folder, static_cast(downloadType), downloadPath); + else + ec = model->updatePath(folder, static_cast(downloadType), downloadPath); + + if (ec == ScanFoldersModel::Ok) { + scanDirs.insert(folder, (downloadType == ScanFoldersModel::CUSTOM_LOCATION) ? QVariant(downloadPath) : QVariant(downloadType)); + qDebug("New watched folder: %s to %s", qPrintable(folder), qPrintable(downloadPath)); + } + else { + qDebug("Watched folder %s failed with error %d", qPrintable(folder), ec); } } - }*/ + + // Update deleted folders + foreach (QVariant folderVariant, oldScanDirs.keys()) { + QString folder = folderVariant.toString(); + if (!scanDirs.contains(folder)) { + model->removePath(folder); + qDebug("Removed watched folder %s", qPrintable(folder)); + } + } + pref->setScanDirs(scanDirs); + } if (m.contains("export_dir")) pref->setTorrentExportDir(m["export_dir"].toString()); if (m.contains("export_dir_fin")) diff --git a/src/webui/www/public/css/style.css b/src/webui/www/public/css/style.css index c91fe07f6..2bf7e0705 100644 --- a/src/webui/www/public/css/style.css +++ b/src/webui/www/public/css/style.css @@ -408,6 +408,37 @@ td.generalLabel { border: 1px solid black; } +.select-watched-folder-editable { + position:relative; + background-color: white; + border: solid grey 1px; + width: 160px; + height: 20px; +} + +.select-watched-folder-editable select { + position: absolute; + top: 0px; + bottom: 0px; + left: 0px; + border: none; + width: 160px; + margin: 0; +} + +.select-watched-folder-editable input { + position: absolute; + top: 0px; + left: 0px; + width: 140px; + padding: 1px; + border: none; +} + +.select-watched-folder-editable select:focus, .select-editable input:focus { + outline: none; +} + /* * Workaround to prevent the transfer list from * disappearing when zooming in the browser. diff --git a/src/webui/www/public/preferences_content.html b/src/webui/www/public/preferences_content.html index 7fcb3ecc3..ed1f3d167 100644 --- a/src/webui/www/public/preferences_content.html +++ b/src/webui/www/public/preferences_content.html @@ -18,9 +18,22 @@

QBT_TR(Automatically add torrents from:)QBT_TR
- + - + + + +
QBT_TR(Watched Folder)QBT_TRQBT_TR(Download here)QBT_TR
QBT_TR(Watched Folder)QBT_TRQBT_TR(Save Files to)QBT_TR
Add
+
+ + + Add +
+

   @@ -412,38 +425,75 @@ updateTempDirEnabled = function() { addWatchFolder = function() { var new_folder = $('new_watch_folder_txt').getProperty('value').trim(); - if(new_folder.length <= 0) return; + if (new_folder.length <= 0) return; + + var new_other = $('new_watch_folder_other_txt').getProperty('value').trim(); + if (new_other.length <= 0) return; + + var new_select = $('new_watch_folder_select').getProperty('value').trim(); - var checked = ""; - if ($('new_watch_folder_dl').getProperty('checked') == true) - checked = "checked"; var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length; - - var myinput = ""; - var mycb = ""; - WatchedFoldersTable.push([myinput, mycb]); + pushWatchFolder(i, new_folder, new_select, new_other); // Clear fields $('new_watch_folder_txt').setProperty('value', ''); - $('new_watch_folder_dl').setProperty('checked', false); + var elt = $('new_watch_folder_select'); + elt.setProperty('value', 'watch_folder'); + var text = elt.options[elt.selectedIndex].innerHTML; + $('new_watch_folder_other_txt').setProperty('value', text); +} + +changeWatchFolderSelect = function(item) { + if (item.value == "other") { + item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR'; + item.nextElementSibling.select(); + } else { + var text = item.options[item.selectedIndex].innerHTML; + item.nextElementSibling.value = text; + } +} + +changeWatchFolderText = function(item) { + item.previousElementSibling.value = 'other'; +} + +pushWatchFolder = function(pos, folder, sel, other) { + var myinput = ""; + var mycb = "
" + + "" + + "
"; + + WatchedFoldersTable.push([myinput, mycb]); + $('cb_watch_' + pos).setProperty('value', sel); + if (sel != "other") { + var elt = $('cb_watch_' + pos); + other = elt.options[elt.selectedIndex].innerHTML; + } + $('cb_watch_txt_'+ pos).setProperty('value', other); } getWatchedFolders = function() { var nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length; - var folders = Array(); - var download_in_place = Array(); - for(var i=0; i 0) { - folders[folders.length] = folder_path; - if($("cb_watch_"+i).getProperty('checked')) { - download_in_place[download_in_place.length] = 1; + var folders = new Hash(); + for(var i = 0; i < nb_folders; i++) { + var fpath = $('text_watch_' + i).getProperty('value').trim(); + if (fpath.length > 0) { + var other; + var sel = $('cb_watch_' + i).getProperty('value').trim(); + if (sel == "other") { + other = $('cb_watch_txt_' + i).getProperty('value').trim(); } else { - download_in_place[download_in_place.length] = 0; + other = (sel == "watch_folder") ? 0 : 1; } + folders.set(fpath, other); } } - return [folders, download_in_place]; + return folders; } updateExportDirEnabled = function() { @@ -714,14 +764,17 @@ loadPreferences = function() { updateTempDirEnabled(); $('preallocateall_checkbox').setProperty('checked', pref.preallocate_all); $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); - var i; - for(i=0; i"; - var checked = ""; - if (pref.download_in_scan_dirs[i]) - checked = "checked"; - var mycb = ""; - WatchedFoldersTable.push([myinput, mycb]); + var i = 0; + for (var folder in pref.scan_dirs) { + var sel; + var other = ""; + if (typeof pref.scan_dirs[folder] == "string") { + other = pref.scan_dirs[folder]; + sel = "other"; + } else { + sel = (pref.scan_dirs[folder] == 0) ? "watch_folder" : "default_folder"; + } + pushWatchFolder(i++, folder, sel, other); } if(pref.export_dir != '') { $('exportdir_checkbox').setProperty('checked', true); @@ -950,9 +1003,7 @@ applyPreferences = function() { settings.set('temp_path', $('temppath_text').getProperty('value')); settings.set('preallocate_all', $('preallocateall_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]); + settings.set('scan_dirs', getWatchedFolders()); if($('exportdir_checkbox').getProperty('checked')) settings.set('export_dir', $('exportdir_text').getProperty('value')); else