1 #include <config.h>
2 
3 #include <gtkmm/icontheme.h>
4 #include <giomm/error.h>
5 
6 #include "iconthemewrapper.h"
7 
8 
9 Glib::RefPtr<Gdk::Pixbuf>
load_icon(const Glib::ustring & icon_name,int size) const10 procman::IconThemeWrapper::load_icon(const Glib::ustring& icon_name, int size) const
11 {
12     gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
13     try
14     {
15       return Gtk::IconTheme::get_default()->load_icon(icon_name, size, scale, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE);
16     }
17     catch (Gtk::IconThemeError &error)
18     {
19         if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
20             g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str());
21         return Glib::RefPtr<Gdk::Pixbuf>();
22     }
23     catch (Gio::Error &error)
24     {
25         g_debug("Could not load icon '%s' : %s", icon_name.c_str(), error.what().c_str());
26         return Glib::RefPtr<Gdk::Pixbuf>();
27     }
28 }
29 
30 Glib::RefPtr<Gdk::Pixbuf>
load_gicon(const Glib::RefPtr<Gio::Icon> & gicon,int size,Gtk::IconLookupFlags flags) const31 procman::IconThemeWrapper::load_gicon(const Glib::RefPtr<Gio::Icon>& gicon,
32                                       int size, Gtk::IconLookupFlags flags) const
33 {
34     Gtk::IconInfo icon_info;
35     gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
36     icon_info = Gtk::IconTheme::get_default()->lookup_icon(gicon, size, scale, flags);
37 
38     if (!icon_info) {
39         return Glib::RefPtr<Gdk::Pixbuf>();
40     }
41 
42     try
43     {
44         return icon_info.load_icon();
45     }
46     catch (Gtk::IconThemeError &error)
47     {
48         if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
49             g_error("Cannot load gicon from theme: %s", error.what().c_str());
50         return Glib::RefPtr<Gdk::Pixbuf>();
51     }
52     catch (Gio::Error &error)
53     {
54         g_debug("Could not load gicon: %s", error.what().c_str());
55         return Glib::RefPtr<Gdk::Pixbuf>();
56     }
57 }
58