~azzar1/unity/fix-crash-tests

« back to all changes in this revision

Viewing changes to dash/ResultRenderer.cpp

UnityCore: add GtkWrapper to handle GtkIconInfo correctly for different GTK versions

Fix a memory leak in LauncherIcon. Fixes: https://bugs.launchpad.net/bugs/1180790.

Approved by PS Jenkins bot, Sam Spilsbury, Ted Gould, Andrea Azzarone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <gtk/gtk.h>
26
26
#include <unity-protocol.h>
27
27
#include <NuxGraphics/GdkGraphics.h>
 
28
#include <UnityCore/GTKWrapper.h>
28
29
 
29
30
namespace unity
30
31
{
39
40
{
40
41
  GdkPixbuf *pbuf;
41
42
  GtkIconTheme *theme;
42
 
  GtkIconInfo *info;
43
 
  GError *error = NULL;
44
 
  GIcon *icon;
 
43
  gtk::IconInfo info;
 
44
  glib::Error error;
 
45
  glib::Object<GIcon> icon;
 
46
 
45
47
  if (icon_hint.empty())
46
48
    icon_hint = DEFAULT_GICON;
 
49
 
47
50
  if (g_str_has_prefix(icon_hint.c_str(), "/"))
48
51
  {
49
52
    pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
50
53
                                              size, size, TRUE, &error);
51
 
    if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
 
54
    if (error || !pbuf || !GDK_IS_PIXBUF (pbuf))
52
55
    {
53
56
      icon_hint = "application-default-icon";
54
 
      g_error_free (error);
55
 
      error = NULL;
56
57
    }
57
58
    else
58
59
      return pbuf;
60
61
  theme = gtk_icon_theme_get_default();
61
62
  icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
62
63
 
63
 
  if (G_IS_ICON(icon))
 
64
  if (icon.IsType(G_TYPE_ICON))
64
65
  {
65
 
     if (UNITY_PROTOCOL_IS_ANNOTATED_ICON(icon))
 
66
     if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))
66
67
     {
67
 
        UnityProtocolAnnotatedIcon *anno;
68
 
        anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon);
69
 
 
 
68
        auto anno = glib::object_cast<UnityProtocolAnnotatedIcon>(icon);
70
69
        GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno);
71
70
        info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, (GtkIconLookupFlags)0);
72
71
     }
74
73
     {
75
74
       info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
76
75
     }
77
 
     g_object_unref(icon);
78
76
  }
79
77
  else
80
78
  {
92
90
                                        (GtkIconLookupFlags) 0);
93
91
  }
94
92
 
95
 
  if (gtk_icon_info_get_filename(info) == NULL)
 
93
  if (!gtk_icon_info_get_filename(info))
96
94
  {
97
 
      g_object_unref(G_OBJECT(info));
98
95
      info = gtk_icon_theme_lookup_icon(theme,
99
96
                                        "application-default-icon",
100
97
                                        size,
103
100
 
104
101
  pbuf = gtk_icon_info_load_icon(info, &error);
105
102
 
106
 
  if (error != NULL)
 
103
  if (error)
107
104
  {
108
 
    g_error_free (error);
109
 
    pbuf = NULL;
 
105
    pbuf = nullptr;
110
106
  }
111
107
 
112
 
  g_object_unref(G_OBJECT(info));
113
108
  return pbuf;
114
109
}
115
110