From 9a1c55ede5e6aad25d0053b097dab47a66b479d1 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Mon, 25 Jun 2001 21:51:17 +0000 Subject: change layout slightly, the icon no longer pushes everything to the left, 2001-06-25 Chris Toshok * gui/contact-list-editor/contact-list-editor.glade: change layout slightly, the icon no longer pushes everything to the left, and make the buttons on the right smaller and more in line with the other widgets. * gui/contact-list-editor/e-contact-list-model.c (contact_list_value_at): return the SimpleAndString->string instead of querying the ecardsimple. (e_contact_list_model_init): initially allocate 10 of each type (email and simple). (e_contact_list_model_add_email): realloc if need be. (e_contact_list_model_add_card): same, and initialize the string displayed to be "[Name] []". (e_contact_list_model_remove_row): change for SimpleAndString. (contact_list_model_destroy): free our 2 arrays. * gui/contact-list-editor/e-contact-list-model.h: add alloc counts and the SimpleAndString struct. * gui/contact-list-editor/e-contact-list-editor.c: Helix Code => Ximian. (e_contact_list_editor_init): hook up d&d destination signals, and un-#if 0 the delete_event signal. (table_drag_motion_cb): new function. (table_drag_drop_cb): new function. (table_drag_data_received_cb): new function. (file_close_cb): new function. (verbs) uncomment the close verb. (close_dialog): new function. (app_delete_event_cb): new function. * gui/contact-list-editor/e-contact-list-editor.h: Helix Code => Ximian. svn path=/trunk/; revision=10494 --- .../gui/contact-list-editor/e-contact-list-model.c | 64 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'addressbook/gui/contact-list-editor/e-contact-list-model.c') diff --git a/addressbook/gui/contact-list-editor/e-contact-list-model.c b/addressbook/gui/contact-list-editor/e-contact-list-model.c index 8d8831a6ab..abc963b198 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-model.c +++ b/addressbook/gui/contact-list-editor/e-contact-list-model.c @@ -30,7 +30,7 @@ contact_list_value_at (ETableModel *etc, int col, int row) EContactListModel *model = E_CONTACT_LIST_MODEL (etc); if (row < model->simple_count) - return (char*)e_card_simple_get_const (model->simples[row], E_CARD_SIMPLE_FIELD_EMAIL); + return model->simples[row]->string; else return model->emails [row - model->simple_count]; } @@ -84,6 +84,21 @@ contact_list_value_to_string (ETableModel *etc, int col, const void *value) static void contact_list_model_destroy (GtkObject *o) { + EContactListModel *model = E_CONTACT_LIST_MODEL (o); + int i; + + for (i = 0; i < model->simple_count; i ++) { + g_free (model->simples[i]->string); + gtk_object_unref (GTK_OBJECT(model->simples[i]->simple)); + g_free (model->simples[i]); + } + g_free (model->simples); + model->simple_count = 0; + + for (i = 0; i < model->email_count; i ++) + g_free (model->emails[i]); + g_free (model->emails); + model->email_count = 0; } static void @@ -112,9 +127,12 @@ e_contact_list_model_init (GtkObject *object) { EContactListModel *model = E_CONTACT_LIST_MODEL(object); - model->simples = NULL; + model->simple_alloc = 10; + model->simples = g_new (SimpleAndString*, model->simple_alloc); model->simple_count = 0; - model->emails = NULL; + + model->email_alloc = 10; + model->emails = g_new (char*, model->email_alloc); model->email_count = 0; } @@ -162,9 +180,12 @@ void e_contact_list_model_add_email (EContactListModel *model, const char *email) { - model->email_count ++; - model->emails = g_renew (char*, model->emails, model->email_count); - model->emails[model->email_count - 1] = g_strdup (email); + if (model->email_count + 1 >= model->email_alloc) { + model->email_alloc *= 2; + model->emails = g_renew (char*, model->emails, model->email_alloc); + } + + model->emails[model->email_count ++] = g_strdup (email); e_table_model_changed (E_TABLE_MODEL (model)); } @@ -172,12 +193,43 @@ void e_contact_list_model_add_card (EContactListModel *model, ECardSimple *simple) { + char *email, *name; + + name = e_card_simple_get (simple, E_CARD_SIMPLE_FIELD_NAME_OR_ORG); + email = e_card_simple_get (simple, E_CARD_SIMPLE_FIELD_EMAIL); + + if (! name && ! email) { + /* what to do here? */ + return; + } + + + if (model->simple_count + 1 >= model->simple_alloc) { + model->simple_alloc *= 2; + model->simples = g_renew (SimpleAndString*, model->simples, model->simple_alloc); + } + + model->simples[model->simple_count] = g_new (SimpleAndString, 1); + + model->simples[model->simple_count]->simple = simple; + model->simples[model->simple_count]->string = g_strconcat (name ? name : "", + email ? " <" : "", email ? email : "", email ? ">" : "", + NULL); + + model->simple_count++; + + gtk_object_ref (GTK_OBJECT (simple)); + + e_table_model_changed (E_TABLE_MODEL (model)); } void e_contact_list_model_remove_row (EContactListModel *model, int row) { if (row < model->simple_count) { + g_free (model->simples[row]->string); + gtk_object_unref (GTK_OBJECT(model->simples[row]->simple)); + g_free (model->simples[row]); memcpy (model->simples + row, model->simples + row + 1, model->simple_count - row); model->simple_count --; } -- cgit v1.2.3