root/branches/gajim_0.11/src/config.py

Revision 7984, 121.4 kB (checked in by asterix, 19 months ago)

mrege diff from trunk

  • Property svn:eol-style set to LF
Line 
1##      config.py
2##
3## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
4## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
5## Copyright (C) 2005 Dimitur Kirov <dkirov@gmail.com>
6## Copyright (C) 2003-2005 Vincent Hanquez <tab@snarc.org>
7## Copyright (C) 2006 Stefan Bethge <stefan@lanpartei.de>
8##
9## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published
11## by the Free Software Foundation; version 2 only.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18
19import gtk
20import gobject
21import os
22import common.config
23import common.sleepy
24from common.i18n import Q_
25
26import gtkgui_helpers
27import dialogs
28import cell_renderer_image
29import message_control
30import chat_control
31
32try:
33        import gtkspell
34        HAS_GTK_SPELL = True
35except:
36        HAS_GTK_SPELL = False
37
38from common import helpers
39from common import gajim
40from common import connection
41from common import passwords
42from common import zeroconf
43from common import dbus_support
44
45from common.exceptions import GajimGeneralException
46
47#---------- PreferencesWindow class -------------#
48class PreferencesWindow:
49        '''Class for Preferences window'''
50
51        def on_preferences_window_destroy(self, widget):
52                '''close window'''
53                del gajim.interface.instances['preferences']
54
55        def on_close_button_clicked(self, widget):
56                self.window.destroy()
57
58        def __init__(self):
59                '''Initialize Preferences window'''
60                self.xml = gtkgui_helpers.get_glade('preferences_window.glade')
61                self.window = self.xml.get_widget('preferences_window')
62                self.window.set_transient_for(gajim.interface.roster.window)
63                self.iconset_combobox = self.xml.get_widget('iconset_combobox')
64                self.notify_on_new_message_radiobutton = self.xml.get_widget(
65                        'notify_on_new_message_radiobutton')
66                self.popup_new_message_radiobutton = self.xml.get_widget(
67                        'popup_new_message_radiobutton')
68                self.notify_on_signin_checkbutton = self.xml.get_widget(
69                        'notify_on_signin_checkbutton')
70                self.notify_on_signout_checkbutton = self.xml.get_widget(
71                        'notify_on_signout_checkbutton')
72                self.auto_popup_away_checkbutton = self.xml.get_widget(
73                        'auto_popup_away_checkbutton')
74                self.auto_away_checkbutton = self.xml.get_widget('auto_away_checkbutton')
75                self.auto_away_time_spinbutton = self.xml.get_widget(
76                        'auto_away_time_spinbutton')
77                self.auto_away_message_entry = self.xml.get_widget(
78                        'auto_away_message_entry')
79                self.auto_xa_checkbutton = self.xml.get_widget('auto_xa_checkbutton')
80                self.auto_xa_time_spinbutton = self.xml.get_widget(
81                        'auto_xa_time_spinbutton')
82                self.auto_xa_message_entry = self.xml.get_widget('auto_xa_message_entry')
83                self.trayicon_checkbutton = self.xml.get_widget('trayicon_checkbutton')
84                self.notebook = self.xml.get_widget('preferences_notebook')
85                self.one_window_type_combobox =\
86                        self.xml.get_widget('one_window_type_combobox')
87                self.treat_incoming_messages_combobox =\
88                        self.xml.get_widget('treat_incoming_messages_combobox')
89
90                #FIXME: remove when ANC will be implemented
91                w = self.xml.get_widget('hbox3020')
92                w.set_no_show_all(True)
93                w.hide()
94
95                # trayicon
96                if gajim.interface.systray_capabilities:
97                        st = gajim.config.get('trayicon')
98                        self.trayicon_checkbutton.set_active(st)
99                else:
100                        self.trayicon_checkbutton.set_sensitive(False)
101
102                # Save position
103                st = gajim.config.get('saveposition')
104                self.xml.get_widget('save_position_checkbutton').set_active(st)
105
106                # Sort contacts by show
107                st = gajim.config.get('sort_by_show')
108                self.xml.get_widget('sort_by_show_checkbutton').set_active(st)
109
110                # Display avatars in roster
111                st = gajim.config.get('show_avatars_in_roster')
112                self.xml.get_widget('show_avatars_in_roster_checkbutton').set_active(st)
113
114                # Display status msg under contact name in roster
115                st = gajim.config.get('show_status_msgs_in_roster')
116                self.xml.get_widget('show_status_msgs_in_roster_checkbutton').set_active(
117                        st)
118
119                # emoticons
120                emoticons_combobox = self.xml.get_widget('emoticons_combobox')
121                emoticons_list = os.listdir(os.path.join(gajim.DATA_DIR, 'emoticons'))
122                # user themes
123                if os.path.isdir(gajim.MY_EMOTS_PATH):
124                        emoticons_list += os.listdir(gajim.MY_EMOTS_PATH)
125                renderer_text = gtk.CellRendererText()
126                emoticons_combobox.pack_start(renderer_text, True)
127                emoticons_combobox.add_attribute(renderer_text, 'text', 0)
128                model = gtk.ListStore(str)
129                emoticons_combobox.set_model(model)
130                l = []
131                for dir in emoticons_list:
132                        if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'emoticons', dir)) \
133                        and not os.path.isdir(os.path.join(gajim.MY_EMOTS_PATH, dir)) :
134                                continue
135                        if dir != '.svn':
136                                l.append(dir)
137                l.append(_('Disabled'))
138                for i in xrange(len(l)):
139                        model.append([l[i]])
140                        if gajim.config.get('emoticons_theme') == l[i]:
141                                emoticons_combobox.set_active(i)
142                if not gajim.config.get('emoticons_theme'):
143                        emoticons_combobox.set_active(len(l)-1)
144
145                # iconset
146                iconsets_list = os.listdir(os.path.join(gajim.DATA_DIR, 'iconsets'))
147                # new model, image in 0, string in 1
148                model = gtk.ListStore(gtk.Image, str)
149                renderer_image = cell_renderer_image.CellRendererImage(0, 0)
150                renderer_text = gtk.CellRendererText()
151                renderer_text.set_property('xpad', 5)
152                self.iconset_combobox.pack_start(renderer_image, expand = False)
153                self.iconset_combobox.pack_start(renderer_text, expand = True)
154                self.iconset_combobox.set_attributes(renderer_text, text = 1)
155                self.iconset_combobox.add_attribute(renderer_image, 'image', 0)
156                self.iconset_combobox.set_model(model)
157                l = []
158                for dir in iconsets_list:
159                        if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', dir)):
160                                continue
161                        if dir != '.svn' and dir != 'transports':
162                                l.append(dir)
163                if l.count == 0:
164                        l.append(' ')
165                for i in xrange(len(l)):
166                        preview = gtk.Image()
167                        files = []
168                        files.append(os.path.join(gajim.DATA_DIR, 'iconsets', l[i], '16x16',
169                                'online.png'))
170                        files.append(os.path.join(gajim.DATA_DIR, 'iconsets', l[i], '16x16',
171                                'online.gif'))
172                        for file in files:
173                                if os.path.exists(file):
174                                        preview.set_from_file(file)
175                        model.append([preview, l[i]])
176                        if gajim.config.get('iconset') == l[i]:
177                                self.iconset_combobox.set_active(i)
178
179                # Set default for single window type
180                choices = common.config.opt_one_window_types
181                type = gajim.config.get('one_message_window')
182                if type in choices:
183                        self.one_window_type_combobox.set_active(choices.index(type))
184                else:
185                        self.one_window_type_combobox.set_active(0)
186
187                # Set default for treat incoming messages
188                choices = common.config.opt_treat_incoming_messages
189                type = gajim.config.get('treat_incoming_messages')
190                if type in choices:
191                        self.treat_incoming_messages_combobox.set_active(choices.index(type))
192                else:
193                        self.treat_incoming_messages_combobox.set_active(0)
194
195                # Use transports iconsets
196                st = gajim.config.get('use_transports_iconsets')
197                self.xml.get_widget('transports_iconsets_checkbutton').set_active(st)
198
199                # Themes
200                theme_combobox = self.xml.get_widget('theme_combobox')
201                cell = gtk.CellRendererText()
202                theme_combobox.pack_start(cell, True)
203                theme_combobox.add_attribute(cell, 'text', 0)
204                model = gtk.ListStore(str)
205                theme_combobox.set_model(model)
206
207                i = 0
208                for config_theme in gajim.config.get_per('themes'):
209                        theme = config_theme.replace('_', ' ')
210                        model.append([theme])
211                        if gajim.config.get('roster_theme') == config_theme:
212                                theme_combobox.set_active(i)
213                        i += 1
214
215                # use speller
216                if os.name == 'nt':
217                        self.xml.get_widget('speller_checkbutton').set_no_show_all(True)
218                else:
219                        if HAS_GTK_SPELL:
220                                st = gajim.config.get('use_speller')
221                                self.xml.get_widget('speller_checkbutton').set_active(st)
222                        else:
223                                self.xml.get_widget('speller_checkbutton').set_sensitive(False)
224
225                # Ignore XHTML
226                st = gajim.config.get('ignore_incoming_xhtml')
227                self.xml.get_widget('xhtml_checkbutton').set_active(st)
228
229                # Print time
230                st = gajim.config.get('print_ichat_every_foo_minutes')
231                text = _('Every %s _minutes') % st
232                self.xml.get_widget('time_sometimes_radiobutton').set_label(text)
233
234                if gajim.config.get('print_time') == 'never':
235                        self.xml.get_widget('time_never_radiobutton').set_active(True)
236                elif gajim.config.get('print_time') == 'sometimes':
237                        self.xml.get_widget('time_sometimes_radiobutton').set_active(True)
238                else:
239                        self.xml.get_widget('time_always_radiobutton').set_active(True)
240
241                # Color for incoming messages
242                colSt = gajim.config.get('inmsgcolor')
243                self.xml.get_widget('incoming_msg_colorbutton').set_color(
244                        gtk.gdk.color_parse(colSt))
245
246                # Color for outgoing messages
247                colSt = gajim.config.get('outmsgcolor')
248                self.xml.get_widget('outgoing_msg_colorbutton').set_color(
249                        gtk.gdk.color_parse(colSt))
250
251                # Color for status messages
252                colSt = gajim.config.get('statusmsgcolor')
253                self.xml.get_widget('status_msg_colorbutton').set_color(
254                        gtk.gdk.color_parse(colSt))
255               
256                # Color for hyperlinks
257                colSt = gajim.config.get('urlmsgcolor')
258                self.xml.get_widget('url_msg_colorbutton').set_color(
259                        gtk.gdk.color_parse(colSt))
260
261                # Font for messages
262                font = gajim.config.get('conversation_font')
263                # try to set default font for the current desktop env
264                fontbutton = self.xml.get_widget('conversation_fontbutton')
265                if font == '':
266                        fontbutton.set_sensitive(False)
267                        self.xml.get_widget('default_chat_font').set_active(True)
268                else:
269                        fontbutton.set_font_name(font)
270
271                # on new message
272                only_in_roster = True
273                if gajim.config.get('notify_on_new_message'):
274                        self.xml.get_widget('notify_on_new_message_radiobutton').set_active(
275                                True)
276                        only_in_roster = False
277                if gajim.config.get('autopopup'):
278                        self.xml.get_widget('popup_new_message_radiobutton').set_active(True)
279                        only_in_roster = False
280                if only_in_roster:
281                        self.xml.get_widget('only_in_roster_radiobutton').set_active(True)
282
283                # notify on online statuses
284                st = gajim.config.get('notify_on_signin')
285                self.notify_on_signin_checkbutton.set_active(st)
286
287                # notify on offline statuses
288                st = gajim.config.get('notify_on_signout')
289                self.notify_on_signout_checkbutton.set_active(st)
290
291                # autopopupaway
292                st = gajim.config.get('autopopupaway')
293                self.auto_popup_away_checkbutton.set_active(st)
294
295                # Ignore messages from unknown contacts
296                self.xml.get_widget('ignore_events_from_unknown_contacts_checkbutton').\
297                        set_active(gajim.config.get('ignore_unknown_contacts'))
298
299                # outgoing send chat state notifications
300                st = gajim.config.get('outgoing_chat_state_notifications')
301                combo = self.xml.get_widget('outgoing_chat_states_combobox')
302                if st == 'all':
303                        combo.set_active(0)
304                elif st == 'composing_only':
305                        combo.set_active(1)
306                else: # disabled
307                        combo.set_active(2)
308
309                # displayed send chat state notifications
310                st = gajim.config.get('displayed_chat_state_notifications')
311                combo = self.xml.get_widget('displayed_chat_states_combobox')
312                if st == 'all':
313                        combo.set_active(0)
314                elif st == 'composing_only':
315                        combo.set_active(1)
316                else: # disabled
317                        combo.set_active(2)
318
319                # sounds
320                if os.name == 'nt':
321                        # if windows, player must not become visible on show_all
322                        soundplayer_hbox = self.xml.get_widget('soundplayer_hbox')
323                        soundplayer_hbox.set_no_show_all(True)
324                if gajim.config.get('sounds_on'):
325                        self.xml.get_widget('play_sounds_checkbutton').set_active(True)
326                else:
327                        self.xml.get_widget('soundplayer_hbox').set_sensitive(False)
328                        self.xml.get_widget('sounds_scrolledwindow').set_sensitive(False)
329                        self.xml.get_widget('browse_sounds_hbox').set_sensitive(False)
330
331                # sound player
332                player = gajim.config.get('soundplayer')
333                self.xml.get_widget('soundplayer_entry').set_text(player)
334                if player == '': # only on first time Gajim starts
335                        commands = ('aplay', 'play', 'esdplay', 'artsplay')
336                        for command in commands:
337                                if helpers.is_in_path(command):
338                                        if command == 'aplay':
339                                                command += ' -q'
340                                        self.xml.get_widget('soundplayer_entry').set_text(command)
341                                        gajim.config.set('soundplayer', command)
342                                        break
343
344                # sounds treeview
345                self.sound_tree = self.xml.get_widget('sounds_treeview')
346               
347                # active, event ui name, path to sound file, event_config_name
348                model = gtk.ListStore(bool, str, str, str)
349                self.sound_tree.set_model(model)
350
351                col = gtk.TreeViewColumn(_('Active'))
352                self.sound_tree.append_column(col)
353                renderer = gtk.CellRendererToggle()
354                renderer.set_property('activatable', True)
355                renderer.connect('toggled', self.sound_toggled_cb)
356                col.pack_start(renderer)
357                col.set_attributes(renderer, active = 0)
358
359                col = gtk.TreeViewColumn(_('Event'))
360                self.sound_tree.append_column(col)
361                renderer = gtk.CellRendererText()
362                col.pack_start(renderer)
363                col.set_attributes(renderer, text = 1)
364
365                self.fill_sound_treeview()
366
367                #Autoaway
368                st = gajim.config.get('autoaway')
369                self.auto_away_checkbutton.set_active(st)
370
371                # Autoawaytime
372                st = gajim.config.get('autoawaytime')
373                self.auto_away_time_spinbutton.set_value(st)
374                self.auto_away_time_spinbutton.set_sensitive(gajim.config.get('autoaway'))
375
376                # autoaway message
377                st = gajim.config.get('autoaway_message')
378                self.auto_away_message_entry.set_text(st)
379                self.auto_away_message_entry.set_sensitive(gajim.config.get('autoaway'))
380
381                # Autoxa
382                st = gajim.config.get('autoxa')
383                self.auto_xa_checkbutton.set_active(st)
384
385                # Autoxatime
386                st = gajim.config.get('autoxatime')
387                self.auto_xa_time_spinbutton.set_value(st)
388                self.auto_xa_time_spinbutton.set_sensitive(gajim.config.get('autoxa'))
389
390                # autoxa message
391                st = gajim.config.get('autoxa_message')
392                self.auto_xa_message_entry.set_text(st)
393                self.auto_xa_message_entry.set_sensitive(gajim.config.get('autoxa'))
394
395                # ask_status when online / offline
396                st = gajim.config.get('ask_online_status')
397                self.xml.get_widget('prompt_online_status_message_checkbutton').\
398                        set_active(st)
399                st = gajim.config.get('ask_offline_status')
400                self.xml.get_widget('prompt_offline_status_message_checkbutton').\
401                        set_active(st)
402
403                # Default Status messages
404                self.default_msg_tree = self.xml.get_widget('default_msg_treeview')
405                # (status, translated_status, message, enabled)
406                model = gtk.ListStore(str, str, str, bool)
407                self.default_msg_tree.set_model(model)
408                col = gtk.TreeViewColumn('Status')
409                self.default_msg_tree.append_column(col)
410                renderer = gtk.CellRendererText()
411                col.pack_start(renderer, False)
412                col.set_attributes(renderer, text = 1)
413                col = gtk.TreeViewColumn('Message')
414                self.default_msg_tree.append_column(col)
415                renderer = gtk.CellRendererText()
416                col.pack_start(renderer, True)
417                col.set_attributes(renderer, text = 2)
418                renderer.connect('edited', self.on_default_msg_cell_edited)
419                renderer.set_property('editable', True)
420                col = gtk.TreeViewColumn('Enabled')
421                self.default_msg_tree.append_column(col)
422                renderer = gtk.CellRendererToggle()
423                col.pack_start(renderer, False)
424                col.set_attributes(renderer, active = 3)
425                renderer.set_property('activatable', True)
426                renderer.connect('toggled', self.default_msg_toggled_cb)
427                self.fill_default_msg_treeview()
428
429                # Status messages
430                self.msg_tree = self.xml.get_widget('msg_treeview')
431                model = gtk.ListStore(str, str)
432                self.msg_tree.set_model(model)
433                col = gtk.TreeViewColumn('name')
434                self.msg_tree.append_column(col)
435                renderer = gtk.CellRendererText()
436                col.pack_start(renderer, True)
437                col.set_attributes(renderer, text = 0)
438                renderer.connect('edited', self.on_msg_cell_edited)
439                renderer.set_property('editable', True)
440                self.fill_msg_treeview()
441                buf = self.xml.get_widget('msg_textview').get_buffer()
442                buf.connect('changed', self.on_msg_textview_changed)
443
444                # open links with
445                if os.name == 'nt':
446                        applications_frame = self.xml.get_widget('applications_frame')
447                        applications_frame.set_no_show_all(True)
448                        applications_frame.hide()
449                else:
450                        self.applications_combobox = self.xml.get_widget(
451                                'applications_combobox')
452                        self.xml.get_widget('custom_apps_frame').hide()
453                        self.xml.get_widget('custom_apps_frame').set_no_show_all(True)
454                        if gajim.config.get('autodetect_browser_mailer'):
455                                self.applications_combobox.set_active(0)
456                        # else autodetect_browser_mailer is False.
457                        # so user has 'Always Use GNOME/KDE/XFCE4' or Custom
458                        elif gajim.config.get('openwith') == 'gnome-open':
459                                self.applications_combobox.set_active(1)
460                        elif gajim.config.get('openwith') == 'kfmclient exec':
461                                self.applications_combobox.set_active(2)
462                        elif gajim.config.get('openwith') == 'exo-open':
463                                self.applications_combobox.set_active(3)                               
464                        elif gajim.config.get('openwith') == 'custom':
465                                self.applications_combobox.set_active(4)
466                                self.xml.get_widget('custom_apps_frame').show()
467                               
468                        self.xml.get_widget('custom_browser_entry').set_text(
469                                gajim.config.get('custombrowser'))
470                        self.xml.get_widget('custom_mail_client_entry').set_text(
471                                gajim.config.get('custommailapp'))
472                        self.xml.get_widget('custom_file_manager_entry').set_text(
473                                gajim.config.get('custom_file_manager'))
474
475                # log status changes of contacts
476                st = gajim.config.get('log_contact_status_changes')
477                self.xml.get_widget('log_show_changes_checkbutton').set_active(st)
478
479                # send os info
480                st = gajim.config.get('send_os_info')
481                self.xml.get_widget('send_os_info_checkbutton').set_active(st)
482
483                # send os info
484                st = gajim.config.get('check_if_gajim_is_default')
485                self.xml.get_widget('check_default_client_checkbutton').set_active(st)
486
487                # set status msg from currently playing music track
488                widget = self.xml.get_widget(
489                        'set_status_msg_from_current_music_track_checkbutton')
490                if os.name == 'nt':
491                        widget.set_no_show_all(True)
492                        widget.hide()
493                elif dbus_support.supported:
494                        st = gajim.config.get('set_status_msg_from_current_music_track')
495                        widget.set_active(st)
496                else:
497                        widget.set_sensitive(False)
498               
499                # Notify user of new gmail e-mail messages,
500                # only show checkbox if user has a gtalk account
501                frame_gmail = self.xml.get_widget('frame_gmail')
502                notify_gmail_checkbutton = self.xml.get_widget('notify_gmail_checkbutton')
503                notify_gmail_extra_checkbutton = self.xml.get_widget(
504                        'notify_gmail_extra_checkbutton')
505                frame_gmail.set_no_show_all(True)
506               
507                for account in gajim.config.get_per('accounts'):
508                        jid = gajim.get_jid_from_account(account)
509                        if gajim.get_server_from_jid(jid) in gajim.gmail_domains:
510                                frame_gmail.show_all()
511                                st = gajim.config.get('notify_on_new_gmail_email')
512                                notify_gmail_checkbutton.set_active(st)
513                                st = gajim.config.get('notify_on_new_gmail_email_extra')
514                                notify_gmail_extra_checkbutton.set_active(st)
515                                break
516                else:
517                        frame_gmail.hide()
518               
519                self.xml.signal_autoconnect(self)
520
521                self.sound_tree.get_model().connect('row-changed',
522                                        self.on_sounds_treemodel_row_changed)
523                self.msg_tree.get_model().connect('row-changed',
524                                        self.on_msg_treemodel_row_changed)
525                self.msg_tree.get_model().connect('row-deleted',
526                                        self.on_msg_treemodel_row_deleted)
527                self.default_msg_tree.get_model().connect('row-changed',
528                                        self.on_default_msg_treemodel_row_changed)
529               
530                self.theme_preferences = None
531               
532                self.notebook.set_current_page(0)
533                self.window.show_all()
534                gtkgui_helpers.possibly_move_window_in_current_desktop(self.window)
535
536        def on_preferences_window_key_press_event(self, widget, event):
537                if event.keyval == gtk.keysyms.Escape:
538                        self.window.hide()
539
540        def on_checkbutton_toggled(self, widget, config_name,
541                change_sensitivity_widgets = None):
542                gajim.config.set(config_name, widget.get_active())
543                if change_sensitivity_widgets:
544                        for w in change_sensitivity_widgets:
545                                w.set_sensitive(widget.get_active())
546                gajim.interface.save_config()
547
548        def on_trayicon_checkbutton_toggled(self, widget):
549                if widget.get_active():
550                        gajim.config.set('trayicon', True)
551                        gajim.interface.show_systray()
552                        show = helpers.get_global_show()
553                        gajim.interface.systray.change_status(show)
554                else:
555                        gajim.config.set('trayicon', False)
556                        if not gajim.interface.roster.window.get_property('visible'):
557                                gajim.interface.roster.window.present()
558                        gajim.interface.hide_systray()
559                        # no tray, show roster!
560                        gajim.config.set('show_roster_on_startup', True)
561                gajim.interface.roster.draw_roster()
562                gajim.interface.save_config()
563
564        def on_save_position_checkbutton_toggled(self, widget):
565                self.on_checkbutton_toggled(widget, 'saveposition')
566
567        def on_sort_by_show_checkbutton_toggled(self, widget):
568                self.on_checkbutton_toggled(widget, 'sort_by_show')
569                gajim.interface.roster.draw_roster()
570
571        def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget):
572                self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster')
573                gajim.interface.roster.draw_roster()
574                for ctl in gajim.interface.msg_win_mgr.controls():
575                        if ctl.type_id == message_control.TYPE_GC:
576                                ctl.update_ui()
577
578        def on_show_avatars_in_roster_checkbutton_toggled(self, widget):
579                self.on_checkbutton_toggled(widget, 'show_avatars_in_roster')
580                gajim.interface.roster.draw_roster()
581
582        def on_emoticons_combobox_changed(self, widget):
583                active = widget.get_active()
584                model = widget.get_model()
585                emot_theme = model[active][0].decode('utf-8')
586                if emot_theme == _('Disabled'):
587                        gajim.config.set('emoticons_theme', '')
588                else:
589                        gajim.config.set('emoticons_theme', emot_theme)
590
591                gajim.interface.init_emoticons(need_reload = True)
592                gajim.interface.make_regexps()
593                self.toggle_emoticons()
594
595        def toggle_emoticons(self):
596                '''Update emoticons state in Opened Chat Windows'''
597                for win in gajim.interface.msg_win_mgr.windows():
598                        win.toggle_emoticons()
599
600        def on_iconset_combobox_changed(self, widget):
601                model = widget.get_model()
602                active = widget.get_active()
603                icon_string = model[active][1].decode('utf-8')
604                gajim.config.set('iconset', icon_string)
605                gajim.interface.roster.reload_jabber_state_images()
606                gajim.interface.save_config()
607
608        def on_transports_iconsets_checkbutton_toggled(self, widget):
609                self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
610                gajim.interface.roster.reload_jabber_state_images()
611
612        def on_manage_theme_button_clicked(self, widget):
613                if self.theme_preferences is None:
614                        self.theme_preferences = dialogs.GajimThemesWindow()
615                else:
616                        self.theme_preferences.window.present()
617                        self.theme_preferences.select_active_theme()
618
619        def on_theme_combobox_changed(self, widget):
620                model = widget.get_model()
621                active = widget.get_active()
622                config_theme = model[active][0].decode('utf-8').replace(' ', '_')
623
624                gajim.config.set('roster_theme', config_theme)
625
626                # begin repainting themed widgets throughout
627                gajim.interface.roster.repaint_themed_widgets()
628                gajim.interface.roster.change_roster_style(None)
629                gajim.interface.save_config()
630
631        def on_open_advanced_notifications_button_clicked(self, widget):
632                dialogs.AdvancedNotificationsWindow()
633
634        def on_one_window_type_combo_changed(self, widget):
635                active = widget.get_active()
636                config_type = common.config.opt_one_window_types[active]
637                gajim.config.set('one_message_window', config_type)
638                gajim.interface.save_config()
639                gajim.interface.msg_win_mgr.reconfig()
640
641        def on_treat_incoming_messages_combobox_changed(self, widget):
642                active = widget.get_active()
643                config_type = common.config.opt_treat_incoming_messages[active]
644                gajim.config.set('treat_incoming_messages', config_type)
645
646        def apply_speller(self):
647                for acct in gajim.connections:
648                        for ctrl in gajim.interface.msg_win_mgr.controls():
649                                if isinstance(ctrl, chat_control.ChatControlBase):
650                                        try:
651                                                spell_obj = gtkspell.get_from_text_view(ctrl.msg_textview)
652                                        except:
653                                                spell_obj = None
654
655                                        if not spell_obj:
656                                                gtkspell.Spell(ctrl.msg_textview)
657
658        def remove_speller(self):
659                for acct in gajim.connections:
660                        for ctrl in gajim.interface.msg_win_mgr.controls():
661                                if isinstance(ctrl, chat_control.ChatControlBase):
662                                        try:
663                                                spell_obj = gtkspell.get_from_text_view(ctrl.msg_textview)
664                                        except:
665                                                spell_obj = None
666                                        if spell_obj:
667                                                spell_obj.detach()
668
669        def on_speller_checkbutton_toggled(self, widget):
670                active = widget.get_active()
671                gajim.config.set('use_speller', active)
672                gajim.interface.save_config()
673                if active:
674                        lang = gajim.config.get('speller_language')
675                        if not lang:
676                                lang = gajim.LANG
677                        tv = gtk.TextView()
678                        try:
679                                spell = gtkspell.Spell(tv, lang)
680                        except:
681                                dialogs.ErrorDialog(
682                                        _('Dictionary for lang %s not available') % lang,
683                                        _('You have to install %s dictionary to use spellchecking, or '
684                                        'choose another language by setting the speller_language option.'
685                                        ) % lang)
686                                gajim.config.set('use_speller', False)
687                                widget.set_active(False)
688                        else:
689                                gajim.config.set('speller_language', lang)
690                                self.apply_speller()
691                else:
692                        self.remove_speller()
693
694        def on_xhtml_checkbutton_toggled(self, widget):
695                self.on_checkbutton_toggled(widget, 'ignore_incoming_xhtml')
696               
697        def on_time_never_radiobutton_toggled(self, widget):
698                if widget.get_active():
699                        gajim.config.set('print_time', 'never')
700                gajim.interface.save_config()
701
702        def on_time_sometimes_radiobutton_toggled(self, widget):
703                if widget.get_active():
704                        gajim.config.set('print_time', 'sometimes')
705                gajim.interface.save_config()
706
707        def on_time_always_radiobutton_toggled(self, widget):
708                if widget.get_active():
709                        gajim.config.set('print_time', 'always')
710                gajim.interface.save_config()
711
712        def update_text_tags(self):
713                '''Update color tags in Opened Chat Windows'''
714                for win in gajim.interface.msg_win_mgr.windows():
715                        win.update_tags()
716
717        def on_preference_widget_color_set(self, widget, text):
718                color = widget.get_color()
719                color_string = gtkgui_helpers.make_color_string(color)
720                gajim.config.set(text, color_string)
721                self.update_text_tags()
722                gajim.interface.save_config()
723
724        def on_preference_widget_font_set(self, widget, text):
725                if widget:
726                        font = widget.get_font_name()
727                else:
728                        font = ''
729                gajim.config.set(text, font)
730                self.update_text_font()
731                gajim.interface.save_config()
732
733        def update_text_font(self):
734                '''Update text font in Opened Chat Windows'''
735                for win in gajim.interface.msg_win_mgr.windows():
736                        win.update_font()
737
738        def on_incoming_msg_colorbutton_color_set(self, widget):
739                self.on_preference_widget_color_set(widget, 'inmsgcolor')
740
741        def on_outgoing_msg_colorbutton_color_set(self, widget):
742                self.on_preference_widget_color_set(widget, 'outmsgcolor')
743
744        def on_url_msg_colorbutton_color_set(self, widget):
745                self.on_preference_widget_color_set(widget, 'urlmsgcolor')
746
747        def on_status_msg_colorbutton_color_set(self, widget):
748                self.on_preference_widget_color_set(widget, 'statusmsgcolor')
749
750        def on_conversation_fontbutton_font_set(self, widget):
751                self.on_preference_widget_font_set(widget, 'conversation_font')
752       
753        def on_default_chat_font_toggled(self, widget):
754                font_widget = self.xml.get_widget('conversation_fontbutton')
755                if widget.get_active():
756                        font_widget.set_sensitive(False)
757                        font_widget = None
758                else:
759                        font_widget.set_sensitive(True)
760                self.on_preference_widget_font_set(font_widget, 'conversation_font')
761
762        def on_reset_colors_button_clicked(self, widget):
763                for i in ('inmsgcolor', 'outmsgcolor', 'statusmsgcolor', 'urlmsgcolor'):
764                        gajim.config.set(i, gajim.interface.default_colors[i])
765
766                self.xml.get_widget('incoming_msg_colorbutton').set_color(\
767                        gtk.gdk.color_parse(gajim.config.get('inmsgcolor')))
768                self.xml.get_widget('outgoing_msg_colorbutton').set_color(\
769                        gtk.gdk.color_parse(gajim.config.get('outmsgcolor')))
770                self.xml.get_widget('status_msg_colorbutton').set_color(\
771                        gtk.gdk.color_parse(gajim.config.get('statusmsgcolor')))
772                self.xml.get_widget('url_msg_colorbutton').set_color(\
773                        gtk.gdk.color_parse(gajim.config.get('urlmsgcolor')))
774                self.update_text_tags()
775                gajim.interface.save_config()
776
777        def on_notify_on_new_message_radiobutton_toggled(self, widget):
778                self.on_checkbutton_toggled(widget, 'notify_on_new_message',
779                                        [self.auto_popup_away_checkbutton])
780
781        def on_popup_new_message_radiobutton_toggled(self, widget):
782                self.on_checkbutton_toggled(widget, 'autopopup',
783                                        [self.auto_popup_away_checkbutton])
784
785        def on_only_in_roster_radiobutton_toggled(self, widget):
786                if widget.get_active():
787                        self.auto_popup_away_checkbutton.set_sensitive(False)
788
789        def on_notify_on_signin_checkbutton_toggled(self, widget):
790                self.on_checkbutton_toggled(widget, 'notify_on_signin')
791
792        def on_notify_on_signout_checkbutton_toggled(self, widget):
793                self.on_checkbutton_toggled(widget, 'notify_on_signout')
794
795        def on_auto_popup_away_checkbutton_toggled(self, widget):
796                self.on_checkbutton_toggled(widget, 'autopopupaway')
797
798        def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget):
799                self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts')
800
801        def on_outgoing_chat_states_combobox_changed(self, widget):
802                active = widget.get_active()
803                if active == 0: # all
804                        gajim.config.set('outgoing_chat_state_notifications', 'all')
805                elif active == 1: # only composing
806                        gajim.config.set('outgoing_chat_state_notifications', 'composing_only')
807                else: # disabled
808                        gajim.config.set('outgoing_chat_state_notifications', 'disabled')
809
810        def on_displayed_chat_states_combobox_changed(self, widget):
811                active = widget.get_active()
812                if active == 0: <