Browse Source

Merge pull request #2277 from buinsky/master

Some changes in WebUI
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
47e7b3fac2
  1. 2
      src/qtlibtorrent/qtorrenthandle.cpp
  2. 2
      src/webui/abstractrequesthandler.cpp
  3. 8
      src/webui/btjson.cpp
  4. 5
      src/webui/www/public/downloadlimit.html
  5. 16
      src/webui/www/public/scripts/client.js
  6. 69
      src/webui/www/public/scripts/parametrics.js
  7. 5
      src/webui/www/public/uploadlimit.html

2
src/qtlibtorrent/qtorrenthandle.cpp

@ -63,12 +63,10 @@ static QPair<int, int> get_file_extremity_pieces(const torrent_info& t, int file
// Determine the first and last piece of the file // Determine the first and last piece of the file
int first_piece = floor((file.offset + 1) / (float) piece_size); int first_piece = floor((file.offset + 1) / (float) piece_size);
Q_ASSERT(first_piece >= 0 && first_piece < num_pieces); Q_ASSERT(first_piece >= 0 && first_piece < num_pieces);
qDebug("First piece of the file is %d/%d", first_piece, num_pieces - 1);
int num_pieces_in_file = ceil(file.size / (float) piece_size); int num_pieces_in_file = ceil(file.size / (float) piece_size);
int last_piece = first_piece + num_pieces_in_file - 1; int last_piece = first_piece + num_pieces_in_file - 1;
Q_ASSERT(last_piece >= 0 && last_piece < num_pieces); Q_ASSERT(last_piece >= 0 && last_piece < num_pieces);
qDebug("last piece of the file is %d/%d", last_piece, num_pieces - 1);
return qMakePair(first_piece, last_piece); return qMakePair(first_piece, last_piece);
} }

2
src/webui/abstractrequesthandler.cpp

@ -45,8 +45,6 @@ AbstractRequestHandler::AbstractRequestHandler(const HttpRequest &request, const
HttpResponse AbstractRequestHandler::run() HttpResponse AbstractRequestHandler::run()
{ {
response_ = HttpResponse();
if (isBanned()) { if (isBanned()) {
status(403, "Forbidden"); status(403, "Forbidden");
print(QObject::tr("Your IP address has been banned after too many failed authentication attempts."), CONTENT_TYPE_TXT); print(QObject::tr("Your IP address has been banned after too many failed authentication attempts."), CONTENT_TYPE_TXT);

8
src/webui/btjson.cpp

@ -45,6 +45,7 @@
#endif #endif
#include <libtorrent/session_status.hpp> #include <libtorrent/session_status.hpp>
#include <libtorrent/session.hpp>
using namespace libtorrent; using namespace libtorrent;
@ -135,8 +136,10 @@ static const char KEY_FILE_IS_SEED[] = "is_seed";
// TransferInfo keys // TransferInfo keys
static const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed"; static const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed";
static const char KEY_TRANSFER_DLDATA[] = "dl_info_data"; static const char KEY_TRANSFER_DLDATA[] = "dl_info_data";
static const char KEY_TRANSFER_DLRATELIMIT[] = "dl_rate_limit";
static const char KEY_TRANSFER_UPSPEED[] = "up_info_speed"; static const char KEY_TRANSFER_UPSPEED[] = "up_info_speed";
static const char KEY_TRANSFER_UPDATA[] = "up_info_data"; static const char KEY_TRANSFER_UPDATA[] = "up_info_data";
static const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit";
class QTorrentCompare class QTorrentCompare
{ {
@ -448,9 +451,14 @@ QByteArray btjson::getTransferInfo()
{ {
CACHED_VARIABLE(QVariantMap, info, CACHE_DURATION_MS); CACHED_VARIABLE(QVariantMap, info, CACHE_DURATION_MS);
session_status sessionStatus = QBtSession::instance()->getSessionStatus(); session_status sessionStatus = QBtSession::instance()->getSessionStatus();
session_settings sessionSettings = QBtSession::instance()->getSession()->settings();
info[KEY_TRANSFER_DLSPEED] = sessionStatus.payload_download_rate; info[KEY_TRANSFER_DLSPEED] = sessionStatus.payload_download_rate;
info[KEY_TRANSFER_DLDATA] = static_cast<qlonglong>(sessionStatus.total_payload_download); info[KEY_TRANSFER_DLDATA] = static_cast<qlonglong>(sessionStatus.total_payload_download);
info[KEY_TRANSFER_UPSPEED] = sessionStatus.payload_upload_rate; info[KEY_TRANSFER_UPSPEED] = sessionStatus.payload_upload_rate;
info[KEY_TRANSFER_UPDATA] = static_cast<qlonglong>(sessionStatus.total_payload_upload); info[KEY_TRANSFER_UPDATA] = static_cast<qlonglong>(sessionStatus.total_payload_upload);
if (sessionSettings.download_rate_limit)
info[KEY_TRANSFER_DLRATELIMIT] = sessionSettings.download_rate_limit;
if (sessionSettings.upload_rate_limit)
info[KEY_TRANSFER_UPRATELIMIT] = sessionSettings.upload_rate_limit;
return json::toJson(info); return json::toJson(info);
} }

5
src/webui/www/public/downloadlimit.html

@ -4,7 +4,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>_(Torrent Download Speed Limiting)</title> <title>_(Torrent Download Speed Limiting)</title>
<link rel="stylesheet" href="css/style.css" type="text/css" /> <link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/mocha.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mocha-yc.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mocha-yc.js" charset="utf-8"></script>
@ -13,7 +12,7 @@
<body> <body>
<div style="width: 100%; text-align: center; margin: 0 auto;"> <div style="width: 100%; text-align: center; margin: 0 auto;">
<div id="dllimitSlider" class="slider"> <div id="dllimitSlider" class="slider">
<div id="dllimitUpdate" class="update">_(Download limit:) <span id="dllimitUpdatevalue" class="updatevalue">0</span> <span id="dlLimitUnit">_(KiB/s)</span></div> <div id="dllimitUpdate" class="update">_(Download limit:) <input id="dllimitUpdatevalue" size="6" placeholder="∞" style="text-align: center;"> <span id="dlLimitUnit">_(KiB/s)</span></div>
<div class="sliderWrapper"> <div class="sliderWrapper">
<div id="dllimitSliderknob" class="sliderknob"></div> <div id="dllimitSliderknob" class="sliderknob"></div>
<div id="dllimitSliderarea" class="sliderarea"></div> <div id="dllimitSliderarea" class="sliderarea"></div>
@ -23,7 +22,7 @@
<script type="text/javascript"> <script type="text/javascript">
var hash = new URI().getData('hash'); var hash = new URI().getData('hash');
setDlLimit = function() { setDlLimit = function() {
var limit = $("dllimitUpdatevalue").get('html').toInt() * 1024; var limit = $("dllimitUpdatevalue").value.toInt() * 1024;
if(hash == "global") { if(hash == "global") {
new Request({url: 'command/setGlobalDlLimit', new Request({url: 'command/setGlobalDlLimit',
method: 'post', method: 'post',

16
src/webui/www/public/scripts/client.js

@ -240,12 +240,20 @@ window.addEvent('load', function () {
}, },
onSuccess : function (info) { onSuccess : function (info) {
if (info) { if (info) {
$("DlInfos").set('html', "_(D: %1 - T: %2)" dl_limit = "";
if (info.dl_rate_limit != undefined)
dl_limit = "[%1] ".replace("%1", friendlyUnit(info.dl_rate_limit, true));
$("DlInfos").set('html', "%3_(D: %1 - T: %2)"
.replace("%1", friendlyUnit(info.dl_info_speed, true)) .replace("%1", friendlyUnit(info.dl_info_speed, true))
.replace("%2", friendlyUnit(info.dl_info_data, false))); .replace("%2", friendlyUnit(info.dl_info_data, false))
$("UpInfos").set('html', "_(U: %1 - T: %2)" .replace("%3", dl_limit));
up_limit = "";
if (info.up_rate_limit != undefined)
up_limit = "[%1] ".replace("%1", friendlyUnit(info.up_rate_limit, true));
$("UpInfos").set('html', "%3_(U: %1 - T: %2)"
.replace("%1", friendlyUnit(info.up_info_speed, true)) .replace("%1", friendlyUnit(info.up_info_speed, true))
.replace("%2", friendlyUnit(info.up_info_data, false))); .replace("%2", friendlyUnit(info.up_info_data, false))
.replace("%3", up_limit));
if (speedInTitle) if (speedInTitle)
document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true)); document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true));
else else

69
src/webui/www/public/scripts/parametrics.js

@ -46,23 +46,23 @@ MochaUI.extend({
initialStep: up_limit.round(), initialStep: up_limit.round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('uplimitUpdatevalue').set('html', pos); $('uplimitUpdatevalue').value = pos;
$('upLimitUnit').set('html', "_(KiB/s)"); $('upLimitUnit').style.visibility = "visible";
} }
else { else {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').set('html', ""); $('upLimitUnit').style.visibility = "hidden";
} }
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (up_limit == 0) { if (up_limit == 0) {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').set('html', ""); $('upLimitUnit').style.visibility = "hidden";
} }
else { else {
$('uplimitUpdatevalue').set('html', up_limit.round()); $('uplimitUpdatevalue').value = up_limit.round();
$('upLimitUnit').set('html', "_(KiB/s)"); $('upLimitUnit').style.visibility = "visible";
} }
} }
else { else {
@ -82,23 +82,23 @@ MochaUI.extend({
initialStep: (up_limit / 1024.).round(), initialStep: (up_limit / 1024.).round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('uplimitUpdatevalue').set('html', pos); $('uplimitUpdatevalue').value = pos;
$('upLimitUnit').set('html', "_(KiB/s)"); $('upLimitUnit').style.visibility = "visible";
} }
else { else {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').set('html', ""); $('upLimitUnit').style.visibility = "hidden";
} }
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (up_limit == 0) { if (up_limit == 0) {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').set('html', ""); $('upLimitUnit').style.visibility = "hidden";
} }
else { else {
$('uplimitUpdatevalue').set('html', (up_limit / 1024.).round()); $('uplimitUpdatevalue').value = (up_limit / 1024.).round();
$('upLimitUnit').set('html', "_(KiB/s)"); $('upLimitUnit').style.visibility = "visible";
} }
} }
} }
@ -126,7 +126,10 @@ MochaUI.extend({
maximum = tmp / 1024. maximum = tmp / 1024.
} }
else { else {
maximum = 1000 if (hash == "global")
maximum = 10000;
else
maximum = 1000;
} }
} }
// Get torrent download limit // Get torrent download limit
@ -141,23 +144,23 @@ MochaUI.extend({
initialStep: dl_limit.round(), initialStep: dl_limit.round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('dllimitUpdatevalue').set('html', pos); $('dllimitUpdatevalue').value = pos;
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dlLimitUnit').style.visibility = "visible";
} }
else { else {
$('dllimitUpdatevalue').set('html', '∞'); $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').set('html', ""); $('dlLimitUnit').style.visibility = "hidden";
} }
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (dl_limit == 0) { if (dl_limit == 0) {
$('dllimitUpdatevalue').set('html', '∞'); $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').set('html', ""); $('dlLimitUnit').style.visibility = "hidden";
} }
else { else {
$('dllimitUpdatevalue').set('html', dl_limit.round()); $('dllimitUpdatevalue').value = dl_limit.round();
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dlLimitUnit').style.visibility = "visible";
} }
} }
else { else {
@ -177,23 +180,23 @@ MochaUI.extend({
initialStep: (dl_limit / 1024.).round(), initialStep: (dl_limit / 1024.).round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('dllimitUpdatevalue').set('html', pos); $('dllimitUpdatevalue').value = pos;
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dlLimitUnit').style.visibility = "visible";
} }
else { else {
$('dllimitUpdatevalue').set('html', '∞'); $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').set('html', ""); $('dlLimitUnit').style.visibility = "hidden";
} }
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (dl_limit == 0) { if (dl_limit == 0) {
$('dllimitUpdatevalue').set('html', '∞'); $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').set('html', ""); $('dlLimitUnit').style.visibility = "hidden";
} }
else { else {
$('dllimitUpdatevalue').set('html', (dl_limit / 1024.).round()); $('dllimitUpdatevalue').value = (dl_limit / 1024.).round();
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dlLimitUnit').style.visibility = "visible";
} }
} }
} }

5
src/webui/www/public/uploadlimit.html

@ -4,7 +4,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>_(Torrent Upload Speed Limiting)</title> <title>_(Torrent Upload Speed Limiting)</title>
<link rel="stylesheet" href="css/style.css" type="text/css" /> <link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/mocha.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mocha-yc.js" charset="utf-8"></script> <script type="text/javascript" src="scripts/mocha-yc.js" charset="utf-8"></script>
@ -13,7 +12,7 @@
<body> <body>
<div style="width: 100%; text-align: center; margin: 0 auto;"> <div style="width: 100%; text-align: center; margin: 0 auto;">
<div id="uplimitSlider" class="slider"> <div id="uplimitSlider" class="slider">
<div id="uplimitUpdate" class="update">_(Upload limit:) <span id="uplimitUpdatevalue" class="updatevalue">0</span> <span id="upLimitUnit">_(KiB/s)</span></div> <div id="uplimitUpdate" class="update">_(Upload limit:) <input id="uplimitUpdatevalue" size="6" placeholder="∞" style="text-align: center;"> <span id="upLimitUnit">_(KiB/s)</span></div>
<div class="sliderWrapper"> <div class="sliderWrapper">
<div id="uplimitSliderknob" class="sliderknob"></div> <div id="uplimitSliderknob" class="sliderknob"></div>
<div id="uplimitSliderarea" class="sliderarea"></div> <div id="uplimitSliderarea" class="sliderarea"></div>
@ -23,7 +22,7 @@
<script type="text/javascript"> <script type="text/javascript">
var hash = new URI().getData('hash'); var hash = new URI().getData('hash');
setUpLimit = function() { setUpLimit = function() {
var limit = $("uplimitUpdatevalue").get('html').toInt() * 1024; var limit = $("uplimitUpdatevalue").value.toInt() * 1024;
if(hash == "global") { if(hash == "global") {
new Request({url: 'command/setGlobalUpLimit', new Request({url: 'command/setGlobalUpLimit',
method: 'post', method: 'post',

Loading…
Cancel
Save