diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-04-10 23:46:25 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-04-10 23:46:25 +0800 |
commit | 99700ad43dcbf0bf95b335a9fc8f95934080d63c (patch) | |
tree | d325feef8319087bb323f592da432884d03b6e92 | |
parent | c4f6086c2948f3384dd95393f7ea737db6143682 (diff) | |
download | gsoc2013-evolution-99700ad43dcbf0bf95b335a9fc8f95934080d63c.tar.gz gsoc2013-evolution-99700ad43dcbf0bf95b335a9fc8f95934080d63c.tar.zst gsoc2013-evolution-99700ad43dcbf0bf95b335a9fc8f95934080d63c.zip |
Fixed a bug where I was sending the wrong information to some callbacks.
2000-04-10 Christopher James Lahey <clahey@helixcode.com>
* addressbook/backend/ebook/e-book-view.c: Fixed a bug where I was
sending the wrong information to some callbacks.
* addressbook/backend/ebook/e-card.c,
addressbook/backend/ebook/e-card.h: Added an e_card_duplicate
function. Made ids get stored in vcards. Made sure to delete the
url if it exists.
* addressbook/backend/pas/Makefile.am: Made pas include
addressbook/backend/ebook/ in the search path.
* addressbook/backend/pas/pas-backend-file.c: Fixed some bugs and
made the create card function store the generated id in the card
being saved.
* addressbook/backend/pas/pas-book-view.c: Fixed a double free
bug.
* addressbook/contact-editor/e-contact-editor.c: Fixed some bugs.
Made the contact editor actually return a valid card when
gtk_object_get(editor, "card", ...) is called.
* addressbook/contact-editor/e-contact-editor.h: Fixed a copy and
paste error.
* addressbook/gui/component/addressbook.c: Made this get the card
properly.
* addressbook/gui/minicard/Makefile.am: Made this include
contact-editor directory in the search path and link against
libecontacteditor so that double clicking can open a dialog.
* addressbook/gui/minicard/e-minicard.c: Fixed some small bugs.
Made double clicking open a contact editor dialog if this minicard
is contained in a minicard view. (It needs the minicard view to
get the EBook to save to.
* wombat/Makefile.am: Link wombat against libebook, since
pas-backend-file now uses ECard.
svn path=/trunk/; revision=2360
-rw-r--r-- | ChangeLog | 42 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book-view.c | 10 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 47 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.h | 2 | ||||
-rw-r--r-- | addressbook/backend/pas/Makefile.am | 1 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 23 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book-view.c | 2 | ||||
-rw-r--r-- | addressbook/contact-editor/e-contact-editor.c | 197 | ||||
-rw-r--r-- | addressbook/contact-editor/e-contact-editor.h | 4 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook.c | 8 | ||||
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-editor.c | 197 | ||||
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-editor.h | 4 | ||||
-rw-r--r-- | addressbook/gui/minicard/Makefile.am | 4 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard.c | 207 | ||||
-rw-r--r-- | addressbook/gui/widgets/Makefile.am | 4 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.c | 207 | ||||
-rw-r--r-- | wombat/Makefile.am | 1 |
17 files changed, 662 insertions, 298 deletions
@@ -1,3 +1,45 @@ +2000-04-10 Christopher James Lahey <clahey@helixcode.com> + + * addressbook/backend/ebook/e-book-view.c: Fixed a bug where I was + sending the wrong information to some callbacks. + + * addressbook/backend/ebook/e-card.c, + addressbook/backend/ebook/e-card.h: Added an e_card_duplicate + function. Made ids get stored in vcards. Made sure to delete the + url if it exists. + + * addressbook/backend/pas/Makefile.am: Made pas include + addressbook/backend/ebook/ in the search path. + + * addressbook/backend/pas/pas-backend-file.c: Fixed some bugs and + made the create card function store the generated id in the card + being saved. + + * addressbook/backend/pas/pas-book-view.c: Fixed a double free + bug. + + * addressbook/contact-editor/e-contact-editor.c: Fixed some bugs. + Made the contact editor actually return a valid card when + gtk_object_get(editor, "card", ...) is called. + + * addressbook/contact-editor/e-contact-editor.h: Fixed a copy and + paste error. + + * addressbook/gui/component/addressbook.c: Made this get the card + properly. + + * addressbook/gui/minicard/Makefile.am: Made this include + contact-editor directory in the search path and link against + libecontacteditor so that double clicking can open a dialog. + + * addressbook/gui/minicard/e-minicard.c: Fixed some small bugs. + Made double clicking open a contact editor dialog if this minicard + is contained in a minicard view. (It needs the minicard view to + get the EBook to save to. + + * wombat/Makefile.am: Link wombat against libebook, since + pas-backend-file now uses ECard. + 2000-04-09 Matt Loper <matt@helixcode.com> * addressbook/gui/component/addressbook.c (control_activate): Make diff --git a/addressbook/backend/ebook/e-book-view.c b/addressbook/backend/ebook/e-book-view.c index fa8deff67c..2931a9347d 100644 --- a/addressbook/backend/ebook/e-book-view.c +++ b/addressbook/backend/ebook/e-book-view.c @@ -51,9 +51,10 @@ e_book_view_do_modified_event (EBookView *book_view, EBookViewListenerResponse *resp) { gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [CARD_CHANGED], - resp->id); + resp->cards); - g_free (resp->id); + g_list_foreach (resp->cards, (GFunc) gtk_object_unref, NULL); + g_list_free (resp->cards); } static void @@ -61,10 +62,9 @@ e_book_view_do_removed_event (EBookView *book_view, EBookViewListenerResponse *resp) { gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [CARD_REMOVED], - resp->cards); + resp->id); - g_list_foreach (resp->cards, (GFunc) gtk_object_unref, NULL); - g_list_free (resp->cards); + g_free(resp->id); } diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 227643fe8c..9c135e4d1f 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -31,7 +31,8 @@ enum { ARG_PHONE, ARG_EMAIL, ARG_BIRTH_DATE, - ARG_URL + ARG_URL, + ARG_ID }; #if 0 @@ -58,6 +59,7 @@ static void parse_email(ECard *card, VObject *object); static void parse_phone(ECard *card, VObject *object); static void parse_address(ECard *card, VObject *object); static void parse_url(ECard *card, VObject *object); +static void parse_id(ECard *card, VObject *object); static ECardPhoneFlags get_phone_flags (VObject *vobj); static void set_phone_flags (VObject *vobj, ECardPhoneFlags flags); @@ -77,7 +79,8 @@ struct { { VCEmailAddressProp, parse_email }, { VCTelephoneProp, parse_phone }, { VCAdrProp, parse_address }, - { VCURLProp, parse_url } + { VCURLProp, parse_url }, + { VCUniqueStringProp, parse_id } }; /** @@ -133,6 +136,14 @@ e_card_new (char *vcard) return card; } +ECard *e_card_duplicate(ECard *card) +{ + char *vcard = e_card_get_vcard(card); + ECard *new_card = e_card_new(vcard); + g_free (vcard); + return new_card; +} + /** * e_card_get_id: * @card: an #ECard @@ -255,9 +266,12 @@ char g_free(value); } - if ( card->url ) + if (card->url) addPropValue(vobj, VCURLProp, card->url); + if (card->id) + addPropValue (vobj, VCUniqueStringProp, card->id); + #if 0 @@ -349,9 +363,6 @@ char add_CardProperty (vprop, &crd->sound.prop); } - add_CardStrProperty (vobj, VCURLProp, &crd->url); - add_CardStrProperty (vobj, VCUniqueStringProp, &crd->uid); - if (crd->key.prop.used) { vprop = addPropValue (vobj, VCPublicKeyProp, crd->key.data); add_KeyType (vprop, crd->key.type); @@ -455,12 +466,20 @@ parse_address(ECard *card, VObject *vobj) static void parse_url(ECard *card, VObject *vobj) { - if ( card->url ) + if (card->url) g_free(card->url); assign_string(vobj, &(card->url)); } static void +parse_id(ECard *card, VObject *vobj) +{ + if ( card->id ) + g_free(card->id); + assign_string(vobj, &(card->id)); +} + +static void parse_attribute(ECard *card, VObject *vobj) { ParsePropertyFunc function = g_hash_table_lookup(E_CARD_CLASS(GTK_OBJECT(card)->klass)->attribute_jump_table, vObjectName(vobj)); @@ -506,6 +525,8 @@ e_card_class_init (ECardClass *klass) GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_BIRTH_DATE); gtk_object_add_arg_type ("ECard::url", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_URL); + gtk_object_add_arg_type ("ECard::id", + GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ID); object_class->destroy = e_card_destroy; @@ -592,6 +613,9 @@ e_card_destroy (GtkObject *object) if ( card->bday ) g_free(card->bday); + if (card->url) + g_free(card->url); + if (card->email) gtk_object_unref(GTK_OBJECT(card->email)); if (card->phone) @@ -629,6 +653,12 @@ e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) if ( card->url ) g_free(card->url); card->url = GTK_VALUE_STRING(*arg); + break; + case ARG_ID: + if (card->id) + g_free(card->id); + card->id = GTK_VALUE_STRING(*arg); + break; default: return; } @@ -676,6 +706,9 @@ e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_URL: GTK_VALUE_STRING(*arg) = card->url; break; + case ARG_ID: + GTK_VALUE_STRING(*arg) = card->id; + break; default: arg->type = GTK_TYPE_INVALID; break; diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h index 1f230159fb..8eaf235c81 100644 --- a/addressbook/backend/ebook/e-card.h +++ b/addressbook/backend/ebook/e-card.h @@ -88,6 +88,8 @@ char *e_card_get_id (ECard *card); void e_card_set_id (ECard *card, const gchar *character); char *e_card_get_vcard (ECard *card); +ECard *e_card_duplicate (ECard *card); + void e_card_phone_free (ECardPhone *phone); ECardPhone *e_card_phone_copy (const ECardPhone *phone); void e_card_delivery_address_free (ECardDeliveryAddress *addr); diff --git a/addressbook/backend/pas/Makefile.am b/addressbook/backend/pas/Makefile.am index b8e478f1b3..62207b5963 100644 --- a/addressbook/backend/pas/Makefile.am +++ b/addressbook/backend/pas/Makefile.am @@ -24,6 +24,7 @@ INCLUDES = \ -I.. \ -I$(top_builddir) \ -I$(includedir) \ + -I$(top_srcdir)/addressbook/backend/ebook \ $(GNOME_INCLUDEDIR) gnome_libs = \ diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 935dab19d5..0dcf745d38 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -19,6 +19,7 @@ #include <pas-backend-file.h> #include <pas-book.h> #include <pas-card-cursor.h> +#include <e-card.h> #define PAS_BACKEND_FILE_VERSION_NAME "PAS-DB-VERSION" #define PAS_BACKEND_FILE_VERSION "0.1" @@ -153,11 +154,20 @@ pas_backend_file_process_create_card (PASBackend *backend, int db_error; char *id; GList *list; + ECard *card; + char *vcard; id = pas_backend_file_create_unique_id (req->vcard); string_to_dbt (id, &id_dbt); - string_to_dbt (req->vcard, &vcard_dbt); + + card = e_card_new(req->vcard); + e_card_set_id(card, id); + vcard = e_card_get_vcard(card); + gtk_object_unref(GTK_OBJECT(card)); + card = NULL; + + string_to_dbt (vcard, &vcard_dbt); db_error = db->put (db, &id_dbt, &vcard_dbt, 0); @@ -187,6 +197,7 @@ pas_backend_file_process_create_card (PASBackend *backend, } g_free (id); + g_free (vcard); g_free (req->vcard); } @@ -239,8 +250,13 @@ pas_backend_file_process_modify_card (PASBackend *backend, DBT id_dbt, vcard_dbt; int db_error; GList *list; + ECard *card; + char *id; - string_to_dbt (req->id, &id_dbt); + card = e_card_new(req->vcard); + id = e_card_get_id(card); + + string_to_dbt (id, &id_dbt); string_to_dbt (req->vcard, &vcard_dbt); db_error = db->put (db, &id_dbt, &vcard_dbt, 0); @@ -253,7 +269,7 @@ pas_backend_file_process_modify_card (PASBackend *backend, /* else if (card changes to match view->search ) pas_book_view_notify_add_1 (view->book_view, req->vcard); else if (card changes to not match view->search ) - pas_book_view_notify_remove (view->book_view, req->id); + pas_book_view_notify_remove (view->book_view, id); */ } @@ -271,6 +287,7 @@ pas_backend_file_process_modify_card (PASBackend *backend, Evolution_BookListener_CardNotFound); } + gtk_object_unref(GTK_OBJECT(card)); g_free (req->vcard); } diff --git a/addressbook/backend/pas/pas-book-view.c b/addressbook/backend/pas/pas-book-view.c index f712cc8ccf..e59028f88a 100644 --- a/addressbook/backend/pas/pas-book-view.c +++ b/addressbook/backend/pas/pas-book-view.c @@ -33,7 +33,7 @@ pas_book_view_notify_change (PASBookView *book_view, card_sequence._length = length; for ( i = 0; cards; cards = g_list_next(cards), i++ ) { - card_sequence._buffer[i] = (char *) cards->data; + card_sequence._buffer[i] = CORBA_string_dup((char *) cards->data); } CORBA_exception_init (&ev); diff --git a/addressbook/contact-editor/e-contact-editor.c b/addressbook/contact-editor/e-contact-editor.c index 81916847f7..cda77e4431 100644 --- a/addressbook/contact-editor/e-contact-editor.c +++ b/addressbook/contact-editor/e-contact-editor.c @@ -32,7 +32,8 @@ static GtkWidget *e_contact_editor_build_dialog(EContactEditor *editor, gchar *e static void _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); -static void fill_in_info(EContactEditor *editor, ECard *card); +static void fill_in_info(EContactEditor *editor); +static void extract_info(EContactEditor *editor); static GtkVBoxClass *parent_class = NULL; @@ -254,8 +255,6 @@ e_contact_editor_new (ECard *card) gtk_object_set (GTK_OBJECT(widget), "card", card, NULL); - - E_CONTACT_EDITOR (widget)->card = card; return widget; } @@ -268,7 +267,10 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) switch (arg_id){ case ARG_CARD: - fill_in_info(e_contact_editor, E_CARD(GTK_VALUE_OBJECT (*arg))); + if (e_contact_editor->card) + gtk_object_unref(GTK_OBJECT(e_contact_editor->card)); + e_contact_editor->card = e_card_duplicate(E_CARD(GTK_VALUE_OBJECT (*arg))); + fill_in_info(e_contact_editor); break; } } @@ -282,7 +284,8 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) switch (arg_id) { case ARG_CARD: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(NULL); + extract_info(e_contact_editor); + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_contact_editor->card); break; default: arg->type = GTK_TYPE_INVALID; @@ -570,14 +573,20 @@ _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEdito } static void -fill_in_info(EContactEditor *editor, ECard *card) +fill_in_info(EContactEditor *editor) { + ECard *card = editor->card; if (card) { char *fname; ECardList *address_list; ECardList *phone_list; ECardList *email_list; char *url; + const ECardDeliveryAddress *address; + const ECardPhone *phone; + GtkEditable *editable; + int position = 0; + const char *email; ECardIterator *iterator; @@ -588,68 +597,136 @@ fill_in_info(EContactEditor *editor, ECard *card) "email", &email_list, "url", &url, NULL); - - if (fname) { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); - gtk_editable_delete_text(editable, 0, -1); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); + gtk_editable_delete_text(editable, 0, -1); + if (fname) gtk_editable_insert_text(editable, fname, strlen(fname), &position); - } else { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); - gtk_editable_delete_text(editable, 0, -1); - gtk_editable_insert_text(editable, "", 0, &position); - } - if (address_list) { - const ECardDeliveryAddress *address; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(address_list); - address = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); - gtk_editable_delete_text(editable, 0, -1); + position = 0; + iterator = e_card_list_get_iterator(address_list); + address = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); + gtk_editable_delete_text(editable, 0, -1); + if (address) gtk_editable_insert_text(editable, address->city, strlen(address->city), &position); - } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); - gtk_editable_delete_text(editable, 0, -1); - } - - if (address_list) { - const ECardPhone *phone; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(phone_list); - phone = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); - gtk_editable_delete_text(editable, 0, -1); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(phone_list); + phone = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); + gtk_editable_delete_text(editable, 0, -1); + if (phone) gtk_editable_insert_text(editable, phone->number, strlen(phone->number), &position); - } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); - gtk_editable_delete_text(editable, 0, -1); - } - if (email_list) { - const char *email; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(email_list); - email = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); - gtk_editable_delete_text(editable, 0, -1); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(email_list); + email = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); + gtk_editable_delete_text(editable, 0, -1); + if (email) gtk_editable_insert_text(editable, email, strlen(email), &position); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); + gtk_editable_delete_text(editable, 0, -1); + if (url) + gtk_editable_insert_text(editable, url, strlen(url), &position); + } +} + +static void +extract_info(EContactEditor *editor) +{ + ECard *card = editor->card; + if (card) { + char *fname; + ECardList *address_list; + ECardList *phone_list; + ECardList *email_list; + char *url; + const ECardDeliveryAddress *address; + const ECardPhone *phone; + ECardDeliveryAddress *address_copy; + ECardPhone *phone_copy; + char *email; + GtkEditable *editable; + int position = 0; + + ECardIterator *iterator; + + gtk_object_get(GTK_OBJECT(card), + "address", &address_list, + "phone", &phone_list, + "email", &email_list, + NULL); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); + fname = gtk_editable_get_chars(editable, 0, -1); + + iterator = e_card_list_get_iterator(address_list); + address = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); + if (address) { + address_copy = e_card_delivery_address_copy(address); + if (address_copy->city) + g_free(address_copy->city); + address_copy->city = gtk_editable_get_chars(editable, 0, -1); + e_card_iterator_set(iterator, address_copy); + e_card_delivery_address_free(address_copy); } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); - gtk_editable_delete_text(editable, 0, -1); + address_copy = g_new0(ECardDeliveryAddress, 1); + address_copy->city = gtk_editable_get_chars(editable, 0, -1); + e_card_list_append(address_list, address_copy); + e_card_delivery_address_free(address_copy); } - if (url) { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); - gtk_editable_delete_text(editable, 0, -1); - gtk_editable_insert_text(editable, url, strlen(url), &position); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(phone_list); + phone = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); + if (phone) { + phone_copy = e_card_phone_copy(phone); + if (phone_copy->number) + g_free(phone_copy->number); + phone_copy->number = gtk_editable_get_chars(editable, 0, -1); + e_card_iterator_set(iterator, phone_copy); + e_card_phone_free(phone_copy); } else { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); - gtk_editable_delete_text(editable, 0, -1); + phone_copy = g_new0(ECardPhone, 1); + phone_copy->number = gtk_editable_get_chars(editable, 0, -1); + e_card_list_append(phone_list, phone_copy); + e_card_phone_free(phone_copy); } + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(email_list); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); + email = gtk_editable_get_chars(editable, 0, -1); + if (e_card_iterator_is_valid(iterator)) + e_card_iterator_set(iterator, email); + else + e_card_list_append(email_list, email); + g_free(email); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); + url = gtk_editable_get_chars(editable, 0, -1); + + gtk_object_set(GTK_OBJECT(card), + "full_name", fname, + "url", url, + NULL); + + g_free(fname); + g_free(url); } } diff --git a/addressbook/contact-editor/e-contact-editor.h b/addressbook/contact-editor/e-contact-editor.h index 1ae0fdf275..72f87e9b08 100644 --- a/addressbook/contact-editor/e-contact-editor.h +++ b/addressbook/contact-editor/e-contact-editor.h @@ -42,8 +42,8 @@ extern "C" { #define E_CONTACT_EDITOR_TYPE (e_contact_editor_get_type ()) #define E_CONTACT_EDITOR(obj) (GTK_CHECK_CAST ((obj), E_CONTACT_EDITOR_TYPE, EContactEditor)) #define E_CONTACT_EDITOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_CONTACT_EDITOR_TYPE, EContactEditorClass)) -#define E_IS_MINICARD(obj) (GTK_CHECK_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) -#define E_IS_MINICARD_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) +#define E_IS_CONTACT_EDITOR(obj) (GTK_CHECK_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) +#define E_IS_CONTACT_EDITOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) typedef struct _EContactEditor EContactEditor; diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 7d795eb8d8..064b29b7f8 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -76,7 +76,7 @@ new_contact_cb (BonoboUIHandler *uih, void *user_data, const char *path) { gint result; GtkWidget* contact_editor = - e_contact_editor_new(e_card_new(BLANK_VCARD)); + e_contact_editor_new(e_card_new("")); EBook *book = E_BOOK (user_data); GtkWidget* dlg = gnome_dialog_new ("Contact Editor", "Save", "Cancel", NULL); @@ -94,13 +94,17 @@ new_contact_cb (BonoboUIHandler *uih, void *user_data, const char *path) /* If the user clicks "okay"...*/ if (result == 0) { + ECard *card; g_assert (contact_editor); g_assert (GTK_IS_OBJECT (contact_editor)); + gtk_object_get(GTK_OBJECT(contact_editor), + "card", &card, + NULL); /* Add the card in the contact editor to our ebook */ e_book_add_card ( book, - E_CONTACT_EDITOR(contact_editor)->card, + card, card_added_cb, NULL); } diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index 81916847f7..cda77e4431 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -32,7 +32,8 @@ static GtkWidget *e_contact_editor_build_dialog(EContactEditor *editor, gchar *e static void _email_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _phone_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); static void _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEditor *editor); -static void fill_in_info(EContactEditor *editor, ECard *card); +static void fill_in_info(EContactEditor *editor); +static void extract_info(EContactEditor *editor); static GtkVBoxClass *parent_class = NULL; @@ -254,8 +255,6 @@ e_contact_editor_new (ECard *card) gtk_object_set (GTK_OBJECT(widget), "card", card, NULL); - - E_CONTACT_EDITOR (widget)->card = card; return widget; } @@ -268,7 +267,10 @@ e_contact_editor_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) switch (arg_id){ case ARG_CARD: - fill_in_info(e_contact_editor, E_CARD(GTK_VALUE_OBJECT (*arg))); + if (e_contact_editor->card) + gtk_object_unref(GTK_OBJECT(e_contact_editor->card)); + e_contact_editor->card = e_card_duplicate(E_CARD(GTK_VALUE_OBJECT (*arg))); + fill_in_info(e_contact_editor); break; } } @@ -282,7 +284,8 @@ e_contact_editor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) switch (arg_id) { case ARG_CARD: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(NULL); + extract_info(e_contact_editor); + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_contact_editor->card); break; default: arg->type = GTK_TYPE_INVALID; @@ -570,14 +573,20 @@ _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEdito } static void -fill_in_info(EContactEditor *editor, ECard *card) +fill_in_info(EContactEditor *editor) { + ECard *card = editor->card; if (card) { char *fname; ECardList *address_list; ECardList *phone_list; ECardList *email_list; char *url; + const ECardDeliveryAddress *address; + const ECardPhone *phone; + GtkEditable *editable; + int position = 0; + const char *email; ECardIterator *iterator; @@ -588,68 +597,136 @@ fill_in_info(EContactEditor *editor, ECard *card) "email", &email_list, "url", &url, NULL); - - if (fname) { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); - gtk_editable_delete_text(editable, 0, -1); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); + gtk_editable_delete_text(editable, 0, -1); + if (fname) gtk_editable_insert_text(editable, fname, strlen(fname), &position); - } else { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); - gtk_editable_delete_text(editable, 0, -1); - gtk_editable_insert_text(editable, "", 0, &position); - } - if (address_list) { - const ECardDeliveryAddress *address; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(address_list); - address = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); - gtk_editable_delete_text(editable, 0, -1); + position = 0; + iterator = e_card_list_get_iterator(address_list); + address = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); + gtk_editable_delete_text(editable, 0, -1); + if (address) gtk_editable_insert_text(editable, address->city, strlen(address->city), &position); - } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); - gtk_editable_delete_text(editable, 0, -1); - } - - if (address_list) { - const ECardPhone *phone; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(phone_list); - phone = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); - gtk_editable_delete_text(editable, 0, -1); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(phone_list); + phone = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); + gtk_editable_delete_text(editable, 0, -1); + if (phone) gtk_editable_insert_text(editable, phone->number, strlen(phone->number), &position); - } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); - gtk_editable_delete_text(editable, 0, -1); - } - if (email_list) { - const char *email; - GtkEditable *editable; - int position = 0; - iterator = e_card_list_get_iterator(email_list); - email = e_card_iterator_get(iterator); - editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); - gtk_editable_delete_text(editable, 0, -1); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(email_list); + email = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); + gtk_editable_delete_text(editable, 0, -1); + if (email) gtk_editable_insert_text(editable, email, strlen(email), &position); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); + gtk_editable_delete_text(editable, 0, -1); + if (url) + gtk_editable_insert_text(editable, url, strlen(url), &position); + } +} + +static void +extract_info(EContactEditor *editor) +{ + ECard *card = editor->card; + if (card) { + char *fname; + ECardList *address_list; + ECardList *phone_list; + ECardList *email_list; + char *url; + const ECardDeliveryAddress *address; + const ECardPhone *phone; + ECardDeliveryAddress *address_copy; + ECardPhone *phone_copy; + char *email; + GtkEditable *editable; + int position = 0; + + ECardIterator *iterator; + + gtk_object_get(GTK_OBJECT(card), + "address", &address_list, + "phone", &phone_list, + "email", &email_list, + NULL); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-fullname")); + fname = gtk_editable_get_chars(editable, 0, -1); + + iterator = e_card_list_get_iterator(address_list); + address = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-address")); + if (address) { + address_copy = e_card_delivery_address_copy(address); + if (address_copy->city) + g_free(address_copy->city); + address_copy->city = gtk_editable_get_chars(editable, 0, -1); + e_card_iterator_set(iterator, address_copy); + e_card_delivery_address_free(address_copy); } else { - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); - gtk_editable_delete_text(editable, 0, -1); + address_copy = g_new0(ECardDeliveryAddress, 1); + address_copy->city = gtk_editable_get_chars(editable, 0, -1); + e_card_list_append(address_list, address_copy); + e_card_delivery_address_free(address_copy); } - if (url) { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); - gtk_editable_delete_text(editable, 0, -1); - gtk_editable_insert_text(editable, url, strlen(url), &position); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(phone_list); + phone = e_card_iterator_get(iterator); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-phone1")); + if (phone) { + phone_copy = e_card_phone_copy(phone); + if (phone_copy->number) + g_free(phone_copy->number); + phone_copy->number = gtk_editable_get_chars(editable, 0, -1); + e_card_iterator_set(iterator, phone_copy); + e_card_phone_free(phone_copy); } else { - int position = 0; - GtkEditable *editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); - gtk_editable_delete_text(editable, 0, -1); + phone_copy = g_new0(ECardPhone, 1); + phone_copy->number = gtk_editable_get_chars(editable, 0, -1); + e_card_list_append(phone_list, phone_copy); + e_card_phone_free(phone_copy); } + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + iterator = e_card_list_get_iterator(email_list); + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-email1")); + email = gtk_editable_get_chars(editable, 0, -1); + if (e_card_iterator_is_valid(iterator)) + e_card_iterator_set(iterator, email); + else + e_card_list_append(email_list, email); + g_free(email); + gtk_object_unref(GTK_OBJECT(iterator)); + + position = 0; + editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-web")); + url = gtk_editable_get_chars(editable, 0, -1); + + gtk_object_set(GTK_OBJECT(card), + "full_name", fname, + "url", url, + NULL); + + g_free(fname); + g_free(url); } } diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h index 1ae0fdf275..72f87e9b08 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.h +++ b/addressbook/gui/contact-editor/e-contact-editor.h @@ -42,8 +42,8 @@ extern "C" { #define E_CONTACT_EDITOR_TYPE (e_contact_editor_get_type ()) #define E_CONTACT_EDITOR(obj) (GTK_CHECK_CAST ((obj), E_CONTACT_EDITOR_TYPE, EContactEditor)) #define E_CONTACT_EDITOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_CONTACT_EDITOR_TYPE, EContactEditorClass)) -#define E_IS_MINICARD(obj) (GTK_CHECK_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) -#define E_IS_MINICARD_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) +#define E_IS_CONTACT_EDITOR(obj) (GTK_CHECK_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) +#define E_IS_CONTACT_EDITOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CONTACT_EDITOR_TYPE)) typedef struct _EContactEditor EContactEditor; diff --git a/addressbook/gui/minicard/Makefile.am b/addressbook/gui/minicard/Makefile.am index 3534e9cb69..2eeb1ec3bc 100644 --- a/addressbook/gui/minicard/Makefile.am +++ b/addressbook/gui/minicard/Makefile.am @@ -1,5 +1,6 @@ INCLUDES = \ -I$(top_srcdir)/addressbook/backend/ebook \ + -I$(top_srcdir)/addressbook/contact-editor \ -I$(top_srcdir)/widgets/e-text \ -I$(top_srcdir)/e-util \ $(GNOME_INCLUDEDIR) @@ -47,6 +48,7 @@ minicard_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a reflow_test_SOURCES = \ @@ -60,6 +62,7 @@ reflow_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a minicard_view_test_SOURCES = \ @@ -73,4 +76,5 @@ minicard_view_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c index 12041a0c5f..6db76afd6d 100644 --- a/addressbook/gui/minicard/e-minicard.c +++ b/addressbook/gui/minicard/e-minicard.c @@ -28,6 +28,8 @@ #include "e-canvas.h" #include "e-util.h" #include "e-canvas-utils.h" +#include "e-contact-editor.h" +#include "e-minicard-view.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -278,87 +280,130 @@ e_minicard_unrealize (GnomeCanvasItem *item) (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); } +static void +card_changed_cb (EBook* book, EBookStatus status, gpointer user_data) +{ + g_print ("%s: %s(): a card was changed\n", __FILE__, __FUNCTION__); +} + static gboolean e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) { - EMinicard *e_minicard; - - e_minicard = E_MINICARD (item); - - switch( event->type ) - { - case GDK_FOCUS_CHANGE: - { - GdkEventFocus *focus_event = (GdkEventFocus *) event; - if ( focus_event->in ) - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", "grey50", - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "darkblue", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "white", - NULL ); - e_minicard->has_focus = TRUE; - } + EMinicard *e_minicard; + + e_minicard = E_MINICARD (item); + + switch( event->type ) { + case GDK_FOCUS_CHANGE: + { + GdkEventFocus *focus_event = (GdkEventFocus *) event; + if ( focus_event->in ) { + gnome_canvas_item_set( e_minicard->rect, + "outline_color", "grey50", + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "fill_color", "darkblue", + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "fill_color", "white", + NULL ); + e_minicard->has_focus = TRUE; + } else { + gnome_canvas_item_set( e_minicard->rect, + "outline_color", NULL, + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "fill_color", "grey70", + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "fill_color", "black", + NULL ); + e_minicard->has_focus = FALSE; + } + } + break; + case GDK_BUTTON_PRESS: + if (event->button.button == 1) { + e_canvas_item_grab_focus(item); + } + break; + case GDK_2BUTTON_PRESS: + if (E_IS_MINICARD_VIEW(item->parent)) { + gint result; + GtkWidget* contact_editor = + e_contact_editor_new(e_minicard->card); + EBook *book; + GtkWidget *dlg; + gtk_object_get(GTK_OBJECT(item->parent), + "book", &book, + NULL); + + dlg = gnome_dialog_new ("Contact Editor", "Save", "Cancel", NULL); + + g_assert (E_IS_BOOK (book)); + + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox), + contact_editor, TRUE, TRUE, 0); + + gtk_widget_show_all (dlg); + + gnome_dialog_close_hides (GNOME_DIALOG (dlg), TRUE); + result = gnome_dialog_run_and_close (GNOME_DIALOG (dlg)); + + + /* If the user clicks "okay"...*/ + if (result == 0) { + ECard *card; + g_assert (contact_editor); + g_assert (GTK_IS_OBJECT (contact_editor)); + gtk_object_get(GTK_OBJECT(contact_editor), + "card", &card, + NULL); + + /* Add the card in the contact editor to our ebook */ + e_book_commit_card (book, + card, + card_changed_cb, + NULL); + } + } + break; + case GDK_KEY_PRESS: + if (event->key.keyval == GDK_Tab || + event->key.keyval == GDK_KP_Tab || + event->key.keyval == GDK_ISO_Left_Tab) { + GList *list; + for (list = e_minicard->fields; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + EFocus has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus != E_FOCUS_NONE) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); else - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", NULL, - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey70", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "black", - NULL ); - e_minicard->has_focus = FALSE; - } - } - break; - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - e_canvas_item_grab_focus(item); - } - break; - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - GList *list; - for (list = e_minicard->fields; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); - EFocus has_focus; - gtk_object_get(GTK_OBJECT(item), - "has_focus", &has_focus, - NULL); - if (has_focus != E_FOCUS_NONE) { - if (event->key.state & GDK_SHIFT_MASK) - list = list->prev; - else - list = list->next; - if (list) { - item = GNOME_CANVAS_ITEM (list->data); - gnome_canvas_item_set(item, - "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, - NULL); - return 1; - } else { - return 0; - } - } - } - } - default: - break; - } - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) - return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); - else - return 0; + return 0; } static void @@ -548,7 +593,13 @@ e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2) gtk_object_get(GTK_OBJECT(minicard2->card), "full_name", &fname2, NULL); - return strcmp(fname1, fname2); + if (fname1 && fname2) + return strcmp(fname1, fname2); + if (fname1) + return -1; + if (fname2) + return 1; + return 0; } else { return 0; } diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index 3534e9cb69..2eeb1ec3bc 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -1,5 +1,6 @@ INCLUDES = \ -I$(top_srcdir)/addressbook/backend/ebook \ + -I$(top_srcdir)/addressbook/contact-editor \ -I$(top_srcdir)/widgets/e-text \ -I$(top_srcdir)/e-util \ $(GNOME_INCLUDEDIR) @@ -47,6 +48,7 @@ minicard_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a reflow_test_SOURCES = \ @@ -60,6 +62,7 @@ reflow_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a minicard_view_test_SOURCES = \ @@ -73,4 +76,5 @@ minicard_view_test_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/addressbook/contact-editor/libecontacteditor.a \ $(top_builddir)/widgets/e-text/libetext.a diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 12041a0c5f..6db76afd6d 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -28,6 +28,8 @@ #include "e-canvas.h" #include "e-util.h" #include "e-canvas-utils.h" +#include "e-contact-editor.h" +#include "e-minicard-view.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -278,87 +280,130 @@ e_minicard_unrealize (GnomeCanvasItem *item) (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); } +static void +card_changed_cb (EBook* book, EBookStatus status, gpointer user_data) +{ + g_print ("%s: %s(): a card was changed\n", __FILE__, __FUNCTION__); +} + static gboolean e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) { - EMinicard *e_minicard; - - e_minicard = E_MINICARD (item); - - switch( event->type ) - { - case GDK_FOCUS_CHANGE: - { - GdkEventFocus *focus_event = (GdkEventFocus *) event; - if ( focus_event->in ) - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", "grey50", - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "darkblue", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "white", - NULL ); - e_minicard->has_focus = TRUE; - } + EMinicard *e_minicard; + + e_minicard = E_MINICARD (item); + + switch( event->type ) { + case GDK_FOCUS_CHANGE: + { + GdkEventFocus *focus_event = (GdkEventFocus *) event; + if ( focus_event->in ) { + gnome_canvas_item_set( e_minicard->rect, + "outline_color", "grey50", + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "fill_color", "darkblue", + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "fill_color", "white", + NULL ); + e_minicard->has_focus = TRUE; + } else { + gnome_canvas_item_set( e_minicard->rect, + "outline_color", NULL, + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "fill_color", "grey70", + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "fill_color", "black", + NULL ); + e_minicard->has_focus = FALSE; + } + } + break; + case GDK_BUTTON_PRESS: + if (event->button.button == 1) { + e_canvas_item_grab_focus(item); + } + break; + case GDK_2BUTTON_PRESS: + if (E_IS_MINICARD_VIEW(item->parent)) { + gint result; + GtkWidget* contact_editor = + e_contact_editor_new(e_minicard->card); + EBook *book; + GtkWidget *dlg; + gtk_object_get(GTK_OBJECT(item->parent), + "book", &book, + NULL); + + dlg = gnome_dialog_new ("Contact Editor", "Save", "Cancel", NULL); + + g_assert (E_IS_BOOK (book)); + + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox), + contact_editor, TRUE, TRUE, 0); + + gtk_widget_show_all (dlg); + + gnome_dialog_close_hides (GNOME_DIALOG (dlg), TRUE); + result = gnome_dialog_run_and_close (GNOME_DIALOG (dlg)); + + + /* If the user clicks "okay"...*/ + if (result == 0) { + ECard *card; + g_assert (contact_editor); + g_assert (GTK_IS_OBJECT (contact_editor)); + gtk_object_get(GTK_OBJECT(contact_editor), + "card", &card, + NULL); + + /* Add the card in the contact editor to our ebook */ + e_book_commit_card (book, + card, + card_changed_cb, + NULL); + } + } + break; + case GDK_KEY_PRESS: + if (event->key.keyval == GDK_Tab || + event->key.keyval == GDK_KP_Tab || + event->key.keyval == GDK_ISO_Left_Tab) { + GList *list; + for (list = e_minicard->fields; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + EFocus has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus != E_FOCUS_NONE) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); else - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", NULL, - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey70", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "black", - NULL ); - e_minicard->has_focus = FALSE; - } - } - break; - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - e_canvas_item_grab_focus(item); - } - break; - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - GList *list; - for (list = e_minicard->fields; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); - EFocus has_focus; - gtk_object_get(GTK_OBJECT(item), - "has_focus", &has_focus, - NULL); - if (has_focus != E_FOCUS_NONE) { - if (event->key.state & GDK_SHIFT_MASK) - list = list->prev; - else - list = list->next; - if (list) { - item = GNOME_CANVAS_ITEM (list->data); - gnome_canvas_item_set(item, - "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, - NULL); - return 1; - } else { - return 0; - } - } - } - } - default: - break; - } - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) - return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); - else - return 0; + return 0; } static void @@ -548,7 +593,13 @@ e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2) gtk_object_get(GTK_OBJECT(minicard2->card), "full_name", &fname2, NULL); - return strcmp(fname1, fname2); + if (fname1 && fname2) + return strcmp(fname1, fname2); + if (fname1) + return -1; + if (fname2) + return 1; + return 0; } else { return 0; } diff --git a/wombat/Makefile.am b/wombat/Makefile.am index 4dbdb4467b..49371f64ab 100644 --- a/wombat/Makefile.am +++ b/wombat/Makefile.am @@ -20,6 +20,7 @@ wombat_LDADD = \ $(BONOBO_HTML_GNOME_LIBS) \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/addressbook/backend/pas/libpas.la \ + $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/calendar/pcs/libpcs.la \ $(top_builddir)/libical/src/libical/libical.la \ $(top_builddir)/calendar/cal-util/libcalutil.la \ |