Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2008-08-15 07:37:01 (GMT)
committer Simon Schampijer <simon@schampijer.de>2008-08-15 07:37:01 (GMT)
commitd425dbefa7deb28d820a2333991dad20dc42957b (patch)
treefe024c19bbca7957c8d3ef8ca24d45373b574c39
parent56b359118972349831da11b0efecbbeb6717b6dd (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.
-rwxr-xr-xjournalactivity.py34
-rw-r--r--modalalert.py93
2 files changed, 126 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
diff --git a/modalalert.py b/modalalert.py
new file mode 100644
index 0000000..543a9ea
--- /dev/null
+++ b/modalalert.py
@@ -0,0 +1,93 @@
+# Copyright (C) 2008 One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gtk
+from gettext import gettext as _
+
+from sugar.graphics.icon import Icon
+from sugar.graphics import style
+from sugar import profile
+
+class ModalAlert(gtk.Window):
+
+ __gtype_name__ = 'SugarModalAlert'
+
+ def __init__(self):
+ gtk.Window.__init__(self)
+
+ self.set_border_width(style.LINE_WIDTH)
+ offset = style.GRID_CELL_SIZE
+ width = gtk.gdk.screen_width() - offset * 2
+ height = gtk.gdk.screen_height() - offset * 2
+ self.set_size_request(width, height)
+ self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+ self.set_decorated(False)
+ self.set_resizable(False)
+ self.set_modal(True)
+
+ self._main_view = gtk.EventBox()
+ self._vbox = gtk.VBox()
+ self._vbox.set_spacing(style.DEFAULT_SPACING)
+ self._vbox.set_border_width(style.GRID_CELL_SIZE * 2)
+ self._main_view.modify_bg(gtk.STATE_NORMAL,
+ style.COLOR_BLACK.get_gdk_color())
+ self._main_view.add(self._vbox)
+ self._vbox.show()
+
+ icon = Icon(file='activity/activity-journal.svg',
+ pixel_size=style.XLARGE_ICON_SIZE,
+ xo_color=profile.get_color())
+ self._vbox.pack_start(icon, False)
+ icon.show()
+
+ self._title = gtk.Label()
+ self._title.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_WHITE.get_gdk_color())
+ self._title.set_markup('<b>%s</b>' % _('Your Journal is full'))
+ self._vbox.pack_start(self._title, False)
+ self._title.show()
+
+ self._message = gtk.Label(_('Please delete some old Journal'
+ ' entries to make space for new ones.'))
+ self._message.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_WHITE.get_gdk_color())
+ self._vbox.pack_start(self._message, False)
+ self._message.show()
+
+ alignment = gtk.Alignment(xalign=0.5, yalign=0.5)
+ self._vbox.pack_start(alignment, expand=False)
+ alignment.show()
+
+ self._show_journal = gtk.Button()
+ self._show_journal.set_label(_('Show Journal'))
+ alignment.add(self._show_journal)
+ self._show_journal.show()
+ self._show_journal.connect('clicked', self.__show_journal_cb)
+
+ self.add(self._main_view)
+ self._main_view.show()
+
+ self.connect("realize", self.__realize_cb)
+
+ def __realize_cb(self, widget):
+ self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+ self.window.set_accept_focus(True)
+
+ def __show_journal_cb(self, button):
+ '''The opener will listen on the destroy signal
+ '''
+ self.destroy()
+