diff options
author | Iain Holmes <iain@src.gnome.org> | 2001-01-18 02:28:39 +0800 |
---|---|---|
committer | Iain Holmes <iain@src.gnome.org> | 2001-01-18 02:28:39 +0800 |
commit | 59bd12b76388b33ccde74bc151fabda14a763924 (patch) | |
tree | 7eacadebe9ff5ca37ea51e144378604b55926407 | |
parent | b77c7192f536108e07ffaf19a58e6bff9b011a93 (diff) | |
download | gsoc2013-evolution-59bd12b76388b33ccde74bc151fabda14a763924.tar.gz gsoc2013-evolution-59bd12b76388b33ccde74bc151fabda14a763924.tar.zst gsoc2013-evolution-59bd12b76388b33ccde74bc151fabda14a763924.zip |
Removed the factory and updated the interfaces and objects
svn path=/trunk/; revision=7590
-rw-r--r-- | shell/importer/GNOME_Evolution_Importer.idl | 4 | ||||
-rw-r--r-- | shell/importer/Makefile.am | 7 | ||||
-rw-r--r-- | shell/importer/evolution-importer-client.c | 124 | ||||
-rw-r--r-- | shell/importer/evolution-importer-client.h | 11 | ||||
-rw-r--r-- | shell/importer/evolution-importer-factory.c | 225 | ||||
-rw-r--r-- | shell/importer/evolution-importer-factory.h | 77 | ||||
-rw-r--r-- | shell/importer/evolution-importer.c | 74 | ||||
-rw-r--r-- | shell/importer/evolution-importer.h | 17 | ||||
-rw-r--r-- | shell/importer/importer.c | 73 |
9 files changed, 231 insertions, 381 deletions
diff --git a/shell/importer/GNOME_Evolution_Importer.idl b/shell/importer/GNOME_Evolution_Importer.idl index 791891f81e..df6c7a22bf 100644 --- a/shell/importer/GNOME_Evolution_Importer.idl +++ b/shell/importer/GNOME_Evolution_Importer.idl @@ -61,9 +61,7 @@ module Evolution { * Returns: A string. */ string getError (); - }; - interface ImporterFactory : Bonobo::Unknown { /** * supportFormat: * @filename: The filename of the file. @@ -85,7 +83,7 @@ module Evolution { * * Returns: An Importer object. */ - Importer loadFile (in string filename); + boolean loadFile (in string filename); }; }; }; diff --git a/shell/importer/Makefile.am b/shell/importer/Makefile.am index 091367d473..64f293eedf 100644 --- a/shell/importer/Makefile.am +++ b/shell/importer/Makefile.am @@ -1,5 +1,6 @@ -INCLUDES = -I$(top_srcdir) -I$(includedir) $(GNOME_INCLUDEDIR) \ - -DG_LOG_DOMAIN=\"Evolution-Importer\" -g -Wall \ +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shell \ + -I$(includedir) $(GNOME_INCLUDEDIR) \ + -DG_LOG_DOMAIN=\"Evolution-Importer\" -g -Wall \ -Wmissing-prototypes -Wmissing-declarations \ -DEVOLUTION_GLADEDIR=\"$(datadir)/evolution/glade\" @@ -26,14 +27,12 @@ idl_DATA = $(IDLS) libevolution_importerincludedir = $(includedir)/evolution/importer libevolution_importer_la_SOURCES = \ $(IDL_GENERATED) \ - evolution-importer-factory.c \ evolution-importer-client.c \ evolution-importer.c \ importer.c \ importer.h libevolution_importerinclude_HEADERS = \ - evolution-importer-factory.h \ evolution-importer-client.h \ evolution-importer.h diff --git a/shell/importer/evolution-importer-client.c b/shell/importer/evolution-importer-client.c index 1687679cc4..da17cecbfd 100644 --- a/shell/importer/evolution-importer-client.c +++ b/shell/importer/evolution-importer-client.c @@ -1,5 +1,5 @@ /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* evolution-importer-listener.c +/* evolution-importer-client.c * * Copyright (C) 2000 Helix Code, Inc. * @@ -30,6 +30,8 @@ #include <bonobo/bonobo-main.h> #include <gal/util/e-util.h> +#include <liboaf/liboaf.h> + #include "GNOME_Evolution_Importer.h" #include "evolution-importer-client.h" @@ -254,7 +256,7 @@ init (EvolutionImporterClient *client) client->private = priv; } -void +static void evolution_importer_client_construct (EvolutionImporterClient *client, CORBA_Object corba_object) { @@ -265,6 +267,14 @@ evolution_importer_client_construct (EvolutionImporterClient *client, bonobo_object_client_construct (BONOBO_OBJECT_CLIENT (client), corba_object); } +/** + * evolution_importer_client_new: + * @objref: The CORBA_Object to make a client for. + * + * Makes a client for @objref. @objref should be an Evolution_Importer. + * + * Returns: A newly created EvolutionImporterClient. + */ EvolutionImporterClient * evolution_importer_client_new (const CORBA_Object objref) { @@ -278,7 +288,108 @@ evolution_importer_client_new (const CORBA_Object objref) return client; } +/** + * evolution_importer_client_new_from_id: + * @id: The oafiid of the component to make a client for. + * + * Makes a client for the object returned by activating @id. + * + * Returns: A newly created EvolutionImporterClient. + */ +EvolutionImporterClient * +evolution_importer_client_new_from_id (const char *id) +{ + CORBA_Environment ev; + CORBA_Object objref; + + g_return_val_if_fail (id != NULL, NULL); + + CORBA_exception_init (&ev); + objref = oaf_activate_from_id ((char *) id, 0, NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); + g_warning ("Could not start %s.", id); + return NULL; + } + + if (objref == CORBA_OBJECT_NIL) { + g_warning ("Could not activate component %s", id); + return NULL; + } + + return evolution_importer_client_new (objref); +} + /* API */ +/** + * evolution_importer_client_support_format: + * @client: The EvolutionImporterClient. + * @filename: Name of the file to check. + * + * Checks whether @client is able to import @filename. + * + * Returns: TRUE if @client can import @filename, FALSE otherwise. + */ +gboolean +evolution_importer_client_support_format (EvolutionImporterClient *client, + const char *filename) +{ + GNOME_Evolution_Importer corba_importer; + gboolean result; + CORBA_Environment ev; + + g_return_val_if_fail (client != NULL, FALSE); + g_return_val_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + + CORBA_exception_init (&ev); + corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client)); + result = GNOME_Evolution_Importer_supportFormat (corba_importer, + filename, &ev); + CORBA_exception_free (&ev); + + return result; +} + +/** + * evolution_importer_client_load_file: + * @client: The EvolutionImporterClient. + * @filename: The file to load. + * + * Loads and initialises the importer. + * + * Returns: TRUE on sucess, FALSE on failure. + */ +gboolean +evolution_importer_client_load_file (EvolutionImporterClient *client, + const char *filename) +{ + GNOME_Evolution_Importer corba_importer; + gboolean result; + CORBA_Environment ev; + + g_return_val_if_fail (client != NULL, FALSE); + g_return_val_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + + CORBA_exception_init (&ev); + corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client)); + result = GNOME_Evolution_Importer_loadFile (corba_importer, + filename, &ev); + CORBA_exception_free (&ev); + + return result; +} + +/** + * evolution_importer_client_process_item: + * @client: The EvolutionImporterClient. + * @callback: The function to be called once the item has been processed. + * @closure: The data to be passed to this function. + * + * Starts importing the next item in the file and calls @callback when the + * item has finished importing. + */ void evolution_importer_client_process_item (EvolutionImporterClient *client, EvolutionImporterClientCallback callback, @@ -312,6 +423,15 @@ evolution_importer_client_process_item (EvolutionImporterClient *client, CORBA_exception_free (&ev); } +/** + * evolution_importer_client_get_error: + * @client: The EvolutionImporterClient. + * + * Gets the error as a string. + * + * Returns: The error as a string. If there is no error NULL is returned. + * Importers need not support this method and if so, NULL is also returned. + */ const char * evolution_importer_client_get_error (EvolutionImporterClient *client) { diff --git a/shell/importer/evolution-importer-client.h b/shell/importer/evolution-importer-client.h index 3e81d8a9ba..e122a7cfdd 100644 --- a/shell/importer/evolution-importer-client.h +++ b/shell/importer/evolution-importer-client.h @@ -25,8 +25,7 @@ #define EVOLUTION_IMPORTER_CLIENT_H #include <bonobo/bonobo-object-client.h> - -#include "evolution-importer.h" +#include <importer/evolution-importer.h> #ifdef __cplusplus extern "C" { @@ -60,10 +59,14 @@ typedef void (* EvolutionImporterClientCallback) (EvolutionImporterClient *clien void *data); GtkType evolution_importer_client_get_type (void); -void evolution_importer_client_construct (EvolutionImporterClient *client, - CORBA_Object corba_object); + EvolutionImporterClient *evolution_importer_client_new (const CORBA_Object objref); +EvolutionImporterClient *evolution_importer_client_new_from_id (const char *id); +gboolean evolution_importer_client_support_format (EvolutionImporterClient *client, + const char *filename); +gboolean evolution_importer_client_load_file (EvolutionImporterClient *client, + const char *filename); void evolution_importer_client_process_item (EvolutionImporterClient *client, EvolutionImporterClientCallback callback, void *closure); diff --git a/shell/importer/evolution-importer-factory.c b/shell/importer/evolution-importer-factory.c deleted file mode 100644 index b31c308571..0000000000 --- a/shell/importer/evolution-importer-factory.c +++ /dev/null @@ -1,225 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* evolution-importer-factory.c - * - * Copyright (C) 2000 Helix Code, 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: Iain Holmes <iain@helixcode.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <bonobo/bonobo-object.h> -#include <gal/util/e-util.h> - -#include "GNOME_Evolution_Importer.h" -#include "evolution-importer-factory.h" - - -#define PARENT_TYPE BONOBO_OBJECT_TYPE -static BonoboObjectClass *parent_class = NULL; - -struct _EvolutionImporterFactoryPrivate { - EvolutionImporterFactorySupportFormatFn support_format_fn; - EvolutionImporterFactoryLoadFileFn load_file_fn; - - void *closure; -}; - - -static POA_GNOME_Evolution_ImporterFactory__vepv ImporterFactory_vepv; - -static POA_GNOME_Evolution_ImporterFactory * -create_servant (void) -{ - POA_GNOME_Evolution_ImporterFactory *servant; - CORBA_Environment ev; - - servant = (POA_GNOME_Evolution_ImporterFactory *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &ImporterFactory_vepv; - - CORBA_exception_init (&ev); - - POA_GNOME_Evolution_ImporterFactory__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - return NULL; - } - - CORBA_exception_free (&ev); - - return servant; -} - -static CORBA_boolean -impl_GNOME_Evolution_ImporterFactory_supportFormat (PortableServer_Servant servant, - const CORBA_char *filename, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - EvolutionImporterFactory *factory; - EvolutionImporterFactoryPrivate *priv; - - bonobo_object = bonobo_object_from_servant (servant); - factory = EVOLUTION_IMPORTER_FACTORY (bonobo_object); - priv = factory->private; - - if (priv->support_format_fn != NULL) - return (priv->support_format_fn) (factory, filename, priv->closure); - else - return FALSE; -} - -static GNOME_Evolution_Importer -impl_GNOME_Evolution_ImporterFactory_loadFile (PortableServer_Servant servant, - const CORBA_char *filename, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - EvolutionImporterFactory *factory; - EvolutionImporterFactoryPrivate *priv; - EvolutionImporter *importer; - GNOME_Evolution_Importer obj, obj_dup; - - bonobo_object = bonobo_object_from_servant (servant); - factory = EVOLUTION_IMPORTER_FACTORY (bonobo_object); - priv = factory->private; - - if (priv->load_file_fn != NULL) { - importer = (priv->load_file_fn) (factory, filename, priv->closure); - obj = bonobo_object_corba_objref (BONOBO_OBJECT (importer)); - obj_dup = CORBA_Object_duplicate (obj, ev); - return obj_dup; - } else { - return CORBA_OBJECT_NIL; - } -} - -static void -destroy (GtkObject *object) -{ - EvolutionImporterFactory *factory; - EvolutionImporterFactoryPrivate *priv; - - factory = EVOLUTION_IMPORTER_FACTORY (object); - priv = factory->private; - - if (priv == NULL) - return; - - g_free (priv); - factory->private = NULL; - - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -corba_class_init (void) -{ - POA_GNOME_Evolution_ImporterFactory__vepv *vepv; - POA_GNOME_Evolution_ImporterFactory__epv *epv; - PortableServer_ServantBase__epv *base_epv; - - base_epv = g_new0 (PortableServer_ServantBase__epv, 1); - base_epv->_private = NULL; - base_epv->finalize = NULL; - base_epv->default_POA = NULL; - - epv = g_new0 (POA_GNOME_Evolution_ImporterFactory__epv, 1); - epv->supportFormat = impl_GNOME_Evolution_ImporterFactory_supportFormat; - epv->loadFile = impl_GNOME_Evolution_ImporterFactory_loadFile; - - vepv = &ImporterFactory_vepv; - vepv->_base_epv = base_epv; - vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); - vepv->GNOME_Evolution_ImporterFactory_epv = epv; -} - -static void -class_init (EvolutionImporterFactoryClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS (klass); - object_class->destroy = destroy; - - parent_class = gtk_type_class (PARENT_TYPE); - corba_class_init (); -} - -static void -init (EvolutionImporterFactory *factory) -{ - EvolutionImporterFactoryPrivate *priv; - - priv = g_new0 (EvolutionImporterFactoryPrivate, 1); - - factory->private = priv; -} - - -void -evolution_importer_factory_construct (EvolutionImporterFactory *factory, - GNOME_Evolution_ImporterFactory corba_object, - EvolutionImporterFactorySupportFormatFn support_format_fn, - EvolutionImporterFactoryLoadFileFn load_file_fn, - void *closure) -{ - EvolutionImporterFactoryPrivate *priv; - - g_return_if_fail (factory != NULL); - g_return_if_fail (EVOLUTION_IS_IMPORTER_FACTORY (factory)); - g_return_if_fail (corba_object != CORBA_OBJECT_NIL); - g_return_if_fail (support_format_fn != NULL); - g_return_if_fail (load_file_fn != NULL); - - bonobo_object_construct (BONOBO_OBJECT (factory), corba_object); - - priv = factory->private; - priv->support_format_fn = support_format_fn; - priv->load_file_fn = load_file_fn; - - priv->closure = closure; -} - -EvolutionImporterFactory * -evolution_importer_factory_new (EvolutionImporterFactorySupportFormatFn support_format_fn, - EvolutionImporterFactoryLoadFileFn load_file_fn, - void *closure) -{ - EvolutionImporterFactory *factory; - POA_GNOME_Evolution_ImporterFactory *servant; - GNOME_Evolution_ImporterFactory corba_object; - - servant = create_servant (); - if (servant == NULL) - return NULL; - - factory = gtk_type_new (evolution_importer_factory_get_type ()); - corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (factory), - servant); - evolution_importer_factory_construct (factory, corba_object, - support_format_fn, - load_file_fn, closure); - return factory; -} - -E_MAKE_TYPE (evolution_importer_factory, "EvolutionImporterFactory", - EvolutionImporterFactory, class_init, init, PARENT_TYPE); diff --git a/shell/importer/evolution-importer-factory.h b/shell/importer/evolution-importer-factory.h deleted file mode 100644 index bff0a23e8d..0000000000 --- a/shell/importer/evolution-importer-factory.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* evolution-importer-factory.h - * - * Copyright (C) 2000 Helix Code, 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: Iain Holmes <iain@helixcode.com> - */ - -#ifndef EVOLUTION_IMPORTER_FACTORY_H -#define EVOLUTION_IMPORTER_FACTORY_H - -#include <bonobo/bonobo-object.h> -#include <evolution-importer.h> -#include "GNOME_Evolution_Importer.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* cplusplus */ - -#define EVOLUTION_TYPE_IMPORTER_FACTORY (evolution_importer_factory_get_type ()) -#define EVOLUTION_IMPORTER_FACTORY(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_IMPORTER_FACTORY, EvolutionImporterFactory)) -#define EVOLUTION_IMPORTER_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_IMPORTER_FACTORY, EvolutionImporterFactoryClass)) -#define EVOLUTION_IS_IMPORTER_FACTORY(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_IMPORTER_FACTORY)) -#define EVOLUTION_IS_IMPORTER_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_IMPORTER_FACTORY)) - -typedef struct _EvolutionImporterFactory EvolutionImporterFactory; -typedef struct _EvolutionImporterFactoryPrivate EvolutionImporterFactoryPrivate; -typedef struct _EvolutionImporterFactoryClass EvolutionImporterFactoryClass; - -typedef gboolean (* EvolutionImporterFactorySupportFormatFn) (EvolutionImporterFactory *factory, - const char *filename, - void *closure); -typedef EvolutionImporter *(* EvolutionImporterFactoryLoadFileFn) (EvolutionImporterFactory *factory, - const char *filename, - void *closure); -struct _EvolutionImporterFactory { - BonoboObject parent; - - EvolutionImporterFactoryPrivate *private; -}; - -struct _EvolutionImporterFactoryClass { - BonoboObjectClass parent_class; -}; - -GtkType evolution_importer_factory_get_type (void); -void evolution_importer_factory_construct (EvolutionImporterFactory *factory, - CORBA_Object corba_object, - EvolutionImporterFactorySupportFormatFn support_format_fn, - EvolutionImporterFactoryLoadFileFn load_file_fn, - void *closure); - -EvolutionImporterFactory *evolution_importer_factory_new (EvolutionImporterFactorySupportFormatFn support_format_fn, - EvolutionImporterFactoryLoadFileFn load_file_fn, - void *closure); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/shell/importer/evolution-importer.c b/shell/importer/evolution-importer.c index 71b32de92e..85d2446a19 100644 --- a/shell/importer/evolution-importer.c +++ b/shell/importer/evolution-importer.c @@ -36,6 +36,8 @@ static BonoboObjectClass *parent_class = NULL; struct _EvolutionImporterPrivate { + EvolutionImporterLoadFileFn load_file_fn; + EvolutionImporterSupportFormatFn support_format_fn; EvolutionImporterProcessItemFn process_item_fn; EvolutionImporterGetErrorFn get_error_fn; @@ -67,6 +69,45 @@ create_servant (void) return servant; } +static CORBA_boolean +impl_GNOME_Evolution_Importer_supportFormat (PortableServer_Servant servant, + const CORBA_char *filename, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionImporter *importer; + EvolutionImporterPrivate *priv; + + bonobo_object = bonobo_object_from_servant (servant); + importer = EVOLUTION_IMPORTER (bonobo_object); + priv = importer->private; + + if (priv->support_format_fn != NULL) + return (priv->support_format_fn) (importer, filename, + priv->closure); + else + return FALSE; +} + +static CORBA_boolean +impl_GNOME_Evolution_Importer_loadFile (PortableServer_Servant servant, + const CORBA_char *filename, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionImporter *importer; + EvolutionImporterPrivate *priv; + + bonobo_object = bonobo_object_from_servant (servant); + importer = EVOLUTION_IMPORTER (bonobo_object); + priv = importer->private; + + if (priv->load_file_fn != NULL) + return (priv->load_file_fn) (importer, filename, priv->closure); + else + return FALSE; +} + static void impl_GNOME_Evolution_Importer_processItem (PortableServer_Servant servant, GNOME_Evolution_ImporterListener listener, @@ -136,6 +177,8 @@ corba_class_init (void) base_epv = g_new0 (PortableServer_ServantBase__epv, 1); epv = g_new0 (POA_GNOME_Evolution_Importer__epv, 1); + epv->supportFormat = impl_GNOME_Evolution_Importer_supportFormat; + epv->loadFile = impl_GNOME_Evolution_Importer_loadFile; epv->processItem = impl_GNOME_Evolution_Importer_processItem; epv->getError = impl_GNOME_Evolution_Importer_getError; @@ -169,9 +212,11 @@ init (EvolutionImporter *importer) -void +static void evolution_importer_construct (EvolutionImporter *importer, GNOME_Evolution_Importer corba_object, + EvolutionImporterSupportFormatFn support_format_fn, + EvolutionImporterLoadFileFn load_file_fn, EvolutionImporterProcessItemFn process_item_fn, EvolutionImporterGetErrorFn get_error_fn, void *closure) @@ -181,20 +226,38 @@ evolution_importer_construct (EvolutionImporter *importer, g_return_if_fail (importer != NULL); g_return_if_fail (EVOLUTION_IS_IMPORTER (importer)); g_return_if_fail (corba_object != CORBA_OBJECT_NIL); + g_return_if_fail (support_format_fn != NULL); + g_return_if_fail (load_file_fn != NULL); g_return_if_fail (process_item_fn != NULL); - g_return_if_fail (get_error_fn != NULL); bonobo_object_construct (BONOBO_OBJECT (importer), corba_object); priv = importer->private; + priv->support_format_fn = support_format_fn; + priv->load_file_fn = load_file_fn; priv->process_item_fn = process_item_fn; priv->get_error_fn = get_error_fn; priv->closure = closure; } +/** + * evolution_importer_new: + * @support_format_fn: The function to be called by the supportFormat method. + * @load_file_fn: The function to be called by the loadFile method. + * @process_item_fn: The function to be called by the processItem method. + * @get_error_fn: The function to be called by the getError method. + * @closure: The data to be passed to all of the above functions. + * + * Creates a new EvolutionImporter object. Of the parameters only + * @get_error_function and @closure may be #NULL. + * + * Returns: A newly created EvolutionImporter object. + */ EvolutionImporter * -evolution_importer_new (EvolutionImporterProcessItemFn process_item_fn, +evolution_importer_new (EvolutionImporterSupportFormatFn support_format_fn, + EvolutionImporterLoadFileFn load_file_fn, + EvolutionImporterProcessItemFn process_item_fn, EvolutionImporterGetErrorFn get_error_fn, void *closure) { @@ -209,8 +272,9 @@ evolution_importer_new (EvolutionImporterProcessItemFn process_item_fn, importer = gtk_type_new (evolution_importer_get_type ()); corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (importer), servant); - evolution_importer_construct (importer, corba_object, process_item_fn, - get_error_fn, closure); + evolution_importer_construct (importer, corba_object, + support_format_fn, load_file_fn, + process_item_fn, get_error_fn, closure); return importer; } diff --git a/shell/importer/evolution-importer.h b/shell/importer/evolution-importer.h index 07dd844955..6842438417 100644 --- a/shell/importer/evolution-importer.h +++ b/shell/importer/evolution-importer.h @@ -26,8 +26,6 @@ #include <bonobo/bonobo-object.h> -#include "evolution-importer.h" - #ifdef __cplusplus extern "C" { #pragma } @@ -44,6 +42,12 @@ typedef struct _EvolutionImporterPrivate EvolutionImporterPrivate; typedef struct _EvolutionImporterClass EvolutionImporterClass; typedef enum _EvolutionImporterResult EvolutionImporterResult; +typedef gboolean (* EvolutionImporterSupportFormatFn) (EvolutionImporter *importer, + const char *filename, + void *closure); +typedef gboolean (* EvolutionImporterLoadFileFn) (EvolutionImporter *importer, + const char *filename, + void *closure); typedef void (* EvolutionImporterProcessItemFn) (EvolutionImporter *importer, CORBA_Object listener, void *closure, @@ -74,13 +78,10 @@ struct _EvolutionImporterClass { }; GtkType evolution_importer_get_type (void); -void evolution_importer_construct (EvolutionImporter *importer, - CORBA_Object corba_object, - EvolutionImporterProcessItemFn process_item_fn, - EvolutionImporterGetErrorFn get_error_fn, - void *closure); -EvolutionImporter *evolution_importer_new (EvolutionImporterProcessItemFn process_item_fn, +EvolutionImporter *evolution_importer_new (EvolutionImporterSupportFormatFn support_format_fn, + EvolutionImporterLoadFileFn load_file_fn, + EvolutionImporterProcessItemFn process_item_fn, EvolutionImporterGetErrorFn get_error_fn, void *closure); diff --git a/shell/importer/importer.c b/shell/importer/importer.c index eb911f4672..7bbec3aa66 100644 --- a/shell/importer/importer.c +++ b/shell/importer/importer.c @@ -232,33 +232,31 @@ get_iid_for_filetype (const char *filename) int i, len = 0; CORBA_exception_init (&ev); - info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/ImporterFactory:1.0')", NULL, &ev); + info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/Importer:1.0')", NULL, &ev); for (i = 0; i < info_list->_length; i++) { CORBA_Environment ev2; - CORBA_Object factory; + CORBA_Object importer; const OAF_ServerInfo *info; - char *name = NULL; info = info_list->_buffer + i; CORBA_exception_init (&ev2); - factory = oaf_activate_from_id ((char *) info->iid, 0, NULL, &ev2); + importer = oaf_activate_from_id ((char *) info->iid, 0, NULL, &ev2); if (ev2._major != CORBA_NO_EXCEPTION) { g_warning ("Error activating %s", info->iid); CORBA_exception_free (&ev2); continue; } - if (GNOME_Evolution_ImporterFactory_supportFormat (factory, - filename, - &ev2)) { + if (GNOME_Evolution_Importer_supportFormat (importer, + filename, &ev2)) { can_handle = g_list_prepend (can_handle, g_strdup (info->iid)); len++; } - bonobo_object_release_unref (factory, &ev2); + bonobo_object_release_unref (importer, &ev2); CORBA_exception_free (&ev2); } @@ -269,6 +267,7 @@ get_iid_for_filetype (const char *filename) } else if (len > 1) { /* FIXME: Some way to choose between multiple iids */ /* FIXME: Free stuff */ + g_warning ("Multiple iids can support"); ret_iid = can_handle->data; g_list_free (can_handle); return ret_iid; @@ -281,10 +280,7 @@ static void start_import (const char *filename, const char *iid) { - CORBA_Object factory, importer; - EvolutionImporterClient *client; ImporterComponentData *icd; - CORBA_Environment ev; char *label; char *real_iid; @@ -303,9 +299,9 @@ start_import (const char *filename, icd = g_new (ImporterComponentData, 1); icd->stop = FALSE; icd->destroyed = FALSE; - icd->dialog = gnome_dialog_new (_("Importing"), - GNOME_STOCK_BUTTON_CANCEL, - NULL); + icd->dialog = GNOME_DIALOG (gnome_dialog_new (_("Importing"), + GNOME_STOCK_BUTTON_CANCEL, + NULL)); gtk_signal_connect (GTK_OBJECT (icd->dialog), "clicked", GTK_SIGNAL_FUNC (dialog_clicked_cb), icd); gtk_signal_connect (GTK_OBJECT (icd->dialog), "destroy", @@ -322,49 +318,21 @@ start_import (const char *filename, while (gtk_events_pending ()) gtk_main_iteration (); - CORBA_exception_init (&ev); - factory = oaf_activate_from_id ((char *) real_iid, 0, NULL, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - label = g_strdup_printf (_("Importing %s\n" - "Cannot activate %s."), - filename, real_iid); - gtk_label_set_text (GTK_LABEL (icd->contents), label); - g_free (label); - while (gtk_events_pending ()) - gtk_main_iteration (); - - g_free (icd); - g_free (real_iid); - return; - } - - importer = GNOME_Evolution_ImporterFactory_loadFile (factory, - filename, - &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - CORBA_Environment ev2; - - label = g_strdup_printf (_("Unable to load %s.\n%s"), - filename, CORBA_exception_id (&ev)); - + icd->client = evolution_importer_client_new_from_id (real_iid); + g_free (real_iid); + + if (evolution_importer_client_load_file (icd->client, filename) == FALSE) { + label = g_strdup_printf (_("Error loading %s"), filename); gtk_label_set_text (GTK_LABEL (icd->contents), label); g_free (label); while (gtk_events_pending ()) gtk_main_iteration (); + bonobo_object_unref (BONOBO_OBJECT (icd->client)); + gtk_object_unref (GTK_OBJECT (icd->dialog)); g_free (icd); - g_free (real_iid); - CORBA_exception_init (&ev2); - CORBA_Object_release (factory, &ev2); - CORBA_exception_free (&ev2); - return; } - - CORBA_Object_release (factory, &ev); - CORBA_exception_free (&ev); - - client = evolution_importer_client_new (importer); - icd->client = client; + icd->filename = g_strdup (filename); icd->item = 1; @@ -375,8 +343,7 @@ start_import (const char *filename, while (gtk_events_pending ()) gtk_main_iteration (); - evolution_importer_client_process_item (client, import_cb, icd); - g_free (real_iid); + evolution_importer_client_process_item (icd->client, import_cb, icd); } static void @@ -445,7 +412,7 @@ create_plugin_menu (ImportData *data) gtk_menu_append (GTK_MENU (menu), item); CORBA_exception_init (&ev); - info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/ImporterFactory:1.0')", NULL, &ev); + info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/Importer:1.0')", NULL, &ev); for (i = 0; i < info_list->_length; i++) { const OAF_ServerInfo *info; char *name = NULL; |