diff options
Diffstat (limited to 'addressbook/gui/widgets')
-rw-r--r-- | addressbook/gui/widgets/Makefile.am | 41 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.c | 239 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.h | 79 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.c | 216 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.h | 13 | ||||
-rw-r--r-- | addressbook/gui/widgets/test-minicard-view.c | 206 | ||||
-rw-r--r-- | addressbook/gui/widgets/test-reflow.c | 28 |
7 files changed, 716 insertions, 106 deletions
diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index e1b130bc2a..3534e9cb69 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = \ + -I$(top_srcdir)/addressbook/backend/ebook \ -I$(top_srcdir)/widgets/e-text \ -I$(top_srcdir)/e-util \ - -I$(top_srcdir)/widgets/e-table \ $(GNOME_INCLUDEDIR) noinst_LIBRARIES = \ @@ -12,40 +12,65 @@ libeminicard_a_SOURCES = \ e-minicard.h \ e-minicard-label.c \ e-minicard-label.h \ + e-minicard-view.c \ + e-minicard-view.h \ + e-reflow-sorted.c \ + e-reflow-sorted.h \ e-reflow.c \ e-reflow.h noinst_PROGRAMS = \ minicard-label-test \ minicard-test \ - reflow-test + reflow-test \ + minicard-view-test minicard_label_test_SOURCES = \ test-minicard-label.c minicard_label_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ + $(GNOMEGNORBA_LIBS) \ libeminicard.a \ + -lbonobo \ $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/e-table/libetable.a + $(top_builddir)/widgets/e-text/libetext.a minicard_test_SOURCES = \ test-minicard.c minicard_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ + $(GNOMEGNORBA_LIBS) \ libeminicard.a \ + -lbonobo \ $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/e-table/libetable.a + $(top_builddir)/addressbook/backend/ebook/libebook.la \ + $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/widgets/e-text/libetext.a reflow_test_SOURCES = \ test-reflow.c reflow_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ + $(GNOMEGNORBA_LIBS) \ libeminicard.a \ + -lbonobo \ $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/e-table/libetable.a + $(top_builddir)/addressbook/backend/ebook/libebook.la \ + $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/widgets/e-text/libetext.a + +minicard_view_test_SOURCES = \ + test-minicard-view.c + +minicard_view_test_LDADD = \ + $(EXTRA_GNOME_LIBS) \ + $(GNOMEGNORBA_LIBS) \ + libeminicard.a \ + -lbonobo \ + $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/addressbook/backend/ebook/libebook.la \ + $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/widgets/e-text/libetext.a diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c new file mode 100644 index 0000000000..6e7b432a8e --- /dev/null +++ b/addressbook/gui/widgets/e-minicard-view.c @@ -0,0 +1,239 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-minicard-view.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * 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 <config.h> +#include <gnome.h> +#include "e-minicard-view.h" +#include "e-minicard.h" +static void e_minicard_view_init (EMinicardView *reflow); +static void e_minicard_view_class_init (EMinicardViewClass *klass); +static void e_minicard_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_minicard_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static void e_minicard_view_destroy (GtkObject *object); + +#define E_MINICARD_VIEW_DIVIDER_WIDTH 2 +#define E_MINICARD_VIEW_BORDER_WIDTH 7 +#define E_MINICARD_VIEW_FULL_GUTTER (E_MINICARD_VIEW_DIVIDER_WIDTH + E_MINICARD_VIEW_BORDER_WIDTH * 2) + +static EReflowSortedClass *parent_class = NULL; + +/* The arguments we take */ +enum { + ARG_0, + ARG_BOOK +}; + +GtkType +e_minicard_view_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EMinicardView", + sizeof (EMinicardView), + sizeof (EMinicardViewClass), + (GtkClassInitFunc) e_minicard_view_class_init, + (GtkObjectInitFunc) e_minicard_view_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (e_reflow_sorted_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_minicard_view_class_init (EMinicardViewClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (e_reflow_sorted_get_type ()); + +gtk_object_add_arg_type ("EMinicardView::book", GTK_TYPE_OBJECT, + GTK_ARG_READWRITE, ARG_BOOK); + + object_class->set_arg = e_minicard_view_set_arg; + object_class->get_arg = e_minicard_view_get_arg; + object_class->destroy = e_minicard_view_destroy; + + /* GnomeCanvasItem method overrides */ +} + +static void +e_minicard_view_init (EMinicardView *view) +{ + view->book = NULL; + view->book_view = NULL; + view->get_view_idle = 0; + view->create_card_id = 0; + view->remove_card_id = 0; + view->modify_card_id = 0; + + E_REFLOW_SORTED(view)->compare_func = (GCompareFunc) e_minicard_compare; + E_REFLOW_SORTED(view)->string_func = (EReflowStringFunc) e_minicard_get_card_id; +} + +static void +create_card(EBookView *book_view, const GList *cards, EMinicardView *view) +{ + for (; cards; cards = g_list_next(cards)) { + GnomeCanvasItem *item = gnome_canvas_item_new(GNOME_CANVAS_GROUP(view), + e_minicard_get_type(), + "card", cards->data, + NULL); + e_reflow_add_item(E_REFLOW(view), item); + } +} + +static void +modify_card(EBookView *book_view, const GList *cards, EMinicardView *view) +{ + for (; cards; cards = g_list_next(cards)) { + GnomeCanvasItem *item = gnome_canvas_item_new(GNOME_CANVAS_GROUP(view), + e_minicard_get_type(), + "card", cards->data, + NULL); + e_reflow_sorted_replace_item(E_REFLOW_SORTED(view), item); + } +} + +static void +remove_card(EBookView *book_view, const char *id, EMinicardView *view) +{ + e_reflow_sorted_remove_item(E_REFLOW_SORTED(view), id); +} + +static void +book_view_loaded (EBook *book, EBookStatus status, EBookView *book_view, gpointer closure) +{ + EMinicardView *view = closure; + if (view->book_view && view->create_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->create_card_id); + if (view->book_view && view->remove_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->remove_card_id); + if (view->book_view && view->modify_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->modify_card_id); + if (view->book_view) + gtk_object_unref(GTK_OBJECT(view->book_view)); + view->book_view = book_view; + if (view->book_view) + gtk_object_ref(GTK_OBJECT(view->book_view)); + view->create_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view), + "card_added", + GTK_SIGNAL_FUNC(create_card), + view); + view->remove_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view), + "card_removed", + GTK_SIGNAL_FUNC(remove_card), + view); + view->modify_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view), + "card_changed", + GTK_SIGNAL_FUNC(modify_card), + view); + g_list_foreach(E_REFLOW(view)->items, (GFunc) gtk_object_destroy, NULL); + g_list_free(E_REFLOW(view)->items); +} + +static gboolean +get_view(EMinicardView *view) +{ + E_REFLOW(view)->items = NULL; + e_book_get_book_view(view->book, "", book_view_loaded, view); + + view->get_view_idle = 0; + return FALSE; +} + +static void +e_minicard_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EMinicardView *view; + + item = GNOME_CANVAS_ITEM (o); + view = E_MINICARD_VIEW (o); + + switch (arg_id){ + case ARG_BOOK: + if (view->book) + gtk_object_unref(GTK_OBJECT(view->book)); + view->book = E_BOOK(GTK_VALUE_OBJECT (*arg)); + if (view->book) { + gtk_object_ref(GTK_OBJECT(view->book)); + if (view->get_view_idle == 0) + g_idle_add((GSourceFunc)get_view, view); + } + break; + } +} + +static void +e_minicard_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EMinicardView *e_minicard_view; + + e_minicard_view = E_MINICARD_VIEW (object); + + switch (arg_id) { + case ARG_BOOK: + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard_view->book); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_minicard_view_destroy (GtkObject *object) +{ + EMinicardView *view = E_MINICARD_VIEW(object); + + if (view->get_view_idle) + g_source_remove(view->get_view_idle); + if (view->book) + gtk_object_unref(GTK_OBJECT(view->book)); + if (view->book_view && view->create_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->create_card_id); + if (view->book_view && view->remove_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->remove_card_id); + if (view->book_view && view->modify_card_id) + gtk_signal_disconnect(GTK_OBJECT (view->book_view), + view->modify_card_id); + if (view->book_view) + gtk_object_unref(GTK_OBJECT(view->book_view)); +} diff --git a/addressbook/gui/widgets/e-minicard-view.h b/addressbook/gui/widgets/e-minicard-view.h new file mode 100644 index 0000000000..a88e6c7dcb --- /dev/null +++ b/addressbook/gui/widgets/e-minicard-view.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-minicard-view.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * 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_MINICARD_VIEW_H__ +#define __E_MINICARD_VIEW_H__ + +#include <gnome.h> +#include "e-reflow-sorted.h" +#include "e-book.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EMinicardView - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * minimum_width double RW minimum width of the reflow. width >= minimum_width + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_MINICARD_VIEW_TYPE (e_minicard_view_get_type ()) +#define E_MINICARD_VIEW(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_VIEW_TYPE, EMinicardView)) +#define E_MINICARD_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_VIEW_TYPE, EMinicardViewClass)) +#define E_IS_MINICARD_VIEW(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_VIEW_TYPE)) +#define E_IS_MINICARD_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_VIEW_TYPE)) + + +typedef struct _EMinicardView EMinicardView; +typedef struct _EMinicardViewClass EMinicardViewClass; + +struct _EMinicardView +{ + EReflowSorted parent; + + /* item specific fields */ + EBook *book; + EBookView *book_view; + + int get_view_idle; + + int create_card_id, remove_card_id, modify_card_id; +}; + +struct _EMinicardViewClass +{ + EReflowSortedClass parent_class; +}; + +GtkType e_minicard_view_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_MINICARD_VIEW_H__ */ diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 2a98a574c7..02c7670df9 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -24,7 +24,7 @@ #include "e-minicard.h" #include "e-minicard-label.h" #include "e-text.h" -#include "e-table-text-model.h" +#include "e-book.h" #include "e-canvas.h" #include "e-util.h" #include "e-canvas-utils.h" @@ -49,9 +49,7 @@ enum { ARG_WIDTH, ARG_HEIGHT, ARG_HAS_FOCUS, - ARG_CARD, - ARG_MODEL, - ARG_ROW + ARG_CARD }; GtkType @@ -98,10 +96,6 @@ e_minicard_class_init (EMinicardClass *klass) GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); - gtk_object_add_arg_type ("EMinicard::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EMinicard::row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_ROW); object_class->set_arg = e_minicard_set_arg; object_class->get_arg = e_minicard_get_arg; @@ -123,8 +117,7 @@ e_minicard_init (EMinicard *minicard) minicard->height = 10; minicard->has_focus = FALSE; - minicard->model = NULL; - minicard->row = 0; + minicard->card = NULL; e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(minicard), e_minicard_reflow); } @@ -164,21 +157,11 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) e_canvas_item_grab_focus(item); break; case ARG_CARD: - /* e_minicard->card = GTK_VALUE_OBJECT (*arg); - _update_card(e_minicard); - gnome_canvas_item_request_update (item);*/ - break; - case ARG_MODEL: - if (e_minicard->model) - gtk_object_unref (e_minicard->model); - e_minicard->model = E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)); - if (e_minicard->model) - gtk_object_ref (e_minicard->model); - remodel(e_minicard); - e_canvas_item_request_reflow(item); - break; - case ARG_ROW: - e_minicard->row = GTK_VALUE_INT (*arg); + if (e_minicard->card) + gtk_object_unref (GTK_OBJECT(e_minicard->card)); + e_minicard->card = E_CARD(GTK_VALUE_OBJECT (*arg)); + if (e_minicard->card) + gtk_object_ref (GTK_OBJECT(e_minicard->card)); remodel(e_minicard); e_canvas_item_request_reflow(item); break; @@ -203,13 +186,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: - /* GTK_VALUE_OBJECT (*arg) = e_minicard->card; */ - break; - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->model); - break; - case ARG_ROW: - GTK_VALUE_INT (*arg) = e_minicard->row; + GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->card); break; default: arg->type = GTK_TYPE_INVALID; @@ -227,8 +204,8 @@ e_minicard_destroy (GtkObject *object) e_minicard = E_MINICARD (object); - if (e_minicard->model) - gtk_object_unref (e_minicard->model); + if (e_minicard->card) + gtk_object_unref (GTK_OBJECT(e_minicard->card)); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); @@ -239,7 +216,6 @@ e_minicard_realize (GnomeCanvasItem *item) { EMinicard *e_minicard; GnomeCanvasGroup *group; - GnomeCanvasItem *new_item; e_minicard = E_MINICARD (item); group = GNOME_CANVAS_GROUP( item ); @@ -276,46 +252,10 @@ e_minicard_realize (GnomeCanvasItem *item) "use_ellipsis", TRUE, "font", "lucidasans-bold-10", "fill_color", "black", - "text", "Chris Lahey", + "text", "", NULL ); e_canvas_item_move_absolute(e_minicard->header_text, 6, 6); - new_item = e_minicard_label_new(group); - gnome_canvas_item_set( new_item, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@address.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - e_canvas_item_move_absolute(new_item, 2, e_minicard->height); - - new_item = e_minicard_label_new(group); - gnome_canvas_item_set( new_item, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - e_canvas_item_move_absolute(new_item, 2, e_minicard->height); - - new_item = e_minicard_label_new(group); - gnome_canvas_item_set( new_item, - "width", e_minicard->width - 4, - "fieldname", "Street Address:", - "field", "100 Main St\nHome town, USA", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - e_canvas_item_move_absolute(new_item, 2, e_minicard->height); - - new_item = e_minicard_label_new(group); - gnome_canvas_item_set( new_item, - "width", e_minicard->width - 4, - "fieldname", "Phone:", - "field", "000-0000", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - e_canvas_item_move_absolute(new_item, 2, e_minicard->height); - remodel(e_minicard); e_canvas_item_request_reflow(item); @@ -439,31 +379,92 @@ e_minicard_resize_children( EMinicard *e_minicard ) } static void -remodel( EMinicard *e_minicard ) +add_field (EMinicard *e_minicard, char *fieldname, char* field) { + GnomeCanvasItem *new_item; GnomeCanvasGroup *group; group = GNOME_CANVAS_GROUP( e_minicard ); - if ( e_minicard->model ) { - gint column = 0; - GList *list = e_minicard->fields; - ETableTextModel *model; - for ( ; list; list = list->next, column++ ) { - ETableTextModel *model = e_table_text_model_new(e_minicard->model, e_minicard->row, column); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data), - "text_model", model, - NULL); - gtk_object_sink(GTK_OBJECT(model)); + new_item = e_minicard_label_new(group); + gnome_canvas_item_set( new_item, + "width", e_minicard->width - 4.0, + "fieldname", fieldname, + "field", field, + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + e_canvas_item_move_absolute(new_item, 2, e_minicard->height); +} + + +static void +remodel( EMinicard *e_minicard ) +{ + if (e_minicard->card) { + char *fname; + ECardList *address_list; + ECardList *phone_list; + ECardList *email_list; + + ECardIterator *iterator; + + GList *list; + + for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { + gtk_object_destroy( GTK_OBJECT( list->data ) ); } - if ( e_minicard->header_text ) { - model = e_table_text_model_new(e_minicard->model, e_minicard->row, 1); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->header_text), - "model", model, - NULL); - gtk_object_sink(GTK_OBJECT(model)); + g_list_free(e_minicard->fields); + e_minicard->fields = NULL; + + gtk_object_get(GTK_OBJECT(e_minicard->card), + "full_name", &fname, + "address", &address_list, + "phone", &phone_list, + "email", &email_list, + NULL); + + if (fname) { + add_field(e_minicard, "Name:", fname); + if (e_minicard->header_text) + gnome_canvas_item_set(e_minicard->header_text, + "text", fname, + NULL); + } else + if (e_minicard->header_text) + gnome_canvas_item_set(e_minicard->header_text, + "text", "", + NULL); + 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 & ADDR_WORK) { + add_field(e_minicard, "Work Address:", address->city); + } else if (address->flags & 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)); + } } - } } @@ -513,3 +514,38 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags ) e_canvas_item_request_parent_reflow(item); } } + +char * +e_minicard_get_card_id (EMinicard *minicard) +{ + g_return_val_if_fail(minicard != NULL, NULL); + g_return_val_if_fail(E_IS_MINICARD(minicard), NULL); + + if (minicard->card) { + return e_card_get_id(minicard->card); + } else { + return NULL; + } +} + +int +e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2) +{ + g_return_val_if_fail(minicard1 != NULL, 0); + g_return_val_if_fail(E_IS_MINICARD(minicard1), 0); + g_return_val_if_fail(minicard2 != NULL, 0); + g_return_val_if_fail(E_IS_MINICARD(minicard2), 0); + + if (minicard1->card && minicard2->card) { + char *fname1, *fname2; + gtk_object_get(GTK_OBJECT(minicard1->card), + "full_name", &fname1, + NULL); + gtk_object_get(GTK_OBJECT(minicard2->card), + "full_name", &fname2, + NULL); + return strcmp(fname1, fname2); + } else { + return 0; + } +} diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h index 05d95a743e..85481d586e 100644 --- a/addressbook/gui/widgets/e-minicard.h +++ b/addressbook/gui/widgets/e-minicard.h @@ -22,7 +22,7 @@ #define __E_MINICARD_H__ #include <gnome.h> -#include "e-table-model.h" +#include "e-card.h" #ifdef __cplusplus extern "C" { @@ -37,10 +37,6 @@ extern "C" { * -------------------------------------------------------------------------------- * width double RW width of the card * height double R height of the card - * model ETableModel RW model to read from - * row int RW ETableModel row to read from - * - * Later: * card ECard* RW Pointer to the ECard */ @@ -72,8 +68,7 @@ struct _EMinicard GnomeCanvasItem *header_text; GList *fields; /* Of type GnomeCanvasItem. */ - ETableModel *model; - int row; + ECard *card; guint needs_remodeling : 1; gboolean has_focus; @@ -90,7 +85,9 @@ struct _EMinicardClass }; -GtkType e_minicard_get_type (void); +GtkType e_minicard_get_type (void); +char *e_minicard_get_card_id (EMinicard *minicard); +int e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2); #ifdef __cplusplus } diff --git a/addressbook/gui/widgets/test-minicard-view.c b/addressbook/gui/widgets/test-minicard-view.c new file mode 100644 index 0000000000..d3ceff228e --- /dev/null +++ b/addressbook/gui/widgets/test-minicard-view.c @@ -0,0 +1,206 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* test-reflow.c + * + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This program 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, 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. + */ + +#include "config.h" + +#include <gnome.h> +#include <libgnorba/gnorba.h> +#include <bonobo.h> +#include "e-canvas.h" +#include "e-minicard-view.h" + +/* This is a horrible thing to do, but it is just a test. */ +GnomeCanvasItem *reflow; +GnomeCanvasItem *rect; +GtkAllocation last_alloc; + +CORBA_Environment ev; +CORBA_ORB orb; + +static void +init_bonobo (int argc, char **argv) +{ + + gnome_CORBA_init_with_popt_table ( + "Reflow Test", VERSION, + &argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev); + + orb = gnome_CORBA_ORB (); + + if (bonobo_init (orb, NULL, NULL) == FALSE) + g_error (_("Could not initialize Bonobo")); + +} + +static void destroy_callback(GtkWidget *app, gpointer data) +{ + exit(0); +} + +static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) +{ + double width; + last_alloc = *allocation; + gnome_canvas_item_set( reflow, + "height", (double) allocation->height, + NULL ); + gnome_canvas_item_set( reflow, + "minimum_width", (double) allocation->width, + NULL ); + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); +} + +static void resize(GnomeCanvas *canvas, gpointer data) +{ + double width; + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, last_alloc.width); + gnome_canvas_set_scroll_region(canvas , 0, 0, width, last_alloc.height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) last_alloc.height, + NULL ); +} + +#if 0 +static void about_callback( GtkWidget *widget, gpointer data ) +{ + + const gchar *authors[] = + { + "Christopher James Lahey <clahey@umich.edu>", + NULL + }; + + GtkWidget *about = + gnome_about_new ( _( "Reflow Test" ), VERSION, + _( "Copyright (C) 2000, Helix Code, Inc." ), + authors, + _( "This should test the reflow canvas item" ), + NULL); + gtk_widget_show (about); +} +#endif + +static void +book_open_cb (EBook *book, EBookStatus status, gpointer closure) +{ + if (status == E_BOOK_STATUS_SUCCESS) + gnome_canvas_item_set(reflow, + "book", book, + NULL); +} + +static guint +ebook_create (void) +{ + EBook *book; + + book = e_book_new (); + + if (!book) { + printf ("%s: %s(): Couldn't create EBook, bailing.\n", + __FILE__, + __FUNCTION__); + return FALSE; + } + + + if (! e_book_load_uri (book, "file:/tmp/test.db", book_open_cb, NULL)) { + printf ("error calling load_uri!\n"); + } + + + return FALSE; +} + +int main( int argc, char *argv[] ) +{ + GtkWidget *app; + GtkWidget *canvas; + GtkWidget *vbox; + GtkWidget *scrollbar; + + /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE);*/ + + CORBA_exception_init (&ev); + init_bonobo (argc, argv); + + app = gnome_app_new("Reflow Test", NULL); + + vbox = gtk_vbox_new(FALSE, 0); + + canvas = e_canvas_new(); + rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + e_minicard_view_get_type(), + "height", (double) 100, + "minimum_width", (double) 100, + NULL ); + gtk_signal_connect( GTK_OBJECT( canvas ), "reflow", + GTK_SIGNAL_FUNC( resize ), + ( gpointer ) app); + + gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), + 0, 0, + 100, 100 ); + + gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); + + scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); + + gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); + + gnome_app_set_contents( GNOME_APP( app ), vbox ); + + /* Connect the signals */ + gtk_signal_connect( GTK_OBJECT( app ), "destroy", + GTK_SIGNAL_FUNC( destroy_callback ), + ( gpointer ) app ); + + gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", + GTK_SIGNAL_FUNC( allocate_callback ), + ( gpointer ) app ); + + gtk_widget_show_all( app ); + gdk_window_set_back_pixmap( GTK_LAYOUT(canvas)->bin_window, NULL, FALSE); + + gtk_idle_add ((GtkFunction) ebook_create, NULL); + + bonobo_main (); + + /* Not reached. */ + return 0; +} diff --git a/addressbook/gui/widgets/test-reflow.c b/addressbook/gui/widgets/test-reflow.c index 8cedbaac28..64c2b89a37 100644 --- a/addressbook/gui/widgets/test-reflow.c +++ b/addressbook/gui/widgets/test-reflow.c @@ -16,6 +16,32 @@ */ +#define TEST_VCARD \ +"BEGIN:VCARD +" \ +"FN:Nat +" \ +"N:Friedman;Nat;D;Mr. +" \ +"BDAY:1977-08-06 +" \ +"TEL;WORK:617 679 1984 +" \ +"TEL;CELL:123 456 7890 +" \ +"EMAIL;INTERNET:nat@nat.org +" \ +"EMAIL;INTERNET:nat@helixcode.com +" \ +"ADR;WORK;POSTAL:P.O. Box 101;;;Any Town;CA;91921-1234; +" \ +"ADR;HOME;POSTAL;INTL:P.O. Box 202;;;Any Town 2;MI;12344-4321;USA +" \ +"END:VCARD +" \ +" +" + #include "config.h" @@ -127,8 +153,10 @@ int main( int argc, char *argv[] ) for ( i = 0; i < 200; i++ ) { GnomeCanvasItem *item; + ECard *card = e_card_new (TEST_VCARD); item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), e_minicard_get_type(), + "card", card, NULL); e_reflow_add_item(E_REFLOW(reflow), item); } |