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

@ -81,6 +81,26 @@ Deluge.Formatters = {
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}
* *
@ -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']);