From c34b5204ace33f06e6b1dfbbb6e0f68724b6d248 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 12 Oct 2007 19:07:02 +0200 Subject: [PATCH] Registration menu --- NEWS | 2 ++ shell/hardware/schoolserver.py | 22 +++++++-------------- shell/view/home/HomeBox.py | 35 +++++++++++++++++++++++----------- sugar/profile.py | 3 +++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index ea318087..05233811 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* Register to the school server from XO palette (marco) + Snapshot 05668dfad7 * First implementation of the alert bar #2822 and hooked it up diff --git a/shell/hardware/schoolserver.py b/shell/hardware/schoolserver.py index cc92e023..68d14f77 100644 --- a/shell/hardware/schoolserver.py +++ b/shell/hardware/schoolserver.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -from sugar import profile +from sugar.profile import get_profile from xmlrpclib import ServerProxy, Error import sys import os @@ -15,19 +14,18 @@ def register_laptop(url=REGISTER_URL): sn = sn or 'SHF00000000' uuid = uuid or '00000000-0000-0000-0000-000000000000' - nick = profile.get_nick_name() - pubkey = profile.get_pubkey() + profile = get_profile() try: server = ServerProxy(url) - data = server.register(sn, nick, uuid, pubkey) + data = server.register(sn, profile.nick_name, uuid, profile.pubkey) if data['success'] != 'OK': print >> sys.stderr, "Error registering laptop: " + data['error'] return False - backupurl = data['backupurl'] - jserver = data['jabberserver'] - profile.set_server(jserver) - profile.set_trial2_backup(backupurl) + + profile.jabber_server = data['jabberserver'] + profile.backup1 = data['backupurl'] + profile.save() except Error, e: print >> sys.stderr, "Error registering laptop: " + str(e) return False @@ -45,9 +43,3 @@ def read_ofw(path): data = fh.read().rstrip('\0\n') fh.close() return data - -if __name__ == "__main__": - url = REGISTER_URL - if len(sys.argv) > 1: - url = sys.argv[1] - register_laptop(url) diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py index 69a277b9..6b5de5fc 100644 --- a/shell/view/home/HomeBox.py +++ b/shell/view/home/HomeBox.py @@ -29,13 +29,14 @@ from sugar.graphics import style from sugar.graphics.xocolor import XoColor from sugar.graphics.palette import Palette, CanvasInvoker from sugar.graphics.icon import CanvasIcon -from sugar import profile +from sugar.profile import get_profile from sugar import env from view.home.activitiesdonut import ActivitiesDonut from view.devices import deviceview from view.home.MyIcon import MyIcon from model.shellmodel import ShellModel +from hardware import schoolserver class HomeBox(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarHomeBox' @@ -178,20 +179,27 @@ class _MyIcon(MyIcon): self._power_manager = None self._shell = shell + self._profile = get_profile() def enable_palette(self): - palette = Palette(profile.get_nick_name()) + palette = Palette(self._profile.nick_name) - reboot_menu_item = gtk.MenuItem(_('Reboot')) - reboot_menu_item.connect('activate', self._reboot_activate_cb) - shutdown_menu_item = gtk.MenuItem(_('Shutdown')) - shutdown_menu_item.connect('activate', self._shutdown_activate_cb) + item = gtk.MenuItem(_('Reboot')) + item.connect('activate', self._reboot_activate_cb) + palette.menu.append(item) + item.show() + + item = gtk.MenuItem(_('Shutdown')) + item.connect('activate', self._shutdown_activate_cb) + palette.menu.append(item) + item.show() + + if not self._profile.is_registered(): + item = gtk.MenuItem(_('Register')) + item.connect('activate', self._register_activate_cb) + palette.menu.append(item) + item.show() - palette.menu.append(reboot_menu_item) - palette.menu.append(shutdown_menu_item) - reboot_menu_item.show() - shutdown_menu_item.show() - self.set_palette(palette) def _reboot_activate_cb(self, menuitem): @@ -222,6 +230,11 @@ class _MyIcon(MyIcon): else: pm.Shutdown() + def _register_activate_cb(self, menuitem): + schoolserver.register_laptop() + if self._profile.is_registered(): + self.get_palette().menu.remove(menuitem) + def _close_emulator(self): if os.environ.has_key('SUGAR_EMULATOR_PID'): pid = int(os.environ['SUGAR_EMULATOR_PID']) diff --git a/sugar/profile.py b/sugar/profile.py index 06084b7a..10a2b6cc 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -79,6 +79,9 @@ class Profile(object): self.pubkey is not None and \ self.privkey_hash is not None + def is_registered(self): + return self.backup1 is not None + def save(self): cp = ConfigParser() parsed = cp.read([self._config_path])