Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/sugar-shell
blob: 0cdda2f5008d25b33d76008862d6a348e12b37d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
# 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

import os
import gettext

import gtk
import gobject
import dbus.glib

gtk.gdk.threads_init()
dbus.glib.threads_init()

from sugar import logger
from sugar.profile import get_profile

from jarabe.view import shell
from jarabe.shellservice import ShellService
from jarabe.hardware import hardwaremanager
from jarabe.intro.window import IntroWindow
from jarabe.intro.window import create_profile
from jarabe.session import get_session_manager
from jarabe import logsmanager
from jarabe import config

def _setup_translations():
    locale_path = os.path.join(config.prefix, 'share', 'locale')
    domain = 'sugar'

    gettext.bindtextdomain(domain, locale_path)
    gettext.textdomain(domain)

def check_cm(bus_name):
    try:
        bus = dbus.SessionBus()
        bus_object = bus.get_object('org.freedesktop.DBus', 
                                    '/org/freedesktop/DBus')
        name_ = bus_object.GetNameOwner(bus_name, 
                                        dbus_interface='org.freedesktop.DBus')
    except dbus.DBusException:
        return False
    return True

def _shell_started_cb():
    # Unfreeze the display
    hw_manager = hardwaremanager.get_manager()
    hw_manager.set_dcon_freeze(0)

def _software_update_cb():
    '''Ask the homeview to display an alert about available software updates
    '''
    home_box = shell.get_instance().home_window.get_home_box()
    home_box.show_software_updates_alert()

def main():
    gobject.idle_add(_shell_started_cb)

    try:
        logsmanager.setup()
    except Exception, e:
        # logs setup is not critical; it should not prevent sugar from
        # starting if (for example) the disk is full or read-only.
        print 'Log setup failed: %s' % e

    logger.start('shell')

    _setup_translations()

    hw_manager = hardwaremanager.get_manager()
    hw_manager.startup()

    icons_path = os.path.join(config.data_path, 'icons')
    gtk.icon_theme_get_default().append_search_path(icons_path)

    # Do initial setup if needed
    if not get_profile().is_valid():
        if 'SUGAR_PROFILE_NAME' in os.environ:
            create_profile(os.environ['SUGAR_PROFILE_NAME'])
        else:
            win = IntroWindow()
            win.show_all()
            gtk.main()

    # set timezone    
    if get_profile().timezone is not None:    
        os.environ['TZ'] = get_profile().timezone

    # TODO: move initializations from the Shell constructor to a start() method
    shell.get_instance()
    ShellService()

    session_manager = get_session_manager()
    session_manager.start()

    # dlo trac #7495: open 'software update' control panel after an upgrade
    # to update activities.
    update_trigger_file = os.path.expanduser('~/.sugar-update')
    if os.path.isfile(update_trigger_file):
        gobject.idle_add(_software_update_cb)

    try:
        gtk.main()
    except KeyboardInterrupt:
        print 'Ctrl+C pressed, exiting...'

main()