Browse Source

Web UI: Add support for speed limits scheduling

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
1b8a2bf7c1
  1. 2
      src/preferences/options.ui
  2. 26
      src/webui/eventmanager.cpp
  3. 133
      src/webui/html/preferences_content.html

2
src/preferences/options.ui

@ -1419,7 +1419,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-40</y>
<width>494</width> <width>494</width>
<height>454</height> <height>454</height>
</rect> </rect>

26
src/webui/eventmanager.cpp

@ -236,6 +236,22 @@ void EventManager::setGlobalPreferences(QVariantMap m) {
#endif #endif
if(m.contains("limit_tcp_overhead")) if(m.contains("limit_tcp_overhead"))
pref.includeOverheadInLimits(m["limit_tcp_overhead"].toBool()); pref.includeOverheadInLimits(m["limit_tcp_overhead"].toBool());
if(m.contains("alt_dl_limit"))
pref.setAltGlobalDownloadLimit(m["alt_dl_limit"].toInt());
if(m.contains("alt_up_limit"))
pref.setAltGlobalUploadLimit(m["alt_up_limit"].toInt());
if(m.contains("scheduler_enabled"))
pref.setSchedulerEnabled(m["scheduler_enabled"].toBool());
if(m.contains("schedule_from_hour") && m.contains("schedule_from_min")) {
pref.setSchedulerStartTime(QTime(m["schedule_from_hour"].toInt(),
m["schedule_from_min"].toInt()));
}
if(m.contains("schedule_to_hour") && m.contains("schedule_to_min")) {
pref.setSchedulerEndTime(QTime(m["schedule_to_hour"].toInt(),
m["schedule_to_min"].toInt()));
}
if(m.contains("scheduler_days"))
pref.setSchedulerDays(scheduler_days(m["scheduler_days"].toInt()));
// Bittorrent // Bittorrent
if(m.contains("dht")) if(m.contains("dht"))
pref.setDHTEnabled(m["dht"].toBool()); pref.setDHTEnabled(m["dht"].toBool());
@ -360,6 +376,16 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["limit_utp_rate"] = pref.isuTPRateLimited(); data["limit_utp_rate"] = pref.isuTPRateLimited();
#endif #endif
data["limit_tcp_overhead"] = pref.includeOverheadInLimits(); data["limit_tcp_overhead"] = pref.includeOverheadInLimits();
data["alt_dl_limit"] = pref.getAltGlobalDownloadLimit();
data["alt_up_limit"] = pref.getAltGlobalUploadLimit();
data["scheduler_enabled"] = pref.isSchedulerEnabled();
const QTime start_time = pref.getSchedulerStartTime();
data["schedule_from_hour"] = start_time.hour();
data["schedule_from_min"] = start_time.minute();
const QTime end_time = pref.getSchedulerEndTime();
data["schedule_to_hour"] = end_time.hour();
data["schedule_to_min"] = end_time.minute();
data["scheduler_days"] = pref.getSchedulerDays();
// Bittorrent // Bittorrent
data["dht"] = pref.isDHTEnabled(); data["dht"] = pref.isDHTEnabled();
data["dhtSameAsBT"] = pref.isDHTPortSameAsBT(); data["dhtSameAsBT"] = pref.isDHTPortSameAsBT();

133
src/webui/html/preferences_content.html

@ -1,4 +1,4 @@
<div id="ConnectionTab" class="PrefTab"> <div id="ConnectionTab" class="PrefTab">
<fieldset class="settings"> <fieldset class="settings">
<legend>_(Listening Port)</legend> <legend>_(Listening Port)</legend>
<label for="port_value">_(Port used for incoming connections:)</label> <label for="port_value">_(Port used for incoming connections:)</label>
@ -60,6 +60,47 @@
<label for="limit_tcp_overhead_checkbox">_(Apply rate limit to transport overhead)</label><br/> <label for="limit_tcp_overhead_checkbox">_(Apply rate limit to transport overhead)</label><br/>
</fieldset> </fieldset>
</fieldset> </fieldset>
<fieldset class="settings">
<legend>_(Alternative Global Rate Limits)</legend>
<table>
<tr>
<td>
_(Upload:)
</td>
<td><input type="text" id="alt_up_limit_value" style="width: 4em;"/>&nbsp;&nbsp;_(KiB/s)</td>
</tr>
<tr>
<td>
_(Download:)
</td>
<td><input type="text" id="alt_dl_limit_value" style="width: 4em;"/>&nbsp;&nbsp;_(KiB/s)</td>
</tr>
</table>
<fieldset class="settings">
<legend><input type="checkbox" id="limit_sheduling_checkbox" onClick="updateSchedulingEnabled();"/>
<label for="limit_sheduling_checkbox">_(Schedule the use of alternative rate limits)</label></legend>
_(from)
<input type="text" id="schedule_from_hour" style="width: 1.5em;"/>:<input type="text" id="schedule_from_min" style="width: 1.5em;"/>
_(to)
<input type="text" id="schedule_to_hour" style="width: 1.5em;"/>:<input type="text" id="schedule_to_min" style="width: 1.5em;"/>
<br/>
_(When:)
<select id="schedule_freq_select">
<option value="0">_(Every day)</option>
<option value="1">_(Week days)</option>
<option value="2">_(Week ends)</option>
<option value="3">_(Monday)</option>
<option value="4">_(Tuesday)</option>
<option value="5">_(Wednesday)</option>
<option value="6">_(Thursday)</option>
<option value="7">_(Friday)</option>
<option value="8">_(Saturday)</option>
<option value="9">_(Sunday)</option>
</select>
</br/>
</fieldset>
</fieldset>
</div> </div>
<div id="BittorrentTab" class="PrefTab invisible"> <div id="BittorrentTab" class="PrefTab invisible">
@ -344,6 +385,22 @@ updateDlLimitEnabled = function() {
} }
} }
updateSchedulingEnabled = function() {
if($('limit_sheduling_checkbox').getProperty('checked')) {
$('schedule_from_hour').setProperty('disabled', false);
$('schedule_from_min').setProperty('disabled', false);
$('schedule_to_hour').setProperty('disabled', false);
$('schedule_to_min').setProperty('disabled', false);
$('schedule_freq_select').setProperty('disabled', false);
} else {
$('schedule_from_hour').setProperty('disabled', true);
$('schedule_from_min').setProperty('disabled', true);
$('schedule_to_hour').setProperty('disabled', true);
$('schedule_to_min').setProperty('disabled', true);
$('schedule_freq_select').setProperty('disabled', true);
}
}
updateUpLimitEnabled = function() { updateUpLimitEnabled = function() {
if($('up_limit_checkbox').getProperty('checked')) { if($('up_limit_checkbox').getProperty('checked')) {
$('up_limit_value').setProperty('disabled', false); $('up_limit_value').setProperty('disabled', false);
@ -568,6 +625,13 @@ addWatchFolder = function() {
$('new_watch_folder_dl').setProperty('checked', false); $('new_watch_folder_dl').setProperty('checked', false);
} }
time_padding = function(val) {
ret = val.toString();
if(ret.length == 1)
ret = '0' + ret
return ret;
}
loadPreferences = function() { loadPreferences = function() {
var url = 'json/preferences'; var url = 'json/preferences';
var request = new Request.JSON({ var request = new Request.JSON({
@ -599,14 +663,26 @@ loadPreferences = function() {
$('up_limit_value').setProperty('value', up_limit); $('up_limit_value').setProperty('value', up_limit);
} }
updateUpLimitEnabled(); updateUpLimitEnabled();
// uTP // Alternative limits
utp_supported = $defined(pref.enable_utp); $('alt_dl_limit_value').setProperty('value', pref.alt_dl_limit.toInt());
setuTPSettingsVisible(utp_supported); $('alt_up_limit_value').setProperty('value', pref.alt_up_limit.toInt());
if(utp_supported) { // Scheduling
$('enable_utp_checkbox').setProperty('checked', pref.enable_utp); $('limit_sheduling_checkbox').setProperty('checked', pref.scheduler_enabled);
$('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate); $('schedule_from_hour').setProperty('value', time_padding(pref.schedule_from_hour));
} $('schedule_from_min').setProperty('value', time_padding(pref.schedule_from_min));
$('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead); $('schedule_to_hour').setProperty('value', time_padding(pref.schedule_to_hour));
$('schedule_to_min').setProperty('value', time_padding(pref.schedule_to_min));
$('schedule_freq_select').setProperty('value', pref.scheduler_days);
updateSchedulingEnabled();
// uTP
utp_supported = $defined(pref.enable_utp);
setuTPSettingsVisible(utp_supported);
if(utp_supported) {
$('enable_utp_checkbox').setProperty('checked', pref.enable_utp);
$('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate);
}
$('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead);
var max_connec = pref.max_connec.toInt(); var max_connec = pref.max_connec.toInt();
if(max_connec <= 0) { if(max_connec <= 0) {
$('max_connec_checkbox').setProperty('checked', false); $('max_connec_checkbox').setProperty('checked', false);
@ -737,13 +813,13 @@ loadPreferences = function() {
$('ssl_key_textarea').setProperty('value', pref.ssl_key); $('ssl_key_textarea').setProperty('value', pref.ssl_key);
$('ssl_cert_textarea').setProperty('value', pref.ssl_cert); $('ssl_cert_textarea').setProperty('value', pref.ssl_cert);
$('locale_select').setProperty('value', pref.locale); $('locale_select').setProperty('value', pref.locale);
// Dyndns // Dyndns
$('use_dyndns_checkbox').setProperty('checked', pref.dyndns_enabled); $('use_dyndns_checkbox').setProperty('checked', pref.dyndns_enabled);
updateDynDnsSettings(); updateDynDnsSettings();
$('dyndns_select').setProperty('value', pref.dyndns_service); $('dyndns_select').setProperty('value', pref.dyndns_service);
$('dyndns_domain_text').setProperty('value', pref.dyndns_domain); $('dyndns_domain_text').setProperty('value', pref.dyndns_domain);
$('dyndns_username_text').setProperty('value', pref.dyndns_username); $('dyndns_username_text').setProperty('value', pref.dyndns_username);
$('dyndns_password_text').setProperty('value', pref.dyndns_password); $('dyndns_password_text').setProperty('value', pref.dyndns_password);
} }
} }
}).send(); }).send();
@ -819,6 +895,31 @@ applyPreferences = function() {
} }
settings.set('max_uploads_per_torrent', max_uploads_per_torrent); settings.set('max_uploads_per_torrent', max_uploads_per_torrent);
// Alternative speed limits
var alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt();
if(alt_dl_limit <= 0) {
alert("_(Download rate limit must be greater than 0 or disabled.)");
return;
}
settings.set('alt_dl_limit', alt_dl_limit);
var alt_up_limit = $('alt_up_limit_value').getProperty('value').toInt();
if(alt_up_limit <= 0) {
alert("_(Upload rate limit must be greater than 0 or disabled.)");
return;
}
settings.set('alt_up_limit', alt_up_limit);
// Scheduler
var scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked');
settings.set('scheduler_enabled', scheduling_enabled);
if (scheduling_enabled) {
settings.set('schedule_from_hour', $('schedule_from_hour').getProperty('value').toInt());
settings.set('schedule_from_min', $('schedule_from_min').getProperty('value').toInt());
settings.set('schedule_to_hour', $('schedule_to_hour').getProperty('value').toInt());
settings.set('schedule_to_min', $('schedule_to_min').getProperty('value').toInt());
settings.set('scheduler_days', $('schedule_freq_select').getProperty('value').toInt());
}
// Bittorrent // Bittorrent
settings.set('dht', $('dht_checkbox').getProperty('checked')); settings.set('dht', $('dht_checkbox').getProperty('checked'));
settings.set('dhtSameAsBT', $('DHTPortDiffThanBT_checkbox').getProperty('checked')); settings.set('dhtSameAsBT', $('DHTPortDiffThanBT_checkbox').getProperty('checked'));

Loading…
Cancel
Save