diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-03-02 05:03:02 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-03-02 05:03:02 +0800 |
commit | ce67772c53108003cd8ba2bf2130722ab17d5df8 (patch) | |
tree | 1b732c251e8cbf340ea060f8737fe504dadc7d77 /addressbook/gui/component/select-names/e-select-names-manager.c | |
parent | fae87e8d3d4e69f40b6c3e51ea2c8c8477995857 (diff) | |
download | gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.tar.gz gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.tar.zst gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.zip |
Change for new EDestination/ESelectNamesModel API.
2001-03-01 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names-table-model.c
(fill_in_info): Change for new EDestination/ESelectNamesModel API.
* gui/component/select-names/e-select-names-manager.c
(e_select_names_manager_get_source): Added. A function for
looking up the ESelectNamesModel by id. (I didn't end up using
this function, but it might come in handy later.)
(e_select_names_manager_get_cards): #if 0/#endif out this
function.
(e_select_names_manager_create_entry): Modified to attach an
ESelectNamesCompletion to the entry we create.
(completion_handler): A post-completion handler for our EEntry, to
take the completion's extra data (an EDestination) and properly
stick it into our ESelectNamesModel.
* gui/component/select-names/e-select-names.c
(real_add_address_cb): Changed to operate on EDestinations rather
than ECards and to use the new ESelectNamesModel API. This leads
to a rather nice code simplication.
(remove_address): Changed for new ESelectNamesModel API.
* gui/component/select-names/e-select-names-bonobo.c
(entry_get_property_fn): Rather than just passing the entry's text
through the property bag, get the "address text" from the model.
This returns a nice, verbose string of addresses with names
expanded when the address is tied to an ECard (i.e. "Jon
Trowbridge <trow@ximian.com>").
(impl_SelectNames_get_entry_for_section): Make the text property
read-only.
(entry_set_property_fn): ...and since it is read-only now, chop
out the setter code.
* gui/component/select-names/e-select-names-text-model.h:
* gui/component/select-names/e-select-names-text-model.c: Again,
this code has been (pretty much) totally rewritten to convert all
text operations into changes on the ESelectNamesModel. This lets
us give the associated EEntry some (IMHO) nice semantics regarding
whitespace, etc. Includes object activation, so destinations tied
to ECards are underlined and can be double-clicked to bring up a
contact editor.
* gui/component/select-names/e-select-names-model.h:
* gui/component/select-names/e-select-names-model.c: I've heavily
modified this object to both hide all implementation details
(which the old version exposed a bit too much for my peculiar
tastes) and to act as an EDestination container. The old code put
the text model operations here. I've moved them all to
ESelectNamesTextModel --- so the text model actions (insert,
delete, etc.) are all done through the API rather than operating on
ESelectNamesModel internals.
* gui/component/select-names/e-select-names-completion.c: Added. A
fairly complicated object derived from ECompletion that searches
our local addressbook in various and sundry ways.
* gui/component/select-names/e-select-names-completion.h:
* backend/ebook/e-destination.h:
* backend/ebook/e-destination.c: Added. This object encapsulates
a place to sent an email to, which can either be just a address as
a string ("trow@ximian.com"), a fancier string ("Jon Trowbridge
<trow@ximian.com>"), or an ECard and a specific address within
that ECard.
svn path=/trunk/; revision=8459
Diffstat (limited to 'addressbook/gui/component/select-names/e-select-names-manager.c')
-rw-r--r-- | addressbook/gui/component/select-names/e-select-names-manager.c | 105 |
1 files changed, 62 insertions, 43 deletions
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 3e629af19d..e1c8d80276 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -16,8 +16,9 @@ #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 "e-select-names-completion.h" #include <gal/e-text/e-entry.h> +#include <addressbook/backend/ebook/e-destination.h> /* Object argument IDs */ enum { @@ -213,9 +214,10 @@ e_select_names_manager_init (ESelectNamesManager *manager) manager->entries = e_list_new(entry_copy, entry_free, manager); } -void e_select_names_manager_add_section (ESelectNamesManager *manager, - const char *id, - const char *title) +void +e_select_names_manager_add_section (ESelectNamesManager *manager, + const char *id, + const char *title) { ESelectNamesManagerSection *section; @@ -227,6 +229,25 @@ void e_select_names_manager_add_section ( section_free(section, manager); } +ESelectNamesModel * +e_select_names_manager_get_source (ESelectNamesManager *manager, const char *id) +{ + EIterator *iterator; + + g_return_val_if_fail (manager && E_IS_SELECT_NAMES_MANAGER (manager), NULL); + g_return_val_if_fail (id, NULL); + + iterator = e_list_get_iterator (manager->sections); + for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) { + const ESelectNamesManagerSection *section = e_iterator_get (iterator); + if (!strcmp (section->id, id)) { + return section->model; + } + } + + return NULL; +} + static void entry_destroyed(EEntry *entry, ESelectNamesManager *manager) { @@ -246,31 +267,30 @@ entry_destroyed(EEntry *entry, ESelectNamesManager *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; + ESelectNamesModel *snm; + EDestination *dest; + gint i, pos, start_pos, len; - 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); -} + if (user_data == NULL) + return; -static void -set_completion (EBook *book, EBookStatus status, EEntry *entry) -{ - ECompletion *addr_comp; + snm = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model")); + dest = E_DESTINATION (user_data); + + /* Sometimes I really long for garbage collection. Reference + counting makes you feel 31337, but sometimes it is just a + bitch. */ + gtk_object_ref (GTK_OBJECT (dest)); - addr_comp = e_address_completion_new (book); - e_entry_enable_completion_full (entry, addr_comp, -1, completion_handler); - gtk_object_unref (GTK_OBJECT (book)); + pos = e_entry_get_position (entry); + e_select_names_model_text_pos (snm, pos, &i, NULL, NULL); + e_select_names_model_replace (snm, i, dest); + e_select_names_model_name_pos (snm, i, &start_pos, &len); + e_entry_set_position (entry, start_pos+len); } -GtkWidget *e_select_names_manager_create_entry (ESelectNamesManager *manager, - const char *id) +GtkWidget * +e_select_names_manager_create_entry (ESelectNamesManager *manager, const char *id) { ETextModel *model; EIterator *iterator; @@ -280,27 +300,22 @@ GtkWidget *e_select_names_manager_create_entry ( if (!strcmp(section->id, id)) { ESelectNamesManagerEntry *entry; EEntry *eentry; - 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); + ECompletion *comp; + + eentry = E_ENTRY (e_entry_new ()); + gtk_object_set_data (GTK_OBJECT (eentry), "select_names_model", section->model); - entry = g_new(ESelectNamesManagerEntry, 1); + 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); + model = e_select_names_text_model_new (section->model); + e_list_append (manager->entries, entry); g_free(entry); + comp = e_select_names_completion_new (NULL, section->model); /* NULL == use local addressbook */ + e_entry_enable_completion_full (eentry, comp, 50, completion_handler); + gtk_object_set(GTK_OBJECT(eentry), "model", model, "editable", TRUE, @@ -356,8 +371,9 @@ e_select_names_clicked(ESelectNames *dialog, gint button, ESelectNamesManager *m gnome_dialog_close(GNOME_DIALOG(dialog)); } -void e_select_names_manager_activate_dialog (ESelectNamesManager *manager, - const char *id) +void +e_select_names_manager_activate_dialog (ESelectNamesManager *manager, + const char *id) { EIterator *iterator; @@ -386,9 +402,11 @@ void e_select_names_manager_activate_dialog ( } } +#if 0 /* Of type ECard */ -EList *e_select_names_manager_get_cards (ESelectNamesManager *manager, - const char *id) +EList * +e_select_names_manager_get_cards (ESelectNamesManager *manager, + const char *id) { EIterator *iterator; iterator = e_list_get_iterator(manager->sections); @@ -400,3 +418,4 @@ EList *e_select_names_manager_get_cards (ESel } return NULL; } +#endif |