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 --- addressbook/ChangeLog | 36 ++++ .../contact-list-editor/contact-list-editor.glade | 182 ++++++++++----------- .../contact-list-editor/e-contact-list-editor.c | 144 +++++++++++++++- .../contact-list-editor/e-contact-list-editor.h | 4 +- .../gui/contact-list-editor/e-contact-list-model.c | 64 +++++++- .../gui/contact-list-editor/e-contact-list-model.h | 9 +- 6 files changed, 327 insertions(+), 112 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 83e1317287..e98d406b16 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,39 @@ +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. + 2001-06-25 Jon Trowbridge * gui/component/e-address-popup.c: Add a huge steaming pile of diff --git a/addressbook/gui/contact-list-editor/contact-list-editor.glade b/addressbook/gui/contact-list-editor/contact-list-editor.glade index 56317384f3..51b7c1a877 100644 --- a/addressbook/gui/contact-list-editor/contact-list-editor.glade +++ b/addressbook/gui/contact-list-editor/contact-list-editor.glade @@ -41,7 +41,7 @@ table1 13 6 - 4 + 3 False 5 5 @@ -55,8 +55,8 @@ 0 Sat, 23 Jun 2001 06:00:16 GMT - 1 - 3 + 0 + 2 4 6 0 @@ -79,8 +79,8 @@ 0 - 1 - 3 + 0 + 2 3 4 0 @@ -105,8 +105,8 @@ 0 0 - 1 - 3 + 0 + 2 2 3 0 @@ -121,20 +121,13 @@ - GtkLabel - label2 - - GTK_JUSTIFY_LEFT - False - 0 - 0.5 - 0 - 0 + GtkHSeparator + hseparator1 - 1 - 2 - 0 - 1 + 0 + 3 + 1 + 2 0 0 False @@ -142,48 +135,20 @@ False False True - False + True - GtkEntry - list-name-entry - True - True - True - 0 - + GtkVBox + vbox1 + False + 0 2 3 - 0 - 1 - 0 - 0 - True - False - False - False - True - False - - - - - GtkVButtonBox - vbuttonbox2 - GTK_BUTTONBOX_START - 10 - 85 - 27 - 7 - 0 - - 3 - 4 4 - 6 + 5 0 0 False @@ -197,44 +162,25 @@ GtkButton remove-button - True True GTK_RELIEF_NORMAL + + 0 + False + False + - GtkHSeparator - hseparator1 - - 1 - 4 - 1 - 2 - 0 - 0 - False - False - False - False - True - True - - - - - GtkVButtonBox - vbuttonbox3 - GTK_BUTTONBOX_DEFAULT_STYLE - 10 - 85 - 27 - 0 - 0 + GtkVBox + vbox2 + False + 0 - 3 - 4 + 2 + 3 3 4 0 @@ -250,26 +196,27 @@ GtkButton add-email-button - True True GTK_RELIEF_NORMAL + + 0 + False + False + - Custom - custom2 - e_create_image_widget - evolution-contacts-plain.png - 0 - 0 - Sat, 23 Jun 2001 05:59:21 GMT + GtkHBox + hbox1 + False + 0 0 - 1 + 2 0 - 6 + 1 0 0 False @@ -279,6 +226,53 @@ True True + + + Custom + custom3 + e_create_image_widget + evolution-contacts-plain.png + 0 + 0 + Sat, 23 Jun 2001 05:59:21 GMT + + 0 + False + True + + + + + GtkLabel + label3 + + GTK_JUSTIFY_LEFT + False + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + list-name-entry + True + True + True + 0 + + + 0 + True + True + + diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.c b/addressbook/gui/contact-list-editor/e-contact-list-editor.c index f95cb936af..06a3473baa 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c +++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* e-contact-list-editor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Toshok + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Toshok * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -45,15 +45,35 @@ static void e_contact_list_editor_destroy (GtkObject *object); static void create_ui (EContactListEditor *ce); static void set_editable (EContactListEditor *editor); static void command_state_changed (EContactListEditor *editor); +static void close_dialog (EContactListEditor *cle); static void add_email_cb (GtkWidget *w, EContactListEditor *editor); static void remove_entry_cb (GtkWidget *w, EContactListEditor *editor); static void list_name_changed_cb (GtkWidget *w, EContactListEditor *editor); +static gint app_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data); +static gboolean table_drag_drop_cb (ETable *table, int row, int col, GdkDragContext *context, + gint x, gint y, guint time, EContactListEditor *editor); +static gboolean table_drag_motion_cb (ETable *table, int row, int col, GdkDragContext *context, + gint x, gint y, guint time, EContactListEditor *editor); +static void table_drag_data_received_cb (ETable *table, int row, int col, + GdkDragContext *context, + gint x, gint y, + GtkSelectionData *selection_data, guint info, guint time, + EContactListEditor *editor); static GtkObjectClass *parent_class = NULL; static guint contact_list_editor_signals[LAST_SIGNAL]; +enum DndTargetType { + DND_TARGET_TYPE_VCARD, +}; +#define VCARD_TYPE "text/x-vcard" +static GtkTargetEntry drag_types[] = { + { VCARD_TYPE, 0, DND_TARGET_TYPE_VCARD }, +}; +static const int num_drag_types = sizeof (drag_types) / sizeof (drag_types[0]); + /* The arguments we take */ enum { ARG_0, @@ -236,14 +256,22 @@ e_contact_list_editor_init (EContactListEditor *editor) gtk_signal_connect (GTK_OBJECT(editor->list_name_entry), "changed", GTK_SIGNAL_FUNC(list_name_changed_cb), editor); + e_table_drag_dest_set (e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table)), + 0, drag_types, num_drag_types, GDK_ACTION_LINK); + + gtk_signal_connect (GTK_OBJECT(e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table))), + "table_drag_motion", GTK_SIGNAL_FUNC(table_drag_motion_cb), editor); + gtk_signal_connect (GTK_OBJECT(e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table))), + "table_drag_drop", GTK_SIGNAL_FUNC(table_drag_drop_cb), editor); + gtk_signal_connect (GTK_OBJECT(e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table))), + "table_drag_data_received", GTK_SIGNAL_FUNC(table_drag_data_received_cb), editor); + command_state_changed (editor); /* Connect to the deletion of the dialog */ -#if 0 gtk_signal_connect (GTK_OBJECT (editor->app), "delete_event", GTK_SIGNAL_FUNC (app_delete_event_cb), editor); -#endif } static void @@ -251,6 +279,16 @@ e_contact_list_editor_destroy (GtkObject *object) { } +/* File/Close callback */ +static void +file_close_cb (GtkWidget *widget, gpointer data) +{ + EContactListEditor *cle; + + cle = E_CONTACT_LIST_EDITOR (data); + close_dialog (cle); +} + static BonoboUIVerb verbs [] = { #if 0 @@ -260,11 +298,8 @@ BonoboUIVerb verbs [] = { BONOBO_UI_UNSAFE_VERB ("ContactEditorSendAs", file_send_as_cb), BONOBO_UI_UNSAFE_VERB ("ContactEditorSendTo", file_send_to_cb), BONOBO_UI_UNSAFE_VERB ("ContactEditorDelete", delete_cb), - BONOBO_UI_UNSAFE_VERB ("ContactEditorPrint", print_cb), - BONOBO_UI_UNSAFE_VERB ("ContactEditorPrintEnvelope", print_envelope_cb), - /* BONOBO_UI_UNSAFE_VERB ("ContactEditorPageSetup", file_page_setup_menu), */ - BONOBO_UI_UNSAFE_VERB ("ContactEditorClose", file_close_cb), -#endif +#endif + BONOBO_UI_UNSAFE_VERB ("ContactListEditorClose", file_close_cb), BONOBO_UI_VERB_END }; @@ -479,6 +514,97 @@ set_editable (EContactListEditor *editor) gtk_widget_set_sensitive (editor->table, editor->editable); } +/* Closes the dialog box and emits the appropriate signals */ +static void +close_dialog (EContactListEditor *cle) +{ + g_assert (cle->app != NULL); + + gtk_widget_destroy (cle->app); + cle->app = NULL; + + gtk_signal_emit (GTK_OBJECT (cle), contact_list_editor_signals[EDITOR_CLOSED]); +} + +/* Callback used when the editor is destroyed */ +static gint +app_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) +{ + EContactListEditor *ce; + + ce = E_CONTACT_LIST_EDITOR (data); + + close_dialog (ce); + return TRUE; +} + +static gboolean +table_drag_motion_cb (ETable *table, int row, int col, + GdkDragContext *context, + gint x, gint y, guint time, EContactListEditor *editor) +{ + GList *p; + + for (p = context->targets; p != NULL; p = p->next) { + char *possible_type; + + possible_type = gdk_atom_name ((GdkAtom) p->data); + if (!strcmp (possible_type, VCARD_TYPE)) { + g_free (possible_type); + gdk_drag_status (context, GDK_ACTION_LINK, time); + return TRUE; + } + + g_free (possible_type); + } + + return FALSE; +} + +static gboolean +table_drag_drop_cb (ETable *table, int row, int col, + GdkDragContext *context, + gint x, gint y, guint time, EContactListEditor *editor) +{ + if (context->targets != NULL) { + gtk_drag_get_data (GTK_WIDGET (table), context, + GPOINTER_TO_INT (context->targets->data), + time); + return TRUE; + } + + return FALSE; +} + +static void +table_drag_data_received_cb (ETable *table, int row, int col, + GdkDragContext *context, + gint x, gint y, + GtkSelectionData *selection_data, + guint info, guint time, EContactListEditor *editor) +{ + char *target_type; + + target_type = gdk_atom_name (selection_data->target); + + if (!strcmp (target_type, VCARD_TYPE)) { + GList *card_list = e_card_load_cards_from_string (selection_data->data); + GList *c; + + for (c = card_list; c; c = c->next) { + ECard *ecard = c->data; + ECardSimple *simple = e_card_simple_new (ecard); + + e_contact_list_model_add_card (E_CONTACT_LIST_MODEL (editor->model), + simple); + + gtk_object_unref (GTK_OBJECT (simple)); + } + g_list_foreach (card_list, (GFunc)gtk_object_unref, NULL); + g_list_free (card_list); + } +} + static void command_state_changed (EContactListEditor *editor) { diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.h b/addressbook/gui/contact-list-editor/e-contact-list-editor.h index 55badc3016..c697275f43 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-editor.h +++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.h @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* e-contact-list-editor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Toshok + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Toshok * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as 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 --; } diff --git a/addressbook/gui/contact-list-editor/e-contact-list-model.h b/addressbook/gui/contact-list-editor/e-contact-list-model.h index da9be77b49..8665245501 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-model.h +++ b/addressbook/gui/contact-list-editor/e-contact-list-model.h @@ -16,13 +16,20 @@ typedef struct _EContactListModel EContactListModel; typedef struct _EContactListModelClass EContactListModelClass; +typedef struct { + ECardSimple *simple; + char *string; +} SimpleAndString; + struct _EContactListModel { ETableModel parent; - ECardSimple **simples; + SimpleAndString **simples; int simple_count; + int simple_alloc; char **emails; int email_count; + int email_alloc; }; -- cgit v1.2.3