diff options
author | JP Rosevear <jpr@ximian.com> | 2003-11-15 06:35:35 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2003-11-15 06:35:35 +0800 |
commit | dccfa1bc639a9d622e203ec0ad4f221487bb1a5f (patch) | |
tree | 6832c2691be1b3065587d81814289db5283273f7 | |
parent | 11e3c8caaab307604b926b3caab2a1d4a3ae6301 (diff) | |
download | gsoc2013-evolution-dccfa1bc639a9d622e203ec0ad4f221487bb1a5f.tar.gz gsoc2013-evolution-dccfa1bc639a9d622e203ec0ad4f221487bb1a5f.tar.zst gsoc2013-evolution-dccfa1bc639a9d622e203ec0ad4f221487bb1a5f.zip |
don't build the e-source stuff anymore, its in e-d-s now
2003-11-14 JP Rosevear <jpr@ximian.com>
* Makefile.am: don't build the e-source stuff anymore, its in
e-d-s now
svn path=/trunk/; revision=23370
-rw-r--r-- | e-util/ChangeLog | 5 | ||||
-rw-r--r-- | e-util/Makefile.am | 12 | ||||
-rw-r--r-- | e-util/e-source-group.c | 605 | ||||
-rw-r--r-- | e-util/e-source-group.h | 102 | ||||
-rw-r--r-- | e-util/e-source-list.c | 530 | ||||
-rw-r--r-- | e-util/e-source-list.h | 86 | ||||
-rw-r--r-- | e-util/e-source.c | 470 | ||||
-rw-r--r-- | e-util/e-source.h | 91 | ||||
-rw-r--r-- | e-util/test-source-list.c | 517 |
9 files changed, 5 insertions, 2413 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 5c04768a4e..727c5cb74d 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,5 +1,10 @@ 2003-11-14 JP Rosevear <jpr@ximian.com> + * Makefile.am: don't build the e-source stuff anymore, its in + e-d-s now + +2003-11-14 JP Rosevear <jpr@ximian.com> + * test-source-list.c (on_idle_do_stuff): we only need the uid to remove and peek at stuff diff --git a/e-util/Makefile.am b/e-util/Makefile.am index a0d314914a..ab8f39a3a2 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -41,9 +41,6 @@ eutilinclude_HEADERS = \ e-path.h \ e-request.h \ e-sexp.h \ - e-source-group.h \ - e-source-list.h \ - e-source.h \ e-time-utils.h \ e-trie.h \ e-uid.h \ @@ -79,9 +76,6 @@ libeutil_la_SOURCES = \ e-path.c \ e-request.c \ e-sexp.c \ - e-source-group.c \ - e-source-list.c \ - e-source.c \ e-time-utils.c \ e-trie.c \ e-uid.c \ @@ -91,12 +85,6 @@ libeutil_la_SOURCES = \ eggtrayicon.h \ md5-utils.c -noinst_PROGRAMS = \ - test-source-list - -test_source_list_SOURCES = test-source-list.c -test_source_list_LDADD = libeutil.la - MARSHAL_GENERATED = e-util-marshal.c e-util-marshal.h @EVO_MARSHAL_RULE@ diff --git a/e-util/e-source-group.c b/e-util/e-source-group.c deleted file mode 100644 index 5fb5a97b23..0000000000 --- a/e-util/e-source-group.c +++ /dev/null @@ -1,605 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source-group.c - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#include <config.h> - -#include "e-source-group.h" - -#include "e-uid.h" -#include "e-util-marshal.h" - -#include <gal/util/e-util.h> - -#include <string.h> - -#define PARENT_TYPE G_TYPE_OBJECT -static GObjectClass *parent_class = NULL; - - -/* Private members. */ - -struct _ESourceGroupPrivate { - char *uid; - char *name; - char *base_uri; - - GSList *sources; - - gboolean ignore_source_changed; -}; - - -/* Signals. */ - -enum { - CHANGED, - SOURCE_REMOVED, - SOURCE_ADDED, - LAST_SIGNAL -}; -static unsigned int signals[LAST_SIGNAL] = { 0 }; - - -/* Callbacks. */ - -static void -source_changed_callback (ESource *source, - ESourceGroup *group) -{ - if (! group->priv->ignore_source_changed) - g_signal_emit (group, signals[CHANGED], 0); -} - - -/* GObject methods. */ - -static void -impl_dispose (GObject *object) -{ - ESourceGroupPrivate *priv = E_SOURCE_GROUP (object)->priv; - - if (priv->sources != NULL) { - GSList *p; - - for (p = priv->sources; p != NULL; p = p->next) { - ESource *source = E_SOURCE (p->data); - - g_signal_handlers_disconnect_by_func (source, - G_CALLBACK (source_changed_callback), - object); - g_object_unref (source); - } - - g_slist_free (priv->sources); - priv->sources = NULL; - } - - (* G_OBJECT_CLASS (parent_class)->dispose) (object); -} - -static void -impl_finalize (GObject *object) -{ - ESourceGroupPrivate *priv = E_SOURCE_GROUP (object)->priv; - - g_free (priv->uid); - g_free (priv->name); - g_free (priv->base_uri); - g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - -/* Initialization. */ - -static void -class_init (ESourceGroupClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; - - parent_class = g_type_class_peek_parent (class); - - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceGroupClass, changed), - NULL, NULL, - e_util_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[SOURCE_ADDED] = - g_signal_new ("source_added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceGroupClass, source_added), - NULL, NULL, - e_util_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[SOURCE_REMOVED] = - g_signal_new ("source_removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceGroupClass, source_removed), - NULL, NULL, - e_util_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); -} - -static void -init (ESourceGroup *source_group) -{ - ESourceGroupPrivate *priv; - - priv = g_new0 (ESourceGroupPrivate, 1); - source_group->priv = priv; -} - - -/* Public methods. */ - -ESourceGroup * -e_source_group_new (const char *name, - const char *base_uri) -{ - ESourceGroup *new; - - g_return_val_if_fail (name != NULL, NULL); - g_return_val_if_fail (base_uri != NULL, NULL); - - new = g_object_new (e_source_group_get_type (), NULL); - new->priv->uid = e_uid_new (); - - e_source_group_set_name (new, name); - e_source_group_set_base_uri (new, base_uri); - - return new; -} - -ESourceGroup * -e_source_group_new_from_xml (const char *xml) -{ - xmlDocPtr doc; - ESourceGroup *group; - - doc = xmlParseDoc ((char *) xml); - if (doc == NULL) - return NULL; - - group = e_source_group_new_from_xmldoc (doc); - xmlFreeDoc (doc); - - return group; -} - -ESourceGroup * -e_source_group_new_from_xmldoc (xmlDocPtr doc) -{ - xmlNodePtr root, p; - xmlChar *uid; - xmlChar *name; - xmlChar *base_uri; - ESourceGroup *new = NULL; - - g_return_val_if_fail (doc != NULL, NULL); - - root = doc->children; - if (strcmp (root->name, "group") != 0) - return NULL; - - uid = xmlGetProp (root, "uid"); - name = xmlGetProp (root, "name"); - base_uri = xmlGetProp (root, "base_uri"); - - if (uid == NULL || name == NULL || base_uri == NULL) - goto done; - - new = g_object_new (e_source_group_get_type (), NULL); - new->priv->uid = g_strdup (uid); - - e_source_group_set_name (new, name); - e_source_group_set_base_uri (new, base_uri); - - for (p = root->children; p != NULL; p = p->next) { - ESource *new_source = e_source_new_from_xml_node (p); - e_source_group_add_source (new, new_source, -1); - } - - done: - if (name != NULL) - xmlFree (name); - if (base_uri != NULL) - xmlFree (base_uri); - return new; -} - -gboolean -e_source_group_update_from_xml (ESourceGroup *group, - const char *xml, - gboolean *changed_return) -{ - xmlDocPtr xmldoc; - gboolean success; - - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - g_return_val_if_fail (xml != NULL, FALSE); - - xmldoc = xmlParseDoc ((char *) xml); - - success = e_source_group_update_from_xmldoc (group, xmldoc, changed_return); - - xmlFreeDoc (xmldoc); - - return success; -} - -gboolean -e_source_group_update_from_xmldoc (ESourceGroup *group, - xmlDocPtr doc, - gboolean *changed_return) -{ - GHashTable *new_sources_hash; - GSList *new_sources_list = NULL; - xmlNodePtr root, nodep; - xmlChar *name, *base_uri; - gboolean changed = FALSE; - GSList *p, *q; - - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - g_return_val_if_fail (doc != NULL, FALSE); - - *changed_return = FALSE; - - root = doc->children; - if (strcmp (root->name, "group") != 0) - return FALSE; - - name = xmlGetProp (root, "name"); - if (name == NULL) - return FALSE; - - base_uri = xmlGetProp (root, "base_uri"); - if (base_uri == NULL) { - xmlFree (name); - return FALSE; - } - - if (strcmp (group->priv->name, name) != 0) { - g_free (group->priv->name); - group->priv->name = g_strdup (name); - changed = TRUE; - } - xmlFree (name); - - if (strcmp (group->priv->base_uri, base_uri) != 0) { - g_free (group->priv->base_uri); - group->priv->base_uri = g_strdup (base_uri); - changed = TRUE; - } - xmlFree (base_uri); - - new_sources_hash = g_hash_table_new (g_direct_hash, g_direct_equal); - - for (nodep = root->children; nodep != NULL; nodep = nodep->next) { - ESource *existing_source; - char *uid = e_source_uid_from_xml_node (nodep); - - if (uid == NULL) - continue; - - existing_source = e_source_group_peek_source_by_uid (group, uid); - if (g_hash_table_lookup (new_sources_hash, existing_source) != NULL) - continue; - - if (existing_source == NULL) { - ESource *new_source = e_source_new_from_xml_node (nodep); - - if (new_source != NULL) { - e_source_set_group (new_source, group); - g_signal_connect (new_source, "changed", G_CALLBACK (source_changed_callback), group); - new_sources_list = g_slist_prepend (new_sources_list, new_source); - - g_hash_table_insert (new_sources_hash, new_source, new_source); - - g_signal_emit (group, signals[SOURCE_ADDED], 0, new_source); - changed = TRUE; - } - } else { - gboolean source_changed; - - group->priv->ignore_source_changed ++; - - if (e_source_update_from_xml_node (existing_source, nodep, &source_changed)) { - new_sources_list = g_slist_prepend (new_sources_list, existing_source); - g_object_ref (existing_source); - g_hash_table_insert (new_sources_hash, existing_source, existing_source); - - if (source_changed) - changed = TRUE; - } - - group->priv->ignore_source_changed --; - } - - g_free (uid); - } - - new_sources_list = g_slist_reverse (new_sources_list); - - /* Emit "group_removed" and disconnect the "changed" signal for all the - groups that we haven't found in the new list. */ - q = new_sources_list; - for (p = group->priv->sources; p != NULL; p = p->next) { - ESource *source = E_SOURCE (p->data); - - if (g_hash_table_lookup (new_sources_hash, source) == NULL) { - changed = TRUE; - - g_signal_emit (group, signals[SOURCE_REMOVED], 0, source); - g_signal_handlers_disconnect_by_func (source, source_changed_callback, group); - } - - if (! changed && q != NULL) { - if (q->data != p->data) - changed = TRUE; - q = q->next; - } - } - - g_hash_table_destroy (new_sources_hash); - - /* Replace the original group list with the new one. */ - g_slist_foreach (group->priv->sources, (GFunc) g_object_unref, NULL); - g_slist_free (group->priv->sources); - - group->priv->sources = new_sources_list; - - /* FIXME if the order changes, the function doesn't notice. */ - - if (changed) { - g_signal_emit (group, signals[CHANGED], 0); - *changed_return = TRUE; - } - - return TRUE; /* Success. */ -} - -char * -e_source_group_uid_from_xmldoc (xmlDocPtr doc) -{ - xmlNodePtr root = doc->children; - xmlChar *name; - char *retval; - - if (strcmp (root->name, "group") != 0) - return NULL; - - name = xmlGetProp (root, "uid"); - if (name == NULL) - return NULL; - - retval = g_strdup (name); - xmlFree (name); - return retval; -} - -void -e_source_group_set_name (ESourceGroup *group, - const char *name) -{ - g_return_if_fail (E_IS_SOURCE_GROUP (group)); - g_return_if_fail (name != NULL); - - if (group->priv->name == name) - return; - - g_free (group->priv->name); - group->priv->name = g_strdup (name); - - g_signal_emit (group, signals[CHANGED], 0); -} - -void e_source_group_set_base_uri (ESourceGroup *group, - const char *base_uri) -{ - g_return_if_fail (E_IS_SOURCE_GROUP (group)); - g_return_if_fail (base_uri != NULL); - - if (group->priv->base_uri == base_uri) - return; - - g_free (group->priv->base_uri); - group->priv->base_uri = g_strdup (base_uri); - - g_signal_emit (group, signals[CHANGED], 0); -} - - -const char * -e_source_group_peek_uid (ESourceGroup *group) -{ - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), NULL); - - return group->priv->uid; -} - -const char * -e_source_group_peek_name (ESourceGroup *group) -{ - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), NULL); - - return group->priv->name; -} - -const char * -e_source_group_peek_base_uri (ESourceGroup *group) -{ - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), NULL); - - return group->priv->base_uri; -} - - -GSList * -e_source_group_peek_sources (ESourceGroup *group) -{ - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), NULL); - - return group->priv->sources; -} - -ESource * -e_source_group_peek_source_by_uid (ESourceGroup *group, - const char *uid) -{ - GSList *p; - - for (p = group->priv->sources; p != NULL; p = p->next) { - if (strcmp (e_source_peek_uid (E_SOURCE (p->data)), uid) == 0) - return E_SOURCE (p->data); - } - - return NULL; -} - -ESource * -e_source_group_peek_source_by_name (ESourceGroup *group, - const char *name) -{ - GSList *p; - - for (p = group->priv->sources; p != NULL; p = p->next) { - if (strcmp (e_source_peek_name (E_SOURCE (p->data)), name) == 0) - return E_SOURCE (p->data); - } - - return NULL; -} - -gboolean -e_source_group_add_source (ESourceGroup *group, - ESource *source, - int position) -{ - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - - if (e_source_group_peek_source_by_uid (group, e_source_peek_uid (source)) != NULL) - return FALSE; - - e_source_set_group (source, group); - g_object_ref (source); - - g_signal_connect (source, "changed", G_CALLBACK (source_changed_callback), group); - - group->priv->sources = g_slist_insert (group->priv->sources, source, position); - g_signal_emit (group, signals[SOURCE_ADDED], 0, source); - g_signal_emit (group, signals[CHANGED], 0); - - return TRUE; -} - -gboolean -e_source_group_remove_source (ESourceGroup *group, - ESource *source) -{ - GSList *p; - - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - for (p = group->priv->sources; p != NULL; p = p->next) { - if (E_SOURCE (p->data) == source) { - group->priv->sources = g_slist_remove_link (group->priv->sources, p); - g_signal_emit (group, signals[SOURCE_REMOVED], 0, source); - g_signal_emit (group, signals[CHANGED], 0); - return TRUE; - } - } - - return FALSE; -} - -gboolean -e_source_group_remove_source_by_uid (ESourceGroup *group, - const char *uid) -{ - GSList *p; - - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - g_return_val_if_fail (uid != NULL, FALSE); - - for (p = group->priv->sources; p != NULL; p = p->next) { - ESource *source = E_SOURCE (p->data); - - if (strcmp (e_source_peek_uid (source), uid) == 0) { - group->priv->sources = g_slist_remove_link (group->priv->sources, p); - g_signal_emit (group, signals[SOURCE_REMOVED], 0, source); - g_signal_emit (group, signals[CHANGED], 0); - return TRUE; - } - } - - return FALSE; -} - - -char * -e_source_group_to_xml (ESourceGroup *group) -{ - xmlDocPtr doc; - xmlNodePtr root; - xmlChar *xml_buffer; - char *returned_buffer; - int xml_buffer_size; - GSList *p; - - doc = xmlNewDoc ("1.0"); - - root = xmlNewDocNode (doc, NULL, "group", NULL); - xmlSetProp (root, "uid", e_source_group_peek_uid (group)); - xmlSetProp (root, "name", e_source_group_peek_name (group)); - xmlSetProp (root, "base_uri", e_source_group_peek_base_uri (group)); - - xmlDocSetRootElement (doc, root); - - for (p = group->priv->sources; p != NULL; p = p->next) - e_source_dump_to_xml_node (E_SOURCE (p->data), root); - - xmlDocDumpMemory (doc, &xml_buffer, &xml_buffer_size); - xmlFreeDoc (doc); - - returned_buffer = g_malloc (xml_buffer_size + 1); - memcpy (returned_buffer, xml_buffer, xml_buffer_size); - returned_buffer [xml_buffer_size] = '\0'; - xmlFree (xml_buffer); - - return returned_buffer; -} - - -E_MAKE_TYPE (e_source_group, "ESourceGroup", ESourceGroup, class_init, init, PARENT_TYPE) diff --git a/e-util/e-source-group.h b/e-util/e-source-group.h deleted file mode 100644 index bebecba58f..0000000000 --- a/e-util/e-source-group.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source-group.h - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _E_SOURCE_GROUP_H_ -#define _E_SOURCE_GROUP_H_ - -#include <glib-object.h> -#include <libxml/tree.h> - -#define E_TYPE_SOURCE_GROUP (e_source_group_get_type ()) -#define E_SOURCE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SOURCE_GROUP, ESourceGroup)) -#define E_SOURCE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SOURCE_GROUP, ESourceGroupClass)) -#define E_IS_SOURCE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SOURCE_GROUP)) -#define E_IS_SOURCE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SOURCE_GROUP)) - - -typedef struct _ESourceGroup ESourceGroup; -typedef struct _ESourceGroupPrivate ESourceGroupPrivate; -typedef struct _ESourceGroupClass ESourceGroupClass; - -#include "e-source.h" - -struct _ESourceGroup { - GObject parent; - - ESourceGroupPrivate *priv; -}; - -struct _ESourceGroupClass { - GObjectClass parent_class; - - /* Signals. */ - - void (* changed) (ESourceGroup *group); - - void (* source_removed) (ESourceGroup *source_list, ESource *source); - void (* source_added) (ESourceGroup *source_list, ESource *source); -}; - - -GType e_source_group_get_type (void); - -ESourceGroup *e_source_group_new (const char *name, - const char *base_uri); -ESourceGroup *e_source_group_new_from_xml (const char *xml); -ESourceGroup *e_source_group_new_from_xmldoc (xmlDocPtr doc); - -gboolean e_source_group_update_from_xml (ESourceGroup *group, - const char *xml, - gboolean *changed_return); -gboolean e_source_group_update_from_xmldoc (ESourceGroup *group, - xmlDocPtr doc, - gboolean *changed_return); - -char *e_source_group_uid_from_xmldoc (xmlDocPtr doc); - -void e_source_group_set_name (ESourceGroup *group, - const char *name); -void e_source_group_set_base_uri (ESourceGroup *group, - const char *base_uri); - -const char *e_source_group_peek_uid (ESourceGroup *group); -const char *e_source_group_peek_name (ESourceGroup *group); -const char *e_source_group_peek_base_uri (ESourceGroup *group); - -GSList *e_source_group_peek_sources (ESourceGroup *group); -ESource *e_source_group_peek_source_by_uid (ESourceGroup *group, - const char *source_uid); -ESource *e_source_group_peek_source_by_name (ESourceGroup *group, - const char *source_name); - -gboolean e_source_group_add_source (ESourceGroup *group, - ESource *source, - int position); -gboolean e_source_group_remove_source (ESourceGroup *group, - ESource *source); -gboolean e_source_group_remove_source_by_uid (ESourceGroup *group, - const char *uid); - -char *e_source_group_to_xml (ESourceGroup *group); - - -#endif /* _E_SOURCE_GROUP_H_ */ diff --git a/e-util/e-source-list.c b/e-util/e-source-list.c deleted file mode 100644 index abe2c63e04..0000000000 --- a/e-util/e-source-list.c +++ /dev/null @@ -1,530 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source-list.c - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#include <config.h> - -#include "e-source-list.h" - -#include "e-util-marshal.h" - -#include <string.h> -#include <gal/util/e-util.h> - - -#define PARENT_TYPE G_TYPE_OBJECT -static GObjectClass *parent_class = NULL; - -struct _ESourceListPrivate { - GConfClient *gconf_client; - char *gconf_path; - - int gconf_notify_id; - - GSList *groups; - - gboolean ignore_group_changed; - int sync_idle_id; -}; - - -/* Signals. */ - -enum { - CHANGED, - GROUP_REMOVED, - GROUP_ADDED, - LAST_SIGNAL -}; -static unsigned int signals[LAST_SIGNAL] = { 0 }; - - -/* Forward declarations. */ - -static gboolean sync_idle_callback (ESourceList *list); -static void group_changed_callback (ESourceGroup *group, - ESourceList *list); -static void conf_changed_callback (GConfClient *client, - unsigned int connection_id, - GConfEntry *entry, - ESourceList *list); - - -/* Utility functions. */ - -static void -load_from_gconf (ESourceList *list) -{ - GSList *conf_list, *p, *q; - GSList *new_groups_list; - GHashTable *new_groups_hash; - gboolean changed = FALSE; - int pos; - - conf_list = gconf_client_get_list (list->priv->gconf_client, - list->priv->gconf_path, - GCONF_VALUE_STRING, NULL); - - new_groups_list = NULL; - new_groups_hash = g_hash_table_new (g_direct_hash, g_direct_equal); - - for (p = conf_list, pos = 0; p != NULL; p = p->next, pos++) { - const char *xml = p->data; - xmlDocPtr xmldoc = xmlParseDoc ((char *) xml); - char *group_uid = e_source_group_uid_from_xmldoc (xmldoc); - ESourceGroup *existing_group; - - if (group_uid == NULL) - continue; - - existing_group = e_source_list_peek_group_by_uid (list, group_uid); - if (g_hash_table_lookup (new_groups_hash, existing_group) != NULL) - continue; - - if (existing_group == NULL) { - ESourceGroup *new_group = e_source_group_new_from_xmldoc (xmldoc); - - if (new_group != NULL) { - g_signal_connect (new_group, "changed", G_CALLBACK (group_changed_callback), list); - new_groups_list = g_slist_prepend (new_groups_list, new_group); - - g_hash_table_insert (new_groups_hash, new_group, new_group); - g_signal_emit (list, signals[GROUP_ADDED], 0, new_group); - changed = TRUE; - } - } else { - gboolean group_changed; - - list->priv->ignore_group_changed ++; - - if (e_source_group_update_from_xmldoc (existing_group, xmldoc, &group_changed)) { - new_groups_list = g_slist_prepend (new_groups_list, existing_group); - g_object_ref (existing_group); - g_hash_table_insert (new_groups_hash, existing_group, existing_group); - - if (group_changed) - changed = TRUE; - } - - list->priv->ignore_group_changed --; - } - - g_free (group_uid); - } - - new_groups_list = g_slist_reverse (new_groups_list); - - g_slist_foreach (conf_list, (GFunc) g_free, NULL); - g_slist_free (conf_list); - - /* Emit "group_removed" and disconnect the "changed" signal for all the - groups that we haven't found in the new list. Also, check if the - order has changed. */ - q = new_groups_list; - for (p = list->priv->groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - - if (g_hash_table_lookup (new_groups_hash, group) == NULL) { - changed = TRUE; - g_signal_emit (list, signals[GROUP_REMOVED], 0, group); - g_signal_handlers_disconnect_by_func (group, group_changed_callback, list); - } - - if (! changed && q != NULL) { - if (q->data != p->data) - changed = TRUE; - q = q->next; - } - } - - g_hash_table_destroy (new_groups_hash); - - /* Replace the original group list with the new one. */ - - g_slist_foreach (list->priv->groups, (GFunc) g_object_unref, NULL); - g_slist_free (list->priv->groups); - - list->priv->groups = new_groups_list; - - /* FIXME if the order changes, the function doesn't notice. */ - - if (changed) - g_signal_emit (list, signals[CHANGED], 0); -} - -static void -remove_group (ESourceList *list, - ESourceGroup *group) -{ - list->priv->groups = g_slist_remove (list->priv->groups, group); - - g_signal_emit (list, signals[GROUP_REMOVED], 0, group); - g_object_unref (group); - - g_signal_emit (list, signals[CHANGED], 0); -} - - -/* Callbacks. */ - -static gboolean -sync_idle_callback (ESourceList *list) -{ - GError *error = NULL; - - if (! e_source_list_sync (list, &error)) { - g_warning ("Cannot update \"%s\": %s", list->priv->gconf_path, error->message); - g_error_free (error); - } - - return FALSE; -} - -static void -group_changed_callback (ESourceGroup *group, - ESourceList *list) -{ - if (! list->priv->ignore_group_changed) - g_signal_emit (list, signals[CHANGED], 0); - - if (list->priv->sync_idle_id == 0) - list->priv->sync_idle_id = g_idle_add ((GSourceFunc) sync_idle_callback, list); -} - -static void -conf_changed_callback (GConfClient *client, - unsigned int connection_id, - GConfEntry *entry, - ESourceList *list) -{ - load_from_gconf (list); -} - - -/* GObject methods. */ - -static void -impl_dispose (GObject *object) -{ - ESourceListPrivate *priv = E_SOURCE_LIST (object)->priv; - - if (priv->sync_idle_id != 0) { - GError *error = NULL; - - g_source_remove (priv->sync_idle_id); - priv->sync_idle_id = 0; - - if (! e_source_list_sync (E_SOURCE_LIST (object), &error)) - g_warning ("Could not update \"%s\": %s", - priv->gconf_path, error->message); - } - - if (priv->groups != NULL) { - GSList *p; - - for (p = priv->groups; p != NULL; p = p->next) - g_object_unref (p->data); - - g_slist_free (priv->groups); - priv->groups = NULL; - } - - if (priv->gconf_client != NULL) { - if (priv->gconf_notify_id != 0) { - gconf_client_notify_remove (priv->gconf_client, - priv->gconf_notify_id); - priv->gconf_notify_id = 0; - } - - g_object_unref (priv->gconf_client); - priv->gconf_client = NULL; - } - - (* G_OBJECT_CLASS (parent_class)->dispose) (object); -} - -static void -impl_finalize (GObject *object) -{ - ESourceListPrivate *priv = E_SOURCE_LIST (object)->priv; - - if (priv->gconf_notify_id != 0) { - gconf_client_notify_remove (priv->gconf_client, - priv->gconf_notify_id); - priv->gconf_notify_id = 0; - } - - g_free (priv->gconf_path); - g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - -/* Initialization. */ - -static void -class_init (ESourceListClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; - - parent_class = g_type_class_peek_parent (class); - - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceListClass, changed), - NULL, NULL, - e_util_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[GROUP_REMOVED] = - g_signal_new ("group_removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceListClass, group_removed), - NULL, NULL, - e_util_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - signals[GROUP_ADDED] = - g_signal_new ("group_added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceListClass, group_added), - NULL, NULL, - e_util_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_POINTER); -} - -static void -init (ESourceList *source_list) -{ - ESourceListPrivate *priv; - - priv = g_new0 (ESourceListPrivate, 1); - - source_list->priv = priv; -} - - -/* Public methods. */ - -ESourceList * -e_source_list_new (void) -{ - ESourceList *list = g_object_new (e_source_list_get_type (), NULL); - - return list; -} - -ESourceList * -e_source_list_new_for_gconf (GConfClient *client, - const char *path) -{ - ESourceList *list; - - g_return_val_if_fail (GCONF_IS_CLIENT (client), NULL); - g_return_val_if_fail (path != NULL, NULL); - - list = g_object_new (e_source_list_get_type (), NULL); - - list->priv->gconf_path = g_strdup (path); - list->priv->gconf_client = client; - g_object_ref (client); - - gconf_client_add_dir (client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - - list->priv->gconf_notify_id - = gconf_client_notify_add (client, path, - (GConfClientNotifyFunc) conf_changed_callback, list, - NULL, NULL); - load_from_gconf (list); - - return list; -} - - -GSList * -e_source_list_peek_groups (ESourceList *list) -{ - g_return_val_if_fail (E_IS_SOURCE_LIST (list), NULL); - - return list->priv->groups; -} - -ESourceGroup * -e_source_list_peek_group_by_uid (ESourceList *list, - const char *uid) -{ - GSList *p; - - g_return_val_if_fail (E_IS_SOURCE_LIST (list), NULL); - g_return_val_if_fail (uid != NULL, NULL); - - for (p = list->priv->groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - - if (strcmp (e_source_group_peek_uid (group), uid) == 0) - return group; - } - - return NULL; -} - -ESource * -e_source_list_peek_source_by_uid (ESourceList *list, - const char *uid) -{ - GSList *p; - - g_return_val_if_fail (E_IS_SOURCE_LIST (list), NULL); - g_return_val_if_fail (uid != NULL, NULL); - - for (p = list->priv->groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - ESource *source; - - source = e_source_group_peek_source_by_uid (group, uid); - if (source) - return source; - } - - return NULL; -} - - -gboolean -e_source_list_add_group (ESourceList *list, - ESourceGroup *group, - int position) -{ - g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - - if (e_source_list_peek_group_by_uid (list, e_source_group_peek_uid (group)) != NULL) - return FALSE; - - list->priv->groups = g_slist_insert (list->priv->groups, group, position); - g_object_ref (group); - - g_signal_connect (group, "changed", G_CALLBACK (group_changed_callback), list); - - g_signal_emit (list, signals[GROUP_ADDED], 0, group); - g_signal_emit (list, signals[CHANGED], 0); - - return TRUE; -} - -gboolean -e_source_list_remove_group (ESourceList *list, - ESourceGroup *group) -{ - g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - g_return_val_if_fail (E_IS_SOURCE_GROUP (group), FALSE); - - if (e_source_list_peek_group_by_uid (list, e_source_group_peek_uid (group)) == NULL) - return FALSE; - - remove_group (list, group); - return TRUE; -} - -gboolean -e_source_list_remove_group_by_uid (ESourceList *list, - const char *uid) -{ - ESourceGroup *group; - - g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - g_return_val_if_fail (uid != NULL, FALSE); - - group = e_source_list_peek_group_by_uid (list, uid); - if (group== NULL) - return FALSE; - - remove_group (list, group); - return TRUE; -} - -gboolean -e_source_list_remove_source_by_uid (ESourceList *list, - const char *uid) -{ - GSList *p; - - g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - g_return_val_if_fail (uid != NULL, FALSE); - - for (p = list->priv->groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - ESource *source; - - source = e_source_group_peek_source_by_uid (group, uid); - if (source) - return e_source_group_remove_source_by_uid (group, uid); - } - - return FALSE; -} - - -gboolean -e_source_list_sync (ESourceList *list, - GError **error) -{ - GSList *conf_list; - GSList *p; - gboolean retval; - - g_return_val_if_fail (E_IS_SOURCE_LIST (list), FALSE); - - conf_list = NULL; - for (p = list->priv->groups; p != NULL; p = p->next) - conf_list = g_slist_prepend (conf_list, e_source_group_to_xml (E_SOURCE_GROUP (p->data))); - conf_list = g_slist_reverse (conf_list); - - retval = gconf_client_set_list (list->priv->gconf_client, - list->priv->gconf_path, - GCONF_VALUE_STRING, - conf_list, - error); - - g_slist_foreach (conf_list, (GFunc) g_free, NULL); - g_slist_free (conf_list); - - if (list->priv->gconf_notify_id != 0) { - gconf_client_notify_remove (list->priv->gconf_client, - list->priv->gconf_notify_id); - list->priv->gconf_notify_id = 0; - } - - return retval; -} - - -E_MAKE_TYPE (e_source_list, "ESourceList", ESourceList, class_init, init, PARENT_TYPE) diff --git a/e-util/e-source-list.h b/e-util/e-source-list.h deleted file mode 100644 index 219ac7b2fa..0000000000 --- a/e-util/e-source-list.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source-list.h - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _E_SOURCE_LIST_H_ -#define _E_SOURCE_LIST_H_ - -#include <libxml/tree.h> -#include <gconf/gconf-client.h> - -#include "e-source-group.h" - -#define E_TYPE_SOURCE_LIST (e_source_list_get_type ()) -#define E_SOURCE_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SOURCE_LIST, ESourceList)) -#define E_SOURCE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SOURCE_LIST, ESourceListClass)) -#define E_IS_SOURCE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SOURCE_LIST)) -#define E_IS_SOURCE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SOURCE_LIST)) - - -typedef struct _ESourceList ESourceList; -typedef struct _ESourceListPrivate ESourceListPrivate; -typedef struct _ESourceListClass ESourceListClass; - -struct _ESourceList { - GObject parent; - - ESourceListPrivate *priv; -}; - -struct _ESourceListClass { - GObjectClass parent_class; - - /* Signals. */ - - void (* changed) (ESourceList *source_list); - - void (* group_removed) (ESourceList *source_list, ESourceGroup *group); - void (* group_added) (ESourceList *source_list, ESourceGroup *group); -}; - - -GType e_source_list_get_type (void); - -ESourceList *e_source_list_new (void); -ESourceList *e_source_list_new_for_gconf (GConfClient *client, - const char *path); - -GSList *e_source_list_peek_groups (ESourceList *list); -ESourceGroup *e_source_list_peek_group_by_uid (ESourceList *list, - const char *uid); -ESource *e_source_list_peek_source_by_uid (ESourceList *list, - const char *uid); - -gboolean e_source_list_add_group (ESourceList *list, - ESourceGroup *group, - int position); -gboolean e_source_list_remove_group (ESourceList *list, - ESourceGroup *group); -gboolean e_source_list_remove_group_by_uid (ESourceList *list, - const char *uid); -gboolean e_source_list_remove_source_by_uid (ESourceList *list, - const char *uidj); - -gboolean e_source_list_sync (ESourceList *list, - GError **error); - - -#endif /* _E_SOURCE_LIST_H_ */ diff --git a/e-util/e-source.c b/e-util/e-source.c deleted file mode 100644 index 593b770055..0000000000 --- a/e-util/e-source.c +++ /dev/null @@ -1,470 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source.c - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#include <config.h> - -#include "e-source.h" - -#include "e-util-marshal.h" -#include "e-uid.h" - -#include <string.h> -#include <gal/util/e-util.h> - - -#define PARENT_TYPE G_TYPE_OBJECT -static GObjectClass *parent_class = NULL; - -#define ES_CLASS(obj) E_SOURCE_CLASS (G_OBJECT_GET_CLASS (obj)) - - -/* String used to put the color in the XML. */ -#define COLOR_FORMAT_STRING "%06x" - - -/* Private members. */ - -struct _ESourcePrivate { - ESourceGroup *group; - - char *uid; - char *name; - char *relative_uri; - - gboolean has_color; - guint32 color; -}; - - -/* Signals. */ - -enum { - CHANGED, - LAST_SIGNAL -}; -static unsigned int signals[LAST_SIGNAL] = { 0 }; - - -/* Callbacks. */ - -static void -group_weak_notify (ESource *source, - GObject **where_the_object_was) -{ - source->priv->group = NULL; - - g_signal_emit (source, signals[CHANGED], 0); -} - - -/* GObject methods. */ - -static void -impl_finalize (GObject *object) -{ - ESourcePrivate *priv = E_SOURCE (object)->priv; - - g_free (priv->uid); - g_free (priv->name); - g_free (priv->relative_uri); - g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void -impl_dispose (GObject *object) -{ - ESourcePrivate *priv = E_SOURCE (object)->priv; - - if (priv->group != NULL) { - g_object_weak_unref (G_OBJECT (priv->group), (GWeakNotify) group_weak_notify, object); - priv->group = NULL; - } - - (* G_OBJECT_CLASS (parent_class)->dispose) (object); -} - - -/* Initialization. */ - -static void -class_init (ESourceClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; - - parent_class = g_type_class_peek_parent (class); - - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ESourceClass, changed), - NULL, NULL, - e_util_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -init (ESource *source) -{ - ESourcePrivate *priv; - - priv = g_new0 (ESourcePrivate, 1); - source->priv = priv; -} - - -/* Public methods. */ - -ESource * -e_source_new (const char *name, - const char *relative_uri) -{ - ESource *source; - - g_return_val_if_fail (name != NULL, NULL); - g_return_val_if_fail (relative_uri != NULL, NULL); - - source = g_object_new (e_source_get_type (), NULL); - source->priv->uid = e_uid_new (); - - e_source_set_name (source, name); - e_source_set_relative_uri (source, relative_uri); - return source; -} - -ESource * -e_source_new_from_xml_node (xmlNodePtr node) -{ - ESource *source; - xmlChar *uid; - - uid = xmlGetProp (node, "uid"); - if (uid == NULL) - return NULL; - - source = g_object_new (e_source_get_type (), NULL); - - source->priv->uid = g_strdup (uid); - xmlFree (uid); - - if (e_source_update_from_xml_node (source, node, NULL)) - return source; - - g_object_unref (source); - return NULL; -} - -/** - * e_source_update_from_xml_node: - * @source: An ESource. - * @node: A pointer to the node to parse. - * - * Update the ESource properties from @node. - * - * Return value: %TRUE if the data in @node was recognized and parsed into - * acceptable values for @source, %FALSE otherwise. - **/ -gboolean -e_source_update_from_xml_node (ESource *source, - xmlNodePtr node, - gboolean *changed_return) -{ - xmlChar *name; - xmlChar *relative_uri; - xmlChar *color_string; - gboolean retval; - gboolean changed = FALSE; - - name = xmlGetProp (node, "name"); - relative_uri = xmlGetProp (node, "relative_uri"); - color_string = xmlGetProp (node, "color"); - - if (name == NULL || relative_uri == NULL) { - retval = FALSE; - goto done; - } - - if (source->priv->name == NULL - || strcmp (name, source->priv->name) != 0 - || source->priv->relative_uri == NULL - || strcmp (relative_uri, source->priv->relative_uri) != 0) { - g_free (source->priv->name); - source->priv->name = g_strdup (name); - - g_free (source->priv->relative_uri); - source->priv->relative_uri = g_strdup (relative_uri); - - changed = TRUE; - } - - if (color_string == NULL) { - if (source->priv->has_color) { - source->priv->has_color = FALSE; - changed = TRUE; - } - } else { - guint32 color = 0; - - sscanf (color_string, COLOR_FORMAT_STRING, &color); - if (! source->priv->has_color || source->priv->color != color) { - source->priv->has_color = TRUE; - source->priv->color = color; - changed = TRUE; - } - } - - retval = TRUE; - - done: - if (changed) - g_signal_emit (source, signals[CHANGED], 0); - - if (changed_return != NULL) - *changed_return = changed; - - if (name != NULL) - xmlFree (name); - if (relative_uri != NULL) - xmlFree (relative_uri); - if (color_string != NULL) - xmlFree (color_string); - - return retval; -} - -/** - * e_source_name_from_xml_node: - * @node: A pointer to an XML node. - * - * Assuming that @node is a valid ESource specification, retrieve the name of - * the source from it. - * - * Return value: Name of the source in the specified @node. The caller must - * free the string. - **/ -char * -e_source_uid_from_xml_node (xmlNodePtr node) -{ - xmlChar *uid = xmlGetProp (node, "uid"); - char *retval; - - if (uid == NULL) - return NULL; - - retval = g_strdup (uid); - xmlFree (uid); - return retval; -} - -void -e_source_set_group (ESource *source, - ESourceGroup *group) -{ - g_return_if_fail (E_IS_SOURCE (source)); - g_return_if_fail (group == NULL || E_IS_SOURCE_GROUP (group)); - - if (source->priv->group == group) - return; - - if (source->priv->group != NULL) - g_object_weak_unref (G_OBJECT (source->priv->group), (GWeakNotify) group_weak_notify, source); - - source->priv->group = group; - if (group != NULL) - g_object_weak_ref (G_OBJECT (group), (GWeakNotify) group_weak_notify, source); - - g_signal_emit (source, signals[CHANGED], 0); -} - -void -e_source_set_name (ESource *source, - const char *name) -{ - g_return_if_fail (E_IS_SOURCE (source)); - - if (source->priv->name == name) - return; - - g_free (source->priv->name); - source->priv->name = g_strdup (name); - - g_signal_emit (source, signals[CHANGED], 0); -} - -void -e_source_set_relative_uri (ESource *source, - const char *relative_uri) -{ - g_return_if_fail (E_IS_SOURCE (source)); - - if (source->priv->relative_uri == relative_uri) - return; - - g_free (source->priv->relative_uri); - source->priv->relative_uri = g_strdup (relative_uri); - - g_signal_emit (source, signals[CHANGED], 0); -} - -void -e_source_set_color (ESource *source, - guint32 color) -{ - g_return_if_fail (E_IS_SOURCE (source)); - - if (source->priv->has_color && source->priv->color == color) - return; - - source->priv->has_color = TRUE; - source->priv->color = color; - - g_signal_emit (source, signals[CHANGED], 0); -} - -void -e_source_unset_color (ESource *source) -{ - g_return_if_fail (E_IS_SOURCE (source)); - - if (! source->priv->has_color) - return; - - source->priv->has_color = FALSE; - g_signal_emit (source, signals[CHANGED], 0); -} - - -ESourceGroup * -e_source_peek_group (ESource *source) -{ - g_return_val_if_fail (E_IS_SOURCE (source), NULL); - - return source->priv->group; -} - -const char * -e_source_peek_uid (ESource *source) -{ - g_return_val_if_fail (E_IS_SOURCE (source), NULL); - - return source->priv->uid; -} - -const char * -e_source_peek_name (ESource *source) -{ - g_return_val_if_fail (E_IS_SOURCE (source), NULL); - - return source->priv->name; -} - -const char * -e_source_peek_relative_uri (ESource *source) -{ - g_return_val_if_fail (E_IS_SOURCE (source), NULL); - - return source->priv->relative_uri; -} - -/** - * e_source_get_color: - * @source: An ESource - * @color_return: Pointer to a variable where the returned color will be - * stored. - * - * If @source has an associated color, return it in *@color_return. - * - * Return value: %TRUE if the @source has a defined color (and hence - * *@color_return was set), %FALSE otherwise. - **/ -gboolean -e_source_get_color (ESource *source, - guint32 *color_return) -{ - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - if (! source->priv->has_color) - return FALSE; - - if (color_return != NULL) - *color_return = source->priv->color; - - return TRUE; -} - - -char * -e_source_get_uri (ESource *source) -{ - const gchar *base_uri_str; - gchar *uri_str; - - g_return_val_if_fail (E_IS_SOURCE (source), NULL); - - if (source->priv->group == NULL) - return NULL; - - base_uri_str = e_source_group_peek_base_uri (source->priv->group); - - /* If last character in base URI is a dir separator, just concat the strings. - * We don't want to compress e.g. the trailing :// in a protocol specification */ - if (*base_uri_str && *(base_uri_str + strlen (base_uri_str) - 1) == G_DIR_SEPARATOR) - uri_str = g_strconcat (base_uri_str, source->priv->relative_uri, NULL); - else - uri_str = g_build_filename (e_source_group_peek_base_uri (source->priv->group), - source->priv->relative_uri, - NULL); - - return uri_str; -} - - -void -e_source_dump_to_xml_node (ESource *source, - xmlNodePtr parent_node) -{ - gboolean has_color; - guint32 color; - xmlNodePtr node = xmlNewChild (parent_node, NULL, "source", NULL); - - g_return_if_fail (E_IS_SOURCE (source)); - - - xmlSetProp (node, "uid", e_source_peek_uid (source)); - xmlSetProp (node, "name", e_source_peek_name (source)); - xmlSetProp (node, "relative_uri", e_source_peek_relative_uri (source)); - - has_color = e_source_get_color (source, &color); - if (has_color) { - char *color_string = g_strdup_printf (COLOR_FORMAT_STRING, color); - xmlSetProp (node, "color", color_string); - g_free (color_string); - } -} - - -E_MAKE_TYPE (e_source, "ESource", ESource, class_init, init, PARENT_TYPE) diff --git a/e-util/e-source.h b/e-util/e-source.h deleted file mode 100644 index 6060b8b588..0000000000 --- a/e-util/e-source.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-source.h - * - * Copyright (C) 2003 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _E_SOURCE_H_ -#define _E_SOURCE_H_ - -#include <glib-object.h> -#include <libxml/tree.h> - -#define E_TYPE_SOURCE (e_source_get_type ()) -#define E_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SOURCE, ESource)) -#define E_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SOURCE, ESourceClass)) -#define E_IS_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SOURCE)) -#define E_IS_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SOURCE)) - - -typedef struct _ESource ESource; -typedef struct _ESourcePrivate ESourcePrivate; -typedef struct _ESourceClass ESourceClass; - -#include "e-source-group.h" - -struct _ESource { - GObject parent; - - ESourcePrivate *priv; -}; - -struct _ESourceClass { - GObjectClass parent_class; - - /* Signals. */ - void (* changed) (ESource *source); -}; - - -GType e_source_get_type (void); - -ESource *e_source_new (const char *name, - const char *relative_uri); -ESource *e_source_new_from_xml_node (xmlNodePtr node); - -gboolean e_source_update_from_xml_node (ESource *source, - xmlNodePtr node, - gboolean *changed_return); - -char *e_source_uid_from_xml_node (xmlNodePtr node); - -void e_source_set_group (ESource *source, - ESourceGroup *group); -void e_source_set_name (ESource *source, - const char *name); -void e_source_set_relative_uri (ESource *source, - const char *relative_uri); -void e_source_set_color (ESource *source, - guint32 color); -void e_source_unset_color (ESource *source); - -ESourceGroup *e_source_peek_group (ESource *source); -const char *e_source_peek_uid (ESource *source); -const char *e_source_peek_name (ESource *source); -const char *e_source_peek_relative_uri (ESource *source); -gboolean e_source_get_color (ESource *source, - guint32 *color_return); - -char *e_source_get_uri (ESource *source); - -void e_source_dump_to_xml_node (ESource *source, - xmlNodePtr parent_node); - - -#endif /* _E_SOURCE_H_ */ diff --git a/e-util/test-source-list.c b/e-util/test-source-list.c deleted file mode 100644 index b869df01d7..0000000000 --- a/e-util/test-source-list.c +++ /dev/null @@ -1,517 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* test-source-list.c - Test for the ESourceList class. - * - * Copyright (C) 2002 Ximian, Inc. - * - * 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. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-source-list.h" - -#include <libgnomeui/gnome-ui-init.h> -#include <glib/gmain.h> - - -/* Globals. */ - -static GMainLoop *main_loop = NULL; -static ESourceList *list = NULL; -static int idle_dump_id = 0; - - -/* Options. */ - -static gboolean listen = FALSE; -static gboolean dump = FALSE; -static char *key_arg = "/apps/evolution/test/source_list"; -static char *source_arg = NULL; -static char *group_arg = NULL; -static char *add_group_arg = NULL; -static char *add_source_arg = NULL; -static char *remove_group_arg = NULL; -static char *remove_source_arg = NULL; -static char *set_name_arg = NULL; -static char *set_base_uri_arg = NULL; -static char *set_relative_uri_arg = NULL; -static char *set_color_arg = NULL; -static gboolean unset_color = FALSE; - -static struct poptOption options[] = { - { "key", '\0', POPT_ARG_STRING, &key_arg, 0, - "Name of the GConf key to use", "PATH" }, - { "source", '\0', POPT_ARG_STRING, &source_arg, 0, - "UID of source to apply operation to", "UID" }, - { "group", '\0', POPT_ARG_STRING, &group_arg, 0, - "UID of group to apply operation to", "UID" }, - { "add-group", '\0', POPT_ARG_STRING, &add_group_arg, 0, - "Add group of specified name", "NAME" }, - { "add-source", '\0', POPT_ARG_STRING, &add_source_arg, 0, - "Add source of specified name", "NAME" }, - { "remove-group", '\0', POPT_ARG_STRING, &remove_group_arg, 0, - "Remove group of specified name", "NAME" }, - { "remove-source", '\0', POPT_ARG_STRING, &remove_source_arg, 0, - "Remove source of specified name", "NAME" }, - { "set-name", '\0', POPT_ARG_STRING, &set_name_arg, 0, - "Set name of source or group. When used with --group, it sets the name of a group. " - "When used with both --group and --source, it sets the name of a source.", "NAME" }, - { "set-relative-uri", '\0', POPT_ARG_STRING, &set_relative_uri_arg, 0, - "Set relative URI of a source. Use with --source or --add-source.", "NAME" }, - { "set-base-uri", '\0', POPT_ARG_STRING, &set_base_uri_arg, 0, - "Set base URI of a group. Use with --group or --add-group.", "NAME" }, - { "set-color", '\0', POPT_ARG_STRING, &set_color_arg, 0, - "Set the color of a source. Use with --source or --add-source.", "COLOR (rrggbb)" }, - { "unset-color", '\0', POPT_ARG_NONE, &unset_color, 0, - "Unset the color of a source. Use with --source or --add-source.", NULL }, - { "listen", '\0', POPT_ARG_NONE, &listen, 0, - "Wait and listen for changes.", "" }, - { "dump", '\0', POPT_ARG_NONE, &dump, 0, - "List the current configured sources.", "" }, - POPT_AUTOHELP - { NULL } -}; - - -/* Forward decls. */ -static void group_added_callback (ESourceList *list, ESourceGroup *group); -static void group_removed_callback (ESourceList *list, ESourceGroup *group); -static void source_added_callback (ESourceGroup *group, ESource *source); -static void source_removed_callback (ESourceGroup *group, ESource *source); - - -static void -dump_source (ESource *source) -{ - char *uri = e_source_get_uri (source); - gboolean has_color; - guint32 color; - - g_print ("\tSource %s\n", e_source_peek_uid (source)); - g_print ("\t\tname: %s\n", e_source_peek_name (source)); - g_print ("\t\trelative_uri: %s\n", e_source_peek_relative_uri (source)); - g_print ("\t\tabsolute_uri: %s\n", uri); - - has_color = e_source_get_color (source, &color); - if (has_color) - g_print ("\t\tcolor: %06x\n", color); - - g_free (uri); -} - -static void -dump_group (ESourceGroup *group) -{ - GSList *sources, *p; - - g_print ("Group %s\n", e_source_group_peek_uid (group)); - g_print ("\tname: %s\n", e_source_group_peek_name (group)); - g_print ("\tbase_uri: %s\n", e_source_group_peek_base_uri (group)); - - sources = e_source_group_peek_sources (group); - for (p = sources; p != NULL; p = p->next) { - ESource *source = E_SOURCE (p->data); - - dump_source (source); - - if (e_source_peek_group (source) != group) - g_warning ("\t\t** ERROR ** parent pointer is %p, should be %p", - e_source_peek_group (source), group); - } -} - -static void -dump_list (void) -{ - GSList *groups, *p; - - groups = e_source_list_peek_groups (list); - if (groups == NULL) { - g_print ("(No items)\n"); - return; - } - - for (p = groups; p != NULL; p = p->next) - dump_group (E_SOURCE_GROUP (p->data)); -} - - -static int -idle_dump_callback (void *unused_data) -{ - dump_list (); - idle_dump_id = 0; - - return FALSE; -} - -static void -dump_on_idle (void) -{ - if (idle_dump_id == 0) - idle_dump_id = g_idle_add (idle_dump_callback, NULL); -} - - -static void -source_changed_callback (ESource *source) -{ - static int count = 0; - - g_print ("** Event: source \"%s\" changed (%d)\n", e_source_peek_name (source), ++count); - - dump_on_idle (); -} - -static void -group_changed_callback (ESourceGroup *group) -{ - static int count = 0; - - g_print ("** Event: group \"%s\" changed (%d)\n", e_source_group_peek_name (group), ++count); - - dump_on_idle (); -} - -static void -list_changed_callback (ESourceGroup *group) -{ - static int count = 0; - - g_print ("** Event: list changed (%d)\n", ++count); - - dump_on_idle (); -} - - -static void -connect_source (ESource *source) -{ - g_object_ref (source); - g_signal_connect (source, "changed", G_CALLBACK (source_changed_callback), NULL); -} - -static void -connect_group (ESourceGroup *group) -{ - GSList *sources, *p; - - g_object_ref (group); - g_signal_connect (group, "changed", G_CALLBACK (group_changed_callback), NULL); - g_signal_connect (group, "source_added", G_CALLBACK (source_added_callback), NULL); - g_signal_connect (group, "source_removed", G_CALLBACK (source_removed_callback), NULL); - - sources = e_source_group_peek_sources (group); - for (p = sources; p != NULL; p = p->next) - connect_source (E_SOURCE (p->data)); -} - -static void -connect_list (void) -{ - GSList *groups, *p; - - g_signal_connect (list, "changed", G_CALLBACK (list_changed_callback), NULL); - g_signal_connect (list, "group_added", G_CALLBACK (group_added_callback), NULL); - g_signal_connect (list, "group_removed", G_CALLBACK (group_removed_callback), NULL); - - groups = e_source_list_peek_groups (list); - for (p = groups; p != NULL; p = p->next) - connect_group (E_SOURCE_GROUP (p->data)); -} - -static void -disconnect_group (ESourceGroup *group) -{ - g_signal_handlers_disconnect_by_func (group, G_CALLBACK (group_changed_callback), NULL); - g_signal_handlers_disconnect_by_func (group, G_CALLBACK (source_added_callback), NULL); - - g_object_unref (group); -} - -static void -disconnect_source (ESource *source) -{ - g_signal_handlers_disconnect_by_func (source, G_CALLBACK (source_changed_callback), NULL); - - g_object_unref (source); -} - - -static void -source_added_callback (ESourceGroup *group, - ESource *source) -{ - static int count = 0; - - g_print ("** Event: source \"%s\" added (%d)\n", e_source_peek_name (source), ++count); - - connect_source (source); - dump_on_idle (); -} - -static void -source_removed_callback (ESourceGroup *group, - ESource *source) -{ - static int count = 0; - - g_print ("** Event: source \"%s\" removed (%d)\n", e_source_peek_name (source), ++count); - - disconnect_source (source); - dump_on_idle (); -} - -static void -group_added_callback (ESourceList *list, - ESourceGroup *group) -{ - static int count = 0; - - g_print ("** Event: group \"%s\" added (%d)\n", e_source_group_peek_name (group), ++count); - - connect_group (group); - dump_on_idle (); -} - -static void -group_removed_callback (ESourceList *list, - ESourceGroup *group) -{ - static int count = 0; - - g_print ("** Event: group \"%s\" removed (%d)\n", e_source_group_peek_name (group), ++count); - - disconnect_group (group); - dump_on_idle (); -} - - -static int -on_idle_do_stuff (void *unused_data) -{ - GConfClient *client = gconf_client_get_default (); - ESourceGroup *new_group = NULL; - ESource *new_source = NULL; - - list = e_source_list_new_for_gconf (client, key_arg); - g_object_unref (client); - - if (add_group_arg != NULL) { - if (group_arg != NULL) { - fprintf (stderr, "--add-group and --group cannot be used at the same time.\n"); - exit (1); - } - if (set_base_uri_arg == NULL) { - fprintf (stderr, "When using --add-group, you need to specify a base URI using --set-base-uri.\n"); - exit (1); - } - - new_group = e_source_group_new (add_group_arg, set_base_uri_arg); - e_source_list_add_group (list, new_group, -1); - g_object_unref (new_group); - - e_source_list_sync (list, NULL); - } - - if (remove_group_arg != NULL) { - ESourceGroup *group; - - group = e_source_list_peek_group_by_uid (list, remove_group_arg); - if (group == NULL) { - fprintf (stderr, "No such group \"%s\".\n", remove_group_arg); - exit (1); - } - - e_source_list_remove_group (list, group); - e_source_list_sync (list, NULL); - } - - if (add_source_arg != NULL) { - ESourceGroup *group; - - if (group_arg == NULL && new_group == NULL) { - fprintf (stderr, - "When using --add-source, you need to specify a group using either --group\n" - "or --add-group.\n"); - exit (1); - } - if (set_relative_uri_arg == NULL) { - fprintf (stderr, - "When using --add-source, you need to specify a relative URI using\n" - "--set-relative-uri.\n"); - exit (1); - } - - if (group_arg == NULL) { - group = new_group; - } else { - group = e_source_list_peek_group_by_uid (list, group_arg); - if (group == NULL) { - fprintf (stderr, "No such group \"%s\".\n", group_arg == NULL ? add_group_arg : group_arg); - exit (1); - } - } - - new_source = e_source_new (add_source_arg, set_relative_uri_arg); - e_source_group_add_source (group, new_source, -1); - e_source_list_sync (list, NULL); - } - - if (remove_source_arg != NULL) { - ESource *source; - - source = e_source_list_peek_source_by_uid (list, remove_source_arg); - if (source == NULL) { - fprintf (stderr, "No such source \"%s\".\n", remove_source_arg); - exit (1); - } - - e_source_list_remove_source_by_uid (list, remove_source_arg); - e_source_list_sync (list, NULL); - } - - if (set_name_arg != NULL) { - if (group_arg == NULL && source_arg == NULL) { - fprintf (stderr, - "When using --set-name, you need to specify a source (using --source" - "alone) or a group (using --group alone).\n"); - exit (1); - } - - if (source_arg != NULL) { - ESource *source = e_source_list_peek_source_by_uid (list, source_arg); - - if (source != NULL) { - e_source_set_name (source, set_name_arg); - } else { - fprintf (stderr, "No such source \"%s\".\n", source_arg); - exit (1); - } - } else { - ESourceGroup *group = e_source_list_peek_group_by_uid (list, group_arg); - - if (group != NULL) { - e_source_group_set_name (group, set_name_arg); - } else { - fprintf (stderr, "No such group \"%s\".\n", group_arg); - exit (1); - } - } - - e_source_list_sync (list, NULL); - } - - if (set_relative_uri_arg != NULL && add_source_arg == NULL) { - ESource *source; - - if (source_arg == NULL) { - fprintf (stderr, - "When using --set-relative-uri, you need to specify a source using " - "--source.\n"); - exit (1); - } - - source = e_source_list_peek_source_by_uid (list, source_arg); - e_source_set_relative_uri (source, set_relative_uri_arg); - e_source_list_sync (list, NULL); - } - - if (set_color_arg != NULL) { - ESource *source; - guint32 color; - - if (add_source_arg == NULL && source_arg == NULL) { - fprintf (stderr, - "When using --set-color, you need to specify a source using --source\n"); - exit (1); - } - - if (add_source_arg != NULL) - source = new_source; - else - source = e_source_list_peek_source_by_uid (list, source_arg); - - sscanf (set_color_arg, "%06x", &color); - e_source_set_color (source, color); - e_source_list_sync (list, NULL); - } - - if (unset_color) { - ESource *source; - - if (add_source_arg == NULL && source_arg == NULL) { - fprintf (stderr, - "When using --unset-color, you need to specify a source using --source\n"); - exit (1); - } - - if (add_source_arg != NULL) - source = new_source; - else - source = e_source_list_peek_source_by_uid (list, source_arg); - - e_source_unset_color (source); - e_source_list_sync (list, NULL); - } - - if (set_base_uri_arg != NULL && add_group_arg == NULL) { - ESourceGroup *group; - - if (group_arg == NULL) { - fprintf (stderr, - "When using --set-base-uri, you need to specify a group using --group.\n"); - exit (1); - } - - group = e_source_list_peek_group_by_uid (list, group_arg); - e_source_group_set_base_uri (group, set_base_uri_arg); - e_source_list_sync (list, NULL); - } - - connect_list (); - - if (dump) - dump_list (); - - if (! listen) - g_main_loop_quit (main_loop); - - return FALSE; -} - - -int -main (int argc, - char **argv) -{ - GnomeProgram *program; - - program = gnome_program_init ("test-source-list", "0.0", - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PARAM_POPT_TABLE, options, - NULL); - - g_idle_add (on_idle_do_stuff, NULL); - - main_loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (main_loop); - - return 0; -} |