diff --git a/configure.ac b/configure.ac index 68d4602b..d729ac3a 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ bindings/Makefile bindings/globalkeys/Makefile bindings/threadframe/Makefile shell/Makefile +shell/conf/Makefile shell/data/Makefile shell/home/Makefile shell/frame/Makefile @@ -58,7 +59,6 @@ sugar/activity/Makefile sugar/canvas/Makefile sugar/chat/Makefile sugar/chat/sketchpad/Makefile -sugar/conf/Makefile sugar/p2p/Makefile sugar/p2p/model/Makefile sugar/presence/Makefile diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py index 7ee4164b..b3703e7a 100644 --- a/shell/ActivityHost.py +++ b/shell/ActivityHost.py @@ -1,7 +1,7 @@ import gtk import dbus -from sugar import conf +import conf from sugar.activity import Activity from sugar.presence import PresenceService from sugar.canvas.IconColor import IconColor diff --git a/shell/ChatController.py b/shell/ChatController.py index b1b39d33..022d6080 100644 --- a/shell/ChatController.py +++ b/shell/ChatController.py @@ -1,4 +1,4 @@ -from sugar import conf +import conf from sugar.chat.BuddyChat import BuddyChat from sugar.activity import ActivityFactory from sugar.presence import PresenceService diff --git a/shell/FirstTimeDialog.py b/shell/FirstTimeDialog.py index 7a7e4876..abf6bd80 100644 --- a/shell/FirstTimeDialog.py +++ b/shell/FirstTimeDialog.py @@ -2,35 +2,35 @@ import gtk from gettext import gettext as _ -from sugar import conf +import conf -class FirstTimeDialog(gtk.Window): +class FirstTimeDialog(gtk.Dialog): def __init__(self): - gtk.Window.__init__(self) - - self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) - - vbox = gtk.VBox(False, 6) - vbox.set_border_width(12) + gtk.Dialog.__init__(self) label = gtk.Label(_('Nick Name:')) label.set_alignment(0.0, 0.5) - vbox.pack_start(label) + self.vbox.pack_start(label) label.show() self._entry = gtk.Entry() - vbox.pack_start(self._entry) + self.vbox.pack_start(self._entry) self._entry.show() button = gtk.Button(None, gtk.STOCK_OK) - vbox.pack_start(button) + self.vbox.pack_start(button) button.connect('clicked', self.__ok_button_clicked_cb) button.show() - self.add(vbox) - vbox.show() - def __ok_button_clicked_cb(self, button): profile = conf.get_profile() profile.set_nick_name(self._entry.get_text()) self.destroy() + +def get_profile(): + profile = conf.get_profile() + if profile.get_nick_name() == None: + dialog = FirstTimeDialog() + dialog.connect('destroy', self.__first_time_dialog_destroy_cb) + dialog.show() + return profile diff --git a/shell/Invites.py b/shell/Invites.py index 35993b19..22598efc 100644 --- a/shell/Invites.py +++ b/shell/Invites.py @@ -1,8 +1,8 @@ import gobject +import conf from sugar.presence import PresenceService from sugar.canvas.IconColor import IconColor -from sugar import conf class Invite: def __init__(self, issuer, bundle_id, activity_id): diff --git a/shell/Makefile.am b/shell/Makefile.am index b57e2947..3aabfad6 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = data session frame home PresenceService +SUBDIRS = conf data session frame home PresenceService bin_SCRIPTS = \ sugar \ diff --git a/shell/Owner.py b/shell/Owner.py index 5cced8c6..b99cc3a5 100644 --- a/shell/Owner.py +++ b/shell/Owner.py @@ -2,10 +2,10 @@ import os import random import base64 +import conf from sugar import env from sugar.p2p import Stream from sugar.presence import PresenceService -from sugar import conf from Friends import Friends from Invites import Invites diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index 547f5472..042982ac 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -6,7 +6,6 @@ import random import logging from sugar import env from sugar import util -from sugar import conf def _get_local_ip_address(ifname): """Call Linux specific bits to retrieve our own IP address.""" @@ -370,7 +369,7 @@ class PresenceService(object): self._dbus_helper.ServiceAppeared(service.object_path()) except KeyError: # Should this service mark the owner? - owner_nick = conf.get_profile().get_nick_name() + owner_nick = env.get_nick_name() source_addr = service.get_source_address() objid = self._get_next_object_id() if name == owner_nick and source_addr in self._local_addrs.values(): diff --git a/shell/Shell.py b/shell/Shell.py index 7644b1b6..7b47026a 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -14,10 +14,9 @@ from ActivityHost import ActivityHost from ChatController import ChatController from sugar.activity import ActivityFactory from sugar.activity import Activity -from FirstTimeDialog import FirstTimeDialog from frame.Frame import Frame from globalkeys import KeyGrabber -from sugar import conf +import conf from sugar import env import sugar import sugar.logger @@ -67,32 +66,6 @@ class Shell(gobject.GObject): self._screen.connect('active-window-changed', self.__active_window_changed_cb) - profile = conf.get_profile() - if profile.get_nick_name() == None: - dialog = FirstTimeDialog() - dialog.connect('destroy', self.__first_time_dialog_destroy_cb) - dialog.set_transient_for(self._home_window) - dialog.show() - else: - self.start() - - def __global_key_pressed_cb(self, grabber, key): - if key == 'F1': - self.set_zoom_level(sugar.ZOOM_ACTIVITY) - elif key == 'F2': - self.set_zoom_level(sugar.ZOOM_HOME) - elif key == 'F3': - self.set_zoom_level(sugar.ZOOM_FRIENDS) - elif key == 'F4': - self.set_zoom_level(sugar.ZOOM_MESH) - elif key == 'F5': - self._frame.toggle_visibility() - - def __first_time_dialog_destroy_cb(self, dialog): - conf.get_profile().save() - self.start() - - def start(self): session_bus = dbus.SessionBus() bus_name = dbus.service.BusName('com.redhat.Sugar.Shell', bus=session_bus) ShellDbusService(self, bus_name) @@ -111,6 +84,18 @@ class Shell(gobject.GObject): self._frame = Frame(self, self._owner) self._frame.show_and_hide(10) + def __global_key_pressed_cb(self, grabber, key): + if key == 'F1': + self.set_zoom_level(sugar.ZOOM_ACTIVITY) + elif key == 'F2': + self.set_zoom_level(sugar.ZOOM_HOME) + elif key == 'F3': + self.set_zoom_level(sugar.ZOOM_FRIENDS) + elif key == 'F4': + self.set_zoom_level(sugar.ZOOM_MESH) + elif key == 'F5': + self._frame.toggle_visibility() + def set_console(self, console): self._console = console diff --git a/sugar/conf/ActivityRegistry.py b/shell/conf/ActivityRegistry.py similarity index 89% rename from sugar/conf/ActivityRegistry.py rename to shell/conf/ActivityRegistry.py index c9b4e2ef..52232846 100644 --- a/sugar/conf/ActivityRegistry.py +++ b/shell/conf/ActivityRegistry.py @@ -3,16 +3,9 @@ import os from ConfigParser import ConfigParser from ConfigParser import NoOptionError +from sugar import activity from sugar import env - -def get_default_type(activity_type): - """Get the activity default type. - - It's the type of the main network service which tracks presence - and provides info about the activity, for example the title.""" - splitted_id = activity_type.split('.') - splitted_id.reverse() - return '_' + '_'.join(splitted_id) + '._udp' +import sugar class ActivityModule: """Info about an activity module. Wraps a .activity file.""" @@ -46,7 +39,7 @@ class ActivityModule: def get_default_type(self): """Get the the type of the default activity service.""" - return get_default_type(self._id) + return activity.get_default_type(self._id) def set_default_type(self, default_type): """Set the the type of the default activity service.""" diff --git a/sugar/conf/Makefile.am b/shell/conf/Makefile.am similarity index 100% rename from sugar/conf/Makefile.am rename to shell/conf/Makefile.am diff --git a/sugar/conf/Profile.py b/shell/conf/Profile.py similarity index 98% rename from sugar/conf/Profile.py rename to shell/conf/Profile.py index 7a6be2e2..c3ca053f 100644 --- a/sugar/conf/Profile.py +++ b/shell/conf/Profile.py @@ -4,7 +4,7 @@ from ConfigParser import ConfigParser from sugar.canvas.IconColor import IconColor from sugar import env -class Profile: +class _Profile: def __init__(self,): self._path = env.get_profile_path() self._nick_name = None diff --git a/sugar/conf/__init__.py b/shell/conf/__init__.py similarity index 50% rename from sugar/conf/__init__.py rename to shell/conf/__init__.py index d8406fae..f69dccbd 100644 --- a/sugar/conf/__init__.py +++ b/shell/conf/__init__.py @@ -1,8 +1,8 @@ -from sugar.conf.ActivityRegistry import _ActivityRegistry -from sugar.conf.Profile import Profile +from conf.ActivityRegistry import _ActivityRegistry +from conf.Profile import _Profile __registry = _ActivityRegistry() -__profile = Profile() +__profile = _Profile() def get_activity_registry(): return __registry diff --git a/shell/frame/BottomPanel.py b/shell/frame/BottomPanel.py index 3cbd53e6..838430d4 100644 --- a/shell/frame/BottomPanel.py +++ b/shell/frame/BottomPanel.py @@ -1,12 +1,12 @@ import gtk import goocanvas +import logging +import conf from sugar.canvas.IconItem import IconItem from sugar.canvas.IconColor import IconColor from sugar.presence import PresenceService -from sugar import conf from frame.Panel import Panel -import logging class ActivityItem(IconItem): def __init__(self, activity, size): diff --git a/shell/home/HomeGroup.py b/shell/home/HomeGroup.py index bb7d27c1..d9600b22 100644 --- a/shell/home/HomeGroup.py +++ b/shell/home/HomeGroup.py @@ -2,11 +2,10 @@ import gtk import goocanvas import wnck +import conf from sugar.canvas.IconItem import IconItem from sugar.canvas.IconColor import IconColor from home.DonutItem import DonutItem -import sugar.conf - import Theme class TasksItem(DonutItem): @@ -65,7 +64,7 @@ class HomeGroup(goocanvas.Group): tasks.translate(600, 450) self.add_child(tasks) - profile = sugar.conf.get_profile() + profile = conf.get_profile() me = IconItem(icon_name = 'stock-buddy', color = profile.get_color(), size = 150) me.translate(600 - (me.get_property('size') / 2), diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index e3d4eab9..5fdb9429 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -2,10 +2,10 @@ import random import goocanvas +import conf from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconColor from sugar.presence import PresenceService -from sugar import conf import Theme diff --git a/shell/sugar b/shell/sugar index 7486c881..1dd726dd 100755 --- a/shell/sugar +++ b/shell/sugar @@ -17,7 +17,7 @@ else: from sugar import env -env.setup() +env.setup_system() from session.Emulator import Emulator @@ -26,6 +26,17 @@ if os.environ.has_key('SUGAR_EMULATOR') and \ emulator = Emulator() emulator.start() +from FirstTimeDialog import FirstTimeDialog +import conf + +profile = conf.get_profile() +if profile.get_nick_name() == None: + dialog = FirstTimeDialog() + dialog.run() + profile.save() + +env.setup_user(profile) + from session.Session import Session session = Session() diff --git a/sugar/Makefile.am b/sugar/Makefile.am index b13bb240..d339fbaf 100644 --- a/sugar/Makefile.am +++ b/sugar/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = activity canvas chat conf p2p presence +SUBDIRS = activity canvas chat p2p presence sugardir = $(pythondir)/sugar sugar_PYTHON = \ diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index f1bbf233..0b0600fb 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -7,7 +7,7 @@ import gtk import gobject from sugar.presence.PresenceService import PresenceService -from sugar.conf import ActivityRegistry +from sugar import activity import sugar.util ACTIVITY_SERVICE_NAME = "org.laptop.Activity" @@ -20,7 +20,6 @@ def get_service_name(xid): def get_object_path(xid): return ACTIVITY_SERVICE_PATH + "/%s" % xid - class ActivityDbusService(dbus.service.Object): """Base dbus service object that each Activity uses to export dbus methods. @@ -91,7 +90,7 @@ class Activity(gtk.Window): def set_type(self, activity_type): """Sets the activity type.""" self._activity_type = activity_type - self._default_type = ActivityRegistry.get_default_type(activity_type) + self._default_type = activity.get_default_type(activity_type) def get_type(self): """Gets the activity type.""" diff --git a/sugar/activity/__init__.py b/sugar/activity/__init__.py index e69de29b..94a1a083 100644 --- a/sugar/activity/__init__.py +++ b/sugar/activity/__init__.py @@ -0,0 +1,8 @@ +def get_default_type(activity_type): + """Get the activity default type. + + It's the type of the main network service which tracks presence + and provides info about the activity, for example the title.""" + splitted_id = activity_type.split('.') + splitted_id.reverse() + return '_' + '_'.join(splitted_id) + '._udp' diff --git a/sugar/env.py b/sugar/env.py index 7d0b76a8..e3c552d8 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -9,7 +9,13 @@ except ImportError: import sugar.setup -def setup(): +def setup_user(profile): + os.environ['SUGAR_NICK_NAME'] = profile.get_nick_name() + +def get_nick_name(): + return os.environ['SUGAR_NICK_NAME'] + +def setup_system(): for path in sugar_python_path: sys.path.insert(0, path) if os.environ.has_key('PYTHONPATH'):