aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-02-20 06:49:18 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-02-20 06:49:18 +0800
commitd369e177b199c4c798f0b6ad8972951d8586bcd9 (patch)
tree492dd3459df5e78e6709e7879a70011f4f729012 /addressbook/gui/component
parent54105acd4e5283899c1659e64e41341eec8d667c (diff)
downloadgsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar.gz
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar.bz2
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar.lz
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar.xz
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.tar.zst
gsoc2013-evolution-d369e177b199c4c798f0b6ad8972951d8586bcd9.zip
When creating the entry, open up an ebook (corresponding to the local
2001-02-19 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names-manager.c (e_select_names_manager_create_entry): When creating the entry, open up an ebook (corresponding to the local addressbook) and make the entry use an EAddressCompletion. (completion_handler): Added; this is the actual completion handler, which manipulates the entry when the user selects something from the drop-down. * gui/component/select-names/e-select-names-model.c: Various hacks by clahey to unbreak e_select_names_model_add_item, e_select_names_model_replace_item (which I added) and e_select_names_model_remove_item. * gui/component/select-names/e-select-names-text-model.c (e_select_names_text_model_obj_count, e_select_names_text_model_get_nth_obj): Make chunks of text that correspond to ECards in the ESelectNamesModel be embedded objects. (e_select_names_text_model_activate_obj): On activation, pop up a contact editor for the embedded object's card. (e_select_names_text_model_model_changed): Fixed to work with ETextModel API changes. (e_select_names_text_model_set_text): Make const correct. (e_select_names_text_model_insert): Make const correct. (e_select_names_text_model_insert_length): Make const correct. * backend/ebook/e-address-completion.h, backend/ebook/e-address-completion.c: Added. EAddressCompletion is a derived class of ECompletion that does asynchronous address lookups for completions. svn path=/trunk/; revision=8282
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r--addressbook/gui/component/select-names/Makefile.am2
-rw-r--r--addressbook/gui/component/select-names/e-select-names-manager.c41
-rw-r--r--addressbook/gui/component/select-names/e-select-names-model.c36
-rw-r--r--addressbook/gui/component/select-names/e-select-names-model.h3
-rw-r--r--addressbook/gui/component/select-names/e-select-names-text-model.c115
5 files changed, 178 insertions, 19 deletions
diff --git a/addressbook/gui/component/select-names/Makefile.am b/addressbook/gui/component/select-names/Makefile.am
index 0bbff76a71..312ff72ee7 100644
--- a/addressbook/gui/component/select-names/Makefile.am
+++ b/addressbook/gui/component/select-names/Makefile.am
@@ -67,6 +67,8 @@ libeselectnames_la_SOURCES = \
gladedir = $(datadir)/evolution/glade
glade_DATA = select-names.glade
+
+
EXTRA_DIST = \
$(glade_DATA) \
$(oaf_in_files) \
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 3af59611ab..3e629af19d 100644
--- a/addressbook/gui/component/select-names/e-select-names-manager.c
+++ b/addressbook/gui/component/select-names/e-select-names-manager.c
@@ -16,6 +16,7 @@
#include "e-select-names-model.h"
#include "e-select-names-text-model.h"
#include "e-select-names.h"
+#include <addressbook/backend/ebook/e-address-completion.h>
#include <gal/e-text/e-entry.h>
/* Object argument IDs */
@@ -242,6 +243,32 @@ entry_destroyed(EEntry *entry, ESelectNamesManager *manager)
gtk_object_unref(GTK_OBJECT(manager));
}
+static void
+completion_handler (EEntry *entry, const gchar *text, gpointer user_data)
+{
+ ESelectNamesModel *snm = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model"));
+ ESelectNamesModelData *data = g_new0 (ESelectNamesModelData, 1);
+ EIterator *iterator;
+
+ data->type = E_SELECT_NAMES_MODEL_DATA_TYPE_CARD;
+ data->card = E_CARD (user_data);
+ gtk_object_ref (GTK_OBJECT (data->card));
+ data->string = g_strdup (text);
+
+ iterator = e_list_get_iterator (snm->data);
+ e_select_names_model_replace_item (snm, iterator, data);
+}
+
+static void
+set_completion (EBook *book, EBookStatus status, EEntry *entry)
+{
+ ECompletion *addr_comp;
+
+ addr_comp = e_address_completion_new (book);
+ e_entry_enable_completion_full (entry, addr_comp, -1, completion_handler);
+ gtk_object_unref (GTK_OBJECT (book));
+}
+
GtkWidget *e_select_names_manager_create_entry (ESelectNamesManager *manager,
const char *id)
{
@@ -253,11 +280,23 @@ GtkWidget *e_select_names_manager_create_entry (
if (!strcmp(section->id, id)) {
ESelectNamesManagerEntry *entry;
EEntry *eentry;
- eentry = E_ENTRY(e_entry_new());
+ gchar *filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db");
+ gchar *uri = g_strdup_printf ("file://%s", filename);
+ EBook *book;
+ eentry = E_ENTRY(e_entry_new());
+ gtk_object_set_data (GTK_OBJECT (eentry), "select_names_model", section->model);
+
+ book = e_book_new ();
+ gtk_object_ref (GTK_OBJECT (book));
+ e_book_load_uri (book, uri, (EBookCallback) set_completion, eentry);
+ g_free (uri);
+ g_free (filename);
+
entry = g_new(ESelectNamesManagerEntry, 1);
entry->entry = eentry;
entry->id = (char *)id;
+
model = e_select_names_text_model_new(section->model);
e_list_append(manager->entries, entry);
g_free(entry);
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 0bbbe588a6..735840d2b3 100644
--- a/addressbook/gui/component/select-names/e-select-names-model.c
+++ b/addressbook/gui/component/select-names/e-select-names-model.c
@@ -420,13 +420,45 @@ e_select_names_model_replace (ESelectNamesModel *model,
gtk_object_unref(GTK_OBJECT(iterator));
}
+static void
+esnm_add_item_real (ESelectNamesModel *model,
+ EIterator *iterator, /* NULL for at the beginning. */
+ gboolean before,
+ ESelectNamesModelData *data)
+{
+ if (iterator == NULL)
+ iterator = e_list_get_iterator(model->data);
+ else
+ gtk_object_ref(GTK_OBJECT(iterator));
+
+ e_iterator_insert(iterator, data, before);
+
+ gtk_object_unref(GTK_OBJECT(iterator));
+}
+
+static void
+esnm_remove_item_real (ESelectNamesModel *model,
+ EIterator *iterator)
+{
+ e_iterator_delete(iterator);
+}
void
e_select_names_model_add_item (ESelectNamesModel *model,
EIterator *iterator, /* NULL for at the beginning. */
ESelectNamesModelData *data)
{
- e_iterator_insert(iterator, data, FALSE);
+ esnm_add_item_real(model, iterator, FALSE, data);
+ e_select_names_model_changed(model);
+}
+
+void
+e_select_names_model_replace_item (ESelectNamesModel *model,
+ EIterator *iterator,
+ ESelectNamesModelData *data)
+{
+ esnm_remove_item_real(model, iterator);
+ esnm_add_item_real(model, iterator, FALSE, data);
e_select_names_model_changed(model);
}
@@ -434,7 +466,7 @@ void
e_select_names_model_remove_item (ESelectNamesModel *model,
EIterator *iterator)
{
- e_iterator_delete(iterator);
+ esnm_remove_item_real(model, iterator);
e_select_names_model_changed(model);
}
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 4ea1bdc8db..576d5e6a9a 100644
--- a/addressbook/gui/component/select-names/e-select-names-model.h
+++ b/addressbook/gui/component/select-names/e-select-names-model.h
@@ -78,6 +78,9 @@ void e_select_names_model_replace (ESelectNamesModel *mo
void e_select_names_model_add_item (ESelectNamesModel *model,
EIterator *iterator, /* NULL for at the beginning. */
ESelectNamesModelData *data);
+void e_select_names_model_replace_item (ESelectNamesModel *model,
+ EIterator *iterator,
+ ESelectNamesModelData *data);
void e_select_names_model_remove_item (ESelectNamesModel *model,
EIterator *iterator);
diff --git a/addressbook/gui/component/select-names/e-select-names-text-model.c b/addressbook/gui/component/select-names/e-select-names-text-model.c
index 71934c46dc..5983ccb93d 100644
--- a/addressbook/gui/component/select-names/e-select-names-text-model.c
+++ b/addressbook/gui/component/select-names/e-select-names-text-model.c
@@ -12,6 +12,7 @@
#include <string.h>
#include <gtk/gtk.h>
+#include <addressbook/contact-editor/e-contact-editor.h>
#include "e-select-names-text-model.h"
/* Object argument IDs */
@@ -27,11 +28,15 @@ static void e_select_names_text_model_destroy (GtkObject *object);
static void e_select_names_text_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void e_select_names_text_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
-static void e_select_names_text_model_set_text (ETextModel *model, gchar *text);
-static void e_select_names_text_model_insert (ETextModel *model, gint position, gchar *text);
-static void e_select_names_text_model_insert_length (ETextModel *model, gint position, gchar *text, gint length);
+static void e_select_names_text_model_set_text (ETextModel *model, const gchar *text);
+static void e_select_names_text_model_insert (ETextModel *model, gint position, const gchar *text);
+static void e_select_names_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length);
static void e_select_names_text_model_delete (ETextModel *model, gint position, gint length);
+static gint e_select_names_text_model_obj_count (ETextModel *model);
+static const gchar *e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len);
+static void e_select_names_text_model_activate_obj (ETextModel *model, gint n);
+
static void e_select_names_text_model_model_changed (ESelectNamesModel *source,
ESelectNamesTextModel *model);
@@ -110,6 +115,10 @@ e_select_names_text_model_class_init (ESelectNamesTextModelClass *klass)
text_model_class->insert = e_select_names_text_model_insert;
text_model_class->insert_length = e_select_names_text_model_insert_length;
text_model_class->delete = e_select_names_text_model_delete;
+
+ text_model_class->obj_count = e_select_names_text_model_obj_count;
+ text_model_class->get_nth_obj = e_select_names_text_model_get_nth_obj;
+ text_model_class->object_activated = e_select_names_text_model_activate_obj;
}
static int
@@ -120,14 +129,11 @@ get_length(EIterator *iterator)
}
static void
-e_select_names_text_model_set_text (ETextModel *model, gchar *text)
+e_select_names_text_model_set_text (ETextModel *model, const gchar *text)
{
ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL(model)->source;
EIterator *iterator = e_list_get_iterator(e_select_names_model_get_data(source));
- int length = 0;
- if (model->text) {
- length = strlen(model->text);
- }
+ int length = e_text_model_get_text_length (model);
e_iterator_reset(iterator);
if (!e_iterator_is_valid(iterator)) {
@@ -138,13 +144,13 @@ e_select_names_text_model_set_text (ETextModel *model, gchar *text)
iterator,
0,
length,
- text);
+ (gchar *) text);
if (iterator)
gtk_object_unref(GTK_OBJECT(iterator));
}
static void
-e_select_names_text_model_insert (ETextModel *model, gint position, gchar *text)
+e_select_names_text_model_insert (ETextModel *model, gint position, const gchar *text)
{
ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL(model)->source;
EIterator *iterator = e_list_get_iterator(e_select_names_model_get_data(source));
@@ -164,13 +170,13 @@ e_select_names_text_model_insert (ETextModel *model, gint position, gchar
e_select_names_model_insert(source,
iterator,
position,
- text);
+ (gchar *) text);
if (iterator)
gtk_object_unref(GTK_OBJECT(iterator));
}
static void
-e_select_names_text_model_insert_length (ETextModel *model, gint position, gchar *text, gint length)
+e_select_names_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length)
{
ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL(model)->source;
EIterator *iterator = e_list_get_iterator(e_select_names_model_get_data(source));
@@ -190,7 +196,7 @@ e_select_names_text_model_insert_length (ETextModel *model, gint position, gchar
e_select_names_model_insert_length(source,
iterator,
position,
- text,
+ (gchar *) text,
length);
if (iterator)
gtk_object_unref(GTK_OBJECT(iterator));
@@ -218,6 +224,83 @@ e_select_names_text_model_delete (ETextModel *model, gint position, gint
gtk_object_unref(GTK_OBJECT(iterator));
}
+static gint
+e_select_names_text_model_obj_count (ETextModel *model)
+{
+ ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source;
+ EIterator *iterator = e_list_get_iterator (e_select_names_model_get_data (source));
+ gint count = 0;
+
+ for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) {
+ const ESelectNamesModelData *data = e_iterator_get (iterator);
+ if (data->type == E_SELECT_NAMES_MODEL_DATA_TYPE_CARD)
+ ++count;
+ }
+
+ return count;
+}
+
+static const gchar *
+e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len)
+{
+ ESelectNamesTextModel *select_text_model = E_SELECT_NAMES_TEXT_MODEL (model);
+ ESelectNamesModel *source = select_text_model->source;
+ EIterator *iterator = e_list_get_iterator (e_select_names_model_get_data (source));
+ const ESelectNamesModelData *data;
+ gint i, pos;
+
+ pos = 0;
+ i = 0;
+ e_iterator_reset (iterator);
+ while (e_iterator_is_valid (iterator) && n > 0) {
+ gint len;
+ data = e_iterator_get (iterator);
+ len = strlen (data->string);
+
+ pos += len + 1; /* advance and extra space for comma */
+ ++i;
+ if (data->type == E_SELECT_NAMES_MODEL_DATA_TYPE_CARD)
+ --n;
+
+ if (n >= 0)
+ e_iterator_next (iterator);
+ }
+
+ if (len) {
+ data = e_iterator_get (iterator);
+ *len = strlen (data->string);
+ }
+
+ return e_text_model_get_text (model) + pos;
+}
+
+static void
+e_select_names_text_model_activate_obj (ETextModel *model, gint n)
+{
+ ESelectNamesTextModel *select_text_model = E_SELECT_NAMES_TEXT_MODEL (model);
+ ESelectNamesModel *source = select_text_model->source;
+ EIterator *iterator = e_list_get_iterator (e_select_names_model_get_data (source));
+ const ESelectNamesModelData *data;
+ const ECard *card;
+ EContactEditor *contact_editor;
+
+ e_iterator_reset (iterator);
+ while (e_iterator_is_valid (iterator) && n > 0) {
+ data = e_iterator_get (iterator);
+ if (data->type == E_SELECT_NAMES_MODEL_DATA_TYPE_CARD)
+ --n;
+
+ if (n >= 0)
+ e_iterator_next (iterator);
+ }
+
+ data = e_iterator_get (iterator);
+ card = E_CARD (data->card);
+
+ contact_editor = e_contact_editor_new (card, FALSE);
+ e_contact_editor_raise (contact_editor);
+}
+
static void
e_select_names_text_model_model_changed (ESelectNamesModel *source,
ESelectNamesTextModel *model)
@@ -260,9 +343,9 @@ e_select_names_text_model_model_changed (ESelectNamesModel *source,
*stringp = 0;
}
*lengthsp = -1;
- g_free(E_TEXT_MODEL(model)->text);
- E_TEXT_MODEL(model)->text = string;
- e_text_model_changed(E_TEXT_MODEL(model));
+
+ E_TEXT_MODEL_CLASS (parent_class)->set_text (E_TEXT_MODEL (model), string);
+ g_free (string);
}