From 793f838a7be8618034e8544ca364c0f09457f316 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Sat, 2 Nov 2002 00:23:28 +0000 Subject: Ported to GObject. 2002-11-01 Jeffrey Stedfast * filter-element.c: Ported to GObject. * filter-input.c: Same. * filter-code.c: This too. * filter-colour.c: And this. * filter-datespec.c: You guessed it. * filter-file.c: And again... * filter-folder.c: Wheee! This is fun... * filter-int.c: Gee, I wonder... * filter-label.c: Also ported. * filter-option.c: Yep, this too. * filter-source.c: And finally this one. svn path=/trunk/; revision=18495 --- filter/filter-source.c | 177 ++++++++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 92 deletions(-) (limited to 'filter/filter-source.c') diff --git a/filter/filter-source.c b/filter/filter-source.c index 83e20d1bd5..4d9aa4f6f8 100644 --- a/filter/filter-source.c +++ b/filter/filter-source.c @@ -1,24 +1,24 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * filter-source.c + * Authors: Jon Trowbridge + * Jeffrey Stedfast * - * Copyright (C) 2001 Ximian, Inc. + * Copyright 2001-2002 Ximian, Inc. (www.ximian.com) * - * Authors: Jon Trowbridge + * 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 free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * 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. * - * 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. * - * 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. */ @@ -41,90 +41,83 @@ #include #include -typedef struct _SourceInfo SourceInfo; -struct _SourceInfo { + +static void filter_source_class_init (FilterSourceClass *klass); +static void filter_source_init (FilterSource *fs); +static void filter_source_finalize (GObject *obj); + +static int source_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 FilterElement *clone (FilterElement *fe); +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_source_add_source (FilterSource *fs, const char *account_name, const char *name, + const char *addr, const char *url); +static void filter_source_get_sources (FilterSource *fs); + +typedef struct _SourceInfo { char *account_name; char *name; char *address; char *url; -}; +} SourceInfo; struct _FilterSourcePrivate { GList *sources; char *current_url; }; -static FilterElementClass *parent_class = NULL; -enum { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static void filter_source_class_init (FilterSourceClass *); -static void filter_source_init (FilterSource *); -static void filter_source_finalize (GtkObject *); - -static int source_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 FilterElement *clone(FilterElement *fe); -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_source_add_source (FilterSource *fs, const char *account_name, const char *name, - const char *addr, const char *url); -static void filter_source_get_sources (FilterSource *fs); +static FilterElementClass *parent_class = NULL; -GtkType +GType filter_source_get_type (void) { - static GtkType type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterSource", - sizeof(FilterSource), - sizeof(FilterSourceClass), - (GtkClassInitFunc)filter_source_class_init, - (GtkObjectInitFunc)filter_source_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterSourceClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_source_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterSource), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_source_init, }; - type = gtk_type_unique (filter_element_get_type (), &type_info); + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterSource", &info, 0); } return type; } static void -filter_source_class_init (FilterSourceClass *class) +filter_source_class_init (FilterSourceClass *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_source_finalize; - + /* override methods */ - filter_element->eq = source_eq; - filter_element->xml_create = xml_create; - filter_element->xml_encode = xml_encode; - filter_element->xml_decode = xml_decode; - filter_element->clone = clone; - 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 = source_eq; + fe_class->xml_create = xml_create; + fe_class->xml_encode = xml_encode; + fe_class->xml_decode = xml_decode; + fe_class->clone = clone; + fe_class->get_widget = get_widget; + fe_class->build_code = build_code; + fe_class->format_sexp = format_sexp; } static void @@ -136,11 +129,11 @@ filter_source_init (FilterSource *fs) } static void -filter_source_finalize (GtkObject *obj) +filter_source_finalize (GObject *obj) { FilterSource *fs = FILTER_SOURCE (obj); GList *i = fs->priv->sources; - + while (i) { SourceInfo *info = i->data; g_free (info->account_name); @@ -150,29 +143,28 @@ filter_source_finalize (GtkObject *obj) g_free (info); i = g_list_next (i); } - + g_list_free (fs->priv->sources); - + g_free (fs->priv); - if (GTK_OBJECT_CLASS (parent_class)->finalize) - GTK_OBJECT_CLASS (parent_class)->finalize (obj); + G_OBJECT_CLASS (parent_class)->finalize (obj); } FilterSource * filter_source_new (void) { - FilterSource *s = (FilterSource *) gtk_type_new (filter_source_get_type ()); - return s; + return (FilterSource *) g_object_new (FILTER_TYPE_SOURCE, NULL, NULL); } static int -source_eq(FilterElement *fe, FilterElement *cm) +source_eq (FilterElement *fe, FilterElement *cm) { FilterSource *fs = (FilterSource *)fe, *cs = (FilterSource *)cm; - - return ((FilterElementClass *)parent_class)->eq(fe, cm) - && ((fs->priv->current_url && cs->priv->current_url && strcmp(fs->priv->current_url, cs->priv->current_url) == 0) + + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) + && ((fs->priv->current_url && cs->priv->current_url + && strcmp (fs->priv->current_url, cs->priv->current_url) == 0) || (fs->priv->current_url == NULL && cs->priv->current_url == NULL)); } @@ -180,7 +172,7 @@ static void xml_create (FilterElement *fe, xmlNodePtr node) { /* Call parent implementation */ - ((FilterElementClass *)parent_class)->xml_create (fe, node); + FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); } static xmlNodePtr @@ -217,7 +209,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) fs->priv->current_url = camel_url_to_string (url, CAMEL_URL_HIDE_ALL); camel_url_free (url); } - + return 0; } @@ -227,23 +219,23 @@ clone (FilterElement *fe) FilterSource *fs = (FilterSource *) fe; FilterSource *cpy = filter_source_new (); GList *i; - - ((FilterElement *)cpy)->name = xmlStrdup (fe->name); - + + ((FilterElement *) cpy)->name = xmlStrdup (fe->name); + cpy->priv->current_url = g_strdup (fs->priv->current_url); - + for (i = fs->priv->sources; i != NULL; i = g_list_next (i)) { SourceInfo *info = (SourceInfo *) i->data; filter_source_add_source (cpy, info->account_name, info->name, info->address, info->url); } - + return (FilterElement *) cpy; } static void source_changed (GtkWidget *w, FilterSource *fs) { - SourceInfo *info = (SourceInfo *) gtk_object_get_data (GTK_OBJECT (w), "source"); + SourceInfo *info = (SourceInfo *) g_object_get_data (w, "source"); g_free (fs->priv->current_url); fs->priv->current_url = g_strdup (info->url); @@ -287,8 +279,9 @@ get_widget (FilterElement *fe) g_free (label); g_free (native_label); - gtk_object_set_data (GTK_OBJECT (item), "source", info); - gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (source_changed), fs); + g_object_set_data (item, "source", info); + g_signal_connect (item, "activate", source_changed, fs); + gtk_menu_append (GTK_MENU (menu), item); gtk_widget_show (item); @@ -340,7 +333,7 @@ filter_source_add_source (FilterSource *fs, const char *account_name, const char { SourceInfo *info; - g_return_if_fail (fs && IS_FILTER_SOURCE (fs)); + g_return_if_fail (IS_FILTER_SOURCE (fs)); info = g_new0 (SourceInfo, 1); info->account_name = g_strdup (account_name); -- cgit v1.2.3