aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/component/Makefile.am2
-rw-r--r--addressbook/gui/component/addressbook-component.c542
-rw-r--r--addressbook/gui/component/addressbook-component.h2
-rw-r--r--addressbook/gui/component/addressbook-view.c1380
-rw-r--r--addressbook/gui/component/addressbook-view.h60
-rw-r--r--addressbook/gui/component/addressbook.c799
-rw-r--r--addressbook/gui/component/addressbook.h7
7 files changed, 1453 insertions, 1339 deletions
diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am
index 5bd4d381e4..48f27f96c8 100644
--- a/addressbook/gui/component/Makefile.am
+++ b/addressbook/gui/component/Makefile.am
@@ -35,6 +35,8 @@ libevolution_addressbook_la_SOURCES = \
autocompletion-config.h \
addressbook.c \
addressbook.h \
+ addressbook-view.c \
+ addressbook-view.h \
component-factory.c
# $(top_builddir)/addressbook/printing/libecontactprint.la
diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c
index aa8b76cc9d..6138aaf6ea 100644
--- a/addressbook/gui/component/addressbook-component.c
+++ b/addressbook/gui/component/addressbook-component.c
@@ -26,30 +26,18 @@
#include <config.h>
#include "addressbook-component.h"
-#include "addressbook-migrate.h"
-
-#include "addressbook.h"
#include "addressbook-config.h"
-
-#include "widgets/misc/e-source-selector.h"
+#include "addressbook-migrate.h"
+#include "addressbook-view.h"
+#include "addressbook/gui/contact-editor/eab-editor.h"
#include "addressbook/gui/widgets/eab-gui-util.h"
-#include "addressbook/gui/merging/eab-contact-merging.h"
-#include "addressbook/util/eab-book-util.h"
-
#include "widgets/misc/e-task-bar.h"
#include "widgets/misc/e-info-label.h"
#include <string.h>
#include <bonobo/bonobo-i18n.h>
-#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtkmenu.h>
#include <gtk/gtkimage.h>
-#include <gtk/gtkimagemenuitem.h>
-#include <gtk/gtklabel.h> /* FIXME */
-#include <gtk/gtkmessagedialog.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtkvbox.h>
#include <gconf/gconf-client.h>
#include <gal/util/e-util.h>
@@ -63,410 +51,8 @@ static BonoboObjectClass *parent_class = NULL;
struct _AddressbookComponentPrivate {
GConfClient *gconf_client;
- ESourceList *source_list;
- GtkWidget *source_selector;
char *base_directory;
-
- EActivityHandler *activity_handler;
-};
-
-enum DndTargetType {
- DND_TARGET_TYPE_VCARD_LIST,
};
-#define VCARD_TYPE "text/x-vcard"
-static GtkTargetEntry drag_types[] = {
- { VCARD_TYPE, 0, DND_TARGET_TYPE_VCARD_LIST }
-};
-static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]);
-
-/* Utility functions. */
-
-static void
-load_uri_for_selection (ESourceSelector *selector,
- BonoboControl *view_control)
-{
- ESource *selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (selector));
-
- if (selected_source != NULL) {
- bonobo_control_set_property (view_control, NULL, "source_uid", TC_CORBA_string,
- e_source_peek_uid (selected_source), NULL);
- }
-}
-
-static ESource *
-find_first_source (ESourceList *source_list)
-{
- GSList *groups, *sources, *l, *m;
-
- groups = e_source_list_peek_groups (source_list);
- for (l = groups; l; l = l->next) {
- ESourceGroup *group = l->data;
-
- sources = e_source_group_peek_sources (group);
- for (m = sources; m; m = m->next) {
- ESource *source = m->data;
-
- return source;
- }
- }
-
- return NULL;
-}
-
-static void
-save_primary_selection (AddressbookComponent *addressbook_component)
-{
- AddressbookComponentPrivate *priv;
- ESource *source;
-
- priv = addressbook_component->priv;
-
- source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->source_selector));
- if (!source)
- return;
-
- /* Save the selection for next time we start up */
- gconf_client_set_string (priv->gconf_client,
- "/apps/evolution/addressbook/display/primary_addressbook",
- e_source_peek_uid (source), NULL);
-}
-
-static ESource *
-get_primary_source (AddressbookComponent *addressbook_component)
-{
- AddressbookComponentPrivate *priv;
- ESource *source;
- char *uid;
-
- priv = addressbook_component->priv;
-
- uid = gconf_client_get_string (priv->gconf_client,
- "/apps/evolution/addressbook/display/primary_addressbook",
- NULL);
- if (uid) {
- source = e_source_list_peek_source_by_uid (priv->source_list, uid);
- g_free (uid);
- } else {
- /* Try to create a default if there isn't one */
- source = find_first_source (priv->source_list);
- }
-
- return source;
-}
-
-static void
-load_primary_selection (AddressbookComponent *addressbook_component)
-{
- AddressbookComponentPrivate *priv;
- ESource *source;
-
- priv = addressbook_component->priv;
-
- source = get_primary_source (addressbook_component);
- if (source)
- e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->source_selector), source);
-}
-
-/* Folder popup menu callbacks */
-
-static void
-add_popup_menu_item (GtkMenu *menu, const char *label, const char *pixmap,
- GCallback callback, gpointer user_data, gboolean sensitive)
-{
- GtkWidget *item, *image;
-
- if (pixmap) {
- item = gtk_image_menu_item_new_with_label (label);
-
- /* load the image */
- if (g_file_test (pixmap, G_FILE_TEST_EXISTS))
- image = gtk_image_new_from_file (pixmap);
- else
- image = gtk_image_new_from_stock (pixmap, GTK_ICON_SIZE_MENU);
-
- if (image) {
- gtk_widget_show (image);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- }
- } else {
- item = gtk_menu_item_new_with_label (label);
- }
-
- if (callback)
- g_signal_connect (G_OBJECT (item), "activate", callback, user_data);
-
- if (!sensitive)
- gtk_widget_set_sensitive (item, FALSE);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
-}
-
-static void
-delete_addressbook_cb (GtkWidget *widget, AddressbookComponent *comp)
-{
- ESource *selected_source;
- AddressbookComponentPrivate *priv;
- GtkWidget *dialog;
- EBook *book;
- gboolean removed = FALSE;
- GError *error = NULL;
-
- priv = comp->priv;
-
- selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->source_selector));
- if (!selected_source)
- return;
-
- /* Create the confirmation dialog */
- dialog = gtk_message_dialog_new (
- GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Address book '%s' will be removed. Are you sure you want to continue?"),
- e_source_peek_name (selected_source));
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) {
- gtk_widget_destroy (dialog);
- return;
- }
-
- /* Remove local data */
- book = e_book_new ();
- if (e_book_load_source (book, selected_source, TRUE, &error))
- removed = e_book_remove (book, &error);
-
- if (removed) {
- /* Remove source */
- if (e_source_selector_source_is_selected (E_SOURCE_SELECTOR (priv->source_selector),
- selected_source))
- e_source_selector_unselect_source (E_SOURCE_SELECTOR (priv->source_selector),
- selected_source);
-
- e_source_group_remove_source (e_source_peek_group (selected_source), selected_source);
-
- e_source_list_sync (priv->source_list, NULL);
- } else {
- GtkWidget *error_dialog;
-
- error_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "Error removing address book: %s",
- error->message);
- gtk_dialog_run (GTK_DIALOG (error_dialog));
- gtk_widget_destroy (error_dialog);
-
- g_error_free (error);
- }
-
- g_object_unref (book);
- gtk_widget_destroy (dialog);
-}
-
-static void
-new_addressbook_cb (GtkWidget *widget, AddressbookComponent *comp)
-{
- addressbook_config_create_new_source (gtk_widget_get_toplevel (widget));
-}
-
-static void
-edit_addressbook_cb (GtkWidget *widget, AddressbookComponent *comp)
-{
- AddressbookComponentPrivate *priv;
- ESource *selected_source;
-
- priv = comp->priv;
-
- selected_source =
- e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->source_selector));
- if (!selected_source)
- return;
-
- addressbook_config_edit_source (gtk_widget_get_toplevel (widget), selected_source);
-}
-
-/* Callbacks. */
-
-static void
-primary_source_selection_changed_callback (ESourceSelector *selector,
- BonoboControl *view_control)
-{
- load_uri_for_selection (selector, view_control);
- save_primary_selection (addressbook_component_peek ());
-}
-
-
-static void
-fill_popup_menu_callback (ESourceSelector *selector, GtkMenu *menu, AddressbookComponent *comp)
-{
- gboolean sensitive;
- gboolean local_addressbook;
- ESource *selected_source;
-
- selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (comp->priv->source_selector));
- sensitive = selected_source ? TRUE : FALSE;
-
- local_addressbook = (!strcmp ("system", e_source_peek_relative_uri (selected_source)));
-
- add_popup_menu_item (menu, _("New Address Book"), NULL, G_CALLBACK (new_addressbook_cb), comp, TRUE);
- add_popup_menu_item (menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK (delete_addressbook_cb), comp, sensitive && !local_addressbook);
- add_popup_menu_item (menu, _("Properties..."), NULL, G_CALLBACK (edit_addressbook_cb), comp, sensitive);
-}
-
-static gboolean
-selector_tree_drag_drop (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- guint time,
- AddressbookComponent *component)
-{
- GtkTreeViewColumn *column;
- int cell_x;
- int cell_y;
- GtkTreePath *path;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gpointer data;
-
- if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &column, &cell_x, &cell_y))
- return FALSE;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
- if (!gtk_tree_model_get_iter (model, &iter, path)) {
- gtk_tree_path_free (path);
- return FALSE;
- }
-
- gtk_tree_model_get (model, &iter, 0, &data, -1);
-
- if (E_IS_SOURCE_GROUP (data)) {
- g_object_unref (data);
- gtk_tree_path_free (path);
- return FALSE;
- }
-
- gtk_tree_path_free (path);
- return TRUE;
-}
-
-static gboolean
-selector_tree_drag_motion (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y)
-{
- GtkTreePath *path = NULL;
- gpointer data = NULL;
- GtkTreeViewDropPosition pos;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GdkDragAction action;
-
- if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
- x, y, &path, &pos))
- goto finish;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
- if (!gtk_tree_model_get_iter (model, &iter, path))
- goto finish;
-
- gtk_tree_model_get (model, &iter, 0, &data, -1);
-
- if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
- goto finish;
-
- gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
- action = context->suggested_action;
-
- finish:
- if (path)
- gtk_tree_path_free (path);
- if (data)
- g_object_unref (data);
-
- gdk_drag_status (context, action, GDK_CURRENT_TIME);
- return TRUE;
-}
-
-static gboolean
-selector_tree_drag_data_received (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *data,
- guint info,
- guint time,
- gpointer user_data)
-{
- GtkTreePath *path = NULL;
- GtkTreeViewDropPosition pos;
- gpointer source = NULL;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gboolean success = FALSE;
-
- EBook *book;
- GList *contactlist;
- GList *l;
-
- if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
- x, y, &path, &pos))
- goto finish;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
- if (!gtk_tree_model_get_iter (model, &iter, path))
- goto finish;
-
- gtk_tree_model_get (model, &iter, 0, &source, -1);
-
- if (E_IS_SOURCE_GROUP (source) || e_source_get_readonly (source))
- goto finish;
-
- book = e_book_new ();
- if (!book) {
- g_message (G_STRLOC ":Couldn't create EBook.");
- return FALSE;
- }
- e_book_load_source (book, source, TRUE, NULL);
- contactlist = eab_contact_list_from_string (data->data);
-
- for (l = contactlist; l; l = l->next) {
- EContact *contact = l->data;
-
- /* XXX NULL for a callback /sigh */
- if (contact)
- eab_merging_book_add_contact (book, contact, NULL /* XXX */, NULL);
- success = TRUE;
- }
-
- g_list_foreach (contactlist, (GFunc)g_object_unref, NULL);
- g_list_free (contactlist);
- g_object_unref (book);
-
- finish:
- if (path)
- gtk_tree_path_free (path);
- if (source)
- g_object_unref (source);
-
- gtk_drag_finish (context, success, context->action == GDK_ACTION_MOVE, time);
-
- return TRUE;
-}
-
-static void
-selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
-{
- gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), NULL, GTK_TREE_VIEW_DROP_BEFORE);
-}
/* Evolution::Component CORBA methods. */
@@ -477,69 +63,14 @@ impl_createControls (PortableServer_Servant servant,
Bonobo_Control *corba_statusbar_control,
CORBA_Environment *ev)
{
- AddressbookComponent *addressbook_component = ADDRESSBOOK_COMPONENT (bonobo_object_from_servant (servant));
- GtkWidget *selector, *vbox, *info;
- GtkWidget *selector_scrolled_window;
- GtkWidget *statusbar_widget;
+ AddressbookView *view = addressbook_view_new ();
BonoboControl *sidebar_control;
BonoboControl *view_control;
BonoboControl *statusbar_control;
- selector = e_source_selector_new (addressbook_component->priv->source_list);
-
- g_signal_connect (selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion), addressbook_component);
- g_signal_connect (selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave), addressbook_component);
- g_signal_connect (selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop), addressbook_component);
- g_signal_connect (selector, "drag-data-received", G_CALLBACK (selector_tree_drag_data_received), addressbook_component);
- /*
- g_signal_connect (selector, "drag-begin", G_CALLBACK (drag_begin_callback), addressbook_component);
- g_signal_connect (selector, "drag-data-get", G_CALLBACK (drag_data_get_callback), addressbook_component);
- g_signal_connect (selector, "drag-end", G_CALLBACK (drag_end_callback), addressbook_component);
- //gtk_drag_source_set(selector, GDK_BUTTON1_MASK, drag_types, num_drop_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);
- */
-
- gtk_drag_dest_set(selector, GTK_DEST_DEFAULT_ALL, drag_types, num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);
-
- e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
- gtk_widget_show (selector);
-
- addressbook_component->priv->source_selector = selector;
-
- selector_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (selector_scrolled_window), GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selector_scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_container_add (GTK_CONTAINER (selector_scrolled_window), selector);
- gtk_widget_show (selector_scrolled_window);
-
- statusbar_widget = e_task_bar_new ();
- gtk_widget_show (statusbar_widget);
-
- e_activity_handler_attach_task_bar (addressbook_component->priv->activity_handler,
- E_TASK_BAR (statusbar_widget));
-
- info = e_info_label_new("evolution-contacts-mini.png");
- e_info_label_set_info((EInfoLabel *)info, _("Contacts"), "");
- gtk_widget_show (info);
-
- vbox = gtk_vbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX (vbox), info, FALSE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX (vbox), selector_scrolled_window, TRUE, TRUE, 0);
- gtk_widget_show (vbox);
-
- sidebar_control = bonobo_control_new (vbox);
- statusbar_control = bonobo_control_new (statusbar_widget);
- view_control = addressbook_new_control ();
-
- g_signal_connect_object (selector, "primary_selection_changed",
- G_CALLBACK (primary_source_selection_changed_callback),
- G_OBJECT (view_control), 0);
- g_signal_connect_object (selector, "fill_popup_menu",
- G_CALLBACK (fill_popup_menu_callback),
- G_OBJECT (addressbook_component), 0);
-
- load_primary_selection (addressbook_component);
- load_uri_for_selection (E_SOURCE_SELECTOR (selector), view_control);
+ sidebar_control = bonobo_control_new (addressbook_view_peek_sidebar (view));
+ view_control = addressbook_view_peek_folder_view (view);
+ statusbar_control = bonobo_control_new (addressbook_view_peek_statusbar (view));
*corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev);
*corba_view_control = CORBA_Object_duplicate (BONOBO_OBJREF (view_control), ev);
@@ -592,10 +123,8 @@ impl_requestCreateItem (PortableServer_Servant servant,
{
AddressbookComponent *addressbook_component = ADDRESSBOOK_COMPONENT (bonobo_object_from_servant (servant));
AddressbookComponentPrivate *priv;
- EBook *book;
+ EBook *book = NULL;
EContact *contact;
- ESource *selected_source;
- gchar *uri;
priv = addressbook_component->priv;
@@ -604,26 +133,11 @@ impl_requestCreateItem (PortableServer_Servant servant,
return;
}
- selected_source = get_primary_source (addressbook_component);
- if (!selected_source) {
+ if (!e_book_get_default_addressbook (&book, NULL)) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_Failed, NULL);
return;
}
- uri = e_source_get_uri (selected_source);
- if (!uri) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_Failed, NULL);
- return;
- }
-
- book = e_book_new ();
- if (!e_book_load_uri (book, uri, TRUE, NULL)) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_Failed, NULL);
- g_object_unref (book);
- g_free (uri);
- return;
- }
-
contact = e_contact_new ();
if (!item_type_name) {
@@ -641,7 +155,6 @@ impl_requestCreateItem (PortableServer_Servant servant,
g_object_unref (book);
g_object_unref (contact);
- g_free (uri);
}
static CORBA_boolean
@@ -663,26 +176,11 @@ impl_dispose (GObject *object)
{
AddressbookComponentPrivate *priv = ADDRESSBOOK_COMPONENT (object)->priv;
- if (priv->source_selector != NULL) {
- g_object_unref (priv->source_selector);
- priv->source_selector = NULL;
- }
-
- if (priv->source_list != NULL) {
- g_object_unref (priv->source_list);
- priv->source_list = NULL;
- }
-
if (priv->gconf_client != NULL) {
g_object_unref (priv->gconf_client);
priv->gconf_client = NULL;
}
- if (priv->activity_handler != NULL) {
- g_object_unref (priv->activity_handler);
- priv->activity_handler = NULL;
- }
-
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
}
@@ -727,10 +225,6 @@ addressbook_component_init (AddressbookComponent *component)
/* EPFIXME: Should use a custom one instead? */
priv->gconf_client = gconf_client_get_default ();
- priv->source_list = e_source_list_new_for_gconf (priv->gconf_client,
- "/apps/evolution/addressbook/sources");
-
- priv->activity_handler = e_activity_handler_new ();
priv->base_directory = g_build_filename (g_get_home_dir (), ".evolution", NULL);
component->priv = priv;
@@ -770,22 +264,4 @@ addressbook_component_peek_base_directory (AddressbookComponent *component)
return component->priv->base_directory;
}
-ESourceList *
-addressbook_component_peek_source_list (AddressbookComponent *component)
-{
- g_return_val_if_fail (ADDRESSBOOK_IS_COMPONENT (component), NULL);
-
- return component->priv->source_list;
-}
-
-
-EActivityHandler *
-addressbook_component_peek_activity_handler (AddressbookComponent *component)
-{
- g_return_val_if_fail (ADDRESSBOOK_IS_COMPONENT (component), NULL);
-
- return component->priv->activity_handler;
-}
-
-
BONOBO_TYPE_FUNC_FULL (AddressbookComponent, GNOME_Evolution_Component, PARENT_TYPE, addressbook_component)
diff --git a/addressbook/gui/component/addressbook-component.h b/addressbook/gui/component/addressbook-component.h
index 76884b0bb8..de92637a59 100644
--- a/addressbook/gui/component/addressbook-component.h
+++ b/addressbook/gui/component/addressbook-component.h
@@ -59,7 +59,5 @@ AddressbookComponent *addressbook_component_peek (void);
GConfClient *addressbook_component_peek_gconf_client (AddressbookComponent *component);
const char *addressbook_component_peek_base_directory (AddressbookComponent *component);
-EActivityHandler *addressbook_component_peek_activity_handler (AddressbookComponent *component);
-ESourceList *addressbook_component_peek_source_list (AddressbookComponent *component);
#endif /* _ADDRESSBOOK_COMPONENT_H_ */
diff --git a/addressbook/gui/component/addressbook-view.c b/addressbook/gui/component/addressbook-view.c
new file mode 100644
index 0000000000..d25cbe68c6
--- /dev/null
+++ b/addressbook/gui/component/addressbook-view.c
@@ -0,0 +1,1380 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* addressbook-view.c
+ *
+ * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc.
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Chris Toshok (toshok@ximian.com)
+ */
+
+#include <config.h>
+
+#include <string.h>
+#include <glib.h>
+#include <gtk/gtkvbox.h>
+#include <gtk/gtknotebook.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkmessagedialog.h>
+#include <libgnome/gnome-i18n.h>
+#include <libgnomeui/gnome-app.h>
+#include <libgnomeui/gnome-href.h>
+#include <libgnomeui/gnome-uidefs.h>
+#include <bonobo/bonobo-generic-factory.h>
+#include <bonobo/bonobo-ui-util.h>
+#include <bonobo/bonobo-exception.h>
+#include <bonobo/bonobo-property-bag.h>
+#include <gal/util/e-util.h>
+
+#include "widgets/misc/e-task-bar.h"
+#include "widgets/misc/e-info-label.h"
+#include "widgets/misc/e-source-selector.h"
+
+#include "e-util/e-passwords.h"
+#include "shell/e-user-creatable-items-handler.h"
+
+#include "evolution-shell-component-utils.h"
+#include "e-activity-handler.h"
+#include "e-contact-editor.h"
+#include "addressbook-config.h"
+#include "addressbook.h"
+#include "addressbook-view.h"
+#include "addressbook-component.h"
+#include "addressbook/gui/search/e-addressbook-search-dialog.h"
+#include "addressbook/gui/widgets/e-addressbook-view.h"
+#include "addressbook/gui/widgets/eab-gui-util.h"
+#include "addressbook/gui/merging/eab-contact-merging.h"
+#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/util/eab-book-util.h"
+
+#include <libebook/e-book-async.h>
+
+#define PARENT_TYPE G_TYPE_OBJECT
+static GObjectClass *parent_class = NULL;
+
+/* This is used for the addressbook status bar */
+#define EVOLUTION_CONTACTS_PROGRESS_IMAGE "evolution-contacts-mini.png"
+static GdkPixbuf *progress_icon = NULL;
+
+#define d(x)
+
+#define PROPERTY_SOURCE_UID "source_uid"
+#define PROPERTY_FOLDER_URI "folder_uri"
+
+#define PROPERTY_SOURCE_UID_IDX 1
+#define PROPERTY_FOLDER_URI_IDX 2
+
+struct _AddressbookViewPrivate {
+ GtkWidget *notebook;
+ BonoboControl *folder_view_control;
+
+ GtkWidget *statusbar_widget;
+ EActivityHandler *activity_handler;
+
+ GtkWidget *info_widget;
+ GtkWidget *sidebar_widget;
+ GtkWidget *selector;
+
+ GConfClient *gconf_client;
+
+ GHashTable *uid_to_view;
+ EBook *book;
+ guint activity_id;
+ BonoboPropertyBag *properties;
+ ESourceList *source_list;
+ char *passwd;
+ EUserCreatableItemsHandler *creatable_items_handler;
+};
+
+enum DndTargetType {
+ DND_TARGET_TYPE_VCARD_LIST,
+};
+#define VCARD_TYPE "text/x-vcard"
+static GtkTargetEntry drag_types[] = {
+ { VCARD_TYPE, 0, DND_TARGET_TYPE_VCARD_LIST }
+};
+static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]);
+
+static void set_status_message (EABView *eav, const char *message, AddressbookView *view);
+static void search_result (EABView *eav, EBookViewStatus status, AddressbookView *view);
+
+static void addressbook_view_init (AddressbookView *view);
+static void addressbook_view_class_init (AddressbookViewClass *klass);
+static void addressbook_view_dispose (GObject *object);
+
+static void set_prop (BonoboPropertyBag *bag, const BonoboArg *arg, guint arg_id,
+ CORBA_Environment *ev, gpointer user_data);
+static void get_prop (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id,
+ CORBA_Environment *ev, gpointer user_data);
+
+static EABView *
+get_current_view (AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+
+ return EAB_VIEW (gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
+ gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook))));
+}
+
+static void
+save_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_save_as(v);
+}
+
+static void
+view_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_view(v);
+}
+
+static void
+search_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ gtk_widget_show(eab_search_dialog_new(v));
+}
+
+static void
+delete_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_delete_selection(v);
+}
+
+static void
+print_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_print(v);
+}
+
+static void
+print_preview_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_print_preview(v);
+}
+
+static void
+stop_loading_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_stop(v);
+}
+
+static void
+cut_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_cut(v);
+}
+
+static void
+copy_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_copy(v);
+}
+
+static void
+paste_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_paste(v);
+}
+
+static void
+select_all_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_select_all (v);
+}
+
+static void
+send_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_send (v);
+}
+
+static void
+send_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_send_to (v);
+}
+
+static void
+copy_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_copy_to_folder (v);
+}
+
+static void
+move_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ AddressbookView *view = (AddressbookView *) user_data;
+ EABView *v = get_current_view (view);
+ if (v)
+ eab_view_move_to_folder (v);
+}
+
+static void
+forget_passwords_cb (BonoboUIComponent *uih, void *user_data, const char *path)
+{
+ e_passwords_forget_passwords();
+}
+
+static void
+set_status_message (EABView *eav, const char *message, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ EActivityHandler *activity_handler = priv->activity_handler;
+
+ if (!message || !*message) {
+ if (priv->activity_id != 0) {
+ e_activity_handler_operation_finished (activity_handler, priv->activity_id);
+ priv->activity_id = 0;
+ }
+ } else if (priv->activity_id == 0) {
+ char *clientid = g_strdup_printf ("%p", view);
+
+ if (progress_icon == NULL)
+ progress_icon = gdk_pixbuf_new_from_file (EVOLUTION_IMAGESDIR "/" EVOLUTION_CONTACTS_PROGRESS_IMAGE, NULL);
+
+ priv->activity_id = e_activity_handler_operation_started (activity_handler, clientid,
+ progress_icon, message, TRUE);
+
+ g_free (clientid);
+ } else {
+ e_activity_handler_operation_progressing (activity_handler, priv->activity_id, message, -1.0);
+ }
+
+}
+
+static void
+set_folder_bar_message (EABView *eav, const char *message, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ EABView *current_view = get_current_view (view);
+
+ if (eav == current_view) {
+ ESource *source = eav->source;
+
+ if (source) {
+ const char *name = e_source_peek_name (source);
+
+ e_info_label_set_info((EInfoLabel*)priv->info_widget, name, message);
+ }
+ }
+}
+
+static void
+search_result (EABView *eav, EBookViewStatus status, AddressbookView *view)
+{
+ eab_search_result_dialog (NULL /* XXX */, status);
+}
+
+static void
+update_command_state (EABView *eav, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ BonoboUIComponent *uic;
+
+ if (eav != get_current_view (view))
+ return;
+
+ g_object_ref (view);
+
+ uic = bonobo_control_get_ui_component (priv->folder_view_control);
+
+ if (bonobo_ui_component_get_container (uic) != CORBA_OBJECT_NIL) {
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsSaveAsVCard",
+ "sensitive",
+ eab_view_can_save_as (eav) ? "1" : "0", NULL);
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsView",
+ "sensitive",
+ eab_view_can_view (eav) ? "1" : "0", NULL);
+
+ /* Print Contact */
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsPrint",
+ "sensitive",
+ eab_view_can_print (eav) ? "1" : "0", NULL);
+
+ /* Print Contact */
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsPrintPreview",
+ "sensitive",
+ eab_view_can_print (eav) ? "1" : "0", NULL);
+
+ /* Delete Contact */
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactDelete",
+ "sensitive",
+ eab_view_can_delete (eav) ? "1" : "0", NULL);
+
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsCut",
+ "sensitive",
+ eab_view_can_cut (eav) ? "1" : "0", NULL);
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsCopy",
+ "sensitive",
+ eab_view_can_copy (eav) ? "1" : "0", NULL);
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsPaste",
+ "sensitive",
+ eab_view_can_paste (eav) ? "1" : "0", NULL);
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsSelectAll",
+ "sensitive",
+ eab_view_can_select_all (eav) ? "1" : "0", NULL);
+
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsSendContactToOther",
+ "sensitive",
+ eab_view_can_send (eav) ? "1" : "0", NULL);
+
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsSendMessageToContact",
+ "sensitive",
+ eab_view_can_send_to (eav) ? "1" : "0", NULL);
+
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsMoveToFolder",
+ "sensitive",
+ eab_view_can_move_to_folder (eav) ? "1" : "0", NULL);
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactsCopyToFolder",
+ "sensitive",
+ eab_view_can_copy_to_folder (eav) ? "1" : "0", NULL);
+
+ /* Stop */
+ bonobo_ui_component_set_prop (uic,
+ "/commands/ContactStop",
+ "sensitive",
+ eab_view_can_stop (eav) ? "1" : "0", NULL);
+ }
+
+ g_object_unref (view);
+}
+
+static BonoboUIVerb verbs [] = {
+ BONOBO_UI_UNSAFE_VERB ("ContactsPrint", print_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsPrintPreview", print_preview_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsSaveAsVCard", save_contact_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsView", view_contact_cb),
+
+ BONOBO_UI_UNSAFE_VERB ("ContactDelete", delete_contact_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactStop", stop_loading_cb),
+
+ BONOBO_UI_UNSAFE_VERB ("ContactsCut", cut_contacts_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsCopy", copy_contacts_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsPaste", paste_contacts_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsSelectAll", select_all_contacts_cb),
+
+ BONOBO_UI_UNSAFE_VERB ("ContactsSendContactToOther", send_contact_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsSendMessageToContact", send_contact_to_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsMoveToFolder", move_contact_to_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsCopyToFolder", copy_contact_to_cb),
+ BONOBO_UI_UNSAFE_VERB ("ContactsForgetPasswords", forget_passwords_cb),
+ /* ContactsViewPreview is a toggle */
+
+ BONOBO_UI_VERB_END
+};
+
+static EPixmap pixmaps [] = {
+ E_PIXMAP ("/menu/File/FileOps/ContactsSaveAsVCard", "save-as-16.png"),
+ E_PIXMAP ("/menu/File/Print/ContactsPrint", "print.xpm"),
+ E_PIXMAP ("/menu/File/Print/ContactsPrintPreview", "print-preview.xpm"),
+
+ E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsCut", "16_cut.png"),
+ E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsCopy", "16_copy.png"),
+ E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsPaste", "16_paste.png"),
+ E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactDelete", "evolution-trash-mini.png"),
+
+ E_PIXMAP ("/Toolbar/ContactsPrint", "buttons/print.png"),
+ E_PIXMAP ("/Toolbar/ContactDelete", "buttons/delete-message.png"),
+
+ E_PIXMAP_END
+};
+
+static void
+control_activate (BonoboControl *control,
+ BonoboUIComponent *uic,
+ AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ Bonobo_UIContainer remote_ui_container;
+ EABView *v = get_current_view (view);
+
+ remote_ui_container = bonobo_control_get_remote_ui_container (control, NULL);
+ bonobo_ui_component_set_container (uic, remote_ui_container, NULL);
+ bonobo_object_release_unref (remote_ui_container, NULL);
+
+ bonobo_ui_component_add_verb_list_with_data (
+ uic, verbs, view);
+
+ bonobo_ui_component_freeze (uic, NULL);
+
+ bonobo_ui_util_set_ui (uic, PREFIX,
+ EVOLUTION_UIDIR "/evolution-addressbook.xml",
+ "evolution-addressbook", NULL);
+
+ if (v)
+ eab_view_setup_menus (v, uic);
+
+ e_pixmaps_update (uic, pixmaps);
+
+ e_user_creatable_items_handler_activate (priv->creatable_items_handler, uic);
+
+ bonobo_ui_component_thaw (uic, NULL);
+
+ if (v)
+ update_command_state (v, view);
+}
+
+static void
+control_activate_cb (BonoboControl *control,
+ gboolean activate,
+ AddressbookView *view)
+{
+ BonoboUIComponent *uic;
+ EABView *v = get_current_view (view);
+
+ uic = bonobo_control_get_ui_component (control);
+ g_assert (uic != NULL);
+
+ if (activate) {
+ control_activate (control, uic, view);
+ if (activate && v && v->model)
+ eab_model_force_folder_bar_message (v->model);
+ } else {
+ bonobo_ui_component_unset_container (uic, NULL);
+ eab_view_discard_menus (v);
+ }
+}
+
+static void
+gather_uids_foreach (char *key,
+ gpointer value,
+ GList **list)
+{
+ (*list) = g_list_prepend (*list, key);
+}
+
+static void
+source_list_changed_cb (ESourceList *source_list, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ GList *uids, *l;
+ EABView *v;
+
+ uids = NULL;
+ g_hash_table_foreach (priv->uid_to_view, (GHFunc)gather_uids_foreach, &uids);
+
+ for (l = uids; l; l = l->next) {
+ char *uid = l->data;
+ if (e_source_list_peek_source_by_uid (source_list, uid)) {
+ /* the source still exists, do nothing */
+ }
+ else {
+ /* the source no longer exists, remove the
+ view and remove it from our hash table. */
+ v = g_hash_table_lookup (priv->uid_to_view,
+ uid);
+ g_hash_table_remove (priv->uid_to_view, uid);
+ gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook),
+ gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
+ GTK_WIDGET (v)));
+ g_object_unref (v);
+ }
+ }
+
+ /* make sure we've got the current view selected and updated
+ properly */
+ v = get_current_view (view);
+ if (v) {
+ eab_view_setup_menus (v, bonobo_control_get_ui_component (priv->folder_view_control));
+ update_command_state (v, view);
+ }
+}
+
+static void
+load_uri_for_selection (ESourceSelector *selector,
+ BonoboControl *view_control)
+{
+ ESource *selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (selector));
+
+ if (selected_source != NULL) {
+ bonobo_control_set_property (view_control, NULL, "source_uid", TC_CORBA_string,
+ e_source_peek_uid (selected_source), NULL);
+ }
+}
+
+static ESource *
+find_first_source (ESourceList *source_list)
+{
+ GSList *groups, *sources, *l, *m;
+
+ groups = e_source_list_peek_groups (source_list);
+ for (l = groups; l; l = l->next) {
+ ESourceGroup *group = l->data;
+
+ sources = e_source_group_peek_sources (group);
+ for (m = sources; m; m = m->next) {
+ ESource *source = m->data;
+
+ return source;
+ }
+ }
+
+ return NULL;
+}
+
+static void
+save_primary_selection (AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *source;
+
+ source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
+ if (!source)
+ return;
+
+ /* Save the selection for next time we start up */
+ gconf_client_set_string (priv->gconf_client,
+ "/apps/evolution/addressbook/display/primary_addressbook",
+ e_source_peek_uid (source), NULL);
+}
+
+static ESource *
+get_primary_source (AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *source;
+ char *uid;
+
+ uid = gconf_client_get_string (priv->gconf_client,
+ "/apps/evolution/addressbook/display/primary_addressbook",
+ NULL);
+ if (uid) {
+ source = e_source_list_peek_source_by_uid (priv->source_list, uid);
+ g_free (uid);
+ } else {
+ /* Try to create a default if there isn't one */
+ source = find_first_source (priv->source_list);
+ }
+
+ return source;
+}
+
+static void
+load_primary_selection (AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *source;
+
+ source = get_primary_source (view);
+ if (source)
+ e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->selector), source);
+}
+
+/* Folder popup menu callbacks */
+
+static void
+add_popup_menu_item (GtkMenu *menu, const char *label, const char *pixmap,
+ GCallback callback, gpointer user_data, gboolean sensitive)
+{
+ GtkWidget *item, *image;
+
+ if (pixmap) {
+ item = gtk_image_menu_item_new_with_label (label);
+
+ /* load the image */
+ if (g_file_test (pixmap, G_FILE_TEST_EXISTS))
+ image = gtk_image_new_from_file (pixmap);
+ else
+ image = gtk_image_new_from_stock (pixmap, GTK_ICON_SIZE_MENU);
+
+ if (image) {
+ gtk_widget_show (image);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ }
+ } else {
+ item = gtk_menu_item_new_with_label (label);
+ }
+
+ if (callback)
+ g_signal_connect (G_OBJECT (item), "activate", callback, user_data);
+
+ if (!sensitive)
+ gtk_widget_set_sensitive (item, FALSE);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+}
+
+static void
+delete_addressbook_cb (GtkWidget *widget, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *selected_source;
+ GtkWidget *dialog;
+ EBook *book;
+ gboolean removed = FALSE;
+ GError *error = NULL;
+
+ selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
+ if (!selected_source)
+ return;
+
+ /* Create the confirmation dialog */
+ dialog = gtk_message_dialog_new (
+ GTK_WINDOW (gtk_widget_get_toplevel (widget)),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("Address book '%s' will be removed. Are you sure you want to continue?"),
+ e_source_peek_name (selected_source));
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) {
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ /* Remove local data */
+ book = e_book_new ();
+ if (e_book_load_source (book, selected_source, TRUE, &error))
+ removed = e_book_remove (book, &error);
+
+ if (removed) {
+ /* Remove source */
+ if (e_source_selector_source_is_selected (E_SOURCE_SELECTOR (priv->selector),
+ selected_source))
+ e_source_selector_unselect_source (E_SOURCE_SELECTOR (priv->selector),
+ selected_source);
+
+ e_source_group_remove_source (e_source_peek_group (selected_source), selected_source);
+
+ e_source_list_sync (priv->source_list, NULL);
+ } else {
+ GtkWidget *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (widget)),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Error removing address book: %s",
+ error->message);
+ gtk_dialog_run (GTK_DIALOG (error_dialog));
+ gtk_widget_destroy (error_dialog);
+
+ g_error_free (error);
+ }
+
+ g_object_unref (book);
+ gtk_widget_destroy (dialog);
+}
+
+static void
+new_addressbook_cb (GtkWidget *widget, AddressbookView *view)
+{
+ addressbook_config_create_new_source (gtk_widget_get_toplevel (widget));
+}
+
+static void
+edit_addressbook_cb (GtkWidget *widget, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *selected_source;
+
+ selected_source =
+ e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
+ if (!selected_source)
+ return;
+
+ addressbook_config_edit_source (gtk_widget_get_toplevel (widget), selected_source);
+}
+
+/* Callbacks. */
+
+static void
+primary_source_selection_changed_callback (ESourceSelector *selector,
+ AddressbookView *view)
+{
+ load_uri_for_selection (selector, view->priv->folder_view_control);
+ save_primary_selection (view);
+}
+
+
+static void
+fill_popup_menu_callback (ESourceSelector *selector, GtkMenu *menu, AddressbookView *view)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ gboolean sensitive;
+ gboolean local_addressbook;
+ ESource *selected_source;
+
+ selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
+ sensitive = selected_source ? TRUE : FALSE;
+
+ local_addressbook = (!strcmp ("system", e_source_peek_relative_uri (selected_source)));
+
+ add_popup_menu_item (menu, _("New Address Book"), NULL, G_CALLBACK (new_addressbook_cb), view, TRUE);
+ add_popup_menu_item (menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK (delete_addressbook_cb), view, sensitive && !local_addressbook);
+ add_popup_menu_item (menu, _("Properties..."), NULL, G_CALLBACK (edit_addressbook_cb), view, sensitive);
+}
+
+static gboolean
+selector_tree_drag_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ guint time,
+ AddressbookView *view)
+{
+ GtkTreeViewColumn *column;
+ int cell_x;
+ int cell_y;
+ GtkTreePath *path;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gpointer data;
+
+ if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &column, &cell_x, &cell_y))
+ return FALSE;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+
+ if (!gtk_tree_model_get_iter (model, &iter, path)) {
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ gtk_tree_model_get (model, &iter, 0, &data, -1);
+
+ if (E_IS_SOURCE_GROUP (data)) {
+ g_object_unref (data);
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ gtk_tree_path_free (path);
+ return TRUE;
+}
+
+static gboolean
+selector_tree_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y)
+{
+ GtkTreePath *path = NULL;
+ gpointer data = NULL;
+ GtkTreeViewDropPosition pos;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GdkDragAction action;
+
+ if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
+ x, y, &path, &pos))
+ goto finish;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ goto finish;
+
+ gtk_tree_model_get (model, &iter, 0, &data, -1);
+
+ if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
+ goto finish;
+
+ gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
+ action = context->suggested_action;
+
+ finish:
+ if (path)
+ gtk_tree_path_free (path);
+ if (data)
+ g_object_unref (data);
+
+ gdk_drag_status (context, action, GDK_CURRENT_TIME);
+ return TRUE;
+}
+
+static gboolean
+selector_tree_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *data,
+ guint info,
+ guint time,
+ gpointer user_data)
+{
+ GtkTreePath *path = NULL;
+ GtkTreeViewDropPosition pos;
+ gpointer source = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean success = FALSE;
+
+ EBook *book;
+ GList *contactlist;
+ GList *l;
+
+ if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
+ x, y, &path, &pos))
+ goto finish;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ goto finish;
+
+ gtk_tree_model_get (model, &iter, 0, &source, -1);
+
+ if (E_IS_SOURCE_GROUP (source) || e_source_get_readonly (source))
+ goto finish;
+
+ book = e_book_new ();
+ if (!book) {
+ g_message (G_STRLOC ":Couldn't create EBook.");
+ return FALSE;
+ }
+ e_book_load_source (book, source, TRUE, NULL);
+ contactlist = eab_contact_list_from_string (data->data);
+
+ for (l = contactlist; l; l = l->next) {
+ EContact *contact = l->data;
+
+ /* XXX NULL for a callback /sigh */
+ if (contact)
+ eab_merging_book_add_contact (book, contact, NULL /* XXX */, NULL);
+ success = TRUE;
+ }
+
+ g_list_foreach (contactlist, (GFunc)g_object_unref, NULL);
+ g_list_free (contactlist);
+ g_object_unref (book);
+
+ finish:
+ if (path)
+ gtk_tree_path_free (path);
+ if (source)
+ g_object_unref (source);
+
+ gtk_drag_finish (context, success, context->action == GDK_ACTION_MOVE, time);
+
+ return TRUE;
+}
+
+static void
+selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
+{
+ gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), NULL, GTK_TREE_VIEW_DROP_BEFORE);
+}
+
+
+static void
+destroy_callback(gpointer data, GObject *where_object_was)
+{
+ AddressbookView *view = data;
+ g_object_unref (view);
+}
+
+GType
+addressbook_view_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static const GTypeInfo info = {
+ sizeof (AddressbookViewClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) addressbook_view_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EABView),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) addressbook_view_init,
+ };
+
+ type = g_type_register_static (PARENT_TYPE, "AddressbookView", &info, 0);
+ }
+
+ return type;
+}
+
+static void
+addressbook_view_class_init (AddressbookViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = addressbook_view_dispose;
+
+ parent_class = g_type_class_peek_parent (klass);
+}
+
+static void
+addressbook_view_init (AddressbookView *view)
+{
+ AddressbookViewPrivate *priv;
+ GtkWidget *selector_scrolled_window;
+
+ view->priv =
+ priv = g_new0 (AddressbookViewPrivate, 1);
+
+ priv->gconf_client = addressbook_component_peek_gconf_client (addressbook_component_peek ());
+
+ priv->uid_to_view = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL);
+
+ priv->notebook = gtk_notebook_new ();
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
+
+ g_object_weak_ref (G_OBJECT (priv->notebook), destroy_callback, view);
+
+ /* Create the control. */
+ priv->folder_view_control = bonobo_control_new (priv->notebook);
+
+ gtk_widget_show (priv->notebook);
+
+ priv->properties = bonobo_property_bag_new (get_prop, set_prop, view);
+
+ bonobo_property_bag_add (priv->properties,
+ PROPERTY_SOURCE_UID, PROPERTY_SOURCE_UID_IDX,
+ BONOBO_ARG_STRING, NULL,
+ _("UID of the contacts source that the view will display"), 0);
+
+ bonobo_property_bag_add (priv->properties,
+ PROPERTY_FOLDER_URI, PROPERTY_FOLDER_URI_IDX,
+ BONOBO_ARG_STRING, NULL,
+ _("The URI that the address book will display"), 0);
+
+ bonobo_control_set_properties (priv->folder_view_control,
+ bonobo_object_corba_objref (BONOBO_OBJECT (priv->properties)),
+ NULL);
+
+ e_book_get_addressbooks (&priv->source_list, NULL);
+ g_signal_connect (priv->source_list,
+ "changed",
+ G_CALLBACK (source_list_changed_cb), view);
+
+ priv->creatable_items_handler = e_user_creatable_items_handler_new ("contacts");
+
+ g_signal_connect (priv->folder_view_control, "activate",
+ G_CALLBACK (control_activate_cb), view);
+
+ priv->activity_handler = e_activity_handler_new ();
+
+ priv->statusbar_widget = e_task_bar_new ();
+ gtk_widget_show (priv->statusbar_widget);
+
+ e_activity_handler_attach_task_bar (priv->activity_handler,
+ E_TASK_BAR (priv->statusbar_widget));
+
+ priv->info_widget = e_info_label_new("evolution-contacts-mini.png");
+ e_info_label_set_info((EInfoLabel*)priv->info_widget, _("Contacts"), "");
+ gtk_widget_show (priv->info_widget);
+
+ priv->selector = e_source_selector_new (priv->source_list);
+
+ g_signal_connect (priv->selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion), view);
+ g_signal_connect (priv->selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave), view);
+ g_signal_connect (priv->selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop), view);
+ g_signal_connect (priv->selector, "drag-data-received", G_CALLBACK (selector_tree_drag_data_received), view);
+ gtk_drag_dest_set (priv->selector, GTK_DEST_DEFAULT_ALL, drag_types, num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+ e_source_selector_show_selection (E_SOURCE_SELECTOR (priv->selector), FALSE);
+ gtk_widget_show (priv->selector);
+
+ selector_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (selector_scrolled_window), GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selector_scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (selector_scrolled_window), priv->selector);
+ gtk_widget_show (selector_scrolled_window);
+
+ priv->sidebar_widget = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX (priv->sidebar_widget), priv->info_widget, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX (priv->sidebar_widget), selector_scrolled_window, TRUE, TRUE, 0);
+ gtk_widget_show (priv->sidebar_widget);
+
+ g_signal_connect_object (priv->selector, "primary_selection_changed",
+ G_CALLBACK (primary_source_selection_changed_callback),
+ G_OBJECT (view), 0);
+ g_signal_connect_object (priv->selector, "fill_popup_menu",
+ G_CALLBACK (fill_popup_menu_callback),
+ G_OBJECT (view), 0);
+
+ load_primary_selection (view);
+ load_uri_for_selection (E_SOURCE_SELECTOR (priv->selector), priv->folder_view_control);
+}
+
+static void
+addressbook_view_dispose (GObject *object)
+{
+ AddressbookView *view = ADDRESSBOOK_VIEW (object);
+ AddressbookViewPrivate *priv = view->priv;
+
+ if (view->priv) {
+ if (priv->book)
+ g_object_unref (priv->book);
+
+ if (priv->properties)
+ bonobo_object_unref (BONOBO_OBJECT(priv->properties));
+
+ g_free(priv->passwd);
+
+ if (priv->source_list)
+ g_object_unref (priv->source_list);
+
+ if (priv->uid_to_view)
+ g_hash_table_destroy (priv->uid_to_view);
+
+ if (priv->creatable_items_handler)
+ g_object_unref (priv->creatable_items_handler);
+
+ g_free (view->priv);
+ view->priv = NULL;
+ }
+
+ if (G_OBJECT_CLASS (parent_class)->dispose)
+ (* G_OBJECT_CLASS (parent_class)->dispose) (object);
+}
+
+typedef struct {
+ EABView *view;
+ ESource *source;
+} BookOpenData;
+
+static void
+book_open_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ BookOpenData *data = closure;
+ EABView *view = data->view;
+ ESource *source = data->source;
+
+ g_free (data);
+
+ /* we always set the "source" property on the EABView, since
+ we use it to reload a previously failed book. */
+ g_object_set(view,
+ "source", source,
+ NULL);
+
+ if (status == E_BOOK_ERROR_OK) {
+ g_object_set(view,
+ "book", book,
+ NULL);
+ }
+ else {
+ eab_load_error_dialog (NULL /* XXX */, source, status);
+ }
+
+
+ g_object_unref (source);
+}
+
+static void
+activate_source (AddressbookView *view,
+ ESource *source,
+ const char *uid)
+{
+ AddressbookViewPrivate *priv = view->priv;
+ GtkWidget *uid_view;
+ EBook *book;
+ BookOpenData *data;
+
+ uid_view = g_hash_table_lookup (priv->uid_to_view, uid);
+
+ if (uid_view) {
+ /* there is a view for this uid. make
+ sure that the view actually
+ contains an EBook (if it doesn't
+ contain an EBook a previous load
+ failed. try to load it again */
+ g_object_get (uid_view,
+ "book", &book,
+ NULL);
+
+ if (book) {
+ g_object_unref (book);
+ }
+ else {
+ book = e_book_new ();
+
+ g_object_get (uid_view,
+ "source", &source,
+ NULL);
+
+ /* source can be NULL here, if
+ a previous load hasn't
+ actually made it to
+ book_open_cb yet. */
+ if (source) {
+ data = g_new (BookOpenData, 1);
+ data->view = g_object_ref (uid_view);
+ data->source = source; /* transfer the ref we get back from g_object_get */
+
+ addressbook_load_source (book, source, book_open_cb, data);
+ }
+ }
+ }
+ else {
+ /* we don't have a view for this uid already
+ set up. */
+ GtkWidget *label = gtk_label_new (uid);
+
+ uid_view = eab_view_new ();
+
+ gtk_widget_show (uid_view);
+ gtk_widget_show (label);
+
+ g_object_set (uid_view, "type", EAB_VIEW_TABLE, NULL);
+
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+ uid_view,
+ label);
+
+ g_hash_table_insert (priv->uid_to_view, g_strdup (uid), uid_view);
+
+ g_signal_connect (uid_view, "status_message",
+ G_CALLBACK(set_status_message), view);
+
+ g_signal_connect (uid_view, "search_result",
+ G_CALLBACK(search_result), view);
+
+ g_signal_connect (uid_view, "folder_bar_message",
+ G_CALLBACK(set_folder_bar_message), view);
+
+ g_signal_connect (uid_view, "command_state_change",
+ G_CALLBACK(update_command_state), view);
+
+ book = e_book_new ();
+
+ data = g_new (BookOpenData, 1);
+ data->view = g_object_ref (uid_view);
+ data->source = g_object_ref (source);
+
+ addressbook_load_source (book, source, book_open_cb, data);
+ }
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
+ uid_view));
+
+ if (EAB_VIEW (uid_view)->model)
+ eab_model_force_folder_bar_message (EAB_VIEW (uid_view)->model);
+
+ /* change menus/toolbars to reflect the new view, assuming we are already displayed */
+ if (bonobo_ui_component_get_container (bonobo_control_get_ui_component (priv->folder_view_control)) != CORBA_OBJECT_NIL) {
+ eab_view_setup_menus (EAB_VIEW (uid_view), bonobo_control_get_ui_component (priv->folder_view_control));
+ update_command_state (EAB_VIEW (uid_view), view);
+ }
+}
+
+static void
+set_prop (BonoboPropertyBag *bag,
+ const BonoboArg *arg,
+ guint arg_id,
+ CORBA_Environment *ev,
+ gpointer user_data)
+{
+ AddressbookView *view = user_data;
+ AddressbookViewPrivate *priv = view->priv;
+ ESource *source;
+
+ switch (arg_id) {
+
+ case PROPERTY_FOLDER_URI_IDX: {
+ const gchar *string = BONOBO_ARG_GET_STRING (arg);
+ ESourceGroup *group;
+
+ group = e_source_group_new ("", string);
+ source = e_source_new ("", "");
+ e_source_set_group (source, group);
+
+ /* we use the uri as the uid here. */
+ activate_source (view, source, string);
+
+ g_object_unref (group);
+
+ break;
+ }
+ case PROPERTY_SOURCE_UID_IDX: {
+ const gchar *uid;
+
+ uid = BONOBO_ARG_GET_STRING (arg);
+
+ source = e_source_list_peek_source_by_uid (priv->source_list, uid);
+
+ if (source) {
+ activate_source (view, source, uid);
+ }
+ else {
+ g_warning ("Could not find source by UID '%s'!", uid);
+ }
+
+ break;
+ }
+ default:
+ g_warning ("Unhandled arg %d\n", arg_id);
+ break;
+ }
+}
+
+static void
+get_prop (BonoboPropertyBag *bag,
+ BonoboArg *arg,
+ guint arg_id,
+ CORBA_Environment *ev,
+ gpointer user_data)
+{
+ AddressbookView *view = user_data;
+ EABView *v = get_current_view (view);
+ ESource *source = NULL;
+
+ switch (arg_id) {
+
+ case PROPERTY_FOLDER_URI_IDX:
+ if (v) {
+ g_object_get (v,
+ "source", &source,
+ NULL);
+ }
+
+ if (source) {
+ char *uri = e_source_get_uri (source);
+
+ BONOBO_ARG_SET_STRING (arg, uri);
+
+ g_free (uri);
+ g_object_unref (source);
+ }
+ else {
+ BONOBO_ARG_SET_STRING (arg, "");
+ }
+ break;
+
+ case PROPERTY_SOURCE_UID_IDX:
+ if (v) {
+ g_object_get (v,
+ "source", &source,
+ NULL);
+ }
+
+ if (source) {
+ BONOBO_ARG_SET_STRING (arg, e_source_peek_uid (source));
+
+ g_object_unref (source);
+ }
+ else {
+ BONOBO_ARG_SET_STRING (arg, "");
+ }
+
+ break;
+
+ default:
+ g_warning ("Unhandled arg %d\n", arg_id);
+ }
+}
+
+AddressbookView *
+addressbook_view_new (void)
+{
+ return g_object_new (ADDRESSBOOK_TYPE_VIEW, NULL);
+}
+
+EActivityHandler*
+addressbook_view_peek_activity_handler (AddressbookView *view)
+{
+ g_return_val_if_fail (ADDRESSBOOK_IS_VIEW (view), NULL);
+
+ return view->priv->activity_handler;
+}
+
+GtkWidget*
+addressbook_view_peek_info_label (AddressbookView *view)
+{
+ g_return_val_if_fail (ADDRESSBOOK_IS_VIEW (view), NULL);
+
+ return view->priv->info_widget;
+}
+
+GtkWidget*
+addressbook_view_peek_sidebar (AddressbookView *view)
+{
+ g_return_val_if_fail (ADDRESSBOOK_IS_VIEW (view), NULL);
+
+ return view->priv->sidebar_widget;
+}
+
+GtkWidget*
+addressbook_view_peek_statusbar (AddressbookView *view)
+{
+ g_return_val_if_fail (ADDRESSBOOK_IS_VIEW (view), NULL);
+
+ return view->priv->statusbar_widget;
+}
+
+BonoboControl*
+addressbook_view_peek_folder_view (AddressbookView *view)
+{
+ g_return_val_if_fail (ADDRESSBOOK_IS_VIEW (view), NULL);
+
+ return view->priv->folder_view_control;
+}
diff --git a/addressbook/gui/component/addressbook-view.h b/addressbook/gui/component/addressbook-view.h
new file mode 100644
index 0000000000..e2292c4527
--- /dev/null
+++ b/addressbook/gui/component/addressbook-view.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* addressbook-view.h
+ *
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Chris Toshok <toshok@ximian.com>
+ */
+
+#ifndef _ADDRESSBOOK_VIEW_H_
+#define _ADDRESSBOOK_VIEW_H_
+
+#include <bonobo/bonobo-control.h>
+
+#define ADDRESSBOOK_TYPE_VIEW (addressbook_view_get_type ())
+#define ADDRESSBOOK_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ADDRESSBOOK_TYPE_VIEW, AddressbookView))
+#define ADDRESSBOOK_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ADDRESSBOOK_TYPE_VIEW, AddressbookViewClass))
+#define ADDRESSBOOK_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ADDRESSBOOK_TYPE_VIEW))
+#define ADDRESSBOOK_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), ADDRESSBOOK_TYPE_VIEW))
+
+
+typedef struct _AddressbookView AddressbookView;
+typedef struct _AddressbookViewPrivate AddressbookViewPrivate;
+typedef struct _AddressbookViewClass AddressbookViewClass;
+
+struct _AddressbookView {
+ GObject parent;
+
+ AddressbookViewPrivate *priv;
+};
+
+struct _AddressbookViewClass {
+ GObjectClass parent_class;
+};
+
+
+GType addressbook_view_get_type (void);
+
+AddressbookView *addressbook_view_new (void);
+
+EActivityHandler *addressbook_view_peek_activity_handler (AddressbookView *view);
+GtkWidget *addressbook_view_peek_info_label (AddressbookView *view);
+GtkWidget *addressbook_view_peek_sidebar (AddressbookView *view);
+GtkWidget *addressbook_view_peek_statusbar (AddressbookView *view);
+BonoboControl *addressbook_view_peek_folder_view (AddressbookView *view);
+
+#endif /* _ADDRESSBOOK_VIEW_H_ */
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index c7ae59c3c8..4e1afeef1d 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -23,569 +23,20 @@
#include <config.h>
#include <string.h>
-#include <glib.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtknotebook.h>
-#include <gtk/gtkwidget.h>
+
#include <gtk/gtkmessagedialog.h>
#include <libgnome/gnome-i18n.h>
-#include <libgnomeui/gnome-app.h>
-#include <libgnomeui/gnome-href.h>
-#include <libgnomeui/gnome-uidefs.h>
-#include <bonobo/bonobo-generic-factory.h>
-#include <bonobo/bonobo-ui-util.h>
-#include <bonobo/bonobo-exception.h>
-#include <bonobo/bonobo-property-bag.h>
-#include <gal/util/e-util.h>
+#include <libebook/e-book-async.h>
#include "e-util/e-passwords.h"
-#include "shell/e-user-creatable-items-handler.h"
-#include "evolution-shell-component-utils.h"
-#include "e-activity-handler.h"
-#include "e-contact-editor.h"
-#include "addressbook-config.h"
#include "addressbook.h"
-#include "addressbook-component.h"
-#include "addressbook/gui/search/e-addressbook-search-dialog.h"
-#include "addressbook/gui/widgets/e-addressbook-view.h"
-#include "addressbook/gui/widgets/eab-gui-util.h"
-#include "addressbook/printing/e-contact-print.h"
-#include "addressbook/util/eab-book-util.h"
-
-#include <libebook/e-book-async.h>
-
-/* This is used for the addressbook status bar */
-#define EVOLUTION_CONTACTS_PROGRESS_IMAGE "evolution-contacts-mini.png"
-static GdkPixbuf *progress_icon = NULL;
#define d(x)
-#define PROPERTY_SOURCE_UID "source_uid"
-#define PROPERTY_FOLDER_URI "folder_uri"
-
-#define PROPERTY_SOURCE_UID_IDX 1
-#define PROPERTY_FOLDER_URI_IDX 2
-
-typedef struct {
- gint refs;
- GHashTable *uid_to_view;
- GtkWidget *notebook;
- EBook *book;
- guint activity_id;
- BonoboControl *control;
- BonoboPropertyBag *properties;
- ESourceList *source_list;
- char *passwd;
- EUserCreatableItemsHandler *creatable_items_handler;
-} AddressbookView;
-
-static void addressbook_view_ref (AddressbookView *);
-static void addressbook_view_unref (AddressbookView *);
-
static void addressbook_authenticate (EBook *book, gboolean previous_failure,
ESource *source, EBookCallback cb, gpointer closure);
-static void book_open_cb (EBook *book, EBookStatus status, gpointer closure);
-static void set_status_message (EABView *eav, const char *message, AddressbookView *view);
-static void search_result (EABView *eav, EBookViewStatus status, AddressbookView *view);
-
-static EABView *
-get_current_view (AddressbookView *view)
-{
- return EAB_VIEW (gtk_notebook_get_nth_page (GTK_NOTEBOOK (view->notebook),
- gtk_notebook_get_current_page (GTK_NOTEBOOK (view->notebook))));
-}
-
-static void
-save_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_save_as(v);
-}
-
-static void
-view_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_view(v);
-}
-
-static void
-search_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- gtk_widget_show(eab_search_dialog_new(v));
-}
-
-static void
-delete_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_delete_selection(v);
-}
-
-static void
-print_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_print(v);
-}
-
-static void
-print_preview_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_print_preview(v);
-}
-
-static void
-stop_loading_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_stop(v);
-}
-
-static void
-cut_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_cut(v);
-}
-
-static void
-copy_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_copy(v);
-}
-
-static void
-paste_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_paste(v);
-}
-
-static void
-select_all_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_select_all (v);
-}
-
-static void
-send_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_send (v);
-}
-
-static void
-send_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_send_to (v);
-}
-
-static void
-copy_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_copy_to_folder (v);
-}
-
-static void
-move_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- AddressbookView *view = (AddressbookView *) user_data;
- EABView *v = get_current_view (view);
- if (v)
- eab_view_move_to_folder (v);
-}
-
-static void
-forget_passwords_cb (BonoboUIComponent *uih, void *user_data, const char *path)
-{
- e_passwords_forget_passwords();
-}
-
-static void
-set_status_message (EABView *eav, const char *message, AddressbookView *view)
-{
- EActivityHandler *activity_handler = addressbook_component_peek_activity_handler (addressbook_component_peek ());
-
- if (!message || !*message) {
- if (view->activity_id != 0) {
- e_activity_handler_operation_finished (activity_handler, view->activity_id);
- view->activity_id = 0;
- }
- } else if (view->activity_id == 0) {
- char *clientid = g_strdup_printf ("%p", view);
-
- if (progress_icon == NULL)
- progress_icon = gdk_pixbuf_new_from_file (EVOLUTION_IMAGESDIR "/" EVOLUTION_CONTACTS_PROGRESS_IMAGE, NULL);
-
- view->activity_id = e_activity_handler_operation_started (activity_handler, clientid,
- progress_icon, message, TRUE);
-
- g_free (clientid);
- } else {
- e_activity_handler_operation_progressing (activity_handler, view->activity_id, message, -1.0);
- }
-
-}
-
-
-static void
-search_result (EABView *eav, EBookViewStatus status, AddressbookView *view)
-{
- eab_search_result_dialog (NULL /* XXX */, status);
-}
-
-static void
-update_command_state (EABView *eav, AddressbookView *view)
-{
- BonoboUIComponent *uic;
-
- if (eav != get_current_view (view))
- return;
-
- addressbook_view_ref (view);
-
- uic = bonobo_control_get_ui_component (view->control);
-
- if (bonobo_ui_component_get_container (uic) != CORBA_OBJECT_NIL) {
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsSaveAsVCard",
- "sensitive",
- eab_view_can_save_as (eav) ? "1" : "0", NULL);
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsView",
- "sensitive",
- eab_view_can_view (eav) ? "1" : "0", NULL);
-
- /* Print Contact */
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsPrint",
- "sensitive",
- eab_view_can_print (eav) ? "1" : "0", NULL);
-
- /* Print Contact */
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsPrintPreview",
- "sensitive",
- eab_view_can_print (eav) ? "1" : "0", NULL);
-
- /* Delete Contact */
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactDelete",
- "sensitive",
- eab_view_can_delete (eav) ? "1" : "0", NULL);
-
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsCut",
- "sensitive",
- eab_view_can_cut (eav) ? "1" : "0", NULL);
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsCopy",
- "sensitive",
- eab_view_can_copy (eav) ? "1" : "0", NULL);
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsPaste",
- "sensitive",
- eab_view_can_paste (eav) ? "1" : "0", NULL);
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsSelectAll",
- "sensitive",
- eab_view_can_select_all (eav) ? "1" : "0", NULL);
-
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsSendContactToOther",
- "sensitive",
- eab_view_can_send (eav) ? "1" : "0", NULL);
-
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsSendMessageToContact",
- "sensitive",
- eab_view_can_send_to (eav) ? "1" : "0", NULL);
-
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsMoveToFolder",
- "sensitive",
- eab_view_can_move_to_folder (eav) ? "1" : "0", NULL);
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactsCopyToFolder",
- "sensitive",
- eab_view_can_copy_to_folder (eav) ? "1" : "0", NULL);
-
- /* Stop */
- bonobo_ui_component_set_prop (uic,
- "/commands/ContactStop",
- "sensitive",
- eab_view_can_stop (eav) ? "1" : "0", NULL);
- }
-
- addressbook_view_unref (view);
-}
-
-static BonoboUIVerb verbs [] = {
- BONOBO_UI_UNSAFE_VERB ("ContactsPrint", print_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsPrintPreview", print_preview_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsSaveAsVCard", save_contact_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsView", view_contact_cb),
-
- BONOBO_UI_UNSAFE_VERB ("ContactDelete", delete_contact_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactStop", stop_loading_cb),
-
- BONOBO_UI_UNSAFE_VERB ("ContactsCut", cut_contacts_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsCopy", copy_contacts_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsPaste", paste_contacts_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsSelectAll", select_all_contacts_cb),
-
- BONOBO_UI_UNSAFE_VERB ("ContactsSendContactToOther", send_contact_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsSendMessageToContact", send_contact_to_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsMoveToFolder", move_contact_to_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsCopyToFolder", copy_contact_to_cb),
- BONOBO_UI_UNSAFE_VERB ("ContactsForgetPasswords", forget_passwords_cb),
- /* ContactsViewPreview is a toggle */
-
- BONOBO_UI_VERB_END
-};
-
-static EPixmap pixmaps [] = {
- E_PIXMAP ("/menu/File/FileOps/ContactsSaveAsVCard", "save-as-16.png"),
- E_PIXMAP ("/menu/File/Print/ContactsPrint", "print.xpm"),
- E_PIXMAP ("/menu/File/Print/ContactsPrintPreview", "print-preview.xpm"),
-
- E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsCut", "16_cut.png"),
- E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsCopy", "16_copy.png"),
- E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactsPaste", "16_paste.png"),
- E_PIXMAP ("/menu/EditPlaceholder/Edit/ContactDelete", "evolution-trash-mini.png"),
-
- E_PIXMAP ("/Toolbar/ContactsPrint", "buttons/print.png"),
- E_PIXMAP ("/Toolbar/ContactDelete", "buttons/delete-message.png"),
-
- E_PIXMAP_END
-};
-
-static void
-control_activate (BonoboControl *control,
- BonoboUIComponent *uic,
- AddressbookView *view)
-{
- Bonobo_UIContainer remote_ui_container;
- EABView *v = get_current_view (view);
-
- remote_ui_container = bonobo_control_get_remote_ui_container (control, NULL);
- bonobo_ui_component_set_container (uic, remote_ui_container, NULL);
- bonobo_object_release_unref (remote_ui_container, NULL);
-
- bonobo_ui_component_add_verb_list_with_data (
- uic, verbs, view);
-
- bonobo_ui_component_freeze (uic, NULL);
-
- bonobo_ui_util_set_ui (uic, PREFIX,
- EVOLUTION_UIDIR "/evolution-addressbook.xml",
- "evolution-addressbook", NULL);
-
- if (v)
- eab_view_setup_menus (v, uic);
-
- e_pixmaps_update (uic, pixmaps);
-
- e_user_creatable_items_handler_activate (view->creatable_items_handler, uic);
-
- bonobo_ui_component_thaw (uic, NULL);
-
- if (v)
- update_command_state (v, view);
-}
-
-static void
-control_activate_cb (BonoboControl *control,
- gboolean activate,
- AddressbookView *view)
-{
- BonoboUIComponent *uic;
- EABView *v = get_current_view (view);
-
- uic = bonobo_control_get_ui_component (control);
- g_assert (uic != NULL);
-
- if (activate) {
- control_activate (control, uic, view);
- if (activate && v && v->model)
- eab_model_force_folder_bar_message (v->model);
- } else {
- bonobo_ui_component_unset_container (uic, NULL);
- eab_view_discard_menus (v);
- }
-}
-
-static void
-gather_uids_foreach (char *key,
- gpointer value,
- GList **list)
-{
- (*list) = g_list_prepend (*list, key);
-}
-
-static void
-source_list_changed_cb (ESourceList *source_list, AddressbookView *view)
-{
- GList *uids, *l;
- EABView *v;
-
- uids = NULL;
- g_hash_table_foreach (view->uid_to_view, (GHFunc)gather_uids_foreach, &uids);
-
- for (l = uids; l; l = l->next) {
- char *uid = l->data;
- if (e_source_list_peek_source_by_uid (source_list, uid)) {
- /* the source still exists, do nothing */
- }
- else {
- /* the source no longer exists, remove the
- view and remove it from our hash table. */
- v = g_hash_table_lookup (view->uid_to_view,
- uid);
- g_hash_table_remove (view->uid_to_view, uid);
- gtk_notebook_remove_page (GTK_NOTEBOOK (view->notebook),
- gtk_notebook_page_num (GTK_NOTEBOOK (view->notebook),
- GTK_WIDGET (v)));
- g_object_unref (v);
- }
- }
-
- /* make sure we've got the current view selected and updated
- properly */
- v = get_current_view (view);
- if (v) {
- eab_view_setup_menus (v, bonobo_control_get_ui_component (view->control));
- update_command_state (v, view);
- }
-}
-
-static void
-addressbook_view_clear (AddressbookView *view)
-{
- if (view->book) {
- g_object_unref (view->book);
- view->book = NULL;
- }
-
- if (view->properties) {
- bonobo_object_unref (BONOBO_OBJECT(view->properties));
- view->properties = NULL;
- }
-
- g_free(view->passwd);
- view->passwd = NULL;
-
- if (view->source_list) {
- g_object_unref (view->source_list);
- view->source_list = NULL;
- }
-
- if (view->uid_to_view) {
- g_hash_table_destroy (view->uid_to_view);
- view->uid_to_view = NULL;
- }
-
- if (view->creatable_items_handler) {
- g_object_unref (view->creatable_items_handler);
- view->creatable_items_handler = NULL;
- }
-}
-
-static void
-addressbook_view_ref (AddressbookView *view)
-{
- g_assert (view->refs > 0);
- ++view->refs;
-}
-
-static void
-addressbook_view_unref (AddressbookView *view)
-{
- g_assert (view->refs > 0);
- --view->refs;
- if (view->refs == 0) {
- addressbook_view_clear (view);
- g_free (view);
- }
-}
-
-typedef struct {
- EABView *view;
- ESource *source;
-} BookOpenData;
-
-static void
-book_open_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- BookOpenData *data = closure;
- EABView *view = data->view;
- ESource *source = data->source;
-
- g_free (data);
-
- /* we always set the "source" property on the EABView, since
- we use it to reload a previously failed book. */
- g_object_set(view,
- "source", source,
- NULL);
-
- if (status == E_BOOK_ERROR_OK) {
- g_object_set(view,
- "book", book,
- NULL);
- }
- else {
- eab_load_error_dialog (NULL /* XXX */, source, status);
- }
-
-
- g_object_unref (source);
-}
-
-static void
-destroy_callback(gpointer data, GObject *where_object_was)
-{
- AddressbookView *view = data;
- addressbook_view_unref (view);
-}
-
typedef struct {
EBookCallback cb;
ESource *source;
@@ -799,249 +250,3 @@ addressbook_load_default_book (EBookCallback cb, gpointer closure)
e_book_async_get_default_addressbook (default_book_cb, load_source_data);
}
-
-static void
-activate_source (AddressbookView *view,
- ESource *source,
- const char *uid)
-{
- GtkWidget *uid_view;
- EBook *book;
- BookOpenData *data;
-
- uid_view = g_hash_table_lookup (view->uid_to_view, uid);
-
- if (uid_view) {
- /* there is a view for this uid. make
- sure that the view actually
- contains an EBook (if it doesn't
- contain an EBook a previous load
- failed. try to load it again */
- g_object_get (uid_view,
- "book", &book,
- NULL);
-
- if (book) {
- g_object_unref (book);
- }
- else {
- book = e_book_new ();
-
- g_object_get (uid_view,
- "source", &source,
- NULL);
-
- /* source can be NULL here, if
- a previous load hasn't
- actually made it to
- book_open_cb yet. */
- if (source) {
- data = g_new (BookOpenData, 1);
- data->view = g_object_ref (uid_view);
- data->source = source; /* transfer the ref we get back from g_object_get */
-
- addressbook_load_source (book, source, book_open_cb, data);
- }
- }
- }
- else {
- /* we don't have a view for this uid already
- set up. */
- GtkWidget *label = gtk_label_new (uid);
-
- uid_view = eab_view_new ();
-
- gtk_widget_show (uid_view);
- gtk_widget_show (label);
-
- g_object_set (uid_view, "type", EAB_VIEW_TABLE, NULL);
-
- gtk_notebook_append_page (GTK_NOTEBOOK (view->notebook),
- uid_view,
- label);
-
- g_hash_table_insert (view->uid_to_view, g_strdup (uid), uid_view);
-
- g_signal_connect (uid_view, "status_message",
- G_CALLBACK(set_status_message), view);
-
- g_signal_connect (uid_view, "search_result",
- G_CALLBACK(search_result), view);
-
- g_signal_connect (uid_view, "command_state_change",
- G_CALLBACK(update_command_state), view);
-
- book = e_book_new ();
-
- data = g_new (BookOpenData, 1);
- data->view = g_object_ref (uid_view);
- data->source = g_object_ref (source);
-
- addressbook_load_source (book, source, book_open_cb, data);
- }
-
- gtk_notebook_set_current_page (GTK_NOTEBOOK (view->notebook),
- gtk_notebook_page_num (GTK_NOTEBOOK (view->notebook),
- uid_view));
-
- /* change menus/toolbars to reflect the new view, assuming we are already displayed */
- if (bonobo_ui_component_get_container (bonobo_control_get_ui_component (view->control)) != CORBA_OBJECT_NIL) {
- eab_view_setup_menus (EAB_VIEW (uid_view), bonobo_control_get_ui_component (view->control));
- update_command_state (EAB_VIEW (uid_view), view);
- }
-}
-
-static void
-set_prop (BonoboPropertyBag *bag,
- const BonoboArg *arg,
- guint arg_id,
- CORBA_Environment *ev,
- gpointer user_data)
-{
- AddressbookView *view = user_data;
- ESource *source;
-
- switch (arg_id) {
-
- case PROPERTY_FOLDER_URI_IDX: {
- const gchar *string = BONOBO_ARG_GET_STRING (arg);
- ESourceGroup *group;
-
- group = e_source_group_new ("", string);
- source = e_source_new ("", "");
- e_source_set_group (source, group);
-
- /* we use the uri as the uid here. */
- activate_source (view, source, string);
-
- g_object_unref (group);
-
- break;
- }
- case PROPERTY_SOURCE_UID_IDX: {
- const gchar *uid;
-
- uid = BONOBO_ARG_GET_STRING (arg);
-
- source = e_source_list_peek_source_by_uid (view->source_list, uid);
-
- if (source) {
- activate_source (view, source, uid);
- }
- else {
- g_warning ("Could not find source by UID '%s'!", uid);
- }
-
- break;
- }
- default:
- g_warning ("Unhandled arg %d\n", arg_id);
- break;
- }
-}
-
-static void
-get_prop (BonoboPropertyBag *bag,
- BonoboArg *arg,
- guint arg_id,
- CORBA_Environment *ev,
- gpointer user_data)
-{
- AddressbookView *view = user_data;
- EABView *v = get_current_view (view);
- ESource *source = NULL;
-
- switch (arg_id) {
-
- case PROPERTY_FOLDER_URI_IDX:
- if (v) {
- g_object_get (v,
- "source", &source,
- NULL);
- }
-
- if (source) {
- char *uri = e_source_get_uri (source);
-
- BONOBO_ARG_SET_STRING (arg, uri);
-
- g_free (uri);
- g_object_unref (source);
- }
- else {
- BONOBO_ARG_SET_STRING (arg, "");
- }
- break;
-
- case PROPERTY_SOURCE_UID_IDX:
- if (v) {
- g_object_get (v,
- "source", &source,
- NULL);
- }
-
- if (source) {
- BONOBO_ARG_SET_STRING (arg, e_source_peek_uid (source));
-
- g_object_unref (source);
- }
- else {
- BONOBO_ARG_SET_STRING (arg, "");
- }
-
- break;
-
- default:
- g_warning ("Unhandled arg %d\n", arg_id);
- }
-}
-
-BonoboControl *
-addressbook_new_control (void)
-{
- AddressbookView *view;
-
- view = g_new0 (AddressbookView, 1);
- view->refs = 1;
-
- view->uid_to_view = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL);
-
- view->notebook = gtk_notebook_new ();
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (view->notebook), FALSE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (view->notebook), FALSE);
-
- g_object_weak_ref (G_OBJECT (view->notebook), destroy_callback, view);
-
- /* Create the control. */
- view->control = bonobo_control_new (view->notebook);
-
- gtk_widget_show (view->notebook);
-
- view->properties = bonobo_property_bag_new (get_prop, set_prop, view);
-
- bonobo_property_bag_add (view->properties,
- PROPERTY_SOURCE_UID, PROPERTY_SOURCE_UID_IDX,
- BONOBO_ARG_STRING, NULL,
- _("UID of the contacts source that the view will display"), 0);
-
- bonobo_property_bag_add (view->properties,
- PROPERTY_FOLDER_URI, PROPERTY_FOLDER_URI_IDX,
- BONOBO_ARG_STRING, NULL,
- _("The URI that the address book will display"), 0);
-
- bonobo_control_set_properties (view->control,
- bonobo_object_corba_objref (BONOBO_OBJECT (view->properties)),
- NULL);
-
- view->source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources");
- g_signal_connect (view->source_list,
- "changed",
- G_CALLBACK (source_list_changed_cb), view);
-
- view->creatable_items_handler = e_user_creatable_items_handler_new ("contacts");
-
- g_signal_connect (view->control, "activate",
- G_CALLBACK (control_activate_cb), view);
-
- return view->control;
-}
diff --git a/addressbook/gui/component/addressbook.h b/addressbook/gui/component/addressbook.h
index 6eb4210951..d44f1f2e36 100644
--- a/addressbook/gui/component/addressbook.h
+++ b/addressbook/gui/component/addressbook.h
@@ -7,15 +7,8 @@
#include <bonobo/bonobo-moniker-util.h>
#include <libebook/e-book-async.h>
-/* use this instead of e_book_load_uri everywhere where you want the
- authentication to be handled for you. */
-#if 0
-void addressbook_load_uri (EBook *book, const char *uri, EBookCallback cb, gpointer closure);
-#endif
guint addressbook_load_source (EBook *book, ESource *source, EBookCallback cb, gpointer closure);
void addressbook_load_source_cancel (guint id);
void addressbook_load_default_book (EBookCallback open_response, gpointer closure);
-BonoboControl *addressbook_new_control (void);
-
#endif /* __ADDRESSBOOK_H__ */