diff options
Diffstat (limited to 'addressbook/gui/component/select-names')
5 files changed, 171 insertions, 6 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 25adf13a65..90b3e477fb 100644 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.c +++ b/addressbook/gui/component/select-names/e-select-names-bonobo.c @@ -132,8 +132,15 @@ entry_set_property_fn (BonoboPropertyBag *bag, switch (arg_id) { case ENTRY_PROPERTY_ID_TEXT: - e_entry_set_text (E_ENTRY (w), BONOBO_ARG_GET_STRING (arg)); - break; + { + ESelectNamesModel *model; + model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (w), "select_names_model")); + g_assert (model != NULL); + + e_entry_set_text (E_ENTRY (w), BONOBO_ARG_GET_STRING (arg)); + e_select_names_model_cardify_all (model, NULL, 0); + break; + } case ENTRY_PROPERTY_ID_DESTINATIONS: { 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 4481438327..0bec7da416 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -368,6 +368,38 @@ popup_cb (EEntry *entry, GdkEventButton *ev, gint pos, ESelectNamesModel *model) e_select_names_popup (model, ev, pos); } +static gint +focus_in_cb (GtkWidget *w, GdkEventFocus *ev, gpointer user_data) +{ + EEntry *entry = E_ENTRY (user_data); + ESelectNamesModel *model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model")); + + e_select_names_model_cancel_cardify_all (model); + + return FALSE; +} + +static gint +focus_out_cb (GtkWidget *w, GdkEventFocus *ev, gpointer user_data) +{ + EEntry *entry = E_ENTRY (user_data); + ESelectNamesModel *model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model")); + + if (!e_entry_completion_popup_is_visible (entry)) + e_select_names_model_cardify_all (model, NULL, 0); + + return FALSE; +} + +static void +completion_popup_cb (EEntry *entry, gint visible, gpointer user_data) +{ + ESelectNamesModel *model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model")); + + if (!visible && !GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (entry->canvas))) + e_select_names_model_cardify_all (model, NULL, 0); +} + GtkWidget * e_select_names_manager_create_entry (ESelectNamesManager *manager, const char *id) { @@ -389,6 +421,19 @@ e_select_names_manager_create_entry (ESelectNamesManager *manager, const char *i GTK_SIGNAL_FUNC (popup_cb), section->model); + gtk_signal_connect (GTK_OBJECT (eentry->canvas), + "focus_in_event", + GTK_SIGNAL_FUNC (focus_in_cb), + eentry); + gtk_signal_connect (GTK_OBJECT (eentry->canvas), + "focus_out_event", + GTK_SIGNAL_FUNC (focus_out_cb), + eentry); + gtk_signal_connect (GTK_OBJECT (eentry), + "completion_popup", + GTK_SIGNAL_FUNC (completion_popup_cb), + NULL); + entry = g_new (ESelectNamesManagerEntry, 1); entry->entry = eentry; entry->id = (char *)id; 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 dc383994d3..9dda927640 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.c +++ b/addressbook/gui/component/select-names/e-select-names-model.c @@ -219,6 +219,12 @@ e_select_names_model_changed (ESelectNamesModel *model) gtk_signal_emit (GTK_OBJECT(model), e_select_names_model_signals[E_SELECT_NAMES_MODEL_CHANGED]); } +static void +destination_changed_proxy (EDestination *dest, gpointer closure) +{ + e_select_names_model_changed (E_SELECT_NAMES_MODEL (closure)); +} + /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ ESelectNamesModel * @@ -240,7 +246,7 @@ e_select_names_model_duplicate (ESelectNamesModel *old) for (iter = old->priv->data; iter != NULL; iter = g_list_next (iter)) { EDestination *dup = e_destination_copy (E_DESTINATION (iter->data)); - model->priv->data = g_list_append (model->priv->data, dup); + e_select_names_model_append (model, dup); } model->priv->limit = old->priv->limit; @@ -444,6 +450,21 @@ e_select_names_model_get_string (ESelectNamesModel *model, gint index) return dest ? e_destination_get_textrep (dest) : ""; } +static void +connect_destination (ESelectNamesModel *model, EDestination *dest) +{ + gtk_signal_connect (GTK_OBJECT (dest), + "changed", + destination_changed_proxy, + model); +} + +static void +disconnect_destination (ESelectNamesModel *model, EDestination *dest) +{ + gtk_signal_disconnect_by_func (GTK_OBJECT (dest), destination_changed_proxy, model); +} + void e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest) { @@ -458,6 +479,8 @@ e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination return; } + connect_destination (model, dest); + model->priv->data = g_list_insert (model->priv->data, dest, index); gtk_object_ref (GTK_OBJECT (dest)); @@ -478,6 +501,8 @@ e_select_names_model_append (ESelectNamesModel *model, EDestination *dest) return; } + connect_destination (model, dest); + model->priv->data = g_list_append (model->priv->data, dest); gtk_object_ref (GTK_OBJECT (dest)); @@ -503,6 +528,8 @@ e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination if (model->priv->data == NULL) { + connect_destination (model, dest); + model->priv->data = g_list_append (model->priv->data, dest); gtk_object_ref (GTK_OBJECT (dest)); gtk_object_sink (GTK_OBJECT (dest)); @@ -513,6 +540,9 @@ e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination if (node->data != dest) { + disconnect_destination (model, E_DESTINATION (node->data)); + connect_destination (model, dest); + old_str = e_destination_get_textrep (E_DESTINATION (node->data)); old_strlen = old_str ? strlen (old_str) : 0; @@ -540,6 +570,7 @@ e_select_names_model_delete (ESelectNamesModel *model, gint index) g_return_if_fail (0 <= index && index < g_list_length (model->priv->data)); node = g_list_nth (model->priv->data, index); + disconnect_destination (model, E_DESTINATION (node->data)); gtk_object_unref (GTK_OBJECT (node->data)); model->priv->data = g_list_remove_link (model->priv->data, node); @@ -565,8 +596,10 @@ e_select_names_model_clean (ESelectNamesModel *model) dest = iter->data ? E_DESTINATION (iter->data) : NULL; if (dest == NULL || e_destination_is_empty (dest)) { - if (dest) + if (dest) { + disconnect_destination (model, dest); gtk_object_unref (GTK_OBJECT (dest)); + } model->priv->data = g_list_remove_link (model->priv->data, iter); g_list_free_1 (iter); changed = TRUE; @@ -579,12 +612,19 @@ e_select_names_model_clean (ESelectNamesModel *model) e_select_names_model_changed (model); } +static void +delete_all_iter (gpointer data, gpointer closure) +{ + disconnect_destination (E_SELECT_NAMES_MODEL (closure), E_DESTINATION (data)); + gtk_object_unref (GTK_OBJECT (data)); +} + void e_select_names_model_delete_all (ESelectNamesModel *model) { g_return_if_fail (model != NULL && E_IS_SELECT_NAMES_MODEL (model)); - g_list_foreach (model->priv->data, (GFunc) gtk_object_unref, NULL); + g_list_foreach (model->priv->data, delete_all_iter, model); g_list_free (model->priv->data); model->priv->data = NULL; @@ -692,3 +732,70 @@ e_select_names_model_text_pos (ESelectNamesModel *model, gint pos, gint *index, if (length) *length = len; } + +void +e_select_names_model_cardify (ESelectNamesModel *model, EBook *book, gint index, gint delay) +{ + EDestination *dest; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); + g_return_if_fail (book == NULL || E_IS_BOOK (book)); + g_return_if_fail (0 <= index && index < g_list_length (model->priv->data)); + + dest = E_DESTINATION (g_list_nth_data (model->priv->data, index)); + + if (!e_destination_is_empty (dest)) { + + if (delay > 0) + e_destination_cardify_delayed (dest, book, delay); + else + e_destination_cardify (dest, book); + } +} + +void +e_select_names_model_cancel_cardify (ESelectNamesModel *model, gint index) +{ + EDestination *dest; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); + g_return_if_fail (0 <= index && index < g_list_length (model->priv->data)); + + dest = E_DESTINATION (g_list_nth_data (model->priv->data, index)); + + e_destination_cancel_cardify (dest); +} + +void +e_select_names_model_cardify_all (ESelectNamesModel *model, EBook *book, gint delay) +{ + GList *iter; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); + g_return_if_fail (book == NULL || E_IS_BOOK (book)); + + for (iter = model->priv->data; iter != NULL; iter = g_list_next (iter)) { + EDestination *dest = E_DESTINATION (iter->data); + if (!e_destination_is_empty (dest)) { + + if (delay > 0) + e_destination_cardify_delayed (dest, book, delay); + else + e_destination_cardify (dest, book); + } + } +} + +void +e_select_names_model_cancel_cardify_all (ESelectNamesModel *model) +{ + GList *iter; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); + + for (iter = model->priv->data; iter != NULL; iter = g_list_next (iter)) { + EDestination *dest = E_DESTINATION (iter->data); + e_destination_cancel_cardify (dest); + } +} + 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 b11e9503ec..9f89e91093 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.h +++ b/addressbook/gui/component/select-names/e-select-names-model.h @@ -73,4 +73,10 @@ void e_select_names_model_clean (ESelectNamesModel *model); void e_select_names_model_name_pos (ESelectNamesModel *model, gint index, gint *pos, gint *length); void e_select_names_model_text_pos (ESelectNamesModel *model, gint pos, gint *index, gint *start_pos, gint *length); +void e_select_names_model_cardify (ESelectNamesModel *model, EBook *book, gint index, gint delay); +void e_select_names_model_cancel_cardify (ESelectNamesModel *model, gint index); +void e_select_names_model_cardify_all (ESelectNamesModel *model, EBook *book, gint delay); +void e_select_names_model_cancel_cardify_all (ESelectNamesModel *model); + + #endif /* ! __E_SELECT_NAMES_MODEL_H__ */ 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 11b3b67323..2f10516dd1 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 @@ -423,7 +423,7 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha EDestination *dest = e_destination_new (); e_destination_set_raw (dest, new_str); - + e_select_names_model_replace (source, index, dest); if (this_length > 0) { |