[Goodies-commits] r6527 - ristretto/branches/ristretto-gio/src

Stephan Arts stephan at xfce.org
Fri Jan 23 00:16:16 CET 2009


Author: stephan
Date: 2009-01-22 23:16:15 +0000 (Thu, 22 Jan 2009)
New Revision: 6527

Added:
   ristretto/branches/ristretto-gio/src/settings.c
   ristretto/branches/ristretto-gio/src/settings.h
Modified:
   ristretto/branches/ristretto-gio/src/Makefile.am
   ristretto/branches/ristretto-gio/src/image.c
   ristretto/branches/ristretto-gio/src/image.h
   ristretto/branches/ristretto-gio/src/main.c
   ristretto/branches/ristretto-gio/src/main_window.c
   ristretto/branches/ristretto-gio/src/main_window_ui.xml
Log:
- Apply patch from Mike Massonnet, to fix language-agnostic EXIF-based rotation
- Add Undo button to UI
- Add Settings Singleton object for loading and saving ristretto settings
- Load and save the accelerator-map



Modified: ristretto/branches/ristretto-gio/src/Makefile.am
===================================================================
--- ristretto/branches/ristretto-gio/src/Makefile.am	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/Makefile.am	2009-01-22 23:16:15 UTC (rev 6527)
@@ -7,6 +7,7 @@
 	image_transformation.c image_transformation.h \
 	image_transform_orientation.c image_transform_orientation.h \
 	picture_viewer.c picture_viewer.h \
+	settings.c settings.h \
 	main_window_ui.h \
 	main_window.c main_window.h \
 	main.c

Modified: ristretto/branches/ristretto-gio/src/image.c
===================================================================
--- ristretto/branches/ristretto-gio/src/image.c	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/image.c	2009-01-22 23:16:15 UTC (rev 6527)
@@ -218,11 +218,10 @@
 
     RsttoImage *image = g_object_new (RSTTO_TYPE_IMAGE, NULL);
     gchar *file_path = g_file_get_path (file);
-    gchar *exif_val = g_new0 (gchar, 20);
     ExifEntry *exif_entry = NULL;
     RsttoImageTransformation *transformation = NULL;
+    RsttoImageOrientation orientation;
 
-
     image->priv->file = file;
     image->priv->exif_data = exif_data_new_from_file (file_path);
     image->priv->thumbnail = NULL;
@@ -231,41 +230,37 @@
     if (image->priv->exif_data) {
         exif_entry = exif_data_get_entry (image->priv->exif_data, EXIF_TAG_ORIENTATION);
     }
-    if (exif_entry)
+    if (exif_entry && exif_entry->data != NULL)
     {
-        exif_entry_get_value(exif_entry, exif_val, 20);
-        if (!strcmp(exif_val, "top - left"))
+        orientation = exif_get_short (exif_entry->data, exif_data_get_byte_order (exif_entry->parent->parent));
+        switch (orientation)
         {
-            transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_NONE);
+            default:
+            case RSTTO_IMAGE_ORIENT_NONE:
+                transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_NONE);
+                break;
+            case RSTTO_IMAGE_ORIENT_90:
+                transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                break;
+            case RSTTO_IMAGE_ORIENT_180:
+                transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
+                break;
+            case RSTTO_IMAGE_ORIENT_270:
+                transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
+                break;
+            case RSTTO_IMAGE_ORIENT_FLIP_HORIZONTAL:
+                transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_NONE);
+                break;
+            case RSTTO_IMAGE_ORIENT_FLIP_VERTICAL:
+                transformation = rstto_image_transform_orientation_new ( TRUE, FALSE, GDK_PIXBUF_ROTATE_NONE);
+                break;
+            case RSTTO_IMAGE_ORIENT_TRANSPOSE:
+                transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                break;
+            case RSTTO_IMAGE_ORIENT_TRANSVERSE:
+                transformation = rstto_image_transform_orientation_new ( TRUE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                break;
         }
-        if (!strcmp(exif_val, "top - right"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_NONE);
-        }
-        if (!strcmp(exif_val, "bottom - left"))
-        {
-            transformation = rstto_image_transform_orientation_new ( TRUE, FALSE, GDK_PIXBUF_ROTATE_NONE);
-        }
-        if (!strcmp(exif_val, "bottom - right"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
-        }
-        if (!strcmp(exif_val, "right - top"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE);
-        }
-        if (!strcmp(exif_val, "left - bottom"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
-        }
-        if (!strcmp(exif_val, "right - bottom"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
-        }
-        if (!strcmp(exif_val, "left - top"))
-        {
-            transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_CLOCKWISE);
-        }
     }
 
     if (transformation)
@@ -273,8 +268,6 @@
         rstto_image_push_transformation (image, G_OBJECT (transformation), NULL);
     }
 
-    g_free (exif_val);
-
     return image;
 }
 

Modified: ristretto/branches/ristretto-gio/src/image.h
===================================================================
--- ristretto/branches/ristretto-gio/src/image.h	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/image.h	2009-01-22 23:16:15 UTC (rev 6527)
@@ -19,6 +19,18 @@
 
 G_BEGIN_DECLS
 
+typedef enum
+{
+  RSTTO_IMAGE_ORIENT_NONE = 1,
+  RSTTO_IMAGE_ORIENT_FLIP_HORIZONTAL,
+  RSTTO_IMAGE_ORIENT_180,
+  RSTTO_IMAGE_ORIENT_FLIP_VERTICAL,
+  RSTTO_IMAGE_ORIENT_TRANSPOSE,
+  RSTTO_IMAGE_ORIENT_90,
+  RSTTO_IMAGE_ORIENT_TRANSVERSE,
+  RSTTO_IMAGE_ORIENT_270,
+} RsttoImageOrientation;
+
 #define RSTTO_TYPE_IMAGE rstto_image_get_type()
 
 #define RSTTO_IMAGE(obj)( \

Modified: ristretto/branches/ristretto-gio/src/main.c
===================================================================
--- ristretto/branches/ristretto-gio/src/main.c	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/main.c	2009-01-22 23:16:15 UTC (rev 6527)
@@ -28,6 +28,7 @@
 
 #include "image.h"
 #include "navigator.h"
+#include "settings.h"
 #include "picture_viewer.h"
 #include "main_window.h"
 
@@ -93,10 +94,10 @@
     }
 
     gtk_window_set_default_icon_name("ristretto");
-    xfce_rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "ristretto/ristrettorc", FALSE);
+    RsttoSettings *settings = rstto_settings_new();
+    rstto_settings_load (settings);
 
     RsttoNavigator *navigator = rstto_navigator_new ();
-    
     GtkWidget *window = rstto_main_window_new (navigator, FALSE);
 
     if (argc > 1)
@@ -117,8 +118,7 @@
 
     gtk_main();
 
-    xfce_rc_flush(xfce_rc);
-    xfce_rc_close(xfce_rc);
+    rstto_settings_save (settings);
 
 
     return 0;

Modified: ristretto/branches/ristretto-gio/src/main_window.c
===================================================================
--- ristretto/branches/ristretto-gio/src/main_window.c	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/main_window.c	2009-01-22 23:16:15 UTC (rev 6527)
@@ -160,6 +160,7 @@
   { "quit", GTK_STOCK_QUIT, N_ ("_Quit"), "<control>Q", N_ ("Quit Ristretto"), G_CALLBACK (cb_rstto_main_window_quit), },
 /* Edit Menu */
   { "edit-menu", NULL, N_ ("_Edit"), NULL, },
+  { "undo", GTK_STOCK_UNDO, N_ ("_Undo"), NULL, NULL, NULL, },
   { "preferences", GTK_STOCK_PREFERENCES, N_ ("_Preferences"), NULL, NULL, G_CALLBACK (cb_rstto_main_window_preferences), },
 /* View Menu */
   { "view-menu", NULL, N_ ("_View"), NULL, },

Modified: ristretto/branches/ristretto-gio/src/main_window_ui.xml
===================================================================
--- ristretto/branches/ristretto-gio/src/main_window_ui.xml	2009-01-22 19:23:19 UTC (rev 6526)
+++ ristretto/branches/ristretto-gio/src/main_window_ui.xml	2009-01-22 23:16:15 UTC (rev 6527)
@@ -17,6 +17,8 @@
             <menuitem action="quit"/>
         </menu>
         <menu action="edit-menu">
+            <menuitem action="undo"/>
+            <separator/>
             <menuitem action="preferences"/>
         </menu>
         <menu action="view-menu">

Added: ristretto/branches/ristretto-gio/src/settings.c
===================================================================
--- ristretto/branches/ristretto-gio/src/settings.c	                        (rev 0)
+++ ristretto/branches/ristretto-gio/src/settings.c	2009-01-22 23:16:15 UTC (rev 6527)
@@ -0,0 +1,171 @@
+/*
+ *  Copyright (c) 2009 Stephan Arts <stephan at xfce.org>
+ *
+ *  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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include "settings.h"
+
+static void
+rstto_settings_init (GObject *);
+static void
+rstto_settings_class_init (GObjectClass *);
+
+static void
+rstto_settings_dispose (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+static RsttoSettings *settings_object;
+
+GType
+rstto_settings_get_type ()
+{
+    static GType rstto_settings_type = 0;
+
+    if (!rstto_settings_type)
+    {
+        static const GTypeInfo rstto_settings_info = 
+        {
+            sizeof (RsttoSettingsClass),
+            (GBaseInitFunc) NULL,
+            (GBaseFinalizeFunc) NULL,
+            (GClassInitFunc) rstto_settings_class_init,
+            (GClassFinalizeFunc) NULL,
+            NULL,
+            sizeof (RsttoSettings),
+            0,
+            (GInstanceInitFunc) rstto_settings_init,
+            NULL
+        };
+
+        rstto_settings_type = g_type_register_static (G_TYPE_OBJECT, "RsttoSettings", &rstto_settings_info, 0);
+    }
+    return rstto_settings_type;
+}
+
+struct _RsttoSettingsPriv
+{
+    gpointer t;
+};
+
+
+static void
+rstto_settings_init (GObject *object)
+{
+    RsttoSettings *settings = RSTTO_SETTINGS (object);
+
+    settings->priv = g_new0 (RsttoSettingsPriv, 1);
+}
+
+
+static void
+rstto_settings_class_init (GObjectClass *object_class)
+{
+    RsttoSettingsClass *settings_class = RSTTO_SETTINGS_CLASS (object_class);
+
+    parent_class = g_type_class_peek_parent (settings_class);
+
+    object_class->dispose = rstto_settings_dispose;
+}
+
+/**
+ * rstto_settings_dispose:
+ * @object:
+ *
+ */
+static void
+rstto_settings_dispose (GObject *object)
+{
+    RsttoSettings *settings = RSTTO_SETTINGS (object);
+
+    if (settings->priv)
+    {
+        g_free (settings->priv);
+        settings->priv = NULL;
+    }
+}
+
+
+
+
+/**
+ * rstto_settings_new:
+ *
+ *
+ * Singleton
+ */
+RsttoSettings *
+rstto_settings_new ()
+{
+    if (settings_object == NULL)
+    {
+        settings_object = g_object_new (RSTTO_TYPE_SETTINGS, NULL);
+    }
+    else
+    {
+        g_object_ref (settings_object);
+    }
+
+    return settings_object;
+}
+
+
+gboolean 
+rstto_settings_load (RsttoSettings *settings)
+{
+    gchar *accelmap_path = NULL;
+
+    accelmap_path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, "ristretto/accels.scm");
+    if (accelmap_path)
+    {
+        gtk_accel_map_load (accelmap_path);
+        g_free (accelmap_path);
+        accelmap_path = NULL;
+    }
+
+    return TRUE;
+}
+
+gboolean
+rstto_settings_save (RsttoSettings *settings)
+{
+    gchar *accelmap_path = NULL;
+    accelmap_path = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "ristretto/accels.scm", TRUE);
+    if (accelmap_path)
+    {
+        gtk_accel_map_save (accelmap_path);
+        g_free (accelmap_path);
+        accelmap_path = NULL;
+    }
+    return TRUE;
+}
+
+void
+rstto_settings_read (RsttoSettings *settings, GValue *value)
+{
+
+}
+
+void
+rstto_settings_write (RsttoSettings *settings, GValue *value)
+{
+
+}

Added: ristretto/branches/ristretto-gio/src/settings.h
===================================================================
--- ristretto/branches/ristretto-gio/src/settings.h	                        (rev 0)
+++ ristretto/branches/ristretto-gio/src/settings.h	2009-01-22 23:16:15 UTC (rev 6527)
@@ -0,0 +1,70 @@
+/*
+ *  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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __RISTRETTO_SETTINGS_H__
+#define __RISTRETTO_SETTINGS_H__
+
+G_BEGIN_DECLS
+
+#define RSTTO_TYPE_SETTINGS rstto_settings_get_type()
+
+#define RSTTO_SETTINGS(obj)( \
+        G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                RSTTO_TYPE_SETTINGS, \
+                RsttoSettings))
+
+#define RSTTO_IS_SETTINGS(obj)( \
+        G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                RSTTO_TYPE_SETTINGS))
+
+#define RSTTO_SETTINGS_CLASS(klass)( \
+        G_TYPE_CHECK_CLASS_CAST ((klass), \
+                RSTTO_TYPE_SETTINGS, \
+                RsttoSettingsClass))
+
+#define RSTTO_IS_SETTINGS_CLASS(klass)( \
+        G_TYPE_CHECK_CLASS_TYPE ((klass), \
+                RSTTO_TYPE_SETTINGS()))
+
+
+typedef struct _RsttoSettings RsttoSettings;
+typedef struct _RsttoSettingsPriv RsttoSettingsPriv;
+
+struct _RsttoSettings
+{
+    GObject parent;
+
+    RsttoSettingsPriv *priv;
+};
+
+typedef struct _RsttoSettingsClass RsttoSettingsClass;
+
+struct _RsttoSettingsClass
+{
+    GObjectClass parent_class;
+};
+
+RsttoSettings *rstto_settings_new ();
+
+gboolean rstto_settings_load (RsttoSettings *settings);
+gboolean rstto_settings_save (RsttoSettings *settings);
+
+void rstto_settings_read (RsttoSettings *settings, GValue *value);
+void rstto_settings_write (RsttoSettings *settings, GValue *value);
+
+G_END_DECLS
+
+#endif /* __RISTRETTO_SETTINGS_H__ */




More information about the Goodies-commits mailing list