aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-05-16 13:17:09 +0800
committerChris Toshok <toshok@src.gnome.org>2001-05-16 13:17:09 +0800
commit934524b95cb86abae6b1457ff5d4853fb702cb87 (patch)
tree53789a427758341d31dd24ec9afcd6ed3d1d2951
parentad6072f81f19f15cc5d6078f56039de99700a986 (diff)
downloadgsoc2013-evolution-934524b95cb86abae6b1457ff5d4853fb702cb87.tar.gz
gsoc2013-evolution-934524b95cb86abae6b1457ff5d4853fb702cb87.tar.zst
gsoc2013-evolution-934524b95cb86abae6b1457ff5d4853fb702cb87.zip
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
-rw-r--r--addressbook/ChangeLog82
-rw-r--r--addressbook/gui/widgets/Makefile.am6
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c241
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.h36
-rw-r--r--addressbook/gui/widgets/e-addressbook-reflow-adapter.c605
-rw-r--r--addressbook/gui/widgets/e-addressbook-reflow-adapter.h51
-rw-r--r--addressbook/gui/widgets/e-addressbook-table-adapter.c353
-rw-r--r--addressbook/gui/widgets/e-addressbook-table-adapter.h44
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c86
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.h3
-rw-r--r--addressbook/gui/widgets/e-minicard-view-model.c708
-rw-r--r--addressbook/gui/widgets/e-minicard-view-model.h71
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.c51
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.h11
-rw-r--r--addressbook/gui/widgets/e-minicard-view.c145
-rw-r--r--addressbook/gui/widgets/e-minicard-view.h10
16 files changed, 1372 insertions, 1131 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index ba324e0bad..7ad1fe032e 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,85 @@
+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
diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am
index fdb97866d3..27db6b3b5c 100644
--- a/addressbook/gui/widgets/Makefile.am
+++ b/addressbook/gui/widgets/Makefile.am
@@ -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 \
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index c20161259f..60da28f6be 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.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;
+}
diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h
index 79a606b314..f8fd01b535 100644
--- a/addressbook/gui/widgets/e-addressbook-model.h
+++ b/addressbook/gui/widgets/e-addressbook-model.h
@@ -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_ */
diff --git a/addressbook/gui/widgets/e-addressbook-reflow-adapter.c b/addressbook/gui/widgets/e-addressbook-reflow-adapter.c
new file mode 100644
index 0000000000..f4e6b4cbfc
--- /dev/null
+++ b/addressbook/gui/widgets/e-addressbook-reflow-adapter.c
@@ -0,0 +1,605 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+
+#include <config.h>
+
+#include "e-addressbook-reflow-adapter.h"
+#include "e-addressbook-model.h"
+
+#include <gal/util/e-i18n.h>
+
+#include "e-minicard.h"
+#include <gal/widgets/e-unicode.h>
+#include <gal/widgets/e-font.h>
+#include <gal/widgets/e-popup-menu.h>
+#include "e-contact-save-as.h"
+#include "addressbook/printing/e-contact-print.h"
+#include "addressbook/printing/e-contact-print-envelope.h"
+
+struct _EAddressbookReflowAdapterPrivate {
+ EAddressbookModel *model;
+
+ int create_card_id, remove_card_id, modify_card_id, model_changed_id;
+};
+
+#define PARENT_TYPE e_reflow_model_get_type()
+EReflowModel *parent_class;
+
+#define d(x)
+
+enum {
+ ARG_0,
+ ARG_BOOK,
+ ARG_QUERY,
+ ARG_EDITABLE,
+};
+
+enum {
+ DRAG_BEGIN,
+ LAST_SIGNAL
+};
+
+static guint e_addressbook_reflow_adapter_signals [LAST_SIGNAL] = {0, };
+
+static void
+unlink_model(EAddressbookReflowAdapter *adapter)
+{
+ EAddressbookReflowAdapterPrivate *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);
+
+ priv->create_card_id = 0;
+ priv->remove_card_id = 0;
+ priv->modify_card_id = 0;
+
+ gtk_object_unref(GTK_OBJECT(priv->model));
+
+ priv->model = NULL;
+}
+
+
+static int
+count_lines (const gchar *text)
+{
+ int num_lines = 1;
+ gunichar unival;
+
+ for (text = e_unicode_get_utf8 (text, &unival); (unival && text); text = e_unicode_get_utf8 (text, &unival)) {
+ if (unival == '\n') {
+ num_lines ++;
+ }
+ }
+
+ return num_lines;
+}
+
+static int
+text_height (GnomeCanvas *canvas, const gchar *text)
+{
+ EFont *font = e_font_from_gdk_font (((GtkWidget *) canvas)->style->font);
+ gint height = e_font_height (font) * count_lines (text) / canvas->pixels_per_unit;
+
+ e_font_unref (font);
+ return height;
+}
+
+typedef struct {
+ EAddressbookReflowAdapter *adapter;
+ ESelectionModel *selection;
+} ModelAndSelection;
+
+static void
+model_and_selection_free (ModelAndSelection *mns)
+{
+ gtk_object_unref(GTK_OBJECT(mns->adapter));
+ gtk_object_unref(GTK_OBJECT(mns->selection));
+ g_free(mns);
+}
+
+static void
+add_to_list (int model_row, gpointer closure)
+{
+ GList **list = closure;
+ *list = g_list_prepend (*list, GINT_TO_POINTER (model_row));
+}
+
+static GList *
+get_card_list (ModelAndSelection *mns)
+{
+ EAddressbookReflowAdapterPrivate *priv = mns->adapter->priv;
+ GList *list;
+ GList *iterator;
+
+ list = NULL;
+ e_selection_model_foreach (mns->selection, add_to_list, &list);
+
+ for (iterator = list; iterator; iterator = iterator->next) {
+ iterator->data = e_addressbook_model_card_at (priv->model, GPOINTER_TO_INT (iterator->data));
+ }
+ list = g_list_reverse (list);
+ return list;
+}
+
+static void
+save_as (GtkWidget *widget, ModelAndSelection *mns)
+{
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list)
+ e_contact_list_save_as (_("Save as VCard"), list);
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+static void
+send_as (GtkWidget *widget, ModelAndSelection *mns)
+{
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list)
+ e_card_list_send (list, E_CARD_DISPOSITION_AS_ATTACHMENT);
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+static void
+send_to (GtkWidget *widget, ModelAndSelection *mns)
+{
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list)
+ e_card_list_send (list, E_CARD_DISPOSITION_AS_TO);
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+static void
+print (GtkWidget *widget, ModelAndSelection *mns)
+{
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list)
+ gtk_widget_show (e_contact_print_card_list_dialog_new (list));
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+static void
+print_envelope (GtkWidget *widget, ModelAndSelection *mns)
+{
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list)
+ gtk_widget_show (e_contact_print_envelope_list_dialog_new (list));
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+static void
+card_changed_cb (EBook* book, EBookStatus status, gpointer user_data)
+{
+ d(g_print ("%s: %s(): a card was changed with status %d\n", __FILE__, __FUNCTION__, status));
+}
+
+static void
+delete (GtkWidget *widget, ModelAndSelection *mns)
+{
+ EAddressbookReflowAdapterPrivate *priv = mns->adapter->priv;
+ GList *list;
+
+ list = get_card_list (mns);
+ if (list) {
+
+ if (e_contact_editor_confirm_delete(NULL)) { /*FIXME: Give a GtkWindow here. */
+ GList *iterator;
+ EBook *book = e_addressbook_model_get_ebook(priv->model);
+
+ for (iterator = list; iterator; iterator = iterator->next) {
+ ECard *card = iterator->data;
+
+ gtk_object_ref(GTK_OBJECT(card));
+
+ e_book_remove_card (book,
+ card,
+ card_changed_cb,
+ NULL);
+
+ gtk_object_unref(GTK_OBJECT(card));
+ }
+ }
+ }
+
+ g_list_free (list);
+ model_and_selection_free (mns);
+}
+
+gint
+e_addressbook_reflow_adapter_right_click (EAddressbookReflowAdapter *adapter, GdkEvent *event, ESelectionModel *selection)
+{
+ ModelAndSelection *mns = g_new(ModelAndSelection, 1);
+ EPopupMenu menu[] = { {N_("Save as VCard"), NULL, GTK_SIGNAL_FUNC(save_as), NULL, 0},
+ {N_("Send contact to other"), NULL, GTK_SIGNAL_FUNC(send_as), NULL, 0},
+ {N_("Send message to contact"), NULL, GTK_SIGNAL_FUNC(send_to), NULL, 0},
+ {N_("Print"), NULL, GTK_SIGNAL_FUNC(print), NULL, 0},
+ {N_("Print Envelope"), NULL, GTK_SIGNAL_FUNC(print_envelope), NULL, 0},
+ {N_("Delete"), NULL, GTK_SIGNAL_FUNC(delete), NULL, 0},
+ {NULL, NULL, NULL, 0}};
+
+ mns->adapter = adapter;
+ mns->selection = selection;
+ gtk_object_ref(GTK_OBJECT(mns->adapter));
+ gtk_object_ref(GTK_OBJECT(mns->selection));
+ e_popup_menu_run (menu, event, 0, 0, mns);
+ return TRUE;
+}
+
+static void
+addressbook_destroy(GtkObject *object)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(object);
+
+ unlink_model (adapter);
+}
+
+static void
+addressbook_set_width (EReflowModel *erm, int width)
+{
+}
+
+/* This function returns the number of items in our EReflowModel. */
+static int
+addressbook_count (EReflowModel *erm)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(erm);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ return e_addressbook_model_card_count (priv->model);
+}
+
+/* This function returns the number of items in our EReflowModel. */
+static int
+addressbook_height (EReflowModel *erm, int i, GnomeCanvasGroup *parent)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(erm);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+ /* FIXME */
+ ECardSimpleField field;
+ int count = 0;
+ int height;
+ char *string;
+ ECardSimple *simple = e_card_simple_new (e_addressbook_model_card_at (priv->model, i));
+
+ string = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FILE_AS);
+ height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, string ? string : "") + 10.0;
+ g_free(string);
+
+ for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST - 2 && count < 5; field++) {
+ string = e_card_simple_get(simple, field);
+ if (string && *string) {
+ int this_height;
+ int field_text_height;
+
+ this_height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, e_card_simple_get_name(simple, field));
+
+ field_text_height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, string);
+ if (this_height < field_text_height)
+ this_height = field_text_height;
+
+ this_height += 3;
+
+ height += this_height;
+ count ++;
+ }
+ g_free (string);
+ }
+ height += 2;
+
+ gtk_object_unref (GTK_OBJECT (simple));
+
+ return height;
+}
+
+static int
+addressbook_compare (EReflowModel *erm, int n1, int n2)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(erm);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+ ECard *card1, *card2;
+
+ card1 = e_addressbook_model_card_at (priv->model, n1);
+ card2 = e_addressbook_model_card_at (priv->model, n2);
+
+ if (card1 && card2) {
+ char *file_as1, *file_as2;
+ file_as1 = card1->file_as;
+ file_as2 = card2->file_as;
+ if (file_as1 && file_as2)
+ return strcasecmp(file_as1, file_as2);
+ if (file_as1)
+ return -1;
+ if (file_as2)
+ return 1;
+ return strcmp(e_card_get_id(card1), e_card_get_id(card2));
+ }
+ if (card1)
+ return -1;
+ if (card2)
+ return 1;
+ return 0;
+}
+
+static int
+adapter_drag_begin (EMinicard *card, GdkEvent *event, EAddressbookReflowAdapter *adapter)
+{
+ gint ret_val = 0;
+
+ gtk_signal_emit (GTK_OBJECT(adapter),
+ e_addressbook_reflow_adapter_signals[DRAG_BEGIN],
+ event, &ret_val);
+
+ return ret_val;
+}
+
+static GnomeCanvasItem *
+addressbook_incarnate (EReflowModel *erm, int i, GnomeCanvasGroup *parent)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(erm);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+ GnomeCanvasItem *item;
+
+ item = gnome_canvas_item_new(parent,
+ e_minicard_get_type(),
+ "card", e_addressbook_model_card_at (priv->model, i),
+ "editable", e_addressbook_model_editable (priv->model),
+ NULL);
+
+#if 0
+ gtk_signal_connect (GTK_OBJECT (item), "selected",
+ GTK_SIGNAL_FUNC(card_selected), emvm);
+#endif
+
+ gtk_signal_connect (GTK_OBJECT (item), "drag_begin",
+ GTK_SIGNAL_FUNC(adapter_drag_begin), adapter);
+
+ return item;
+}
+
+static void
+addressbook_reincarnate (EReflowModel *erm, int i, GnomeCanvasItem *item)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(erm);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ gnome_canvas_item_set(item,
+ "card", e_addressbook_model_card_at (priv->model, i),
+ NULL);
+}
+
+
+
+static void
+create_card(EAddressbookModel *model,
+ gint index, gint count,
+ EAddressbookReflowAdapter *adapter)
+{
+ e_reflow_model_items_inserted (E_REFLOW_MODEL (adapter),
+ index,
+ count);
+}
+
+static void
+remove_card(EAddressbookModel *model,
+ gint index,
+ EAddressbookReflowAdapter *adapter)
+{
+ e_reflow_model_changed (E_REFLOW_MODEL (adapter));
+}
+
+static void
+modify_card(EAddressbookModel *model,
+ gint index,
+ EAddressbookReflowAdapter *adapter)
+{
+ e_reflow_model_item_changed (E_REFLOW_MODEL (adapter), index);
+}
+
+static void
+model_changed(EAddressbookModel *model,
+ EAddressbookReflowAdapter *adapter)
+{
+ e_reflow_model_changed (E_REFLOW_MODEL (adapter));
+}
+
+static void
+addressbook_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(o);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ switch (arg_id){
+ case ARG_BOOK:
+ gtk_object_set (GTK_OBJECT (priv->model),
+ "book", GTK_VALUE_OBJECT (*arg),
+ NULL);
+ break;
+ case ARG_QUERY:
+ gtk_object_set (GTK_OBJECT (priv->model),
+ "query", GTK_VALUE_STRING (*arg),
+ NULL);
+ break;
+ case ARG_EDITABLE:
+ gtk_object_set (GTK_OBJECT (priv->model),
+ "editable", GTK_VALUE_BOOL (*arg),
+ NULL);
+ break;
+ }
+}
+
+static void
+addressbook_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(o);
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ switch (arg_id) {
+ case ARG_BOOK: {
+ EBook *book;
+ gtk_object_get (GTK_OBJECT (priv->model),
+ "book", &book,
+ NULL);
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(book);
+ break;
+ }
+ case ARG_QUERY: {
+ char *query;
+ gtk_object_get (GTK_OBJECT (priv->model),
+ "query", &query,
+ NULL);
+ GTK_VALUE_STRING (*arg) = query;
+ break;
+ }
+ case ARG_EDITABLE: {
+ gboolean editable;
+ gtk_object_get (GTK_OBJECT (priv->model),
+ "editable", &editable,
+ NULL);
+ GTK_VALUE_BOOL (*arg) = editable;
+ break;
+ }
+ default:
+ arg->type = GTK_TYPE_INVALID;
+ break;
+ }
+}
+
+static void
+e_addressbook_reflow_adapter_class_init (GtkObjectClass *object_class)
+{
+ EReflowModelClass *model_class = (EReflowModelClass *) object_class;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+
+ object_class->set_arg = addressbook_set_arg;
+ object_class->get_arg = addressbook_get_arg;
+ object_class->destroy = addressbook_destroy;
+
+ gtk_object_add_arg_type ("EAddressbookReflowAdapter::book", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_BOOK);
+ gtk_object_add_arg_type ("EAddressbookReflowAdapter::query", GTK_TYPE_STRING,
+ GTK_ARG_READWRITE, ARG_QUERY);
+ gtk_object_add_arg_type ("EAddressbookReflowAdapter::editable", GTK_TYPE_BOOL,
+ GTK_ARG_READWRITE, ARG_EDITABLE);
+
+ e_addressbook_reflow_adapter_signals [DRAG_BEGIN] =
+ gtk_signal_new ("drag_begin",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EAddressbookReflowAdapterClass, drag_begin),
+ gtk_marshal_INT__POINTER,
+ GTK_TYPE_INT, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER);
+
+
+ gtk_object_class_add_signals (object_class, e_addressbook_reflow_adapter_signals, LAST_SIGNAL);
+
+ model_class->set_width = addressbook_set_width;
+ model_class->count = addressbook_count;
+ model_class->height = addressbook_height;
+ model_class->compare = addressbook_compare;
+ model_class->incarnate = addressbook_incarnate;
+ model_class->reincarnate = addressbook_reincarnate;
+}
+
+static void
+e_addressbook_reflow_adapter_init (GtkObject *object)
+{
+ EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(object);
+ EAddressbookReflowAdapterPrivate *priv;
+
+ priv = adapter->priv = g_new0 (EAddressbookReflowAdapterPrivate, 1);
+
+ priv->create_card_id = 0;
+ priv->remove_card_id = 0;
+ priv->modify_card_id = 0;
+ priv->model_changed_id = 0;
+}
+
+GtkType
+e_addressbook_reflow_adapter_get_type (void)
+{
+ static GtkType type = 0;
+
+ if (!type){
+ GtkTypeInfo info = {
+ "EAddressbookReflowAdapter",
+ sizeof (EAddressbookReflowAdapter),
+ sizeof (EAddressbookReflowAdapterClass),
+ (GtkClassInitFunc) e_addressbook_reflow_adapter_class_init,
+ (GtkObjectInitFunc) e_addressbook_reflow_adapter_init,
+ NULL, /* reserved 1 */
+ NULL, /* reserved 2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ type = gtk_type_unique (PARENT_TYPE, &info);
+ }
+
+ return type;
+}
+
+void
+e_addressbook_reflow_adapter_construct (EAddressbookReflowAdapter *adapter,
+ EAddressbookModel *model)
+{
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ priv->model = model;
+
+ priv->create_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_added",
+ GTK_SIGNAL_FUNC(create_card),
+ adapter);
+ priv->remove_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_removed",
+ GTK_SIGNAL_FUNC(remove_card),
+ adapter);
+ priv->modify_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_changed",
+ GTK_SIGNAL_FUNC(modify_card),
+ adapter);
+ priv->model_changed_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "model_changed",
+ GTK_SIGNAL_FUNC(model_changed),
+ adapter);
+}
+
+EReflowModel *
+e_addressbook_reflow_adapter_new (EAddressbookModel *model)
+{
+ EAddressbookReflowAdapter *et;
+
+ et = gtk_type_new (e_addressbook_reflow_adapter_get_type ());
+
+ e_addressbook_reflow_adapter_construct (et, model);
+
+ return E_REFLOW_MODEL(et);
+}
+
+
+ECard *
+e_addressbook_reflow_adapter_get_card (EAddressbookReflowAdapter *adapter,
+ int index)
+{
+ EAddressbookReflowAdapterPrivate *priv = adapter->priv;
+
+ return e_addressbook_model_get_card (priv->model, index);
+}
diff --git a/addressbook/gui/widgets/e-addressbook-reflow-adapter.h b/addressbook/gui/widgets/e-addressbook-reflow-adapter.h
new file mode 100644
index 0000000000..1614a65064
--- /dev/null
+++ b/addressbook/gui/widgets/e-addressbook-reflow-adapter.h
@@ -0,0 +1,51 @@
+/* -*- 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_ */
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c b/addressbook/gui/widgets/e-addressbook-table-adapter.c
new file mode 100644
index 0000000000..01337bf8e3
--- /dev/null
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -0,0 +1,353 @@
+/* -*- 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)
+{
+ EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc);
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ return e_addressbook_model_editable(priv->model) && col < E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING;
+}
+
+static void
+addressbook_append_row (ETableModel *etm, ETableModel *source, gint row)
+{
+ EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etm);
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ ECard *card;
+ ECardSimple *simple;
+ 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 (e_addressbook_model_get_ebook (priv->model), 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
+e_addressbook_table_adapter_class_init (GtkObjectClass *object_class)
+{
+ ETableModelClass *model_class = (ETableModelClass *) object_class;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+
+ object_class->destroy = addressbook_destroy;
+
+ 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
+e_addressbook_table_adapter_init (GtkObject *object)
+{
+ EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(object);
+ EAddressbookTableAdapterPrivate *priv;
+
+ priv = adapter->priv = g_new0 (EAddressbookTableAdapterPrivate, 1);
+
+ priv->create_card_id = 0;
+ priv->remove_card_id = 0;
+ priv->modify_card_id = 0;
+ priv->model_changed_id = 0;
+ priv->simples = NULL;
+ priv->count = 0;
+}
+
+
+static void
+create_card (EAddressbookModel *model,
+ gint index, gint count,
+ EAddressbookTableAdapter *adapter)
+{
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ int i;
+
+ priv->count += count;
+ priv->simples = g_renew(ECardSimple *, priv->simples, priv->count);
+ memmove (priv->simples + index + count - 1, priv->simples + index, count * sizeof (ECardSimple*));
+
+ e_table_model_pre_change (E_TABLE_MODEL (adapter));
+ for (i = 0; i < count; i ++) {
+ priv->simples[index + i] = e_card_simple_new (e_addressbook_model_card_at (priv->model, index + i));
+ gtk_object_ref (GTK_OBJECT (priv->simples[index + i]));
+ e_table_model_row_inserted (E_TABLE_MODEL (adapter), index + i);
+ }
+}
+
+static void
+remove_card (EAddressbookModel *model,
+ gint index,
+ EAddressbookTableAdapter *adapter)
+{
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ gtk_object_unref (GTK_OBJECT (priv->simples[index]));
+ if (priv->count > 1)
+ memmove (priv->simples + index, priv->simples + index + 1, (priv->count - index - 1) * sizeof (ECardSimple*));
+ priv->count --;
+ e_table_model_rows_deleted (E_TABLE_MODEL (adapter), index, 1);
+}
+
+static void
+modify_card (EAddressbookModel *model,
+ gint index,
+ EAddressbookTableAdapter *adapter)
+{
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ e_table_model_row_changed (E_TABLE_MODEL (adapter), index);
+ gtk_object_unref (GTK_OBJECT (priv->simples[index]));
+ priv->simples[index] = e_card_simple_new (e_addressbook_model_card_at (priv->model, index));
+ gtk_object_ref (GTK_OBJECT (priv->simples[index]));
+}
+
+static void
+model_changed (EAddressbookModel *model,
+ EAddressbookTableAdapter *adapter)
+{
+ build_simple_mapping (adapter);
+ e_table_model_changed (E_TABLE_MODEL (adapter));
+}
+
+GtkType
+e_addressbook_table_adapter_get_type (void)
+{
+ static GtkType type = 0;
+
+ if (!type){
+ GtkTypeInfo info = {
+ "EAddressbookTableAdapter",
+ sizeof (EAddressbookTableAdapter),
+ sizeof (EAddressbookTableAdapterClass),
+ (GtkClassInitFunc) e_addressbook_table_adapter_class_init,
+ (GtkObjectInitFunc) e_addressbook_table_adapter_init,
+ NULL, /* reserved 1 */
+ NULL, /* reserved 2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ type = gtk_type_unique (PARENT_TYPE, &info);
+ }
+
+ return type;
+}
+
+void
+e_addressbook_table_adapter_construct (EAddressbookTableAdapter *adapter,
+ EAddressbookModel *model)
+{
+ EAddressbookTableAdapterPrivate *priv = adapter->priv;
+
+ priv->model = model;
+
+ priv->create_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_added",
+ GTK_SIGNAL_FUNC(create_card),
+ adapter);
+ priv->remove_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_removed",
+ GTK_SIGNAL_FUNC(remove_card),
+ adapter);
+ priv->modify_card_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "card_changed",
+ GTK_SIGNAL_FUNC(modify_card),
+ adapter);
+ priv->model_changed_id = gtk_signal_connect(GTK_OBJECT(priv->model),
+ "model_changed",
+ GTK_SIGNAL_FUNC(model_changed),
+ adapter);
+
+ build_simple_mapping (adapter);
+}
+
+ETableModel *
+e_addressbook_table_adapter_new (EAddressbookModel *model)
+{
+ EAddressbookTableAdapter *et;
+
+ et = gtk_type_new (e_addressbook_table_adapter_get_type ());
+
+ e_addressbook_table_adapter_construct (et, model);
+
+ return E_TABLE_MODEL(et);
+}
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.h b/addressbook/gui/widgets/e-addressbook-table-adapter.h
new file mode 100644
index 0000000000..d76434e80a
--- /dev/null
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef _E_ADDRESSBOOK_TABLE_ADAPTER_H_
+#define _E_ADDRESSBOOK_TABLE_ADAPTER_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"
+
+#define E_ADDRESSBOOK_TABLE_ADAPTER_TYPE (e_addressbook_table_adapter_get_type ())
+#define E_ADDRESSBOOK_TABLE_ADAPTER(o) (GTK_CHECK_CAST ((o), E_ADDRESSBOOK_TABLE_ADAPTER_TYPE, EAddressbookTableAdapter))
+#define E_ADDRESSBOOK_TABLE_ADAPTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_ADDRESSBOOK_TABLE_ADAPTER_TYPE, EAddressbookTableAdapterClass))
+#define E_IS_ADDRESSBOOK_TABLE_ADAPTER(o) (GTK_CHECK_TYPE ((o), E_ADDRESSBOOK_TABLE_ADAPTER_TYPE))
+#define E_IS_ADDRESSBOOK_TABLE_ADAPTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ADDRESSBOOK_TABLE_ADAPTER_TYPE))
+
+/* Virtual Column list:
+ 0 Email
+ 1 Full Name
+ 2 Street
+ 3 Phone
+*/
+
+typedef struct _EAddressbookTableAdapter EAddressbookTableAdapter;
+typedef struct _EAddressbookTableAdapterPrivate EAddressbookTableAdapterPrivate;
+typedef struct _EAddressbookTableAdapterClass EAddressbookTableAdapterClass;
+
+struct _EAddressbookTableAdapter {
+ ETableModel parent;
+
+ EAddressbookTableAdapterPrivate *priv;
+};
+
+
+struct _EAddressbookTableAdapterClass {
+ ETableModelClass parent_class;
+};
+
+
+GtkType e_addressbook_table_adapter_get_type (void);
+void e_addressbook_table_adapter_construct (EAddressbookTableAdapter *adapter,
+ EAddressbookModel *model);
+ETableModel *e_addressbook_table_adapter_new (EAddressbookModel *model);
+
+#endif /* _E_ADDRESSBOOK_TABLE_ADAPTER_H_ */
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 5a340bc0a6..352d1b4b62 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -47,6 +47,8 @@
#include "e-addressbook-view.h"
#include "e-addressbook-model.h"
+#include "e-addressbook-table-adapter.h"
+#include "e-addressbook-reflow-adapter.h"
#include "e-minicard-view-widget.h"
#include "e-contact-save-as.h"
@@ -59,6 +61,8 @@ static void e_addressbook_view_get_arg (GtkObject *object, GtkArg *arg, guint ar
static void e_addressbook_view_destroy (GtkObject *object);
static void change_view_type (EAddressbookView *view, EAddressbookViewType view_type);
+static void status_message (GtkObject *object, const gchar *status, EAddressbookView *eav);
+
static GtkTableClass *parent_class = NULL;
/* The arguments we take */
@@ -145,6 +149,13 @@ e_addressbook_view_init (EAddressbookView *eav)
{
eav->view_type = E_ADDRESSBOOK_VIEW_NONE;
+ eav->model = e_addressbook_model_new ();
+
+ gtk_signal_connect (GTK_OBJECT(eav->model),
+ "status_message",
+ GTK_SIGNAL_FUNC (status_message),
+ eav);
+
eav->editable = FALSE;
eav->book = NULL;
eav->query = g_strdup("(contains \"x-evolution-any-field\" \"\")");
@@ -177,10 +188,9 @@ static void
book_writable_cb (EBook *book, gboolean writable, EAddressbookView *eav)
{
eav->editable = writable;
- if (eav->object)
- gtk_object_set (GTK_OBJECT (eav->object),
- "editable", eav->editable,
- NULL);
+ gtk_object_set (GTK_OBJECT (eav->model),
+ "editable", eav->editable,
+ NULL);
}
static void
@@ -202,11 +212,10 @@ e_addressbook_view_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
}
else
eav->book = NULL;
- if (eav->object)
- gtk_object_set(GTK_OBJECT(eav->object),
- "book", eav->book,
- "editable", eav->editable,
- NULL);
+ gtk_object_set(GTK_OBJECT(eav->model),
+ "book", eav->book,
+ "editable", eav->editable,
+ NULL);
break;
case ARG_QUERY:
@@ -214,10 +223,9 @@ e_addressbook_view_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
eav->query = g_strdup(GTK_VALUE_STRING(*arg));
if (!eav->query)
eav->query = g_strdup("(contains \"x-evolution-any-field\" \"\")");
- if (eav->object)
- gtk_object_set(GTK_OBJECT(eav->object),
- "query", eav->query,
- NULL);
+ gtk_object_set(GTK_OBJECT(eav->model),
+ "query", eav->query,
+ NULL);
break;
case ARG_TYPE:
change_view_type(eav, GTK_VALUE_ENUM(*arg));
@@ -319,13 +327,15 @@ create_minicard_view (EAddressbookView *view)
GtkWidget *alphabet;
GtkWidget *minicard_view;
GtkWidget *minicard_hbox;
+ EAddressbookReflowAdapter *adapter;
gtk_widget_push_visual (gdk_rgb_get_visual ());
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
minicard_hbox = gtk_hbox_new(FALSE, 0);
- minicard_view = e_minicard_view_widget_new();
+ adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(e_addressbook_reflow_adapter_new (view->model));
+ minicard_view = e_minicard_view_widget_new(adapter);
view->object = GTK_OBJECT(minicard_view);
view->widget = minicard_hbox;
@@ -358,6 +368,8 @@ create_minicard_view (EAddressbookView *view)
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
+
+ e_reflow_model_changed (E_REFLOW_MODEL (adapter));
}
@@ -441,8 +453,8 @@ supported_fields_cb (EBook *book, EBookStatus status, EList *fields, CardAndView
static void
table_double_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view)
{
- if (E_IS_ADDRESSBOOK_MODEL(view->object)) {
- EAddressbookModel *model = E_ADDRESSBOOK_MODEL(view->object);
+ if (E_IS_ADDRESSBOOK_TABLE_ADAPTER(view->object)) {
+ EAddressbookModel *model = view->model;
ECard *card = e_addressbook_model_get_card(model, row);
EBook *book;
CardAndView *card_and_view;
@@ -489,7 +501,7 @@ get_card_list_1(gint model_row,
list = card_and_book->closure;
view = card_and_book->view;
- card = e_addressbook_model_get_card(E_ADDRESSBOOK_MODEL(view->object), model_row);
+ card = e_addressbook_model_get_card(view->model, model_row);
*list = g_list_prepend(*list, card);
}
@@ -565,8 +577,8 @@ delete (GtkWidget *widget, CardAndBook *card_and_book)
static gint
table_right_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view)
{
- if (E_IS_ADDRESSBOOK_MODEL(view->object)) {
- EAddressbookModel *model = E_ADDRESSBOOK_MODEL(view->object);
+ if (E_IS_ADDRESSBOOK_TABLE_ADAPTER(view->object)) {
+ EAddressbookModel *model = view->model;
CardAndBook *card_and_book;
EPopupMenu menu[] = {
@@ -610,14 +622,14 @@ table_drag_data_get (ETable *table,
printf ("table_drag_data_get (row %d, col %d)\n", row, col);
- if (!E_IS_ADDRESSBOOK_MODEL(view->object))
+ if (!E_IS_ADDRESSBOOK_TABLE_ADAPTER(view->object))
return;
switch (info) {
case DND_TARGET_TYPE_VCARD: {
char *value;
- value = e_card_simple_get_vcard(E_ADDRESSBOOK_MODEL(view->object)->data[row]);
+ value = e_card_get_vcard(view->model->data[row]);
gtk_selection_data_set (selection_data,
selection_data->target,
@@ -737,20 +749,20 @@ static char *list [] = {
static void
create_table_view (EAddressbookView *view)
{
- ETableModel *model;
+ ETableModel *adapter;
ECardSimple *simple;
GtkWidget *table;
simple = e_card_simple_new(NULL);
- model = e_addressbook_model_new();
+ adapter = e_addressbook_table_adapter_new(view->model);
/* Here we create the table. We give it the three pieces of
the table we've created, the header, the model, and the
initial layout. It does the rest. */
- table = e_table_scrolled_new (model, NULL, SPEC, NULL);
+ table = e_table_scrolled_new (adapter, NULL, SPEC, NULL);
- view->object = GTK_OBJECT(model);
+ view->object = GTK_OBJECT(adapter);
view->widget = table;
gtk_signal_connect(GTK_OBJECT(e_table_scrolled_get_table(E_TABLE_SCROLLED(table))), "double_click",
@@ -804,17 +816,6 @@ change_view_type (EAddressbookView *view, EAddressbookViewType view_type)
}
view->view_type = view_type;
-
- gtk_signal_connect (view->object,
- "status_message",
- GTK_SIGNAL_FUNC (status_message),
- view);
-
- gtk_object_set(view->object,
- "query", view->query,
- "book", view->book,
- "editable", view->editable,
- NULL);
}
static void
@@ -950,7 +951,7 @@ e_addressbook_view_print(EAddressbookView *view)
EBook *book;
GtkWidget *print;
- gtk_object_get (view->object,
+ gtk_object_get (GTK_OBJECT(view->model),
"query", &query,
"book", &book,
NULL);
@@ -1006,14 +1007,5 @@ e_addressbook_view_show_all(EAddressbookView *view)
void
e_addressbook_view_stop(EAddressbookView *view)
{
- switch(view->view_type) {
- case E_ADDRESSBOOK_VIEW_MINICARD:
- e_minicard_view_widget_stop(E_MINICARD_VIEW_WIDGET (view->object));
- break;
- case E_ADDRESSBOOK_VIEW_TABLE:
- e_addressbook_model_stop(E_ADDRESSBOOK_MODEL (view->object));
- break;
- case E_ADDRESSBOOK_VIEW_NONE:
- break;
- }
+ e_addressbook_model_stop (view->model);
}
diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h
index 0c282c013a..30633c57fe 100644
--- a/addressbook/gui/widgets/e-addressbook-view.h
+++ b/addressbook/gui/widgets/e-addressbook-view.h
@@ -23,6 +23,7 @@
#include <gtk/gtktable.h>
#include <bonobo/bonobo-ui-component.h>
+#include "e-addressbook-model.h"
#include "addressbook/backend/ebook/e-book.h"
#ifdef __cplusplus
@@ -61,6 +62,8 @@ struct _EAddressbookView
/* item specific fields */
EAddressbookViewType view_type;
+ EAddressbookModel *model;
+
EBook *book;
char *query;
guint editable : 1;
diff --git a/addressbook/gui/widgets/e-minicard-view-model.c b/addressbook/gui/widgets/e-minicard-view-model.c
deleted file mode 100644
index 00c0e4fd9f..0000000000
--- a/addressbook/gui/widgets/e-minicard-view-model.c
+++ /dev/null
@@ -1,708 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- *
- * Author:
- * Christopher James Lahey <clahey@helixcode.com>
- *
- * (C) 1999 Helix Code, Inc.
- */
-
-#include <config.h>
-
-#include "e-minicard-view-model.h"
-
-#include <gal/util/e-i18n.h>
-#include <gal/util/e-util.h>
-
-#include <gal/widgets/e-unicode.h>
-#include <gal/widgets/e-font.h>
-#include <gal/widgets/e-popup-menu.h>
-#include "e-contact-save-as.h"
-#include "addressbook/printing/e-contact-print.h"
-#include "addressbook/printing/e-contact-print-envelope.h"
-
-#define PARENT_TYPE e_reflow_model_get_type()
-EReflowModelClass *parent_class;
-
-#define d(x)
-
-/*
- * EMinicardViewModel callbacks
- * These are the callbacks that define the behavior of our custom model.
- */
-static void e_minicard_view_model_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
-static void e_minicard_view_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
-
-
-enum {
- ARG_0,
- ARG_BOOK,
- ARG_QUERY,
- ARG_EDITABLE,
-};
-
-enum {
- STATUS_MESSAGE,
- DRAG_BEGIN,
- LAST_SIGNAL
-};
-
-static guint e_minicard_view_model_signals [LAST_SIGNAL] = {0, };
-
-static void
-disconnect_signals(EMinicardViewModel *model)
-{
- if (model->book_view && model->create_card_id)
- gtk_signal_disconnect(GTK_OBJECT (model->book_view),
- model->create_card_id);
- if (model->book_view && model->remove_card_id)
- gtk_signal_disconnect(GTK_OBJECT (model->book_view),
- model->remove_card_id);
- if (model->book_view && model->modify_card_id)
- gtk_signal_disconnect(GTK_OBJECT (model->book_view),
- model->modify_card_id);
- if (model->book_view && model->status_message_id)
- gtk_signal_disconnect(GTK_OBJECT (model->book_view),
- model->status_message_id);
-
- model->create_card_id = 0;
- model->remove_card_id = 0;
- model->modify_card_id = 0;
- model->status_message_id = 0;
-}
-
-static void
-remove_book_view(EMinicardViewModel *model)
-{
- disconnect_signals (model);
- if (model->book_view)
- gtk_object_unref(GTK_OBJECT(model->book_view));
-
- model->book_view = NULL;
-}
-
-static int
-count_lines (const gchar *text)
-{
- int num_lines = 1;
- gunichar unival;
-
- for (text = e_unicode_get_utf8 (text, &unival); (unival && text); text = e_unicode_get_utf8 (text, &unival)) {
- if (unival == '\n') {
- num_lines ++;
- }
- }
-
- return num_lines;
-}
-
-static int
-text_height (GnomeCanvas *canvas, const gchar *text)
-{
- EFont *font = e_font_from_gdk_font (((GtkWidget *) canvas)->style->font);
- gint height = e_font_height (font) * count_lines (text) / canvas->pixels_per_unit;
-
- e_font_unref (font);
- return height;
-}
-
-typedef struct {
- EMinicardViewModel *emvm;
- ESelectionModel *selection;
-} ModelAndSelection;
-
-static void
-model_and_selection_free (ModelAndSelection *mns)
-{
- gtk_object_unref(GTK_OBJECT(mns->emvm));
- gtk_object_unref(GTK_OBJECT(mns->selection));
- g_free(mns);
-}
-
-static void
-add_to_list (int model_row, gpointer closure)
-{
- GList **list = closure;
- *list = g_list_prepend (*list, GINT_TO_POINTER (model_row));
-}
-
-static GList *
-get_card_list (ModelAndSelection *mns)
-{
- GList *list;
- GList *iterator;
-
- list = NULL;
- e_selection_model_foreach (mns->selection, add_to_list, &list);
-
- for (iterator = list; iterator; iterator = iterator->next) {
- iterator->data = mns->emvm->data [GPOINTER_TO_INT (iterator->data)];
- }
- list = g_list_reverse (list);
- return list;
-}
-
-static void
-save_as (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list)
- e_contact_list_save_as (_("Save as VCard"), list);
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-static void
-send_as (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list)
- e_card_list_send (list, E_CARD_DISPOSITION_AS_ATTACHMENT);
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-static void
-send_to (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list)
- e_card_list_send (list, E_CARD_DISPOSITION_AS_TO);
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-static void
-print (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list)
- gtk_widget_show (e_contact_print_card_list_dialog_new (list));
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-static void
-print_envelope (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list)
- gtk_widget_show (e_contact_print_envelope_list_dialog_new (list));
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-static void
-card_changed_cb (EBook* book, EBookStatus status, gpointer user_data)
-{
- d(g_print ("%s: %s(): a card was changed with status %d\n", __FILE__, __FUNCTION__, status));
-}
-
-static void
-delete (GtkWidget *widget, ModelAndSelection *mns)
-{
- GList *list;
-
- list = get_card_list (mns);
- if (list) {
-
- if (e_contact_editor_confirm_delete(NULL)) { /*FIXME: Give a GtkWindow here. */
- GList *iterator;
- EBook *book;
-
- book = mns->emvm->book;
-
- for (iterator = list; iterator; iterator = iterator->next) {
- ECard *card = iterator->data;
-
- gtk_object_ref(GTK_OBJECT(card));
-
- e_book_remove_card (book,
- card,
- card_changed_cb,
- NULL);
-
- gtk_object_unref(GTK_OBJECT(card));
- }
- }
- }
-
- g_list_free (list);
- model_and_selection_free (mns);
-}
-
-gint
-e_minicard_view_model_right_click (EMinicardViewModel *emvm, GdkEvent *event, ESelectionModel *selection)
-{
- ModelAndSelection *mns = g_new(ModelAndSelection, 1);
- EPopupMenu menu[] = { {N_("Save as VCard"), NULL, GTK_SIGNAL_FUNC(save_as), NULL, 0},
- {N_("Send contact to other"), NULL, GTK_SIGNAL_FUNC(send_as), NULL, 0},
- {N_("Send message to contact"), NULL, GTK_SIGNAL_FUNC(send_to), NULL, 0},
- {N_("Print"), NULL, GTK_SIGNAL_FUNC(print), NULL, 0},
- {N_("Print Envelope"), NULL, GTK_SIGNAL_FUNC(print_envelope), NULL, 0},
- {N_("Delete"), NULL, GTK_SIGNAL_FUNC(delete), NULL, 0},
- {NULL, NULL, NULL, 0}};
-
- mns->emvm = emvm;
- mns->selection = selection;
- gtk_object_ref(GTK_OBJECT(mns->emvm));
- gtk_object_ref(GTK_OBJECT(mns->selection));
- e_popup_menu_run (menu, event, 0, 0, mns);
- return TRUE;
-}
-
-static void
-addressbook_destroy(GtkObject *object)
-{
- EMinicardViewModel *model = E_MINICARD_VIEW_MODEL(object);
- int i;
-
- if (model->get_view_idle)
- g_source_remove(model->get_view_idle);
-
- remove_book_view (model);
-
- g_free(model->query);
- if (model->book)
- gtk_object_unref(GTK_OBJECT(model->book));
-
- for ( i = 0; i < model->data_count; i++ ) {
- gtk_object_unref(GTK_OBJECT(model->data[i]));
- }
- g_free(model->data);
-}
-
-static void
-addressbook_set_width (EReflowModel *erm, int width)
-{
-}
-
-/* This function returns the number of items in our EReflowModel. */
-static int
-addressbook_count (EReflowModel *erm)
-{
- EMinicardViewModel *addressbook = E_MINICARD_VIEW_MODEL(erm);
- return addressbook->data_count;
-}
-
-/* This function returns the number of items in our EReflowModel. */
-static int
-addressbook_height (EReflowModel *erm, int i, GnomeCanvasGroup *parent)
-{
- /* FIXME */
- ECardSimpleField field;
- int count = 0;
- int height;
- char *string;
- EMinicardViewModel *emvm = E_MINICARD_VIEW_MODEL(erm);
- ECardSimple *simple = e_card_simple_new (emvm->data[i]);
-
- string = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FILE_AS);
- height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, string ? string : "") + 10.0;
- g_free(string);
-
- for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST - 2 && count < 5; field++) {
- if (field == E_CARD_SIMPLE_FIELD_FAMILY_NAME)
- field ++;
- string = e_card_simple_get(simple, field);
- if (string && *string) {
- int this_height;
- int field_text_height;
-
- this_height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, e_card_simple_get_name(simple, field));
-
- field_text_height = text_height (GNOME_CANVAS_ITEM (parent)->canvas, string);
- if (this_height < field_text_height)
- this_height = field_text_height;
-
- this_height += 3;
-
- height += this_height;
- count ++;
- }
- g_free (string);
- }
- height += 2;
-
- gtk_object_unref (GTK_OBJECT (simple));
-
- return height;
-}
-
-static int
-addressbook_compare (EReflowModel *erm, int n1, int n2)
-{
- ECard *card1, *card2;
- EMinicardViewModel *emvm = E_MINICARD_VIEW_MODEL(erm);
-
- card1 = emvm->data[n1];
- card2 = emvm->data[n2];
-
- if (card1 && card2) {
- char *file_as1, *file_as2;
- file_as1 = card1->file_as;
- file_as2 = card2->file_as;
- if (file_as1 && file_as2)
- return strcasecmp(file_as1, file_as2);
- if (file_as1)
- return -1;
- if (file_as2)
- return 1;
- return strcmp(e_card_get_id(card1), e_card_get_id(card2));
- }
- if (card1)
- return -1;
- if (card2)
- return 1;
- return 0;
-}
-
-static int
-minicard_drag_begin (EMinicard *card, GdkEvent *event, EMinicardViewModel *model)
-{
- gint ret_val = 0;
-
- gtk_signal_emit (GTK_OBJECT(model),
- e_minicard_view_model_signals[DRAG_BEGIN],
- event, &ret_val);
-
- return ret_val;
-}
-
-static GnomeCanvasItem *
-addressbook_incarnate (EReflowModel *erm, int i, GnomeCanvasGroup *parent)
-{
- EMinicardViewModel *emvm = E_MINICARD_VIEW_MODEL (erm);
- GnomeCanvasItem *item;
-
- item = gnome_canvas_item_new(parent,
- e_minicard_get_type(),
- "card", emvm->data[i],
- "editable", emvm->editable,
- NULL);
-
-#if 0
- gtk_signal_connect (GTK_OBJECT (item), "selected",
- GTK_SIGNAL_FUNC(card_selected), emvm);
-#endif
- gtk_signal_connect (GTK_OBJECT (item), "drag_begin",
- GTK_SIGNAL_FUNC(minicard_drag_begin), emvm);
- return item;
-}
-
-static void
-addressbook_reincarnate (EReflowModel *erm, int i, GnomeCanvasItem *item)
-{
- EMinicardViewModel *emvm = E_MINICARD_VIEW_MODEL (erm);
-
- gnome_canvas_item_set(item,
- "card", emvm->data[i],
- NULL);
-}
-
-
-
-static void
-create_card(EBookView *book_view,
- const GList *cards,
- EMinicardViewModel *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++] = cards->data;
- gtk_object_ref (cards->data);
- }
- e_reflow_model_items_inserted (E_REFLOW_MODEL (model),
- old_count,
- model->data_count - old_count);
-}
-
-static void
-remove_card(EBookView *book_view,
- const char *id,
- EMinicardViewModel *model)
-{
- int i;
- gboolean found = FALSE;
- for ( i = 0; i < model->data_count; i++) {
- 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 *));
- model->data_count --;
- found = TRUE;
- }
- }
- if (found)
- e_reflow_model_changed (E_REFLOW_MODEL (model));
-}
-
-static void
-modify_card(EBookView *book_view,
- const GList *cards,
- EMinicardViewModel *model)
-{
- for ( ; cards; cards = cards->next) {
- int i;
- for ( i = 0; i < model->data_count; i++) {
- if ( !strcmp(e_card_get_id(model->data[i]), e_card_get_id(cards->data)) ) {
- gtk_object_unref (GTK_OBJECT (model->data[i]));
- model->data[i] = cards->data;
- gtk_object_ref (GTK_OBJECT (model->data[i]));
- e_reflow_model_item_changed (E_REFLOW_MODEL (model), i);
- break;
- }
- }
- }
-}
-
-static void
-status_message (EBookView *book_view,
- char* status,
- EMinicardViewModel *model)
-{
- gtk_signal_emit (GTK_OBJECT (model),
- e_minicard_view_model_signals [STATUS_MESSAGE],
- status);
-}
-
-static void
-e_minicard_view_model_class_init (GtkObjectClass *object_class)
-{
- EReflowModelClass *model_class = (EReflowModelClass *) object_class;
-
- parent_class = gtk_type_class (PARENT_TYPE);
-
- object_class->destroy = addressbook_destroy;
- object_class->set_arg = e_minicard_view_model_set_arg;
- object_class->get_arg = e_minicard_view_model_get_arg;
-
- gtk_object_add_arg_type ("EMinicardViewModel::book", GTK_TYPE_OBJECT,
- GTK_ARG_READWRITE, ARG_BOOK);
- gtk_object_add_arg_type ("EMinicardViewModel::query", GTK_TYPE_STRING,
- GTK_ARG_READWRITE, ARG_QUERY);
- gtk_object_add_arg_type ("EMinicardViewModel::editable", GTK_TYPE_BOOL,
- GTK_ARG_READWRITE, ARG_EDITABLE);
-
- e_minicard_view_model_signals [STATUS_MESSAGE] =
- gtk_signal_new ("status_message",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (EMinicardViewModelClass, status_message),
- gtk_marshal_NONE__POINTER,
- GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
-
- e_minicard_view_model_signals [DRAG_BEGIN] =
- gtk_signal_new ("drag_begin",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (EMinicardViewModelClass, drag_begin),
- gtk_marshal_INT__POINTER,
- GTK_TYPE_INT, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER);
-
-
- gtk_object_class_add_signals (object_class, e_minicard_view_model_signals, LAST_SIGNAL);
-
- model_class->set_width = addressbook_set_width;
- model_class->count = addressbook_count;
- model_class->height = addressbook_height;
- model_class->compare = addressbook_compare;
- model_class->incarnate = addressbook_incarnate;
- model_class->reincarnate = addressbook_reincarnate;
-}
-
-static void
-e_minicard_view_model_init (GtkObject *object)
-{
- EMinicardViewModel *model = E_MINICARD_VIEW_MODEL(object);
- model->book = NULL;
- model->query = g_strdup("(contains \"x-evolution-any-field\" \"\")");
- model->book_view = NULL;
- model->get_view_idle = 0;
- model->create_card_id = 0;
- model->remove_card_id = 0;
- model->modify_card_id = 0;
- model->status_message_id = 0;
- model->data = NULL;
- model->data_count = 0;
- model->allocated_count = 0;
- model->editable = FALSE;
- model->first_get_view = TRUE;
-}
-
-static void
-book_view_loaded (EBook *book, EBookStatus status, EBookView *book_view, gpointer closure)
-{
- EMinicardViewModel *model = closure;
- int i;
- remove_book_view(model);
- model->book_view = book_view;
- if (model->book_view)
- gtk_object_ref(GTK_OBJECT(model->book_view));
- model->create_card_id = gtk_signal_connect(GTK_OBJECT(model->book_view),
- "card_added",
- GTK_SIGNAL_FUNC(create_card),
- model);
- model->remove_card_id = gtk_signal_connect(GTK_OBJECT(model->book_view),
- "card_removed",
- GTK_SIGNAL_FUNC(remove_card),
- model);
- model->modify_card_id = gtk_signal_connect(GTK_OBJECT(model->book_view),
- "card_changed",
- GTK_SIGNAL_FUNC(modify_card),
- model);
- model->status_message_id = gtk_signal_connect(GTK_OBJECT(model->book_view),
- "status_message",
- GTK_SIGNAL_FUNC(status_message),
- model);
-
- for ( i = 0; i < model->data_count; i++ ) {
- gtk_object_unref(GTK_OBJECT(model->data[i]));
- }
-
- g_free(model->data);
- model->data = NULL;
- model->data_count = 0;
- model->allocated_count = 0;
- e_reflow_model_changed(E_REFLOW_MODEL(model));
-}
-
-static gboolean
-get_view (EMinicardViewModel *model)
-{
- if (model->book && model->query) {
- if (model->first_get_view) {
- char *capabilities;
- capabilities = e_book_get_static_capabilities (model->book);
- if (capabilities && strstr (capabilities, "local")) {
- e_book_get_book_view (model->book, model->query, book_view_loaded, model);
- }
- model->first_get_view = FALSE;
- }
- else
- e_book_get_book_view (model->book, model->query, book_view_loaded, model);
- }
-
- model->get_view_idle = 0;
- return FALSE;
-}
-
-ECard *
-e_minicard_view_model_get_card(EMinicardViewModel *model,
- int row)
-{
- if (model->data && row < model->data_count) {
- gtk_object_ref(GTK_OBJECT(model->data[row]));
- return model->data[row];
- }
- return NULL;
-}
-
-static void
-e_minicard_view_model_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
-{
- EMinicardViewModel *model;
-
- model = E_MINICARD_VIEW_MODEL (o);
-
- switch (arg_id){
- case ARG_BOOK:
- if (model->book)
- gtk_object_unref(GTK_OBJECT(model->book));
- model->book = E_BOOK(GTK_VALUE_OBJECT (*arg));
- if (model->book) {
- gtk_object_ref(GTK_OBJECT(model->book));
- if (model->get_view_idle == 0)
- model->get_view_idle = g_idle_add((GSourceFunc)get_view, model);
- }
- break;
- case ARG_QUERY:
- if (model->query)
- g_free(model->query);
- model->query = g_strdup(GTK_VALUE_STRING (*arg));
- if (model->get_view_idle == 0)
- model->get_view_idle = g_idle_add((GSourceFunc)get_view, model);
- break;
- case ARG_EDITABLE:
- model->editable = GTK_VALUE_BOOL (*arg);
- break;
- }
-}
-
-static void
-e_minicard_view_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
-{
- EMinicardViewModel *e_minicard_view_model;
-
- e_minicard_view_model = E_MINICARD_VIEW_MODEL (object);
-
- switch (arg_id) {
- case ARG_BOOK:
- GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard_view_model->book);
- break;
- case ARG_QUERY:
- GTK_VALUE_STRING (*arg) = g_strdup(e_minicard_view_model->query);
- break;
- case ARG_EDITABLE:
- GTK_VALUE_BOOL (*arg) = e_minicard_view_model->editable;
- break;
- default:
- arg->type = GTK_TYPE_INVALID;
- break;
- }
-}
-
-GtkType
-e_minicard_view_model_get_type (void)
-{
- static GtkType type = 0;
-
- if (!type){
- GtkTypeInfo info = {
- "EMinicardViewModel",
- sizeof (EMinicardViewModel),
- sizeof (EMinicardViewModelClass),
- (GtkClassInitFunc) e_minicard_view_model_class_init,
- (GtkObjectInitFunc) e_minicard_view_model_init,
- NULL, /* reserved 1 */
- NULL, /* reserved 2 */
- (GtkClassInitFunc) NULL
- };
-
- type = gtk_type_unique (PARENT_TYPE, &info);
- }
-
- return type;
-}
-
-EReflowModel *
-e_minicard_view_model_new (void)
-{
- EMinicardViewModel *et;
-
- et = gtk_type_new (e_minicard_view_model_get_type ());
-
- return E_REFLOW_MODEL(et);
-}
-
-void e_minicard_view_model_stop (EMinicardViewModel *model)
-{
- remove_book_view(model);
-}
diff --git a/addressbook/gui/widgets/e-minicard-view-model.h b/addressbook/gui/widgets/e-minicard-view-model.h
deleted file mode 100644
index c958a81690..0000000000
--- a/addressbook/gui/widgets/e-minicard-view-model.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-#ifndef _E_MINICARD_VIEW_MODEL_H_
-#define _E_MINICARD_VIEW_MODEL_H_
-
-#include <gal/widgets/e-reflow-model.h>
-#include <gal/widgets/e-selection-model.h>
-#include "e-minicard.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_MINICARD_VIEW_MODEL_TYPE (e_minicard_view_model_get_type ())
-#define E_MINICARD_VIEW_MODEL(o) (GTK_CHECK_CAST ((o), E_MINICARD_VIEW_MODEL_TYPE, EMinicardViewModel))
-#define E_MINICARD_VIEW_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_MINICARD_VIEW_MODEL_TYPE, EMinicardViewModelClass))
-#define E_IS_MINICARD_VIEW_MODEL(o) (GTK_CHECK_TYPE ((o), E_MINICARD_VIEW_MODEL_TYPE))
-#define E_IS_MINICARD_VIEW_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_MINICARD_VIEW_MODEL_TYPE))
-
-/* Virtual Column list:
- 0 Email
- 1 Full Name
- 2 Street
- 3 Phone
-*/
-
-typedef struct _EMinicardViewModel EMinicardViewModel;
-typedef struct _EMinicardViewModelClass EMinicardViewModelClass;
-
-struct _EMinicardViewModel {
- EReflowModel parent;
-
- /* item specific fields */
- EBook *book;
- char *query;
- EBookView *book_view;
-
- int get_view_idle;
-
- ECard **data;
- int data_count;
- int allocated_count;
-
- int create_card_id, remove_card_id, modify_card_id, status_message_id;
-
- guint editable : 1;
- guint first_get_view : 1;
-};
-
-
-struct _EMinicardViewModelClass {
- EReflowModelClass parent_class;
-
- /*
- * Signals
- */
- void (*status_message) (EMinicardViewModel *model, const gchar *message);
- gint (* drag_begin) (EMinicardViewModel *model, GdkEvent *event);
-};
-
-
-GtkType e_minicard_view_model_get_type (void);
-EReflowModel *e_minicard_view_model_new (void);
-
-/* Returns object with ref count of 1. */
-ECard *e_minicard_view_model_get_card (EMinicardViewModel *model,
- int row);
-void e_minicard_view_model_stop (EMinicardViewModel *model);
-gint e_minicard_view_model_right_click (EMinicardViewModel *emvm,
- GdkEvent *event,
- ESelectionModel *selection);
-
-#endif /* _E_MINICARD_VIEW_MODEL_H_ */
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.c b/addressbook/gui/widgets/e-minicard-view-widget.c
index 5a4e3d2d06..8944f2118c 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.c
+++ b/addressbook/gui/widgets/e-minicard-view-widget.c
@@ -47,14 +47,6 @@ enum {
ARG_EDITABLE
};
-enum {
- STATUS_MESSAGE,
- LAST_SIGNAL
-};
-
-static guint e_minicard_view_widget_signals [LAST_SIGNAL] = {0, };
-
-
GtkType
e_minicard_view_widget_get_type (void)
{
@@ -100,16 +92,6 @@ e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass)
gtk_object_add_arg_type ("EMinicardViewWidget::editable", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_EDITABLE);
- e_minicard_view_widget_signals [STATUS_MESSAGE] =
- gtk_signal_new ("status_message",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (EMinicardViewWidgetClass, status_message),
- gtk_marshal_NONE__POINTER,
- GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
-
- gtk_object_class_add_signals (object_class, e_minicard_view_widget_signals, LAST_SIGNAL);
-
object_class->set_arg = e_minicard_view_widget_set_arg;
object_class->get_arg = e_minicard_view_widget_get_arg;
object_class->destroy = e_minicard_view_widget_destroy;
@@ -132,9 +114,13 @@ e_minicard_view_widget_init (EMinicardViewWidget *view)
}
GtkWidget *
-e_minicard_view_widget_new (void)
+e_minicard_view_widget_new (EAddressbookReflowAdapter *adapter)
{
- return GTK_WIDGET (gtk_type_new (e_minicard_view_widget_get_type ()));
+ EMinicardViewWidget *widget = E_MINICARD_VIEW_WIDGET (gtk_type_new (e_minicard_view_widget_get_type ()));
+
+ widget->adapter = adapter;
+
+ return GTK_WIDGET (widget);
}
static void
@@ -212,16 +198,6 @@ e_minicard_view_widget_destroy (GtkObject *object)
}
static void
-status_message (EMinicardView *mini_view,
- char* status,
- EMinicardViewWidget *view)
-{
- gtk_signal_emit (GTK_OBJECT (view),
- e_minicard_view_widget_signals [STATUS_MESSAGE],
- status);
-}
-
-static void
e_minicard_view_widget_realize (GtkWidget *widget)
{
EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET(widget);
@@ -243,15 +219,8 @@ e_minicard_view_widget_realize (GtkWidget *widget)
"minimum_width", (double) 100,
NULL );
- gtk_signal_connect(GTK_OBJECT(view->emv),
- "status_message",
- GTK_SIGNAL_FUNC(status_message),
- view);
-
gtk_object_set(GTK_OBJECT(view->emv),
- "book", view->book,
- "query", view->query,
- "editable", view->editable,
+ "adapter", view->adapter,
NULL);
if (GTK_WIDGET_CLASS(parent_class)->realize)
@@ -321,9 +290,3 @@ void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view,
if (view->emv)
e_minicard_view_jump_to_letter(E_MINICARD_VIEW(view->emv), letter);
}
-
-void
-e_minicard_view_widget_stop(EMinicardViewWidget *view)
-{
- e_minicard_view_stop(E_MINICARD_VIEW(view->emv));
-}
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.h b/addressbook/gui/widgets/e-minicard-view-widget.h
index e22d651826..db37d1631a 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.h
+++ b/addressbook/gui/widgets/e-minicard-view-widget.h
@@ -47,6 +47,8 @@ struct _EMinicardViewWidget
GnomeCanvasItem *rect;
GnomeCanvasItem *emv;
+ EAddressbookReflowAdapter *adapter;
+
EBook *book;
char *query;
guint editable : 1;
@@ -55,11 +57,6 @@ struct _EMinicardViewWidget
struct _EMinicardViewWidgetClass
{
ECanvasClass parent_class;
-
- /*
- * Signals
- */
- void (*status_message) (EMinicardView *mini_view, const gchar *message);
};
GtkType e_minicard_view_widget_get_type (void);
@@ -68,9 +65,7 @@ void e_minicard_view_widget_remove_selection (EMinicardViewWidget *view,
gpointer closure);
void e_minicard_view_widget_jump_to_letter (EMinicardViewWidget *view,
char letter);
-void e_minicard_view_widget_stop (EMinicardViewWidget *view);
-
-GtkWidget *e_minicard_view_widget_new (void);
+GtkWidget *e_minicard_view_widget_new (EAddressbookReflowAdapter *adapter);
#ifdef __cplusplus
}
diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c
index 3a89978756..d8b3c73d9a 100644
--- a/addressbook/gui/widgets/e-minicard-view.c
+++ b/addressbook/gui/widgets/e-minicard-view.c
@@ -33,6 +33,7 @@
#include <libgnome/gnome-i18n.h>
static void canvas_destroy (GtkObject *object, EMinicardView *view);
+
static void e_minicard_view_drag_data_get(GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
@@ -46,16 +47,12 @@ static EReflowClass *parent_class = NULL;
/* The arguments we take */
enum {
ARG_0,
+ ARG_ADAPTER,
ARG_BOOK,
ARG_QUERY,
ARG_EDITABLE
};
-enum {
- STATUS_MESSAGE,
- LAST_SIGNAL
-};
-
enum DndTargetType {
DND_TARGET_TYPE_VCARD_LIST,
};
@@ -65,8 +62,6 @@ static GtkTargetEntry drag_types[] = {
};
static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]);
-static guint e_minicard_view_signals [LAST_SIGNAL] = {0, };
-
static void
e_minicard_view_drag_data_get(GtkWidget *widget,
GdkDragContext *context,
@@ -99,22 +94,22 @@ e_minicard_view_drag_data_get(GtkWidget *widget,
typedef struct {
GList *list;
- EMinicardViewModel *model;
+ EAddressbookReflowAdapter *adapter;
} ModelAndList;
static void
add_to_list (int index, gpointer closure)
{
ModelAndList *mal = closure;
- mal->list = g_list_prepend (mal->list, e_minicard_view_model_get_card (mal->model, index));
+ mal->list = g_list_prepend (mal->list, e_addressbook_reflow_adapter_get_card (mal->adapter, index));
}
static GList *
-get_card_list (EMinicardViewModel *model, ESelectionModel *selection)
+get_card_list (EAddressbookReflowAdapter *adapter, ESelectionModel *selection)
{
ModelAndList mal;
- mal.model = model;
+ mal.adapter = adapter;
mal.list = NULL;
e_selection_model_foreach (selection, add_to_list, &mal);
@@ -124,13 +119,13 @@ get_card_list (EMinicardViewModel *model, ESelectionModel *selection)
}
static int
-e_minicard_view_drag_begin (EMinicardViewModel *model, GdkEvent *event, EMinicardView *view)
+e_minicard_view_drag_begin (EAddressbookReflowAdapter *adapter, GdkEvent *event, EMinicardView *view)
{
GdkDragContext *context;
GtkTargetList *target_list;
GdkDragAction actions = GDK_ACTION_MOVE;
- view->drag_list = get_card_list (model, E_REFLOW (view)->selection);
+ view->drag_list = get_card_list (adapter, E_REFLOW (view)->selection);
g_print ("dragging %d card(s)\n", g_list_length (view->drag_list));
@@ -150,18 +145,6 @@ e_minicard_view_drag_begin (EMinicardViewModel *model, GdkEvent *event, EMinicar
return TRUE;
}
-#if 0
-static void
-status_message (EBookView *book_view,
- char* status,
- EMinicardView *view)
-{
- gtk_signal_emit (GTK_OBJECT (view),
- e_minicard_view_signals [STATUS_MESSAGE],
- status);
-}
-#endif
-
static void
card_added_cb (EBook* book, EBookStatus status, const char *id,
gpointer user_data)
@@ -211,7 +194,7 @@ supported_fields_cb (EBook *book, EBookStatus status, EList *fields, EMinicardVi
card = e_card_new("");
- gtk_object_get (GTK_OBJECT (view->model),
+ gtk_object_get (GTK_OBJECT (view->adapter),
"editable", &editable,
NULL);
@@ -228,6 +211,25 @@ supported_fields_cb (EBook *book, EBookStatus status, EList *fields, EMinicardVi
}
static void
+adapter_changed (EMinicardView *view)
+{
+ char *empty_message;
+
+ view->canvas_drag_data_get_id = 0;
+
+ empty_message = e_utf8_from_locale_string(_("\n\nThere are no items to show in this view\n\n"
+ "Double-click here to create a new Contact."));
+ gtk_object_set (GTK_OBJECT(view),
+ "empty_message", empty_message,
+ NULL);
+
+ gtk_signal_connect (GTK_OBJECT (view->adapter), "drag_begin",
+ GTK_SIGNAL_FUNC (e_minicard_view_drag_begin), view);
+
+ g_free (empty_message);
+}
+
+static void
e_minicard_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
@@ -237,18 +239,28 @@ e_minicard_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
view = E_MINICARD_VIEW (o);
switch (arg_id){
+ case ARG_ADAPTER:
+ if (view->adapter)
+ gtk_object_unref (GTK_OBJECT(view->adapter));
+ view->adapter = GTK_VALUE_POINTER (*arg);
+ gtk_object_ref (GTK_OBJECT (view->adapter));
+ adapter_changed (view);
+ gtk_object_set (GTK_OBJECT (view),
+ "model", view->adapter,
+ NULL);
+ break;
case ARG_BOOK:
- gtk_object_set (GTK_OBJECT (view->model),
+ gtk_object_set (GTK_OBJECT (view->adapter),
"book", GTK_VALUE_OBJECT (*arg),
NULL);
break;
case ARG_QUERY:
- gtk_object_set (GTK_OBJECT (view->model),
+ gtk_object_set (GTK_OBJECT (view->adapter),
"query", GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_EDITABLE:
- gtk_object_set (GTK_OBJECT (view->model),
+ gtk_object_set (GTK_OBJECT (view->adapter),
"editable", GTK_VALUE_BOOL (*arg),
NULL);
break;
@@ -263,19 +275,21 @@ e_minicard_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
view = E_MINICARD_VIEW (object);
switch (arg_id) {
+ case ARG_ADAPTER:
+ GTK_VALUE_POINTER (*arg) = view->adapter;
+ break;
case ARG_BOOK:
- gtk_object_get (GTK_OBJECT (view->model),
+ gtk_object_get (GTK_OBJECT (view->adapter),
"book", &GTK_VALUE_OBJECT (*arg),
NULL);
break;
- break;
case ARG_QUERY:
- gtk_object_get (GTK_OBJECT (view->model),
+ gtk_object_get (GTK_OBJECT (view->adapter),
"query", &GTK_VALUE_STRING (*arg),
NULL);
break;
case ARG_EDITABLE:
- gtk_object_get (GTK_OBJECT (view->model),
+ gtk_object_get (GTK_OBJECT (view->adapter),
"editable", &GTK_VALUE_BOOL (*arg),
NULL);
break;
@@ -291,7 +305,7 @@ e_minicard_view_destroy (GtkObject *object)
EMinicardView *view = E_MINICARD_VIEW(object);
- gtk_object_unref (GTK_OBJECT (view->model));
+ gtk_object_unref (GTK_OBJECT (view->adapter));
GTK_OBJECT_CLASS(parent_class)->destroy (object);
}
@@ -341,7 +355,7 @@ e_minicard_view_selection_event (EReflow *reflow, GnomeCanvasItem *item, GdkEven
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 3) {
- return_val = e_minicard_view_model_right_click (view->model, event, reflow->selection);
+ return_val = e_addressbook_reflow_adapter_right_click (view->adapter, event, reflow->selection);
}
break;
default:
@@ -353,15 +367,10 @@ e_minicard_view_selection_event (EReflow *reflow, GnomeCanvasItem *item, GdkEven
static void
disconnect_signals(EMinicardView *view)
{
- if (view->model && view->status_message_id)
- gtk_signal_disconnect(GTK_OBJECT (view->model),
- view->status_message_id);
-
if (view->canvas_drag_data_get_id)
gtk_signal_disconnect(GTK_OBJECT (GNOME_CANVAS_ITEM (view)->canvas),
- view->status_message_id);
+ view->canvas_drag_data_get_id);
- view->status_message_id = 0;
view->canvas_drag_data_get_id = 0;
}
@@ -382,15 +391,22 @@ typedef struct {
static void
do_remove (int i, gpointer user_data)
{
+ EBook *book;
ECard *card;
ViewCbClosure *viewcbclosure = user_data;
EMinicardView *view = viewcbclosure->view;
EBookCallback cb = viewcbclosure->cb;
gpointer closure = viewcbclosure->closure;
- gtk_object_get(GTK_OBJECT(view->model->data[i]),
- "card", &card,
- NULL);
- e_book_remove_card(view->model->book, card, cb, closure);
+
+ gtk_object_get (GTK_OBJECT(view->adapter),
+ "book", &book,
+ NULL);
+
+ card = e_addressbook_reflow_adapter_get_card (view->adapter, i);
+
+ e_book_remove_card(book, card, cb, closure);
+
+ gtk_object_unref (GTK_OBJECT (card));
}
void
@@ -446,14 +462,6 @@ e_minicard_view_jump_to_letter (EMinicardView *view,
#endif
}
-void
-e_minicard_view_stop (EMinicardView *view)
-{
- e_minicard_view_model_stop (view->model);
- disconnect_signals(view);
-}
-
-
static void
e_minicard_view_class_init (EMinicardViewClass *klass)
{
@@ -467,6 +475,8 @@ e_minicard_view_class_init (EMinicardViewClass *klass)
parent_class = gtk_type_class (PARENT_TYPE);
+ gtk_object_add_arg_type ("EMinicardView::adapter", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_ADAPTER);
gtk_object_add_arg_type ("EMinicardView::book", GTK_TYPE_OBJECT,
GTK_ARG_READWRITE, ARG_BOOK);
gtk_object_add_arg_type ("EMinicardView::query", GTK_TYPE_STRING,
@@ -474,16 +484,6 @@ e_minicard_view_class_init (EMinicardViewClass *klass)
gtk_object_add_arg_type ("EMinicardView::editable", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_EDITABLE);
- e_minicard_view_signals [STATUS_MESSAGE] =
- gtk_signal_new ("status_message",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (EMinicardViewClass, status_message),
- gtk_marshal_NONE__POINTER,
- GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
-
- gtk_object_class_add_signals (object_class, e_minicard_view_signals, LAST_SIGNAL);
-
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;
@@ -497,24 +497,7 @@ e_minicard_view_class_init (EMinicardViewClass *klass)
static void
e_minicard_view_init (EMinicardView *view)
{
- char *empty_message;
-
- view->model = E_MINICARD_VIEW_MODEL(e_minicard_view_model_new());
-
- view->canvas_drag_data_get_id = 0;
- view->status_message_id = 0;
-
- empty_message = e_utf8_from_locale_string(_("\n\nThere are no items to show in this view\n\n"
- "Double-click here to create a new Contact."));
- gtk_object_set (GTK_OBJECT(view),
- "empty_message", empty_message,
- "model", view->model,
- NULL);
-
- gtk_signal_connect (GTK_OBJECT (view->model), "drag_begin",
- GTK_SIGNAL_FUNC (e_minicard_view_drag_begin), view);
-
- g_free (empty_message);
+ view->adapter = NULL;
}
GtkType
diff --git a/addressbook/gui/widgets/e-minicard-view.h b/addressbook/gui/widgets/e-minicard-view.h
index 318989958b..8f8f5ab2aa 100644
--- a/addressbook/gui/widgets/e-minicard-view.h
+++ b/addressbook/gui/widgets/e-minicard-view.h
@@ -22,11 +22,11 @@
#define __E_MINICARD_VIEW_H__
#include "e-minicard.h"
-#include "e-minicard-view-model.h"
#include <gal/widgets/e-reflow.h>
#include <gal/widgets/e-selection-model-simple.h>
#include "addressbook/backend/ebook/e-book.h"
+#include "e-addressbook-reflow-adapter.h"
#ifdef __cplusplus
extern "C" {
@@ -66,7 +66,7 @@ struct _EMinicardView
{
EReflow parent;
- EMinicardViewModel *model;
+ EAddressbookReflowAdapter *adapter;
/* item specific fields */
@@ -83,11 +83,6 @@ struct _EMinicardView
struct _EMinicardViewClass
{
EReflowClass parent_class;
-
- /*
- * Signals
- */
- void (*status_message) (EMinicardView *mini_view, const gchar *message);
};
GtkType e_minicard_view_get_type (void);
@@ -96,7 +91,6 @@ void e_minicard_view_remove_selection (EMinicardView *view,
gpointer closure);
void e_minicard_view_jump_to_letter (EMinicardView *view,
char letter);
-void e_minicard_view_stop (EMinicardView *view);
#ifdef __cplusplus
}