2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, 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
|
|
|
|
|
2006-10-16 13:34:43 +02:00
|
|
|
import os
|
|
|
|
from ConfigParser import ConfigParser
|
2006-08-22 16:15:52 +02:00
|
|
|
|
2006-10-16 13:34:43 +02:00
|
|
|
import gtk
|
2006-08-22 16:15:52 +02:00
|
|
|
from gettext import gettext as _
|
|
|
|
|
2006-10-16 13:34:43 +02:00
|
|
|
from sugar.graphics.iconcolor import IconColor
|
|
|
|
from sugar import env
|
2006-08-22 16:15:52 +02:00
|
|
|
|
2006-09-04 21:34:54 +02:00
|
|
|
class FirstTimeDialog(gtk.Dialog):
|
2006-08-22 16:15:52 +02:00
|
|
|
def __init__(self):
|
2006-09-04 21:34:54 +02:00
|
|
|
gtk.Dialog.__init__(self)
|
2006-08-22 16:15:52 +02:00
|
|
|
|
|
|
|
label = gtk.Label(_('Nick Name:'))
|
|
|
|
label.set_alignment(0.0, 0.5)
|
2006-09-04 21:34:54 +02:00
|
|
|
self.vbox.pack_start(label)
|
2006-08-22 16:15:52 +02:00
|
|
|
label.show()
|
|
|
|
|
|
|
|
self._entry = gtk.Entry()
|
2006-09-26 22:52:45 +02:00
|
|
|
self._entry.connect('changed', self._entry_changed_cb)
|
2006-11-10 13:40:49 +01:00
|
|
|
self._entry.connect('activate', self._entry_activated_cb)
|
2006-09-04 21:34:54 +02:00
|
|
|
self.vbox.pack_start(self._entry)
|
2006-08-22 16:15:52 +02:00
|
|
|
self._entry.show()
|
|
|
|
|
2006-09-26 22:52:45 +02:00
|
|
|
self._ok = gtk.Button(None, gtk.STOCK_OK)
|
|
|
|
self._ok.set_sensitive(False)
|
|
|
|
self.vbox.pack_start(self._ok)
|
2006-10-16 13:34:43 +02:00
|
|
|
self._ok.connect('clicked', self._ok_button_clicked_cb)
|
2006-09-26 22:52:45 +02:00
|
|
|
self._ok.show()
|
|
|
|
|
|
|
|
def _entry_changed_cb(self, entry):
|
|
|
|
valid = (len(entry.get_text()) > 0)
|
|
|
|
self._ok.set_sensitive(valid)
|
2006-08-22 16:15:52 +02:00
|
|
|
|
2006-11-10 13:40:49 +01:00
|
|
|
def _entry_activated_cb(self, entry):
|
|
|
|
self._create_buddy_section()
|
|
|
|
|
2006-10-16 13:34:43 +02:00
|
|
|
def _ok_button_clicked_cb(self, button):
|
2006-11-10 13:40:49 +01:00
|
|
|
self._create_buddy_section()
|
|
|
|
|
|
|
|
def _create_buddy_section(self):
|
2006-10-16 13:34:43 +02:00
|
|
|
cp = ConfigParser()
|
2006-09-04 21:34:54 +02:00
|
|
|
|
2006-10-16 13:34:43 +02:00
|
|
|
section = 'Buddy'
|
|
|
|
cp.add_section(section)
|
|
|
|
cp.set(section, 'NickName', self._entry.get_text())
|
|
|
|
cp.set(section, 'Color', IconColor().to_string())
|
|
|
|
|
|
|
|
config_path = os.path.join(env.get_profile_path(), 'config')
|
|
|
|
fileobject = open(config_path, 'w')
|
|
|
|
cp.write(fileobject)
|
|
|
|
fileobject.close()
|
|
|
|
|
|
|
|
self.destroy()
|