From 5009d8d479665301efdec3beb784e252fa29527d Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Fri, 24 May 2002 10:32:16 +0000 Subject: [ #24189 ] ifdef out the body of this because it only works with a single 2002-05-24 Chris Toshok [ #24189 ] * gui/component/select-names/e-select-names-manager.c (focus_out_cb): ifdef out the body of this because it only works with a single completion book. not sure what to do here, but it doesn't impact most usage scenarios. (completion_popup_cb): same. (e_select_names_manager_entry_new): add the books that have been loaded successfully by the time this entry is created. (open_book_cb): add the opened book to the entries that have already been created, and store it in our list so that entries that are created in the future can catch up. (read_completion_books_from_db): slurp in the folder list from the config db and load all the uris. (uris_listener): listener function - when there's a change it calls _clear_books on all the created entries, and clears our list. It then re-reads the books from the db. (e_select_names_manager_new): create our bonobo listener and call read_completion_books_from_db. (e_select_names_manager_init): init completion_books. (e_select_names_manager_destroy): free our list of completion_books. * gui/component/select-names/e-select-names-manager.h: switch from a single EBook to a GList of completion_books here. * gui/component/select-names/e-select-names-completion.c (e_select_names_completion_add_book): deal with the case where there's an active query (by effectively restarting it.) This is quite a contrived edge case. (e_select_names_completion_clear_books): stop the current query and clear our list of books. (e_select_names_completion_new): track change to prototype, and axe the majority of this method since an EBook* isn't passed anymore. (e_select_names_completion_clear_book_data): split this code out from the destroy method so it can be called from _clear_books. * gui/component/select-names/e-select-names-completion.h: the constructor no longer takes an EBook -- pass in as many as you want using _add_book. Also, add prototype for _clear_books. * gui/component/addressbook.c (load_uri_cb): when storing/retrieving passwords, use the cleaned (without params) version of the uri, so changing things like download limit don't cause the user to be prompted for a password again. * gui/component/addressbook-component.c (ensure_completion_uris_exist): new function - probably doesn't belong in this file. Make sure the basic local Contacts folder exists in the completion uris. (addressbook_component_factory_init): call ensure_completion_uris_exist. * backend/ebook/e-book-util.h: add prototype for e_book_get_default_book_uri. * backend/ebook/e-book-util.c (e_book_get_default_book_uri): new function, just return the default contacts uri. (e_book_load_default_book): change to use e_book_get_default_book_uri. svn path=/trunk/; revision=16999 --- .../select-names/e-select-names-manager.c | 115 +++++++++++++++++---- 1 file changed, 94 insertions(+), 21 deletions(-) (limited to 'addressbook/gui/component/select-names/e-select-names-manager.c') diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c index 53978ac502..29de56cb1a 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -15,12 +15,14 @@ #include +#include #include "e-select-names-manager.h" #include "e-select-names-model.h" #include "e-select-names-text-model.h" #include "e-select-names.h" #include "e-select-names-completion.h" #include "e-select-names-popup.h" +#include "e-folder-list.h" #include #include #include @@ -51,6 +53,7 @@ typedef struct { EEntry *entry; ESelectNamesManager *manager; ESelectNamesModel *model; + ECompletion *comp; guint cleaning_tag; } ESelectNamesManagerEntry; @@ -175,6 +178,8 @@ focus_in_cb (GtkWidget *w, GdkEventFocus *ev, gpointer user_data) static gint focus_out_cb (GtkWidget *w, GdkEventFocus *ev, gpointer user_data) { +#if 0 + /* XXX fix me */ ESelectNamesManagerEntry *entry = user_data; gboolean visible = e_entry_completion_popup_is_visible (entry->entry); @@ -183,17 +188,20 @@ focus_out_cb (GtkWidget *w, GdkEventFocus *ev, gpointer user_data) if (entry->cleaning_tag == 0) entry->cleaning_tag = gtk_timeout_add (100, clean_cb, entry); } - +#endif return FALSE; } static void completion_popup_cb (EEntry *w, gint visible, gpointer user_data) { +#if 0 + /* XXX fix me */ ESelectNamesManagerEntry *entry = user_data; if (!visible && !GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (entry->entry->canvas))) e_select_names_model_cardify_all (entry->model, entry->manager->completion_book, 0); +#endif } static void @@ -232,7 +240,7 @@ e_select_names_manager_entry_new (ESelectNamesManager *manager, ESelectNamesMode { ESelectNamesManagerEntry *entry; ETextModel *text_model; - ECompletion *comp; + GList *l; g_return_val_if_fail (E_IS_SELECT_NAMES_MANAGER (manager), NULL); g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), NULL); @@ -252,13 +260,15 @@ e_select_names_manager_entry_new (ESelectNamesManager *manager, ESelectNamesMode gtk_object_ref (GTK_OBJECT (entry->entry)); - comp = e_select_names_completion_new (NULL, E_SELECT_NAMES_TEXT_MODEL (text_model)); - if (manager->completion_book) - e_select_names_completion_add_book (E_SELECT_NAMES_COMPLETION (comp), - manager->completion_book); + entry->comp = e_select_names_completion_new (E_SELECT_NAMES_TEXT_MODEL (text_model)); - e_entry_enable_completion_full (entry->entry, comp, 50, completion_handler); + for (l = manager->completion_books; l; l = l->next) { + EBook *book = l->data; + e_select_names_completion_add_book (E_SELECT_NAMES_COMPLETION(entry->comp), book); + } + e_entry_enable_completion_full (entry->entry, entry->comp, 50, completion_handler); + entry->manager = manager; entry->model = model; @@ -287,7 +297,7 @@ e_select_names_manager_entry_new (ESelectNamesManager *manager, ESelectNamesMode gtk_object_set_data (GTK_OBJECT (entry->entry), "entry_info", entry); gtk_object_set_data (GTK_OBJECT (entry->entry), "select_names_model", model); gtk_object_set_data (GTK_OBJECT (entry->entry), "select_names_text_model", text_model); - gtk_object_set_data (GTK_OBJECT (entry->entry), "completion_handler", comp); + gtk_object_set_data (GTK_OBJECT (entry->entry), "completion_handler", entry->comp); return entry; } @@ -359,14 +369,77 @@ e_select_names_manager_discard_saved_models (ESelectNamesManager *manager) static void open_book_cb (EBook *book, EBookStatus status, ESelectNamesManager *manager) { - if (status != E_BOOK_STATUS_SUCCESS) { + if (status == E_BOOK_STATUS_SUCCESS) { + GList *l; + for (l = manager->entries; l; l = l->next) { + ESelectNamesManagerEntry *entry = l->data; + e_select_names_completion_add_book (E_SELECT_NAMES_COMPLETION(entry->comp), book); + } + + manager->completion_books = g_list_append (manager->completion_books, book); + } + else { gtk_object_unref (GTK_OBJECT (book)); - manager->completion_book = NULL; } gtk_object_unref (GTK_OBJECT (manager)); /* unref ourself (matches ref before the load_uri call below) */ } +static void +read_completion_books_from_db (ESelectNamesManager *manager) +{ + Bonobo_ConfigDatabase db; + CORBA_Environment ev; + char *val; + + CORBA_exception_init (&ev); + + db = addressbook_config_database (&ev); + + val = bonobo_config_get_string (db, "/Addressbook/Completion/uris", &ev); + + CORBA_exception_free (&ev); + + if (val) { + EFolderListItem *folders = e_folder_list_parse_xml (val); + EFolderListItem *f; + + for (f = folders; f && f->physical_uri; f++) { + char *uri; + EBook *book = e_book_new (); + gtk_object_ref (GTK_OBJECT (manager)); /* ref ourself before our async call */ + + if (!strncmp (f->physical_uri, "file:", 5)) + uri = g_strdup_printf ("%s/addressbook.db", f->physical_uri); + else + uri = g_strdup (f->physical_uri); + addressbook_load_uri (book, uri, (EBookCallback)open_book_cb, manager); + } + e_folder_list_free_items (folders); + + g_free (val); + } +} + +static void +uris_listener (BonoboListener *listener, char *event_name, + CORBA_any *any, CORBA_Environment *ev, + gpointer user_data) +{ + ESelectNamesManager *manager = E_SELECT_NAMES_MANAGER (user_data); + GList *l; + for (l = manager->entries; l; l = l->next) { + ESelectNamesManagerEntry *entry = l->data; + e_select_names_completion_clear_books (E_SELECT_NAMES_COMPLETION (entry->comp)); + } + + g_list_foreach (manager->completion_books, (GFunc)gtk_object_unref, NULL); + g_list_free (manager->completion_books); + manager->completion_books = NULL; + + read_completion_books_from_db (manager); +} + /** * e_select_names_manager_new: * @VCard: a string in vCard format @@ -379,24 +452,19 @@ e_select_names_manager_new (void) ESelectNamesManager *manager = E_SELECT_NAMES_MANAGER(gtk_type_new(e_select_names_manager_get_type())); Bonobo_ConfigDatabase db; CORBA_Environment ev; - char *val; CORBA_exception_init (&ev); db = addressbook_config_database (&ev); - val = bonobo_config_get_string (db, "/Addressbook/Completion/uri", &ev); - CORBA_exception_free (&ev); - if (val) { - manager->completion_book = e_book_new (); - gtk_object_ref (GTK_OBJECT (manager)); /* ref ourself before our async call */ - addressbook_load_uri (manager->completion_book, val, (EBookCallback)open_book_cb, manager); - g_free (val); - } - else - manager->completion_book = NULL; + bonobo_event_source_client_add_listener (db, uris_listener, + "Bonobo/ConfigDatabase:change/Addressbook/Completion:", + NULL, + manager); + + read_completion_books_from_db (manager); return manager; } @@ -550,6 +618,7 @@ e_select_names_manager_init (ESelectNamesManager *manager) { manager->sections = NULL; manager->entries = NULL; + manager->completion_books = NULL; } static void @@ -571,6 +640,10 @@ e_select_names_manager_destroy (GtkObject *object) g_list_foreach (manager->entries, (GFunc) e_select_names_manager_entry_free, NULL); g_list_free (manager->entries); manager->entries = NULL; + + g_list_foreach (manager->completion_books, (GFunc) gtk_object_unref, NULL); + g_list_free (manager->completion_books); + manager->completion_books = NULL; } static void -- cgit v1.2.3