mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
Added back folder watching in Web UI
This commit is contained in:
parent
165b33a94e
commit
912056a364
@ -197,6 +197,10 @@ void Bittorrent::preAllocateAllFiles(bool b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScanFoldersModel* Bittorrent::getScanFoldersModel() const {
|
||||||
|
return m_scanFolders;
|
||||||
|
}
|
||||||
|
|
||||||
void Bittorrent::deleteBigRatios() {
|
void Bittorrent::deleteBigRatios() {
|
||||||
if(ratio_limit == -1) return;
|
if(ratio_limit == -1) return;
|
||||||
std::vector<torrent_handle> torrents = getTorrents();
|
std::vector<torrent_handle> torrents = getTorrents();
|
||||||
|
@ -115,6 +115,7 @@ public:
|
|||||||
qlonglong getETA(QString hash);
|
qlonglong getETA(QString hash);
|
||||||
bool useTemporaryFolder() const;
|
bool useTemporaryFolder() const;
|
||||||
QString getDefaultSavePath() const;
|
QString getDefaultSavePath() const;
|
||||||
|
ScanFoldersModel* getScanFoldersModel() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "eventmanager.h"
|
#include "eventmanager.h"
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
|
#include "scannedfoldersmodel.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
//#include "proplistdelegate.h"
|
//#include "proplistdelegate.h"
|
||||||
@ -129,8 +130,23 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
|
|||||||
Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool());
|
Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool());
|
||||||
if(m.contains("temp_path"))
|
if(m.contains("temp_path"))
|
||||||
Preferences::setTempPath(m["temp_path"].toString());
|
Preferences::setTempPath(m["temp_path"].toString());
|
||||||
if(m.contains("scan_dirs"))
|
if(m.contains("scan_dirs")) {
|
||||||
Preferences::setScanDirs(m["scan_dirs"].toStringList());
|
QStringList old_folders = Preferences::getScanDirs();
|
||||||
|
QStringList new_folders = m["scan_dirs"].toStringList();
|
||||||
|
foreach(const QString &old_folder, old_folders) {
|
||||||
|
// Update deleted folders
|
||||||
|
if(!new_folders.contains(old_folder)) {
|
||||||
|
BTSession->getScanFoldersModel()->removePath(old_folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(const QString &new_folder, new_folders) {
|
||||||
|
// Update new folders
|
||||||
|
if(!old_folders.contains(new_folder)) {
|
||||||
|
BTSession->getScanFoldersModel()->addPath(new_folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Preferences::setScanDirs(new_folders);
|
||||||
|
}
|
||||||
if(m.contains("download_in_scan_dirs"))
|
if(m.contains("download_in_scan_dirs"))
|
||||||
Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList());
|
Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList());
|
||||||
if(m.contains("export_dir"))
|
if(m.contains("export_dir"))
|
||||||
|
@ -104,7 +104,7 @@ void HttpConnection::write()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString HttpConnection::translateDocument(QString data) {
|
QString HttpConnection::translateDocument(QString data) {
|
||||||
std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel", "options_imp", "Preferences", "TrackersAdditionDlg"};
|
std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel", "options_imp", "Preferences", "TrackersAdditionDlg", "ScanFoldersModel"};
|
||||||
int i=0;
|
int i=0;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
do {
|
do {
|
||||||
@ -119,7 +119,7 @@ QString HttpConnection::translateDocument(QString data) {
|
|||||||
do {
|
do {
|
||||||
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1);
|
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1);
|
||||||
++context_index;
|
++context_index;
|
||||||
}while(translation == word && context_index < 12);
|
}while(translation == word && context_index < 13);
|
||||||
//qDebug("Translation is %s", translation.toUtf8().data());
|
//qDebug("Translation is %s", translation.toUtf8().data());
|
||||||
data = data.replace(i, regex.matchedLength(), translation);
|
data = data.replace(i, regex.matchedLength(), translation);
|
||||||
i += translation.length();
|
i += translation.length();
|
||||||
|
44
src/json.h
44
src/json.h
@ -113,7 +113,24 @@ namespace json {
|
|||||||
if(json.startsWith("{") && json.endsWith("}")) {
|
if(json.startsWith("{") && json.endsWith("}")) {
|
||||||
json.chop(1);
|
json.chop(1);
|
||||||
json = json.replace(0, 1, "");
|
json = json.replace(0, 1, "");
|
||||||
QStringList couples = json.split(",");
|
QStringList couples;
|
||||||
|
QString tmp = "";
|
||||||
|
bool in_list = false;
|
||||||
|
foreach(QChar c, json) {
|
||||||
|
if(c == ',' && !in_list) {
|
||||||
|
couples << tmp;
|
||||||
|
tmp = "";
|
||||||
|
} else {
|
||||||
|
if(c == '[') {
|
||||||
|
in_list = true;
|
||||||
|
} else {
|
||||||
|
if(c == ']') {
|
||||||
|
in_list = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
foreach(QString couple, couples) {
|
foreach(QString couple, couples) {
|
||||||
QStringList parts = couple.split(":");
|
QStringList parts = couple.split(":");
|
||||||
if(parts.size() != 2) continue;
|
if(parts.size() != 2) continue;
|
||||||
@ -124,12 +141,29 @@ namespace json {
|
|||||||
}
|
}
|
||||||
QString value_str = parts.last();
|
QString value_str = parts.last();
|
||||||
QVariant value;
|
QVariant value;
|
||||||
if(value_str.startsWith("\"") && value_str.endsWith("\"")) {
|
if(value_str.startsWith("[") && value_str.endsWith("]")) {
|
||||||
value_str.chop(1);
|
value_str.chop(1);
|
||||||
value_str = value_str.replace(0, 1, "");
|
value_str.replace(0, 1, "");
|
||||||
value = value_str;
|
QStringList list_elems = value_str.split(",");
|
||||||
|
QVariantList varlist;
|
||||||
|
foreach(QString list_val, list_elems) {
|
||||||
|
if(list_val.startsWith("\"") && list_val.endsWith("\"")) {
|
||||||
|
list_val.chop(1);
|
||||||
|
list_val = list_val.replace(0, 1, "");
|
||||||
|
varlist << list_val;
|
||||||
|
} else {
|
||||||
|
varlist << list_val.toInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = varlist;
|
||||||
} else {
|
} else {
|
||||||
value = value_str.toInt();
|
if(value_str.startsWith("\"") && value_str.endsWith("\"")) {
|
||||||
|
value_str.chop(1);
|
||||||
|
value_str = value_str.replace(0, 1, "");
|
||||||
|
value = value_str;
|
||||||
|
} else {
|
||||||
|
value = value_str.toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.insert(key,value);
|
m.insert(key,value);
|
||||||
qDebug("%s:%s", key.toLocal8Bit().data(), value_str.toLocal8Bit().data());
|
qDebug("%s:%s", key.toLocal8Bit().data(), value_str.toLocal8Bit().data());
|
||||||
|
@ -100,12 +100,17 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: bottom; text-align: right;"></td><td><input type="text" id="temppath_text"/></td>
|
<td style="vertical-align: bottom; text-align: right;"></td><td><input type="text" id="temppath_text"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- <tr>
|
<tr><td colspan="2">_(Check Folders for .torrent Files:)</td></tr>
|
||||||
<td style="vertical-align: bottom; text-align: right;"><input type="checkbox" id="scandir_checkbox" onclick="updateScanDirEnabled();"/></td><td>_(Automatically load .torrent files from:)</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: bottom; text-align: right;"></td><td><input type="text" id="scandir_text"/></td>
|
<td></td>
|
||||||
</tr> -->
|
<td>
|
||||||
|
<table style="border: 1px solid black; text-align: center" id="watched_folders_tab">
|
||||||
|
<thead><tr style="border: 1px solid black;"><th>_(Watched Folder)</th><th>_(Download here)</th></tr></thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
<tfoot><tr style="border: 1px solid black;"><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="images/oxygen/list-add.png" alt="Add" style="padding-left:2px;width:16px;cursor:pointer;margin-right:-18px;" onclick="javascript:addWatchFolder();"/></td></tr></tfoot>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: bottom; text-align: right;"><input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();"/></td><td>_(Copy .torrent files to:)</td>
|
<td style="vertical-align: bottom; text-align: right;"><input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();"/></td><td>_(Copy .torrent files to:)</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -229,7 +234,7 @@
|
|||||||
<option value="ja_JP" title="Icons/flags/japan.png">日本語</option>
|
<option value="ja_JP" title="Icons/flags/japan.png">日本語</option>
|
||||||
<option value="zh_CN" title="Icons/flags/china.png">中文 (简体)</option>
|
<option value="zh_CN" title="Icons/flags/china.png">中文 (简体)</option>
|
||||||
<option value="zh_TW" title="Icons/flags/taiwan.png">中文 (繁體)</option>
|
<option value="zh_TW" title="Icons/flags/taiwan.png">中文 (繁體)</option>
|
||||||
<option value="ko_KR" title="Icons/flags/south_korea.png">한글"</option>
|
<option value="ko_KR" title="Icons/flags/south_korea.png">한글</option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -266,6 +271,8 @@
|
|||||||
<center><input type="button" value="_(Apply)" onclick="applyPreferences();"/></center>
|
<center><input type="button" value="_(Apply)" onclick="applyPreferences();"/></center>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
|
||||||
|
|
||||||
applyPreferences = function() {
|
applyPreferences = function() {
|
||||||
// Validate form data
|
// Validate form data
|
||||||
// Connection
|
// Connection
|
||||||
@ -340,12 +347,7 @@
|
|||||||
if($defined($('temppath_checkbox').get('checked')) && $('temppath_checkbox').get('checked'))
|
if($defined($('temppath_checkbox').get('checked')) && $('temppath_checkbox').get('checked'))
|
||||||
temp_path_enabled = 1;
|
temp_path_enabled = 1;
|
||||||
var temp_path = $('temppath_text').get('value');
|
var temp_path = $('temppath_text').get('value');
|
||||||
/*var scandir_enabled = 0;
|
var watched_folders = getWatchedFolders();
|
||||||
if($defined($('scandir_checkbox').get('checked')) && $('scandir_checkbox').get('checked'))
|
|
||||||
scandir_enabled = 1;
|
|
||||||
var scandir_path = '';
|
|
||||||
if(scandir_enabled)
|
|
||||||
scandir_path = $('scandir_text').get('value');*/
|
|
||||||
var exportdir_enabled = 0;
|
var exportdir_enabled = 0;
|
||||||
if($defined($('exportdir_checkbox').get('checked')) && $('exportdir_checkbox').get('checked'))
|
if($defined($('exportdir_checkbox').get('checked')) && $('exportdir_checkbox').get('checked'))
|
||||||
exportdir_enabled = 1;
|
exportdir_enabled = 1;
|
||||||
@ -467,7 +469,8 @@
|
|||||||
dict.set('save_path', save_path);
|
dict.set('save_path', save_path);
|
||||||
dict.set('temp_path_enabled', temp_path_enabled);
|
dict.set('temp_path_enabled', temp_path_enabled);
|
||||||
dict.set('temp_path', temp_path);
|
dict.set('temp_path', temp_path);
|
||||||
//dict.set('scan_dir', scandir_path);
|
dict.set('scan_dirs', watched_folders[0]);
|
||||||
|
dict.set('download_in_scan_dirs', watched_folders[1]);
|
||||||
dict.set('export_dir', exportdir_path);
|
dict.set('export_dir', exportdir_path);
|
||||||
dict.set('preallocate_all', preallocate_all);
|
dict.set('preallocate_all', preallocate_all);
|
||||||
if(!$('appendexttr').hasClass('invisible')) {
|
if(!$('appendexttr').hasClass('invisible')) {
|
||||||
@ -686,6 +689,47 @@ updatePeerProxyAuthSettings = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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).get('value').trim();
|
||||||
|
if(folder_path.length > 0) {
|
||||||
|
folders[folders.length] = folder_path;
|
||||||
|
if($defined($("cb_watch_"+i).get('checked')) && $("cb_watch_"+i).get('checked')) {
|
||||||
|
download_in_place[download_in_place.length] = 1;
|
||||||
|
} else {
|
||||||
|
download_in_place[download_in_place.length] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [folders, download_in_place];
|
||||||
|
}
|
||||||
|
|
||||||
|
addWatchFolder = function() {
|
||||||
|
var new_folder = $("new_watch_folder_txt").get('value').trim();
|
||||||
|
if(new_folder.length <= 0) return;
|
||||||
|
var download_here = ($defined($("new_watch_folder_dl").get('checked')) && $("new_watch_folder_dl").get('checked'));
|
||||||
|
var myinput = new Element("input");
|
||||||
|
var i = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length;
|
||||||
|
myinput.set('id', 'text_watch_'+i);
|
||||||
|
myinput.set('type', 'text');
|
||||||
|
myinput.set('value', new_folder);
|
||||||
|
var mycb = new Element("input");
|
||||||
|
mycb.set("type", "checkbox");
|
||||||
|
mycb.set("id", "cb_watch_"+i);
|
||||||
|
if(download_here) {
|
||||||
|
mycb.set("checked", "checked");
|
||||||
|
} else {
|
||||||
|
mycb.removeProperty('checked');
|
||||||
|
}
|
||||||
|
WatchedFoldersTable.push([myinput, mycb]);
|
||||||
|
// Clear fields
|
||||||
|
$("new_watch_folder_txt").set('value', '');
|
||||||
|
$("new_watch_folder_dl").removeProperty('checked');
|
||||||
|
}
|
||||||
|
|
||||||
loadPreferences = function() {
|
loadPreferences = function() {
|
||||||
var url = 'json/preferences';
|
var url = 'json/preferences';
|
||||||
var request = new Request.JSON({
|
var request = new Request.JSON({
|
||||||
@ -793,15 +837,23 @@ loadPreferences = function() {
|
|||||||
var temp_path = pref.temp_path;
|
var temp_path = pref.temp_path;
|
||||||
$('temppath_text').set('value', temp_path);
|
$('temppath_text').set('value', temp_path);
|
||||||
updateTempDirEnabled();
|
updateTempDirEnabled();
|
||||||
/*var scan_dir_enabled = pref.scan_dir_enabled;
|
var i = 0;
|
||||||
if(scan_dir_enabled) {
|
for(i=0; i<pref.scan_dirs.length; i+=1) {
|
||||||
$('scandir_text').set('value', pref.scan_dir);
|
var myinput = new Element("input");
|
||||||
$('scandir_checkbox').set('checked', 'checked');
|
myinput.set('id', 'text_watch_'+i);
|
||||||
} else {
|
myinput.set('type', 'text');
|
||||||
$('scandir_text').set('value', '');
|
myinput.set('value', pref.scan_dirs[i]);
|
||||||
$('scandir_checkbox').removeProperty('checked');
|
var mycb = new Element("input");
|
||||||
|
mycb.set("type", "checkbox");
|
||||||
|
mycb.set("id", "cb_watch_"+i);
|
||||||
|
if(pref.download_in_scan_dirs[i] == "true" || pref.download_in_scan_dirs[i] == 1) {
|
||||||
|
mycb.set("checked", "checked");
|
||||||
|
} else {
|
||||||
|
mycb.removeProperty('checked');
|
||||||
|
}
|
||||||
|
WatchedFoldersTable.push([myinput, mycb]);
|
||||||
}
|
}
|
||||||
updateScanDirEnabled();*/
|
|
||||||
var export_dir_enabled = pref.export_dir_enabled;
|
var export_dir_enabled = pref.export_dir_enabled;
|
||||||
if(export_dir_enabled) {
|
if(export_dir_enabled) {
|
||||||
$('exportdir_text').set('value', pref.export_dir);
|
$('exportdir_text').set('value', pref.export_dir);
|
||||||
@ -905,4 +957,4 @@ loadPreferences = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPreferences();
|
loadPreferences();
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user