mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-04 10:54:35 +00:00
- Started work on program preferences in Web UI
This commit is contained in:
parent
52ac94cc73
commit
9a16a9d11b
@ -32,6 +32,7 @@
|
||||
#include "eventmanager.h"
|
||||
#include "bittorrent.h"
|
||||
#include "misc.h"
|
||||
#include "preferences.h"
|
||||
#include "proplistdelegate.h"
|
||||
#include "torrentpersistentdata.h"
|
||||
#include <QDebug>
|
||||
@ -118,6 +119,17 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
||||
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 data;
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
|
@ -54,6 +54,7 @@ class EventManager : public QObject
|
||||
QVariantMap getPropGeneralInfo(QString hash) const;
|
||||
QList<QVariantMap> getPropTrackersInfo(QString hash) const;
|
||||
QList<QVariantMap> getPropFilesInfo(QString hash) const;
|
||||
QVariantMap getGlobalPreferences() const;
|
||||
|
||||
public slots:
|
||||
void addedTorrent(QTorrentHandle& h);
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "httpconnection.h"
|
||||
#include "httpserver.h"
|
||||
#include "eventmanager.h"
|
||||
#include "preferences.h"
|
||||
#include "json.h"
|
||||
#include "bittorrent.h"
|
||||
#include <QTcpSocket>
|
||||
@ -102,7 +103,7 @@ void HttpConnection::write()
|
||||
}
|
||||
|
||||
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;
|
||||
bool found = false;
|
||||
do {
|
||||
@ -117,7 +118,7 @@ QString HttpConnection::translateDocument(QString data) {
|
||||
do {
|
||||
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1);
|
||||
++context_index;
|
||||
}while(translation == word && context_index < 9);
|
||||
}while(translation == word && context_index < 10);
|
||||
//qDebug("Translation is %s", translation.toUtf8().data());
|
||||
data = data.replace(i, regex.matchedLength(), translation);
|
||||
i += translation.length();
|
||||
@ -172,6 +173,10 @@ void HttpConnection::respond()
|
||||
respondFilesPropertiesJson(hash);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(list[1] == "preferences") {
|
||||
respondPreferencesJson();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list[0] == "command")
|
||||
@ -254,6 +259,14 @@ void HttpConnection::respondFilesPropertiesJson(QString hash) {
|
||||
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)
|
||||
{
|
||||
@ -306,10 +319,43 @@ void HttpConnection::respondCommand(QString command)
|
||||
emit pauseAllTorrents();
|
||||
return;
|
||||
}
|
||||
if(command == "resume") {
|
||||
if(command == "resume") {
|
||||
emit resumeTorrent(parser.post("hash"));
|
||||
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") {
|
||||
QString hash = parser.post("hash");
|
||||
int file_id = parser.post("id").toInt();
|
||||
|
@ -59,6 +59,7 @@ class HttpConnection : public QObject
|
||||
void respondGenPropertiesJson(QString hash);
|
||||
void respondTrackersPropertiesJson(QString hash);
|
||||
void respondFilesPropertiesJson(QString hash);
|
||||
void respondPreferencesJson();
|
||||
void respondCommand(QString command);
|
||||
void respondNotFound();
|
||||
void processDownloadedFile(QString, QString);
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <QSettings>
|
||||
#include <QPair>
|
||||
#include <QDir>
|
||||
|
||||
class Preferences {
|
||||
public:
|
||||
@ -311,21 +312,41 @@ public:
|
||||
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() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
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() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
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() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
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() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
return settings.value(QString::fromUtf8("Preferences/Bittorrent/sameDHTPortAsBT"), true).toBool();
|
||||
|
@ -13,6 +13,7 @@
|
||||
<file>webui/properties.html</file>
|
||||
<file>webui/uploadlimit.html</file>
|
||||
<file>webui/downloadlimit.html</file>
|
||||
<file>webui/preferences.html</file>
|
||||
<file>webui/css/mocha.css</file>
|
||||
<file>webui/css/dynamicTable.css</file>
|
||||
<file>webui/css/style.css</file>
|
||||
|
@ -47,6 +47,12 @@
|
||||
<li><a id="deletePermLink">_(Delete from HD)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="returnFalse">_(Options)</a>
|
||||
<ul>
|
||||
<li><a id="preferencesLink">_(Preferences)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="returnFalse">_(Help)</a>
|
||||
<ul>
|
||||
@ -59,17 +65,18 @@
|
||||
</ul>
|
||||
</div>
|
||||
<div id="mochaToolbar">
|
||||
<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="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="resumeButton"><img class="mochaToolButton" title="Resume" src="images/skin/play.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="pauseAllButton"><img class="mochaToolButton" title="Pause All" src="images/skin/pause_all.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="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="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="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="preferencesButton"><img class="mochaToolButton" title="_(Preferences)" src="images/skin/settings.png"/></a>
|
||||
<span id="queueingButtons">
|
||||
<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="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>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -23,7 +23,7 @@ initializeWindows = function(){
|
||||
new Event(e).stop();
|
||||
new MochaUI.Window({
|
||||
id: 'downloadPage',
|
||||
title: "(Download from URL)",
|
||||
title: "_(Download from URL)",
|
||||
loadMethod: 'iframe',
|
||||
contentURL:'download.html',
|
||||
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){
|
||||
new Event(e).stop();
|
||||
new MochaUI.Window({
|
||||
|
Loading…
x
Reference in New Issue
Block a user