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. 89
      src/webui/prefjson.cpp
  3. 31
      src/webui/www/public/css/style.css
  4. 115
      src/webui/www/public/preferences_content.html

2
src/webui/extra_translations.h

@ -87,6 +87,8 @@ static const char *__TRANSLATIONS__[] = { @@ -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__[] = {

89
src/webui/prefjson.cpp

@ -58,21 +58,15 @@ QByteArray prefjson::getPreferences() @@ -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) @@ -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<bool> 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<ScanFoldersModel::PathType>(downloadType), downloadPath);
else
ec = model->updatePath(folder, static_cast<ScanFoldersModel::PathType>(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"))

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

@ -408,6 +408,37 @@ td.generalLabel { @@ -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.

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

@ -18,9 +18,22 @@ @@ -18,9 +18,22 @@
</span><br/><br/>
QBT_TR(Automatically add torrents from:)QBT_TR<br/>
<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>
<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/>
<input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();"/>
<label for="exportdir_checkbox">QBT_TR(Copy .torrent files to:)QBT_TR</label>&nbsp;&nbsp;
@ -412,38 +425,75 @@ updateTempDirEnabled = function() { @@ -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 checked = "";
if ($('new_watch_folder_dl').getProperty('checked') == true)
checked = "checked";
var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
var new_other = $('new_watch_folder_other_txt').getProperty('value').trim();
if (new_other.length <= 0) return;
var myinput = "<input id='text_watch_"+ i +"' type='text' value='" + new_folder + "'>";
var mycb = "<input id='cb_watch_"+ i +"' type='checkbox' " + checked + ">";
WatchedFoldersTable.push([myinput, mycb]);
var new_select = $('new_watch_folder_select').getProperty('value').trim();
var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
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 = "<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() {
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<nb_folders; i+=1) {
var folder_path = $('text_watch_'+i).getProperty('value').trim();
if(folder_path.length > 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() { @@ -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<pref.scan_dirs.length; i+=1) {
var myinput = "<input id='text_watch_"+ i +"' type='text' value='" + pref.scan_dirs[i] + "'>";
var checked = "";
if (pref.download_in_scan_dirs[i])
checked = "checked";
var mycb = "<input id='cb_watch_"+ i +"' type='checkbox' " + checked + ">";
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() { @@ -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

Loading…
Cancel
Save