[gthumb] added two orientation tools



commit 241a7bafe77dac1ccd375e4f6cfb5110996776be
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Aug 7 18:56:43 2010 +0200

    added two orientation tools
    
    added tool to rotate the images according to their
    embedded orientation; and a tool to reset the embedded
    orientation without rotating the images.

 extensions/image_rotation/Makefile.am              |    2 +
 extensions/image_rotation/actions.c                |   45 ++++
 extensions/image_rotation/actions.h                |    2 +
 extensions/image_rotation/callbacks.c              |   19 ++
 .../image_rotation/gth-reset-orientation-task.c    |  222 ++++++++++++++++++++
 .../image_rotation/gth-reset-orientation-task.h    |   57 +++++
 po/POTFILES.in                                     |    2 +
 7 files changed, 349 insertions(+), 0 deletions(-)
---
diff --git a/extensions/image_rotation/Makefile.am b/extensions/image_rotation/Makefile.am
index 2f2e839..767b9b8 100644
--- a/extensions/image_rotation/Makefile.am
+++ b/extensions/image_rotation/Makefile.am
@@ -7,6 +7,8 @@ libimage_rotation_la_SOURCES = 		\
 	actions.h			\
 	callbacks.c			\
 	callbacks.h			\
+	gth-reset-orientation-task.c	\
+	gth-reset-orientation-task.h	\
 	gth-transform-task.c		\
 	gth-transform-task.h		\
 	main.c				\
diff --git a/extensions/image_rotation/actions.c b/extensions/image_rotation/actions.c
index 0cc2625..656e4ba 100644
--- a/extensions/image_rotation/actions.c
+++ b/extensions/image_rotation/actions.c
@@ -24,6 +24,7 @@
 #include <config.h>
 #include <glib/gi18n.h>
 #include <gthumb.h>
+#include "gth-reset-orientation-task.h"
 #include "gth-transform-task.h"
 
 
@@ -69,3 +70,47 @@ gth_browser_activate_action_tool_rotate_left (GtkAction  *action,
 	_g_object_list_unref (file_data_list);
 	_gtk_tree_path_list_free (items);
 }
+
+
+void
+gth_browser_activate_action_tool_apply_orientation (GtkAction  *action,
+						    GthBrowser *browser)
+{
+	GList   *items;
+	GList   *file_data_list;
+	GList   *file_list;
+	GthTask *task;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+	file_list = gth_file_data_list_to_file_list (file_data_list);
+	task = gth_transform_task_new (browser, file_list, GTH_TRANSFORM_NONE);
+	gth_browser_exec_task (browser, task, FALSE);
+
+	g_object_unref (task);
+	_g_object_list_unref (file_list);
+	_g_object_list_unref (file_data_list);
+	_gtk_tree_path_list_free (items);
+}
+
+
+void
+gth_browser_activate_action_tool_reset_orientation (GtkAction  *action,
+						    GthBrowser *browser)
+{
+	GList   *items;
+	GList   *file_data_list;
+	GList   *file_list;
+	GthTask *task;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+	file_list = gth_file_data_list_to_file_list (file_data_list);
+	task = gth_reset_orientation_task_new (browser, file_list);
+	gth_browser_exec_task (browser, task, FALSE);
+
+	g_object_unref (task);
+	_g_object_list_unref (file_list);
+	_g_object_list_unref (file_data_list);
+	_gtk_tree_path_list_free (items);
+}
diff --git a/extensions/image_rotation/actions.h b/extensions/image_rotation/actions.h
index e698e4f..924a2bc 100644
--- a/extensions/image_rotation/actions.h
+++ b/extensions/image_rotation/actions.h
@@ -29,5 +29,7 @@
 
 DEFINE_ACTION(gth_browser_activate_action_tool_rotate_right)
 DEFINE_ACTION(gth_browser_activate_action_tool_rotate_left)
+DEFINE_ACTION(gth_browser_activate_action_tool_apply_orientation)
+DEFINE_ACTION(gth_browser_activate_action_tool_reset_orientation)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/image_rotation/callbacks.c b/extensions/image_rotation/callbacks.c
index 6c70f97..ba05f36 100644
--- a/extensions/image_rotation/callbacks.c
+++ b/extensions/image_rotation/callbacks.c
@@ -37,6 +37,9 @@ static const char *fixed_ui_info =
 "    <placeholder name='Tools'>"
 "      <menuitem name='RotateRight' action='Tool_RotateRight'/>"
 "      <menuitem name='RotateLeft' action='Tool_RotateLeft'/>"
+"      <menuitem name='ApplyOrientation' action='Tool_ApplyOrientation'/>"
+"      <menuitem name='ResetOrientation' action='Tool_ResetOrientation'/>"
+"      <separator />"
 "    </placeholder>"
 "  </popup>"
 "</ui>";
@@ -52,6 +55,16 @@ static GtkActionEntry action_entries[] = {
 	  N_("Rotate Left"), "<control><alt>L",
 	  N_("Rotate the selected images 90° to the left"),
 	  G_CALLBACK (gth_browser_activate_action_tool_rotate_left) },
+
+	{ "Tool_ApplyOrientation", NULL,
+	  N_("Rotate Physically"), NULL,
+	  N_("Rotate the selected images according to the embedded orientation"),
+	  G_CALLBACK (gth_browser_activate_action_tool_apply_orientation) },
+
+	{ "Tool_ResetOrientation", NULL,
+	  N_("Reset the EXIF Orientation"), NULL,
+	  N_("Reset the embedded orientation without rotating the images"),
+	  G_CALLBACK (gth_browser_activate_action_tool_reset_orientation) }
 };
 
 
@@ -115,6 +128,12 @@ ir__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 
 	action = gtk_action_group_get_action (data->action_group, "Tool_RotateLeft");
 	g_object_set (action, "sensitive", sensitive, NULL);
+
+	action = gtk_action_group_get_action (data->action_group, "Tool_ApplyOrientation");
+	g_object_set (action, "sensitive", sensitive, NULL);
+
+	action = gtk_action_group_get_action (data->action_group, "Tool_ResetOrientation");
+	g_object_set (action, "sensitive", sensitive, NULL);
 }
 
 
diff --git a/extensions/image_rotation/gth-reset-orientation-task.c b/extensions/image_rotation/gth-reset-orientation-task.c
new file mode 100644
index 0000000..e3d4c2b
--- /dev/null
+++ b/extensions/image_rotation/gth-reset-orientation-task.c
@@ -0,0 +1,222 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2010 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include "gth-reset-orientation-task.h"
+
+
+struct _GthResetOrientationTaskPrivate {
+	GthBrowser    *browser;
+	GList         *file_list;
+	GList         *current;
+	GthFileData   *file_data;
+};
+
+
+static gpointer parent_class = NULL;
+
+
+static void
+gth_reset_orientation_task_finalize (GObject *object)
+{
+	GthResetOrientationTask *self;
+
+	self = GTH_RESET_ORIENTATION_TASK (object);
+
+	_g_object_unref (self->priv->file_data);
+	_g_object_list_unref (self->priv->file_list);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void transform_current_file (GthResetOrientationTask *self);
+
+
+static void
+transform_next_file (GthResetOrientationTask *self)
+{
+	self->priv->current = self->priv->current->next;
+	transform_current_file (self);
+}
+
+
+static void
+write_metadata_ready_cb (GError   *error,
+			 gpointer  user_data)
+{
+	GthResetOrientationTask *self = user_data;
+	GFile               *parent;
+	GList               *file_list;
+
+	if (error != NULL) {
+		gth_task_completed (GTH_TASK (self), error);
+		return;
+	}
+
+	parent = g_file_get_parent (self->priv->file_data->file);
+	file_list = g_list_append (NULL, self->priv->file_data->file);
+	gth_monitor_folder_changed (gth_main_get_default_monitor (),
+				    parent,
+				    file_list,
+				    GTH_MONITOR_EVENT_CHANGED);
+
+	g_list_free (file_list);
+	g_object_unref (parent);
+
+	transform_next_file (self);
+}
+
+
+static void
+file_info_ready_cb (GList    *files,
+		    GError   *error,
+		    gpointer  user_data)
+{
+	GthResetOrientationTask *self = user_data;
+	GthMetadata         *metadata;
+
+	if (error != NULL) {
+		gth_task_completed (GTH_TASK (self), error);
+		return;
+	}
+
+	_g_object_unref (self->priv->file_data);
+	self->priv->file_data = g_object_ref ((GthFileData *) files->data);
+
+	metadata = g_object_new (GTH_TYPE_METADATA, "raw", "1", NULL);
+	g_file_info_set_attribute_object (self->priv->file_data->info, "Exif::Image::Orientation", G_OBJECT (metadata));
+
+	_g_write_metadata_async (files,
+				 GTH_METADATA_WRITE_FORCE_EMBEDDED,
+				 "*",
+				 gth_task_get_cancellable (GTH_TASK (self)),
+				 write_metadata_ready_cb,
+				 self);
+
+	g_object_unref (metadata);
+}
+
+
+static void
+transform_current_file (GthResetOrientationTask *self)
+{
+	GFile *file;
+	GList *singleton;
+
+	if (self->priv->current == NULL) {
+		gth_task_completed (GTH_TASK (self), NULL);
+		return;
+	}
+
+	file = self->priv->current->data;
+	singleton = g_list_append (NULL, g_object_ref (file));
+	_g_query_all_metadata_async (singleton,
+				     GTH_LIST_DEFAULT,
+				     "*",
+				     gth_task_get_cancellable (GTH_TASK (self)),
+				     file_info_ready_cb,
+				     self);
+
+	_g_object_list_unref (singleton);
+}
+
+
+static void
+gth_reset_orientation_task_exec (GthTask *task)
+{
+	GthResetOrientationTask *self;
+
+	g_return_if_fail (GTH_IS_RESET_ORIENTATION_TASK (task));
+
+	self = GTH_RESET_ORIENTATION_TASK (task);
+
+	self->priv->current = self->priv->file_list;
+	transform_current_file (self);
+}
+
+
+static void
+gth_reset_orientation_task_class_init (GthResetOrientationTaskClass *klass)
+{
+	GObjectClass *object_class;
+	GthTaskClass *task_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (GthResetOrientationTaskPrivate));
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gth_reset_orientation_task_finalize;
+
+	task_class = GTH_TASK_CLASS (klass);
+	task_class->exec = gth_reset_orientation_task_exec;
+}
+
+
+static void
+gth_reset_orientation_task_init (GthResetOrientationTask *self)
+{
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_RESET_ORIENTATION_TASK, GthResetOrientationTaskPrivate);
+	self->priv->file_data = NULL;
+}
+
+
+GType
+gth_reset_orientation_task_get_type (void)
+{
+	static GType type = 0;
+
+	if (! type) {
+		GTypeInfo type_info = {
+			sizeof (GthResetOrientationTaskClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) gth_reset_orientation_task_class_init,
+			NULL,
+			NULL,
+			sizeof (GthResetOrientationTask),
+			0,
+			(GInstanceInitFunc) gth_reset_orientation_task_init
+		};
+
+		type = g_type_register_static (GTH_TYPE_TASK,
+					       "GthResetOrientationTask",
+					       &type_info,
+					       0);
+	}
+
+	return type;
+}
+
+
+GthTask *
+gth_reset_orientation_task_new (GthBrowser *browser,
+				GList      *file_list)
+{
+	GthResetOrientationTask *self;
+
+	self = GTH_RESET_ORIENTATION_TASK (g_object_new (GTH_TYPE_RESET_ORIENTATION_TASK, NULL));
+	self->priv->browser = browser;
+	self->priv->file_list = _g_object_list_ref (file_list);
+
+	return (GthTask *) self;
+}
diff --git a/extensions/image_rotation/gth-reset-orientation-task.h b/extensions/image_rotation/gth-reset-orientation-task.h
new file mode 100644
index 0000000..e901f07
--- /dev/null
+++ b/extensions/image_rotation/gth-reset-orientation-task.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2010 The 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GTH_RESET_ORIENTATION_TASK_H
+#define GTH_RESET_ORIENTATION_TASK_H
+
+#include <glib.h>
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_RESET_ORIENTATION_TASK            (gth_reset_orientation_task_get_type ())
+#define GTH_RESET_ORIENTATION_TASK(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_RESET_ORIENTATION_TASK, GthResetOrientationTask))
+#define GTH_RESET_ORIENTATION_TASK_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_RESET_ORIENTATION_TASK, GthResetOrientationTaskClass))
+#define GTH_IS_RESET_ORIENTATION_TASK(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_RESET_ORIENTATION_TASK))
+#define GTH_IS_RESET_ORIENTATION_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_RESET_ORIENTATION_TASK))
+#define GTH_RESET_ORIENTATION_TASK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_RESET_ORIENTATION_TASK, GthResetOrientationTaskClass))
+
+typedef struct _GthResetOrientationTask        GthResetOrientationTask;
+typedef struct _GthResetOrientationTaskClass   GthResetOrientationTaskClass;
+typedef struct _GthResetOrientationTaskPrivate GthResetOrientationTaskPrivate;
+
+struct _GthResetOrientationTask {
+	GthTask __parent;
+	GthResetOrientationTaskPrivate *priv;
+};
+
+struct _GthResetOrientationTaskClass {
+	GthTaskClass __parent;
+};
+
+GType         gth_reset_orientation_task_get_type  (void);
+GthTask *     gth_reset_orientation_task_new       (GthBrowser   *browser,
+						    GList        *file_list /* GFile list */);
+
+G_END_DECLS
+
+#endif /* GTH_RESET_ORIENTATION_TASK_H */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8ce53f9..b9254cd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -296,6 +296,8 @@ extensions/image_rotation/actions.c
 extensions/image_rotation/actions.h
 extensions/image_rotation/callbacks.c
 extensions/image_rotation/callbacks.h
+extensions/image_rotation/gth-reset-orientation-task.c
+extensions/image_rotation/gth-reset-orientation-task.h
 extensions/image_rotation/gth-transform-task.c
 extensions/image_rotation/gth-transform-task.h
 [type: gettext/ini]extensions/image_rotation/image_rotation.extension.in.in



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