2007-02-25 23:53:10 +01:00
|
|
|
# Copyright (C) 2007, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
import os
|
|
|
|
from ConfigParser import ConfigParser
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
2007-03-05 22:10:14 +01:00
|
|
|
import dbus
|
2007-02-25 23:53:10 +01:00
|
|
|
import hippo
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from sugar import env
|
2007-07-09 16:09:24 +02:00
|
|
|
from sugar.graphics import style
|
2007-09-24 17:43:04 +02:00
|
|
|
from sugar.graphics.icon import Icon
|
2007-08-25 13:15:28 +02:00
|
|
|
from sugar.graphics.entry import CanvasEntry
|
2007-09-17 13:53:10 +02:00
|
|
|
from sugar.profile import get_profile
|
2007-02-25 23:53:10 +01:00
|
|
|
|
|
|
|
import colorpicker
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
_BACKGROUND_COLOR = style.COLOR_PANEL_GREY
|
|
|
|
|
|
|
|
class _Page(hippo.CanvasBox):
|
|
|
|
__gproperties__ = {
|
|
|
|
'valid' : (bool, None, None, False,
|
|
|
|
gobject.PARAM_READABLE)
|
|
|
|
}
|
|
|
|
|
2007-02-26 17:10:24 +01:00
|
|
|
def __init__(self, **kwargs):
|
2007-07-11 12:20:36 +02:00
|
|
|
hippo.CanvasBox.__init__(self, **kwargs)
|
|
|
|
self.valid = False
|
|
|
|
|
|
|
|
def set_valid(self, valid):
|
|
|
|
self.valid = valid
|
|
|
|
self.notify('valid')
|
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
|
|
|
if pspec.name == 'valid':
|
|
|
|
return self.valid
|
|
|
|
|
2007-09-04 23:24:15 +02:00
|
|
|
def activate(self):
|
|
|
|
pass
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
class _NamePage(_Page):
|
2007-07-30 12:59:50 +02:00
|
|
|
def __init__(self, intro):
|
2007-07-11 12:20:36 +02:00
|
|
|
_Page.__init__(self, xalign=hippo.ALIGNMENT_CENTER,
|
|
|
|
background_color=_BACKGROUND_COLOR.get_int(),
|
|
|
|
spacing=style.DEFAULT_SPACING,
|
|
|
|
orientation=hippo.ORIENTATION_HORIZONTAL,)
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-30 12:59:50 +02:00
|
|
|
self._intro = intro
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
label = hippo.CanvasText(text=_("Name:"))
|
|
|
|
self.append(label)
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self._entry = CanvasEntry(box_width=style.zoom(300))
|
2007-07-11 12:20:36 +02:00
|
|
|
self._entry.set_background(_BACKGROUND_COLOR.get_html())
|
|
|
|
self._entry.connect('notify::text', self._text_changed_cb)
|
2007-07-30 12:59:50 +02:00
|
|
|
|
|
|
|
widget = self._entry.props.widget
|
|
|
|
widget.set_max_length(45)
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self.append(self._entry)
|
2007-03-08 01:33:55 +01:00
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
def _text_changed_cb(self, entry, pspec):
|
|
|
|
valid = len(entry.props.text.strip()) > 0
|
|
|
|
self.set_valid(valid)
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
def get_name(self):
|
2007-07-11 12:20:36 +02:00
|
|
|
return self._entry.props.text
|
|
|
|
|
2007-09-04 23:24:15 +02:00
|
|
|
def activate(self):
|
|
|
|
self._entry.props.widget.grab_focus()
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
class _ColorPage(_Page):
|
2007-02-25 23:53:10 +01:00
|
|
|
def __init__(self, **kwargs):
|
2007-07-11 12:20:36 +02:00
|
|
|
_Page.__init__(self, xalign=hippo.ALIGNMENT_CENTER,
|
|
|
|
background_color=_BACKGROUND_COLOR.get_int(),
|
|
|
|
spacing=style.DEFAULT_SPACING,
|
|
|
|
yalign=hippo.ALIGNMENT_CENTER, **kwargs)
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self._label = hippo.CanvasText(text=_("Click to change color:"),
|
|
|
|
xalign=hippo.ALIGNMENT_CENTER)
|
2007-02-25 23:53:10 +01:00
|
|
|
self.append(self._label)
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self._cp = colorpicker.ColorPicker(xalign=hippo.ALIGNMENT_CENTER)
|
2007-02-25 23:53:10 +01:00
|
|
|
self.append(self._cp)
|
|
|
|
|
2007-02-27 21:03:25 +01:00
|
|
|
self._color = self._cp.get_color()
|
2007-07-11 12:20:36 +02:00
|
|
|
self.set_valid(True)
|
2007-02-27 21:03:25 +01:00
|
|
|
|
2007-02-25 23:53:10 +01:00
|
|
|
def get_color(self):
|
2007-07-11 12:50:57 +02:00
|
|
|
return self._cp.get_color()
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
class _IntroBox(hippo.CanvasBox):
|
2007-02-27 21:03:25 +01:00
|
|
|
__gsignals__ = {
|
2007-07-11 11:45:27 +02:00
|
|
|
'done': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
|
|
|
|
gobject.TYPE_PYOBJECT]))
|
2007-02-27 21:03:25 +01:00
|
|
|
}
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
PAGE_NAME = 0
|
|
|
|
PAGE_COLOR = 1
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
PAGE_FIRST = PAGE_NAME
|
|
|
|
PAGE_LAST = PAGE_COLOR
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
def __init__(self):
|
2007-07-11 12:35:13 +02:00
|
|
|
hippo.CanvasBox.__init__(self, padding=style.zoom(30),
|
|
|
|
background_color=_BACKGROUND_COLOR.get_int())
|
2007-06-29 17:08:06 +02:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self._page = self.PAGE_NAME
|
2007-07-30 12:59:50 +02:00
|
|
|
self._name_page = _NamePage(self)
|
2007-07-11 12:20:36 +02:00
|
|
|
self._color_page = _ColorPage()
|
|
|
|
self._current_page = None
|
2007-07-11 11:45:27 +02:00
|
|
|
|
|
|
|
self._setup_page()
|
|
|
|
|
|
|
|
def _setup_page(self):
|
|
|
|
self.remove_all()
|
|
|
|
|
|
|
|
if self._page == self.PAGE_NAME:
|
2007-07-11 12:20:36 +02:00
|
|
|
self._current_page = self._name_page
|
2007-07-11 11:45:27 +02:00
|
|
|
elif self._page == self.PAGE_COLOR:
|
2007-07-11 12:20:36 +02:00
|
|
|
self._current_page = self._color_page
|
|
|
|
|
|
|
|
self.append(self._current_page, hippo.PACK_EXPAND)
|
2007-07-11 11:45:27 +02:00
|
|
|
|
|
|
|
button_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL)
|
|
|
|
|
|
|
|
if self._page != self.PAGE_FIRST:
|
2007-09-24 17:43:04 +02:00
|
|
|
back_button = hippo.CanvasButton(text=_('Back'))
|
|
|
|
image = Icon(icon_name='go-left')
|
|
|
|
back_button.props.widget.set_image(image)
|
2007-07-11 12:20:36 +02:00
|
|
|
back_button.connect('activated', self._back_activated_cb)
|
2007-07-11 11:45:27 +02:00
|
|
|
button_box.append(back_button)
|
2007-02-27 21:03:25 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
spacer = hippo.CanvasBox()
|
|
|
|
button_box.append(spacer, hippo.PACK_EXPAND)
|
|
|
|
|
2007-09-24 17:43:04 +02:00
|
|
|
self._next_button = hippo.CanvasButton()
|
|
|
|
image = Icon(icon_name='go-right')
|
|
|
|
self._next_button.props.widget.set_image(image)
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
if self._page == self.PAGE_LAST:
|
2007-09-24 17:43:04 +02:00
|
|
|
self._next_button.props.text = _('Done')
|
2007-07-11 12:20:36 +02:00
|
|
|
self._next_button.connect('activated', self._done_activated_cb)
|
2007-07-11 11:45:27 +02:00
|
|
|
else:
|
2007-09-24 17:43:04 +02:00
|
|
|
self._next_button.props.text = _('Next')
|
2007-07-11 12:20:36 +02:00
|
|
|
self._next_button.connect('activated', self._next_activated_cb)
|
|
|
|
|
2007-09-04 23:24:15 +02:00
|
|
|
self._current_page.activate()
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
self._update_next_button()
|
2007-07-14 10:29:45 +02:00
|
|
|
button_box.append(self._next_button)
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
self._current_page.connect('notify::valid',
|
|
|
|
self._page_valid_changed_cb)
|
2007-07-11 11:45:27 +02:00
|
|
|
self.append(button_box)
|
|
|
|
|
2007-07-11 12:20:36 +02:00
|
|
|
def _update_next_button(self):
|
|
|
|
widget = self._next_button.props.widget
|
|
|
|
widget.props.sensitive = self._current_page.props.valid
|
|
|
|
|
|
|
|
def _page_valid_changed_cb(self, page, pspec):
|
|
|
|
self._update_next_button()
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
def _back_activated_cb(self, item):
|
2007-09-04 23:24:15 +02:00
|
|
|
self.back()
|
|
|
|
|
|
|
|
def back(self):
|
|
|
|
if self._page != self.PAGE_FIRST:
|
|
|
|
self._page -= 1
|
|
|
|
self._setup_page()
|
2007-07-11 11:45:27 +02:00
|
|
|
|
|
|
|
def _next_activated_cb(self, item):
|
2007-07-30 12:59:50 +02:00
|
|
|
self.next()
|
2007-07-11 11:45:27 +02:00
|
|
|
|
2007-09-04 23:24:15 +02:00
|
|
|
def next(self):
|
|
|
|
if self._page == self.PAGE_LAST:
|
|
|
|
self.done()
|
|
|
|
if self._current_page.props.valid:
|
|
|
|
self._page += 1
|
|
|
|
self._setup_page()
|
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
def _done_activated_cb(self, item):
|
2007-09-04 23:24:15 +02:00
|
|
|
self.done()
|
|
|
|
|
|
|
|
def done(self):
|
2007-07-11 11:45:27 +02:00
|
|
|
path = os.path.join(os.path.dirname(__file__), 'default-picture.png')
|
|
|
|
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
|
|
|
|
name = self._name_page.get_name()
|
|
|
|
color = self._color_page.get_color()
|
2007-09-04 23:24:15 +02:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
self.emit('done', pixbuf, name, color)
|
2007-02-27 21:03:25 +01:00
|
|
|
|
2007-09-04 23:24:15 +02:00
|
|
|
def _key_press_cb(self, widget, event):
|
|
|
|
if gtk.gdk.keyval_name(event.keyval) == "Return":
|
|
|
|
self.next()
|
|
|
|
return True
|
|
|
|
elif gtk.gdk.keyval_name(event.keyval) == "Escape":
|
|
|
|
self.back()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2007-02-27 21:03:25 +01:00
|
|
|
class IntroWindow(gtk.Window):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Window.__init__(self)
|
|
|
|
|
|
|
|
self._canvas = hippo.Canvas()
|
2007-07-11 11:45:27 +02:00
|
|
|
self._intro_box = _IntroBox()
|
|
|
|
self._intro_box.connect('done', self._done_cb)
|
2007-02-27 21:03:25 +01:00
|
|
|
self._canvas.set_root(self._intro_box)
|
2007-07-11 11:45:27 +02:00
|
|
|
|
2007-02-27 21:03:25 +01:00
|
|
|
self.add(self._canvas)
|
2007-07-11 11:45:27 +02:00
|
|
|
self._canvas.show()
|
2007-09-04 23:24:15 +02:00
|
|
|
self.connect('key-press-event', self._intro_box._key_press_cb)
|
2007-02-27 21:03:25 +01:00
|
|
|
|
2007-07-11 11:45:27 +02:00
|
|
|
def _done_cb(self, box, pixbuf, name, color):
|
2007-02-27 21:03:25 +01:00
|
|
|
self.hide()
|
|
|
|
gobject.idle_add(self._create_profile, pixbuf, name, color)
|
2007-02-25 23:53:10 +01:00
|
|
|
|
|
|
|
def _create_profile(self, pixbuf, name, color):
|
|
|
|
# Save the buddy icon
|
2007-03-14 19:43:53 +01:00
|
|
|
icon_path = os.path.join(env.get_profile_path(), "buddy-icon.jpg")
|
|
|
|
scaled = pixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR)
|
|
|
|
pixbuf.save(icon_path, "jpeg", {"quality":"85"})
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-09-17 13:53:10 +02:00
|
|
|
profile = get_profile()
|
2007-09-18 13:56:07 +02:00
|
|
|
profile.nick_name = name
|
2007-09-17 13:53:10 +02:00
|
|
|
profile.color = color
|
|
|
|
profile.save()
|
2007-02-25 23:53:10 +01:00
|
|
|
|
|
|
|
# Generate keypair
|
|
|
|
import commands
|
|
|
|
keypath = os.path.join(env.get_profile_path(), "owner.key")
|
2007-07-30 15:34:02 +02:00
|
|
|
if not os.path.isfile(keypath):
|
|
|
|
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % keypath
|
|
|
|
(s, o) = commands.getstatusoutput(cmd)
|
|
|
|
if s != 0:
|
|
|
|
logging.error("Could not generate key pair: %d" % s)
|
|
|
|
else:
|
|
|
|
logging.error("Keypair exists, skip generation.")
|
2007-02-25 23:53:10 +01:00
|
|
|
|
2007-02-27 21:03:25 +01:00
|
|
|
gtk.main_quit()
|
|
|
|
return False
|
2007-02-25 23:53:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
w = IntroWindow()
|
2007-07-11 11:45:27 +02:00
|
|
|
w.show()
|
2007-02-25 23:53:10 +01:00
|
|
|
w.connect('destroy', gtk.main_quit)
|
|
|
|
gtk.main()
|