aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/contact-list-editor/e-contact-list-model.c
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui/contact-list-editor/e-contact-list-model.c')
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-model.c162
1 files changed, 91 insertions, 71 deletions
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-model.c b/addressbook/gui/contact-list-editor/e-contact-list-model.c
index 1a0cc6d0b6..63e0f59105 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-model.c
+++ b/addressbook/gui/contact-list-editor/e-contact-list-model.c
@@ -31,6 +31,15 @@
static gpointer parent_class;
+G_DEFINE_TYPE (EContactListModel, e_contact_list_model, GTK_TYPE_TREE_STORE);
+
+struct _EContactListModelPrivate {
+
+ GHashTable *uids_table;
+ GHashTable *emails_table;
+
+};
+
static gboolean
contact_list_get_iter (EContactListModel *model,
GtkTreeIter *iter,
@@ -61,38 +70,51 @@ contact_list_model_constructor (GType type,
object = G_OBJECT_CLASS (parent_class)->constructor (
type, n_construct_properties, construct_properties);
- gtk_list_store_set_column_types (
- GTK_LIST_STORE (object), G_N_ELEMENTS (types), types);
+ gtk_tree_store_set_column_types (
+ GTK_TREE_STORE (object), G_N_ELEMENTS (types), types);
return object;
}
static void
-contact_list_model_class_init (EContactListModelClass *class)
+contact_list_model_dispose (GObject *object)
+{
+ EContactListModelPrivate *priv = E_CONTACT_LIST_MODEL (object)->priv;
+
+ if (priv->uids_table) {
+ g_hash_table_unref (priv->uids_table);
+ priv->uids_table = NULL;
+ }
+
+ if (priv->emails_table) {
+ g_hash_table_unref (priv->emails_table);
+ priv->emails_table = NULL;
+ }
+
+ G_OBJECT_CLASS (e_contact_list_model_parent_class)->dispose (object);
+}
+
+static void
+e_contact_list_model_class_init (EContactListModelClass *class)
{
GObjectClass *object_class;
+ g_type_class_add_private (class, sizeof (EContactListModelPrivate));
+
parent_class = g_type_class_peek_parent (class);
object_class = G_OBJECT_CLASS (class);
object_class->constructor = contact_list_model_constructor;
+ object_class->dispose = contact_list_model_dispose;
}
-GType
-e_contact_list_model_get_type (void)
+static void
+e_contact_list_model_init (EContactListModel *model)
{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0))
- type = g_type_register_static_simple (
- GTK_TYPE_LIST_STORE,
- "EContactListModel",
- sizeof (EContactListModelClass),
- (GClassInitFunc) contact_list_model_class_init,
- sizeof (EContactListModel),
- (GInstanceInitFunc) NULL, 0);
-
- return type;
+ model->priv = G_TYPE_INSTANCE_GET_PRIVATE (model, E_TYPE_CONTACT_LIST_MODEL, EContactListModelPrivate);
+
+ model->priv->uids_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ model->priv->emails_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
GtkTreeModel *
@@ -105,64 +127,51 @@ gboolean
e_contact_list_model_has_email (EContactListModel *model,
const gchar *email)
{
- GtkTreeIter iter;
- gboolean iter_valid;
- gboolean has_email = FALSE;
-
- g_return_val_if_fail (E_IS_CONTACT_LIST_MODEL (model), FALSE);
- g_return_val_if_fail (email != NULL, FALSE);
-
- iter_valid = gtk_tree_model_get_iter_first (
- GTK_TREE_MODEL (model), &iter);
-
- while (!has_email && iter_valid) {
- EDestination *destination;
- const gchar *textrep;
-
- gtk_tree_model_get (
- GTK_TREE_MODEL (model), &iter, 0, &destination, -1);
- textrep = e_destination_get_textrep (destination, TRUE);
- has_email = (strcmp (email, textrep) == 0);
- g_object_unref (destination);
-
- iter_valid = gtk_tree_model_iter_next (
- GTK_TREE_MODEL (model), &iter);
- }
+ return (g_hash_table_lookup (model->priv->emails_table, email) != NULL);
+}
- return has_email;
+gboolean
+e_contact_list_model_has_uid (EContactListModel *model,
+ const gchar* uid)
+{
+ return (g_hash_table_lookup (model->priv->uids_table, uid) != NULL);
}
-void
+GtkTreePath*
e_contact_list_model_add_destination (EContactListModel *model,
- EDestination *destination)
+ EDestination *destination,
+ GtkTreeIter *parent)
{
GtkTreeIter iter;
+ GtkTreePath *path;
- g_return_if_fail (E_IS_CONTACT_LIST_MODEL (model));
- g_return_if_fail (E_IS_DESTINATION (destination));
+ g_return_val_if_fail (E_IS_CONTACT_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (E_IS_DESTINATION (destination), NULL);
- gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, destination, -1);
-}
+ gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, destination, -1);
-void
-e_contact_list_model_add_email (EContactListModel *model,
- const gchar *email)
-{
- const gchar *tag = "addressbook:ask-list-add-exists";
- EDestination *destination;
+ if (e_destination_is_evolution_list (destination)) {
+ const GList *dest, *dests = e_destination_list_get_root_dests (destination);
- g_return_if_fail (E_IS_CONTACT_LIST_MODEL (model));
- g_return_if_fail (email != NULL);
+ g_hash_table_insert (model->priv->uids_table,
+ g_strdup (e_destination_get_contact_uid (destination)),
+ destination);
- if (e_contact_list_model_has_email (model, email))
- if (e_alert_run_dialog_for_args (e_shell_get_active_window
- (NULL), tag, email, NULL) != GTK_RESPONSE_YES)
- return;
+ for (dest = dests; dest; dest = dest->next) {
+ path = e_contact_list_model_add_destination (model, dest->data, &iter);
+ if (dest->next)
+ gtk_tree_path_free (path);
+ }
+ } else {
+ g_hash_table_insert (model->priv->emails_table,
+ g_strdup (e_destination_get_email (destination)),
+ destination);
- destination = e_destination_new ();
- e_destination_set_email (destination, email);
- e_contact_list_model_add_destination (model, destination);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ }
+
+ return path;
}
void
@@ -177,22 +186,30 @@ e_contact_list_model_add_contact (EContactListModel *model,
destination = e_destination_new ();
e_destination_set_contact (destination, contact, email_num);
- e_contact_list_model_add_destination (model, destination);
+ e_contact_list_model_add_destination (model, destination, NULL);
}
void
e_contact_list_model_remove_row (EContactListModel *model,
- gint row)
+ GtkTreeIter *iter)
{
- GtkTreeIter iter;
- gboolean iter_valid;
+ EDestination *dest;
g_return_if_fail (E_IS_CONTACT_LIST_MODEL (model));
+ g_return_if_fail (iter);
- iter_valid = contact_list_get_iter (model, &iter, row);
- g_return_if_fail (iter_valid);
+ gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 0, &dest, -1);
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+ if (e_destination_is_evolution_list (dest)) {
+ const gchar *uid = e_destination_get_contact_uid (dest);
+ g_hash_table_remove (model->priv->uids_table, uid);
+ } else {
+ const gchar *email = e_destination_get_email (dest);
+ g_hash_table_remove (model->priv->emails_table, email);
+ }
+
+ g_object_unref (dest);
+ gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
}
void
@@ -200,7 +217,10 @@ e_contact_list_model_remove_all (EContactListModel *model)
{
g_return_if_fail (E_IS_CONTACT_LIST_MODEL (model));
- gtk_list_store_clear (GTK_LIST_STORE (model));
+ g_hash_table_remove_all (model->priv->uids_table);
+ g_hash_table_remove_all (model->priv->emails_table);
+
+ gtk_tree_store_clear (GTK_TREE_STORE (model));
}
EDestination *