diff --git a/src/common/config.py b/src/common/config.py index ecc896920..41b231775 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -4,6 +4,7 @@ ## - Yann Le Boulanger ## - Vincent Hanquez ## - Nikos Kouremenos +## - Dimitur Kirov ## ## Copyright (C) 2003-2005 Gajim Team ## @@ -69,7 +70,7 @@ class Config: 'statusmsgcolor': [ opt_color, '#1eaa1e' ], 'markedmsgcolor': [ opt_color, '#ff8080' ], 'collapsed_rows': [ opt_str, '' ], - 'roster_theme': [ opt_str, 'green' ], + 'roster_theme': [ opt_str, 'GTK+' ], 'saveposition': [ opt_bool, True ], 'mergeaccounts': [ opt_bool, False ], 'sort_by_show': [ opt_bool, True ], @@ -209,20 +210,20 @@ class Config: 'jid': [ opt_str, ''], }, {}), 'themes': ({ - 'accounttextcolor': [ opt_color, 'white' ], - 'accountbgcolor': [ opt_color, 'black' ], + 'accounttextcolor': [ opt_color, 'black' ], + 'accountbgcolor': [ opt_color, 'white' ], 'accountfont': [ opt_str, '' ], - 'accountfontattrs': [ opt_str, '' ], - 'grouptextcolor': [ opt_color, 'white' ], - 'groupbgcolor': [ opt_color, 'black' ], + 'accountfontattrs': [ opt_str, 'B' ], + 'grouptextcolor': [ opt_color, 'black' ], + 'groupbgcolor': [ opt_color, 'white' ], 'groupfont': [ opt_str, '' ], - 'groupfontattrs': [ opt_str, '' ], - 'contacttextcolor': [ opt_color, 'white' ], - 'contactbgcolor': [ opt_color, 'black' ], + 'groupfontattrs': [ opt_str, 'I' ], + 'contacttextcolor': [ opt_color, 'black' ], + 'contactbgcolor': [ opt_color, 'white' ], 'contactfont': [ opt_str, '' ], 'contactfontattrs': [ opt_str, '' ], - 'bannertextcolor': [ opt_color, 'white' ], - 'bannerbgcolor': [ opt_color, 'black' ], + 'bannertextcolor': [ opt_color, 'black' ], + 'bannerbgcolor': [ opt_color, '' ], # http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html # FIXME: not black but the default color from gtk+ theme @@ -319,6 +320,7 @@ class Config: } themes_default = { + 'GTK+': [ '', '', '', 'B', '', '','', 'I', '', '', '', '', '','' ], 'green': [ '#ffffff', '#94aa8c', '', 'B', '#0000ff', '#eff3e7', '', 'I', '#000000', '#ffffff', '', '', '#ffffff', '#94aa8c' ], diff --git a/src/gajim.py b/src/gajim.py index 10b021c4f..2c6f6d0bc 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1101,7 +1101,7 @@ class Interface: #add default themes if there is not in the config file theme = gajim.config.get('roster_theme') if not theme in gajim.config.get_per('themes'): - gajim.config.set('roster_theme', 'green') + gajim.config.set('roster_theme', 'GTK+') if len(gajim.config.get_per('themes')) == 0: d = ['accounttextcolor', 'accountbgcolor', 'accountfont', 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont', 'groupfontattrs', diff --git a/src/gajim_themes_window.py b/src/gajim_themes_window.py index 6ff2d504e..e311bba9f 100644 --- a/src/gajim_themes_window.py +++ b/src/gajim_themes_window.py @@ -1,9 +1,10 @@ -## dialogs.py +## gajim_themes_window.py ## ## Gajim Team: ## - Yann Le Boulanger ## - Vincent Hanquez ## - Nikos Kouremenos +## - Dimitur Kirov ## ## Copyright (C) 2003-2005 Gajim Team ## @@ -21,6 +22,7 @@ import gtk import gtk.glade import gobject import pango +import dialogs from config import mk_color_string from common import gajim @@ -57,6 +59,7 @@ class GajimThemesWindow: self.italic_togglebutton = self.xml.get_widget('italic_togglebutton') self.underline_togglebutton = self.xml.get_widget('underline_togglebutton') self.themes_tree = self.xml.get_widget('themes_treeview') + self.theme_options_vbox = self.xml.get_widget('theme_options_vbox') model = gtk.ListStore(str) self.themes_tree.set_model(model) col = gtk.TreeViewColumn(_('Theme')) @@ -69,8 +72,12 @@ class GajimThemesWindow: self.current_theme = gajim.config.get('roster_theme') self.no_update = False self.fill_themes_treeview() - + self.current_option = self.options[0] + self.set_theme_options(self.current_theme, self.current_option) + self.xml.signal_autoconnect(self) + self.themes_tree.get_selection().connect('changed', + self.selection_changed) self.window.show_all() def on_theme_cell_edited(self, cell, row, new_name): @@ -87,19 +94,22 @@ class GajimThemesWindow: gajim.config.add_per('themes', new_config_name) #Copy old theme values old_config_name = old_name.replace(' ', '_') - for option in self.color_widgets.values(): - gajim.config.set_per('themes', new_config_name, option, - gajim.config.get_per('themes', old_config_name, option)) - for option in self.font_widgets.values(): - gajim.config.set_per('themes', new_config_name, option, - gajim.config.get_per('themes', old_config_name, option)) + properties = ['textcolor', 'bgcolor', 'font', 'fontattrs'] + gajim.config.add_per('themes', new_config_name) + for option in self.options: + for property in properties: + option_name = option + property + gajim.config.set_per('themes', new_config_name, option_name, + gajim.config.get_per('themes', old_config_name, option_name)) gajim.config.del_per('themes', old_config_name) + if old_config_name == gajim.config.get('roster_theme'): + gajim.config.set('roster_theme', new_config_name) model.set_value(iter, 0, new_name) self.plugin.windows['preferences'].update_preferences_window() def fill_themes_treeview(self): self.xml.get_widget('remove_button').set_sensitive(False) - self.xml.get_widget('theme_options_vbox').set_sensitive(False) + self.theme_options_vbox.set_sensitive(False) model = self.themes_tree.get_model() model.clear() for config_theme in gajim.config.get_per('themes'): @@ -108,14 +118,16 @@ class GajimThemesWindow: if gajim.config.get('roster_theme') == config_theme: self.themes_tree.get_selection().select_iter(iter) self.xml.get_widget('remove_button').set_sensitive(True) - self.xml.get_widget('theme_options_vbox').set_sensitive(True) + self.theme_options_vbox.set_sensitive(True) - def on_themes_treeview_cursor_changed(self, widget): + def selection_changed(self, widget = None): (model, iter) = self.themes_tree.get_selection().get_selected() - if not iter: + selected = self.themes_tree.get_selection().get_selected_rows() + if not iter or selected[1] == []: + self.theme_options_vbox.set_sensitive(False) return self.xml.get_widget('remove_button').set_sensitive(True) - self.xml.get_widget('theme_options_vbox').set_sensitive(True) + self.theme_options_vbox.set_sensitive(True) self.current_theme = model.get_value(iter, 0).decode('utf-8') self.current_theme = self.current_theme.replace(' ', '_') self.set_theme_options(self.current_theme) @@ -124,19 +136,27 @@ class GajimThemesWindow: model = self.themes_tree.get_model() iter = model.append() i = 0 - while _('theme_name') + unicode(i) in gajim.config.get_per('themes'): + # don't confuse translators + theme_name = _('theme name') + theme_name_ns = theme_name.replace(' ', '_') + while theme_name_ns + unicode(i) in gajim.config.get_per('themes'): i += 1 - model.set_value(iter, 0, _('theme name') + unicode(i)) - gajim.config.add_per('themes', _('theme_name') + unicode(i)) + model.set_value(iter, 0, theme_name + unicode(i)) + gajim.config.add_per('themes', theme_name_ns + unicode(i)) + self.themes_tree.get_selection().select_iter(iter) + gobject.emit_signal_by_name(editing-started) self.plugin.windows['preferences'].update_preferences_window() def on_remove_button_clicked(self, widget): (model, iter) = self.themes_tree.get_selection().get_selected() if not iter: return - config_name = model.get_value(iter, 0).decode('utf-8') - config_name = config_name.replace(' ', '_') - gajim.config.del_per('themes', config_name) + if self.current_theme == gajim.config.get('roster_theme'): + dialogs.ErrorDialog( + _('You cannot delete your current theme')).get_response() + return + self.theme_options_vbox.set_sensitive(False) + gajim.config.del_per('themes', self.current_theme) model.remove(iter) self.plugin.windows['preferences'].update_preferences_window() @@ -162,7 +182,7 @@ class GajimThemesWindow: self.background_checkbutton.set_active(state) self.background_colorbutton.set_sensitive(state) - #get the font name before we set widgets ant it will not be overriden + #get the font name before we set widgets and it will not be overriden font_name = gajim.config.get_per('themes', theme, option + 'font') font_attrs = gajim.config.get_per('themes', theme, option + 'fontattrs') self._set_font_widgets(font_attrs) @@ -174,7 +194,7 @@ class GajimThemesWindow: self.textfont_checkbutton.set_active(state) self.text_fontbutton.set_sensitive(state) self.no_update = False - self.plugin.roster.draw_roster() + self.plugin.roster.change_roster_style(None) def on_textcolor_checkbutton_toggled(self, widget): state = widget.get_active() @@ -230,10 +250,10 @@ class GajimThemesWindow: # use faster functions for this if self.current_option == 'banner': self.plugin.roster.repaint_themed_widgets() + return if self.no_update: return - # FIXME check if this is currently selected theme - self.plugin.roster.draw_roster() + self.plugin.roster.change_roster_style(self.current_option) def _set_font(self): ''' set font value in prefs and update the UI ''' @@ -252,8 +272,7 @@ class GajimThemesWindow: self.plugin.roster.repaint_themed_widgets() if self.no_update: return - # FIXME check if this is currently selected theme - self.plugin.roster.draw_roster() + self.plugin.roster.change_roster_style(self.current_option) def _toggle_font_widgets(self, font_props): ''' toggle font buttons with the bool values of font_props tuple''' diff --git a/src/roster_window.py b/src/roster_window.py index 359cc750e..12e43ca5e 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -4,6 +4,7 @@ ## - Yann Le Boulanger ## - Vincent Hanquez ## - Nikos Kouremenos +## - Dimitur Kirov ## ## Copyright (C) 2003-2005 Gajim Team ## @@ -526,6 +527,23 @@ class RosterWindow: show_offline_contacts_menuitem.set_sensitive(False) profile_avatar_menuitem.set_sensitive(False) + def _change_style(self, model, path, iter, option): + if option is None: + model[iter][C_NAME] = model[iter][C_NAME] + elif model[iter][C_TYPE] == 'account': + if option == 'account': + model[iter][C_NAME] = model[iter][C_NAME] + elif model[iter][C_TYPE] == 'group': + if option == 'group': + model[iter][C_NAME] = model[iter][C_NAME] + elif model[iter][C_TYPE] == 'contact': + if option == 'contact': + model[iter][C_NAME] = model[iter][C_NAME] + + def change_roster_style(self, option): + model = self.tree.get_model() + model.foreach(self._change_style, option) + def draw_roster(self): '''Clear and draw roster''' self.tree.get_model().clear() @@ -1908,11 +1926,15 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'accountbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('xalign', 0) elif model[iter][C_TYPE] == 'group': color = gajim.config.get_per('themes', theme, 'groupbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('xalign', 0.5) else: jid = model[iter][C_JID].decode('utf-8') @@ -1925,6 +1947,8 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'contactbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('xalign', 1) renderer.set_property('width', 20) @@ -1935,9 +1959,13 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'accounttextcolor') if color: renderer.set_property('foreground', color) + else: + renderer.set_property('foreground', None) color = gajim.config.get_per('themes', theme, 'accountbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('font', gtkgui_helpers.get_theme_font_for_option(theme, 'accountfont')) renderer.set_property('xpad', 0) @@ -1946,9 +1974,13 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'grouptextcolor') if color: renderer.set_property('foreground', color) + else: + renderer.set_property('foreground', None) color = gajim.config.get_per('themes', theme, 'groupbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('font', gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont')) renderer.set_property('xpad', 4) @@ -1958,6 +1990,8 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'contacttextcolor') if color: renderer.set_property('foreground', color) + else: + renderer.set_property('foreground', None) if jid in gajim.newly_added[account]: renderer.set_property('cell-background', '#adc3c6') elif jid in gajim.to_be_removed[account]: @@ -1966,6 +2000,8 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'contactbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) renderer.set_property('font', gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont')) renderer.set_property('xpad', 8) @@ -1977,10 +2013,14 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'accountbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) elif model[iter][C_TYPE] == 'group': color = gajim.config.get_per('themes', theme, 'groupbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) else: jid = model[iter][C_JID].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8') @@ -1992,6 +2032,8 @@ _('If "%s" accepts this request you will know his status.') %jid) color = gajim.config.get_per('themes', theme, 'contactbgcolor') if color: renderer.set_property('cell-background', color) + else: + renderer.set_property('cell-background', None) #renderer.set_property('width', 20) #renderer.set_property('xalign', 0) @@ -2211,7 +2253,7 @@ _('If "%s" accepts this request you will know his status.') %jid) render_image = cell_renderer_image.CellRendererImage() # show img or +- col.pack_start(render_image, expand = False) - col.add_attribute(render_image, 'image', 0) + col.add_attribute(render_image, 'image', C_IMG) col.set_cell_data_func(render_image, self.iconCellDataFunc, None) render_text = gtk.CellRendererText() # contact or group or account name @@ -2219,14 +2261,14 @@ _('If "%s" accepts this request you will know his status.') %jid) render_text.connect('editing-canceled', self.on_editing_canceled) render_text.connect('editing-started', self.on_editing_started) col.pack_start(render_text, expand = True) - col.add_attribute(render_text, 'text', 1) # where we hold the name - col.add_attribute(render_text, 'editable', 5) + col.add_attribute(render_text, 'text', C_NAME) # where we hold the name + col.add_attribute(render_text, 'editable', C_EDITABLE) col.set_cell_data_func(render_text, self.nameCellDataFunc, None) render_pixbuf = gtk.CellRendererPixbuf() # tls or avatar img col.pack_start(render_pixbuf, expand = False) - col.add_attribute(render_pixbuf, 'pixbuf', 6) + col.add_attribute(render_pixbuf, 'pixbuf', C_SECPIXBUF) col.set_cell_data_func(render_pixbuf, self.fill_secondary_pixbuf_rederer, None)