From 5ea91bd94b21b27d83d0f6b14d64ce8c0df88acf Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 1 Jun 2000 22:29:10 +0000 Subject: return TRUE if opening a contact editor so that we don't get a "new 2000-06-01 Christopher James Lahey * gui/minicard/e-minicard.c: return TRUE if opening a contact editor so that we don't get a "new dialog" contact editor. svn path=/trunk/; revision=3342 --- addressbook/ChangeLog | 5 + addressbook/gui/component/Makefile.am | 4 + addressbook/gui/component/addressbook.c | 2 + addressbook/gui/component/e-cardlist-model.c | 29 ++- addressbook/gui/component/e-cardlist-model.h | 21 +- addressbook/gui/component/e-select-names.c | 289 +++++++++++++++++++++++++++ addressbook/gui/component/e-select-names.h | 82 ++++++++ addressbook/gui/minicard/e-minicard-view.c | 7 +- addressbook/gui/minicard/e-minicard.c | 1 + addressbook/gui/widgets/e-minicard-view.c | 7 +- addressbook/gui/widgets/e-minicard.c | 1 + 11 files changed, 420 insertions(+), 28 deletions(-) create mode 100644 addressbook/gui/component/e-select-names.c create mode 100644 addressbook/gui/component/e-select-names.h diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 458236ad84..3932596639 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,8 @@ +2000-06-01 Christopher James Lahey + + * gui/minicard/e-minicard.c: return TRUE if opening a contact + editor so that we don't get a "new dialog" contact editor. + 2000-06-01 Ettore Perazzoli * gui/component/addressbook.c (new_contact_cb): Use the stock diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am index 370265e019..35939f8940 100644 --- a/addressbook/gui/component/Makefile.am +++ b/addressbook/gui/component/Makefile.am @@ -30,6 +30,10 @@ evolution_addressbook_SOURCES = \ e-ldap-server-dialog.h \ e-addressbook-model.c \ e-addressbook-model.h \ + e-cardlist-model.c \ + e-cardlist-model.h \ + e-select-names.c \ + e-select-names.h \ addressbook-component.c \ addressbook-component.h \ addressbook-factory.c \ diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 42ca9dca78..779b4bc147 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -710,6 +710,8 @@ create_alphabet (AddressbookView *view) for (letter = 'a'; letter <= 'z'; letter ++) { connect_button(view, gui, letter); } + + gtk_object_unref(GTK_OBJECT(gui)); return widget; } diff --git a/addressbook/gui/component/e-cardlist-model.c b/addressbook/gui/component/e-cardlist-model.c index 1bc9bb4c2b..eb6793ec6f 100644 --- a/addressbook/gui/component/e-cardlist-model.c +++ b/addressbook/gui/component/e-cardlist-model.c @@ -116,22 +116,31 @@ addressbook_thaw (ETableModel *etc) } void -add_card(ECardlistModel *model, - ECard **cards, - int count) +e_cardlist_model_add(ECardlistModel *model, + ECard **cards, + int count) { int i; model->data = g_realloc(model->data, model->data_count + count * sizeof(ECard *)); for (i = 0; i < count; i++) { - gtk_object_ref(GTK_OBJECT(cards[i])); - model->data[model->data_count++] = e_card_simple_new (cards[i]); - e_table_model_row_inserted(E_TABLE_MODEL(model), model->data_count - 1); + gboolean found = FALSE; + gchar *id = e_card_get_id(cards[i]); + for ( i = 0; i < model->data_count; i++) { + if ( !strcmp(e_card_simple_get_id(model->data[i]), id) ) { + found = TRUE; + } + } + if (!found) { + gtk_object_ref(GTK_OBJECT(cards[i])); + model->data[model->data_count++] = e_card_simple_new (cards[i]); + e_table_model_row_inserted(E_TABLE_MODEL(model), model->data_count - 1); + } } } void -remove_card(ECardlistModel *model, - const char *id) +e_cardlist_model_remove(ECardlistModel *model, + const char *id) { int i; for ( i = 0; i < model->data_count; i++) { @@ -171,8 +180,8 @@ e_cardlist_model_init (GtkObject *object) } ECard * -e_cardlist_model_get_card(ECardlistModel *model, - int row) +e_cardlist_model_get(ECardlistModel *model, + int row) { if (model->data && row < model->data_count) { ECard *card; diff --git a/addressbook/gui/component/e-cardlist-model.h b/addressbook/gui/component/e-cardlist-model.h index 4a04bbf225..b7df356342 100644 --- a/addressbook/gui/component/e-cardlist-model.h +++ b/addressbook/gui/component/e-cardlist-model.h @@ -13,13 +13,6 @@ #define E_IS_CARDLIST_MODEL(o) (GTK_CHECK_TYPE ((o), E_CARDLIST_MODEL_TYPE)) #define E_IS_CARDLIST_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CARDLIST_MODEL_TYPE)) -/* Virtual Column list: - 0 Email - 1 Full Name - 2 Street - 3 Phone -*/ - typedef struct { ETableModel parent; @@ -38,12 +31,12 @@ GtkType e_cardlist_model_get_type (void); ETableModel *e_cardlist_model_new (void); /* Returns object with an extra ref count. */ -ECard *e_cardlist_model_get_card(ECardlistModel *model, - int row); -void add_card (ECardlistModel *model, - ECard **card, - int count); -void remove_card (ECardlistModel *model, - const char *id); +ECard *e_cardlist_model_get (ECardlistModel *model, + int row); +void e_cardlist_model_add (ECardlistModel *model, + ECard **card, + int count); +void e_cardlist_model_remove (ECardlistModel *model, + const char *id); #endif /* _E_CARDLIST_MODEL_H_ */ diff --git a/addressbook/gui/component/e-select-names.c b/addressbook/gui/component/e-select-names.c new file mode 100644 index 0000000000..986a1102af --- /dev/null +++ b/addressbook/gui/component/e-select-names.c @@ -0,0 +1,289 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-select-names.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include "e-select-names.h" +#include +#include +#include +#include +#include +#include + +static void e_select_names_init (ESelectNames *card); +static void e_select_names_class_init (ESelectNamesClass *klass); +static void e_select_names_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_select_names_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static void e_select_names_destroy (GtkObject *object); + +static GnomeDialogClass *parent_class = NULL; + +/* The arguments we take */ +enum { + ARG_0, + ARG_BOOK, + ARG_QUERY, +}; + +typedef struct { + char *title; + ETableModel *model; +} ESelectNamesChild; + +GtkType +e_select_names_get_type (void) +{ + static GtkType type = 0; + + if (!type) { + static const GtkTypeInfo info = + { + "ESelectNames", + sizeof (ESelectNames), + sizeof (ESelectNamesClass), + (GtkClassInitFunc) e_select_names_class_init, + (GtkObjectInitFunc) e_select_names_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + type = gtk_type_unique (gtk_vbox_get_type (), &info); + } + + return type; +} + +static void +e_select_names_class_init (ESelectNamesClass *klass) +{ + GtkObjectClass *object_class; + + object_class = (GtkObjectClass*) klass; + + parent_class = gtk_type_class (gnome_dialog_get_type ()); + + gtk_object_add_arg_type ("EAddressbookModel::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); + gtk_object_add_arg_type ("EAddressbookModel::query", GTK_TYPE_STRING, + GTK_ARG_READWRITE, ARG_QUERY); + + object_class->set_arg = e_select_names_set_arg; + object_class->get_arg = e_select_names_get_arg; + object_class->destroy = e_select_names_destroy; +} + +#define SPEC " \ + \ + 0 \ + \ + \ +" + +GtkWidget *e_addressbook_create_ebook_table(char *name, char *string1, char *string2, int num1, int num2); + +static void +set_book(EBook *book, EBookStatus status, ETableModel *model) +{ + gtk_object_set(GTK_OBJECT(model), + "book", book, + NULL); + gtk_object_unref(GTK_OBJECT(model)); + gtk_object_unref(GTK_OBJECT(book)); +} + +GtkWidget * +e_addressbook_create_ebook_table(char *name, char *string1, char *string2, int num1, int num2) +{ + ETableModel *model; + ETableHeader *header; + ECell *cell_left_just; + EBook *book; + char *filename; + char *uri; + + model = e_addressbook_model_new(); + cell_left_just = e_cell_text_new (model, NULL, GTK_JUSTIFY_LEFT); + + header = e_table_header_new (); + e_table_header_add_column (header, e_table_col_new (0, "Full Name", 1.0, 20, cell_left_just, + g_str_compare, TRUE), 0); + + book = e_book_new(); + gtk_object_ref(GTK_OBJECT(model)); + gtk_object_ref(GTK_OBJECT(book)); + filename = gnome_util_prepend_user_home("evolution/local/Contacts/addressbook.db"); + uri = g_strdup_printf("file://%s", filename); + e_book_load_uri(book, uri, (EBookCallback) set_book, model); + g_free(uri); + g_free(filename); + return e_table_new (header, model, SPEC); +} + +static void +e_select_names_init (ESelectNames *e_select_names) +{ + GladeXML *gui; + GtkWidget *widget; + + gui = glade_xml_new (EVOLUTION_GLADEDIR "/select-names.glade", NULL); + e_select_names->gui = gui; + + e_select_names->children = g_hash_table_new(g_str_hash, g_str_equal); + e_select_names->child_count = 0; + + widget = glade_xml_get_widget(gui, "table-top"); + if (!widget) { + return; + } + gtk_widget_reparent(widget, + GTK_WIDGET(e_select_names)); + + gnome_dialog_append_buttons(GNOME_DIALOG(e_select_names), + GNOME_STOCK_BUTTON_OK, + GNOME_STOCK_BUTTON_CANCEL, + NULL); + +#if 0 + widget = glade_xml_get_widget(e_select_names->gui, "button-fullname"); + if (widget && GTK_IS_BUTTON(widget)) + gtk_signal_connect(GTK_OBJECT(widget), "clicked", + full_name_clicked, e_select_names); + + widget = glade_xml_get_widget(e_select_names->gui, "button-categories"); + if (widget && GTK_IS_BUTTON(widget)) + gtk_signal_connect(GTK_OBJECT(widget), "clicked", + categories_clicked, e_select_names); +#endif +} + +static void e_select_names_child_free(char *key, ESelectNamesChild *child, ESelectNames *e_select_names) +{ + g_free(child->title); + gtk_object_unref(GTK_OBJECT(child->model)); + g_free(key); +} + +void +e_select_names_destroy (GtkObject *object) { + ESelectNames *e_select_names = E_SELECT_NAMES(object); + + gtk_object_unref(GTK_OBJECT(e_select_names->gui)); + g_hash_table_foreach(e_select_names->children, (GHFunc) e_select_names_child_free, e_select_names); + g_hash_table_destroy(e_select_names->children); +} + +GtkWidget* +e_select_names_new (void) +{ + GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_select_names_get_type ())); + return widget; +} + +static void +e_select_names_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + ESelectNames *editor; + + editor = E_SELECT_NAMES (o); + + switch (arg_id){ + default: + return; + } +} + +static void +e_select_names_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + ESelectNames *e_select_names; + + e_select_names = E_SELECT_NAMES (object); + + switch (arg_id) { + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +void +e_select_names_add_section(ESelectNames *e_select_names, char *name, char *id) +{ + ESelectNamesChild *child; + GtkWidget *button; + GtkWidget *alignment; + GtkTable *table; + char *label; + + ETableModel *model; + GtkWidget *etable; + ETableHeader *header; + ECell *cell_left_just; + + if (g_hash_table_lookup(e_select_names->children, id)) { + return; + } + + table = GTK_TABLE(glade_xml_get_widget (e_select_names->gui, "recipient-table")); + + child = g_new(ESelectNamesChild, 1); + + e_select_names->child_count++; + + alignment = gtk_alignment_new(0, 0, 1, 0); + label = g_strdup_printf("%s ->", _(name)); + button = gtk_button_new_with_label(label); + g_free(label); + gtk_container_add(GTK_CONTAINER(alignment), button); + gtk_widget_show_all(alignment); + gtk_table_attach(table, alignment, + 0, 1, + e_select_names->child_count, + e_select_names->child_count + 1, + GTK_FILL, GTK_FILL, + 0, 0); + + model = e_cardlist_model_new(); + header = e_table_header_new (); + cell_left_just = e_cell_text_new (model, NULL, GTK_JUSTIFY_LEFT); + e_table_header_add_column (header, e_table_col_new (0, "Full Name", 1.0, 20, cell_left_just, + g_str_compare, TRUE), 0); + etable = e_table_new (header, model, SPEC); + + child->model = model; + gtk_object_ref(GTK_OBJECT(child->model)); + + gtk_table_attach(table, etable, + 1, 2, + e_select_names->child_count, + e_select_names->child_count + 1, + GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, + 0, 0); +} + +ECardList * +e_select_names_get_section(ESelectNames *e_select_names, char *id) +{ + + return NULL; +} diff --git a/addressbook/gui/component/e-select-names.h b/addressbook/gui/component/e-select-names.h new file mode 100644 index 0000000000..4356180694 --- /dev/null +++ b/addressbook/gui/component/e-select-names.h @@ -0,0 +1,82 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-select-names.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_SELECT_NAMES_H__ +#define __E_SELECT_NAMES_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* ESelectNames - A dialog displaying information about a contact. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + */ + +#define E_SELECT_NAMES_TYPE (e_select_names_get_type ()) +#define E_SELECT_NAMES(obj) (GTK_CHECK_CAST ((obj), E_SELECT_NAMES_TYPE, ESelectNames)) +#define E_SELECT_NAMES_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_SELECT_NAMES_TYPE, ESelectNamesClass)) +#define E_IS_SELECT_NAMES(obj) (GTK_CHECK_TYPE ((obj), E_SELECT_NAMES_TYPE)) +#define E_IS_SELECT_NAMES_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_SELECT_NAMES_TYPE)) + + +typedef struct _ESelectNames ESelectNames; +typedef struct _ESelectNamesClass ESelectNamesClass; + +struct _ESelectNames +{ + GnomeDialog parent; + + /* item specific fields */ + GladeXML *gui; + + GHashTable *children; /* Of type char * to ESelectNamesChild */ + int child_count; +}; + +struct _ESelectNamesClass +{ + GnomeDialogClass parent_class; +}; + + +GtkWidget *e_select_names_new (void); +GtkType e_select_names_get_type (void); +void e_select_names_add_section (ESelectNames *e_select_names, + char *name, + char *id); +/* Returns a ref counted list of addresses. */ +ECardList *e_select_names_get_section (ESelectNames *e_select_names, + char *id); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_SELECT_NAMES_H__ */ diff --git a/addressbook/gui/minicard/e-minicard-view.c b/addressbook/gui/minicard/e-minicard-view.c index 73463866f4..2243f91b80 100644 --- a/addressbook/gui/minicard/e-minicard-view.c +++ b/addressbook/gui/minicard/e-minicard-view.c @@ -328,9 +328,12 @@ e_minicard_view_event (GnomeCanvasItem *item, GdkEvent *event) NULL); } } - return FALSE; - default: return TRUE; + default: + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) + return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); + else + return FALSE; break; } } diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c index 834bd3a0b0..1510c34205 100644 --- a/addressbook/gui/minicard/e-minicard.c +++ b/addressbook/gui/minicard/e-minicard.c @@ -423,6 +423,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) card_changed_cb, NULL); } + return TRUE; } break; case GDK_KEY_PRESS: diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c index 73463866f4..2243f91b80 100644 --- a/addressbook/gui/widgets/e-minicard-view.c +++ b/addressbook/gui/widgets/e-minicard-view.c @@ -328,9 +328,12 @@ e_minicard_view_event (GnomeCanvasItem *item, GdkEvent *event) NULL); } } - return FALSE; - default: return TRUE; + default: + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) + return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); + else + return FALSE; break; } } diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 834bd3a0b0..1510c34205 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -423,6 +423,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) card_changed_cb, NULL); } + return TRUE; } break; case GDK_KEY_PRESS: -- cgit v1.2.3