aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component/e-address-widget.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-03-16 16:16:29 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-03-16 16:16:29 +0800
commit57de6972c845dbae49717a4520aeed75f88f0078 (patch)
treef58e45cdbb09793d8a09506af00c70b1ca63a389 /addressbook/gui/component/e-address-widget.c
parent403205b15e9f14472711ee115cae17031eb4ce7b (diff)
downloadgsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar.gz
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar.bz2
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar.lz
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar.xz
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.tar.zst
gsoc2013-evolution-57de6972c845dbae49717a4520aeed75f88f0078.zip
Added addressbook querying and "cardification" functions, which are turned
2001-03-15 Jon Trowbridge <trow@ximian.com> * gui/component/e-address-widget.c: Added addressbook querying and "cardification" functions, which are turned off by default for now because of addressbook bugs. Added a popup menu option to turn queries on, so that others can enjoy the thrill of massive flaming death. * gui/component/addressbook-factory.c (main): Made warnings always be fatal. * backend/pas/pas-book-view.c: Added some debugging spew. * backend/pas/pas-backend-file.c (pas_backend_file_search): Added a little experimental code to try to make file searches scale better. #if 0/#endif-ed out for now. * contact-editor/e-contact-quick-add.c: #included e-book-util.h. * backend/ebook/e-card.c (e_card_name_match_string): Added. Looser name-matching function. (e_card_email_match_string): Added. Loose e-mail matching. * backend/ebook/e-book-view-listener.c (e_book_view_listener_check_queue): Added code to cause us to abort rather than get trapped in a 100%-CPU-consuming loop in certain situations. Now we just need to figure out how to avoid these situations altogether. * backend/ebook/e-book-util.c: Added. Now contains the simple query stuff and the open local addressbook functions. * backend/ebook/e-book.c: Moved simple query stuff and open local addressbook functions into e-book-util.c. 2001-03-15 Jon Trowbridge <trow@ximian.com> * wombat.c (main): If we can't initialize a service on startup, tell us which one before terminating. svn path=/trunk/; revision=8754
Diffstat (limited to 'addressbook/gui/component/e-address-widget.c')
-rw-r--r--addressbook/gui/component/e-address-widget.c213
1 files changed, 190 insertions, 23 deletions
diff --git a/addressbook/gui/component/e-address-widget.c b/addressbook/gui/component/e-address-widget.c
index 8a3e3b52ac..92b0b9337c 100644
--- a/addressbook/gui/component/e-address-widget.c
+++ b/addressbook/gui/component/e-address-widget.c
@@ -26,6 +26,7 @@
*/
#include <config.h>
+#include <ctype.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-property-bag.h>
#include <bonobo/bonobo-generic-factory.h>
@@ -38,9 +39,14 @@ static void e_address_widget_destroy (GtkObject *obj);
static gint e_address_widget_button_press_handler (GtkWidget *w, GdkEventButton *ev);
static void e_address_widget_popup (EAddressWidget *, GdkEventButton *ev);
+static void e_address_widget_schedule_query (EAddressWidget *);
static GtkObjectClass *parent_class;
+static EBook *common_book = NULL; /* sort of lame */
+
+static gboolean doing_queries = FALSE;
+
static void
e_address_widget_class_init (EAddressWidgetClass *klass)
{
@@ -67,8 +73,12 @@ e_address_widget_destroy (GtkObject *obj)
g_free (addr->name);
g_free (addr->email);
- if (addr->card)
- gtk_object_unref (GTK_OBJECT (addr->card));
+
+ if (addr->query_tag)
+ e_book_simple_query_cancel (common_book, addr->query_tag);
+
+ if (addr->query_idle_tag)
+ gtk_idle_remove (addr->query_idle_tag);
}
static gint
@@ -123,10 +133,21 @@ e_address_widget_refresh (EAddressWidget *addr)
g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
have_name = addr->name && *addr->name;
- have_email = addr->email && *addr->email;
+ have_email = addr->email && *addr->email && (addr->card == NULL || !addr->known_email);
gtk_label_set_text (GTK_LABEL (addr->name_widget), have_name ? addr->name : "");
gtk_widget_visible (addr->name_widget, have_name);
+ if (addr->card) {
+ gint i, N = strlen (addr->name);
+ gchar *pattern = g_malloc (N+1);
+ for (i=0; i<N; ++i)
+ pattern[i] = '_';
+ pattern[i] = '\0';
+ gtk_label_set_pattern (GTK_LABEL (addr->name_widget), pattern);
+ g_free (pattern);
+ } else {
+ gtk_label_set_pattern (GTK_LABEL (addr->name_widget), "");
+ }
if (have_email) {
str = g_strdup_printf (have_name ? "<%s>" : "%s", addr->email);
@@ -140,7 +161,8 @@ e_address_widget_refresh (EAddressWidget *addr)
gtk_widget_visible (addr->spacer, have_name && have_email);
/* Launch a query to find the appropriate card, if necessary. */
- addr->querying = TRUE;
+ if (addr->card == NULL)
+ e_address_widget_schedule_query (addr);
}
void
@@ -209,18 +231,175 @@ e_address_widget_new (void)
/*
*
+ * Cardification
+ *
+ */
+
+static void
+e_address_widget_cardify (EAddressWidget *addr, ECard *card, gboolean known_email)
+{
+ if (addr->card != card || addr->known_email != known_email) {
+
+ if (addr->card != card) {
+ if (addr->card)
+ gtk_object_unref (GTK_OBJECT (addr->card));
+ addr->card = card;
+ gtk_object_ref (GTK_OBJECT (addr->card));
+ }
+
+ addr->known_email = known_email;
+
+ if (!(addr->name && *addr->name)) {
+ gchar *s = e_card_name_to_string (card->name);
+ e_address_widget_set_name (addr, s);
+ g_free (s);
+ }
+
+ e_address_widget_refresh (addr);
+ }
+}
+
+static void
+query_results_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer user_data)
+{
+ EAddressWidget *addr = user_data;
+
+ if (g_list_length ((GList *) cards) == 1) {
+ ECard *card = E_CARD (cards->data);
+ e_address_widget_cardify (addr, card, TRUE);
+ }
+
+ addr->query_tag = 0;
+}
+
+static void
+e_address_widget_do_query (EAddressWidget *addr)
+{
+ e_book_name_and_email_query (common_book, addr->name, addr->email, query_results_cb, addr);
+}
+
+static void
+book_ready_cb (EBook *book, EBookStatus status, gpointer user_data)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (user_data);
+
+ if (common_book == NULL) {
+ common_book = book;
+ gtk_object_ref (GTK_OBJECT (common_book));
+ } else
+ gtk_object_unref (GTK_OBJECT (book));
+
+ e_address_widget_do_query (addr);
+}
+
+static gint
+query_idle_fn (gpointer ptr)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (ptr);
+
+ if (common_book) {
+ e_address_widget_do_query (addr);
+ } else {
+ e_book_load_local_address_book (e_book_new (), book_ready_cb, addr);
+ }
+
+ addr->query_idle_tag = 0;
+ return FALSE;
+}
+
+static void
+e_address_widget_schedule_query (EAddressWidget *addr)
+{
+ if (addr->query_idle_tag || !doing_queries)
+ return;
+ addr->query_idle_tag = gtk_idle_add (query_idle_fn, addr);
+}
+
+/*
+ *
* Popup Menu
*
*/
#define ARBITRARY_UIINFO_LIMIT 64
+
+static gint
+popup_add_name_and_address (EAddressWidget *addr, GnomeUIInfo *uiinfo, gint i)
+{
+ gboolean flag = FALSE;
+
+ if (addr->name && *addr->name) {
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = addr->name;
+ ++i;
+ flag = TRUE;
+ }
+
+ if (addr->email && *addr->email) {
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = addr->email;
+ ++i;
+ flag = TRUE;
+ }
+
+ if (flag) {
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+ }
+
+ return i;
+}
+
+static void
+flip_queries_flag_cb (GtkWidget *w, gpointer user_data)
+{
+ doing_queries = !doing_queries;
+}
+
+static gint
+popup_add_query_change (EAddressWidget *addr, GnomeUIInfo *uiinfo, gint i)
+{
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = doing_queries ? _("Disable Queries") : _("Enable Queries (Dangerous!)");
+ uiinfo[i].moreinfo = flip_queries_flag_cb;
+ ++i;
+
+ return i;
+}
+
+
static GtkWidget *
popup_menu_card (EAddressWidget *addr)
{
+ GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT];
+ GtkWidget *pop;
+ gint i=0;
ECard *card = E_CARD (addr->card);
+
g_return_val_if_fail (card != NULL, NULL);
- return NULL;
+ memset (uiinfo, 0, sizeof (uiinfo));
+
+ i = popup_add_name_and_address (addr, uiinfo, i);
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = _("Edit Contact Info");
+ ++i;
+
+ i = popup_add_query_change (addr, uiinfo, i);
+
+ uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+ pop = gnome_popup_menu_new (uiinfo);
+ return pop;
+}
+
+static void
+post_quick_add_cb (ECard *card, gpointer user_data)
+{
+ e_address_widget_cardify (E_ADDRESS_WIDGET (user_data), card, TRUE);
}
static void
@@ -228,7 +407,7 @@ add_contacts_cb (GtkWidget *w, gpointer user_data)
{
EAddressWidget *addr = E_ADDRESS_WIDGET (user_data);
- e_contact_quick_add (addr->name, addr->email, NULL, NULL);
+ e_contact_quick_add (addr->name, addr->email, post_quick_add_cb, addr);
}
static GtkWidget *
@@ -240,30 +419,17 @@ popup_menu_nocard (EAddressWidget *addr)
memset (uiinfo, 0, sizeof (uiinfo));
- if (addr->name) {
- uiinfo[i].type = GNOME_APP_UI_ITEM;
- uiinfo[i].label = addr->name;
- ++i;
- }
-
- if (addr->email) {
- uiinfo[i].type = GNOME_APP_UI_ITEM;
- uiinfo[i].label = addr->email;
- ++i;
- }
-
- uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
- ++i;
+ i = popup_add_name_and_address (addr, uiinfo, i);
uiinfo[i].type = GNOME_APP_UI_ITEM;
- uiinfo[i].label = N_("Add to Contacts");
+ uiinfo[i].label = _("Add to Contacts");
uiinfo[i].moreinfo = add_contacts_cb;
++i;
- uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+ i = popup_add_query_change (addr, uiinfo, i);
+ uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
pop = gnome_popup_menu_new (uiinfo);
-
return pop;
}
@@ -409,3 +575,4 @@ e_address_widget_factory_init (void)
if (factory == NULL)
g_error ("I could not register an AddressWidget factory.");
}
+