From eb3a53c79110c94b7a272cdb2f4ca3e1f24e3ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Wed, 21 Feb 2018 23:52:23 +0100 Subject: [PATCH] Refactor emoticon theme combobox - Use ComboBoxText, its much simpler - Add a dedicated method that returns all available themes - If the configured Theme is not available fallback to font-emoticons --- gajim/common/helpers.py | 16 ++++++++++++ gajim/config.py | 37 +++++++++++----------------- gajim/data/gui/preferences_window.ui | 27 +++++++++++--------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py index d5fc04bd0..4d8ed27af 100644 --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -1592,3 +1592,19 @@ def version_condition(current_version, required_version): if V(current_version) < V(required_version): return False return True + +def get_available_emoticon_themes(): + emoticons_themes = [] + emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons') + + folders = os.listdir(emoticons_data_path) + if os.path.isdir(app.MY_EMOTS_PATH): + folders += os.listdir(app.MY_EMOTS_PATH) + + for theme in folders: + theme_path = os.path.join( + emoticons_data_path, theme, 'emoticons_theme.py') + if os.path.exists(theme_path): + emoticons_themes.append(theme) + emoticons_themes.sort() + return emoticons_themes diff --git a/gajim/config.py b/gajim/config.py index 1fab60f1b..8a718df98 100644 --- a/gajim/config.py +++ b/gajim/config.py @@ -143,29 +143,20 @@ class PreferencesWindow: # emoticons emoticons_combobox = self.xml.get_object('emoticons_combobox') - emoticons_list = os.listdir(os.path.join(app.DATA_DIR, 'emoticons')) - # user themes - if os.path.isdir(app.MY_EMOTS_PATH): - emoticons_list += os.listdir(app.MY_EMOTS_PATH) - emoticons_list.sort() - renderer_text = Gtk.CellRendererText() - emoticons_combobox.pack_start(renderer_text, True) - emoticons_combobox.add_attribute(renderer_text, 'text', 0) - model = Gtk.ListStore(str) - emoticons_combobox.set_model(model) - l = [_('Disabled')] - for dir_ in emoticons_list: - if not os.path.isdir(os.path.join(app.DATA_DIR, 'emoticons', dir_)) \ - and not os.path.isdir(os.path.join(app.MY_EMOTS_PATH, dir_)) : - continue - if dir_ != '.svn': - l.append(dir_) - for i in range(len(l)): - model.append([l[i]]) - if app.config.get('emoticons_theme') == l[i]: - emoticons_combobox.set_active(i) - if not app.config.get('emoticons_theme'): - emoticons_combobox.set_active(0) + emoticon_themes = helpers.get_available_emoticon_themes() + + emoticons_combobox.append_text(_('Disabled')) + for theme in emoticon_themes: + emoticons_combobox.append_text(theme) + + config_theme = app.config.get('emoticons_theme') + if config_theme not in emoticon_themes: + # Fallback theme + config_theme = 'font-emoticons' + app.config.set('emoticons_theme', 'font-emoticons') + emoticons_combobox.set_id_column(0) + emoticons_combobox.set_active_id(config_theme) + # Set default for single window type choices = c_config.opt_one_window_types diff --git a/gajim/data/gui/preferences_window.ui b/gajim/data/gui/preferences_window.ui index 101c4f255..0121805df 100644 --- a/gajim/data/gui/preferences_window.ui +++ b/gajim/data/gui/preferences_window.ui @@ -1,5 +1,5 @@ - + @@ -515,17 +515,6 @@ 1 - - - True - False - - - - 1 - 0 - - Show avatar in chat tabs @@ -542,6 +531,17 @@ 2 + + + True + False + + + + 1 + 0 + + @@ -2888,5 +2888,8 @@ to discover one from server. + + +