gimp r24633 - in trunk: . app/core



Author: neo
Date: Thu Jan 17 10:51:31 2008
New Revision: 24633
URL: http://svn.gnome.org/viewvc/gimp?rev=24633&view=rev

Log:
2008-01-17  Sven Neumann  <sven gimp org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimptagged.[ch]: define a simple interface for tagged
	objects.

	* app/core/gimpdata.[ch]: implement the GimpTagged interface. 


Added:
   trunk/app/core/gimptagged.c   (contents, props changed)
   trunk/app/core/gimptagged.h   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/app/core/Makefile.am
   trunk/app/core/core-types.h
   trunk/app/core/gimpdata.c
   trunk/app/core/gimpdata.h

Modified: trunk/app/core/Makefile.am
==============================================================================
--- trunk/app/core/Makefile.am	(original)
+++ trunk/app/core/Makefile.am	Thu Jan 17 10:51:31 2008
@@ -290,6 +290,8 @@
 	gimpstrokeoptions.h		\
 	gimpsubprogress.c		\
 	gimpsubprogress.h		\
+	gimptagged.c			\
+	gimptagged.h			\
 	gimptemplate.c			\
 	gimptemplate.h			\
 	gimptoolinfo.c			\

Modified: trunk/app/core/core-types.h
==============================================================================
--- trunk/app/core/core-types.h	(original)
+++ trunk/app/core/core-types.h	Thu Jan 17 10:51:31 2008
@@ -150,6 +150,7 @@
 
 typedef struct _GimpPickable        GimpPickable; /* dummy typedef */
 typedef struct _GimpProgress        GimpProgress; /* dummy typedef */
+typedef struct _GimpTagged          GimpTagged;   /* dummy typedef */
 
 
 /*  non-object types  */
@@ -163,6 +164,13 @@
 typedef struct _GimpScanConvert     GimpScanConvert;
 
 
+/*  tags  */
+
+typedef GQuark                      GimpTag;
+#define gimp_tag_new(name)          g_quark_from_string (name)
+#define gimp_tag_get_name(tag)      g_quark_to_string (name)
+
+
 /*  functions  */
 
 typedef void     (* GimpInitStatusFunc)    (const gchar      *text1,

Modified: trunk/app/core/gimpdata.c
==============================================================================
--- trunk/app/core/gimpdata.c	(original)
+++ trunk/app/core/gimpdata.c	Thu Jan 17 10:51:31 2008
@@ -42,6 +42,7 @@
 #include "gimp-utils.h"
 #include "gimpdata.h"
 #include "gimpmarshal.h"
+#include "gimptagged.h"
 
 #include "gimp-intl.h"
 
@@ -62,14 +63,15 @@
 };
 
 
-static void      gimp_data_class_init   (GimpDataClass *klass);
-static void      gimp_data_init         (GimpData      *data,
-                                         GimpDataClass *data_class);
+static void      gimp_data_class_init        (GimpDataClass       *klass);
+static void      gimp_data_tagged_iface_init (GimpTaggedInterface *iface);
 
-static GObject * gimp_data_constructor  (GType                  type,
-                                         guint                  n_params,
-                                         GObjectConstructParam *params);
+static GObject * gimp_data_constructor     (GType                  type,
+                                            guint                  n_params,
+                                            GObjectConstructParam *params);
 
+static void      gimp_data_init         (GimpData      *data,
+                                         GimpDataClass *data_class);
 static void      gimp_data_finalize     (GObject       *object);
 static void      gimp_data_set_property (GObject       *object,
                                          guint          property_id,
@@ -85,6 +87,12 @@
 
 static void      gimp_data_real_dirty   (GimpData      *data);
 
+static gboolean  gimp_data_add_tag      (GimpTagged    *tagged,
+                                         GimpTag        tag);
+static gboolean  gimp_data_remove_tag   (GimpTagged    *tagged,
+                                         GimpTag        tag);
+static GList *   gimp_data_get_tags     (GimpTagged    *tagged);
+
 
 static guint data_signals[LAST_SIGNAL] = { 0 };
 
@@ -111,9 +119,18 @@
         (GInstanceInitFunc) gimp_data_init,
       };
 
+      const GInterfaceInfo tagged_info =
+      {
+        (GInterfaceInitFunc) gimp_data_tagged_iface_init,
+        NULL,           /* interface_finalize */
+        NULL            /* interface_data     */
+      };
+
       data_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
                                           "GimpData",
                                           &data_info, 0);
+
+      g_type_add_interface_static (data_type, GIMP_TYPE_TAGGED, &tagged_info);
   }
 
   return data_type;
@@ -171,6 +188,14 @@
 }
 
 static void
+gimp_data_tagged_iface_init (GimpTaggedInterface *iface)
+{
+  iface->add_tag    = gimp_data_add_tag;
+  iface->remove_tag = gimp_data_remove_tag;
+  iface->get_tags   = gimp_data_get_tags;
+}
+
+static void
 gimp_data_init (GimpData      *data,
                 GimpDataClass *data_class)
 {
@@ -182,6 +207,7 @@
   data->internal     = FALSE;
   data->freeze_count = 0;
   data->mtime        = 0;
+  data->tags         = NULL;
 
   /*  look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
    *  here, because the latter is always GimpDataClass itself
@@ -204,6 +230,12 @@
       data->filename = NULL;
     }
 
+  if (data->tags)
+    {
+      g_list_free (data->tags);
+      data->tags = NULL;
+    }
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -314,6 +346,53 @@
   gimp_object_name_changed (GIMP_OBJECT (data));
 }
 
+static gboolean
+gimp_data_add_tag (GimpTagged *tagged,
+                   GimpTag     tag)
+{
+  GimpData *data = GIMP_DATA (tagged);
+  GList    *list;
+
+  for (list = data->tags; list; list = list->next)
+    {
+      GimpTag this = GPOINTER_TO_UINT (list->data);
+
+      if (this == tag)
+        return FALSE;
+    }
+
+  data->tags = g_list_prepend (data->tags, GUINT_TO_POINTER (tag));
+
+  return TRUE;
+}
+
+static gboolean
+gimp_data_remove_tag (GimpTagged *tagged,
+                      GimpTag     tag)
+{
+  GimpData *data = GIMP_DATA (tagged);
+  GList    *list;
+
+  for (list = data->tags; list; list = list->next)
+    {
+      GimpTag this = GPOINTER_TO_UINT (list->data);
+
+      if (this == tag)
+        {
+          data->tags = g_list_delete_link (data->tags, list);
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+static GList *
+gimp_data_get_tags (GimpTagged *tagged)
+{
+  return GIMP_DATA (tagged)->tags;
+}
+
 /**
  * gimp_data_save:
  * @data:  object whose contents are to be saved.

Modified: trunk/app/core/gimpdata.h
==============================================================================
--- trunk/app/core/gimpdata.h	(original)
+++ trunk/app/core/gimpdata.h	Thu Jan 17 10:51:31 2008
@@ -58,6 +58,8 @@
   guint         internal  : 1;
   gint          freeze_count;
   time_t        mtime;
+
+  GList        *tags;
 };
 
 struct _GimpDataClass

Added: trunk/app/core/gimptagged.c
==============================================================================
--- (empty file)
+++ trunk/app/core/gimptagged.c	Thu Jan 17 10:51:31 2008
@@ -0,0 +1,154 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimptagged.c
+ * Copyright (C) 2008  Sven Neumann <sven gimp 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 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-object.h>
+
+#include "core-types.h"
+
+#include "gimpmarshal.h"
+#include "gimptagged.h"
+
+
+enum
+{
+  TAG_ADDED,
+  TAG_REMOVED,
+  LAST_SIGNAL
+};
+
+static void  gimp_tagged_base_init (gpointer klass);
+
+static guint gimp_tagged_signals[LAST_SIGNAL] = { 0, };
+
+
+GType
+gimp_tagged_interface_get_type (void)
+{
+  static GType tagged_iface_type = 0;
+
+  if (! tagged_iface_type)
+    {
+      const GTypeInfo tagged_iface_info =
+      {
+        sizeof (GimpTaggedInterface),
+        gimp_tagged_base_init,
+        (GBaseFinalizeFunc) NULL,
+      };
+
+      tagged_iface_type = g_type_register_static (G_TYPE_INTERFACE,
+                                                  "GimpTaggedInterface",
+                                                  &tagged_iface_info,
+                                                  0);
+   }
+
+  return tagged_iface_type;
+}
+
+static void
+gimp_tagged_base_init (gpointer klass)
+{
+  static gboolean initialized = FALSE;
+
+  if (! initialized)
+    {
+      gimp_tagged_signals[TAG_ADDED] =
+        g_signal_new ("tag-added",
+                      GIMP_TYPE_TAGGED,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (GimpTaggedInterface, tag_added),
+                      NULL, NULL,
+                      gimp_marshal_VOID__INT,
+                      G_TYPE_NONE, 1,
+                      G_TYPE_INT);
+      gimp_tagged_signals[TAG_REMOVED] =
+        g_signal_new ("tag-removed",
+                      GIMP_TYPE_TAGGED,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (GimpTaggedInterface, tag_removed),
+                      NULL, NULL,
+                      gimp_marshal_VOID__INT,
+                      G_TYPE_NONE, 1,
+                      G_TYPE_INT);
+
+      initialized = TRUE;
+    }
+}
+
+/**
+ * gimp_tagged_add_tag:
+ * @tagged: an object that implements the %GimpTagged interface
+ * @tag:    a %GimpTag
+ *
+ * Adds @tag to the @tagged object. The GimpTagged::tag-added signal
+ * is emitted if and only if the @tag was not already assigned to this
+ * object.
+ **/
+void
+gimp_tagged_add_tag (GimpTagged    *tagged,
+                     const GimpTag  tag)
+{
+  g_return_if_fail (GIMP_IS_TAGGED (tagged));
+
+  if (GIMP_TAGGED_GET_INTERFACE (tagged)->add_tag (tagged, tag))
+    {
+      g_signal_emit (tagged, gimp_tagged_signals[TAG_ADDED], 0, tag);
+    }
+}
+
+/**
+ * gimp_tagged_remove_tag:
+ * @tagged: an object that implements the %GimpTagged interface
+ * @tag:    a %GimpTag
+ *
+ * Removes @tag from the @tagged object. The GimpTagged::tag-removed
+ * signal is emitted if and only if the @tag was actually assigned to
+ * this object.
+ **/
+void
+gimp_tagged_remove_tag (GimpTagged *tagged,
+                        GimpTag     tag)
+{
+  g_return_if_fail (GIMP_IS_TAGGED (tagged));
+
+  if (GIMP_TAGGED_GET_INTERFACE (tagged)->remove_tag (tagged, tag))
+    {
+      g_signal_emit (tagged, gimp_tagged_signals[TAG_REMOVED], 0, tag);
+    }
+}
+
+/**
+ * gimp_tagged_get_tags:
+ * @tagged: an object that implements the %GimpTagged interface
+ *
+ * Returns the list of tags assigned to this object. The returned %GList
+ * is owned by the @tagged object and must not be modified or destroyed.
+ *
+ * Return value: a list of tags
+ **/
+GList *
+gimp_tagged_get_get_tags (GimpTagged *tagged)
+{
+  g_return_val_if_fail (GIMP_IS_TAGGED (tagged), NULL);
+
+  return GIMP_TAGGED_GET_INTERFACE (tagged)->get_tags (tagged);
+}

Added: trunk/app/core/gimptagged.h
==============================================================================
--- (empty file)
+++ trunk/app/core/gimptagged.h	Thu Jan 17 10:51:31 2008
@@ -0,0 +1,62 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
+ *
+ * gimptagged.h
+ * Copyright (C) 2008  Sven Neumann <sven gimp 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 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 __GIMP_TAGGED_H__
+#define __GIMP_TAGGED_H__
+
+
+#define GIMP_TYPE_TAGGED               (gimp_tagged_interface_get_type ())
+#define GIMP_IS_TAGGED(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TAGGED))
+#define GIMP_TAGGED(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TAGGED, GimpTagged))
+#define GIMP_TAGGED_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GIMP_TYPE_TAGGED, GimpTaggedInterface))
+
+
+typedef struct _GimpTaggedInterface GimpTaggedInterface;
+
+struct _GimpTaggedInterface
+{
+  GTypeInterface base_iface;
+
+  /*  signals            */
+  void       (* tag_added)   (GimpTagged *tagged,
+                              GimpTag     tag);
+  void       (* tag_removed) (GimpTagged *tagged,
+                              GimpTag     tag);
+
+  /*  virtual functions  */
+  gboolean   (* add_tag)     (GimpTagged *tagged,
+                              GimpTag     tag);
+  gboolean   (* remove_tag)  (GimpTagged *tagged,
+                              GimpTag     tag);
+  GList    * (* get_tags)    (GimpTagged *tagged);
+};
+
+
+GType      gimp_tagged_interface_get_type (void) G_GNUC_CONST;
+
+void       gimp_tagged_add_tag            (GimpTagged *tagged,
+                                           GimpTag     tag);
+void       gimp_tagged_remove_tag         (GimpTagged *tagged,
+                                           GimpTag     tag);
+GList    * gimp_tagged_get_get_tags       (GimpTagged *tagged);
+
+
+#endif  /* __GIMP_TAGGED_H__ */



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