From 5b10d8fe5c84453ea649539c2d3ce1044fd86ab7 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 27 Nov 2009 16:42:32 +0100 Subject: [PATCH] base of using icon themes. see #2378 --- configure.ac | 1 + data/Makefile.am | 2 +- data/icons/Makefile.am | 38 ++++++++++++++++++ .../hicolor/16x16/actions/gajim-upload.png} | Bin src/chat_control.py | 2 +- src/common/configpaths.py | 1 + src/common/gajim.py | 1 + src/groupchat_control.py | 2 +- src/gtkgui_helpers.py | 20 +++++++++ src/gui_menu_builder.py | 2 +- 10 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 data/icons/Makefile.am rename data/{pixmaps/upload.png => icons/hicolor/16x16/actions/gajim-upload.png} (100%) diff --git a/configure.ac b/configure.ac index af9840989..35137be01 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ AC_CONFIG_FILES([ data/iconsets/Makefile data/moods/Makefile data/activities/Makefile + data/icons/Makefile data/gajim.desktop.in data/defs.py src/Makefile diff --git a/data/Makefile.am b/data/Makefile.am index 541dcc85e..d7b4dc7f7 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = glade emoticons pixmaps iconsets moods activities +SUBDIRS = glade emoticons pixmaps iconsets moods activities icons @INTLTOOL_DESKTOP_RULE@ desktopdir = $(datadir)/applications diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am new file mode 100644 index 000000000..bdea3806a --- /dev/null +++ b/data/icons/Makefile.am @@ -0,0 +1,38 @@ +iconsdir = $(pkgdatadir)/icons + +icons_DATA = + +ICONS_DIRS = **/**/** + +ICONS_FILES = **/**/**/{*.png,*.svg} + + +install-data-local: + @for d in $$(cd $(srcdir); echo $(ICONS_DIRS));do \ + if test -d $(srcdir)/$$d;then \ + echo " $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/icons/$$d"; \ + $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/icons/$$d || exit 1; \ + fi; \ + done; \ + for f in $$(cd $(srcdir); echo $(ICONS_FILES));do \ + if test -f $(srcdir)/$$f; then \ + echo " $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(pkgdatadir)/icons/$$f"; \ + $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(pkgdatadir)/icons/$$f || exit 1; \ + fi; \ + done; + +dist-hook: + @for d in $$(cd $(srcdir); echo $(ICONS_DIRS));do \ + if test -d $(srcdir)/$$d;then \ + echo " $(mkdir_p) $(distdir)/$$d"; \ + $(mkdir_p) $(distdir)/$$d || exit 1; \ + fi; \ + done; \ + for f in $$(cd $(srcdir); echo $(ICONS_FILES));do \ + if test -f $(srcdir)/$$f; then \ + echo " cp -pR $(srcdir)/$$f $(distdir)/$$f"; \ + cp -pR $(srcdir)/$$f $(distdir)/$$f || exit 1; \ + fi; \ + done; + +MAINTAINERCLEANFILES = Makefile.in diff --git a/data/pixmaps/upload.png b/data/icons/hicolor/16x16/actions/gajim-upload.png similarity index 100% rename from data/pixmaps/upload.png rename to data/icons/hicolor/16x16/actions/gajim-upload.png diff --git a/src/chat_control.py b/src/chat_control.py index 13ed056d9..5aef1a7e8 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1292,7 +1292,7 @@ class ChatControl(ChatControlBase): self._send_file_button = self.xml.get_widget('send_file_button') # add a special img for send file button - path_to_upload_img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'upload.png') + path_to_upload_img = gtkgui_helpers.get_icon_path('gajim-upload') img = gtk.Image() img.set_from_file(path_to_upload_img) self._send_file_button.set_image(img) diff --git a/src/common/configpaths.py b/src/common/configpaths.py index bf1372970..f1e820abb 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -122,6 +122,7 @@ class ConfigPaths: if not datadir: datadir = u'..' self.add('DATA', os.path.join(datadir, windowsify(u'data'))) + self.add('ICONS', os.path.join(datadir, windowsify(u'icons'))) self.add('HOME', fse(os.path.expanduser('~'))) try: self.add('TMP', fse(tempfile.gettempdir())) diff --git a/src/common/gajim.py b/src/common/gajim.py index ba43cff68..509ef0591 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -85,6 +85,7 @@ MY_ACTIVITY_ICONSETS_PATH = gajimpaths['MY_ACTIVITY_ICONSETS'] MY_CACERTS = gajimpaths['MY_CACERTS'] TMP = gajimpaths['TMP'] DATA_DIR = gajimpaths['DATA'] +ICONS_DIR = gajimpaths['ICONS'] HOME_DIR = gajimpaths['HOME'] try: diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 8b7c1ed9d..8319b2a4c 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -2086,7 +2086,7 @@ class GroupchatControl(ChatControlBase): item = xml.get_widget('send_file_menuitem') # add a special img for send file menuitem - path_to_upload_img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'upload.png') + path_to_upload_img = gtkgui_helpers.get_icon_path('gajim-upload') img = gtk.Image() img.set_from_file(path_to_upload_img) item.set_image(img) diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 273dc65b7..eb77e7db6 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -61,6 +61,26 @@ gtk.glade.textdomain(i18n.APP) screen_w = gtk.gdk.screen_width() screen_h = gtk.gdk.screen_height() +gtk_icon_theme = gtk.icon_theme_get_default() +gtk_icon_theme.append_search_path(gajim.ICONS_DIR) + +def get_icon_pixmap(icon_name, size=16): + try: + return gtk_icon_theme.load_icon(icon_name, size, 0) + except gobject.GError, e: + log.error('Unable to load icon %s: %s' % (icon_name, str(e))) + +def get_icon_path(icon_name, size=16): + try: + icon_info = gtk_icon_theme.lookup_icon(icon_name, size, 0) + if icon_info == None: + log.error('Icon not found: %s' % icon_name) + return "" + else: + return icon_info.get_filename() + except gobject.GError, e: + log.error("Unable to find icon %s: %s" % (icon_name, str(e))) + GLADE_DIR = os.path.join(gajim.DATA_DIR, 'glade') def get_glade(file_name, root = None): file_path = os.path.join(GLADE_DIR, file_name) diff --git a/src/gui_menu_builder.py b/src/gui_menu_builder.py index 453677aa2..f18354175 100644 --- a/src/gui_menu_builder.py +++ b/src/gui_menu_builder.py @@ -200,7 +200,7 @@ def get_contact_menu(contact, account, use_multiple_contacts=True, items_to_hide = [] # add a special img for send file menuitem - path_to_upload_img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'upload.png') + path_to_upload_img = gtkgui_helpers.get_icon_path('gajim-upload') img = gtk.Image() img.set_from_file(path_to_upload_img) send_file_menuitem.set_image(img)