From 2ca2244e6b47fa020ba10bcfb6836033ddfc3cc8 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Wed, 5 Jul 2000 20:07:46 +0000 Subject: call e_ldap_storage_add_server call. 2000-07-05 Chris Toshok * gui/component/addressbook.c (new_server_cb): call e_ldap_storage_add_server call. * gui/component/ldap-server-dialog.glade: add name row. * gui/component/e-ldap-server-dialog.h: remove the ELDAPServer type. * gui/component/e-ldap-server-dialog.c (extract_server_info): add support for the name-entry. * gui/component/e-ldap-server-dialog.c (fill_in_server_info): same. * gui/component/e-ldap-storage.h: add ELDAPServer type, and add prototypes for e_ldap_storage_add_server and e_ldap_storage_remove_server. * gui/component/e-ldap-storage.c (e_ldap_storage_add_server): new function, add it to our hash table, add a shell folder, and save out the metadata. (ldap_server_foreach): add the ldap server info under a "contactserver" node. (setup_ldap_storage): create our hashtable. svn path=/trunk/; revision=3895 --- addressbook/ChangeLog | 25 ++++ addressbook/gui/component/addressbook.c | 24 ++- addressbook/gui/component/e-ldap-server-dialog.c | 19 ++- addressbook/gui/component/e-ldap-server-dialog.h | 7 +- addressbook/gui/component/e-ldap-storage.c | 58 ++++++-- addressbook/gui/component/e-ldap-storage.h | 11 ++ addressbook/gui/component/ldap-server-dialog.glade | 165 +++++++++++++-------- .../gui/component/ldap-server-dialog.glade.h | 1 + 8 files changed, 216 insertions(+), 94 deletions(-) diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index ca76381f8e..ad019beb68 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,28 @@ +2000-07-05 Chris Toshok + + * gui/component/addressbook.c (new_server_cb): call + e_ldap_storage_add_server call. + + * gui/component/ldap-server-dialog.glade: add name row. + + * gui/component/e-ldap-server-dialog.h: remove the ELDAPServer type. + + * gui/component/e-ldap-server-dialog.c (extract_server_info): add + support for the name-entry. + + * gui/component/e-ldap-server-dialog.c (fill_in_server_info): same. + + * gui/component/e-ldap-storage.h: add ELDAPServer type, and add + prototypes for e_ldap_storage_add_server and + e_ldap_storage_remove_server. + + * gui/component/e-ldap-storage.c (e_ldap_storage_add_server): new + function, add it to our hash table, add a shell folder, and save + out the metadata. + (ldap_server_foreach): add the ldap server info under a + "contactserver" node. + (setup_ldap_storage): create our hashtable. + 2000-07-05 Chris Toshok * gui/component/addressbook.c (set_prop): remove hack to read diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 97cdb04b53..f248e1e4bd 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -186,19 +186,19 @@ null_cb (EBook *book, EBookStatus status, gpointer closure) static void new_server_cb (BonoboUIHandler *uih, void *user_data, const char *path) { - ELDAPServer server; - char *uri; + ELDAPServer *server = g_new (ELDAPServer, 1); EBook *book; AddressbookView *view = (AddressbookView *) user_data; GtkObject *object; /* fill in the defaults */ - server.host = g_strdup(""); - server.port = 389; - server.description = g_strdup(""); - server.rootdn = g_strdup(""); - - e_ldap_server_editor_show (&server); + server->name = g_strdup(""); + server->host = g_strdup(""); + server->port = 389; + server->description = g_strdup(""); + server->rootdn = g_strdup(""); + server->uri = g_strdup_printf ("ldap://%s:%d/%s", server->host, server->port, server->rootdn); + e_ldap_server_editor_show (server); if (view->view) object = GTK_OBJECT(view->view); @@ -207,14 +207,12 @@ new_server_cb (BonoboUIHandler *uih, void *user_data, const char *path) gtk_object_get(object, "book", &book, NULL); g_assert (E_IS_BOOK (book)); - /* XXX write out the new server info */ + /* write out the new server info */ + e_ldap_storage_add_server (server); /* now update the view */ - uri = g_strdup_printf ("ldap://%s:%d/%s", server.host, server.port, server.rootdn); - e_book_unload_uri (book); - - if (! e_book_load_uri (book, uri, null_cb, NULL)) { + if (! e_book_load_uri (book, server->uri, null_cb, NULL)) { g_warning ("error calling load_uri!\n"); } } diff --git a/addressbook/gui/component/e-ldap-server-dialog.c b/addressbook/gui/component/e-ldap-server-dialog.c index d64549cc2d..2242282f3f 100644 --- a/addressbook/gui/component/e-ldap-server-dialog.c +++ b/addressbook/gui/component/e-ldap-server-dialog.c @@ -39,6 +39,12 @@ fill_in_server_info (ELDAPServerDialog *dialog) int position; char buf[128]; + /* the name */ + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(dialog->gui, "name-entry")); + gtk_editable_delete_text (editable, 0, -1); + gtk_editable_insert_text (editable, ldap_server->name, strlen (ldap_server->name), &position); + /* the server description */ position = 0; editable = GTK_EDITABLE(glade_xml_get_widget(dialog->gui, "description-entry")); @@ -70,7 +76,16 @@ extract_server_info (ELDAPServerDialog *dialog) { ELDAPServer *ldap_server = dialog->server; GtkEditable *editable; - char *description, *server, *port, *rootdn; + char *description, *server, *port, *rootdn, *name; + + /* the server name */ + editable = GTK_EDITABLE(glade_xml_get_widget(dialog->gui, "name-entry")); + name = gtk_editable_get_chars(editable, 0, -1); + if (name && *name) { + if (ldap_server->name) + g_free(ldap_server->name); + ldap_server->name = name; + } /* the server description */ editable = GTK_EDITABLE(glade_xml_get_widget(dialog->gui, "description-entry")); @@ -111,7 +126,7 @@ extract_server_info (ELDAPServerDialog *dialog) void e_ldap_server_editor_show(ELDAPServer *server) { - ELDAPServerDialog *dialog = g_new0(ELDAPServerDialog, 1); + ELDAPServerDialog *dialog = g_new0 (ELDAPServerDialog, 1); dialog->server = server; dialog->gui = glade_xml_new (EVOLUTION_GLADEDIR "/ldap-server-dialog.glade", NULL); diff --git a/addressbook/gui/component/e-ldap-server-dialog.h b/addressbook/gui/component/e-ldap-server-dialog.h index f0e73d1ebc..e5ae169f5c 100644 --- a/addressbook/gui/component/e-ldap-server-dialog.h +++ b/addressbook/gui/component/e-ldap-server-dialog.h @@ -2,12 +2,7 @@ #ifndef __E_LDAP_SERVER_DIALOG_H__ #define __E_LDAP_SERVER_DIALOG_H__ -typedef struct { - char *description; - char *host; - int port; - char *rootdn; -} ELDAPServer; +#include "e-ldap-storage.h" void e_ldap_server_editor_show(ELDAPServer *server); diff --git a/addressbook/gui/component/e-ldap-storage.c b/addressbook/gui/component/e-ldap-storage.c index e3663452bc..ab3fc21fdb 100644 --- a/addressbook/gui/component/e-ldap-storage.c +++ b/addressbook/gui/component/e-ldap-storage.c @@ -60,13 +60,13 @@ static gboolean load_ldap_data (EvolutionStorage *storage, const char *file_path static gboolean save_ldap_data (const char *file_path); GHashTable *servers; +EvolutionStorage *storage; 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); @@ -84,6 +84,8 @@ setup_ldap_storage (EvolutionShellComponent *shell_component) } /* save the storage for later */ + servers = g_hash_table_new (g_str_hash, g_str_equal); + gtk_object_set_data (GTK_OBJECT (shell_component), "e-storage", storage); path = g_strdup_printf ("%s/evolution/" LDAPSERVER_XML, g_get_home_dir()); @@ -135,26 +137,25 @@ load_ldap_data (EvolutionStorage *storage, for (child = root->childs; child; child = child->next) { char *path; - char *name; - char *uri; - char *description; + ELDAPServer *server; 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"); + server = g_new (ELDAPServer, 1); + + server->name = get_string_value (child, "name"); + server->uri = get_string_value (child, "uri"); + server->description = get_string_value (child, "description"); + + path = g_strdup_printf ("/%s", server->name); + evolution_storage_new_folder (storage, path, "contacts", server->uri, server->description); - path = g_strdup_printf ("/%s", name); - evolution_storage_new_folder (storage, path, "contacts", uri, description); + g_hash_table_insert (servers, server->name, server); g_free (path); - g_free (name); - g_free (uri); - g_free (description); } xmlFreeDoc (doc); @@ -167,15 +168,19 @@ ldap_server_foreach(gpointer key, gpointer value, gpointer user_data) { ELDAPServer *server = (ELDAPServer*)value; xmlNode *root = (xmlNode*)user_data; + xmlNode *server_root = xmlNewDocNode (root, NULL, + (xmlChar *) "contactserver", NULL); - xmlNewChild (root, NULL, (xmlChar *) "name", + xmlAddChild (root, server_root); + + xmlNewChild (server_root, NULL, (xmlChar *) "name", (xmlChar *) server->name); - xmlNewChild (root, NULL, (xmlChar *) "uri", + xmlNewChild (server_root, NULL, (xmlChar *) "uri", (xmlChar *) server->uri); if (server->description) - xmlNewChild (root, NULL, (xmlChar *) "description", + xmlNewChild (server_root, NULL, (xmlChar *) "description", (xmlChar *) server->description); } @@ -200,3 +205,26 @@ save_ldap_data (const char *file_path) xmlFreeDoc (doc); return TRUE; } + +void +e_ldap_storage_add_server (ELDAPServer *server) +{ + char *path; + /* add it to our hashtable */ + g_hash_table_insert (servers, server->name, server); + + /* and then to the ui */ + path = g_strdup_printf ("/%s", server->name); + evolution_storage_new_folder (storage, path, "contacts", server->uri, server->description); + + g_free (path); + + path = g_strdup_printf ("%s/evolution/" LDAPSERVER_XML, g_get_home_dir()); + save_ldap_data (path); + g_free (path); +} + +void +e_ldap_storage_remove_server (char *name) +{ +} diff --git a/addressbook/gui/component/e-ldap-storage.h b/addressbook/gui/component/e-ldap-storage.h index c91a060dca..cf11e9a6fb 100644 --- a/addressbook/gui/component/e-ldap-storage.h +++ b/addressbook/gui/component/e-ldap-storage.h @@ -26,6 +26,17 @@ #include "evolution-shell-component.h" +typedef struct { + char *name; + char *description; + char *host; + int port; + char *rootdn; + char *uri; +} ELDAPServer; + void setup_ldap_storage (EvolutionShellComponent *shell_component); +void e_ldap_storage_add_server (ELDAPServer *server); +void e_ldap_storage_remove_server (char *name); #endif /* __E_LDAP_STORAGE_H__ */ diff --git a/addressbook/gui/component/ldap-server-dialog.glade b/addressbook/gui/component/ldap-server-dialog.glade index 71090f53dd..a4dad9c2c2 100644 --- a/addressbook/gui/component/ldap-server-dialog.glade +++ b/addressbook/gui/component/ldap-server-dialog.glade @@ -10,17 +10,7 @@ C True True - False False - True - True - True - interface.c - interface.h - callbacks.c - callbacks.h - support.c - support.h True ldap-server-dialog.glade.h @@ -49,6 +39,40 @@ True + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button1 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button3 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + GtkVBox vbox1 @@ -63,7 +87,7 @@ GtkTable table2 - 4 + 5 2 False 0 @@ -85,8 +109,8 @@ 1 2 - 0 - 1 + 1 + 2 0 0 True @@ -109,8 +133,8 @@ 1 2 - 1 - 2 + 2 + 3 0 0 True @@ -133,8 +157,8 @@ 1 2 - 2 - 3 + 3 + 4 0 0 True @@ -157,8 +181,8 @@ 1 2 - 3 - 4 + 4 + 5 0 0 True @@ -180,8 +204,8 @@ 0 1 - 0 - 1 + 1 + 2 0 0 True @@ -215,8 +239,8 @@ 0 1 - 1 - 2 + 2 + 3 0 0 False @@ -250,8 +274,8 @@ 0 1 - 2 - 3 + 3 + 4 0 0 False @@ -285,8 +309,8 @@ 0 1 - 3 - 4 + 4 + 5 0 0 False @@ -309,40 +333,65 @@ 0 - - - - GtkHButtonBox - GnomeDialog:action_area - dialog-action_area1 - GTK_BUTTONBOX_END - 8 - 85 - 27 - 7 - 0 - - 0 - False - True - GTK_PACK_END - + + GtkEntry + name-entry + True + True + True + 0 + + + 1 + 2 + 0 + 1 + 0 + 0 + True + False + False + False + True + False + + - - GtkButton - button1 - True - True - GNOME_STOCK_BUTTON_OK - + + GtkAlignment + alignment5 + 0 + 0.5 + 1 + 1 + + 0 + 1 + 0 + 1 + 0 + 0 + False + False + False + False + True + True + - - GtkButton - button3 - True - True - GNOME_STOCK_BUTTON_CANCEL + + GtkLabel + label5 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + diff --git a/addressbook/gui/component/ldap-server-dialog.glade.h b/addressbook/gui/component/ldap-server-dialog.glade.h index 68b45bdb34..c99dfa3cb5 100644 --- a/addressbook/gui/component/ldap-server-dialog.glade.h +++ b/addressbook/gui/component/ldap-server-dialog.glade.h @@ -8,3 +8,4 @@ gchar *s = N_("Description:"); gchar *s = N_("LDAP Server:"); gchar *s = N_("Port Number:"); gchar *s = N_("Root DN:"); +gchar *s = N_("Name:"); -- cgit v1.2.3