aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2000-06-30 13:36:32 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2000-06-30 13:36:32 +0800
commit55499e0ce4bb8a081d12e7243a0dd42aa55bbbfd (patch)
tree6efa90b13a9dc59a015ed62ac22bb8f2d01881fb
parentf5fa17c2d0a2069e25d0b49aaf5fd4e8ea8dc4da (diff)
downloadgsoc2013-evolution-55499e0ce4bb8a081d12e7243a0dd42aa55bbbfd.tar.gz
gsoc2013-evolution-55499e0ce4bb8a081d12e7243a0dd42aa55bbbfd.tar.zst
gsoc2013-evolution-55499e0ce4bb8a081d12e7243a0dd42aa55bbbfd.zip
EvolutionShellClient.
svn path=/trunk/; revision=3820
-rw-r--r--ChangeLog6
-rw-r--r--addressbook/ChangeLog6
-rw-r--r--addressbook/gui/component/addressbook-component.c2
-rw-r--r--calendar/ChangeLog6
-rw-r--r--calendar/gui/calendar-component.c3
-rw-r--r--calendar/gui/component-factory.c3
-rw-r--r--configure.in1
-rw-r--r--filter/ChangeLog10
-rw-r--r--filter/filter-arg-types.c111
-rw-r--r--mail/ChangeLog5
-rw-r--r--mail/component-factory.c14
-rw-r--r--notes/component-factory.c2
-rw-r--r--shell/ChangeLog13
-rw-r--r--shell/Makefile.am4
-rw-r--r--shell/e-storage-set.c5
-rw-r--r--shell/evolution-shell-client.c296
-rw-r--r--shell/evolution-shell-client.h71
-rw-r--r--shell/evolution-shell-component.c30
-rw-r--r--shell/evolution-shell-component.h6
19 files changed, 475 insertions, 119 deletions
diff --git a/ChangeLog b/ChangeLog
index d4019a5f86..7520c8b6bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * notes/component-factory.c (owner_set_cb): Get an
+ EvolutionShellClient instead of an Evolution_Shell to match the
+ changes in libeshell.
+
2000-06-29 Peter Williams <peterw@helixcode.com>
* configure.in: Re-enable GNOME_PILOT_CHECK.
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 840e491fdb..962ca4b8ef 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,9 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * gui/component/addressbook-component.c (owner_set_cb): Get an
+ EvolutionShellClient instead of an Evolution_Shell to match the
+ changes in libeshell.
+
2000-06-28 Christopher James Lahey <clahey@helixcode.com>
* gui/component/select-names/,
diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c
index 793e168c18..8469967e7c 100644
--- a/addressbook/gui/component/addressbook-component.c
+++ b/addressbook/gui/component/addressbook-component.c
@@ -74,7 +74,7 @@ static int owner_count = 0;
static void
owner_set_cb (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface,
+ EvolutionShellClient *shell_client,
gpointer user_data)
{
owner_count ++;
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 46fd6690e8..06518ca29f 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,9 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * gui/component-factory.c (owner_set_cb): Get an
+ EvolutionShellClient instead of an Evolution_Shell to match the
+ changes in libeshell.
+
2000-06-29 Federico Mena Quintero <federico@helixcode.com>
* gui/Makefile.am: Do not link and include the pilot stuff for the
diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c
index 1b178cfdfc..5ca51772b9 100644
--- a/calendar/gui/calendar-component.c
+++ b/calendar/gui/calendar-component.c
@@ -69,7 +69,8 @@ create_view (EvolutionShellComponent *shell_component,
static void
owner_set_cb (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface)
+ EvolutionShellClient shell_client,
+ void *data)
{
g_print ("evolution-calendar: Yeeeh! We have an owner!\n"); /* FIXME */
}
diff --git a/calendar/gui/component-factory.c b/calendar/gui/component-factory.c
index 1b178cfdfc..5ca51772b9 100644
--- a/calendar/gui/component-factory.c
+++ b/calendar/gui/component-factory.c
@@ -69,7 +69,8 @@ create_view (EvolutionShellComponent *shell_component,
static void
owner_set_cb (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface)
+ EvolutionShellClient shell_client,
+ void *data)
{
g_print ("evolution-calendar: Yeeeh! We have an owner!\n"); /* FIXME */
}
diff --git a/configure.in b/configure.in
index f6f713c367..370beb3551 100644
--- a/configure.in
+++ b/configure.in
@@ -469,6 +469,7 @@ widgets/Makefile
widgets/e-paned/Makefile
widgets/e-table/Makefile
widgets/e-text/Makefile
+widgets/e-toolbar/Makefile
widgets/meeting-time-sel/Makefile
widgets/misc/Makefile
widgets/shortcut-bar/Makefile
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 170b4b0ee0..6bcf2bd0a4 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,3 +1,13 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * filter-arg-types.c: Replaced `global_shell_interface' with
+ `global_shell_client'.
+ (arg_folder_edit_value): Use
+ `evolution_shell_client_user_select_folder()'.
+ (create_listener): Removed.
+ (impl_FolderSelectionListener_selected): Removed, together with
+ all the ::Listener stuff.
+
2000-06-29 Arik Devens <arik@helixcode.com>
* vfoldertypes.xml (ruleset type="match"): Changed Cc to CC to be
diff --git a/filter/filter-arg-types.c b/filter/filter-arg-types.c
index 8599665b82..afecb0bcde 100644
--- a/filter/filter-arg-types.c
+++ b/filter/filter-arg-types.c
@@ -22,6 +22,8 @@
#include <gnome.h>
+#include "evolution-shell-client.h"
+
#include "filter-arg-types.h"
/* ********************************************************************** */
@@ -501,91 +503,7 @@ static void filter_arg_folder_class_init (FilterArgFolderClass *class);
static void filter_arg_folder_init (FilterArgFolder *gspaper);
static FilterArg *folder_parent_class;
-extern Evolution_Shell global_shell_interface;
-
-static PortableServer_ServantBase__epv FolderSelectionListener_base_epv;
-static POA_Evolution_FolderSelectionListener__epv FolderSelectionListener_epv;
-static POA_Evolution_FolderSelectionListener__vepv FolderSelectionListener_vepv;
-static gboolean FolderSelectionListener_vepv_initialized = FALSE;
-
-struct _FolderSelectionListenerServant {
- POA_Evolution_FolderSelectionListener servant;
- FilterArg *arg;
- int index;
- /*EvolutionShellComponentClient *component_client;*/
-};
-typedef struct _FolderSelectionListenerServant FolderSelectionListenerServant;
-
-static void
-impl_FolderSelectionListener_selected(PortableServer_Servant listener_servant, char *uri, char *physical, CORBA_Environment *ev)
-{
- FolderSelectionListenerServant *servant = listener_servant;
- GList *node;
-
- /* only if we have a selection */
- if (physical[0]) {
- printf ("user selected; %s, or did they select %s\n", uri, physical);
-
- /* FIXME: passing arg 2 of `g_list_index' makes pointer from integer without a cast */
- if (servant->index >= 0 && (node = g_list_index (servant->arg->values, servant->index))) {
- node->data = g_strdup (physical);
- } else {
- servant->arg->values = g_list_append (servant->arg->values, g_strdup (physical));
- }
-
- gtk_signal_emit_by_name (GTK_OBJECT (servant->arg), "changed");
- }
- gtk_object_unref (GTK_OBJECT (servant->arg));
-
- g_free (servant);
-}
-
-static Evolution_FolderSelectionListener
-create_listener (FilterArg *arg, int index)
-{
- PortableServer_Servant listener_servant;
- Evolution_FolderSelectionListener corba_interface;
- CORBA_Environment ev;
- FolderSelectionListenerServant *servant;
-
- if (!FolderSelectionListener_vepv_initialized) {
- FolderSelectionListener_base_epv._private = NULL;
- FolderSelectionListener_base_epv.finalize = NULL;
- FolderSelectionListener_base_epv.default_POA = NULL;
-
- FolderSelectionListener_epv.selected = impl_FolderSelectionListener_selected;
-
- FolderSelectionListener_vepv._base_epv = & FolderSelectionListener_base_epv;
- FolderSelectionListener_vepv.Evolution_FolderSelectionListener_epv = & FolderSelectionListener_epv;
-
- FolderSelectionListener_vepv_initialized = TRUE;
- }
- servant = g_malloc0 (sizeof (*servant));
- servant->servant.vepv = &FolderSelectionListener_vepv;
- servant->arg = arg;
- gtk_object_ref (GTK_OBJECT (arg));
- servant->index = index;
-
- listener_servant = (PortableServer_Servant) servant;
-
- CORBA_exception_init (&ev);
-
- POA_Evolution_FolderSelectionListener__init (listener_servant, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_free(servant);
- return CORBA_OBJECT_NIL;
- }
-
- 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;
- }
-
- CORBA_exception_free (&ev);
- return corba_interface;
-}
+extern EvolutionShellClient *global_shell_client;
guint
filter_arg_folder_get_type (void)
@@ -639,19 +557,32 @@ static int
arg_folder_edit_value (FilterArg *arg, int index)
{
char *def;
- CORBA_Environment ev;
+ char *physical_uri;
printf ("folder edit value %d\n", index);
+
if (index < 0) {
def = "";
} else {
def = filter_arg_get_value (arg, index);
}
- CORBA_exception_init (&ev);
- Evolution_Shell_user_select_folder (global_shell_interface,
- create_listener (arg, index),
- "Select Folder", def, &ev);
+ evolution_shell_client_user_select_folder (global_shell_client,
+ _("Select Folder"),
+ def, NULL, &physical_uri);
+
+ if (physical_uri != NULL && physical_uri[0] != '\0') {
+ GList *node;
+
+ if (index >= 0 && (node = g_list_index (arg->values, index)))
+ node->data = physical_uri;
+ else
+ arg->values = g_list_append (arg->values, physical_uri);
+
+ gtk_signal_emit_by_name (GTK_OBJECT (arg), "changed");
+ } else {
+ g_free (physical_uri);
+ }
#warning "What do we really want to return here???"
return 0;
diff --git a/mail/ChangeLog b/mail/ChangeLog
index f6ba7c3ade..460421471c 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,8 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * component-factory.c: Replace `global_shell_interface' with
+ `global_shell_client'.
+
2000-06-29 Jeffrey Stedfast <fejj@helixcode.com>
* mail-ops.c (delete_msg): Clean up compile warnings
diff --git a/mail/component-factory.c b/mail/component-factory.c
index deb33b8a22..e29a174188 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -64,7 +64,7 @@ static const EvolutionShellComponentFolderType folder_types[] = {
static GList *browsers;
/* GROSS HACK: for passing to other parts of the program */
-Evolution_Shell global_shell_interface;
+EvolutionShellClient global_shell_client;
/* EvolutionShellComponent methods and signals. */
@@ -143,13 +143,14 @@ create_folder (EvolutionShellComponent *shell_component,
static void
owner_set_cb (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface,
+ EvolutionShellClient shell_client,
gpointer user_data)
{
g_print ("evolution-mail: Yeeeh! We have an owner!\n"); /* FIXME */
/* GROSS HACK */
- global_shell_interface = shell_interface;
+ global_shell_client = shell_client;
+
create_vfolder_storage (shell_component);
create_imap_storage (shell_component);
create_news_storage (shell_component);
@@ -211,14 +212,17 @@ component_factory_init (void)
static void
create_vfolder_storage (EvolutionShellComponent *shell_component)
{
+ EvolutionShellClient *shell_client;
Evolution_Shell corba_shell;
EvolutionStorage *storage;
- corba_shell = evolution_shell_component_get_owner (shell_component);
- if (corba_shell == CORBA_OBJECT_NIL) {
+ shell_client = evolution_shell_component_get_owner (shell_component);
+ if (shell_client == NULL) {
g_warning ("We have no shell!?");
return;
}
+
+ corba_shell = bonobo_object_corba_objref (BONOBO_OBJECT (shell_client));
storage = evolution_storage_new ("VFolders");
if (evolution_storage_register_on_shell (storage, corba_shell) != EVOLUTION_STORAGE_OK) {
diff --git a/notes/component-factory.c b/notes/component-factory.c
index 5e9cae24f5..f416156ba3 100644
--- a/notes/component-factory.c
+++ b/notes/component-factory.c
@@ -102,7 +102,7 @@ create_view (EvolutionShellComponent *shell_component,
static void
owner_set_cb (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface,
+ EvolutionShellClient shell_client,
gpointer user_data)
{
g_print ("evolution-notes: Yeeeh! We have an owner!\n"); /* FIXME */
diff --git a/shell/ChangeLog b/shell/ChangeLog
index da707efdeb..ac11499d52 100644
--- a/shell/ChangeLog
+++ b/shell/ChangeLog
@@ -1,3 +1,16 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * evolution-shell-component.c: New member `owner_client'. Removed
+ member `corba_owner'. All the code updated to use it.
+ (evolution_shell_component_get_owner): Changed so that it returns
+ an EvolutionShellClient instead of the raw CORBA object.
+
+ * evolution-shell-component.h: Change signal "owner_set" to get an
+ EvolutionShellClient wrapper instead of a CORBA interface.
+
+ * evolution-shell-client.c: New.
+ * evolution-shell-client.h: New.
+
2000-06-29 Dan Winship <danw@helixcode.com>
* evolution-shell-component-client.c
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 034403cc52..dbcc08cac6 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -44,6 +44,8 @@ noinst_LIBRARIES = \
libeshell_a_SOURCES = \
$(IDL_GENERATED) \
+ evolution-shell-client.c \
+ evolution-shell-client.h \
evolution-shell-component.c \
evolution-shell-component.h \
evolution-storage.c \
@@ -95,6 +97,8 @@ evolution_SOURCES = \
e-storage-set.h \
e-storage.c \
e-storage.h \
+ evolution-shell-client.c \
+ evolution-shell-client.h \
evolution-shell-component-client.c \
evolution-shell-component-client.h \
main.c
diff --git a/shell/e-storage-set.c b/shell/e-storage-set.c
index a779023bab..f24a3ac05c 100644
--- a/shell/e-storage-set.c
+++ b/shell/e-storage-set.c
@@ -214,8 +214,7 @@ class_init (EStorageSetClass *klass)
GtkObjectClass *object_class;
parent_class = gtk_type_class (gtk_object_get_type ());
-
- object_class = (GtkObjectClass*) klass;
+ object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = destroy;
@@ -260,6 +259,8 @@ init (EStorageSet *storage_set)
{
EStorageSetPrivate *priv;
+ g_return_if_fail (E_IS_STORAGE_SET (storage_set));
+
priv = g_new (EStorageSetPrivate, 1);
priv->storages = NULL;
priv->name_to_named_storage = g_hash_table_new (g_str_hash, g_str_equal);
diff --git a/shell/evolution-shell-client.c b/shell/evolution-shell-client.c
new file mode 100644
index 0000000000..d9cc63cec2
--- /dev/null
+++ b/shell/evolution-shell-client.c
@@ -0,0 +1,296 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* evolution-shell-client.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: Ettore Perazzoli
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo.h>
+
+#include "e-util/e-util.h"
+
+#include "evolution-shell-client.h"
+
+
+struct _EvolutionShellClientPrivate {
+ int dummy;
+};
+
+#define PARENT_TYPE bonobo_object_get_type ()
+static BonoboObjectClass *parent_class = NULL;
+
+
+/* Easy-to-use wrapper for Evolution::user_select_folder. */
+
+static PortableServer_ServantBase__epv FolderSelectionListener_base_epv;
+static POA_Evolution_FolderSelectionListener__epv FolderSelectionListener_epv;
+static POA_Evolution_FolderSelectionListener__vepv FolderSelectionListener_vepv;
+static gboolean FolderSelectionListener_vtables_initialized = FALSE;
+
+struct _FolderSelectionListenerServant {
+ POA_Evolution_FolderSelectionListener servant;
+ GMainLoop *main_loop;
+ char **uri_return;
+ char **physical_uri_return;
+};
+typedef struct _FolderSelectionListenerServant FolderSelectionListenerServant;
+
+static void
+impl_FolderSelectionListener_selected (PortableServer_Servant servant,
+ const CORBA_char *uri,
+ const CORBA_char *physical_uri,
+ CORBA_Environment *ev)
+{
+ FolderSelectionListenerServant *listener_servant;
+
+ listener_servant = (FolderSelectionListenerServant *) servant;
+
+ if (listener_servant->uri_return != NULL)
+ * (listener_servant->uri_return) = g_strdup (uri);
+
+ if (listener_servant->physical_uri_return != NULL)
+ * (listener_servant->physical_uri_return) = g_strdup (physical_uri);
+
+ g_main_quit (listener_servant->main_loop);
+}
+
+static void
+init_FolderSelectionListener_vtables (void)
+{
+ FolderSelectionListener_base_epv._private = NULL;
+ FolderSelectionListener_base_epv.finalize = NULL;
+ FolderSelectionListener_base_epv.default_POA = NULL;
+
+ FolderSelectionListener_epv.selected = impl_FolderSelectionListener_selected;
+
+ FolderSelectionListener_vepv._base_epv = &FolderSelectionListener_base_epv;
+ FolderSelectionListener_vepv.Evolution_FolderSelectionListener_epv = &FolderSelectionListener_epv;
+
+ FolderSelectionListener_vtables_initialized = TRUE;
+}
+
+static Evolution_FolderSelectionListener
+create_folder_selection_listener_interface (char **result,
+ GMainLoop *main_loop,
+ char **uri_return,
+ char **physical_uri_return)
+{
+ Evolution_FolderSelectionListener corba_interface;
+ CORBA_Environment ev;
+ FolderSelectionListenerServant *servant;
+ PortableServer_Servant listener_servant;
+
+ if (! FolderSelectionListener_vtables_initialized)
+ init_FolderSelectionListener_vtables ();
+
+ servant = g_new (FolderSelectionListenerServant, 1);
+ servant->servant.vepv = &FolderSelectionListener_vepv;
+ servant->main_loop = main_loop;
+ servant->uri_return = uri_return;
+ servant->physical_uri_return = physical_uri_return;
+
+ listener_servant = (PortableServer_Servant) servant;
+
+ CORBA_exception_init (&ev);
+
+ POA_Evolution_FolderSelectionListener__init (listener_servant, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ g_free(servant);
+ return CORBA_OBJECT_NIL;
+ }
+
+ 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;
+
+ CORBA_exception_free (&ev);
+
+ return corba_interface;
+}
+
+static void
+user_select_folder (EvolutionShellClient *shell_client,
+ const char *title,
+ const char *default_folder,
+ char **uri_return,
+ char **physical_uri_return)
+{
+ Evolution_FolderSelectionListener listener_interface;
+ Evolution_Shell corba_shell;
+ GMainLoop *main_loop;
+ CORBA_Environment ev;
+ char *result;
+
+ result = NULL;
+ main_loop = g_main_new (FALSE);
+
+ listener_interface = create_folder_selection_listener_interface (&result, main_loop,
+ uri_return, physical_uri_return);
+ if (listener_interface == CORBA_OBJECT_NIL) {
+ g_main_destroy (main_loop);
+ return;
+ }
+
+ CORBA_exception_init (&ev);
+
+ corba_shell = bonobo_object_corba_objref (BONOBO_OBJECT (shell_client));
+
+ Evolution_Shell_user_select_folder (corba_shell, listener_interface,
+ title, default_folder, &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+
+ if (uri_return != NULL)
+ *uri_return = NULL;
+ if (physical_uri_return != NULL)
+ *physical_uri_return = NULL;
+
+ return;
+ }
+
+ g_main_run (main_loop);
+
+ CORBA_Object_release (listener_interface, &ev);
+
+ CORBA_exception_free (&ev);
+}
+
+
+/* GtkObject methods. */
+
+static void
+destroy (GtkObject *object)
+{
+ EvolutionShellClient *shell_client;
+ EvolutionShellClientPrivate *priv;
+
+ shell_client = EVOLUTION_SHELL_CLIENT (object);
+ priv = shell_client->priv;
+
+ /* Nothing to do here. */
+
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+
+static void
+class_init (EvolutionShellClientClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ parent_class = gtk_type_class (bonobo_object_get_type ());
+
+ object_class = GTK_OBJECT_CLASS (klass);
+
+ object_class->destroy = destroy;
+}
+
+static void
+init (EvolutionShellClient *shell_client)
+{
+ EvolutionShellClientPrivate *priv;
+
+ priv = g_new (EvolutionShellClientPrivate, 1);
+ priv->dummy = 0;
+
+ shell_client->priv = priv;
+}
+
+
+/**
+ * evolution_shell_client_construct:
+ * @shell_client:
+ * @corba_shell:
+ *
+ * Construct @shell_client associating it to @corba_shell.
+ **/
+void
+evolution_shell_client_construct (EvolutionShellClient *shell_client,
+ Evolution_Shell corba_shell)
+{
+ g_return_if_fail (shell_client != NULL);
+ g_return_if_fail (EVOLUTION_IS_SHELL_CLIENT (shell_client));
+ g_return_if_fail (corba_shell != CORBA_OBJECT_NIL);
+
+ bonobo_object_construct (BONOBO_OBJECT (shell_client), (CORBA_Object) corba_shell);
+}
+
+/**
+ * evolution_shell_client_new:
+ * @corba_shell: A pointer to the CORBA Evolution::Shell interface.
+ *
+ * Create a new client object for @corba_shell.
+ *
+ * Return value: A pointer to the Evolution::Shell client BonoboObject.
+ **/
+EvolutionShellClient *
+evolution_shell_client_new (Evolution_Shell corba_shell)
+{
+ EvolutionShellClient *shell_client;
+
+ shell_client = gtk_type_new (evolution_shell_client_get_type ());
+
+ evolution_shell_client_construct (shell_client, corba_shell);
+
+ if (bonobo_object_corba_objref (BONOBO_OBJECT (shell_client)) == CORBA_OBJECT_NIL) {
+ bonobo_object_unref (BONOBO_OBJECT (shell_client));
+ return NULL;
+ }
+
+ return shell_client;
+}
+
+
+/**
+ * evolution_shell_client_user_select_folder:
+ * @shell_client: A EvolutionShellClient object
+ * @title: The title for the folder selection dialog
+ * @default_folder: The folder initially selected on the dialog
+ * @uri_return:
+ * @physical_uri_return:
+ *
+ * Pop up the shell's folder selection dialog with the specified @title and *
+ * *@default_folder as the initially selected folder. On return, set *@uri and
+ * *@physical_uri to the evolution: URI and the physical URI of the selected
+ * *folder. (The dialog is modal.)
+ **/
+void
+evolution_shell_client_user_select_folder (EvolutionShellClient *shell_client,
+ const char *title,
+ const char *default_folder,
+ char **uri_return,
+ char **physical_uri_return)
+{
+ g_return_if_fail (shell_client != NULL);
+ g_return_if_fail (EVOLUTION_IS_SHELL_CLIENT (shell_client));
+ g_return_if_fail (title != NULL);
+ g_return_if_fail (default_folder != NULL);
+
+ user_select_folder (shell_client, title, default_folder, uri_return, physical_uri_return);
+}
+
+
+E_MAKE_TYPE (evolution_shell_client, "EvolutionShellClient", EvolutionShellClient, class_init, init, PARENT_TYPE)
diff --git a/shell/evolution-shell-client.h b/shell/evolution-shell-client.h
new file mode 100644
index 0000000000..c1b693fd45
--- /dev/null
+++ b/shell/evolution-shell-client.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* evolution-shell-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: Ettore Perazzoli
+ */
+
+#ifndef __EVOLUTION_SHELL_CLIENT_H__
+#define __EVOLUTION_SHELL_CLIENT_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+
+#include "Evolution.h"
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+#define EVOLUTION_TYPE_SHELL_CLIENT (evolution_shell_client_get_type ())
+#define EVOLUTION_SHELL_CLIENT(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_SHELL_CLIENT, EvolutionShellClient))
+#define EVOLUTION_SHELL_CLIENT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_SHELL_CLIENT, EvolutionShellClientClass))
+#define EVOLUTION_IS_SHELL_CLIENT(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_SHELL_CLIENT))
+#define EVOLUTION_IS_SHELL_CLIENT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_SHELL_CLIENT))
+
+
+typedef struct _EvolutionShellClient EvolutionShellClient;
+typedef struct _EvolutionShellClientPrivate EvolutionShellClientPrivate;
+typedef struct _EvolutionShellClientClass EvolutionShellClientClass;
+
+struct _EvolutionShellClient {
+ BonoboObject parent;
+
+ EvolutionShellClientPrivate *priv;
+};
+
+struct _EvolutionShellClientClass {
+ BonoboObjectClass parent_class;
+};
+
+
+GtkType evolution_shell_client_get_type (void);
+void evolution_shell_client_construct (EvolutionShellClient *shell_client,
+ Evolution_Shell corba_shell);
+EvolutionShellClient *evolution_shell_client_new (Evolution_Shell shell);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __EVOLUTION_SHELL_CLIENT_H__ */
diff --git a/shell/evolution-shell-component.c b/shell/evolution-shell-component.c
index db57e6fa6b..2b739b67b6 100644
--- a/shell/evolution-shell-component.c
+++ b/shell/evolution-shell-component.c
@@ -44,7 +44,8 @@ struct _EvolutionShellComponentPrivate {
EvolutionShellComponentCreateFolderFn create_folder_fn;
EvolutionShellComponentRemoveFolderFn remove_folder_fn;
- Evolution_Shell corba_owner;
+ EvolutionShellClient *owner_client;
+
void *closure;
};
@@ -131,15 +132,15 @@ impl_ShellComponent_set_owner (PortableServer_Servant servant,
shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object);
priv = shell_component->priv;
- if (priv->corba_owner != CORBA_OBJECT_NIL) {
+ if (priv->owner_client != NULL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Evolution_ShellComponent_AlreadyOwned, NULL);
return;
}
- priv->corba_owner = CORBA_Object_duplicate (shell, ev);
+ priv->owner_client = evolution_shell_client_new (shell);
- gtk_signal_emit (GTK_OBJECT (shell_component), signals[OWNER_SET], priv->corba_owner);
+ gtk_signal_emit (GTK_OBJECT (shell_component), signals[OWNER_SET], priv->owner_client);
}
static void
@@ -154,14 +155,13 @@ impl_ShellComponent_unset_owner (PortableServer_Servant servant,
shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object);
priv = shell_component->priv;
- if (priv->corba_owner == CORBA_OBJECT_NIL) {
+ if (priv->owner_client == CORBA_OBJECT_NIL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Evolution_ShellComponent_NotOwned, NULL);
return;
}
- Bonobo_Unknown_unref (priv->corba_owner, ev);
- CORBA_Object_release (priv->corba_owner, ev);
+ bonobo_object_unref (BONOBO_OBJECT (priv->owner_client));
gtk_signal_emit (GTK_OBJECT (shell_component), signals[OWNER_UNSET]);
}
@@ -275,10 +275,8 @@ destroy (GtkObject *object)
CORBA_exception_init (&ev);
- if (priv->corba_owner != NULL) {
- Bonobo_Unknown_unref (priv->corba_owner, &ev);
- CORBA_Object_release (priv->corba_owner, &ev);
- }
+ if (priv->owner_client != NULL)
+ bonobo_object_unref (BONOBO_OBJECT (priv->owner_client));
CORBA_exception_free (&ev);
@@ -368,7 +366,7 @@ init (EvolutionShellComponent *shell_component)
priv->create_view_fn = NULL;
priv->create_folder_fn = NULL;
priv->remove_folder_fn = NULL;
- priv->corba_owner = CORBA_OBJECT_NIL;
+ priv->owner_client = NULL;
priv->closure = NULL;
shell_component->priv = priv;
@@ -444,13 +442,13 @@ evolution_shell_component_new (const EvolutionShellComponentFolderType folder_ty
return new;
}
-Evolution_Shell
+EvolutionShellClient *
evolution_shell_component_get_owner (EvolutionShellComponent *shell_component)
{
- g_return_val_if_fail (shell_component != NULL, CORBA_OBJECT_NIL);
- g_return_val_if_fail (EVOLUTION_IS_SHELL_COMPONENT (shell_component), CORBA_OBJECT_NIL);
+ g_return_val_if_fail (shell_component != NULL, NULL);
+ g_return_val_if_fail (EVOLUTION_IS_SHELL_COMPONENT (shell_component), NULL);
- return shell_component->priv->corba_owner;
+ return shell_component->priv->owner_client;
}
diff --git a/shell/evolution-shell-component.h b/shell/evolution-shell-component.h
index a1a70ebafa..c91d4bec97 100644
--- a/shell/evolution-shell-component.h
+++ b/shell/evolution-shell-component.h
@@ -33,6 +33,8 @@
#include "Evolution.h"
+#include "evolution-shell-client.h"
+
#ifdef cplusplus
extern "C" {
#pragma }
@@ -104,7 +106,7 @@ struct _EvolutionShellComponentClass {
/* Signals. */
void (* owner_set) (EvolutionShellComponent *shell_component,
- Evolution_Shell shell_interface);
+ EvolutionShellClient *shell_client);
void (* owner_unset) (EvolutionShellComponent *shell_component);
};
@@ -122,7 +124,7 @@ EvolutionShellComponent *evolution_shell_component_new (const EvolutionSh
EvolutionShellComponentCreateFolderFn create_folder_fn,
EvolutionShellComponentRemoveFolderFn remove_folder_fn,
void *closure);
-Evolution_Shell evolution_shell_component_get_owner (EvolutionShellComponent *shell_component);
+EvolutionShellClient *evolution_shell_component_get_owner (EvolutionShellComponent *shell_component);
#ifdef cplusplus
}
'sha1'>c64eccfe00
553de94865
bbb6a6942f
e8d6fc2756
482cf3700a
e8d6fc2756

bbb6a6942f
bbb6a6942f

48fb58e530
bbb6a6942f
48fb58e530
bbb6a6942f
48fb58e530
fcad5f23f2
26112575da
bbb6a6942f



553de94865
bbb6a6942f

602fee638e
92a54f0660
602fee638e
bbb6a6942f
e8d6fc2756
bbb6a6942f


482cf3700a

48fb58e530

602fee638e

bbf29c9100
602fee638e


f342817e88



602fee638e
f344dd0ad3
482cf3700a
602fee638e

f342817e88
f344dd0ad3

602fee638e
482cf3700a
f342817e88
602fee638e
f344dd0ad3
8cf2b93847
f342817e88


602fee638e
f342817e88

482cf3700a
f342817e88



602fee638e





352561d06b
602fee638e






482cf3700a
f342817e88

602fee638e
bbf29c9100

57516b50db




bbf29c9100
57516b50db

bbf29c9100

57516b50db

bbf29c9100

57516b50db
57516b50db

57516b50db
bbf29c9100

bbf29c9100





99c2d72b99
57516b50db
bbf29c9100



57516b50db
bbf29c9100

26a78dd6c5
bbf29c9100








57516b50db
bbf29c9100
































92a54f0660
bbf29c9100
bbf29c9100



























57516b50db

bbf29c9100
57516b50db
bbf29c9100
57516b50db

602fee638e

bbf29c9100
602fee638e




602fee638e
bbf29c9100
602fee638e





51f77f649b


602fee638e

eb2c101eaf
602fee638e
602fee638e
bbf29c9100

602fee638e

bbf29c9100

602fee638e
bbf29c9100



602fee638e
57516b50db
602fee638e
f342817e88
e8d6fc2756



c55ddc508d
e8d6fc2756









c55ddc508d
ede7fcb220
c55ddc508d

e8d6fc2756
c55ddc508d
e8d6fc2756
c55ddc508d

e8d6fc2756


c55ddc508d















e8d6fc2756


f342817e88

48fb58e530










e8d6fc2756
553de94865
e7971bb4f5

f342817e88


e7971bb4f5
bbb6a6942f



e7971bb4f5

602fee638e
e7971bb4f5

602fee638e
bbf29c9100
602fee638e

eb2c101eaf
e7971bb4f5

f342817e88











































482cf3700a
f342817e88



482cf3700a
8cf2b93847
f342817e88
482cf3700a
f342817e88









































f342817e88

















97cc1d57ad
f342817e88


f342817e88



bb7d2c4499

f342817e88





bb7d2c4499
f342817e88













3b17294f86
f342817e88
3b17294f86



f342817e88

f342817e88






















3e805202e4
f342817e88
3e805202e4
f342817e88



a6b2711b08
bb7d2c4499



a6b2711b08


f342817e88




3e805202e4


f342817e88


838ab4dc66
f342817e88



bb7d2c4499

f342817e88












e8d6fc2756



f342817e88
e8d6fc2756
f342817e88
e8d6fc2756
f342817e88








acaea79e71
51f77f649b
acaea79e71

51f77f649b
f342817e88



















e8d6fc2756

725d0a088d
385ba85d42
553de94865
e8d6fc2756
553de94865
8c2f3a00ef


ae79a5820b
8c2f3a00ef




e8d6fc2756
553de94865
8c2f3a00ef
0f618ac4cf
eb2c101eaf
602fee638e
ae79a5820b
602fee638e







bbf29c9100
602fee638e


385ba85d42
0fa29927fc
385ba85d42
0fa29927fc
0f618ac4cf





0f618ac4cf



385ba85d42
eb2c101eaf
0f618ac4cf


725d0a088d





c55ddc508d
725d0a088d
9d77b85ae3
c55ddc508d

e7971bb4f5
725d0a088d
c55ddc508d

725d0a088d
bbb6a6942f

e8d6fc2756
725d0a088d








aa20072666
bbb6a6942f
aa20072666
725d0a088d






bbb6a6942f
725d0a088d

e7971bb4f5
7065f6dba3
725d0a088d

9c73777f22
3bc843ceb5
7065f6dba3

725d0a088d
e7971bb4f5

725d0a088d
d2d0eebd74
725d0a088d



bbb6a6942f
ede7fcb220
bbb6a6942f
e7971bb4f5


725d0a088d
aa20072666
d325e6d453
aa20072666
ede7fcb220








0f618ac4cf
725d0a088d



bbb6a6942f
e7971bb4f5
725d0a088d


bbb6a6942f

725d0a088d

1bb3a9f0a8
725d0a088d
bbb6a6942f
ede7fcb220
725d0a088d















385ba85d42
aa20072666


385ba85d42
aa20072666










725d0a088d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201


                                                                           
                                        

                                                                
                                                                   
                                                        

















                                                                    


                                                                                      





                    
                  



                      
                   
                   
 
                          
 
                                
                                
 
                            
 
                          
                           
                              
 
                              
 

                            
                                    



                                          
                              
                                                  
                        
                                           


  


























































                                                                               

                         








                                         






                                                                                 
                                                                        
                                                                             
                                                                         

                                            

 
               

                                                    

                                                    






                                                                        
                                         
                                             
                                                            






                                                  







                                                                                


               


                                       
 
                                     
                        
 

                                               
                                                              
                             
                                                                                              

                            
 
                                                 









                                                                  


                                                                               



                                            

 












                                                                           


                                                                                   























                                                                                   

                                       
                                 
 

                           















                                                                                              
                                      


                                                               

                                                                           





                                                                                              
                                                                         





                                                                                
                                                                             
                                                                 

                                                             
                                                
                                                           


                 
                                                
 

                                                                         
                                                               
 

                                                                    
                                                            

                                                                           

                                             






                                              
 
                                                
 





                                                      
 
                          
                                   
                          
                            

                                            
                                   
 
                                     
                                             
        
                                               
 
                                      
                                                         

                             
                                                                             
                                                              
                                                                                                  
 
                                                                                             

                                                                                     
                                                


                                                                  
                                                            
                                
         
 
                             
 

                                                                   
                                                          
        
                                              
                                                


                                                  


                            
           
                                            
                                              










                                                        
                          







                                                                                                   

                                                                                

                                                                            
                       





                                                                                                  
                                     
                                                             


                                                                 
                                       
                       
         
        
                                                 

                                                                                             
 

                                                                                         
        
                                                                    
        
                                                                 
                                                                 
                                                       
                                                              



                                                              
                                                

                                                
 
                                        
 
                                                                               
                                                                           


                                                                                                     

                             

 

                                       
                                    


                                                                            



                                                      
                          
                                   
                          

                            
 

                                   
                                            
                                                 
 
                                                                    
                                                                   
                                                                                              


                           
                                             

                                          
                                     



                                              





                                                                        
                                                                                     






                                                                                                       
                             

                            
 

                                                                                  




                                                                                              
                                   

                                                     

                         

                                                               

                                                                        
 

                                                                           
                                                     

                                                                                                  





                                                                                                    
                                                
 



                                                                            
 

                                                                 
 








                                                                                   
 
































                                                                                                
                              
 



























                                                                                                     

         
                                 
 
                    

                                

                                            
                                




                                                        
                        
                                    





                                                      


                                                       

                                                                                                           
                                     
                                             
 

                                                                                       

                                                                 

                                                                        
 



                                                              
 
                                            
 
 



                         
                              









                                                 
                                                 
                                                            

                                                  
 
                                             
                                                                             

                                              


                                   















                                                             


 

                        










                                                          
 
                                                                                                 

 


                        
           



                                                          

                                     
                              

                                                  
 
                                                     

                             
                                                                       

 











































                                                                                      
                                



                                                                   
                                                                 
                                                                                           
                                                                                           
                                   









































                                                                                        

















                                                                                                                  
                                                                                                     


                                                                                            



                              

                                                





                                                 
                                                  













                                                                                            
                                                     
                                                                                                        



                                                                                                                            

                 






















                                                                                  
                                 
                               
        



                                                                 
                                                     



                                                                                       


                       




                                                                                                       


                                                                                                                    


                                                                         
                                                                                               



                                                                                          

                                                                                                                       












                                                                 



                                                     
                                               
                                                        
                                            
 








                                                  
                                                                                                   
                                                                                       

                       
 



















                                                                                                            

 
 
                                                                                             
           
                                                             
                                                                  


                                                           
                                                                   




                                               
 
                                                                                     
 
 
          
                                                             
                                                                  







                                                            
                                                   


           
                                                             
                                                    
                                                    
                                              





                                               



                                                                        
                                                         
               


 





                                      
                                   
 
                                                                

                                               
                                                
 

                                               
 

                                                                      
                                                                    








                                               
                                          
                                          
                                          






                                        
                                                     

                                 
                                   
                             

                          
                                                                        
                                                       

                                                  
 

                                   
                                           
                                                                                     



                                                         
                                                      
                                            
                                                          


                                                               
 
                                                  
                                                                                     
 








                                                                          
 



                                                
                                                                
                                            


                      

                                                                                      

                                                       
                                                               
 
                                                                                   
                                     















                                                                        
                             


                                                                  
                                                










                                                                                              
                                                                                            
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-local-storage.c
 *
 * Copyright (C) 2000, 2001 Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli
 */

/* FIXMEs:
 *
 *   - If we have `.' or `..' as path elements, we lose.
 *
 *   - If the LocalStorage is destroyed and an async operation on a shell component is
 *     pending, we get a callback on a bogus object.  We need support for cancelling
 *     operations on the shell component.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>

#include <gtk/gtksignal.h>

#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>

#include <gal/util/e-util.h>

#include "e-util/e-path.h"
#include "e-local-folder.h"
#include "e-shell-constants.h"

#include "evolution-storage.h"

#include "e-local-storage.h"

#include <bonobo/bonobo-exception.h>

#define PARENT_TYPE E_TYPE_STORAGE
static EStorageClass *parent_class = NULL;

struct _ELocalStoragePrivate {
    EFolderTypeRegistry *folder_type_registry;
    char *base_path;
    EvolutionStorage *bonobo_interface;
};


/* 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.  */

static void
new_folder (ELocalStorage *local_storage,
        const char *path,
        EFolder *folder)
{
    ELocalStoragePrivate *priv;

    priv = local_storage->priv;

    e_storage_new_folder (E_STORAGE (local_storage), path, folder);

    evolution_storage_new_folder (EVOLUTION_STORAGE (priv->bonobo_interface),
                      path,
                      e_folder_get_name (folder),
                      e_folder_get_type_string (folder),
                      e_folder_get_physical_uri (folder),
                      e_folder_get_description (folder),
                      e_folder_get_custom_icon_name (folder),
                      e_folder_get_unread_count (folder),
                      FALSE,
                      0);
}

static gboolean
setup_folder_as_stock (ELocalStorage *local_storage,
               const char *path,
               const char *name,
               const char *custom_icon_name)
{
    EFolder *folder;

    folder = e_storage_get_folder (E_STORAGE (local_storage), path);
    if (folder == NULL)
        return FALSE;

    e_folder_set_name (folder, name);
    e_folder_set_is_stock (folder, TRUE);
    e_folder_set_custom_icon (folder, custom_icon_name);

    return TRUE;
}

static void
setup_stock_folders (ELocalStorage *local_storage)
{
    setup_folder_as_stock (local_storage, "/Calendar", _("Calendar"), NULL);
    setup_folder_as_stock (local_storage, "/Contacts", _("Contacts"), NULL);
    setup_folder_as_stock (local_storage, "/Drafts", _("Drafts"), NULL);
    setup_folder_as_stock (local_storage, "/Inbox", _("Inbox"), "inbox");
    setup_folder_as_stock (local_storage, "/Outbox", _("Outbox"), "outbox");
    setup_folder_as_stock (local_storage, "/Sent", _("Sent"), NULL);
    setup_folder_as_stock (local_storage, "/Tasks", _("Tasks"), NULL);
    setup_folder_as_stock (local_storage, "/Trash", _("Trash"), NULL);
}

static gboolean
load_folder (const char *physical_path,
         const char *path,
         void *data)
{
    ELocalStorage *local_storage;
    EFolder *folder;

    local_storage = E_LOCAL_STORAGE (data);

    folder = e_local_folder_new_from_path (physical_path);
    if (folder == NULL) {
        /* g_warning ("No folder metadata in %s... ignoring", physical_path); FIXME */
        return TRUE;
    }

    new_folder (local_storage, path, folder);
    return TRUE;
}

static gboolean
load_all_folders (ELocalStorage *local_storage)
{
    const char *base_path;

    base_path = e_local_storage_get_base_path (local_storage);

    /* Ignore errors, so we set up the local storage even if there is stale
       data that we don't understand in ~/evolution.  */
    e_path_find_folders (base_path, load_folder, local_storage);

    setup_stock_folders (local_storage);

    return TRUE;
}

static EStorageResult
storage_result_from_component_result (EvolutionShellComponentResult result)
{
    switch (result) {
    case EVOLUTION_SHELL_COMPONENT_PERMISSIONDENIED:
        return E_STORAGE_PERMISSIONDENIED;
    case EVOLUTION_SHELL_COMPONENT_NOSPACE:
        return E_STORAGE_NOSPACE; 
    default:
        return E_STORAGE_GENERICERROR;
    }
}


/* Callbacks for the async methods invoked on the `Evolution::ShellComponent's.  */

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);
    if (BONOBO_EX (&ev)) {
        g_warning ("Exception notifing listener: %s\n",
               CORBA_exception_id (&ev));
    }
    CORBA_exception_free (&ev);
}

struct _AsyncCreateFolderCallbackData {
    EStorage *storage;
    Bonobo_Listener listener;

    char *path;
    char *display_name;
    char *type;
    char *description;
    char *physical_uri;
    char *physical_path;

    EStorageResultCallback callback;
    void *callback_data;
};
typedef struct _AsyncCreateFolderCallbackData AsyncCreateFolderCallbackData;

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);
    } else {
        EFolder *folder;

        folder = e_local_folder_new (callback_data->display_name,
                         callback_data->type,
                         callback_data->description);

        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);
        } else {
            rmdir (callback_data->physical_path);
            g_object_unref (folder);
            storage_result = E_STORAGE_IOERROR;
        }
    }

    g_object_unref (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,
                         storage_result,
                         callback_data->callback_data);
    
    g_free (callback_data->path);
    g_free (callback_data->display_name);
    g_free (callback_data->type);
    g_free (callback_data->description);
    g_free (callback_data->physical_uri);
    g_free (callback_data->physical_path);
    g_free (callback_data);
}


/* Implementation for the folder operations.  */

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;
    char *parent_path;
    char *physical_path;
    
    storage = E_STORAGE (local_storage);
    priv = local_storage->priv;

    *physical_path_return = NULL;
    g_assert (g_path_is_absolute (path));
    
    parent_path = g_path_get_dirname(path);

    if (strlen(parent_path) > 1) {
        char *subfolders_directory_physical_path;
        char *parent;

        /* Create the `subfolders' subdirectory under the parent.  */
        parent = g_strdup_printf ("%s/", parent_path);
        subfolders_directory_physical_path = e_path_to_physical (priv->base_path, parent);

        if (! g_file_test (subfolders_directory_physical_path, G_FILE_TEST_EXISTS)) {
            if (mkdir (subfolders_directory_physical_path, 0700) == -1) {
                g_free (subfolders_directory_physical_path);
                g_free (parent);
                return errno_to_storage_result ();
            }
        }
        g_free (subfolders_directory_physical_path);
        g_free (parent);
    }

    g_free (parent_path);

    physical_path = e_path_to_physical (priv->base_path, path);

    /* Create the directory that holds the folder.  */
    
    *physical_path_return = physical_path;
    if (mkdir (physical_path, 0700) == -1) {
        return errno_to_storage_result ();
    }

    return E_STORAGE_OK;
}

static void
create_folder (ELocalStorage *local_storage,
           const 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;
    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 (listener != CORBA_OBJECT_NIL)
            notify_listener (listener, E_STORAGE_INVALIDTYPE, NULL);
        if (callback != NULL)
            (* callback) (storage, E_STORAGE_INVALIDTYPE, data);
        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, result, data);
        if (listener != CORBA_OBJECT_NIL)
            notify_listener (listener, result, NULL);

        g_free (physical_path);
        return;
    }
    
    folder_name = g_path_get_basename (path);

    /* 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.  */
    
    physical_uri = g_strconcat ("file://", physical_path, NULL);
    
    callback_data = g_new (AsyncCreateFolderCallbackData, 1);
    callback_data->storage       = E_STORAGE (local_storage);
    callback_data->path          = g_strdup (path);
    callback_data->display_name  = g_strdup (folder_name);
    callback_data->type          = g_strdup (type);
    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;

    g_object_ref (component_client);

    evolution_shell_component_client_async_create_folder (component_client,
                                  physical_uri,
                                  type,
                                  component_async_create_folder_callback,
                                  callback_data);

    g_free (folder_name);
}

struct _AsyncRemoveFolderCallbackData {
    EStorage *storage;
    GList *next_paths_to_delete;
};
typedef struct _AsyncRemoveFolderCallbackData AsyncRemoveFolderCallbackData;

static EStorageResult
remove_folder_directory (ELocalStorage *local_storage,
             const char *path)
{
    EStorage *storage;
    ELocalStoragePrivate *priv;
    char *folder_name;
    char *file_name;
    char *physical_path;

    priv = local_storage->priv;

    storage = E_STORAGE (local_storage);
    folder_name = g_path_get_basename (path);

    /* Delete the metadata file associated with this folder.  */
    physical_path = e_path_to_physical (priv->base_path, path);
    file_name = g_build_filename (physical_path, E_LOCAL_FOLDER_METADATA_FILE_NAME, NULL);
    unlink (file_name);
    g_free (file_name);

    /* Delete the physical directory.  */
    if (rmdir (physical_path) == -1) {
        g_free (physical_path);
        g_free (folder_name);
        return E_STORAGE_GENERICERROR;
    }

    g_free (physical_path);

    /* Delete the 'subfolders' directory that this folder lies in */
    if (folder_name != path + 1) {
        char *subfolders_directory_physical_path;
        char *parent_path;
        
        parent_path = g_strndup (path, strlen (path) - strlen (folder_name));
        subfolders_directory_physical_path = e_path_to_physical (priv->base_path, parent_path);
        g_free (parent_path);

        rmdir (subfolders_directory_physical_path);
        g_free (subfolders_directory_physical_path);
    }

    g_free (folder_name);
    return E_STORAGE_OK;
}

static gboolean remove_folder_step (AsyncRemoveFolderCallbackData *callback_data);

static void
component_async_remove_folder_callback (EvolutionShellComponentClient *shell_component_client,
                    EvolutionShellComponentResult result,
                    void *data)
{
    ELocalStoragePrivate *priv;
    AsyncRemoveFolderCallbackData *callback_data;
    EStorageResult storage_result;
    gboolean success;
    const char *path;

    callback_data = (AsyncRemoveFolderCallbackData *) data;
    priv = E_LOCAL_STORAGE (callback_data->storage)->priv;
    path = (const char *) callback_data->next_paths_to_delete->data;

    storage_result = shell_component_result_to_storage_result (result);

    if (result == EVOLUTION_SHELL_COMPONENT_OK) {
        result = remove_folder_directory (E_LOCAL_STORAGE (callback_data->storage), path);
        e_storage_removed_folder (E_STORAGE (callback_data->storage), path);
        evolution_storage_removed_folder (EVOLUTION_STORAGE (priv->bonobo_interface), path);
    } else {
        /* FIXME: Handle errors.  */
        g_print ("...Error removing %s!\n", path);
    }

    g_object_unref (shell_component_client);

    /* Now go on and delete the next subfolder in the list that still
       exists, deallocating the elements in the list in the process.  */
    do {
        char *path;

        path = callback_data->next_paths_to_delete->data;
        g_free (path);

        callback_data->next_paths_to_delete
            = g_list_remove_link (callback_data->next_paths_to_delete,
                          callback_data->next_paths_to_delete);

        /* Check if we are done.  */
        if (callback_data->next_paths_to_delete == NULL) {
            g_free (callback_data);
            return;
        }

        /* Remove the folder; if the folder has disappeared from the
           tree for some reason (this is an async callback!), just go
           on with the next one.  */
        success = remove_folder_step (callback_data);
    } while (! success);
}

static gboolean
remove_folder_step (AsyncRemoveFolderCallbackData *callback_data)
{
    EvolutionShellComponentClient *client;
    ELocalStoragePrivate *priv;
    EFolder *folder;
    const char *path;
    const char *type;
    char *physical_path;
    char *physical_uri;

    g_assert (callback_data->next_paths_to_delete != NULL);
    path = (const char *) callback_data->next_paths_to_delete->data;

    folder = e_storage_get_folder (callback_data->storage, path);
    if (folder == NULL)
        return FALSE;

    priv = E_LOCAL_STORAGE (callback_data->storage)->priv;

    physical_path = e_path_to_physical (priv->base_path, path);
    physical_uri = g_strconcat ("file://", physical_path, NULL);

    type = e_folder_get_type_string (folder);
    client = e_folder_type_registry_get_handler_for_type (priv->folder_type_registry, type);

    g_object_ref (client);

    evolution_shell_component_client_async_remove_folder (client, physical_uri, type,
                                  component_async_remove_folder_callback,
                                  callback_data);

    g_free (physical_path);
    g_free (physical_uri);

    return TRUE;
}

static GList *
create_subfolder_list (ELocalStorage *local_storage,
               const char *path)
{
    GList *subfolders;
    GList *list;
    GList *p;

    subfolders = e_storage_get_subfolder_paths (E_STORAGE (local_storage), path);

    list = NULL;
    for (p = subfolders; p != NULL; p = p->next) {
        char *path;

        path = (char *) p->data;

        list = g_list_concat (list, create_subfolder_list (local_storage, path));
        list = g_list_append (list, path);
    }

    g_list_free (subfolders);

    return list;
}
                
static EStorageResult
remove_folder (ELocalStorage *local_storage,
           const char *path)
{
    ELocalStoragePrivate *priv;
    EStorage *storage;
    AsyncRemoveFolderCallbackData *callback_data;
    EvolutionShellComponentClient *component_client;
    EFolder *folder;
    GList *next_paths_to_delete;

    priv = local_storage->priv;

    storage = E_STORAGE (local_storage);
    folder = e_storage_get_folder (storage, path);

    if (e_folder_get_is_stock (folder))
        return E_STORAGE_CANTCHANGESTOCKFOLDER;

    component_client = e_folder_type_registry_get_handler_for_type (priv->folder_type_registry,
                                    e_folder_get_type_string (folder));
    if (component_client == NULL)
        return E_STORAGE_INVALIDTYPE;

    next_paths_to_delete = create_subfolder_list (E_LOCAL_STORAGE (storage), path);
    next_paths_to_delete = g_list_append (next_paths_to_delete, g_strdup (path));

    callback_data = g_new (AsyncRemoveFolderCallbackData, 1);
    callback_data->storage              = E_STORAGE (local_storage);
    callback_data->next_paths_to_delete = next_paths_to_delete;

    if (! remove_folder_step (callback_data)) {
        /* Eek, something wacky happened.  */
        return EVOLUTION_SHELL_COMPONENT_UNKNOWNERROR;
    }

    return EVOLUTION_SHELL_COMPONENT_OK;
}


/* GtkObject methods.  */

static void
impl_dispose (GObject *object)
{
    ELocalStorage *local_storage;
    ELocalStoragePrivate *priv;
    CORBA_Environment ev;

    local_storage = E_LOCAL_STORAGE (object);
    priv = local_storage->priv;

    CORBA_exception_init (&ev);

    if (priv->folder_type_registry != NULL) {
        g_object_unref (priv->folder_type_registry);
        priv->folder_type_registry = NULL;
    }

    if (priv->bonobo_interface != NULL) {
        bonobo_object_unref (BONOBO_OBJECT (priv->bonobo_interface));
        priv->bonobo_interface = NULL;
    }

    CORBA_exception_free (&ev);

    (* G_OBJECT_CLASS (parent_class)->dispose) (object);
}

static void
impl_finalize (GObject *object)
{
    ELocalStorage *local_storage;
    ELocalStoragePrivate *priv;

    local_storage = E_LOCAL_STORAGE (object);
    priv = local_storage->priv;

    g_free (priv->base_path);
    g_free (priv);

    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
}


/* Creating folders.  */

static void
impl_async_create_folder (EStorage *storage,
              const char *path,
              const char *type,
              const char *description,
              EStorageResultCallback callback,
              void *data)
{
    ELocalStorage *local_storage;

    local_storage = E_LOCAL_STORAGE (storage);

    create_folder (local_storage, CORBA_OBJECT_NIL, path, type, description, callback, data);
}


/* Removing folders.  */

static void
impl_async_remove_folder (EStorage *storage,
              const char *path,
              EStorageResultCallback callback,
              void *data)
{
    ELocalStorage *local_storage;
    EStorageResult result;

    local_storage = E_LOCAL_STORAGE (storage);

    result = remove_folder (local_storage, path);

    if (callback != NULL)
        (* callback) (E_STORAGE (local_storage), result, data);
}



/* Transferring folders.  */

struct _XferItem {
    char *source_path;
    char *destination_path;
};
typedef struct _XferItem XferItem;

static XferItem *
xfer_item_new (char *source_path,
           char *destination_path)
{
    XferItem *new;

    new = g_new (XferItem, 1);
    new->source_path      = source_path;
    new->destination_path = destination_path;

    return new;
}

static void
xfer_item_free (XferItem *item)
{
    g_free (item->source_path);
    g_free (item->destination_path);
    g_free (item);
}

static void
append_xfer_item_list (EStorage *storage,
               char *source_path,
               char *destination_path,
               GList **list)
{
    GList *subfolders;
    GList *p;

    *list = g_list_prepend (*list, xfer_item_new (source_path, destination_path));

    subfolders = e_storage_get_subfolder_paths (storage, source_path);
    for (p = subfolders; p != NULL; p = p->next) {
        char *base_name;
        char *source_subpath;
        char *destination_subpath;

        source_subpath = g_strdup ((const char *) p->data);
        base_name = g_path_get_basename (source_subpath);
        destination_subpath = g_build_filename (destination_path, base_name, NULL);
        append_xfer_item_list (storage, source_subpath, destination_subpath, list);
        g_free (base_name);
    }

    e_free_string_list (subfolders);
}

struct _XferData {
    /* The storage on which we are performing the xfer operation.  */
    ELocalStorage *local_storage;

    /* List of source/destination path couples to copy, in the right
       order.  */
    GList *folder_items;

    /* Pointer into `folder_items'.  The folder item pointed by this is the
       one handled by the previous CORBA invocation.  */
    GList *current_folder_item;

    /* Whether we want to remove the source too.  */
    gboolean remove_source;

    /* The callback, with its data.  */
    EStorageResultCallback callback;
    void *callback_data;
};
typedef struct _XferData XferData;

static void
async_xfer_folder_step (ELocalStorage *local_storage,
            const char *source_path,
            const char *destination_path,
            gboolean remove_source,
            EvolutionShellComponentClientCallback component_client_callback,
            void *component_client_callback_data)
{
    ELocalStoragePrivate *priv;
    EFolder *source_folder;
    EvolutionShellComponentClient *component_client;
    char *physical_path;
    char *physical_uri;

    priv = local_storage->priv;

    source_folder = e_storage_get_folder (E_STORAGE (local_storage), source_path);
    g_assert (source_folder != NULL);

    create_folder_directory (local_storage, destination_path,
                 e_folder_get_type_string (source_folder),
                 e_folder_get_description (source_folder),
                 &physical_path);

    physical_uri = g_strconcat ("file://", physical_path, NULL);
    g_free (physical_path);

    component_client = e_folder_type_registry_get_handler_for_type (priv->folder_type_registry,
                                    e_folder_get_type_string (source_folder));
    g_assert (component_client != NULL);

    evolution_shell_component_client_async_xfer_folder (component_client,
                                e_folder_get_physical_uri (source_folder),
                                physical_uri,
                                e_folder_get_type_string (source_folder),
                                remove_source,
                                component_client_callback,
                                component_client_callback_data);
    g_free (physical_uri);
}

static void
async_xfer_folder_complete (XferData *xfer_data,
                gboolean success)
{
    ELocalStorage *local_storage;
    GList *p;

    local_storage = xfer_data->local_storage;

    if (success && xfer_data->remove_source) {
        EStorageResult result;

        /* Remove all the source physical directories, and also the
           corresponding folders from the folder tree.  */

        for (p = g_list_last (xfer_data->folder_items); p != NULL; p = p->prev) {
            XferItem *item;

            item = (XferItem *) p->data;

            result = remove_folder_directory (local_storage, item->source_path);

            /* FIXME handle failure differently?  This should be n
               unlikely situation.  */
            if (result == E_STORAGE_OK) {
                e_storage_removed_folder (E_STORAGE (local_storage), item->source_path);

                evolution_storage_removed_folder (EVOLUTION_STORAGE (local_storage->priv->bonobo_interface),
                                  item->source_path);
            }
        }
    }

    /* Free the data.  */

    for (p = xfer_data->folder_items; p != NULL; p = p->next) {
        XferItem *item;

        item = (XferItem *) p->data;
        xfer_item_free (item);
    }
    g_list_free (xfer_data->folder_items);

    g_free (xfer_data);
}

static void
async_xfer_folder_callback (EvolutionShellComponentClient *shell_component_client,
                EvolutionShellComponentResult result,
                void *callback_data)
{
    XferData *xfer_data;
    XferItem *item;
    EFolder *source_folder;
    EFolder *destination_folder;
    char *dest_physical_path;
    char *new_physical_uri;
    
    xfer_data = (XferData *) callback_data;

    item = (XferItem *) xfer_data->current_folder_item->data;

    if (result != EVOLUTION_SHELL_COMPONENT_OK) {
        (* xfer_data->callback) (E_STORAGE (xfer_data->local_storage),
                     storage_result_from_component_result (result),
                     xfer_data->callback_data);
        async_xfer_folder_complete (xfer_data, FALSE);
        return;
    }

    source_folder = e_storage_get_folder (E_STORAGE (xfer_data->local_storage), item->source_path);
    destination_folder = e_local_folder_new (e_folder_get_name (source_folder),
                         e_folder_get_type_string (source_folder),
                         e_folder_get_description (source_folder));

    dest_physical_path = e_path_to_physical (xfer_data->local_storage->priv->base_path, item->destination_path);
    new_physical_uri = g_strconcat ("file://", dest_physical_path, NULL);
    g_free (dest_physical_path);
    e_folder_set_physical_uri (destination_folder, new_physical_uri);
    g_free (new_physical_uri);

    e_local_folder_save (E_LOCAL_FOLDER (destination_folder)); /* FIXME check for errors */
    new_folder (xfer_data->local_storage, item->destination_path, destination_folder);

    xfer_data->current_folder_item = xfer_data->current_folder_item->next;
    if (xfer_data->current_folder_item == NULL) {
        (* xfer_data->callback) (E_STORAGE (xfer_data->local_storage), E_STORAGE_OK, xfer_data->callback_data);
        async_xfer_folder_complete (xfer_data, TRUE);
        return;
    }

    item = (XferItem *) xfer_data->current_folder_item->data;

    async_xfer_folder_step (xfer_data->local_storage,
                item->source_path,
                item->destination_path,
                xfer_data->remove_source,
                async_xfer_folder_callback,
                xfer_data);
}

static void
impl_async_xfer_folder (EStorage *storage,
            const char *source_path,
            const char *destination_path,
            gboolean remove_source,
            EStorageResultCallback callback,
            void *callback_data)
{
    ELocalStorage *local_storage;
    ELocalStoragePrivate *priv;
    XferData *xfer_data;
    GList *folder_items;    /* <XferItem> */
    XferItem *first_item;

    local_storage = E_LOCAL_STORAGE (storage);
    priv = local_storage->priv;

    if (remove_source && e_folder_get_is_stock (e_storage_get_folder (storage, source_path))) {
        (* callback) (storage, E_STORAGE_CANTCHANGESTOCKFOLDER, callback_data);
        return;
    }

    folder_items = NULL;
    append_xfer_item_list (storage, g_strdup (source_path), g_strdup (destination_path), &folder_items);
    folder_items = g_list_reverse (folder_items); /* lame */

    xfer_data = g_new (XferData, 1);
    xfer_data->local_storage       = local_storage;
    xfer_data->folder_items        = folder_items;
    xfer_data->current_folder_item = folder_items;
    xfer_data->remove_source       = remove_source;
    xfer_data->callback            = callback;
    xfer_data->callback_data       = callback_data;

    first_item = (XferItem *) xfer_data->folder_items->data;

    async_xfer_folder_step (E_LOCAL_STORAGE (storage),
                first_item->source_path,
                first_item->destination_path,
                remove_source,
                async_xfer_folder_callback,
                xfer_data);
}


/* Callbacks for the `Evolution::Storage' interface we are exposing to the outside world.  */
static void
bonobo_interface_create_folder_cb (EvolutionStorage *storage,
                   const Bonobo_Listener listener,
                   const char *path,
                   const char *type,
                   const char *description,
                   const char *parent_physical_uri,
                   void *data)
{
    ELocalStorage *local_storage;

    local_storage = E_LOCAL_STORAGE (data);

    create_folder (local_storage, listener, path, type, description, NULL, NULL);
}

static int
bonobo_interface_remove_folder_cb (EvolutionStorage *storage,
                   const Bonobo_Listener listener,
                   const char *path,
                   const char *physical_uri,
                   void *data)
{
    ELocalStorage *local_storage;

    local_storage = E_LOCAL_STORAGE (data);

    return remove_folder (local_storage, path);
}

static void
bonobo_interface_update_folder_cb (EvolutionStorage *storage,
                   const char *path,
                   int unread_count,
                   void *data)
{
    ELocalStorage *local_storage;
    EFolder *folder;

    local_storage = E_LOCAL_STORAGE (data);

    folder = e_storage_get_folder (E_STORAGE (local_storage), path);
    if (folder == NULL)
        return;

    e_folder_set_unread_count (folder, unread_count);
    return;
}


/* Initialization.  */

static void
class_init (ELocalStorageClass *class)
{
    EStorageClass *storage_class;
    GObjectClass *object_class;

    parent_class  = g_type_class_ref(e_storage_get_type ());

    object_class  = G_OBJECT_CLASS (class);
    storage_class = E_STORAGE_CLASS (class);

    object_class->finalize = impl_finalize;
    object_class->dispose  = impl_dispose;

    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
init (ELocalStorage *local_storage)
{
    ELocalStoragePrivate *priv;

    priv = g_new (ELocalStoragePrivate, 1);

    priv->base_path            = NULL;
    priv->folder_type_registry = NULL;
    priv->bonobo_interface     = NULL;

    local_storage->priv = priv;
}


static gboolean
construct (ELocalStorage *local_storage,
       EFolderTypeRegistry *folder_type_registry,
       const char *base_path)
{
    ELocalStoragePrivate *priv;
    EFolder *root_folder;
    int base_path_len;

    root_folder = e_folder_new (_("Local Folders"), "noselect", "");
    e_storage_construct (E_STORAGE (local_storage),
                 E_LOCAL_STORAGE_NAME,
                 root_folder);

    priv = local_storage->priv;

    base_path_len = strlen (base_path);
    while (base_path_len > 0 && base_path[base_path_len - 1] == E_PATH_SEPARATOR)
        base_path_len--;

    g_return_val_if_fail (base_path_len != 0, FALSE);

    g_assert (priv->folder_type_registry == NULL);
    g_object_ref (folder_type_registry);
    priv->folder_type_registry = folder_type_registry;

    g_assert (priv->base_path == NULL);
    priv->base_path = g_strndup (base_path, base_path_len);

    g_assert (priv->bonobo_interface == NULL);
    priv->bonobo_interface = evolution_storage_new (E_LOCAL_STORAGE_NAME, FALSE);

    g_signal_connect (priv->bonobo_interface, "create_folder",
              G_CALLBACK (bonobo_interface_create_folder_cb), 
              local_storage);
    g_signal_connect (priv->bonobo_interface, "remove_folder",
              G_CALLBACK (bonobo_interface_remove_folder_cb),
              local_storage);
    g_signal_connect (priv->bonobo_interface, "update_folder",
              G_CALLBACK (bonobo_interface_update_folder_cb),
              local_storage);

    return load_all_folders (local_storage);
}

EStorage *
e_local_storage_open (EFolderTypeRegistry *folder_type_registry,
              const char *base_path)
{
    EStorage *new;

    g_return_val_if_fail (folder_type_registry != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), NULL);
    g_return_val_if_fail (base_path != NULL, NULL);

    new = g_object_new (e_local_storage_get_type (), NULL);

    if (! construct (E_LOCAL_STORAGE (new), folder_type_registry, base_path)) {
        g_object_unref (new);
        return NULL;
    }

    return new;
}

const char *
e_local_storage_get_base_path (ELocalStorage *local_storage)
{
    g_return_val_if_fail (local_storage != NULL, NULL);
    g_return_val_if_fail (E_IS_LOCAL_STORAGE (local_storage), NULL);

    return local_storage->priv->base_path;
}


const GNOME_Evolution_Storage
e_local_storage_get_corba_interface (ELocalStorage *local_storage)
{
    ELocalStoragePrivate *priv;
    GNOME_Evolution_Storage corba_interface;

    g_return_val_if_fail (local_storage != NULL, NULL);
    g_return_val_if_fail (E_IS_LOCAL_STORAGE (local_storage), NULL);

    priv = local_storage->priv;
    corba_interface = bonobo_object_corba_objref (BONOBO_OBJECT (priv->bonobo_interface));

    return corba_interface;
}


E_MAKE_TYPE (e_local_storage, "ELocalStorage", ELocalStorage, class_init, init, PARENT_TYPE)