Browse Source

Implemented WebUI interface for the new Watched Folders feature

adaptive-webui-19844
Naikel Aparicio 9 years ago committed by sledgehammer999
parent
commit
fa34f0efcc
  1. 2
      src/webui/extra_translations.h
  2. 83
      src/webui/prefjson.cpp
  3. 31
      src/webui/www/public/css/style.css
  4. 113
      src/webui/www/public/preferences_content.html

2
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", "Save files to location:")
QT_TRANSLATE_NOOP("HttpServer", "Label:") QT_TRANSLATE_NOOP("HttpServer", "Label:")
QT_TRANSLATE_NOOP("HttpServer", "Cookie:") 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__[] = { static const struct { const char *source; const char *comment; } __COMMENTED_TRANSLATIONS__[] = {

83
src/webui/prefjson.cpp

@ -58,21 +58,15 @@ QByteArray prefjson::getPreferences()
data["temp_path"] = Utils::Fs::toNativePath(pref->getTempPath()); data["temp_path"] = Utils::Fs::toNativePath(pref->getTempPath());
data["preallocate_all"] = pref->preAllocateAllFiles(); data["preallocate_all"] = pref->preAllocateAllFiles();
data["incomplete_files_ext"] = pref->useIncompleteFilesExtension(); data["incomplete_files_ext"] = pref->useIncompleteFilesExtension();
/*QVariantList scanDirs; QVariantHash dirs = pref->getScanDirs();
foreach (const QString& s, pref->getScanDirs()) { QVariantMap nativeDirs;
scanDirs << Utils::Fs::toNativePath(s); for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) {
} if (i.value().type() == QVariant::Int)
data["scan_dirs"] = scanDirs; nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt());
QVariantList ScanDirsDownloadPaths; else
foreach (const QString& s, pref->getScanDirsDownloadPaths()) { nativeDirs.insert(Utils::Fs::toNativePath(i.key()), Utils::Fs::toNativePath(i.value().toString()));
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"] = Utils::Fs::toNativePath(pref->getTorrentExportDir());
data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir()); data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir());
// Email notification upon download completion // Email notification upon download completion
@ -188,36 +182,49 @@ void prefjson::setPreferences(const QString& json)
pref->preAllocateAllFiles(m["preallocate_all"].toBool()); pref->preAllocateAllFiles(m["preallocate_all"].toBool());
if (m.contains("incomplete_files_ext")) if (m.contains("incomplete_files_ext"))
pref->useIncompleteFilesExtension(m["incomplete_files_ext"].toBool()); pref->useIncompleteFilesExtension(m["incomplete_files_ext"].toBool());
/*if (m.contains("scan_dirs") && m.contains("download_in_scan_dirs") && m.contains("scan_dirs_download_paths")) { if (m.contains("scan_dirs")) {
QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList(); QVariantMap nativeDirs = m["scan_dirs"].toMap();
QList<bool> download_at_path; QVariantHash oldScanDirs = pref->getScanDirs();
foreach (QVariant var, download_at_path_tmp) { QVariantHash scanDirs;
download_at_path << var.toBool(); 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());
} }
QStringList old_folders = pref->getScanDirs(); else {
QStringList new_folders = m["scan_dirs"].toStringList(); downloadType = i.value().toInt();
QStringList download_paths = m["scan_dirs_download_paths"].toStringList(); downloadPath = (downloadType == ScanFoldersModel::DEFAULT_LOCATION) ? "Default folder" : "Watch folder";
if (download_at_path.size() == new_folders.size()) { }
pref->setScanDirs(new_folders);
pref->setDownloadInScanDirs(download_at_path); if (!oldScanDirs.contains(folder))
pref->setScanDirsDownloadPaths(download_paths); ec = model->addPath(folder, static_cast<ScanFoldersModel::PathType>(downloadType), downloadPath);
foreach (const QString &old_folder, old_folders) { else
// Update deleted folders ec = model->updatePath(folder, static_cast<ScanFoldersModel::PathType>(downloadType), downloadPath);
if (!new_folders.contains(old_folder)) {
ScanFoldersModel::instance()->removePath(old_folder); 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);
} }
} }
int i = 0;
foreach (const QString &new_folder, new_folders) { // Update deleted folders
qDebug("New watched folder: %s", qPrintable(new_folder)); foreach (QVariant folderVariant, oldScanDirs.keys()) {
// Update new folders QString folder = folderVariant.toString();
if (!old_folders.contains(Utils::Fs::fromNativePath(new_folder))) { if (!scanDirs.contains(folder)) {
ScanFoldersModel::instance()->addPath(new_folder, download_at_path.at(i), download_paths.at(i)); model->removePath(folder);
qDebug("Removed watched folder %s", qPrintable(folder));
} }
++i;
} }
pref->setScanDirs(scanDirs);
} }
}*/
if (m.contains("export_dir")) if (m.contains("export_dir"))
pref->setTorrentExportDir(m["export_dir"].toString()); pref->setTorrentExportDir(m["export_dir"].toString());
if (m.contains("export_dir_fin")) if (m.contains("export_dir_fin"))

31
src/webui/www/public/css/style.css

@ -408,6 +408,37 @@ td.generalLabel {
border: 1px solid black; 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 * Workaround to prevent the transfer list from
* disappearing when zooming in the browser. * disappearing when zooming in the browser.

113
src/webui/www/public/preferences_content.html

@ -18,9 +18,22 @@
</span><br/><br/> </span><br/><br/>
QBT_TR(Automatically add torrents from:)QBT_TR<br/> QBT_TR(Automatically add torrents from:)QBT_TR<br/>
<table border="1" id="watched_folders_tab"> <table border="1" id="watched_folders_tab">
<thead><tr><th>QBT_TR(Watched Folder)QBT_TR</th><th>QBT_TR(Download here)QBT_TR</th></tr></thead> <thead><tr><th>QBT_TR(Watched Folder)QBT_TR</th><th>QBT_TR(Save Files to)QBT_TR</th></tr></thead>
<tbody></tbody> <tbody></tbody>
<tfoot><tr><td style="padding-top:4px;"><input type="text" id="new_watch_folder_txt"/></td><td style="padding-top:4px;"><input type="checkbox" id="new_watch_folder_dl" style="padding-left:18px;"/><img src="theme/list-add" alt="Add" style="padding-left:2px;width:16px;cursor:pointer;margin-right:-18px;" onclick="addWatchFolder();"/></td></tr></tfoot> <tfoot><tr>
<td style="padding-top:4px;"><input type="text" id="new_watch_folder_txt"/></td>
<td style="padding-top:4px;">
<div class="select-watched-folder-editable">
<select id="new_watch_folder_select" onchange="changeWatchFolderSelect(this)">
<option selected value="watch_folder">QBT_TR(Watch Folder)QBT_TR</option>
<option value="default_folder">QBT_TR(Default Folder)QBT_TR</option>
<option value="other">QBT_TR(Other...)QBT_TR</option>
</select>
<input id="new_watch_folder_other_txt" type="text" value="QBT_TR(Watch Folder)QBT_TR" onchange="changeWatchFolderText(this)" />
<img src="theme/list-add" alt="Add" style="padding-left:170px;width:16px;cursor:pointer;" onclick="addWatchFolder();"/>
</div>
</td>
</tr></tfoot>
</table><br/> </table><br/>
<input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();"/> <input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();"/>
<label for="exportdir_checkbox">QBT_TR(Copy .torrent files to:)QBT_TR</label>&nbsp;&nbsp; <label for="exportdir_checkbox">QBT_TR(Copy .torrent files to:)QBT_TR</label>&nbsp;&nbsp;
@ -414,36 +427,73 @@ addWatchFolder = function() {
var new_folder = $('new_watch_folder_txt').getProperty('value').trim(); var new_folder = $('new_watch_folder_txt').getProperty('value').trim();
if (new_folder.length <= 0) return; if (new_folder.length <= 0) return;
var checked = ""; var new_other = $('new_watch_folder_other_txt').getProperty('value').trim();
if ($('new_watch_folder_dl').getProperty('checked') == true) if (new_other.length <= 0) return;
checked = "checked";
var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
var myinput = "<input id='text_watch_"+ i +"' type='text' value='" + new_folder + "'>"; var new_select = $('new_watch_folder_select').getProperty('value').trim();
var mycb = "<input id='cb_watch_"+ i +"' type='checkbox' " + checked + ">";
WatchedFoldersTable.push([myinput, mycb]); var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
pushWatchFolder(i, new_folder, new_select, new_other);
// Clear fields // Clear fields
$('new_watch_folder_txt').setProperty('value', ''); $('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 = "<input id='text_watch_"+ pos +"' type='text' value='" + folder + "'>";
var mycb = "<div class='select-watched-folder-editable'>" +
"<select id ='cb_watch_" + pos + "' onchange='changeWatchFolderSelect(this)'>" +
"<option value='watch_folder'>QBT_TR(Watch Folder)QBT_TR</option>" +
"<option value='default_folder'>QBT_TR(Default Folder)QBT_TR</option>" +
"<option value='other'>QBT_TR(Other...)QBT_TR</option>" +
"</select>" +
"<input id='cb_watch_txt_" + pos + "' type='text' " +
"onchange='changeWatchFolderText(this)' /></div>";
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() { getWatchedFolders = function() {
var nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length; var nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length;
var folders = Array(); var folders = new Hash();
var download_in_place = Array(); for(var i = 0; i < nb_folders; i++) {
for(var i=0; i<nb_folders; i+=1) { var fpath = $('text_watch_' + i).getProperty('value').trim();
var folder_path = $('text_watch_'+i).getProperty('value').trim(); if (fpath.length > 0) {
if(folder_path.length > 0) { var other;
folders[folders.length] = folder_path; var sel = $('cb_watch_' + i).getProperty('value').trim();
if($("cb_watch_"+i).getProperty('checked')) { if (sel == "other") {
download_in_place[download_in_place.length] = 1; other = $('cb_watch_txt_' + i).getProperty('value').trim();
} else { } 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() { updateExportDirEnabled = function() {
@ -714,14 +764,17 @@ loadPreferences = function() {
updateTempDirEnabled(); updateTempDirEnabled();
$('preallocateall_checkbox').setProperty('checked', pref.preallocate_all); $('preallocateall_checkbox').setProperty('checked', pref.preallocate_all);
$('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext);
var i; var i = 0;
for(i=0; i<pref.scan_dirs.length; i+=1) { for (var folder in pref.scan_dirs) {
var myinput = "<input id='text_watch_"+ i +"' type='text' value='" + pref.scan_dirs[i] + "'>"; var sel;
var checked = ""; var other = "";
if (pref.download_in_scan_dirs[i]) if (typeof pref.scan_dirs[folder] == "string") {
checked = "checked"; other = pref.scan_dirs[folder];
var mycb = "<input id='cb_watch_"+ i +"' type='checkbox' " + checked + ">"; sel = "other";
WatchedFoldersTable.push([myinput, mycb]); } else {
sel = (pref.scan_dirs[folder] == 0) ? "watch_folder" : "default_folder";
}
pushWatchFolder(i++, folder, sel, other);
} }
if(pref.export_dir != '') { if(pref.export_dir != '') {
$('exportdir_checkbox').setProperty('checked', true); $('exportdir_checkbox').setProperty('checked', true);
@ -950,9 +1003,7 @@ applyPreferences = function() {
settings.set('temp_path', $('temppath_text').getProperty('value')); settings.set('temp_path', $('temppath_text').getProperty('value'));
settings.set('preallocate_all', $('preallocateall_checkbox').getProperty('checked')); settings.set('preallocate_all', $('preallocateall_checkbox').getProperty('checked'));
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', getWatchedFolders());
settings.set('scan_dirs', watched_folders[0]);
settings.set('download_in_scan_dirs', watched_folders[1]);
if($('exportdir_checkbox').getProperty('checked')) if($('exportdir_checkbox').getProperty('checked'))
settings.set('export_dir', $('exportdir_text').getProperty('value')); settings.set('export_dir', $('exportdir_text').getProperty('value'));
else else

Loading…
Cancel
Save