diff --git a/deluge/common.py b/deluge/common.py index 274d14ae7..d2b0c0da3 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -17,9 +17,9 @@ # # You should have received a copy of the GNU General Public License # along with deluge. If not, write to: -# The Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor -# Boston, MA 02110-1301, USA. +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. # # In addition, as a special exception, the copyright holders give # 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 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): """ Formats a string to display a percentage with two decimal places diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index ed6392384..992e4b930 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -300,11 +300,11 @@ class MainWindow(component.Component): def update(self): # Update the window title def _on_get_session_status(status): - download_rate = deluge.common.fspeed(status["download_rate"]) - upload_rate = deluge.common.fspeed(status["upload_rate"]) - self.window.set_title("Deluge - %s %s %s %s" % (_("Down:"), download_rate, _("Up:"), upload_rate)) + download_rate = deluge.common.fsize_short(status["payload_download_rate"]) + upload_rate = deluge.common.fsize_short(status["payload_upload_rate"]) + self.window.set_title("%s%s %s%s - Deluge" % (_("D:"), download_rate, _("U:"), upload_rate)) 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): if value: diff --git a/deluge/ui/web/js/deluge-all/Formatters.js b/deluge/ui/web/js/deluge-all/Formatters.js index 0ea3b6903..f7b9fcdc5 100644 --- a/deluge/ui/web/js/deluge-all/Formatters.js +++ b/deluge/ui/web/js/deluge-all/Formatters.js @@ -1,6 +1,6 @@ /*! * Deluge.Formatters.js - * + * * Copyright (c) Damien Churchill 2009-2010 * * 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.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2)); }, - + /** * Formats the bytes value into a string with KiB, MiB or GiB units. * @@ -71,16 +71,36 @@ Deluge.Formatters = { size: function(bytes, showZero) { if (!bytes && !showZero) return ''; bytes = bytes / 1024.0; - + if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; } else { bytes = bytes / 1024; } - + if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; } else { bytes = bytes / 1024; } - + 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} * @@ -91,7 +111,7 @@ Deluge.Formatters = { speed: function(bytes, showZero) { return (!bytes && !showZero) ? '' : fsize(bytes, showZero) + '/s'; }, - + /** * Formats a string to show time in a human readable form. * @@ -103,7 +123,7 @@ Deluge.Formatters = { time = time.toFixed(0); if (time < 60) { return time + 's'; } else { time = time / 60; } - + if (time < 60) { var minutes = Math.floor(time) var seconds = Math.round(60 * (time - minutes)) @@ -113,18 +133,18 @@ Deluge.Formatters = { return minutes + 'm'; } } else { time = time / 60; } - - if (time < 24) { + + if (time < 24) { var hours = Math.floor(time) var minutes = Math.round(60 * (time - hours)) if (minutes > 0) { return hours + 'h ' + minutes + 'm'; } else { return hours + 'h'; - } + } } else { time = time / 24; } - + var days = Math.floor(time) var hours = Math.round(24 * (time - days)) if (hours > 0) { @@ -133,7 +153,7 @@ Deluge.Formatters = { return days + 'd'; } }, - + /** * Simply returns the value untouched, for when no formatting is required. * @@ -149,6 +169,7 @@ Deluge.Formatters = { } } var fsize = Deluge.Formatters.size; +var fsize_short = Deluge.Formatters.sizeShort; var fspeed = Deluge.Formatters.speed; var ftime = Deluge.Formatters.timeRemaining; var fdate = Deluge.Formatters.date; diff --git a/deluge/ui/web/js/deluge-all/UI.js b/deluge/ui/web/js/deluge-all/UI.js index 84a3c1fae..b4305c06f 100644 --- a/deluge/ui/web/js/deluge-all/UI.js +++ b/deluge/ui/web/js/deluge-all/UI.js @@ -185,9 +185,9 @@ deluge.ui = { } if (deluge.config.show_session_speed) { - document.title = this.originalTitle + - ' (Down: ' + fspeed(data['stats'].download_rate, true) + - ' Up: ' + fspeed(data['stats'].upload_rate, true) + ')'; + document.title = 'D: ' + fsize_short(data['stats'].download_rate, true) + + ' U: ' + fsize_short(data['stats'].upload_rate, true) + ' - ' + + this.originalTitle; } if (Ext.areObjectsEqual(this.filters, this.oldFilters)) { deluge.torrents.update(data['torrents']);