Commit 934524b9 authored by Chris Toshok's avatar Chris Toshok Committed by Chris Toshok

MinicardViewModel -> ReflowAdapter name change. (get_card_list): same.

2001-05-15  Chris Toshok  <toshok@ximian.com>

	* gui/widgets/e-minicard-view.c (add_to_list): MinicardViewModel
	-> ReflowAdapter name change.
	(get_card_list): same.
	(e_minicard_view_drag_begin): same.
	(supported_fields_cb): model -> adapter.
	(adapter_changed): hook up signals and set the empty message on
	our adapter.
	(e_minicard_view_set_arg): add support for "adapter", and set
	model -> adapter.
	(e_minicard_view_get_arg): same.
	(disconnect_signals): no more status_message.
	(do_remove): track to use adapter.
	(e_minicard_view_class_init): add adapter arg, and remove
	status_message.
	(e_minicard_view_init): all the code here is in adapter_changed
	now.

	* gui/widgets/e-minicard-view.h (struct _EMinicardView):
	EMinicardViewModel -> EAddressbookReflowAdapter.
	(struct _EMinicardViewClass): get rid of status_message.

	* gui/widgets/e-minicard-view-widget.c
	(e_minicard_view_widget_class_init): remove the status_message
	signal.
	(e_minicard_view_widget_new): take the adapter as our argument,
	and store it away for when we create the view.
	(e_minicard_view_widget_realize): when we create the view just set
	the adapter field on it.  also, don't connect to status_message.

	* gui/widgets/e-minicard-view-widget.h (struct
	_EMinicardViewWidget): add our adapter here, so we can pass it
	into the view when we create it.
	(struct _EMinicardViewWidgetClass): remove status_message.

	* gui/widgets/e-addressbook-view.c (status_message): new function,
	no more propagating status messages!
	(e_addressbook_view_init): create our model and conenct to its
	status_message signal.
	(book_writable_cb): set "editable" on the model, not our object.
	(e_addressbook_view_set_arg): same, but with "book" and "query" as
	well.
	(create_minicard_view): create our reflow adapter and pass it to
	the minicard view widget.  also, call e_reflow_model_changed so
	it'll pick up any already present cards.
	(table_double_click): ADDRESSBOOK_MODEL -> TABLE_ADAPTER.
	(get_card_list_1): remove the cast, since we don't need it any
	longer.
	(table_right_click): ADDRESSBOOK_MODEL -> TABLE_ADAPTER.
	(table_drag_data_get): same.
	(create_table_view): create the table adapter, and use it as our
	ETableModel.
	(change_view_type): remove the status_message hook up and setting
	of query/book/editable.
	(e_addressbook_view_stop): just call e_addressbook_model_stop here
	instead of switching on the view type.

	* gui/widgets/e-addressbook-view.h (struct _EAddressbookView): add
	our EAddressbookModel.

	* gui/widgets/Makefile.am (libeminicard_a_SOURCES): add the
	adapter files, and remove e-minicard-view-model.[ch].

	* gui/widgets/e-minicard-view-model.[ch]: removed.

	* gui/widgets/e-addressbook-table-adapter.c: new file.

	* gui/widgets/e-addressbook-table-adapter.h: new file.

	* gui/widgets/e-addressbook-reflow-adapter.c: new file.

	* gui/widgets/e-addressbook-reflow-adapter.h: new file.

	* gui/widgets/e-addressbook-model.c: rework this class to now
	subclass from ETableModel anymore.  It not subclasses from
	GtkObject, and we use table and reflow adapters to get at the
	data.

	* gui/widgets/e-addressbook-model.h: same.

svn path=/trunk/; revision=9837
parent ad6072f8
2001-05-15 Chris Toshok <toshok@ximian.com>
* gui/widgets/e-minicard-view.c (add_to_list): MinicardViewModel
-> ReflowAdapter name change.
(get_card_list): same.
(e_minicard_view_drag_begin): same.
(supported_fields_cb): model -> adapter.
(adapter_changed): hook up signals and set the empty message on
our adapter.
(e_minicard_view_set_arg): add support for "adapter", and set
model -> adapter.
(e_minicard_view_get_arg): same.
(disconnect_signals): no more status_message.
(do_remove): track to use adapter.
(e_minicard_view_class_init): add adapter arg, and remove
status_message.
(e_minicard_view_init): all the code here is in adapter_changed
now.
* gui/widgets/e-minicard-view.h (struct _EMinicardView):
EMinicardViewModel -> EAddressbookReflowAdapter.
(struct _EMinicardViewClass): get rid of status_message.
* gui/widgets/e-minicard-view-widget.c
(e_minicard_view_widget_class_init): remove the status_message
signal.
(e_minicard_view_widget_new): take the adapter as our argument,
and store it away for when we create the view.
(e_minicard_view_widget_realize): when we create the view just set
the adapter field on it. also, don't connect to status_message.
* gui/widgets/e-minicard-view-widget.h (struct
_EMinicardViewWidget): add our adapter here, so we can pass it
into the view when we create it.
(struct _EMinicardViewWidgetClass): remove status_message.
* gui/widgets/e-addressbook-view.c (status_message): new function,
no more propagating status messages!
(e_addressbook_view_init): create our model and conenct to its
status_message signal.
(book_writable_cb): set "editable" on the model, not our object.
(e_addressbook_view_set_arg): same, but with "book" and "query" as
well.
(create_minicard_view): create our reflow adapter and pass it to
the minicard view widget. also, call e_reflow_model_changed so
it'll pick up any already present cards.
(table_double_click): ADDRESSBOOK_MODEL -> TABLE_ADAPTER.
(get_card_list_1): remove the cast, since we don't need it any
longer.
(table_right_click): ADDRESSBOOK_MODEL -> TABLE_ADAPTER.
(table_drag_data_get): same.
(create_table_view): create the table adapter, and use it as our
ETableModel.
(change_view_type): remove the status_message hook up and setting
of query/book/editable.
(e_addressbook_view_stop): just call e_addressbook_model_stop here
instead of switching on the view type.
* gui/widgets/e-addressbook-view.h (struct _EAddressbookView): add
our EAddressbookModel.
* gui/widgets/Makefile.am (libeminicard_a_SOURCES): add the
adapter files, and remove e-minicard-view-model.[ch].
* gui/widgets/e-minicard-view-model.[ch]: removed.
* gui/widgets/e-addressbook-table-adapter.c: new file.
* gui/widgets/e-addressbook-table-adapter.h: new file.
* gui/widgets/e-addressbook-reflow-adapter.c: new file.
* gui/widgets/e-addressbook-reflow-adapter.h: new file.
* gui/widgets/e-addressbook-model.c: rework this class to now
subclass from ETableModel anymore. It not subclasses from
GtkObject, and we use table and reflow adapters to get at the
data.
* gui/widgets/e-addressbook-model.h: same.
2001-05-14 Christopher James Lahey <clahey@ximian.com>
* gui/widgets/e-minicard-view-model.c (remove_card): Fix a small
......
......@@ -17,6 +17,10 @@ noinst_LIBRARIES = \
libeminicard.a
libeminicard_a_SOURCES = \
e-addressbook-reflow-adapter.c \
e-addressbook-reflow-adapter.h \
e-addressbook-table-adapter.c \
e-addressbook-table-adapter.h \
e-addressbook-model.c \
e-addressbook-model.h \
e-addressbook-view.c \
......@@ -27,8 +31,6 @@ libeminicard_a_SOURCES = \
e-minicard-label.h \
e-minicard-view-widget.c \
e-minicard-view-widget.h \
e-minicard-view-model.c \
e-minicard-view-model.h \
e-minicard-view.c \
e-minicard-view.h \
e-minicard-widget.c \
......
......@@ -14,8 +14,8 @@
#include <gnome-xml/xmlmemory.h>
#include <gnome.h>
#define PARENT_TYPE e_table_model_get_type()
ETableModelClass *parent_class;
#define PARENT_TYPE gtk_object_get_type()
GtkObjectClass *parent_class;
/*
* EAddressbookModel callbacks
......@@ -34,6 +34,10 @@ enum {
enum {
STATUS_MESSAGE,
CARD_ADDED,
CARD_REMOVED,
CARD_CHANGED,
MODEL_CHANGED,
LAST_SIGNAL
};
......@@ -88,129 +92,28 @@ addressbook_destroy(GtkObject *object)
g_free(model->data);
}
/* This function returns the number of columns in our ETableModel. */
static int
addressbook_col_count (ETableModel *etc)
{
return COLS;
}
/* This function returns the number of rows in our ETableModel. */
static int
addressbook_row_count (ETableModel *etc)
{
EAddressbookModel *addressbook = E_ADDRESSBOOK_MODEL(etc);
return addressbook->data_count;
}
/* This function returns the value at a particular point in our ETableModel. */
static void *
addressbook_value_at (ETableModel *etc, int col, int row)
{
EAddressbookModel *addressbook = E_ADDRESSBOOK_MODEL(etc);
const char *value;
if ( col >= COLS || row >= addressbook->data_count )
return NULL;
value = e_card_simple_get_const(addressbook->data[row],
col);
return (void *)(value ? value : "");
}
/* This function sets the value at a particular point in our ETableModel. */
static void
addressbook_set_value_at (ETableModel *etc, int col, int row, const void *val)
{
EAddressbookModel *addressbook = E_ADDRESSBOOK_MODEL(etc);
ECard *card;
if (addressbook->editable) {
if ( col >= COLS|| row >= addressbook->data_count )
return;
e_card_simple_set(addressbook->data[row],
col,
val);
gtk_object_get(GTK_OBJECT(addressbook->data[row]),
"card", &card,
NULL);
e_book_commit_card(addressbook->book, card, NULL, NULL);
e_table_model_cell_changed(etc, col, row);
}
}
/* This function returns whether a particular cell is editable. */
static gboolean
addressbook_is_cell_editable (ETableModel *etc, int col, int row)
{
return E_ADDRESSBOOK_MODEL(etc)->editable && col < E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING;
}
static void
addressbook_append_row (ETableModel *etm, ETableModel *source, gint row)
{
ECard *card;
ECardSimple *simple;
EAddressbookModel *addressbook = E_ADDRESSBOOK_MODEL(etm);
int col;
card = e_card_new("");
simple = e_card_simple_new(card);
for (col = 0; col < E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING; col++) {
const void *val = e_table_model_value_at(source, col, row);
e_card_simple_set(simple,
col,
val);
}
e_card_simple_sync_card(simple);
e_book_add_card(addressbook->book, card, NULL, NULL);
gtk_object_unref(GTK_OBJECT(simple));
gtk_object_unref(GTK_OBJECT(card));
}
/* This function duplicates the value passed to it. */
static void *
addressbook_duplicate_value (ETableModel *etc, int col, const void *value)
{
return g_strdup(value);
}
/* This function frees the value passed to it. */
static void
addressbook_free_value (ETableModel *etc, int col, void *value)
{
g_free(value);
}
static void *
addressbook_initialize_value (ETableModel *etc, int col)
{
return g_strdup("");
}
static gboolean
addressbook_value_is_empty (ETableModel *etc, int col, const void *value)
{
return !(value && *(char *)value);
}
static char *
addressbook_value_to_string (ETableModel *etc, int col, const void *value)
{
return g_strdup(value);
}
static void
create_card(EBookView *book_view,
const GList *cards,
EAddressbookModel *model)
{
model->data = g_realloc(model->data, (model->data_count + g_list_length((GList *)cards)) * sizeof(ECard *));
e_table_model_pre_change(E_TABLE_MODEL(model));
int old_count = model->data_count;
int length = g_list_length ((GList *)cards);
if (model->data_count + length > model->allocated_count) {
while (model->data_count + length > model->allocated_count)
model->allocated_count += 256;
model->data = g_renew(ECard *, model->data, model->allocated_count);
}
for ( ; cards; cards = cards->next) {
model->data[model->data_count++] = e_card_simple_new (E_CARD(cards->data));
e_table_model_row_inserted(E_TABLE_MODEL(model), model->data_count - 1);
model->data[model->data_count++] = cards->data;
gtk_object_ref (cards->data);
}
gtk_signal_emit (GTK_OBJECT (model),
e_addressbook_model_signals [CARD_ADDED],
old_count, model->data_count - old_count);
}
static void
......@@ -219,12 +122,14 @@ remove_card(EBookView *book_view,
EAddressbookModel *model)
{
int i;
e_table_model_pre_change(E_TABLE_MODEL(model));
for ( i = 0; i < model->data_count; i++) {
if ( !strcmp(e_card_simple_get_id(model->data[i]), id) ) {
if ( !strcmp(e_card_get_id(model->data[i]), id) ) {
gtk_object_unref(GTK_OBJECT(model->data[i]));
memmove(model->data + i, model->data + i + 1, (model->data_count - i - 1) * sizeof (ECard *));
e_table_model_row_deleted(E_TABLE_MODEL(model), i);
gtk_signal_emit (GTK_OBJECT (model),
e_addressbook_model_signals [CARD_REMOVED],
i);
}
}
}
......@@ -237,11 +142,13 @@ modify_card(EBookView *book_view,
for ( ; cards; cards = cards->next) {
int i;
for ( i = 0; i < model->data_count; i++) {
if ( !strcmp(e_card_simple_get_id(model->data[i]), e_card_get_id(E_CARD(cards->data))) ) {
if ( !strcmp(e_card_get_id(model->data[i]), e_card_get_id(E_CARD(cards->data))) ) {
gtk_object_unref(GTK_OBJECT(model->data[i]));
model->data[i] = e_card_simple_new(E_CARD(cards->data));
model->data[i] = e_card_duplicate(E_CARD(cards->data));
gtk_object_ref(GTK_OBJECT(model->data[i]));
e_table_model_row_changed(E_TABLE_MODEL(model), i);
gtk_signal_emit (GTK_OBJECT (model),
e_addressbook_model_signals [CARD_CHANGED],
i);
break;
}
}
......@@ -261,8 +168,6 @@ status_message (EBookView *book_view,
static void
e_addressbook_model_class_init (GtkObjectClass *object_class)
{
ETableModelClass *model_class = (ETableModelClass *) object_class;
parent_class = gtk_type_class (PARENT_TYPE);
object_class->destroy = addressbook_destroy;
......@@ -284,19 +189,39 @@ e_addressbook_model_class_init (GtkObjectClass *object_class)
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
e_addressbook_model_signals [CARD_ADDED] =
gtk_signal_new ("card_added",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EAddressbookModelClass, card_added),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
e_addressbook_model_signals [CARD_REMOVED] =
gtk_signal_new ("card_removed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EAddressbookModelClass, card_removed),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
e_addressbook_model_signals [CARD_CHANGED] =
gtk_signal_new ("card_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EAddressbookModelClass, card_changed),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
e_addressbook_model_signals [MODEL_CHANGED] =
gtk_signal_new ("model_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (EAddressbookModelClass, model_changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, e_addressbook_model_signals, LAST_SIGNAL);
model_class->column_count = addressbook_col_count;
model_class->row_count = addressbook_row_count;
model_class->value_at = addressbook_value_at;
model_class->set_value_at = addressbook_set_value_at;
model_class->is_cell_editable = addressbook_is_cell_editable;
model_class->append_row = addressbook_append_row;
model_class->duplicate_value = addressbook_duplicate_value;
model_class->free_value = addressbook_free_value;
model_class->initialize_value = addressbook_initialize_value;
model_class->value_is_empty = addressbook_value_is_empty;
model_class->value_to_string = addressbook_value_to_string;
}
static void
......@@ -313,6 +238,7 @@ e_addressbook_model_init (GtkObject *object)
model->status_message_id = 0;
model->data = NULL;
model->data_count = 0;
model->allocated_count = 0;
model->editable = FALSE;
model->first_get_view = TRUE;
}
......@@ -347,11 +273,12 @@ book_view_loaded (EBook *book, EBookStatus status, EBookView *book_view, gpointe
gtk_object_unref(GTK_OBJECT(model->data[i]));
}
e_table_model_pre_change(E_TABLE_MODEL(model));
g_free(model->data);
model->data = NULL;
model->data_count = 0;
e_table_model_changed(E_TABLE_MODEL(model));
model->allocated_count = 0;
gtk_signal_emit (GTK_OBJECT (model),
e_addressbook_model_signals [MODEL_CHANGED]);
}
static gboolean
......@@ -380,10 +307,8 @@ e_addressbook_model_get_card(EAddressbookModel *model,
{
if (model->data && row < model->data_count) {
ECard *card;
gtk_object_get(GTK_OBJECT(model->data[row]),
"card", &card,
NULL);
gtk_object_ref(GTK_OBJECT(card));
card = e_card_duplicate (model->data[row]);
gtk_object_ref (GTK_OBJECT (card));
return card;
}
return NULL;
......@@ -466,17 +391,41 @@ e_addressbook_model_get_type (void)
return type;
}
ETableModel *
EAddressbookModel*
e_addressbook_model_new (void)
{
EAddressbookModel *et;
et = gtk_type_new (e_addressbook_model_get_type ());
return E_TABLE_MODEL(et);
return et;
}
void e_addressbook_model_stop (EAddressbookModel *model)
{
remove_book_view(model);
}
int
e_addressbook_model_card_count (EAddressbookModel *model)
{
return model->data_count;
}
ECard *
e_addressbook_model_card_at (EAddressbookModel *model, int index)
{
return model->data[index];
}
gboolean
e_addressbook_model_editable (EAddressbookModel *model)
{
return model->editable;
}
EBook *
e_addressbook_model_get_ebook (EAddressbookModel *model)
{
return model->book;
}
......@@ -2,7 +2,6 @@
#ifndef _E_ADDRESSBOOK_MODEL_H_
#define _E_ADDRESSBOOK_MODEL_H_
#include <gal/e-table/e-table-model.h>
#include "addressbook/backend/ebook/e-book.h"
#include "addressbook/backend/ebook/e-book-view.h"
#include "addressbook/backend/ebook/e-card-simple.h"
......@@ -13,18 +12,11 @@
#define E_IS_ADDRESSBOOK_MODEL(o) (GTK_CHECK_TYPE ((o), E_ADDRESSBOOK_MODEL_TYPE))
#define E_IS_ADDRESSBOOK_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ADDRESSBOOK_MODEL_TYPE))
/* Virtual Column list:
0 Email
1 Full Name
2 Street
3 Phone
*/
typedef struct _EAddressbookModel EAddressbookModel;
typedef struct _EAddressbookModelClass EAddressbookModelClass;
struct _EAddressbookModel {
ETableModel parent;
GtkObject parent;
/* item specific fields */
EBook *book;
......@@ -33,8 +25,9 @@ struct _EAddressbookModel {
int get_view_idle;
ECardSimple **data;
ECard **data;
int data_count;
int allocated_count;
int create_card_id, remove_card_id, modify_card_id, status_message_id;
......@@ -44,21 +37,32 @@ struct _EAddressbookModel {
struct _EAddressbookModelClass {
ETableModelClass parent_class;
GtkObjectClass parent_class;
/*
* Signals
*/
void (*status_message) (EAddressbookModel *model, const gchar *message);
void (*card_added) (EAddressbookModel *model, gint index, gint count);
void (*card_removed) (EAddressbookModel *model, gint index);
void (*card_changed) (EAddressbookModel *model, gint index);
void (*model_changed) (EAddressbookModel *model);
};
GtkType e_addressbook_model_get_type (void);
ETableModel *e_addressbook_model_new (void);
GtkType e_addressbook_model_get_type (void);
EAddressbookModel *e_addressbook_model_new (void);
/* Returns object with ref count of 1. */
ECard *e_addressbook_model_get_card(EAddressbookModel *model,
int row);
void e_addressbook_model_stop (EAddressbookModel *model);
ECard *e_addressbook_model_get_card (EAddressbookModel *model,
int row);
EBook *e_addressbook_model_get_ebook (EAddressbookModel *model);
void e_addressbook_model_stop (EAddressbookModel *model);
int e_addressbook_model_card_count (EAddressbookModel *model);
ECard *e_addressbook_model_card_at (EAddressbookModel *model, int index);
gboolean e_addressbook_model_editable (EAddressbookModel *model);
#endif /* _E_ADDRESSBOOK_MODEL_H_ */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef _E_ADDRESSBOOK_REFLOW_ADAPTER_H_
#define _E_ADDRESSBOOK_REFLOW_ADAPTER_H_
#include <gal/widgets/e-reflow-model.h>
#include <gal/widgets/e-selection-model.h>
#include "e-addressbook-model.h"
#include "addressbook/backend/ebook/e-book.h"
#include "addressbook/backend/ebook/e-book-view.h"
#include "addressbook/backend/ebook/e-card.h"
#define E_ADDRESSBOOK_REFLOW_ADAPTER_TYPE (e_addressbook_reflow_adapter_get_type ())
#define E_ADDRESSBOOK_REFLOW_ADAPTER(o) (GTK_CHECK_CAST ((o), E_ADDRESSBOOK_REFLOW_ADAPTER_TYPE, EAddressbookReflowAdapter))
#define E_ADDRESSBOOK_REFLOW_ADAPTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_ADDRESSBOOK_REFLOW_ADAPTER_TYPE, EAddressbookReflowAdapterClass))
#define E_IS_ADDRESSBOOK_REFLOW_ADAPTER(o) (GTK_CHECK_TYPE ((o), E_ADDRESSBOOK_REFLOW_ADAPTER_TYPE))
#define E_IS_ADDRESSBOOK_REFLOW_ADAPTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ADDRESSBOOK_REFLOW_ADAPTER_TYPE))
typedef struct _EAddressbookReflowAdapter EAddressbookReflowAdapter;
typedef struct _EAddressbookReflowAdapterPrivate EAddressbookReflowAdapterPrivate;
typedef struct _EAddressbookReflowAdapterClass EAddressbookReflowAdapterClass;
struct _EAddressbookReflowAdapter {
EReflowModel parent;
EAddressbookReflowAdapterPrivate *priv;
};
struct _EAddressbookReflowAdapterClass {
EReflowModelClass parent_class;
/*
* Signals
*/
gint (* drag_begin) (EAddressbookReflowAdapter *adapter, GdkEvent *event);
};
GtkType e_addressbook_reflow_adapter_get_type (void);
void e_addressbook_reflow_adapter_construct (EAddressbookReflowAdapter *adapter,
EAddressbookModel *model);
EReflowModel *e_addressbook_reflow_adapter_new (EAddressbookModel *model);
/* Returns object with ref count of 1. */
ECard *e_addressbook_reflow_adapter_get_card (EAddressbookReflowAdapter *adapter,
int index);
gint e_addressbook_reflow_adapter_right_click (EAddressbookReflowAdapter *emvm,
GdkEvent *event,
ESelectionModel *selection);
#endif /* _E_ADDRESSBOOK_REFLOW_ADAPTER_H_ */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <config.h>
#include "e-addressbook-model.h"
#include "e-addressbook-table-adapter.h"
#include <gnome-xml/tree.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/xmlmemory.h>
#include <gnome.h>
struct _EAddressbookTableAdapterPrivate {
EAddressbookModel *model;
ECardSimple **simples;
int count;
int create_card_id, remove_card_id, modify_card_id, model_changed_id;
};
#define PARENT_TYPE e_table_model_get_type()
ETableModelClass *parent_class;
#define COLS (E_CARD_SIMPLE_FIELD_LAST)
static void
unlink_model(EAddressbookTableAdapter *adapter)
{
EAddressbookTableAdapterPrivate *priv = adapter->priv;
gtk_signal_disconnect(GTK_OBJECT (priv->model),
priv->create_card_id);
gtk_signal_disconnect(GTK_OBJECT (priv->model),
priv->remove_card_id);
gtk_signal_disconnect(GTK_OBJECT (priv->model),
priv->modify_card_id);
gtk_signal_disconnect(GTK_OBJECT (priv->model),
priv->model_changed_id);
priv->create_card_id = 0;
priv->remove_card_id = 0;
priv->modify_card_id = 0;
priv->model_changed_id = 0;
gtk_object_unref(GTK_OBJECT(priv->model));
priv->model = NULL;
}
static void
build_simple_mapping(EAddressbookTableAdapter *adapter)
{
EAddressbookTableAdapterPrivate *priv = adapter->priv;
int i;
/* free up the existing mapping if there is one */
if (priv->simples) {
for (i = 0; i < priv->count; i ++)
gtk_object_unref (GTK_OBJECT (priv->simples[i]));
g_free (priv->simples);
}
/* build up our mapping to ECardSimple*'s */
priv->count = e_addressbook_model_card_count (priv->model);
priv->simples = g_new (ECardSimple*, priv->count);
for (i = 0; i < priv->count; i ++) {
priv->simples[i] = e_card_simple_new (e_addressbook_model_card_at (priv->model, i));
gtk_object_ref (GTK_OBJECT (priv->simples[i]));
}
}
static void
addressbook_destroy(GtkObject *object)
{
EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(object);
unlink_model(adapter);
}
/* This function returns the number of columns in our ETableModel. */
static int
addressbook_col_count (ETableModel *etc)
{
return COLS;
}
/* This function returns the number of rows in our ETableModel. */
static int
addressbook_row_count (ETableModel *etc)
{
EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc);
EAddressbookTableAdapterPrivate *priv = adapter->priv;
return e_addressbook_model_card_count (priv->model);
}
/* This function returns the value at a particular point in our ETableModel. */
static void *
addressbook_value_at (ETableModel *etc, int col, int row)
{
EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc);
EAddressbookTableAdapterPrivate *priv = adapter->priv;
const char *value;
if ( col >= COLS || row >= e_addressbook_model_card_count (priv->model) )
return NULL;
value = e_card_simple_get_const(priv->simples[row], col);
return (void *)(value ? value : "");
}
/* This function sets the value at a particular point in our ETableModel. */
static void
addressbook_set_value_at (ETableModel *etc, int col, int row, const void *val)
{
EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc);
EAddressbookTableAdapterPrivate *priv = adapter->priv;
if (e_addressbook_model_editable (priv->model)) {
ECard *card;
if ( col >= COLS|| row >= e_addressbook_model_card_count (priv->model) )
return;
e_card_simple_set(priv->simples[row],
col,
val);
gtk_object_get(GTK_OBJECT(priv->simples[row]),
"card", &card,
NULL);
e_book_commit_card(e_addressbook_model_get_ebook(priv->model),
card, NULL, NULL);
/* XXX do we need this? shouldn't the commit_card generate a changed signal? */
e_table_model_cell_changed(etc, col, row);
}
}
/* This function returns whether a particular cell is editable. */
static gboolean
addressbook_is_cell_editable (ETableModel *etc, int col, int row)
{