aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addressbook/ChangeLog18
-rw-r--r--addressbook/gui/component/Makefile.am4
-rw-r--r--addressbook/gui/component/addressbook-component.c8
-rw-r--r--addressbook/gui/component/addressbook.c13
-rw-r--r--addressbook/gui/component/e-ldap-storage.c202
-rw-r--r--addressbook/gui/component/e-ldap-storage.h31
6 files changed, 267 insertions, 9 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 22bf73dcab..ca76381f8e 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,21 @@
+2000-07-05 Chris Toshok <toshok@helixcode.com>
+
+ * gui/component/addressbook.c (set_prop): remove hack to read
+ "uri" file from local directory.
+
+ * gui/component/Makefile.am (evolution_addressbook_SOURCES): add
+ e-ldap-storage.{c,h}
+
+ * gui/component/addressbook-component.c (owner_set_cb): call
+ setup_ldap_storage.
+
+ * gui/component/e-ldap-storage.c (setup_ldap_storage): Register
+ the LDAP storage and load the .xml file.
+ (load_ldap_data): function to load our xml file.
+ (save_ldap_data): function to save our xml file.
+
+ * gui/component/e-ldap-storage.h: new file.
+
2000-07-03 Christopher James Lahey <clahey@helixcode.com>
* gui/component/select-names/e-select-names-manager.c,
diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am
index f4776e3dd1..389f51f9ba 100644
--- a/addressbook/gui/component/Makefile.am
+++ b/addressbook/gui/component/Makefile.am
@@ -38,7 +38,9 @@ evolution_addressbook_SOURCES = \
e-cardlist-model.c \
e-cardlist-model.h \
e-ldap-server-dialog.c \
- e-ldap-server-dialog.h
+ e-ldap-server-dialog.h \
+ e-ldap-storage.c \
+ e-ldap-storage.h
evolution_addressbook_LDADD = \
select-names/libeselectnames.la \
diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c
index 8469967e7c..b6b682d18d 100644
--- a/addressbook/gui/component/addressbook-component.c
+++ b/addressbook/gui/component/addressbook-component.c
@@ -32,6 +32,7 @@
#include "addressbook-component.h"
#include "addressbook.h"
+#include "e-ldap-storage.h"
#ifdef USING_OAF
@@ -47,6 +48,10 @@ static const EvolutionShellComponentFolderType folder_types[] = {
{ NULL, NULL }
};
+#ifdef HAVE_LDAP
+extern void setup_ldap_storage (EvolutionShellComponent *shell_component);
+#endif
+
/* EvolutionShellComponent methods and signals. */
@@ -78,6 +83,8 @@ owner_set_cb (EvolutionShellComponent *shell_component,
gpointer user_data)
{
owner_count ++;
+
+ setup_ldap_storage (shell_component);
}
static void
@@ -122,3 +129,4 @@ addressbook_component_factory_init (void)
if (factory == NULL)
g_error ("Cannot initialize the Evolution addressbook factory.");
}
+
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index 710a3b756d..97cdb04b53 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -706,7 +706,6 @@ set_prop (BonoboPropertyBag *bag,
{
AddressbookView *view = user_data;
- char *uri_file;
char *uri_data;
switch (arg_id) {
@@ -720,21 +719,19 @@ set_prop (BonoboPropertyBag *bag,
view->uri = g_strdup(BONOBO_ARG_GET_STRING (arg));
- uri_file = g_concat_dir_and_file(view->uri + 7, "uri");
-
- uri_data = e_read_file(uri_file);
-
- if (!uri_data) {
+ if (!strncmp (view->uri, "file:", 5)) {
char *file_name = g_concat_dir_and_file(view->uri + 7, "addressbook.db");
uri_data = g_strdup_printf("file://%s", file_name);
g_free(file_name);
}
+ else {
+ uri_data = g_strdup (view->uri);
+ }
+
if (! e_book_load_uri (view->book, uri_data, book_open_cb, view))
printf ("error calling load_uri!\n");
-
g_free(uri_data);
- g_free(uri_file);
break;
diff --git a/addressbook/gui/component/e-ldap-storage.c b/addressbook/gui/component/e-ldap-storage.c
new file mode 100644
index 0000000000..e3663452bc
--- /dev/null
+++ b/addressbook/gui/component/e-ldap-storage.c
@@ -0,0 +1,202 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-ldap-storage.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: Chris Toshok
+ */
+
+/* The ldap server file goes like this:
+
+ <?xml version="1.0"?>
+ <contactservers>
+ <contactserver>
+ <name>LDAP Server</name>
+ <description>This is my company address book.</description>
+ <uri>ldap://ldap.somewhere.net/</uri>
+ </contactserver>
+ </contactservers>
+
+ FIXME: Do we want to use a namespace for this?
+ FIXME: Do we want to have an internationalized description?
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo.h>
+
+#include "evolution-shell-component.h"
+#include "evolution-storage.h"
+
+#include <gnome-xml/parser.h>
+#include <gnome-xml/xmlmemory.h>
+
+#include "e-ldap-storage.h"
+#include "e-ldap-server-dialog.h"
+
+#include "e-util/e-util.h"
+#include "e-util/e-xml-utils.h"
+
+#define LDAPSERVER_XML "ldapservers.xml"
+
+static gboolean load_ldap_data (EvolutionStorage *storage, const char *file_path);
+static gboolean save_ldap_data (const char *file_path);
+
+GHashTable *servers;
+
+void
+setup_ldap_storage (EvolutionShellComponent *shell_component)
+{
+ EvolutionShellClient *shell_client;
+ Evolution_Shell corba_shell;
+ EvolutionStorage *storage;
+ char *path;
+
+ shell_client = evolution_shell_component_get_owner (shell_component);
+ if (shell_client == CORBA_OBJECT_NIL) {
+ g_warning ("We have no shell!?");
+ return;
+ }
+
+ corba_shell = bonobo_object_corba_objref (BONOBO_OBJECT (shell_client));
+
+ storage = evolution_storage_new (_("External Directories"));
+ if (evolution_storage_register_on_shell (storage, corba_shell) != EVOLUTION_STORAGE_OK) {
+ g_warning ("Cannot register storage");
+ return;
+ }
+
+ /* save the storage for later */
+ gtk_object_set_data (GTK_OBJECT (shell_component), "e-storage", storage);
+
+ path = g_strdup_printf ("%s/evolution/" LDAPSERVER_XML, g_get_home_dir());
+ load_ldap_data (storage, path);
+ g_free (path);
+}
+
+static char *
+get_string_value (xmlNode *node,
+ const char *name)
+{
+ xmlNode *p;
+ xmlChar *xml_string;
+ char *retval;
+
+ p = e_xml_get_child_by_name (node, (xmlChar *) name);
+ if (p == NULL)
+ return NULL;
+
+ p = e_xml_get_child_by_name (p, (xmlChar *) "text");
+ if (p == NULL)
+ return NULL;
+
+ xml_string = xmlNodeListGetString (node->doc, p, 1);
+ retval = g_strdup ((char *) xml_string);
+ xmlFree (xml_string);
+
+ return retval;
+}
+
+static gboolean
+load_ldap_data (EvolutionStorage *storage,
+ const char *file_path)
+{
+ xmlDoc *doc;
+ xmlNode *root;
+ xmlNode *child;
+
+ doc = xmlParseFile (file_path);
+ if (doc == NULL) {
+ return FALSE;
+ }
+
+ root = xmlDocGetRootElement (doc);
+ if (root == NULL || strcmp (root->name, "contactservers") != 0) {
+ xmlFreeDoc (doc);
+ return FALSE;
+ }
+
+ for (child = root->childs; child; child = child->next) {
+ char *path;
+ char *name;
+ char *uri;
+ char *description;
+
+ if (strcmp (child->name, "contactserver")) {
+ g_warning ("unknown node '%s' in %s", child->name, file_path);
+ continue;
+ }
+
+ name = get_string_value (child, "name");
+ uri = get_string_value (child, "uri");
+ description = get_string_value (child, "description");
+
+ path = g_strdup_printf ("/%s", name);
+ evolution_storage_new_folder (storage, path, "contacts", uri, description);
+
+ g_free (path);
+ g_free (name);
+ g_free (uri);
+ g_free (description);
+ }
+
+ xmlFreeDoc (doc);
+
+ return TRUE;
+}
+
+static void
+ldap_server_foreach(gpointer key, gpointer value, gpointer user_data)
+{
+ ELDAPServer *server = (ELDAPServer*)value;
+ xmlNode *root = (xmlNode*)user_data;
+
+ xmlNewChild (root, NULL, (xmlChar *) "name",
+ (xmlChar *) server->name);
+
+ xmlNewChild (root, NULL, (xmlChar *) "uri",
+ (xmlChar *) server->uri);
+
+ if (server->description)
+ xmlNewChild (root, NULL, (xmlChar *) "description",
+ (xmlChar *) server->description);
+}
+
+static gboolean
+save_ldap_data (const char *file_path)
+{
+ xmlDoc *doc;
+ xmlNode *root;
+
+ doc = xmlNewDoc ((xmlChar *) "1.0");
+ root = xmlNewDocNode (doc, NULL, (xmlChar *) "contactservers", NULL);
+ xmlDocSetRootElement (doc, root);
+
+ g_hash_table_foreach (servers, ldap_server_foreach, root);
+
+ if (xmlSaveFile (file_path, doc) < 0) {
+ unlink (file_path);
+ xmlFreeDoc (doc);
+ return FALSE;
+ }
+
+ xmlFreeDoc (doc);
+ return TRUE;
+}
diff --git a/addressbook/gui/component/e-ldap-storage.h b/addressbook/gui/component/e-ldap-storage.h
new file mode 100644
index 0000000000..c91a060dca
--- /dev/null
+++ b/addressbook/gui/component/e-ldap-storage.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-ldap-storage.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: Chris Toshok
+ */
+
+#ifndef __E_LDAP_STORAGE_H__
+#define __E_LDAP_STORAGE_H__
+
+#include "evolution-shell-component.h"
+
+void setup_ldap_storage (EvolutionShellComponent *shell_component);
+
+#endif /* __E_LDAP_STORAGE_H__ */