Commit 1179333f authored by Philipp Hörist's avatar Philipp Hörist

Refactor loading user supplied iconsets

parent aca34d5c
......@@ -200,6 +200,9 @@ class GajimApplication(Gtk.Application):
dlg.destroy()
sys.exit()
from gajim.gtk.util import load_user_iconsets
load_user_iconsets()
# Set Application Menu
app.app = self
from gajim.gtk.util import get_builder
......
......@@ -15,7 +15,9 @@
# Constants for the gtk module
from collections import namedtuple
from enum import IntEnum, unique
from enum import Enum
from enum import IntEnum
from enum import unique
Filter = namedtuple('Filter', 'name pattern default')
......@@ -24,3 +26,13 @@ class Theme(IntEnum):
NOT_DARK = 0
DARK = 1
SYSTEM = 2
class GajimIconSet(Enum):
DCRAVEN = 'dcraven'
GNOME = 'gnome'
GOOJIM = 'goojim'
GOTA = 'gota'
JABBERBULB = 'jabberbulb'
SUN = 'sun'
WROOP = 'wroop'
......@@ -21,7 +21,6 @@ from gi.repository import Pango
from gajim.common import app
from gajim.common import helpers
from gajim.common import configpaths
from gajim.common import config as c_config
from gajim.common import idle
from gajim.common.i18n import _
......@@ -32,6 +31,7 @@ from gajim.chat_control_base import ChatControlBase
from gajim.gtk.util import get_builder
from gajim.gtk.util import get_icon_name
from gajim.gtk.util import get_available_iconsets
from gajim.gtk.dialogs import AspellDictError
from gajim.gtk.themes import Themes
from gajim.gtk.advanced_config import AdvancedConfig
......@@ -331,11 +331,6 @@ class Preferences(Gtk.ApplicationWindow):
self._ui.ascii_emoticons.set_active(app.config.get('ascii_emoticons'))
# Iconset
iconsets_list = os.listdir(
os.path.join(configpaths.get('DATA'), 'iconsets'))
if os.path.isdir(configpaths.get('MY_ICONSETS')):
iconsets_list += os.listdir(configpaths.get('MY_ICONSETS'))
model = Gtk.ListStore(str, str)
renderer_image = Gtk.CellRendererPixbuf()
renderer_text = Gtk.CellRendererText()
......@@ -345,19 +340,11 @@ class Preferences(Gtk.ApplicationWindow):
self._ui.iconset_combobox.add_attribute(renderer_text, 'text', 1)
self._ui.iconset_combobox.add_attribute(renderer_image, 'icon_name', 0)
self._ui.iconset_combobox.set_model(model)
dirlist = []
for dir_ in iconsets_list:
if not os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', dir_)) \
and not os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), dir_)):
continue
if dir_ not in ('.svn', 'transports'):
dirlist.append(dir_)
if not dirlist:
dirlist.append(' ')
for index, dir_ in enumerate(dirlist):
icon_name = get_icon_name('online', iconset=dir_)
model.append([icon_name, dir_])
if app.config.get('iconset') == dir_:
for index, iconset_name in enumerate(get_available_iconsets()):
icon_name = get_icon_name('online', iconset=iconset_name)
model.append([icon_name, iconset_name])
if app.config.get('iconset') == iconset_name:
self._ui.iconset_combobox.set_active(index)
# Use transports iconsets
......
......@@ -21,6 +21,7 @@ import os
import sys
import logging
import xml.etree.ElementTree as ET
from pathlib import Path
from gi.repository import Gdk
from gi.repository import Gtk
......@@ -32,6 +33,8 @@ from gajim.common import configpaths
from gajim.common import i18n
from gajim.common.i18n import _
from gajim.gtk.const import GajimIconSet
_icon_theme = Gtk.IconTheme.get_default()
if _icon_theme is not None:
_icon_theme.append_search_path(configpaths.get('ICONS'))
......@@ -140,6 +143,34 @@ def get_icon_name(name: str,
return '%s-%s' % (iconset, name)
def load_user_iconsets():
iconsets_path = Path(configpaths.get('MY_ICONSETS'))
if not iconsets_path.exists():
return
for path in iconsets_path.iterdir():
if not path.is_dir():
continue
log.info('Found iconset: %s', path.stem)
_icon_theme.append_search_path(str(path))
def get_available_iconsets():
iconsets = []
for iconset in GajimIconSet:
iconsets.append(iconset.value)
iconsets_path = Path(configpaths.get('MY_ICONSETS'))
if not iconsets_path.exists():
return iconsets
for path in iconsets_path.iterdir():
if not path.is_dir():
continue
iconsets.append(path.stem)
return iconsets
def get_total_screen_geometry() -> Tuple[int, int]:
screen = Gdk.Screen.get_default()
window = Gdk.Screen.get_root_window(screen)
......
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