Fix #2010 : Move speed text in titlebar to the beginning

This commit is contained in:
Calum Lind 2012-01-08 03:53:30 +00:00
parent c88ba97531
commit be49fd6a40
4 changed files with 68 additions and 23 deletions

View File

@ -17,9 +17,9 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with deluge. If not, write to: # along with deluge. If not, write to:
# The Free Software Foundation, Inc., # The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor # 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
# In addition, as a special exception, the copyright holders give # In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL # permission to link the code of portions of this program with the OpenSSL
@ -269,6 +269,30 @@ def fsize(fsize_b):
fsize_gb = fsize_mb / 1024.0 fsize_gb = fsize_mb / 1024.0
return "%.1f %s" % (fsize_gb, _("GiB")) return "%.1f %s" % (fsize_gb, _("GiB"))
def fsize_short(fsize_b):
"""
Formats the bytes value into a string with K, M or G units
:param fsize_b: the filesize in bytes
:type fsize_b: int
:returns: formatted string in K, M or G units
:rtype: string
**Usage**
>>> fsize(112245)
'109.6 K'
"""
fsize_kb = fsize_b / 1024.0
if fsize_kb < 1024:
return "%.1f %s" % (fsize_kb, _("K"))
fsize_mb = fsize_kb / 1024.0
if fsize_mb < 1024:
return "%.1f %s" % (fsize_mb, _("M"))
fsize_gb = fsize_mb / 1024.0
return "%.1f %s" % (fsize_gb, _("G"))
def fpcnt(dec): def fpcnt(dec):
""" """
Formats a string to display a percentage with two decimal places Formats a string to display a percentage with two decimal places

View File

@ -300,11 +300,11 @@ class MainWindow(component.Component):
def update(self): def update(self):
# Update the window title # Update the window title
def _on_get_session_status(status): def _on_get_session_status(status):
download_rate = deluge.common.fspeed(status["download_rate"]) download_rate = deluge.common.fsize_short(status["payload_download_rate"])
upload_rate = deluge.common.fspeed(status["upload_rate"]) upload_rate = deluge.common.fsize_short(status["payload_upload_rate"])
self.window.set_title("Deluge - %s %s %s %s" % (_("Down:"), download_rate, _("Up:"), upload_rate)) self.window.set_title("%s%s %s%s - Deluge" % (_("D:"), download_rate, _("U:"), upload_rate))
if self.config["show_rate_in_title"]: if self.config["show_rate_in_title"]:
client.core.get_session_status(["download_rate", "upload_rate"]).addCallback(_on_get_session_status) client.core.get_session_status(["payload_download_rate", "payload_upload_rate"]).addCallback(_on_get_session_status)
def _on_set_show_rate_in_title(self, key, value): def _on_set_show_rate_in_title(self, key, value):
if value: if value:

View File

@ -1,6 +1,6 @@
/*! /*!
* Deluge.Formatters.js * Deluge.Formatters.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -60,7 +60,7 @@ Deluge.Formatters = {
zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear(), zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear(),
zeroPad(date.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2)); zeroPad(date.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2));
}, },
/** /**
* Formats the bytes value into a string with KiB, MiB or GiB units. * Formats the bytes value into a string with KiB, MiB or GiB units.
* *
@ -71,16 +71,36 @@ Deluge.Formatters = {
size: function(bytes, showZero) { size: function(bytes, showZero) {
if (!bytes && !showZero) return ''; if (!bytes && !showZero) return '';
bytes = bytes / 1024.0; bytes = bytes / 1024.0;
if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; } if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; }
else { bytes = bytes / 1024; } else { bytes = bytes / 1024; }
if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; } if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; }
else { bytes = bytes / 1024; } else { bytes = bytes / 1024; }
return bytes.toFixed(1) + ' GiB' return bytes.toFixed(1) + ' GiB'
}, },
/**
* Formats the bytes value into a string with K, M or G units.
*
* @param {Number} bytes the filesize in bytes
* @param {Boolean} showZero pass in true to displays 0 values
* @return {String} formatted string with K, M or G units.
*/
sizeShort: function(bytes, showZero) {
if (!bytes && !showZero) return '';
bytes = bytes / 1024.0;
if (bytes < 1024) { return bytes.toFixed(1) + ' K'; }
else { bytes = bytes / 1024; }
if (bytes < 1024) { return bytes.toFixed(1) + ' M'; }
else { bytes = bytes / 1024; }
return bytes.toFixed(1) + ' G'
},
/** /**
* Formats a string to display a transfer speed utilizing {@link #size} * Formats a string to display a transfer speed utilizing {@link #size}
* *
@ -91,7 +111,7 @@ Deluge.Formatters = {
speed: function(bytes, showZero) { speed: function(bytes, showZero) {
return (!bytes && !showZero) ? '' : fsize(bytes, showZero) + '/s'; return (!bytes && !showZero) ? '' : fsize(bytes, showZero) + '/s';
}, },
/** /**
* Formats a string to show time in a human readable form. * Formats a string to show time in a human readable form.
* *
@ -103,7 +123,7 @@ Deluge.Formatters = {
time = time.toFixed(0); time = time.toFixed(0);
if (time < 60) { return time + 's'; } if (time < 60) { return time + 's'; }
else { time = time / 60; } else { time = time / 60; }
if (time < 60) { if (time < 60) {
var minutes = Math.floor(time) var minutes = Math.floor(time)
var seconds = Math.round(60 * (time - minutes)) var seconds = Math.round(60 * (time - minutes))
@ -113,18 +133,18 @@ Deluge.Formatters = {
return minutes + 'm'; } return minutes + 'm'; }
} }
else { time = time / 60; } else { time = time / 60; }
if (time < 24) { if (time < 24) {
var hours = Math.floor(time) var hours = Math.floor(time)
var minutes = Math.round(60 * (time - hours)) var minutes = Math.round(60 * (time - hours))
if (minutes > 0) { if (minutes > 0) {
return hours + 'h ' + minutes + 'm'; return hours + 'h ' + minutes + 'm';
} else { } else {
return hours + 'h'; return hours + 'h';
} }
} }
else { time = time / 24; } else { time = time / 24; }
var days = Math.floor(time) var days = Math.floor(time)
var hours = Math.round(24 * (time - days)) var hours = Math.round(24 * (time - days))
if (hours > 0) { if (hours > 0) {
@ -133,7 +153,7 @@ Deluge.Formatters = {
return days + 'd'; return days + 'd';
} }
}, },
/** /**
* Simply returns the value untouched, for when no formatting is required. * Simply returns the value untouched, for when no formatting is required.
* *
@ -149,6 +169,7 @@ Deluge.Formatters = {
} }
} }
var fsize = Deluge.Formatters.size; var fsize = Deluge.Formatters.size;
var fsize_short = Deluge.Formatters.sizeShort;
var fspeed = Deluge.Formatters.speed; var fspeed = Deluge.Formatters.speed;
var ftime = Deluge.Formatters.timeRemaining; var ftime = Deluge.Formatters.timeRemaining;
var fdate = Deluge.Formatters.date; var fdate = Deluge.Formatters.date;

View File

@ -185,9 +185,9 @@ deluge.ui = {
} }
if (deluge.config.show_session_speed) { if (deluge.config.show_session_speed) {
document.title = this.originalTitle + document.title = 'D: ' + fsize_short(data['stats'].download_rate, true) +
' (Down: ' + fspeed(data['stats'].download_rate, true) + ' U: ' + fsize_short(data['stats'].upload_rate, true) + ' - ' +
' Up: ' + fspeed(data['stats'].upload_rate, true) + ')'; this.originalTitle;
} }
if (Ext.areObjectsEqual(this.filters, this.oldFilters)) { if (Ext.areObjectsEqual(this.filters, this.oldFilters)) {
deluge.torrents.update(data['torrents']); deluge.torrents.update(data['torrents']);