Merge lp:~robertcarr/unity/result-dragimages into lp:unity

Proposed by Robert Carr
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1528
Proposed branch: lp:~robertcarr/unity/result-dragimages
Merge into: lp:unity
Diff against target: 135 lines (+65/-39)
1 file modified
plugins/unityshell/src/ResultViewGrid.cpp (+65/-39)
To merge this branch: bzr merge lp:~robertcarr/unity/result-dragimages
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+74670@code.launchpad.net

Description of the change

Make use of the icon_hint from lenses when making a drag image. Currently we assume it is also a name, but it could be a path to a thumbnail. This ensures the drag image will be the same as the image displayed in the dash.

In a lot of cases this will fail without:
https://code.launchpad.net/~robertcarr/nux/dnd-imageformat/+merge/74667

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/ResultViewGrid.cpp'
2--- plugins/unityshell/src/ResultViewGrid.cpp 2011-09-08 11:08:57 +0000
3+++ plugins/unityshell/src/ResultViewGrid.cpp 2011-09-08 19:17:25 +0000
4@@ -690,66 +690,92 @@
5 return true;
6 }
7
8-nux::NBitmapData*
9-ResultViewGrid::DndSourceGetDragImage()
10+GdkPixbuf *
11+_icon_hint_get_drag_pixbuf (std::string icon_hint)
12 {
13- nux::NBitmapData* result = 0;
14- GdkPixbuf* pbuf;
15- GtkIconTheme* theme;
16- GtkIconInfo* info;
17- GError* error = NULL;
18- GIcon* icon;
19-
20- std::string icon_name = current_drag_icon_name_.c_str();
21+ GdkPixbuf *pbuf;
22+ GtkIconTheme *theme;
23+ GtkIconInfo *info;
24+ GError *error = NULL;
25+ GIcon *icon;
26 int size = 64;
27-
28- if (icon_name.empty())
29- icon_name = "application-default-icon";
30-
31+
32+ if (icon_hint.empty())
33+ icon_hint = "application-default-icon";
34+
35+ if (g_str_has_prefix(icon_hint.c_str(), "/"))
36+ {
37+
38+ pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
39+ size, -1, TRUE, &error);
40+
41+ if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
42+ {
43+ icon_hint = "application-default-icon";
44+ g_error_free (error);
45+ error = NULL;
46+ }
47+ else
48+ return pbuf;
49+ }
50 theme = gtk_icon_theme_get_default();
51- icon = g_icon_new_for_string(icon_name.c_str(), NULL);
52-
53+ icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
54+
55 if (G_IS_ICON(icon))
56 {
57- info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
58- g_object_unref(icon);
59+ info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
60+ g_object_unref(icon);
61 }
62 else
63 {
64- info = gtk_icon_theme_lookup_icon(theme,
65- icon_name.c_str(),
66- size,
67- (GtkIconLookupFlags) 0);
68+ info = gtk_icon_theme_lookup_icon(theme,
69+ icon_hint.c_str(),
70+ size,
71+ (GtkIconLookupFlags) 0);
72 }
73-
74+
75 if (!info)
76 {
77- info = gtk_icon_theme_lookup_icon(theme,
78- "application-default-icon",
79- size,
80- (GtkIconLookupFlags) 0);
81+ info = gtk_icon_theme_lookup_icon(theme,
82+ "application-default-icon",
83+ size,
84+ (GtkIconLookupFlags) 0);
85 }
86-
87+
88 if (gtk_icon_info_get_filename(info) == NULL)
89 {
90- gtk_icon_info_free(info);
91- info = gtk_icon_theme_lookup_icon(theme,
92- "application-default-icon",
93- size,
94- (GtkIconLookupFlags) 0);
95+ gtk_icon_info_free(info);
96+ info = gtk_icon_theme_lookup_icon(theme,
97+ "application-default-icon",
98+ size,
99+ (GtkIconLookupFlags) 0);
100 }
101-
102+
103 pbuf = gtk_icon_info_load_icon(info, &error);
104+
105+
106 if (error != NULL)
107 {
108- LOG_WARN (logger) << "could not find a pixbuf for " << icon_name;
109+ LOG_WARN (logger) << "could not find a pixbuf for " << icon_hint;
110 g_error_free (error);
111- result = NULL;
112+ pbuf = NULL;
113 }
114-
115+
116 gtk_icon_info_free(info);
117-
118- if (GDK_IS_PIXBUF(pbuf))
119+
120+ return pbuf;
121+
122+}
123+
124+nux::NBitmapData*
125+ResultViewGrid::DndSourceGetDragImage()
126+{
127+ nux::NBitmapData* result = 0;
128+ GdkPixbuf* pbuf;
129+
130+ pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_);
131+
132+ if (pbuf && GDK_IS_PIXBUF(pbuf))
133 {
134 // we don't free the pbuf as GdkGraphics will do it for us will do it for us
135 nux::GdkGraphics graphics(pbuf);