diff options
author | Simon Schampijer <simon@schampijer.de> | 2008-08-15 07:37:01 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@schampijer.de> | 2008-08-15 07:37:01 (GMT) |
commit | d425dbefa7deb28d820a2333991dad20dc42957b (patch) | |
tree | fe024c19bbca7957c8d3ef8ca24d45373b574c39 /journalactivity.py | |
parent | 56b359118972349831da11b0efecbbeb6717b6dd (diff) |
Show alert when available space is below 50MB #7588
The modal alert encourages to delete old journal entries. Available
space is checked on boot and when creating or updating journal
entries.
Diffstat (limited to 'journalactivity.py')
-rwxr-xr-x | journalactivity.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/journalactivity.py b/journalactivity.py index f531e0f..12099b6 100755 --- a/journalactivity.py +++ b/journalactivity.py @@ -23,10 +23,13 @@ import uuid import gtk import dbus +import statvfs +import os from sugar.activity import activity from sugar.bundle.bundle import ZipExtractException, RegistrationException from sugar.datastore import datastore +from sugar import env from journaltoolbox import MainToolbox, DetailToolbox from listview import ListView @@ -35,6 +38,7 @@ from volumestoolbar import VolumesToolbar import misc from journalentrybundle import JournalEntryBundle from objectchooser import ObjectChooser +from modalalert import ModalAlert DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore' DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore' @@ -44,6 +48,8 @@ J_DBUS_SERVICE = 'org.laptop.Journal' J_DBUS_INTERFACE = 'org.laptop.Journal' J_DBUS_PATH = '/org/laptop/Journal' +_SPACE_TRESHOLD = 52428800 + class JournalActivityDBusService(dbus.service.Object): def __init__(self, parent): self._parent = parent @@ -143,6 +149,9 @@ class JournalActivity(activity.Activity): self._dbus_service = JournalActivityDBusService(self) self.iconify() + + self._critical_space_alert = None + self._check_available_space() def can_close(self): return False @@ -242,7 +251,8 @@ class JournalActivity(activity.Activity): finally: jobject.destroy() self._main_toolbox.search_toolbar.refresh_filters() - + self._check_available_space() + def __data_store_updated_cb(self, uid): jobject = datastore.get(uid) if jobject is None: @@ -251,6 +261,7 @@ class JournalActivity(activity.Activity): self._check_for_bundle(jobject) finally: jobject.destroy() + self._check_available_space() def __data_store_deleted_cb(self, uid): if self.canvas == self._secondary_view and \ @@ -302,3 +313,24 @@ class JournalActivity(activity.Activity): visible = event.state != gtk.gdk.VISIBILITY_FULLY_OBSCURED self._list_view.set_is_visible(visible) + def _check_available_space(self): + ''' Check available space on device + + If the available space is below 50MB an alert will be + shown which encourages to delete old journal entries. + ''' + + if self._critical_space_alert: + return + stat = os.statvfs(env.get_profile_path()) + free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL] + if free_space < _SPACE_TRESHOLD: + self._critical_space_alert = ModalAlert() + self._critical_space_alert.connect('destroy', + self.__alert_closed_cb) + self._critical_space_alert.show() + + def __alert_closed_cb(self, data): + self._show_main_view() + self.present() + self._critical_space_alert = None |