From 912056a36422c43b75e260b2c30206b3d22f1d40 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 18 Mar 2010 19:25:16 +0000 Subject: [PATCH] Added back folder watching in Web UI --- src/bittorrent.cpp | 4 ++ src/bittorrent.h | 1 + src/eventmanager.cpp | 20 ++++++- src/httpconnection.cpp | 4 +- src/json.h | 44 ++++++++++++-- src/webui/preferences_content.html | 96 +++++++++++++++++++++++------- 6 files changed, 138 insertions(+), 31 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 46d689607..68810f954 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -197,6 +197,10 @@ void Bittorrent::preAllocateAllFiles(bool b) { } } +ScanFoldersModel* Bittorrent::getScanFoldersModel() const { + return m_scanFolders; +} + void Bittorrent::deleteBigRatios() { if(ratio_limit == -1) return; std::vector torrents = getTorrents(); diff --git a/src/bittorrent.h b/src/bittorrent.h index a03dbea26..206fcb3c8 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -115,6 +115,7 @@ public: qlonglong getETA(QString hash); bool useTemporaryFolder() const; QString getDefaultSavePath() const; + ScanFoldersModel* getScanFoldersModel() const; public slots: QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 923f7b044..af8054a8d 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -31,6 +31,7 @@ #include "eventmanager.h" #include "bittorrent.h" +#include "scannedfoldersmodel.h" #include "misc.h" #include "preferences.h" //#include "proplistdelegate.h" @@ -129,8 +130,23 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool()); if(m.contains("temp_path")) Preferences::setTempPath(m["temp_path"].toString()); - if(m.contains("scan_dirs")) - Preferences::setScanDirs(m["scan_dirs"].toStringList()); + if(m.contains("scan_dirs")) { + 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")) Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList()); if(m.contains("export_dir")) diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index ac267d18b..404d7a4fc 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -104,7 +104,7 @@ void HttpConnection::write() } 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; bool found = false; do { @@ -119,7 +119,7 @@ QString HttpConnection::translateDocument(QString data) { do { translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1); ++context_index; - }while(translation == word && context_index < 12); + }while(translation == word && context_index < 13); //qDebug("Translation is %s", translation.toUtf8().data()); data = data.replace(i, regex.matchedLength(), translation); i += translation.length(); diff --git a/src/json.h b/src/json.h index e15030455..22ceadccb 100644 --- a/src/json.h +++ b/src/json.h @@ -113,7 +113,24 @@ namespace json { if(json.startsWith("{") && json.endsWith("}")) { json.chop(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) { QStringList parts = couple.split(":"); if(parts.size() != 2) continue; @@ -124,12 +141,29 @@ namespace json { } QString value_str = parts.last(); QVariant value; - if(value_str.startsWith("\"") && value_str.endsWith("\"")) { + if(value_str.startsWith("[") && value_str.endsWith("]")) { value_str.chop(1); - value_str = value_str.replace(0, 1, ""); - value = value_str; + value_str.replace(0, 1, ""); + 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 { - 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); qDebug("%s:%s", key.toLocal8Bit().data(), value_str.toLocal8Bit().data()); diff --git a/src/webui/preferences_content.html b/src/webui/preferences_content.html index 423c301c9..361095d5e 100644 --- a/src/webui/preferences_content.html +++ b/src/webui/preferences_content.html @@ -100,12 +100,17 @@ - + + + + + + +
_(Watched Folder)_(Download here)
Add
+ + _(Copy .torrent files to:) @@ -229,7 +234,7 @@ - + @@ -266,6 +271,8 @@
\ No newline at end of file +