diff options
| -rw-r--r-- | UnityCore/ModelRowAdaptor-inl.h | 6 | ||||
| -rw-r--r-- | UnityCore/ModelRowAdaptor.cpp | 14 | ||||
| -rw-r--r-- | UnityCore/ModelRowAdaptor.h | 17 | ||||
| -rw-r--r-- | UnityCore/Result.cpp | 22 | ||||
| -rw-r--r-- | UnityCore/Result.h | 9 | ||||
| -rw-r--r-- | dash/ResultRenderer.cpp | 95 | ||||
| -rw-r--r-- | dash/ResultRenderer.h | 3 | ||||
| -rw-r--r-- | dash/ResultRendererHorizontalTile.cpp | 22 | ||||
| -rw-r--r-- | dash/ResultRendererHorizontalTile.h | 2 | ||||
| -rw-r--r-- | dash/ResultRendererTile.cpp | 23 | ||||
| -rw-r--r-- | dash/ResultRendererTile.h | 4 | ||||
| -rw-r--r-- | dash/ResultViewGrid.cpp | 110 | ||||
| -rw-r--r-- | dash/ResultViewGrid.h | 2 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/test_result_renderer.cpp | 124 |
15 files changed, 331 insertions, 123 deletions
diff --git a/UnityCore/ModelRowAdaptor-inl.h b/UnityCore/ModelRowAdaptor-inl.h index 96e24e675..58623584b 100644 --- a/UnityCore/ModelRowAdaptor-inl.h +++ b/UnityCore/ModelRowAdaptor-inl.h @@ -28,13 +28,13 @@ namespace dash template<typename T> void RowAdaptorBase::set_renderer(T renderer) { - dee_model_set_tag(model_, iter_, tag_, renderer); + set_model_tag(renderer); } template<typename T> -T RowAdaptorBase::renderer() +T RowAdaptorBase::renderer() const { - return static_cast<T>(dee_model_get_tag(model_, iter_, tag_)); + return static_cast<T>(get_model_tag()); } } diff --git a/UnityCore/ModelRowAdaptor.cpp b/UnityCore/ModelRowAdaptor.cpp index 5f701400d..d1c7d4ba7 100644 --- a/UnityCore/ModelRowAdaptor.cpp +++ b/UnityCore/ModelRowAdaptor.cpp @@ -36,6 +36,10 @@ RowAdaptorBase::RowAdaptorBase(RowAdaptorBase const& other) tag_ = other.tag_; } +RowAdaptorBase::~RowAdaptorBase() +{ +} + RowAdaptorBase& RowAdaptorBase::operator=(RowAdaptorBase const& other) { model_ = other.model_; @@ -91,5 +95,15 @@ float RowAdaptorBase::GetFloatAt(int position) const return static_cast<float>(dee_model_get_double(model_, iter_, position)); } +void RowAdaptorBase::set_model_tag(gpointer value) +{ + dee_model_set_tag(model_, iter_, tag_, value); +} + +gpointer RowAdaptorBase::get_model_tag() const +{ + return dee_model_get_tag(model_, iter_, tag_); +} + } } diff --git a/UnityCore/ModelRowAdaptor.h b/UnityCore/ModelRowAdaptor.h index b4fc929b4..8d38e841c 100644 --- a/UnityCore/ModelRowAdaptor.h +++ b/UnityCore/ModelRowAdaptor.h @@ -50,13 +50,15 @@ class RowAdaptorBase public: RowAdaptorBase(DeeModel* model=0, DeeModelIter* iter=0, DeeModelTag* tag=0); RowAdaptorBase(RowAdaptorBase const& other); + virtual ~RowAdaptorBase(); + RowAdaptorBase& operator=(RowAdaptorBase const& other); - std::string GetStringAt(int position) const; - bool GetBoolAt(int position) const; - int GetIntAt(int position) const; - unsigned int GetUIntAt(int position) const; - float GetFloatAt(int position) const; + virtual std::string GetStringAt(int position) const; + virtual bool GetBoolAt(int position) const; + virtual int GetIntAt(int position) const; + virtual unsigned int GetUIntAt(int position) const; + virtual float GetFloatAt(int position) const; void SetTarget(DeeModel* model, DeeModelIter* iter, DeeModelTag* tag); @@ -64,9 +66,12 @@ public: void set_renderer(T renderer); template<typename T> - T renderer(); + T renderer() const; protected: + virtual void set_model_tag(gpointer value); + virtual gpointer get_model_tag() const; + DeeModel* model_; DeeModelIter* iter_; DeeModelTag* tag_; diff --git a/UnityCore/Result.cpp b/UnityCore/Result.cpp index 78723c5e1..e334761d3 100644 --- a/UnityCore/Result.cpp +++ b/UnityCore/Result.cpp @@ -48,14 +48,22 @@ Result& Result::operator=(Result const& other) void Result::SetupGetters() { - uri.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 0)); - icon_hint.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 1)); - category_index.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetUIntAt), 2)); - mimetype.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 3)); - name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 4)); - comment.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 5)); - dnd_uri.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 6)); + uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetURI)); + icon_hint.SetGetterFunction(sigc::mem_fun(this, &Result::GetIconHint)); + category_index.SetGetterFunction(sigc::mem_fun(this, &Result::GetCategoryIndex)); + mimetype.SetGetterFunction(sigc::mem_fun(this, &Result::GetMimeType)); + name.SetGetterFunction(sigc::mem_fun(this, &Result::GetName)); + comment.SetGetterFunction(sigc::mem_fun(this, &Result::GetComment)); + dnd_uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetDndURI)); } +std::string Result::GetURI() const { return GetStringAt(0); } +std::string Result::GetIconHint() const { return GetStringAt(1); } +std::size_t Result::GetCategoryIndex() const { return GetUIntAt(2); } +std::string Result::GetMimeType() const { return GetStringAt(3); } +std::string Result::GetName() const { return GetStringAt(4); } +std::string Result::GetComment() const { return GetStringAt(5); } +std::string Result::GetDndURI() const { return GetStringAt(6); } + } } diff --git a/UnityCore/Result.h b/UnityCore/Result.h index 8e00f85fd..4fb3332cc 100644 --- a/UnityCore/Result.h +++ b/UnityCore/Result.h @@ -51,6 +51,15 @@ public: nux::ROProperty<std::string> comment; nux::ROProperty<std::string> dnd_uri; +protected: + virtual std::string GetURI() const; + virtual std::string GetIconHint() const; + virtual std::size_t GetCategoryIndex() const; + virtual std::string GetMimeType() const; + virtual std::string GetName() const; + virtual std::string GetComment() const; + virtual std::string GetDndURI() const; + private: void SetupGetters(); }; diff --git a/dash/ResultRenderer.cpp b/dash/ResultRenderer.cpp index 1d18176ea..a7bc6e965 100644 --- a/dash/ResultRenderer.cpp +++ b/dash/ResultRenderer.cpp @@ -22,10 +22,99 @@ #include "ResultRenderer.h" +#include <gtk/gtk.h> +#include <unity-protocol.h> +#include <NuxGraphics/GdkGraphics.h> + namespace unity { namespace dash { + +namespace +{ +#define DEFAULT_GICON ". GThemedIcon text-x-preview" + +GdkPixbuf* _icon_hint_get_drag_pixbuf(std::string icon_hint, int size) +{ + GdkPixbuf *pbuf; + GtkIconTheme *theme; + GtkIconInfo *info; + GError *error = NULL; + GIcon *icon; + if (icon_hint.empty()) + icon_hint = DEFAULT_GICON; + if (g_str_has_prefix(icon_hint.c_str(), "/")) + { + pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(), + size, size, TRUE, &error); + if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf)) + { + icon_hint = "application-default-icon"; + g_error_free (error); + error = NULL; + } + else + return pbuf; + } + theme = gtk_icon_theme_get_default(); + icon = g_icon_new_for_string(icon_hint.c_str(), NULL); + + if (G_IS_ICON(icon)) + { + if (UNITY_PROTOCOL_IS_ANNOTATED_ICON(icon)) + { + UnityProtocolAnnotatedIcon *anno; + anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon); + + GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno); + info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, (GtkIconLookupFlags)0); + } + else + { + info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0); + } + g_object_unref(icon); + } + else + { + info = gtk_icon_theme_lookup_icon(theme, + icon_hint.c_str(), + size, + (GtkIconLookupFlags) 0); + } + + if (!info) + { + info = gtk_icon_theme_lookup_icon(theme, + "application-default-icon", + size, + (GtkIconLookupFlags) 0); + } + + if (gtk_icon_info_get_filename(info) == NULL) + { + gtk_icon_info_free(info); + info = gtk_icon_theme_lookup_icon(theme, + "application-default-icon", + size, + (GtkIconLookupFlags) 0); + } + + pbuf = gtk_icon_info_load_icon(info, &error); + + if (error != NULL) + { + g_error_free (error); + pbuf = NULL; + } + + gtk_icon_info_free(info); + return pbuf; +} + +} + NUX_IMPLEMENT_OBJECT_TYPE(ResultRenderer); ResultRenderer::ResultRenderer(NUX_FILE_LINE_DECL) @@ -52,6 +141,12 @@ void ResultRenderer::Unload(Result& row) // unload any resources } +nux::NBitmapData* ResultRenderer::GetDndImage(Result const& row) const +{ + nux::GdkGraphics graphics(_icon_hint_get_drag_pixbuf(row.icon_hint, 64)); + return graphics.GetBitmap(); +} + } } diff --git a/dash/ResultRenderer.h b/dash/ResultRenderer.h index 44dacdc8a..6ba94aa77 100644 --- a/dash/ResultRenderer.h +++ b/dash/ResultRenderer.h @@ -62,6 +62,9 @@ public: // unload any previous grabbed images virtual void Unload(Result& row); + // get a image to drag + virtual nux::NBitmapData* GetDndImage(Result const& row) const; + nux::Property<int> width; nux::Property<int> height; diff --git a/dash/ResultRendererHorizontalTile.cpp b/dash/ResultRendererHorizontalTile.cpp index acedf8878..93201af58 100644 --- a/dash/ResultRendererHorizontalTile.cpp +++ b/dash/ResultRendererHorizontalTile.cpp @@ -29,6 +29,7 @@ #include "unity-shared/CairoTexture.h" #include "unity-shared/TextureCache.h" +#include <NuxGraphics/GdkGraphics.h> namespace unity @@ -42,7 +43,7 @@ const int CARD_VIEW_WIDTH = 277; // pixels const int CARD_VIEW_HEIGHT = 74; // pixels const int CARD_VIEW_HIGHLIGHT_CORNER_RADIUS = 2; // pixels const int CARD_VIEW_ICON_OUTLINE_WIDTH = 1; // pixels -const int CARD_VIEW_TEXT_LINE_SPACING = 0; // points +const int CARD_VIEW_TEXT_LINE_SPACING = 0; // points } namespace dash @@ -297,6 +298,25 @@ void ResultRendererHorizontalTile::LoadText(Result& row) container->text = texture_ptr_from_cairo_graphics(_cairoGraphics); } +nux::NBitmapData* ResultRendererHorizontalTile::GetDndImage(Result const& row) const +{ + TextureContainer* container = row.renderer<TextureContainer*>(); + nux::NBitmapData* bitmap = nullptr; + + if (container && container->drag_icon && container->drag_icon.IsType(GDK_TYPE_PIXBUF)) + { + int width = gdk_pixbuf_get_width(container->drag_icon); + int height = gdk_pixbuf_get_height(container->drag_icon); + + if (width != CARD_VIEW_ICON_SIZE || height != CARD_VIEW_ICON_SIZE) + { + nux::GdkGraphics graphics(gdk_pixbuf_scale_simple(container->drag_icon, CARD_VIEW_ICON_SIZE, CARD_VIEW_ICON_SIZE, GDK_INTERP_BILINEAR)); + bitmap = graphics.GetBitmap(); + } + } + return bitmap ? bitmap : ResultRendererTile::GetDndImage(row); +} + } } diff --git a/dash/ResultRendererHorizontalTile.h b/dash/ResultRendererHorizontalTile.h index 678bf2f59..88c7f5b86 100644 --- a/dash/ResultRendererHorizontalTile.h +++ b/dash/ResultRendererHorizontalTile.h @@ -46,6 +46,8 @@ public: nux::Geometry const& geometry, int x_offset, int y_offset); + virtual nux::NBitmapData* GetDndImage(Result const& row) const; + protected: virtual void LoadText(Result& row); diff --git a/dash/ResultRendererTile.cpp b/dash/ResultRendererTile.cpp index 40dd675ee..c5ce010f3 100644 --- a/dash/ResultRendererTile.cpp +++ b/dash/ResultRendererTile.cpp @@ -23,10 +23,10 @@ #include "ResultRendererTile.h" #include <pango/pangocairo.h> -#include <gtk/gtk.h> #include <NuxCore/Logger.h> #include <UnityCore/GLibWrapper.h> +#include <NuxGraphics/GdkGraphics.h> #include "unity-shared/CairoTexture.h" #include "unity-shared/DashStyle.h" @@ -34,7 +34,8 @@ namespace { - bool neko; +bool neko; +#define DEFAULT_GICON ". GThemedIcon text-x-preview" } namespace unity @@ -180,11 +181,24 @@ void ResultRendererTile::Unload(Result& row) row.set_renderer<TextureContainer*>(nullptr); } +nux::NBitmapData* ResultRendererTile::GetDndImage(Result const& row) const +{ + TextureContainer* container = row.renderer<TextureContainer*>(); + nux::NBitmapData* bitmap = nullptr; + + if (container && container->drag_icon && container->drag_icon.IsType(GDK_TYPE_PIXBUF)) + { + // Need to ref the drag icon because GdkGraphics will unref it. + nux::GdkGraphics graphics(GDK_PIXBUF(g_object_ref(container->drag_icon))); + bitmap = graphics.GetBitmap(); + } + return bitmap ? bitmap : ResultRenderer::GetDndImage(row); +} + void ResultRendererTile::LoadIcon(Result& row) { Style& style = Style::Instance(); std::string icon_hint(row.icon_hint); -#define DEFAULT_GICON ". GThemedIcon text-x-preview" std::string icon_name; if (G_UNLIKELY(neko)) { @@ -289,10 +303,8 @@ nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& t return texture_from_cairo_graphics(cairo_graphics); } - } - void ResultRendererTile::IconLoaded(std::string const& texid, int max_width, int max_height, @@ -314,6 +326,7 @@ void ResultRendererTile::IconLoaded(std::string const& texid, container->icon = texture; container->prelight = texture_prelight; + container->drag_icon = pixbuf; NeedsRedraw.emit(); diff --git a/dash/ResultRendererTile.h b/dash/ResultRendererTile.h index be7e18aa2..86a003d9e 100644 --- a/dash/ResultRendererTile.h +++ b/dash/ResultRendererTile.h @@ -38,6 +38,8 @@ namespace dash BaseTexturePtr text; BaseTexturePtr icon; BaseTexturePtr prelight; + glib::Object<GdkPixbuf> drag_icon; + int slot_handle; TextureContainer() @@ -67,6 +69,8 @@ public: virtual void Preload(Result& row); virtual void Unload(Result& row); + + virtual nux::NBitmapData* GetDndImage(Result const& row) const; int spacing; int padding; diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index 6bba014d9..7d273f451 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -56,6 +56,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) , last_lazy_loaded_result_(0) , last_mouse_down_x_(-1) , last_mouse_down_y_(-1) + , drag_index_(~0) , recorded_dash_width_(-1) , recorded_dash_height_(-1) , mouse_last_x_(-1) @@ -778,27 +779,23 @@ std::tuple<int, int> ResultViewGrid::GetResultPosition(const unsigned int& index bool ResultViewGrid::DndSourceDragBegin() { #ifdef USE_X11 - unsigned num_results = GetNumResults(); - unsigned drag_index = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_); + drag_index_ = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_); - if (drag_index >= num_results) + if (drag_index_ >= GetNumResults()) return false; Reference(); - ResultIterator iter(GetIteratorAtRow(drag_index)); + ResultIterator iter(GetIteratorAtRow(drag_index_)); Result drag_result = *iter; current_drag_uri_ = drag_result.dnd_uri; if (current_drag_uri_ == "") current_drag_uri_ = drag_result.uri().substr(drag_result.uri().find(":") + 1); - current_drag_icon_name_ = drag_result.icon_hint; - LOG_DEBUG (logger) << "Dnd begin at " << last_mouse_down_x_ << ", " << last_mouse_down_y_ << " - using; " - << current_drag_uri_ << " - " - << current_drag_icon_name_; + << current_drag_uri_; return true; #else @@ -806,101 +803,14 @@ bool ResultViewGrid::DndSourceDragBegin() #endif } -GdkPixbuf* _icon_hint_get_drag_pixbuf(std::string icon_hint) -{ - GdkPixbuf *pbuf; - GtkIconTheme *theme; - GtkIconInfo *info; - GError *error = NULL; - GIcon *icon; - int size = 64; - if (icon_hint.empty()) - icon_hint = "application-default-icon"; - if (g_str_has_prefix(icon_hint.c_str(), "/")) - { - pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(), - size, size, FALSE, &error); - if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf)) - { - icon_hint = "application-default-icon"; - g_error_free (error); - error = NULL; - } - else - return pbuf; - } - theme = gtk_icon_theme_get_default(); - icon = g_icon_new_for_string(icon_hint.c_str(), NULL); - - if (G_IS_ICON(icon)) - { - if (UNITY_PROTOCOL_IS_ANNOTATED_ICON(icon)) - { - UnityProtocolAnnotatedIcon *anno; - anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon); - - GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno); - info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, (GtkIconLookupFlags)0); - } - else - { - info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0); - } - g_object_unref(icon); - } - else - { - info = gtk_icon_theme_lookup_icon(theme, - icon_hint.c_str(), - size, - (GtkIconLookupFlags) 0); - } - - if (!info) - { - info = gtk_icon_theme_lookup_icon(theme, - "application-default-icon", - size, - (GtkIconLookupFlags) 0); - } - - if (gtk_icon_info_get_filename(info) == NULL) - { - gtk_icon_info_free(info); - info = gtk_icon_theme_lookup_icon(theme, - "application-default-icon", - size, - (GtkIconLookupFlags) 0); - } - - pbuf = gtk_icon_info_load_icon(info, &error); - - if (error != NULL) - { - LOG_WARN (logger) << "could not find a pixbuf for " << icon_hint; - g_error_free (error); - pbuf = NULL; - } - - gtk_icon_info_free(info); - return pbuf; -} - nux::NBitmapData* ResultViewGrid::DndSourceGetDragImage() { - nux::NBitmapData* result = 0; - GdkPixbuf* pbuf; - pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_); + if (drag_index_ >= GetNumResults()) + return nullptr; - if (pbuf && GDK_IS_PIXBUF(pbuf)) - { - // we don't free the pbuf as GdkGraphics will do it for us will do it for us - nux::GdkGraphics graphics(pbuf); - result = graphics.GetBitmap(); - } - - return result; + Result result(*GetIteratorAtRow(drag_index_)); + return renderer_->GetDndImage(result); } std::list<const char*> @@ -934,7 +844,7 @@ void ResultViewGrid::DndSourceDragFinished(nux::DndAction result) last_mouse_down_x_ = -1; last_mouse_down_y_ = -1; current_drag_uri_.clear(); - current_drag_icon_name_.clear(); + drag_index_ = ~0; // We need this because the drag can start in a ResultViewGrid and can // end in another ResultViewGrid diff --git a/dash/ResultViewGrid.h b/dash/ResultViewGrid.h index 2fdd92da8..cb89f27dc 100644 --- a/dash/ResultViewGrid.h +++ b/dash/ResultViewGrid.h @@ -106,7 +106,7 @@ private: int last_mouse_down_x_; int last_mouse_down_y_; std::string current_drag_uri_; - std::string current_drag_icon_name_; + unsigned drag_index_; int recorded_dash_width_; int recorded_dash_height_; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9a420db1b..1d9e3a01e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -230,6 +230,7 @@ if (ENABLE_X_SUPPORT) test_overlay_scrollbar.cpp test_quicklist_menu_item.cpp test_quicklist_view.cpp + test_result_renderer.cpp test_resultviewgrid.cpp test_shortcut_controller.cpp test_single_monitor_launcher_icon.cpp diff --git a/tests/test_result_renderer.cpp b/tests/test_result_renderer.cpp new file mode 100644 index 000000000..e0770ddf0 --- /dev/null +++ b/tests/test_result_renderer.cpp @@ -0,0 +1,124 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ +#include <gmock/gmock.h> +#include <glib-object.h> + +#include "unity-shared/DashStyle.h" +#include "unity-shared/UnitySettings.h" +#include "UnityCore/Result.h" +#include "dash/ResultRendererTile.h" + +#include "test_utils.h" + +using namespace std; +using namespace unity; +using namespace testing; + +namespace unity +{ + +namespace +{ + +#define DEFAULT_GICON ". GThemedIcon text-x-preview" + +GdkPixbuf* GetIconData(std::string icon_hint, int size) +{ + GdkPixbuf *pbuf; + GtkIconTheme *theme; + GError *error = NULL; + + theme = gtk_icon_theme_get_default(); + glib::Object<GIcon> icon(g_icon_new_for_string(icon_hint.c_str(), NULL)); + + if (icon.IsType(G_TYPE_ICON)) + { + GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0); + pbuf = gtk_icon_info_load_icon(info, &error); + if (error != NULL) + { + g_error_free (error); + pbuf = NULL; + } + gtk_icon_info_free(info); + } + + return pbuf; +} + +} // namespace [anonymous] + +class TestResultRenderer : public testing::Test +{ +public: + TestResultRenderer() {} + + unity::Settings settings; + dash::Style style; +}; + +class MockResult : public dash::Result +{ +public: + MockResult() + : Result(NULL, NULL, NULL) + , renderer_(new dash::TextureContainer()) + { + ON_CALL (*this, GetURI ()).WillByDefault (Return ("file:///result_render_test")); + ON_CALL (*this, GetIconHint()).WillByDefault (Return (DEFAULT_GICON)); + ON_CALL (*this, GetCategoryIndex ()).WillByDefault (Return (0)); + ON_CALL (*this, GetName ()).WillByDefault (Return ("Result Render Test")); + ON_CALL (*this, GetDndURI ()).WillByDefault (Return ("file:///result_render_test_dnd")); + } + + MOCK_CONST_METHOD0(GetURI, std::string()); + MOCK_CONST_METHOD0(GetIconHint, std::string()); + MOCK_CONST_METHOD0(GetCategoryIndex, std::size_t()); + MOCK_CONST_METHOD0(GetMimeType, std::string()); + MOCK_CONST_METHOD0(GetName, std::string()); + MOCK_CONST_METHOD0(GetComment, std::string()); + MOCK_CONST_METHOD0(GetDndURI, std::string()); + + virtual gpointer get_model_tag() const + { + return renderer_.get(); + } + +private: + std::auto_ptr<dash::TextureContainer> renderer_; +}; + +TEST_F(TestResultRenderer, TestConstruction) +{ + dash::ResultRendererTile renderer; +} + +TEST_F(TestResultRenderer, TestDndIcon) +{ + dash::ResultRendererTile renderer; + NiceMock<MockResult> result; + + nux::NBitmapData* bitmap = renderer.GetDndImage(result); + ASSERT_NE(bitmap, nullptr); +} + +} |
