Browse Source

- Started work on program preferences in Web UI

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
9a16a9d11b
  1. 12
      src/eventmanager.cpp
  2. 1
      src/eventmanager.h
  3. 52
      src/httpconnection.cpp
  4. 1
      src/httpconnection.h
  5. 21
      src/preferences.h
  6. 1
      src/webui.qrc
  7. 27
      src/webui/index.html
  8. 20
      src/webui/scripts/mocha-init.js

12
src/eventmanager.cpp

@ -32,6 +32,7 @@
#include "eventmanager.h" #include "eventmanager.h"
#include "bittorrent.h" #include "bittorrent.h"
#include "misc.h" #include "misc.h"
#include "preferences.h"
#include "proplistdelegate.h" #include "proplistdelegate.h"
#include "torrentpersistentdata.h" #include "torrentpersistentdata.h"
#include <QDebug> #include <QDebug>
@ -118,6 +119,17 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
return files; return files;
} }
QVariantMap EventManager::getGlobalPreferences() const {
QVariantMap data;
data["dl_limit"] = Preferences::getGlobalDownloadLimit();
data["up_limit"] = Preferences::getGlobalUploadLimit();
data["dht"] = Preferences::isDHTEnabled();
data["max_connec"] = Preferences::getMaxConnecs();
data["max_connec_per_torrent"] = Preferences::getMaxConnecsPerTorrent();
data["max_uploads_per_torrent"] = Preferences::getMaxUploadsPerTorrent();
return data;
}
QVariantMap EventManager::getPropGeneralInfo(QString hash) const { QVariantMap EventManager::getPropGeneralInfo(QString hash) const {
QVariantMap data; QVariantMap data;
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);

1
src/eventmanager.h

@ -54,6 +54,7 @@ class EventManager : public QObject
QVariantMap getPropGeneralInfo(QString hash) const; QVariantMap getPropGeneralInfo(QString hash) const;
QList<QVariantMap> getPropTrackersInfo(QString hash) const; QList<QVariantMap> getPropTrackersInfo(QString hash) const;
QList<QVariantMap> getPropFilesInfo(QString hash) const; QList<QVariantMap> getPropFilesInfo(QString hash) const;
QVariantMap getGlobalPreferences() const;
public slots: public slots:
void addedTorrent(QTorrentHandle& h); void addedTorrent(QTorrentHandle& h);

52
src/httpconnection.cpp

@ -32,6 +32,7 @@
#include "httpconnection.h" #include "httpconnection.h"
#include "httpserver.h" #include "httpserver.h"
#include "eventmanager.h" #include "eventmanager.h"
#include "preferences.h"
#include "json.h" #include "json.h"
#include "bittorrent.h" #include "bittorrent.h"
#include <QTcpSocket> #include <QTcpSocket>
@ -102,7 +103,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"}; std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget", "PropertiesWidget", "GUI", "MainWindow", "HttpServer", "confirmDeletionDlg", "TrackerList", "TorrentFilesModel", "options_imp"};
int i=0; int i=0;
bool found = false; bool found = false;
do { do {
@ -117,7 +118,7 @@ QString HttpConnection::translateDocument(QString data) {
do { do {
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1); translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1);
++context_index; ++context_index;
}while(translation == word && context_index < 9); }while(translation == word && context_index < 10);
//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();
@ -172,6 +173,10 @@ void HttpConnection::respond()
respondFilesPropertiesJson(hash); respondFilesPropertiesJson(hash);
return; return;
} }
} else {
if(list[1] == "preferences") {
respondPreferencesJson();
}
} }
} }
if (list[0] == "command") if (list[0] == "command")
@ -254,6 +259,14 @@ void HttpConnection::respondFilesPropertiesJson(QString hash) {
write(); write();
} }
void HttpConnection::respondPreferencesJson() {
EventManager* manager = parent->eventManager();
QString string = json::toJson(manager->getGlobalPreferences());
generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("js");
generator.setMessage(string);
write();
}
void HttpConnection::respondCommand(QString command) void HttpConnection::respondCommand(QString command)
{ {
@ -306,10 +319,43 @@ void HttpConnection::respondCommand(QString command)
emit pauseAllTorrents(); emit pauseAllTorrents();
return; return;
} }
if(command == "resume") { if(command == "resume") {
emit resumeTorrent(parser.post("hash")); emit resumeTorrent(parser.post("hash"));
return; return;
} }
if(command == "setPreferences") {
bool ok = false;
int dl_limit = parser.post("dl_limit").toInt(&ok);
if(ok) {
BTSession->setDownloadRateLimit(dl_limit*1024);
Preferences::setGlobalDownloadLimit(dl_limit);
}
int up_limit = parser.post("up_limit").toInt(&ok);
if(ok) {
BTSession->setUploadRateLimit(up_limit*1024);
Preferences::setGlobalUploadLimit(up_limit);
}
int dht_state = parser.post("dht").toInt(&ok);
if(ok) {
BTSession->enableDHT(dht_state == 1);
Preferences::setDHTEnabled(dht_state == 1);
}
int mac_connec = parser.post("mac_connec").toInt(&ok);
if(ok) {
BTSession->setMaxConnections(mac_connec);
Preferences::setMaxConnecs(mac_connec);
}
int max_connec_per_torrent = parser.post("mac_connec_per_torrent").toInt(&ok);
if(ok) {
BTSession->setMaxConnectionsPerTorrent(max_connec_per_torrent);
Preferences::setMaxConnecsPerTorrent(max_connec_per_torrent);
}
int max_uploads_per_torrent = parser.post("mac_uploads_per_torrent").toInt(&ok);
if(ok) {
BTSession->setMaxUploadsPerTorrent(max_uploads_per_torrent);
Preferences::setMaxUploadsPerTorrent(max_uploads_per_torrent);
}
}
if(command == "setFilePrio") { if(command == "setFilePrio") {
QString hash = parser.post("hash"); QString hash = parser.post("hash");
int file_id = parser.post("id").toInt(); int file_id = parser.post("id").toInt();

1
src/httpconnection.h

@ -59,6 +59,7 @@ class HttpConnection : public QObject
void respondGenPropertiesJson(QString hash); void respondGenPropertiesJson(QString hash);
void respondTrackersPropertiesJson(QString hash); void respondTrackersPropertiesJson(QString hash);
void respondFilesPropertiesJson(QString hash); void respondFilesPropertiesJson(QString hash);
void respondPreferencesJson();
void respondCommand(QString command); void respondCommand(QString command);
void respondNotFound(); void respondNotFound();
void processDownloadedFile(QString, QString); void processDownloadedFile(QString, QString);

21
src/preferences.h

@ -33,6 +33,7 @@
#include <QSettings> #include <QSettings>
#include <QPair> #include <QPair>
#include <QDir>
class Preferences { class Preferences {
public: public:
@ -311,21 +312,41 @@ public:
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt(); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), 500).toInt();
} }
static void setMaxConnecs(int val) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecs"), val);
}
static int getMaxConnecsPerTorrent() { static int getMaxConnecsPerTorrent() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt(); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), 100).toInt();
} }
static void setMaxConnecsPerTorrent(int val) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val);
}
static int getMaxUploadsPerTorrent() { static int getMaxUploadsPerTorrent() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt(); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt();
} }
static void setMaxUploadsPerTorrent(int val) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val);
}
static bool isDHTEnabled() { static bool isDHTEnabled() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool(); return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool();
} }
static void setDHTEnabled(bool enabled) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled);
}
static bool isDHTPortSameAsBT() { static bool isDHTPortSameAsBT() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool(); return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool();

1
src/webui.qrc

@ -13,6 +13,7 @@
<file>webui/properties.html</file> <file>webui/properties.html</file>
<file>webui/uploadlimit.html</file> <file>webui/uploadlimit.html</file>
<file>webui/downloadlimit.html</file> <file>webui/downloadlimit.html</file>
<file>webui/preferences.html</file>
<file>webui/css/mocha.css</file> <file>webui/css/mocha.css</file>
<file>webui/css/dynamicTable.css</file> <file>webui/css/dynamicTable.css</file>
<file>webui/css/style.css</file> <file>webui/css/style.css</file>

27
src/webui/index.html

@ -47,6 +47,12 @@
<li><a id="deletePermLink">_(Delete from HD)</a></li> <li><a id="deletePermLink">_(Delete from HD)</a></li>
</ul> </ul>
</li> </li>
<li>
<a class="returnFalse">_(Options)</a>
<ul>
<li><a id="preferencesLink">_(Preferences)</a></li>
</ul>
</li>
<li> <li>
<a class="returnFalse">_(Help)</a> <a class="returnFalse">_(Help)</a>
<ul> <ul>
@ -59,17 +65,18 @@
</ul> </ul>
</div> </div>
<div id="mochaToolbar"> <div id="mochaToolbar">
<a id="downloadButton"><img class="mochaToolButton" title="Download from URL" src="images/skin/url.png"/></a> <a id="downloadButton"><img class="mochaToolButton" title="_(Download from URL)" src="images/skin/url.png"/></a>
<a id="uploadButton"><img class="mochaToolButton" title="Download local torrent" src="images/skin/open.png"/></a> <a id="uploadButton"><img class="mochaToolButton" title="_(Download local torrent)" src="images/skin/open.png"/></a>
<a id="deleteButton"><img class="mochaToolButton" title="Delete" src="images/skin/delete.png"/></a> <a id="deleteButton"><img class="mochaToolButton" title="_(Delete)" src="images/skin/delete.png"/></a>
<a id="deletePermButton"><img class="mochaToolButton" title="Delete from HD" src="images/skin/delete_perm.png"/></a> <a id="deletePermButton"><img class="mochaToolButton" title="_(Delete from HD)" src="images/skin/delete_perm.png"/></a>
<a id="resumeButton"><img class="mochaToolButton" title="Resume" src="images/skin/play.png"/></a> <a id="resumeButton"><img class="mochaToolButton" title="_(Start)" src="images/skin/play.png"/></a>
<a id="pauseButton"><img class="mochaToolButton" title="Pause" src="images/skin/pause.png"/></a> <a id="pauseButton"><img class="mochaToolButton" title="_(Pause)" src="images/skin/pause.png"/></a>
<a id="resumeAllButton"><img class="mochaToolButton" title="Resume all" src="images/skin/play_all.png"/></a> <a id="resumeAllButton"><img class="mochaToolButton" title="_(Start All)" src="images/skin/play_all.png"/></a>
<a id="pauseAllButton"><img class="mochaToolButton" title="Pause All" src="images/skin/pause_all.png"/></a> <a id="pauseAllButton"><img class="mochaToolButton" title="_(Pause All)" src="images/skin/pause_all.png"/></a>
<a id="preferencesButton"><img class="mochaToolButton" title="_(Preferences)" src="images/skin/settings.png"/></a>
<span id="queueingButtons"> <span id="queueingButtons">
<a id="decreasePrioButton"><img class="mochaToolButton" title="Decrease priority" src="images/skin/decrease.png"/></a> <a id="decreasePrioButton"><img class="mochaToolButton" title="_(Decrease priority)" src="images/skin/decrease.png"/></a>
<a id="increasePrioButton"><img class="mochaToolButton" title="Increase priority" src="images/skin/increase.png"/></a> <a id="increasePrioButton"><img class="mochaToolButton" title="_(Increase priority)" src="images/skin/increase.png"/></a>
</span> </span>
</div> </div>
</div> </div>

20
src/webui/scripts/mocha-init.js

@ -23,7 +23,7 @@ initializeWindows = function(){
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({
id: 'downloadPage', id: 'downloadPage',
title: "(Download from URL)", title: "_(Download from URL)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'download.html', contentURL:'download.html',
scrollbars: false, scrollbars: false,
@ -37,6 +37,24 @@ initializeWindows = function(){
}); });
}); });
addClickEvent('preferences', function(e) {
new Event(e).stop();
new MochaUI.Window({
id: 'preferencesPage',
title: "_(Preferences)",
loadMethod: 'iframe',
contentURL:'preferences.html',
scrollbars: false,
resizable: false,
maximizable: false,
closable: true,
paddingVertical: 0,
paddingHorizontal: 0,
width: 500,
height: 270
});
});
addClickEvent('upload', function(e){ addClickEvent('upload', function(e){
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({

Loading…
Cancel
Save