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
=== modified file 'plugins/unityshell/src/ResultViewGrid.cpp'
--- plugins/unityshell/src/ResultViewGrid.cpp 2011-09-08 11:08:57 +0000
+++ plugins/unityshell/src/ResultViewGrid.cpp 2011-09-08 19:17:25 +0000
@@ -690,66 +690,92 @@
690 return true;690 return true;
691}691}
692692
693nux::NBitmapData*693GdkPixbuf *
694ResultViewGrid::DndSourceGetDragImage()694_icon_hint_get_drag_pixbuf (std::string icon_hint)
695{695{
696 nux::NBitmapData* result = 0;696 GdkPixbuf *pbuf;
697 GdkPixbuf* pbuf;697 GtkIconTheme *theme;
698 GtkIconTheme* theme;698 GtkIconInfo *info;
699 GtkIconInfo* info;699 GError *error = NULL;
700 GError* error = NULL;700 GIcon *icon;
701 GIcon* icon;
702
703 std::string icon_name = current_drag_icon_name_.c_str();
704 int size = 64;701 int size = 64;
705702
706 if (icon_name.empty())703 if (icon_hint.empty())
707 icon_name = "application-default-icon";704 icon_hint = "application-default-icon";
708705
706 if (g_str_has_prefix(icon_hint.c_str(), "/"))
707 {
708
709 pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
710 size, -1, TRUE, &error);
711
712 if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
713 {
714 icon_hint = "application-default-icon";
715 g_error_free (error);
716 error = NULL;
717 }
718 else
719 return pbuf;
720 }
709 theme = gtk_icon_theme_get_default();721 theme = gtk_icon_theme_get_default();
710 icon = g_icon_new_for_string(icon_name.c_str(), NULL);722 icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
711723
712 if (G_IS_ICON(icon))724 if (G_IS_ICON(icon))
713 {725 {
714 info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);726 info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
715 g_object_unref(icon);727 g_object_unref(icon);
716 }728 }
717 else729 else
718 {730 {
719 info = gtk_icon_theme_lookup_icon(theme,731 info = gtk_icon_theme_lookup_icon(theme,
720 icon_name.c_str(),732 icon_hint.c_str(),
721 size,733 size,
722 (GtkIconLookupFlags) 0);734 (GtkIconLookupFlags) 0);
723 }735 }
724736
725 if (!info)737 if (!info)
726 {738 {
727 info = gtk_icon_theme_lookup_icon(theme,739 info = gtk_icon_theme_lookup_icon(theme,
728 "application-default-icon",740 "application-default-icon",
729 size,741 size,
730 (GtkIconLookupFlags) 0);742 (GtkIconLookupFlags) 0);
731 }743 }
732744
733 if (gtk_icon_info_get_filename(info) == NULL)745 if (gtk_icon_info_get_filename(info) == NULL)
734 {746 {
735 gtk_icon_info_free(info);747 gtk_icon_info_free(info);
736 info = gtk_icon_theme_lookup_icon(theme,748 info = gtk_icon_theme_lookup_icon(theme,
737 "application-default-icon",749 "application-default-icon",
738 size,750 size,
739 (GtkIconLookupFlags) 0);751 (GtkIconLookupFlags) 0);
740 }752 }
741753
742 pbuf = gtk_icon_info_load_icon(info, &error);754 pbuf = gtk_icon_info_load_icon(info, &error);
755
756
743 if (error != NULL)757 if (error != NULL)
744 {758 {
745 LOG_WARN (logger) << "could not find a pixbuf for " << icon_name;759 LOG_WARN (logger) << "could not find a pixbuf for " << icon_hint;
746 g_error_free (error);760 g_error_free (error);
747 result = NULL;761 pbuf = NULL;
748 }762 }
749763
750 gtk_icon_info_free(info);764 gtk_icon_info_free(info);
751765
752 if (GDK_IS_PIXBUF(pbuf))766 return pbuf;
767
768}
769
770nux::NBitmapData*
771ResultViewGrid::DndSourceGetDragImage()
772{
773 nux::NBitmapData* result = 0;
774 GdkPixbuf* pbuf;
775
776 pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_);
777
778 if (pbuf && GDK_IS_PIXBUF(pbuf))
753 {779 {
754 // we don't free the pbuf as GdkGraphics will do it for us will do it for us780 // we don't free the pbuf as GdkGraphics will do it for us will do it for us
755 nux::GdkGraphics graphics(pbuf);781 nux::GdkGraphics graphics(pbuf);