Better emoticon theme fallback strategy
Fallback must be happening in init_emoticon() instead of PreferencesWindow
This commit is contained in:
parent
eb3a53c791
commit
52fa57795a
3 changed files with 27 additions and 16 deletions
|
@ -1596,15 +1596,31 @@ def version_condition(current_version, required_version):
|
||||||
def get_available_emoticon_themes():
|
def get_available_emoticon_themes():
|
||||||
emoticons_themes = []
|
emoticons_themes = []
|
||||||
emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons')
|
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)
|
folders = os.listdir(emoticons_data_path)
|
||||||
if os.path.isdir(app.MY_EMOTS_PATH):
|
if os.path.isdir(app.MY_EMOTS_PATH):
|
||||||
folders += os.listdir(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:
|
for theme in folders:
|
||||||
theme_path = os.path.join(
|
theme_path = os.path.join(emoticons_data_path, theme, file)
|
||||||
emoticons_data_path, theme, 'emoticons_theme.py')
|
|
||||||
if os.path.exists(theme_path):
|
if os.path.exists(theme_path):
|
||||||
emoticons_themes.append(theme)
|
emoticons_themes.append(theme)
|
||||||
emoticons_themes.sort()
|
emoticons_themes.sort()
|
||||||
return emoticons_themes
|
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')
|
config_theme = app.config.get('emoticons_theme')
|
||||||
if config_theme not in emoticon_themes:
|
if config_theme not in emoticon_themes:
|
||||||
# Fallback theme
|
config_theme = _('Disabled')
|
||||||
config_theme = 'font-emoticons'
|
|
||||||
app.config.set('emoticons_theme', 'font-emoticons')
|
|
||||||
emoticons_combobox.set_id_column(0)
|
emoticons_combobox.set_id_column(0)
|
||||||
emoticons_combobox.set_active_id(config_theme)
|
emoticons_combobox.set_active_id(config_theme)
|
||||||
|
|
||||||
|
|
||||||
# Set default for single window type
|
# Set default for single window type
|
||||||
choices = c_config.opt_one_window_types
|
choices = c_config.opt_one_window_types
|
||||||
type_ = app.config.get('one_message_window')
|
type_ = app.config.get('one_message_window')
|
||||||
|
|
|
@ -1996,18 +1996,16 @@ class Interface:
|
||||||
if 'preferences' in app.interface.instances:
|
if 'preferences' in app.interface.instances:
|
||||||
transient_for = app.interface.instances['preferences'].window
|
transient_for = app.interface.instances['preferences'].window
|
||||||
|
|
||||||
path = os.path.join(app.DATA_DIR, 'emoticons', emot_theme)
|
themes = helpers.get_available_emoticon_themes()
|
||||||
if not os.path.exists(path):
|
if emot_theme not in themes:
|
||||||
# It's maybe a user theme
|
if 'font-emoticons' in themes:
|
||||||
path = os.path.join(app.MY_EMOTS_PATH, emot_theme)
|
emot_theme = 'font-emoticons'
|
||||||
if not os.path.exists(path):
|
app.config.set('emoticons_theme', 'font-emoticons')
|
||||||
# theme doesn't exist, disable emoticons
|
else:
|
||||||
dialogs.WarningDialog(_('Emoticons disabled'),
|
|
||||||
_('Your configured emoticons theme has not been found, so '
|
|
||||||
'emoticons have been disabled.'),
|
|
||||||
transient_for=transient_for)
|
|
||||||
app.config.set('emoticons_theme', '')
|
app.config.set('emoticons_theme', '')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
path = helpers.get_emoticon_theme_path(emot_theme)
|
||||||
if not emoticons.load(path, ascii_emoticons):
|
if not emoticons.load(path, ascii_emoticons):
|
||||||
dialogs.WarningDialog(
|
dialogs.WarningDialog(
|
||||||
_('Emoticons disabled'),
|
_('Emoticons disabled'),
|
||||||
|
|
Loading…
Add table
Reference in a new issue