diff options
-rw-r--r-- | addressbook/ChangeLog | 16 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-simple.c | 246 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-simple.h | 114 | ||||
-rw-r--r-- | addressbook/contact-editor/e-contact-editor.c | 33 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook.c | 10 | ||||
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-editor.c | 33 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard.c | 143 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard.h | 7 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.c | 143 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.h | 7 |
10 files changed, 486 insertions, 266 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index e1a9d7bbfa..0cc40898fd 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,4 +1,20 @@ +2000-05-06 Christopher James Lahey <clahey@helixcode.com> + + * backend/ebook/e-card-simple.c, backend/ebook/e-card-simple.h: + Mostly finished ECardSimple. + + * contact-editor/e-contact-editor.c: Changed this to match with + some of the changes to ECardSimple. + + * gui/component/addressbook.c: Changed this to look for + "addressbook.db" in the given directory if it doesn't find the + file "uri". + + * gui/minicard/e-minicard.c, gui/minicard/e-minicard.h: Changed + this to use ECardSimple. + 2000-05-06 Chris Toshok <toshok@helixcode.com> + * gui/component/.cvsignore: ignore evolution-addressbook.pure * gui/component/Makefile.am: add support for generating diff --git a/addressbook/backend/ebook/e-card-simple.c b/addressbook/backend/ebook/e-card-simple.c index 495fc71e80..cd3d75f957 100644 --- a/addressbook/backend/ebook/e-card-simple.c +++ b/addressbook/backend/ebook/e-card-simple.c @@ -48,6 +48,67 @@ enum { #endif }; + +typedef enum _ECardSimpleInternalType ECardSimpleInternalType; +typedef struct _ECardSimpleFieldData ECardSimpleFieldData; + +enum _ECardSimpleInternalType { + E_CARD_SIMPLE_INTERNAL_TYPE_STRING, + E_CARD_SIMPLE_INTERNAL_TYPE_DATE, + E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS, + E_CARD_SIMPLE_INTERNAL_TYPE_PHONE, + E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL, +}; + +struct _ECardSimpleFieldData { + ECardSimpleField field; + char *ecard_field; + char *name; + char *short_name; + int list_type_index; + ECardSimpleInternalType type; +}; + +/* This order must match the order in the .h. */ + +static ECardSimpleFieldData field_data[] = +{ + { E_CARD_SIMPLE_FIELD_FILE_AS, "file_as", "File As", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "Name", "Name", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_BIRTH_DATE, "birth_date", "Birth Date", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_DATE }, + { E_CARD_SIMPLE_FIELD_URL, "url", "Web Site", "Url", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_ORG, "org", "Organization", "Org", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_ORG_UNIT, "org_unit", "Department", "Dep", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_OFFICE, "office", "Office", "Off", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_TITLE, "title", "Title", "Title", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_ROLE, "role", "Profession", "Prof", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_MANAGER, "manager", "Manager", "Man", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_ASSISTANT, "assistant", "Assistant", "Ass", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_NICKNAME, "nickname", "Nickname", "Nick", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_SPOUSE, "spouse", "Spouse", "Spouse", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_ANNIVERSARY, "anniversary", "Anniversary", "Anniv", 0, E_CARD_SIMPLE_INTERNAL_TYPE_DATE }, + { E_CARD_SIMPLE_FIELD_FBURL, "fburl", "Free-busy URL", "FBUrl", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_NOTE, "note", "Note", "Note", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, + { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS, "", "Business", "Bus", E_CARD_SIMPLE_PHONE_ID_BUSINESS, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2, "", "Business 2", "Bus 2", E_CARD_SIMPLE_PHONE_ID_BUSINESS_2, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX, "", "Business Fax", "Bus Fax", E_CARD_SIMPLE_PHONE_ID_BUSINESS_FAX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_CAR, "", "Car", "Car", E_CARD_SIMPLE_PHONE_ID_CAR, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_HOME, "", "Home", "Home", E_CARD_SIMPLE_PHONE_ID_HOME, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_HOME_2, "", "Home 2", "Home 2", E_CARD_SIMPLE_PHONE_ID_HOME_2, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX, "", "Home Fax", "Home Fax", E_CARD_SIMPLE_PHONE_ID_HOME_FAX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_ISDN, "", "ISDN", "ISDN", E_CARD_SIMPLE_PHONE_ID_ISDN, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_MOBILE, "", "Mobile", "Mobile", E_CARD_SIMPLE_PHONE_ID_MOBILE, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_OTHER, "", "Other", "Other", E_CARD_SIMPLE_PHONE_ID_OTHER, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_PAGER, "", "Pager", "Pager", E_CARD_SIMPLE_PHONE_ID_PAGER, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "", "Primary", "Prim", E_CARD_SIMPLE_PHONE_ID_PRIMARY, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, + { E_CARD_SIMPLE_FIELD_ADDRESS_HOME, "", "Home", "Home", E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, + { E_CARD_SIMPLE_FIELD_ADDRESS_BUSINESS, "", "Business", "Bus", E_CARD_SIMPLE_ADDRESS_ID_HOME, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, + { E_CARD_SIMPLE_FIELD_ADDRESS_OTHER, "", "Other", "Other", E_CARD_SIMPLE_ADDRESS_ID_OTHER, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, + { E_CARD_SIMPLE_FIELD_EMAIL, "", "Email", "Email", E_CARD_SIMPLE_EMAIL_ID_EMAIL, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, + { E_CARD_SIMPLE_FIELD_EMAIL_2, "", "Email 2", "Email 2", E_CARD_SIMPLE_EMAIL_ID_EMAIL_2, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, + { E_CARD_SIMPLE_FIELD_EMAIL_3, "", "Email 3", "Email 3", E_CARD_SIMPLE_EMAIL_ID_EMAIL_3, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, +}; + static void e_card_simple_init (ECardSimple *simple); static void e_card_simple_class_init (ECardSimpleClass *klass); @@ -79,12 +140,62 @@ ECardPhoneFlags phone_correspondences[] = { 0xFF, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ }; +char *phone_names[] = { + NULL, /* E_CARD_SIMPLE_PHONE_ID_ASSISTANT, */ + "Business", + "Business 2", + "Business Fax", + NULL, /* E_CARD_SIMPLE_PHONE_ID_CALLBACK, */ + "Car", + NULL, /* E_CARD_SIMPLE_PHONE_ID_COMPANY, */ + "Home", + "Home 2", + "Home Fax", + "ISDN", + "Mobile", + "Other", + NULL, /* E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, */ + "Pager", + "Primary", + NULL, /* E_CARD_SIMPLE_PHONE_ID_RADIO, */ + NULL, /* E_CARD_SIMPLE_PHONE_ID_TELEX, */ + NULL, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ +}; + +char *phone_short_names[] = { + NULL, /* E_CARD_SIMPLE_PHONE_ID_ASSISTANT, */ + "Bus", + "Bus 2", + "Bus Fax", + NULL, /* E_CARD_SIMPLE_PHONE_ID_CALLBACK, */ + "Car", + NULL, /* E_CARD_SIMPLE_PHONE_ID_COMPANY, */ + "Home", + "Home 2", + "Home Fax", + "ISDN", + "Mob", + "Other", + NULL, /* E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, */ + "Pag", + "Prim", + NULL, /* E_CARD_SIMPLE_PHONE_ID_RADIO, */ + NULL, /* E_CARD_SIMPLE_PHONE_ID_TELEX, */ + NULL, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ +}; + ECardAddressFlags addr_correspondences[] = { E_CARD_ADDR_WORK, /* E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, */ E_CARD_ADDR_HOME, /* E_CARD_SIMPLE_ADDRESS_ID_HOME, */ E_CARD_ADDR_POSTAL, /* E_CARD_SIMPLE_ADDRESS_ID_OTHER, */ }; +char *address_names[] = { + "Business", + "Home", + "Other", +}; + /** * e_card_simple_get_type: * @void: @@ -256,6 +367,12 @@ e_card_simple_class_init (ECardSimpleClass *klass) static void e_card_simple_destroy (GtkObject *object) { + ECardSimple *simple; + + simple = E_CARD_SIMPLE (object); + + if (simple->card) + gtk_object_unref(GTK_OBJECT(simple->card)); } @@ -667,27 +784,27 @@ e_card_simple_sync_card(ECardSimple *simple) } } -ECardPhone *e_card_simple_get_phone (ECardSimple *simple, - ECardSimplePhoneId id) +const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, + ECardSimplePhoneId id) { return simple->phone[id]; } -char *e_card_simple_get_email (ECardSimple *simple, - ECardSimpleEmailId id) +const char *e_card_simple_get_email (ECardSimple *simple, + ECardSimpleEmailId id) { return simple->email[id]; } -ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, - ECardSimpleAddressId id) +const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, + ECardSimpleAddressId id) { return simple->address[id]; } void e_card_simple_set_phone (ECardSimple *simple, ECardSimplePhoneId id, - ECardPhone *phone) + const ECardPhone *phone) { if (simple->phone[id]) e_card_phone_free(simple->phone[id]); @@ -696,7 +813,7 @@ void e_card_simple_set_phone (ECardSimple *simple, void e_card_simple_set_email (ECardSimple *simple, ECardSimpleEmailId id, - char *email) + const char *email) { if (simple->email[id]) g_free(simple->email[id]); @@ -705,9 +822,120 @@ void e_card_simple_set_email (ECardSimple *simple, void e_card_simple_set_address (ECardSimple *simple, ECardSimpleAddressId id, - ECardAddrLabel *address) + const ECardAddrLabel *address) { if (simple->address[id]) e_card_address_label_free(simple->address[id]); simple->address[id] = e_card_address_label_copy(address); } + +char *e_card_simple_get (ECardSimple *simple, + ECardSimpleField field) +{ + ECardSimpleInternalType type = field_data[field].type; + const ECardAddrLabel *addr; + const ECardPhone *phone; + const char *string; + ECardDate *date; + switch(type) { + case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: + gtk_object_get(GTK_OBJECT(simple->card), + field_data[field].ecard_field, &string, + NULL); + return g_strdup(string); + case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: + gtk_object_get(GTK_OBJECT(simple->card), + field_data[field].ecard_field, &date, + NULL); + return NULL; /* FIXME!!!! */ + case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: + addr = e_card_simple_get_address(simple, + field_data[field].list_type_index); + if (addr) + return g_strdup(addr->data); + else + return NULL; + case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: + phone = e_card_simple_get_phone(simple, + field_data[field].list_type_index); + if (phone) + return g_strdup(phone->number); + else + return NULL; + case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: + string = e_card_simple_get_email(simple, + field_data[field].list_type_index); + return g_strdup(string); + default: + return NULL; + } +} + +void e_card_simple_set (ECardSimple *simple, + ECardSimpleField field, + const char *data) +{ + ECardSimpleInternalType type = field_data[field].type; + ECardAddrLabel *address; + ECardPhone *phone; + switch(type) { + case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: + gtk_object_set(GTK_OBJECT(simple->card), + field_data[field].ecard_field, data, + NULL); + break; + case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: + break; /* FIXME!!!! */ + case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: + address = e_card_address_label_new(); + address->data = (char *) data; + e_card_simple_set_address(simple, + field_data[field].list_type_index, + address); + address->data = NULL; + e_card_address_label_free(address); + break; + case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: + phone = e_card_phone_new(); + phone->number = (char *) data; + e_card_simple_set_phone(simple, + field_data[field].list_type_index, + phone); + phone->number = NULL; + e_card_phone_free(phone); + break; + case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: + e_card_simple_set_email(simple, + field_data[field].list_type_index, + data); + break; + } +} + +ECardSimpleType e_card_simple_type (ECardSimple *simple, + ECardSimpleField field) +{ + ECardSimpleInternalType type = field_data[field].type; + switch(type) { + case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: + case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: + case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: + case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: + default: + return E_CARD_SIMPLE_TYPE_STRING; + case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: + return E_CARD_SIMPLE_TYPE_DATE; + } +} + +const char *e_card_simple_get_name (ECardSimple *simple, + ECardSimpleField field) +{ + return field_data[field].name; +} + +const char *e_card_simple_get_short_name (ECardSimple *simple, + ECardSimpleField field) +{ + return field_data[field].short_name; +} diff --git a/addressbook/backend/ebook/e-card-simple.h b/addressbook/backend/ebook/e-card-simple.h index e039b55340..f0bb6cb541 100644 --- a/addressbook/backend/ebook/e-card-simple.h +++ b/addressbook/backend/ebook/e-card-simple.h @@ -28,6 +28,8 @@ typedef enum _ECardSimplePhoneId ECardSimplePhoneId; typedef enum _ECardSimpleEmailId ECardSimpleEmailId; typedef enum _ECardSimpleAddressId ECardSimpleAddressId; +typedef enum _ECardSimpleType ECardSimpleType; +typedef enum _ECardSimpleField ECardSimpleField; enum _ECardSimplePhoneId { E_CARD_SIMPLE_PHONE_ID_ASSISTANT, @@ -68,6 +70,49 @@ enum _ECardSimpleAddressId { E_CARD_SIMPLE_ADDRESS_ID_LAST }; +enum _ECardSimpleType { + E_CARD_SIMPLE_TYPE_STRING, + E_CARD_SIMPLE_TYPE_DATE, +}; + +enum _ECardSimpleField { + E_CARD_SIMPLE_FIELD_FILE_AS, + E_CARD_SIMPLE_FIELD_FULL_NAME, + E_CARD_SIMPLE_FIELD_BIRTH_DATE, + E_CARD_SIMPLE_FIELD_URL, + E_CARD_SIMPLE_FIELD_ORG, + E_CARD_SIMPLE_FIELD_ORG_UNIT, + E_CARD_SIMPLE_FIELD_OFFICE, + E_CARD_SIMPLE_FIELD_TITLE, + E_CARD_SIMPLE_FIELD_ROLE, + E_CARD_SIMPLE_FIELD_MANAGER, + E_CARD_SIMPLE_FIELD_ASSISTANT, + E_CARD_SIMPLE_FIELD_NICKNAME, + E_CARD_SIMPLE_FIELD_SPOUSE, + E_CARD_SIMPLE_FIELD_ANNIVERSARY, + E_CARD_SIMPLE_FIELD_FBURL, + E_CARD_SIMPLE_FIELD_NOTE, + E_CARD_SIMPLE_FIELD_PHONE_BUSINESS, + E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2, + E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX, + E_CARD_SIMPLE_FIELD_PHONE_CAR, + E_CARD_SIMPLE_FIELD_PHONE_HOME, + E_CARD_SIMPLE_FIELD_PHONE_HOME_2, + E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX, + E_CARD_SIMPLE_FIELD_PHONE_ISDN, + E_CARD_SIMPLE_FIELD_PHONE_MOBILE, + E_CARD_SIMPLE_FIELD_PHONE_OTHER, + E_CARD_SIMPLE_FIELD_PHONE_PAGER, + E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, + E_CARD_SIMPLE_FIELD_ADDRESS_HOME, + E_CARD_SIMPLE_FIELD_ADDRESS_BUSINESS, + E_CARD_SIMPLE_FIELD_ADDRESS_OTHER, + E_CARD_SIMPLE_FIELD_EMAIL, + E_CARD_SIMPLE_FIELD_EMAIL_2, + E_CARD_SIMPLE_FIELD_EMAIL_3, + E_CARD_SIMPLE_FIELD_LAST +}; + typedef struct _ECardSimple ECardSimple; typedef struct _ECardSimpleClass ECardSimpleClass; @@ -84,32 +129,51 @@ struct _ECardSimpleClass { GtkObjectClass parent_class; }; -ECardSimple *e_card_simple_new (ECard *card); -char *e_card_simple_get_id (ECardSimple *simple); -void e_card_simple_set_id (ECardSimple *simple, const gchar *character); -char *e_card_simple_get_vcard (ECardSimple *simple); - -ECardSimple *e_card_simple_duplicate (ECardSimple *simple); - -ECardPhone *e_card_simple_get_phone (ECardSimple *simple, - ECardSimplePhoneId id); -char *e_card_simple_get_email (ECardSimple *simple, - ECardSimpleEmailId id); -ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, - ECardSimpleAddressId id); -void e_card_simple_set_phone (ECardSimple *simple, - ECardSimplePhoneId id, - ECardPhone *phone); -void e_card_simple_set_email (ECardSimple *simple, - ECardSimpleEmailId id, - char *email); -void e_card_simple_set_address (ECardSimple *simple, - ECardSimpleAddressId id, - ECardAddrLabel *address); - -void e_card_simple_sync_card (ECardSimple *simple); +ECardSimple *e_card_simple_new (ECard *card); +char *e_card_simple_get_id (ECardSimple *simple); +void e_card_simple_set_id (ECardSimple *simple, + const gchar *character); +char *e_card_simple_get_vcard (ECardSimple *simple); + +ECardSimple *e_card_simple_duplicate (ECardSimple *simple); + +char *e_card_simple_get (ECardSimple *simple, + ECardSimpleField field); +void e_card_simple_set (ECardSimple *simple, + ECardSimpleField field, + const char *data); + +ECardSimpleType e_card_simple_type (ECardSimple *simple, + ECardSimpleField field); +const char *e_card_simple_get_name (ECardSimple *simple, + ECardSimpleField field); +const char *e_card_simple_get_short_name (ECardSimple *simple, + ECardSimpleField field); + + +/* Use these only if building lists of specific types. It should be + * easier to use the above if you consider a phone field to be the + * same as any other field. + */ +const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, + ECardSimplePhoneId id); +const char *e_card_simple_get_email (ECardSimple *simple, + ECardSimpleEmailId id); +const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, + ECardSimpleAddressId id); +void e_card_simple_set_phone (ECardSimple *simple, + ECardSimplePhoneId id, + const ECardPhone *phone); +void e_card_simple_set_email (ECardSimple *simple, + ECardSimpleEmailId id, + const char *email); +void e_card_simple_set_address (ECardSimple *simple, + ECardSimpleAddressId id, + const ECardAddrLabel *address); + +void e_card_simple_sync_card (ECardSimple *simple); /* Standard Gtk function */ -GtkType e_card_simple_get_type (void); +GtkType e_card_simple_get_type (void); #endif /* ! __E_CARD_SIMPLE_H__ */ diff --git a/addressbook/contact-editor/e-contact-editor.c b/addressbook/contact-editor/e-contact-editor.c index 42e1759bea..6205ecdcc6 100644 --- a/addressbook/contact-editor/e-contact-editor.c +++ b/addressbook/contact-editor/e-contact-editor.c @@ -188,16 +188,11 @@ phone_entry_changed (GtkWidget *widget, EContactEditor *editor) } else return; string = gtk_entry_get_text(entry); - phone = e_card_simple_get_phone(editor->simple, editor->phone_choice[which - 1]); - if (phone) { - g_free(phone->number); - } else { - phone = e_card_phone_new(); - e_card_simple_set_phone(editor->simple, editor->phone_choice[which - 1], phone); - e_card_phone_free(phone); - phone = e_card_simple_get_phone(editor->simple, editor->phone_choice[which - 1]); - } - phone->number = g_strdup(string); + phone = e_card_phone_new(); + phone->number = string; + e_card_simple_set_phone(editor->simple, editor->phone_choice[which - 1], phone); + phone->number = NULL; + e_card_phone_free(phone); set_fields(editor); } @@ -215,24 +210,16 @@ email_entry_changed (GtkWidget *widget, EContactEditor *editor) static void address_text_changed (GtkWidget *widget, EContactEditor *editor) { - gchar *string; GtkEditable *editable = GTK_EDITABLE(widget); ECardAddrLabel *address; if (editor->address_choice == -1) return; - address = e_card_simple_get_address(editor->simple, editor->address_choice); - if (address) { - g_free(address->data); - } else { - address = e_card_address_label_new(); - e_card_simple_set_address(editor->simple, editor->address_choice, address); - e_card_address_label_free(address); - address = e_card_simple_get_address(editor->simple, editor->address_choice); - } - string = gtk_editable_get_chars(editable, 0, -1); - address->data = string; + address = e_card_address_label_new(); + address->data = gtk_editable_get_chars(editable, 0, -1); + e_card_simple_set_address(editor->simple, editor->address_choice, address); + e_card_address_label_free(address); } /* This function tells you whether name_to_style will make sense. */ @@ -944,7 +931,7 @@ set_address_field(EContactEditor *editor, int result) { GtkEditable *editable; int position; - ECardAddrLabel *address; + const ECardAddrLabel *address; if (result == -1) result = editor->address_choice; editor->address_choice = -1; diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 72bd8967ba..f86a58a005 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -442,7 +442,6 @@ set_prop (BonoboPropertyBag *bag, EBook *book; char *uri_file; char *uri_data; - char *uri; switch (arg_id) { @@ -461,12 +460,11 @@ set_prop (BonoboPropertyBag *bag, uri_file = g_concat_dir_and_file(view->uri + 7, "uri"); uri_data = e_read_file(uri_file); - if (uri_data) - uri = uri_data; - else - uri = view->uri; + + if (!uri_data) + uri_data = g_concat_dir_and_file(view->uri + 7, "addressbook.db"); - if (! e_book_load_uri (book, uri, book_open_cb, view)) + if (! e_book_load_uri (book, uri_data, book_open_cb, view)) { printf ("error calling load_uri!\n"); } diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index 42e1759bea..6205ecdcc6 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -188,16 +188,11 @@ phone_entry_changed (GtkWidget *widget, EContactEditor *editor) } else return; string = gtk_entry_get_text(entry); - phone = e_card_simple_get_phone(editor->simple, editor->phone_choice[which - 1]); - if (phone) { - g_free(phone->number); - } else { - phone = e_card_phone_new(); - e_card_simple_set_phone(editor->simple, editor->phone_choice[which - 1], phone); - e_card_phone_free(phone); - phone = e_card_simple_get_phone(editor->simple, editor->phone_choice[which - 1]); - } - phone->number = g_strdup(string); + phone = e_card_phone_new(); + phone->number = string; + e_card_simple_set_phone(editor->simple, editor->phone_choice[which - 1], phone); + phone->number = NULL; + e_card_phone_free(phone); set_fields(editor); } @@ -215,24 +210,16 @@ email_entry_changed (GtkWidget *widget, EContactEditor *editor) static void address_text_changed (GtkWidget *widget, EContactEditor *editor) { - gchar *string; GtkEditable *editable = GTK_EDITABLE(widget); ECardAddrLabel *address; if (editor->address_choice == -1) return; - address = e_card_simple_get_address(editor->simple, editor->address_choice); - if (address) { - g_free(address->data); - } else { - address = e_card_address_label_new(); - e_card_simple_set_address(editor->simple, editor->address_choice, address); - e_card_address_label_free(address); - address = e_card_simple_get_address(editor->simple, editor->address_choice); - } - string = gtk_editable_get_chars(editable, 0, -1); - address->data = string; + address = e_card_address_label_new(); + address->data = gtk_editable_get_chars(editable, 0, -1); + e_card_simple_set_address(editor->simple, editor->address_choice, address); + e_card_address_label_free(address); } /* This function tells you whether name_to_style will make sense. */ @@ -944,7 +931,7 @@ set_address_field(EContactEditor *editor, int result) { GtkEditable *editable; int position; - ECardAddrLabel *address; + const ECardAddrLabel *address; if (result == -1) result = editor->address_choice; editor->address_choice = -1; diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c index 76aec54854..b75d1779d4 100644 --- a/addressbook/gui/minicard/e-minicard.c +++ b/addressbook/gui/minicard/e-minicard.c @@ -122,6 +122,7 @@ e_minicard_init (EMinicard *minicard) minicard->has_focus = FALSE; minicard->card = NULL; + minicard->simple = e_card_simple_new(NULL); e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow); } @@ -166,6 +167,9 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) e_minicard->card = E_CARD(GTK_VALUE_OBJECT (*arg)); if (e_minicard->card) gtk_object_ref (GTK_OBJECT(e_minicard->card)); + gtk_object_set(GTK_OBJECT(e_minicard->simple), + "card", e_minicard->card, + NULL); remodel(e_minicard); e_canvas_item_request_reflow(item); break; @@ -190,6 +194,7 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE; break; case ARG_CARD: + e_card_simple_sync_card(e_minicard->simple); GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->card); break; default: @@ -210,6 +215,8 @@ e_minicard_destroy (GtkObject *object) if (e_minicard->card) gtk_object_unref (GTK_OBJECT(e_minicard->card)); + if (e_minicard->simple) + gtk_object_unref (GTK_OBJECT(e_minicard->simple)); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); @@ -427,117 +434,79 @@ e_minicard_resize_children( EMinicard *e_minicard ) } static void -add_field (EMinicard *e_minicard, char *fieldname, char* field) +field_changed (EText *text, EMinicard *e_minicard) +{ + ECardSimpleType type; + char *string; + + type = GPOINTER_TO_INT + (gtk_object_get_data(GTK_OBJECT(text), + "EMinicard:field")); + gtk_object_get(GTK_OBJECT(text), + "text", &string, + NULL); + e_card_simple_set(e_minicard->simple, + type, + string); + g_free(string); +} + +static void +add_field (EMinicard *e_minicard, ECardSimpleField field) { GnomeCanvasItem *new_item; GnomeCanvasGroup *group; + ECardSimpleType type; + char *name; + char *string; group = GNOME_CANVAS_GROUP( e_minicard ); + + type = e_card_simple_type(e_minicard->simple, field); + name = g_strdup_printf("%s:", e_card_simple_get_name(e_minicard->simple, field)); + string = e_card_simple_get(e_minicard->simple, field); new_item = e_minicard_label_new(group); gnome_canvas_item_set( new_item, "width", e_minicard->width - 4.0, - "fieldname", fieldname, - "field", field, + "fieldname", name, + "field", string, NULL ); + gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), + "changed", GTK_SIGNAL_FUNC(field_changed), e_minicard); + gtk_object_set_data(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), + "EMinicard:field", + GINT_TO_POINTER(field)); e_minicard->fields = g_list_append( e_minicard->fields, new_item); e_canvas_item_move_absolute(new_item, 2, e_minicard->height); + g_free(name); + g_free(string); } - + static void remodel( EMinicard *e_minicard ) { - if (e_minicard->card) { - char *fname; + int count = 0; + if (e_minicard->simple) { + ECardSimpleField field; char *file_as; - char *url; - char *org; - char *title; - char *role; - ECardList *address_list; - ECardList *phone_list; - ECardList *email_list; - - ECardIterator *iterator; - - GList *list; + file_as = e_card_simple_get(e_minicard->simple, E_CARD_SIMPLE_FIELD_FILE_AS); + gnome_canvas_item_set( e_minicard->header_text, + "text", file_as ? file_as : "", + NULL ); + g_free(file_as); - for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { - gtk_object_destroy( GTK_OBJECT( list->data ) ); - } + g_list_foreach(e_minicard->fields, (GFunc) gtk_object_destroy, NULL); g_list_free(e_minicard->fields); e_minicard->fields = NULL; - gtk_object_get(GTK_OBJECT(e_minicard->card), - "full_name", &fname, - "file_as", &file_as, - "address", &address_list, - "phone", &phone_list, - "email", &email_list, - "url", &url, - "org", &org, - "title", &title, - "role", &role, - NULL); - - if (e_minicard->header_text) { - if (file_as) - gnome_canvas_item_set(e_minicard->header_text, - "text", file_as, - NULL); - else - gnome_canvas_item_set(e_minicard->header_text, - "text", "", - NULL); - } - - if (fname) - add_field(e_minicard, "Name:", fname); - - if (org) - add_field(e_minicard, "Company:", org); - - if (title) - add_field(e_minicard, "Title:", title); - - if (role) - add_field(e_minicard, "Profession:", role); - - if (address_list) { - for (iterator = e_card_list_get_iterator(address_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - const ECardDeliveryAddress *address = e_card_iterator_get(iterator); - if (address->flags & E_CARD_ADDR_WORK) { - add_field(e_minicard, "Work Address:", address->city); - } else if (address->flags & E_CARD_ADDR_HOME) { - add_field(e_minicard, "Home Address:", address->city); - } else { - add_field(e_minicard, "Address:", address->city); - } - } - } - if (phone_list) { - for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - const ECardPhone *phone = e_card_iterator_get(iterator); - if (phone->flags & E_CARD_PHONE_WORK) { - add_field(e_minicard, "Work Phone:", phone->number); - } else if (phone->flags & E_CARD_PHONE_HOME) { - add_field(e_minicard, "Home Phone:", phone->number); - } else if (phone->flags & E_CARD_PHONE_CELL) { - add_field(e_minicard, "Mobile Phone:", phone->number); - } else { - add_field(e_minicard, "Phone:", phone->number); - } - } - } - if (email_list) { - for (iterator = e_card_list_get_iterator(email_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - add_field(e_minicard, "Email:", (char *) e_card_iterator_get(iterator)); + for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST && count < 5; field++) { + if (e_card_simple_get(e_minicard->simple, field)) { + add_field(e_minicard, field); + count++; } } - - if (url) - add_field(e_minicard, "Web page:", url); } } diff --git a/addressbook/gui/minicard/e-minicard.h b/addressbook/gui/minicard/e-minicard.h index 6844e136bd..81a6f8bae6 100644 --- a/addressbook/gui/minicard/e-minicard.h +++ b/addressbook/gui/minicard/e-minicard.h @@ -23,6 +23,7 @@ #include <gnome.h> #include <ebook/e-card.h> +#include <ebook/e-card-simple.h> #ifdef __cplusplus extern "C" { @@ -61,14 +62,14 @@ struct _EMinicard GnomeCanvasGroup parent; /* item specific fields */ - /* ECard *card; */ + ECard *card; + ECardSimple *simple; GnomeCanvasItem *rect; GnomeCanvasItem *header_rect; GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ - ECard *card; + GList *fields; /* Of type GnomeCanvasItem. */ guint needs_remodeling : 1; gboolean has_focus; diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 76aec54854..b75d1779d4 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -122,6 +122,7 @@ e_minicard_init (EMinicard *minicard) minicard->has_focus = FALSE; minicard->card = NULL; + minicard->simple = e_card_simple_new(NULL); e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow); } @@ -166,6 +167,9 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) e_minicard->card = E_CARD(GTK_VALUE_OBJECT (*arg)); if (e_minicard->card) gtk_object_ref (GTK_OBJECT(e_minicard->card)); + gtk_object_set(GTK_OBJECT(e_minicard->simple), + "card", e_minicard->card, + NULL); remodel(e_minicard); e_canvas_item_request_reflow(item); break; @@ -190,6 +194,7 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE; break; case ARG_CARD: + e_card_simple_sync_card(e_minicard->simple); GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->card); break; default: @@ -210,6 +215,8 @@ e_minicard_destroy (GtkObject *object) if (e_minicard->card) gtk_object_unref (GTK_OBJECT(e_minicard->card)); + if (e_minicard->simple) + gtk_object_unref (GTK_OBJECT(e_minicard->simple)); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); @@ -427,117 +434,79 @@ e_minicard_resize_children( EMinicard *e_minicard ) } static void -add_field (EMinicard *e_minicard, char *fieldname, char* field) +field_changed (EText *text, EMinicard *e_minicard) +{ + ECardSimpleType type; + char *string; + + type = GPOINTER_TO_INT + (gtk_object_get_data(GTK_OBJECT(text), + "EMinicard:field")); + gtk_object_get(GTK_OBJECT(text), + "text", &string, + NULL); + e_card_simple_set(e_minicard->simple, + type, + string); + g_free(string); +} + +static void +add_field (EMinicard *e_minicard, ECardSimpleField field) { GnomeCanvasItem *new_item; GnomeCanvasGroup *group; + ECardSimpleType type; + char *name; + char *string; group = GNOME_CANVAS_GROUP( e_minicard ); + + type = e_card_simple_type(e_minicard->simple, field); + name = g_strdup_printf("%s:", e_card_simple_get_name(e_minicard->simple, field)); + string = e_card_simple_get(e_minicard->simple, field); new_item = e_minicard_label_new(group); gnome_canvas_item_set( new_item, "width", e_minicard->width - 4.0, - "fieldname", fieldname, - "field", field, + "fieldname", name, + "field", string, NULL ); + gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), + "changed", GTK_SIGNAL_FUNC(field_changed), e_minicard); + gtk_object_set_data(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), + "EMinicard:field", + GINT_TO_POINTER(field)); e_minicard->fields = g_list_append( e_minicard->fields, new_item); e_canvas_item_move_absolute(new_item, 2, e_minicard->height); + g_free(name); + g_free(string); } - + static void remodel( EMinicard *e_minicard ) { - if (e_minicard->card) { - char *fname; + int count = 0; + if (e_minicard->simple) { + ECardSimpleField field; char *file_as; - char *url; - char *org; - char *title; - char *role; - ECardList *address_list; - ECardList *phone_list; - ECardList *email_list; - - ECardIterator *iterator; - - GList *list; + file_as = e_card_simple_get(e_minicard->simple, E_CARD_SIMPLE_FIELD_FILE_AS); + gnome_canvas_item_set( e_minicard->header_text, + "text", file_as ? file_as : "", + NULL ); + g_free(file_as); - for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { - gtk_object_destroy( GTK_OBJECT( list->data ) ); - } + g_list_foreach(e_minicard->fields, (GFunc) gtk_object_destroy, NULL); g_list_free(e_minicard->fields); e_minicard->fields = NULL; - gtk_object_get(GTK_OBJECT(e_minicard->card), - "full_name", &fname, - "file_as", &file_as, - "address", &address_list, - "phone", &phone_list, - "email", &email_list, - "url", &url, - "org", &org, - "title", &title, - "role", &role, - NULL); - - if (e_minicard->header_text) { - if (file_as) - gnome_canvas_item_set(e_minicard->header_text, - "text", file_as, - NULL); - else - gnome_canvas_item_set(e_minicard->header_text, - "text", "", - NULL); - } - - if (fname) - add_field(e_minicard, "Name:", fname); - - if (org) - add_field(e_minicard, "Company:", org); - - if (title) - add_field(e_minicard, "Title:", title); - - if (role) - add_field(e_minicard, "Profession:", role); - - if (address_list) { - for (iterator = e_card_list_get_iterator(address_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - const ECardDeliveryAddress *address = e_card_iterator_get(iterator); - if (address->flags & E_CARD_ADDR_WORK) { - add_field(e_minicard, "Work Address:", address->city); - } else if (address->flags & E_CARD_ADDR_HOME) { - add_field(e_minicard, "Home Address:", address->city); - } else { - add_field(e_minicard, "Address:", address->city); - } - } - } - if (phone_list) { - for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - const ECardPhone *phone = e_card_iterator_get(iterator); - if (phone->flags & E_CARD_PHONE_WORK) { - add_field(e_minicard, "Work Phone:", phone->number); - } else if (phone->flags & E_CARD_PHONE_HOME) { - add_field(e_minicard, "Home Phone:", phone->number); - } else if (phone->flags & E_CARD_PHONE_CELL) { - add_field(e_minicard, "Mobile Phone:", phone->number); - } else { - add_field(e_minicard, "Phone:", phone->number); - } - } - } - if (email_list) { - for (iterator = e_card_list_get_iterator(email_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) { - add_field(e_minicard, "Email:", (char *) e_card_iterator_get(iterator)); + for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST && count < 5; field++) { + if (e_card_simple_get(e_minicard->simple, field)) { + add_field(e_minicard, field); + count++; } } - - if (url) - add_field(e_minicard, "Web page:", url); } } diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h index 6844e136bd..81a6f8bae6 100644 --- a/addressbook/gui/widgets/e-minicard.h +++ b/addressbook/gui/widgets/e-minicard.h @@ -23,6 +23,7 @@ #include <gnome.h> #include <ebook/e-card.h> +#include <ebook/e-card-simple.h> #ifdef __cplusplus extern "C" { @@ -61,14 +62,14 @@ struct _EMinicard GnomeCanvasGroup parent; /* item specific fields */ - /* ECard *card; */ + ECard *card; + ECardSimple *simple; GnomeCanvasItem *rect; GnomeCanvasItem *header_rect; GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ - ECard *card; + GList *fields; /* Of type GnomeCanvasItem. */ guint needs_remodeling : 1; gboolean has_focus; |