From 4416de463e9e41759c6f21e64aaa4458ddc10fde Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Mon, 4 Feb 2002 11:12:58 +0000 Subject: if the shown address in the mailing address or there is no mailing 2002-02-04 JP Rosevear * gui/contact-editor/e-contact-editor.c (address_text_changed): if the shown address in the mailing address or there is no mailing address, set the default flag and make sure the button is checked (address_mailing_changed): set the flags properly when the mailing address changes (e_contact_editor_init): listen for the check button being toggled (find_address_mailing): find the address (if any) with the default flag (set_address_field): set the mailing address button appropriately (fill_in_info): find the mailing address * gui/contact-editor/e-contact-editor.h: add new class data member * gui/contact-editor/contact-editor.glade: show mailing address check button svn path=/trunk/; revision=15561 --- addressbook/ChangeLog | 18 ++++ .../gui/contact-editor/contact-editor.glade | 1 - addressbook/gui/contact-editor/e-contact-editor.c | 120 ++++++++++++++++++++- addressbook/gui/contact-editor/e-contact-editor.h | 1 + 4 files changed, 134 insertions(+), 6 deletions(-) diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index b7cfe0ce46..9978df9d77 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,21 @@ +2002-02-04 JP Rosevear + + * gui/contact-editor/e-contact-editor.c (address_text_changed): if + the shown address in the mailing address or there is no mailing + address, set the default flag and make sure the button is checked + (address_mailing_changed): set the flags properly when the mailing + address changes + (e_contact_editor_init): listen for the check button being toggled + (find_address_mailing): find the address (if any) with the default + flag + (set_address_field): set the mailing address button appropriately + (fill_in_info): find the mailing address + + * gui/contact-editor/e-contact-editor.h: add new class data member + + * gui/contact-editor/contact-editor.glade: show mailing address + check button + 2002-02-01 Jeffrey Stedfast * backend/ebook/e-destination.c (e_destination_is_auto_recipient): diff --git a/addressbook/gui/contact-editor/contact-editor.glade b/addressbook/gui/contact-editor/contact-editor.glade index 6e554c36ea..c8c880fa0c 100644 --- a/addressbook/gui/contact-editor/contact-editor.glade +++ b/addressbook/gui/contact-editor/contact-editor.glade @@ -1174,7 +1174,6 @@ GtkCheckButton checkbutton-mailingaddress - False False True diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index bfd78ebe2d..016e515fd0 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -78,6 +78,7 @@ 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 find_address_mailing (EContactEditor *editor); static void enable_writable_fields(EContactEditor *editor); static void set_editable(EContactEditor *editor); static void fill_in_info(EContactEditor *editor); @@ -313,6 +314,19 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor) address = e_card_address_label_new(); + if (editor->address_mailing == editor->address_choice || editor->address_mailing == -1) { + GtkWidget *check; + + address->flags |= E_CARD_ADDR_DEFAULT; + + check = glade_xml_get_widget(editor->gui, "checkbutton-mailingaddress"); + if (check && GTK_IS_CHECK_BUTTON (check)) { + gtk_signal_handler_block_by_data (GTK_OBJECT (check), editor); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (check), editor); + } + } + address->data = e_utf8_gtk_editable_get_chars(editable, 0, -1); e_card_simple_set_address(editor->simple, editor->address_choice, address); @@ -321,6 +335,58 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor) widget_changed (widget, editor); } + +static void +address_mailing_changed (GtkWidget *widget, EContactEditor *editor) +{ + ECardAddrLabel *address; + GtkWidget *text; + gboolean mailing_address; + + if (editor->address_choice == -1) + return; + + mailing_address = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + + /* Mark the current address as the mailing address */ + text = glade_xml_get_widget(editor->gui, "text-address"); + if (text && GTK_IS_TEXT(text)) { + + address = e_card_address_label_new(); + + if (mailing_address) + address->flags |= E_CARD_ADDR_DEFAULT; + else + address->flags &= ~E_CARD_ADDR_DEFAULT; + address->data = e_utf8_gtk_editable_get_chars(GTK_EDITABLE (text), 0, -1); + + e_card_simple_set_address(editor->simple, editor->address_choice, address); + e_card_address_label_unref(address); + } + + /* Unset the previous mailing address flag */ + if (mailing_address && editor->address_mailing != -1) { + const ECardAddrLabel *curr; + + curr = e_card_simple_get_address(editor->simple, + editor->address_mailing); + address = e_card_address_label_copy (curr); + address->flags &= ~E_CARD_ADDR_DEFAULT; + e_card_simple_set_address(editor->simple, + editor->address_mailing, + address); + } + + /* Remember the new mailing address */ + if (mailing_address) + editor->address_mailing = editor->address_choice; + else + editor->address_mailing = -1; + + widget_changed (widget, editor); +} + + /* This function tells you whether name_to_style will make sense. */ static gboolean style_makes_sense(const ECardName *name, char *company, int style) @@ -1238,6 +1304,7 @@ e_contact_editor_init (EContactEditor *e_contact_editor) e_contact_editor->phone_choice[2] = E_CARD_SIMPLE_PHONE_ID_BUSINESS_FAX; e_contact_editor->phone_choice[3] = E_CARD_SIMPLE_PHONE_ID_MOBILE; e_contact_editor->address_choice = 0; + e_contact_editor->address_mailing = -1; e_contact_editor->arbitrary_fields = NULL; @@ -1267,6 +1334,11 @@ e_contact_editor_init (EContactEditor *e_contact_editor) if (wants_html && GTK_IS_TOGGLE_BUTTON(wants_html)) gtk_signal_connect(GTK_OBJECT(wants_html), "toggled", wants_html_changed, e_contact_editor); + + widget = glade_xml_get_widget(e_contact_editor->gui, "checkbutton-mailingaddress"); + if (widget && GTK_IS_TOGGLE_BUTTON(widget)) + gtk_signal_connect(GTK_OBJECT(widget), "toggled", + address_mailing_changed, e_contact_editor); widget = glade_xml_get_widget(e_contact_editor->gui, "button-fullname"); if (widget && GTK_IS_BUTTON(widget)) @@ -1920,6 +1992,32 @@ _address_arrow_pressed (GtkWidget *widget, GdkEventButton *button, EContactEdito } } +static void +find_address_mailing (EContactEditor *editor) +{ + const ECardAddrLabel *address; + int i; + + editor->address_mailing = -1; + for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) { + address = e_card_simple_get_address(editor->simple, i); + if (address && (address->flags & E_CARD_ADDR_DEFAULT)) { + if (editor->address_mailing == -1) { + editor->address_mailing = i; + } else { + ECardAddrLabel *new; + + new = e_card_address_label_copy (address); + new->flags &= ~E_CARD_ADDR_DEFAULT; + e_card_simple_set_address(editor->simple, i, new); + e_card_address_label_unref (new); + } + } + } + + +} + static void set_field(GtkEntry *entry, const char *string) { @@ -1990,11 +2088,11 @@ set_fields(EContactEditor *editor) static void set_address_field(EContactEditor *editor, int result) { - GtkWidget *widget; + GtkWidget *text, *check; - widget = glade_xml_get_widget(editor->gui, "text-address"); + text = glade_xml_get_widget(editor->gui, "text-address"); - if (widget && GTK_IS_TEXT(widget)) { + if (text && GTK_IS_TEXT(text)) { int position; GtkEditable *editable; const ECardAddrLabel *address; @@ -2004,7 +2102,8 @@ set_address_field(EContactEditor *editor, int result) editor->address_choice = -1; position = 0; - editable = GTK_EDITABLE(widget); + editable = GTK_EDITABLE(text); + gtk_editable_delete_text(editable, 0, -1); address = e_card_simple_get_address(editor->simple, result); if (address && address->data) { @@ -2013,6 +2112,15 @@ set_address_field(EContactEditor *editor, int result) g_free (u); } + check = glade_xml_get_widget(editor->gui, "checkbutton-mailingaddress"); + if (check && GTK_IS_CHECK_BUTTON (check)) { + if (address && address->data) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), + address->flags & E_CARD_ADDR_DEFAULT); + else + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), FALSE); + } + editor->address_choice = result; } } @@ -2241,7 +2349,7 @@ enable_writable_fields(EContactEditor *editor) /* disable the label widgets for the dropdowns (4 phone, 1 email and the toggle button, and 1 address and one for - the full adress button */ + the full address button */ for (i = 0; i < 4; i ++) { widget_name = g_strdup_printf ("label-phone%d", i+1); enable_widget (glade_xml_get_widget (editor->gui, widget_name), FALSE); @@ -2393,6 +2501,8 @@ fill_in_info(EContactEditor *editor) fill_in_single_field(editor, list->data); } + find_address_mailing (editor); + if (wants_html_set) { GtkWidget *widget = glade_xml_get_widget(editor->gui, "checkbutton-htmlmail"); if (widget && GTK_IS_CHECK_BUTTON(widget)) { diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h index 69036ef9a8..249640379b 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.h +++ b/addressbook/gui/contact-editor/e-contact-editor.h @@ -86,6 +86,7 @@ struct _EContactEditor ECardSimpleEmailId email_choice; ECardSimplePhoneId phone_choice[4]; ECardSimpleAddressId address_choice; + ECardSimpleAddressId address_mailing; GList *arbitrary_fields; -- cgit v1.2.3