[Sugar-devel] [PATCH] Journal XS backup and restore
Martin Abente
mabente at paraguayeduca.org
Mon Jul 5 10:00:09 EDT 2010
Include a new journal volumes toolbar icon. The icon represents
the schoolserver. The icon palette provides a backup and restore
options.
---
src/jarabe/desktop/favoritesview.py | 2 +
src/jarabe/journal/processdialog.py | 30 ++++++++++++++++++++++++++
src/jarabe/journal/volumestoolbar.py | 37 +++++++++++++++++++++++++++++--
src/jarabe/view/palettes.py | 39 +++++++++++++++++++++++++++++++++-
4 files changed, 104 insertions(+), 4 deletions(-)
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index aca945a..a311b52 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -42,6 +42,7 @@ from jarabe.view import launcher
from jarabe.model.buddy import BuddyModel
from jarabe.model import shell
from jarabe.model import bundleregistry
+from jarabe.journal.journalactivity import get_journal
from jarabe.journal import misc
from jarabe.desktop import schoolserver
@@ -328,6 +329,7 @@ class FavoritesView(hippo.Canvas):
alert.props.msg = _('You are now registered ' \
'with your school server.')
self._my_icon.remove_register_menu()
+ get_journal()._volumes_toolbar.setup_xs_button()
ok_icon = Icon(icon_name='dialog-ok')
alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon)
diff --git a/src/jarabe/journal/processdialog.py b/src/jarabe/journal/processdialog.py
index 8217973..4d8704e 100644
--- a/src/jarabe/journal/processdialog.py
+++ b/src/jarabe/journal/processdialog.py
@@ -246,3 +246,33 @@ class VolumeRestoreDialog(ProcessDialog):
self._message.set_markup('%s %s.\n\n' % (_('Journal content will be restored from'), volume_path) + \
'<big><b>%s</b> %s</big>' % (_('Warning:'), _('Current Journal content will be deleted!')))
+class XSBackupDialog(ProcessDialog):
+
+ def __init__(self, xs_hostname):
+ ProcessDialog.__init__(self, 'journal-backup')
+ self._resetup_information(xs_hostname)
+
+ def _resetup_information(self, xs_hostname):
+ self._start_message = '%s %s.' % (_('Please wait, saving Journal content to'), xs_hostname)
+
+ self._finished_message = _('The journal content has been saved.')
+
+ self._title.set_markup('<big><b>%s</b></big>' % _('Backup'))
+
+ self._message.set_text('%s %s.' % (_('Journal content will be saved to'), xs_hostname))
+
+class XSRestoreDialog(ProcessDialog):
+
+ def __init__(self, xs_hostname):
+ ProcessDialog.__init__(self, 'journal-restore')
+ self._resetup_information(xs_hostname)
+
+ def _resetup_information(self, xs_hostname):
+ self._start_message = '%s %s.' % (_('Please wait, restoring journal content from'), xs_hostname)
+
+ self._finished_message = _('The journal content has been restored.')
+
+ self._title.set_markup('<big><b>%s</b></big>' % _('Restore'))
+
+ self._message.set_text('%s %s.' % (_('Journal content will be restored from'), xs_hostname))
+
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 2e64fe2..e1f9ce0 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -22,12 +22,14 @@ import gio
import gtk
import gconf
+from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton
+from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette
from sugar.graphics.xocolor import XoColor
from jarabe.journal import model
-from jarabe.view.palettes import JournalVolumePalette
+from jarabe.view.palettes import JournalVolumePalette, JournalXSPalette
class VolumesToolbar(gtk.Toolbar):
__gtype_name__ = 'VolumesToolbar'
@@ -52,6 +54,7 @@ class VolumesToolbar(gtk.Toolbar):
self.connect('destroy', self.__destroy_cb)
+ self.setup_xs_button()
gobject.idle_add(self._set_up_volumes)
def __destroy_cb(self, widget):
@@ -59,6 +62,21 @@ class VolumesToolbar(gtk.Toolbar):
volume_monitor.disconnect(self._mount_added_hid)
volume_monitor.disconnect(self._mount_removed_hid)
+ def setup_xs_button(self):
+ client = gconf.client_get_default()
+ backup_url = client.get_string('/desktop/sugar/backup_url')
+
+ if backup_url:
+ xs_button = XSButton()
+ xs_button.set_palette(JournalXSPalette(backup_url))
+ #xs_button.props.group = self._volume_buttons[0]
+ xs_button.show()
+
+ self._volume_buttons.append(xs_button)
+ position = len(self._volume_buttons) - 1
+ self.insert(xs_button, position)
+ self.show()
+
def _set_up_volumes(self):
volume_monitor = gio.volume_monitor_get()
self._mount_added_hid = \
@@ -104,8 +122,9 @@ class VolumesToolbar(gtk.Toolbar):
def _get_button_for_mount(self, mount):
mount_point = mount.get_root().get_path()
for button in self.get_children():
- if button.mount_point == mount_point:
- return button
+ if type(button) == VolumeButton and \
+ button.mount_point == mount_point:
+ return button
logging.error('Couldnt find button with mount_point %r', mount_point)
return None
@@ -180,3 +199,15 @@ class JournalButton(BaseButton):
color = XoColor(client.get_string('/desktop/sugar/user/color'))
self.props.xo_color = color
+class XSButton(ToolButton):
+ def __init__(self):
+ ToolButton.__init__(self)
+ self.set_icon('school-server')
+
+ def set_icon(self, icon_name):
+ client = gconf.client_get_default()
+ color = XoColor(client.get_string('/desktop/sugar/user/color'))
+ icon = Icon(icon_name=icon_name, xo_color=color, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ icon.show()
+
+ self.set_icon_widget(icon)
diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
index 2fc4d5f..51c40f1 100644
--- a/src/jarabe/view/palettes.py
+++ b/src/jarabe/view/palettes.py
@@ -33,7 +33,7 @@ from sugar.graphics.xocolor import XoColor
from sugar.activity import activityfactory
from sugar.activity.activityhandle import ActivityHandle
-from jarabe.journal.processdialog import VolumeBackupDialog, VolumeRestoreDialog
+from jarabe.journal.processdialog import VolumeBackupDialog, VolumeRestoreDialog, XSBackupDialog, XSRestoreDialog
from jarabe.model import shell
from jarabe.view import launcher
from jarabe.view.viewsource import setup_view_source
@@ -302,3 +302,40 @@ class JournalVolumePalette(VolumePalette):
dialog = VolumeRestoreDialog(mount_path)
dialog.show()
+class JournalXSPalette(Palette):
+ def __init__(self, xs_hostname):
+ Palette.__init__(self, _('School Server'))
+
+ self.props.secondary_text = xs_hostname
+
+ vbox = gtk.VBox()
+ self.set_content(vbox)
+ vbox.show()
+
+ icon = Icon(icon_name='transfer-to', icon_size=gtk.ICON_SIZE_MENU)
+ icon.show()
+
+ menu_item_journal_backup = MenuItem(_('Backup Journal'))
+ menu_item_journal_backup.set_image(icon)
+ menu_item_journal_backup.connect('activate', self.__journal_backup_activate_cb, xs_hostname)
+ menu_item_journal_backup.show()
+
+ self.menu.append(menu_item_journal_backup)
+
+ icon = Icon(icon_name='transfer-from', icon_size=gtk.ICON_SIZE_MENU)
+ icon.show()
+
+ menu_item_journal_restore = MenuItem(_('Restore Journal'))
+ menu_item_journal_restore.set_image(icon)
+ menu_item_journal_restore.connect('activate', self.__journal_restore_activate_cb, xs_hostname)
+ menu_item_journal_restore.show()
+
+ self.menu.append(menu_item_journal_restore)
+
+ def __journal_backup_activate_cb(self, menu_item, xs_hostname):
+ dialog = XSBackupDialog(xs_hostname)
+ dialog.show()
+
+ def __journal_restore_activate_cb(self, menu_item, xs_hostname):
+ dialog = XSRestoreDialog(xs_hostname)
+ dialog.show()
--
1.6.0.4
More information about the Sugar-devel
mailing list