~doctormo/gdm-commmunity-greeter/efl

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
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
#
# Copyright 2011 Martin Owens
#
# 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 3 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, see <http://www.gnu.org/licenses/>
#
"""
Greeter program for GDM using gtk (nothing else works)
"""

import sys, os
import logging
import babel

from gi.repository import Gtk, Gdk, GLib, GObject

from gtkme import GtkApp
from GdmGreeter.services import GdmGreeter
from GdmGreeter.language import (
    LanguageWindow, TranslatableWindow, Translatable
)
from GdmGreeter.login import LoginWindow
from GdmGreeter.register import RegisterWindow
from GdmGreeter.user import User
from GdmGreeter import GLADE_DIR, __appname__

# Store users and their settings here
USER_CONF = '/home/users/%s.conf'

class CommunityGreeterApp(GtkApp, GdmGreeter):
    """Identity Menu for setting up or importing a new identity"""
    app_name  = __appname__
    glade_dir = GLADE_DIR
    windows   = [ LoginWindow, LanguageWindow, RegisterWindow ]

    def __init__(self, *args, **kwargs):
        GtkApp.__init__(self, *args, **kwargs)
        GdmGreeter.__init__(self)
        self.scr = Gdk.Display.get_default().get_screen(self.display.number)
        self.lang = None
        self.login = None
        self.user = None
        self.language = 'en_GB.UTF-8'
        self.session = None
        self.layout = None

    def load_window(self, *args, **kwargs):
        """When loading a window, also translate it"""
        window = GtkApp.load_window(self, *args, **kwargs)
        if isinstance(window, Translatable) and self.language:
            logging.debug("Translating %s to %s" % (window.name, self.language))
            window.translate_to(self.language)
        return window

    def translate_to(self, lang):
        """Translate all windows to target language"""
        self.language = lang
        for window in self._loaded.values():
            if isinstance(window, Translatable):
                logging.debug("I18n window %s to %s" % (window.name, lang))
                window.translate_to(lang)

    def Ready(self):
        """Sever is ready"""
        if not self.lang:
            self.lang = self.load_window('language')
            self.lang.set_position(self.scr.get_width(), self.scr.get_height())
        if not self.login:
            # Load this after language to give it focus
            self.login = self.load_window('login', service=self.obj)
        else:
            self.login.window.set_sensitive(True)
            self.login.show_user('')
        # Tie up the responses, I should do a signal here.
        GdmGreeter.Ready(self)
        logging.warn("Ready!")

    def SelectedUserChanged(self, username):
        """The user has selected the user to login as"""
        self.user = User(username)
        self.SelectLanguage(self.user.get('language', 'en'), loaded=True)

    def SelectLanguage(self, lang, loaded=False):
        """The user wants to change languages"""
        if not loaded and self.user:
            self.user.save(data={ 'language': lang })
        # Translate all windows in the login screen
        self.translate_to(lang)
        # Make sure the session is set correctly.
        if self.user:
            GdmGreeter.SelectLanguage(self, lang)

    def DefaultLanguageNameChanged(self, lang):
        self.language = lang

    def DefaultLayoutNameChanged(self, layout):
        self.layout = str(layout)

    def DefaultSessionNameChanged(self, session):
        self.session = str(session)

    def InfoQuery(self, text):
        """Server wants to ask the user for something"""
        self.login.show_user(text)

    def SecretInfoQuery(self, text):
        """Server wants to ask for some secrate info"""
        self.login.show_pass(text)

    def FinishProcess(self):
        """We're done, quit gtk app"""
        Gtk.main_quit()


if __name__ == "__main__":
    sys.stderr.write("Community Center Greeter Started\n")
    app = CommunityGreeterApp( )
    Gtk.main()