[nautilus/previewer: 2/6] all: hook up the previewer with NautilusIconView



commit c691460d68a5ef5f622b66700dc2daa960e864cb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 21 16:44:46 2011 -0400

    all: hook up the previewer with NautilusIconView

 libnautilus-private/nautilus-icon-container.c |   45 ++++++++++++++++++++++++-
 libnautilus-private/nautilus-icon-container.h |    3 ++
 src/nautilus-icon-view.c                      |   15 ++++++++
 src/nautilus-view.c                           |   30 ++++++++++++++++
 src/nautilus-view.h                           |    3 ++
 5 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/libnautilus-private/nautilus-icon-container.c b/libnautilus-private/nautilus-icon-container.c
index 3c931a8..b358b20 100644
--- a/libnautilus-private/nautilus-icon-container.c
+++ b/libnautilus-private/nautilus-icon-container.c
@@ -144,6 +144,7 @@ typedef struct {
 
 static GType         nautilus_icon_container_accessible_get_type (void);
 
+static void          preview_selected_items                         (NautilusIconContainer *container);
 static void          activate_selected_items                        (NautilusIconContainer *container);
 static void          activate_selected_items_alternate              (NautilusIconContainer *container,
 								     NautilusIcon          *icon);
@@ -226,6 +227,7 @@ G_DEFINE_TYPE (NautilusIconContainer, nautilus_icon_container, EEL_TYPE_CANVAS);
 enum {
 	ACTIVATE,
 	ACTIVATE_ALTERNATE,
+	ACTIVATE_PREVIEWER,
 	BAND_SELECT_STARTED,
 	BAND_SELECT_ENDED,
 	BUTTON_PRESS,
@@ -3888,7 +3890,7 @@ keyboard_space (NautilusIconContainer *container,
 	} else if ((event->state & GDK_SHIFT_MASK) != 0) {
 		activate_selected_items_alternate (container, NULL);
 	} else {
-		activate_selected_items (container);
+		preview_selected_items (container);
 	}
 }
 
@@ -5679,6 +5681,16 @@ nautilus_icon_container_class_init (NautilusIconContainerClass *class)
 		                g_cclosure_marshal_VOID__POINTER,
 		                G_TYPE_NONE, 1,
 				G_TYPE_POINTER);
+	signals[ACTIVATE_PREVIEWER]
+		= g_signal_new ("activate_previewer",
+		                G_TYPE_FROM_CLASS (class),
+		                G_SIGNAL_RUN_LAST,
+		                G_STRUCT_OFFSET (NautilusIconContainerClass,
+						 activate_previewer),
+		                NULL, NULL,
+		                nautilus_marshal_VOID__POINTER_POINTER,
+		                G_TYPE_NONE, 2,
+				G_TYPE_POINTER, G_TYPE_POINTER);
 	signals[CONTEXT_CLICK_SELECTION]
 		= g_signal_new ("context_click_selection",
 		                G_TYPE_FROM_CLASS (class),
@@ -6674,6 +6686,37 @@ activate_selected_items (NautilusIconContainer *container)
 }
 
 static void
+preview_selected_items (NautilusIconContainer *container)
+{
+	GList *selection;
+	GArray *locations;
+	gint idx;
+
+	g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
+
+	selection = nautilus_icon_container_get_selection (container);
+	locations = nautilus_icon_container_get_selected_icon_locations (container);
+
+	for (idx = 0; idx < locations->len; idx++) {
+		GdkPoint *point = &(g_array_index (locations, GdkPoint, idx));
+		gint scroll_x, scroll_y;
+
+		eel_canvas_get_scroll_offsets (EEL_CANVAS (container),
+					       &scroll_x, &scroll_y);
+
+		point->x -= scroll_x;
+		point->y -= scroll_y;
+	}
+
+	if (selection != NULL) {
+	  	g_signal_emit (container,
+			       signals[ACTIVATE_PREVIEWER], 0,
+			       selection, locations);
+	}
+	g_list_free (selection);	
+}
+
+static void
 activate_selected_items_alternate (NautilusIconContainer *container,
 				   NautilusIcon *icon)
 {
diff --git a/libnautilus-private/nautilus-icon-container.h b/libnautilus-private/nautilus-icon-container.h
index 93c54ce..cdae0ca 100644
--- a/libnautilus-private/nautilus-icon-container.h
+++ b/libnautilus-private/nautilus-icon-container.h
@@ -93,6 +93,9 @@ typedef struct {
 						   NautilusIconData *data);
 	void         (* activate_alternate)       (NautilusIconContainer *container,
 						   NautilusIconData *data);
+	void         (* activate_previewer)       (NautilusIconContainer *container,
+						   GList *files,
+						   GArray *locations);
 	void         (* context_click_selection)  (NautilusIconContainer *container,
 						   GdkEventButton *event);
 	void	     (* move_copy_items)	  (NautilusIconContainer *container,
diff --git a/src/nautilus-icon-view.c b/src/nautilus-icon-view.c
index 68ba2cc..ff8017c 100644
--- a/src/nautilus-icon-view.c
+++ b/src/nautilus-icon-view.c
@@ -1688,6 +1688,19 @@ icon_container_activate_callback (NautilusIconContainer *container,
 				      0, TRUE);
 }
 
+static void
+icon_container_activate_previewer_callback (NautilusIconContainer *container,
+					    GList *file_list,
+					    GArray *locations,
+					    NautilusIconView *icon_view)
+{
+	g_assert (NAUTILUS_IS_ICON_VIEW (icon_view));
+	g_assert (container == get_icon_container (icon_view));
+
+	nautilus_view_preview_files (NAUTILUS_VIEW (icon_view),
+				     file_list, locations);
+}
+
 /* this is called in one of these cases:
  * - we activate with enter holding shift
  * - we activate with space holding shift
@@ -2558,6 +2571,8 @@ create_icon_container (NautilusIconView *icon_view)
 				 G_CALLBACK (icon_container_activate_callback), icon_view, 0);
 	g_signal_connect_object (icon_container, "activate_alternate",	
 				 G_CALLBACK (icon_container_activate_alternate_callback), icon_view, 0);
+	g_signal_connect_object (icon_container, "activate_previewer",
+				 G_CALLBACK (icon_container_activate_previewer_callback), icon_view, 0);
 	g_signal_connect_object (icon_container, "band_select_started",
 				 G_CALLBACK (band_select_started_callback), icon_view, 0);
 	g_signal_connect_object (icon_container, "band_select_ended",
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 09e439f..1ddc6e2 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -36,9 +36,11 @@
 #include "nautilus-error-reporting.h"
 #include "nautilus-list-view.h"
 #include "nautilus-mime-actions.h"
+#include "nautilus-previewer.h"
 #include "nautilus-properties-window.h"
 #include "nautilus-src-marshal.h"
 
+#include <gdk/gdkx.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
@@ -1110,6 +1112,34 @@ get_view_directory (NautilusView *view)
 }
 
 void
+nautilus_view_preview_files (NautilusView *view,
+			     GList *files,
+			     GArray *locations)
+{
+	NautilusPreviewer *previewer;
+	gchar *uri;
+	guint xid, x, y;
+	GdkPoint location;
+	GtkWidget *toplevel;
+
+	previewer = nautilus_previewer_dup_singleton ();
+	uri = nautilus_file_get_uri (files->data);
+	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+	if (locations != NULL) {
+		location = g_array_index (locations, GdkPoint, 0);
+		x = location.x;
+		y = location.y;
+	} else {
+		x = y = 0;
+	}
+
+	xid = gdk_x11_window_get_xid (gtk_widget_get_window (toplevel));
+
+	nautilus_previewer_call_show_file (previewer, uri, xid, x, y);
+}
+
+void
 nautilus_view_activate_files (NautilusView *view,
 			      GList *files,
 			      NautilusWindowOpenFlags flags,
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index b53c45f..bd3c6d7 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -329,6 +329,9 @@ void                nautilus_view_activate_files                   (NautilusView
 								    GList                  *files,
 								    NautilusWindowOpenFlags flags,
 								    gboolean                confirm_multiple);
+void                nautilus_view_preview_files                    (NautilusView        *view,
+								    GList               *files,
+								    GArray              *locations);
 void                nautilus_view_start_batching_selection_changes (NautilusView  *view);
 void                nautilus_view_stop_batching_selection_changes  (NautilusView  *view);
 void                nautilus_view_notify_selection_changed         (NautilusView  *view);



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