Refactor loading user supplied iconsets

This commit is contained in:
Philipp Hörist 2018-11-18 17:42:41 +01:00
parent aca34d5c35
commit 1179333fa0
4 changed files with 53 additions and 20 deletions

View File

@ -200,6 +200,9 @@ class GajimApplication(Gtk.Application):
dlg.destroy() dlg.destroy()
sys.exit() sys.exit()
from gajim.gtk.util import load_user_iconsets
load_user_iconsets()
# Set Application Menu # Set Application Menu
app.app = self app.app = self
from gajim.gtk.util import get_builder from gajim.gtk.util import get_builder

View File

@ -15,7 +15,9 @@
# Constants for the gtk module # Constants for the gtk module
from collections import namedtuple 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') Filter = namedtuple('Filter', 'name pattern default')
@ -24,3 +26,13 @@ class Theme(IntEnum):
NOT_DARK = 0 NOT_DARK = 0
DARK = 1 DARK = 1
SYSTEM = 2 SYSTEM = 2
class GajimIconSet(Enum):
DCRAVEN = 'dcraven'
GNOME = 'gnome'
GOOJIM = 'goojim'
GOTA = 'gota'
JABBERBULB = 'jabberbulb'
SUN = 'sun'
WROOP = 'wroop'

View File

@ -21,7 +21,6 @@ from gi.repository import Pango
from gajim.common import app from gajim.common import app
from gajim.common import helpers from gajim.common import helpers
from gajim.common import configpaths
from gajim.common import config as c_config from gajim.common import config as c_config
from gajim.common import idle from gajim.common import idle
from gajim.common.i18n import _ 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_builder
from gajim.gtk.util import get_icon_name 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.dialogs import AspellDictError
from gajim.gtk.themes import Themes from gajim.gtk.themes import Themes
from gajim.gtk.advanced_config import AdvancedConfig 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')) self._ui.ascii_emoticons.set_active(app.config.get('ascii_emoticons'))
# Iconset # 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) model = Gtk.ListStore(str, str)
renderer_image = Gtk.CellRendererPixbuf() renderer_image = Gtk.CellRendererPixbuf()
renderer_text = Gtk.CellRendererText() 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_text, 'text', 1)
self._ui.iconset_combobox.add_attribute(renderer_image, 'icon_name', 0) self._ui.iconset_combobox.add_attribute(renderer_image, 'icon_name', 0)
self._ui.iconset_combobox.set_model(model) self._ui.iconset_combobox.set_model(model)
dirlist = []
for dir_ in iconsets_list: for index, iconset_name in enumerate(get_available_iconsets()):
if not os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', dir_)) \ icon_name = get_icon_name('online', iconset=iconset_name)
and not os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), dir_)): model.append([icon_name, iconset_name])
continue if app.config.get('iconset') == iconset_name:
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_:
self._ui.iconset_combobox.set_active(index) self._ui.iconset_combobox.set_active(index)
# Use transports iconsets # Use transports iconsets

View File

@ -21,6 +21,7 @@ import os
import sys import sys
import logging import logging
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from pathlib import Path
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import Gtk from gi.repository import Gtk
@ -32,6 +33,8 @@ from gajim.common import configpaths
from gajim.common import i18n from gajim.common import i18n
from gajim.common.i18n import _ from gajim.common.i18n import _
from gajim.gtk.const import GajimIconSet
_icon_theme = Gtk.IconTheme.get_default() _icon_theme = Gtk.IconTheme.get_default()
if _icon_theme is not None: if _icon_theme is not None:
_icon_theme.append_search_path(configpaths.get('ICONS')) _icon_theme.append_search_path(configpaths.get('ICONS'))
@ -140,6 +143,34 @@ def get_icon_name(name: str,
return '%s-%s' % (iconset, name) 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]: def get_total_screen_geometry() -> Tuple[int, int]:
screen = Gdk.Screen.get_default() screen = Gdk.Screen.get_default()
window = Gdk.Screen.get_root_window(screen) window = Gdk.Screen.get_root_window(screen)