root/branches/gajim_0.6.1/plugins/gtkgui/config.py

Revision 994, 65.4 kB (checked in by asterix, 4 years ago)

show the correct icon when we activate systray icon
reorder functions so that they are in the order in which they appear in the window

Line 
1##      plugins/config.py
2##
3## Gajim Team:
4##      - Yann Le Boulanger <asterix@lagaule.org>
5##      - Vincent Hanquez <tab@snarc.org>
6##      - Nikos Kouremenos <kourem@gmail.com>
7##
8##      Copyright (C) 2003-2005 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import gtk
21import gtk.glade
22import gobject
23import os
24import common.sleepy
25from common import i18n
26_ = i18n._
27APP = i18n.APP
28gtk.glade.bindtextdomain (APP, i18n.DIR)
29gtk.glade.textdomain (APP)
30
31from dialogs import *
32import gtkgui
33
34GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
35
36
37class Preferences_window:
38        """Class for Preferences window"""
39       
40        def on_preferences_window_delete_event(self, widget, event):
41                self.window.hide()
42                return True # do NOT destroy the window
43       
44        def on_close_button_clicked(self, widget):
45                self.window.hide()     
46
47        def on_preferences_window_show(self, widget):
48                self.notebook.set_current_page(0)
49
50        def on_tray_icon_checkbutton_toggled(self, widget):
51                if widget.get_active():
52                        self.plugin.config['trayicon'] = 1
53                        self.plugin.show_systray()
54                        self.plugin.roster.update_status_comboxbox()
55                else:
56                        self.plugin.config['trayicon'] = 0
57                        self.plugin.hide_systray()
58                self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config, 'GtkGui'))
59                self.plugin.roster.draw_roster()
60       
61        def on_save_position_checkbutton_toggled(self, widget):
62                if widget.get_active():
63                        self.plugin.config['saveposition'] = 1
64                else:
65                        self.plugin.config['saveposition'] = 0
66       
67        def on_merge_checkbutton_toggled(self, widget):
68                if widget.get_active():
69                        self.plugin.config['mergeaccounts'] = 1
70                else:
71                        self.plugin.config['mergeaccounts'] = 0
72                self.plugin.roster.regroup = self.plugin.config['mergeaccounts']
73                self.plugin.roster.draw_roster()
74       
75        def on_iconset_combobox_changed(self, widget):
76                model = widget.get_model()
77                active = widget.get_active()
78                icon_string = model[active][0]
79                self.plugin.config['iconset'] = icon_string
80                self.plugin.roster.reload_pixbufs()
81               
82        def on_account_text_colorbutton_color_set(self, widget):
83                """Take The Color For The Account Text"""
84                color = widget.get_color()
85                color_string = '#' + (hex(color.red) + '0')[2:4] + \
86                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
87                self.plugin.config['accounttextcolor'] = color_string
88                self.plugin.roster.draw_roster()
89       
90        def on_group_text_colorbutton_color_set(self, widget):
91                """Take The Color For The Group Text"""
92                color = widget.get_color()
93                color_string = '#' + (hex(color.red) + '0')[2:4] + \
94                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
95                self.plugin.config['grouptextcolor'] = color_string
96                self.plugin.roster.draw_roster()
97
98        def on_user_text_colorbutton_color_set(self, widget):
99                """Take The Color For The User Text"""
100                color = widget.get_color()
101                color_string = '#' + (hex(color.red) + '0')[2:4] + \
102                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
103                self.plugin.config['usertextcolor'] = color_string
104                self.plugin.roster.draw_roster()
105
106        def on_account_text_bg_colorbutton_color_set(self, widget):
107                """Take The Color For The Background Of Account Text"""
108                color = widget.get_color()
109                color_string = '#' + (hex(color.red) + '0')[2:4] + \
110                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
111                self.plugin.config['accountbgcolor'] = color_string
112                self.plugin.roster.draw_roster()
113       
114        def on_group_text_bg_colorbutton_color_set(self, widget):
115                """Take The Color For The Background Of Group Text"""
116                color = widget.get_color()
117                color_string = '#' + (hex(color.red) + '0')[2:4] + \
118                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
119                self.plugin.config['groupbgcolor'] = color_string
120                self.plugin.roster.draw_roster()
121       
122        def on_user_text_bg_colorbutton_color_set(self, widget):
123                """Take The Color For The Background Of User Text"""
124                color = widget.get_color()
125                color_string = '#' + (hex(color.red) + '0')[2:4] + \
126                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
127                self.plugin.config['userbgcolor'] = color_string
128                self.plugin.roster.draw_roster()
129       
130        def on_account_text_fontbutton_font_set(self, widget):
131                """Take The Font For The User Text"""
132                font_string = widget.get_font_name()
133                self.plugin.config['accountfont'] = font_string
134                self.plugin.roster.draw_roster()
135
136        def on_group_text_fontbutton_font_set(self, widget):
137                """Take The Font For The Group Text"""
138                font_string = widget.get_font_name()
139                self.plugin.config['groupfont'] = font_string
140                self.plugin.roster.draw_roster()
141       
142        def on_user_text_fontbutton_font_set(self, widget):
143                """Take The Font For The User Text"""
144                font_string = widget.get_font_name()
145                self.plugin.config['userfont'] = font_string
146                self.plugin.roster.draw_roster()
147       
148        def on_reset_colors_and_fonts_button_clicked(self, widget):
149                defaults = self.plugin.default_config
150                self.plugin.config['accounttextcolor'] = defaults['accounttextcolor']
151                self.plugin.config['grouptextcolor'] = defaults['grouptextcolor']
152                self.plugin.config['usertextcolor'] = defaults['usertextcolor']
153                self.plugin.config['accountbgcolor'] = defaults['accountbgcolor']
154                self.plugin.config['groupbgcolor'] = defaults['groupbgcolor']
155                self.plugin.config['userbgcolor'] = defaults['userbgcolor']
156                self.plugin.config['accountfont'] = defaults['accountfont']
157                self.plugin.config['groupfont'] = defaults['groupfont']
158                self.plugin.config['userfont'] = defaults['userfont']
159                self.xml.get_widget('account_text_colorbutton').set_color(\
160                        gtk.gdk.color_parse(defaults['accounttextcolor']))             
161                self.xml.get_widget('group_text_colorbutton').set_color(\
162                        gtk.gdk.color_parse(defaults['grouptextcolor']))               
163                self.xml.get_widget('user_text_colorbutton').set_color(\
164                        gtk.gdk.color_parse(defaults['usertextcolor'])) 
165                self.xml.get_widget('account_text_bg_colorbutton').set_color(\
166                        gtk.gdk.color_parse(defaults['accountbgcolor']))               
167                self.xml.get_widget('group_text_bg_colorbutton').set_color(\
168                        gtk.gdk.color_parse(defaults['groupbgcolor']))         
169                self.xml.get_widget('user_text_bg_colorbutton').set_color(\
170                        gtk.gdk.color_parse(defaults['userbgcolor']))
171                self.xml.get_widget('account_text_fontbutton').set_font_name(\
172                        defaults['accountfont'])               
173                self.xml.get_widget('group_text_fontbutton').set_font_name(\
174                        defaults['groupfont'])
175                self.xml.get_widget('user_text_fontbutton').set_font_name(\
176                        defaults['userfont'])
177                self.plugin.roster.draw_roster()
178       
179        def on_use_tabbed_chat_window_checkbutton_toggled(self, widget):
180                buf1 = {}
181                buf2 = {}
182                jids = {}
183                if widget.get_active():
184                        #FIXME Does not work
185                        #save buffers and close windows
186#                       for acct in self.plugin.accounts:
187#                               buf1[acct] = {}
188#                               buf2[acct] = {}
189#                               jids[acct] = self.plugin.windows[acct]['chats'].keys()
190#                               for jid in jids[acct]:
191#                                       buf1[acct][jid] = self.plugin.windows[acct]['chats'][jid].\
192#                                               xmls[jid].get_widget('conversation_textview').get_buffer()
193#                                       buf2[acct][jid] = self.plugin.windows[acct]['chats'][jid].\
194#                                               xmls[jid].get_widget('message_textview').get_buffer()
195#                                       self.plugin.windows[acct]['chats'][jid].window.destroy()
196                        self.plugin.config['usetabbedchat'] = 1
197                        #open new tabbed chat windows
198#                       for acct in self.plugin.accounts:
199#                               for jid in jids[acct]:
200#                                       user = self.plugin.roster.contacts[acct][jid][0]
201#                                       self.plugin.roster.new_chat(user, acct)
202#                                       self.plugin.windows[acct]['chats'][jid].xmls[jid].\
203#                                               get_widget('conversation_textview').set_buffer(\
204#                                                       buf1[acct][jid])
205#                                       self.plugin.windows[acct]['chats'][jid].xmls[jid].\
206#                                               get_widget('message_textview').set_buffer(buf2[acct][jid])
207                else:
208                        #save buffers and close tabbed chat windows
209#                       for acct in self.plugin.accounts:
210#                               buf1[acct] = {}
211#                               buf2[acct] = {}
212#                               jids[acct] = self.plugin.windows[acct]['chats'].keys()
213#                               if 'tabbed' in jids[acct]:
214#                                       jids[acct].remove('tabbed')
215#                                       for jid in jids[acct]:
216#                                               buf1[acct][jid] = self.plugin.windows[acct]['chats'][jid].\
217#                                                       xmls[jid].get_widget('conversation_textview').get_buffer()
218#                                               buf2[acct][jid] = self.plugin.windows[acct]['chats'][jid].\
219#                                                       xmls[jid].get_widget('message_textview').get_buffer()
220#                                       self.plugin.windows[acct]['chats']['tabbed'].window.destroy()
221                        self.plugin.config['usetabbedchat'] = 0
222                        #open new tabbed chat windows
223#                       for acct in self.plugin.accounts:
224#                               for jid in jids[acct]:
225#                                       user = self.plugin.roster.contacts[acct][jid][0]
226#                                       self.plugin.roster.new_chat(user, acct)
227#                                       self.plugin.windows[acct]['chats'][jid].xmls[jid].\
228#                                               get_widget('conversation_textview').set_buffer(\
229#                                                       buf1[acct][jid])
230#                                       self.plugin.windows[acct]['chats'][jid].xmls[jid].\
231#                                               get_widget('message_textview').set_buffer(buf2[acct][jid])
232       
233        def update_print_time(self):
234                """Update time in Opened Chat Windows"""
235                for a in self.plugin.accounts.keys():
236                        if self.plugin.windows[a]['chats'].has_key('tabbed'):
237                                self.plugin.windows[a]['chats']['tabbed'].update_print_time()
238                        else:
239                                for jid in self.plugin.windows[a]['chats'].keys():
240                                        self.plugin.windows[a]['chats'][jid].update_print_time()
241       
242        def on_time_never_radiobutton_toggled(self, widget):
243                if widget.get_active():
244                        self.plugin.config['print_time'] = 'never'
245                self.update_print_time()
246
247        def on_time_sometimes_radiobutton_toggled(self, widget):
248                if widget.get_active():
249                        self.plugin.config['print_time'] = 'sometimes'
250                self.update_print_time()
251
252        def on_time_always_radiobutton_toggled(self, widget):
253                if widget.get_active():
254                        self.plugin.config['print_time'] = 'always'
255                self.update_print_time()
256
257        def on_before_time_entry_focus_out_event(self, widget, event):
258                self.plugin.config['before_time'] = widget.get_text()
259       
260        def on_after_time_entry_focus_out_event(self, widget, event):
261                self.plugin.config['after_time'] = widget.get_text()
262
263        def on_before_nickname_entry_focus_out_event(self, widget, event):
264                self.plugin.config['before_nickname'] = widget.get_text()
265
266        def on_after_nickname_entry_focus_out_event(self, widget, event):
267                self.plugin.config['after_nickname'] = widget.get_text()
268
269        def update_text_tags(self):
270                """Update color tags in Opened Chat Windows"""
271                for a in self.plugin.accounts.keys():
272                        if self.plugin.windows[a]['chats'].has_key('tabbed'):
273                                self.plugin.windows[a]['chats']['tabbed'].update_tags()
274                        else:
275                                for jid in self.plugin.windows[a]['chats'].keys():
276                                        self.plugin.windows[a]['chats'][jid].update_tags()
277       
278        def on_incoming_msg_colorbutton_color_set(self, widget):
279                """Take The Color For The Incoming Messages"""
280                color = widget.get_color()
281                color_string = '#' + (hex(color.red) + '0')[2:4] + \
282                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
283                self.plugin.config['inmsgcolor'] = color_string
284                self.update_text_tags()
285               
286        def on_outgoing_msg_colorbutton_color_set(self, widget):
287                """Take The Color For The Outgoing Messages"""
288                color = widget.get_color()
289                color_string = '#' + (hex(color.red) + '0')[2:4] + \
290                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
291                self.plugin.config['outmsgcolor'] = color_string
292                self.update_text_tags()
293       
294        def on_status_msg_colorbutton_color_set(self, widget):
295                """Take The Color For The Status Messages"""
296                color = widget.get_color()
297                color_string = '#' + (hex(color.red) + '0')[2:4] + \
298                        (hex(color.green) + '0')[2:4] + (hex(color.blue) + '0')[2:4]
299                self.plugin.config['statusmsgcolor'] = color_string
300                self.update_text_tags()
301       
302        def on_reset_colors_button_clicked(self, widget):
303                defaults = self.plugin.default_config
304                self.plugin.config['inmsgcolor'] = defaults['inmsgcolor']
305                self.plugin.config['outmsgcolor'] = defaults['outmsgcolor']
306                self.plugin.config['statusmsgcolor'] = defaults['statusmsgcolor']
307                self.xml.get_widget('incoming_msg_colorbutton').set_color(\
308                        gtk.gdk.color_parse(defaults['inmsgcolor']))           
309                self.xml.get_widget('outgoing_msg_colorbutton').set_color(\
310                        gtk.gdk.color_parse(defaults['outmsgcolor']))           
311                self.xml.get_widget('status_msg_colorbutton').set_color(\
312                        gtk.gdk.color_parse(defaults['statusmsgcolor']))               
313                self.update_text_tags()
314
315        def on_use_emoticons_checkbutton_toggled(self, widget):
316                self.on_checkbutton_toggled(widget, 'useemoticons',\
317                        [self.xml.get_widget('button_new_emoticon'),\
318                        self.xml.get_widget('button_remove_emoticon'),\
319                        self.xml.get_widget('treeview_emoticons'),\
320                        self.xml.get_widget('set_image_button'),\
321                        self.xml.get_widget('emoticons_image')])
322
323        def on_emoticons_treemodel_row_deleted(self, model, path):
324                iter = model.get_iter_first()
325                emots = []
326                while iter:
327                        emots.append(model.get_value(iter, 0))
328                        emots.append(model.get_value(iter, 1))
329                        iter = model.iter_next(iter)
330                self.plugin.config['emoticons'] = '\t'.join(emots)
331                self.plugin.init_regexp()
332
333        def on_emoticons_treemodel_row_changed(self, model, path, iter):
334                if model[path][1] != None and len(model[path][1]) != 0:
335                        iter = model.get_iter_first()
336                        emots = []
337                        while iter:
338                                emots.append(model.get_value(iter, 0))
339                                emots.append(model.get_value(iter, 1))
340                                iter = model.iter_next(iter)
341                        self.plugin.config['emoticons'] = '\t'.join(emots)
342                        self.plugin.init_regexp()
343
344        def on_auto_pop_up_checkbutton_toggled(self, widget):
345                self.on_checkbutton_toggled(widget, 'autopopup', None,\
346                        [self.auto_pp_away_checkbutton])
347
348        def on_auto_pop_up_away_checkbutton_toggled(self, widget):
349                self.on_checkbutton_toggled(widget, 'autopopupaway')
350
351        def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget):
352                self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts')
353
354        def on_soundplayer_entry_changed(self, widget):
355                self.plugin.config['soundplayer'] = widget.get_text()
356               
357        def on_prompt_online_status_message_checkbutton_toggled(self, widget):
358                """On Prompt Online Status Message Checkbutton Toggled"""
359                self.on_checkbutton_toggled(widget, 'ask_online_status')
360       
361        def on_prompt_offline_status_message_checkbutton_toggled(self, widget):
362                """On Prompt Offline Status Message Checkbutton Toggled"""
363                self.on_checkbutton_toggled(widget, 'ask_offline_status')
364       
365        def on_sounds_treemodel_row_changed(self, model, path, iter):
366                iter = model.get_iter_first()
367                while iter:
368                        path = model.get_path(iter)
369                        sound_event = model.get_value(iter, 0)
370                        if model[path][1]:
371                                self.plugin.config['sound_' + sound_event] = 1
372                        else:
373                                self.plugin.config['sound_' + sound_event] = 0
374                        self.plugin.config['sound_' + sound_event + '_file'] = \
375                                model.get_value(iter, 2)
376                        iter = model.iter_next(iter)
377
378        def on_auto_away_checkbutton_toggled(self, widget):
379                self.on_checkbutton_toggled(widget, 'autoaway', None,\
380                        [self.auto_away_time_spinbutton])
381
382        def on_auto_away_time_spinbutton_value_changed(self, widget):
383                aat = widget.get_value_as_int()
384                self.plugin.config['autoawaytime'] = aat
385                self.plugin.sleeper = common.sleepy.Sleepy(\
386                        self.plugin.config['autoawaytime']*60, \
387                        self.plugin.config['autoxatime']*60)
388
389        def on_auto_xa_checkbutton_toggled(self, widget):
390                self.on_checkbutton_toggled(widget, 'autoxa', None,\
391                        [self.auto_xa_time_spinbutton])
392
393        def on_auto_xa_time_spinbutton_value_changed(self, widget):
394                axt = widget.get_value_as_int()
395                self.plugin.config['autoxatime'] = axt
396                self.plugin.sleeper = common.sleepy.Sleepy(\
397                        self.plugin.config['autoawaytime']*60, \
398                        self.plugin.config['autoxatime']*60)
399
400        def on_msg_treemodel_row_changed(self, model, path, iter):
401                iter = model.get_iter_first()
402                i = 0
403                while iter:
404                        self.plugin.config['msg%i_name' % i] = model.get_value(iter, 0)
405                        self.plugin.config['msg%i' % i] = model.get_value(iter, 1)
406                        iter = model.iter_next(iter)
407                        i += 1
408                while self.plugin.config.has_key('msg%s_name' % i):
409                        del self.plugin.config['msg%i_name' % i]
410                        del self.plugin.config['msg%i' % i]
411                        i += 1
412
413        def on_msg_treemodel_row_deleted(self, model, path, iter):
414                iter = model.get_iter_first()
415                i = 0
416                while iter:
417                        self.plugin.config['msg%i_name' % i] = model.get_value(iter, 0)
418                        self.plugin.config['msg%i' % i] = model.get_value(iter, 1)
419                        iter = model.iter_next(iter)
420                        i += 1
421                while self.plugin.config.has_key('msg%s_name' % i):
422                        del self.plugin.config['msg%i_name' % i]
423                        del self.plugin.config['msg%i' % i]
424                        i += 1
425
426        def on_links_open_with_combobox_changed(self, widget):
427                if widget.get_active() == 2:
428                        self.xml.get_widget('custom_apps_frame').set_sensitive(True)
429                        self.plugin.config['openwith'] = 'custom'
430                else:
431                        if widget.get_active() == 0:
432                                self.plugin.config['openwith'] = 'gnome-open'
433                        if widget.get_active() == 1:
434                                self.plugin.config['openwith'] = 'kfmclient exec'
435                        self.xml.get_widget('custom_apps_frame').set_sensitive(False)
436
437        def on_custom_browser_entry_changed(self, widget):
438                self.plugin.config['custombrowser'] = widget.get_text()
439
440        def on_custom_mail_client_entry_changed(self, widget):
441                self.plugin.config['custommailapp'] = widget.get_text()
442
443        def on_log_in_contact_checkbutton_toggled(self, widget):
444                if widget.get_active():
445                        self.config_logger['lognotusr'] = 1
446                else:
447                        self.config_logger['lognotusr'] = 0
448                self.plugin.send('CONFIG', None, ('Logger', self.config_logger, 'GtkGui'))
449
450        def on_log_in_extern_checkbutton_toggled(self, widget):
451                if widget.get_active():
452                        self.config_logger['lognotsep'] = 1
453                else:
454                        self.config_logger['lognotsep'] = 0
455                self.plugin.send('CONFIG', None, ('Logger', self.config_logger, 'GtkGui'))
456
457        def fill_msg_treeview(self):
458                i = 0
459                self.xml.get_widget('delete_msg_button').set_sensitive(False)
460                model = self.msg_tree.get_model()
461                model.clear()
462                while self.plugin.config.has_key('msg%s_name' % i):
463                        iter = model.append()
464                        model.set(iter, 0, self.plugin.config['msg%s_name' % i], 1, self.plugin.config['msg%s' % i])
465                        i += 1
466
467        def on_msg_cell_edited(self, cell, row, new_text):
468                model = self.msg_tree.get_model()
469                iter = model.get_iter_from_string(row)
470                model.set_value(iter, 0, new_text)
471
472        def on_msg_treeview_cursor_changed(self, widget, data=None):
473                self.xml.get_widget('delete_msg_button').set_sensitive(True)
474                buf = self.xml.get_widget('msg_textview').get_buffer()
475                (model, iter) = self.msg_tree.get_selection().get_selected()
476                name = model.get_value(iter, 0)
477                msg = model.get_value(iter, 1)
478                buf.set_text(msg)
479
480        def on_new_msg_button_clicked(self, widget, data=None):
481                model = self.msg_tree.get_model()
482                iter = model.append()
483                model.set(iter, 0, 'msg', 1, 'message')
484
485        def on_delete_msg_button_clicked(self, widget, data=None):
486                (model, iter) = self.msg_tree.get_selection().get_selected()
487                buf = self.xml.get_widget('msg_textview').get_buffer()
488                model.remove(iter)
489                buf.set_text('')
490                self.xml.get_widget('delete_msg_button').set_sensitive(False)
491                       
492        def on_msg_textview_changed(self, widget, data=None):
493                (model, iter) = self.msg_tree.get_selection().get_selected()
494                if not iter:
495                        return
496                buf = self.xml.get_widget('msg_textview').get_buffer()
497                first_iter, end_iter = buf.get_bounds()
498                name = model.get_value(iter, 0)
499                model.set_value(iter, 1, buf.get_text(first_iter, end_iter))
500       
501        def on_msg_treeview_key_press_event(self, widget, event):
502                if event.keyval == gtk.keysyms.Delete:
503                        self.on_delete_msg_button_clicked(widget)
504
505        def image_is_ok(self, image):
506                if not os.path.exists(image):