aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r--addressbook/gui/component/addressbook-component.c48
-rw-r--r--addressbook/gui/component/addressbook.c11
-rw-r--r--addressbook/gui/component/select-names/e-select-names-completion.c54
-rw-r--r--addressbook/gui/component/select-names/e-select-names-completion.h3
-rw-r--r--addressbook/gui/component/select-names/e-select-names-manager.c115
-rw-r--r--addressbook/gui/component/select-names/e-select-names-manager.h2
6 files changed, 183 insertions, 50 deletions
diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c
index 54940faeab..ed135f98db 100644
--- a/addressbook/gui/component/addressbook-component.c
+++ b/addressbook/gui/component/addressbook-component.c
@@ -39,6 +39,7 @@
#include "evolution-shell-component.h"
#include "evolution-shell-component-dnd.h"
#include "evolution-storage.h"
+#include "e-folder-list.h"
#include "ebook/e-book.h"
#include "ebook/e-card.h"
@@ -590,6 +591,48 @@ create_component (void)
return BONOBO_OBJECT (shell_component);
}
+static void
+ensure_completion_uris_exist()
+{
+ /* Initialize the completion uris if they aren't set yet. The
+ default set is just the local Contacts folder. */
+ 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);
+
+ if (!val) {
+ EFolderListItem f[2];
+ char *dirname, *uri;
+ /* in the case where the user is running for the first
+ time, populate the list with the local contact
+ folder */
+ dirname = gnome_util_prepend_user_home("evolution/local/Contacts");
+ uri = g_strdup_printf ("file://%s", dirname);
+
+ f[0].uri = "evolution:/local/Contacts";
+ f[0].physical_uri = uri;
+ f[0].display_name = _("Contacts");
+
+ memset (&f[1], 0, sizeof (f[1]));
+
+ val = e_folder_list_create_xml (f);
+
+ g_free (dirname);
+ g_free (uri);
+ bonobo_config_set_string (db, "/Addressbook/Completion/uris", val, &ev);
+
+ g_free (val);
+ }
+
+ CORBA_exception_free (&ev);
+}
+
/* FIXME this should probably be renamed as we don't use factories anymore. */
void
@@ -606,4 +649,9 @@ addressbook_component_factory_init (void)
bonobo_object_corba_objref (object));
if (result == OAF_REG_ERROR)
g_error ("Cannot register -- %s", GNOME_EVOLUTION_ADDRESSBOOK_COMPONENT_ID);
+
+ /* XXX this could probably go someplace else, but I'll leave
+ it here for now since it's a component init time
+ operation. */
+ ensure_completion_uris_exist ();
}
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index b74b946098..8c585917d4 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -632,8 +632,13 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
source->auth != ADDRESSBOOK_LDAP_AUTH_NONE) {
const char *password;
char *pass_dup = NULL;
+ char *uri = g_strdup (e_book_get_uri (book));
+ char *semicolon = strchr (uri, ';');
- password = e_passwords_get_password (e_book_get_uri (book));
+ if (semicolon)
+ *semicolon = '\0';
+
+ password = e_passwords_get_password (uri);
if (!password) {
char *prompt;
@@ -647,7 +652,7 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
source->name, source->email_addr);
remember = source->remember_passwd;
pass_dup = e_passwords_ask_password (
- prompt, e_book_get_uri (book), prompt, TRUE,
+ prompt, uri, prompt, TRUE,
E_PASSWORDS_REMEMBER_FOREVER, &remember,
NULL);
if (remember != source->remember_passwd) {
@@ -657,6 +662,8 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
g_free (prompt);
}
+ g_free (uri);
+
if (password || pass_dup) {
char *user;
diff --git a/addressbook/gui/component/select-names/e-select-names-completion.c b/addressbook/gui/component/select-names/e-select-names-completion.c
index cbfc1d56c6..7b29cd2472 100644
--- a/addressbook/gui/component/select-names/e-select-names-completion.c
+++ b/addressbook/gui/component/select-names/e-select-names-completion.c
@@ -734,14 +734,10 @@ e_select_names_completion_init (ESelectNamesCompletion *comp)
}
static void
-e_select_names_completion_destroy (GtkObject *object)
+e_select_names_completion_clear_book_data (ESelectNamesCompletion *comp)
{
- ESelectNamesCompletion *comp = E_SELECT_NAMES_COMPLETION (object);
GList *l;
- if (comp->priv->text_model)
- gtk_object_unref (GTK_OBJECT (comp->priv->text_model));
-
for (l = comp->priv->book_data; l; l = l->next) {
ESelectNamesCompletionBookData *book_data = l->data;
@@ -763,6 +759,17 @@ e_select_names_completion_destroy (GtkObject *object)
g_free (book_data);
}
g_list_free (comp->priv->book_data);
+}
+
+static void
+e_select_names_completion_destroy (GtkObject *object)
+{
+ ESelectNamesCompletion *comp = E_SELECT_NAMES_COMPLETION (object);
+
+ if (comp->priv->text_model)
+ gtk_object_unref (GTK_OBJECT (comp->priv->text_model));
+
+ e_select_names_completion_clear_book_data (comp);
g_free (comp->priv->waiting_query);
g_free (comp->priv->query_text);
@@ -1227,33 +1234,14 @@ e_select_names_completion_book_ready (EBook *book, EBookStatus status, ESelectNa
*/
ECompletion *
-e_select_names_completion_new (EBook *book, ESelectNamesTextModel *text_model)
+e_select_names_completion_new (ESelectNamesTextModel *text_model)
{
ESelectNamesCompletion *comp;
- g_return_val_if_fail (book == NULL || E_IS_BOOK (book), NULL);
g_return_val_if_fail (E_IS_SELECT_NAMES_TEXT_MODEL (text_model), NULL);
comp = (ESelectNamesCompletion *) gtk_type_new (e_select_names_completion_get_type ());
- if (book == NULL) {
- ESelectNamesCompletionBookData *book_data = g_new0 (ESelectNamesCompletionBookData, 1);
-
- book_data->book = e_book_new ();
- book_data->comp = comp;
- gtk_object_ref (GTK_OBJECT (book_data->book));
- gtk_object_sink (GTK_OBJECT (book_data->book));
-
- comp->priv->book_data = g_list_append (comp->priv->book_data, book_data);
- comp->priv->books_not_ready++;
-
- gtk_object_ref (GTK_OBJECT (comp)); /* ref ourself before our async call */
- e_book_load_local_address_book (book_data->book, (EBookCallback) e_select_names_completion_book_ready, comp);
-
- } else {
- e_select_names_completion_add_book (comp, book);
- }
-
comp->priv->text_model = text_model;
gtk_object_ref (GTK_OBJECT (text_model));
@@ -1273,6 +1261,22 @@ e_select_names_completion_add_book (ESelectNamesCompletion *comp, EBook *book)
check_capabilities (comp, book);
gtk_object_ref (GTK_OBJECT (book_data->book));
comp->priv->book_data = g_list_append (comp->priv->book_data, book_data);
+
+ /* if the user is typing as we're adding books, restart the
+ query after the new book has been added */
+ if (comp->priv->query_text && *comp->priv->query_text) {
+ char *query_text = g_strdup (comp->priv->query_text);
+ e_select_names_completion_stop_query (comp);
+ e_select_names_completion_start_query (comp, query_text);
+ g_free (query_text);
+ }
+}
+
+void
+e_select_names_completion_clear_books (ESelectNamesCompletion *comp)
+{
+ e_select_names_completion_stop_query (comp);
+ e_select_names_completion_clear_book_data (comp);
}
gboolean
diff --git a/addressbook/gui/component/select-names/e-select-names-completion.h b/addressbook/gui/component/select-names/e-select-names-completion.h
index 86522fa5ce..ae5a8db471 100644
--- a/addressbook/gui/component/select-names/e-select-names-completion.h
+++ b/addressbook/gui/component/select-names/e-select-names-completion.h
@@ -56,8 +56,9 @@ struct _ESelectNamesCompletionClass {
GtkType e_select_names_completion_get_type (void);
-ECompletion *e_select_names_completion_new (EBook *, ESelectNamesTextModel *);
+ECompletion *e_select_names_completion_new (ESelectNamesTextModel *);
void e_select_names_completion_add_book (ESelectNamesCompletion *, EBook *);
+void e_select_names_completion_clear_books (ESelectNamesCompletion *);
gboolean e_select_names_completion_get_match_contact_lists (ESelectNamesCompletion *);
void e_select_names_completion_set_match_contact_lists (ESelectNamesCompletion *, gboolean);
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 <gal/e-text/e-entry.h>
+#include <libgnome/gnome-i18n.h>
#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 <addressbook/backend/ebook/e-destination.h>
#include <addressbook/gui/component/addressbook.h>
#include <bonobo-conf/bonobo-config-database.h>
@@ -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
diff --git a/addressbook/gui/component/select-names/e-select-names-manager.h b/addressbook/gui/component/select-names/e-select-names-manager.h
index 9fdad2c304..30b4be35a4 100644
--- a/addressbook/gui/component/select-names/e-select-names-manager.h
+++ b/addressbook/gui/component/select-names/e-select-names-manager.h
@@ -32,7 +32,7 @@ struct _ESelectNamesManager {
ESelectNames *names;
- EBook *completion_book;
+ GList *completion_books;
};
struct _ESelectNamesManagerClass {