aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-07-19 08:29:16 +0800
committerChris Toshok <toshok@src.gnome.org>2001-07-19 08:29:16 +0800
commit150e7c57f8f542baf7e4f71caf38fe0d60c8917b (patch)
tree17907e329a5a79aace5c1b061a2fb6cdc1f10188
parent833e3bf56a4dd7bafc7a0fe823a63b1b050e1707 (diff)
downloadgsoc2013-evolution-150e7c57f8f542baf7e4f71caf38fe0d60c8917b.tar.gz
gsoc2013-evolution-150e7c57f8f542baf7e4f71caf38fe0d60c8917b.tar.zst
gsoc2013-evolution-150e7c57f8f542baf7e4f71caf38fe0d60c8917b.zip
[ patch contributed by Jos Dehaes <jos.dehaes@bigfoot.com> ]
2001-07-18 Chris Toshok <toshok@ximian.com> [ patch contributed by Jos Dehaes <jos.dehaes@bigfoot.com> ] * gui/component/addressbook-storage.c (register_storage): new function, register our evolution_storage. (addressbook_storage_setup): remove storage registration from here. (load_source_data): register the storage here before we load addressbook-sources.xml, and deregister it if there are no sources listed. (addressbook_storage_remove_source): unregister the storage if the list of sources hits 0 length. svn path=/trunk/; revision=11217
-rw-r--r--addressbook/ChangeLog14
-rw-r--r--addressbook/gui/component/addressbook-storage.c76
2 files changed, 75 insertions, 15 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index f0673c9246..78a8d0360d 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,17 @@
+2001-07-18 Chris Toshok <toshok@ximian.com>
+
+ [ patch contributed by Jos Dehaes <jos.dehaes@bigfoot.com> ]
+
+ * gui/component/addressbook-storage.c (register_storage): new
+ function, register our evolution_storage.
+ (addressbook_storage_setup): remove storage registration from
+ here.
+ (load_source_data): register the storage here before we load
+ addressbook-sources.xml, and deregister it if there are no sources
+ listed.
+ (addressbook_storage_remove_source): unregister the storage if the
+ list of sources hits 0 length.
+
2001-07-18 Dan Winship <danw@ximian.com>
* backend/ebook/e-book.c (e_book_unload_uri): Flush the listener's
diff --git a/addressbook/gui/component/addressbook-storage.c b/addressbook/gui/component/addressbook-storage.c
index 531051defd..7ef8b74fcc 100644
--- a/addressbook/gui/component/addressbook-storage.c
+++ b/addressbook/gui/component/addressbook-storage.c
@@ -74,19 +74,21 @@
#define ADDRESSBOOK_SOURCES_XML "addressbook-sources.xml"
-static gboolean load_source_data (EvolutionStorage *storage, const char *file_path);
+static gboolean load_source_data (const char *file_path);
static gboolean save_source_data (const char *file_path);
+static void register_storage(void);
+static void deregister_storage(void);
-GList *sources;
-EvolutionStorage *storage;
+static GList *sources;
+static EvolutionStorage *storage;
static char *storage_path;
+static GNOME_Evolution_Shell corba_shell;
void
addressbook_storage_setup (EvolutionShellComponent *shell_component,
const char *evolution_homedir)
{
EvolutionShellClient *shell_client;
- GNOME_Evolution_Shell corba_shell;
shell_client = evolution_shell_component_get_owner (shell_component);
if (shell_client == CORBA_OBJECT_NIL) {
@@ -96,20 +98,53 @@ addressbook_storage_setup (EvolutionShellComponent *shell_component,
corba_shell = bonobo_object_corba_objref (BONOBO_OBJECT (shell_client));
- storage = evolution_storage_new (_("Other Contacts"), NULL, NULL);
- if (evolution_storage_register_on_shell (storage, corba_shell) != EVOLUTION_STORAGE_OK) {
- g_warning ("Cannot register storage");
- return;
- }
-
sources = NULL;
- gtk_object_set_data (GTK_OBJECT (shell_component), "e-storage", storage);
-
if (storage_path)
g_free (storage_path);
storage_path = g_strdup_printf ("%s/" ADDRESSBOOK_SOURCES_XML, evolution_homedir);
- load_source_data (storage, storage_path);
+ load_source_data (storage_path);
+}
+
+static void
+register_storage()
+{
+ EvolutionStorageResult result;
+
+ if (storage == NULL) {
+ storage = evolution_storage_new (_("Other Contacts"), NULL, NULL);
+ result = evolution_storage_register_on_shell (storage, corba_shell);
+ switch (result) {
+ case EVOLUTION_STORAGE_OK:
+ break;
+ case EVOLUTION_STORAGE_ERROR_GENERIC :
+ g_warning("register_storage: generic error");
+ break;
+ case EVOLUTION_STORAGE_ERROR_CORBA :
+ g_warning("register_storage: corba error");
+ break;
+ case EVOLUTION_STORAGE_ERROR_ALREADYREGISTERED :
+ g_warning("register_storage: already registered error");
+ break;
+ case EVOLUTION_STORAGE_ERROR_EXISTS :
+ g_warning("register_storage: already exists error");
+ break;
+ default:
+ g_warning("register_storage: other error");
+ break;
+ }
+ }
+}
+
+static void
+deregister_storage()
+{
+ if (evolution_storage_deregister_on_shell(storage, corba_shell) !=
+ EVOLUTION_STORAGE_OK) {
+ g_warning("couldn't deregister storage");
+ }
+
+ storage = NULL;
}
static char *
@@ -207,13 +242,14 @@ addressbook_storage_init_source_uri (AddressbookSource *source)
}
static gboolean
-load_source_data (EvolutionStorage *storage,
- const char *file_path)
+load_source_data (const char *file_path)
{
xmlDoc *doc;
xmlNode *root;
xmlNode *child;
+ register_storage();
+
tryagain:
doc = xmlParseFile (file_path);
if (doc == NULL) {
@@ -289,6 +325,10 @@ load_source_data (EvolutionStorage *storage,
g_free (path);
}
+ if (g_list_length(sources) == 0) {
+ deregister_storage();
+ }
+
xmlFreeDoc (doc);
return TRUE;
@@ -408,6 +448,7 @@ addressbook_storage_add_source (AddressbookSource *source)
sources = g_list_append (sources, source);
/* and then to the ui */
+ register_storage();
path = g_strdup_printf ("/%s", source->name);
evolution_storage_new_folder (storage, path, source->name, "contacts",
source->uri, source->description, FALSE);
@@ -443,6 +484,10 @@ addressbook_storage_remove_source (const char *name)
path = g_strdup_printf ("/%s", name);
evolution_storage_removed_folder (storage, path);
+ if (g_list_length(sources) == 0) {
+ deregister_storage();
+ }
+
g_free (path);
}
@@ -501,6 +546,7 @@ addressbook_storage_clear_sources ()
{
g_list_foreach (sources, (GFunc)addressbook_source_foreach, NULL);
g_list_free (sources);
+ deregister_storage();
sources = NULL;
}