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 96d8f10080
commit 62aa339fd8
4 changed files with 55 additions and 10 deletions

View file

@ -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):
"""

View file

@ -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:

View file

@ -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;

View file

@ -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']);