diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2001-06-28 10:22:40 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2001-06-28 10:22:40 +0800 |
commit | 764cfb5a6ba195958b1b3b814fdb584d6a5ff63b (patch) | |
tree | 1c49f5dca5a940c4a4715ba055738da25d64498b /shell/e-uri-schema-registry.c | |
parent | ad31ac2c9e472dd03e537b7bc3008cd9c54842e8 (diff) | |
download | gsoc2013-evolution-764cfb5a6ba195958b1b3b814fdb584d6a5ff63b.tar.gz gsoc2013-evolution-764cfb5a6ba195958b1b3b814fdb584d6a5ff63b.tar.zst gsoc2013-evolution-764cfb5a6ba195958b1b3b814fdb584d6a5ff63b.zip |
Added a URI schema registry to the shell, and changed the bootstrap
sequence to get the schema lists from the components and register them
into it.
svn path=/trunk/; revision=10553
Diffstat (limited to 'shell/e-uri-schema-registry.c')
-rw-r--r-- | shell/e-uri-schema-registry.c | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/shell/e-uri-schema-registry.c b/shell/e-uri-schema-registry.c new file mode 100644 index 0000000000..e27648359f --- /dev/null +++ b/shell/e-uri-schema-registry.c @@ -0,0 +1,177 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-uri-schema-registry.c + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli <ettore@ximian.com> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "e-uri-schema-registry.h" + +#include <gal/util/e-util.h> + + +#define PARENT_TYPE gtk_object_get_type () +static GtkObjectClass *parent_class = NULL; + +struct _SchemaHandler { + char *schema; + EvolutionShellComponentClient *component; +}; +typedef struct _SchemaHandler SchemaHandler; + +struct _EUriSchemaRegistryPrivate { + GHashTable *schema_to_handler; +}; + + +/* SchemaHandler. */ + +static SchemaHandler * +schema_handler_new (const char *schema, + EvolutionShellComponentClient *component) +{ + SchemaHandler *handler; + + handler = g_new (SchemaHandler, 1); + handler->schema = g_strdup (schema); + handler->component = component; + + bonobo_object_ref (BONOBO_OBJECT (component)); + + return handler; +} + +static void +schema_handler_free (SchemaHandler *handler) +{ + g_free (handler->schema); + bonobo_object_unref (BONOBO_OBJECT (handler->component)); + + g_free (handler); +} + + +static void +schema_to_handler_destroy_foreach_callback (void *key, + void *value, + void *data) +{ + schema_handler_free ((SchemaHandler *) value); +} + + +/* GtkObject methods. */ + +static void +impl_destroy (GtkObject *object) +{ + EUriSchemaRegistry *registry; + EUriSchemaRegistryPrivate *priv; + + registry = E_URI_SCHEMA_REGISTRY (object); + priv = registry->priv; + + g_hash_table_foreach (priv->schema_to_handler, schema_to_handler_destroy_foreach_callback, NULL); + g_hash_table_destroy (priv->schema_to_handler); + g_free (priv); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + +static void +class_init (GtkObjectClass *object_class) +{ + parent_class = gtk_type_class (PARENT_TYPE); + + object_class->destroy = impl_destroy; +} + +static void +init (EUriSchemaRegistry *uri_schema_registry) +{ + EUriSchemaRegistryPrivate *priv; + + priv = g_new (EUriSchemaRegistryPrivate, 1); + priv->schema_to_handler = g_hash_table_new (g_str_hash, g_str_equal); + + uri_schema_registry->priv = priv; +} + + +EUriSchemaRegistry * +e_uri_schema_registry_new (void) +{ + EUriSchemaRegistry *registry; + + registry = gtk_type_new (e_uri_schema_registry_get_type ()); + + return registry; +} + + +gboolean +e_uri_schema_registry_set_handler_for_schema (EUriSchemaRegistry *registry, + const char *schema, + EvolutionShellComponentClient *shell_component) +{ + EUriSchemaRegistryPrivate *priv; + SchemaHandler *existing_handler; + SchemaHandler *new_handler; + + g_return_val_if_fail (registry != NULL, FALSE); + g_return_val_if_fail (E_IS_URI_SCHEMA_REGISTRY (registry), FALSE); + g_return_val_if_fail (schema != NULL, FALSE); + g_return_val_if_fail (shell_component == NULL || EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component), FALSE); + + priv = registry->priv; + + existing_handler = g_hash_table_lookup (priv->schema_to_handler, schema); + if (existing_handler != NULL) + return FALSE; + + new_handler = schema_handler_new (schema, shell_component); + g_hash_table_insert (priv->schema_to_handler, new_handler->schema, new_handler); + + return TRUE; +} + +EvolutionShellComponentClient * +e_uri_schema_get_handler_for_schema (EUriSchemaRegistry *registry, + const char *schema) +{ + EUriSchemaRegistryPrivate *priv; + const SchemaHandler *handler; + + g_return_val_if_fail (registry != NULL, NULL); + g_return_val_if_fail (E_IS_URI_SCHEMA_REGISTRY (registry), NULL); + g_return_val_if_fail (schema != NULL, NULL); + + priv = registry->priv; + + handler = g_hash_table_lookup (priv->schema_to_handler, schema); + return handler->component; +} + + +E_MAKE_TYPE (e_uri_schema_registry, "EUriSchemaRegistry", EUriSchemaRegistry, class_init, init, PARENT_TYPE) |