~jsjgruber/lernid/lernid

« back to all changes in this revision

Viewing changes to lernid/EventManager.py

  • Committer: John S Gruber
  • Date: 2011-09-03 19:19:47 UTC
  • mfrom: (228.1.17 lernid-proposed)
  • Revision ID: johnsgruber@gmail.com-20110903191947-jkpnalq8wqdnqcbt
* Make schedule a bit easier to read by making font used for instructors one size smaller
* Add 'avoid-desktopcouch' debugging option.
* Remove #ubuntu-classroom-es. Assign correct calendar to #ubuntu-charlas
* Document the following merges in debian/changelog:
* Add instructor names to schedule.
* Add option -d (--debug) for message received and members changed events as
    well as for all other verbose messages. Makes --verbose less verbose.
    Fixes LP: #816080.
* Couch desktopcouch in try: clause; ignore desktopcouch database if
    unavailable. Fixes LP: #795138 and LP: #516619 by this circumvention.
* Use a config file as backup for desktopcouch. Window sizes and pane settings
    will not be restored. The config file is recreated each time lernid
    is run, whether or not desktopcouch is available.
* Get the events from /etc/lernid-classrooms.d/* rather than from the
    Internet. Remove all but the last weeks events and scroll down
    to the current time. LP: #528870.
* Add /etc/lernid-classrooms.d/ubuntu-classroom and
    /etc/lernid-classrooms.d/ubuntu-classroom-es
* Add ubuntu-charlas chatroom choice. These implement the 
    lernid-config-file-improvements blueprint
    basic requirements. Also fix LP: #533279 and LP: #793033.
* Add button to open the slide file in the user's (external) browser.
    Add tooltip text to slide window giving the slide url.
    Resolves LP: #830856 and LP: #530817.
* Add new [slidefile url] and [slidefile url 3] instructor commands to
    load a slide file during a session, and to load the slide file and then
    switch to the page.
* Load slide file asynchronously using gio (rather than using threads). 
    Again fixes LP: #530119. Fixes LP: #795347. Report downloading progress.
    Restablishes these two functions originally created by Peeyoosh
    Sangolekar.
* Remove bold effect from the room names in the classroom and chatroom label.
    Include the '#' in the name, if someone had  abbreviated it.
    Fixes LP: #806797.
* Add a ZERO WIDTH SPACE and SIX-PER-EM SPACE following "QUESTION: " to help
    classbot pick out questions without regard to the word "QUESTION" as its
    language might not match the one lernid is using. Addresses LP: 808570.
* Look for classbot messages in a case-insensitive manner. Mark its messages
    by making them italic. Fixes LP: #794126
* Retrieve the value of "QUESTION:" from the session or the event. Look first
    for a question_token value in the session, then for a locale for the
    session, then for a question_token value for the event, then for a locale
    value for the event. 

* If locale is used and begins with es, translate QUESTION to spanish, otherwise
    leave as english.

* Added a server variable to events for later use.
* Replace light style of QUESTION: label with normal style so it doesn't appear
    to be insensitive. Tooltip text applies to both label and the check  box
    itself. Clicking on the tooltext label toggles the button. Fixes
    LP: #806800, LP: #806793, LP: #793029.
* Make Question: upper-case in the notification reminder and in the mouse-over
    text. Thanks to Mohammad AbuShady. Fixes LP: #808569 .
* Handle the response to the user dismissing the Open event window in two
    stages so that the window can be hidden before the remaining processing
    is started. Fixes LP: #806804.
* Add preference to open URL's as a new tab in the user's default browser
    rather than in Lernid. The initial classroom web page and the
    Event->Open URL... dialog are excluded.
    Thanks to Peeyoosh Sangolekar for providing this feature. See
    https://blueprints.launchpad.net/lernid/+spec/open-in-default-browser .
* Make the test for messages from instructors and helpers case-insensitive.
    Thanks to Mohammad AbuShady. Fixes LP: #812427 .
* Change the last user-agent product-id from Safari to lernid. Thanks go to
    Mohammad AbuShady. Fixes LP: #793805 .
* Prepend URL's input into the Open URL... dialog box with http:// if
    necessary. Thanks, Diogenese The Cynical. Fixes LP: #793793.
* Set new version number

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
import gtk
 
23
import glib
23
24
import gobject
24
25
import ConfigParser
25
26
import urllib2
29
30
from lernid import ConnectDialog
30
31
from lernid.PasswordDialog import PasswordDialog
31
32
from lernid.lernidconfig import save_cache_path
 
33
from lernid.lernidconfig import __lernid_data_directory__
32
34
from lernid.CouchDBPreferences import Preferences
33
35
from lernid.Event import Event
34
36
from lernid.LernidOptions import Options
74
76
homepage: https://wiki.ubuntu.com/Classroom
75
77
classroom: ubuntu-classroom-es
76
78
Chat: ubuntu-classroom-chat-es
 
79
locale: es.ES
77
80
icalurl: http://www.google.com/calendar/ical/canonical.com_qg6t4s8i7mg8d4lgfu9f93qid4@group.calendar.google.com/public/basic.ics
78
81
"""
 
82
 
 
83
# Make sure that these names are lower case
79
84
        self.classbotnames = ['classbot', 'classroombot']
80
 
        try:
81
 
            self._configtext = self._read_config()
82
 
        except IOError:
83
 
            Statusbar.push_message(_('Cannot retrieve configuration'))
84
 
            self._configtext = self._defaultconfig
85
 
        self._config.readfp(io.StringIO(unicode(self._configtext)))
 
85
        if Options.get('config'):
 
86
            try:
 
87
                self._configtext = self._read_config()
 
88
            except IOError:
 
89
                Statusbar.push_message(_('Cannot retrieve configuration'))
 
90
                self._configtext = self._defaultconfig
 
91
            self._config.readfp(io.StringIO(unicode(self._configtext)))
 
92
        else:
 
93
            if __lernid_data_directory__.startswith('/'):
 
94
                path = '/etc/lernid-classrooms.d'
 
95
            else:
 
96
                path = os.path.join(os.path.dirname(__file__),'../etc/lernid-classrooms.d')
 
97
            path = os.path.abspath(path)
 
98
            self._config.read([path+'/'+i for i in os.listdir(path)])
86
99
             
87
100
    @classmethod
88
101
    def get_instance(cls):
92
105
        return _instance_object
93
106
 
94
107
    def _read_config(self):
95
 
        if Options.get('config'):
96
 
            uri = Options.get('config')
97
 
            if uri.startswith('http://') or uri.startswith('https://'):
98
 
                return urllib2.urlopen(uri,None,30).read()
99
 
            else:
100
 
                try:
101
 
                    return open(uri).read()
102
 
                except IOError:
103
 
                    logging.critical("Unable to read configuration file "+uri)
104
 
                    raise
 
108
        uri = Options.get('config')
 
109
        if uri.startswith('http://') or uri.startswith('https://'):
 
110
            return urllib2.urlopen(uri,None,30).read()
105
111
        else:
106
 
            return urllib2.urlopen('http://ubuntu-owl.org/lernid/ubuntu.lernid',None,30).read()
 
112
            try:
 
113
                return open(uri).read()
 
114
            except IOError:
 
115
                logging.critical("Unable to read configuration file "+uri)
 
116
                raise
107
117
 
108
118
    def _connect_event(self, event, nick):
109
119
        if self.is_connected():
126
136
            icalurl = "http://www.google.com/calendar/ical/canonical.com_qg6t4s8i7mg8d4lgfu9f93qid4@group.calendar.google.com/public/basic.ics"
127
137
        try:
128
138
            classroom = self._config.get(event, 'classroom')
 
139
            if classroom[0] not in '#&!+':
 
140
                classroom = '#' + classroom
129
141
        except:
130
 
            classroom = "ubuntu-classroom"
 
142
            classroom = "#ubuntu-classroom"
131
143
        try:
132
144
            chat = self._config.get(event, 'chat')
133
 
        except:
134
 
            chat = "ubuntu-classroom-chat"
 
145
            if chat[0] not in '#&!+':
 
146
                chat = '#' + chat
 
147
        except:
 
148
            chat = "#ubuntu-classroom-chat"
 
149
        try:
 
150
            locale = self._config.get(event, 'locale')
 
151
        except:
 
152
            locale = None
 
153
        try:
 
154
            server = self._config.get(event, 'server')
 
155
        except:
 
156
            server = None
 
157
        try:
 
158
            question_token = self._config.get(event, 'question_token')
 
159
        except:
 
160
            question_token = None
135
161
 
136
162
        self._event = Event(
137
163
            name = event,
141
167
            classroom = classroom,
142
168
            chat = chat,
143
169
            eventstart=eventstart,
144
 
            eventend=eventend
 
170
            eventend=eventend,
 
171
            locale = locale,
 
172
            question_token = question_token,
 
173
            server = server
145
174
        )
146
175
        logging.debug('connecting to event {0}'.format(event))
147
176
        Statusbar.push_message(_('Connecting to event'), duration=10)
168
197
        if not self._connectdialog:
169
198
            self._connectdialog = ConnectDialog.NewConnectDialog()
170
199
            self._connectdialog.set_transient_for(parent)
171
 
            self._connectdialog.connect('response', self._connect_dialog_reponse)
 
200
            self._connectdialog.connect('response', self._connect_dialog_first_response)
172
201
            self._connectdialog.set_nick(Preferences.get('nick'))
173
202
            self._connectdialog.set_transient_for(widget)
174
203
        self._connectdialog.show()
175
204
 
176
 
    def _connect_dialog_reponse(self, dialog, response):
 
205
    def _connect_dialog_first_response(self, dialog, response):
177
206
        if response == gtk.RESPONSE_OK:
178
 
            event = self._connectdialog.get_event()
179
 
            nick = self._connectdialog.get_nick()
180
 
            Preferences.set('nick', nick)
181
 
            self._connect_event(event, nick)
182
 
            password = self._connectdialog.get_password()
183
 
            if password:
184
 
                self._identify_nick(nick, password)
 
207
            self._connectdialog.hide()
 
208
            glib.idle_add(self._connect_dialog_response, dialog, response)
 
209
 
 
210
    def _connect_dialog_response(self, dialog, response):
 
211
        event = self._connectdialog.get_event()
 
212
        nick = self._connectdialog.get_nick()
 
213
        Preferences.set('nick', nick)
 
214
        self._connect_event(event, nick)
 
215
        password = self._connectdialog.get_password()
 
216
        if password:
 
217
            self._identify_nick(nick, password)
185
218
 
186
219
    def disconnect(self):
187
220
        if not self.is_connected():