diff options
-rw-r--r-- | shell/ChangeLog | 15 | ||||
-rw-r--r-- | shell/e-local-storage.c | 383 |
2 files changed, 206 insertions, 192 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index ccee247b77..b30128eaeb 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,18 @@ +2001-03-23 Ettore Perazzoli <ettore@ximian.com> + + * e-local-storage.c (impl_async_xfer_folder): New, implementation + for `EStorage::async_xfer_folder'. + (class_init): Install it. + (check_valid_name): Removed. Conflicts shouldn't be handled this + way, and hardcoding the names is *bad*. + (create_folder_directory): New helper function. + (real_do_folder_create): Removed. + (create_folder): New. Do things here using + `create_folder_directory'. + (impl_async_create_folder): Use `create_folder'. + (notify_bonobo_listener): Renamed from `notify_listener'. Moved + on top for clarity. + 2001-03-22 Iain Holmes <iain@ximian.com> * importer/evolution-importer-listener.c (evolution_importer_listener_new): diff --git a/shell/e-local-storage.c b/shell/e-local-storage.c index 3417776731..bbdc5eaef1 100644 --- a/shell/e-local-storage.c +++ b/shell/e-local-storage.c @@ -70,6 +70,65 @@ struct _ELocalStoragePrivate { }; +/* EStorageResult <-> errno mapping. */ + +static EStorageResult +errno_to_storage_result (void) +{ + EStorageResult storage_result; + + switch (errno) { + case EACCES: + case EROFS: + storage_result = E_STORAGE_PERMISSIONDENIED; + break; + case EEXIST: + storage_result = E_STORAGE_EXISTS; + break; + case ENOSPC: + storage_result = E_STORAGE_NOSPACE; + break; + default: + storage_result = E_STORAGE_GENERICERROR; + } + + return storage_result; +} + +static EStorageResult +shell_component_result_to_storage_result (EvolutionShellComponentResult result) +{ + /* FIXME: Maybe we need better mapping here. */ + switch (result) { + case EVOLUTION_SHELL_COMPONENT_OK: + return E_STORAGE_OK; + case EVOLUTION_SHELL_COMPONENT_NOTFOUND: + return E_STORAGE_NOTFOUND; + case EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDTYPE: + return E_STORAGE_UNSUPPORTEDTYPE; + case EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDOPERATION: + return E_STORAGE_UNSUPPORTEDOPERATION; + case EVOLUTION_SHELL_COMPONENT_EXISTS: + return E_STORAGE_EXISTS; + case EVOLUTION_SHELL_COMPONENT_PERMISSIONDENIED: + return E_STORAGE_PERMISSIONDENIED; + case EVOLUTION_SHELL_COMPONENT_ALREADYOWNED: + case EVOLUTION_SHELL_COMPONENT_BUSY: + case EVOLUTION_SHELL_COMPONENT_CORBAERROR: + case EVOLUTION_SHELL_COMPONENT_HASSUBFOLDERS: + case EVOLUTION_SHELL_COMPONENT_INTERNALERROR: + case EVOLUTION_SHELL_COMPONENT_INTERRUPTED: + case EVOLUTION_SHELL_COMPONENT_INVALIDARG: + case EVOLUTION_SHELL_COMPONENT_INVALIDURI: + case EVOLUTION_SHELL_COMPONENT_NOSPACE: + case EVOLUTION_SHELL_COMPONENT_NOTOWNED: + case EVOLUTION_SHELL_COMPONENT_UNKNOWNERROR: + default: + return E_STORAGE_GENERICERROR; + } +} + + /* Utility functions. */ /* Translate a storage path into a physical path on the file system. */ @@ -261,60 +320,24 @@ load_all_folders (ELocalStorage *local_storage) return load_folders (local_storage, NULL, G_DIR_SEPARATOR_S, base_path); } -static EStorageResult -errno_to_storage_result (void) +static void +notify_bonobo_listener (const Bonobo_Listener listener, + EStorageResult result, + const char *physical_path) { - EStorageResult storage_result; - - switch (errno) { - case EACCES: - case EROFS: - storage_result = E_STORAGE_PERMISSIONDENIED; - break; - case EEXIST: - storage_result = E_STORAGE_EXISTS; - break; - case ENOSPC: - storage_result = E_STORAGE_NOSPACE; - break; - default: - storage_result = E_STORAGE_GENERICERROR; - } + CORBA_any any; + GNOME_Evolution_Storage_FolderResult folder_result; + CORBA_Environment ev; - return storage_result; -} + 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; -static EStorageResult -shell_component_result_to_storage_result (EvolutionShellComponentResult result) -{ - /* FIXME: Maybe we need better mapping here. */ - switch (result) { - case EVOLUTION_SHELL_COMPONENT_OK: - return E_STORAGE_OK; - case EVOLUTION_SHELL_COMPONENT_NOTFOUND: - return E_STORAGE_NOTFOUND; - case EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDTYPE: - return E_STORAGE_UNSUPPORTEDTYPE; - case EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDOPERATION: - return E_STORAGE_UNSUPPORTEDOPERATION; - case EVOLUTION_SHELL_COMPONENT_EXISTS: - return E_STORAGE_EXISTS; - case EVOLUTION_SHELL_COMPONENT_PERMISSIONDENIED: - return E_STORAGE_PERMISSIONDENIED; - case EVOLUTION_SHELL_COMPONENT_ALREADYOWNED: - case EVOLUTION_SHELL_COMPONENT_BUSY: - case EVOLUTION_SHELL_COMPONENT_CORBAERROR: - case EVOLUTION_SHELL_COMPONENT_HASSUBFOLDERS: - case EVOLUTION_SHELL_COMPONENT_INTERNALERROR: - case EVOLUTION_SHELL_COMPONENT_INTERRUPTED: - case EVOLUTION_SHELL_COMPONENT_INVALIDARG: - case EVOLUTION_SHELL_COMPONENT_INVALIDURI: - case EVOLUTION_SHELL_COMPONENT_NOSPACE: - case EVOLUTION_SHELL_COMPONENT_NOTOWNED: - case EVOLUTION_SHELL_COMPONENT_UNKNOWNERROR: - default: - return E_STORAGE_GENERICERROR; - } + CORBA_exception_init (&ev); + Bonobo_Listener_event (listener, "evolution-shell:folder_created", + &any, &ev); + CORBA_exception_free (&ev); } @@ -337,27 +360,6 @@ 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) @@ -382,7 +384,8 @@ component_async_create_folder_callback (EvolutionShellComponentClient *shell_com e_folder_set_physical_uri (folder, callback_data->physical_uri); if (e_local_folder_save (E_LOCAL_FOLDER (folder))) { - new_folder (E_LOCAL_STORAGE(callback_data->storage), callback_data->path, folder); + new_folder (E_LOCAL_STORAGE(callback_data->storage), + callback_data->path, folder); } else { rmdir (callback_data->physical_path); gtk_object_unref (GTK_OBJECT (folder)); @@ -393,8 +396,8 @@ component_async_create_folder_callback (EvolutionShellComponentClient *shell_com 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); + notify_bonobo_listener (callback_data->listener, storage_result, + callback_data->physical_path); if (callback_data->callback != NULL) (* callback_data->callback) (callback_data->storage, @@ -411,107 +414,28 @@ component_async_create_folder_callback (EvolutionShellComponentClient *shell_com } -/* GtkObject methods. */ - -static void -impl_destroy (GtkObject *object) -{ - ELocalStorage *local_storage; - ELocalStoragePrivate *priv; - CORBA_Environment ev; - - local_storage = E_LOCAL_STORAGE (object); - priv = local_storage->priv; - - CORBA_exception_init (&ev); - - g_free (priv->base_path); - - if (priv->folder_type_registry != NULL) - gtk_object_unref (GTK_OBJECT (priv->folder_type_registry)); - - if (priv->bonobo_interface != NULL) - bonobo_object_unref (BONOBO_OBJECT (priv->bonobo_interface)); - - g_free (priv); - - CORBA_exception_free (&ev); - - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -/* EStorage methods. */ +/* Implementation for the folder operations. */ -static const char * -impl_get_name (EStorage *storage) -{ - return E_LOCAL_STORAGE_NAME; -} - -const char *invalid_names[6] = { - "Calendar", - "Contacts", - "Trash", - "Executive-Summary", - "Tasks", - NULL}; -/* Checks that @foldername isn't an invalid name like Trash, Calendar etc */ -static gboolean -check_valid_name (const char *foldername) -{ - int i; - - g_return_val_if_fail (foldername != NULL, FALSE); - for (i = 0; invalid_names[i] != NULL; i++) { - if (strcmp (invalid_names[i], foldername) == 0) - return FALSE; - } - - return TRUE; -} - -static void -real_do_folder_create (ELocalStorage *local_storage, - Bonobo_Listener listener, - const char *path, - const char *type, - const char *description, - EStorageResultCallback callback, - void *data) +static EStorageResult +create_folder_directory (ELocalStorage *local_storage, + const char *path, + const char *type, + const char *description, + char **physical_path_return) { EStorage *storage; ELocalStoragePrivate *priv; - EvolutionShellComponentClient *component_client; - AsyncCreateFolderCallbackData *callback_data; const char *folder_name; char *physical_path; - char *physical_uri; char *parent_path; storage = E_STORAGE (local_storage); priv = local_storage->priv; - component_client = e_folder_type_registry_get_handler_for_type (priv->folder_type_registry, - type); - if (component_client == NULL) { - if (callback != NULL) - (* callback) (storage, E_STORAGE_INVALIDTYPE, data); - notify_listener (listener, E_STORAGE_INVALIDTYPE, NULL); - return; - } - + *physical_path_return = NULL; g_assert (g_path_is_absolute (path)); folder_name = g_basename (path); - /* Some validity checks */ - if (!check_valid_name (folder_name)) { - if (callback != NULL) - (*callback) (storage, E_STORAGE_INVALIDNAME, data); - - notify_listener (listener, E_STORAGE_INVALIDNAME, NULL); - return; - } if (folder_name == path + 1) { /* We want a direct child of the root, so we don't need to create a @@ -528,23 +452,6 @@ real_do_folder_create (ELocalStorage *local_storage, parent_physical_path = get_physical_path (local_storage, parent_path); subfolders_directory_physical_path = g_concat_dir_and_file (parent_physical_path, SUBFOLDER_DIR_NAME); - if (! g_file_exists (subfolders_directory_physical_path) - && mkdir (subfolders_directory_physical_path, 0700) == -1) { - if (errno != EEXIST) { - /* Really bad error which we can't recover from */ - g_free (parent_path); - g_free (subfolders_directory_physical_path); - g_free (parent_physical_path); - if (callback != NULL) - (* callback) (storage, - errno_to_storage_result (), - data); - - notify_listener (listener, - errno_to_storage_result (), NULL); - return; - } - } physical_path = g_concat_dir_and_file (subfolders_directory_physical_path, folder_name); @@ -555,17 +462,59 @@ real_do_folder_create (ELocalStorage *local_storage, /* Create the directory that holds the folder. */ if (mkdir (physical_path, 0700) == -1) { - notify_listener (listener, errno_to_storage_result (), - physical_path); g_free (physical_path); + return errno_to_storage_result (); + } + + *physical_path_return = physical_path; + return E_STORAGE_OK; +} + +static void +create_folder (ELocalStorage *local_storage, + Bonobo_Listener listener, + const char *path, + const char *type, + const char *description, + EStorageResultCallback callback, + void *data) +{ + EStorage *storage; + ELocalStoragePrivate *priv; + EvolutionShellComponentClient *component_client; + AsyncCreateFolderCallbackData *callback_data; + EStorageResult result; + const char *folder_name; + char *physical_path; + char *physical_uri; + + storage = E_STORAGE (local_storage); + priv = local_storage->priv; + component_client = e_folder_type_registry_get_handler_for_type (priv->folder_type_registry, + type); + if (component_client == NULL) { + if (callback != NULL) + (* callback) (storage, E_STORAGE_INVALIDTYPE, data); + if (listener != CORBA_OBJECT_NIL) + notify_bonobo_listener (listener, E_STORAGE_INVALIDTYPE, NULL); + return; + } + + g_assert (g_path_is_absolute (path)); + + result = create_folder_directory (local_storage, path, type, description, &physical_path); + if (result != E_STORAGE_OK) { if (callback != NULL) - (* callback) (storage, - errno_to_storage_result (), data); + (* callback) (storage, result, data); + if (listener != CORBA_OBJECT_NIL) + notify_bonobo_listener (listener, result, NULL); return; } + + folder_name = g_basename (path); + + /* Finally tell the component to do the job of creating the physical files in it. */ - /* Finally tell the component to do the job of creating the physical files in - it. */ /* FIXME: We should put the operations on a queue so that we can cancel them when the ELocalStorage is destroyed. */ @@ -586,12 +535,51 @@ real_do_folder_create (ELocalStorage *local_storage, bonobo_object_ref (BONOBO_OBJECT (component_client)); evolution_shell_component_client_async_create_folder (component_client, - physical_path, + physical_uri, type, component_async_create_folder_callback, callback_data); } + +/* GtkObject methods. */ + +static void +impl_destroy (GtkObject *object) +{ + ELocalStorage *local_storage; + ELocalStoragePrivate *priv; + CORBA_Environment ev; + + local_storage = E_LOCAL_STORAGE (object); + priv = local_storage->priv; + + CORBA_exception_init (&ev); + + g_free (priv->base_path); + + if (priv->folder_type_registry != NULL) + gtk_object_unref (GTK_OBJECT (priv->folder_type_registry)); + + if (priv->bonobo_interface != NULL) + bonobo_object_unref (BONOBO_OBJECT (priv->bonobo_interface)); + + g_free (priv); + + CORBA_exception_free (&ev); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + +/* EStorage methods. */ + +static const char * +impl_get_name (EStorage *storage) +{ + return E_LOCAL_STORAGE_NAME; +} + static void impl_async_create_folder (EStorage *storage, const char *path, @@ -603,8 +591,8 @@ impl_async_create_folder (EStorage *storage, ELocalStorage *local_storage; local_storage = E_LOCAL_STORAGE (storage); - real_do_folder_create (local_storage, NULL, path, type, - description, callback, data); + + create_folder (local_storage, NULL, path, type, description, callback, data); } static void @@ -618,22 +606,32 @@ impl_async_remove_folder (EStorage *storage, local_storage = E_LOCAL_STORAGE (storage); } +static void +impl_async_xfer_folder (EStorage *storage, + const char *source_path, + const char *destination_path, + const gboolean remove_source, + EStorageResultCallback callback, + void *data) +{ +} + /* Callbacks for the `Evolution::LocalStorage' interface we are exposing to the outside world. */ static void -bonobo_interface_create_folder_cb (EvolutionStorage *estorage, +bonobo_interface_create_folder_cb (EvolutionStorage *storage, const Bonobo_Listener listener, const char *path, const char *type, const char *description, - const char *parent_p_path, + const char *parent_path, void *data) { ELocalStorage *local_storage; local_storage = E_LOCAL_STORAGE (data); - real_do_folder_create (local_storage, listener, path, type, - description, NULL, data); + + create_folder (local_storage, listener, path, type, description, NULL, NULL); } static void @@ -674,6 +672,7 @@ class_init (ELocalStorageClass *class) storage_class->get_name = impl_get_name; storage_class->async_create_folder = impl_async_create_folder; storage_class->async_remove_folder = impl_async_remove_folder; + storage_class->async_xfer_folder = impl_async_xfer_folder; } static void |