[gthumb/ext: 48/79] Added a thumbnail to the basic file viewer



commit 2299e3d0c1332d9d6bef3d1076d078406f417f50
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jul 14 17:23:44 2009 +0200

    Added a thumbnail to the basic file viewer

 extensions/file_viewer/gth-file-viewer-page.c   |   91 +++++++++++++++++++++--
 extensions/image_viewer/gth-image-viewer-page.c |    4 +-
 gthumb/glib-utils.h                             |    1 +
 3 files changed, 88 insertions(+), 8 deletions(-)
---
diff --git a/extensions/file_viewer/gth-file-viewer-page.c b/extensions/file_viewer/gth-file-viewer-page.c
index e7d186d..8517b25 100644
--- a/extensions/file_viewer/gth-file-viewer-page.c
+++ b/extensions/file_viewer/gth-file-viewer-page.c
@@ -36,21 +36,55 @@ static const char *file_viewer_ui_info =
 
 
 struct _GthFileViewerPagePrivate {
-	GthBrowser *browser;
-	GtkWidget  *viewer;
-	guint       merge_id;
+	GthBrowser     *browser;
+	GtkWidget      *viewer;
+	GtkWidget      *icon;
+	GtkWidget      *label;
+	guint           merge_id;
+	GthThumbLoader *thumb_loader;
+	gulong          thumb_loader_ready_event;
 };
 
 
 static gpointer gth_file_viewer_page_parent_class = NULL;
 
 
+static gboolean
+viewer_scroll_event_cb (GtkWidget 	     *widget,
+			GdkEventScroll       *event,
+			GthFileViewerPage   *self)
+{
+	if (event->direction == GDK_SCROLL_UP)
+		gth_browser_show_prev_image (self->priv->browser, FALSE, FALSE);
+	else if (event->direction == GDK_SCROLL_DOWN)
+		gth_browser_show_next_image (self->priv->browser, FALSE, FALSE);
+
+	return TRUE;
+}
+
+
+static void
+thumb_loader_ready_cb (GthThumbLoader *il,
+		       GError         *error,
+		       gpointer        user_data)
+{
+	GthFileViewerPage *self = user_data;
+
+	if (error != NULL)
+		return;
+
+	gtk_image_set_from_pixbuf (GTK_IMAGE (self->priv->icon), gth_thumb_loader_get_pixbuf (self->priv->thumb_loader));
+}
+
+
 static void
 gth_file_viewer_page_real_activate (GthViewerPage *base,
 				    GthBrowser    *browser)
 {
 	GthFileViewerPage *self;
-	GError *error = NULL;
+	GError            *error = NULL;
+	GtkWidget         *vbox1;
+	GtkWidget         *vbox2;
 
 	self = (GthFileViewerPage*) base;
 
@@ -62,8 +96,37 @@ gth_file_viewer_page_real_activate (GthViewerPage *base,
 		g_error_free (error);
 	}
 
-	self->priv->viewer = gtk_label_new ("...");
+	self->priv->thumb_loader = gth_thumb_loader_new (128, 128);
+	self->priv->thumb_loader_ready_event =
+			g_signal_connect (G_OBJECT (self->priv->thumb_loader),
+					  "ready",
+					  G_CALLBACK (thumb_loader_ready_cb),
+					  self);
+
+	self->priv->viewer = gtk_event_box_new ();
 	gtk_widget_show (self->priv->viewer);
+
+	vbox1 = gtk_vbox_new (TRUE, 0);
+	gtk_widget_show (vbox1);
+	gtk_container_add (GTK_CONTAINER (self->priv->viewer), vbox1);
+
+	vbox2 = gtk_vbox_new (FALSE, 6);
+	gtk_widget_show (vbox2);
+	gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
+
+	self->priv->icon = gtk_image_new ();
+	gtk_widget_show (self->priv->icon);
+	gtk_box_pack_start (GTK_BOX (vbox2), self->priv->icon, FALSE, FALSE, 0);
+
+	self->priv->label = gtk_label_new ("...");
+	gtk_widget_show (self->priv->label);
+	gtk_box_pack_start (GTK_BOX (vbox2), self->priv->label, FALSE, FALSE, 0);
+
+	g_signal_connect (G_OBJECT (self->priv->viewer),
+			  "scroll-event",
+			  G_CALLBACK (viewer_scroll_event_cb),
+			  self);
+
 	gth_browser_set_viewer_widget (browser, self->priv->viewer);
 	gtk_widget_grab_focus (self->priv->viewer);
 }
@@ -76,6 +139,9 @@ gth_file_viewer_page_real_deactivate (GthViewerPage *base)
 
 	self = (GthFileViewerPage*) base;
 
+	g_signal_handler_disconnect (self->priv->thumb_loader, self->priv->thumb_loader_ready_event);
+	self->priv->thumb_loader_ready_event = 0;
+
 	if (self->priv->merge_id != 0) {
 		gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (self->priv->browser), self->priv->merge_id);
 		self->priv->merge_id = 0;
@@ -114,11 +180,18 @@ gth_file_viewer_page_real_view (GthViewerPage *base,
 				GthFileData   *file_data)
 {
 	GthFileViewerPage *self;
+	GIcon             *icon;
 
 	self = (GthFileViewerPage*) base;
 	g_return_if_fail (file_data != NULL);
 
-	gtk_label_set_text (GTK_LABEL (self->priv->viewer), g_file_info_get_display_name (file_data->info));
+	gtk_label_set_text (GTK_LABEL (self->priv->label), g_file_info_get_display_name (file_data->info));
+	icon = g_file_info_get_icon (file_data->info);
+	if (icon != NULL)
+		gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_DIALOG);
+
+	gth_thumb_loader_set_file (self->priv->thumb_loader, file_data);
+	gth_thumb_loader_load (self->priv->thumb_loader);
 }
 
 
@@ -154,6 +227,12 @@ gth_file_viewer_page_real_can_save (GthViewerPage *base)
 static void
 gth_file_viewer_page_finalize (GObject *obj)
 {
+	GthFileViewerPage *self;
+
+	self = GTH_FILE_VIEWER_PAGE (obj);
+
+	g_object_unref (self->priv->thumb_loader);
+
 	G_OBJECT_CLASS (gth_file_viewer_page_parent_class)->finalize (obj);
 }
 
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 2d9d8f0..0f6f8b9 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -238,9 +238,9 @@ mouse_wheel_scrolled_cb (GtkWidget 	     *widget,
 			 GthImageViewerPage  *self)
 {
 	if (direction == GDK_SCROLL_UP)
-		gth_browser_show_prev_image (self->priv->browser, TRUE, FALSE);
+		gth_browser_show_prev_image (self->priv->browser, FALSE, FALSE);
 	else
-		gth_browser_show_next_image (self->priv->browser, TRUE, FALSE);
+		gth_browser_show_next_image (self->priv->browser, FALSE, FALSE);
 
 	return TRUE;
 }
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 7255b1b..08af24f 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -42,6 +42,7 @@ G_BEGIN_DECLS
 	"standard::edit-name," \
 	"standard::icon," \
 	"standard::size," \
+	"thumbnail::path" \
 	"time::created," \
 	"time::created-usec," \
 	"time::modified," \



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