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
This commit is contained in:
Calum Lind 2013-05-07 01:24:20 +01:00
parent a49d558aaf
commit 1a0ca9edbe
4 changed files with 11 additions and 4 deletions

View File

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

View File

@ -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()

View File

@ -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("<span foreground=\"red\">" + _("Error") + "</span>")
def _on_max_download_speed(self, max_download_speed):
self.max_download_speed = max_download_speed

View File

@ -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"));
}
});