diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-11-02 06:07:46 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-11-02 06:07:46 +0800 |
commit | 9bfc63718a9752a4e55cf03f5440dd82df63a758 (patch) | |
tree | d2529c3babf3bdaab3398a6cb308001cf1287f92 | |
parent | fc0d5a9556b9f1ed0aa1514dd26b6b737c495a1b (diff) | |
download | gsoc2013-evolution-9bfc63718a9752a4e55cf03f5440dd82df63a758.tar.gz gsoc2013-evolution-9bfc63718a9752a4e55cf03f5440dd82df63a758.tar.zst gsoc2013-evolution-9bfc63718a9752a4e55cf03f5440dd82df63a758.zip |
Ported to GObject.
2002-11-01 Jeffrey Stedfast <fejj@ximian.com>
* filter-element.c: Ported to GObject.
* filter-input.c: Same.
* filter-code.c: This too.
* filter-colour.c: And this.
svn path=/trunk/; revision=18492
-rw-r--r-- | filter/ChangeLog | 10 | ||||
-rw-r--r-- | filter/filter-code.c | 87 | ||||
-rw-r--r-- | filter/filter-code.h | 27 | ||||
-rw-r--r-- | filter/filter-colour.c | 168 | ||||
-rw-r--r-- | filter/filter-colour.h | 34 | ||||
-rw-r--r-- | filter/filter-element.c | 136 | ||||
-rw-r--r-- | filter/filter-element.h | 57 | ||||
-rw-r--r-- | filter/filter-input.c | 163 | ||||
-rw-r--r-- | filter/filter-input.h | 35 |
9 files changed, 362 insertions, 355 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 28c3cf5812..3f2da28ff4 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,13 @@ +2002-11-01 Jeffrey Stedfast <fejj@ximian.com> + + * filter-element.c: Ported to GObject. + + * filter-input.c: Same. + + * filter-code.c: This too. + + * filter-colour.c: And this. + 2002-10-30 Dan Winship <danw@ximian.com> * rule-editor.c (rule_add): Adjust default rule editor size to diff --git a/filter/filter-code.c b/filter/filter-code.c index eb4de2f374..11739a318d 100644 --- a/filter/filter-code.c +++ b/filter/filter-code.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,76 +20,76 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif #include "filter-code.h" -static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff); -static void format_sexp(FilterElement *, GString *); +static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff); +static void format_sexp (FilterElement *, GString *); + +static void filter_code_class_init (FilterCodeClass *class); +static void filter_code_init (FilterCode *fc); +static void filter_code_finalise (GObject *obj); -static void filter_code_class_init (FilterCodeClass *class); -static void filter_code_init (FilterCode *gspaper); -static void filter_code_finalise (GtkObject *obj); static FilterInputClass *parent_class; -guint + +GType filter_code_get_type (void) { - static guint type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterCode", - sizeof(FilterCode), - sizeof(FilterCodeClass), - (GtkClassInitFunc)filter_code_class_init, - (GtkObjectInitFunc)filter_code_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterCodeClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_code_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterCode), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_code_init, }; - type = gtk_type_unique(filter_input_get_type (), &type_info); + type = g_type_register_static (FILTER_TYPE_INPUT, "FilterCode", &info, 0); } return type; } static void -filter_code_class_init (FilterCodeClass *class) +filter_code_class_init (FilterCodeClass *klass) { - GtkObjectClass *object_class; - FilterElementClass *filter_element = (FilterElementClass *)class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); + + parent_class = g_type_class_ref (FILTER_TYPE_INPUT); - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(filter_input_get_type ()); - - filter_element->build_code = build_code; - filter_element->format_sexp = format_sexp; - object_class->finalize = filter_code_finalise; + /* override methods */ - + fe_class->build_code = build_code; + fe_class->format_sexp = format_sexp; } static void -filter_code_init (FilterCode *o) +filter_code_init (FilterCode *fc) { - ((FilterInput *)o)->type = xmlStrdup("code"); + ((FilterInput *) fc)->type = xmlStrdup ("code"); } static void -filter_code_finalise(GtkObject *obj) +filter_code_finalise (GObject *obj) { - FilterCode *o = (FilterCode *)obj; - - o = o; - - ((GtkObjectClass *)(parent_class))->finalize(obj); + G_OBJECT_CLASS (parent_class)->finalize (obj); } + /** * filter_code_new: * @@ -96,18 +98,18 @@ filter_code_finalise(GtkObject *obj) * Return value: A new #FilterCode object. **/ FilterCode * -filter_code_new(void) +filter_code_new (void) { - FilterCode *o = (FilterCode *)gtk_type_new(filter_code_get_type ()); - return o; + return (FilterCode *) g_object_new (FILTER_TYPE_CODE, NULL, NULL); } /* here, the string IS the code */ -static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff) +static void +build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) { GList *l; FilterInput *fi = (FilterInput *)fe; - + l = fi->values; while (l) { g_string_append(out, (char *)l->data); @@ -116,7 +118,8 @@ static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff) } /* and we have no value */ -static void format_sexp(FilterElement *fe, GString *out) +static void +format_sexp (FilterElement *fe, GString *out) { - return; + ; } diff --git a/filter/filter-code.h b/filter/filter-code.h index 3f640fe909..2d590279ee 100644 --- a/filter/filter-code.h +++ b/filter/filter-code.h @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,34 +20,37 @@ * Boston, MA 02111-1307, USA. */ + #ifndef _FILTER_CODE_H #define _FILTER_CODE_H #include "filter-input.h" -#define FILTER_CODE(obj) GTK_CHECK_CAST (obj, filter_code_get_type (), FilterCode) -#define FILTER_CODE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_code_get_type (), FilterCodeClass) -#define IS_FILTER_CODE(obj) GTK_CHECK_TYPE (obj, filter_code_get_type ()) +#define FILTER_TYPE_CODE (filter_code_get_type ()) +#define FILTER_CODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_CODE, FilterCode)) +#define FILTER_CODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_CODE, FilterCodeClass)) +#define IS_FILTER_CODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_CODE)) +#define IS_FILTER_CODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_CODE)) +#define FILTER_CODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_CODE, FilterCodeClass)) -typedef struct _FilterCode FilterCode; +typedef struct _FilterCode FilterCode; typedef struct _FilterCodeClass FilterCodeClass; struct _FilterCode { - FilterInput parent; + FilterInput parent_object; }; struct _FilterCodeClass { FilterInputClass parent_class; - + /* virtual methods */ - + /* signals */ }; -guint filter_code_get_type (void); -FilterCode *filter_code_new (void); +GType filter_code_get_type (void); +FilterCode *filter_code_new (void); /* methods */ #endif /* ! _FILTER_CODE_H */ - diff --git a/filter/filter-colour.c b/filter/filter-colour.c index 2a3f68b887..09cc04115d 100644 --- a/filter/filter-colour.c +++ b/filter/filter-colour.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -30,92 +33,76 @@ #define d(x) -static int colour_eq(FilterElement *fe, FilterElement *cm); -static void xml_create(FilterElement *fe, xmlNodePtr node); -static xmlNodePtr xml_encode(FilterElement *fe); -static int xml_decode(FilterElement *fe, xmlNodePtr node); -static GtkWidget *get_widget(FilterElement *fe); -static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff); -static void format_sexp(FilterElement *, GString *); - -static void filter_colour_class_init (FilterColourClass *class); -static void filter_colour_init (FilterColour *gspaper); -static void filter_colour_finalise (GtkObject *obj); +static int colour_eq (FilterElement *fe, FilterElement *cm); +static void xml_create (FilterElement *fe, xmlNodePtr node); +static xmlNodePtr xml_encode (FilterElement *fe); +static int xml_decode (FilterElement *fe, xmlNodePtr node); +static GtkWidget *get_widget (FilterElement *fe); +static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff); +static void format_sexp (FilterElement *, GString *); -#define _PRIVATE(x) (((FilterColour *)(x))->priv) +static void filter_colour_class_init (FilterColourClass *klass); +static void filter_colour_init (FilterColour *fc); +static void filter_colour_finalise (GObject *obj); -struct _FilterColourPrivate { -}; static FilterElementClass *parent_class; -enum { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; -guint +GType filter_colour_get_type (void) { - static guint type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterColour", - sizeof(FilterColour), - sizeof(FilterColourClass), - (GtkClassInitFunc)filter_colour_class_init, - (GtkObjectInitFunc)filter_colour_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterColourClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_colour_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterColour), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_colour_init, }; - type = gtk_type_unique(filter_element_get_type (), &type_info); + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterColour", &info, 0); } return type; } static void -filter_colour_class_init (FilterColourClass *class) +filter_colour_class_init (FilterColourClass *klass) { - GtkObjectClass *object_class; - FilterElementClass *filter_element = (FilterElementClass *)class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); + + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(filter_element_get_type ()); - object_class->finalize = filter_colour_finalise; - + /* override methods */ - filter_element->eq = colour_eq; - filter_element->xml_create = xml_create; - filter_element->xml_encode = xml_encode; - filter_element->xml_decode = xml_decode; - filter_element->get_widget = get_widget; - filter_element->build_code = build_code; - filter_element->format_sexp = format_sexp; - - /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + fe_class->eq = colour_eq; + fe_class->xml_create = xml_create; + fe_class->xml_encode = xml_encode; + fe_class->xml_decode = xml_decode; + fe_class->get_widget = get_widget; + fe_class->build_code = build_code; + fe_class->format_sexp = format_sexp; } static void -filter_colour_init (FilterColour *o) +filter_colour_init (FilterColour *fc) { - o->priv = g_malloc0(sizeof(*o->priv)); + ; } static void -filter_colour_finalise(GtkObject *obj) +filter_colour_finalise (GObject *obj) { - FilterColour *o = (FilterColour *)obj; - - o = o; - - ((GtkObjectClass *)(parent_class))->finalize(obj); + G_OBJECT_CLASS (parent_class)->finalize (obj); } /** @@ -126,43 +113,42 @@ filter_colour_finalise(GtkObject *obj) * Return value: A new #FilterColour object. **/ FilterColour * -filter_colour_new(void) +filter_colour_new (void) { - FilterColour *o = (FilterColour *)gtk_type_new(filter_colour_get_type ()); - return o; + return (FilterColour *) g_object_new (FILTER_TYPE_COLOUR, NULL, NULL); } static int -colour_eq(FilterElement *fe, FilterElement *cm) +colour_eq (FilterElement *fe, FilterElement *cm) { FilterColour *fc = (FilterColour *)fe, *cc = (FilterColour *)cm; - - return ((FilterElementClass *)(parent_class))->eq(fe, cm) + + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) && fc->r == cc->r && fc->g == cc->g && fc->b == cc->b && fc->a == cc->a; } -static void xml_create(FilterElement *fe, xmlNodePtr node) +static void +xml_create (FilterElement *fe, xmlNodePtr node) { - /*FilterColour *fc = (FilterColour *)fe;*/ - /* parent implementation */ - ((FilterElementClass *)(parent_class))->xml_create(fe, node); + FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); } -static xmlNodePtr xml_encode(FilterElement *fe) +static xmlNodePtr +xml_encode (FilterElement *fe) { xmlNodePtr value; FilterColour *fc = (FilterColour *)fe; char hex[16]; - + d(printf("Encoding colour as xml\n")); value = xmlNewNode(NULL, "value"); xmlSetProp(value, "name", fe->name); xmlSetProp(value, "type", "colour"); - + sprintf(hex, "%04x", fc->r); xmlSetProp(value, "red", hex); sprintf(hex, "%04x", fc->g); @@ -171,16 +157,16 @@ static xmlNodePtr xml_encode(FilterElement *fe) xmlSetProp(value, "blue", hex); sprintf(hex, "%04x", fc->a); xmlSetProp(value, "alpha", hex); - + return value; } static guint16 -get_value(xmlNodePtr node, char *name) +get_value (xmlNodePtr node, char *name) { unsigned int ret; char *value; - + value = xmlGetProp(node, name); sscanf(value, "%04x", &ret); xmlFree(value); @@ -188,21 +174,23 @@ get_value(xmlNodePtr node, char *name) } -static int xml_decode(FilterElement *fe, xmlNodePtr node) +static int +xml_decode (FilterElement *fe, xmlNodePtr node) { FilterColour *fc = (FilterColour *)fe; - + xmlFree (fe->name); fe->name = xmlGetProp(node, "name"); fc->r = get_value(node, "red"); fc->g = get_value(node, "green"); fc->b = get_value(node, "blue"); fc->a = get_value(node, "alpha"); - + return 0; } -static void set_colour(GnomeColorPicker *cp, guint r, guint g, guint b, guint a, FilterColour *fc) +static void +set_colour (GnomeColorPicker *cp, guint r, guint g, guint b, guint a, FilterColour *fc) { fc->r = r; fc->g = g; @@ -210,29 +198,33 @@ static void set_colour(GnomeColorPicker *cp, guint r, guint g, guint b, guint a, fc->a = a; } -static GtkWidget *get_widget(FilterElement *fe) +static GtkWidget * +get_widget (FilterElement *fe) { FilterColour *fc = (FilterColour *)fe; GnomeColorPicker *cp; - + cp = (GnomeColorPicker *)gnome_color_picker_new(); gnome_color_picker_set_i16(cp, fc->r, fc->g, fc->b, fc->a); gtk_widget_show((GtkWidget *)cp); - gtk_signal_connect((GtkObject *)cp, "color_set", set_colour, fe); - return (GtkWidget *)cp; + g_signal_connect (cp, "color_set", set_colour, fe); + + return (GtkWidget *) cp; } -static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff) +static void +build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) { return; } -static void format_sexp(FilterElement *fe, GString *out) +static void +format_sexp (FilterElement *fe, GString *out) { - char *str; FilterColour *fc = (FilterColour *)fe; - - str =g_strdup_printf("rgb:%04x/%04x/%04x", fc->r, fc->g, fc->b); - e_sexp_encode_string(out, str); - g_free(str); + char *str; + + str = g_strdup_printf ("rgb:%04x/%04x/%04x", fc->r, fc->g, fc->b); + e_sexp_encode_string (out, str); + g_free (str); } diff --git a/filter/filter-colour.h b/filter/filter-colour.h index 95ca2a4249..9e22a2021f 100644 --- a/filter/filter-colour.h +++ b/filter/filter-colour.h @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,37 +20,39 @@ * Boston, MA 02111-1307, USA. */ + #ifndef _FILTER_COLOUR_H #define _FILTER_COLOUR_H #include "filter-element.h" -#define FILTER_COLOUR(obj) GTK_CHECK_CAST (obj, filter_colour_get_type (), FilterColour) -#define FILTER_COLOUR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_colour_get_type (), FilterColourClass) -#define IS_FILTER_COLOUR(obj) GTK_CHECK_TYPE (obj, filter_colour_get_type ()) +#define FILTER_TYPE_COLOUR (filter_colour_get_type ()) +#define FILTER_COLOUR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_COLOUR, FilterColour)) +#define FILTER_COLOUR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_COLOUR, FilterColourClass)) +#define IS_FILTER_COLOUR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_COLOUR)) +#define IS_FILTER_COLOUR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_COLOUR)) +#define FILTER_COLOUR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_COLOUR, FilterColourClass)) -typedef struct _FilterColour FilterColour; -typedef struct _FilterColourClass FilterColourClass; +typedef struct _FilterColour FilterColour; +typedef struct _FilterColourClass FilterColourClass; struct _FilterColour { - FilterElement parent; - struct _FilterColourPrivate *priv; - - guint16 r,g,b,a; + FilterElement parent_object; + + guint16 r, g, b, a; }; struct _FilterColourClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; -guint filter_colour_get_type (void); -FilterColour *filter_colour_new (void); +GType filter_colour_get_type (void); +FilterColour *filter_colour_new (void); /* methods */ #endif /* ! _FILTER_COLOUR_H */ - diff --git a/filter/filter-element.c b/filter/filter-element.c index 3da614f065..22b9b3c6a8 100644 --- a/filter/filter-element.c +++ b/filter/filter-element.c @@ -3,6 +3,7 @@ * Copyright (C) 2000 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -19,13 +20,13 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <string.h> #include <stdlib.h> -#include <gtk/gtktypeutils.h> #include "filter-element.h" #include "filter-input.h" @@ -45,63 +46,56 @@ static int element_eq(FilterElement *fe, FilterElement *cm); static void xml_create(FilterElement *fe, xmlNodePtr node); static FilterElement *clone(FilterElement *fe); -static void filter_element_class_init (FilterElementClass *class); -static void filter_element_init (FilterElement *gspaper); -static void filter_element_finalise (GtkObject *obj); +static void filter_element_class_init (FilterElementClass *klass); +static void filter_element_init (FilterElement *fe); +static void filter_element_finalise (GObject *obj); -static GtkObjectClass *parent_class; -enum { - LAST_SIGNAL -}; +static GObjectClass *parent_class; -static guint signals[LAST_SIGNAL] = { 0 }; -GtkType +GType filter_element_get_type (void) { - static GtkType type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterElement", - sizeof(FilterElement), - sizeof(FilterElementClass), - (GtkClassInitFunc)filter_element_class_init, - (GtkObjectInitFunc)filter_element_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterElementClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_element_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterElement), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_element_init, }; - type = gtk_type_unique(gtk_object_get_type (), &type_info); + type = g_type_register_static (G_TYPE_OBJECT, "FilterElement", &info, 0); } return type; } static void -filter_element_class_init (FilterElementClass *class) +filter_element_class_init (FilterElementClass *klass) { - GtkObjectClass *object_class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_ref (G_TYPE_OBJECT); - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class (gtk_object_get_type ()); - object_class->finalize = filter_element_finalise; - + /* override methods */ - class->validate = validate; - class->eq = element_eq; - class->xml_create = xml_create; - class->clone = clone; - - /* signals */ - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + klass->validate = validate; + klass->eq = element_eq; + klass->xml_create = xml_create; + klass->clone = clone; } static void -filter_element_init (FilterElement *o) +filter_element_init (FilterElement *fe) { ; } @@ -110,10 +104,10 @@ static void filter_element_finalise (GtkObject *obj) { FilterElement *o = (FilterElement *)obj; - - xmlFree(o->name); - - ((GtkObjectClass *)(parent_class))->finalize(obj); + + xmlFree (o->name); + + G_OBJECT_CLASS (parent_class)->finalize (obj); } /** @@ -126,21 +120,22 @@ filter_element_finalise (GtkObject *obj) FilterElement * filter_element_new (void) { - FilterElement *o = (FilterElement *)gtk_type_new(filter_element_get_type ()); - return o; + return (FilterElement *) g_object_new (FILTER_TYPE_ELEMENT, NULL, NULL); } gboolean filter_element_validate (FilterElement *fe) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->validate (fe); + return FILTER_ELEMENT_GET_CLASS (fe)->validate (fe); } int -filter_element_eq(FilterElement *fe, FilterElement *cm) +filter_element_eq (FilterElement *fe, FilterElement *cm) { - return ((GtkObject *)fe)->klass == ((GtkObject *)cm)->klass - && ((FilterElementClass *)((GtkObject *)fe)->klass)->eq(fe, cm); + FilterElementClass *klass; + + klass = FILTER_ELEMENT_GET_CLASS (fe); + return (klass == FILTER_ELEMENT_GET_CLASS (cm)) && klass->eq (fe, cm); } /** @@ -154,7 +149,7 @@ filter_element_eq(FilterElement *fe, FilterElement *cm) void filter_element_xml_create (FilterElement *fe, xmlNodePtr node) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->xml_create(fe, node); + return FILTER_ELEMENT_GET_CLASS (fe)->xml_create (fe, node); } /** @@ -168,7 +163,7 @@ filter_element_xml_create (FilterElement *fe, xmlNodePtr node) xmlNodePtr filter_element_xml_encode (FilterElement *fe) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->xml_encode(fe); + return FILTER_ELEMENT_GET_CLASS (fe)->xml_encode (fe); } /** @@ -183,7 +178,7 @@ filter_element_xml_encode (FilterElement *fe) int filter_element_xml_decode (FilterElement *fe, xmlNodePtr node) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->xml_decode(fe, node); + return FILTER_ELEMENT_GET_CLASS (fe)->xml_decode (fe, node); } /** @@ -197,7 +192,7 @@ filter_element_xml_decode (FilterElement *fe, xmlNodePtr node) FilterElement * filter_element_clone (FilterElement *fe) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->clone(fe); + return FILTER_ELEMENT_GET_CLASS (fe)->clone (fe); } /** @@ -212,7 +207,7 @@ filter_element_clone (FilterElement *fe) GtkWidget * filter_element_get_widget (FilterElement *fe) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->get_widget(fe); + return FILTER_ELEMENT_GET_CLASS (fe)->get_widget (fe); } /** @@ -226,7 +221,7 @@ filter_element_get_widget (FilterElement *fe) void filter_element_build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->build_code(fe, out, ff); + return FILTER_ELEMENT_GET_CLASS (fe)->build_code (fe, out, ff); } /** @@ -240,7 +235,7 @@ filter_element_build_code (FilterElement *fe, GString *out, struct _FilterPart * void filter_element_format_sexp (FilterElement *fe, GString *out) { - return ((FilterElementClass *)((GtkObject *)fe)->klass)->format_sexp(fe, out); + return FILTER_ELEMENT_GET_CLASS (fe)->format_sexp (fe, out); } /** @@ -256,30 +251,30 @@ filter_element_new_type_name (const char *type) { if (type == NULL) return NULL; - + if (!strcmp (type, "string")) { - return (FilterElement *)filter_input_new (); + return (FilterElement *) filter_input_new (); } else if (!strcmp (type, "folder")) { - return (FilterElement *)filter_folder_new (); + return (FilterElement *) filter_folder_new (); } else if (!strcmp (type, "address")) { /* FIXME: temporary ... need real address type */ - return (FilterElement *)filter_input_new_type_name (type); + return (FilterElement *) filter_input_new_type_name (type); } else if (!strcmp (type, "code")) { - return (FilterElement *)filter_code_new (); + return (FilterElement *) filter_code_new (); } else if (!strcmp (type, "colour")) { - return (FilterElement *)filter_colour_new (); + return (FilterElement *) filter_colour_new (); } else if (!strcmp (type, "optionlist") || !strcmp (type, "system-flag")) { - return (FilterElement *)filter_option_new (); + return (FilterElement *) filter_option_new (); } else if (!strcmp (type, "datespec")) { - return (FilterElement *)filter_datespec_new (); + return (FilterElement *) filter_datespec_new (); } else if (!strcmp (type, "score")) { - return (FilterElement *)filter_int_new_type("score", -3, 3); + return (FilterElement *) filter_int_new_type("score", -3, 3); } else if (!strcmp (type, "integer")) { - return (FilterElement *)filter_int_new (); + return (FilterElement *) filter_int_new (); } else if (!strcmp (type, "regex")) { - return (FilterElement *)filter_input_new_type_name (type); + return (FilterElement *) filter_input_new_type_name (type); } else if (!strcmp (type, "source")) { - return (FilterElement *)filter_source_new (); + return (FilterElement *) filter_source_new (); } else if (!strcmp (type, "command")) { return (FilterElement *) filter_file_new_type_name (type); } else if (!strcmp (type, "file")) { @@ -288,7 +283,7 @@ filter_element_new_type_name (const char *type) return (FilterElement *) filter_label_new (); } else { g_warning("Unknown filter type '%s'", type); - return 0; + return NULL; } } @@ -306,9 +301,9 @@ validate (FilterElement *fe) } static int -element_eq(FilterElement *fe, FilterElement *cm) +element_eq (FilterElement *fe, FilterElement *cm) { - return ((fe->name && cm->name && strcmp(fe->name, cm->name) == 0) + return ((fe->name && cm->name && strcmp (fe->name, cm->name) == 0) || (fe->name == NULL && cm->name == NULL)); } @@ -323,8 +318,8 @@ clone (FilterElement *fe) { xmlNodePtr node; FilterElement *new; - - new = (FilterElement *)gtk_type_new (GTK_OBJECT (fe)->klass->type); + + new = (FilterElement *) g_object_new (G_OBJECT_TYPE (fe), NULL, NULL); node = filter_element_xml_encode (fe); filter_element_xml_decode (new, node); xmlFreeNodeList (node); @@ -334,7 +329,7 @@ clone (FilterElement *fe) /* only copies the value, not the name/type */ void -filter_element_copy_value(FilterElement *de, FilterElement *se) +filter_element_copy_value (FilterElement *de, FilterElement *se) { /* bit of a hack, but saves having to do the same in each type ? */ @@ -388,4 +383,3 @@ filter_element_copy_value(FilterElement *de, FilterElement *se) } } } - diff --git a/filter/filter-element.h b/filter/filter-element.h index 235ff38cde..c05d9f63a6 100644 --- a/filter/filter-element.h +++ b/filter/filter-element.h @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -21,21 +23,25 @@ #ifndef _FILTER_ELEMENT_H #define _FILTER_ELEMENT_H -#include <gtk/gtkobject.h> +#include <glib.h> +#include <glib-object.h> #include <gtk/gtkwidget.h> #include <gnome-xml/parser.h> #include <gnome-xml/xmlmemory.h> -#define FILTER_ELEMENT(obj) GTK_CHECK_CAST (obj, filter_element_get_type (), FilterElement) -#define FILTER_ELEMENT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_element_get_type (), FilterElementClass) -#define IS_FILTER_ELEMENT(obj) GTK_CHECK_TYPE (obj, filter_element_get_type ()) +#define FILTER_TYPE_ELEMENT (filter_element_get_type ()) +#define FILTER_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_ELEMENT, FilterElement)) +#define FILTER_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_ELEMENT, FilterElementClass)) +#define IS_FILTER_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_ELEMENT)) +#define IS_FILTER_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_ELEMENT)) +#define FILTER_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_ELEMENT, FilterElementClass)) -typedef struct _FilterElement FilterElement; -typedef struct _FilterElementClass FilterElementClass; +typedef struct _FilterElement FilterElement; +typedef struct _FilterElementClass FilterElementClass; struct _FilterElement { - GtkObject parent; - + GObject parent_object; + char *name; gpointer data; }; @@ -43,26 +49,26 @@ struct _FilterElement { struct _FilterPart; struct _FilterElementClass { - GtkObjectClass parent_class; - + GObjectClass parent_class; + /* virtual methods */ - gboolean (*validate)(FilterElement *fe); - int (*eq)(FilterElement *fe, FilterElement *cm); - - void (*xml_create)(FilterElement *, xmlNodePtr); - xmlNodePtr (*xml_encode)(FilterElement *); - int (*xml_decode)(FilterElement *, xmlNodePtr); - - FilterElement *(*clone)(FilterElement *fe); - - GtkWidget *(*get_widget)(FilterElement *); - void (*build_code)(FilterElement *, GString *, struct _FilterPart *ff); - void (*format_sexp)(FilterElement *, GString *); - + gboolean (*validate) (FilterElement *fe); + int (*eq) (FilterElement *fe, FilterElement *cm); + + void (*xml_create) (FilterElement *, xmlNodePtr); + xmlNodePtr (*xml_encode) (FilterElement *); + int (*xml_decode) (FilterElement *, xmlNodePtr); + + FilterElement *(*clone) (FilterElement *fe); + + GtkWidget *(*get_widget) (FilterElement *); + void (*build_code) (FilterElement *, GString *, struct _FilterPart *ff); + void (*format_sexp) (FilterElement *, GString *); + /* signals */ }; -GtkType filter_element_get_type (void); +GType filter_element_get_type (void); FilterElement *filter_element_new (void); FilterElement *filter_element_new_type_name (const char *type); @@ -85,4 +91,3 @@ void filter_element_build_code (FilterElement *fe, GString *out, struct _Filter void filter_element_format_sexp (FilterElement *fe, GString *out); #endif /* ! _FILTER_ELEMENT_H */ - diff --git a/filter/filter-input.c b/filter/filter-input.c index 9be03e66c1..693c56fef0 100644 --- a/filter/filter-input.c +++ b/filter/filter-input.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -25,9 +28,8 @@ #include <string.h> #include <sys/types.h> #include <regex.h> -#include <gtk/gtkobject.h> -#include <gtk/gtkwidget.h> +#include <gtk/gtkwidget.h> #include <libgnome/gnome-defs.h> #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-dialog.h> @@ -40,97 +42,85 @@ #define d(x) static gboolean validate (FilterElement *fe); -static int input_eq(FilterElement *fe, FilterElement *cm); -static void xml_create(FilterElement *fe, xmlNodePtr node); -static xmlNodePtr xml_encode(FilterElement *fe); -static int xml_decode(FilterElement *fe, xmlNodePtr node); -static GtkWidget *get_widget(FilterElement *fe); -static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff); -static void format_sexp(FilterElement *, GString *); - -static void filter_input_class_init (FilterInputClass *class); -static void filter_input_init (FilterInput *gspaper); -static void filter_input_finalise (GtkObject *obj); +static int input_eq (FilterElement *fe, FilterElement *cm); +static void xml_create (FilterElement *fe, xmlNodePtr node); +static xmlNodePtr xml_encode (FilterElement *fe); +static int xml_decode (FilterElement *fe, xmlNodePtr node); +static GtkWidget *get_widget (FilterElement *fe); +static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff); +static void format_sexp (FilterElement *, GString *); -#define _PRIVATE(x) (((FilterInput *)(x))->priv) +static void filter_input_class_init (FilterInputClass *klass); +static void filter_input_init (FilterInput *fi); +static void filter_input_finalise (GObject *obj); -struct _FilterInputPrivate { -}; static FilterElementClass *parent_class; -enum { - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL] = { 0 }; - -guint +GType filter_input_get_type (void) { - static guint type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterInput", - sizeof(FilterInput), - sizeof(FilterInputClass), - (GtkClassInitFunc)filter_input_class_init, - (GtkObjectInitFunc)filter_input_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterInputClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_input_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterInput), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_input_init, }; - type = gtk_type_unique(filter_element_get_type (), &type_info); + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterInput", &info, 0); } return type; } static void -filter_input_class_init (FilterInputClass *class) +filter_input_class_init (FilterInputClass *klass) { - GtkObjectClass *object_class; - FilterElementClass *filter_element = (FilterElementClass *)class; - - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(filter_element_get_type ()); - + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); + + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); + object_class->finalize = filter_input_finalise; - + /* override methods */ - filter_element->validate = validate; - filter_element->eq = input_eq; - filter_element->xml_create = xml_create; - filter_element->xml_encode = xml_encode; - filter_element->xml_decode = xml_decode; - filter_element->get_widget = get_widget; - filter_element->build_code = build_code; - filter_element->format_sexp = format_sexp; - - /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + fe_class->validate = validate; + fe_class->eq = input_eq; + fe_class->xml_create = xml_create; + fe_class->xml_encode = xml_encode; + fe_class->xml_decode = xml_decode; + fe_class->get_widget = get_widget; + fe_class->build_code = build_code; + fe_class->format_sexp = format_sexp; } static void -filter_input_init (FilterInput *o) +filter_input_init (FilterInput *fi) { - o->priv = g_malloc0 (sizeof (*o->priv)); + ; } static void filter_input_finalise (GtkObject *obj) { - FilterInput *o = (FilterInput *)obj; - - xmlFree (o->type); - g_list_foreach(o->values, (GFunc)g_free, NULL); - g_list_free(o->values); - - g_free(o->priv); + FilterInput *fi = (FilterInput *) obj; - ((GtkObjectClass *)(parent_class))->finalize(obj); + xmlFree (fi->type); + g_list_foreach (fi->values, (GFunc)g_free, NULL); + g_list_free (fi->values); + + g_free (fi->priv); + + G_OBJECT_CLASS (parent_class)->finalize (obj); } /** @@ -143,18 +133,20 @@ filter_input_finalise (GtkObject *obj) FilterInput * filter_input_new (void) { - FilterInput *o = (FilterInput *)gtk_type_new(filter_input_get_type ()); - return o; + return (FilterInput *) g_object_new (FILTER_TYPE_INPUT, NULL, NULL); } FilterInput * filter_input_new_type_name (const char *type) { - FilterInput *o = filter_input_new (); - o->type = xmlStrdup (type); + FilterInput *fi; - d(printf("new type %s = %p\n", type, o)); - return o; + fi = filter_input_new (); + fi->type = xmlStrdup (type); + + d(printf("new type %s = %p\n", type, fi)); + + return fi; } void @@ -180,7 +172,7 @@ validate (FilterElement *fe) if (fi->values && !strcmp (fi->type, "regex")) { regex_t regexpat; /* regex patern */ - gint regerr; + int regerr; char *text; text = fi->values->data; @@ -188,7 +180,7 @@ validate (FilterElement *fe) regerr = regcomp (®expat, text, REG_EXTENDED | REG_NEWLINE | REG_ICASE); if (regerr) { GtkWidget *dialog; - gchar *regmsg, *errmsg; + char *regmsg, *errmsg; size_t reglen; /* regerror gets called twice to get the full error string @@ -216,35 +208,34 @@ validate (FilterElement *fe) } static int -list_eq(GList *al, GList *bl) +list_eq (GList *al, GList *bl) { int truth = TRUE; - + while (truth && al && bl) { - truth = strcmp((char *)al->data, (char *)bl->data) == 0; + truth = strcmp ((char *) al->data, (char *) bl->data) == 0; al = al->next; bl = bl->next; } - + return truth && al == NULL && bl == NULL; } static int -input_eq(FilterElement *fe, FilterElement *cm) +input_eq (FilterElement *fe, FilterElement *cm) { FilterInput *fi = (FilterInput *)fe, *ci = (FilterInput *)cm; - - return ((FilterElementClass *)(parent_class))->eq(fe, cm) - && strcmp(fi->type, ci->type) == 0 - && list_eq(fi->values, ci->values); + + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) + && strcmp (fi->type, ci->type) == 0 + && list_eq (fi->values, ci->values); } static void xml_create (FilterElement *fe, xmlNodePtr node) { /* parent implementation */ - ((FilterElementClass *)(parent_class))->xml_create(fe, node); - + FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); } static xmlNodePtr @@ -304,7 +295,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) xmlFree (str); } else decstr = g_strdup(""); - + d(printf (" '%s'\n", decstr)); fi->values = g_list_append (fi->values, decstr); } else { @@ -323,7 +314,7 @@ entry_changed (GtkEntry *entry, FilterElement *fe) FilterInput *fi = (FilterInput *)fe; GList *l; - new = e_utf8_gtk_entry_get_text(entry); + new = e_utf8_gtk_entry_get_text (entry); /* NOTE: entry only supports a single value ... */ l = fi->values; @@ -348,7 +339,7 @@ get_widget (FilterElement *fe) e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), fi->values->data); } - gtk_signal_connect (GTK_OBJECT (entry), "changed", entry_changed, fe); + g_signal_connect (entry, "changed", entry_changed, fe); return entry; } @@ -356,7 +347,7 @@ get_widget (FilterElement *fe) static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) { - return; + ; } static void diff --git a/filter/filter-input.h b/filter/filter-input.h index ab03391116..760548c3b3 100644 --- a/filter/filter-input.h +++ b/filter/filter-input.h @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -23,36 +25,37 @@ #include "filter-element.h" -#define FILTER_INPUT(obj) GTK_CHECK_CAST (obj, filter_input_get_type (), FilterInput) -#define FILTER_INPUT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_input_get_type (), FilterInputClass) -#define IS_FILTER_INPUT(obj) GTK_CHECK_TYPE (obj, filter_input_get_type ()) +#define FILTER_TYPE_INPUT (filter_input_get_type ()) +#define FILTER_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_INPUT, FilterInput)) +#define FILTER_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_INPUT, FilterInputClass)) +#define IS_FILTER_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_INPUT)) +#define IS_FILTER_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_INPUT)) +#define FILTER_INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_INPUT, FilterInputClass)) -typedef struct _FilterInput FilterInput; -typedef struct _FilterInputClass FilterInputClass; +typedef struct _FilterInput FilterInput; +typedef struct _FilterInputClass FilterInputClass; struct _FilterInput { - FilterElement parent; - struct _FilterInputPrivate *priv; - + FilterElement parent_object; + char *type; /* name of type */ GList *values; /* strings */ }; struct _FilterInputClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; -guint filter_input_get_type (void); -FilterInput *filter_input_new (void); +GType filter_input_get_type (void); +FilterInput *filter_input_new (void); -FilterInput *filter_input_new_type_name (const char *type); +FilterInput *filter_input_new_type_name (const char *type); /* methods */ -void filter_input_set_value(FilterInput *fi, const char *value); +void filter_input_set_value (FilterInput *fi, const char *value); #endif /* ! _FILTER_INPUT_H */ - |