Skip to content

Commit

Permalink
Fix loading applicaton icons
Browse files Browse the repository at this point in the history
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 <mhabrnal@redhat.com>
Signed-off-by: Jakub Filak <jfilak@redhat.com>
  • Loading branch information
Matej Habrnal authored and Jakub Filak committed Jun 29, 2015
1 parent b95e9b2 commit 796ac63
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
37 changes: 37 additions & 0 deletions src/gnome_abrt/tools.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
26 changes: 9 additions & 17 deletions src/gnome_abrt/views.py
Expand Up @@ -40,7 +40,7 @@
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


Expand Down Expand Up @@ -833,23 +833,15 @@ def destroy_links(widget, _):
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"))
Expand Down

0 comments on commit 796ac63

Please sign in to comment.