diff --git a/deluge/common.py b/deluge/common.py index 8467276e9..a92b858ae 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 @@ -277,6 +277,30 @@ def fsize(fsize_b): return "%.1f %s" % (fsize_mb, _("MiB")) 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): """ diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 75b8d64bb..5b365e41c 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -232,11 +232,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 902922461..884febd53 100644 --- a/deluge/ui/web/js/deluge-all/Formatters.js +++ b/deluge/ui/web/js/deluge-all/Formatters.js @@ -80,7 +80,27 @@ Deluge.Formatters = { 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} * @@ -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 eefa9e978..70f5ae23f 100644 --- a/deluge/ui/web/js/deluge-all/UI.js +++ b/deluge/ui/web/js/deluge-all/UI.js @@ -184,9 +184,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']);