From 01b6f4ee32b0aeb16699af276e47618c1f776378 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Fri, 8 Jun 2001 21:36:58 +0000 Subject: remove the gtk_widget_show call... (e_contact_editor_show): and put it 2001-06-08 Chris Toshok * contact-editor/e-contact-editor.c (e_contact_editor_new): remove the gtk_widget_show call... (e_contact_editor_show): and put it here. * contact-editor/e-contact-editor.h: add prototype for e_contact_editor_show. * gui/widgets/e-minicard.c (e_minicard_event): call e_addressbook_show_contact_editor. (card_modified_cb): call e_addressbook_error_dialog if status != SUCCESS. * gui/widgets/e-minicard-view.c (e_minicard_view_event): call e_addressbook_show_contact_editor. also, use card_modified_cb as the commit_card callback. * gui/widgets/e-addressbook-view.c (table_double_click): clean this area up alot, call e_addressbook_show_contact_editor. (card_deleted_cb): call e_addressbook_error_dialog. * gui/widgets/e-addressbook-table-adapter.c (card_modified_cb): new function, call e_addressbook_error_dialog if the status != SUCCESS. (addressbook_set_value_at): use card_modified_cb as the callback for e_book_commit_card. * gui/widgets/Makefile.am (libeminicard_a_SOURCES): add e-addressbook-util.[ch]. * gui/component/addressbook.c (new_contact_cb): use e_addressbook_show_contact_editor here. svn path=/trunk/; revision=10164 --- addressbook/gui/widgets/e-addressbook-util.c | 160 +++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 addressbook/gui/widgets/e-addressbook-util.c (limited to 'addressbook/gui/widgets/e-addressbook-util.c') diff --git a/addressbook/gui/widgets/e-addressbook-util.c b/addressbook/gui/widgets/e-addressbook-util.c new file mode 100644 index 0000000000..55d3ce503e --- /dev/null +++ b/addressbook/gui/widgets/e-addressbook-util.c @@ -0,0 +1,160 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-table-field-chooser.c + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Toshok + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include + +#include "e-addressbook-util.h" +#include "e-contact-editor.h" + +void +e_addressbook_error_dialog (const gchar *msg, EBookStatus status) +{ + static char *status_to_string[] = { + N_("Success"), + N_("Unknown error"), + N_("Repository offline"), + N_("Permission denied"), + N_("Card not found"), + N_("Protocol not supported"), + N_("Canceled"), + N_("Other error") + }; + char *error_msg; + + error_msg = g_strdup_printf ("%s: %s", msg, status_to_string [status]); + + gtk_widget_show (gnome_error_dialog (error_msg)); + + g_free (error_msg); +} + + +static void +card_added_cb (EBook* book, EBookStatus status, const char *id, + gpointer user_data) +{ + g_print ("%s: %s(): a card was added\n", __FILE__, __FUNCTION__); + if (status != E_BOOK_STATUS_SUCCESS) + e_addressbook_error_dialog (_("Error adding card"), status); +} + +static void +card_modified_cb (EBook* book, EBookStatus status, + gpointer user_data) +{ + g_print ("%s: %s(): a card was modified\n", __FILE__, __FUNCTION__); + if (status != E_BOOK_STATUS_SUCCESS) + e_addressbook_error_dialog (_("Error modifying card"), status); +} + +static void +card_removed_cb (EBook* book, EBookStatus status, + gpointer user_data) +{ + g_print ("%s: %s(): a card was removed\n", __FILE__, __FUNCTION__); + if (status != E_BOOK_STATUS_SUCCESS) + e_addressbook_error_dialog (_("Error removing card"), status); +} + +/* Callback for the add_card signal from the contact editor */ +static void +add_card_cb (EContactEditor *ce, ECard *card, gpointer data) +{ + EBook *book; + + book = E_BOOK (data); + e_book_add_card (book, card, card_added_cb, NULL); +} + +/* Callback for the commit_card signal from the contact editor */ +static void +commit_card_cb (EContactEditor *ce, ECard *card, gpointer data) +{ + EBook *book; + + book = E_BOOK (data); + e_book_commit_card (book, card, card_modified_cb, NULL); +} + +/* Callback for the delete_card signal from the contact editor */ +static void +delete_card_cb (EContactEditor *ce, ECard *card, gpointer data) +{ + EBook *book; + + book = E_BOOK (data); + e_book_remove_card (book, card, card_removed_cb, NULL); +} + +/* Callback used when the contact editor is closed */ +static void +editor_closed_cb (EContactEditor *ce, gpointer data) +{ + gtk_object_unref (GTK_OBJECT (ce)); +} + +typedef struct { + ECard *card; + gboolean editable; +} SupportedFieldsClosure; + +static void +supported_fields_cb (EBook *book, EBookStatus status, + EList *fields, EContactEditor *ce) +{ + gtk_object_set (GTK_OBJECT (ce), + "writable_fields", fields, + NULL); + + gtk_signal_connect (GTK_OBJECT (ce), "add_card", + GTK_SIGNAL_FUNC (add_card_cb), book); + gtk_signal_connect (GTK_OBJECT (ce), "commit_card", + GTK_SIGNAL_FUNC (commit_card_cb), book); + gtk_signal_connect (GTK_OBJECT (ce), "delete_card", + GTK_SIGNAL_FUNC (delete_card_cb), book); + gtk_signal_connect (GTK_OBJECT (ce), "editor_closed", + GTK_SIGNAL_FUNC (editor_closed_cb), NULL); + + e_contact_editor_show (ce); +} + +EContactEditor * +e_addressbook_show_contact_editor (EBook *book, ECard *card, + gboolean editable) +{ + EContactEditor *ce; + gboolean new_card = FALSE; + + if (card == NULL) { + new_card = TRUE; + card = e_card_new (""); + } + + ce = e_contact_editor_new (card, new_card, NULL, + !editable); + + e_book_get_supported_fields (book, (EBookFieldsCallback)supported_fields_cb, ce); + + return ce; +} -- cgit v1.2.3