Commit 52fa5779 authored by Philipp Hörist's avatar Philipp Hörist

Better emoticon theme fallback strategy

Fallback must be happening in init_emoticon() instead of PreferencesWindow
parent eb3a53c7
......@@ -1596,15 +1596,31 @@ def version_condition(current_version, required_version):
def get_available_emoticon_themes():
emoticons_themes = []
emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons')
font_theme_path = os.path.join(
app.DATA_DIR, 'emoticons', 'font-emoticons', 'emoticons_theme.py')
folders = os.listdir(emoticons_data_path)
if os.path.isdir(app.MY_EMOTS_PATH):
folders += os.listdir(app.MY_EMOTS_PATH)
file = 'emoticons_theme.py'
if os.name == 'nt' and not os.path.exists(font_theme_path):
# When starting Gajim from source .py files are available
# We test this with font-emoticons and fallback to .pyc files otherwise
file = 'emoticons_theme.pyc'
for theme in folders:
theme_path = os.path.join(
emoticons_data_path, theme, 'emoticons_theme.py')
theme_path = os.path.join(emoticons_data_path, theme, file)
if os.path.exists(theme_path):
emoticons_themes.append(theme)
emoticons_themes.sort()
return emoticons_themes
def get_emoticon_theme_path(theme):
emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons', theme)
if os.path.exists(emoticons_data_path):
return emoticons_data_path
emoticons_user_path = os.path.join(app.MY_EMOTS_PATH, theme)
if os.path.exists(emoticons_user_path):
return emoticons_user_path
......@@ -151,13 +151,10 @@ class PreferencesWindow:
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')
config_theme = _('Disabled')
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
type_ = app.config.get('one_message_window')
......
......@@ -1996,18 +1996,16 @@ class Interface:
if 'preferences' in app.interface.instances:
transient_for = app.interface.instances['preferences'].window
path = os.path.join(app.DATA_DIR, 'emoticons', emot_theme)
if not os.path.exists(path):
# It's maybe a user theme
path = os.path.join(app.MY_EMOTS_PATH, emot_theme)
if not os.path.exists(path):
# theme doesn't exist, disable emoticons
dialogs.WarningDialog(_('Emoticons disabled'),
_('Your configured emoticons theme has not been found, so '
'emoticons have been disabled.'),
transient_for=transient_for)
themes = helpers.get_available_emoticon_themes()
if emot_theme not in themes:
if 'font-emoticons' in themes:
emot_theme = 'font-emoticons'
app.config.set('emoticons_theme', 'font-emoticons')
else:
app.config.set('emoticons_theme', '')
return
path = helpers.get_emoticon_theme_path(emot_theme)
if not emoticons.load(path, ascii_emoticons):
dialogs.WarningDialog(
_('Emoticons disabled'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment