app/core/Makefile.am app/core/core-types.h define a simple interface for
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. svn path=/trunk/; revision=24633
This commit is contained in:

committed by
Sven Neumann

parent
3ed00ecbea
commit
e4d64122bb
@ -1,3 +1,12 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2008-01-17 Sven Neumann <sven@gimp.org>
|
2008-01-17 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* app/core/gimpviewable.h: formatting.
|
* app/core/gimpviewable.h: formatting.
|
||||||
|
@ -290,6 +290,8 @@ libappcore_a_sources = \
|
|||||||
gimpstrokeoptions.h \
|
gimpstrokeoptions.h \
|
||||||
gimpsubprogress.c \
|
gimpsubprogress.c \
|
||||||
gimpsubprogress.h \
|
gimpsubprogress.h \
|
||||||
|
gimptagged.c \
|
||||||
|
gimptagged.h \
|
||||||
gimptemplate.c \
|
gimptemplate.c \
|
||||||
gimptemplate.h \
|
gimptemplate.h \
|
||||||
gimptoolinfo.c \
|
gimptoolinfo.c \
|
||||||
|
@ -150,6 +150,7 @@ typedef struct _GimpStrokeDesc GimpStrokeDesc;
|
|||||||
|
|
||||||
typedef struct _GimpPickable GimpPickable; /* dummy typedef */
|
typedef struct _GimpPickable GimpPickable; /* dummy typedef */
|
||||||
typedef struct _GimpProgress GimpProgress; /* dummy typedef */
|
typedef struct _GimpProgress GimpProgress; /* dummy typedef */
|
||||||
|
typedef struct _GimpTagged GimpTagged; /* dummy typedef */
|
||||||
|
|
||||||
|
|
||||||
/* non-object types */
|
/* non-object types */
|
||||||
@ -163,6 +164,13 @@ typedef struct _GimpPaletteEntry GimpPaletteEntry;
|
|||||||
typedef struct _GimpScanConvert GimpScanConvert;
|
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 */
|
/* functions */
|
||||||
|
|
||||||
typedef void (* GimpInitStatusFunc) (const gchar *text1,
|
typedef void (* GimpInitStatusFunc) (const gchar *text1,
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "gimp-utils.h"
|
#include "gimp-utils.h"
|
||||||
#include "gimpdata.h"
|
#include "gimpdata.h"
|
||||||
#include "gimpmarshal.h"
|
#include "gimpmarshal.h"
|
||||||
|
#include "gimptagged.h"
|
||||||
|
|
||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
@ -63,13 +64,14 @@ enum
|
|||||||
|
|
||||||
|
|
||||||
static void gimp_data_class_init (GimpDataClass *klass);
|
static void gimp_data_class_init (GimpDataClass *klass);
|
||||||
static void gimp_data_init (GimpData *data,
|
static void gimp_data_tagged_iface_init (GimpTaggedInterface *iface);
|
||||||
GimpDataClass *data_class);
|
|
||||||
|
|
||||||
static GObject * gimp_data_constructor (GType type,
|
static GObject * gimp_data_constructor (GType type,
|
||||||
guint n_params,
|
guint n_params,
|
||||||
GObjectConstructParam *params);
|
GObjectConstructParam *params);
|
||||||
|
|
||||||
|
static void gimp_data_init (GimpData *data,
|
||||||
|
GimpDataClass *data_class);
|
||||||
static void gimp_data_finalize (GObject *object);
|
static void gimp_data_finalize (GObject *object);
|
||||||
static void gimp_data_set_property (GObject *object,
|
static void gimp_data_set_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
@ -85,6 +87,12 @@ static gint64 gimp_data_get_memsize (GimpObject *object,
|
|||||||
|
|
||||||
static void gimp_data_real_dirty (GimpData *data);
|
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 };
|
static guint data_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
@ -111,9 +119,18 @@ gimp_data_get_type (void)
|
|||||||
(GInstanceInitFunc) gimp_data_init,
|
(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,
|
data_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
|
||||||
"GimpData",
|
"GimpData",
|
||||||
&data_info, 0);
|
&data_info, 0);
|
||||||
|
|
||||||
|
g_type_add_interface_static (data_type, GIMP_TYPE_TAGGED, &tagged_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_type;
|
return data_type;
|
||||||
@ -170,6 +187,14 @@ gimp_data_class_init (GimpDataClass *klass)
|
|||||||
G_PARAM_CONSTRUCT_ONLY));
|
G_PARAM_CONSTRUCT_ONLY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
gimp_data_init (GimpData *data,
|
gimp_data_init (GimpData *data,
|
||||||
GimpDataClass *data_class)
|
GimpDataClass *data_class)
|
||||||
@ -182,6 +207,7 @@ gimp_data_init (GimpData *data,
|
|||||||
data->internal = FALSE;
|
data->internal = FALSE;
|
||||||
data->freeze_count = 0;
|
data->freeze_count = 0;
|
||||||
data->mtime = 0;
|
data->mtime = 0;
|
||||||
|
data->tags = NULL;
|
||||||
|
|
||||||
/* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
|
/* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
|
||||||
* here, because the latter is always GimpDataClass itself
|
* here, because the latter is always GimpDataClass itself
|
||||||
@ -204,6 +230,12 @@ gimp_data_finalize (GObject *object)
|
|||||||
data->filename = NULL;
|
data->filename = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data->tags)
|
||||||
|
{
|
||||||
|
g_list_free (data->tags);
|
||||||
|
data->tags = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +346,53 @@ gimp_data_real_dirty (GimpData *data)
|
|||||||
gimp_object_name_changed (GIMP_OBJECT (data));
|
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:
|
* gimp_data_save:
|
||||||
* @data: object whose contents are to be saved.
|
* @data: object whose contents are to be saved.
|
||||||
|
@ -58,6 +58,8 @@ struct _GimpData
|
|||||||
guint internal : 1;
|
guint internal : 1;
|
||||||
gint freeze_count;
|
gint freeze_count;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
|
|
||||||
|
GList *tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpDataClass
|
struct _GimpDataClass
|
||||||
|
154
app/core/gimptagged.c
Normal file
154
app/core/gimptagged.c
Normal file
@ -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);
|
||||||
|
}
|
62
app/core/gimptagged.h
Normal file
62
app/core/gimptagged.h
Normal file
@ -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__ */
|
Reference in New Issue
Block a user