From 796ac63aa1eb75c8558faa6d21721b331297b4a6 Mon Sep 17 00:00:00 2001 From: Matej Habrnal Date: Wed, 24 Jun 2015 09:33:19 +0200 Subject: [PATCH] Fix loading applicaton icons Without this patch gnome-abrt raises an exception in the case the application icon should exists but doesn't. Related to rhbz#1234732 v2: jfilak@redhat.com - added a new function load_icon() Signed-off-by: Matej Habrnal Signed-off-by: Jakub Filak --- src/gnome_abrt/tools.py | 37 +++++++++++++++++++++++++++++++++++++ src/gnome_abrt/views.py | 26 +++++++++----------------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/gnome_abrt/tools.py b/src/gnome_abrt/tools.py index 7e440a3..a7361a0 100644 --- a/src/gnome_abrt/tools.py +++ b/src/gnome_abrt/tools.py @@ -17,6 +17,12 @@ import datetime import calendar +import logging + +#pylint: disable=E0611 +from gi.repository import GLib +#pylint: disable=E0611 +from gi.repository import Gtk from gnome_abrt.l10n import _ from gnome_abrt.l10n import ngettext @@ -61,3 +67,34 @@ def smart_truncate(content, length=100, suffix='...'): return content else: return content[:length].rsplit(' ', 1)[0] + suffix + + +def load_icon(name=None, gicon=None): + theme = Gtk.IconTheme.get_default() + + icon = None + if not gicon is None and name is None: + name = gicon.to_string() + icon = theme.lookup_by_gicon(gicon, 128, + Gtk.IconLookupFlags.FORCE_SIZE) + elif not name is None and gicon is None: + icon = theme.lookup_icon(name, 128, + Gtk.IconLookupFlags.FORCE_SIZE + | Gtk.IconLookupFlags.FORCE_SYMBOLIC) + else: + logging.error("BUG: invalid arguments in load_icon():" \ + "name={0}, gicon={1}".format(str(name), str(gicon))) + return None + + if icon is None: + logging.warning(_("Failed to find icon '{0}'").format(name)) + return None + + try: + return icon.load_icon() + #pylint: disable=E0712 + except GLib.Error as ex: + logging.warning(_("Failed to load icon '{0}': {1}") + .format(name, str(ex))) + + return None diff --git a/src/gnome_abrt/views.py b/src/gnome_abrt/views.py index 95c9639..a1e684b 100644 --- a/src/gnome_abrt/views.py +++ b/src/gnome_abrt/views.py @@ -40,7 +40,7 @@ import gnome_abrt.wrappers as wrappers import gnome_abrt.errors as errors import gnome_abrt.desktop as desktop from gnome_abrt import GNOME_ABRT_UI_DIR -from gnome_abrt.tools import fancydate, smart_truncate +from gnome_abrt.tools import fancydate, smart_truncate, load_icon from gnome_abrt.l10n import _, GETTEXT_PROGNAME @@ -833,23 +833,15 @@ class OopsWindow(Gtk.ApplicationWindow): self._builder.lbl_detected_value.set_tooltip_text( problem['date'].strftime(config.get_configuration()['D_T_FMT'])) + icon_buf = None if app.icon: - self._builder.img_app_icon.set_from_pixbuf( - Gtk.IconTheme - .get_default() - .lookup_by_gicon(app.icon, - 128, - Gtk.IconLookupFlags.FORCE_SIZE) - .load_icon()) - else: - self._builder.img_app_icon.set_from_pixbuf( - Gtk.IconTheme - .get_default() - .lookup_icon("system-run-symbolic", - 128, - Gtk.IconLookupFlags.FORCE_SIZE | - Gtk.IconLookupFlags.FORCE_SYMBOLIC) - .load_icon()) + icon_buf = load_icon(gicon=app.icon) + + if icon_buf is None: + icon_buf = load_icon(name="system-run-symbolic") + + # icon_buf can be None and if it is None, no icon will be displayed + self._builder.img_app_icon.set_from_pixbuf(icon_buf) self._builder.lbl_reported_value.show() self._builder.lbl_reported.set_text(_("Reported")) -- 2.4.5