From 68a1984433b5b8597ea7cf99fc2417a30dc2d89d Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Wed, 20 Jun 2001 00:34:24 +0000 Subject: rename ce_book_found_fields to this, remove the fetching of fields (the 2001-06-19 Chris Toshok * contact-editor/e-contact-quick-add.c (ce_have_book): rename ce_book_found_fields to this, remove the fetching of fields (the contact editor code handles that now.), and change the add_card signal to card_added. (card_added_cb): copied somewhat from merge_cb above. we don't need to do the merge here, just call the callback. * contact-editor/e-contact-editor.c (e_contact_editor_class_init): track signal change. add book arg, and is_read_only -> editable. (wants_html_changed): if the card isn't already changed, flag it as such (and update the commands.) (phone_entry_changed): same. (email_entry_changed): same. (address_text_changed): same. (name_entry_changed): same. (company_entry_changed): same. (full_name_clicked): is_read_only -> editable. (full_addr_clicked): same. (card_added_cb): new function, emit our card_added signal, and close the dialog if we're supposed to. properly deal with error status here. (card_modified_cb): same, modulo card_added -> card_modified. (save_card): actually call e_card_merging_book_{add/commit}_card instead of using a signal. Also, add a gboolean arg to tell whether or not to close the dialog after saving the card. (card_deleted_cb): new function, just emit our "card_deleted" signal. (delete_cb): actually call e_book_remove_card here, instead of using a signal. (tb_save_and_close_cb): call save_card with TRUE for should_close. (e_contact_editor_init): init changed = FALSE; (e_contact_editor_destroy): unref our book if we have one. (e_contact_editor_new): new signature, set the "book" arg, and call e_book_get_supported_fields here. (supported_fields_cb): new function, show the contact editor. (e_contact_editor_set_arg): initialize changed to FALSE when setting the card (but *after*, since the changed callbacks will set it to TRUE.) also, call command_state_changed if editable changes. also handle setting "book". oh, and is_read_only -> editable. (command_state_changed): new function - set the state of the commands we care about. (e_contact_editor_get_arg): add "book" handling, and is_read_only -> editable. (_phone_arrow_pressed): is_read_only -> editable. (_email_arrow_pressed): same. (_address_arrow_pressed): same. (enable_writable_fields): same. (set_editable): rename set_read_only to this, and is_read_only -> editable. * contact-editor/e-contact-editor.h (struct _EContactEditor): is_read_only -> editable, add a "changed" flag so we can sensitize commands correctly, and add an EBook* arg to e_contact_editor_new and to the EContactEditor struct. Also, change all the signals to past tense, and send the EBookStatus in them. * contact-editor/e-contact-editor-address.c (e_contact_editor_address_class_init): is_read_only -> editable. (e_contact_editor_address_set_arg): same. (e_contact_editor_address_get_arg): same. * contact-editor/e-contact-editor-address.h (struct _EContactEditorAddress): same. * contact-editor/e-contact-editor-fullname.c (e_contact_editor_fullname_class_init): same. (e_contact_editor_fullname_set_arg): same. (e_contact_editor_fullname_get_arg): same. * contact-editor/e-contact-editor-fullname.h (struct _EContactEditorFullname): same. * contact-editor/Makefile.am: don't build contact-editor-test now, until contact-editor gets moved to gui/ and we can more easily depend on the e_card_merging_* calls. * backend/pas/pas-backend-ldap.c (ldap_error_to_response): return CardIdAlreadyExists for LDAP_ALREADY_EXISTS. * backend/idl/addressbook.idl: Add CardIdAlreadyExists to the BookListener status enum. * backend/ebook/e-book-types.h: add E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS. * backend/ebook/e-book-listener.c (e_book_listener_convert_status): add support for CardIdAlreadyExists. svn path=/trunk/; revision=10317 --- addressbook/ChangeLog | 92 +++++++ addressbook/backend/ebook/e-book-listener.c | 2 + addressbook/backend/ebook/e-book-types.h | 1 + addressbook/backend/idl/addressbook.idl | 1 + addressbook/backend/pas/pas-backend-ldap.c | 8 +- addressbook/contact-editor/Makefile.am | 38 +-- .../contact-editor/e-contact-editor-address.c | 8 +- .../contact-editor/e-contact-editor-address.h | 2 +- .../contact-editor/e-contact-editor-fullname.c | 8 +- .../contact-editor/e-contact-editor-fullname.h | 2 +- addressbook/contact-editor/e-contact-editor.c | 297 +++++++++++++++------ addressbook/contact-editor/e-contact-editor.h | 22 +- addressbook/contact-editor/e-contact-quick-add.c | 49 ++-- addressbook/gui/contact-editor/Makefile.am | 38 +-- .../gui/contact-editor/e-contact-editor-address.c | 8 +- .../gui/contact-editor/e-contact-editor-address.h | 2 +- .../gui/contact-editor/e-contact-editor-fullname.c | 8 +- .../gui/contact-editor/e-contact-editor-fullname.h | 2 +- addressbook/gui/contact-editor/e-contact-editor.c | 297 +++++++++++++++------ addressbook/gui/contact-editor/e-contact-editor.h | 22 +- .../gui/contact-editor/e-contact-quick-add.c | 49 ++-- 21 files changed, 664 insertions(+), 292 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index ba75cdc205..2c21b19837 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,95 @@ +2001-06-19 Chris Toshok + + * contact-editor/e-contact-quick-add.c (ce_have_book): rename + ce_book_found_fields to this, remove the fetching of fields (the + contact editor code handles that now.), and change the add_card + signal to card_added. + (card_added_cb): copied somewhat from merge_cb above. we don't + need to do the merge here, just call the callback. + + * contact-editor/e-contact-editor.c (e_contact_editor_class_init): + track signal change. add book arg, and is_read_only -> editable. + (wants_html_changed): if the card isn't already changed, flag it + as such (and update the commands.) + (phone_entry_changed): same. + (email_entry_changed): same. + (address_text_changed): same. + (name_entry_changed): same. + (company_entry_changed): same. + (full_name_clicked): is_read_only -> editable. + (full_addr_clicked): same. + (card_added_cb): new function, emit our card_added signal, and + close the dialog if we're supposed to. properly deal with error + status here. + (card_modified_cb): same, modulo card_added -> card_modified. + (save_card): actually call e_card_merging_book_{add/commit}_card + instead of using a signal. Also, add a gboolean arg to tell + whether or not to close the dialog after saving the card. + (card_deleted_cb): new function, just emit our "card_deleted" + signal. + (delete_cb): actually call e_book_remove_card here, instead of + using a signal. + (tb_save_and_close_cb): call save_card with TRUE for should_close. + (e_contact_editor_init): init changed = FALSE; + (e_contact_editor_destroy): unref our book if we have one. + (e_contact_editor_new): new signature, set the "book" arg, and + call e_book_get_supported_fields here. + (supported_fields_cb): new function, show the contact editor. + (e_contact_editor_set_arg): initialize changed to FALSE when + setting the card (but *after*, since the changed callbacks will + set it to TRUE.) also, call command_state_changed if editable + changes. also handle setting "book". oh, and is_read_only -> + editable. + (command_state_changed): new function - set the state of the + commands we care about. + (e_contact_editor_get_arg): add "book" handling, and is_read_only + -> editable. + (_phone_arrow_pressed): is_read_only -> editable. + (_email_arrow_pressed): same. + (_address_arrow_pressed): same. + (enable_writable_fields): same. + (set_editable): rename set_read_only to this, and is_read_only -> + editable. + + * contact-editor/e-contact-editor.h (struct _EContactEditor): + is_read_only -> editable, add a "changed" flag so we can sensitize + commands correctly, and add an EBook* arg to e_contact_editor_new + and to the EContactEditor struct. Also, change all the signals to + past tense, and send the EBookStatus in them. + + * contact-editor/e-contact-editor-address.c + (e_contact_editor_address_class_init): is_read_only -> editable. + (e_contact_editor_address_set_arg): same. + (e_contact_editor_address_get_arg): same. + + * contact-editor/e-contact-editor-address.h (struct + _EContactEditorAddress): same. + + * contact-editor/e-contact-editor-fullname.c + (e_contact_editor_fullname_class_init): same. + (e_contact_editor_fullname_set_arg): same. + (e_contact_editor_fullname_get_arg): same. + + * contact-editor/e-contact-editor-fullname.h (struct + _EContactEditorFullname): same. + + * contact-editor/Makefile.am: don't build contact-editor-test now, + until contact-editor gets moved to gui/ and we can more easily + depend on the e_card_merging_* calls. + + * backend/pas/pas-backend-ldap.c (ldap_error_to_response): return + CardIdAlreadyExists for LDAP_ALREADY_EXISTS. + + * backend/idl/addressbook.idl: Add CardIdAlreadyExists to the + BookListener status enum. + + * backend/ebook/e-book-types.h: add + E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS. + + * backend/ebook/e-book-listener.c + (e_book_listener_convert_status): add support for + CardIdAlreadyExists. + 2001-06-19 Jon Trowbridge * contact-editor/e-contact-quick-add.c: Serious de-crufting, diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c index f9d4f67f97..b483d10d87 100644 --- a/addressbook/backend/ebook/e-book-listener.c +++ b/addressbook/backend/ebook/e-book-listener.c @@ -480,6 +480,8 @@ e_book_listener_convert_status (const GNOME_Evolution_Addressbook_BookListener_C return E_BOOK_STATUS_PERMISSION_DENIED; case GNOME_Evolution_Addressbook_BookListener_CardNotFound: return E_BOOK_STATUS_CARD_NOT_FOUND; + case GNOME_Evolution_Addressbook_BookListener_CardIdAlreadyExists: + return E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS; case GNOME_Evolution_Addressbook_BookListener_ProtocolNotSupported: return E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED; case GNOME_Evolution_Addressbook_BookListener_OtherError: diff --git a/addressbook/backend/ebook/e-book-types.h b/addressbook/backend/ebook/e-book-types.h index d7eee35ede..d6d69b4b20 100644 --- a/addressbook/backend/ebook/e-book-types.h +++ b/addressbook/backend/ebook/e-book-types.h @@ -22,6 +22,7 @@ typedef enum { E_BOOK_STATUS_REPOSITORY_OFFLINE, E_BOOK_STATUS_PERMISSION_DENIED, E_BOOK_STATUS_CARD_NOT_FOUND, + E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS, E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED, E_BOOK_STATUS_CANCELLED, E_BOOK_STATUS_OTHER_ERROR diff --git a/addressbook/backend/idl/addressbook.idl b/addressbook/backend/idl/addressbook.idl index 877813e5d3..583824bba2 100644 --- a/addressbook/backend/idl/addressbook.idl +++ b/addressbook/backend/idl/addressbook.idl @@ -105,6 +105,7 @@ module Addressbook { RepositoryOffline, PermissionDenied, CardNotFound, + CardIdAlreadyExists, ProtocolNotSupported, AuthenticationFailed, AuthenticationRequired, diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index ae683594c5..9562441181 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -29,12 +29,6 @@ #define OPENLDAP1 #endif -#if 0 -#ifdef OPENLDAP1 -#define LDAP_NAME_ERROR(x) NAME_ERROR(x) -#endif -#endif - #ifdef OPENLDAP2 #include "ldap_schema.h" #endif @@ -530,6 +524,8 @@ ldap_error_to_response (int ldap_error) return GNOME_Evolution_Addressbook_BookListener_PermissionDenied; else if (ldap_error == LDAP_SERVER_DOWN) return GNOME_Evolution_Addressbook_BookListener_RepositoryOffline; + else if (ldap_error == LDAP_ALREADY_EXISTS) + return GNOME_Evolution_Addressbook_BookListener_CardIdAlreadyExists; else return GNOME_Evolution_Addressbook_BookListener_OtherError; } diff --git a/addressbook/contact-editor/Makefile.am b/addressbook/contact-editor/Makefile.am index 47a79c7255..6d3567b2f7 100644 --- a/addressbook/contact-editor/Makefile.am +++ b/addressbook/contact-editor/Makefile.am @@ -27,25 +27,25 @@ libecontacteditor_a_SOURCES = \ e-contact-quick-add.c \ e-contact-quick-add.h -noinst_PROGRAMS = \ - contact-editor-test - -contact_editor_test_SOURCES = \ - test-editor.c - -contact_editor_test_LDADD = \ - libecontacteditor.a \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/addressbook/printing/libecontactprint.a \ - $(top_builddir)/addressbook/backend/ebook/libebook.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(GNOMEGNORBA_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) \ - $(EXTRA_GNOME_LIBS) +# noinst_PROGRAMS = \ +# contact-editor-test + +# contact_editor_test_SOURCES = \ +# test-editor.c + +# contact_editor_test_LDADD = \ +# libecontacteditor.a \ +# $(top_builddir)/e-util/libeutil.la \ +# $(top_builddir)/addressbook/printing/libecontactprint.a \ +# $(top_builddir)/addressbook/backend/ebook/libebook.la \ +# $(top_builddir)/e-util/ename/libename.la \ +# $(top_builddir)/libversit/libversit.la \ +# $(GNOMEGNORBA_LIBS) \ +# $(BONOBO_GNOME_LIBS) \ +# $(top_builddir)/widgets/misc/libemiscwidgets.a \ +# $(top_builddir)/e-util/libeutil.la \ +# $(GNOME_PRINT_LIBS) \ +# $(EXTRA_GNOME_LIBS) evolutiondir = $(datadir)/evolution diff --git a/addressbook/contact-editor/e-contact-editor-address.c b/addressbook/contact-editor/e-contact-editor-address.c index 777a3cb617..4ffd499e13 100644 --- a/addressbook/contact-editor/e-contact-editor-address.c +++ b/addressbook/contact-editor/e-contact-editor-address.c @@ -81,7 +81,7 @@ e_contact_editor_address_class_init (EContactEditorAddressClass *klass) gtk_object_add_arg_type ("EContactEditorAddress::address", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_ADDRESS); - gtk_object_add_arg_type ("EContactEditorAddress::is_read_only", GTK_TYPE_BOOL, + gtk_object_add_arg_type ("EContactEditorAddress::editable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_READ_ONLY); object_class->set_arg = e_contact_editor_address_set_arg; @@ -161,9 +161,9 @@ e_contact_editor_address_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "entry-code", NULL }; - e_contact_editor_address->is_read_only = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; + e_contact_editor_address->editable = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; for (i = 0; entry_names[i] != NULL; i ++) { - gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_address->gui, entry_names[i]), !e_contact_editor_address->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_address->gui, entry_names[i]), e_contact_editor_address->editable); } break; } @@ -183,7 +183,7 @@ e_contact_editor_address_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_POINTER (*arg) = e_card_delivery_address_copy(e_contact_editor_address->address); break; case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor_address->is_read_only ? TRUE : FALSE; + GTK_VALUE_BOOL (*arg) = e_contact_editor_address->editable ? TRUE : FALSE; break; default: arg->type = GTK_TYPE_INVALID; diff --git a/addressbook/contact-editor/e-contact-editor-address.h b/addressbook/contact-editor/e-contact-editor-address.h index 48d88aab85..e555370528 100644 --- a/addressbook/contact-editor/e-contact-editor-address.h +++ b/addressbook/contact-editor/e-contact-editor-address.h @@ -56,7 +56,7 @@ struct _EContactEditorAddress /* item specific fields */ ECardDeliveryAddress *address; - guint is_read_only : 1; + guint editable : 1; GladeXML *gui; }; diff --git a/addressbook/contact-editor/e-contact-editor-fullname.c b/addressbook/contact-editor/e-contact-editor-fullname.c index 69477d3325..bb622cdf3e 100644 --- a/addressbook/contact-editor/e-contact-editor-fullname.c +++ b/addressbook/contact-editor/e-contact-editor-fullname.c @@ -82,7 +82,7 @@ e_contact_editor_fullname_class_init (EContactEditorFullnameClass *klass) gtk_object_add_arg_type ("EContactEditorFullname::name", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_NAME); - gtk_object_add_arg_type ("EContactEditorFullname::is_read_only", GTK_TYPE_BOOL, + gtk_object_add_arg_type ("EContactEditorFullname::editable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_READ_ONLY); object_class->set_arg = e_contact_editor_fullname_set_arg; @@ -159,11 +159,11 @@ e_contact_editor_fullname_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "entry-last", NULL }; - e_contact_editor_fullname->is_read_only = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; + e_contact_editor_fullname->editable = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; for (i = 0; entry_names[i] != NULL; i ++) { gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_fullname->gui, entry_names[i]), - !e_contact_editor_fullname->is_read_only); + e_contact_editor_fullname->editable); } break; } @@ -183,7 +183,7 @@ e_contact_editor_fullname_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_POINTER (*arg) = e_card_name_copy(e_contact_editor_fullname->name); break; case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor_fullname->is_read_only ? TRUE : FALSE; + GTK_VALUE_BOOL (*arg) = e_contact_editor_fullname->editable ? TRUE : FALSE; break; default: arg->type = GTK_TYPE_INVALID; diff --git a/addressbook/contact-editor/e-contact-editor-fullname.h b/addressbook/contact-editor/e-contact-editor-fullname.h index 70bb793d0a..3a27551910 100644 --- a/addressbook/contact-editor/e-contact-editor-fullname.h +++ b/addressbook/contact-editor/e-contact-editor-fullname.h @@ -58,7 +58,7 @@ struct _EContactEditorFullname GladeXML *gui; /* Whether the dialog will accept modifications */ - guint is_read_only : 1; + guint editable : 1; }; struct _EContactEditorFullnameClass diff --git a/addressbook/contact-editor/e-contact-editor.c b/addressbook/contact-editor/e-contact-editor.c index 4be7b90303..2a1eb40653 100644 --- a/addressbook/contact-editor/e-contact-editor.c +++ b/addressbook/contact-editor/e-contact-editor.c @@ -43,6 +43,8 @@ #include "e-util/e-gui-utils.h" #include "widgets/misc/e-dateedit.h" +#include "e-card-merging.h" + #include "e-contact-editor.h" #include "e-contact-editor-address.h" #include "e-contact-editor-fullname.h" @@ -50,9 +52,9 @@ /* Signal IDs */ enum { - ADD_CARD, - COMMIT_CARD, - DELETE_CARD, + CARD_ADDED, + CARD_MODIFIED, + CARD_DELETED, EDITOR_CLOSED, LAST_SIGNAL }; @@ -70,12 +72,13 @@ static void _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, ECo static void _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void enable_writable_fields(EContactEditor *editor); -static void set_read_only(EContactEditor *editor); +static void set_editable(EContactEditor *editor); static void fill_in_info(EContactEditor *editor); static void extract_info(EContactEditor *editor); static void set_fields(EContactEditor *editor); static void set_address_field(EContactEditor *editor, int result); static void add_field_callback(GtkWidget *widget, EContactEditor *editor); +static void command_state_changed (EContactEditor *ce); static GtkObjectClass *parent_class = NULL; @@ -84,9 +87,10 @@ static guint contact_editor_signals[LAST_SIGNAL]; /* The arguments we take */ enum { ARG_0, + ARG_BOOK, ARG_CARD, ARG_IS_NEW_CARD, - ARG_IS_READ_ONLY, + ARG_EDITABLE, ARG_WRITABLE_FIELDS }; @@ -121,6 +125,24 @@ e_contact_editor_get_type (void) return contact_editor_type; } +typedef void (*GtkSignal_NONE__INT_OBJECT) (GtkObject * object, + gint arg1, + GtkObject *arg2, + gpointer user_data); + +static void +e_marshal_NONE__INT_OBJECT (GtkObject * object, + GtkSignalFunc func, + gpointer func_data, GtkArg * args) +{ + GtkSignal_NONE__INT_OBJECT rfunc; + rfunc = (GtkSignal_NONE__INT_OBJECT) func; + (*rfunc) (object, + GTK_VALUE_INT (args[0]), + GTK_VALUE_OBJECT (args[1]), + func_data); +} + static void e_contact_editor_class_init (EContactEditorClass *klass) { @@ -130,41 +152,43 @@ e_contact_editor_class_init (EContactEditorClass *klass) parent_class = gtk_type_class (GTK_TYPE_OBJECT); + gtk_object_add_arg_type ("EContactEditor::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); gtk_object_add_arg_type ("EContactEditor::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); gtk_object_add_arg_type ("EContactEditor::is_new_card", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_NEW_CARD); gtk_object_add_arg_type ("EContactEditor::writable_fields", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_WRITABLE_FIELDS); - gtk_object_add_arg_type ("EContactEditor::is_read_only", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_IS_READ_ONLY); + gtk_object_add_arg_type ("EContactEditor::editable", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_EDITABLE); - contact_editor_signals[ADD_CARD] = - gtk_signal_new ("add_card", + contact_editor_signals[CARD_ADDED] = + gtk_signal_new ("card_added", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, add_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_added), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); - contact_editor_signals[COMMIT_CARD] = - gtk_signal_new ("commit_card", + contact_editor_signals[CARD_MODIFIED] = + gtk_signal_new ("card_modified", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, commit_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_modified), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); - contact_editor_signals[DELETE_CARD] = - gtk_signal_new ("delete_card", + contact_editor_signals[CARD_DELETED] = + gtk_signal_new ("card_deleted", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, delete_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_deleted), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); contact_editor_signals[EDITOR_CLOSED] = gtk_signal_new ("editor_closed", @@ -220,6 +244,11 @@ wants_html_changed (GtkWidget *widget, EContactEditor *editor) gtk_object_set(GTK_OBJECT(editor->card), "wants_html", wants_html, NULL); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -249,6 +278,11 @@ phone_entry_changed (GtkWidget *widget, EContactEditor *editor) #endif e_card_phone_free(phone); set_fields(editor); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -262,6 +296,11 @@ email_entry_changed (GtkWidget *widget, EContactEditor *editor) e_card_simple_set_email(editor->simple, editor->email_choice, string); g_free (string); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -279,6 +318,11 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor) e_card_simple_set_address(editor->simple, editor->address_choice, address); e_card_address_label_free(address); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } /* This function tells you whether name_to_style will make sense. */ @@ -450,6 +494,11 @@ name_entry_changed (GtkWidget *widget, EContactEditor *editor) g_free (string); file_as_set_style(editor, style); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -464,6 +513,11 @@ company_entry_changed (GtkWidget *widget, EContactEditor *editor) editor->company = e_utf8_gtk_entry_get_text(GTK_ENTRY(widget)); file_as_set_style(editor, style); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -512,7 +566,7 @@ full_name_clicked(GtkWidget *button, EContactEditor *editor) int result; gtk_object_set (GTK_OBJECT (dialog), - "is_read_only", editor->is_read_only, + "editable", editor->editable, NULL); gtk_widget_show(GTK_WIDGET(dialog)); result = gnome_dialog_run (dialog); @@ -554,7 +608,7 @@ full_addr_clicked(GtkWidget *button, EContactEditor *editor) dialog = GNOME_DIALOG(e_contact_editor_address_new(address)); gtk_object_set (GTK_OBJECT (dialog), - "is_read_only", editor->is_read_only, + "editable", editor->editable, NULL); gtk_widget_show(GTK_WIDGET(dialog)); @@ -624,25 +678,65 @@ categories_clicked(GtkWidget *button, EContactEditor *editor) #endif } +typedef struct { + EContactEditor *ce; + gboolean should_close; +} EditorCloseStruct; + +static void +card_added_cb (EBook *book, EBookStatus status, const char *id, EditorCloseStruct *ecs) +{ + EContactEditor *ce = ecs->ce; + gboolean should_close = ecs->should_close; + + g_free (ecs); + + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_ADDED], + status, ce->card); + + if (status == E_BOOK_STATUS_SUCCESS) { + ce->is_new_card = FALSE; + + if (should_close) + close_dialog (ce); + } +} + +static void +card_modified_cb (EBook *book, EBookStatus status, EditorCloseStruct *ecs) +{ + EContactEditor *ce = ecs->ce; + gboolean should_close = ecs->should_close; + + g_free (ecs); + + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_MODIFIED], + status, ce->card); + + if (status == E_BOOK_STATUS_SUCCESS) { + if (should_close) + close_dialog (ce); + } +} + /* Emits the signal to request saving a card */ static void -save_card (EContactEditor *ce) +save_card (EContactEditor *ce, gboolean should_close) { extract_info (ce); e_card_simple_sync_card (ce->simple); - if (ce->is_new_card) - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[ADD_CARD], - ce->card); - else - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[COMMIT_CARD], - ce->card); - - /* FIXME: should we set the ce->is_new_card here or have the client code - * set the "is_new_card" argument on the contact editor object? - */ + if (ce->book) { + EditorCloseStruct *ecs = g_new(EditorCloseStruct, 1); + + ecs->ce = ce; + ecs->should_close = should_close; - ce->is_new_card = FALSE; + if (ce->is_new_card) + e_card_merging_book_add_card (ce->book, ce->card, GTK_SIGNAL_FUNC(card_added_cb), ecs); + else + e_card_merging_book_commit_card (ce->book, ce->card, GTK_SIGNAL_FUNC(card_modified_cb), ecs); + } } /* Closes the dialog box and emits the appropriate signals */ @@ -666,7 +760,7 @@ file_save_cb (GtkWidget *widget, gpointer data) EContactEditor *ce; ce = E_CONTACT_EDITOR (data); - save_card (ce); + save_card (ce, FALSE); } /* File/Close callback */ @@ -744,6 +838,13 @@ e_contact_editor_confirm_delete(GtkWindow *parent) return !result; } +static void +card_deleted_cb (EBook *book, EBookStatus status, EContactEditor *ce) +{ + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_DELETED], + status, ce->card); +} + static void delete_cb (GtkWidget *widget, gpointer data) { @@ -759,11 +860,8 @@ delete_cb (GtkWidget *widget, gpointer data) extract_info (ce); e_card_simple_sync_card (simple); - if (!ce->is_new_card) - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[DELETE_CARD], - card); - - close_dialog (ce); + if (!ce->is_new_card && ce->book) + e_book_remove_card (ce->book, card, GTK_SIGNAL_FUNC(card_deleted_cb), ce); } gtk_object_unref(GTK_OBJECT(card)); @@ -805,8 +903,7 @@ tb_save_and_close_cb (BonoboUIComponent *uih, void *data, const char *path) EContactEditor *ce; ce = E_CONTACT_EDITOR (data); - save_card (ce); - close_dialog (ce); + save_card (ce, TRUE); } static @@ -920,6 +1017,7 @@ e_contact_editor_init (EContactEditor *e_contact_editor) e_contact_editor->simple = e_card_simple_new(NULL); e_contact_editor->card = NULL; + e_contact_editor->changed = FALSE; gui = glade_xml_new (EVOLUTION_GLADEDIR "/contact-editor.glade", NULL); e_contact_editor->gui = gui; @@ -1041,6 +1139,9 @@ e_contact_editor_destroy (GtkObject *object) { if (e_contact_editor->simple) gtk_object_unref(GTK_OBJECT(e_contact_editor->simple)); + if (e_contact_editor->book) + gtk_object_unref(GTK_OBJECT(e_contact_editor->book)); + if (e_contact_editor->name) e_card_name_free(e_contact_editor->name); @@ -1049,23 +1150,56 @@ e_contact_editor_destroy (GtkObject *object) { gtk_object_unref(GTK_OBJECT(e_contact_editor->gui)); } +static void +command_state_changed (EContactEditor *ce) +{ + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorSaveClose", + "sensitive", + ce->changed ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorSave", + "sensitive", + ce->changed ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorDelete", + "sensitive", + (ce->editable && !ce->is_new_card) ? "1" : "0", NULL); +} + +static void +supported_fields_cb (EBook *book, EBookStatus status, + EList *fields, EContactEditor *ce) +{ + gtk_object_set (GTK_OBJECT (ce), + "writable_fields", fields, + NULL); + + e_contact_editor_show (ce); + + command_state_changed (ce); +} + EContactEditor * -e_contact_editor_new (ECard *card, +e_contact_editor_new (EBook *book, + ECard *card, gboolean is_new_card, - EList *fields, - gboolean is_read_only) + gboolean editable) { EContactEditor *ce; ce = E_CONTACT_EDITOR (gtk_type_new (E_CONTACT_EDITOR_TYPE)); gtk_object_set (GTK_OBJECT (ce), + "book", book, "card", card, "is_new_card", is_new_card, - "writable_fields", fields, - "is_read_only", is_read_only, + "editable", editable, NULL); + if (book) + e_book_get_supported_fields (book, (EBookFieldsCallback)supported_fields_cb, ce); + return ce; } @@ -1077,6 +1211,13 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) editor = E_CONTACT_EDITOR (o); switch (arg_id){ + case ARG_BOOK: + if (editor->book) + gtk_object_unref(GTK_OBJECT(editor->book)); + editor->book = E_BOOK(GTK_VALUE_OBJECT (*arg)); + gtk_object_ref (GTK_OBJECT (editor->book)); + /* XXX more here about editable/etc. */ + break; case ARG_CARD: if (editor->card) gtk_object_unref(GTK_OBJECT(editor->card)); @@ -1085,20 +1226,23 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "card", editor->card, NULL); fill_in_info(editor); + editor->changed = FALSE; break; case ARG_IS_NEW_CARD: editor->is_new_card = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; break; - case ARG_IS_READ_ONLY: { + case ARG_EDITABLE: { gboolean new_value = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; - gboolean changed = (editor->is_read_only != new_value); + gboolean changed = (editor->editable != new_value); - editor->is_read_only = new_value; + editor->editable = new_value; - if (changed) - set_read_only (editor); + if (changed) { + set_editable (editor); + command_state_changed (editor); + } break; } case ARG_WRITABLE_FIELDS: @@ -1122,6 +1266,10 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) e_contact_editor = E_CONTACT_EDITOR (object); switch (arg_id) { + case ARG_BOOK: + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_contact_editor->book); + break; + case ARG_CARD: e_card_simple_sync_card(e_contact_editor->simple); extract_info(e_contact_editor); @@ -1132,8 +1280,8 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_BOOL (*arg) = e_contact_editor->is_new_card ? TRUE : FALSE; break; - case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor->is_read_only ? TRUE : FALSE; + case ARG_EDITABLE: + GTK_VALUE_BOOL (*arg) = e_contact_editor->editable ? TRUE : FALSE; break; case ARG_WRITABLE_FIELDS: @@ -1450,7 +1598,7 @@ _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor editor->phone_choice[which - 1] = result; set_fields(editor); gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, label), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, entry), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, entry), editor->editable); } g_free(label); @@ -1483,8 +1631,8 @@ _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor /* make sure the buttons/entry is/are sensitive */ gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-email1"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), editor->editable); } } @@ -1513,8 +1661,8 @@ _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEdito /* make sure the buttons/entry is/are sensitive */ gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-address"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), editor->editable); } } @@ -1846,13 +1994,13 @@ enable_writable_fields(EContactEditor *editor) enabled. */ if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_email_to_field(editor->email_choice)))) { gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-email1"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), editor->editable); gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), TRUE); } else if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_address_to_field(editor->address_choice)))) { gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-address"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), editor->editable); } else for (i = 0; i < 4; i ++) { if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_phone_to_field(editor->phone_choice[i])))) { @@ -1860,7 +2008,7 @@ enable_writable_fields(EContactEditor *editor) gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), TRUE); g_free (widget_name); widget_name = g_strdup_printf ("entry-phone%d", i+1); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), editor->editable); g_free (widget_name); } } @@ -1883,7 +2031,7 @@ enable_writable_fields(EContactEditor *editor) } static void -set_read_only (EContactEditor *editor) +set_editable (EContactEditor *editor) { int i; char *label, *entry; @@ -1891,7 +2039,7 @@ set_read_only (EContactEditor *editor) for (i = 0; i < num_widget_field_mappings; i ++) { if (widget_field_mappings[i].desensitize_for_read_only) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - widget_field_mappings[i].widget_name), !editor->is_read_only); + widget_field_mappings[i].widget_name), editor->editable); } /* handle the phone dropdown entries */ @@ -1901,7 +2049,7 @@ set_read_only (EContactEditor *editor) if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); g_free (label); g_free (entry); @@ -1912,9 +2060,9 @@ set_read_only (EContactEditor *editor) entry = "entry-email1"; if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) { gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - "checkbutton-htmlmail"), !editor->is_read_only); + "checkbutton-htmlmail"), editor->editable); } /* handle the address dropdown entry */ @@ -1922,7 +2070,7 @@ set_read_only (EContactEditor *editor) entry = "text-address"; if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); } static void @@ -2140,7 +2288,6 @@ e_contact_editor_show (EContactEditor *ce) gtk_widget_show (ce->app); } - GtkWidget * e_contact_editor_create_date(gchar *name, gchar *string1, gchar *string2, diff --git a/addressbook/contact-editor/e-contact-editor.h b/addressbook/contact-editor/e-contact-editor.h index 09de660681..21e7c62000 100644 --- a/addressbook/contact-editor/e-contact-editor.h +++ b/addressbook/contact-editor/e-contact-editor.h @@ -26,6 +26,7 @@ #include #include +#include "addressbook/backend/ebook/e-book.h" #include "addressbook/backend/ebook/e-card.h" #include "addressbook/backend/ebook/e-card-simple.h" @@ -58,6 +59,7 @@ struct _EContactEditor GtkObject object; /* item specific fields */ + EBook *book; ECard *card; ECardSimple *simple; @@ -88,8 +90,11 @@ struct _EContactEditor /* Whether we are editing a new card or an existing one */ guint is_new_card : 1; + /* Whether the card has been changed since bringing up the contact editor */ + guint changed : 1; + /* Whether the contact editor will accept modifications */ - guint is_read_only : 1; + guint editable : 1; EList *writable_fields; }; @@ -100,18 +105,19 @@ struct _EContactEditorClass /* Notification signals */ - void (* add_card) (EContactEditor *ce, ECard *card); - void (* commit_card) (EContactEditor *ce, ECard *card); - void (* delete_card) (EContactEditor *ce, ECard *card); + void (* card_added) (EContactEditor *ce, EBookStatus status, ECard *card); + void (* card_modified) (EContactEditor *ce, EBookStatus status, ECard *card); + void (* card_deleted) (EContactEditor *ce, EBookStatus status, ECard *card); void (* editor_closed) (EContactEditor *ce); }; -EContactEditor *e_contact_editor_new (ECard *card, - gboolean is_new_card, - EList *writable_fields, - gboolean is_read_only); +EContactEditor *e_contact_editor_new (EBook *book, + ECard *card, + gboolean is_new_card, + gboolean editable); GtkType e_contact_editor_get_type (void); void e_contact_editor_show (EContactEditor *editor); +void e_contact_editor_close (EContactEditor *editor); void e_contact_editor_raise (EContactEditor *editor); diff --git a/addressbook/contact-editor/e-contact-quick-add.c b/addressbook/contact-editor/e-contact-quick-add.c index 548ff6ed4d..096f038dd7 100644 --- a/addressbook/contact-editor/e-contact-quick-add.c +++ b/addressbook/contact-editor/e-contact-quick-add.c @@ -151,11 +151,14 @@ quick_add_merge_card (QuickAdd *qa) */ static void -add_card_cb (EContactEditor *ce, ECard *card, gpointer closure) +card_added_cb (EContactEditor *ce, EBookStatus status, ECard *card, gpointer closure) { QuickAdd *qa = (QuickAdd *) closure; - g_warning ("add_card_cb"); - quick_add_merge_card (qa); + + if (qa->cb) + qa->cb (qa->card, qa->closure); + + quick_add_unref (qa); } static void @@ -168,32 +171,7 @@ editor_closed_cb (GtkWidget *w, gpointer closure) } static void -ce_book_found_fields (EBook *book, EBookStatus status, EList *fields, gpointer closure) -{ - QuickAdd *qa = (QuickAdd *) closure; - EContactEditor *contact_editor; - - if (status != E_BOOK_STATUS_SUCCESS) { - g_warning ("Couldn't find supported fields for local address book."); - return; - } - - contact_editor = e_contact_editor_new (qa->card, TRUE, fields, FALSE /* XXX */); - - gtk_signal_connect (GTK_OBJECT (contact_editor), - "add_card", - GTK_SIGNAL_FUNC (add_card_cb), - qa); - gtk_signal_connect (GTK_OBJECT (contact_editor), - "editor_closed", - GTK_SIGNAL_FUNC (editor_closed_cb), - qa); - - e_contact_editor_show (contact_editor); -} - -static void -ce_get_fields (EBook *book, gpointer closure) +ce_have_book (EBook *book, gpointer closure) { QuickAdd *qa = (QuickAdd *) closure; @@ -201,14 +179,23 @@ ce_get_fields (EBook *book, gpointer closure) g_warning ("Couldn't open local address book."); quick_add_unref (qa); } else { - e_book_get_supported_fields (book, ce_book_found_fields, qa); + EContactEditor *contact_editor = e_contact_editor_new (book, qa->card, TRUE, FALSE /* XXX */); + + gtk_signal_connect (GTK_OBJECT (contact_editor), + "card_added", + GTK_SIGNAL_FUNC (card_added_cb), + qa); + gtk_signal_connect (GTK_OBJECT (contact_editor), + "editor_closed", + GTK_SIGNAL_FUNC (editor_closed_cb), + qa); } } static void edit_card (QuickAdd *qa) { - e_book_use_local_address_book (ce_get_fields, qa); + e_book_use_local_address_book (ce_have_book, qa); } static void diff --git a/addressbook/gui/contact-editor/Makefile.am b/addressbook/gui/contact-editor/Makefile.am index 47a79c7255..6d3567b2f7 100644 --- a/addressbook/gui/contact-editor/Makefile.am +++ b/addressbook/gui/contact-editor/Makefile.am @@ -27,25 +27,25 @@ libecontacteditor_a_SOURCES = \ e-contact-quick-add.c \ e-contact-quick-add.h -noinst_PROGRAMS = \ - contact-editor-test - -contact_editor_test_SOURCES = \ - test-editor.c - -contact_editor_test_LDADD = \ - libecontacteditor.a \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/addressbook/printing/libecontactprint.a \ - $(top_builddir)/addressbook/backend/ebook/libebook.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(GNOMEGNORBA_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) \ - $(EXTRA_GNOME_LIBS) +# noinst_PROGRAMS = \ +# contact-editor-test + +# contact_editor_test_SOURCES = \ +# test-editor.c + +# contact_editor_test_LDADD = \ +# libecontacteditor.a \ +# $(top_builddir)/e-util/libeutil.la \ +# $(top_builddir)/addressbook/printing/libecontactprint.a \ +# $(top_builddir)/addressbook/backend/ebook/libebook.la \ +# $(top_builddir)/e-util/ename/libename.la \ +# $(top_builddir)/libversit/libversit.la \ +# $(GNOMEGNORBA_LIBS) \ +# $(BONOBO_GNOME_LIBS) \ +# $(top_builddir)/widgets/misc/libemiscwidgets.a \ +# $(top_builddir)/e-util/libeutil.la \ +# $(GNOME_PRINT_LIBS) \ +# $(EXTRA_GNOME_LIBS) evolutiondir = $(datadir)/evolution diff --git a/addressbook/gui/contact-editor/e-contact-editor-address.c b/addressbook/gui/contact-editor/e-contact-editor-address.c index 777a3cb617..4ffd499e13 100644 --- a/addressbook/gui/contact-editor/e-contact-editor-address.c +++ b/addressbook/gui/contact-editor/e-contact-editor-address.c @@ -81,7 +81,7 @@ e_contact_editor_address_class_init (EContactEditorAddressClass *klass) gtk_object_add_arg_type ("EContactEditorAddress::address", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_ADDRESS); - gtk_object_add_arg_type ("EContactEditorAddress::is_read_only", GTK_TYPE_BOOL, + gtk_object_add_arg_type ("EContactEditorAddress::editable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_READ_ONLY); object_class->set_arg = e_contact_editor_address_set_arg; @@ -161,9 +161,9 @@ e_contact_editor_address_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "entry-code", NULL }; - e_contact_editor_address->is_read_only = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; + e_contact_editor_address->editable = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; for (i = 0; entry_names[i] != NULL; i ++) { - gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_address->gui, entry_names[i]), !e_contact_editor_address->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_address->gui, entry_names[i]), e_contact_editor_address->editable); } break; } @@ -183,7 +183,7 @@ e_contact_editor_address_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_POINTER (*arg) = e_card_delivery_address_copy(e_contact_editor_address->address); break; case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor_address->is_read_only ? TRUE : FALSE; + GTK_VALUE_BOOL (*arg) = e_contact_editor_address->editable ? TRUE : FALSE; break; default: arg->type = GTK_TYPE_INVALID; diff --git a/addressbook/gui/contact-editor/e-contact-editor-address.h b/addressbook/gui/contact-editor/e-contact-editor-address.h index 48d88aab85..e555370528 100644 --- a/addressbook/gui/contact-editor/e-contact-editor-address.h +++ b/addressbook/gui/contact-editor/e-contact-editor-address.h @@ -56,7 +56,7 @@ struct _EContactEditorAddress /* item specific fields */ ECardDeliveryAddress *address; - guint is_read_only : 1; + guint editable : 1; GladeXML *gui; }; diff --git a/addressbook/gui/contact-editor/e-contact-editor-fullname.c b/addressbook/gui/contact-editor/e-contact-editor-fullname.c index 69477d3325..bb622cdf3e 100644 --- a/addressbook/gui/contact-editor/e-contact-editor-fullname.c +++ b/addressbook/gui/contact-editor/e-contact-editor-fullname.c @@ -82,7 +82,7 @@ e_contact_editor_fullname_class_init (EContactEditorFullnameClass *klass) gtk_object_add_arg_type ("EContactEditorFullname::name", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_NAME); - gtk_object_add_arg_type ("EContactEditorFullname::is_read_only", GTK_TYPE_BOOL, + gtk_object_add_arg_type ("EContactEditorFullname::editable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_READ_ONLY); object_class->set_arg = e_contact_editor_fullname_set_arg; @@ -159,11 +159,11 @@ e_contact_editor_fullname_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "entry-last", NULL }; - e_contact_editor_fullname->is_read_only = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; + e_contact_editor_fullname->editable = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; for (i = 0; entry_names[i] != NULL; i ++) { gtk_widget_set_sensitive (glade_xml_get_widget(e_contact_editor_fullname->gui, entry_names[i]), - !e_contact_editor_fullname->is_read_only); + e_contact_editor_fullname->editable); } break; } @@ -183,7 +183,7 @@ e_contact_editor_fullname_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_POINTER (*arg) = e_card_name_copy(e_contact_editor_fullname->name); break; case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor_fullname->is_read_only ? TRUE : FALSE; + GTK_VALUE_BOOL (*arg) = e_contact_editor_fullname->editable ? TRUE : FALSE; break; default: arg->type = GTK_TYPE_INVALID; diff --git a/addressbook/gui/contact-editor/e-contact-editor-fullname.h b/addressbook/gui/contact-editor/e-contact-editor-fullname.h index 70bb793d0a..3a27551910 100644 --- a/addressbook/gui/contact-editor/e-contact-editor-fullname.h +++ b/addressbook/gui/contact-editor/e-contact-editor-fullname.h @@ -58,7 +58,7 @@ struct _EContactEditorFullname GladeXML *gui; /* Whether the dialog will accept modifications */ - guint is_read_only : 1; + guint editable : 1; }; struct _EContactEditorFullnameClass diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index 4be7b90303..2a1eb40653 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -43,6 +43,8 @@ #include "e-util/e-gui-utils.h" #include "widgets/misc/e-dateedit.h" +#include "e-card-merging.h" + #include "e-contact-editor.h" #include "e-contact-editor-address.h" #include "e-contact-editor-fullname.h" @@ -50,9 +52,9 @@ /* Signal IDs */ enum { - ADD_CARD, - COMMIT_CARD, - DELETE_CARD, + CARD_ADDED, + CARD_MODIFIED, + CARD_DELETED, EDITOR_CLOSED, LAST_SIGNAL }; @@ -70,12 +72,13 @@ static void _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, ECo static void _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void enable_writable_fields(EContactEditor *editor); -static void set_read_only(EContactEditor *editor); +static void set_editable(EContactEditor *editor); static void fill_in_info(EContactEditor *editor); static void extract_info(EContactEditor *editor); static void set_fields(EContactEditor *editor); static void set_address_field(EContactEditor *editor, int result); static void add_field_callback(GtkWidget *widget, EContactEditor *editor); +static void command_state_changed (EContactEditor *ce); static GtkObjectClass *parent_class = NULL; @@ -84,9 +87,10 @@ static guint contact_editor_signals[LAST_SIGNAL]; /* The arguments we take */ enum { ARG_0, + ARG_BOOK, ARG_CARD, ARG_IS_NEW_CARD, - ARG_IS_READ_ONLY, + ARG_EDITABLE, ARG_WRITABLE_FIELDS }; @@ -121,6 +125,24 @@ e_contact_editor_get_type (void) return contact_editor_type; } +typedef void (*GtkSignal_NONE__INT_OBJECT) (GtkObject * object, + gint arg1, + GtkObject *arg2, + gpointer user_data); + +static void +e_marshal_NONE__INT_OBJECT (GtkObject * object, + GtkSignalFunc func, + gpointer func_data, GtkArg * args) +{ + GtkSignal_NONE__INT_OBJECT rfunc; + rfunc = (GtkSignal_NONE__INT_OBJECT) func; + (*rfunc) (object, + GTK_VALUE_INT (args[0]), + GTK_VALUE_OBJECT (args[1]), + func_data); +} + static void e_contact_editor_class_init (EContactEditorClass *klass) { @@ -130,41 +152,43 @@ e_contact_editor_class_init (EContactEditorClass *klass) parent_class = gtk_type_class (GTK_TYPE_OBJECT); + gtk_object_add_arg_type ("EContactEditor::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); gtk_object_add_arg_type ("EContactEditor::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); gtk_object_add_arg_type ("EContactEditor::is_new_card", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_IS_NEW_CARD); gtk_object_add_arg_type ("EContactEditor::writable_fields", GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_WRITABLE_FIELDS); - gtk_object_add_arg_type ("EContactEditor::is_read_only", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_IS_READ_ONLY); + gtk_object_add_arg_type ("EContactEditor::editable", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_EDITABLE); - contact_editor_signals[ADD_CARD] = - gtk_signal_new ("add_card", + contact_editor_signals[CARD_ADDED] = + gtk_signal_new ("card_added", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, add_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_added), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); - contact_editor_signals[COMMIT_CARD] = - gtk_signal_new ("commit_card", + contact_editor_signals[CARD_MODIFIED] = + gtk_signal_new ("card_modified", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, commit_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_modified), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); - contact_editor_signals[DELETE_CARD] = - gtk_signal_new ("delete_card", + contact_editor_signals[CARD_DELETED] = + gtk_signal_new ("card_deleted", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (EContactEditorClass, delete_card), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, - GTK_TYPE_OBJECT); + GTK_SIGNAL_OFFSET (EContactEditorClass, card_deleted), + e_marshal_NONE__INT_OBJECT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_OBJECT); contact_editor_signals[EDITOR_CLOSED] = gtk_signal_new ("editor_closed", @@ -220,6 +244,11 @@ wants_html_changed (GtkWidget *widget, EContactEditor *editor) gtk_object_set(GTK_OBJECT(editor->card), "wants_html", wants_html, NULL); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -249,6 +278,11 @@ phone_entry_changed (GtkWidget *widget, EContactEditor *editor) #endif e_card_phone_free(phone); set_fields(editor); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -262,6 +296,11 @@ email_entry_changed (GtkWidget *widget, EContactEditor *editor) e_card_simple_set_email(editor->simple, editor->email_choice, string); g_free (string); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -279,6 +318,11 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor) e_card_simple_set_address(editor->simple, editor->address_choice, address); e_card_address_label_free(address); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } /* This function tells you whether name_to_style will make sense. */ @@ -450,6 +494,11 @@ name_entry_changed (GtkWidget *widget, EContactEditor *editor) g_free (string); file_as_set_style(editor, style); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -464,6 +513,11 @@ company_entry_changed (GtkWidget *widget, EContactEditor *editor) editor->company = e_utf8_gtk_entry_get_text(GTK_ENTRY(widget)); file_as_set_style(editor, style); + + if (!editor->changed) { + editor->changed = TRUE; + command_state_changed (editor); + } } static void @@ -512,7 +566,7 @@ full_name_clicked(GtkWidget *button, EContactEditor *editor) int result; gtk_object_set (GTK_OBJECT (dialog), - "is_read_only", editor->is_read_only, + "editable", editor->editable, NULL); gtk_widget_show(GTK_WIDGET(dialog)); result = gnome_dialog_run (dialog); @@ -554,7 +608,7 @@ full_addr_clicked(GtkWidget *button, EContactEditor *editor) dialog = GNOME_DIALOG(e_contact_editor_address_new(address)); gtk_object_set (GTK_OBJECT (dialog), - "is_read_only", editor->is_read_only, + "editable", editor->editable, NULL); gtk_widget_show(GTK_WIDGET(dialog)); @@ -624,25 +678,65 @@ categories_clicked(GtkWidget *button, EContactEditor *editor) #endif } +typedef struct { + EContactEditor *ce; + gboolean should_close; +} EditorCloseStruct; + +static void +card_added_cb (EBook *book, EBookStatus status, const char *id, EditorCloseStruct *ecs) +{ + EContactEditor *ce = ecs->ce; + gboolean should_close = ecs->should_close; + + g_free (ecs); + + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_ADDED], + status, ce->card); + + if (status == E_BOOK_STATUS_SUCCESS) { + ce->is_new_card = FALSE; + + if (should_close) + close_dialog (ce); + } +} + +static void +card_modified_cb (EBook *book, EBookStatus status, EditorCloseStruct *ecs) +{ + EContactEditor *ce = ecs->ce; + gboolean should_close = ecs->should_close; + + g_free (ecs); + + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_MODIFIED], + status, ce->card); + + if (status == E_BOOK_STATUS_SUCCESS) { + if (should_close) + close_dialog (ce); + } +} + /* Emits the signal to request saving a card */ static void -save_card (EContactEditor *ce) +save_card (EContactEditor *ce, gboolean should_close) { extract_info (ce); e_card_simple_sync_card (ce->simple); - if (ce->is_new_card) - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[ADD_CARD], - ce->card); - else - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[COMMIT_CARD], - ce->card); - - /* FIXME: should we set the ce->is_new_card here or have the client code - * set the "is_new_card" argument on the contact editor object? - */ + if (ce->book) { + EditorCloseStruct *ecs = g_new(EditorCloseStruct, 1); + + ecs->ce = ce; + ecs->should_close = should_close; - ce->is_new_card = FALSE; + if (ce->is_new_card) + e_card_merging_book_add_card (ce->book, ce->card, GTK_SIGNAL_FUNC(card_added_cb), ecs); + else + e_card_merging_book_commit_card (ce->book, ce->card, GTK_SIGNAL_FUNC(card_modified_cb), ecs); + } } /* Closes the dialog box and emits the appropriate signals */ @@ -666,7 +760,7 @@ file_save_cb (GtkWidget *widget, gpointer data) EContactEditor *ce; ce = E_CONTACT_EDITOR (data); - save_card (ce); + save_card (ce, FALSE); } /* File/Close callback */ @@ -744,6 +838,13 @@ e_contact_editor_confirm_delete(GtkWindow *parent) return !result; } +static void +card_deleted_cb (EBook *book, EBookStatus status, EContactEditor *ce) +{ + gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[CARD_DELETED], + status, ce->card); +} + static void delete_cb (GtkWidget *widget, gpointer data) { @@ -759,11 +860,8 @@ delete_cb (GtkWidget *widget, gpointer data) extract_info (ce); e_card_simple_sync_card (simple); - if (!ce->is_new_card) - gtk_signal_emit (GTK_OBJECT (ce), contact_editor_signals[DELETE_CARD], - card); - - close_dialog (ce); + if (!ce->is_new_card && ce->book) + e_book_remove_card (ce->book, card, GTK_SIGNAL_FUNC(card_deleted_cb), ce); } gtk_object_unref(GTK_OBJECT(card)); @@ -805,8 +903,7 @@ tb_save_and_close_cb (BonoboUIComponent *uih, void *data, const char *path) EContactEditor *ce; ce = E_CONTACT_EDITOR (data); - save_card (ce); - close_dialog (ce); + save_card (ce, TRUE); } static @@ -920,6 +1017,7 @@ e_contact_editor_init (EContactEditor *e_contact_editor) e_contact_editor->simple = e_card_simple_new(NULL); e_contact_editor->card = NULL; + e_contact_editor->changed = FALSE; gui = glade_xml_new (EVOLUTION_GLADEDIR "/contact-editor.glade", NULL); e_contact_editor->gui = gui; @@ -1041,6 +1139,9 @@ e_contact_editor_destroy (GtkObject *object) { if (e_contact_editor->simple) gtk_object_unref(GTK_OBJECT(e_contact_editor->simple)); + if (e_contact_editor->book) + gtk_object_unref(GTK_OBJECT(e_contact_editor->book)); + if (e_contact_editor->name) e_card_name_free(e_contact_editor->name); @@ -1049,23 +1150,56 @@ e_contact_editor_destroy (GtkObject *object) { gtk_object_unref(GTK_OBJECT(e_contact_editor->gui)); } +static void +command_state_changed (EContactEditor *ce) +{ + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorSaveClose", + "sensitive", + ce->changed ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorSave", + "sensitive", + ce->changed ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ce->uic, + "/commands/ContactEditorDelete", + "sensitive", + (ce->editable && !ce->is_new_card) ? "1" : "0", NULL); +} + +static void +supported_fields_cb (EBook *book, EBookStatus status, + EList *fields, EContactEditor *ce) +{ + gtk_object_set (GTK_OBJECT (ce), + "writable_fields", fields, + NULL); + + e_contact_editor_show (ce); + + command_state_changed (ce); +} + EContactEditor * -e_contact_editor_new (ECard *card, +e_contact_editor_new (EBook *book, + ECard *card, gboolean is_new_card, - EList *fields, - gboolean is_read_only) + gboolean editable) { EContactEditor *ce; ce = E_CONTACT_EDITOR (gtk_type_new (E_CONTACT_EDITOR_TYPE)); gtk_object_set (GTK_OBJECT (ce), + "book", book, "card", card, "is_new_card", is_new_card, - "writable_fields", fields, - "is_read_only", is_read_only, + "editable", editable, NULL); + if (book) + e_book_get_supported_fields (book, (EBookFieldsCallback)supported_fields_cb, ce); + return ce; } @@ -1077,6 +1211,13 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) editor = E_CONTACT_EDITOR (o); switch (arg_id){ + case ARG_BOOK: + if (editor->book) + gtk_object_unref(GTK_OBJECT(editor->book)); + editor->book = E_BOOK(GTK_VALUE_OBJECT (*arg)); + gtk_object_ref (GTK_OBJECT (editor->book)); + /* XXX more here about editable/etc. */ + break; case ARG_CARD: if (editor->card) gtk_object_unref(GTK_OBJECT(editor->card)); @@ -1085,20 +1226,23 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "card", editor->card, NULL); fill_in_info(editor); + editor->changed = FALSE; break; case ARG_IS_NEW_CARD: editor->is_new_card = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; break; - case ARG_IS_READ_ONLY: { + case ARG_EDITABLE: { gboolean new_value = GTK_VALUE_BOOL (*arg) ? TRUE : FALSE; - gboolean changed = (editor->is_read_only != new_value); + gboolean changed = (editor->editable != new_value); - editor->is_read_only = new_value; + editor->editable = new_value; - if (changed) - set_read_only (editor); + if (changed) { + set_editable (editor); + command_state_changed (editor); + } break; } case ARG_WRITABLE_FIELDS: @@ -1122,6 +1266,10 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) e_contact_editor = E_CONTACT_EDITOR (object); switch (arg_id) { + case ARG_BOOK: + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_contact_editor->book); + break; + case ARG_CARD: e_card_simple_sync_card(e_contact_editor->simple); extract_info(e_contact_editor); @@ -1132,8 +1280,8 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_BOOL (*arg) = e_contact_editor->is_new_card ? TRUE : FALSE; break; - case ARG_IS_READ_ONLY: - GTK_VALUE_BOOL (*arg) = e_contact_editor->is_read_only ? TRUE : FALSE; + case ARG_EDITABLE: + GTK_VALUE_BOOL (*arg) = e_contact_editor->editable ? TRUE : FALSE; break; case ARG_WRITABLE_FIELDS: @@ -1450,7 +1598,7 @@ _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor editor->phone_choice[which - 1] = result; set_fields(editor); gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, label), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, entry), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, entry), editor->editable); } g_free(label); @@ -1483,8 +1631,8 @@ _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor /* make sure the buttons/entry is/are sensitive */ gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-email1"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), editor->editable); } } @@ -1513,8 +1661,8 @@ _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEdito /* make sure the buttons/entry is/are sensitive */ gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-address"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), editor->editable); } } @@ -1846,13 +1994,13 @@ enable_writable_fields(EContactEditor *editor) enabled. */ if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_email_to_field(editor->email_choice)))) { gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-email1"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "entry-email1"), editor->editable); gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "checkbutton-htmlmail"), TRUE); } else if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_address_to_field(editor->address_choice)))) { gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "label-address"), TRUE); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), !editor->is_read_only); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "button-fulladdr"), editor->editable); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "text-address"), editor->editable); } else for (i = 0; i < 4; i ++) { if (!strcmp (field, e_card_simple_get_ecard_field (simple, e_card_simple_map_phone_to_field(editor->phone_choice[i])))) { @@ -1860,7 +2008,7 @@ enable_writable_fields(EContactEditor *editor) gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), TRUE); g_free (widget_name); widget_name = g_strdup_printf ("entry-phone%d", i+1); - gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), !editor->is_read_only); + gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, widget_name), editor->editable); g_free (widget_name); } } @@ -1883,7 +2031,7 @@ enable_writable_fields(EContactEditor *editor) } static void -set_read_only (EContactEditor *editor) +set_editable (EContactEditor *editor) { int i; char *label, *entry; @@ -1891,7 +2039,7 @@ set_read_only (EContactEditor *editor) for (i = 0; i < num_widget_field_mappings; i ++) { if (widget_field_mappings[i].desensitize_for_read_only) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - widget_field_mappings[i].widget_name), !editor->is_read_only); + widget_field_mappings[i].widget_name), editor->editable); } /* handle the phone dropdown entries */ @@ -1901,7 +2049,7 @@ set_read_only (EContactEditor *editor) if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); g_free (label); g_free (entry); @@ -1912,9 +2060,9 @@ set_read_only (EContactEditor *editor) entry = "entry-email1"; if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) { gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - "checkbutton-htmlmail"), !editor->is_read_only); + "checkbutton-htmlmail"), editor->editable); } /* handle the address dropdown entry */ @@ -1922,7 +2070,7 @@ set_read_only (EContactEditor *editor) entry = "text-address"; if (GTK_WIDGET_IS_SENSITIVE (glade_xml_get_widget (editor->gui, label))) gtk_widget_set_sensitive (glade_xml_get_widget(editor->gui, - entry), !editor->is_read_only); + entry), editor->editable); } static void @@ -2140,7 +2288,6 @@ e_contact_editor_show (EContactEditor *ce) gtk_widget_show (ce->app); } - GtkWidget * e_contact_editor_create_date(gchar *name, gchar *string1, gchar *string2, diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h index 09de660681..21e7c62000 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.h +++ b/addressbook/gui/contact-editor/e-contact-editor.h @@ -26,6 +26,7 @@ #include #include +#include "addressbook/backend/ebook/e-book.h" #include "addressbook/backend/ebook/e-card.h" #include "addressbook/backend/ebook/e-card-simple.h" @@ -58,6 +59,7 @@ struct _EContactEditor GtkObject object; /* item specific fields */ + EBook *book; ECard *card; ECardSimple *simple; @@ -88,8 +90,11 @@ struct _EContactEditor /* Whether we are editing a new card or an existing one */ guint is_new_card : 1; + /* Whether the card has been changed since bringing up the contact editor */ + guint changed : 1; + /* Whether the contact editor will accept modifications */ - guint is_read_only : 1; + guint editable : 1; EList *writable_fields; }; @@ -100,18 +105,19 @@ struct _EContactEditorClass /* Notification signals */ - void (* add_card) (EContactEditor *ce, ECard *card); - void (* commit_card) (EContactEditor *ce, ECard *card); - void (* delete_card) (EContactEditor *ce, ECard *card); + void (* card_added) (EContactEditor *ce, EBookStatus status, ECard *card); + void (* card_modified) (EContactEditor *ce, EBookStatus status, ECard *card); + void (* card_deleted) (EContactEditor *ce, EBookStatus status, ECard *card); void (* editor_closed) (EContactEditor *ce); }; -EContactEditor *e_contact_editor_new (ECard *card, - gboolean is_new_card, - EList *writable_fields, - gboolean is_read_only); +EContactEditor *e_contact_editor_new (EBook *book, + ECard *card, + gboolean is_new_card, + gboolean editable); GtkType e_contact_editor_get_type (void); void e_contact_editor_show (EContactEditor *editor); +void e_contact_editor_close (EContactEditor *editor); void e_contact_editor_raise (EContactEditor *editor); diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c index 548ff6ed4d..096f038dd7 100644 --- a/addressbook/gui/contact-editor/e-contact-quick-add.c +++ b/addressbook/gui/contact-editor/e-contact-quick-add.c @@ -151,11 +151,14 @@ quick_add_merge_card (QuickAdd *qa) */ static void -add_card_cb (EContactEditor *ce, ECard *card, gpointer closure) +card_added_cb (EContactEditor *ce, EBookStatus status, ECard *card, gpointer closure) { QuickAdd *qa = (QuickAdd *) closure; - g_warning ("add_card_cb"); - quick_add_merge_card (qa); + + if (qa->cb) + qa->cb (qa->card, qa->closure); + + quick_add_unref (qa); } static void @@ -168,32 +171,7 @@ editor_closed_cb (GtkWidget *w, gpointer closure) } static void -ce_book_found_fields (EBook *book, EBookStatus status, EList *fields, gpointer closure) -{ - QuickAdd *qa = (QuickAdd *) closure; - EContactEditor *contact_editor; - - if (status != E_BOOK_STATUS_SUCCESS) { - g_warning ("Couldn't find supported fields for local address book."); - return; - } - - contact_editor = e_contact_editor_new (qa->card, TRUE, fields, FALSE /* XXX */); - - gtk_signal_connect (GTK_OBJECT (contact_editor), - "add_card", - GTK_SIGNAL_FUNC (add_card_cb), - qa); - gtk_signal_connect (GTK_OBJECT (contact_editor), - "editor_closed", - GTK_SIGNAL_FUNC (editor_closed_cb), - qa); - - e_contact_editor_show (contact_editor); -} - -static void -ce_get_fields (EBook *book, gpointer closure) +ce_have_book (EBook *book, gpointer closure) { QuickAdd *qa = (QuickAdd *) closure; @@ -201,14 +179,23 @@ ce_get_fields (EBook *book, gpointer closure) g_warning ("Couldn't open local address book."); quick_add_unref (qa); } else { - e_book_get_supported_fields (book, ce_book_found_fields, qa); + EContactEditor *contact_editor = e_contact_editor_new (book, qa->card, TRUE, FALSE /* XXX */); + + gtk_signal_connect (GTK_OBJECT (contact_editor), + "card_added", + GTK_SIGNAL_FUNC (card_added_cb), + qa); + gtk_signal_connect (GTK_OBJECT (contact_editor), + "editor_closed", + GTK_SIGNAL_FUNC (editor_closed_cb), + qa); } } static void edit_card (QuickAdd *qa) { - e_book_use_local_address_book (ce_get_fields, qa); + e_book_use_local_address_book (ce_have_book, qa); } static void -- cgit v1.2.3