| 1 | ## dialogs.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 | |
|---|
| 20 | import gtk |
|---|
| 21 | import gtk.glade |
|---|
| 22 | from config import mk_color_string |
|---|
| 23 | |
|---|
| 24 | from common import gajim |
|---|
| 25 | from common import i18n |
|---|
| 26 | _ = i18n._ |
|---|
| 27 | APP = i18n.APP |
|---|
| 28 | gtk.glade.bindtextdomain (APP, i18n.DIR) |
|---|
| 29 | gtk.glade.textdomain (APP) |
|---|
| 30 | |
|---|
| 31 | GTKGUI_GLADE = 'gtkgui.glade' |
|---|
| 32 | |
|---|
| 33 | class GajimThemesWindow: |
|---|
| 34 | def on_close_button_clicked(self, widget): |
|---|
| 35 | self.window.destroy() |
|---|
| 36 | |
|---|
| 37 | def __init__(self, plugin): |
|---|
| 38 | self.xml = gtk.glade.XML(GTKGUI_GLADE, 'gajim_themes_window', APP) |
|---|
| 39 | self.window = self.xml.get_widget('gajim_themes_window') |
|---|
| 40 | self.plugin = plugin |
|---|
| 41 | |
|---|
| 42 | self.xml.get_widget('banner_text_fontbutton').set_no_show_all(True) |
|---|
| 43 | |
|---|
| 44 | self.color_widgets = { |
|---|
| 45 | 'account_text_colorbutton': 'accounttextcolor', |
|---|
| 46 | 'group_text_colorbutton': 'grouptextcolor', |
|---|
| 47 | 'user_text_colorbutton': 'contacttextcolor', |
|---|
| 48 | 'banner_colorbutton': 'bannertextcolor', |
|---|
| 49 | 'account_text_bg_colorbutton': 'accountbgcolor', |
|---|
| 50 | 'group_text_bg_colorbutton': 'groupbgcolor', |
|---|
| 51 | 'user_text_bg_colorbutton': 'contactbgcolor', |
|---|
| 52 | 'banner_bg_colorbutton': 'bannerbgcolor', |
|---|
| 53 | } |
|---|
| 54 | self.font_widgets = { |
|---|
| 55 | 'account_text_fontbutton': 'accountfont', |
|---|
| 56 | 'group_text_fontbutton': 'groupfont', |
|---|
| 57 | 'user_text_fontbutton': 'contactfont', |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | self.themes_tree = self.xml.get_widget('themes_treeview') |
|---|
| 61 | model = gtk.ListStore(str) |
|---|
| 62 | self.themes_tree.set_model(model) |
|---|
| 63 | col = gtk.TreeViewColumn(_('Theme')) |
|---|
| 64 | self.themes_tree.append_column(col) |
|---|
| 65 | renderer = gtk.CellRendererText() |
|---|
| 66 | col.pack_start(renderer, True) |
|---|
| 67 | col.set_attributes(renderer, text = 0) |
|---|
| 68 | renderer.connect('edited', self.on_theme_cell_edited) |
|---|
| 69 | renderer.set_property('editable', True) |
|---|
| 70 | self.fill_themes_treeview() |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | self.current_theme = gajim.config.get('roster_theme') |
|---|
| 74 | self.set_widgets(self.current_theme) |
|---|
| 75 | |
|---|
| 76 | self.xml.signal_autoconnect(self) |
|---|
| 77 | self.window.show_all() |
|---|
| 78 | |
|---|
| 79 | def on_theme_cell_edited(self, cell, row, new_name): |
|---|
| 80 | model = self.themes_tree.get_model() |
|---|
| 81 | iter = model.get_iter_from_string(row) |
|---|
| 82 | old_name = model.get_value(iter, 0).decode('utf-8') |
|---|
| 83 | new_name = new_name.decode('utf-8') |
|---|
| 84 | if old_name == new_name: |
|---|
| 85 | return |
|---|
| 86 | new_config_name = new_name.replace(' ', '_') |
|---|
| 87 | if new_config_name in gajim.config.get_per('themes'): |
|---|
| 88 | #ErrorDialog() |
|---|
| 89 | return |
|---|
| 90 | gajim.config.add_per('themes', new_config_name) |
|---|
| 91 | #Copy old theme values |
|---|
| 92 | old_config_name = old_name.replace(' ', '_') |
|---|
| 93 | for option in self.color_widgets.values(): |
|---|
| 94 | gajim.config.set_per('themes', new_config_name, option, |
|---|
| 95 | gajim.config.get_per('themes', old_config_name, option)) |
|---|
| 96 | for option in self.font_widgets.values(): |
|---|
| 97 | gajim.config.set_per('themes', new_config_name, option, |
|---|
| 98 | gajim.config.get_per('themes', old_config_name, option)) |
|---|
| 99 | gajim.config.del_per('themes', old_config_name) |
|---|
| 100 | model.set_value(iter, 0, new_name) |
|---|
| 101 | self.plugin.windows['preferences'].update_preferences_window() |
|---|
| 102 | |
|---|
| 103 | def fill_themes_treeview(self): |
|---|
| 104 | self.xml.get_widget('remove_button').set_sensitive(False) |
|---|
| 105 | self.xml.get_widget('fonts_colors_table').set_sensitive(False) |
|---|
| 106 | model = self.themes_tree.get_model() |
|---|
| 107 | model.clear() |
|---|
| 108 | for config_theme in gajim.config.get_per('themes'): |
|---|
| 109 | theme = config_theme.replace('_', ' ') |
|---|
| 110 | iter = model.append([theme]) |
|---|
| 111 | if gajim.config.get('roster_theme') == config_theme: |
|---|
| 112 | self.themes_tree.get_selection().select_iter(iter) |
|---|
| 113 | self.xml.get_widget('remove_button').set_sensitive(True) |
|---|
| 114 | self.xml.get_widget('fonts_colors_table').set_sensitive(True) |
|---|
| 115 | |
|---|
| 116 | def on_themes_treeview_cursor_changed(self, widget): |
|---|
| 117 | (model, iter) = self.themes_tree.get_selection().get_selected() |
|---|
| 118 | if not iter: |
|---|
| 119 | return |
|---|
| 120 | self.xml.get_widget('remove_button').set_sensitive(True) |
|---|
| 121 | self.xml.get_widget('fonts_colors_table').set_sensitive(True) |
|---|
| 122 | self.current_theme = model.get_value(iter, 0).decode('utf-8') |
|---|
| 123 | self.current_theme = self.current_theme.replace(' ', '_') |
|---|
| 124 | self.set_widgets(self.current_theme) |
|---|
| 125 | |
|---|
| 126 | def on_add_button_clicked(self, widget): |
|---|
| 127 | model = self.themes_tree.get_model() |
|---|
| 128 | iter = model.append() |
|---|
| 129 | i = 0 |
|---|
| 130 | while _('theme_name') + unicode(i) in gajim.config.get_per('themes'): |
|---|
| 131 | i += 1 |
|---|
| 132 | model.set_value(iter, 0, _('theme name') + unicode(i)) |
|---|
| 133 | gajim.config.add_per('themes', _('theme_name') + unicode(i)) |
|---|
| 134 | self.plugin.windows['preferences'].update_preferences_window() |
|---|
| 135 | |
|---|
| 136 | def on_remove_button_clicked(self, widget): |
|---|
| 137 | (model, iter) = self.themes_tree.get_selection().get_selected() |
|---|
| 138 | if not iter: |
|---|
| 139 | return |
|---|
| 140 | config_name = model.get_value(iter, 0).decode('utf-8') |
|---|
| 141 | config_name = config_name.replace(' ', '_') |
|---|
| 142 | gajim.config.del_per('themes', config_name) |
|---|
| 143 | model.remove(iter) |
|---|
| 144 | self.plugin.windows['preferences'].update_preferences_window() |
|---|
| 145 | |
|---|
| 146 | def set_widgets(self, theme): |
|---|
| 147 | for w in self.color_widgets: |
|---|
| 148 | widg = self.xml.get_widget(w) |
|---|
| 149 | widg.set_color(gtk.gdk.color_parse(gajim.config.get_per('themes', |
|---|
| 150 | theme, self.color_widgets[w]))) |
|---|
| 151 | for w in self.font_widgets: |
|---|
| 152 | widg = self.xml.get_widget(w) |
|---|
| 153 | widg.set_font_name(gajim.config.get_per('themes', theme, |
|---|
| 154 | self.font_widgets[w])) |
|---|
| 155 | |
|---|
| 156 | def on_roster_widget_color_set(self, widget, option): |
|---|
| 157 | color = widget.get_color() |
|---|
| 158 | color_string = mk_color_string(color) |
|---|
| 159 | gajim.config.set_per('themes', self.current_theme, option, color_string) |
|---|
| 160 | self.plugin.roster.repaint_themed_widgets() |
|---|
| 161 | self.plugin.roster.draw_roster() |
|---|
| 162 | self.plugin.save_config() |
|---|
| 163 | |
|---|
| 164 | def on_account_text_colorbutton_color_set(self, widget): |
|---|
| 165 | self.on_roster_widget_color_set(widget, 'accounttextcolor') |
|---|
| 166 | |
|---|
| 167 | def on_group_text_colorbutton_color_set(self, widget): |
|---|
| 168 | self.on_roster_widget_color_set(widget, 'grouptextcolor') |
|---|
| 169 | |
|---|
| 170 | def on_user_text_colorbutton_color_set(self, widget): |
|---|
| 171 | self.on_roster_widget_color_set(widget, 'contacttextcolor') |
|---|
| 172 | |
|---|
| 173 | def on_account_text_bg_colorbutton_color_set(self, widget): |
|---|
| 174 | self.on_roster_widget_color_set(widget, 'accountbgcolor') |
|---|
| 175 | |
|---|
| 176 | def on_group_text_bg_colorbutton_color_set(self, widget): |
|---|
| 177 | self.on_roster_widget_color_set(widget, 'groupbgcolor') |
|---|
| 178 | |
|---|
| 179 | def on_user_text_bg_colorbutton_color_set(self, widget): |
|---|
| 180 | self.on_roster_widget_color_set(widget, 'contactbgcolor') |
|---|
| 181 | |
|---|
| 182 | def on_banner_text_colorbutton_color_set(self, widget): |
|---|
| 183 | self.on_roster_widget_color_set(widget, 'bannertextcolor') |
|---|
| 184 | |
|---|
| 185 | def on_banner_bg_colorbutton_color_set(self, widget): |
|---|
| 186 | self.on_roster_widget_color_set(widget, 'bannerbgcolor') |
|---|
| 187 | |
|---|
| 188 | def on_widget_font_set(self, widget, option): |
|---|
| 189 | font_string = widget.get_font_name() |
|---|
| 190 | gajim.config.set_per('themes', self.current_theme, option, font_string) |
|---|
| 191 | self.plugin.roster.draw_roster() |
|---|
| 192 | self.plugin.save_config() |
|---|
| 193 | |
|---|
| 194 | def on_account_text_fontbutton_font_set(self, widget): |
|---|
| 195 | self.on_widget_font_set(widget, 'accountfont') |
|---|
| 196 | |
|---|
| 197 | def on_group_text_fontbutton_font_set(self, widget): |
|---|
| 198 | self.on_widget_font_set(widget, 'groupfont') |
|---|
| 199 | |
|---|
| 200 | def on_user_text_fontbutton_font_set(self, widget): |
|---|
| 201 | self.on_widget_font_set(widget, 'contactfont') |
|---|