aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r--addressbook/gui/component/Makefile.am5
-rw-r--r--addressbook/gui/component/addressbook.c338
-rw-r--r--addressbook/gui/component/e-book-shell-content.c14
-rw-r--r--addressbook/gui/component/e-book-shell-content.h7
-rw-r--r--addressbook/gui/component/e-book-shell-module.c11
-rw-r--r--addressbook/gui/component/e-book-shell-view-actions.c48
-rw-r--r--addressbook/gui/component/e-book-shell-view-private.c29
-rw-r--r--addressbook/gui/component/e-book-shell-view-private.h14
-rw-r--r--addressbook/gui/component/eab-composer-util.c214
-rw-r--r--addressbook/gui/component/eab-composer-util.h (renamed from addressbook/gui/component/addressbook.h)25
10 files changed, 339 insertions, 366 deletions
diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am
index 9bfdabe13d..0e4747f2a5 100644
--- a/addressbook/gui/component/Makefile.am
+++ b/addressbook/gui/component/Makefile.am
@@ -30,8 +30,8 @@ libevolution_addressbook_la_SOURCES = \
addressbook-config.h \
autocompletion-config.c \
autocompletion-config.h \
- addressbook.c \
- addressbook.h \
+ eab-composer-util.c \
+ eab-composer-util.h \
e-book-shell-content.c \
e-book-shell-content.h \
e-book-shell-module.c \
@@ -53,6 +53,7 @@ endif
libevolution_addressbook_la_LIBADD = \
$(SMIME_LIB) \
$(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/composer/libcomposer.la \
$(top_builddir)/addressbook/printing/libecontactprint.la \
$(top_builddir)/shell/libeshell.la \
$(top_builddir)/addressbook/gui/merging/libeabbookmerging.la \
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
deleted file mode 100644
index c8285d8171..0000000000
--- a/addressbook/gui/component/addressbook.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with the program; if not, see <http://www.gnu.org/licenses/>
- *
- *
- * Authors:
- * Chris Lahey <clahey@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
- */
-
-#include <config.h>
-
-#include <string.h>
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <libebook/e-book.h>
-#include <libedataserver/e-url.h>
-#include <libedataserverui/e-passwords.h>
-
-#include "e-util/e-error.h"
-#include "addressbook.h"
-
-#define d(x)
-
-static void addressbook_authenticate (EBook *book, gboolean previous_failure,
- ESource *source, EBookCallback cb, gpointer closure);
-static void auth_required_cb (EBook *book, gpointer data);
-
-typedef struct {
- EBookCallback cb;
- ESource *source;
- gpointer closure;
- guint cancelled : 1;
-} LoadSourceData;
-
-static void
-free_load_source_data (LoadSourceData *data)
-{
- if (data->source)
- g_object_unref (data->source);
- g_free (data);
-}
-
-/*this function removes of anything present after semicolon
-in uri*/
-
-static gchar*
-remove_parameters_from_uri (const gchar *uri)
-{
- char *euri_str;
- EUri *euri;
-
- euri = e_uri_new (uri);
- euri_str = e_uri_to_string (euri, FALSE);
- e_uri_free (euri);
- return euri_str;
-}
-
-static void
-load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- LoadSourceData *data = closure;
- gboolean was_in = g_object_get_data (G_OBJECT (book), "authenticated") != NULL;
-
- g_object_set_data (G_OBJECT (book), "authenticated", NULL);
-
- if (data->cancelled) {
- free_load_source_data (data);
- return;
- }
-
- if (status != E_BOOK_ERROR_OK) {
-
- /* the user clicked cancel in the password dialog */
- if (status == E_BOOK_ERROR_CANCELLED) {
-
- if (e_book_check_static_capability (book, "anon-access")) {
-
- GtkWidget *dialog;
-
- /* XXX "LDAP" has to be removed from the folowing message
- so that it wil valid for other servers which provide
- anonymous access*/
-
- dialog = gtk_message_dialog_new (NULL,
- 0,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "%s", _("Accessing LDAP Server anonymously"));
- g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
- gtk_widget_show (dialog);
- status = E_BOOK_ERROR_OK;
-
- goto done;
- }
- } else if (status == E_BOOK_ERROR_INVALID_SERVER_VERSION) {
- e_error_run (NULL, "addressbook:server-version", NULL);
- status = E_BOOK_ERROR_OK;
- goto done;
- } else if (status == E_BOOK_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD) {
- goto done;
- } else {
- if (status == E_BOOK_ERROR_AUTHENTICATION_FAILED) {
- const gchar *uri = e_book_get_uri (book);
- gchar *stripped_uri = remove_parameters_from_uri (uri);
- const gchar *auth_domain = e_source_get_property (data->source, "auth-domain");
- const gchar *component_name;
-
- component_name = auth_domain ? auth_domain : "Addressbook";
-
- e_passwords_forget_password (component_name, stripped_uri);
-
- g_free (stripped_uri);
- } else if (was_in) {
- /* We already tried to authenticate to the server, and it failed with
- other reason than with E_BOOK_ERROR_AUTHENTICATION_FAILED, thus stop
- poking with the server and report error to the user. */
- goto done;
- }
-
- g_object_set_data (G_OBJECT (book), "authenticated", GINT_TO_POINTER (1));
- addressbook_authenticate (book, TRUE, data->source, load_source_auth_cb, closure);
- return;
- }
- }
-
-done:
- if (data->cb)
- data->cb (book, status, data->closure);
-
- free_load_source_data (data);
-}
-
-static gboolean
-get_remember_password (ESource *source)
-{
- const gchar *value;
-
- value = e_source_get_property (source, "remember_password");
- if (value && !g_ascii_strcasecmp (value, "true"))
- return TRUE;
-
- return FALSE;
-}
-
-static void
-set_remember_password (ESource *source, gboolean value)
-{
- e_source_set_property (source, "remember_password",
- value ? "true" : "false");
-}
-
-static void
-addressbook_authenticate (EBook *book, gboolean previous_failure, ESource *source,
- EBookCallback cb, gpointer closure)
-{
- const char *password = NULL;
- char *pass_dup = NULL;
- const gchar *auth;
- const gchar *user;
- gchar *uri = remove_parameters_from_uri(e_book_get_uri (book));
- const gchar *auth_domain = e_source_get_property (source, "auth-domain");
- const gchar *component_name;
-
- component_name = auth_domain ? auth_domain : "Addressbook";
-
- password = e_passwords_get_password (component_name, uri);
-
- auth = e_source_get_property (source, "auth");
-
- if (auth && !strcmp ("ldap/simple-binddn", auth)) {
- user = e_source_get_property (source, "binddn");
- }
- else if (auth && !strcmp ("plain/password", auth)) {
- user = e_source_get_property (source, "user");
- if (!user) {
- user = e_source_get_property (source, "username");
- }
- }
- else {
- user = e_source_get_property (source, "email_addr");
- }
- if (!user)
- user = "";
-
- if (!password) {
- char *prompt;
- char *password_prompt;
- gboolean remember;
- char *failed_auth;
- guint32 flags = E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET|E_PASSWORDS_ONLINE;
-
- if (previous_failure) {
- failed_auth = _("Failed to authenticate.\n");
- flags |= E_PASSWORDS_REPROMPT;
- }
- else {
- failed_auth = "";
- }
-
- password_prompt = g_strdup_printf (_("Enter password for %s (user %s)"),
- e_source_peek_name (source), user);
-
- prompt = g_strconcat (failed_auth, password_prompt, NULL);
- g_free (password_prompt);
-
- remember = get_remember_password (source);
- pass_dup = e_passwords_ask_password (
- _("Enter password"), component_name,
- uri, prompt, flags, &remember, NULL);
- if (remember != get_remember_password (source))
- set_remember_password (source, remember);
-
- g_free (prompt);
- }
-
- if (password || pass_dup) {
- e_book_async_authenticate_user (book, user, password ? password : pass_dup,
- e_source_get_property (source, "auth"),
- cb, closure);
- g_free (pass_dup);
- }
- else {
- /* they hit cancel */
- cb (book, E_BOOK_ERROR_CANCELLED, closure);
- }
-
- g_free (uri);
-}
-
-
-
-static void
-auth_required_cb (EBook *book, gpointer data)
-{
- LoadSourceData *load_source_data = g_new0(LoadSourceData, 1);
-
- load_source_data->source = g_object_ref (g_object_ref (e_book_get_source (book)));
- load_source_data->cancelled = FALSE;
- addressbook_authenticate (book, FALSE, load_source_data->source,
- load_source_auth_cb, load_source_data);
-
-
-
-}
-static void
-load_source_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- LoadSourceData *load_source_data = closure;
-
- if (load_source_data->cancelled) {
- free_load_source_data (load_source_data);
- return;
- }
-
- if (status == E_BOOK_ERROR_OK && book != NULL) {
- const gchar *auth;
-
- auth = e_source_get_property (load_source_data->source, "auth");
- if (auth && strcmp (auth, "none")) {
- g_signal_connect (book, "auth_required", G_CALLBACK(auth_required_cb), NULL);
-
- if (e_book_is_online (book)) {
- addressbook_authenticate (book, FALSE, load_source_data->source,
- load_source_auth_cb, closure);
- return;
- }
- }
- }
- load_source_data->cb (book, status, load_source_data->closure);
- free_load_source_data (load_source_data);
-}
-
-guint
-addressbook_load (EBook *book,
- EBookCallback cb, gpointer closure)
-{
- LoadSourceData *load_source_data = g_new0 (LoadSourceData, 1);
-
- load_source_data->cb = cb;
- load_source_data->closure = closure;
- load_source_data->source = g_object_ref (g_object_ref (e_book_get_source (book)));
- load_source_data->cancelled = FALSE;
-
- e_book_async_open (book, FALSE, load_source_cb, load_source_data);
-
- return GPOINTER_TO_UINT (load_source_data);
-}
-
-void
-addressbook_load_cancel (guint id)
-{
- LoadSourceData *load_source_data = GUINT_TO_POINTER (id);
-
- load_source_data->cancelled = TRUE;
-}
-
-static void
-default_book_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- LoadSourceData *load_source_data = closure;
-
- if (status == E_BOOK_ERROR_OK)
- load_source_data->source = g_object_ref (e_book_get_source (book));
-
- load_source_cb (book, status, closure);
-}
-
-void
-addressbook_load_default_book (EBookCallback cb, gpointer closure)
-{
- LoadSourceData *load_source_data = g_new (LoadSourceData, 1);
- EBook *book;
-
- load_source_data->cb = cb;
- load_source_data->source = NULL;
- load_source_data->closure = closure;
- load_source_data->cancelled = FALSE;
-
- book = e_book_new_default_addressbook (NULL);
- if (!book)
- load_source_cb (NULL, E_BOOK_ERROR_OTHER_ERROR, load_source_data); /* XXX we should just use a GError and it's error code here */
- else
- e_book_async_open (book, FALSE, default_book_cb, load_source_data);
-}
diff --git a/addressbook/gui/component/e-book-shell-content.c b/addressbook/gui/component/e-book-shell-content.c
index 8190a5958a..c9066c9ef1 100644
--- a/addressbook/gui/component/e-book-shell-content.c
+++ b/addressbook/gui/component/e-book-shell-content.c
@@ -44,6 +44,16 @@ enum {
static gpointer parent_class;
static void
+book_shell_content_send_message_cb (EBookShellContent *book_shell_content,
+ EDestination *destination,
+ EABContactDisplay *display)
+{
+ GList node = { destination, NULL, NULL };
+
+ eab_send_message (&node, EAB_DISPOSITION_AS_TO);
+}
+
+static void
book_shell_content_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -176,6 +186,10 @@ book_shell_content_constructed (GObject *object)
priv->preview = g_object_ref (widget);
gtk_widget_show (widget);
+ g_signal_connect_swapped (
+ priv->preview, "send-message",
+ book_shell_content_send_message_cb, object);
+
/* Bind GObject properties to GConf keys. */
bridge = gconf_bridge_get ();
diff --git a/addressbook/gui/component/e-book-shell-content.h b/addressbook/gui/component/e-book-shell-content.h
index 7f48503a88..e8fe856a86 100644
--- a/addressbook/gui/component/e-book-shell-content.h
+++ b/addressbook/gui/component/e-book-shell-content.h
@@ -24,10 +24,11 @@
#include <libebook/e-contact.h>
-#include <e-shell-content.h>
-#include <e-shell-view.h>
+#include "shell/e-shell-content.h"
+#include "shell/e-shell-view.h"
-#include <e-addressbook-view.h>
+#include "addressbook/gui/component/eab-composer-util.h"
+#include "addressbook/gui/widgets/e-addressbook-view.h"
/* Standard GObject macros */
#define E_TYPE_BOOK_SHELL_CONTENT \
diff --git a/addressbook/gui/component/e-book-shell-module.c b/addressbook/gui/component/e-book-shell-module.c
index fbe660b7b6..a3f8a7aea0 100644
--- a/addressbook/gui/component/e-book-shell-module.c
+++ b/addressbook/gui/component/e-book-shell-module.c
@@ -32,10 +32,12 @@
#include "shell/e-shell-window.h"
#include "e-util/e-import.h"
+#include "addressbook/gui/widgets/eab-gui-util.h"
+#include "addressbook/gui/contact-editor/e-contact-editor.h"
+#include "addressbook/gui/contact-list-editor/e-contact-list-editor.h"
#include "addressbook/importers/evolution-addressbook-importers.h"
#include <eab-config.h>
-#include <eab-gui-util.h>
#include <addressbook-config.h>
#include <autocompletion-config.h>
@@ -214,6 +216,7 @@ book_shell_module_book_loaded_cb (EBook *book,
{
EContact *contact;
GtkAction *action;
+ GtkWidget *editor;
const gchar *action_name;
/* XXX Handle errors better. */
@@ -225,10 +228,12 @@ book_shell_module_book_loaded_cb (EBook *book,
action_name = gtk_action_get_name (action);
if (strcmp (action_name, "contact-new") == 0)
- eab_show_contact_editor (book, contact, TRUE, TRUE);
+ editor = e_contact_editor_new (book, contact, TRUE, TRUE);
if (strcmp (action_name, "contact-new-list") == 0)
- eab_show_contact_list_editor (book, contact, TRUE, TRUE);
+ editor = e_contact_list_editor_new (book, contact, TRUE, TRUE);
+
+ eab_editor_show (EAB_EDITOR (editor));
g_object_unref (contact);
g_object_unref (book);
diff --git a/addressbook/gui/component/e-book-shell-view-actions.c b/addressbook/gui/component/e-book-shell-view-actions.c
index 15838f96bc..646715d88a 100644
--- a/addressbook/gui/component/e-book-shell-view-actions.c
+++ b/addressbook/gui/component/e-book-shell-view-actions.c
@@ -285,12 +285,30 @@ action_contact_forward_cb (GtkAction *action,
{
EBookShellContent *book_shell_content;
EAddressbookView *view;
+ GList *list, *iter;
book_shell_content = book_shell_view->priv->book_shell_content;
view = e_book_shell_content_get_current_view (book_shell_content);
g_return_if_fail (view != NULL);
- e_addressbook_view_send (view);
+ list = e_addressbook_view_get_selected (view);
+ g_return_if_fail (list != NULL);
+
+ /* Convert the list of contacts to a list of destinations. */
+ for (iter = list; iter != NULL; iter = iter->next) {
+ EContact *contact = iter->data;
+ EDestination *destination;
+
+ destination = e_destination_new ();
+ e_destination_set_contact (destination, contact, 0);
+ g_object_unref (contact);
+
+ iter->data = destination;
+ }
+
+ eab_send_message (list, EAB_DISPOSITION_AS_ATTACHMENT);
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
}
static void
@@ -315,6 +333,7 @@ action_contact_new_cb (GtkAction *action,
EAddressbookView *view;
EAddressbookModel *model;
EContact *contact;
+ GtkWidget *editor;
EBook *book;
book_shell_content = book_shell_view->priv->book_shell_content;
@@ -326,7 +345,8 @@ action_contact_new_cb (GtkAction *action,
g_return_if_fail (book != NULL);
contact = e_contact_new ();
- eab_show_contact_editor (book, contact, TRUE, TRUE);
+ editor = e_contact_editor_new (book, contact, TRUE, TRUE);
+ eab_editor_show (EAB_EDITOR (editor));
g_object_unref (contact);
}
@@ -338,6 +358,7 @@ action_contact_new_list_cb (GtkAction *action,
EAddressbookView *view;
EAddressbookModel *model;
EContact *contact;
+ GtkWidget *editor;
EBook *book;
book_shell_content = book_shell_view->priv->book_shell_content;
@@ -349,7 +370,8 @@ action_contact_new_list_cb (GtkAction *action,
g_return_if_fail (book != NULL);
contact = e_contact_new ();
- eab_show_contact_list_editor (book, contact, TRUE, TRUE);
+ editor = e_contact_list_editor_new (book, contact, TRUE, TRUE);
+ eab_editor_show (EAB_EDITOR (editor));
g_object_unref (contact);
}
@@ -445,12 +467,30 @@ action_contact_send_message_cb (GtkAction *action,
{
EBookShellContent *book_shell_content;
EAddressbookView *view;
+ GList *list, *iter;
book_shell_content = book_shell_view->priv->book_shell_content;
view = e_book_shell_content_get_current_view (book_shell_content);
g_return_if_fail (view != NULL);
- e_addressbook_view_send_to (view);
+ list = e_addressbook_view_get_selected (view);
+ g_return_if_fail (list != NULL);
+
+ /* Convert the list of contacts to a list of destinations. */
+ for (iter = list; iter != NULL; iter = iter->next) {
+ EContact *contact = iter->data;
+ EDestination *destination;
+
+ destination = e_destination_new ();
+ e_destination_set_contact (destination, contact, 0);
+ g_object_unref (contact);
+
+ iter->data = destination;
+ }
+
+ eab_send_message (list, EAB_DISPOSITION_AS_TO);
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
}
static void
diff --git a/addressbook/gui/component/e-book-shell-view-private.c b/addressbook/gui/component/e-book-shell-view-private.c
index c3eecb5a8a..90ebad94f8 100644
--- a/addressbook/gui/component/e-book-shell-view-private.c
+++ b/addressbook/gui/component/e-book-shell-view-private.c
@@ -27,6 +27,31 @@
#include <addressbook.h>
static void
+open_contact (EBookShellView *book_shell_view,
+ EContact *contact,
+ gboolean is_new_contact,
+ EAddressbookView *view)
+{
+ EAddressbookModel *model;
+ GtkWidget *editor;
+ EBook *book;
+ gboolean editable;
+
+ model = e_addressbook_view_get_model (view);
+ book = e_addressbook_model_get_book (model);
+ editable = e_addressbook_model_get_editable (model);
+
+ if (e_contact_get (contact, E_CONTACT_IS_LIST))
+ editor = e_contact_list_editor_new (
+ book, contact, is_new_contact, editable);
+ else
+ editor = e_contact_editor_new (
+ book, contact, is_new_contact, editable);
+
+ eab_editor_show (EAB_EDITOR (editor));
+}
+
+static void
popup_event (EBookShellView *book_shell_view,
GdkEventButton *event)
{
@@ -215,6 +240,10 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
g_object_ref (widget));
g_signal_connect_swapped (
+ widget, "open-contact",
+ G_CALLBACK (open_contact), book_shell_view);
+
+ g_signal_connect_swapped (
widget, "popup-event",
G_CALLBACK (popup_event), book_shell_view);
diff --git a/addressbook/gui/component/e-book-shell-view-private.h b/addressbook/gui/component/e-book-shell-view-private.h
index 0d7fd706f6..d53ced9440 100644
--- a/addressbook/gui/component/e-book-shell-view-private.h
+++ b/addressbook/gui/component/e-book-shell-view-private.h
@@ -32,15 +32,17 @@
#include <libedataserver/e-sexp.h>
#include <libedataserverui/e-source-selector.h>
-#include <e-util/gconf-bridge.h>
-#include <shell/e-shell-content.h>
-#include <shell/e-shell-sidebar.h>
+#include "e-util/gconf-bridge.h"
+#include "shell/e-shell-content.h"
+#include "shell/e-shell-sidebar.h"
+
+#include "addressbook/gui/contact-editor/e-contact-editor.h"
+#include "addressbook/gui/contact-list-editor/e-contact-list-editor.h"
+#include "addressbook/gui/widgets/eab-gui-util.h"
+#include "addressbook/gui/widgets/e-addressbook-view.h"
-#include <eab-gui-util.h>
-#include <e-addressbook-view.h>
#include <e-book-shell-content.h>
#include <e-book-shell-sidebar.h>
-
#include <e-book-shell-view-actions.h>
#define E_BOOK_SHELL_VIEW_GET_PRIVATE(obj) \
diff --git a/addressbook/gui/component/eab-composer-util.c b/addressbook/gui/component/eab-composer-util.c
new file mode 100644
index 0000000000..ce3a96cc13
--- /dev/null
+++ b/addressbook/gui/component/eab-composer-util.c
@@ -0,0 +1,214 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "eab-composer-util.h"
+
+#include <glib/gi18n.h>
+#include <libebook/e-contact.h>
+#include <libebook/e-destination.h>
+
+#include "mail/em-composer-utils.h"
+#include "composer/e-msg-composer.h"
+#include "addressbook/util/eab-book-util.h"
+#include "addressbook/gui/widgets/eab-gui-util.h"
+
+static void
+eab_send_as_to (GList *destinations)
+{
+ EMsgComposer *composer;
+ EComposerHeaderTable *table;
+ GPtrArray *to_array;
+ GPtrArray *bcc_array;
+
+ union {
+ gpointer *pdata;
+ EDestination **destinations;
+ } convert;
+
+ if (destinations == NULL)
+ return;
+
+ composer = e_msg_composer_new ();
+ table = e_msg_composer_get_header_table (composer);
+ em_composer_utils_setup_default_callbacks (composer);
+
+ to_array = g_ptr_array_new ();
+ bcc_array = g_ptr_array_new ();
+
+ /* Sort contacts into "To" and "Bcc" destinations. */
+ while (destinations != NULL) {
+ EDestination *destination = destinations->data;
+
+ if (e_destination_is_evolution_list (destination)) {
+ if (e_destination_list_show_addresses (destination))
+ g_ptr_array_add (to_array, destination);
+ else
+ g_ptr_array_add (bcc_array, destination);
+ } else
+ g_ptr_array_add (to_array, destination);
+
+ destinations = g_list_next (destinations);
+ }
+
+ /* Add sentinels to each array. */
+ g_ptr_array_add (to_array, NULL);
+ g_ptr_array_add (bcc_array, NULL);
+
+ /* XXX Acrobatics like this make me question whether NULL-terminated
+ * arrays are really the best argument type for passing a list of
+ * destinations to the header table. */
+
+ /* Add "To" destinations. */
+ convert.pdata = to_array->pdata;
+ e_composer_header_table_set_destinations_to (
+ table, convert.destinations);
+ g_ptr_array_free (to_array, FALSE);
+ e_destination_freev (convert.destinations);
+
+ /* Add "Bcc" destinations. */
+ convert.pdata = bcc_array->pdata;
+ e_composer_header_table_set_destinations_bcc (
+ table, convert.destinations);
+ g_ptr_array_free (bcc_array, FALSE);
+ e_destination_freev (convert.destinations);
+
+ gtk_widget_show (GTK_WIDGET (composer));
+}
+
+static const char *
+get_email (EContact *contact, EContactField field_id, gchar **to_free)
+{
+ char *name = NULL, *mail = NULL;
+ const char *value = e_contact_get_const (contact, field_id);
+
+ *to_free = NULL;
+
+ if (eab_parse_qp_email (value, &name, &mail)) {
+ *to_free = g_strdup_printf ("%s <%s>", name, mail);
+ value = *to_free;
+ }
+
+ g_free (name);
+ g_free (mail);
+
+ return value;
+}
+
+static void
+eab_send_as_attachment (GList *destinations)
+{
+ EMsgComposer *composer;
+ EComposerHeaderTable *table;
+ CamelMimePart *attachment;
+ GList *contacts, *iter;
+ gchar *data;
+
+ if (contacts == NULL)
+ return;
+
+ composer = e_msg_composer_new ();
+ table = e_msg_composer_get_header_table (composer);
+ em_composer_utils_setup_default_callbacks (composer);
+
+ attachment = camel_mime_part_new ();
+
+ contacts = g_list_copy (destinations);
+ for (iter = contacts; iter != NULL; iter = iter->next)
+ iter->data = e_destination_get_contact (iter->data);
+ data = eab_contact_list_to_string (contacts);
+ g_list_free (contacts);
+
+ camel_mime_part_set_content (
+ attachment, data, strlen (data), "text/x-vcard");
+
+ if (destinations->next != NULL)
+ camel_mime_part_set_description (
+ attachment, _("Multiple vCards"));
+ else {
+ EContact *contact;
+ const gchar *file_as;
+ gchar *description;
+
+ contact = e_destination_get_contact (destinations->data);
+ file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+ description = g_strdup_printf (_("vCard for %s"), file_as);
+ camel_mime_part_set_description (attachment, description);
+ g_free (description);
+ }
+
+ camel_mime_part_set_disposition (attachment, "attachment");
+
+ e_msg_composer_attach (composer, attachment);
+ camel_object_unref (attachment);
+
+ if (destinations->next != NULL)
+ e_composer_header_table_set_subject (
+ table, _("Contact information"));
+ else {
+ EContact *contact;
+ gchar *tempstr;
+ const gchar *tempstr2;
+ gchar *tempfree = NULL;
+
+ contact = e_destination_get_contact (destinations->data);
+ tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+ if (!tempstr2 || !*tempstr2)
+ tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME);
+ if (!tempstr2 || !*tempstr2)
+ tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG);
+ if (!tempstr2 || !*tempstr2) {
+ g_free (tempfree);
+ tempstr2 = get_email (contact, E_CONTACT_EMAIL_1, &tempfree);
+ }
+ if (!tempstr2 || !*tempstr2) {
+ g_free (tempfree);
+ tempstr2 = get_email (contact, E_CONTACT_EMAIL_2, &tempfree);
+ }
+ if (!tempstr2 || !*tempstr2) {
+ g_free (tempfree);
+ tempstr2 = get_email (contact, E_CONTACT_EMAIL_3, &tempfree);
+ }
+
+ if (!tempstr2 || !*tempstr2)
+ tempstr = g_strdup_printf (_("Contact information"));
+ else
+ tempstr = g_strdup_printf (_("Contact information for %s"), tempstr2);
+
+ e_composer_header_table_set_subject (table, tempstr);
+
+ g_free (tempstr);
+ g_free (tempfree);
+ }
+
+ gtk_widget_show (GTK_WIDGET (composer));
+}
+
+void
+eab_send_message (GList *destinations,
+ EABDisposition disposition)
+{
+ switch (disposition) {
+ case EAB_DISPOSITION_AS_TO:
+ eab_send_as_to (destinations);
+ break;
+
+ case EAB_DISPOSITION_AS_ATTACHMENT:
+ eab_send_as_attachment (destinations);
+ break;
+ }
+}
diff --git a/addressbook/gui/component/addressbook.h b/addressbook/gui/component/eab-composer-util.h
index 2e25448717..4e9ce581d0 100644
--- a/addressbook/gui/component/addressbook.h
+++ b/addressbook/gui/component/eab-composer-util.h
@@ -12,20 +12,25 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
- *
- * Authors:
- *
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
-#ifndef __ADDRESSBOOK_H__
-#define __ADDRESSBOOK_H__
+#ifndef EAB_COMPOSER_UTIL_H
+#define EAB_COMPOSER_UTIL_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ EAB_DISPOSITION_AS_ATTACHMENT,
+ EAB_DISPOSITION_AS_TO,
+} EABDisposition;
-#include <libebook/e-book.h>
+void eab_send_message (GList *destinations,
+ EABDisposition disposition);
-guint addressbook_load (EBook *book, EBookCallback cb, gpointer closure);
-void addressbook_load_cancel (guint id);
-void addressbook_load_default_book (EBookCallback open_response, gpointer closure);
+G_END_DECLS
-#endif /* __ADDRESSBOOK_H__ */
+#endif /* EAB_COMPOSER_UTIL_H */