aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-05-18 15:10:04 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-05-18 15:10:04 +0800
commit3ca3f79dbe4641478582cd0b78a6e377c3430b19 (patch)
tree2693ebef04b05fff098f38f00233e676caf6229e /addressbook/gui
parentc8476fc1ff4887bde985382de708f248067ac7ba (diff)
downloadgsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.gz
gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.zst
gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.zip
Return the serialized EDestinations (rather than just a string w/ e-mail
2001-05-18 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names-bonobo.c (entry_get_property_fn): Return the serialized EDestinations (rather than just a string w/ e-mail addresses) through the bonobo component's property bag. * gui/component/select-names/e-select-names-model.c (e_select_names_model_export_destinationv): Added. A convenience routine for serializing the model's EDestinations into a string. * gui/component/select-names/e-select-names-popup.c (add_html_mail): Added. Puts in a check menu item for whether or not the recipient wants HTML mail. (popup_menu_card): Add menu item for HTML mail. Enable edit contact info item. (popup_menu_nocard): Add menu item for HTML mail. Enable edit contact info item. * backend/ebook/e-book-util.c (e_book_use_local_address_book): Added. Fetches the local addressbook and caches it on the first call. This is meant to be an easy and efficient way to get at the local addressbook with the minimum of code. (e_book_query_address_locally): Added. Convenience code that does an e-mail only e_book_name_and_email_query against the local address book. * backend/ebook/e-destination.c (e_destination_set_html_mail_pref): Added. Allows the intended recipient's HTML mail preference to be manipulated. (e_destination_get_email_verbose): Added. Cleaned up to use e_destination_get_name. (e_destination_get_html_mail_pref): Added. Read the recipient's HTML mail preference. If the destination is linked to a card, the preference is taken from the card (unless it has been explicitly overridden by a called to e_destination_set_html_mail_pref). (e_destination_get_address_textv): Added. Form a unified address string from a NULL-terminated vector of EDestinations. (e_destination_export): Added. Serialize an EDestination to a string. (e_destination_import): Added. Unserialize a string to build an EDestination. (e_destination_exportv): Added. Serialize a NULL-terminated vector of EDestinations to a string. (e_destination_importv): Added. Unserialize a string to build a NULL-terminated vector of EDestinations. * gui/component/select-names/e-select-names-completion.c: Implemented local versions of g_strcasecmp and g_strncasecmp (which should really be in glib, I think...) for utf8, and used them to make this code utf8-safe. 2001-05-18 Jon Trowbridge <trow@ximian.com> * Makefile.am (evolution_mail_LDADD): Added libebook.la (which is now required by the composer.) 2001-05-18 Jon Trowbridge <trow@ximian.com> * e-msg-composer-hdrs.c (set_recipients): Properly unserialize the string returned by the "text" property of the bonobo control, convert it into EDestinations, and use them to get the e-mail addresses of our recipients. 22001-05-18 Jon Trowbridge <trow@ximian.com> * Makefile.am (SUBDIRS): Changed build order. Now addressbook gets built before mail. svn path=/trunk/; revision=9878
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/component/select-names/e-select-names-bonobo.c3
-rw-r--r--addressbook/gui/component/select-names/e-select-names-completion.c70
-rw-r--r--addressbook/gui/component/select-names/e-select-names-model.c25
-rw-r--r--addressbook/gui/component/select-names/e-select-names-model.h9
-rw-r--r--addressbook/gui/component/select-names/e-select-names-popup.c93
5 files changed, 176 insertions, 24 deletions
diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.c b/addressbook/gui/component/select-names/e-select-names-bonobo.c
index 98c235c067..18f88c7f5a 100644
--- a/addressbook/gui/component/select-names/e-select-names-bonobo.c
+++ b/addressbook/gui/component/select-names/e-select-names-bonobo.c
@@ -82,8 +82,9 @@ entry_get_property_fn (BonoboPropertyBag *bag,
gtk_object_get(GTK_OBJECT(text_model),
"source", &model,
NULL);
- text = e_select_names_model_get_address_text (model);
+ text = e_select_names_model_export_destinationv (model);
BONOBO_ARG_SET_STRING (arg, text);
+ g_free (text);
}
break;
default:
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 cebd57791f..76b8fd0550 100644
--- a/addressbook/gui/component/select-names/e-select-names-completion.c
+++ b/addressbook/gui/component/select-names/e-select-names-completion.c
@@ -34,6 +34,8 @@
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-util.h>
+#include <gal/unicode/gunicode.h>
+
#include <addressbook/backend/ebook/e-book-util.h>
#include <addressbook/backend/ebook/e-destination.h>
#include <addressbook/backend/ebook/e-card-simple.h>
@@ -98,6 +100,54 @@ sexp_nickname (ESelectNamesCompletion *comp)
}
+static gint
+e_utf8_strncasecmp (const gchar *p, const gchar *q, gint len)
+{
+ if (p == NULL || q == NULL) {
+ if (p) return +1;
+ if (q) return -1;
+ return 0;
+ }
+
+ if (len < 0)
+ len = G_MAXINT;
+
+ while (*p && *q && len > 0) {
+ gunichar cp = g_utf8_get_char (p);
+ gunichar cq = g_utf8_get_char (q);
+
+ if (!(g_unichar_validate (cp)
+ && g_unichar_validate (cq)))
+ break;
+
+ cp = g_unichar_tolower (cp);
+ cq = g_unichar_tolower (cq);
+
+ if (cp != cq)
+ return (cp < cq) - (cp > cq);
+
+ p = g_utf8_next_char (p);
+ q = g_utf8_next_char (q);
+ --len;
+ }
+
+ if (len) {
+ if (*p)
+ return +1;
+ else if (*q)
+ return -1;
+ }
+
+ return 0;
+}
+
+static gint
+e_utf8_strcasecmp (const gchar *p, const gchar *q)
+{
+ return e_utf8_strncasecmp (p, q, -1);
+}
+
+
static gchar *
match_nickname (ESelectNamesCompletion *comp, EDestination *dest, double *score)
{
@@ -105,7 +155,7 @@ match_nickname (ESelectNamesCompletion *comp, EDestination *dest, double *score)
ECard *card = e_destination_get_card (dest);
if (card->nickname
- && !g_strncasecmp (comp->priv->query_text, card->nickname, len)) {
+ && !e_utf8_strncasecmp (comp->priv->query_text, card->nickname, len)) {
gchar *name = e_card_name_to_string (card->name);
gchar *str;
@@ -136,7 +186,7 @@ match_email (ESelectNamesCompletion *comp, EDestination *dest, double *score)
ECard *card = e_destination_get_card (dest);
const gchar *email = e_destination_get_email (dest);
- if (email && !g_strncasecmp (comp->priv->query_text, email, len)) {
+ if (email && !e_utf8_strncasecmp (comp->priv->query_text, email, len)) {
gchar *name, *str;
*score = len * 2; /* 2 points for each matching character */
name = e_card_name_to_string (card->name);
@@ -208,7 +258,7 @@ match_name_fragment (const gchar *fragment, const gchar *txt)
gint len = strlen (txt);
while (*fragment) {
- if (!g_strncasecmp (fragment, txt, len))
+ if (!e_utf8_strncasecmp (fragment, txt, len))
return TRUE;
while (*fragment && !isspace ((gint) *fragment))
@@ -281,9 +331,9 @@ match_name (ESelectNamesCompletion *comp, EDestination *dest, double *score)
/* We massively boost the score if the nickname exists and is the same as one of the "real" names. This keeps the
nickname from matching ahead of the real name for this card. */
len = strlen (card->nickname);
- if ((card->name->given && !g_strncasecmp (card->name->given, card->nickname, MIN (strlen (card->name->given), len)))
- || (card->name->family && !g_strncasecmp (card->name->family, card->nickname, MIN (strlen (card->name->family), len)))
- || (card->name->additional && !g_strncasecmp (card->name->additional, card->nickname, MIN (strlen (card->name->additional), len))))
+ if ((card->name->given && !e_utf8_strncasecmp (card->name->given, card->nickname, MIN (strlen (card->name->given), len)))
+ || (card->name->family && !e_utf8_strncasecmp (card->name->family, card->nickname, MIN (strlen (card->name->family), len)))
+ || (card->name->additional && !e_utf8_strncasecmp (card->name->additional, card->nickname, MIN (strlen (card->name->additional), len))))
*score *= 100;
}
@@ -432,11 +482,11 @@ book_query_score (ESelectNamesCompletion *comp, EDestination *dest, double *scor
if (email) {
simp = e_card_simple_new (card);
simp_email = e_card_simple_get_email (simp, E_CARD_SIMPLE_EMAIL_ID_EMAIL);
- if (simp_email && !g_strcasecmp (simp_email, email)) {
+ if (simp_email && !e_utf8_strcasecmp (simp_email, email)) {
best_score += 0.2;
}
simp_email = e_card_simple_get_email (simp, E_CARD_SIMPLE_EMAIL_ID_EMAIL_2);
- if (simp_email && !g_strcasecmp (simp_email, email)) {
+ if (simp_email && !e_utf8_strcasecmp (simp_email, email)) {
best_score += 0.1;
}
gtk_object_unref (GTK_OBJECT (simp));
@@ -856,7 +906,7 @@ e_select_names_completion_do_query (ESelectNamesCompletion *comp, const gchar *q
can_reuse_cached_cards = (comp->priv->cached_query_text
&& (strlen (comp->priv->cached_query_text) <= strlen (clean))
- && !g_strncasecmp (comp->priv->cached_query_text, clean, strlen (comp->priv->cached_query_text)));
+ && !e_utf8_strncasecmp (comp->priv->cached_query_text, clean, strlen (comp->priv->cached_query_text)));
if (can_reuse_cached_cards) {
@@ -912,7 +962,7 @@ search_override_check (SearchOverride *over, const gchar *text)
if (over == NULL || text == NULL)
return FALSE;
- return !g_strcasecmp (over->trigger, text);
+ return !e_utf8_strcasecmp (over->trigger, text);
}
diff --git a/addressbook/gui/component/select-names/e-select-names-model.c b/addressbook/gui/component/select-names/e-select-names-model.c
index 1baf729b3e..74dfcb8158 100644
--- a/addressbook/gui/component/select-names/e-select-names-model.c
+++ b/addressbook/gui/component/select-names/e-select-names-model.c
@@ -310,14 +310,35 @@ e_select_names_model_count (ESelectNamesModel *model)
const EDestination *
e_select_names_model_get_destination (ESelectNamesModel *model, gint index)
{
- g_return_val_if_fail (model != NULL, NULL);
- g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), NULL);
+ g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL);
g_return_val_if_fail (0 <= index, NULL);
g_return_val_if_fail (index < g_list_length (model->priv->data), NULL);
return E_DESTINATION (g_list_nth_data (model->priv->data, index));
}
+gchar *
+e_select_names_model_export_destinationv (ESelectNamesModel *model)
+{
+ EDestination **destv;
+ gchar *str;
+ gint i, len = 0;
+ GList *j;
+ g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL);
+
+ len = g_list_length (model->priv->data);
+ destv = g_new0 (EDestination *, len+1);
+
+ for (i=0, j = model->priv->data; j != NULL; j = g_list_next (j)) {
+ destv[i++] = E_DESTINATION (j->data);
+ }
+
+ str = e_destination_exportv (destv);
+ g_free (destv);
+
+ return str;
+}
+
ECard *
e_select_names_model_get_card (ESelectNamesModel *model, gint index)
{
diff --git a/addressbook/gui/component/select-names/e-select-names-model.h b/addressbook/gui/component/select-names/e-select-names-model.h
index 2e1c970ef7..417ec7abb1 100644
--- a/addressbook/gui/component/select-names/e-select-names-model.h
+++ b/addressbook/gui/component/select-names/e-select-names-model.h
@@ -49,10 +49,11 @@ ESelectNamesModel *e_select_names_model_duplicate (ESelectNamesModel *old);
const gchar *e_select_names_model_get_textification (ESelectNamesModel *model);
const gchar *e_select_names_model_get_address_text (ESelectNamesModel *model);
-gint e_select_names_model_count (ESelectNamesModel *model);
-const EDestination *e_select_names_model_get_destination (ESelectNamesModel *model, gint index);
-ECard *e_select_names_model_get_card (ESelectNamesModel *model, gint index);
-const gchar *e_select_names_model_get_string (ESelectNamesModel *model, gint index);
+gint e_select_names_model_count (ESelectNamesModel *model);
+const EDestination *e_select_names_model_get_destination (ESelectNamesModel *model, gint index);
+gchar *e_select_names_model_export_destinationv (ESelectNamesModel *model);
+ECard *e_select_names_model_get_card (ESelectNamesModel *model, gint index);
+const gchar *e_select_names_model_get_string (ESelectNamesModel *model, gint index);
void e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest);
void e_select_names_model_append (ESelectNamesModel *model, EDestination *dest);
diff --git a/addressbook/gui/component/select-names/e-select-names-popup.c b/addressbook/gui/component/select-names/e-select-names-popup.c
index f6164f0022..4f40093901 100644
--- a/addressbook/gui/component/select-names/e-select-names-popup.c
+++ b/addressbook/gui/component/select-names/e-select-names-popup.c
@@ -38,6 +38,8 @@
#include <libgnomeui/gnome-app-helper.h>
#include <libgnomeui/gnome-popup-menu.h>
+#include <addressbook/backend/ebook/e-book-util.h>
+#include <addressbook/contact-editor/e-contact-editor.h>
#include <addressbook/contact-editor/e-contact-quick-add.h>
#include "e-select-names-popup.h"
@@ -88,10 +90,38 @@ popup_info_cleanup (GtkWidget *w, gpointer info)
popup_info_free ((PopupInfo *) info);
}
+/* You are in a maze of twisty little callbacks, all alike... */
+
+static void
+found_fields_cb (EBook *book, EBookStatus status, EList *writable_fields, gpointer user_data)
+{
+ EDestination *dest = E_DESTINATION (user_data);
+ EContactEditor *ce;
+ ECard *card;
+
+ card = (ECard *) e_destination_get_card (dest);
+ ce = e_contact_editor_new (card, FALSE, writable_fields, FALSE);
+ e_contact_editor_raise (ce);
+ gtk_object_unref (GTK_OBJECT (dest));
+}
+
+static void
+edit_contact_info_have_book_cb (EBook *book, gpointer user_data)
+{
+ if (book) {
+ e_book_get_supported_fields (book, found_fields_cb, user_data);
+ }
+}
+
static void
-do_nothing (gpointer foo)
+edit_contact_info_cb (GtkWidget *w, gpointer user_data)
{
+ PopupInfo *info = (PopupInfo *) user_data;
+ if (info == NULL)
+ return;
+ gtk_object_ref (GTK_OBJECT (info->dest));
+ e_book_use_local_address_book (edit_contact_info_have_book_cb, info->dest);
}
static void
@@ -147,6 +177,39 @@ add_remove_all_recipients (GnomeUIInfo *uiinfo, PopupInfo *info)
uiinfo->moreinfo = remove_all_recipients_cb;
}
+static void
+toggle_html_mail_cb (GtkWidget *w, gpointer user_data)
+{
+ PopupInfo *info = (PopupInfo *) user_data;
+ GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (w);
+ const EDestination *dest;
+
+ if (info == NULL)
+ return;
+
+ dest = info->dest;
+
+ item = GTK_CHECK_MENU_ITEM (item);
+ e_destination_set_html_mail_pref ((EDestination *) dest, item->active);
+}
+
+static void
+add_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info)
+{
+ uiinfo->type = GNOME_APP_UI_TOGGLEITEM;
+ uiinfo->label = _("Send HTML Mail?");
+ uiinfo->moreinfo = toggle_html_mail_cb;
+}
+
+static void
+init_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info)
+{
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (uiinfo->widget),
+ e_destination_get_html_mail_pref (info->dest));
+ gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (uiinfo->widget), TRUE);
+
+}
+
#define ARBITRARY_UIINFO_LIMIT 64
static GtkWidget *
popup_menu_card (PopupInfo *info)
@@ -159,6 +222,7 @@ popup_menu_card (PopupInfo *info)
GtkWidget *pop;
EIterator *iterator;
gchar *name_str;
+ gint html_toggle;
/*
* Build up our GnomeUIInfo array.
@@ -184,11 +248,14 @@ popup_menu_card (PopupInfo *info)
iterator = e_list_get_iterator (card->email);
for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) {
+ gchar *label = (gchar *)e_iterator_get (iterator);
- radioinfo[j].type = GNOME_APP_UI_ITEM;
- radioinfo[j].label = (gchar *)e_iterator_get (iterator);
- radioinfo[j].moreinfo = change_email_num_cb;
- ++j;
+ if (label && *label) {
+ radioinfo[j].type = GNOME_APP_UI_ITEM;
+ radioinfo[j].label = label;
+ radioinfo[j].moreinfo = change_email_num_cb;
+ ++j;
+ }
}
radioinfo[j].type = GNOME_APP_UI_ENDOFINFO;
@@ -206,9 +273,13 @@ popup_menu_card (PopupInfo *info)
uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
++i;
+ add_html_mail (&(uiinfo[i]), info);
+ html_toggle = i;
+ ++i;
+
uiinfo[i].type = GNOME_APP_UI_ITEM;
uiinfo[i].label = N_("Edit Contact Info");
- uiinfo[i].moreinfo = do_nothing;
+ uiinfo[i].moreinfo = edit_contact_info_cb;
++i;
add_remove_recipient (&(uiinfo[i]), info);
@@ -236,6 +307,8 @@ popup_menu_card (PopupInfo *info)
}
}
+ init_html_mail (&(uiinfo[html_toggle]), info);
+
return pop;
}
@@ -253,6 +326,7 @@ popup_menu_nocard (PopupInfo *info)
gint i=0;
GtkWidget *pop;
const gchar *str;
+ gint html_toggle;
memset (uiinfo, 0, sizeof (uiinfo));
@@ -265,6 +339,10 @@ popup_menu_nocard (PopupInfo *info)
uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
++i;
+ add_html_mail (&(uiinfo[i]), info);
+ html_toggle = i;
+ ++i;
+
uiinfo[i].type = GNOME_APP_UI_ITEM;
uiinfo[i].label = _("Add to Contacts");
uiinfo[i].moreinfo = quick_add_cb;
@@ -279,11 +357,12 @@ popup_menu_nocard (PopupInfo *info)
uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
pop = gnome_popup_menu_new (uiinfo);
+
+ init_html_mail (&(uiinfo[html_toggle]), info);
return pop;
}
-
void
e_select_names_popup (ESelectNamesModel *model, GdkEventButton *ev, gint pos)
{