Merge lp:~nick-dedekind/unity/lp863412.dash-result-dnd-icon into lp:unity

Proposed by Nick Dedekind
Status: Merged
Approved by: Francis Ginther
Approved revision: no longer in the source branch.
Merged at revision: 2967
Proposed branch: lp:~nick-dedekind/unity/lp863412.dash-result-dnd-icon
Merge into: lp:unity
Diff against target: 742 lines (+332/-124)
15 files modified
UnityCore/ModelRowAdaptor-inl.h (+3/-3)
UnityCore/ModelRowAdaptor.cpp (+14/-0)
UnityCore/ModelRowAdaptor.h (+11/-6)
UnityCore/Result.cpp (+15/-7)
UnityCore/Result.h (+9/-0)
dash/ResultRenderer.cpp (+95/-0)
dash/ResultRenderer.h (+3/-0)
dash/ResultRendererHorizontalTile.cpp (+21/-1)
dash/ResultRendererHorizontalTile.h (+2/-0)
dash/ResultRendererTile.cpp (+18/-5)
dash/ResultRendererTile.h (+4/-0)
dash/ResultViewGrid.cpp (+11/-101)
dash/ResultViewGrid.h (+1/-1)
tests/CMakeLists.txt (+1/-0)
tests/test_result_renderer.cpp (+124/-0)
To merge this branch: bzr merge lp:~nick-dedekind/unity/lp863412.dash-result-dnd-icon
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Brandon Schaefer (community) Approve
Review via email: mp+138527@code.launchpad.net

Commit message

Use the dash rendered icon as the source for the drag icon.

Description of the change

= Problem description =

Dash result drag icon is not the same as the icon rendered onto the dash.
https://bugs.launchpad.net/unity/+bug/863412

= The fix =

Use the dash rendered icon as the source for the drag icon.

= Test coverage =

Cannot directly test the drag icon.
Added unit test harness for result renderer. Includes tests for result renderer construction and dnd icon return.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Looks good, just couple things:

60 + virtual ~RowAdaptorBase();

Could we make this pure? Or just define it in the header, with a {}?

437 + , drag_index_(~0)
585 + drag_index_ = ~0;

Why not just -1? As the bit complement of 0 is a bit less readable. (Though I like it :)
Unless you change all the -1 usage to ~0, it should be consistent.

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> Looks good, just couple things:
>
> 60 + virtual ~RowAdaptorBase();
>
> Could we make this pure? Or just define it in the header, with a {}?
>

Pure virtual would require the derived classes to implement a destructor.
I don't see any benifit from inlining the destructor in a non-abstract class.

> 437 + , drag_index_(~0)
> 585 + drag_index_ = ~0;
>
> Why not just -1? As the bit complement of 0 is a bit less readable. (Though I
> like it :)
> Unless you change all the -1 usage to ~0, it should be consistent.

-1 is not an unsigned value.
I believe a comparison of "-1 == (unsigned)value" will cause an overflow error on 64bit systems.
There are a few instances of ~0 for unsigned values around the code
And they should all be changed, but I'm not going to go around and find them. :)

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

O I didn't notice it was an unsigned int...cool looks good then!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

Re-approving. Autolanding failed due to a API change with compiz that was not yet reflected in unity. The API change has been resolved.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/ModelRowAdaptor-inl.h'
--- UnityCore/ModelRowAdaptor-inl.h 2011-07-29 14:21:22 +0000
+++ UnityCore/ModelRowAdaptor-inl.h 2012-12-06 18:02:23 +0000
@@ -28,13 +28,13 @@
28template<typename T>28template<typename T>
29void RowAdaptorBase::set_renderer(T renderer)29void RowAdaptorBase::set_renderer(T renderer)
30{30{
31 dee_model_set_tag(model_, iter_, tag_, renderer);31 set_model_tag(renderer);
32}32}
3333
34template<typename T>34template<typename T>
35T RowAdaptorBase::renderer()35T RowAdaptorBase::renderer() const
36{36{
37 return static_cast<T>(dee_model_get_tag(model_, iter_, tag_));37 return static_cast<T>(get_model_tag());
38}38}
3939
40}40}
4141
=== modified file 'UnityCore/ModelRowAdaptor.cpp'
--- UnityCore/ModelRowAdaptor.cpp 2012-09-02 20:34:37 +0000
+++ UnityCore/ModelRowAdaptor.cpp 2012-12-06 18:02:23 +0000
@@ -36,6 +36,10 @@
36 tag_ = other.tag_;36 tag_ = other.tag_;
37}37}
3838
39RowAdaptorBase::~RowAdaptorBase()
40{
41}
42
39RowAdaptorBase& RowAdaptorBase::operator=(RowAdaptorBase const& other)43RowAdaptorBase& RowAdaptorBase::operator=(RowAdaptorBase const& other)
40{44{
41 model_ = other.model_;45 model_ = other.model_;
@@ -91,5 +95,15 @@
91 return static_cast<float>(dee_model_get_double(model_, iter_, position));95 return static_cast<float>(dee_model_get_double(model_, iter_, position));
92}96}
9397
98void RowAdaptorBase::set_model_tag(gpointer value)
99{
100 dee_model_set_tag(model_, iter_, tag_, value);
101}
102
103gpointer RowAdaptorBase::get_model_tag() const
104{
105 return dee_model_get_tag(model_, iter_, tag_);
106}
107
94}108}
95}109}
96110
=== modified file 'UnityCore/ModelRowAdaptor.h'
--- UnityCore/ModelRowAdaptor.h 2012-09-02 20:34:37 +0000
+++ UnityCore/ModelRowAdaptor.h 2012-12-06 18:02:23 +0000
@@ -50,13 +50,15 @@
50public:50public:
51 RowAdaptorBase(DeeModel* model=0, DeeModelIter* iter=0, DeeModelTag* tag=0);51 RowAdaptorBase(DeeModel* model=0, DeeModelIter* iter=0, DeeModelTag* tag=0);
52 RowAdaptorBase(RowAdaptorBase const& other);52 RowAdaptorBase(RowAdaptorBase const& other);
53 virtual ~RowAdaptorBase();
54
53 RowAdaptorBase& operator=(RowAdaptorBase const& other);55 RowAdaptorBase& operator=(RowAdaptorBase const& other);
5456
55 std::string GetStringAt(int position) const;57 virtual std::string GetStringAt(int position) const;
56 bool GetBoolAt(int position) const;58 virtual bool GetBoolAt(int position) const;
57 int GetIntAt(int position) const;59 virtual int GetIntAt(int position) const;
58 unsigned int GetUIntAt(int position) const;60 virtual unsigned int GetUIntAt(int position) const;
59 float GetFloatAt(int position) const;61 virtual float GetFloatAt(int position) const;
6062
61 void SetTarget(DeeModel* model, DeeModelIter* iter, DeeModelTag* tag);63 void SetTarget(DeeModel* model, DeeModelIter* iter, DeeModelTag* tag);
6264
@@ -64,9 +66,12 @@
64 void set_renderer(T renderer);66 void set_renderer(T renderer);
6567
66 template<typename T>68 template<typename T>
67 T renderer();69 T renderer() const;
6870
69protected:71protected:
72 virtual void set_model_tag(gpointer value);
73 virtual gpointer get_model_tag() const;
74
70 DeeModel* model_;75 DeeModel* model_;
71 DeeModelIter* iter_;76 DeeModelIter* iter_;
72 DeeModelTag* tag_;77 DeeModelTag* tag_;
7378
=== modified file 'UnityCore/Result.cpp'
--- UnityCore/Result.cpp 2011-09-13 22:35:13 +0000
+++ UnityCore/Result.cpp 2012-12-06 18:02:23 +0000
@@ -48,14 +48,22 @@
4848
49void Result::SetupGetters()49void Result::SetupGetters()
50{50{
51 uri.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 0));51 uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetURI));
52 icon_hint.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 1));52 icon_hint.SetGetterFunction(sigc::mem_fun(this, &Result::GetIconHint));
53 category_index.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetUIntAt), 2));53 category_index.SetGetterFunction(sigc::mem_fun(this, &Result::GetCategoryIndex));
54 mimetype.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 3));54 mimetype.SetGetterFunction(sigc::mem_fun(this, &Result::GetMimeType));
55 name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 4));55 name.SetGetterFunction(sigc::mem_fun(this, &Result::GetName));
56 comment.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 5));56 comment.SetGetterFunction(sigc::mem_fun(this, &Result::GetComment));
57 dnd_uri.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 6));57 dnd_uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetDndURI));
58}58}
59
60std::string Result::GetURI() const { return GetStringAt(0); }
61std::string Result::GetIconHint() const { return GetStringAt(1); }
62std::size_t Result::GetCategoryIndex() const { return GetUIntAt(2); }
63std::string Result::GetMimeType() const { return GetStringAt(3); }
64std::string Result::GetName() const { return GetStringAt(4); }
65std::string Result::GetComment() const { return GetStringAt(5); }
66std::string Result::GetDndURI() const { return GetStringAt(6); }
5967
60}68}
61}69}
6270
=== modified file 'UnityCore/Result.h'
--- UnityCore/Result.h 2011-09-13 22:35:13 +0000
+++ UnityCore/Result.h 2012-12-06 18:02:23 +0000
@@ -51,6 +51,15 @@
51 nux::ROProperty<std::string> comment;51 nux::ROProperty<std::string> comment;
52 nux::ROProperty<std::string> dnd_uri;52 nux::ROProperty<std::string> dnd_uri;
5353
54protected:
55 virtual std::string GetURI() const;
56 virtual std::string GetIconHint() const;
57 virtual std::size_t GetCategoryIndex() const;
58 virtual std::string GetMimeType() const;
59 virtual std::string GetName() const;
60 virtual std::string GetComment() const;
61 virtual std::string GetDndURI() const;
62
54private:63private:
55 void SetupGetters();64 void SetupGetters();
56};65};
5766
=== modified file 'dash/ResultRenderer.cpp'
--- dash/ResultRenderer.cpp 2012-10-22 12:04:55 +0000
+++ dash/ResultRenderer.cpp 2012-12-06 18:02:23 +0000
@@ -22,10 +22,99 @@
2222
23#include "ResultRenderer.h"23#include "ResultRenderer.h"
2424
25#include <gtk/gtk.h>
26#include <unity-protocol.h>
27#include <NuxGraphics/GdkGraphics.h>
28
25namespace unity29namespace unity
26{30{
27namespace dash31namespace dash
28{32{
33
34namespace
35{
36#define DEFAULT_GICON ". GThemedIcon text-x-preview"
37
38GdkPixbuf* _icon_hint_get_drag_pixbuf(std::string icon_hint, int size)
39{
40 GdkPixbuf *pbuf;
41 GtkIconTheme *theme;
42 GtkIconInfo *info;
43 GError *error = NULL;
44 GIcon *icon;
45 if (icon_hint.empty())
46 icon_hint = DEFAULT_GICON;
47 if (g_str_has_prefix(icon_hint.c_str(), "/"))
48 {
49 pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
50 size, size, TRUE, &error);
51 if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
52 {
53 icon_hint = "application-default-icon";
54 g_error_free (error);
55 error = NULL;
56 }
57 else
58 return pbuf;
59 }
60 theme = gtk_icon_theme_get_default();
61 icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
62
63 if (G_IS_ICON(icon))
64 {
65 if (UNITY_PROTOCOL_IS_ANNOTATED_ICON(icon))
66 {
67 UnityProtocolAnnotatedIcon *anno;
68 anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon);
69
70 GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno);
71 info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, (GtkIconLookupFlags)0);
72 }
73 else
74 {
75 info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
76 }
77 g_object_unref(icon);
78 }
79 else
80 {
81 info = gtk_icon_theme_lookup_icon(theme,
82 icon_hint.c_str(),
83 size,
84 (GtkIconLookupFlags) 0);
85 }
86
87 if (!info)
88 {
89 info = gtk_icon_theme_lookup_icon(theme,
90 "application-default-icon",
91 size,
92 (GtkIconLookupFlags) 0);
93 }
94
95 if (gtk_icon_info_get_filename(info) == NULL)
96 {
97 gtk_icon_info_free(info);
98 info = gtk_icon_theme_lookup_icon(theme,
99 "application-default-icon",
100 size,
101 (GtkIconLookupFlags) 0);
102 }
103
104 pbuf = gtk_icon_info_load_icon(info, &error);
105
106 if (error != NULL)
107 {
108 g_error_free (error);
109 pbuf = NULL;
110 }
111
112 gtk_icon_info_free(info);
113 return pbuf;
114}
115
116}
117
29NUX_IMPLEMENT_OBJECT_TYPE(ResultRenderer);118NUX_IMPLEMENT_OBJECT_TYPE(ResultRenderer);
30119
31ResultRenderer::ResultRenderer(NUX_FILE_LINE_DECL)120ResultRenderer::ResultRenderer(NUX_FILE_LINE_DECL)
@@ -52,6 +141,12 @@
52 // unload any resources141 // unload any resources
53}142}
54143
144nux::NBitmapData* ResultRenderer::GetDndImage(Result const& row) const
145{
146 nux::GdkGraphics graphics(_icon_hint_get_drag_pixbuf(row.icon_hint, 64));
147 return graphics.GetBitmap();
148}
149
55}150}
56}151}
57152
58153
=== modified file 'dash/ResultRenderer.h'
--- dash/ResultRenderer.h 2012-10-22 12:04:55 +0000
+++ dash/ResultRenderer.h 2012-12-06 18:02:23 +0000
@@ -62,6 +62,9 @@
62 // unload any previous grabbed images62 // unload any previous grabbed images
63 virtual void Unload(Result& row);63 virtual void Unload(Result& row);
6464
65 // get a image to drag
66 virtual nux::NBitmapData* GetDndImage(Result const& row) const;
67
65 nux::Property<int> width;68 nux::Property<int> width;
66 nux::Property<int> height;69 nux::Property<int> height;
6770
6871
=== modified file 'dash/ResultRendererHorizontalTile.cpp'
--- dash/ResultRendererHorizontalTile.cpp 2012-10-22 12:04:55 +0000
+++ dash/ResultRendererHorizontalTile.cpp 2012-12-06 18:02:23 +0000
@@ -29,6 +29,7 @@
2929
30#include "unity-shared/CairoTexture.h"30#include "unity-shared/CairoTexture.h"
31#include "unity-shared/TextureCache.h"31#include "unity-shared/TextureCache.h"
32#include <NuxGraphics/GdkGraphics.h>
3233
3334
34namespace unity35namespace unity
@@ -42,7 +43,7 @@
42const int CARD_VIEW_HEIGHT = 74; // pixels43const int CARD_VIEW_HEIGHT = 74; // pixels
43const int CARD_VIEW_HIGHLIGHT_CORNER_RADIUS = 2; // pixels44const int CARD_VIEW_HIGHLIGHT_CORNER_RADIUS = 2; // pixels
44const int CARD_VIEW_ICON_OUTLINE_WIDTH = 1; // pixels45const int CARD_VIEW_ICON_OUTLINE_WIDTH = 1; // pixels
45const int CARD_VIEW_TEXT_LINE_SPACING = 0; // points46const int CARD_VIEW_TEXT_LINE_SPACING = 0; // points
46}47}
4748
48namespace dash49namespace dash
@@ -297,6 +298,25 @@
297 container->text = texture_ptr_from_cairo_graphics(_cairoGraphics);298 container->text = texture_ptr_from_cairo_graphics(_cairoGraphics);
298}299}
299300
301nux::NBitmapData* ResultRendererHorizontalTile::GetDndImage(Result const& row) const
302{
303 TextureContainer* container = row.renderer<TextureContainer*>();
304 nux::NBitmapData* bitmap = nullptr;
305
306 if (container && container->drag_icon && container->drag_icon.IsType(GDK_TYPE_PIXBUF))
307 {
308 int width = gdk_pixbuf_get_width(container->drag_icon);
309 int height = gdk_pixbuf_get_height(container->drag_icon);
310
311 if (width != CARD_VIEW_ICON_SIZE || height != CARD_VIEW_ICON_SIZE)
312 {
313 nux::GdkGraphics graphics(gdk_pixbuf_scale_simple(container->drag_icon, CARD_VIEW_ICON_SIZE, CARD_VIEW_ICON_SIZE, GDK_INTERP_BILINEAR));
314 bitmap = graphics.GetBitmap();
315 }
316 }
317 return bitmap ? bitmap : ResultRendererTile::GetDndImage(row);
318}
319
300320
301}321}
302}322}
303323
=== modified file 'dash/ResultRendererHorizontalTile.h'
--- dash/ResultRendererHorizontalTile.h 2012-10-22 12:04:55 +0000
+++ dash/ResultRendererHorizontalTile.h 2012-12-06 18:02:23 +0000
@@ -46,6 +46,8 @@
46 nux::Geometry const& geometry,46 nux::Geometry const& geometry,
47 int x_offset, int y_offset);47 int x_offset, int y_offset);
4848
49 virtual nux::NBitmapData* GetDndImage(Result const& row) const;
50
49protected:51protected:
50 virtual void LoadText(Result& row);52 virtual void LoadText(Result& row);
5153
5254
=== modified file 'dash/ResultRendererTile.cpp'
--- dash/ResultRendererTile.cpp 2012-10-30 18:18:35 +0000
+++ dash/ResultRendererTile.cpp 2012-12-06 18:02:23 +0000
@@ -23,10 +23,10 @@
23#include "ResultRendererTile.h"23#include "ResultRendererTile.h"
2424
25#include <pango/pangocairo.h>25#include <pango/pangocairo.h>
26#include <gtk/gtk.h>
2726
28#include <NuxCore/Logger.h>27#include <NuxCore/Logger.h>
29#include <UnityCore/GLibWrapper.h>28#include <UnityCore/GLibWrapper.h>
29#include <NuxGraphics/GdkGraphics.h>
3030
31#include "unity-shared/CairoTexture.h"31#include "unity-shared/CairoTexture.h"
32#include "unity-shared/DashStyle.h"32#include "unity-shared/DashStyle.h"
@@ -34,7 +34,8 @@
3434
35namespace35namespace
36{36{
37 bool neko;37bool neko;
38#define DEFAULT_GICON ". GThemedIcon text-x-preview"
38}39}
3940
40namespace unity41namespace unity
@@ -180,11 +181,24 @@
180 row.set_renderer<TextureContainer*>(nullptr);181 row.set_renderer<TextureContainer*>(nullptr);
181}182}
182183
184nux::NBitmapData* ResultRendererTile::GetDndImage(Result const& row) const
185{
186 TextureContainer* container = row.renderer<TextureContainer*>();
187 nux::NBitmapData* bitmap = nullptr;
188
189 if (container && container->drag_icon && container->drag_icon.IsType(GDK_TYPE_PIXBUF))
190 {
191 // Need to ref the drag icon because GdkGraphics will unref it.
192 nux::GdkGraphics graphics(GDK_PIXBUF(g_object_ref(container->drag_icon)));
193 bitmap = graphics.GetBitmap();
194 }
195 return bitmap ? bitmap : ResultRenderer::GetDndImage(row);
196}
197
183void ResultRendererTile::LoadIcon(Result& row)198void ResultRendererTile::LoadIcon(Result& row)
184{199{
185 Style& style = Style::Instance();200 Style& style = Style::Instance();
186 std::string icon_hint(row.icon_hint);201 std::string icon_hint(row.icon_hint);
187#define DEFAULT_GICON ". GThemedIcon text-x-preview"
188 std::string icon_name;202 std::string icon_name;
189 if (G_UNLIKELY(neko))203 if (G_UNLIKELY(neko))
190 {204 {
@@ -289,10 +303,8 @@
289303
290 return texture_from_cairo_graphics(cairo_graphics);304 return texture_from_cairo_graphics(cairo_graphics);
291 }305 }
292
293}306}
294307
295
296void ResultRendererTile::IconLoaded(std::string const& texid,308void ResultRendererTile::IconLoaded(std::string const& texid,
297 int max_width,309 int max_width,
298 int max_height,310 int max_height,
@@ -314,6 +326,7 @@
314326
315 container->icon = texture;327 container->icon = texture;
316 container->prelight = texture_prelight;328 container->prelight = texture_prelight;
329 container->drag_icon = pixbuf;
317330
318 NeedsRedraw.emit();331 NeedsRedraw.emit();
319332
320333
=== modified file 'dash/ResultRendererTile.h'
--- dash/ResultRendererTile.h 2012-10-24 15:01:10 +0000
+++ dash/ResultRendererTile.h 2012-12-06 18:02:23 +0000
@@ -38,6 +38,8 @@
38 BaseTexturePtr text;38 BaseTexturePtr text;
39 BaseTexturePtr icon;39 BaseTexturePtr icon;
40 BaseTexturePtr prelight;40 BaseTexturePtr prelight;
41 glib::Object<GdkPixbuf> drag_icon;
42
41 int slot_handle;43 int slot_handle;
4244
43 TextureContainer()45 TextureContainer()
@@ -67,6 +69,8 @@
6769
68 virtual void Preload(Result& row);70 virtual void Preload(Result& row);
69 virtual void Unload(Result& row);71 virtual void Unload(Result& row);
72
73 virtual nux::NBitmapData* GetDndImage(Result const& row) const;
7074
71 int spacing;75 int spacing;
72 int padding;76 int padding;
7377
=== modified file 'dash/ResultViewGrid.cpp'
--- dash/ResultViewGrid.cpp 2012-12-04 17:23:39 +0000
+++ dash/ResultViewGrid.cpp 2012-12-06 18:02:23 +0000
@@ -56,6 +56,7 @@
56 , last_lazy_loaded_result_(0)56 , last_lazy_loaded_result_(0)
57 , last_mouse_down_x_(-1)57 , last_mouse_down_x_(-1)
58 , last_mouse_down_y_(-1)58 , last_mouse_down_y_(-1)
59 , drag_index_(~0)
59 , recorded_dash_width_(-1)60 , recorded_dash_width_(-1)
60 , recorded_dash_height_(-1)61 , recorded_dash_height_(-1)
61 , mouse_last_x_(-1)62 , mouse_last_x_(-1)
@@ -778,27 +779,23 @@
778bool ResultViewGrid::DndSourceDragBegin()779bool ResultViewGrid::DndSourceDragBegin()
779{780{
780#ifdef USE_X11781#ifdef USE_X11
781 unsigned num_results = GetNumResults();782 drag_index_ = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_);
782 unsigned drag_index = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_);
783783
784 if (drag_index >= num_results)784 if (drag_index_ >= GetNumResults())
785 return false;785 return false;
786786
787 Reference();787 Reference();
788788
789 ResultIterator iter(GetIteratorAtRow(drag_index));789 ResultIterator iter(GetIteratorAtRow(drag_index_));
790 Result drag_result = *iter;790 Result drag_result = *iter;
791791
792 current_drag_uri_ = drag_result.dnd_uri;792 current_drag_uri_ = drag_result.dnd_uri;
793 if (current_drag_uri_ == "")793 if (current_drag_uri_ == "")
794 current_drag_uri_ = drag_result.uri().substr(drag_result.uri().find(":") + 1);794 current_drag_uri_ = drag_result.uri().substr(drag_result.uri().find(":") + 1);
795795
796 current_drag_icon_name_ = drag_result.icon_hint;
797
798 LOG_DEBUG (logger) << "Dnd begin at " <<796 LOG_DEBUG (logger) << "Dnd begin at " <<
799 last_mouse_down_x_ << ", " << last_mouse_down_y_ << " - using; "797 last_mouse_down_x_ << ", " << last_mouse_down_y_ << " - using; "
800 << current_drag_uri_ << " - "798 << current_drag_uri_;
801 << current_drag_icon_name_;
802799
803 return true;800 return true;
804#else801#else
@@ -806,101 +803,14 @@
806#endif803#endif
807}804}
808805
809GdkPixbuf* _icon_hint_get_drag_pixbuf(std::string icon_hint)
810{
811 GdkPixbuf *pbuf;
812 GtkIconTheme *theme;
813 GtkIconInfo *info;
814 GError *error = NULL;
815 GIcon *icon;
816 int size = 64;
817 if (icon_hint.empty())
818 icon_hint = "application-default-icon";
819 if (g_str_has_prefix(icon_hint.c_str(), "/"))
820 {
821 pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
822 size, size, FALSE, &error);
823 if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
824 {
825 icon_hint = "application-default-icon";
826 g_error_free (error);
827 error = NULL;
828 }
829 else
830 return pbuf;
831 }
832 theme = gtk_icon_theme_get_default();
833 icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
834
835 if (G_IS_ICON(icon))
836 {
837 if (UNITY_PROTOCOL_IS_ANNOTATED_ICON(icon))
838 {
839 UnityProtocolAnnotatedIcon *anno;
840 anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon);
841
842 GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno);
843 info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, (GtkIconLookupFlags)0);
844 }
845 else
846 {
847 info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
848 }
849 g_object_unref(icon);
850 }
851 else
852 {
853 info = gtk_icon_theme_lookup_icon(theme,
854 icon_hint.c_str(),
855 size,
856 (GtkIconLookupFlags) 0);
857 }
858
859 if (!info)
860 {
861 info = gtk_icon_theme_lookup_icon(theme,
862 "application-default-icon",
863 size,
864 (GtkIconLookupFlags) 0);
865 }
866
867 if (gtk_icon_info_get_filename(info) == NULL)
868 {
869 gtk_icon_info_free(info);
870 info = gtk_icon_theme_lookup_icon(theme,
871 "application-default-icon",
872 size,
873 (GtkIconLookupFlags) 0);
874 }
875
876 pbuf = gtk_icon_info_load_icon(info, &error);
877
878 if (error != NULL)
879 {
880 LOG_WARN (logger) << "could not find a pixbuf for " << icon_hint;
881 g_error_free (error);
882 pbuf = NULL;
883 }
884
885 gtk_icon_info_free(info);
886 return pbuf;
887}
888
889nux::NBitmapData*806nux::NBitmapData*
890ResultViewGrid::DndSourceGetDragImage()807ResultViewGrid::DndSourceGetDragImage()
891{808{
892 nux::NBitmapData* result = 0;809 if (drag_index_ >= GetNumResults())
893 GdkPixbuf* pbuf;810 return nullptr;
894 pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_);811
895812 Result result(*GetIteratorAtRow(drag_index_));
896 if (pbuf && GDK_IS_PIXBUF(pbuf))813 return renderer_->GetDndImage(result);
897 {
898 // we don't free the pbuf as GdkGraphics will do it for us will do it for us
899 nux::GdkGraphics graphics(pbuf);
900 result = graphics.GetBitmap();
901 }
902
903 return result;
904}814}
905815
906std::list<const char*>816std::list<const char*>
@@ -934,7 +844,7 @@
934 last_mouse_down_x_ = -1;844 last_mouse_down_x_ = -1;
935 last_mouse_down_y_ = -1;845 last_mouse_down_y_ = -1;
936 current_drag_uri_.clear();846 current_drag_uri_.clear();
937 current_drag_icon_name_.clear();847 drag_index_ = ~0;
938848
939 // We need this because the drag can start in a ResultViewGrid and can849 // We need this because the drag can start in a ResultViewGrid and can
940 // end in another ResultViewGrid850 // end in another ResultViewGrid
941851
=== modified file 'dash/ResultViewGrid.h'
--- dash/ResultViewGrid.h 2012-11-19 18:54:19 +0000
+++ dash/ResultViewGrid.h 2012-12-06 18:02:23 +0000
@@ -106,7 +106,7 @@
106 int last_mouse_down_x_;106 int last_mouse_down_x_;
107 int last_mouse_down_y_;107 int last_mouse_down_y_;
108 std::string current_drag_uri_;108 std::string current_drag_uri_;
109 std::string current_drag_icon_name_;109 unsigned drag_index_;
110110
111 int recorded_dash_width_;111 int recorded_dash_width_;
112 int recorded_dash_height_;112 int recorded_dash_height_;
113113
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-12-05 09:10:04 +0000
+++ tests/CMakeLists.txt 2012-12-06 18:02:23 +0000
@@ -230,6 +230,7 @@
230 test_overlay_scrollbar.cpp230 test_overlay_scrollbar.cpp
231 test_quicklist_menu_item.cpp231 test_quicklist_menu_item.cpp
232 test_quicklist_view.cpp232 test_quicklist_view.cpp
233 test_result_renderer.cpp
233 test_resultviewgrid.cpp234 test_resultviewgrid.cpp
234 test_shortcut_controller.cpp235 test_shortcut_controller.cpp
235 test_single_monitor_launcher_icon.cpp236 test_single_monitor_launcher_icon.cpp
236237
=== added file 'tests/test_result_renderer.cpp'
--- tests/test_result_renderer.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_result_renderer.cpp 2012-12-06 18:02:23 +0000
@@ -0,0 +1,124 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
20 *
21 */
22#include <gmock/gmock.h>
23#include <glib-object.h>
24
25#include "unity-shared/DashStyle.h"
26#include "unity-shared/UnitySettings.h"
27#include "UnityCore/Result.h"
28#include "dash/ResultRendererTile.h"
29
30#include "test_utils.h"
31
32using namespace std;
33using namespace unity;
34using namespace testing;
35
36namespace unity
37{
38
39namespace
40{
41
42#define DEFAULT_GICON ". GThemedIcon text-x-preview"
43
44GdkPixbuf* GetIconData(std::string icon_hint, int size)
45{
46 GdkPixbuf *pbuf;
47 GtkIconTheme *theme;
48 GError *error = NULL;
49
50 theme = gtk_icon_theme_get_default();
51 glib::Object<GIcon> icon(g_icon_new_for_string(icon_hint.c_str(), NULL));
52
53 if (icon.IsType(G_TYPE_ICON))
54 {
55 GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
56 pbuf = gtk_icon_info_load_icon(info, &error);
57 if (error != NULL)
58 {
59 g_error_free (error);
60 pbuf = NULL;
61 }
62 gtk_icon_info_free(info);
63 }
64
65 return pbuf;
66}
67
68} // namespace [anonymous]
69
70class TestResultRenderer : public testing::Test
71{
72public:
73 TestResultRenderer() {}
74
75 unity::Settings settings;
76 dash::Style style;
77};
78
79class MockResult : public dash::Result
80{
81public:
82 MockResult()
83 : Result(NULL, NULL, NULL)
84 , renderer_(new dash::TextureContainer())
85 {
86 ON_CALL (*this, GetURI ()).WillByDefault (Return ("file:///result_render_test"));
87 ON_CALL (*this, GetIconHint()).WillByDefault (Return (DEFAULT_GICON));
88 ON_CALL (*this, GetCategoryIndex ()).WillByDefault (Return (0));
89 ON_CALL (*this, GetName ()).WillByDefault (Return ("Result Render Test"));
90 ON_CALL (*this, GetDndURI ()).WillByDefault (Return ("file:///result_render_test_dnd"));
91 }
92
93 MOCK_CONST_METHOD0(GetURI, std::string());
94 MOCK_CONST_METHOD0(GetIconHint, std::string());
95 MOCK_CONST_METHOD0(GetCategoryIndex, std::size_t());
96 MOCK_CONST_METHOD0(GetMimeType, std::string());
97 MOCK_CONST_METHOD0(GetName, std::string());
98 MOCK_CONST_METHOD0(GetComment, std::string());
99 MOCK_CONST_METHOD0(GetDndURI, std::string());
100
101 virtual gpointer get_model_tag() const
102 {
103 return renderer_.get();
104 }
105
106private:
107 std::auto_ptr<dash::TextureContainer> renderer_;
108};
109
110TEST_F(TestResultRenderer, TestConstruction)
111{
112 dash::ResultRendererTile renderer;
113}
114
115TEST_F(TestResultRenderer, TestDndIcon)
116{
117 dash::ResultRendererTile renderer;
118 NiceMock<MockResult> result;
119
120 nux::NBitmapData* bitmap = renderer.GetDndImage(result);
121 ASSERT_NE(bitmap, nullptr);
122}
123
124}