diff options
author | Iain Holmes <iain@src.gnome.org> | 2001-01-12 03:01:03 +0800 |
---|---|---|
committer | Iain Holmes <iain@src.gnome.org> | 2001-01-12 03:01:03 +0800 |
commit | 0fd4de8110c0dc2aebd29dc40434a9629e6a5d27 (patch) | |
tree | 1274d39ab16d8f6627d6541c482772621b8a1b65 /shell/importer | |
parent | f753547d5d281b34587430a88a1dc1934d65c889 (diff) | |
download | gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar.gz gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar.bz2 gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar.lz gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar.xz gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.tar.zst gsoc2013-evolution-0fd4de8110c0dc2aebd29dc40434a9629e6a5d27.zip |
add the importer part 1
svn path=/trunk/; revision=7398
Diffstat (limited to 'shell/importer')
-rw-r--r-- | shell/importer/GNOME_Evolution_Importer.idl | 91 | ||||
-rw-r--r-- | shell/importer/Makefile.am | 47 | ||||
-rw-r--r-- | shell/importer/evolution-importer-client.c | 336 | ||||
-rw-r--r-- | shell/importer/evolution-importer-client.h | 76 | ||||
-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 | 218 | ||||
-rw-r--r-- | shell/importer/evolution-importer.h | 92 | ||||
-rw-r--r-- | shell/importer/import.glade | 104 | ||||
-rw-r--r-- | shell/importer/importer.c | 506 | ||||
-rw-r--r-- | shell/importer/importer.h | 29 |
11 files changed, 1801 insertions, 0 deletions
diff --git a/shell/importer/GNOME_Evolution_Importer.idl b/shell/importer/GNOME_Evolution_Importer.idl new file mode 100644 index 0000000000..791891f81e --- /dev/null +++ b/shell/importer/GNOME_Evolution_Importer.idl @@ -0,0 +1,91 @@ +/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Interfaces for the importer framework. + * + * Authors: + * Iain Holmes <iain@helixcode.com> + * + * Copyright (C) 2000 Helix Code, Inc. + */ + +#include <Bonobo.idl> + +module GNOME { +module Evolution { + interface ImporterListener { + enum ImporterResult { + OK, + UNSUPPORTED_OPERATION, + NOT_READY, + UNKNOWN_DATA, + BAD_DATA, + BAD_FILE + }; + + /** + * notifyResult: + * @result: The result of the import. + * @more_items: Are there any more items to be processed? + * + * Notifies the listener of the result and whether there are + * any more items to be imported. + */ + void notifyResult (in ImporterResult result, + in boolean more_items); + }; + + interface Importer : Bonobo::Unknown { + + /** + * Busy: Raised if the Importer object is in the middle of + * processing an item; + */ + exception Busy {}; + + /** + * processItem: + * @listener: The ImporterListener that will be notified of the + * progress. + * + * Processes the next item. + * + */ + void processItem (in ImporterListener listener) + raises (Busy); + + /** + * getError: + * + * Retrieve a detailed explaination of the error. + * + * Returns: A string. + */ + string getError (); + }; + + interface ImporterFactory : Bonobo::Unknown { + /** + * supportFormat: + * @filename: The filename of the file. + * + * Checks if the importer created by this factory can + * import the file specified. + * + * Returns: A boolean, TRUE if it can import the file, + * FALSE otherwise. + */ + boolean supportFormat (in string filename); + + /** + * loadFile: + * @filename: The filename of the file. + * + * Loads the file and prepares an Importer object that can + * process files of this type. + * + * Returns: An Importer object. + */ + Importer loadFile (in string filename); + }; +}; +}; diff --git a/shell/importer/Makefile.am b/shell/importer/Makefile.am new file mode 100644 index 0000000000..e921636181 --- /dev/null +++ b/shell/importer/Makefile.am @@ -0,0 +1,47 @@ +INCLUDES = -I$(top_srcdir) -I$(includedir) $(GNOME_INCLUDEDIR) \ + -DG_LOG_DOMAIN=\"Evolution-Importer\" -g -Wall \ + -Wmissing-prototypes -Wmissing-declarations \ + -DEVOLUTION_GLADEDIR=\"$(datadir)/evolution/glade\" + +lib_LTLIBRARIES = libevolution-importer.la + +noinst_LIBRARIES = libimporter.a + +IDLS = \ + GNOME_Evolution_Importer.idl + +IDL_GENERATED = \ + GNOME_Evolution_Importer.h \ + GNOME_Evolution_Importer-common.c \ + GNOME_Evolution_Importer-skels.c \ + GNOME_Evolution_Importer-stubs.c + +GNOME_Evolution_Importer-impl.o: GNOME_Evolution_Importer.h + +$(IDL_GENERATED): $(IDLS) + $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ + $(srcdir)/GNOME_Evolution_Importer.idl + +idldir = $(datadir)/idl +idl_DATA = $(IDLS) + +libimporter_a_SOURCES = \ + importer.c \ + importer.h + +libevolution_importerincludedir = $(includedir)/evolution/importer +libevolution_importer_la_SOURCES = \ + $(IDL_GENERATED) \ + evolution-importer-factory.c \ + evolution-importer-client.c \ + evolution-importer.c + +libevolution_importerinclude_HEADERS = \ + evolution-importer-factory.h \ + evolution-importer-client.h \ + evolution-importer.h + +gladedir = $(datadir)/evolution/glade +glade_DATA = import.glade + +EXTRA_DIST = $(glade_DATA) diff --git a/shell/importer/evolution-importer-client.c b/shell/importer/evolution-importer-client.c new file mode 100644 index 0000000000..2ed190ce71 --- /dev/null +++ b/shell/importer/evolution-importer-client.c @@ -0,0 +1,336 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-importer-listener.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> + * Based on evolution-shell-component-client.c by Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <bonobo/bonobo-object.h> +#include <bonobo/bonobo-main.h> +#include <gal/util/e-util.h> + +#include "GNOME_Evolution_Importer.h" +#include "evolution-importer-client.h" + + +#define PARENT_TYPE BONOBO_OBJECT_CLIENT_TYPE +static BonoboObjectClass *parent_class = NULL; + +struct _EvolutionImporterClientPrivate { + EvolutionImporterClientCallback callback; + void *closure; + + GNOME_Evolution_ImporterListener listener_interface; + PortableServer_Servant listener_servant; +}; + + +static PortableServer_ServantBase__epv Listener_base_epv; +static POA_GNOME_Evolution_ImporterListener__epv Listener_epv; +static POA_GNOME_Evolution_ImporterListener__vepv Listener_vepv; +static gboolean Listener_vepv_initialized = FALSE; + +struct _ImporterListenerServant { + POA_GNOME_Evolution_ImporterListener servant; + EvolutionImporterClient *component_client; +}; +typedef struct _ImporterListenerServant ImporterListenerServant; + + + +static void +dispatch_callback (EvolutionImporterClient *client, + EvolutionImporterResult result, + gboolean more_items) +{ + EvolutionImporterClientPrivate *priv; + EvolutionImporterClientCallback callback; + PortableServer_ObjectId *oid; + void *closure; + CORBA_Environment ev; + + priv = client->private; + + g_return_if_fail (priv->callback != NULL); + g_return_if_fail (priv->listener_servant != NULL); + + CORBA_exception_init (&ev); + + oid = PortableServer_POA_servant_to_id (bonobo_poa (), priv->listener_servant, &ev); + PortableServer_POA_deactivate_object (bonobo_poa (), oid, &ev); + POA_GNOME_Evolution_ImporterListener__fini (priv->listener_servant, &ev); + CORBA_free (oid); + + CORBA_Object_release (priv->listener_interface, &ev); + CORBA_exception_free (&ev); + + priv->listener_servant = NULL; + priv->listener_interface = CORBA_OBJECT_NIL; + + callback = priv->callback; + closure = priv->closure; + + priv->callback = NULL; + priv->closure = NULL; + + (* callback) (client, result, more_items, closure); +} + +static EvolutionImporterClient * +component_client_from_ImporterListener_servant (PortableServer_Servant servant) +{ + ImporterListenerServant *listener_servant; + + listener_servant = (ImporterListenerServant *) servant; + return listener_servant->component_client; +} + +static EvolutionImporterResult +result_from_async_corba_result (GNOME_Evolution_ImporterListener_ImporterResult corba_result) +{ + switch (corba_result) { + case GNOME_Evolution_ImporterListener_OK: + return EVOLUTION_IMPORTER_OK; + case GNOME_Evolution_ImporterListener_UNSUPPORTED_OPERATION: + return EVOLUTION_IMPORTER_UNSUPPORTED_OPERATION; + case GNOME_Evolution_ImporterListener_UNKNOWN_DATA: + return EVOLUTION_IMPORTER_UNKNOWN_DATA; + case GNOME_Evolution_ImporterListener_BAD_DATA: + return EVOLUTION_IMPORTER_BAD_DATA; + case GNOME_Evolution_ImporterListener_BAD_FILE: + return EVOLUTION_IMPORTER_BAD_FILE; + case GNOME_Evolution_ImporterListener_NOT_READY: + return EVOLUTION_IMPORTER_NOT_READY; + default: + return EVOLUTION_IMPORTER_UNKNOWN_ERROR; + } +} + +static void +impl_ImporterListener_notifyResult (PortableServer_Servant servant, + const GNOME_Evolution_ImporterListener_ImporterResult result, + const CORBA_boolean more_items, + CORBA_Environment *ev) +{ + EvolutionImporterClient *client; + + client = component_client_from_ImporterListener_servant (servant); + dispatch_callback (client, result_from_async_corba_result (result), more_items); +} + +static void +ImporterListener_vepv_initialize (void) +{ + Listener_base_epv._private = NULL; + Listener_base_epv.finalize = NULL; + Listener_base_epv.default_POA = NULL; + + Listener_epv.notifyResult = impl_ImporterListener_notifyResult; + + Listener_vepv._base_epv = &Listener_base_epv; + Listener_vepv.GNOME_Evolution_ImporterListener_epv = &Listener_epv; + + Listener_vepv_initialized = TRUE; +} + +static PortableServer_Servant * +create_listener_servant (EvolutionImporterClient *client) +{ + ImporterListenerServant *servant; + + if (!Listener_vepv_initialized) + ImporterListener_vepv_initialize (); + + servant = g_new0 (ImporterListenerServant, 1); + servant->servant.vepv = &Listener_vepv; + servant->component_client = client; + + return (PortableServer_Servant) servant; +} + +static void +free_listener_servant (PortableServer_Servant servant) +{ + g_free (servant); +} + +static void +create_listener_interface (EvolutionImporterClient *client) +{ + EvolutionImporterClientPrivate *priv; + PortableServer_Servant listener_servant; + GNOME_Evolution_ImporterListener corba_interface; + CORBA_Environment ev; + + priv = client->private; + + listener_servant = create_listener_servant (client); + CORBA_exception_init (&ev); + + POA_GNOME_Evolution_ImporterListener__init (listener_servant, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + free_listener_servant (listener_servant); + return; + } + + CORBA_free (PortableServer_POA_activate_object (bonobo_poa (), + listener_servant, &ev)); + corba_interface = PortableServer_POA_servant_to_reference (bonobo_poa (), + listener_servant, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + corba_interface = CORBA_OBJECT_NIL; + free_listener_servant (listener_servant); + } + + CORBA_exception_free (&ev); + + priv->listener_servant = listener_servant; + priv->listener_interface = corba_interface; +} + + + +static void +destroy (GtkObject *object) +{ + EvolutionImporterClient *client; + EvolutionImporterClientPrivate *priv; + + client = EVOLUTION_IMPORTER_CLIENT (object); + priv = client->private; + + if (priv->callback != NULL) + dispatch_callback (client, EVOLUTION_IMPORTER_INTERRUPTED, FALSE); + + g_free (priv); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +class_init (EvolutionImporterClientClass *klass) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (klass); + parent_class = gtk_type_class (PARENT_TYPE); + + object_class->destroy = destroy; +} + +static void +init (EvolutionImporterClient *client) +{ + EvolutionImporterClientPrivate *priv; + + priv = g_new (EvolutionImporterClientPrivate, 1); + priv->listener_interface = CORBA_OBJECT_NIL; + priv->listener_servant = NULL; + priv->callback = NULL; + priv->closure = NULL; + + client->private = priv; +} + +void +evolution_importer_client_construct (EvolutionImporterClient *client, + CORBA_Object corba_object) +{ + g_return_if_fail (client != NULL); + g_return_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client)); + g_return_if_fail (corba_object != CORBA_OBJECT_NIL); + + bonobo_object_client_construct (BONOBO_OBJECT_CLIENT (client), corba_object); +} + +EvolutionImporterClient * +evolution_importer_client_new (const GNOME_Evolution_Importer objref) +{ + EvolutionImporterClient *client; + + g_return_val_if_fail (objref != CORBA_OBJECT_NIL, NULL); + + client = gtk_type_new (evolution_importer_client_get_type ()); + evolution_importer_client_construct (client, objref); + + return client; +} + +/* API */ +void +evolution_importer_client_process_item (EvolutionImporterClient *client, + EvolutionImporterClientCallback callback, + void *closure) +{ + EvolutionImporterClientPrivate *priv; + GNOME_Evolution_Importer corba_importer; + CORBA_Environment ev; + + g_return_if_fail (client != NULL); + g_return_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client)); + g_return_if_fail (callback != NULL); + + priv = client->private; + + if (priv->callback != NULL) { + (* callback) (client, EVOLUTION_IMPORTER_BUSY, FALSE, closure); + return; + } + + create_listener_interface (client); + + CORBA_exception_init (&ev); + + corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client)); + priv->callback = callback; + priv->closure = closure; + + GNOME_Evolution_Importer_processItem (corba_importer, + priv->listener_interface, &ev); + CORBA_exception_free (&ev); +} + +const char * +evolution_importer_client_get_error (EvolutionImporterClient *client) +{ + EvolutionImporterClientPrivate *priv; + GNOME_Evolution_Importer corba_importer; + CORBA_char *str; + CORBA_Environment ev; + + g_return_val_if_fail (client != NULL, NULL); + g_return_val_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client), NULL); + + priv = client->private; + corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client)); + + CORBA_exception_init (&ev); + str = GNOME_Evolution_Importer_getError (corba_importer, &ev); + + return str; +} + +E_MAKE_TYPE (evolution_importer_client, "EvolutionImporterClient", + EvolutionImporterClient, class_init, init, PARENT_TYPE) diff --git a/shell/importer/evolution-importer-client.h b/shell/importer/evolution-importer-client.h new file mode 100644 index 0000000000..464cce826f --- /dev/null +++ b/shell/importer/evolution-importer-client.h @@ -0,0 +1,76 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-importer-client.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_CLIENT_H +#define EVOLUTION_IMPORTER_CLIENT_H + +#include <bonobo/bonobo-object-client.h> + +#include "evolution-importer.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif + +#define EVOLUTION_TYPE_IMPORTER_CLIENT (evolution_importer_client_get_type ()) +#define EVOLUTION_IMPORTER_CLIENT(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_IMPORTER_CLIENT, EvolutionImporterClient)) +#define EVOLUTION_IMPORTER_CLIENT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_IMPORTER_CLIENT, EvolutionImporterClientClass)) +#define EVOLUTION_IS_IMPORTER_CLIENT(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_IMPORTER_CLIENT)) +#define EVOLUTION_IS_IMPORTER_CLIENT_CLASS(klass) (GTK_CHECK_TYPE ((klass), EVOLUTION_TYPE_IMPORTER_CLIENT)) + + +typedef struct _EvolutionImporterClient EvolutionImporterClient; +typedef struct _EvolutionImporterClientPrivate EvolutionImporterClientPrivate; +typedef struct _EvolutionImporterClientClass EvolutionImporterClientClass; + +struct _EvolutionImporterClient { + BonoboObjectClient parent; + + EvolutionImporterClientPrivate *private; +}; + +struct _EvolutionImporterClientClass { + BonoboObjectClientClass parent_class; +}; + +typedef void (* EvolutionImporterClientCallback) (EvolutionImporterClient *client, + EvolutionImporterResult result, + gboolean more_items, + 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 GNOME_Evolution_Importer objref); + +void evolution_importer_client_process_item (EvolutionImporterClient *client, + EvolutionImporterClientCallback callback, + void *closure); +const char *evolution_importer_client_get_error (EvolutionImporterClient *client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/shell/importer/evolution-importer-factory.c b/shell/importer/evolution-importer-factory.c new file mode 100644 index 0000000000..b31c308571 --- /dev/null +++ b/shell/importer/evolution-importer-factory.c @@ -0,0 +1,225 @@ +/* -*- 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 new file mode 100644 index 0000000000..bff0a23e8d --- /dev/null +++ b/shell/importer/evolution-importer-factory.h @@ -0,0 +1,77 @@ +/* -*- 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 new file mode 100644 index 0000000000..71b32de92e --- /dev/null +++ b/shell/importer/evolution-importer.c @@ -0,0 +1,218 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-importer.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.h" + + +#define PARENT_TYPE BONOBO_OBJECT_TYPE +static BonoboObjectClass *parent_class = NULL; + +struct _EvolutionImporterPrivate { + EvolutionImporterProcessItemFn process_item_fn; + EvolutionImporterGetErrorFn get_error_fn; + + void *closure; +}; + + +static POA_GNOME_Evolution_Importer__vepv Importer_vepv; + +static POA_GNOME_Evolution_Importer * +create_servant (void) +{ + POA_GNOME_Evolution_Importer *servant; + CORBA_Environment ev; + + servant = (POA_GNOME_Evolution_Importer *) g_new0 (BonoboObjectServant, 1); + servant->vepv = &Importer_vepv; + + CORBA_exception_init (&ev); + POA_GNOME_Evolution_Importer__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 void +impl_GNOME_Evolution_Importer_processItem (PortableServer_Servant servant, + GNOME_Evolution_ImporterListener listener, + 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->process_item_fn != NULL) + (priv->process_item_fn) (importer, listener, priv->closure, ev); + else + GNOME_Evolution_ImporterListener_notifyResult (listener, + GNOME_Evolution_ImporterListener_UNSUPPORTED_OPERATION, FALSE, ev); +} + +static CORBA_char * +impl_GNOME_Evolution_Importer_getError (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionImporter *importer; + EvolutionImporterPrivate *priv; + CORBA_char *out_str; + + bonobo_object = bonobo_object_from_servant (servant); + importer = EVOLUTION_IMPORTER (bonobo_object); + priv = importer->private; + + if (priv->get_error_fn != NULL) { + out_str = (priv->get_error_fn) (importer, priv->closure); + return CORBA_string_dup (out_str ? out_str : ""); + } else + return CORBA_string_dup (""); +} + + +static void +destroy (GtkObject *object) +{ + EvolutionImporter *importer; + EvolutionImporterPrivate *priv; + + importer = EVOLUTION_IMPORTER (object); + priv = importer->private; + + if (priv == NULL) + return; + + g_free (priv); + importer->private = NULL; + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +corba_class_init (void) +{ + POA_GNOME_Evolution_Importer__vepv *vepv; + POA_GNOME_Evolution_Importer__epv *epv; + PortableServer_ServantBase__epv *base_epv; + + base_epv = g_new0 (PortableServer_ServantBase__epv, 1); + + epv = g_new0 (POA_GNOME_Evolution_Importer__epv, 1); + epv->processItem = impl_GNOME_Evolution_Importer_processItem; + epv->getError = impl_GNOME_Evolution_Importer_getError; + + vepv = &Importer_vepv; + vepv->_base_epv = base_epv; + vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); + vepv->GNOME_Evolution_Importer_epv = epv; +} + +static void +class_init (EvolutionImporterClass *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 (EvolutionImporter *importer) +{ + EvolutionImporterPrivate *priv; + + priv = g_new0 (EvolutionImporterPrivate, 1); + + importer->private = priv; +} + + + +void +evolution_importer_construct (EvolutionImporter *importer, + GNOME_Evolution_Importer corba_object, + EvolutionImporterProcessItemFn process_item_fn, + EvolutionImporterGetErrorFn get_error_fn, + void *closure) +{ + EvolutionImporterPrivate *priv; + + 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 (process_item_fn != NULL); + g_return_if_fail (get_error_fn != NULL); + + bonobo_object_construct (BONOBO_OBJECT (importer), corba_object); + + priv = importer->private; + priv->process_item_fn = process_item_fn; + priv->get_error_fn = get_error_fn; + + priv->closure = closure; +} + +EvolutionImporter * +evolution_importer_new (EvolutionImporterProcessItemFn process_item_fn, + EvolutionImporterGetErrorFn get_error_fn, + void *closure) +{ + EvolutionImporter *importer; + POA_GNOME_Evolution_Importer *servant; + GNOME_Evolution_Importer corba_object; + + servant = create_servant (); + if (servant == NULL) + return NULL; + + 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); + return importer; +} + +E_MAKE_TYPE (evolution_importer, "EvolutionImporter", EvolutionImporter, + class_init, init, PARENT_TYPE); diff --git a/shell/importer/evolution-importer.h b/shell/importer/evolution-importer.h new file mode 100644 index 0000000000..be4ca1b34d --- /dev/null +++ b/shell/importer/evolution-importer.h @@ -0,0 +1,92 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-importer.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_H +#define EVOLUTION_IMPORTER_H + +#include <bonobo/bonobo-object.h> + +#include "GNOME_Evolution_Importer.h" +#include "evolution-importer.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* cplusplus */ + +#define EVOLUTION_TYPE_IMPORTER (evolution_importer_get_type ()) +#define EVOLUTION_IMPORTER(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_IMPORTER, EvolutionImporter)) +#define EVOLUTION_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_IMPORTER, EvolutionImporterClass)) +#define EVOLUTION_IS_IMPORTER(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_IMPORTER)) +#define EVOLUTION_IS_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_IMPORTER)) + +typedef struct _EvolutionImporter EvolutionImporter; +typedef struct _EvolutionImporterPrivate EvolutionImporterPrivate; +typedef struct _EvolutionImporterClass EvolutionImporterClass; +typedef enum _EvolutionImporterResult EvolutionImporterResult; + +typedef void (* EvolutionImporterProcessItemFn) (EvolutionImporter *importer, + GNOME_Evolution_ImporterListener listener, + void *closure, + CORBA_Environment *ev); +typedef char *(* EvolutionImporterGetErrorFn) (EvolutionImporter *importer, + void *closure); + +enum _EvolutionImporterResult { + EVOLUTION_IMPORTER_OK, + EVOLUTION_IMPORTER_UNSUPPORTED_OPERATION, + EVOLUTION_IMPORTER_INTERRUPTED, + EVOLUTION_IMPORTER_BUSY, + EVOLUTION_IMPORTER_NOT_READY, + EVOLUTION_IMPORTER_UNKNOWN_DATA, + EVOLUTION_IMPORTER_BAD_DATA, + EVOLUTION_IMPORTER_BAD_FILE, + EVOLUTION_IMPORTER_UNKNOWN_ERROR +}; + +struct _EvolutionImporter { + BonoboObject parent; + + EvolutionImporterPrivate *private; +}; + +struct _EvolutionImporterClass { + BonoboObjectClass parent_class; +}; + +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, + EvolutionImporterGetErrorFn get_error_fn, + void *closure); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/shell/importer/import.glade b/shell/importer/import.glade new file mode 100644 index 0000000000..3ff4cbaee0 --- /dev/null +++ b/shell/importer/import.glade @@ -0,0 +1,104 @@ +<?xml version="1.0"?> +<GTK-Interface> + +<project> + <name>import</name> + <program_name>import</program_name> + <directory></directory> + <source_directory>src</source_directory> + <pixmaps_directory>pixmaps</pixmaps_directory> + <language>C</language> + <gnome_support>True</gnome_support> + <gettext_support>True</gettext_support> + <use_widget_names>False</use_widget_names> + <output_main_file>True</output_main_file> + <output_support_files>True</output_support_files> + <output_build_files>True</output_build_files> + <backup_source_files>True</backup_source_files> + <main_source_file>interface.c</main_source_file> + <main_header_file>interface.h</main_header_file> + <handler_source_file>callbacks.c</handler_source_file> + <handler_header_file>callbacks.h</handler_header_file> + <support_source_file>support.c</support_source_file> + <support_header_file>support.h</support_header_file> + <translatable_strings_file></translatable_strings_file> +</project> + +<widget> + <class>GtkWindow</class> + <name>importwizard</name> + <cxx_use_heap>True</cxx_use_heap> + <visible>False</visible> + <title>Evolution Importer Utility</title> + <type>GTK_WINDOW_TOPLEVEL</type> + <position>GTK_WIN_POS_NONE</position> + <modal>False</modal> + <allow_shrink>False</allow_shrink> + <allow_grow>True</allow_grow> + <auto_shrink>False</auto_shrink> + + <widget> + <class>GnomeDruid</class> + <name>druid1</name> + <cxx_use_heap>True</cxx_use_heap> + + <widget> + <class>GnomeDruidPageStart</class> + <name>page1</name> + <cxx_use_heap>True</cxx_use_heap> + <title>Evolution Import Utility</title> + <text>Welcome to the Evolution Import Utility. +With this wizard you will be guided through the process of +importing external files into Evolution.</text> + <title_color>1,1,1</title_color> + <text_color>0,0,0</text_color> + <background_color>153,174,191</background_color> + <logo_background_color>255,255,255</logo_background_color> + <textbox_color>255,255,255</textbox_color> + </widget> + + <widget> + <class>GnomeDruidPageStandard</class> + <name>page2</name> + <cxx_use_heap>True</cxx_use_heap> + <title>Select a file</title> + <title_color>1,1,1</title_color> + <background_color>153,174,191</background_color> + <logo_background_color>255,255,255</logo_background_color> + + <widget> + <class>GtkVBox</class> + <child_name>GnomeDruidPageStandard:vbox</child_name> + <name>druid-vbox1</name> + <cxx_use_heap>True</cxx_use_heap> + <homogeneous>False</homogeneous> + <spacing>0</spacing> + <child> + <padding>0</padding> + <expand>True</expand> + <fill>True</fill> + </child> + + <widget> + <class>Placeholder</class> + </widget> + </widget> + </widget> + + <widget> + <class>GnomeDruidPageFinish</class> + <name>page3</name> + <cxx_use_heap>True</cxx_use_heap> + <title>Import</title> + <text>Click "Finish" to begin importing the file into Evolution. +***FIXME: Change the name of the finish button***</text> + <background_color>153,174,191</background_color> + <logo_background_color>255,255,255</logo_background_color> + <textbox_color>255,255,255</textbox_color> + <text_color>0,0,0</text_color> + <title_color>1,1,1</title_color> + </widget> + </widget> +</widget> + +</GTK-Interface> diff --git a/shell/importer/importer.c b/shell/importer/importer.c new file mode 100644 index 0000000000..71373937db --- /dev/null +++ b/shell/importer/importer.c @@ -0,0 +1,506 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* importer.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 <gnome.h> + +#include <liboaf/liboaf.h> + +#include <evolution-importer-client.h> + +#include <glade/glade.h> +#include <gtkhtml/gtkhtml.h> +#include <e-util/e-html-utils.h> + +#include "importer.h" + +typedef struct _ImportDialogFilePage { + GtkWidget *vbox; + GtkWidget *filename; + GtkWidget *filetype; + GtkWidget *menu; + + gboolean need_filename; +} ImportDialogFilePage; + +typedef struct _ImportData { + GladeXML *wizard; + GtkWidget *dialog; + GtkWidget *druid; + ImportDialogFilePage *filepage; + GtkWidget *filedialog; + GtkWidget *vbox; + + char *choosen_iid; +} ImportData; + +/* Some HTML helper functions from mail/mail-config-gui.c */ +static void +html_size_req (GtkWidget *widget, + GtkRequisition *requisition) +{ + requisition->height = GTK_LAYOUT (widget)->height; +} + +/* Returns a GtkHTML which is already inside a GtkScrolledWindow. If + * @white is TRUE, the GtkScrolledWindow will be inside a GtkFrame. + */ +static GtkWidget * +html_new (gboolean white) +{ + GtkWidget *html, *scrolled, *frame; + GtkStyle *style; + + html = gtk_html_new (); + GTK_LAYOUT (html)->height = 0; + gtk_signal_connect (GTK_OBJECT (html), "size_request", + GTK_SIGNAL_FUNC (html_size_req), NULL); + gtk_html_set_editable (GTK_HTML (html), FALSE); + style = gtk_rc_get_style (html); + if (style) { + gtk_html_set_default_background_color (GTK_HTML (html), + white ? &style->white: + &style->bg[0]); + } + gtk_widget_set_sensitive (html, FALSE); + scrolled = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), + GTK_POLICY_NEVER, GTK_POLICY_NEVER); + gtk_container_add (GTK_CONTAINER (scrolled), html); + if (white) { + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), + GTK_SHADOW_ETCHED_IN); + gtk_container_add (GTK_CONTAINER (frame), scrolled); + gtk_widget_show_all (frame); + } else { + gtk_widget_show_all (scrolled); + } + + return html; +} + +static void +put_html (GtkHTML *html, + const char *text) +{ + GtkHTMLStream *handle; + char *htmltext; + + htmltext = e_text_to_html (text, E_TEXT_TO_HTML_CONVERT_NL); + handle = gtk_html_begin (html); + gtk_html_write (html, handle, "<HTML><BODY>", 12); + gtk_html_write (html, handle, text, strlen (text)); + gtk_html_write (html, handle, "</BODY></HTML>", 14); + g_free (htmltext); + gtk_html_end (html, handle, GTK_HTML_STREAM_OK); +} + +/* Importing functions */ + +/* Data to be passed around */ +typedef struct _ImporterComponentData { + EvolutionImporterClient *client; + char *filename; + + GnomeDialog *dialog; + GtkWidget *contents; + + int item; +} ImporterComponentData; + +static gboolean importer_timeout_fn (gpointer data); +static void +import_cb (EvolutionImporterClient *client, + EvolutionImporterResult result, + gboolean more_items, + void *data) +{ + ImporterComponentData *icd = (ImporterComponentData *) data; + char *label; + + g_warning ("Recieved callback. Result: %d\tmore_items: %s", result, + more_items ? "TRUE" : "FALSE"); + if (result == EVOLUTION_IMPORTER_NOT_READY) { + /* Importer isn't ready yet. Wait 5 seconds and try again. */ + + label = g_strdup_printf (_("Importing %s\nImporter not ready." + "\nWaiting 5 seconds to retry."), + icd->filename); + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + gtk_timeout_add (5000, importer_timeout_fn, data); + return; + } + + if (more_items) { + label = g_strdup_printf (_("Importing %s\nImporting item %d."), + icd->filename, ++(icd->item)); + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + evolution_importer_client_process_item (client, import_cb, data); + return; + } + + g_free (icd->filename); + gtk_object_unref (GTK_OBJECT (icd->dialog)); + bonobo_object_unref (BONOBO_OBJECT (icd->client)); + g_free (icd); +} + +static gboolean +importer_timeout_fn (gpointer data) +{ + ImporterComponentData *icd = (ImporterComponentData *) data; + char *label; + + label = g_strdup_printf (_("Importing %s\nImporting item %d."), + icd->filename, icd->item); + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + evolution_importer_client_process_item (icd->client, import_cb, data); + return FALSE; +} + +static void +start_import (const char *filename, + const char *iid) +{ + if (iid == NULL || strcmp (iid, "Automatic") == 0) { + /* Work out the component to use */ + } else { + CORBA_Object factory, importer; + EvolutionImporterClient *client; + ImporterComponentData *icd; + CORBA_Environment ev; + char *label; + + icd = g_new (ImporterComponentData, 1); + icd->dialog = gnome_dialog_new (_("Importing"), + GNOME_STOCK_BUTTON_CANCEL, + NULL); + + label = g_strdup_printf (_("Importing %s.\nStarting %s"), + filename, iid); + icd->contents = gtk_label_new (label); + g_free (label); + + gtk_box_pack_start (GTK_BOX (icd->dialog->vbox), icd->contents, + TRUE, TRUE, 0); + gtk_widget_show_all (GTK_WIDGET (icd->dialog)); + while (gtk_events_pending ()) + gtk_main_iteration (); + + CORBA_exception_init (&ev); + factory = oaf_activate_from_id ((char *) iid, 0, NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + label = g_strdup_printf (_("Importing %s\n" + "Cannot activate %s."), + filename, iid); + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + g_free (icd); + 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)); + + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + g_free (icd); + 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; + + label = g_strdup_printf (_("Importing %s\nImporting item 1."), + filename); + gtk_label_set_text (GTK_LABEL (icd->contents), label); + g_free (label); + while (gtk_events_pending ()) + gtk_main_iteration (); + + evolution_importer_client_process_item (client, import_cb, icd); + } +} + +static void +filename_changed (GtkEntry *entry, + ImportData *data) +{ + ImportDialogFilePage *page; + char *filename; + + page = data->filepage; + + filename = gtk_entry_get_text (entry); + if (filename != NULL && *filename != '\0') + page->need_filename = FALSE; + else + page->need_filename = TRUE; + + gnome_druid_set_buttons_sensitive (GNOME_DRUID (data->druid), + TRUE, !page->need_filename, TRUE); +} + +static const char * +get_name_from_component_info (const OAF_ServerInfo *info) +{ + OAF_Property *property; + const char *name; + + property = oaf_server_info_prop_find ((OAF_ServerInfo *) info, + "evolution:menu-name"); + if (property == NULL || property->v._d != OAF_P_STRING) + return NULL; + + name = property->v._u.value_string; + + return name; +} + +static void +item_selected (GtkWidget *item, + ImportData *data) +{ + char *iid; + + g_free (data->choosen_iid); + iid = gtk_object_get_data (GTK_OBJECT (item), "oafiid"); + g_print ("iid: %s\n", iid); + if (iid == NULL) + data->choosen_iid = g_strdup ("Automatic"); + else + data->choosen_iid = g_strdup (iid); +} + +static GtkWidget * +create_plugin_menu (ImportData *data) +{ + OAF_ServerInfoList *info_list; + CORBA_Environment ev; + int i; + GtkWidget *menu; + GtkWidget *item; + + menu = gtk_menu_new (); + item = gtk_menu_item_new_with_label (_("Automatic")); + gtk_object_set_data_full (GTK_OBJECT (item), "oafiid", + g_strdup ("Automatic"), g_free); + 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); + for (i = 0; i < info_list->_length; i++) { + const OAF_ServerInfo *info; + char *name = NULL; + + info = info_list->_buffer + i; + + name = g_strdup (get_name_from_component_info (info)); + if (name == NULL) { + name = g_strdup (info->iid); + } + + item = gtk_menu_item_new_with_label (name); + g_free (name); + + gtk_signal_connect (GTK_OBJECT (item), "activate", + GTK_SIGNAL_FUNC (item_selected), data); + + gtk_object_set_data_full (GTK_OBJECT (item), "oafiid", + g_strdup (info->iid), g_free); + gtk_menu_append (GTK_MENU (menu), item); + } + + return menu; +} + +static ImportDialogFilePage * +importer_file_page_new (ImportData *data) +{ + ImportDialogFilePage *page; + GtkWidget *table, *label; + int row = 0; + + page = g_new0 (ImportDialogFilePage, 1); + + page->vbox = gtk_vbox_new (FALSE, 5); + page->need_filename = TRUE; + + table = gtk_table_new (2, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 2); + gtk_table_set_col_spacings (GTK_TABLE (table), 10); + gtk_container_set_border_width (GTK_CONTAINER (table), 8); + gtk_box_pack_start (GTK_BOX (page->vbox), table, TRUE, TRUE, 0); + + label = gtk_label_new (_("Filename:")); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1, + GTK_FILL, 0, 0, 0); + gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5); + + page->filename = gnome_file_entry_new (NULL, _("Select a file")); + gtk_signal_connect (GTK_OBJECT (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (page->filename))), + "changed", GTK_SIGNAL_FUNC (filename_changed), + data); + + gtk_table_attach (GTK_TABLE (table), page->filename, 1, 2, + row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); + + row++; + + label = gtk_label_new (_("File type:")); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1, + GTK_FILL, 0, 0, 0); + gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5); + + page->filetype = gtk_option_menu_new (); + page->menu = create_plugin_menu (data); + gtk_option_menu_set_menu (GTK_OPTION_MENU (page->filetype), page->menu); + + gtk_table_attach (GTK_TABLE (table), page->filetype, 1, 2, + row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); + gtk_widget_show_all (table); + + return page; +} + +static void +import_druid_cancel (GnomeDruid *druid, + ImportData *data) +{ + gtk_object_unref (GTK_OBJECT (data->wizard)); + gtk_widget_destroy (GTK_WIDGET (data->dialog)); + g_free (data->choosen_iid); + g_free (data); +} + +static void +import_druid_finish (GnomeDruidPage *page, + GnomeDruid *druid, + ImportData *data) +{ + char *filename; + + filename = g_strdup (gtk_entry_get_text (GTK_ENTRY (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (data->filepage->filename))))); + g_print ("You have selected %s to be imported with %s\n", filename, + data->choosen_iid); + start_import (filename, data->choosen_iid); + + gtk_widget_destroy (data->dialog); + g_free (filename); +} + +static gboolean +prepare_file_page (GnomeDruidPage *page, + GnomeDruid *druid, + ImportData *data) +{ + g_print ("Prepare thyself\n"); + gnome_druid_set_buttons_sensitive (druid, TRUE, + !data->filepage->need_filename, + TRUE); + return FALSE; +} + +void +show_import_wizard (void) +{ + ImportData *data = g_new0 (ImportData, 1); + GnomeDruidPageStart *start; + GnomeDruidPageFinish *finish; + GtkWidget *html; + + data->wizard = glade_xml_new (EVOLUTION_GLADEDIR "/import.glade", NULL); + data->dialog = glade_xml_get_widget (data->wizard, "importwizard"); + gtk_window_set_wmclass (GTK_WINDOW (data->dialog), "importdruid", + "Evolution:shell"); + + data->druid = glade_xml_get_widget (data->wizard, "druid1"); + gtk_signal_connect (GTK_OBJECT (data->druid), "cancel", + GTK_SIGNAL_FUNC (import_druid_cancel), data); + + start = GNOME_DRUID_PAGE_START (glade_xml_get_widget (data->wizard, "page1")); + data->filedialog = glade_xml_get_widget (data->wizard, "page2"); + gtk_signal_connect (GTK_OBJECT (data->filedialog), "prepare", + GTK_SIGNAL_FUNC (prepare_file_page), data); + + finish = GNOME_DRUID_PAGE_FINISH (glade_xml_get_widget (data->wizard, "page3")); + + data->filepage = importer_file_page_new (data); + data->vbox = data->filepage->vbox; + + html = html_new (TRUE); + put_html (GTK_HTML (html), + _("Choose the file that you want to import into Evolution," + "and select what type of file it is from the list.\n\n" + "You can select \"Automatic\" if you do not know, and" + "Evolution will attempt to work it out.")); + gtk_box_pack_start (GTK_BOX (data->vbox), html->parent->parent, + FALSE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (data->vbox), html->parent->parent, 0); + + gtk_box_pack_start (GTK_BOX (GNOME_DRUID_PAGE_STANDARD (data->filedialog)->vbox), data->vbox, TRUE, TRUE, 0); + + /* Finish page */ + gtk_signal_connect (GTK_OBJECT (finish), "finish", + GTK_SIGNAL_FUNC (import_druid_finish), data); + gtk_signal_connect (GTK_OBJECT (data->dialog), "destroy", + GTK_SIGNAL_FUNC (import_druid_cancel), data); + + gtk_widget_show_all (data->dialog); +} diff --git a/shell/importer/importer.h b/shell/importer/importer.h new file mode 100644 index 0000000000..ed457b9e15 --- /dev/null +++ b/shell/importer/importer.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* importer.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> + */ + +#ifndef __IMPORTER_H__ +#define __IMPORTER_H__ + +void show_import_wizard (void); + +#endif |