-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebUI Add Limit Share Ratio context menu option #8598
Conversation
10c46dc
to
cf18fd0
Compare
src/webui/api/torrentscontroller.cpp
Outdated
ratioLimit = -1; | ||
|
||
qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong(); | ||
if (seedingTimeLimit == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use <=
?
And also in above instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you drop zero?
FYI, setRatioLimit/setSeedingTimeLimit checks its params for incorrect values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to handle the case where values of 0 should be treated as no limit. But the GUI doesn't seem to exhibit this behavior, so removing this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it does do this in UpDownRatioDlg::ratio()
. But this is WebUI-implementation specific so I'm now handling this in shareratio.html
's js logic.
if (hashes.length === 1) { | ||
var hash = hashes[0]; | ||
var row = torrentsTable.rows[hash].full_data; | ||
console.log(row); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't commit code in the early hours of the morning. Removing this.
height: 175 | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this empty line.
@@ -163,6 +162,33 @@ initializeWindows = function() { | |||
} | |||
}; | |||
|
|||
shareRatioFN = function() { | |||
console.log("Limit share ratio..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
@@ -387,13 +412,12 @@ initializeWindows = function() { | |||
if (hashes.length == 1) { | |||
var hash = hashes[0]; | |||
var row = torrentsTable.rows[hash]; | |||
if (row) { | |||
var name = row.full_data.name; | |||
if (row) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the curly braces, better safe than sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional's code block doesn't seem complex enough to warrant curly braces.
}; | ||
|
||
// select current values | ||
if (hashesList.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about if (hashesList.length !== 1) return;
? and you save some indention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've replaced this code.
if ($('setMinutes').get('checked')) | ||
seedingTimeLimitValue = $('minutes').get('value'); | ||
} | ||
else return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add braces here to be coherent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, it is not accepted to write consistent code in web development, as well as adhere to any other rules... Nothing personal, it follows from all my observations of the web code.
function getSelectedRadioValue(name) { | ||
var radios = document.getElementsByName(name); | ||
|
||
for (var i = 0; i < radios.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++i
and instances below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context the results are identical, and i++
is a lot more common in JavaScript. We have 39 instances of i++
in our js codebase, but only 1 instance of ++i
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm merely pointing out the coding style, until the coding guidelines extends to JS, I can't/won't force you to change it.
In this context the results are identical, and i++ is a lot more common in JavaScript.
Of course and I often wonder why that is the case in JS world given ++i
, i++
have the same counterparts in C++...
@@ -76,6 +76,11 @@ function friendlyPercentage(value) { | |||
return percentage.toFixed(1) + "%"; | |||
} | |||
|
|||
function friendlyFloat(value, precision) { | |||
var mult = Math.pow(10, precision); | |||
return Math.round(value * mult) / mult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fell over this... why multiply then divide?
can't you do return Math.round(value).toFixed(2)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so that we can round to a specific digit. Otherwise Math.round(value)
will round to the nearest int, with toFixed(2)
adding two zeros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining it.
AFAIK javascript numbers are always float
type, then this function can be just return value.toFixed(precision);
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK javascript numbers are always float type, then this function can be just return value.toFixed(precision); right?
You're right. That's a simpler solution too.
src/webui/www/private/index.html
Outdated
@@ -120,6 +120,7 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version | |||
</li> | |||
<li class="separator"><a href="#DownloadLimit"><img src="theme/kt-set-max-download-speed" alt="QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget]</a></li> | |||
<li><a href="#UploadLimit"><img src="theme/kt-set-max-upload-speed" alt="QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget]</a></li> | |||
<li><a href="#ShareRatio"><img src="theme/ratio" alt="QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget]</a></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the img src, there is already one at icons/skin/ratio.png, the webUI cannot access there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That version is 256x256 and 5x larger than this icon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's "usually" better to provide large image and scale it down than scale up small image, especially when high-dpi monitor is getting common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant 5x larger in terms of file size. In the WebUI this image has a static, specified height of 16px x 16px.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant 5x larger in terms of file size.
Surely our bottleneck isn't here... and almost all icons in the icon folder are 256x256, obviously you can see the motivation.
If you really insist adding the icon, move it to www/private/image folder.
In the WebUI this image has a static, specified height of 16px x 16px.
Would be better if we used em
as unit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better if we used em as unit.
This would be a great goal for a separate PR. I don't feel comfortable switching units for this small change.
src/webui/api/torrentscontroller.cpp
Outdated
@@ -622,6 +622,26 @@ void TorrentsController::setDownloadLimitAction() | |||
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *torrent) { torrent->setDownloadLimit(limit); }); | |||
} | |||
|
|||
void TorrentsController::setShareLimitAction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use setShareLimits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update this.
src/webui/api/torrentscontroller.cpp
Outdated
ratioLimit = -1; | ||
|
||
qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong(); | ||
if (seedingTimeLimit == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you drop zero?
FYI, setRatioLimit/setSeedingTimeLimit checks its params for incorrect values.
09564ab
to
7768630
Compare
Are per-torrent rate limits supposed to be persisted between application restarts? They appear not to be. |
What makes you think that? |
In my testing, custom ratios aren't persisted across restarts. "No limit" does appear to be persisted correctly. To reproduce:
|
This hasn't been my experience. I make extensive use of per-torrent share ratios (the reason I requested them for the WebUI) and if they didnt persist across restarts it would be a show stopper for me. What I have found and reported previously under #7335 is that the default global share ratio does not stick. If I set a default share ratio it gets applied to all torrents which dont already have an explicit per-torrent ratio set, but then after a reasonably short period of time (I havent timed it but its less than an hour or so) it just reverts back to Per-torrent share ratios are ok though. Im seeding a couple of hundred long-term torrents, all of which have per-torrent share ratios which have persisted through numerous application (and server) restarts. |
@Arathen what version of qBittorrent are you running? I'm experiencing this both on master and on 4.0.4. Can anyone else try to reproduce this and see if it works as expected? |
@Piccirello Im running master. |
It work as expected, I only tested in GUI. |
I first noticed it when testing the WebUI feature, but verified in the GUI. When testing master I'm exclusively checking the GUI. If anyone can confirm that the WebUI functionality works post-restart, I can just chalk it up to a local client issue. |
Confirmed. I grabbed down your PR, compiled and ran nox with it. Over the course of the last hour and a half I've successfully set per-torrent ratio limits via the WebUI and restarted the daemon half a dozen times. All per-torrent limits are preserved through the restarts just fine. I have not compiled or tested the GUI. Thank you again for implementing this @Piccirello. It truly is a game changing feature for me :) |
Thanks for confirming @Arathen. And glad I could get this feature implemented. With luck we can get this in 4.0.5. |
One minor issue that i've noticed with this - it doesn't seem to work on multiple torrent selections. It works great for a single torrent, but when you Control or Shift click to select multiple lines, clicking the "Save" button after setting a share ratio seems to do nothing. Like I said, its a minor issue. The overall functionality as it is now is completely usable and far outweighs the glitch. |
I'm so glad you caught this. This issue should now be fixed with the latest commit. Your testing is much appreciated! While working on this, I figured out my "local" issue with saving torrent share limits. Turns out that the torrents for which share limits aren't being persisted are all in an error state. Torrents in a good state (Paused, Downloading, Seeding, etc.) successfully persist share ratios across application reboots. |
<!DOCTYPE html> | ||
<html lang="${LANG}"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #8621 is merged now, can you please apply the changes to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to reflect the changes.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg]</title> | ||
<link rel="stylesheet" href="css/style.css" type="text/css" /> | ||
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the script tags too.
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script> | ||
<script type="text/javascript" src="scripts/misc.js"></script> | ||
<script type="text/javascript"> | ||
console.log("shareratio.html"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover. I've removed it.
src/webui/api/torrentscontroller.cpp
Outdated
|
||
const qreal ratioLimit = params()["ratioLimit"].toDouble(); | ||
const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong(); | ||
const QStringList hashes {params()["hashes"].split('|')}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency please change to: const QStringList hashes = params()["hashes"].split('|');
or you can choose using the curly braces in the above 2 lines instead.
And now its time to squash commits!
I'll turn a blind eye to the coding style comments on JS for now, mind you we also updated the coding guidelines recently (#8629 & #8640).
<title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg]</title> | ||
<link rel="stylesheet" href="css/style.css" type="text/css" /> | ||
<script src="scripts/mootools-1.2-core-yc.js"></script> | ||
<script src="scripts/mootools-1.2-more.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since #8672 is merged, please rebase this PR and also you'll need to change this to: scripts/lib/mootools-1.2-core-yc.js
, scripts/lib/mootools-1.2-more.js
.
0fa8746
to
adb0d2b
Compare
All commits have been squashed and rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Piccirello |
That would be a huge help. Finding time has been tough lately, and now I’m without a computer for the next several days. |
adb0d2b
to
9f36b54
Compare
Okay, its done now. |
@Chocobo1 thanks for taking care of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to change Wiki accordingly (both pages for current and new API).
No problem and thanks a lot for this. |
GUI:
WebUI: