diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ChangeLog | 38 | ||||
-rw-r--r-- | shell/Evolution-Storage.idl | 5 | ||||
-rw-r--r-- | shell/e-local-storage.c | 98 | ||||
-rw-r--r-- | shell/e-shell.c | 4 | ||||
-rw-r--r-- | shell/evolution-storage.c | 38 | ||||
-rw-r--r-- | shell/importer/GNOME_Evolution_Importer.idl | 10 | ||||
-rw-r--r-- | shell/importer/Makefile.am | 3 | ||||
-rw-r--r-- | shell/importer/evolution-importer-listener.c | 52 | ||||
-rw-r--r-- | shell/importer/evolution-importer-listener.h | 14 | ||||
-rw-r--r-- | shell/importer/evolution-importer.c | 112 | ||||
-rw-r--r-- | shell/importer/evolution-importer.h | 13 | ||||
-rw-r--r-- | shell/importer/evolution-intelligent-importer.c | 198 | ||||
-rw-r--r-- | shell/importer/evolution-intelligent-importer.h | 74 | ||||
-rw-r--r-- | shell/importer/intelligent.c | 174 | ||||
-rw-r--r-- | shell/importer/intelligent.h | 0 |
15 files changed, 669 insertions, 164 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index 78eaf1c244..cf6ab7683e 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,41 @@ +2001-03-12 Iain Holmes <iain@ximian.com> + + * Evolution-Storage.idl: Add a FolderResult structure. + + * e-local-storage.c (struct _AsyncCreateFolderCallbackData): Add a + Bonobo_Listener. + (notify_listener): Function to...notify the listener. + (component_async_create_folder_callback): Use the notify_listener + function. + (real_do_folder_create): New prototype. Replace all returns with + a call to notify_listener. Make the directory with a call to + e_mkdir_hier instead of multiple calls to mkdir. Only emit a fail + on a bad error, not on EEXIST. + (bonobo_interface_create_folder_cb): Namespace create_folder_cb to match + the others. + + e-shell.c: Run the intelligent importer. + + evolution-storage.c (impl_Storage_async_create_folder): Just emit the signal, + not the callback. + (e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER): Lovely signal + marshaller. + (class_init): Change the signal definition for the create_folder signal. + + importer/GNOME_Evolution_Importer.idl: Add an IntelligentImporter inteface. + + importer/Makefile.am: Add the evolution-intelligent-importer.c, intelligent.c + and evolution-intelligent-importer.h to the files. + + importer/evolution-importer-listener.[ch]: Convert to BonoboXObject. + + importer/evolution-importer.[ch]: BonoboXObjectification. + + importer/evolution-intelligent-importer.[ch]: BonoboXObject for the + GNOME:Evolution:IntelligentImporter interface. + + importer/intelligent.c: Code for running the intelligent importers. + 2001-03-08 Ettore Perazzoli <ettore@ximian.com> * e-storage-set-view.c (get_folder_at_row): New helper function. diff --git a/shell/Evolution-Storage.idl b/shell/Evolution-Storage.idl index 879df8afb0..a0cf16a303 100644 --- a/shell/Evolution-Storage.idl +++ b/shell/Evolution-Storage.idl @@ -42,6 +42,11 @@ module Evolution { GENERIC_ERROR }; + struct FolderResult { + Result result; + string path; + }; + void asyncCreateFolder (in string path, in string type, in string description, diff --git a/shell/e-local-storage.c b/shell/e-local-storage.c index b669701be9..15247295e0 100644 --- a/shell/e-local-storage.c +++ b/shell/e-local-storage.c @@ -322,6 +322,7 @@ shell_component_result_to_storage_result (EvolutionShellComponentResult result) struct _AsyncCreateFolderCallbackData { EStorage *storage; + Bonobo_Listener listener; char *path; char *display_name; @@ -336,14 +337,38 @@ struct _AsyncCreateFolderCallbackData { typedef struct _AsyncCreateFolderCallbackData AsyncCreateFolderCallbackData; static void +notify_listener (const Bonobo_Listener listener, + EStorageResult result, + const char *physical_path) +{ + CORBA_any any; + GNOME_Evolution_Storage_FolderResult folder_result; + CORBA_Environment ev; + + folder_result.result = result; + folder_result.path = CORBA_string_dup (physical_path ? + physical_path : ""); + any._type = TC_GNOME_Evolution_Storage_FolderResult; + any._value = &folder_result; + + CORBA_exception_init (&ev); + Bonobo_Listener_event (listener, "evolution-shell:folder_created", + &any, &ev); + CORBA_exception_free (&ev); +} + +static void component_async_create_folder_callback (EvolutionShellComponentClient *shell_component_client, EvolutionShellComponentResult result, void *data) { AsyncCreateFolderCallbackData *callback_data; + EStorageResult storage_result; callback_data = (AsyncCreateFolderCallbackData *) data; + storage_result = shell_component_result_to_storage_result (result); + if (result != EVOLUTION_SHELL_COMPONENT_OK) { /* XXX: This assumes the component won't leave any files in the directory. */ rmdir (callback_data->physical_path); @@ -361,15 +386,19 @@ component_async_create_folder_callback (EvolutionShellComponentClient *shell_com } else { rmdir (callback_data->physical_path); gtk_object_unref (GTK_OBJECT (folder)); - result = E_STORAGE_IOERROR; + storage_result = E_STORAGE_IOERROR; } } bonobo_object_unref (BONOBO_OBJECT (shell_component_client)); + if (callback_data->listener != CORBA_OBJECT_NIL) + notify_listener (callback_data->listener, storage_result, + callback_data->physical_path); + if (callback_data->callback != NULL) (* callback_data->callback) (callback_data->storage, - shell_component_result_to_storage_result (result), + storage_result, callback_data->callback_data); g_free (callback_data->path); @@ -420,8 +449,9 @@ impl_get_name (EStorage *storage) return E_LOCAL_STORAGE_NAME; } -static int +static void real_do_folder_create (ELocalStorage *local_storage, + Bonobo_Listener listener, const char *path, const char *type, const char *description, @@ -445,7 +475,7 @@ real_do_folder_create (ELocalStorage *local_storage, if (callback != NULL) (* callback) (storage, E_STORAGE_INVALIDTYPE, data); - return E_STORAGE_INVALIDTYPE; + notify_listener (listener, E_STORAGE_INVALIDTYPE, NULL); } g_assert (g_path_is_absolute (path)); @@ -467,6 +497,7 @@ real_do_folder_create (ELocalStorage *local_storage, subfolders_directory_physical_path = g_concat_dir_and_file (parent_physical_path, SUBFOLDER_DIR_NAME); +#if 0 if (! g_file_exists (subfolders_directory_physical_path) && mkdir (subfolders_directory_physical_path, 0700) == -1) { g_free (parent_path); @@ -477,7 +508,8 @@ real_do_folder_create (ELocalStorage *local_storage, errno_to_storage_result (), data); return errno_to_storage_result (); } - +#endif + physical_path = g_concat_dir_and_file (subfolders_directory_physical_path, folder_name); g_free (subfolders_directory_physical_path); @@ -486,13 +518,17 @@ real_do_folder_create (ELocalStorage *local_storage, /* Create the directory that holds the folder. */ - if (mkdir (physical_path, 0700) == -1) { - g_free (physical_path); - if (callback != NULL) - (* callback) (storage, - errno_to_storage_result (), data); + if (e_mkdir_hier (physical_path, 0700) == -1) { - return errno_to_storage_result (); + /* Bad error which we can't recover from */ + if (errno != EEXIST) { + notify_listener (listener, errno_to_storage_result (), + physical_path); + g_free (physical_path); + if (callback != NULL) + (* callback) (storage, + errno_to_storage_result (), data); + } } /* Finally tell the component to do the job of creating the physical files in @@ -510,6 +546,7 @@ real_do_folder_create (ELocalStorage *local_storage, callback_data->description = g_strdup (description); callback_data->physical_uri = physical_uri; callback_data->physical_path = physical_path; + callback_data->listener = listener; callback_data->callback = callback; callback_data->callback_data = data; @@ -520,25 +557,6 @@ real_do_folder_create (ELocalStorage *local_storage, type, component_async_create_folder_callback, callback_data); - return EVOLUTION_STORAGE_OK; -} - -static int -create_folder_cb (EvolutionStorage *estorage, - const char *path, - const char *type, - const char *description, - const char *parent_p_path, - void *data) -{ - ELocalStorage *local_storage; - int ret; - - local_storage = E_LOCAL_STORAGE (data); - ret = real_do_folder_create (local_storage, path, type, - description, NULL, data); - - return ret; } static void @@ -552,7 +570,7 @@ impl_async_create_folder (EStorage *storage, ELocalStorage *local_storage; local_storage = E_LOCAL_STORAGE (storage); - real_do_folder_create (local_storage, path, type, + real_do_folder_create (local_storage, NULL, path, type, description, callback, data); } @@ -569,6 +587,21 @@ impl_async_remove_folder (EStorage *storage, /* Callbacks for the `Evolution::LocalStorage' interface we are exposing to the outside world. */ +static void +bonobo_interface_create_folder_cb (EvolutionStorage *estorage, + const Bonobo_Listener listener, + const char *path, + const char *type, + const char *description, + const char *parent_p_path, + void *data) +{ + ELocalStorage *local_storage; + + local_storage = E_LOCAL_STORAGE (data); + real_do_folder_create (local_storage, listener, path, type, + description, NULL, data); +} static void bonobo_interface_update_folder_cb (EvolutionLocalStorage *bonobo_local_storage, @@ -654,7 +687,8 @@ construct (ELocalStorage *local_storage, priv->bonobo_interface = evolution_local_storage_new (E_LOCAL_STORAGE_NAME); gtk_signal_connect (GTK_OBJECT (priv->bonobo_interface), "create_folder", - GTK_SIGNAL_FUNC (create_folder_cb), local_storage); + GTK_SIGNAL_FUNC (bonobo_interface_create_folder_cb), + local_storage); gtk_signal_connect (GTK_OBJECT (priv->bonobo_interface), "update_folder", GTK_SIGNAL_FUNC (bonobo_interface_update_folder_cb), local_storage); diff --git a/shell/e-shell.c b/shell/e-shell.c index 6656e2f79b..ba27c9a89f 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -752,6 +752,10 @@ e_shell_construct (EShell *shell, /* Now that we have a local storage, we can tell the components we are here. */ set_owner_on_components (shell); + /* Run the intelligent importers to find see if any data needs + importing. */ + intelligent_importer_init (); + shortcut_path = g_concat_dir_and_file (local_directory, "shortcuts.xml"); priv->shortcuts = e_shortcuts_new (priv->storage_set, priv->folder_type_registry, diff --git a/shell/evolution-storage.c b/shell/evolution-storage.c index bf02c19110..c3ffad319c 100644 --- a/shell/evolution-storage.c +++ b/shell/evolution-storage.c @@ -287,23 +287,12 @@ impl_Storage_async_create_folder (PortableServer_Servant servant, { BonoboObject *bonobo_object; EvolutionStorage *storage; - int int_result; - CORBA_any any; - GNOME_Evolution_Storage_Result corba_result; bonobo_object = bonobo_object_from_servant (servant); storage = EVOLUTION_STORAGE (bonobo_object); - int_result = GNOME_Evolution_Storage_UNSUPPORTED_OPERATION; gtk_signal_emit (GTK_OBJECT (storage), signals[CREATE_FOLDER], - path, type, description, parent_physical_uri, - &int_result); - - corba_result = storage_gtk_to_corba_result (int_result); - any._type = TC_GNOME_Evolution_Storage_Result; - any._value = &corba_result; - - Bonobo_Listener_event (listener, "result", &any, ev); + listener, path, type, description, parent_physical_uri); } static void @@ -435,6 +424,29 @@ corba_class_init (void) vepv->GNOME_Evolution_Storage_epv = evolution_storage_get_epv (); } +/* The worst signal marshaller in Scotland */ +typedef void (*GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER) (GtkObject *, + gpointer, gpointer, gpointer, gpointer, gpointer, + gpointer user_data); + +static void +e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER (GtkObject *object, + GtkSignalFunc func, + gpointer func_data, + GtkArg *args) +{ + GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER rfunc; + + rfunc = (GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER) func; + (*rfunc) (object, + GTK_VALUE_POINTER (args[0]), + GTK_VALUE_POINTER (args[1]), + GTK_VALUE_POINTER (args[2]), + GTK_VALUE_POINTER (args[3]), + GTK_VALUE_POINTER (args[4]), + func_data); +} + static void class_init (EvolutionStorageClass *klass) { @@ -450,7 +462,7 @@ class_init (EvolutionStorageClass *klass) object_class->type, GTK_SIGNAL_OFFSET (EvolutionStorageClass, create_folder), - e_marshal_INT__POINTER_POINTER_POINTER_POINTER, + e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER, GTK_TYPE_INT, 4, GTK_TYPE_STRING, GTK_TYPE_STRING, diff --git a/shell/importer/GNOME_Evolution_Importer.idl b/shell/importer/GNOME_Evolution_Importer.idl index fe49ab82c5..7dec5e7e0c 100644 --- a/shell/importer/GNOME_Evolution_Importer.idl +++ b/shell/importer/GNOME_Evolution_Importer.idl @@ -79,5 +79,15 @@ module Evolution { */ boolean loadFile (in string filename); }; + + interface IntelligentImporter : Bonobo::Unknown { + + readonly attribute string importername; + readonly attribute string message; + + boolean canImport (); + + void importData (); + }; }; }; diff --git a/shell/importer/Makefile.am b/shell/importer/Makefile.am index 96bbbafd5c..975d5a372a 100644 --- a/shell/importer/Makefile.am +++ b/shell/importer/Makefile.am @@ -27,14 +27,17 @@ idl_DATA = $(IDLS) libevolution_importerincludedir = $(includedir)/evolution/importer libevolution_importer_la_SOURCES = \ $(IDL_GENERATED) \ + evolution-intelligent-importer.c \ evolution-importer-client.c \ evolution-importer-listener.c \ evolution-importer.c \ + intelligent.c \ importer.c \ importer.h libevolution_importerinclude_HEADERS = \ GNOME_Evolution_Importer.h \ + evolution-intelligent-importer.h \ evolution-importer-client.h \ evolution-importer-listener.h \ evolution-importer.h diff --git a/shell/importer/evolution-importer-listener.c b/shell/importer/evolution-importer-listener.c index 35e73634d5..62dc35b19c 100644 --- a/shell/importer/evolution-importer-listener.c +++ b/shell/importer/evolution-importer-listener.c @@ -31,9 +31,9 @@ #include "GNOME_Evolution_Importer.h" #include "evolution-importer-listener.h" -#define PARENT_TYPE (bonobo_object_get_type ()) +#define PARENT_TYPE BONOBO_X_OBJECT_TYPE -static BonoboObjectClass *parent_class; +static BonoboObjectClass *parent_class = NULL; struct _EvolutionImporterListenerPrivate { EvolutionImporterListenerCallback callback; @@ -41,6 +41,7 @@ struct _EvolutionImporterListenerPrivate { void *closure; }; +#if 0 static POA_GNOME_Evolution_ImporterListener__vepv Listener_vepv; static POA_GNOME_Evolution_ImporterListener * @@ -64,6 +65,7 @@ create_servant (void) return servant; } +#endif static EvolutionImporterResult corba_result_to_evolution (GNOME_Evolution_ImporterListener_ImporterResult corba_result) @@ -88,20 +90,24 @@ corba_result_to_evolution (GNOME_Evolution_ImporterListener_ImporterResult corba } } +static inline EvolutionImporterListener * +evolution_importer_listener_from_servant (PortableServer_Servant servant) +{ + return EVOLUTION_IMPORTER_LISTENER (bonobo_object_from_servant (servant)); +} + static void impl_GNOME_Evolution_ImporterListener_notifyResult (PortableServer_Servant servant, GNOME_Evolution_ImporterListener_ImporterResult result, CORBA_boolean more_items, CORBA_Environment *ev) { - BonoboObject *bonobo_object; EvolutionImporterListener *listener; EvolutionImporterListenerPrivate *priv; EvolutionImporterResult out_result; - bonobo_object = bonobo_object_from_servant (servant); - listener = EVOLUTION_IMPORTER_LISTENER (bonobo_object); - priv = listener->private; + listener = evolution_importer_listener_from_servant (servant); + priv = listener->priv; out_result = corba_result_to_evolution (result); if (priv->callback) { @@ -121,17 +127,18 @@ destroy (GtkObject *object) EvolutionImporterListenerPrivate *priv; listener = EVOLUTION_IMPORTER_LISTENER (object); - priv = listener->private; + priv = listener->priv; if (priv == NULL) return; g_free (priv); - listener->private = NULL; + listener->priv = NULL; - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + GTK_OBJECT_CLASS (parent_class)->destroy (object); } +#if 0 static void corba_class_init (void) { @@ -152,32 +159,30 @@ corba_class_init (void) vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); vepv->GNOME_Evolution_ImporterListener_epv = epv; } +#endif static void -class_init (EvolutionImporterListenerClass *klass) +evolution_importer_listener_class_init (EvolutionImporterListenerClass *klass) { GtkObjectClass *object_class; + POA_GNOME_Evolution_ImporterListener__epv *epv = &klass->epv; object_class = GTK_OBJECT_CLASS (klass); object_class->destroy = destroy; parent_class = gtk_type_class (PARENT_TYPE); - - corba_class_init (); + epv->notifyResult = impl_GNOME_Evolution_ImporterListener_notifyResult; } static void -init (EvolutionImporterListener *listener) +evolution_importer_listener_init (EvolutionImporterListener *listener) { EvolutionImporterListenerPrivate *priv; priv = g_new0 (EvolutionImporterListenerPrivate, 1); - listener->private = priv; + listener->priv = priv; } -E_MAKE_TYPE (evolution_importer_listener, "EvolutionImporterListener", - EvolutionImporterListener, class_init, init, PARENT_TYPE); - static void evolution_importer_listener_construct (EvolutionImporterListener *listener, GNOME_Evolution_ImporterListener corba_object, @@ -191,7 +196,7 @@ evolution_importer_listener_construct (EvolutionImporterListener *listener, g_return_if_fail (corba_object != CORBA_OBJECT_NIL); g_return_if_fail (callback != NULL); - priv = listener->private; + priv = listener->priv; priv->callback = callback; priv->closure = closure; @@ -212,18 +217,15 @@ evolution_importer_listener_new (EvolutionImporterListenerCallback callback, void *closure) { EvolutionImporterListener *listener; - POA_GNOME_Evolution_ImporterListener *servant; GNOME_Evolution_ImporterListener corba_object; - servant = create_servant (); - if (servant == NULL) - return NULL; - listener = gtk_type_new (evolution_importer_listener_get_type ()); - corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (listener), - servant); evolution_importer_listener_construct (listener, corba_object, callback, closure); return listener; } + +BONOBO_X_TYPE_FUNC_FULL (EvolutionImporterListener, + GNOME_Evolution_ImporterListener, + PARENT_TYPE, evolution_importer_listener); diff --git a/shell/importer/evolution-importer-listener.h b/shell/importer/evolution-importer-listener.h index 33c4617332..e61fdb3465 100644 --- a/shell/importer/evolution-importer-listener.h +++ b/shell/importer/evolution-importer-listener.h @@ -24,8 +24,8 @@ #ifndef EVOLUTION_IMPORTER_LISTENER_H #define EVOLUTION_IMPORTER_LISTENER_H -#include <bonobo/bonobo-object.h> - +#include <bonobo/bonobo-xobject.h> +#include <importer/GNOME_Evolution_Importer.h> #include "evolution-importer.h" #ifdef __cplusplus @@ -48,13 +48,15 @@ typedef void (* EvolutionImporterListenerCallback) (EvolutionImporterListener *l gboolean more_items, void *closure); struct _EvolutionImporterListener { - BonoboObject parent; - - EvolutionImporterListenerPrivate *private; + BonoboXObject parent; + + EvolutionImporterListenerPrivate *priv; }; struct _EvolutionImporterListenerClass { - BonoboObjectClass parent_class; + BonoboXObjectClass parent_class; + + POA_GNOME_Evolution_ImporterListener__epv epv; }; GtkType evolution_importer_listener_get_type (void); diff --git a/shell/importer/evolution-importer.c b/shell/importer/evolution-importer.c index 85d2446a19..c48390c9e5 100644 --- a/shell/importer/evolution-importer.c +++ b/shell/importer/evolution-importer.c @@ -32,7 +32,7 @@ #include "evolution-importer.h" -#define PARENT_TYPE BONOBO_OBJECT_TYPE +#define PARENT_TYPE BONOBO_X_OBJECT_TYPE static BonoboObjectClass *parent_class = NULL; struct _EvolutionImporterPrivate { @@ -45,28 +45,10 @@ struct _EvolutionImporterPrivate { }; -static POA_GNOME_Evolution_Importer__vepv Importer_vepv; - -static POA_GNOME_Evolution_Importer * -create_servant (void) +static inline EvolutionImporter * +evolution_importer_from_servant (PortableServer_Servant servant) { - 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; + return EVOLUTION_IMPORTER (bonobo_object_from_servant (servant)); } static CORBA_boolean @@ -74,13 +56,11 @@ 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; + importer = evolution_importer_from_servant (servant); + priv = importer->priv; if (priv->support_format_fn != NULL) return (priv->support_format_fn) (importer, filename, @@ -94,13 +74,11 @@ 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; + importer = evolution_importer_from_servant (servant); + priv = importer->priv; if (priv->load_file_fn != NULL) return (priv->load_file_fn) (importer, filename, priv->closure); @@ -113,13 +91,11 @@ 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; + importer = evolution_importer_from_servant (servant); + priv = importer->priv; if (priv->process_item_fn != NULL) (priv->process_item_fn) (importer, listener, priv->closure, ev); @@ -132,14 +108,12 @@ 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; + importer = evolution_importer_from_servant (servant); + priv = importer->priv; if (priv->get_error_fn != NULL) { out_str = (priv->get_error_fn) (importer, priv->closure); @@ -156,65 +130,47 @@ destroy (GtkObject *object) EvolutionImporterPrivate *priv; importer = EVOLUTION_IMPORTER (object); - priv = importer->private; + priv = importer->priv; if (priv == NULL) return; g_free (priv); - importer->private = NULL; + importer->priv = NULL; - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + 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->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; - - 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) +evolution_importer_class_init (EvolutionImporterClass *klass) { GtkObjectClass *object_class; + POA_GNOME_Evolution_Importer__epv *epv = &klass->epv; object_class = GTK_OBJECT_CLASS (klass); object_class->destroy = destroy; parent_class = gtk_type_class (PARENT_TYPE); - corba_class_init (); + 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; } static void -init (EvolutionImporter *importer) +evolution_importer_init (EvolutionImporter *importer) { EvolutionImporterPrivate *priv; priv = g_new0 (EvolutionImporterPrivate, 1); - importer->private = priv; + importer->priv = priv; } static void evolution_importer_construct (EvolutionImporter *importer, - GNOME_Evolution_Importer corba_object, EvolutionImporterSupportFormatFn support_format_fn, EvolutionImporterLoadFileFn load_file_fn, EvolutionImporterProcessItemFn process_item_fn, @@ -225,14 +181,11 @@ 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); - bonobo_object_construct (BONOBO_OBJECT (importer), corba_object); - - priv = importer->private; + priv = importer->priv; priv->support_format_fn = support_format_fn; priv->load_file_fn = load_file_fn; priv->process_item_fn = process_item_fn; @@ -262,21 +215,14 @@ evolution_importer_new (EvolutionImporterSupportFormatFn support_format_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, - support_format_fn, load_file_fn, + evolution_importer_construct (importer, support_format_fn, load_file_fn, process_item_fn, get_error_fn, closure); return importer; } -E_MAKE_TYPE (evolution_importer, "EvolutionImporter", EvolutionImporter, - class_init, init, PARENT_TYPE); +BONOBO_X_TYPE_FUNC_FULL (EvolutionImporter, + GNOME_Evolution_Importer, + PARENT_TYPE, + evolution_importer); diff --git a/shell/importer/evolution-importer.h b/shell/importer/evolution-importer.h index fa5c944c2c..a5f6e07e87 100644 --- a/shell/importer/evolution-importer.h +++ b/shell/importer/evolution-importer.h @@ -24,7 +24,8 @@ #ifndef EVOLUTION_IMPORTER_H #define EVOLUTION_IMPORTER_H -#include <bonobo/bonobo-object.h> +#include <bonobo/bonobo-xobject.h> +#include <importer/GNOME_Evolution_Importer.h> #ifdef __cplusplus extern "C" { @@ -67,13 +68,15 @@ typedef enum { } EvolutionImporterResult; struct _EvolutionImporter { - BonoboObject parent; - - EvolutionImporterPrivate *private; + BonoboXObject parent; + + EvolutionImporterPrivate *priv; }; struct _EvolutionImporterClass { - BonoboObjectClass parent_class; + BonoboXObjectClass parent_class; + + POA_GNOME_Evolution_Importer__epv epv; }; GtkType evolution_importer_get_type (void); diff --git a/shell/importer/evolution-intelligent-importer.c b/shell/importer/evolution-intelligent-importer.c new file mode 100644 index 0000000000..0149d48f97 --- /dev/null +++ b/shell/importer/evolution-intelligent-importer.c @@ -0,0 +1,198 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-intelligent-importer.c + * + * Copyright (C) 2000, 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: Iain Holmes <iain@ximian.com> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <bonobo/bonobo-object.h> + +#include "GNOME_Evolution_Importer.h" +#include "evolution-intelligent-importer.h" + + +#define PARENT_TYPE BONOBO_X_OBJECT_TYPE +static BonoboObjectClass *parent_class = NULL; + +struct _EvolutionIntelligentImporterPrivate { + EvolutionIntelligentImporterCanImportFn can_import_fn; + EvolutionIntelligentImporterImportDataFn import_data_fn; + + char *importername; + char *message; + void *closure; +}; + + +static inline EvolutionIntelligentImporter * +evolution_intelligent_importer_from_servant (PortableServer_Servant servant) +{ + return EVOLUTION_INTELLIGENT_IMPORTER (bonobo_object_from_servant (servant)); +} + +static CORBA_char * +impl_GNOME_Evolution_IntelligentImporter__get_importername (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + EvolutionIntelligentImporter *ii; + + ii = evolution_intelligent_importer_from_servant (servant); + + return CORBA_string_dup (ii->priv->importername ? + ii->priv->importername : ""); +} + +static CORBA_char * +impl_GNOME_Evolution_IntelligentImporter__get_message (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + EvolutionIntelligentImporter *ii; + + ii = evolution_intelligent_importer_from_servant (servant); + + return CORBA_string_dup (ii->priv->message ? + ii->priv->message : ""); +} + +static CORBA_boolean +impl_GNOME_Evolution_IntelligentImporter_canImport (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + EvolutionIntelligentImporter *ii; + EvolutionIntelligentImporterPrivate *priv; + + ii = evolution_intelligent_importer_from_servant (servant); + priv = ii->priv; + + if (priv->can_import_fn != NULL) + return (priv->can_import_fn) (ii, priv->closure); + else + return FALSE; +} + +static void +impl_GNOME_Evolution_IntelligentImporter_importData (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + EvolutionIntelligentImporter *ii; + EvolutionIntelligentImporterPrivate *priv; + + ii = evolution_intelligent_importer_from_servant (servant); + priv = ii->priv; + + if (priv->import_data_fn) + (priv->import_data_fn) (ii, priv->closure); +} + + +static void +destroy (GtkObject *object) +{ + EvolutionIntelligentImporter *ii; + + ii = EVOLUTION_INTELLIGENT_IMPORTER (object); + + if (ii->priv == NULL) + return; + + g_free (ii->priv->importername); + g_free (ii->priv); + ii->priv = NULL; + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +static void +evolution_intelligent_importer_class_init (EvolutionIntelligentImporterClass *klass) +{ + GtkObjectClass *object_class; + POA_GNOME_Evolution_IntelligentImporter__epv *epv = &klass->epv; + + object_class = GTK_OBJECT_CLASS (klass); + object_class->destroy = destroy; + + parent_class = gtk_type_class (PARENT_TYPE); + epv->_get_importername = impl_GNOME_Evolution_IntelligentImporter__get_importername; + epv->_get_message = impl_GNOME_Evolution_IntelligentImporter__get_message; + epv->canImport = impl_GNOME_Evolution_IntelligentImporter_canImport; + epv->importData = impl_GNOME_Evolution_IntelligentImporter_importData; +} + +static void +evolution_intelligent_importer_init (EvolutionIntelligentImporter *ii) +{ + ii->priv = g_new0 (EvolutionIntelligentImporterPrivate, 1); +} + + +static void +evolution_intelligent_importer_construct (EvolutionIntelligentImporter *ii, + EvolutionIntelligentImporterCanImportFn can_import_fn, + EvolutionIntelligentImporterImportDataFn import_data_fn, + const char *importername, + const char *message, + void *closure) +{ + g_return_if_fail (ii != NULL); + ii->priv->importername = g_strdup (importername); + ii->priv->message = g_strdup (message); + + ii->priv->can_import_fn = can_import_fn; + ii->priv->import_data_fn = import_data_fn; + ii->priv->closure = closure; +} + +/** + * evolution_intelligent_importer_new: + * can_import_fn: The function that will be called to see if this importer can do + * anything. + * import_data_fn: The function that will be called when the importer should + * import the data. + * importername: The name of this importer. + * message: The message that will be displayed when the importer can import. + * closure: The data to be passed to @can_import_fn and @import_data_fn. + * + * Creates a new IntelligentImporter. + * + * Returns: A newly allocated EvolutionIntelligentImporter. + */ +EvolutionIntelligentImporter * +evolution_intelligent_importer_new (EvolutionIntelligentImporterCanImportFn can_import_fn, + EvolutionIntelligentImporterImportDataFn import_data_fn, + const char *importername, + const char *message, + void *closure) +{ + EvolutionIntelligentImporter *ii; + + ii = gtk_type_new (evolution_intelligent_importer_get_type ()); + evolution_intelligent_importer_construct (ii, can_import_fn, + import_data_fn, importername, + message, closure); + return ii; +} + +BONOBO_X_TYPE_FUNC_FULL (EvolutionIntelligentImporter, + GNOME_Evolution_IntelligentImporter, + PARENT_TYPE, + evolution_intelligent_importer); diff --git a/shell/importer/evolution-intelligent-importer.h b/shell/importer/evolution-intelligent-importer.h new file mode 100644 index 0000000000..1714a2a046 --- /dev/null +++ b/shell/importer/evolution-intelligent-importer.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-intelligent-importer.h + * + * Copyright (C) 2000 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: Iain Holmes <iain@ximian.com> + */ + +#ifndef EVOLUTION_INTELLIGENT_IMPORTER_H +#define EVOLUTION_INTELLIGENT_IMPORTER_H + +#include <bonobo/bonobo-xobject.h> +#include <importer/GNOME_Evolution_Importer.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define EVOLUTION_TYPE_INTELLIGENT_IMPORTER (evolution_intelligent_importer_get_type ()) +#define EVOLUTION_INTELLIGENT_IMPORTER(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER, EvolutionIntelligentImporter)) +#define EVOLUTION_INTELLIGENT_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_INTELLIGENT_IMPORTER, EvolutionIntelligentImporterClass)) +#define EVOLUTION_IS_INTELLIGENT_IMPORTER(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER)) +#define EVOLUTION_IS_INTELLIGENT_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER)) + +typedef struct _EvolutionIntelligentImporter EvolutionIntelligentImporter; +typedef struct _EvolutionIntelligentImporterPrivate EvolutionIntelligentImporterPrivate; +typedef struct _EvolutionIntelligentImporterClass EvolutionIntelligentImporterClass; + +typedef gboolean (* EvolutionIntelligentImporterCanImportFn) (EvolutionIntelligentImporter *ii, + void *closure); +typedef void (* EvolutionIntelligentImporterImportDataFn) (EvolutionIntelligentImporter *ii, + void *closure); + +struct _EvolutionIntelligentImporter { + BonoboXObject parent; + + EvolutionIntelligentImporterPrivate *priv; +}; + +struct _EvolutionIntelligentImporterClass { + BonoboXObjectClass parent_class; + + POA_GNOME_Evolution_IntelligentImporter__epv epv; +}; + +GtkType evolution_intelligent_importer_get_type (void); + +EvolutionIntelligentImporter *evolution_intelligent_importer_new (EvolutionIntelligentImporterCanImportFn can_import_fn, + EvolutionIntelligentImporterImportDataFn import_data_fn, + const char *importername, + const char *message, + void *closure); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/shell/importer/intelligent.c b/shell/importer/intelligent.c new file mode 100644 index 0000000000..e3f0f4b03b --- /dev/null +++ b/shell/importer/intelligent.c @@ -0,0 +1,174 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* intelligent.c + * + * Authors: + * Iain Holmes <iain@ximian.com> + * + * Copyright 2001 Ximian, Inc. (http://www.ximian.com) + * + * 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 + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gnome.h> + +#include <liboaf/liboaf.h> + +#include "intelligent.h" +#include "GNOME_Evolution_Importer.h" + +static void +start_importer (const char *iid) +{ + CORBA_Object importer; + CORBA_Environment ev; + CORBA_char *name; + CORBA_char *message; + CORBA_boolean can_run; + + GtkWidget *dialog, *label; + char *str; + + if (iid == NULL || *iid == '\0') + return; + + CORBA_exception_init (&ev); + importer = oaf_activate_from_id ((char *) iid, 0, NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); + g_warning ("Could not start %s", iid); + return; + } + + CORBA_exception_free (&ev); + if (importer == CORBA_OBJECT_NIL) { + g_warning ("Could not activate_component %s", iid); + return; + } + + CORBA_exception_init (&ev); + can_run = GNOME_Evolution_IntelligentImporter_canImport (importer, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Could not get canImport(%s): %s", iid, CORBA_exception_id (&ev)); + CORBA_Object_release (importer, &ev); + CORBA_exception_free (&ev); + return; + } + CORBA_exception_free (&ev); + + if (can_run == FALSE) { + return; + } + + name = GNOME_Evolution_IntelligentImporter__get_importername (importer, + &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Could not get name(%s): %s", iid, CORBA_exception_id (&ev)); + CORBA_Object_release (importer, &ev); + CORBA_exception_free (&ev); + return; + } + message = GNOME_Evolution_IntelligentImporter__get_message (importer, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Could not get message(%s): %s", iid, CORBA_exception_id (&ev)); + CORBA_Object_release (importer, &ev); + CORBA_exception_free (&ev); + return; + } + + CORBA_exception_free (&ev); + + dialog = gnome_dialog_new ("Import files", + GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, + NULL); + gtk_window_set_title (GTK_WINDOW (dialog), name); + CORBA_free (name); + + label = gtk_label_new (message); + CORBA_free (message); + + gtk_box_pack_start (GNOME_DIALOG (dialog)->vbox, label, FALSE, FALSE, 0); + gtk_widget_show (label); + switch (gnome_dialog_run_and_close (GNOME_DIALOG (dialog))) { + case 0: + /* Yes */ +#if 0 + /* This sucks */ + dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL); + label = gtk_label_new ("Importing"); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_container_add (GTK_CONTAINER (dialog), label); + gtk_widget_show_all (dialog); +#endif + + GNOME_Evolution_IntelligentImporter_importData (importer, &ev); + break; + case 1: + case -1: + default: + /* No */ + break; + } + + CORBA_exception_init (&ev); + CORBA_Object_release (importer, &ev); + CORBA_exception_free (&ev); +} + + +static GList * +get_intelligent_importers (void) +{ + OAF_ServerInfoList *info_list; + GList *iids_ret = NULL; + CORBA_Environment ev; + int i; + + CORBA_exception_init (&ev); + info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/IntelligentImporter:1.0')", NULL, &ev); + CORBA_exception_free (&ev); + + for (i = 0; i < info_list->_length; i++) { + const OAF_ServerInfo *info; + + info = info_list->_buffer + i; + iids_ret = g_list_prepend (iids_ret, g_strdup (info->iid)); + } + + return iids_ret; +} + +void +intelligent_importer_init (void) +{ + GList *importers, *l; + + importers = get_intelligent_importers (); + if (importers == NULL) + return; /* No intelligent importers. Easy :) */ + + /* Loop through each importer, running it. */ + for (l = importers; l; l = l->next) { + start_importer (l->data); + g_free (l->data); + } + + g_list_free (importers); +} + diff --git a/shell/importer/intelligent.h b/shell/importer/intelligent.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/shell/importer/intelligent.h |