From 1a0ca9edbeb95692ff4d2b34f87da56bbd5541d8 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Tue, 7 May 2013 01:24:20 +0100 Subject: [PATCH] Alter return value to -1 for invalid freespace path Updated GTK and Web UI to display error if value is -1 Added set_markup method to gtk statusbaritem class --- deluge/core/core.py | 2 +- deluge/tests/test_core.py | 2 +- deluge/ui/gtkui/statusbar.py | 9 ++++++++- deluge/ui/web/js/deluge-all/Statusbar.js | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index 8637670b2..5b2ba70bd 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -858,7 +858,7 @@ class Core(component.Component): try: return deluge.common.free_space(path) except InvalidPathError: - return 0 + return -1 @export def get_libtorrent_version(self): diff --git a/deluge/tests/test_core.py b/deluge/tests/test_core.py index 38f4fdac2..a249c317b 100644 --- a/deluge/tests/test_core.py +++ b/deluge/tests/test_core.py @@ -175,7 +175,7 @@ class CoreTestCase(unittest.TestCase): space = self.core.get_free_space(".") self.assertTrue(type(space) in (int, long)) self.assertTrue(space >= 0) - self.assertEquals(self.core.get_free_space("/someinvalidpath"), 0) + self.assertEquals(self.core.get_free_space("/someinvalidpath"), -1) def test_test_listen_port(self): d = self.core.test_listen_port() diff --git a/deluge/ui/gtkui/statusbar.py b/deluge/ui/gtkui/statusbar.py index d89880782..2bd617a7b 100644 --- a/deluge/ui/gtkui/statusbar.py +++ b/deluge/ui/gtkui/statusbar.py @@ -96,6 +96,10 @@ class StatusBarItem: if self._label.get_text() != text: self._label.set_text(text) + def set_markup(self, text): + if self._label.get_label() != text: + self._label.set_markup(text) + def set_tooltip(self, tip): if self._ebox.get_tooltip_text() != tip: self._ebox.set_tooltip_text(tip) @@ -327,7 +331,10 @@ class StatusBar(component.Component): self.remove_item(self.health_item) def _on_get_free_space(self, space): - self.diskspace_item.set_text(deluge.common.fsize(space)) + if space >= 0: + self.diskspace_item.set_text(deluge.common.fsize(space)) + else: + self.diskspace_item.set_markup("" + _("Error") + "") def _on_max_download_speed(self, max_download_speed): self.max_download_speed = max_download_speed diff --git a/deluge/ui/web/js/deluge-all/Statusbar.js b/deluge/ui/web/js/deluge-all/Statusbar.js index 1066883f3..c3b41c8a9 100644 --- a/deluge/ui/web/js/deluge-all/Statusbar.js +++ b/deluge/ui/web/js/deluge-all/Statusbar.js @@ -310,6 +310,6 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { }); this.items.get('statusbar-dht').setText(stats.dht_nodes); - this.items.get('statusbar-freespace').setText(fsize(stats.free_space)); + this.items.get('statusbar-freespace').setText(stats.free_space >= 0 ? fsize(stats.free_space): _("Error")); } });