[gthumb] added a base tool to load the original image asynchronously
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] added a base tool to load the original image asynchronously
- Date: Sat, 9 Nov 2013 20:00:57 +0000 (UTC)
commit 6306fbef2b9edd66c347c13cabe054a01827b586
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Oct 9 11:47:44 2013 +0200
added a base tool to load the original image asynchronously
extensions/image_viewer/Makefile.am | 2 +
.../image_viewer/gth-image-viewer-page-tool.c | 191 ++++++++++++++++++++
.../image_viewer/gth-image-viewer-page-tool.h | 62 +++++++
extensions/image_viewer/image-viewer.h | 1 +
gthumb/gth-file-tool.c | 19 ++-
gthumb/gth-file-tool.h | 1 +
6 files changed, 270 insertions(+), 6 deletions(-)
---
diff --git a/extensions/image_viewer/Makefile.am b/extensions/image_viewer/Makefile.am
index 2dbf5cf..ae7bc8a 100644
--- a/extensions/image_viewer/Makefile.am
+++ b/extensions/image_viewer/Makefile.am
@@ -8,6 +8,8 @@ libimage_viewer_la_SOURCES = \
gth-image-histogram.h \
gth-image-viewer-page.c \
gth-image-viewer-page.h \
+ gth-image-viewer-page-tool.c \
+ gth-image-viewer-page-tool.h \
gth-image-viewer-task.c \
gth-image-viewer-task.h \
gth-metadata-provider-image.c \
diff --git a/extensions/image_viewer/gth-image-viewer-page-tool.c
b/extensions/image_viewer/gth-image-viewer-page-tool.c
new file mode 100644
index 0000000..500be71
--- /dev/null
+++ b/extensions/image_viewer/gth-image-viewer-page-tool.c
@@ -0,0 +1,191 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gthumb.h>
+#include "gth-image-viewer-page-tool.h"
+
+
+G_DEFINE_TYPE (GthImageViewerPageTool, gth_image_viewer_page_tool, GTH_TYPE_FILE_TOOL)
+
+
+struct _GthImageViewerPageToolPrivate {
+ cairo_surface_t *source;
+ GthTask *image_task;
+};
+
+
+static void
+original_image_task_completed_cb (GthTask *task,
+ GError *error,
+ gpointer user_data)
+{
+ GthImageViewerPageTool *self = user_data;
+
+ self->priv->image_task = NULL;
+
+ if (gth_file_tool_is_cancelled (GTH_FILE_TOOL (self))) {
+ GTH_IMAGE_VIEWER_PAGE_TOOL_GET_CLASS (self)->reset_image (self);
+ g_object_unref (task);
+ return;
+ }
+
+ if (error != NULL) {
+ g_object_unref (task);
+ return;
+ }
+
+ self->priv->source = gth_original_image_task_get_image (task);
+ if (self->priv->source != NULL) {
+ GTH_IMAGE_VIEWER_PAGE_TOOL_GET_CLASS (self)->modify_image (self);
+ /*gth_file_tool_show_options (GTH_FILE_TOOL (self)); FIXME */
+ }
+
+ g_object_unref (task);
+}
+
+
+static void
+gth_image_viewer_page_tool_activate (GthFileTool *base)
+{
+ GthImageViewerPageTool *self = (GthImageViewerPageTool *) base;
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+
+ /* load the original image */
+
+ window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+ return;
+
+ self->priv->image_task = gth_original_image_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+ g_signal_connect (self->priv->image_task,
+ "completed",
+ G_CALLBACK (original_image_task_completed_cb),
+ self);
+ gth_browser_exec_task (GTH_BROWSER (gth_file_tool_get_window (GTH_FILE_TOOL (self))),
+ self->priv->image_task,
+ FALSE);
+}
+
+
+static void
+gth_image_viewer_page_tool_cancel (GthFileTool *base)
+{
+ GthImageViewerPageTool *self = (GthImageViewerPageTool *) base;
+
+ if (self->priv->image_task != NULL) {
+ gth_task_cancel (self->priv->image_task);
+ return;
+ }
+
+ GTH_IMAGE_VIEWER_PAGE_TOOL_GET_CLASS (self)->reset_image (self);
+}
+
+
+static void
+base_modify_image (GthImageViewerPageTool *self)
+{
+ /* virtual */
+}
+
+
+static void
+base_reset_image (GthImageViewerPageTool *self)
+{
+ /* virtual */
+}
+
+
+static void
+gth_image_viewer_page_tool_finalize (GObject *object)
+{
+ GthImageViewerPageTool *self;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GTH_IS_IMAGE_VIEWER_PAGE_TOOL (object));
+
+ self = (GthImageViewerPageTool *) object;
+
+ cairo_surface_destroy (self->priv->source);
+
+ /* Chain up */
+ G_OBJECT_CLASS (gth_image_viewer_page_tool_parent_class)->finalize (object);
+}
+
+
+static void
+gth_image_viewer_page_tool_class_init (GthImageViewerPageToolClass *klass)
+{
+ GObjectClass *gobject_class;
+ GthFileToolClass *file_tool_class;
+
+ g_type_class_add_private (klass, sizeof (GthImageViewerPageToolPrivate));
+
+ gobject_class = (GObjectClass*) klass;
+ gobject_class->finalize = gth_image_viewer_page_tool_finalize;
+
+ file_tool_class = (GthFileToolClass *) klass;
+ file_tool_class->activate = gth_image_viewer_page_tool_activate;
+ file_tool_class->cancel = gth_image_viewer_page_tool_cancel;
+
+ klass->modify_image = base_modify_image;
+ klass->reset_image = base_reset_image;
+}
+
+
+static void
+gth_image_viewer_page_tool_init (GthImageViewerPageTool *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL,
GthImageViewerPageToolPrivate);
+ self->priv->source = NULL;
+ self->priv->image_task = NULL;
+}
+
+
+cairo_surface_t *
+gth_image_viewer_page_tool_get_source (GthImageViewerPageTool *self)
+{
+ return self->priv->source;
+}
+
+
+GthTask *
+gth_image_viewer_page_tool_get_task (GthImageViewerPageTool *self)
+{
+ return self->priv->image_task;
+}
+
+
+GtkWidget *
+gth_image_viewer_page_tool_get_page (GthImageViewerPageTool *self)
+{
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+
+ window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+ return NULL;
+
+ return viewer_page;
+}
diff --git a/extensions/image_viewer/gth-image-viewer-page-tool.h
b/extensions/image_viewer/gth-image-viewer-page-tool.h
new file mode 100644
index 0000000..d647225
--- /dev/null
+++ b/extensions/image_viewer/gth-image-viewer-page-tool.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_IMAGE_VIEWER_PAGE_PAGE_TOOL_H
+#define GTH_IMAGE_VIEWER_PAGE_PAGE_TOOL_H
+
+#include <gthumb.h>
+#include <extensions/image_viewer/image-viewer.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL (gth_image_viewer_page_tool_get_type ())
+#define GTH_IMAGE_VIEWER_PAGE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL,
GthImageViewerPageTool))
+#define GTH_IMAGE_VIEWER_PAGE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL, GthImageViewerPageToolClass))
+#define GTH_IS_IMAGE_VIEWER_PAGE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL))
+#define GTH_IS_IMAGE_VIEWER_PAGE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL))
+#define GTH_IMAGE_VIEWER_PAGE_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL, GthImageViewerPageToolClass))
+
+typedef struct _GthImageViewerPageTool GthImageViewerPageTool;
+typedef struct _GthImageViewerPageToolClass GthImageViewerPageToolClass;
+typedef struct _GthImageViewerPageToolPrivate GthImageViewerPageToolPrivate;
+
+struct _GthImageViewerPageTool {
+ GthFileTool parent_instance;
+ GthImageViewerPageToolPrivate *priv;
+};
+
+struct _GthImageViewerPageToolClass {
+ GthFileToolClass parent_class;
+
+ /* virtual functions */
+
+ void (*modify_image) (GthImageViewerPageTool *self);
+ void (*reset_image) (GthImageViewerPageTool *self);
+};
+
+GType gth_image_viewer_page_tool_get_type (void);
+cairo_surface_t * gth_image_viewer_page_tool_get_source (GthImageViewerPageTool *self);
+GthTask * gth_image_viewer_page_tool_get_task (GthImageViewerPageTool *self);
+GtkWidget * gth_image_viewer_page_tool_get_page (GthImageViewerPageTool *self);
+
+G_END_DECLS
+
+#endif /* GTH_IMAGE_VIEWER_PAGE_PAGE_TOOL_H */
diff --git a/extensions/image_viewer/image-viewer.h b/extensions/image_viewer/image-viewer.h
index 75a3f26..efef9dc 100644
--- a/extensions/image_viewer/image-viewer.h
+++ b/extensions/image_viewer/image-viewer.h
@@ -23,6 +23,7 @@
#define IMAGE_VIEWER_H
#include "gth-image-viewer-page.h"
+#include "gth-image-viewer-page-tool.h"
#include "gth-image-viewer-task.h"
#include "preferences.h"
diff --git a/gthumb/gth-file-tool.c b/gthumb/gth-file-tool.c
index 7c5f7d9..5ad39fc 100644
--- a/gthumb/gth-file-tool.c
+++ b/gthumb/gth-file-tool.c
@@ -39,7 +39,7 @@ struct _GthFileToolPrivate {
const char *button_text;
const char *options_title;
gboolean separator;
- gboolean canceled;
+ gboolean cancelled;
};
@@ -136,7 +136,7 @@ gth_file_tool_init (GthFileTool *self)
self->priv->icon_name = NULL;
self->priv->button_text = NULL;
self->priv->options_title = NULL;
- self->priv->canceled = FALSE;
+ self->priv->cancelled = FALSE;
gtk_button_set_relief (GTK_BUTTON (self), GTK_RELIEF_NONE);
}
@@ -195,7 +195,7 @@ gth_file_tool_get_icon_name (GthFileTool *self)
void
gth_file_tool_activate (GthFileTool *self)
{
- self->priv->canceled = FALSE;
+ self->priv->cancelled = FALSE;
GTH_FILE_TOOL_GET_CLASS (self)->activate (self);
}
@@ -203,12 +203,19 @@ gth_file_tool_activate (GthFileTool *self)
void
gth_file_tool_cancel (GthFileTool *self)
{
- if (self->priv->canceled)
+ if (self->priv->cancelled)
return;
- self->priv->canceled = TRUE;
+ self->priv->cancelled = TRUE;
GTH_FILE_TOOL_GET_CLASS (self)->cancel (self);
- gth_file_tool_hide_options (self);
+ /*gth_file_tool_hide_options (self); FIXME */
+}
+
+
+gboolean
+gth_file_tool_is_cancelled (GthFileTool *self)
+{
+ return self->priv->cancelled;
}
diff --git a/gthumb/gth-file-tool.h b/gthumb/gth-file-tool.h
index 60b08da..37fa4f4 100644
--- a/gthumb/gth-file-tool.h
+++ b/gthumb/gth-file-tool.h
@@ -69,6 +69,7 @@ GtkWidget * gth_file_tool_get_window (GthFileTool *self);
const char * gth_file_tool_get_icon_name (GthFileTool *self);
void gth_file_tool_activate (GthFileTool *self);
void gth_file_tool_cancel (GthFileTool *self);
+gboolean gth_file_tool_is_cancelled (GthFileTool *self);
void gth_file_tool_update_sensitivity (GthFileTool *self);
GtkWidget * gth_file_tool_get_options (GthFileTool *self);
const char * gth_file_tool_get_options_title (GthFileTool *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]