[evolution] Bug 783908 - Prefill new contact lists with mails from selected contacts



commit 6eba67332184e6c135b65e971531427b15c8f15e
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 29 16:11:00 2017 +0200

    Bug 783908 - Prefill new contact lists with mails from selected contacts

 src/modules/addressbook/e-book-shell-backend.c     |    4 +
 .../addressbook/e-book-shell-view-actions.c        |    3 +
 src/modules/addressbook/e-book-shell-view.c        |  102 ++++++++++++++++++++
 src/modules/addressbook/e-book-shell-view.h        |    3 +
 4 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/src/modules/addressbook/e-book-shell-backend.c b/src/modules/addressbook/e-book-shell-backend.c
index f908224..99884e6 100644
--- a/src/modules/addressbook/e-book-shell-backend.c
+++ b/src/modules/addressbook/e-book-shell-backend.c
@@ -153,6 +153,10 @@ book_shell_backend_new_contact_list_cb (GObject *source_object,
 
        contact = e_contact_new ();
 
+       e_book_shell_view_maybe_prefill_list_with_selection (
+               e_shell_window_get_shell_view (shell_window,
+               e_shell_window_get_active_view (shell_window)), contact);
+
        editor = e_contact_list_editor_new (
                e_shell_window_get_shell (shell_window), E_BOOK_CLIENT (client), contact, TRUE, TRUE);
        gtk_window_set_transient_for (eab_editor_get_window (editor), GTK_WINDOW (shell_window));
diff --git a/src/modules/addressbook/e-book-shell-view-actions.c 
b/src/modules/addressbook/e-book-shell-view-actions.c
index e9eb7e1..fabfbc9 100644
--- a/src/modules/addressbook/e-book-shell-view-actions.c
+++ b/src/modules/addressbook/e-book-shell-view-actions.c
@@ -737,6 +737,9 @@ action_contact_new_list_cb (GtkAction *action,
        g_return_if_fail (book != NULL);
 
        contact = e_contact_new ();
+
+       e_book_shell_view_maybe_prefill_list_with_selection (shell_view, contact);
+
        editor = e_contact_list_editor_new (shell, book, contact, TRUE, TRUE);
        gtk_window_set_transient_for (eab_editor_get_window (editor), GTK_WINDOW (shell_window));
        eab_editor_show (editor);
diff --git a/src/modules/addressbook/e-book-shell-view.c b/src/modules/addressbook/e-book-shell-view.c
index f8281a5..8f2da6b 100644
--- a/src/modules/addressbook/e-book-shell-view.c
+++ b/src/modules/addressbook/e-book-shell-view.c
@@ -427,3 +427,105 @@ e_book_shell_view_enable_searching (EBookShellView *book_shell_view)
 
        priv->search_locked--;
 }
+
+typedef struct _AddToListData {
+       EAddressbookModel *model;
+       EContact *list_contact;
+       gboolean any_added;
+} AddToListData;
+
+static void
+book_shell_view_add_to_list_cb (gint row,
+                               gpointer user_data)
+{
+       AddToListData *atld = user_data;
+       EContact *contact;
+
+       g_return_if_fail (atld != NULL);
+
+       contact = e_addressbook_model_get_contact (atld->model, row);
+       if (contact) {
+               EBookClient *book_client = e_addressbook_model_get_client (atld->model);
+               GList *emails;
+               gint ii, len;
+               gboolean is_list;
+
+               emails = e_contact_get (contact, E_CONTACT_EMAIL);
+               len = g_list_length (emails);
+               g_list_free_full (emails, g_free);
+
+               is_list = e_contact_get (contact, E_CONTACT_IS_LIST) != NULL;
+
+               if (len > 0) {
+                       EDestination *dest;
+                       EVCardAttribute *attr;
+                       EVCard *vcard = E_VCARD (atld->list_contact);
+
+                       if (is_list)
+                               e_contact_set (contact, E_CONTACT_IS_LIST, GINT_TO_POINTER (FALSE));
+
+                       atld->any_added = TRUE;
+
+                       for (ii = 0; ii < len; ii++) {
+                               dest = e_destination_new ();
+
+                               if (book_client)
+                                       e_destination_set_client (dest, book_client);
+
+                               e_destination_set_contact (dest, contact, ii);
+
+                               attr = e_vcard_attribute_new (NULL, EVC_EMAIL);
+                               e_destination_export_to_vcard_attribute (dest, attr);
+
+                               e_vcard_append_attribute (vcard, attr);
+
+                               g_object_unref (dest);
+                       }
+
+                       if (is_list)
+                               e_contact_set (contact, E_CONTACT_IS_LIST, GINT_TO_POINTER (TRUE));
+               }
+
+               g_object_unref (contact);
+       }
+}
+
+void
+e_book_shell_view_maybe_prefill_list_with_selection (EShellView *shell_view,
+                                                    EContact *contact)
+{
+       EBookShellView *book_shell_view;
+       EBookShellContent *book_shell_content;
+       EAddressbookView *current_view;
+       ESelectionModel *selection_model;
+       gint n_selected;
+
+       g_return_if_fail (E_IS_CONTACT (contact));
+
+       if (!E_IS_BOOK_SHELL_VIEW (shell_view))
+               return;
+
+       book_shell_view = E_BOOK_SHELL_VIEW (shell_view);
+       book_shell_content = book_shell_view->priv->book_shell_content;
+       current_view = e_book_shell_content_get_current_view (book_shell_content);
+
+       if (!current_view)
+               return;
+
+       selection_model = e_addressbook_view_get_selection_model (current_view);
+
+       n_selected = selection_model ? e_selection_model_selected_count (selection_model) : 0;
+
+       if (n_selected >= 1) {
+               AddToListData atld;
+
+               atld.model = e_addressbook_view_get_model (current_view);
+               atld.list_contact = contact;
+               atld.any_added = FALSE;
+
+               e_selection_model_foreach (selection_model, book_shell_view_add_to_list_cb, &atld);
+
+               if (atld.any_added)
+                       e_contact_set (contact, E_CONTACT_IS_LIST, GINT_TO_POINTER (TRUE));
+       }
+}
diff --git a/src/modules/addressbook/e-book-shell-view.h b/src/modules/addressbook/e-book-shell-view.h
index a9c0c7a..587cf9d 100644
--- a/src/modules/addressbook/e-book-shell-view.h
+++ b/src/modules/addressbook/e-book-shell-view.h
@@ -62,6 +62,9 @@ void          e_book_shell_view_type_register (GTypeModule *type_module);
 
 void           e_book_shell_view_disable_searching (EBookShellView *book_shell_view);
 void           e_book_shell_view_enable_searching (EBookShellView *book_shell_view);
+void           e_book_shell_view_maybe_prefill_list_with_selection
+                                               (EShellView *shell_view,
+                                                EContact *contact);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]