aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/Makefile.am2
-rw-r--r--addressbook/backend/ebook/e-card-iterator.c4
-rw-r--r--addressbook/backend/ebook/e-card-iterator.h22
-rw-r--r--addressbook/backend/ebook/e-card-list-iterator.c10
-rw-r--r--addressbook/backend/ebook/e-card-list.c4
-rw-r--r--addressbook/backend/ebook/e-card-list.h6
-rw-r--r--addressbook/backend/ebook/e-card.c33
-rw-r--r--addressbook/backend/ebook/e-card.h6
-rw-r--r--addressbook/demo/Makefile.am12
-rw-r--r--addressbook/demo/e-test-model.c312
-rw-r--r--addressbook/demo/e-test-model.h20
11 files changed, 263 insertions, 168 deletions
diff --git a/addressbook/Makefile.am b/addressbook/Makefile.am
index d360f7b5d7..8e421f8e2d 100644
--- a/addressbook/Makefile.am
+++ b/addressbook/Makefile.am
@@ -1,2 +1,2 @@
SUBDIRS = \
- contact-editor printing demo backend
+ backend contact-editor printing demo
diff --git a/addressbook/backend/ebook/e-card-iterator.c b/addressbook/backend/ebook/e-card-iterator.c
index df4cb5a4a4..0d666e649f 100644
--- a/addressbook/backend/ebook/e-card-iterator.c
+++ b/addressbook/backend/ebook/e-card-iterator.c
@@ -100,7 +100,7 @@ e_card_iterator_init (ECardIterator *card)
/*
* Virtual functions:
*/
-void *
+const void *
e_card_iterator_get (ECardIterator *iterator)
{
if (ECI_CLASS(iterator)->get)
@@ -143,7 +143,7 @@ e_card_iterator_delete (ECardIterator *iterator)
void
e_card_iterator_set (ECardIterator *iterator,
- void *object)
+ const void *object)
{
if (ECI_CLASS(iterator)->set)
ECI_CLASS(iterator)->set(iterator, object);
diff --git a/addressbook/backend/ebook/e-card-iterator.h b/addressbook/backend/ebook/e-card-iterator.h
index 4b5aaf55b7..9d657e03ef 100644
--- a/addressbook/backend/ebook/e-card-iterator.h
+++ b/addressbook/backend/ebook/e-card-iterator.h
@@ -31,26 +31,26 @@ struct _ECardIteratorClass {
GtkObjectClass parent_class;
/* Signals */
- void (*invalidate) (ECardIterator *iterator);
+ void (*invalidate) (ECardIterator *iterator);
/* Virtual functions */
- void * (*get) (ECardIterator *iterator);
- void (*reset) (ECardIterator *iterator);
- gboolean (*next) (ECardIterator *iterator);
- gboolean (*prev) (ECardIterator *iterator);
- void (*delete) (ECardIterator *iterator);
- void (*set) (ECardIterator *iterator,
- void *object);
- gboolean (*is_valid) (ECardIterator *iterator);
+ const void * (*get) (ECardIterator *iterator);
+ void (*reset) (ECardIterator *iterator);
+ gboolean (*next) (ECardIterator *iterator);
+ gboolean (*prev) (ECardIterator *iterator);
+ void (*delete) (ECardIterator *iterator);
+ void (*set) (ECardIterator *iterator,
+ const void *object);
+ gboolean (*is_valid) (ECardIterator *iterator);
};
-void *e_card_iterator_get (ECardIterator *iterator);
+const void *e_card_iterator_get (ECardIterator *iterator);
void e_card_iterator_reset (ECardIterator *iterator);
gboolean e_card_iterator_next (ECardIterator *iterator);
gboolean e_card_iterator_prev (ECardIterator *iterator);
void e_card_iterator_delete (ECardIterator *iterator);
void e_card_iterator_set (ECardIterator *iterator,
- void *object);
+ const void *object);
gboolean e_card_iterator_is_valid (ECardIterator *iterator);
void e_card_iterator_invalidate (ECardIterator *iterator);
diff --git a/addressbook/backend/ebook/e-card-list-iterator.c b/addressbook/backend/ebook/e-card-list-iterator.c
index e6d9a9c040..e3426ddc3b 100644
--- a/addressbook/backend/ebook/e-card-list-iterator.c
+++ b/addressbook/backend/ebook/e-card-list-iterator.c
@@ -19,12 +19,12 @@ static void e_card_list_iterator_class_init (ECardListIteratorClass *klass);
static void e_card_list_iterator_invalidate (ECardIterator *iterator);
static gboolean e_card_list_iterator_is_valid (ECardIterator *iterator);
static void e_card_list_iterator_set (ECardIterator *iterator,
- void *object);
+ const void *object);
static void e_card_list_iterator_delete (ECardIterator *iterator);
static gboolean e_card_list_iterator_prev (ECardIterator *iterator);
static gboolean e_card_list_iterator_next (ECardIterator *iterator);
static void e_card_list_iterator_reset (ECardIterator *iterator);
-static void *e_card_list_iterator_get (ECardIterator *iterator);
+static const void *e_card_list_iterator_get (ECardIterator *iterator);
static void e_card_list_iterator_destroy (GtkObject *object);
#define PARENT_TYPE (e_card_iterator_get_type ())
@@ -120,7 +120,7 @@ e_card_list_iterator_destroy (GtkObject *object)
gtk_object_unref(GTK_OBJECT(iterator->list));
}
-static void *
+static const void *
e_card_list_iterator_get (ECardIterator *_iterator)
{
ECardListIterator *iterator = E_CARD_LIST_ITERATOR(_iterator);
@@ -171,7 +171,7 @@ e_card_list_iterator_delete (ECardIterator *_iterator)
static void
e_card_list_iterator_set (ECardIterator *_iterator,
- void *object)
+ const void *object)
{
ECardListIterator *iterator = E_CARD_LIST_ITERATOR(_iterator);
if (iterator->iterator) {
@@ -180,7 +180,7 @@ e_card_list_iterator_set (ECardIterator *_iterator,
if (iterator->list->copy)
iterator->iterator->data = iterator->list->copy(object, iterator->list->closure);
else
- iterator->iterator->data = object;
+ iterator->iterator->data = (void *) object;
}
}
diff --git a/addressbook/backend/ebook/e-card-list.c b/addressbook/backend/ebook/e-card-list.c
index 641f5b1f0a..d4965b77d5 100644
--- a/addressbook/backend/ebook/e-card-list.c
+++ b/addressbook/backend/ebook/e-card-list.c
@@ -96,13 +96,13 @@ e_card_list_get_iterator (ECardList *list)
}
void
-e_card_list_append (ECardList *list, void *data)
+e_card_list_append (ECardList *list, const void *data)
{
e_card_list_invalidate_iterators(list, NULL);
if (list->copy)
list->list = g_list_append(list->list, list->copy(data, list->closure));
else
- list->list = g_list_append(list->list, data);
+ list->list = g_list_append(list->list, (void *) data);
}
void
diff --git a/addressbook/backend/ebook/e-card-list.h b/addressbook/backend/ebook/e-card-list.h
index 123d890e88..7ceeef1993 100644
--- a/addressbook/backend/ebook/e-card-list.h
+++ b/addressbook/backend/ebook/e-card-list.h
@@ -21,8 +21,8 @@
#define E_IS_CARD_LIST(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_CARD_LIST))
#define E_IS_CARD_LIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_CARD_LIST))
-typedef void *(*ECardListCopyFunc) (void *data, void *closure);
-typedef void *(*ECardListFreeFunc) (void *data, void *closure);
+typedef void *(*ECardListCopyFunc) (const void *data, void *closure);
+typedef void (*ECardListFreeFunc) (void *data, void *closure);
typedef struct _ECardList ECardList;
typedef struct _ECardListClass ECardListClass;
@@ -45,7 +45,7 @@ ECardList *e_card_list_new (ECardListCopyFunc copy,
void *closure);
ECardIterator *e_card_list_get_iterator (ECardList *list);
void e_card_list_append (ECardList *list,
- void *data);
+ const void *data);
/* For iterators to call. */
void e_card_list_invalidate_iterators (ECardList *list,
diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c
index ba55ffc2f7..0ec6105a95 100644
--- a/addressbook/backend/ebook/e-card.c
+++ b/addressbook/backend/ebook/e-card.c
@@ -62,11 +62,6 @@ static void set_phone_flags (VObject *vobj, ECardPhoneFlags flags);
static ECardAddressFlags get_address_flags (VObject *vobj);
static void set_address_flags (VObject *vobj, ECardAddressFlags flags);
-static void e_card_phone_free (ECardPhone *phone);
-static ECardPhone *e_card_phone_copy (ECardPhone *phone);
-static void e_card_delivery_address_free (ECardDeliveryAddress *addr);
-static ECardDeliveryAddress *e_card_delivery_address_copy (ECardDeliveryAddress *addr);
-
typedef void (* ParsePropertyFunc) (ECard *card, VObject *object);
struct {
@@ -502,7 +497,7 @@ e_card_class_init (ECardClass *klass)
object_class->set_arg = e_card_set_arg;
}
-static void
+void
e_card_phone_free (ECardPhone *phone)
{
if ( phone ) {
@@ -512,8 +507,8 @@ e_card_phone_free (ECardPhone *phone)
}
}
-static ECardPhone *
-e_card_phone_copy (ECardPhone *phone)
+ECardPhone *
+e_card_phone_copy (const ECardPhone *phone)
{
if ( phone ) {
ECardPhone *phone_copy = g_new(ECardPhone, 1);
@@ -524,7 +519,7 @@ e_card_phone_copy (ECardPhone *phone)
return NULL;
}
-static void
+void
e_card_delivery_address_free (ECardDeliveryAddress *addr)
{
if ( addr ) {
@@ -546,8 +541,8 @@ e_card_delivery_address_free (ECardDeliveryAddress *addr)
}
}
-static ECardDeliveryAddress *
-e_card_delivery_address_copy (ECardDeliveryAddress *addr)
+ECardDeliveryAddress *
+e_card_delivery_address_copy (const ECardDeliveryAddress *addr)
{
if ( addr ) {
ECardDeliveryAddress *addr_copy = g_new(ECardDeliveryAddress, 1);
@@ -642,17 +637,17 @@ e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->address);
break;
case ARG_PHONE:
- if (!card->address)
- card->address = e_card_list_new((ECardListCopyFunc) e_card_phone_copy,
- (ECardListFreeFunc) e_card_phone_free,
- NULL);
+ if (!card->phone)
+ card->phone = e_card_list_new((ECardListCopyFunc) e_card_phone_copy,
+ (ECardListFreeFunc) e_card_phone_free,
+ NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->phone);
break;
case ARG_EMAIL:
- if (!card->address)
- card->address = e_card_list_new((ECardListCopyFunc) g_strdup,
- (ECardListFreeFunc) g_free,
- NULL);
+ if (!card->email)
+ card->email = e_card_list_new((ECardListCopyFunc) g_strdup,
+ (ECardListFreeFunc) g_free,
+ NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->email);
break;
case ARG_BIRTH_DATE:
diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h
index 3d2af18c55..a8e1324b20 100644
--- a/addressbook/backend/ebook/e-card.h
+++ b/addressbook/backend/ebook/e-card.h
@@ -90,6 +90,12 @@ char *e_card_get_id (ECard *card);
void e_card_set_id (ECard *card, const gchar *character);
char *e_card_get_vcard (ECard *card);
+void e_card_phone_free (ECardPhone *phone);
+ECardPhone *e_card_phone_copy (const ECardPhone *phone);
+void e_card_delivery_address_free (ECardDeliveryAddress *addr);
+ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr);
+
+
/* Standard Gtk function */
GtkType e_card_get_type (void);
diff --git a/addressbook/demo/Makefile.am b/addressbook/demo/Makefile.am
index 4a7f39a503..84869488cc 100644
--- a/addressbook/demo/Makefile.am
+++ b/addressbook/demo/Makefile.am
@@ -6,6 +6,7 @@ INCLUDES = \
-I$(top_srcdir)/widgets/e-table \
-I$(top_srcdir) \
-I$(top_srcdir)/widgets/e-minicard \
+ -I$(top_srcdir)/addressbook/backend/ebook \
$(BONOBO_HTML_GNOME_CFLAGS) \
-DEVOLUTION_VERSION=\""$(VERSION)"\" \
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
@@ -23,10 +24,13 @@ test_addressbook_SOURCES = \
test_addressbook_LDADD = \
$(EXTRA_GNOME_LIBS) \
+ $(BONOBO_HTML_GNOME_LIBS) \
$(top_builddir)/widgets/e-minicard/libeminicard.a \
$(top_builddir)/widgets/e-table/libetable.a \
$(top_builddir)/widgets/e-text/libetext.a \
- $(top_builddir)/e-util/libeutil.la
+ $(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/addressbook/backend/ebook/libebook.la \
+ $(top_builddir)/libversit/libversit.la
test_addressbook_LDFLAGS = `gnome-config --libs gdk_pixbuf`
@@ -43,12 +47,14 @@ evolution_addressbook_SOURCES = \
e-test-model.h
evolution_addressbook_LDADD = \
- $(EXTRA_GNOME_LIBS) \
+ $(EXTRA_GNOME_LIBS) \
$(BONOBO_HTML_GNOME_LIBS) \
$(top_builddir)/widgets/e-minicard/libeminicard.a \
$(top_builddir)/widgets/e-table/libetable.a \
$(top_builddir)/widgets/e-text/libetext.a \
- $(top_builddir)/e-util/libeutil.la
+ $(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/addressbook/backend/ebook/libebook.la \
+ $(top_builddir)/libversit/libversit.la
evolution_addressbook_LDFLAGS = `gnome-config --libs gdk_pixbuf`
diff --git a/addressbook/demo/e-test-model.c b/addressbook/demo/e-test-model.c
index c218283e48..941e1c006f 100644
--- a/addressbook/demo/e-test-model.c
+++ b/addressbook/demo/e-test-model.c
@@ -17,7 +17,7 @@
#define PARENT_TYPE e_table_model_get_type()
/*
* ETestModel callbacks
- * These are the callbacks that define the behavior of our custom model.
+n * These are the callbacks that define the behavior of our custom model.
*/
static void
@@ -25,15 +25,15 @@ test_destroy(GtkObject *object)
{
ETestModel *model = E_TEST_MODEL(object);
int i;
+ if (model->book)
+ gtk_object_unref(GTK_OBJECT(model->book));
+ if (model->book_view)
+ gtk_object_unref(GTK_OBJECT(model->book_view));
for ( i = 0; i < model->data_count; i++ ) {
- g_free(model->data[i]->email);
- g_free(model->data[i]->full_name);
- g_free(model->data[i]->street);
- g_free(model->data[i]->phone);
- g_free(model->data[i]);
+ gtk_object_unref(GTK_OBJECT(model->data[i]));
}
g_free(model->data);
- g_free(model->filename);
+ g_free(model->uri);
}
/* This function returns the number of columns in our ETableModel. */
@@ -56,17 +56,54 @@ static void *
test_value_at (ETableModel *etc, int col, int row)
{
ETestModel *test = E_TEST_MODEL(etc);
+ ECardList *list;
+ ECardIterator *iterator;
+ gchar *string;
if ( col >= LAST_COL || row >= test->data_count )
return NULL;
switch (col) {
case EMAIL:
- return test->data[row]->email;
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "email", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_get(iterator))
+ return (void *) e_card_iterator_get(iterator);
+ else
+ return "";
+ gtk_object_unref(GTK_OBJECT(iterator));
+ break;
case FULL_NAME:
- return test->data[row]->full_name;
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "full_name", &string,
+ NULL);
+ if (string)
+ return string;
+ else
+ return "";
+ break;
case STREET:
- return test->data[row]->street;
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "street", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_get(iterator))
+ return ((ECardDeliveryAddress *)e_card_iterator_get(iterator))->street;
+ else
+ return "";
+ gtk_object_unref(GTK_OBJECT(iterator));
+ break;
case PHONE:
- return test->data[row]->phone;
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "phone", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_get(iterator))
+ return ((ECardPhone *)e_card_iterator_get(iterator))->number;
+ else
+ return "";
+ gtk_object_unref(GTK_OBJECT(iterator));
+ break;
default:
return NULL;
}
@@ -77,28 +114,80 @@ static void
test_set_value_at (ETableModel *etc, int col, int row, const void *val)
{
ETestModel *test = E_TEST_MODEL(etc);
+ ECardList *list;
+ ECardIterator *iterator;
if ( col >= LAST_COL || row >= test->data_count )
return;
switch (col) {
case EMAIL:
- g_free (test->data[row]->email);
- test->data[row]->email = g_strdup (val);
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "email", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_is_valid(iterator)) {
+ e_card_iterator_set(iterator, val);
+ } else {
+ e_card_list_append(list, val);
+ }
+ gtk_object_unref(GTK_OBJECT(iterator));
break;
case FULL_NAME:
- g_free (test->data[row]->full_name);
- test->data[row]->full_name = g_strdup (val);
+ gtk_object_set(GTK_OBJECT(test->data[row]),
+ "full_name", val,
+ NULL);
break;
case STREET:
- g_free (test->data[row]->street);
- test->data[row]->street = g_strdup (val);
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "address", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_is_valid(iterator)) {
+ const ECardDeliveryAddress *address = e_card_iterator_get(iterator);
+ ECardDeliveryAddress *address_copy = e_card_delivery_address_copy(address);
+ g_free(address_copy->street);
+ address_copy->street = g_strdup(val);
+ e_card_iterator_set(iterator, address_copy);
+ e_card_delivery_address_free(address_copy);
+ } else {
+ ECardDeliveryAddress *address = g_new(ECardDeliveryAddress, 1);
+ address->po = NULL;
+ address->ext = NULL;
+ address->street = g_strdup(val);
+ address->city = NULL;
+ address->region = NULL;
+ address->code = NULL;
+ address->country = NULL;
+ address->flags = 0;
+ e_card_list_append(list, address);
+ e_card_delivery_address_free(address);
+ }
+ gtk_object_unref(GTK_OBJECT(iterator));
break;
case PHONE:
- g_free (test->data[row]->phone);
- test->data[row]->phone = g_strdup (val);
+ gtk_object_get(GTK_OBJECT(test->data[row]),
+ "phone", &list,
+ NULL);
+ iterator = e_card_list_get_iterator(list);
+ if (e_card_iterator_is_valid(iterator)) {
+ const ECardPhone *phone = e_card_iterator_get(iterator);
+ ECardPhone *phone_copy = e_card_phone_copy(phone);
+ g_free(phone_copy->number);
+ phone_copy->number = g_strdup(val);
+ e_card_iterator_set(iterator, phone_copy);
+ e_card_phone_free(phone_copy);
+ } else {
+ ECardPhone *phone = g_new(ECardPhone, 1);
+ phone->number = g_strdup(val);
+ phone->flags = 0;
+ e_card_list_append(list, phone);
+ e_card_phone_free(phone);
+ }
+ gtk_object_unref(GTK_OBJECT(iterator));
break;
default:
return;
}
+ e_book_commit_card(test->book, test->data[row], NULL, NULL);
if ( !etc->frozen )
e_table_model_cell_changed(etc, col, row);
}
@@ -155,7 +244,8 @@ e_test_model_init (GtkObject *object)
ETestModel *model = E_TEST_MODEL(object);
model->data = NULL;
model->data_count = 0;
- model->idle = 0;
+ model->book = NULL;
+ model->book_view = NULL;
}
GtkType
@@ -181,117 +271,115 @@ e_test_model_get_type (void)
return type;
}
-static gboolean
-save(gpointer data)
+void
+e_test_model_add_column (ETestModel *model, Address *newadd)
{
- int i;
- xmlDoc *document = xmlNewDoc("1.0");
- xmlNode *root;
- ETestModel *model = data;
+#if 0
+ model->data = g_realloc(model->data, (++model->data_count) * sizeof(Address *));
+ model->data[model->data_count - 1] = newadd;
+ e_test_model_queue_save(model);
+ if ( model && !E_TABLE_MODEL(model)->frozen )
+ e_table_model_changed(E_TABLE_MODEL(model));
+#endif
+}
- root = xmlNewDocNode(document, NULL, "address-book", NULL);
- xmlDocSetRootElement(document, root);
- for ( i = 0; i < model->data_count; i++ ) {
- xmlNode *xml_address = xmlNewChild(root, NULL, "address", NULL);
- if ( model->data[i]->email && *model->data[i]->email )
- xmlSetProp(xml_address, "email", model->data[i]->email);
- if ( model->data[i]->email && *model->data[i]->street )
- xmlSetProp(xml_address, "street", model->data[i]->street);
- if ( model->data[i]->email && *model->data[i]->full_name )
- xmlSetProp(xml_address, "full-name", model->data[i]->full_name);
- if ( model->data[i]->email && *model->data[i]->phone )
- xmlSetProp(xml_address, "phone", model->data[i]->phone);
+static void
+e_test_model_card_added(EBookView *book_view,
+ const GList *cards,
+ ETestModel *model)
+{
+ model->data = g_realloc(model->data, (model->data_count + g_list_length((GList *)cards)) * sizeof(ECard *));
+ for ( ; cards; cards = cards->next) {
+ gtk_object_ref(GTK_OBJECT(cards->data));
+ model->data[model->data_count++] = E_CARD (cards->data);
}
- xmlSaveFile (model->filename, document);
- model->idle = 0;
- gtk_object_unref(GTK_OBJECT(model));
- /* e_table_save_specification(E_TABLE(e_table), "spec"); */
- return FALSE;
+ e_table_model_changed(E_TABLE_MODEL(model));
}
-void
-e_test_model_queue_save(ETestModel *model)
+static void
+e_test_model_card_removed(EBookView *book_view,
+ const char *id,
+ ETestModel *model)
{
- if ( !model->idle ) {
- gtk_object_ref(GTK_OBJECT(model));
- model->idle = g_idle_add(save, model);
+ int i;
+ 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 *));
+ }
}
+ e_table_model_changed(E_TABLE_MODEL(model));
}
-void
-e_test_model_add_column (ETestModel *model, Address *newadd)
+static void
+e_test_model_card_changed(EBookView *book_view,
+ const GList *cards,
+ ETestModel *model)
{
- model->data = g_realloc(model->data, (++model->data_count) * sizeof(Address *));
- model->data[model->data_count - 1] = newadd;
- e_test_model_queue_save(model);
- if ( model && !E_TABLE_MODEL(model)->frozen )
- e_table_model_changed(E_TABLE_MODEL(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(E_CARD(cards->data))) ) {
+ gtk_object_unref(GTK_OBJECT(model->data[i]));
+ model->data[i] = E_CARD(cards->data);
+ gtk_object_ref(GTK_OBJECT(model->data[i]));
+ e_table_model_row_changed(E_TABLE_MODEL(model), i);
+ break;
+ }
+ }
+ }
}
+static void
+e_test_model_book_respond_get_view(EBook *book,
+ EBookStatus status,
+ EBookView *book_view,
+ ETestModel *model)
+{
+ if (status == E_BOOK_STATUS_SUCCESS) {
+ model->book_view = book_view;
+ gtk_object_ref(GTK_OBJECT(book_view));
+ gtk_signal_connect(GTK_OBJECT(book_view),
+ "card_changed",
+ GTK_SIGNAL_FUNC(e_test_model_card_changed),
+ model);
+ gtk_signal_connect(GTK_OBJECT(book_view),
+ "card_removed",
+ GTK_SIGNAL_FUNC(e_test_model_card_removed),
+ model);
+ gtk_signal_connect(GTK_OBJECT(book_view),
+ "card_added",
+ GTK_SIGNAL_FUNC(e_test_model_card_added),
+ model);
+ }
+}
+
+static void
+e_test_model_uri_loaded(EBook *book,
+ EBookStatus status,
+ ETestModel *model)
+{
+ if (status == E_BOOK_STATUS_SUCCESS) {
+ e_book_get_book_view (book,
+ "",
+ (EBookBookViewCallback) e_test_model_book_respond_get_view,
+ model);
+ }
+}
ETableModel *
-e_test_model_new (gchar *filename)
+e_test_model_new (gchar *uri)
{
ETestModel *et;
- xmlDoc *document;
- xmlNode *xml_addressbook;
- xmlNode *xml_address;
et = gtk_type_new (e_test_model_get_type ());
-
- /* First we fill in the simple data. */
- if ( g_file_exists(filename) ) {
- e_table_model_freeze(E_TABLE_MODEL(et));
- document = xmlParseFile(filename);
- xml_addressbook = xmlDocGetRootElement(document);
- for (xml_address = xml_addressbook->childs; xml_address; xml_address = xml_address->next) {
- char *datum;
- Address *newadd;
-
- newadd = g_new(Address, 1);
-
- datum = xmlGetProp(xml_address, "email");
- if ( datum ) {
- newadd->email = g_strdup(datum);
- xmlFree(datum);
- } else
- newadd->email = g_strdup("");
-
- datum = xmlGetProp(xml_address, "street");
- if ( datum ) {
- newadd->street = g_strdup(datum);
- xmlFree(datum);
- } else
- newadd->street = g_strdup("");
-
- datum = xmlGetProp(xml_address, "full-name");
- if ( datum ) {
- newadd->full_name = g_strdup(datum);
- xmlFree(datum);
- } else
- newadd->full_name = g_strdup("");
-
- datum = xmlGetProp(xml_address, "phone");
- if ( datum ) {
- newadd->phone = g_strdup(datum);
- xmlFree(datum);
- } else
- newadd->phone = g_strdup("");
- e_test_model_add_column (et, newadd);
- }
- xmlFreeDoc(document);
- e_table_model_thaw(E_TABLE_MODEL(et));
- }
-
- et->filename = g_strdup(filename);
-
- gtk_signal_connect(GTK_OBJECT(et), "model_changed",
- GTK_SIGNAL_FUNC(e_test_model_queue_save), NULL);
- gtk_signal_connect(GTK_OBJECT(et), "model_row_changed",
- GTK_SIGNAL_FUNC(e_test_model_queue_save), NULL);
- gtk_signal_connect(GTK_OBJECT(et), "model_cell_changed",
- GTK_SIGNAL_FUNC(e_test_model_queue_save), NULL);
+ et->uri = g_strdup(uri);
+ et->book = e_book_new();
+ e_book_load_uri(et->book,
+ et->uri,
+ (EBookCallback) e_test_model_uri_loaded,
+ et);
return E_TABLE_MODEL(et);
}
diff --git a/addressbook/demo/e-test-model.h b/addressbook/demo/e-test-model.h
index dd3f8e0fa9..871ea11de8 100644
--- a/addressbook/demo/e-test-model.h
+++ b/addressbook/demo/e-test-model.h
@@ -3,6 +3,9 @@
#define _E_TEST_MODEL_H_
#include "e-table-model.h"
+#include <e-book.h>
+#include <e-book-view.h>
+#include <e-card.h>
#define E_TEST_MODEL_TYPE (e_test_model_get_type ())
#define E_TEST_MODEL(o) (GTK_CHECK_CAST ((o), E_TEST_MODEL_TYPE, ETestModel))
@@ -19,7 +22,6 @@
typedef struct _Address Address;
typedef enum _Rows Rows;
-
struct _Address {
gchar *email;
gchar *full_name;
@@ -35,16 +37,17 @@ enum _Rows {
LAST_COL
};
-
-
typedef struct {
ETableModel parent;
- Address **data;
+ EBook *book;
+
+ EBookView *book_view;
+
+ ECard **data;
int data_count;
- char *filename;
- int idle;
+ char *uri;
} ETestModel;
@@ -54,11 +57,8 @@ typedef struct {
GtkType e_test_model_get_type (void);
-ETableModel *e_test_model_new (char *filename);
+ETableModel *e_test_model_new (char *uri);
-void e_test_model_queue_save(ETestModel *model);
void e_test_model_add_column (ETestModel *model, Address *newadd);
-
#endif /* _E_TEST_MODEL_H_ */
-