[nautilus/gnome-2-32: 101/283] Implement transparent icons for cut files in list view.



commit 1810ec018e0d223745dab8ea2b4292b570342ae0
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat May 15 15:40:12 2010 +0200

    Implement transparent icons for cut files in list view.

 src/file-manager/fm-list-model.c |   83 +++++++++++++++++++++++++++++++++++++-
 src/file-manager/fm-list-model.h |    3 +
 src/file-manager/fm-list-view.c  |   40 ++++++++++++++++++
 3 files changed, 124 insertions(+), 2 deletions(-)
---
diff --git a/src/file-manager/fm-list-model.c b/src/file-manager/fm-list-model.c
index 5e235fb..7cc8bad 100644
--- a/src/file-manager/fm-list-model.c
+++ b/src/file-manager/fm-list-model.c
@@ -75,6 +75,8 @@ struct FMListModelDetails {
 	int drag_begin_y;
 
 	GPtrArray *columns;
+
+	GList *highlight_files;
 };
 
 typedef struct {
@@ -246,6 +248,24 @@ fm_list_model_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
 	return path;
 }
 
+static gint
+compare_files (gconstpointer a,
+               gconstpointer b)
+{
+	GFile *loc_a, *loc_b;
+	gboolean res;
+	
+	loc_a = nautilus_file_get_location (NAUTILUS_FILE (a));
+	loc_b = nautilus_file_get_location (NAUTILUS_FILE (b));
+
+	res = !g_file_equal (loc_a, loc_b);
+
+	g_object_unref (loc_a);
+	g_object_unref (loc_b);
+
+	return (gint) res;
+}
+
 static void
 fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
 {
@@ -253,7 +273,7 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
 	FileEntry *file_entry;
 	NautilusFile *file;
 	char *str;
-	GdkPixbuf *icon;
+	GdkPixbuf *icon, *rendered_icon;
 	int icon_size;
 	guint emblem_size;
 	NautilusZoomLevel zoom_level;
@@ -317,7 +337,19 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
 			}
 
 			icon = nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, flags);
-  
+
+			if (model->details->highlight_files != NULL &&
+			    g_list_find_custom (model->details->highlight_files,
+			                        file, compare_files))
+			{
+				rendered_icon = eel_gdk_pixbuf_render (icon, 1, 255, 255, 0, 0);
+
+				if (rendered_icon != NULL) {
+					g_object_unref (icon);
+					icon = rendered_icon;
+				}
+			}
+
 			g_value_set_object (value, icon);
 			g_object_unref (icon);
 		}
@@ -1553,6 +1585,11 @@ fm_list_model_finalize (GObject *object)
 
 	model = FM_LIST_MODEL (object);
 
+	if (model->details->highlight_files != NULL) {
+		nautilus_file_list_free (model->details->highlight_files);
+		model->details->highlight_files = NULL;
+	}
+
 	g_free (model->details);
 
 	G_OBJECT_CLASS (fm_list_model_parent_class)->finalize (object);
@@ -1668,3 +1705,45 @@ fm_list_model_subdirectory_done_loading (FMListModel *model, NautilusDirectory *
 		}
 	}
 }
+
+static void
+refresh_row (gpointer data,
+             gpointer user_data)
+{
+	NautilusFile *file;
+	FMListModel *model;
+	GList *iters, *l;
+	GtkTreePath *path;
+
+	model = user_data;
+	file = data;
+
+	iters = fm_list_model_get_all_iters_for_file (model, file);
+	for (l = iters; l != NULL; l = l->next) {
+		path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), l->data);
+		gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, l->data);
+
+		gtk_tree_path_free (path);
+	}
+
+	eel_g_list_free_deep (iters);
+}
+
+void
+fm_list_model_set_highlight_for_files (FMListModel *model,
+                                       GList *files)
+{
+	if (model->details->highlight_files != NULL) {
+		g_list_foreach (model->details->highlight_files,
+		                refresh_row, model);
+		nautilus_file_list_free (model->details->highlight_files);
+		model->details->highlight_files = NULL;
+	}
+
+	if (files != NULL) {
+		model->details->highlight_files = nautilus_file_list_copy (files);
+		g_list_foreach (model->details->highlight_files,
+		                refresh_row, model);
+
+	}
+}
diff --git a/src/file-manager/fm-list-model.h b/src/file-manager/fm-list-model.h
index d6a6b14..b01fee8 100644
--- a/src/file-manager/fm-list-model.h
+++ b/src/file-manager/fm-list-model.h
@@ -138,5 +138,8 @@ int               fm_list_model_get_column_number (FMListModel *model,
 						   
 void              fm_list_model_subdirectory_done_loading (FMListModel       *model,
 							   NautilusDirectory *directory);
+
+void              fm_list_model_set_highlight_for_files (FMListModel *model,
+                                                         GList *files);
 						   
 #endif /* FM_LIST_MODEL_H */
diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c
index 1bab954..c307c5a 100644
--- a/src/file-manager/fm-list-view.c
+++ b/src/file-manager/fm-list-view.c
@@ -33,6 +33,7 @@
 #include "fm-list-model.h"
 #include <string.h>
 #include <eel/eel-vfs-extensions.h>
+#include <eel/eel-gdk-extensions.h>
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-gtk-macros.h>
 #include <gdk/gdk.h>
@@ -42,6 +43,7 @@
 #include <glib/gi18n.h>
 #include <glib-object.h>
 #include <libnautilus-extension/nautilus-column-provider.h>
+#include <libnautilus-private/nautilus-clipboard-monitor.h>
 #include <libnautilus-private/nautilus-column-chooser.h>
 #include <libnautilus-private/nautilus-column-utilities.h>
 #include <libnautilus-private/nautilus-debug-log.h>
@@ -104,6 +106,8 @@ struct FMListViewDetails {
 	gboolean rename_done;
 	guint renaming_file_activate_timeout;
 
+	gulong clipboard_handler_id;
+
 	GQuark last_sort_attr;
 };
 
@@ -2757,6 +2761,12 @@ fm_list_view_dispose (GObject *object)
 		list_view->details->renaming_file_activate_timeout = 0;
 	}
 
+	if (list_view->details->clipboard_handler_id != 0) {
+		g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
+		                             list_view->details->clipboard_handler_id);
+		list_view->details->clipboard_handler_id = 0;
+	}
+
 	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -2880,6 +2890,31 @@ list_view_scroll_to_file (NautilusView *view,
 }
 
 static void
+list_view_notify_clipboard_info (NautilusClipboardMonitor *monitor,
+                                 NautilusClipboardInfo *info,
+                                 FMListView *view)
+{
+	if (info != NULL && info->cut) {
+		fm_list_model_set_highlight_for_files (view->details->model, info->files);
+	} else {
+		fm_list_model_set_highlight_for_files (view->details->model, NULL);
+	}
+}
+
+static void
+fm_list_view_end_loading (FMDirectoryView *view,
+                          gboolean all_files_seen)
+{
+	NautilusClipboardMonitor *monitor;
+	NautilusClipboardInfo *info;
+
+	monitor = nautilus_clipboard_monitor_get ();
+	info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
+
+	list_view_notify_clipboard_info (monitor, info, FM_LIST_VIEW (view));
+}
+
+static void
 real_set_is_active (FMDirectoryView *view,
 		    gboolean is_active)
 {
@@ -2913,6 +2948,7 @@ fm_list_view_class_init (FMListViewClass *class)
 
 	fm_directory_view_class->add_file = fm_list_view_add_file;
 	fm_directory_view_class->begin_loading = fm_list_view_begin_loading;
+	fm_directory_view_class->end_loading = fm_list_view_end_loading;
 	fm_directory_view_class->bump_zoom_level = fm_list_view_bump_zoom_level;
 	fm_directory_view_class->can_zoom_in = fm_list_view_can_zoom_in;
 	fm_directory_view_class->can_zoom_out = fm_list_view_can_zoom_out;
@@ -3008,6 +3044,10 @@ fm_list_view_init (FMListView *list_view)
 	list_view->details->zoom_level = NAUTILUS_ZOOM_LEVEL_SMALLEST - 1;
 
 	list_view->details->hover_path = NULL;
+	list_view->details->clipboard_handler_id = 
+		g_signal_connect (nautilus_clipboard_monitor_get (),
+		                  "clipboard_info",
+		                  G_CALLBACK (list_view_notify_clipboard_info), list_view);
 }
 
 static NautilusView *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]