diff options
author | nobody <nobody@localhost> | 2001-08-05 03:29:35 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2001-08-05 03:29:35 +0800 |
commit | 220ead4cc561abeed2c9143190b96e8654ab1605 (patch) | |
tree | 0f0f7d161df8ec2e9a2e06dc0f87a8c17389d1e1 /addressbook/backend/ebook | |
parent | 950e90cd92e950cb17645b5c3d6fc6eae2f07c5e (diff) | |
download | gsoc2013-evolution-GGV_1_1_1.tar gsoc2013-evolution-GGV_1_1_1.tar.gz gsoc2013-evolution-GGV_1_1_1.tar.bz2 gsoc2013-evolution-GGV_1_1_1.tar.lz gsoc2013-evolution-GGV_1_1_1.tar.xz gsoc2013-evolution-GGV_1_1_1.tar.zst gsoc2013-evolution-GGV_1_1_1.zip |
This commit was manufactured by cvs2svn to create tag 'GGV_1_1_1'.GGV_1_1_1
svn path=/tags/GGV_1_1_1/; revision=11660
Diffstat (limited to 'addressbook/backend/ebook')
33 files changed, 0 insertions, 13146 deletions
diff --git a/addressbook/backend/ebook/.cvsignore b/addressbook/backend/ebook/.cvsignore deleted file mode 100644 index f1eef28fc4..0000000000 --- a/addressbook/backend/ebook/.cvsignore +++ /dev/null @@ -1,23 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -addressbook-stubs.c -addressbook-skels.c -addressbook-common.c -addressbook.h -test-card -test-client -test-client-list -load-pine-addressbook -load-gnomecard-addressbook -evolution-vcard-importer -evolution-gnomecard-importer -Evolution-Composer-stubs.c -Evolution-Composer-skels.c -Evolution-Composer-common.c -Evolution-Composer.h -GNOME_Evolution_Addressbook_VCard_Importer.oaf diff --git a/addressbook/backend/ebook/GNOME_Evolution_Addressbook_VCard_Importer.oaf.in b/addressbook/backend/ebook/GNOME_Evolution_Addressbook_VCard_Importer.oaf.in deleted file mode 100644 index 9cd4699633..0000000000 --- a/addressbook/backend/ebook/GNOME_Evolution_Addressbook_VCard_Importer.oaf.in +++ /dev/null @@ -1,29 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_VCard_ImporterFactory" - type="exe" - location="evolution-vcard-importer"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="description" type="string" - _value="Factory to import VCard files into Evolution."/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_VCard_Importer" - type="factory" - location="OAFIID:GNOME_Evolution_Addressbook_VCard_ImporterFactory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Importer:1.0"/> - </oaf_attribute> - - <oaf_attribute name="evolution:menu-name" type="string" - value="VCard (.vcf, .gcrd)"/> - <oaf_attribute name="description" type="string" - _value="Imports VCard files into Evolution."/> -</oaf_server> - -</oaf_info> diff --git a/addressbook/backend/ebook/Makefile.am b/addressbook/backend/ebook/Makefile.am deleted file mode 100644 index 37a940d515..0000000000 --- a/addressbook/backend/ebook/Makefile.am +++ /dev/null @@ -1,185 +0,0 @@ -noinst_PROGRAMS = test-card test-client test-client-list - -bin_PROGRAMS = evolution-vcard-importer \ - load-pine-addressbook load-gnomecard-addressbook - -CORBA_SOURCE = \ - addressbook.h \ - addressbook-common.c \ - addressbook-stubs.c \ - addressbook-skels.c \ - Evolution-Composer.h \ - Evolution-Composer-common.c \ - Evolution-Composer-skels.c \ - Evolution-Composer-stubs.c - -idls = \ - $(srcdir)/../idl/addressbook.idl \ - $(srcdir)/../../../composer/Evolution-Composer.idl - -idl_flags = `$(GNOME_CONFIG) --cflags idl` -I $(datadir)/idl - -$(CORBA_SOURCE): $(idls) - $(ORBIT_IDL) -I $(srcdir) $(idls) $(idl_flags) - -INCLUDES = \ - -DGNOMELOCALEDIR=\""$(localedir)"\" \ - -DG_LOG_DOMAIN=\"EBook\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/camel \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_srcdir)/addressbook/ename \ - -I$(top_builddir)/addressbook/backend \ - -I$(top_builddir)/addressbook/ename \ - -I$(top_builddir)/shell \ - -I$(top_srcdir)/shell \ - $(BONOBO_GNOME_CFLAGS) \ - $(EXTRA_GNOME_CFLAGS) - -lib_LTLIBRARIES = libebook.la - -libebook_la_SOURCES = \ - $(CORBA_SOURCE) \ - e-book-listener.c \ - e-book-view-listener.c \ - e-book-view.c \ - e-book.c \ - e-book-util.c \ - e-card-cursor.c \ - e-card-simple.c \ - e-card.c \ - e-card-compare.c \ - e-destination.c - -libebookincludedir = $(includedir)/evolution/ebook - -libebookinclude_HEADERS = \ - e-book-listener.h \ - e-book-types.h \ - e-book-view-listener.h \ - e-book-view.h \ - e-book.h \ - e-book-util.h \ - e-card-cursor.h \ - e-card-simple.h \ - e-card-types.h \ - e-card.h \ - e-card-compare.h \ - e-destination.h - - -# -# make a static library for use by addressbook's conduit's shared library -# -noinst_LTLIBRARIES = libebook-static.la -libebook_static_la_SOURCES = $(libebook_la_SOURCES) -libebook_static_la_LDFLAGS = --all-static - - -test_client_SOURCES = \ - test-client.c - -test_client_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/e-util/libeutil.la - -test_client_list_SOURCES = \ - test-client-list.c - -test_client_list_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/libeutil.la - -test_card_SOURCES = \ - test-card.c - -test_card_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/libeutil.la - -evolution_vcard_importer_SOURCES = \ - evolution-vcard-importer.c -evolution_vcard_importer_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/shell/importer/libevolution-importer.la \ - $(DB3_LDADD) \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/libeutil.la - -load_pine_addressbook_SOURCES = \ - load-pine-addressbook.c - -load_pine_addressbook_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/libeutil.la - - -load_gnomecard_addressbook_SOURCES = \ - load-gnomecard-addressbook.c - -load_gnomecard_addressbook_LDADD = \ - libebook.la \ - $(BONOBO_CONF_LIBS) \ - $(BONOBO_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/libibex/libibex.la \ - $(top_builddir)/e-util/ename/libename.la \ - $(top_builddir)/libversit/libversit.la \ - $(top_builddir)/e-util/libeutil.la - - -BUILT_SOURCES = $(CORBA_SOURCE) -CLEANFILES += $(BUILT_SOURCES) - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) - -oafdir = $(datadir)/oaf -oaf_in_files = GNOME_Evolution_Addressbook_VCard_Importer.oaf.in -oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) - -@XML_I18N_MERGE_OAF_RULE@ - -# add this back when you add the file to the archive ;) -# GNOME_Evolution_Addressbook_Pine_Importer.oafinfo - -EXTRA_DIST = $(oaf_in_files) $(oaf_DATA) - - - - diff --git a/addressbook/backend/ebook/TODO b/addressbook/backend/ebook/TODO deleted file mode 100644 index a69703cd92..0000000000 --- a/addressbook/backend/ebook/TODO +++ /dev/null @@ -1,2 +0,0 @@ -* Make sure open_book_progress does not use the EBook op queue; make - sure it works. diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c deleted file mode 100644 index 285c6646b2..0000000000 --- a/addressbook/backend/ebook/e-book-listener.c +++ /dev/null @@ -1,770 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Exports the BookListener interface. Maintains a queue of messages - * which come in on the interface. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-book-listener.h" - -static EBookStatus e_book_listener_convert_status (GNOME_Evolution_Addressbook_BookListener_CallStatus status); - -enum { - RESPONSES_QUEUED, - LAST_SIGNAL -}; - -static guint e_book_listener_signals [LAST_SIGNAL]; - -static BonoboObjectClass *e_book_listener_parent_class; -POA_GNOME_Evolution_Addressbook_BookListener__vepv e_book_listener_vepv; - -struct _EBookListenerPrivate { - GList *response_queue; - gint idle_id; - - guint stopped : 1; -}; - -static gboolean -e_book_listener_check_queue (EBookListener *listener) -{ - if (listener->priv->response_queue != NULL) { - gtk_signal_emit (GTK_OBJECT (listener), - e_book_listener_signals [RESPONSES_QUEUED]); - } - - if (listener->priv->response_queue == NULL) { - listener->priv->idle_id = 0; - - /* We only release our reference to the listener when the idle - function is totally finished. */ - bonobo_object_unref (BONOBO_OBJECT (listener)); - - return FALSE; - } - - return TRUE; -} - -static void -e_book_listener_queue_response (EBookListener *listener, - EBookListenerResponse *response) -{ - listener->priv->response_queue = - g_list_append (listener->priv->response_queue, - response); - - if (listener->priv->idle_id == 0) { - - /* Hold a reference to the listener until the idle function is finished. */ - bonobo_object_ref (BONOBO_OBJECT (listener)); - - listener->priv->idle_id = g_idle_add ( - (GSourceFunc) e_book_listener_check_queue, listener); - } -} - -/* Add, Remove, Modify */ -static void -e_book_listener_queue_generic_response (EBookListener *listener, - EBookListenerOperation op, - EBookStatus status) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = op; - resp->status = status; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_open_response (EBookListener *listener, - EBookStatus status, - GNOME_Evolution_Addressbook_Book book) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = OpenBookResponse; - resp->status = status; - resp->book = book; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_open_progress (EBookListener *listener, - const char *msg, - short percent) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = OpenProgressEvent; - resp->msg = g_strdup (msg); - resp->percent = percent; - - e_book_listener_queue_response (listener, resp); -} - - -static void -e_book_listener_queue_create_card_response (EBookListener *listener, - EBookStatus status, - const char *id) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = CreateCardResponse; - resp->status = status; - resp->id = g_strdup (id); - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_get_cursor_response (EBookListener *listener, - EBookStatus status, - GNOME_Evolution_Addressbook_CardCursor cursor) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = GetCursorResponse; - resp->status = status; - resp->cursor = cursor; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_get_view_response (EBookListener *listener, - EBookStatus status, - GNOME_Evolution_Addressbook_BookView book_view) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = GetBookViewResponse; - resp->status = status; - resp->book_view = book_view; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_get_changes_response (EBookListener *listener, - EBookStatus status, - GNOME_Evolution_Addressbook_BookView book_view) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = GetChangesResponse; - resp->status = status; - resp->book_view = book_view; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_link_status (EBookListener *listener, - gboolean connected) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = LinkStatusEvent; - resp->connected = connected; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_writable_status (EBookListener *listener, - gboolean writable) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = WritableStatusEvent; - resp->writable = writable; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_authentication_response (EBookListener *listener, - EBookStatus status) -{ - EBookListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = AuthenticationResponse; - resp->status = status; - - e_book_listener_queue_response (listener, resp); -} - -static void -e_book_listener_queue_get_supported_fields_response (EBookListener *listener, - EBookStatus status, - const GNOME_Evolution_Addressbook_stringlist *fields) -{ - EBookListenerResponse *resp; - int i; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookListenerResponse, 1); - - resp->op = GetSupportedFieldsResponse; - resp->status = status; - resp->fields = e_list_new ((EListCopyFunc)g_strdup, (EListFreeFunc)g_free, NULL); - - for (i = 0; i < fields->_length; i ++) { - e_list_append (resp->fields, fields->_buffer[i]); - } - - e_book_listener_queue_response (listener, resp); -} - -static void -impl_BookListener_respond_create_card (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_CardId id, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_create_card_response ( - listener, - e_book_listener_convert_status (status), - id); -} - -static void -impl_BookListener_respond_remove_card (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_generic_response ( - listener, RemoveCardResponse, - e_book_listener_convert_status (status)); -} - -static void -impl_BookListener_respond_modify_card (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_generic_response ( - listener, ModifyCardResponse, - e_book_listener_convert_status (status)); -} - -static void -impl_BookListener_respond_get_cursor (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_CardCursor cursor, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - GNOME_Evolution_Addressbook_CardCursor cursor_copy; - - cursor_copy = bonobo_object_dup_ref (cursor, ev); - - if (ev->_major != CORBA_NO_EXCEPTION) { - g_warning ("EBookListener: Exception while duplicating CardCursor!\n"); - return; - } - - e_book_listener_queue_get_cursor_response ( - listener, - e_book_listener_convert_status (status), - cursor_copy); -} - -static void -impl_BookListener_respond_get_view (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_BookView book_view, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - GNOME_Evolution_Addressbook_BookView book_view_copy; - - book_view_copy = bonobo_object_dup_ref (book_view, ev); - - if (ev->_major != CORBA_NO_EXCEPTION) { - g_warning ("EBookListener: Exception while duplicating BookView.\n"); - return; - } - - e_book_listener_queue_get_view_response ( - listener, - e_book_listener_convert_status (status), - book_view_copy); -} - -static void -impl_BookListener_respond_get_changes (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_BookView book_view, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - GNOME_Evolution_Addressbook_BookView book_view_copy; - - book_view_copy = bonobo_object_dup_ref (book_view, ev); - - if (ev->_major != CORBA_NO_EXCEPTION) { - g_warning ("EBookListener: Exception while duplicating BookView.\n"); - return; - } - - e_book_listener_queue_get_changes_response ( - listener, - e_book_listener_convert_status (status), - book_view_copy); -} - -static void -impl_BookListener_respond_open_book (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_Book book, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - GNOME_Evolution_Addressbook_Book book_copy; - - book_copy = bonobo_object_dup_ref (book, ev); - - if (ev->_major != CORBA_NO_EXCEPTION) { - g_warning ("EBookListener: Exception while duplicating Book!\n"); - return; - } - - e_book_listener_queue_open_response ( - listener, - e_book_listener_convert_status (status), - book_copy); -} - -static void -impl_BookListener_report_open_book_progress (PortableServer_Servant servant, - const CORBA_char *status_message, - const CORBA_short percent, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_open_progress ( - listener, status_message, percent); -} - -static void -impl_BookListener_respond_authentication_result (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_authentication_response ( - listener, status); -} - -static void -impl_BookListener_response_get_supported_fields (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_BookListener_CallStatus status, - const GNOME_Evolution_Addressbook_stringlist *fields, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_get_supported_fields_response ( - listener, status, fields); -} - -static void -impl_BookListener_report_connection_status (PortableServer_Servant servant, - const CORBA_boolean connected, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_link_status ( - listener, connected); -} - -static void -impl_BookListener_report_writable (PortableServer_Servant servant, - const CORBA_boolean writable, - CORBA_Environment *ev) -{ - EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - - e_book_listener_queue_writable_status (listener, writable); -} - -/** - * e_book_listener_check_pending: - * @listener: the #EBookListener - * - * Returns: the number of items on the response queue, - * or -1 if the @listener is isn't an #EBookListener. - */ -int -e_book_listener_check_pending (EBookListener *listener) -{ - g_return_val_if_fail (listener != NULL, -1); - g_return_val_if_fail (E_IS_BOOK_LISTENER (listener), -1); - - return g_list_length (listener->priv->response_queue); -} - -/** - * e_book_listener_pop_response: - * @listener: the #EBookListener for which a request is to be popped - * - * Returns: an #EBookListenerResponse if there are responses on the - * queue to be returned; %NULL if there aren't, or if the @listener - * isn't an EBookListener. - */ -EBookListenerResponse * -e_book_listener_pop_response (EBookListener *listener) -{ - EBookListenerResponse *resp; - GList *popped; - - g_return_val_if_fail (listener != NULL, NULL); - g_return_val_if_fail (E_IS_BOOK_LISTENER (listener), NULL); - - if (listener->priv->response_queue == NULL) - return NULL; - - resp = listener->priv->response_queue->data; - - popped = listener->priv->response_queue; - listener->priv->response_queue = - g_list_remove_link (listener->priv->response_queue, - listener->priv->response_queue); - g_list_free_1 (popped); - - return resp; -} - -static EBookStatus -e_book_listener_convert_status (const GNOME_Evolution_Addressbook_BookListener_CallStatus status) -{ - switch (status) { - case GNOME_Evolution_Addressbook_BookListener_Success: - return E_BOOK_STATUS_SUCCESS; - case GNOME_Evolution_Addressbook_BookListener_RepositoryOffline: - return E_BOOK_STATUS_REPOSITORY_OFFLINE; - case GNOME_Evolution_Addressbook_BookListener_PermissionDenied: - return E_BOOK_STATUS_PERMISSION_DENIED; - case GNOME_Evolution_Addressbook_BookListener_CardNotFound: - return E_BOOK_STATUS_CARD_NOT_FOUND; - case GNOME_Evolution_Addressbook_BookListener_CardIdAlreadyExists: - return E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS; - case GNOME_Evolution_Addressbook_BookListener_ProtocolNotSupported: - return E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED; - case GNOME_Evolution_Addressbook_BookListener_OtherError: - return E_BOOK_STATUS_OTHER_ERROR; - default: - g_warning ("e_book_listener_convert_status: Unknown status " - "from card server: %d\n", (int) status); - return E_BOOK_STATUS_UNKNOWN; - - } -} - -static EBookListener * -e_book_listener_construct (EBookListener *listener) -{ - POA_GNOME_Evolution_Addressbook_BookListener *servant; - CORBA_Environment ev; - CORBA_Object obj; - - g_assert (listener != NULL); - g_assert (E_IS_BOOK_LISTENER (listener)); - - servant = (POA_GNOME_Evolution_Addressbook_BookListener *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &e_book_listener_vepv; - - CORBA_exception_init (&ev); - - POA_GNOME_Evolution_Addressbook_BookListener__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - - return NULL; - } - - CORBA_exception_free (&ev); - - obj = bonobo_object_activate_servant (BONOBO_OBJECT (listener), servant); - if (obj == CORBA_OBJECT_NIL) { - g_free (servant); - - return NULL; - } - - bonobo_object_construct (BONOBO_OBJECT (listener), obj); - - return listener; -} - -/** - * e_book_listener_new: - * @book: the #EBook for which the listener is to be bound - * - * Creates and returns a new #EBookListener for the book. - * - * Returns: a new #EBookListener - */ -EBookListener * -e_book_listener_new () -{ - EBookListener *listener; - EBookListener *retval; - - listener = gtk_type_new (E_BOOK_LISTENER_TYPE); - - retval = e_book_listener_construct (listener); - - if (retval == NULL) { - g_warning ("e_book_listener_new: Error constructing " - "EBookListener!\n"); - bonobo_object_unref (BONOBO_OBJECT (listener)); - return NULL; - } - - return retval; -} - -static void -e_book_listener_init (EBookListener *listener) -{ - listener->priv = g_new0 (EBookListenerPrivate, 1); -} - -void -e_book_listener_stop (EBookListener *listener) -{ - GList *l; - - if (listener->priv->stopped) - return; - - for (l = listener->priv->response_queue; l != NULL; l = l->next) { - EBookListenerResponse *resp = l->data; - - g_free (resp->msg); - g_free (resp->id); - - if (resp->book != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_listener_destroy: " - "Exception destroying book " - "in response queue!\n"); - } - - CORBA_exception_free (&ev); - } - - if (resp->cursor != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_listener_destroy: " - "Exception destroying cursor " - "in response queue!\n"); - } - - CORBA_exception_free (&ev); - } - - if (resp->book_view != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->book_view, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_listener_destroy: " - "Exception destroying book_view " - "in response queue!\n"); - } - - CORBA_exception_free (&ev); - } - - g_free (resp); - } - g_list_free (listener->priv->response_queue); - listener->priv->response_queue = NULL; - - listener->priv->stopped = TRUE; -} - -static void -e_book_listener_destroy (GtkObject *object) -{ - EBookListener *listener = E_BOOK_LISTENER (object); - - e_book_listener_stop (listener); - g_free (listener->priv); - - GTK_OBJECT_CLASS (e_book_listener_parent_class)->destroy (object); -} - -POA_GNOME_Evolution_Addressbook_BookListener__epv * -e_book_listener_get_epv (void) -{ - POA_GNOME_Evolution_Addressbook_BookListener__epv *epv; - - epv = g_new0 (POA_GNOME_Evolution_Addressbook_BookListener__epv, 1); - - epv->notifyOpenBookProgress = impl_BookListener_report_open_book_progress; - epv->notifyBookOpened = impl_BookListener_respond_open_book; - - epv->notifyCardCreated = impl_BookListener_respond_create_card; - epv->notifyCardRemoved = impl_BookListener_respond_remove_card; - epv->notifyCardModified = impl_BookListener_respond_modify_card; - - epv->notifyAuthenticationResult = impl_BookListener_respond_authentication_result; - epv->notifySupportedFields = impl_BookListener_response_get_supported_fields; - - epv->notifyCursorRequested = impl_BookListener_respond_get_cursor; - epv->notifyViewRequested = impl_BookListener_respond_get_view; - epv->notifyChangesRequested = impl_BookListener_respond_get_changes; - - epv->notifyConnectionStatus = impl_BookListener_report_connection_status; - epv->notifyWritable = impl_BookListener_report_writable; - - return epv; -} - -static void -e_book_listener_corba_class_init (void) -{ - e_book_listener_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - e_book_listener_vepv.GNOME_Evolution_Addressbook_BookListener_epv = e_book_listener_get_epv (); -} - -static void -e_book_listener_class_init (EBookListenerClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - e_book_listener_parent_class = gtk_type_class (bonobo_object_get_type ()); - - e_book_listener_signals [RESPONSES_QUEUED] = - gtk_signal_new ("responses_queued", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookListenerClass, responses_queued), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_book_listener_signals, LAST_SIGNAL); - - object_class->destroy = e_book_listener_destroy; - - e_book_listener_corba_class_init (); -} - -/** - * e_book_listener_get_type: - */ -GtkType -e_book_listener_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "EBookListener", - sizeof (EBookListener), - sizeof (EBookListenerClass), - (GtkClassInitFunc) e_book_listener_class_init, - (GtkObjectInitFunc) e_book_listener_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/ebook/e-book-listener.h b/addressbook/backend/ebook/e-book-listener.h deleted file mode 100644 index 16cb518ce5..0000000000 --- a/addressbook/backend/ebook/e-book-listener.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * A client-side GtkObject which exposes the - * Evolution:BookListener interface. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_BOOK_LISTENER_H__ -#define __E_BOOK_LISTENER_H__ - -#include <libgnome/gnome-defs.h> -#include <bonobo/bonobo-object.h> -#include <ebook/addressbook.h> -#include <ebook/e-book-types.h> -#include <e-util/e-list.h> - -BEGIN_GNOME_DECLS - -typedef struct _EBookListener EBookListener; -typedef struct _EBookListenerClass EBookListenerClass; -typedef struct _EBookListenerPrivate EBookListenerPrivate; - -struct _EBookListener { - BonoboObject parent; - EBookListenerPrivate *priv; -}; - -struct _EBookListenerClass { - BonoboObjectClass parent; - - /* - * Signals - */ - void (*responses_queued) (void); -}; - -typedef enum { - /* Async responses */ - OpenBookResponse, - CreateCardResponse, - RemoveCardResponse, - ModifyCardResponse, - GetCursorResponse, - GetBookViewResponse, - GetChangesResponse, - AuthenticationResponse, - GetSupportedFieldsResponse, - - /* Async events */ - LinkStatusEvent, - WritableStatusEvent, - OpenProgressEvent, -} EBookListenerOperation; - -typedef struct { - EBookListenerOperation op; - - /* For most Response notifications */ - EBookStatus status; - - /* For OpenBookResponse */ - GNOME_Evolution_Addressbook_Book book; - - /* For GetCursorResponse */ - GNOME_Evolution_Addressbook_CardCursor cursor; - - /* For GetBookViewReponse */ - GNOME_Evolution_Addressbook_BookView book_view; - - /* For GetSupportedFields */ - EList *fields; - - /* For OpenProgressEvent */ - char *msg; - short percent; - - /* For LinkStatusEvent */ - gboolean connected; - - /* For WritableStatusEvent */ - gboolean writable; - - /* For Card[Added|Removed|Modified]Event */ - char *id; -} EBookListenerResponse; - -EBookListener *e_book_listener_new (void); -int e_book_listener_check_pending (EBookListener *listener); -EBookListenerResponse *e_book_listener_pop_response (EBookListener *listener); -GtkType e_book_listener_get_type (void); -void e_book_listener_stop (EBookListener *listener); - -POA_GNOME_Evolution_Addressbook_BookListener__epv *e_book_listener_get_epv (void); - -#define E_BOOK_LISTENER_TYPE (e_book_listener_get_type ()) -#define E_BOOK_LISTENER(o) (GTK_CHECK_CAST ((o), E_BOOK_LISTENER_TYPE, EBookListener)) -#define E_BOOK_LISTENER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BOOK_LISTENER_TYPE, EBookListenerClass)) -#define E_IS_BOOK_LISTENER(o) (GTK_CHECK_TYPE ((o), E_BOOK_LISTENER_TYPE)) -#define E_IS_BOOK_LISTENER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_BOOK_LISTENER_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __E_BOOK_LISTENER_H__ */ diff --git a/addressbook/backend/ebook/e-book-types.h b/addressbook/backend/ebook/e-book-types.h deleted file mode 100644 index 0a477678eb..0000000000 --- a/addressbook/backend/ebook/e-book-types.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * A client-side GtkObject which exposes the - * Evolution:BookListener interface. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_BOOK_TYPES_H__ -#define __E_BOOK_TYPES_H__ - -#include <libgnome/gnome-defs.h> - -BEGIN_GNOME_DECLS - -typedef enum { - E_BOOK_STATUS_SUCCESS, - E_BOOK_STATUS_UNKNOWN, - E_BOOK_STATUS_REPOSITORY_OFFLINE, - E_BOOK_STATUS_PERMISSION_DENIED, - E_BOOK_STATUS_CARD_NOT_FOUND, - E_BOOK_STATUS_CARD_ID_ALREADY_EXISTS, - E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED, - E_BOOK_STATUS_CANCELLED, - E_BOOK_STATUS_OTHER_ERROR -} EBookStatus; - -typedef enum { - E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS, - E_BOOK_SIMPLE_QUERY_STATUS_CANCELLED, - E_BOOK_SIMPLE_QUERY_STATUS_OTHER_ERROR -} EBookSimpleQueryStatus; - -END_GNOME_DECLS - -#endif /* ! __E_BOOK_TYPES_H__ */ diff --git a/addressbook/backend/ebook/e-book-util.c b/addressbook/backend/ebook/e-book-util.c deleted file mode 100644 index d10c5612f1..0000000000 --- a/addressbook/backend/ebook/e-book-util.c +++ /dev/null @@ -1,571 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-book-util.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#include <config.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-util.h> -#include "e-book-util.h" - -gboolean -e_book_load_local_address_book (EBook *book, EBookCallback open_response, gpointer closure) -{ - gchar *filename; - gchar *uri; - gboolean rv; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (open_response != NULL, FALSE); - - filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf ("file://%s", filename); - - rv = e_book_load_uri (book, uri, open_response, closure); - - if (!rv) { - g_warning ("Couldn't load local addressbook %s", uri); - } - - g_free (filename); - g_free (uri); - - return rv; -} - -static EBook *common_local_book = NULL; - -typedef struct _CommonBookInfo CommonBookInfo; -struct _CommonBookInfo { - EBookCommonCallback cb; - gpointer closure; -}; - -static void -got_local_book_cb (EBook *book, EBookStatus status, gpointer closure) -{ - CommonBookInfo *info = (CommonBookInfo *) closure; - - if (status == E_BOOK_STATUS_SUCCESS) { - - /* We try not to leak in a race condition where the - local book got loaded twice. */ - - if (common_local_book) { - gtk_object_unref (GTK_OBJECT (book)); - book = common_local_book; - } - - info->cb (book, info->closure); - - if (common_local_book == NULL) { - common_local_book = book; - } - - } else { - - info->cb (NULL, info->closure); - - } - g_free (info); -} - -void -e_book_use_local_address_book (EBookCommonCallback cb, gpointer closure) -{ - EBook *book; - CommonBookInfo *info; - - g_return_if_fail (cb != NULL); - - if (common_local_book != NULL) { - cb (common_local_book, closure); - return; - } - - info = g_new0 (CommonBookInfo, 1); - info->cb = cb; - info->closure = closure; - - book = e_book_new (); - if (! e_book_load_local_address_book (book, got_local_book_cb, info)) { - gtk_object_unref (GTK_OBJECT (book)); - g_free (info); - } -} - -/* - * - * Simple Query Stuff - * - */ - -typedef struct _SimpleQueryInfo SimpleQueryInfo; -struct _SimpleQueryInfo { - guint tag; - EBook *book; - gchar *query; - EBookSimpleQueryCallback cb; - gpointer closure; - EBookView *view; - guint add_tag; - guint seq_complete_tag; - GList *cards; -}; - -static void -book_add_simple_query (EBook *book, SimpleQueryInfo *info) -{ - GList *pending = gtk_object_get_data (GTK_OBJECT (book), "sq_pending"); - pending = g_list_prepend (pending, info); - gtk_object_set_data (GTK_OBJECT (book), "sq_pending", pending); -} - -static SimpleQueryInfo * -book_lookup_simple_query (EBook *book, guint tag) -{ - GList *pending = gtk_object_get_data (GTK_OBJECT (book), "sq_pending"); - while (pending) { - SimpleQueryInfo *sq = pending->data; - if (sq->tag == tag) - return sq; - pending = g_list_next (pending); - } - return NULL; -} - -static void -book_remove_simple_query (EBook *book, SimpleQueryInfo *info) -{ - GList *pending = gtk_object_get_data (GTK_OBJECT (book), "sq_pending"); - GList *i; - - for (i=pending; i != NULL; i = g_list_next (i)) { - if (i->data == info) { - pending = g_list_remove_link (pending, i); - g_list_free_1 (i); - break; - } - } - gtk_object_set_data (GTK_OBJECT (book), "sq_pending", pending); -} - -static guint -book_issue_tag (EBook *book) -{ - gpointer ptr = gtk_object_get_data (GTK_OBJECT (book), "sq_tag"); - guint tag = GPOINTER_TO_UINT (ptr); - if (tag == 0) - tag = 1; - gtk_object_set_data (GTK_OBJECT (book), "sq_tag", GUINT_TO_POINTER (tag+1)); - return tag; -} - -#ifdef USE_WORKAROUND -static GList *WORKAROUND_sq_queue = NULL; -static gboolean WORKAROUND_running_query = FALSE; -#endif - -static SimpleQueryInfo * -simple_query_new (EBook *book, const char *query, EBookSimpleQueryCallback cb, gpointer closure) -{ - SimpleQueryInfo *sq = g_new0 (SimpleQueryInfo, 1); - - sq->tag = book_issue_tag (book); - sq->book = book; - gtk_object_ref (GTK_OBJECT (book)); - sq->query = g_strdup_printf (query); - sq->cb = cb; - sq->closure = closure; - - /* Automatically add ourselves to the EBook's pending list. */ - book_add_simple_query (book, sq); - -#ifdef USE_WORKAROUND - /* Add ourselves to the queue. */ - WORKAROUND_sq_queue = g_list_append (WORKAROUND_sq_queue, sq); -#endif - - return sq; -} - -static void -simple_query_free (SimpleQueryInfo *sq) -{ - /* Remove ourselves from the EBook's pending list. */ - book_remove_simple_query (sq->book, sq); - -#ifdef USE_WORKAROUND - Glist *i; - - /* If we are still in the queue, remove ourselves. */ - for (i = WORKAROUND_sq_queue; i != NULL; i = g_list_next (i)) { - if (i->data == sq) { - WORKAROUND_sq_queue = g_list_remove_link (WORKAROUND_sq_queue, i); - g_list_free_1 (i); - break; - } - } -#endif - - g_free (sq->query); - - if (sq->add_tag) - gtk_signal_disconnect (GTK_OBJECT (sq->view), sq->add_tag); - if (sq->seq_complete_tag) - gtk_signal_disconnect (GTK_OBJECT (sq->view), sq->seq_complete_tag); - -#ifdef USE_WORKAROUND - if (sq->view) - WORKAROUND_running_query = FALSE; -#endif - - if (sq->view) - gtk_object_unref (GTK_OBJECT (sq->view)); - - if (sq->book) - gtk_object_unref (GTK_OBJECT (sq->book)); - - g_list_foreach (sq->cards, (GFunc) gtk_object_unref, NULL); - g_list_free (sq->cards); - - g_free (sq); -} - -static void -simple_query_card_added_cb (EBookView *view, const GList *cards, gpointer closure) -{ - SimpleQueryInfo *sq = closure; - - sq->cards = g_list_concat (sq->cards, g_list_copy ((GList *) cards)); - g_list_foreach ((GList *) cards, (GFunc) gtk_object_ref, NULL); -} - -static void -simple_query_sequence_complete_cb (EBookView *view, gpointer closure) -{ - SimpleQueryInfo *sq = closure; - - sq->cb (sq->book, E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS, sq->cards, sq->closure); - simple_query_free (sq); -} - -static void -simple_query_book_view_cb (EBook *book, EBookStatus status, EBookView *book_view, gpointer closure) -{ - SimpleQueryInfo *sq = closure; - - if (status != E_BOOK_STATUS_SUCCESS) { - sq->cb (sq->book, E_BOOK_SIMPLE_QUERY_STATUS_OTHER_ERROR, NULL, sq->closure); - simple_query_free (sq); - return; - } - - sq->view = book_view; - gtk_object_ref (GTK_OBJECT (book_view)); - - sq->add_tag = gtk_signal_connect (GTK_OBJECT (sq->view), - "card_added", - GTK_SIGNAL_FUNC (simple_query_card_added_cb), - sq); - sq->seq_complete_tag = gtk_signal_connect (GTK_OBJECT (sq->view), - "sequence_complete", - GTK_SIGNAL_FUNC (simple_query_sequence_complete_cb), - sq); -} - -#ifdef USE_WORKAROUND -static gint -WORKAROUND_try_queue (gpointer foo) -{ - if (WORKAROUND_sq_queue) { - SimpleQueryInfo *sq; - GList *i; - - if (WORKAROUND_running_query) - return TRUE; - - WORKAROUND_running_query = TRUE; - sq = WORKAROUND_sq_queue->data; - - i = WORKAROUND_sq_queue; - WORKAROUND_sq_queue = g_list_remove_link (WORKAROUND_sq_queue, WORKAROUND_sq_queue); - g_list_free_1 (i); - - e_book_get_book_view (sq->book, sq->query, simple_query_book_view_cb, sq); - } - - return FALSE; -} -#endif - -guint -e_book_simple_query (EBook *book, const char *query, EBookSimpleQueryCallback cb, gpointer closure) -{ - SimpleQueryInfo *sq; - - g_return_val_if_fail (book && E_IS_BOOK (book), 0); - g_return_val_if_fail (query, 0); - g_return_val_if_fail (cb, 0); - - sq = simple_query_new (book, query, cb, closure); -#ifdef USE_WORKAROUND - gtk_timeout_add (50, WORKAROUND_try_queue, NULL); -#else - e_book_get_book_view (book, (gchar *) query, simple_query_book_view_cb, sq); -#endif - - return sq->tag; -} - -void -e_book_simple_query_cancel (EBook *book, guint tag) -{ - SimpleQueryInfo *sq; - - g_return_if_fail (book && E_IS_BOOK (book)); - - sq = book_lookup_simple_query (book, tag); - - if (sq) { - sq->cb (sq->book, E_BOOK_SIMPLE_QUERY_STATUS_CANCELLED, NULL, sq->closure); - simple_query_free (sq); - } else { - g_warning ("Simple query tag %d is unknown", tag); - } -} - -/* - * - * Specialized Queries - * - */ - -typedef struct _NameEmailQueryInfo NameEmailQueryInfo; -struct _NameEmailQueryInfo { - gchar *name; - gchar *email; - EBookSimpleQueryCallback cb; - gpointer closure; -}; - -static void -name_email_query_info_free (NameEmailQueryInfo *info) -{ - if (info) { - g_free (info->name); - g_free (info->email); - g_free (info); - } -} - -static void -name_and_email_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) -{ - NameEmailQueryInfo *info = closure; - GList *filtered_cards = NULL; - - while (cards) { - ECard *card = E_CARD (cards->data); - if ((info->name == NULL || e_card_name_match_string (card->name, info->name)) - && (info->email == NULL || e_card_email_match_string (card, info->email))) - filtered_cards = g_list_append (filtered_cards, card); - cards = g_list_next (cards); - } - - info->cb (book, status, filtered_cards, info->closure); - - g_list_free (filtered_cards); - - name_email_query_info_free (info); -} - -guint -e_book_name_and_email_query (EBook *book, - const gchar *name, - const gchar *email, - EBookSimpleQueryCallback cb, - gpointer closure) -{ - NameEmailQueryInfo *info; - gchar *email_query=NULL, *name_query=NULL, *query; - guint tag; - - g_return_val_if_fail (book && E_IS_BOOK (book), 0); - g_return_val_if_fail (cb != NULL, 0); - - if (name && !*name) - name = NULL; - if (email && !*email) - email = NULL; - - if (name == NULL && email == NULL) - return 0; - - /* Build our e-mail query. - * We only query against the username part of the address, to avoid not matching - * fred@foo.com and fred@mail.foo.com. While their may be namespace collisions - * in the usernames of everyone out there, it shouldn't be that bad. (Famous last words.) - */ - if (email) { - const gchar *t=email; - while (*t && *t != '@') - ++t; - if (*t == '@') { - email_query = g_strdup_printf ("(beginswith \"email\" \"%.*s@\")", t-email, email); - - } else { - email_query = g_strdup_printf ("(beginswith \"email\" \"%s\")", email); - } - } - - /* Build our name query. - * We only do name-query stuff if we don't have an e-mail address. Our basic assumption - * is that the username part of the email is good enough to keep the amount of stuff returned - * in the query relatively small. - */ - if (name && !email) { - gchar *name_cpy = g_strdup (name), *qjoined; - gchar **namev; - gint i, count=0; - - g_strstrip (name_cpy); - namev = g_strsplit (" ", name_cpy, 0); - for (i=0; namev[i]; ++i) { - if (*namev[i]) { - namev[i] = g_strdup_printf ("(contains \"file_as\" \"%s\")", namev[i]); - ++count; - } - } - - qjoined = g_strjoinv (" ", namev); - if (count > 1) { - name_query = g_strdup_printf ("(or %s)", qjoined); - } else { - name_query = qjoined; - qjoined = NULL; - } - - - g_free (name_cpy); - for (i=0; namev[i]; ++i) - if (*namev[i]) - g_free (namev[i]); - g_free (namev); - g_free (qjoined); - } - - /* Assemble our e-mail & name queries */ - if (email_query && name_query) { - query = g_strdup_printf ("(and %s %s)", email_query, name_query); - } else if (email_query) { - query = email_query; - email_query = NULL; - } else if (name_query) { - query = name_query; - name_query = NULL; - } else - return 0; - - info = g_new0 (NameEmailQueryInfo, 1); - info->name = g_strdup (name); - info->email = g_strdup (email); - info->cb = cb; - info->closure = closure; - - tag = e_book_simple_query (book, query, name_and_email_cb, info); - - g_free (email_query); - g_free (name_query); - g_free (query); - - return tag; -} - -/* - * Convenience routine to check for addresses in the local address book. - */ - -typedef struct _HaveAddressInfo HaveAddressInfo; -struct _HaveAddressInfo { - gchar *email; - EBookHaveAddressCallback cb; - gpointer closure; -}; - -static void -have_address_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) -{ - HaveAddressInfo *info = (HaveAddressInfo *) closure; - - - info->cb (book, - info->email, - cards && (status == E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS) ? E_CARD (cards->data) : NULL, - info->closure); - - g_free (info->email); - g_free (info); -} - -static void -have_address_book_open_cb (EBook *book, gpointer closure) -{ - HaveAddressInfo *info = (HaveAddressInfo *) closure; - - if (book) { - - e_book_name_and_email_query (book, NULL, info->email, have_address_query_cb, info); - - } else { - - info->cb (NULL, info->email, NULL, info->closure); - - g_free (info->email); - g_free (info); - - } -} - -void -e_book_query_address_locally (const gchar *email, - EBookHaveAddressCallback cb, - gpointer closure) -{ - HaveAddressInfo *info; - - g_return_if_fail (email != NULL); - g_return_if_fail (cb != NULL); - - info = g_new0 (HaveAddressInfo, 1); - info->email = g_strdup (email); - info->cb = cb; - info->closure = closure; - - e_book_use_local_address_book (have_address_book_open_cb, info); -} diff --git a/addressbook/backend/ebook/e-book-util.h b/addressbook/backend/ebook/e-book-util.h deleted file mode 100644 index 0988887324..0000000000 --- a/addressbook/backend/ebook/e-book-util.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-book-util.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#ifndef __E_BOOK_UTIL_H__ -#define __E_BOOK_UTIL_H__ - -#include <libgnome/gnome-defs.h> -#include "e-book.h" - -BEGIN_GNOME_DECLS - -/* Callbacks for asynchronous functions. */ -typedef void (*EBookCommonCallback) (EBook *book, gpointer closure); -typedef void (*EBookSimpleQueryCallback) (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure); -typedef void (*EBookHaveAddressCallback) (EBook *book, const gchar *addr, ECard *card, gpointer closure); - -gboolean e_book_load_local_address_book (EBook *book, - EBookCallback open_response, - gpointer closure); - -void e_book_use_local_address_book (EBookCommonCallback cb, gpointer closure); - -/* Simple Query Interface. */ - -guint e_book_simple_query (EBook *book, - const char *query, - EBookSimpleQueryCallback cb, - gpointer closure); -void e_book_simple_query_cancel (EBook *book, - guint tag); - -/* Specialized Name/Email Queries */ - -guint e_book_name_and_email_query (EBook *book, - const char *name, - const char *email, - EBookSimpleQueryCallback cb, - gpointer closure); - -/* Returns the ECard associated to email in the callback, - or NULL if no match is found in the local address book. */ -void e_book_query_address_locally (const gchar *email, - EBookHaveAddressCallback cb, - gpointer closure); - -END_GNOME_DECLS - - -#endif /* __E_BOOK_UTIL_H__ */ - diff --git a/addressbook/backend/ebook/e-book-view-listener.c b/addressbook/backend/ebook/e-book-view-listener.c deleted file mode 100644 index 7e0f6d5c29..0000000000 --- a/addressbook/backend/ebook/e-book-view-listener.c +++ /dev/null @@ -1,450 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Exports the BookViewListener interface. Maintains a queue of messages - * which come in on the interface. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-book-view-listener.h" -#include "e-book-view.h" -#include "e-card.h" - -enum { - RESPONSES_QUEUED, - LAST_SIGNAL -}; - -static guint e_book_view_listener_signals [LAST_SIGNAL]; - -static BonoboObjectClass *e_book_view_listener_parent_class; -POA_GNOME_Evolution_Addressbook_BookViewListener__vepv e_book_view_listener_vepv; - -struct _EBookViewListenerPrivate { - GList *response_queue; - gint idle_id; - - guint stopped : 1; -}; - -/* Only release our listener reference when the idle is finished. */ -static gboolean -e_book_view_listener_check_queue (EBookViewListener *listener) -{ - if (listener->priv->stopped) { - listener->priv->idle_id = 0; - bonobo_object_unref (BONOBO_OBJECT (listener)); - return FALSE; - } - - if (listener->priv->response_queue != NULL) { - gtk_signal_emit (GTK_OBJECT (listener), - e_book_view_listener_signals [RESPONSES_QUEUED]); - } - - if (listener->priv->response_queue == NULL) { - listener->priv->idle_id = 0; - bonobo_object_unref (BONOBO_OBJECT (listener)); - return FALSE; - } - - return TRUE; -} - -static void -e_book_view_listener_queue_response (EBookViewListener *listener, - EBookViewListenerResponse *response) -{ - listener->priv->response_queue = - g_list_append (listener->priv->response_queue, - response); - - if (listener->priv->idle_id == 0) { - - /* Hold a reference to the listener while the idle is active. */ - bonobo_object_ref (BONOBO_OBJECT (listener)); - - listener->priv->idle_id = g_idle_add ( - (GSourceFunc) e_book_view_listener_check_queue, listener); - } -} - -/* Add, Remove, Modify */ -static void -e_book_view_listener_queue_empty_event (EBookViewListener *listener, - EBookViewListenerOperation op) -{ - EBookViewListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookViewListenerResponse, 1); - - resp->op = op; - resp->id = NULL; - resp->cards = NULL; - resp->message = NULL; - - e_book_view_listener_queue_response (listener, resp); -} - -/* Add, Remove, Modify */ -static void -e_book_view_listener_queue_id_event (EBookViewListener *listener, - EBookViewListenerOperation op, - const char *id) -{ - EBookViewListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookViewListenerResponse, 1); - - resp->op = op; - resp->id = g_strdup (id); - resp->cards = NULL; - resp->message = NULL; - - e_book_view_listener_queue_response (listener, resp); -} - -/* Add, Remove, Modify */ -static void -e_book_view_listener_queue_sequence_event (EBookViewListener *listener, - EBookViewListenerOperation op, - const GNOME_Evolution_Addressbook_VCardList *cards) -{ - EBookViewListenerResponse *resp; - int i; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookViewListenerResponse, 1); - - resp->op = op; - resp->id = NULL; - resp->cards = NULL; - resp->message = NULL; - - for ( i = 0; i < cards->_length; i++ ) { - resp->cards = g_list_append(resp->cards, e_card_new(cards->_buffer[i])); - } - - e_book_view_listener_queue_response (listener, resp); -} - -/* Status Message */ -static void -e_book_view_listener_queue_message_event (EBookViewListener *listener, - EBookViewListenerOperation op, - const char *message) -{ - EBookViewListenerResponse *resp; - - if (listener->priv->stopped) - return; - - resp = g_new0 (EBookViewListenerResponse, 1); - - resp->op = op; - resp->id = NULL; - resp->cards = NULL; - resp->message = g_strdup(message); - - e_book_view_listener_queue_response (listener, resp); -} - -static void -impl_BookViewListener_notify_card_added (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_VCardList *cards, - CORBA_Environment *ev) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (bonobo_object_from_servant (servant)); - - e_book_view_listener_queue_sequence_event ( - listener, CardAddedEvent, cards); -} - -static void -impl_BookViewListener_notify_card_removed (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_CardId id, - CORBA_Environment *ev) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (bonobo_object_from_servant (servant)); - - e_book_view_listener_queue_id_event ( - listener, CardRemovedEvent, (const char *) id); -} - -static void -impl_BookViewListener_notify_card_changed (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_VCardList *cards, - CORBA_Environment *ev) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (bonobo_object_from_servant (servant)); - - e_book_view_listener_queue_sequence_event ( - listener, CardModifiedEvent, cards); -} - -static void -impl_BookViewListener_notify_sequence_complete (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (bonobo_object_from_servant (servant)); - - e_book_view_listener_queue_empty_event (listener, SequenceCompleteEvent); -} - -static void -impl_BookViewListener_notify_status_message (PortableServer_Servant servant, - const char *message, - CORBA_Environment *ev) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (bonobo_object_from_servant (servant)); - - e_book_view_listener_queue_message_event (listener, StatusMessageEvent, message); -} - -/** - * e_book_view_listener_check_pending: - * @listener: the #EBookViewListener - * - * Returns: the number of items on the response queue, - * or -1 if the @listener is isn't an #EBookViewListener. - */ -int -e_book_view_listener_check_pending (EBookViewListener *listener) -{ - g_return_val_if_fail (listener != NULL, -1); - g_return_val_if_fail (E_IS_BOOK_VIEW_LISTENER (listener), -1); - - return g_list_length (listener->priv->response_queue); -} - -/** - * e_book_view_listener_pop_response: - * @listener: the #EBookViewListener for which a request is to be popped - * - * Returns: an #EBookViewListenerResponse if there are responses on the - * queue to be returned; %NULL if there aren't, or if the @listener - * isn't an EBookViewListener. - */ -EBookViewListenerResponse * -e_book_view_listener_pop_response (EBookViewListener *listener) -{ - EBookViewListenerResponse *resp; - GList *popped; - - g_return_val_if_fail (listener != NULL, NULL); - g_return_val_if_fail (E_IS_BOOK_VIEW_LISTENER (listener), NULL); - - if (listener->priv->response_queue == NULL) - return NULL; - - resp = listener->priv->response_queue->data; - - popped = listener->priv->response_queue; - listener->priv->response_queue = - g_list_remove_link (listener->priv->response_queue, - listener->priv->response_queue); - g_list_free_1 (popped); - - return resp; -} - -static EBookViewListener * -e_book_view_listener_construct (EBookViewListener *listener) -{ - POA_GNOME_Evolution_Addressbook_BookViewListener *servant; - CORBA_Environment ev; - CORBA_Object obj; - - g_assert (listener != NULL); - g_assert (E_IS_BOOK_VIEW_LISTENER (listener)); - - servant = (POA_GNOME_Evolution_Addressbook_BookViewListener *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &e_book_view_listener_vepv; - - CORBA_exception_init (&ev); - - POA_GNOME_Evolution_Addressbook_BookViewListener__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - - return NULL; - } - - CORBA_exception_free (&ev); - - obj = bonobo_object_activate_servant (BONOBO_OBJECT (listener), servant); - if (obj == CORBA_OBJECT_NIL) { - g_free (servant); - - return NULL; - } - - bonobo_object_construct (BONOBO_OBJECT (listener), obj); - - return listener; -} - -/** - * e_book_view_listener_new: - * @book: the #EBookView for which the listener is to be bound - * - * Creates and returns a new #EBookViewListener for the book. - * - * Returns: a new #EBookViewListener - */ -EBookViewListener * -e_book_view_listener_new () -{ - EBookViewListener *listener; - EBookViewListener *retval; - - listener = gtk_type_new (E_BOOK_VIEW_LISTENER_TYPE); - - retval = e_book_view_listener_construct (listener); - - if (retval == NULL) { - g_warning ("e_book_view_listener_new: Error constructing " - "EBookViewListener!\n"); - bonobo_object_unref (BONOBO_OBJECT (listener)); - return NULL; - } - - return retval; -} - -static void -e_book_view_listener_init (EBookViewListener *listener) -{ - listener->priv = g_new0 (EBookViewListenerPrivate, 1); - listener->priv->response_queue = NULL; - listener->priv->idle_id = 0; - listener->priv->stopped = FALSE; -} - -void -e_book_view_listener_stop (EBookViewListener *listener) -{ - GList *l; - - if (listener->priv->stopped) - return; - - if (listener->priv->idle_id) { - g_source_remove(listener->priv->idle_id); - listener->priv->idle_id = 0; - bonobo_object_unref (BONOBO_OBJECT (listener)); - } - - for (l = listener->priv->response_queue; l != NULL; l = l->next) { - EBookViewListenerResponse *resp = l->data; - - g_free(resp->id); - - g_list_foreach(resp->cards, (GFunc) gtk_object_unref, NULL); - g_list_free(resp->cards); - - g_free (resp->message); - - g_free (resp); - } - g_list_free (listener->priv->response_queue); - listener->priv->response_queue = NULL; - - listener->priv->stopped = TRUE; -} - -static void -e_book_view_listener_destroy (GtkObject *object) -{ - EBookViewListener *listener = E_BOOK_VIEW_LISTENER (object); - - e_book_view_listener_stop (listener); - g_free (listener->priv); - - GTK_OBJECT_CLASS (e_book_view_listener_parent_class)->destroy (object); -} - -POA_GNOME_Evolution_Addressbook_BookViewListener__epv * -e_book_view_listener_get_epv (void) -{ - POA_GNOME_Evolution_Addressbook_BookViewListener__epv *epv; - - epv = g_new0 (POA_GNOME_Evolution_Addressbook_BookViewListener__epv, 1); - - epv->notifyCardChanged = impl_BookViewListener_notify_card_changed; - epv->notifyCardRemoved = impl_BookViewListener_notify_card_removed; - epv->notifyCardAdded = impl_BookViewListener_notify_card_added; - epv->notifySequenceComplete = impl_BookViewListener_notify_sequence_complete; - epv->notifyStatusMessage = impl_BookViewListener_notify_status_message; - - return epv; -} - -static void -e_book_view_listener_corba_class_init (void) -{ - e_book_view_listener_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - e_book_view_listener_vepv.GNOME_Evolution_Addressbook_BookViewListener_epv = e_book_view_listener_get_epv (); -} - -static void -e_book_view_listener_class_init (EBookViewListenerClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - e_book_view_listener_parent_class = gtk_type_class (bonobo_object_get_type ()); - - e_book_view_listener_signals [RESPONSES_QUEUED] = - gtk_signal_new ("responses_queued", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewListenerClass, responses_queued), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_book_view_listener_signals, LAST_SIGNAL); - - object_class->destroy = e_book_view_listener_destroy; - - e_book_view_listener_corba_class_init (); -} - -/** - * e_book_view_listener_get_type: - */ -GtkType -e_book_view_listener_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "EBookViewListener", - sizeof (EBookViewListener), - sizeof (EBookViewListenerClass), - (GtkClassInitFunc) e_book_view_listener_class_init, - (GtkObjectInitFunc) e_book_view_listener_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/ebook/e-book-view-listener.h b/addressbook/backend/ebook/e-book-view-listener.h deleted file mode 100644 index d373872ad0..0000000000 --- a/addressbook/backend/ebook/e-book-view-listener.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * A client-side GtkObject which exposes the - * Evolution:BookViewListener interface. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_BOOK_VIEW_LISTENER_H__ -#define __E_BOOK_VIEW_LISTENER_H__ - -#include <libgnome/gnome-defs.h> -#include <bonobo/bonobo-object.h> -#include <addressbook/backend/ebook/addressbook.h> - -BEGIN_GNOME_DECLS - -typedef struct _EBookViewListener EBookViewListener; -typedef struct _EBookViewListenerClass EBookViewListenerClass; -typedef struct _EBookViewListenerPrivate EBookViewListenerPrivate; - -struct _EBookViewListener { - BonoboObject parent; - EBookViewListenerPrivate *priv; -}; - -struct _EBookViewListenerClass { - BonoboObjectClass parent; - - /* - * Signals - */ - void (*responses_queued) (void); -}; - -typedef enum { - /* Async events */ - CardAddedEvent, - CardRemovedEvent, - CardModifiedEvent, - SequenceCompleteEvent, - StatusMessageEvent, -} EBookViewListenerOperation; - -typedef struct { - EBookViewListenerOperation op; - - /* For CardRemovedEvent */ - char *id; - - /* For Card[Added|Modified]Event */ - GList *cards; /* Of type ECard. */ - - /* For StatusMessageEvent */ - char *message; - -} EBookViewListenerResponse; - -EBookViewListener *e_book_view_listener_new (void); -int e_book_view_listener_check_pending (EBookViewListener *listener); -EBookViewListenerResponse *e_book_view_listener_pop_response (EBookViewListener *listener); -GtkType e_book_view_listener_get_type (void); -void e_book_view_listener_stop (EBookViewListener *listener); - -POA_GNOME_Evolution_Addressbook_BookViewListener__epv *e_book_view_listener_get_epv (void); - -#define E_BOOK_VIEW_LISTENER_TYPE (e_book_view_listener_get_type ()) -#define E_BOOK_VIEW_LISTENER(o) (GTK_CHECK_CAST ((o), E_BOOK_VIEW_LISTENER_TYPE, EBookViewListener)) -#define E_BOOK_VIEW_LISTENER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BOOK_VIEW_LISTENER_TYPE, EBookViewListenerClass)) -#define E_IS_BOOK_VIEW_LISTENER(o) (GTK_CHECK_TYPE ((o), E_BOOK_VIEW_LISTENER_TYPE)) -#define E_IS_BOOK_VIEW_LISTENER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_BOOK_VIEW_LISTENER_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __E_BOOK_VIEW_LISTENER_H__ */ diff --git a/addressbook/backend/ebook/e-book-view.c b/addressbook/backend/ebook/e-book-view.c deleted file mode 100644 index 7dbe7d46fb..0000000000 --- a/addressbook/backend/ebook/e-book-view.c +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * The Evolution addressbook client object. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 1999, 2000, Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkmarshal.h> - -#include "addressbook.h" -#include "e-card-cursor.h" -#include "e-book-view-listener.h" -#include "e-book-view.h" -#include "e-book.h" - -GtkObjectClass *e_book_view_parent_class; - -struct _EBookViewPrivate { - GNOME_Evolution_Addressbook_BookView corba_book_view; - - EBook *book; - - EBookViewListener *listener; - - int responses_queued_id; -}; - -enum { - CARD_CHANGED, - CARD_REMOVED, - CARD_ADDED, - SEQUENCE_COMPLETE, - STATUS_MESSAGE, - LAST_SIGNAL -}; - -static guint e_book_view_signals [LAST_SIGNAL]; - -static void -add_book_iterator (gpointer data, gpointer closure) -{ - ECard *card = E_CARD (data); - EBook *book = E_BOOK (closure); - - if (card->book == NULL) { - card->book = book; - gtk_object_ref (GTK_OBJECT (book)); - } -} - -static void -e_book_view_do_added_event (EBookView *book_view, - EBookViewListenerResponse *resp) -{ - if (book_view->priv->book) - g_list_foreach (resp->cards, add_book_iterator, book_view->priv->book); - - gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [CARD_ADDED], - resp->cards); - - g_list_foreach (resp->cards, (GFunc) gtk_object_unref, NULL); - g_list_free (resp->cards); -} - -static void -e_book_view_do_modified_event (EBookView *book_view, - EBookViewListenerResponse *resp) -{ - if (book_view->priv->book) - g_list_foreach (resp->cards, add_book_iterator, book_view->priv->book); - - gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [CARD_CHANGED], - resp->cards); - - g_list_foreach (resp->cards, (GFunc) gtk_object_unref, NULL); - g_list_free (resp->cards); -} - -static void -e_book_view_do_removed_event (EBookView *book_view, - EBookViewListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [CARD_REMOVED], - resp->id); - - g_free(resp->id); -} - -static void -e_book_view_do_complete_event (EBookView *book_view, - EBookViewListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [SEQUENCE_COMPLETE]); -} - -static void -e_book_view_do_status_message_event (EBookView *book_view, - EBookViewListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book_view), e_book_view_signals [STATUS_MESSAGE], - resp->message); - g_free(resp->message); -} - - -/* - * Reading notices out of the EBookViewListener's queue. - */ -static void -e_book_view_check_listener_queue (EBookViewListener *listener, EBookView *book_view) -{ - EBookViewListenerResponse *resp; - - resp = e_book_view_listener_pop_response (listener); - - if (resp == NULL) - return; - - switch (resp->op) { - case CardAddedEvent: - e_book_view_do_added_event (book_view, resp); - break; - case CardModifiedEvent: - e_book_view_do_modified_event (book_view, resp); - break; - case CardRemovedEvent: - e_book_view_do_removed_event (book_view, resp); - break; - case SequenceCompleteEvent: - e_book_view_do_complete_event (book_view, resp); - break; - case StatusMessageEvent: - e_book_view_do_status_message_event (book_view, resp); - break; - default: - g_error ("EBookView: Unknown operation %d in listener queue!\n", - resp->op); - break; - } - - g_free (resp); -} - -static gboolean -e_book_view_construct (EBookView *book_view, GNOME_Evolution_Addressbook_BookView corba_book_view, EBookViewListener *listener) -{ - CORBA_Environment ev; - g_return_val_if_fail (book_view != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK_VIEW (book_view), FALSE); - - /* - * Copy in the corba_book_view. - */ - CORBA_exception_init (&ev); - - book_view->priv->corba_book_view = bonobo_object_dup_ref(corba_book_view, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_view_construct: Exception duplicating corba_book_view.\n"); - CORBA_exception_free (&ev); - book_view->priv->corba_book_view = NULL; - return FALSE; - } - - CORBA_exception_free (&ev); - - /* - * Create our local BookListener interface. - */ - book_view->priv->listener = listener; - - bonobo_object_ref(BONOBO_OBJECT(book_view->priv->listener)); - book_view->priv->responses_queued_id = gtk_signal_connect (GTK_OBJECT (book_view->priv->listener), "responses_queued", - e_book_view_check_listener_queue, book_view); - - return TRUE; -} - -/** - * e_book_view_new: - */ -EBookView * -e_book_view_new (GNOME_Evolution_Addressbook_BookView corba_book_view, EBookViewListener *listener) -{ - EBookView *book_view; - - book_view = gtk_type_new (E_BOOK_VIEW_TYPE); - - if (! e_book_view_construct (book_view, corba_book_view, listener)) { - gtk_object_unref (GTK_OBJECT (book_view)); - return NULL; - } - - return book_view; -} - -void -e_book_view_set_book (EBookView *book_view, EBook *book) -{ - g_return_if_fail (book_view && E_IS_BOOK_VIEW (book_view)); - g_return_if_fail (book && E_IS_BOOK (book)); - g_return_if_fail (book_view->priv->book == NULL); - - book_view->priv->book = book; - gtk_object_ref (GTK_OBJECT (book)); -} - -static void -e_book_view_init (EBookView *book_view) -{ - book_view->priv = g_new0 (EBookViewPrivate, 1); - book_view->priv->book = NULL; - book_view->priv->corba_book_view = CORBA_OBJECT_NIL; - book_view->priv->listener = NULL; - book_view->priv->responses_queued_id = 0; -} - -static void -e_book_view_destroy (GtkObject *object) -{ - EBookView *book_view = E_BOOK_VIEW (object); - CORBA_Environment ev; - - if (book_view->priv->book) { - gtk_object_unref (GTK_OBJECT (book_view->priv->book)); - } - - if (book_view->priv->corba_book_view) { - CORBA_exception_init (&ev); - - bonobo_object_release_unref (book_view->priv->corba_book_view, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("EBookView: Exception while releasing BookView\n"); - } - - CORBA_exception_free (&ev); - } - - if (book_view->priv->listener) { - if (book_view->priv->responses_queued_id) - gtk_signal_disconnect(GTK_OBJECT(book_view->priv->listener), - book_view->priv->responses_queued_id); - e_book_view_listener_stop (book_view->priv->listener); - bonobo_object_unref (BONOBO_OBJECT(book_view->priv->listener)); - } - - g_free (book_view->priv); - - if (GTK_OBJECT_CLASS (e_book_view_parent_class)->destroy) - GTK_OBJECT_CLASS (e_book_view_parent_class)->destroy (object); -} - -static void -e_book_view_class_init (EBookViewClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - e_book_view_parent_class = gtk_type_class (gtk_object_get_type ()); - - e_book_view_signals [CARD_CHANGED] = - gtk_signal_new ("card_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewClass, card_changed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - e_book_view_signals [CARD_ADDED] = - gtk_signal_new ("card_added", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewClass, card_added), - gtk_marshal_NONE__STRING, - GTK_TYPE_NONE, 1, - GTK_TYPE_STRING); - - e_book_view_signals [CARD_REMOVED] = - gtk_signal_new ("card_removed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewClass, card_removed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - e_book_view_signals [SEQUENCE_COMPLETE] = - gtk_signal_new ("sequence_complete", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewClass, sequence_complete), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_book_view_signals [STATUS_MESSAGE] = - gtk_signal_new ("status_message", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookViewClass, status_message), - gtk_marshal_NONE__STRING, - GTK_TYPE_NONE, 1, - GTK_TYPE_STRING); - - gtk_object_class_add_signals (object_class, e_book_view_signals, - LAST_SIGNAL); - - klass->card_changed = NULL; - klass->card_added = NULL; - klass->card_removed = NULL; - klass->sequence_complete = NULL; - klass->status_message = NULL; - - object_class->destroy = e_book_view_destroy; -} - -/** - * e_book_view_get_type: - */ -GtkType -e_book_view_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "EBookView", - sizeof (EBookView), - sizeof (EBookViewClass), - (GtkClassInitFunc) e_book_view_class_init, - (GtkObjectInitFunc) e_book_view_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/ebook/e-book-view.h b/addressbook/backend/ebook/e-book-view.h deleted file mode 100644 index 5e576d6642..0000000000 --- a/addressbook/backend/ebook/e-book-view.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * The Evolution addressbook client object. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 1999, 2000, Ximian, Inc. - */ - -#ifndef __E_BOOK_VIEW_H__ -#define __E_BOOK_VIEW_H__ - -#include <libgnome/gnome-defs.h> - -#include <addressbook/backend/ebook/e-card.h> -#include <addressbook/backend/ebook/e-book-view-listener.h> - -BEGIN_GNOME_DECLS - -typedef struct _EBookView EBookView; -typedef struct _EBookViewClass EBookViewClass; -typedef struct _EBookViewPrivate EBookViewPrivate; - -struct _EBook; /* Forward reference */ - -struct _EBookView { - GtkObject parent; - EBookViewPrivate *priv; -}; - -struct _EBookViewClass { - GtkObjectClass parent; - - /* - * Signals. - */ - void (* card_changed) (EBookView *book_view, const GList *cards); - void (* card_removed) (EBookView *book_view, const char *id); - void (* card_added) (EBookView *book_view, const GList *cards); - void (* sequence_complete) (EBookView *book_view); - void (* status_message) (EBookView *book_view, const char *message); -}; - -/* Creating a new addressbook. */ -EBookView *e_book_view_new (GNOME_Evolution_Addressbook_BookView corba_book_view, EBookViewListener *listener); - -GtkType e_book_view_get_type (void); - -void e_book_view_set_book (EBookView *book_view, struct _EBook *book); - -#define E_BOOK_VIEW_TYPE (e_book_view_get_type ()) -#define E_BOOK_VIEW(o) (GTK_CHECK_CAST ((o), E_BOOK_VIEW_TYPE, EBookView)) -#define E_BOOK_VIEW_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BOOK_VIEW_TYPE, EBookViewClass)) -#define E_IS_BOOK_VIEW(o) (GTK_CHECK_TYPE ((o), E_BOOK_VIEW_TYPE)) -#define E_IS_BOOK_VIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_BOOK_VIEW_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __E_BOOK_VIEW_H__ */ diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c deleted file mode 100644 index 9c8111b714..0000000000 --- a/addressbook/backend/ebook/e-book.c +++ /dev/null @@ -1,1346 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * The Evolution addressbook client object. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 1999, 2000, Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkmarshal.h> -#include <libgnome/gnome-defs.h> -#include <liboaf/liboaf.h> - -#include "addressbook.h" -#include "e-card-cursor.h" -#include "e-book-listener.h" -#include "e-book.h" - -GtkObjectClass *e_book_parent_class; - -#define CARDSERVER_OAF_ID "OAFIID:GNOME_Evolution_Wombat_ServerFactory" - -typedef enum { - URINotLoaded, - URILoading, - URILoaded -} EBookLoadState; - -struct _EBookPrivate { - GNOME_Evolution_Addressbook_BookFactory book_factory; - EBookListener *listener; - - GNOME_Evolution_Addressbook_Book corba_book; - - EBookLoadState load_state; - - /* - * The operation queue. New operations are appended to the - * end of the queue. When responses come back from the PAS, - * the op structures are popped off the front of the queue. - */ - GList *pending_ops; - - guint op_tag; - - gchar *uri; -}; - -enum { - OPEN_PROGRESS, - WRITABLE_STATUS, - LINK_STATUS, - LAST_SIGNAL -}; - -static guint e_book_signals [LAST_SIGNAL]; - -typedef struct { - guint tag; - gboolean active; - gpointer cb; - gpointer closure; - EBookViewListener *listener; -} EBookOp; - -/* - * Local response queue management. - */ -static guint -e_book_queue_op (EBook *book, - gpointer cb, - gpointer closure, - EBookViewListener *listener) -{ - EBookOp *op; - - op = g_new0 (EBookOp, 1); - op->tag = book->priv->op_tag++; - op->active = TRUE; - op->cb = cb; - op->closure = closure; - op->listener = listener; - - book->priv->pending_ops = - g_list_append (book->priv->pending_ops, op); - - return op->tag; -} - -/* - * Local response queue management. - */ -static void -e_book_unqueue_op (EBook *book) -{ - EBookOp *op; - GList *removed; - - removed = g_list_last (book->priv->pending_ops); - - if (removed) { - book->priv->pending_ops = g_list_remove_link (book->priv->pending_ops, - removed); - op = removed->data; - g_free (op); - g_list_free_1 (removed); - book->priv->op_tag--; - } -} - -static EBookOp * -e_book_pop_op (EBook *book) -{ - GList *popped; - EBookOp *op; - - if (book->priv->pending_ops == NULL) - return NULL; - - op = book->priv->pending_ops->data; - - popped = book->priv->pending_ops; - book->priv->pending_ops = - g_list_remove_link (book->priv->pending_ops, - book->priv->pending_ops); - - g_list_free_1 (popped); - - return op; -} - -static gboolean -e_book_cancel_op (EBook *book, guint tag) -{ - GList *iter; - gboolean cancelled = FALSE; - - for (iter = book->priv->pending_ops; iter != NULL && !cancelled; iter = g_list_next (iter)) { - EBookOp *op = iter->data; - if (op->tag == tag) { - op->active = FALSE; - cancelled = TRUE; - } - } - - return cancelled; -} - -static void -e_book_do_response_create_card (EBook *book, - EBookListenerResponse *resp) -{ - EBookOp *op; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_create_card: Cannot find operation " - "in local op queue!\n"); - return; - } - - if (op->cb) - ((EBookIdCallback) op->cb) (book, resp->status, resp->id, op->closure); - g_free (resp->id); - g_free (op); -} - -static void -e_book_do_response_generic (EBook *book, - EBookListenerResponse *resp) -{ - EBookOp *op; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_generic: Cannot find operation " - "in local op queue!\n"); - } - - if (op->cb) - ((EBookCallback) op->cb) (book, resp->status, op->closure); - - g_free (op); -} - -static void -e_book_do_response_get_cursor (EBook *book, - EBookListenerResponse *resp) -{ - CORBA_Environment ev; - EBookOp *op; - ECardCursor *cursor; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_get_cursor: Cannot find operation " - "in local op queue!\n"); - return; - } - - cursor = e_card_cursor_new(resp->cursor); - - if (cursor != NULL) { - if (op->cb) { - if (op->active) - ((EBookCursorCallback) op->cb) (book, resp->status, cursor, op->closure); - else - ((EBookCursorCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - /* - * Release the remote GNOME_Evolution_Addressbook_Book in the PAS. - */ - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_do_response_get_cursor: Exception releasing " - "remote GNOME_Evolution_Addressbook_CardCursor interface!\n"); - } - - CORBA_exception_free (&ev); - - gtk_object_unref(GTK_OBJECT(cursor)); - } else { - ((EBookCursorCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - g_free (op); -} - - - -static void -e_book_do_response_get_view (EBook *book, - EBookListenerResponse *resp) -{ - CORBA_Environment ev; - EBookOp *op; - EBookView *book_view; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_get_view: Cannot find operation " - "in local op queue!\n"); - return; - } - - book_view = e_book_view_new(resp->book_view, op->listener); - - if (book_view != NULL) { - e_book_view_set_book (book_view, book); - - /* Only execute the callback if the operation is still flagged as active (i.e. hasn't - been cancelled. This is mildly wasteful since we unnecessaryily create the - book_view, etc... but I'm leery of tinkering with the CORBA magic. */ - if (op->cb) { - if (op->active) - ((EBookBookViewCallback) op->cb) (book, resp->status, book_view, op->closure); - else - ((EBookBookViewCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - /* - * Release the remote GNOME_Evolution_Addressbook_Book in the PAS. - */ - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->book_view, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_do_response_get_view: Exception releasing " - "remote GNOME_Evolution_Addressbook_BookView interface!\n"); - } - - CORBA_exception_free (&ev); - - gtk_object_unref(GTK_OBJECT(book_view)); - } else { - e_book_view_listener_stop (op->listener); - ((EBookBookViewCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - bonobo_object_unref(BONOBO_OBJECT(op->listener)); - g_free (op); -} - -static void -e_book_do_response_get_changes (EBook *book, - EBookListenerResponse *resp) -{ - CORBA_Environment ev; - EBookOp *op; - EBookView *book_view; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_get_changes: Cannot find operation " - "in local op queue!\n"); - return; - } - - book_view = e_book_view_new (resp->book_view, op->listener); - - if (book_view != NULL) { - e_book_view_set_book (book_view, book); - - if (op->cb) { - if (op->active) - ((EBookBookViewCallback) op->cb) (book, resp->status, book_view, op->closure); - else - ((EBookBookViewCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - /* - * Release the remote GNOME_Evolution_Addressbook_BookView in the PAS. - */ - CORBA_exception_init (&ev); - - bonobo_object_release_unref (resp->book_view, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_do_response_get_changes: Exception releasing " - "remote GNOME_Evolution_Addressbook_BookView interface!\n"); - } - - CORBA_exception_free (&ev); - - gtk_object_unref(GTK_OBJECT(book_view)); - } else { - e_book_view_listener_stop (op->listener); - ((EBookBookViewCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - bonobo_object_unref(BONOBO_OBJECT(op->listener)); - g_free (op); -} - -static void -e_book_do_response_open (EBook *book, - EBookListenerResponse *resp) -{ - EBookOp *op; - - if (resp->status == E_BOOK_STATUS_SUCCESS) { - book->priv->corba_book = resp->book; - book->priv->load_state = URILoaded; - } - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_open: Cannot find operation " - "in local op queue!\n"); - return; - } - - if (op->cb) - ((EBookCallback) op->cb) (book, resp->status, op->closure); - g_free (op); -} - -static void -e_book_do_progress_event (EBook *book, - EBookListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book), e_book_signals [OPEN_PROGRESS], - resp->msg, resp->percent); - - g_free (resp->msg); -} - -static void -e_book_do_link_event (EBook *book, - EBookListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book), e_book_signals [LINK_STATUS], - resp->connected); -} - -static void -e_book_do_writable_event (EBook *book, - EBookListenerResponse *resp) -{ - gtk_signal_emit (GTK_OBJECT (book), e_book_signals [WRITABLE_STATUS], - resp->writable); -} - -static void -e_book_do_response_get_supported_fields (EBook *book, - EBookListenerResponse *resp) -{ - EBookOp *op; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_get_supported_fields: Cannot find operation " - "in local op queue!\n"); - return; - } - - if (op->cb) { - if (op->active) - ((EBookFieldsCallback) op->cb) (book, resp->status, resp->fields, op->closure); - else - ((EBookFieldsCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - g_free (op); -} - -/* - * Reading notices out of the EBookListener's queue. - */ -static void -e_book_check_listener_queue (EBookListener *listener, EBook *book) -{ - EBookListenerResponse *resp; - - resp = e_book_listener_pop_response (listener); - - if (resp == NULL) - return; - - switch (resp->op) { - case CreateCardResponse: - e_book_do_response_create_card (book, resp); - break; - case RemoveCardResponse: - case ModifyCardResponse: - case AuthenticationResponse: - e_book_do_response_generic (book, resp); - break; - case GetCursorResponse: - e_book_do_response_get_cursor (book, resp); - break; - case GetBookViewResponse: - e_book_do_response_get_view(book, resp); - break; - case GetChangesResponse: - e_book_do_response_get_changes(book, resp); - break; - case OpenBookResponse: - e_book_do_response_open (book, resp); - break; - case GetSupportedFieldsResponse: - e_book_do_response_get_supported_fields (book, resp); - break; - - case OpenProgressEvent: - e_book_do_progress_event (book, resp); - break; - case LinkStatusEvent: - e_book_do_link_event (book, resp); - break; - case WritableStatusEvent: - e_book_do_writable_event (book, resp); - break; - default: - g_error ("EBook: Unknown operation %d in listener queue!\n", - resp->op); - } - - g_free (resp); -} - -/** - * e_book_load_uri: - */ - -gboolean -e_book_load_uri (EBook *book, - const char *uri, - EBookCallback open_response, - gpointer closure) -{ - CORBA_Environment ev; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (uri != NULL, FALSE); - g_return_val_if_fail (open_response != NULL, FALSE); - - if (book->priv->load_state != URINotLoaded) { - g_warning ("e_book_load_uri: Attempted to load a URI " - "on a book which already has a URI loaded!\n"); - return FALSE; - } - - g_free (book->priv->uri); - book->priv->uri = g_strdup (uri); - - /* - * Create our local BookListener interface. - */ - book->priv->listener = e_book_listener_new (); - if (book->priv->listener == NULL) { - g_warning ("e_book_load_uri: Could not create EBookListener!\n"); - return FALSE; - } - - gtk_signal_connect (GTK_OBJECT (book->priv->listener), "responses_queued", - e_book_check_listener_queue, book); - - /* - * Load the addressbook into the PAS. - */ - CORBA_exception_init (&ev); - - e_book_queue_op (book, open_response, closure, NULL); - - GNOME_Evolution_Addressbook_BookFactory_openBook ( - book->priv->book_factory, uri, - bonobo_object_corba_objref (BONOBO_OBJECT (book->priv->listener)), - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_load_uri: CORBA exception while opening addressbook!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return FALSE; - } - - CORBA_exception_free (&ev); - - book->priv->load_state = URILoading; - - /* Now we play the waiting game. */ - - return TRUE; -} - -/** - * e_book_unload_uri: - */ -void -e_book_unload_uri (EBook *book) -{ - CORBA_Environment ev; - - g_return_if_fail (book != NULL); - g_return_if_fail (E_IS_BOOK (book)); - - /* - * FIXME: Make sure this works if the URI is still being - * loaded. - */ - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_unload_uri: No URI is loaded!\n"); - return; - } - - /* - * Release the remote GNOME_Evolution_Addressbook_Book in the PAS. - */ - CORBA_exception_init (&ev); - - bonobo_object_release_unref (book->priv->corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_unload_uri: Exception releasing " - "remote book interface!\n"); - } - - CORBA_exception_free (&ev); - - e_book_listener_stop (book->priv->listener); - bonobo_object_unref (BONOBO_OBJECT (book->priv->listener)); - - book->priv->listener = NULL; - book->priv->load_state = URINotLoaded; -} - -const char * -e_book_get_uri (EBook *book) -{ - g_return_val_if_fail (book && E_IS_BOOK (book), NULL); - - return book->priv->uri; -} - -char * -e_book_get_static_capabilities (EBook *book) -{ - CORBA_Environment ev; - char *temp; - char *ret_val; - - CORBA_exception_init (&ev); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_unload_uri: No URI is loaded!\n"); - return g_strdup(""); - } - - temp = GNOME_Evolution_Addressbook_Book_getStaticCapabilities(book->priv->corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_static_capabilities: Exception " - "during get_static_capabilities!\n"); - CORBA_exception_free (&ev); - return NULL; - } - - ret_val = g_strdup(temp); - CORBA_free(temp); - - CORBA_exception_free (&ev); - - return ret_val; -} - -guint -e_book_get_supported_fields (EBook *book, - EBookFieldsCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - guint tag; - - CORBA_exception_init (&ev); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_unload_uri: No URI is loaded!\n"); - return 0; - } - - tag = e_book_queue_op (book, cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_getSupportedFields(book->priv->corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_supported_fields: Exception " - "during get_supported_fields!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return 0; - } - - CORBA_exception_free (&ev); - - return tag; -} - -static gboolean -e_book_construct (EBook *book) -{ - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - - /* - * Connect to the Personal Addressbook Server. - */ - - book->priv->book_factory = (GNOME_Evolution_Addressbook_BookFactory) - oaf_activate_from_id (CARDSERVER_OAF_ID, 0, NULL, NULL); - if (book->priv->book_factory == CORBA_OBJECT_NIL) { - g_warning ("e_book_construct: Could not obtain a handle " - "to the Personal Addressbook Server!\n"); - return FALSE; - } - - return TRUE; -} - -/** - * e_book_new: - */ -EBook * -e_book_new (void) -{ - EBook *book; - - book = gtk_type_new (E_BOOK_TYPE); - - if (! e_book_construct (book)) { - gtk_object_unref (GTK_OBJECT (book)); - return NULL; - } - - return book; -} - -/* User authentication. */ - -void -e_book_authenticate_user (EBook *book, - const char *user, - const char *passwd, - EBookCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - - g_return_if_fail (book != NULL); - g_return_if_fail (E_IS_BOOK (book)); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_authenticate_user: No URI loaded!\n"); - return; - } - - CORBA_exception_init (&ev); - - e_book_queue_op (book, cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_authenticateUser (book->priv->corba_book, - user, - passwd, - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_authenticate_user: Exception authenticating user with the PAS!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return; - } - - CORBA_exception_free (&ev); -} - -/* Fetching cards */ - -/** - * e_book_get_card: - */ -ECard * -e_book_get_card (EBook *book, - const char *id) -{ - char *vcard; - ECard *card; - - g_return_val_if_fail (book != NULL, NULL); - g_return_val_if_fail (E_IS_BOOK (book), NULL); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_get_card: No URI loaded!\n"); - return NULL; - } - - vcard = e_book_get_vcard (book, id); - - if (vcard == NULL) { - g_warning ("e_book_get_card: Got bogus VCard from PAS!\n"); - return NULL; - } - - card = e_card_new (vcard); - g_free(vcard); - - e_card_set_id(card, id); - card->book = book; - gtk_object_ref (GTK_OBJECT (card->book)); - - return card; -} - -/** - * e_book_get_vcard: - */ -char * -e_book_get_vcard (EBook *book, - const char *id) -{ - CORBA_Environment ev; - char *retval; - char *vcard; - - g_return_val_if_fail (book != NULL, NULL); - g_return_val_if_fail (E_IS_BOOK (book), NULL); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_get_vcard: No URI loaded!\n"); - return NULL; - } - - CORBA_exception_init (&ev); - - vcard = GNOME_Evolution_Addressbook_Book_getVCard (book->priv->corba_book, - (GNOME_Evolution_Addressbook_CardId) id, - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_vcard: Exception getting VCard from PAS!\n"); - CORBA_exception_free (&ev); - return NULL; - } - - CORBA_exception_free (&ev); - - if (vcard == NULL || strlen (vcard) == 0) { - g_warning ("e_book_get_vcard: Got NULL VCard from PAS!\n"); - return NULL; - } - - retval = g_strdup (vcard); - CORBA_free (vcard); - - return retval; -} - -/* Deleting cards. */ - -/** - * e_book_remove_card: - */ -gboolean -e_book_remove_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure) -{ - const char *id; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (card != NULL, FALSE); - g_return_val_if_fail (E_IS_CARD (card), FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_remove_card: No URI loaded!\n"); - return FALSE; - } - - id = e_card_get_id (card); - g_assert (id != NULL); - - return e_book_remove_card_by_id (book, id, cb, closure); -} - -/** - * e_book_remove_card_by_id: - */ -gboolean -e_book_remove_card_by_id (EBook *book, - const char *id, - EBookCallback cb, - gpointer closure) - -{ - CORBA_Environment ev; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (id != NULL, FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_remove_card_by_id: No URI loaded!\n"); - return FALSE; - } - - CORBA_exception_init (&ev); - - e_book_queue_op (book, cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_removeCard ( - book->priv->corba_book, (const GNOME_Evolution_Addressbook_CardId) id, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_remove_card_by_id: CORBA exception " - "talking to PAS!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return FALSE; - } - - CORBA_exception_free (&ev); - - return TRUE; -} - -/* Adding cards. */ - -/** - * e_book_add_card: - */ -gboolean -e_book_add_card (EBook *book, - ECard *card, - EBookIdCallback cb, - gpointer closure) - -{ - char *vcard; - gboolean retval; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (card != NULL, FALSE); - g_return_val_if_fail (E_IS_CARD (card), FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_add_card: No URI loaded!\n"); - return FALSE; - } - - vcard = e_card_get_vcard (card); - - if (vcard == NULL) { - g_warning ("e_book_add_card: Cannot convert card to VCard string!\n"); - return FALSE; - } - - retval = e_book_add_vcard (book, vcard, cb, closure); - - g_free (vcard); - - if (card->book && card->book != book) - gtk_object_unref (GTK_OBJECT (card->book)); - card->book = book; - gtk_object_ref (GTK_OBJECT (card->book)); - - return retval; -} - -/** - * e_book_add_vcard: - */ -gboolean -e_book_add_vcard (EBook *book, - const char *vcard, - EBookIdCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (vcard != NULL, FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_add_vcard: No URI loaded!\n"); - return FALSE; - } - - CORBA_exception_init (&ev); - - e_book_queue_op (book, (EBookCallback) cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_addCard ( - book->priv->corba_book, (const GNOME_Evolution_Addressbook_VCard) vcard, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_add_vcard: Exception adding card to PAS!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return FALSE; - } - - CORBA_exception_free (&ev); - - return TRUE; -} - -/* Modifying cards. */ - -/** - * e_book_commit_card: - */ -gboolean -e_book_commit_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure) -{ - char *vcard; - gboolean retval; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (card != NULL, FALSE); - g_return_val_if_fail (E_IS_CARD (card), FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_commit_card: No URI loaded!\n"); - return FALSE; - } - - vcard = e_card_get_vcard (card); - - if (vcard == NULL) { - g_warning ("e_book_commit_card: Error " - "getting VCard for card!\n"); - return FALSE; - } - - retval = e_book_commit_vcard (book, vcard, cb, closure); - - g_free (vcard); - - if (card->book && card->book != book) - gtk_object_unref (GTK_OBJECT (card->book)); - card->book = book; - gtk_object_ref (GTK_OBJECT (card->book)); - - return retval; -} - -/** - * e_book_commit_vcard: - */ -gboolean -e_book_commit_vcard (EBook *book, - const char *vcard, - EBookCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (vcard != NULL, FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_commit_vcard: No URI loaded!\n"); - return FALSE; - } - - CORBA_exception_init (&ev); - - e_book_queue_op (book, cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_modifyCard ( - book->priv->corba_book, (const GNOME_Evolution_Addressbook_VCard) vcard, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_commit_vcard: Exception " - "modifying card in PAS!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return FALSE; - } - - CORBA_exception_free (&ev); - - return TRUE; -} - -/** - * e_book_check_connection: - */ -gboolean -e_book_check_connection (EBook *book) -{ - CORBA_Environment ev; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_check_connection: No URI loaded!\n"); - return FALSE; - } - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_Book_checkConnection (book->priv->corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_check_connection: Exception " - "querying the PAS!\n"); - CORBA_exception_free (&ev); - return FALSE; - } - - CORBA_exception_free (&ev); - - return TRUE; -} - -guint -e_book_get_cursor (EBook *book, - gchar *query, - EBookCursorCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - guint tag; - - g_return_val_if_fail (book != NULL, 0); - g_return_val_if_fail (E_IS_BOOK (book), 0); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_check_connection: No URI loaded!\n"); - return 0; - } - - CORBA_exception_init (&ev); - - tag = e_book_queue_op (book, cb, closure, NULL); - - GNOME_Evolution_Addressbook_Book_getCursor (book->priv->corba_book, query, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_all_cards: Exception " - "querying list of cards!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return 0; - } - - CORBA_exception_free (&ev); - - return tag; -} - -guint -e_book_get_book_view (EBook *book, - const gchar *query, - EBookBookViewCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - EBookViewListener *listener; - guint tag; - - g_return_val_if_fail (book != NULL, 0); - g_return_val_if_fail (E_IS_BOOK (book), 0); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_get_book_view: No URI loaded!\n"); - return 0; - } - - listener = e_book_view_listener_new(); - - CORBA_exception_init (&ev); - - tag = e_book_queue_op (book, cb, closure, listener); - - GNOME_Evolution_Addressbook_Book_getBookView (book->priv->corba_book, bonobo_object_corba_objref(BONOBO_OBJECT(listener)), query, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_book_view: Exception " - "getting book_view!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return 0; - } - - CORBA_exception_free (&ev); - - return tag; -} - -guint -e_book_get_changes (EBook *book, - gchar *changeid, - EBookBookViewCallback cb, - gpointer closure) -{ - CORBA_Environment ev; - EBookViewListener *listener; - guint tag; - - g_return_val_if_fail (book != NULL, 0); - g_return_val_if_fail (E_IS_BOOK (book), 0); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_get_changes: No URI loaded!\n"); - return FALSE; - } - - listener = e_book_view_listener_new(); - - CORBA_exception_init (&ev); - - tag = e_book_queue_op (book, cb, closure, listener); - - GNOME_Evolution_Addressbook_Book_getChanges (book->priv->corba_book, bonobo_object_corba_objref(BONOBO_OBJECT(listener)), changeid, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_changes: Exception " - "getting changes!\n"); - CORBA_exception_free (&ev); - e_book_unqueue_op (book); - return 0; - } - - CORBA_exception_free (&ev); - - return tag; -} - -/** - * e_book_cancel - */ - -void -e_book_cancel (EBook *book, guint tag) -{ - g_return_if_fail (book != NULL); - g_return_if_fail (E_IS_BOOK (book)); - g_return_if_fail (tag != 0); - - /* In an attempt to be useful, we take a bit of extra care in reporting - errors. This might come in handy someday. */ - if (tag >= book->priv->op_tag) - g_warning ("Attempt to cancel unassigned operation (%u)", tag); - else if (! e_book_cancel_op (book, tag)) - g_warning ("Attempt to cancel unknown operation (%u)", tag); -} - -/** - * e_book_get_name: - */ -char * -e_book_get_name (EBook *book) -{ - CORBA_Environment ev; - char *retval; - char *name; - - g_return_val_if_fail (book != NULL, NULL); - g_return_val_if_fail (E_IS_BOOK (book), NULL); - - if (book->priv->load_state != URILoaded) { - g_warning ("e_book_get_name: No URI loaded!\n"); - return NULL; - } - - CORBA_exception_init (&ev); - - name = GNOME_Evolution_Addressbook_Book_getName (book->priv->corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_book_get_name: Exception getting name from PAS!\n"); - CORBA_exception_free (&ev); - return NULL; - } - - CORBA_exception_free (&ev); - - if (name == NULL) { - g_warning ("e_book_get_name: Got NULL name from PAS!\n"); - return NULL; - } - - retval = g_strdup (name); - CORBA_free (name); - - return retval; -} - -static void -e_book_init (EBook *book) -{ - book->priv = g_new0 (EBookPrivate, 1); - book->priv->load_state = URINotLoaded; - book->priv->op_tag = 1; - book->priv->uri = NULL; -} - -static void -e_book_destroy (GtkObject *object) -{ - EBook *book = E_BOOK (object); - CORBA_Environment ev; - - if (book->priv->load_state == URILoaded) - e_book_unload_uri (book); - - CORBA_exception_init (&ev); - - CORBA_Object_release (book->priv->book_factory, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("EBook: Exception while releasing BookFactory\n"); - - CORBA_exception_free (&ev); - CORBA_exception_init (&ev); - } - - g_free (book->priv->uri); - - g_free (book->priv); - - GTK_OBJECT_CLASS (e_book_parent_class)->destroy (object); -} - -static void -e_book_class_init (EBookClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - e_book_parent_class = gtk_type_class (gtk_object_get_type ()); - - e_book_signals [LINK_STATUS] = - gtk_signal_new ("link_status", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookClass, link_status), - gtk_marshal_NONE__BOOL, - GTK_TYPE_NONE, 1, - GTK_TYPE_BOOL); - - e_book_signals [WRITABLE_STATUS] = - gtk_signal_new ("writable_status", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EBookClass, writable_status), - gtk_marshal_NONE__BOOL, - GTK_TYPE_NONE, 1, - GTK_TYPE_BOOL); - - gtk_object_class_add_signals (object_class, e_book_signals, - LAST_SIGNAL); - - object_class->destroy = e_book_destroy; -} - -/** - * e_book_get_type: - */ -GtkType -e_book_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "EBook", - sizeof (EBook), - sizeof (EBookClass), - (GtkClassInitFunc) e_book_class_init, - (GtkObjectInitFunc) e_book_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/ebook/e-book.h b/addressbook/backend/ebook/e-book.h deleted file mode 100644 index 1c9386cfa7..0000000000 --- a/addressbook/backend/ebook/e-book.h +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * The Evolution addressbook client object. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 1999, 2000, Ximian, Inc. - */ - -#ifndef __E_BOOK_H__ -#define __E_BOOK_H__ - -#include <libgnome/gnome-defs.h> - -#include <addressbook/backend/ebook/e-card.h> -#include <addressbook/backend/ebook/e-card-cursor.h> -#include <addressbook/backend/ebook/e-book-view.h> -#include <addressbook/backend/ebook/e-book-types.h> - -BEGIN_GNOME_DECLS - -typedef struct _EBook EBook; -typedef struct _EBookClass EBookClass; -typedef struct _EBookPrivate EBookPrivate; - -struct _EBook { - GtkObject parent; - EBookPrivate *priv; -}; - -struct _EBookClass { - GtkObjectClass parent; - - /* - * Signals. - */ - void (* open_progress) (EBook *book, const char *msg, short percent); - void (* link_status) (EBook *book, gboolean connected); - void (* writable_status) (EBook *book, gboolean writable); -}; - -/* Callbacks for asynchronous functions. */ -typedef void (*EBookCallback) (EBook *book, EBookStatus status, gpointer closure); -typedef void (*EBookOpenProgressCallback) (EBook *book, - const char *status_message, - short percent, - gpointer closure); -typedef void (*EBookIdCallback) (EBook *book, EBookStatus status, const char *id, gpointer closure); -typedef void (*EBookCursorCallback) (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure); -typedef void (*EBookBookViewCallback) (EBook *book, EBookStatus status, EBookView *book_view, gpointer closure); -typedef void (*EBookFieldsCallback) (EBook *book, EBookStatus status, EList *fields, gpointer closure); - -/* Creating a new addressbook. */ -EBook *e_book_new (void); - -gboolean e_book_load_uri (EBook *book, - const char *uri, - EBookCallback open_response, - gpointer closure); -void e_book_unload_uri (EBook *book); - -const char *e_book_get_uri (EBook *book); - -char *e_book_get_static_capabilities (EBook *book); - -guint e_book_get_supported_fields (EBook *book, - EBookFieldsCallback cb, - gpointer closure); - - -/* User authentication. */ -void e_book_authenticate_user (EBook *book, - const char *user, - const char *passwd, - EBookCallback cb, - gpointer closure); - -/* Fetching cards. */ -ECard *e_book_get_card (EBook *book, - const char *id); -char *e_book_get_vcard (EBook *book, - const char *id); - -/* Deleting cards. */ -gboolean e_book_remove_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure); -gboolean e_book_remove_card_by_id (EBook *book, - const char *id, - EBookCallback cb, - gpointer closure); - -/* Adding cards. */ -gboolean e_book_add_card (EBook *book, - ECard *card, - EBookIdCallback cb, - gpointer closure); -gboolean e_book_add_vcard (EBook *book, - const char *vcard, - EBookIdCallback cb, - gpointer closure); - -/* Modifying cards. */ -gboolean e_book_commit_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure); -gboolean e_book_commit_vcard (EBook *book, - const char *vcard, - EBookCallback cb, - gpointer closure); - -/* Checking to see if we're connected to the card repository. */ -gboolean e_book_check_connection (EBook *book); -guint e_book_get_cursor (EBook *book, - char *query, - EBookCursorCallback cb, - gpointer closure); - -guint e_book_get_book_view (EBook *book, - const gchar *query, - EBookBookViewCallback cb, - gpointer closure); - -guint e_book_get_changes (EBook *book, - char *changeid, - EBookBookViewCallback cb, - gpointer closure); - -/* Cancel a pending operation. */ -void e_book_cancel (EBook *book, - guint tag); - - -/* Getting the name of the repository. */ -char *e_book_get_name (EBook *book); - -GtkType e_book_get_type (void); - -#define E_BOOK_TYPE (e_book_get_type ()) -#define E_BOOK(o) (GTK_CHECK_CAST ((o), E_BOOK_TYPE, EBook)) -#define E_BOOK_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BOOK_TYPE, EBookClass)) -#define E_IS_BOOK(o) (GTK_CHECK_TYPE ((o), E_BOOK_TYPE)) -#define E_IS_BOOK_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_BOOK_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __E_BOOK_H__ */ diff --git a/addressbook/backend/ebook/e-card-compare.c b/addressbook/backend/ebook/e-card-compare.c deleted file mode 100644 index 19352e4755..0000000000 --- a/addressbook/backend/ebook/e-card-compare.c +++ /dev/null @@ -1,528 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-card-compare.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#include <config.h> -#include <ctype.h> -#include <gal/unicode/gunicode.h> -#include "e-book-util.h" -#include "e-card-compare.h" - -/* This is an "optimistic" combiner: the best of the two outcomes is - selected. */ -static ECardMatchType -combine_comparisons (ECardMatchType prev, - ECardMatchType new_info) -{ - if (new_info == E_CARD_MATCH_NOT_APPLICABLE) - return prev; - return (ECardMatchType) MAX ((gint) prev, (gint) new_info); -} - - -/*** Name comparisons ***/ - -/* This *so* doesn't belong here... at least not implemented in a - sucky way like this. But by getting it in here now, I can fix it - up w/o adding a new feature when we are in feature freeze. :-) */ - -/* This is very Anglocentric. */ -static gchar *name_synonyms[][2] = { - { "jon", "john" }, /* Ah, the hacker's perogative */ - { "joseph", "joe" }, - { "robert", "bob" }, - { "richard", "dick" }, - { "william", "bill" }, - { "anthony", "tony" }, - { "michael", "mike" }, - { "eric", "erik" }, - { "elizabeth", "liz" }, - { "jeff", "geoff" }, - { "jeff", "geoffrey" }, - { "jim", "james" }, - { "abigal", "abby" }, - { "amanda", "amy" }, - { "amanda", "manda" }, - { "jennifer", "jenny" }, - { "rebecca", "becca" }, - { "rebecca", "becky" }, - { "anderson", "andersen" }, - /* We could go on and on... */ - { NULL, NULL } -}; - -static gboolean -name_fragment_match (const gchar *a, const gchar *b) -{ - gint i, len_a, len_b; - - /* This will cause "Chris" and "Christopher" to match. */ - len_a = g_utf8_strlen (a, -1); - len_b = g_utf8_strlen (b, -1); - if (!g_utf8_strncasecmp (a, b, MIN (len_a, len_b))) - return TRUE; - - /* Check for nicknames. Yes, the linear search blows. */ - for (i=0; name_synonyms[i][0]; ++i) { - - if (!g_utf8_strcasecmp (name_synonyms[i][0], a) - && !g_utf8_strcasecmp (name_synonyms[i][1], b)) - return TRUE; - - if (!g_utf8_strcasecmp (name_synonyms[i][0], b) - && !g_utf8_strcasecmp (name_synonyms[i][1], a)) - return TRUE; - } - - return FALSE; -} - -ECardMatchType -e_card_compare_name (ECard *card1, ECard *card2) -{ - ECardName *a, *b; - gint matches=0, possible=0; - gboolean given_match = FALSE, additional_match = FALSE, family_match = FALSE; - - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - a = card1->name; - b = card2->name; - - if (a == NULL || b == NULL) - return E_CARD_MATCH_NOT_APPLICABLE; - - if (a->given && b->given) { - ++possible; - if (name_fragment_match (a->given, b->given)) { - ++matches; - given_match = TRUE; - } - } - - if (a->additional && b->additional) { - ++possible; - if (name_fragment_match (a->additional, b->additional)) { - ++matches; - additional_match = TRUE; - } - } - - if (a->family && b->family) { - ++possible; - if (name_fragment_match (a->family, b->family)) { - ++matches; - family_match = TRUE; - } - } - - /* Now look at the # of matches and try to intelligently map - an E_CARD_MATCH_* type to it. Special consideration is given - to family-name matches. */ - - if (possible == 0) - return E_CARD_MATCH_NOT_APPLICABLE; - - if (possible == 1) - return family_match ? E_CARD_MATCH_VAGUE : E_CARD_MATCH_NONE; - - if (possible == matches) - return family_match ? E_CARD_MATCH_EXACT : E_CARD_MATCH_PARTIAL; - - if (possible == matches+1) - return family_match ? E_CARD_MATCH_PARTIAL : E_CARD_MATCH_VAGUE; - - return E_CARD_MATCH_NONE; -} - - -/*** Nickname Comparisons ***/ - -ECardMatchType -e_card_compare_nickname (ECard *card1, ECard *card2) -{ - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - return E_CARD_MATCH_NOT_APPLICABLE; -} - - - -/*** E-mail Comparisons ***/ - -static gboolean -match_email_username (const gchar *addr1, const gchar *addr2) -{ - gint c1, c2; - if (addr1 == NULL || addr2 == NULL) - return FALSE; - - while (*addr1 && *addr2 && *addr1 != '@' && *addr2 != '@') { - c1 = isupper (*addr1) ? tolower (*addr1) : *addr1; - c2 = isupper (*addr2) ? tolower (*addr2) : *addr2; - if (c1 != c2) - return FALSE; - ++addr1; - ++addr2; - } - - return *addr1 == *addr2; -} - -static gboolean -match_email_hostname (const gchar *addr1, const gchar *addr2) -{ - gint c1, c2; - gboolean seen_at1, seen_at2; - if (addr1 == NULL || addr2 == NULL) - return FALSE; - - /* Walk to the end of each string. */ - seen_at1 = FALSE; - if (*addr1) { - while (*addr1) { - if (*addr1 == '@') - seen_at1 = TRUE; - ++addr1; - } - --addr1; - } - - seen_at2 = FALSE; - if (*addr2) { - while (*addr2) { - if (*addr2 == '@') - seen_at2 = TRUE; - ++addr2; - } - --addr2; - } - - if (!seen_at1 && !seen_at2) - return TRUE; - if (!seen_at1 || !seen_at2) - return FALSE; - - while (*addr1 != '@' && *addr2 != '@') { - c1 = isupper (*addr1) ? tolower (*addr1) : *addr1; - c2 = isupper (*addr2) ? tolower (*addr2) : *addr2; - if (c1 != c2) - return FALSE; - --addr1; - --addr2; - } - - /* This will match bob@foo.ximian.com and bob@ximian.com */ - return *addr1 == '.' || *addr2 == '.'; -} - -static ECardMatchType -compare_email_addresses (const gchar *addr1, const gchar *addr2) -{ - if (addr1 == NULL || addr2 == NULL) - return E_CARD_MATCH_NOT_APPLICABLE; - - if (match_email_username (addr1, addr2)) - return match_email_hostname (addr1, addr2) ? E_CARD_MATCH_EXACT : E_CARD_MATCH_PARTIAL; - - return E_CARD_MATCH_NONE; -} - -ECardMatchType -e_card_compare_email (ECard *card1, ECard *card2) -{ - EIterator *i1, *i2; - ECardMatchType match = E_CARD_MATCH_NOT_APPLICABLE; - - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - if (card1->email == NULL || card2->email == NULL) - return E_CARD_MATCH_NOT_APPLICABLE; - - i1 = e_list_get_iterator (card1->email); - i2 = e_list_get_iterator (card2->email); - - /* Do pairwise-comparisons on all of the e-mail addresses. If - we find an exact match, there is no reason to keep - checking. */ - e_iterator_reset (i1); - while (e_iterator_is_valid (i1) && match != E_CARD_MATCH_EXACT) { - const gchar *addr1 = (const gchar *) e_iterator_get (i1); - - e_iterator_reset (i2); - while (e_iterator_is_valid (i2) && match != E_CARD_MATCH_EXACT) { - const gchar *addr2 = (const gchar *) e_iterator_get (i2); - - match = combine_comparisons (match, compare_email_addresses (addr1, addr2)); - - e_iterator_next (i2); - } - - e_iterator_next (i1); - } - - gtk_object_unref (GTK_OBJECT (i1)); - gtk_object_unref (GTK_OBJECT (i2)); - - return match; -} - -ECardMatchType -e_card_compare_address (ECard *card1, ECard *card2) -{ - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - /* Unimplemented */ - - return E_CARD_MATCH_NOT_APPLICABLE; -} - -ECardMatchType -e_card_compare_telephone (ECard *card1, ECard *card2) -{ - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - /* Unimplemented */ - - return E_CARD_MATCH_NOT_APPLICABLE; -} - -ECardMatchType -e_card_compare (ECard *card1, ECard *card2) -{ - ECardMatchType result; - - g_return_val_if_fail (card1 && E_IS_CARD (card1), E_CARD_MATCH_NOT_APPLICABLE); - g_return_val_if_fail (card2 && E_IS_CARD (card2), E_CARD_MATCH_NOT_APPLICABLE); - - result = E_CARD_MATCH_NONE; - result = combine_comparisons (result, e_card_compare_name (card1, card2)); - result = combine_comparisons (result, e_card_compare_nickname (card1, card2)); - result = combine_comparisons (result, e_card_compare_email (card1, card2)); - result = combine_comparisons (result, e_card_compare_address (card1, card2)); - result = combine_comparisons (result, e_card_compare_telephone (card1, card2)); - - return result; -} - -typedef struct _MatchSearchInfo MatchSearchInfo; -struct _MatchSearchInfo { - ECard *card; - GList *avoid; - ECardMatchQueryCallback cb; - gpointer closure; -}; - -static void -match_search_info_free (MatchSearchInfo *info) -{ - if (info) { - gtk_object_unref (GTK_OBJECT (info->card)); - - /* This should already have been deallocated, but just in case... */ - if (info->avoid) { - g_list_foreach (info->avoid, (GFunc) gtk_object_unref, NULL); - g_list_free (info->avoid); - info->avoid = NULL; - } - - g_free (info); - } -} - -static void -simple_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) -{ - MatchSearchInfo *info = (MatchSearchInfo *) closure; - ECardMatchType best_match = E_CARD_MATCH_NONE; - ECard *best_card = NULL; - GList *remaining_cards = NULL; - const GList *i; - - if (status != E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS) { - info->cb (info->card, NULL, E_CARD_MATCH_NONE, info->closure); - match_search_info_free (info); - return; - } - - /* remove the cards we're to avoid from the list, if they're present */ - for (i = cards; i != NULL; i = g_list_next (i)) { - ECard *this_card = E_CARD (i->data); - GList *iterator; - gboolean avoid = FALSE; - for (iterator = info->avoid; iterator; iterator = iterator->next) { - if (!strcmp (e_card_get_id (iterator->data), e_card_get_id (this_card))) { - avoid = TRUE; - break; - } - } - if (!avoid) - remaining_cards = g_list_prepend (remaining_cards, this_card); - } - - remaining_cards = g_list_reverse (remaining_cards); - - for (i = remaining_cards; i != NULL; i = g_list_next (i)) { - ECard *this_card = E_CARD (i->data); - ECardMatchType this_match = e_card_compare (info->card, this_card); - if ((gint)this_match > (gint)best_match) { - best_match = this_match; - best_card = this_card; - } - } - - g_list_free (remaining_cards); - - info->cb (info->card, best_card, best_match, info->closure); - match_search_info_free (info); -} - -#define MAX_QUERY_PARTS 10 -static void -use_common_book_cb (EBook *book, gpointer closure) -{ - MatchSearchInfo *info = (MatchSearchInfo *) closure; - ECard *card = info->card; - gchar *query_parts[MAX_QUERY_PARTS]; - gint p=0; - gchar *query, *qj; - int i; - - if (book == NULL) { - info->cb (info->card, NULL, E_CARD_MATCH_NONE, info->closure); - match_search_info_free (info); - return; - } - - if (card->nickname) - query_parts[p++] = g_strdup_printf ("(beginswith \"nickname\" \"%s\")", card->nickname); - - - if (card->name->given && strlen (card->name->given) > 1) - query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", card->name->given); - - if (card->name->additional && strlen (card->name->additional) > 1) - query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", card->name->additional); - - if (card->name->family && strlen (card->name->family) > 1) - query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", card->name->family); - - - if (card->email) { - EIterator *iter = e_list_get_iterator (card->email); - while (e_iterator_is_valid (iter) && p < MAX_QUERY_PARTS) { - gchar *addr = g_strdup (e_iterator_get (iter)); - if (addr) { - gchar *s = addr; - while (*s) { - if (*s == '@') { - *s = '\0'; - break; - } - ++s; - } - query_parts[p++] = g_strdup_printf ("(beginswith \"email\" \"%s\")", addr); - g_free (addr); - } - e_iterator_next (iter); - } - } - - - - /* Build up our full query from the parts. */ - query_parts[p] = NULL; - qj = g_strjoinv (" ", query_parts); - for(i = 0; query_parts[i] != NULL; i++) - g_free(query_parts[i]); - if (p > 0) { - query = g_strdup_printf ("(or %s)", qj); - g_free (qj); - } else { - query = qj; - } - - e_book_simple_query (book, query, simple_query_cb, info); - - g_free (query); -} - -void -e_card_locate_match (ECard *card, ECardMatchQueryCallback cb, gpointer closure) -{ - MatchSearchInfo *info; - - g_return_if_fail (card && E_IS_CARD (card)); - g_return_if_fail (cb != NULL); - - info = g_new (MatchSearchInfo, 1); - info->card = card; - gtk_object_ref (GTK_OBJECT (card)); - info->cb = cb; - info->closure = closure; - info->avoid = NULL; - - e_book_use_local_address_book (use_common_book_cb, info); -} - -/** - * e_card_locate_match_full: - * @book: The book to look in. If this is NULL, use the main local - * addressbook. - * @card: The card to compare to. - * @avoid: A list of cards to not match. These will not show up in the search. - * @cb: The function to call. - * @closure: The closure to add to the call. - * - * Look for the best match and return it using the ECardMatchQueryCallback. - **/ -void -e_card_locate_match_full (EBook *book, ECard *card, GList *avoid, ECardMatchQueryCallback cb, gpointer closure) -{ - MatchSearchInfo *info; - - g_return_if_fail (card && E_IS_CARD (card)); - g_return_if_fail (cb != NULL); - - info = g_new (MatchSearchInfo, 1); - info->card = card; - gtk_object_ref (GTK_OBJECT (card)); - info->cb = cb; - info->closure = closure; - info->avoid = g_list_copy (avoid); - g_list_foreach (info->avoid, (GFunc) gtk_object_ref, NULL); - - if (book) - use_common_book_cb (book, info); - else - e_book_use_local_address_book (use_common_book_cb, info); -} - diff --git a/addressbook/backend/ebook/e-card-compare.h b/addressbook/backend/ebook/e-card-compare.h deleted file mode 100644 index e5f034600b..0000000000 --- a/addressbook/backend/ebook/e-card-compare.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-card-compare.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#ifndef __E_CARD_COMPARE_H__ -#define __E_CARD_COMPARE_H__ - -#include "e-book.h" -#include "e-card.h" - -typedef enum { - E_CARD_MATCH_NOT_APPLICABLE = 0, - E_CARD_MATCH_NONE = 1, - E_CARD_MATCH_VAGUE = 2, - E_CARD_MATCH_PARTIAL = 3, - E_CARD_MATCH_EXACT = 4 -} ECardMatchType; - -typedef void (*ECardMatchQueryCallback) (ECard *card, ECard *match, ECardMatchType type, gpointer closure); - -ECardMatchType e_card_compare_name (ECard *card1, ECard *card2); -ECardMatchType e_card_compare_nickname (ECard *card1, ECard *card2); -ECardMatchType e_card_compare_email (ECard *card1, ECard *card2); -ECardMatchType e_card_compare_address (ECard *card1, ECard *card2); -ECardMatchType e_card_compare_telephone (ECard *card1, ECard *card2); - -ECardMatchType e_card_compare (ECard *card1, ECard *card2); - -void e_card_locate_match (ECard *card, ECardMatchQueryCallback cb, gpointer closure); -void e_card_locate_match_full (EBook *book, ECard *card, GList *avoid, ECardMatchQueryCallback cb, gpointer closure); - - - -#endif /* __E_CARD_COMPARE_H__ */ - diff --git a/addressbook/backend/ebook/e-card-cursor.c b/addressbook/backend/ebook/e-card-cursor.c deleted file mode 100644 index 171f83d736..0000000000 --- a/addressbook/backend/ebook/e-card-cursor.c +++ /dev/null @@ -1,235 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-card-cursor.c: Implements card cursors. - * - * Author: - * Christopher James Lahey <clahey@ximian.com. - */ - -#include <config.h> -#include <gtk/gtkobject.h> -#include "addressbook.h" -#include "e-card-cursor.h" - -struct _ECardCursorPrivate { - GNOME_Evolution_Addressbook_CardCursor corba_cursor; -}; - -/* - * A pointer to our parent object class - */ -static GtkObjectClass *parent_class; - -/* - * Implemented GtkObject::destroy - */ -static void -e_card_cursor_destroy (GtkObject *object) -{ - ECardCursor *cursor = E_CARD_CURSOR (object); - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_CardCursor_unref( cursor->priv->corba_cursor, &ev ); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_destroy: Exception unreffing " - "corba cursor.\n"); - CORBA_exception_free (&ev); - CORBA_exception_init (&ev); - } - - CORBA_Object_release (cursor->priv->corba_cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_destroy: Exception releasing " - "corba cursor.\n"); - } - - CORBA_exception_free (&ev); - - if ( cursor->priv ) - g_free ( cursor->priv ); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -/** - * e_card_cursor_get_length: - * @cursor: the #ECardCursor whose length is being queried - * - * Returns: the number of items the cursor references, or -1 there's - * an error. - */ -long -e_card_cursor_get_length (ECardCursor *cursor) -{ - if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) { - CORBA_Environment ev; - long ret_val; - - CORBA_exception_init (&ev); - - ret_val = GNOME_Evolution_Addressbook_CardCursor_count (cursor->priv->corba_cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_get_length: Exception during " - "get_length corba call.\n"); - ret_val = -1; - } - - CORBA_exception_free (&ev); - - return ret_val; - } - else - return -1; -} - -/** - * e_card_cursor_get_nth: - * @cursor: an #ECardCursor object - * @n: the index of the item requested - * - * Gets an #ECard based on an index. - * - * Returns: a new #ECard on success, or %NULL on failure. - */ -ECard * -e_card_cursor_get_nth (ECardCursor *cursor, - const long n) -{ - if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) { - CORBA_Environment en; - CORBA_char *vcard; - ECard *card; - - CORBA_exception_init (&en); - - vcard = GNOME_Evolution_Addressbook_CardCursor_getNth(cursor->priv->corba_cursor, n, &en); - - if (en._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_get_nth: Exception during " - "get_nth corba call.\n"); - } - - CORBA_exception_free (&en); - - card = e_card_new (vcard); - - CORBA_free(vcard); - - return card; - } - else - return e_card_new(""); -} - -static void -e_card_cursor_class_init (ECardCursorClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class->destroy = e_card_cursor_destroy; -} - -static void -e_card_cursor_init (ECardCursor *cursor) -{ - cursor->priv = g_new(ECardCursorPrivate, 1); - cursor->priv->corba_cursor = CORBA_OBJECT_NIL; -} - -GtkType -e_card_cursor_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ECardCursor", - sizeof (ECardCursor), - sizeof (ECardCursorClass), - (GtkClassInitFunc) e_card_cursor_class_init, - (GtkObjectInitFunc) e_card_cursor_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -/** - * e_card_cursor_construct: - * @cursor: an #ECardCursor object - * @corba_cursor: an #GNOME_Evolution_Addressbook_CardCursor - * - * Wraps an #GNOME_Evolution_Addressbook_CardCursor object inside the #ECardCursor - * @cursor object. - * - * Returns: a new #ECardCursor on success, or %NULL on failure. - */ -ECardCursor * -e_card_cursor_construct (ECardCursor *cursor, - GNOME_Evolution_Addressbook_CardCursor corba_cursor) -{ - CORBA_Environment ev; - g_return_val_if_fail (cursor != NULL, NULL); - g_return_val_if_fail (E_IS_CARD_CURSOR (cursor), NULL); - g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL); - - CORBA_exception_init (&ev); - - /* - * Initialize cursor - */ - cursor->priv->corba_cursor = CORBA_Object_duplicate(corba_cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_construct: Exception duplicating " - "corba cursor.\n"); - CORBA_exception_free (&ev); - CORBA_exception_init (&ev); - } - - GNOME_Evolution_Addressbook_CardCursor_ref(cursor->priv->corba_cursor, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("e_card_cursor_construct: Exception reffing " - "corba cursor.\n"); - } - - CORBA_exception_free (&ev); - - /* - * Success: return the GtkType we were given - */ - return cursor; -} - -/** - * e_card_cursor_new: - * @cursor: the #GNOME_Evolution_Addressbook_CardCursor to be wrapped - * - * Creates a new #ECardCursor, which wraps an #GNOME_Evolution_Addressbook_CardCursor - * object. - * - * Returns: a new #ECardCursor on success, or %NULL on failure. - */ -ECardCursor * -e_card_cursor_new (GNOME_Evolution_Addressbook_CardCursor corba_cursor) -{ - ECardCursor *cursor; - - cursor = gtk_type_new (e_card_cursor_get_type ()); - - return e_card_cursor_construct (cursor, - corba_cursor); -} diff --git a/addressbook/backend/ebook/e-card-cursor.h b/addressbook/backend/ebook/e-card-cursor.h deleted file mode 100644 index e042268635..0000000000 --- a/addressbook/backend/ebook/e-card-cursor.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_CARD_CURSOR_H__ -#define __E_CARD_CURSOR_H__ - -#include <gtk/gtkobject.h> -#include <libgnome/gnome-defs.h> -#include <addressbook/backend/ebook/addressbook.h> -#include <addressbook/backend/ebook/e-card.h> - -BEGIN_GNOME_DECLS - -typedef struct _ECardCursor ECardCursor; -typedef struct _ECardCursorPrivate ECardCursorPrivate; -typedef struct _ECardCursorClass ECardCursorClass; - -struct _ECardCursor { - GtkObject parent; - ECardCursorPrivate *priv; -}; - -struct _ECardCursorClass { - GtkObjectClass parent; -}; - -/* Creating a new addressbook. */ -ECardCursor *e_card_cursor_new (GNOME_Evolution_Addressbook_CardCursor corba_cursor); -ECardCursor *e_card_cursor_construct (ECardCursor *cursor, - GNOME_Evolution_Addressbook_CardCursor corba_cursor); - -GtkType e_card_cursor_get_type (void); - -/* Fetching cards. */ -long e_card_cursor_get_length (ECardCursor *cursor); -ECard *e_card_cursor_get_nth (ECardCursor *cursor, - const long nth); -#define E_CARD_CURSOR_TYPE (e_card_cursor_get_type ()) -#define E_CARD_CURSOR(o) (GTK_CHECK_CAST ((o), E_CARD_CURSOR_TYPE, ECardCursor)) -#define E_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CARD_CURSOR_TYPE, ECardCursorClass)) -#define E_IS_CARD_CURSOR(o) (GTK_CHECK_TYPE ((o), E_CARD_CURSOR_TYPE)) -#define E_IS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CARD_CURSOR_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __E_CARD_CURSOR_H__ */ diff --git a/addressbook/backend/ebook/e-card-pairs.h b/addressbook/backend/ebook/e-card-pairs.h deleted file mode 100644 index 0f379d3477..0000000000 --- a/addressbook/backend/ebook/e-card-pairs.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* GnomeCard - a graphical contact manager. - * - * pairs.h: This file is part of GnomeCard. - * - * Copyright (C) 1999 The Free Software Foundation - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef __E_CARD_PAIRS_H__ -#define __E_CARD_PAIRS_H__ - -#include <libversit/vcc.h> -#include <ebook/e-card.h> - - -#if 0 -struct pair -{ - char *str; - ECardPropertyType i ; -}; - -struct pair prop_lookup[] = { - { VCFullNameProp, PROP_FNAME }, - { VCNameProp, PROP_NAME }, - { VCPhotoProp, PROP_PHOTO }, - { VCBirthDateProp, PROP_BDAY }, - { VCAdrProp, PROP_DELADDR }, - { VCDeliveryLabelProp, PROP_DELLABEL }, - { VCTelephoneProp, PROP_PHONE }, - { VCEmailAddressProp, PROP_EMAIL }, - { VCMailerProp, PROP_MAILER }, - { VCTimeZoneProp, PROP_TIMEZN }, - { VCGeoProp, PROP_GEOPOS }, - { VCTitleProp, PROP_TITLE }, - { VCBusinessRoleProp, PROP_ROLE }, - { VCLogoProp, PROP_LOGO }, - { VCAgentProp, PROP_AGENT }, - { VCOrgProp, PROP_ORG }, - { VCCategoriesProp, PROP_CATEGORIES }, - { VCCommentProp, PROP_COMMENT }, - { VCLastRevisedProp, PROP_REV }, - { VCPronunciationProp, PROP_SOUND }, - { VCURLProp, PROP_URL }, - { VCUniqueStringProp, PROP_UID }, - { VCVersionProp, PROP_VERSION }, - { VCPublicKeyProp, PROP_KEY }, - { VCValueProp, PROP_VALUE }, - { VCEncodingProp, PROP_ENCODING }, - { VCQuotedPrintableProp, PROP_QUOTED_PRINTABLE }, - { VC8bitProp, PROP_8BIT }, - { VCBase64Prop, PROP_BASE64 }, - { VCLanguageProp, PROP_LANG }, - { VCCharSetProp, PROP_CHARSET }, - { NULL, PROP_NONE} }; - -struct pair photo_pairs[] = { - { VCGIFProp, PHOTO_GIF }, - { VCCGMProp, PHOTO_CGM }, - { VCWMFProp, PHOTO_WMF }, - { VCBMPProp, PHOTO_BMP }, - { VCMETProp, PHOTO_MET }, - { VCPMBProp, PHOTO_PMB }, - { VCDIBProp, PHOTO_DIB }, - { VCPICTProp, PHOTO_PICT }, - { VCTIFFProp, PHOTO_TIFF }, - { VCPDFProp, PHOTO_PDF }, - { VCPSProp, PHOTO_PS }, - { VCJPEGProp, PHOTO_JPEG }, - { VCMPEGProp, PHOTO_MPEG }, - { VCMPEG2Prop, PHOTO_MPEG2 }, - { VCAVIProp, PHOTO_AVI }, - { VCQuickTimeProp, PHOTO_QTIME }, - { NULL, 0 } }; - -struct pair email_pairs[] = { - { VCAOLProp, EMAIL_AOL }, - { VCAppleLinkProp, EMAIL_APPLE_LINK }, - { VCATTMailProp, EMAIL_ATT }, - { VCCISProp, EMAIL_CIS }, - { VCEWorldProp, EMAIL_EWORLD }, - { VCInternetProp, EMAIL_INET }, - { VCIBMMailProp, EMAIL_IBM }, - { VCMCIMailProp, EMAIL_MCI }, - { VCPowerShareProp, EMAIL_POWERSHARE }, - { VCProdigyProp, EMAIL_PRODIGY }, - { VCTLXProp, EMAIL_TLX }, - { VCX400Prop, EMAIL_X400 }, - { NULL, 0 } }; - -struct pair sound_pairs[] = { - { VCAIFFProp, SOUND_AIFF }, - { VCPCMProp, SOUND_PCM }, - { VCWAVEProp, SOUND_WAVE }, - { NULL, 0 } }; - -struct pair key_pairs[] = { - { VCX509Prop, KEY_X509 }, - { VCPGPProp, KEY_PGP }, - { NULL, 0 } }; - - -#endif -#endif /* ! __E_CARD_PAIRS_H__ */ diff --git a/addressbook/backend/ebook/e-card-simple.c b/addressbook/backend/ebook/e-card-simple.c deleted file mode 100644 index 5bd8bb57e5..0000000000 --- a/addressbook/backend/ebook/e-card-simple.c +++ /dev/null @@ -1,1158 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * Arturo Espinosa (arturo@nuclecu.unam.mx) - * Nat Friedman (nat@ximian.com) - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include <config.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <gtk/gtkobject.h> - -#include <libversit/vcc.h> -#include "e-card-simple.h" - -/* Object argument IDs */ -enum { - ARG_0, - ARG_CARD, -}; - - -typedef enum _ECardSimpleInternalType ECardSimpleInternalType; -typedef struct _ECardSimpleFieldData ECardSimpleFieldData; - -enum _ECardSimpleInternalType { - E_CARD_SIMPLE_INTERNAL_TYPE_STRING, - E_CARD_SIMPLE_INTERNAL_TYPE_DATE, - E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS, - E_CARD_SIMPLE_INTERNAL_TYPE_PHONE, - E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL, - E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL, -}; - -struct _ECardSimpleFieldData { - ECardSimpleField field; - char *ecard_field; - char *name; - char *short_name; - int list_type_index; - ECardSimpleInternalType type; -}; - -/* This order must match the order in the .h. */ - -/* the ecard_field data below should only be used for TYPE_STRING, - TYPE_DATE, and TYPE_SPECIAL fields. that is, it's only valid for - e-cards for those types. it is used as a unique name for fields - for the get_supported functionality. */ -static ECardSimpleFieldData field_data[] = -{ - { E_CARD_SIMPLE_FIELD_FILE_AS, "file_as", "File As", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "Name", "Name", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_FAMILY_NAME, "family_name", "Family Name", "Family Name", 0, E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL }, - { E_CARD_SIMPLE_FIELD_EMAIL, "email", "Email", "Email", E_CARD_SIMPLE_EMAIL_ID_EMAIL, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, - { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "primary_phone", "Primary", "Prim", E_CARD_SIMPLE_PHONE_ID_PRIMARY, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_ASSISTANT, "assistant_phone", "Assistant", "Assistant",E_CARD_SIMPLE_PHONE_ID_ASSISTANT, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS, "business_phone", "Business", "Bus", E_CARD_SIMPLE_PHONE_ID_BUSINESS, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_CALLBACK, "callback_phone", "Callback", "Callback", E_CARD_SIMPLE_PHONE_ID_CALLBACK, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_COMPANY, "company_phone", "Company", "Comp", E_CARD_SIMPLE_PHONE_ID_COMPANY, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_HOME, "home_phone", "Home", "Home", E_CARD_SIMPLE_PHONE_ID_HOME, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_ORG, "org", "Organization", "Org", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_ADDRESS_BUSINESS, "business_address","Business", "Bus", E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, - { E_CARD_SIMPLE_FIELD_ADDRESS_HOME, "home_address", "Home", "Home", E_CARD_SIMPLE_ADDRESS_ID_HOME, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, - { E_CARD_SIMPLE_FIELD_PHONE_MOBILE, "mobile_phone", "Mobile", "Mobile", E_CARD_SIMPLE_PHONE_ID_MOBILE, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_CAR, "car_phone", "Car", "Car", E_CARD_SIMPLE_PHONE_ID_CAR, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX, "business_fax", "Business Fax", "Bus Fax", E_CARD_SIMPLE_PHONE_ID_BUSINESS_FAX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX, "home_fax", "Home Fax", "Home Fax", E_CARD_SIMPLE_PHONE_ID_HOME_FAX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2, "business_phone_2","Business 2", "Bus 2", E_CARD_SIMPLE_PHONE_ID_BUSINESS_2, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_HOME_2, "home_phone_2", "Home 2", "Home 2", E_CARD_SIMPLE_PHONE_ID_HOME_2, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_ISDN, "isdn", "ISDN", "ISDN", E_CARD_SIMPLE_PHONE_ID_ISDN, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_OTHER, "other_phone", "Other", "Other", E_CARD_SIMPLE_PHONE_ID_OTHER, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_OTHER_FAX, "other_fax", "Other Fax", "Other Fax", E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_PAGER, "pager", "Pager", "Pager", E_CARD_SIMPLE_PHONE_ID_PAGER, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_RADIO, "radio", "Radio", "Radio", E_CARD_SIMPLE_PHONE_ID_RADIO, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_TELEX, "telex", "Telex", "Telex", E_CARD_SIMPLE_PHONE_ID_TELEX, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_PHONE_TTYTTD, "tty", "TTY", "TTY", E_CARD_SIMPLE_PHONE_ID_TTYTTD, E_CARD_SIMPLE_INTERNAL_TYPE_PHONE }, - { E_CARD_SIMPLE_FIELD_ADDRESS_OTHER, "other_address", "Other", "Other", E_CARD_SIMPLE_ADDRESS_ID_OTHER, E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS }, - { E_CARD_SIMPLE_FIELD_EMAIL_2, "email_2", "Email 2", "Email 2", E_CARD_SIMPLE_EMAIL_ID_EMAIL_2, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, - { E_CARD_SIMPLE_FIELD_EMAIL_3, "email_3", "Email 3", "Email 3", E_CARD_SIMPLE_EMAIL_ID_EMAIL_3, E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL }, - { E_CARD_SIMPLE_FIELD_URL, "url", "Web Site", "Url", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_ORG_UNIT, "org_unit", "Department", "Dep", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_OFFICE, "office", "Office", "Off", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_TITLE, "title", "Title", "Title", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_ROLE, "role", "Profession", "Prof", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_MANAGER, "manager", "Manager", "Man", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_ASSISTANT, "assistant", "Assistant", "Ass", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_NICKNAME, "nickname", "Nickname", "Nick", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_SPOUSE, "spouse", "Spouse", "Spouse", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_NOTE, "note", "Note", "Note", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_FBURL, "fburl", "Free-busy URL", "FBUrl", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_ANNIVERSARY, "anniversary", "Anniversary", "Anniv", 0, E_CARD_SIMPLE_INTERNAL_TYPE_DATE }, - { E_CARD_SIMPLE_FIELD_BIRTH_DATE, "birth_date", "Birth Date", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_DATE }, - { E_CARD_SIMPLE_FIELD_MAILER, "mailer", "", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, - { E_CARD_SIMPLE_FIELD_NAME_OR_ORG, "nameororg", "", "", 0, E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL }, - { E_CARD_SIMPLE_FIELD_CATEGORIES, "categories", "Categories", "Categories", 0, E_CARD_SIMPLE_INTERNAL_TYPE_STRING }, -}; -static int field_data_count = sizeof (field_data) / sizeof (field_data[0]); - -static void e_card_simple_init (ECardSimple *simple); -static void e_card_simple_class_init (ECardSimpleClass *klass); - -static void e_card_simple_destroy (GtkObject *object); -static void e_card_simple_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_card_simple_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void fill_in_info(ECardSimple *simple); - -ECardPhoneFlags phone_correspondences[] = { - E_CARD_PHONE_ASSISTANT, /* E_CARD_SIMPLE_PHONE_ID_ASSISTANT, */ - E_CARD_PHONE_WORK | E_CARD_PHONE_VOICE, /* E_CARD_SIMPLE_PHONE_ID_BUSINESS, */ - E_CARD_PHONE_WORK | E_CARD_PHONE_VOICE, /* E_CARD_SIMPLE_PHONE_ID_BUSINESS_2, */ - E_CARD_PHONE_WORK | E_CARD_PHONE_FAX, /* E_CARD_SIMPLE_PHONE_ID_BUSINESS_FAX, */ - E_CARD_PHONE_CALLBACK, /* E_CARD_SIMPLE_PHONE_ID_CALLBACK, */ - E_CARD_PHONE_CAR, /* E_CARD_SIMPLE_PHONE_ID_CAR, */ - E_CARD_PHONE_WORK, /* E_CARD_SIMPLE_PHONE_ID_COMPANY, */ - E_CARD_PHONE_HOME, /* E_CARD_SIMPLE_PHONE_ID_HOME, */ - E_CARD_PHONE_HOME, /* E_CARD_SIMPLE_PHONE_ID_HOME_2, */ - E_CARD_PHONE_HOME | E_CARD_PHONE_FAX, /* E_CARD_SIMPLE_PHONE_ID_HOME_FAX, */ - E_CARD_PHONE_ISDN, /* E_CARD_SIMPLE_PHONE_ID_ISDN, */ - E_CARD_PHONE_CELL, /* E_CARD_SIMPLE_PHONE_ID_MOBILE, */ - E_CARD_PHONE_VOICE, /* E_CARD_SIMPLE_PHONE_ID_OTHER, */ - E_CARD_PHONE_FAX, /* E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, */ - E_CARD_PHONE_PAGER, /* E_CARD_SIMPLE_PHONE_ID_PAGER, */ - E_CARD_PHONE_PREF, /* E_CARD_SIMPLE_PHONE_ID_PRIMARY, */ - E_CARD_PHONE_RADIO, /* E_CARD_SIMPLE_PHONE_ID_RADIO, */ - E_CARD_PHONE_TELEX, /* E_CARD_SIMPLE_PHONE_ID_TELEX, */ - E_CARD_PHONE_TTYTDD, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ -}; - -char *phone_names[] = { - NULL, /* E_CARD_SIMPLE_PHONE_ID_ASSISTANT, */ - "Business", - "Business 2", - "Business Fax", - NULL, /* E_CARD_SIMPLE_PHONE_ID_CALLBACK, */ - "Car", - NULL, /* E_CARD_SIMPLE_PHONE_ID_COMPANY, */ - "Home", - "Home 2", - "Home Fax", - "ISDN", - "Mobile", - "Other", - NULL, /* E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, */ - "Pager", - "Primary", - NULL, /* E_CARD_SIMPLE_PHONE_ID_RADIO, */ - NULL, /* E_CARD_SIMPLE_PHONE_ID_TELEX, */ - NULL, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ -}; - -char *phone_short_names[] = { - NULL, /* E_CARD_SIMPLE_PHONE_ID_ASSISTANT, */ - "Bus", - "Bus 2", - "Bus Fax", - NULL, /* E_CARD_SIMPLE_PHONE_ID_CALLBACK, */ - "Car", - NULL, /* E_CARD_SIMPLE_PHONE_ID_COMPANY, */ - "Home", - "Home 2", - "Home Fax", - "ISDN", - "Mob", - "Other", - NULL, /* E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, */ - "Pag", - "Prim", - NULL, /* E_CARD_SIMPLE_PHONE_ID_RADIO, */ - NULL, /* E_CARD_SIMPLE_PHONE_ID_TELEX, */ - NULL, /* E_CARD_SIMPLE_PHONE_ID_TTYTTD, */ -}; - -ECardAddressFlags addr_correspondences[] = { - E_CARD_ADDR_WORK, /* E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, */ - E_CARD_ADDR_HOME, /* E_CARD_SIMPLE_ADDRESS_ID_HOME, */ - E_CARD_ADDR_POSTAL, /* E_CARD_SIMPLE_ADDRESS_ID_OTHER, */ -}; - -char *address_names[] = { - "Business", - "Home", - "Other", -}; - -/** - * e_card_simple_get_type: - * @void: - * - * Registers the &ECardSimple class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ECardSimple class. - **/ -GtkType -e_card_simple_get_type (void) -{ - static GtkType simple_type = 0; - - if (!simple_type) { - GtkTypeInfo simple_info = { - "ECardSimple", - sizeof (ECardSimple), - sizeof (ECardSimpleClass), - (GtkClassInitFunc) e_card_simple_class_init, - (GtkObjectInitFunc) e_card_simple_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - simple_type = gtk_type_unique (gtk_object_get_type (), &simple_info); - } - - return simple_type; -} - -/** - * e_card_simple_new: - * @VCard: a string in vCard format - * - * Returns: a new #ECardSimple that wraps the @VCard. - */ -ECardSimple * -e_card_simple_new (ECard *card) -{ - ECardSimple *simple = E_CARD_SIMPLE(gtk_type_new(e_card_simple_get_type())); - gtk_object_set(GTK_OBJECT(simple), - "card", card, - NULL); - return simple; -} - -ECardSimple * -e_card_simple_duplicate(ECardSimple *simple) -{ - char *vcard = e_card_simple_get_vcard(simple); - ECard *card = e_card_new(vcard); - ECardSimple *new_simple = e_card_simple_new(card); - g_free (vcard); - return new_simple; -} - -/** - * e_card_simple_get_id: - * @simple: an #ECardSimple - * - * Returns: a string representing the id of the simple, which is unique - * within its book. - */ -const char * -e_card_simple_get_id (ECardSimple *simple) -{ - if (simple->card) - return e_card_get_id(simple->card); - else - return ""; -} - -/** - * e_card_simple_get_id: - * @simple: an #ECardSimple - * @id: a id in string format - * - * Sets the identifier of a simple, which should be unique within its - * book. - */ -void -e_card_simple_set_id (ECardSimple *simple, const char *id) -{ - if ( simple->card ) - e_card_set_id(simple->card, id); -} - -/** - * e_card_simple_get_vcard: - * @simple: an #ECardSimple - * - * Returns: a string in vcard format, which is wrapped by the @simple. - */ -char * -e_card_simple_get_vcard (ECardSimple *simple) -{ - if (simple->card) - return e_card_get_vcard(simple->card); - else - return g_strdup(""); -} - -static void -e_card_simple_class_init (ECardSimpleClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - gtk_object_add_arg_type ("ECardSimple::card", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); - - object_class->destroy = e_card_simple_destroy; - object_class->get_arg = e_card_simple_get_arg; - object_class->set_arg = e_card_simple_set_arg; -} - -/* - * ECardSimple lifecycle management and vcard loading/saving. - */ - -static void -e_card_simple_destroy (GtkObject *object) -{ - ECardSimple *simple; - int i; - - simple = E_CARD_SIMPLE (object); - - if (simple->card) - gtk_object_unref(GTK_OBJECT(simple->card)); - g_list_foreach(simple->temp_fields, (GFunc) g_free, NULL); - g_list_free(simple->temp_fields); - simple->temp_fields = NULL; - - for(i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i++) - e_card_phone_free (simple->phone[i]); - for(i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i++) - g_free(simple->email[i]); - for(i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) - e_card_address_label_free(simple->address[i]); - for(i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) - e_card_delivery_address_free(simple->delivery[i]); -} - - -/* Set_arg handler for the simple */ -static void -e_card_simple_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECardSimple *simple; - - simple = E_CARD_SIMPLE (object); - - switch (arg_id) { - case ARG_CARD: - if (simple->card) - gtk_object_unref(GTK_OBJECT(simple->card)); - g_list_foreach(simple->temp_fields, (GFunc) g_free, NULL); - g_list_free(simple->temp_fields); - simple->temp_fields = NULL; - if (GTK_VALUE_OBJECT(*arg)) - simple->card = E_CARD(GTK_VALUE_OBJECT(*arg)); - else - simple->card = NULL; - if(simple->card) - gtk_object_ref(GTK_OBJECT(simple->card)); - fill_in_info(simple); - break; - default: - return; - } -} - -/* Get_arg handler for the simple */ -static void -e_card_simple_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECardSimple *simple; - - simple = E_CARD_SIMPLE (object); - - switch (arg_id) { - case ARG_CARD: - e_card_simple_sync_card(simple); - GTK_VALUE_OBJECT (*arg) = (GtkObject *) simple->card; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - - -/** - * e_card_simple_init: - */ -static void -e_card_simple_init (ECardSimple *simple) -{ - int i; - simple->card = NULL; - for(i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i++) - simple->phone[i] = NULL; - for(i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i++) - simple->email[i] = NULL; - for(i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) - simple->address[i] = NULL; - simple->temp_fields = NULL; - - simple->changed = TRUE; -} - -static void -fill_in_info(ECardSimple *simple) -{ - ECard *card = simple->card; - if (card) { - EList *address_list; - EList *phone_list; - EList *email_list; - EList *delivery_list; - const ECardPhone *phone; - const char *email; - const ECardAddrLabel *address; - const ECardDeliveryAddress *delivery; - int i; - - EIterator *iterator; - - gtk_object_get(GTK_OBJECT(card), - "address_label", &address_list, - "address", &delivery_list, - "phone", &phone_list, - "email", &email_list, - NULL); - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i++) { - e_card_phone_free(simple->phone[i]); - simple->phone[i] = NULL; - } - for (iterator = e_list_get_iterator(phone_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - gboolean found = FALSE; - phone = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - if ((phone->flags == phone_correspondences[i]) && (simple->phone[i] == NULL)) { - simple->phone[i] = e_card_phone_copy(phone); - found = TRUE; - break; - } - } - if (found) - continue; - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - if (((phone->flags & phone_correspondences[i]) == phone_correspondences[i]) && (simple->phone[i] == NULL)) { - simple->phone[i] = e_card_phone_copy(phone); - break; - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - for (i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i++) { - g_free(simple->email[i]); - simple->email[i] = NULL; - } - for (iterator = e_list_get_iterator(email_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - email = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { - if ((simple->email[i] == NULL)) { - simple->email[i] = g_strdup(email); - break; - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) { - e_card_address_label_free(simple->address[i]); - simple->address[i] = NULL; - } - for (iterator = e_list_get_iterator(address_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - address = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if (((address->flags & addr_correspondences[i]) == addr_correspondences[i]) && (simple->address[i] == NULL)) { - simple->address[i] = e_card_address_label_copy(address); - break; - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) { - e_card_delivery_address_free(simple->delivery[i]); - simple->delivery[i] = NULL; - } - for (iterator = e_list_get_iterator(delivery_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - delivery = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if (((delivery->flags & addr_correspondences[i]) == addr_correspondences[i]) && (simple->delivery[i] == NULL)) { - simple->delivery[i] = e_card_delivery_address_copy(delivery); - break; - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - e_card_free_empty_lists (card); - } -} - -void -e_card_simple_sync_card(ECardSimple *simple) -{ - ECard *card = simple->card; - if (card && simple->changed) { - EList *address_list; - EList *phone_list; - EList *email_list; - EList *delivery_list; - const ECardPhone *phone; - const ECardAddrLabel *address; - const ECardDeliveryAddress *delivery; - const char *email; - int i; - - EIterator *iterator; - - gtk_object_get(GTK_OBJECT(card), - "address_label", &address_list, - "address", &delivery_list, - "phone", &phone_list, - "email", &email_list, - NULL); - - for (iterator = e_list_get_iterator(phone_list); e_iterator_is_valid(iterator); e_iterator_next(iterator) ) { - int i; - gboolean found = FALSE; - phone = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - if (phone->flags == phone_correspondences[i]) { - if (simple->phone[i]) { - simple->phone[i]->flags = phone_correspondences[i]; - if (simple->phone[i]->number && *simple->phone[i]->number) { - e_iterator_set(iterator, simple->phone[i]); - } else { - e_iterator_delete(iterator); - } - e_card_phone_free(simple->phone[i]); - simple->phone[i] = NULL; - found = TRUE; - break; - } - } - } - if (found) - continue; - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - if ((phone->flags & phone_correspondences[i]) == phone_correspondences[i]) { - if (simple->phone[i]) { - simple->phone[i]->flags = phone_correspondences[i]; - if (simple->phone[i]->number && *simple->phone[i]->number) { - e_iterator_set(iterator, simple->phone[i]); - } else { - e_iterator_delete(iterator); - } - e_card_phone_free(simple->phone[i]); - simple->phone[i] = NULL; - break; - } - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - if (simple->phone[i]) { - simple->phone[i]->flags = phone_correspondences[i]; - e_list_append(phone_list, simple->phone[i]); - e_card_phone_free(simple->phone[i]); - simple->phone[i] = NULL; - } - } - - for (iterator = e_list_get_iterator(email_list); e_iterator_is_valid(iterator); e_iterator_next(iterator) ) { - int i; - email = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { - if (simple->email[i]) { - if (*simple->email[i]) { - e_iterator_set(iterator, simple->email[i]); - } else { - e_iterator_delete(iterator); - } - g_free(simple->email[i]); - simple->email[i] = NULL; - break; - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - for (i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { - if (simple->email[i]) { - e_list_append(email_list, simple->email[i]); - g_free(simple->email[i]); - simple->email[i] = NULL; - } - } - - for (iterator = e_list_get_iterator(address_list); e_iterator_is_valid(iterator); e_iterator_next(iterator) ) { - int i; - address = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if ((address->flags & addr_correspondences[i]) == addr_correspondences[i]) { - if (simple->address[i]) { - simple->address[i]->flags = addr_correspondences[i]; - if (simple->address[i]->data && *simple->address[i]->data) { - e_iterator_set(iterator, simple->address[i]); - } else { - e_iterator_delete(iterator); - } - e_card_address_label_free(simple->address[i]); - simple->address[i] = NULL; - break; - } - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if (simple->address[i]) { - simple->address[i]->flags = addr_correspondences[i]; - e_list_append(address_list, simple->address[i]); - e_card_address_label_free(simple->address[i]); - simple->address[i] = NULL; - } - } - - for (iterator = e_list_get_iterator(delivery_list); e_iterator_is_valid(iterator); e_iterator_next(iterator) ) { - int i; - delivery = e_iterator_get(iterator); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if ((delivery->flags & addr_correspondences[i]) == addr_correspondences[i]) { - if (simple->delivery[i]) { - simple->delivery[i]->flags = addr_correspondences[i]; - if (!e_card_delivery_address_is_empty(simple->delivery[i])) { - e_iterator_set(iterator, simple->delivery[i]); - } else { - e_iterator_delete(iterator); - } - e_card_delivery_address_free(simple->delivery[i]); - simple->delivery[i] = NULL; - break; - } - } - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) { - if (simple->delivery[i]) { - simple->delivery[i]->flags = addr_correspondences[i]; - e_list_append(delivery_list, simple->delivery[i]); - e_card_delivery_address_free(simple->delivery[i]); - simple->delivery[i] = NULL; - } - } - fill_in_info(simple); - e_card_free_empty_lists (card); - } - - simple->changed = FALSE; -} - -const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, - ECardSimplePhoneId id) -{ - return simple->phone[id]; -} - -const char *e_card_simple_get_email (ECardSimple *simple, - ECardSimpleEmailId id) -{ - return simple->email[id]; -} - -const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, - ECardSimpleAddressId id) -{ - return simple->address[id]; -} - -const ECardDeliveryAddress *e_card_simple_get_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id) -{ - return simple->delivery[id]; -} - -void e_card_simple_set_phone (ECardSimple *simple, - ECardSimplePhoneId id, - const ECardPhone *phone) -{ - if (simple->phone[id]) - e_card_phone_free(simple->phone[id]); - simple->phone[id] = e_card_phone_copy(phone); - simple->changed = TRUE; -} - -void e_card_simple_set_email (ECardSimple *simple, - ECardSimpleEmailId id, - const char *email) -{ - if (simple->email[id]) - g_free(simple->email[id]); - simple->email[id] = g_strdup(email); - simple->changed = TRUE; -} - -void e_card_simple_set_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardAddrLabel *address) -{ - if (simple->address[id]) - e_card_address_label_free(simple->address[id]); - simple->address[id] = e_card_address_label_copy(address); - if (simple->delivery[id]) - e_card_delivery_address_free(simple->delivery[id]); - simple->delivery[id] = e_card_delivery_address_from_label(simple->address[id]); - simple->changed = TRUE; -} - -void e_card_simple_set_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardDeliveryAddress *delivery) -{ - if (simple->delivery[id]) - e_card_delivery_address_free(simple->delivery[id]); - simple->delivery[id] = e_card_delivery_address_copy(delivery); - simple->changed = TRUE; -} - -const char *e_card_simple_get_const (ECardSimple *simple, - ECardSimpleField field) -{ - char *ret_val = e_card_simple_get(simple, field); - if (ret_val) - simple->temp_fields = g_list_prepend(simple->temp_fields, ret_val); - return ret_val; -} - -char *e_card_simple_get (ECardSimple *simple, - ECardSimpleField field) -{ - ECardSimpleInternalType type = field_data[field].type; - const ECardAddrLabel *addr; - const ECardPhone *phone; - const char *string; - ECardDate *date; - ECardName *name; - switch(type) { - case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: - if (simple->card) { - gtk_object_get(GTK_OBJECT(simple->card), - field_data[field].ecard_field, &string, - NULL); - return g_strdup(string); - } else - return NULL; - case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: - if (simple->card) { - gtk_object_get(GTK_OBJECT(simple->card), - field_data[field].ecard_field, &date, - NULL); - return NULL; /* FIXME!!!! */ - } else - return NULL; - case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: - addr = e_card_simple_get_address(simple, - field_data[field].list_type_index); - if (addr) - return g_strdup(addr->data); - else - return NULL; - case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: - phone = e_card_simple_get_phone(simple, - field_data[field].list_type_index); - if (phone) - return g_strdup(phone->number); - else - return NULL; - case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: - string = e_card_simple_get_email(simple, - field_data[field].list_type_index); - return g_strdup(string); - case E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL: - switch (field) { - case E_CARD_SIMPLE_FIELD_NAME_OR_ORG: - if (simple->card) { - gtk_object_get(GTK_OBJECT(simple->card), - "full_name", &string, - NULL); - if (string && *string) - return g_strdup(string); - gtk_object_get(GTK_OBJECT(simple->card), - "org", &string, - NULL); - if (string && *string) - return g_strdup(string); - string = e_card_simple_get_email(simple, - E_CARD_SIMPLE_EMAIL_ID_EMAIL); - return g_strdup(string); - } else - return NULL; - case E_CARD_SIMPLE_FIELD_FAMILY_NAME: - if (simple->card) { - gtk_object_get (GTK_OBJECT(simple->card), - "name", &name, - NULL); - return g_strdup (name->family); - } else - return NULL; - default: - return NULL; - } - default: - return NULL; - } -} - -static char * -name_to_style(const ECardName *name, char *company, int style) -{ - char *string; - char *strings[4], **stringptr; - char *substring; - switch (style) { - case 0: - stringptr = strings; - if (name->family && *name->family) - *(stringptr++) = name->family; - if (name->given && *name->given) - *(stringptr++) = name->given; - *stringptr = NULL; - string = g_strjoinv(", ", strings); - break; - case 1: - stringptr = strings; - if (name->given && *name->given) - *(stringptr++) = name->given; - if (name->family && *name->family) - *(stringptr++) = name->family; - *stringptr = NULL; - string = g_strjoinv(" ", strings); - break; - case 2: - string = g_strdup(company); - break; - case 3: /* Fall Through */ - case 4: - stringptr = strings; - if (name->family && *name->family) - *(stringptr++) = name->family; - if (name->given && *name->given) - *(stringptr++) = name->given; - *stringptr = NULL; - substring = g_strjoinv(", ", strings); - if (!(company && *company)) - company = ""; - if (style == 3) - string = g_strdup_printf("%s (%s)", substring, company); - else - string = g_strdup_printf("%s (%s)", company, substring); - g_free(substring); - break; - default: - string = g_strdup(""); - } - return string; -} - -static int -file_as_get_style (ECardSimple *simple) -{ - char *filestring = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FILE_AS); - char *trystring; - char *full_name = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FULL_NAME); - char *company = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_ORG); - ECardName *name = NULL; - int i; - int style; - style = 0; - if (!full_name) - full_name = g_strdup(""); - if (!company) - company = g_strdup(""); - if (filestring) { - - name = e_card_name_from_string(full_name); - - if (!name) { - goto end; - } - - style = -1; - - for (i = 0; i < 5; i++) { - trystring = name_to_style(name, company, i); - if (!strcmp(trystring, filestring)) { - g_free(trystring); - style = i; - goto end; - } - g_free(trystring); - } - } - end: - - g_free(filestring); - g_free(full_name); - g_free(company); - if (name) - e_card_name_free(name); - - return style; -} - -static void -file_as_set_style(ECardSimple *simple, int style) -{ - if (style != -1) { - char *string; - char *full_name = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FULL_NAME); - char *company = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_ORG); - ECardName *name; - - if (!full_name) - full_name = g_strdup(""); - if (!company) - company = g_strdup(""); - name = e_card_name_from_string(full_name); - if (name) { - string = name_to_style(name, company, style); - e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_FILE_AS, string); - g_free(string); - } - g_free(full_name); - g_free(company); - e_card_name_free(name); - } -} - -void e_card_simple_set (ECardSimple *simple, - ECardSimpleField field, - const char *data) -{ - ECardSimpleInternalType type = field_data[field].type; - ECardAddrLabel *address; - ECardPhone *phone; - int style; - simple->changed = TRUE; - switch (field) { - case E_CARD_SIMPLE_FIELD_FULL_NAME: - case E_CARD_SIMPLE_FIELD_ORG: - style = file_as_get_style(simple); - gtk_object_set(GTK_OBJECT(simple->card), - field_data[field].ecard_field, data, - NULL); - file_as_set_style(simple, style); - break; - default: - switch(type) { - case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: - gtk_object_set(GTK_OBJECT(simple->card), - field_data[field].ecard_field, data, - NULL); - break; - case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: - break; /* FIXME!!!! */ - case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: - address = e_card_address_label_new(); - address->data = (char *) data; - e_card_simple_set_address(simple, - field_data[field].list_type_index, - address); - address->data = NULL; - e_card_address_label_free(address); - break; - case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: - phone = e_card_phone_new(); - phone->number = (char *) data; - e_card_simple_set_phone(simple, - field_data[field].list_type_index, - phone); - phone->number = NULL; - e_card_phone_free(phone); - break; - case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: - e_card_simple_set_email(simple, - field_data[field].list_type_index, - data); - break; - case E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL: - break; - } - break; - } -} - -ECardSimpleType e_card_simple_type (ECardSimple *simple, - ECardSimpleField field) -{ - ECardSimpleInternalType type = field_data[field].type; - switch(type) { - case E_CARD_SIMPLE_INTERNAL_TYPE_STRING: - case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS: - case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE: - case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL: - default: - return E_CARD_SIMPLE_TYPE_STRING; - - case E_CARD_SIMPLE_INTERNAL_TYPE_DATE: - return E_CARD_SIMPLE_TYPE_DATE; - - case E_CARD_SIMPLE_INTERNAL_TYPE_SPECIAL: - return E_CARD_SIMPLE_TYPE_STRING; - } -} - -const char *e_card_simple_get_ecard_field (ECardSimple *simple, - ECardSimpleField field) -{ - return field_data[field].ecard_field; -} - -const char *e_card_simple_get_name (ECardSimple *simple, - ECardSimpleField field) -{ - return field_data[field].name; -} - -const char *e_card_simple_get_short_name (ECardSimple *simple, - ECardSimpleField field) -{ - return field_data[field].short_name; -} - -void e_card_simple_arbitrary_foreach (ECardSimple *simple, - ECardSimpleArbitraryCallback *callback, - gpointer closure) -{ - if (simple->card) { - EList *list; - EIterator *iterator; - gtk_object_get(GTK_OBJECT(simple->card), - "arbitrary", &list, - NULL); - for (iterator = e_list_get_iterator(list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ECardArbitrary *arbitrary = e_iterator_get(iterator); - if (callback) - (*callback) (arbitrary, closure); - } - e_card_free_empty_lists (simple->card); - } -} - -const ECardArbitrary *e_card_simple_get_arbitrary (ECardSimple *simple, - const char *key) -{ - if (simple->card) { - EList *list; - EIterator *iterator; - gtk_object_get(GTK_OBJECT(simple->card), - "arbitrary", &list, - NULL); - for (iterator = e_list_get_iterator(list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ECardArbitrary *arbitrary = e_iterator_get(iterator); - if (!strcasecmp(arbitrary->key, key)) - return arbitrary; - } - e_card_free_empty_lists (simple->card); - } - return NULL; -} - -/* Any of these except key can be NULL */ -void e_card_simple_set_arbitrary (ECardSimple *simple, - const char *key, - const char *type, - const char *value) -{ - if (simple->card) { - ECardArbitrary *new_arb; - EList *list; - EIterator *iterator; - - simple->changed = TRUE; - gtk_object_get(GTK_OBJECT(simple->card), - "arbitrary", &list, - NULL); - for (iterator = e_list_get_iterator(list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ECardArbitrary *arbitrary = e_iterator_get(iterator); - if (!strcasecmp(arbitrary->key, key)) { - new_arb = e_card_arbitrary_new(); - new_arb->key = g_strdup(key); - new_arb->type = g_strdup(type); - new_arb->value = g_strdup(value); - e_iterator_set(iterator, new_arb); - e_card_arbitrary_free(new_arb); - return; - } - } - new_arb = e_card_arbitrary_new(); - new_arb->key = g_strdup(key); - new_arb->type = g_strdup(type); - new_arb->value = g_strdup(value); - e_list_append(list, new_arb); - e_card_arbitrary_free(new_arb); - } -} - -/* These map between the individual list types and ECardSimpleField */ -ECardSimpleField -e_card_simple_map_phone_to_field (ECardSimplePhoneId phone_id) -{ - int i; - - g_return_val_if_fail (phone_id < E_CARD_SIMPLE_PHONE_ID_LAST, 0); - - for (i = 0; i < field_data_count; i ++) - if (field_data[i].list_type_index == phone_id - && field_data[i].type == E_CARD_SIMPLE_INTERNAL_TYPE_PHONE) - return i; - - g_warning ("couldn't find phone id %d, returning 0 (which is almost assuredly incorrect)\n", phone_id); - - return 0; -} - -ECardSimpleField -e_card_simple_map_email_to_field (ECardSimpleEmailId email_id) -{ - int i; - - g_return_val_if_fail (email_id < E_CARD_SIMPLE_EMAIL_ID_LAST, 0); - - for (i = 0; i < field_data_count; i ++) - if (field_data[i].list_type_index == email_id - && field_data[i].type == E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL) - return i; - - g_warning ("couldn't find email id %d, returning 0 (which is almost assuredly incorrect)\n", email_id); - return 0; -} - -ECardSimpleField -e_card_simple_map_address_to_field (ECardSimpleAddressId address_id) -{ - int i; - - g_return_val_if_fail (address_id < E_CARD_SIMPLE_ADDRESS_ID_LAST, 0); - - for (i = 0; i < field_data_count; i ++) - if (field_data[i].list_type_index == address_id - && field_data[i].type == E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS) - return i; - - g_warning ("couldn't find address id %d, returning 0 (which is almost assuredly incorrect)\n", address_id); - return 0; -} diff --git a/addressbook/backend/ebook/e-card-simple.h b/addressbook/backend/ebook/e-card-simple.h deleted file mode 100644 index 9e758516d3..0000000000 --- a/addressbook/backend/ebook/e-card-simple.h +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * Arturo Espinosa - * Nat Friedman (nat@ximian.com) - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_CARD_SIMPLE_H__ -#define __E_CARD_SIMPLE_H__ - -#include <time.h> -#include <gtk/gtk.h> -#include <stdio.h> -#include <addressbook/backend/ebook/e-card.h> -#include <addressbook/backend/ebook/e-card-types.h> -#include <e-util/e-list.h> - -#define E_TYPE_CARD_SIMPLE (e_card_simple_get_type ()) -#define E_CARD_SIMPLE(obj) (GTK_CHECK_CAST ((obj), E_TYPE_CARD_SIMPLE, ECardSimple)) -#define E_CARD_SIMPLE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_CARD_SIMPLE, ECardSimpleClass)) -#define E_IS_CARD_SIMPLE(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_CARD_SIMPLE)) -#define E_IS_CARD_SIMPLE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_CARD_SIMPLE)) - -typedef enum _ECardSimplePhoneId ECardSimplePhoneId; -typedef enum _ECardSimpleEmailId ECardSimpleEmailId; -typedef enum _ECardSimpleAddressId ECardSimpleAddressId; -typedef enum _ECardSimpleType ECardSimpleType; -typedef enum _ECardSimpleField ECardSimpleField; - -enum _ECardSimplePhoneId { - E_CARD_SIMPLE_PHONE_ID_ASSISTANT, - E_CARD_SIMPLE_PHONE_ID_BUSINESS, - E_CARD_SIMPLE_PHONE_ID_BUSINESS_2, - E_CARD_SIMPLE_PHONE_ID_BUSINESS_FAX, - E_CARD_SIMPLE_PHONE_ID_CALLBACK, - E_CARD_SIMPLE_PHONE_ID_CAR, - E_CARD_SIMPLE_PHONE_ID_COMPANY, - E_CARD_SIMPLE_PHONE_ID_HOME, - E_CARD_SIMPLE_PHONE_ID_HOME_2, - E_CARD_SIMPLE_PHONE_ID_HOME_FAX, - E_CARD_SIMPLE_PHONE_ID_ISDN, - E_CARD_SIMPLE_PHONE_ID_MOBILE, - E_CARD_SIMPLE_PHONE_ID_OTHER, - E_CARD_SIMPLE_PHONE_ID_OTHER_FAX, - E_CARD_SIMPLE_PHONE_ID_PAGER, - E_CARD_SIMPLE_PHONE_ID_PRIMARY, - E_CARD_SIMPLE_PHONE_ID_RADIO, - E_CARD_SIMPLE_PHONE_ID_TELEX, - E_CARD_SIMPLE_PHONE_ID_TTYTTD, - E_CARD_SIMPLE_PHONE_ID_LAST -}; - -/* We need HOME and WORK email addresses here. */ -enum _ECardSimpleEmailId { - E_CARD_SIMPLE_EMAIL_ID_EMAIL, - E_CARD_SIMPLE_EMAIL_ID_EMAIL_2, - E_CARD_SIMPLE_EMAIL_ID_EMAIL_3, - E_CARD_SIMPLE_EMAIL_ID_LAST -}; - -/* Should this include (BILLING/SHIPPING)? */ -enum _ECardSimpleAddressId { - E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, - E_CARD_SIMPLE_ADDRESS_ID_HOME, - E_CARD_SIMPLE_ADDRESS_ID_OTHER, - E_CARD_SIMPLE_ADDRESS_ID_LAST -}; - -enum _ECardSimpleType { - E_CARD_SIMPLE_TYPE_STRING, - E_CARD_SIMPLE_TYPE_DATE, -}; - -enum _ECardSimpleField { - E_CARD_SIMPLE_FIELD_FILE_AS, - E_CARD_SIMPLE_FIELD_FULL_NAME, - E_CARD_SIMPLE_FIELD_FAMILY_NAME, - E_CARD_SIMPLE_FIELD_EMAIL, - E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, - E_CARD_SIMPLE_FIELD_PHONE_ASSISTANT, - E_CARD_SIMPLE_FIELD_PHONE_BUSINESS, - E_CARD_SIMPLE_FIELD_PHONE_CALLBACK, - E_CARD_SIMPLE_FIELD_PHONE_COMPANY, - E_CARD_SIMPLE_FIELD_PHONE_HOME, - E_CARD_SIMPLE_FIELD_ORG, - E_CARD_SIMPLE_FIELD_ADDRESS_BUSINESS, - E_CARD_SIMPLE_FIELD_ADDRESS_HOME, - E_CARD_SIMPLE_FIELD_PHONE_MOBILE, - E_CARD_SIMPLE_FIELD_PHONE_CAR, - E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX, - E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX, - E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2, - E_CARD_SIMPLE_FIELD_PHONE_HOME_2, - E_CARD_SIMPLE_FIELD_PHONE_ISDN, - E_CARD_SIMPLE_FIELD_PHONE_OTHER, - E_CARD_SIMPLE_FIELD_PHONE_OTHER_FAX, - E_CARD_SIMPLE_FIELD_PHONE_PAGER, - E_CARD_SIMPLE_FIELD_PHONE_RADIO, - E_CARD_SIMPLE_FIELD_PHONE_TELEX, - E_CARD_SIMPLE_FIELD_PHONE_TTYTTD, - E_CARD_SIMPLE_FIELD_ADDRESS_OTHER, - E_CARD_SIMPLE_FIELD_EMAIL_2, - E_CARD_SIMPLE_FIELD_EMAIL_3, - E_CARD_SIMPLE_FIELD_URL, - E_CARD_SIMPLE_FIELD_ORG_UNIT, - E_CARD_SIMPLE_FIELD_OFFICE, - E_CARD_SIMPLE_FIELD_TITLE, - E_CARD_SIMPLE_FIELD_ROLE, - E_CARD_SIMPLE_FIELD_MANAGER, - E_CARD_SIMPLE_FIELD_ASSISTANT, - E_CARD_SIMPLE_FIELD_NICKNAME, - E_CARD_SIMPLE_FIELD_SPOUSE, - E_CARD_SIMPLE_FIELD_NOTE, - E_CARD_SIMPLE_FIELD_FBURL, - E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING = E_CARD_SIMPLE_FIELD_FBURL, - E_CARD_SIMPLE_FIELD_ANNIVERSARY, - E_CARD_SIMPLE_FIELD_BIRTH_DATE, - E_CARD_SIMPLE_FIELD_MAILER, - E_CARD_SIMPLE_FIELD_NAME_OR_ORG, - E_CARD_SIMPLE_FIELD_CATEGORIES, - E_CARD_SIMPLE_FIELD_LAST -}; - -typedef struct _ECardSimple ECardSimple; -typedef struct _ECardSimpleClass ECardSimpleClass; - -struct _ECardSimple { - GtkObject object; - ECard *card; - - GList *temp_fields; - - ECardPhone *phone[E_CARD_SIMPLE_PHONE_ID_LAST]; - char *email[E_CARD_SIMPLE_EMAIL_ID_LAST]; - ECardAddrLabel *address[E_CARD_SIMPLE_ADDRESS_ID_LAST]; - ECardDeliveryAddress *delivery[E_CARD_SIMPLE_ADDRESS_ID_LAST]; - - gboolean changed; -}; - -struct _ECardSimpleClass { - GtkObjectClass parent_class; -}; - -typedef void (*ECardSimpleArbitraryCallback) (const ECardArbitrary *arbitrary, gpointer closure); -ECardSimple *e_card_simple_new (ECard *card); -const char *e_card_simple_get_id (ECardSimple *simple); -void e_card_simple_set_id (ECardSimple *simple, - const gchar *character); -char *e_card_simple_get_vcard (ECardSimple *simple); -ECardSimple *e_card_simple_duplicate (ECardSimple *simple); -char *e_card_simple_get (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_const (ECardSimple *simple, - ECardSimpleField field); -void e_card_simple_set (ECardSimple *simple, - ECardSimpleField field, - const char *data); -ECardSimpleType e_card_simple_type (ECardSimple *simple, - ECardSimpleField field); - -const char *e_card_simple_get_ecard_field (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_name (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_short_name (ECardSimple *simple, - ECardSimpleField field); - - -/* Use these only if building lists of specific types. It should be - * easier to use the above if you consider a phone field to be the - * same as any other field. - */ -const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, - ECardSimplePhoneId id); -const char *e_card_simple_get_email (ECardSimple *simple, - ECardSimpleEmailId id); -const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, - ECardSimpleAddressId id); -const ECardDeliveryAddress *e_card_simple_get_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id); -void e_card_simple_set_phone (ECardSimple *simple, - ECardSimplePhoneId id, - const ECardPhone *phone); -void e_card_simple_set_email (ECardSimple *simple, - ECardSimpleEmailId id, - const char *email); -void e_card_simple_set_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardAddrLabel *address); -void e_card_simple_set_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardDeliveryAddress *delivery); -void e_card_simple_arbitrary_foreach (ECardSimple *simple, - ECardSimpleArbitraryCallback *callback, - gpointer closure); -const ECardArbitrary *e_card_simple_get_arbitrary (ECardSimple *simple, - const char *key); -/* Any of these except key can be NULL */ -void e_card_simple_set_arbitrary (ECardSimple *simple, - const char *key, - const char *type, - const char *value); -void e_card_simple_sync_card (ECardSimple *simple); - -/* These map between the individual list types and ECardSimpleField */ -ECardSimpleField e_card_simple_map_phone_to_field (ECardSimplePhoneId phone_id); -ECardSimpleField e_card_simple_map_email_to_field (ECardSimpleEmailId email_id); -ECardSimpleField e_card_simple_map_address_to_field (ECardSimpleAddressId address_id); - -/* Standard Gtk function */ -GtkType e_card_simple_get_type (void); - -#endif /* ! __E_CARD_SIMPLE_H__ */ - - diff --git a/addressbook/backend/ebook/e-card-types.h b/addressbook/backend/ebook/e-card-types.h deleted file mode 100644 index 13854c30e7..0000000000 --- a/addressbook/backend/ebook/e-card-types.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Arturo Espinosa - * Nat Friedman (nat@ximian.com) - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_CARD_TYPES_H__ -#define __E_CARD_TYPES_H__ - -/* IDENTIFICATION PROPERTIES */ - -typedef struct { - char *prefix; /* Mr. */ - char *given; /* John */ - char *additional; /* Quinlan */ - char *family; /* Public */ - char *suffix; /* Esq. */ -} ECardName; - -typedef struct { - int year; - int month; - int day; -} ECardDate; - -/* TELECOMMUNICATIONS ADDRESSING PROPERTIES */ - -typedef enum { - E_CARD_PHONE_PREF = 1 << 0, - E_CARD_PHONE_WORK = 1 << 1, - E_CARD_PHONE_HOME = 1 << 2, - E_CARD_PHONE_VOICE = 1 << 3, - E_CARD_PHONE_FAX = 1 << 4, - E_CARD_PHONE_MSG = 1 << 5, - E_CARD_PHONE_CELL = 1 << 6, - E_CARD_PHONE_PAGER = 1 << 7, - E_CARD_PHONE_BBS = 1 << 8, - E_CARD_PHONE_MODEM = 1 << 9, - E_CARD_PHONE_CAR = 1 << 10, - E_CARD_PHONE_ISDN = 1 << 11, - E_CARD_PHONE_VIDEO = 1 << 12, - E_CARD_PHONE_ASSISTANT = 1 << 13, - E_CARD_PHONE_CALLBACK = 1 << 14, - E_CARD_PHONE_RADIO = 1 << 15, - E_CARD_PHONE_TELEX = 1 << 16, - E_CARD_PHONE_TTYTDD = 1 << 17, -} ECardPhoneFlags; - -typedef struct { - ECardPhoneFlags flags; - char *number; -} ECardPhone; - -/* DELIVERY ADDRESSING PROPERTIES */ - -typedef enum { - E_CARD_ADDR_HOME = 1 << 0, - E_CARD_ADDR_WORK = 1 << 1, - E_CARD_ADDR_POSTAL = 1 << 2, - E_CARD_ADDR_PARCEL = 1 << 3, - E_CARD_ADDR_DOM = 1 << 4, - E_CARD_ADDR_INTL = 1 << 5 -} ECardAddressFlags; - -typedef struct { - ECardAddressFlags flags; - - char *po; - char *ext; - char *street; - char *city; - char *region; - char *code; - char *country; -} ECardDeliveryAddress; - -typedef struct { - ECardAddressFlags flags; - char *data; -} ECardAddrLabel; - -/* ARBITRARY PROPERTIES */ - -typedef struct { - char *key; - char *type; - char *value; -} ECardArbitrary; - -#endif /* __E_CARD_TYPES_H__ */ diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c deleted file mode 100644 index 3833211637..0000000000 --- a/addressbook/backend/ebook/e-card.c +++ /dev/null @@ -1,4188 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Arturo Espinosa (arturo@nuclecu.unam.mx) - * Nat Friedman (nat@ximian.com) - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include <config.h> - -#include "e-card.h" - -#include <gal/util/e-i18n.h> - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <math.h> - -#include <gtk/gtkobject.h> -#include <bonobo/bonobo-object-client.h> -#include <gal/util/e-util.h> - -#include <libversit/vcc.h> -#include "e-util/ename/e-name-western.h" -#include "e-util/ename/e-address-western.h" -#include "e-book.h" - -#define is_a_prop_of(obj,prop) (isAPropertyOf ((obj),(prop))) -#define str_val(obj) (the_str = (vObjectValueType (obj))? fakeCString (vObjectUStringZValue (obj)) : calloc (1, 1)) -#define has(obj,prop) (vo = isAPropertyOf ((obj), (prop))) - -#define XEV_WANTS_HTML "X-MOZILLA-HTML" -#define XEV_ARBITRARY "X-EVOLUTION-ARBITRARY" -#define XEV_LIST "X-EVOLUTION-LIST" -#define XEV_LIST_SHOW_ADDRESSES "X-EVOLUTION-LIST-SHOW_ADDRESSES" -#define XEV_RELATED_CONTACTS "X-EVOLUTION-RELATED_CONTACTS" - -/* Object argument IDs */ -enum { - ARG_0, - ARG_FILE_AS, - ARG_FULL_NAME, - ARG_NAME, - ARG_ADDRESS, - ARG_ADDRESS_LABEL, - ARG_PHONE, - ARG_EMAIL, - ARG_BIRTH_DATE, - ARG_URL, - ARG_ORG, - ARG_ORG_UNIT, - ARG_OFFICE, - ARG_TITLE, - ARG_ROLE, - ARG_MANAGER, - ARG_ASSISTANT, - ARG_NICKNAME, - ARG_SPOUSE, - ARG_ANNIVERSARY, - ARG_MAILER, - ARG_FBURL, - ARG_NOTE, - ARG_RELATED_CONTACTS, - ARG_CATEGORIES, - ARG_CATEGORY_LIST, - ARG_WANTS_HTML, - ARG_WANTS_HTML_SET, - ARG_EVOLUTION_LIST, - ARG_EVOLUTION_LIST_SHOW_ADDRESSES, - ARG_ARBITRARY, - ARG_ID, - ARG_LAST_USE, - ARG_USE_SCORE, -}; - -#if 0 -static VObject *card_convert_to_vobject (ECard *crd); -#endif -static void parse(ECard *card, VObject *vobj); -static void e_card_init (ECard *card); -static void e_card_class_init (ECardClass *klass); - -static void e_card_destroy (GtkObject *object); -static void e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void assign_string(VObject *vobj, char **string); - -char *e_v_object_get_child_value(VObject *vobj, char *name); -static ECardDate e_card_date_from_string (char *str); - -static void parse_bday(ECard *card, VObject *object); -static void parse_full_name(ECard *card, VObject *object); -static void parse_file_as(ECard *card, VObject *object); -static void parse_name(ECard *card, VObject *object); -static void parse_email(ECard *card, VObject *object); -static void parse_phone(ECard *card, VObject *object); -static void parse_address(ECard *card, VObject *object); -static void parse_address_label(ECard *card, VObject *object); -static void parse_url(ECard *card, VObject *object); -static void parse_org(ECard *card, VObject *object); -static void parse_office(ECard *card, VObject *object); -static void parse_title(ECard *card, VObject *object); -static void parse_role(ECard *card, VObject *object); -static void parse_manager(ECard *card, VObject *object); -static void parse_assistant(ECard *card, VObject *object); -static void parse_nickname(ECard *card, VObject *object); -static void parse_spouse(ECard *card, VObject *object); -static void parse_anniversary(ECard *card, VObject *object); -static void parse_mailer(ECard *card, VObject *object); -static void parse_fburl(ECard *card, VObject *object); -static void parse_note(ECard *card, VObject *object); -static void parse_related_contacts(ECard *card, VObject *object); -static void parse_categories(ECard *card, VObject *object); -static void parse_wants_html(ECard *card, VObject *object); -static void parse_list(ECard *card, VObject *object); -static void parse_list_show_addresses(ECard *card, VObject *object); -static void parse_arbitrary(ECard *card, VObject *object); -static void parse_id(ECard *card, VObject *object); -static void parse_last_use(ECard *card, VObject *object); -static void parse_use_score(ECard *card, VObject *object); - -static ECardPhoneFlags get_phone_flags (VObject *vobj); -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 gchar *e_card_uri_extract_book_uri (const gchar *uri); -static gchar *e_card_uri_extract_card_id (const gchar *uri); - -typedef void (* ParsePropertyFunc) (ECard *card, VObject *object); - -struct { - char *key; - ParsePropertyFunc function; -} attribute_jump_array[] = -{ - { VCFullNameProp, parse_full_name }, - { "X-EVOLUTION-FILE-AS", parse_file_as }, - { VCNameProp, parse_name }, - { VCBirthDateProp, parse_bday }, - { VCEmailAddressProp, parse_email }, - { VCTelephoneProp, parse_phone }, - { VCAdrProp, parse_address }, - { VCDeliveryLabelProp, parse_address_label }, - { VCURLProp, parse_url }, - { VCOrgProp, parse_org }, - { "X-EVOLUTION-OFFICE", parse_office }, - { VCTitleProp, parse_title }, - { VCBusinessRoleProp, parse_role }, - { "X-EVOLUTION-MANAGER", parse_manager }, - { "X-EVOLUTION-ASSISTANT", parse_assistant }, - { "NICKNAME", parse_nickname }, - { "X-EVOLUTION-SPOUSE", parse_spouse }, - { "X-EVOLUTION-ANNIVERSARY", parse_anniversary }, - { VCMailerProp, parse_mailer }, - { "FBURL", parse_fburl }, - { VCNoteProp, parse_note }, - { XEV_RELATED_CONTACTS, parse_related_contacts }, - { "CATEGORIES", parse_categories }, - { XEV_WANTS_HTML, parse_wants_html }, - { XEV_ARBITRARY, parse_arbitrary }, - { VCUniqueStringProp, parse_id }, - { "X-EVOLUTION-LAST-USE", parse_last_use }, - { "X-EVOLUTION-USE-SCORE", parse_use_score }, - { XEV_LIST, parse_list }, - { XEV_LIST_SHOW_ADDRESSES, parse_list_show_addresses }, - { VCUniqueStringProp, parse_id } -}; - -/** - * e_card_get_type: - * @void: - * - * Registers the &ECard class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ECard class. - **/ -GtkType -e_card_get_type (void) -{ - static GtkType card_type = 0; - - if (!card_type) { - GtkTypeInfo card_info = { - "ECard", - sizeof (ECard), - sizeof (ECardClass), - (GtkClassInitFunc) e_card_class_init, - (GtkObjectInitFunc) e_card_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - card_type = gtk_type_unique (gtk_object_get_type (), &card_info); - } - - return card_type; -} - -/** - * e_card_new: - * @vcard: a string in vCard format - * - * Returns: a new #ECard that wraps the @vcard. - */ -ECard * -e_card_new (char *vcard) -{ - ECard *card = E_CARD(gtk_type_new(e_card_get_type())); - VObject *vobj = Parse_MIME(vcard, strlen(vcard)); - while(vobj) { - VObject *next; - parse(card, vobj); - next = nextVObjectInList(vobj); - cleanVObject(vobj); - vobj = next; - } - if (card->name == NULL) - card->name = e_card_name_new(); - if (card->file_as == NULL) - card->file_as = g_strdup(""); - if (card->fname == NULL) - card->fname = g_strdup(""); - return card; -} - -ECard * -e_card_duplicate(ECard *card) -{ - char *vcard = e_card_get_vcard(card); - ECard *new_card = e_card_new(vcard); - g_free (vcard); - - if (card->book) { - new_card->book = card->book; - gtk_object_ref (GTK_OBJECT (new_card->book)); - } - - return new_card; -} - -static void -e_card_get_today (GDate *dt) -{ - time_t now; - struct tm *now_tm; - if (dt == NULL) - return; - - time (&now); - now_tm = localtime (&now); - - g_date_set_dmy (dt, now_tm->tm_mday, now_tm->tm_mon + 1, now_tm->tm_year + 1900); -} - -float -e_card_get_use_score(ECard *card) -{ - GDate today, last_use; - gint days_since_last_use; - - g_return_val_if_fail (card != NULL && E_IS_CARD (card), 0); - - if (card->last_use == NULL) - return 0.0; - - e_card_get_today (&today); - g_date_set_dmy (&last_use, card->last_use->day, card->last_use->month, card->last_use->year); - - days_since_last_use = g_date_julian (&today) - g_date_julian (&last_use); - - /* Apply a seven-day "grace period" to the use score decay. */ - days_since_last_use -= 7; - if (days_since_last_use < 0) - days_since_last_use = 0; - - return MAX (card->raw_use_score, 0) * exp (- days_since_last_use / 30.0); -} - -void -e_card_touch(ECard *card) -{ - GDate today; - double use_score; - - g_return_if_fail (card != NULL && E_IS_CARD (card)); - - e_card_get_today (&today); - use_score = e_card_get_use_score (card); - - if (card->last_use == NULL) - card->last_use = g_new (ECardDate, 1); - - card->last_use->day = g_date_day (&today); - card->last_use->month = g_date_month (&today); - card->last_use->year = g_date_year (&today); - - card->raw_use_score = use_score + 1.0; -} - -/** - * e_card_get_id: - * @card: an #ECard - * - * Returns: a string representing the id of the card, which is unique - * within its book. - */ -const char * -e_card_get_id (ECard *card) -{ - g_return_val_if_fail (card && E_IS_CARD (card), NULL); - - return card->id; -} - -/** - * e_card_get_id: - * @card: an #ECard - * @id: a id in string format - * - * Sets the identifier of a card, which should be unique within its - * book. - */ -void -e_card_set_id (ECard *card, const char *id) -{ - g_return_if_fail (card && E_IS_CARD (card)); - - if ( card->id ) - g_free(card->id); - card->id = g_strdup(id); -} - -EBook * -e_card_get_book (ECard *card) -{ - g_return_val_if_fail (card && E_IS_CARD (card), NULL); - - return card->book; -} - -const gchar * -e_card_get_uri (ECard *card) -{ - g_return_val_if_fail (card && E_IS_CARD (card), NULL); - - if (card->uri == NULL && card->id && *card->id && card->book) { - const char *book_uri = e_book_get_uri (card->book); - if (book_uri) - card->uri = g_strdup_printf ("%s/%s", book_uri, card->id); - } - return card->uri; -} - -static gchar * -e_card_date_to_string (ECardDate *dt) -{ - if (dt) - return g_strdup_printf ("%04d-%02d-%02d", - CLAMP(dt->year, 1000, 9999), - CLAMP(dt->month, 1, 12), - CLAMP(dt->day, 1, 31)); - else - return NULL; -} - -static VObject * -e_card_get_vobject (ECard *card) -{ - VObject *vobj; - const char *tmp; - - vobj = newVObject (VCCardProp); - - if ( card->file_as && *card->file_as ) - addPropValue(vobj, "X-EVOLUTION-FILE-AS", card->file_as); - else if (card->file_as) - addProp(vobj, "X-EVOLUTION-FILE_AS"); - - if ( card->fname ) - addPropValue(vobj, VCFullNameProp, card->fname); - else if (card->fname) - addProp(vobj, VCFullNameProp); - - if ( card->name && (card->name->prefix || card->name->given || card->name->additional || card->name->family || card->name->suffix) ) { - VObject *nameprop; - nameprop = addProp(vobj, VCNameProp); - if ( card->name->prefix ) - addPropValue(nameprop, VCNamePrefixesProp, card->name->prefix); - if ( card->name->given ) - addPropValue(nameprop, VCGivenNameProp, card->name->given); - if ( card->name->additional ) - addPropValue(nameprop, VCAdditionalNamesProp, card->name->additional); - if ( card->name->family ) - addPropValue(nameprop, VCFamilyNameProp, card->name->family); - if ( card->name->suffix ) - addPropValue(nameprop, VCNameSuffixesProp, card->name->suffix); - } - else if (card->name) - addProp(vobj, VCNameProp); - - - if ( card->address ) { - EIterator *iterator = e_list_get_iterator(card->address); - for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { - VObject *addressprop; - ECardDeliveryAddress *address = (ECardDeliveryAddress *) e_iterator_get(iterator); - addressprop = addProp(vobj, VCAdrProp); - - set_address_flags (addressprop, address->flags); - if ( address->po ) - addPropValue(addressprop, VCPostalBoxProp, address->po); - if ( address->ext ) - addPropValue(addressprop, VCExtAddressProp, address->ext); - if ( address->street ) - addPropValue(addressprop, VCStreetAddressProp, address->street); - if ( address->city ) - addPropValue(addressprop, VCCityProp, address->city); - if ( address->region ) - addPropValue(addressprop, VCRegionProp, address->region); - if ( address->code ) - addPropValue(addressprop, VCPostalCodeProp, address->code); - if ( address->country ) - addPropValue(addressprop, VCCountryNameProp, address->country); - addProp(addressprop, VCQuotedPrintableProp); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - - if ( card->address_label ) { - EIterator *iterator = e_list_get_iterator(card->address_label); - for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { - VObject *labelprop; - ECardAddrLabel *address_label = (ECardAddrLabel *) e_iterator_get(iterator); - if (address_label->data) - labelprop = addPropValue(vobj, VCDeliveryLabelProp, address_label->data); - else - labelprop = addProp(vobj, VCDeliveryLabelProp); - - set_address_flags (labelprop, address_label->flags); - addProp(labelprop, VCQuotedPrintableProp); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - - if ( card->phone ) { - EIterator *iterator = e_list_get_iterator(card->phone); - for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { - VObject *phoneprop; - ECardPhone *phone = (ECardPhone *) e_iterator_get(iterator); - phoneprop = addPropValue(vobj, VCTelephoneProp, phone->number); - - set_phone_flags (phoneprop, phone->flags); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - - if ( card->email ) { - EIterator *iterator = e_list_get_iterator(card->email); - for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { - VObject *emailprop; - emailprop = addPropValue(vobj, VCEmailAddressProp, (char *) e_iterator_get(iterator)); - addProp (emailprop, VCInternetProp); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - - if ( card->bday ) { - char *value; - value = e_card_date_to_string (card->bday); - addPropValue(vobj, VCBirthDateProp, value); - g_free(value); - } - - if (card->url) - addPropValue(vobj, VCURLProp, card->url); - - if (card->org || card->org_unit) { - VObject *orgprop; - orgprop = addProp(vobj, VCOrgProp); - - if (card->org) - addPropValue(orgprop, VCOrgNameProp, card->org); - if (card->org_unit) - addPropValue(orgprop, VCOrgUnitProp, card->org_unit); - } - - if (card->office) - addPropValue(vobj, "X-EVOLUTION-OFFICE", card->office); - - if (card->title) - addPropValue(vobj, VCTitleProp, card->title); - - if (card->role) - addPropValue(vobj, VCBusinessRoleProp, card->role); - - if (card->manager) - addPropValue(vobj, "X-EVOLUTION-MANAGER", card->manager); - - if (card->assistant) - addPropValue(vobj, "X-EVOLUTION-ASSISTANT", card->assistant); - - if (card->nickname) - addPropValue(vobj, "NICKNAME", card->nickname); - - if (card->spouse) - addPropValue(vobj, "X-EVOLUTION-SPOUSE", card->spouse); - - if ( card->anniversary ) { - char *value; - value = e_card_date_to_string (card->anniversary); - addPropValue(vobj, "X-EVOLUTION-ANNIVERSARY", value); - g_free(value); - } - - if (card->mailer) { - addPropValue(vobj, VCMailerProp, card->mailer); - } - - if (card->fburl) - addPropValue(vobj, "FBURL", card->fburl); - - if (card->note) { - VObject *noteprop; - - noteprop = addPropValue(vobj, VCNoteProp, card->note); - addProp(noteprop, VCQuotedPrintableProp); - } - - if (card->last_use) { - char *value; - value = e_card_date_to_string (card->last_use); - addPropValue (vobj, "X-EVOLUTION-LAST-USE", value); - g_free (value); - } - - if (card->raw_use_score > 0) { - char *value; - value = g_strdup_printf ("%f", card->raw_use_score); - addPropValue (vobj, "X-EVOLUTION-USE-SCORE", value); - g_free (value); - } - - if (card->related_contacts && *card->related_contacts) { - addPropValue(vobj, XEV_RELATED_CONTACTS, card->related_contacts); - } - - if (card->categories) { - EIterator *iterator; - int length = 0; - char *string; - char *stringptr; - for (iterator = e_list_get_iterator(card->categories); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - length += strlen(e_iterator_get(iterator)) + 1; - } - string = g_new(char, length + 1); - stringptr = string; - *stringptr = 0; - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - strcpy(stringptr, e_iterator_get(iterator)); - stringptr += strlen(stringptr); - *stringptr = ','; - stringptr++; - *stringptr = 0; - } - if (stringptr > string) { - stringptr --; - *stringptr = 0; - } - addPropValue (vobj, "CATEGORIES", string); - g_free(string); - } - - if (card->wants_html_set) { - addPropValue (vobj, XEV_WANTS_HTML, card->wants_html ? "TRUE" : "FALSE"); - } - - if (card->list) { - addPropValue (vobj, XEV_LIST, "TRUE"); - addPropValue (vobj, XEV_LIST_SHOW_ADDRESSES, card->list_show_addresses ? "TRUE" : "FALSE"); - } - - if (card->arbitrary) { - EIterator *iterator; - for (iterator = e_list_get_iterator(card->arbitrary); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ECardArbitrary *arbitrary = e_iterator_get(iterator); - VObject *arb_object; - if (arbitrary->value) { - arb_object = addPropValue (vobj, XEV_ARBITRARY, arbitrary->value); - } else { - arb_object = addProp (vobj, XEV_ARBITRARY); - } - if (arbitrary->type) { - addPropValue (arb_object, "TYPE", arbitrary->type); - } - if (arbitrary->key) { - addProp (arb_object, arbitrary->key); - } - } - } - - tmp = e_card_get_uri (card); - if (tmp == NULL) - tmp = card->id; - if (tmp) { - addPropValue (vobj, VCUniqueStringProp, tmp); - } - -#if 0 - - - if (crd->photo.prop.used) { - vprop = addPropSizedValue (vobj, VCPhotoProp, - crd->photo.data, crd->photo.size); - add_PhotoType (vprop, crd->photo.type); - add_CardProperty (vprop, &crd->photo.prop); - } - - if (crd->xtension.l) { - GList *node; - - for (node = crd->xtension.l; node; node = node->next) { - CardXProperty *xp = (CardXProperty *) node->data; - addPropValue (vobj, xp->name, xp->data); - add_CardProperty (vobj, &xp->prop); - } - } - - if (crd->timezn.prop.used) { - char *str; - - str = card_timezn_str (crd->timezn); - vprop = addPropValue (vobj, VCTimeZoneProp, str); - free (str); - add_CardProperty (vprop, &crd->timezn.prop); - } - - if (crd->geopos.prop.used) { - char *str; - - str = card_geopos_str (crd->geopos); - vprop = addPropValue (vobj, VCGeoLocationProp, str); - free (str); - add_CardProperty (vprop, &crd->geopos.prop); - } - - if (crd->logo.prop.used) { - vprop = addPropSizedValue (vobj, VCLogoProp, - crd->logo.data, crd->logo.size); - add_PhotoType (vprop, crd->logo.type); - add_CardProperty (vprop, &crd->logo.prop); - } - - if (crd->agent) - addVObjectProp (vobj, card_convert_to_vobject (crd->agent)); - - if (crd->sound.prop.used) { - if (crd->sound.type != SOUND_PHONETIC) - vprop = addPropSizedValue (vobj, VCPronunciationProp, - crd->sound.data, crd->sound.size); - else - vprop = addPropValue (vobj, VCPronunciationProp, - crd->sound.data); - - add_SoundType (vprop, crd->sound.type); - add_CardProperty (vprop, &crd->sound.prop); - } - - if (crd->key.prop.used) { - vprop = addPropValue (vobj, VCPublicKeyProp, crd->key.data); - add_KeyType (vprop, crd->key.type); - add_CardProperty (vprop, &crd->key.prop); - } -#endif - return vobj; -} - -/** - * e_card_get_vcard: - * @card: an #ECard - * - * Returns: a string in vCard format, which is wrapped by the @card. - */ -char * -e_card_get_vcard (ECard *card) -{ - VObject *vobj; - char *temp, *ret_val; - - vobj = e_card_get_vobject (card); - temp = writeMemVObject(NULL, NULL, vobj); - ret_val = g_strdup(temp); - free(temp); - cleanVObject(vobj); - return ret_val; -} - -/** - * e_card_list_get_vcard: - * @list: a list of #ECards - * - * Returns: a string in vCard format. - */ -char * -e_card_list_get_vcard (GList *list) -{ - VObject *vobj; - - char *temp, *ret_val; - - vobj = NULL; - - for (; list; list = list->next) { - VObject *tempvobj; - ECard *card = list->data; - - tempvobj = e_card_get_vobject (card); - addList (&vobj, tempvobj); - } - temp = writeMemVObjects(NULL, NULL, vobj); - ret_val = g_strdup(temp); - free(temp); - cleanVObjects(vobj); - return ret_val; -} - -static void -parse_file_as(ECard *card, VObject *vobj) -{ - if ( card->file_as ) - g_free(card->file_as); - assign_string(vobj, &(card->file_as)); -} - -static void -parse_name(ECard *card, VObject *vobj) -{ - if ( card->name ) { - e_card_name_free(card->name); - } - card->name = g_new(ECardName, 1); - - card->name->family = e_v_object_get_child_value (vobj, VCFamilyNameProp); - card->name->given = e_v_object_get_child_value (vobj, VCGivenNameProp); - card->name->additional = e_v_object_get_child_value (vobj, VCAdditionalNamesProp); - card->name->prefix = e_v_object_get_child_value (vobj, VCNamePrefixesProp); - card->name->suffix = e_v_object_get_child_value (vobj, VCNameSuffixesProp); -} - -static void -parse_full_name(ECard *card, VObject *vobj) -{ - if ( card->fname ) - g_free(card->fname); - assign_string(vobj, &(card->fname)); -} - -static void -parse_email(ECard *card, VObject *vobj) -{ - char *next_email; - EList *list; - - assign_string(vobj, &next_email); - gtk_object_get(GTK_OBJECT(card), - "email", &list, - NULL); - e_list_append(list, next_email); - g_free (next_email); -} - -static void -parse_bday(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if ( card->bday ) - g_free(card->bday); - card->bday = g_new(ECardDate, 1); - *(card->bday) = e_card_date_from_string(str); - free(str); - } -} - -static void -parse_phone(ECard *card, VObject *vobj) -{ - ECardPhone *next_phone = g_new(ECardPhone, 1); - EList *list; - - assign_string(vobj, &(next_phone->number)); - next_phone->flags = get_phone_flags(vobj); - - gtk_object_get(GTK_OBJECT(card), - "phone", &list, - NULL); - e_list_append(list, next_phone); - e_card_phone_free (next_phone); -} - -static void -parse_address(ECard *card, VObject *vobj) -{ - ECardDeliveryAddress *next_addr = g_new(ECardDeliveryAddress, 1); - EList *list; - - next_addr->flags = get_address_flags (vobj); - next_addr->po = e_v_object_get_child_value (vobj, VCPostalBoxProp); - next_addr->ext = e_v_object_get_child_value (vobj, VCExtAddressProp); - next_addr->street = e_v_object_get_child_value (vobj, VCStreetAddressProp); - next_addr->city = e_v_object_get_child_value (vobj, VCCityProp); - next_addr->region = e_v_object_get_child_value (vobj, VCRegionProp); - next_addr->code = e_v_object_get_child_value (vobj, VCPostalCodeProp); - next_addr->country = e_v_object_get_child_value (vobj, VCCountryNameProp); - - gtk_object_get(GTK_OBJECT(card), - "address", &list, - NULL); - e_list_append(list, next_addr); - e_card_delivery_address_free (next_addr); -} - -static void -parse_address_label(ECard *card, VObject *vobj) -{ - ECardAddrLabel *next_addr = g_new(ECardAddrLabel, 1); - EList *list; - - next_addr->flags = get_address_flags (vobj); - assign_string(vobj, &next_addr->data); - - gtk_object_get(GTK_OBJECT(card), - "address_label", &list, - NULL); - e_list_append(list, next_addr); - e_card_address_label_free (next_addr); -} - -static void -parse_url(ECard *card, VObject *vobj) -{ - if (card->url) - g_free(card->url); - assign_string(vobj, &(card->url)); -} - -static void -parse_org(ECard *card, VObject *vobj) -{ - char *temp; - - temp = e_v_object_get_child_value(vobj, VCOrgNameProp); - g_free(card->org); - card->org = temp; - - temp = e_v_object_get_child_value(vobj, VCOrgUnitProp); - g_free(card->org_unit); - card->org_unit = temp; -} - -static void -parse_office(ECard *card, VObject *vobj) -{ - if ( card->office ) - g_free(card->office); - assign_string(vobj, &(card->office)); -} - -static void -parse_title(ECard *card, VObject *vobj) -{ - if ( card->title ) - g_free(card->title); - assign_string(vobj, &(card->title)); -} - -static void -parse_role(ECard *card, VObject *vobj) -{ - if (card->role) - g_free(card->role); - assign_string(vobj, &(card->role)); -} - -static void -parse_manager(ECard *card, VObject *vobj) -{ - if ( card->manager ) - g_free(card->manager); - assign_string(vobj, &(card->manager)); -} - -static void -parse_assistant(ECard *card, VObject *vobj) -{ - if ( card->assistant ) - g_free(card->assistant); - assign_string(vobj, &(card->assistant)); -} - -static void -parse_nickname(ECard *card, VObject *vobj) -{ - if (card->nickname) - g_free(card->nickname); - assign_string(vobj, &(card->nickname)); -} - -static void -parse_spouse(ECard *card, VObject *vobj) -{ - if ( card->spouse ) - g_free(card->spouse); - assign_string(vobj, &(card->spouse)); -} - -static void -parse_anniversary(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if (card->anniversary) - g_free(card->anniversary); - card->anniversary = g_new(ECardDate, 1); - *(card->anniversary) = e_card_date_from_string(str); - free(str); - } -} - -static void -parse_mailer(ECard *card, VObject *vobj) -{ - if ( card->mailer ) - g_free(card->mailer); - assign_string(vobj, &(card->mailer)); -} - -static void -parse_fburl(ECard *card, VObject *vobj) -{ - g_free(card->fburl); - assign_string(vobj, &(card->fburl)); -} - -static void -parse_note(ECard *card, VObject *vobj) -{ - g_free(card->note); - assign_string(vobj, &(card->note)); -} - -static void -parse_related_contacts(ECard *card, VObject *vobj) -{ - g_free(card->related_contacts); - assign_string(vobj, &(card->related_contacts)); -} - -static void -add_list_unique(ECard *card, EList *list, char *string) -{ - char *temp = e_strdup_strip(string); - EIterator *iterator; - - if (!*temp) { - g_free(temp); - return; - } - for ( iterator = e_list_get_iterator(list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - if (!strcmp(e_iterator_get(iterator), temp)) { - break; - } - } - if (!e_iterator_is_valid(iterator)) { - e_list_append(list, temp); - } - g_free(temp); - gtk_object_unref(GTK_OBJECT(iterator)); -} - -static void -do_parse_categories(ECard *card, char *str) -{ - int length = strlen(str); - char *copy = g_new(char, length + 1); - int i, j; - EList *list; - gtk_object_get(GTK_OBJECT(card), - "category_list", &list, - NULL); - for (i = 0, j = 0; str[i]; i++, j++) { - switch (str[i]) { - case '\\': - i++; - if (str[i]) { - copy[j] = str[i]; - } else - i--; - break; - case ',': - copy[j] = 0; - add_list_unique(card, list, copy); - j = -1; - break; - default: - copy[j] = str[i]; - break; - } - } - copy[j] = 0; - add_list_unique(card, list, copy); - g_free(copy); -} - -static void -parse_categories(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - do_parse_categories(card, str); - free(str); - } -} - -static void -parse_wants_html(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if (!strcasecmp(str, "true")) { - card->wants_html = TRUE; - card->wants_html_set = TRUE; - } - if (!strcasecmp(str, "false")) { - card->wants_html = FALSE; - card->wants_html_set = TRUE; - } - free(str); - } -} - -static void -parse_list(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if (!strcasecmp(str, "true")) { - card->list = TRUE; - } - if (!strcasecmp(str, "false")) { - card->list = FALSE; - } - free(str); - } -} - -static void -parse_list_show_addresses(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if (!strcasecmp(str, "true")) { - card->list_show_addresses = TRUE; - } - if (!strcasecmp(str, "false")) { - card->list_show_addresses = FALSE; - } - free(str); - } -} - -typedef union ValueItem { - const char *strs; - const wchar_t *ustrs; - unsigned int i; - unsigned long l; - void *any; - VObject *vobj; -} ValueItem; - -struct VObject { - VObject *next; - const char *id; - VObject *prop; - unsigned short valType; - ValueItem val; -}; - -static void -parse_arbitrary(ECard *card, VObject *vobj) -{ - ECardArbitrary *arbitrary = e_card_arbitrary_new(); - VObjectIterator iterator; - EList *list; - for ( initPropIterator (&iterator, vobj); moreIteration(&iterator); ) { - VObject *temp = nextVObject(&iterator); - const char *name = vObjectName(temp); - if (name && !strcmp(name, "TYPE")) { - g_free(arbitrary->type); - assign_string(temp, &(arbitrary->type)); - } else { - g_free(arbitrary->key); - arbitrary->key = g_strdup(name); - } - } - - assign_string(vobj, &(arbitrary->value)); - - gtk_object_get(GTK_OBJECT(card), - "arbitrary", &list, - NULL); - e_list_append(list, arbitrary); - e_card_arbitrary_free(arbitrary); -} - -static void -parse_id(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - gchar *str = fakeCString (vObjectUStringZValue (vobj)); - gchar *id; - if ( card->id ) - g_free(card->id); - if ( card->uri ) - g_free(card->uri); - - id = e_card_uri_extract_card_id (str); - if (id) { - card->id = id; - card->uri = g_strdup (str); - } else { - card->id = g_strdup (str); - card->uri = NULL; - } - free (str); - } -} - -static void -parse_last_use(ECard *card, VObject *vobj) -{ - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - if ( card->last_use ) - g_free(card->last_use); - card->last_use = g_new(ECardDate, 1); - *(card->last_use) = e_card_date_from_string(str); - free(str); - } -} - -static void -parse_use_score(ECard *card, VObject *vobj) -{ - card->raw_use_score = 0; - - if ( vObjectValueType (vobj) ) { - char *str = fakeCString (vObjectUStringZValue (vobj)); - card->raw_use_score = MAX(0, atof (str)); - free (str); - } -} - -static void -parse_attribute(ECard *card, VObject *vobj) -{ - ParsePropertyFunc function = g_hash_table_lookup(E_CARD_CLASS(GTK_OBJECT(card)->klass)->attribute_jump_table, vObjectName(vobj)); - if ( function ) - function(card, vobj); -} - -static void -parse(ECard *card, VObject *vobj) -{ - VObjectIterator iterator; - initPropIterator(&iterator, vobj); - while(moreIteration (&iterator)) { - parse_attribute(card, nextVObject(&iterator)); - } - if (!card->fname) { - card->fname = g_strdup(""); - } - if (!card->name) { - card->name = e_card_name_from_string(card->fname); - } - if (!card->file_as) { - ECardName *name = card->name; - char *strings[3], **stringptr; - char *string; - stringptr = strings; - if (name->family && *name->family) - *(stringptr++) = name->family; - if (name->given && *name->given) - *(stringptr++) = name->given; - *stringptr = NULL; - string = g_strjoinv(", ", strings); - card->file_as = string; - } -} - -static void -e_card_class_init (ECardClass *klass) -{ - int i; - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - klass->attribute_jump_table = g_hash_table_new(g_str_hash, g_str_equal); - - for ( i = 0; i < sizeof(attribute_jump_array) / sizeof(attribute_jump_array[0]); i++ ) { - g_hash_table_insert(klass->attribute_jump_table, attribute_jump_array[i].key, attribute_jump_array[i].function); - } - - gtk_object_add_arg_type ("ECard::file_as", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FILE_AS); - gtk_object_add_arg_type ("ECard::full_name", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FULL_NAME); - gtk_object_add_arg_type ("ECard::name", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_NAME); - gtk_object_add_arg_type ("ECard::address", - GTK_TYPE_OBJECT, GTK_ARG_READABLE, ARG_ADDRESS); - gtk_object_add_arg_type ("ECard::address_label", - GTK_TYPE_OBJECT, GTK_ARG_READABLE, ARG_ADDRESS_LABEL); - gtk_object_add_arg_type ("ECard::phone", - GTK_TYPE_OBJECT, GTK_ARG_READABLE, ARG_PHONE); - gtk_object_add_arg_type ("ECard::email", - GTK_TYPE_OBJECT, GTK_ARG_READABLE, ARG_EMAIL); - gtk_object_add_arg_type ("ECard::birth_date", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_BIRTH_DATE); - gtk_object_add_arg_type ("ECard::url", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_URL); - gtk_object_add_arg_type ("ECard::org", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ORG); - gtk_object_add_arg_type ("ECard::org_unit", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ORG_UNIT); - gtk_object_add_arg_type ("ECard::office", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_OFFICE); - gtk_object_add_arg_type ("ECard::title", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TITLE); - gtk_object_add_arg_type ("ECard::role", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ROLE); - gtk_object_add_arg_type ("ECard::manager", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_MANAGER); - gtk_object_add_arg_type ("ECard::assistant", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ASSISTANT); - gtk_object_add_arg_type ("ECard::nickname", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_NICKNAME); - gtk_object_add_arg_type ("ECard::spouse", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_SPOUSE); - gtk_object_add_arg_type ("ECard::anniversary", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_ANNIVERSARY); - gtk_object_add_arg_type ("ECard::mailer", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_MAILER); - gtk_object_add_arg_type ("ECard::fburl", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FBURL); - gtk_object_add_arg_type ("ECard::note", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_NOTE); - gtk_object_add_arg_type ("ECard::related_contacts", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_RELATED_CONTACTS); - gtk_object_add_arg_type ("ECard::categories", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_CATEGORIES); - gtk_object_add_arg_type ("ECard::category_list", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CATEGORY_LIST); - gtk_object_add_arg_type ("ECard::wants_html", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_WANTS_HTML); - gtk_object_add_arg_type ("ECard::wants_html_set", - GTK_TYPE_BOOL, GTK_ARG_READABLE, ARG_WANTS_HTML); - gtk_object_add_arg_type ("ECard::list", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EVOLUTION_LIST); - gtk_object_add_arg_type ("ECard::list_show_addresses", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EVOLUTION_LIST_SHOW_ADDRESSES); - gtk_object_add_arg_type ("ECard::arbitrary", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_ARBITRARY); - gtk_object_add_arg_type ("ECard::id", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ID); - gtk_object_add_arg_type ("ECard::last_use", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_LAST_USE); - gtk_object_add_arg_type ("ECard::use_score", - GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_USE_SCORE); - - - object_class->destroy = e_card_destroy; - object_class->get_arg = e_card_get_arg; - object_class->set_arg = e_card_set_arg; -} - -ECardPhone * -e_card_phone_new (void) -{ - ECardPhone *newphone = g_new(ECardPhone, 1); - - newphone->number = NULL; - newphone->flags = 0; - - return newphone; -} - -void -e_card_phone_free (ECardPhone *phone) -{ - if ( phone ) { - g_free(phone->number); - - g_free(phone); - } -} - -ECardPhone * -e_card_phone_copy (const ECardPhone *phone) -{ - if ( phone ) { - ECardPhone *phone_copy = g_new(ECardPhone, 1); - phone_copy->number = g_strdup(phone->number); - phone_copy->flags = phone->flags; - return phone_copy; - } else - return NULL; -} - -ECardDeliveryAddress * -e_card_delivery_address_new (void) -{ - ECardDeliveryAddress *newaddr = g_new(ECardDeliveryAddress, 1); - - newaddr->po = NULL; - newaddr->ext = NULL; - newaddr->street = NULL; - newaddr->city = NULL; - newaddr->region = NULL; - newaddr->code = NULL; - newaddr->country = NULL; - newaddr->flags = 0; - - return newaddr; -} - -void -e_card_delivery_address_free (ECardDeliveryAddress *addr) -{ - if ( addr ) { - g_free(addr->po); - g_free(addr->ext); - g_free(addr->street); - g_free(addr->city); - g_free(addr->region); - g_free(addr->code); - g_free(addr->country); - - g_free(addr); - } -} - -ECardDeliveryAddress * -e_card_delivery_address_copy (const ECardDeliveryAddress *addr) -{ - if ( addr ) { - ECardDeliveryAddress *addr_copy = g_new(ECardDeliveryAddress, 1); - addr_copy->po = g_strdup(addr->po ); - addr_copy->ext = g_strdup(addr->ext ); - addr_copy->street = g_strdup(addr->street ); - addr_copy->city = g_strdup(addr->city ); - addr_copy->region = g_strdup(addr->region ); - addr_copy->code = g_strdup(addr->code ); - addr_copy->country = g_strdup(addr->country); - addr_copy->flags = addr->flags; - return addr_copy; - } else - return NULL; -} - -gboolean -e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr) -{ - return (((addr->po == NULL) || (*addr->po == 0)) && - ((addr->ext == NULL) || (*addr->ext == 0)) && - ((addr->street == NULL) || (*addr->street == 0)) && - ((addr->city == NULL) || (*addr->city == 0)) && - ((addr->region == NULL) || (*addr->region == 0)) && - ((addr->code == NULL) || (*addr->code == 0)) && - ((addr->country == NULL) || (*addr->country == 0))); -} - -ECardDeliveryAddress * -e_card_delivery_address_from_label(const ECardAddrLabel *label) -{ - ECardDeliveryAddress *addr = g_new(ECardDeliveryAddress, 1); - EAddressWestern *western = e_address_western_parse (label->data); - - addr->po = g_strdup (western->po_box ); - addr->ext = g_strdup (western->extended ); - addr->street = g_strdup (western->street ); - addr->city = g_strdup (western->locality ); - addr->region = g_strdup (western->region ); - addr->code = g_strdup (western->postal_code); - addr->country = g_strdup (western->country ); - addr->flags = label->flags; - - e_address_western_free(western); - - return addr; -} - -char * -e_card_delivery_address_to_string(const ECardDeliveryAddress *addr) -{ - char *strings[5], **stringptr = strings; - char *line1, *line22, *line2; - char *final; - if (addr->po && *addr->po) - *(stringptr++) = addr->po; - if (addr->street && *addr->street) - *(stringptr++) = addr->street; - *stringptr = NULL; - line1 = g_strjoinv(" ", strings); - stringptr = strings; - if (addr->region && *addr->region) - *(stringptr++) = addr->region; - if (addr->code && *addr->code) - *(stringptr++) = addr->code; - *stringptr = NULL; - line22 = g_strjoinv(" ", strings); - stringptr = strings; - if (addr->city && *addr->city) - *(stringptr++) = addr->city; - if (line22 && *line22) - *(stringptr++) = line22; - *stringptr = NULL; - line2 = g_strjoinv(", ", strings); - stringptr = strings; - if (line1 && *line1) - *(stringptr++) = line1; - if (addr->ext && *addr->ext) - *(stringptr++) = addr->ext; - if (line2 && *line2) - *(stringptr++) = line2; - if (addr->country && *addr->country) - *(stringptr++) = addr->country; - *stringptr = NULL; - final = g_strjoinv("\n", strings); - g_free(line1); - g_free(line22); - g_free(line2); - return final; -} - -ECardAddrLabel * -e_card_delivery_address_to_label (const ECardDeliveryAddress *addr) -{ - ECardAddrLabel *label; - label = e_card_address_label_new(); - label->flags = addr->flags; - label->data = e_card_delivery_address_to_string(addr); - - return label; -} - -ECardAddrLabel * -e_card_address_label_new (void) -{ - ECardAddrLabel *newaddr = g_new(ECardAddrLabel, 1); - - newaddr->data = NULL; - newaddr->flags = 0; - - return newaddr; -} - -void -e_card_address_label_free (ECardAddrLabel *addr) -{ - if ( addr ) { - g_free(addr->data); - - g_free(addr); - } -} - -ECardAddrLabel * -e_card_address_label_copy (const ECardAddrLabel *addr) -{ - if ( addr ) { - ECardAddrLabel *addr_copy = g_new(ECardAddrLabel, 1); - addr_copy->data = g_strdup(addr->data); - addr_copy->flags = addr->flags; - return addr_copy; - } else - return NULL; -} - -ECardName *e_card_name_new(void) -{ - ECardName *newname = g_new(ECardName, 1); - - newname->prefix = NULL; - newname->given = NULL; - newname->additional = NULL; - newname->family = NULL; - newname->suffix = NULL; - - return newname; -} - -void -e_card_name_free(ECardName *name) -{ - if (name) { - if ( name->prefix ) - g_free(name->prefix); - if ( name->given ) - g_free(name->given); - if ( name->additional ) - g_free(name->additional); - if ( name->family ) - g_free(name->family); - if ( name->suffix ) - g_free(name->suffix); - g_free ( name ); - } -} - -ECardName * -e_card_name_copy(const ECardName *name) -{ - if (name) { - ECardName *newname = g_new(ECardName, 1); - - newname->prefix = g_strdup(name->prefix); - newname->given = g_strdup(name->given); - newname->additional = g_strdup(name->additional); - newname->family = g_strdup(name->family); - newname->suffix = g_strdup(name->suffix); - - return newname; - } else - return NULL; -} - -char * -e_card_name_to_string(const ECardName *name) -{ - char *strings[6], **stringptr = strings; - - g_return_val_if_fail (name != NULL, NULL); - - if (name->prefix && *name->prefix) - *(stringptr++) = name->prefix; - if (name->given && *name->given) - *(stringptr++) = name->given; - if (name->additional && *name->additional) - *(stringptr++) = name->additional; - if (name->family && *name->family) - *(stringptr++) = name->family; - if (name->suffix && *name->suffix) - *(stringptr++) = name->suffix; - *stringptr = NULL; - return g_strjoinv(" ", strings); -} - -ECardName * -e_card_name_from_string(const char *full_name) -{ - ECardName *name = g_new(ECardName, 1); - ENameWestern *western = e_name_western_parse (full_name); - - name->prefix = g_strdup (western->prefix); - name->given = g_strdup (western->first ); - name->additional = g_strdup (western->middle); - name->family = g_strdup (western->last ); - name->suffix = g_strdup (western->suffix); - - e_name_western_free(western); - - return name; -} - - -/* This *so* doesn't belong here... at least not implemented in a - sucky way like this. But by getting it in here now, I can fix it - up w/o adding a new feature when we are in feature freeze. :-) */ - -/* This is very Anglocentric. Maybe it should be by locale? */ -static gchar *name_synonyms[][2] = { - { "Jon", "John" }, /* Ah, the hacker's perogative */ - { "Jon", "Jonathan" }, - { "Daniel", "Dan" }, - { "Joseph", "Joe" }, - { "Robert", "Rob" }, - { "Robert", "Bob" }, - { "Richard", "Rich" }, - { "Richard", "Dick" }, - { "William", "Will" }, - { "William", "Bill" }, - { "Anthony", "Tony" }, - { "Steven", "Steve" }, - { "Michael", "Mike" }, - { "Douglas", "Doug" }, - { "Sidney", "Sid" }, - { "Eric", "Erik" }, - { "Chris", "Christopher" }, - { "Chris", "Christine" }, - { "Chris", "Christy" }, - { "Elizabeth", "Liz" }, - { "Jeff", "Geoff" }, - { "Jeff", "Jeffrey" }, - { "Jeff", "Geoffrey" }, - { "Jim", "James" }, - { "Abigal", "Abby" }, - { "Amanda", "Amy" }, - { "Amanda", "Manda" }, - { "Di", "Diana" }, - { "Di", "Diane" }, - { "Maxine", "Max" }, - { "Rebecca", "Becca" }, - { "Rebecca", "Becky" }, - { "Jennifer", "Jen" }, - { "Jennifer", "Jenny" }, - /* We could go on and on... */ - { NULL, NULL } -}; - -static gboolean -name_fragment_match (const gchar *a, const gchar *b) -{ - gint i; - gboolean nickname_match = FALSE; - - if (!g_strcasecmp (a, b)) - return TRUE; - - /* Check for nicknames. Yes, the linear search blows. */ - for (i=0; name_synonyms[i][0]; ++i) { - if (!g_strcasecmp (name_synonyms[i][1], a)) { - a = name_synonyms[i][0]; - nickname_match = TRUE; - break; - } - } - - for (i=0; name_synonyms[i][0]; ++i) { - if (!g_strcasecmp (name_synonyms[i][1], b)) { - b = name_synonyms[i][0]; - nickname_match = TRUE; - break; - } - } - - return nickname_match && !g_strcasecmp (a, b); -} - -gboolean -e_card_name_match_string (const ECardName *name, const gchar *str) -{ - gchar *name_str; - gchar **strv, **namev; - gint i, j, match_count; - - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (str != NULL, FALSE); - - strv = g_strsplit (str, " ", 0); - for (i=0; strv[i]; ++i) - g_strstrip (strv[i]); - - name_str = e_card_name_to_string (name); - namev = g_strsplit (name_str, " ", 0); - for (i=0; namev[i]; ++i) - g_strstrip (namev[i]); - - match_count = 0; - i = j = 0; - - while (strv[i] && namev[j]) { - gint k; - gboolean first_match = FALSE, second_match = FALSE; - - for (k=0; strv[i + k]; ++k) { - if (name_fragment_match (strv[i + k], namev[j])) { - first_match = TRUE; - break; - } - } - - if (!first_match) { - for (k=0; namev[j + k]; ++k) { - if (name_fragment_match (strv[i], namev[j + k])) { - second_match = TRUE; - break; - } - } - } - - if (! (first_match || second_match)) - break; - - ++match_count; - - if (first_match) { - i += k + 1; - ++j; - } else { - ++i; - j += k + 1; - } - } - - /* This rule could be made more precise. - As it is, it will say that "Joe Smith" will match the name - "Joe Allen Smith" (which is good), but "de Icaza" will match - either "Miguel de Icaza" as well as Miguel's shiftless - brother "Roger de Icaza". In this sort of a case, the match - threshold should go up to 3. */ - - g_strfreev (strv); - g_strfreev (namev); - g_free (name_str); - - return match_count >= 2; -} - -ECardArbitrary * -e_card_arbitrary_new(void) -{ - ECardArbitrary *arbitrary = g_new(ECardArbitrary, 1); - arbitrary->key = NULL; - arbitrary->type = NULL; - arbitrary->value = NULL; - return arbitrary; -} - -ECardArbitrary * -e_card_arbitrary_copy(const ECardArbitrary *arbitrary) -{ - if (arbitrary) { - ECardArbitrary *arb_copy = g_new(ECardArbitrary, 1); - arb_copy->key = g_strdup(arbitrary->key); - arb_copy->type = g_strdup(arbitrary->type); - arb_copy->value = g_strdup(arbitrary->value); - return arb_copy; - } else - return NULL; -} - -void -e_card_arbitrary_free(ECardArbitrary *arbitrary) -{ - if (arbitrary) { - g_free(arbitrary->key); - g_free(arbitrary->type); - g_free(arbitrary->value); - } - g_free(arbitrary); -} - -/* EMail matching */ -static gboolean -e_card_email_match_single_string (const gchar *a, const gchar *b) -{ - const gchar *xa = NULL, *xb = NULL; - gboolean match = TRUE; - - for (xa=a; *xa && *xa != '@'; ++xa); - for (xb=b; *xb && *xb != '@'; ++xb); - - if (xa-a != xb-b || *xa != *xb || g_strncasecmp (a, b, xa-a)) - return FALSE; - - if (*xa == '\0') - return TRUE; - - /* Find the end of the string, then walk through backwards comparing. - This is so that we'll match joe@foobar.com and joe@mail.foobar.com. - */ - while (*xa) - ++xa; - while (*xb) - ++xb; - - while (match && *xa != '@' && *xb != '@') { - match = (*xa == *xb); - --xa; - --xb; - } - - match = match && ((*xa == *xb) || (*xa == '.') || (*xb == '.')); - - return match; -} - -gboolean -e_card_email_match_string (const ECard *card, const gchar *str) -{ - EIterator *iter; - - g_return_val_if_fail (card && E_IS_CARD (card), FALSE); - g_return_val_if_fail (str != NULL, FALSE); - - iter = e_list_get_iterator (card->email); - for (e_iterator_reset (iter); e_iterator_is_valid (iter); e_iterator_next (iter)) { - if (e_card_email_match_single_string (e_iterator_get (iter), str)) - return TRUE; - } - gtk_object_unref (GTK_OBJECT (iter)); - - return FALSE; -} - -/* - * ECard lifecycle management and vCard loading/saving. - */ - -static void -e_card_destroy (GtkObject *object) -{ - ECard *card = E_CARD(object); - g_free(card->id); - if (card->book) - gtk_object_unref (GTK_OBJECT (card->book)); - g_free(card->uri); - g_free(card->file_as); - g_free(card->fname); - if ( card->name ) - e_card_name_free(card->name); - g_free(card->bday); - - g_free(card->url); - g_free(card->org); - g_free(card->org_unit); - g_free(card->office); - g_free(card->title); - g_free(card->role); - g_free(card->manager); - g_free(card->assistant); - g_free(card->nickname); - g_free(card->spouse); - g_free(card->anniversary); - g_free(card->fburl); - g_free(card->note); - g_free(card->related_contacts); - - if (card->categories) - gtk_object_unref(GTK_OBJECT(card->categories)); - if (card->email) - gtk_object_unref(GTK_OBJECT(card->email)); - if (card->phone) - gtk_object_unref(GTK_OBJECT(card->phone)); - if (card->address) - gtk_object_unref(GTK_OBJECT(card->address)); - if (card->address_label) - gtk_object_unref(GTK_OBJECT(card->address_label)); -} - - -/* Set_arg handler for the card */ -static void -e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECard *card; - - card = E_CARD (object); - - switch (arg_id) { - case ARG_FILE_AS: - g_free(card->file_as); - card->file_as = g_strdup(GTK_VALUE_STRING(*arg)); - if (card->file_as == NULL) - card->file_as = g_strdup(""); - break; - case ARG_FULL_NAME: - g_free(card->fname); - card->fname = g_strdup(GTK_VALUE_STRING(*arg)); - if (card->name) - e_card_name_free (card->name); - if (card->fname == NULL) - card->fname = g_strdup(""); - card->name = e_card_name_from_string (card->fname); - break; - case ARG_NAME: - if ( card->name ) - e_card_name_free(card->name); - card->name = e_card_name_copy(GTK_VALUE_POINTER(*arg)); - if (card->name == NULL) - card->name = e_card_name_new(); - if (card->fname == NULL) { - card->fname = e_card_name_to_string(card->name); - } - if (card->file_as == NULL) { - ECardName *name = card->name; - char *strings[3], **stringptr; - char *string; - stringptr = strings; - if (name->family && *name->family) - *(stringptr++) = name->family; - if (name->given && *name->given) - *(stringptr++) = name->given; - *stringptr = NULL; - string = g_strjoinv(", ", strings); - card->file_as = string; - } - break; - case ARG_CATEGORIES: - if (card->categories) - gtk_object_unref(GTK_OBJECT(card->categories)); - card->categories = NULL; - if (GTK_VALUE_STRING(*arg)) - do_parse_categories(card, GTK_VALUE_STRING(*arg)); - break; - case ARG_CATEGORY_LIST: - if (card->categories) - gtk_object_unref(GTK_OBJECT(card->categories)); - card->categories = E_LIST(GTK_VALUE_OBJECT(*arg)); - if (card->categories) - gtk_object_ref(GTK_OBJECT(card->categories)); - break; - case ARG_BIRTH_DATE: - g_free(card->bday); - if (GTK_VALUE_POINTER (*arg)) { - card->bday = g_new (ECardDate, 1); - memcpy (card->bday, GTK_VALUE_POINTER (*arg), sizeof (ECardDate)); - } else { - card->bday = NULL; - } - break; - case ARG_URL: - g_free(card->url); - card->url = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_ORG: - g_free(card->org); - card->org = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_ORG_UNIT: - g_free(card->org_unit); - card->org_unit = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_OFFICE: - g_free(card->office); - card->office = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_TITLE: - g_free(card->title); - card->title = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_ROLE: - g_free(card->role); - card->role = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_MANAGER: - g_free(card->manager); - card->manager = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_ASSISTANT: - g_free(card->assistant); - card->assistant = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_NICKNAME: - g_free(card->nickname); - card->nickname = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_SPOUSE: - g_free(card->spouse); - card->spouse = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_ANNIVERSARY: - g_free(card->anniversary); - if (GTK_VALUE_POINTER (*arg)) { - card->anniversary = g_new (ECardDate, 1); - memcpy (card->anniversary, GTK_VALUE_POINTER (*arg), sizeof (ECardDate)); - } else { - card->anniversary = NULL; - } - break; - case ARG_MAILER: - g_free(card->mailer); - card->mailer = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_FBURL: - g_free(card->fburl); - card->fburl = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_NOTE: - g_free (card->note); - card->note = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_RELATED_CONTACTS: - g_free (card->related_contacts); - card->related_contacts = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_WANTS_HTML: - card->wants_html = GTK_VALUE_BOOL(*arg); - card->wants_html_set = TRUE; - break; - case ARG_ARBITRARY: - if (card->arbitrary) - gtk_object_unref(GTK_OBJECT(card->arbitrary)); - card->arbitrary = E_LIST(GTK_VALUE_OBJECT(*arg)); - if (card->arbitrary) - gtk_object_ref(GTK_OBJECT(card->arbitrary)); - break; - case ARG_ID: - g_free(card->id); - card->id = g_strdup(GTK_VALUE_STRING(*arg)); - break; - case ARG_LAST_USE: - g_free(card->last_use); - if (GTK_VALUE_POINTER (*arg)) { - card->last_use = g_new (ECardDate, 1); - memcpy (card->last_use, GTK_VALUE_POINTER (*arg), sizeof (ECardDate)); - } else { - card->last_use = NULL; - } - break; - case ARG_USE_SCORE: - card->raw_use_score = GTK_VALUE_FLOAT(*arg); - break; - case ARG_EVOLUTION_LIST: - card->list = GTK_VALUE_BOOL(*arg); - break; - case ARG_EVOLUTION_LIST_SHOW_ADDRESSES: - card->list_show_addresses = GTK_VALUE_BOOL(*arg); - break; - default: - return; - } -} - -/* Get_arg handler for the card */ -static void -e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECard *card; - - card = E_CARD (object); - - switch (arg_id) { - case ARG_FILE_AS: - GTK_VALUE_STRING (*arg) = card->file_as; - break; - case ARG_FULL_NAME: - GTK_VALUE_STRING (*arg) = card->fname; - break; - case ARG_NAME: - GTK_VALUE_POINTER(*arg) = card->name; - break; - case ARG_ADDRESS: - if (!card->address) - card->address = e_list_new((EListCopyFunc) e_card_delivery_address_copy, - (EListFreeFunc) e_card_delivery_address_free, - NULL); - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->address); - break; - case ARG_ADDRESS_LABEL: - if (!card->address_label) - card->address_label = e_list_new((EListCopyFunc) e_card_address_label_copy, - (EListFreeFunc) e_card_address_label_free, - NULL); - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->address_label); - break; - case ARG_PHONE: - if (!card->phone) - card->phone = e_list_new((EListCopyFunc) e_card_phone_copy, - (EListFreeFunc) e_card_phone_free, - NULL); - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->phone); - break; - case ARG_EMAIL: - if (!card->email) - card->email = e_list_new((EListCopyFunc) g_strdup, - (EListFreeFunc) g_free, - NULL); - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->email); - break; - case ARG_CATEGORIES: - { - int i; - char ** strs; - int length; - EIterator *iterator; - if (!card->categories) - card->categories = e_list_new((EListCopyFunc) g_strdup, - (EListFreeFunc) g_free, - NULL); - length = e_list_length(card->categories); - strs = g_new(char *, length + 1); - for (iterator = e_list_get_iterator(card->categories), i = 0; e_iterator_is_valid(iterator); e_iterator_next(iterator), i++) { - strs[i] = (char *)e_iterator_get(iterator); - } - strs[i] = 0; - GTK_VALUE_STRING(*arg) = g_strjoinv(", ", strs); - g_free(strs); - } - break; - case ARG_CATEGORY_LIST: - if (!card->categories) - card->categories = e_list_new((EListCopyFunc) g_strdup, - (EListFreeFunc) g_free, - NULL); - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->categories); - break; - case ARG_BIRTH_DATE: - GTK_VALUE_POINTER(*arg) = card->bday; - break; - case ARG_URL: - GTK_VALUE_STRING(*arg) = card->url; - break; - case ARG_ORG: - GTK_VALUE_STRING(*arg) = card->org; - break; - case ARG_ORG_UNIT: - GTK_VALUE_STRING(*arg) = card->org_unit; - break; - case ARG_OFFICE: - GTK_VALUE_STRING(*arg) = card->office; - break; - case ARG_TITLE: - GTK_VALUE_STRING(*arg) = card->title; - break; - case ARG_ROLE: - GTK_VALUE_STRING(*arg) = card->role; - break; - case ARG_MANAGER: - GTK_VALUE_STRING(*arg) = card->manager; - break; - case ARG_ASSISTANT: - GTK_VALUE_STRING(*arg) = card->assistant; - break; - case ARG_NICKNAME: - GTK_VALUE_STRING(*arg) = card->nickname; - break; - case ARG_SPOUSE: - GTK_VALUE_STRING(*arg) = card->spouse; - break; - case ARG_ANNIVERSARY: - GTK_VALUE_POINTER(*arg) = card->anniversary; - break; - case ARG_MAILER: - GTK_VALUE_STRING(*arg) = card->mailer; - break; - case ARG_FBURL: - GTK_VALUE_STRING(*arg) = card->fburl; - break; - case ARG_NOTE: - GTK_VALUE_STRING(*arg) = card->note; - break; - case ARG_RELATED_CONTACTS: - GTK_VALUE_STRING(*arg) = card->related_contacts; - break; - case ARG_WANTS_HTML: - GTK_VALUE_BOOL(*arg) = card->wants_html; - break; - case ARG_WANTS_HTML_SET: - GTK_VALUE_BOOL(*arg) = card->wants_html_set; - break; - case ARG_ARBITRARY: - if (!card->arbitrary) - card->arbitrary = e_list_new((EListCopyFunc) e_card_arbitrary_copy, - (EListFreeFunc) e_card_arbitrary_free, - NULL); - - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->arbitrary); - break; - case ARG_ID: - GTK_VALUE_STRING(*arg) = card->id; - break; - case ARG_LAST_USE: - GTK_VALUE_POINTER(*arg) = card->last_use; - break; - - case ARG_USE_SCORE: - GTK_VALUE_FLOAT(*arg) = e_card_get_use_score (card); - break; - case ARG_EVOLUTION_LIST: - GTK_VALUE_BOOL(*arg) = card->list; - break; - case ARG_EVOLUTION_LIST_SHOW_ADDRESSES: - GTK_VALUE_BOOL(*arg) = card->list_show_addresses; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - - -/** - * e_card_init: - */ -static void -e_card_init (ECard *card) -{ - card->id = g_strdup(""); - - card->file_as = NULL; - card->fname = NULL; - card->name = NULL; - card->bday = NULL; - card->email = NULL; - card->phone = NULL; - card->address = NULL; - card->address_label = NULL; - card->url = NULL; - card->org = NULL; - card->org_unit = NULL; - card->office = NULL; - card->title = NULL; - card->role = NULL; - card->manager = NULL; - card->assistant = NULL; - card->nickname = NULL; - card->spouse = NULL; - card->anniversary = NULL; - card->mailer = NULL; - card->fburl = NULL; - card->note = NULL; - card->related_contacts = NULL; - card->categories = NULL; - card->wants_html = FALSE; - card->wants_html_set = FALSE; - card->list = FALSE; - card->list_show_addresses = FALSE; - card->arbitrary = NULL; - card->last_use = NULL; - card->raw_use_score = 0; -#if 0 - - c = g_new0 (ECard, 1); - - c->fname = - c->mailer = - c->role = - c->comment = - c->categories = - c->uid = e_card_prop_str_empty (); - - c->photo.type = PHOTO_JPEG; - c->logo.type = PHOTO_JPEG; - c->rev.utc = -1; - c->sound.type = SOUND_PHONETIC; - c->key.type = KEY_PGP; - - c->categories.prop.encod = ENC_QUOTED_PRINTABLE; - c->comment.prop.encod = ENC_QUOTED_PRINTABLE; - - c->name.prop = c->photo.prop = c->bday.prop = c->timezn.prop = - c->geopos.prop = c->logo.prop = c->org.prop = c->rev.prop = - c->sound.prop = c->key.prop = c->deladdr.prop = c->dellabel.prop = - c->phone.prop = c->email.prop = c->xtension.prop = c->prop = e_card_prop_empty (); - - c->prop.type = PROP_CARD; - c->fname.prop.type = PROP_FNAME; - c->name.prop.type = PROP_NAME; - c->photo.prop.type = PROP_PHOTO; - c->bday.prop.type = PROP_BDAY; - - c->deladdr.prop.type = PROP_DELADDR_LIST; - c->dellabel.prop.type = PROP_DELLABEL_LIST; - c->phone.prop.type = PROP_PHONE_LIST; - c->email.prop.type = PROP_EMAIL_LIST; - c->xtension.prop.type = PROP_XTENSION_LIST; - c->mailer.prop.type = PROP_MAILER; - c->timezn.prop.type = PROP_TIMEZN; - c->geopos.prop.type = PROP_GEOPOS; - c->role.prop.type = PROP_ROLE; - c->logo.prop.type = PROP_LOGO; - c->org.prop.type = PROP_ORG; - c->categories.prop.type = PROP_CATEGORIES; - c->comment.prop.type = PROP_COMMENT; - c->rev.prop.type = PROP_REV; - c->sound.prop.type = PROP_SOUND; - c->uid.prop.type = PROP_UID; - c->key.prop.type = PROP_KEY; - - return c; -#endif -} - -GList * -e_card_load_cards_from_file(const char *filename) -{ - VObject *vobj = Parse_MIME_FromFileName((char *) filename); - GList *list = NULL; - while(vobj) { - VObject *next; - ECard *card = E_CARD(gtk_type_new(e_card_get_type())); - parse(card, vobj); - next = nextVObjectInList(vobj); - cleanVObject(vobj); - vobj = next; - list = g_list_prepend(list, card); - } - list = g_list_reverse(list); - return list; -} - -GList * -e_card_load_cards_from_string(const char *str) -{ - VObject *vobj = Parse_MIME(str, strlen (str)); - GList *list = NULL; - while(vobj) { - VObject *next; - ECard *card = E_CARD(gtk_type_new(e_card_get_type())); - parse(card, vobj); - next = nextVObjectInList(vobj); - cleanVObject(vobj); - vobj = next; - list = g_list_prepend(list, card); - } - list = g_list_reverse(list); - return list; -} - -void -e_card_free_empty_lists (ECard *card) -{ - if (card->address && e_list_length (card->address) == 0) { - gtk_object_unref (GTK_OBJECT (card->address)); - card->address = NULL; - } - - if (card->address_label && e_list_length (card->address_label) == 0) { - gtk_object_unref (GTK_OBJECT (card->address_label)); - card->address_label = NULL; - } - - if (card->phone && e_list_length (card->phone) == 0) { - gtk_object_unref (GTK_OBJECT (card->phone)); - card->phone = NULL; - } - - if (card->email && e_list_length (card->email) == 0) { - gtk_object_unref (GTK_OBJECT (card->email)); - card->email = NULL; - } - - if (card->categories && e_list_length (card->categories) == 0) { - gtk_object_unref (GTK_OBJECT (card->categories)); - card->categories = NULL; - } - - if (card->arbitrary && e_list_length (card->arbitrary) == 0) { - gtk_object_unref (GTK_OBJECT (card->arbitrary)); - card->arbitrary = NULL; - } -} - -static void -assign_string(VObject *vobj, char **string) -{ - int type = vObjectValueType(vobj); - char *str; - - switch(type) { - case VCVT_STRINGZ: - *string = g_strdup (vObjectStringZValue(vobj)); - break; - case VCVT_USTRINGZ: - str = (vObjectValueType (vobj) ? fakeCString (vObjectUStringZValue (vobj)) : calloc(1, 1)); - *string = g_strdup(str); - free(str); - break; - default: - *string = g_strdup(""); - break; - } -} - -#if 0 -static void -e_card_str_free (CardStrProperty *sp) -{ - g_free (sp->str); - - e_card_prop_free (sp->prop); -} - -static void -e_card_photo_free (CardPhoto *photo) -{ - g_free (photo->data); - - e_card_prop_free (photo->prop); -} - -/** - * e_card_free: - */ -void -e_card_free (ECard *card) -{ - GList *l; - - g_return_if_fail (card != NULL); - - e_card_name_free (& card->name); - e_card_str_free (& card->fname); - - e_card_photo_free (card->photo); - - e_card_logo_free (card->logo); - e_card_org_free (card->org); - e_card_key_free (card->key); - e_card_sound_free (card->sound); - - e_card_prop_str_free (& card->mailer); - e_card_prop_str_free (& card->role); - e_card_prop_str_free (& card->categories); - e_card_prop_str_free (& card->comment); - e_card_prop_str_free (& card->uid); - - /* address is a little more complicated */ - card_prop_free (card->deladdr.prop); - while ((l = card->deladdr.l)) { - - e_card_deladdr_free ((CardDelAddr *) l->data); - - card->deladdr.l = g_list_remove_link (card->deladdr.l, l); - g_list_free (l); - } - - g_free (card); -} - -typedef struct -{ - char c; - int id; - - GList *sons; -} tree; - -extern CardProperty -e_card_prop_empty (void) -{ - CardProperty prop; - - prop.used = FALSE; - - prop.type = PROP_NONE; - prop.encod = ENC_7BIT; - prop.value = VAL_INLINE; - prop.charset = NULL; - prop.lang = NULL; - prop.grp = NULL; - prop.xtension = NULL; - - prop.user_data = NULL; - - return prop; -} - -static CardStrProperty -e_card_prop_str_empty (void) -{ - CardStrProperty strprop; - - strprop.prop = card_prop_empty (); - strprop.str = NULL; - - return strprop; -} - -/* Intended to check asserts. */ -extern int card_check_prop (ECardProperty prop) -{ - if (((prop.used == FALSE) || (prop.used == TRUE)) && - ((prop.type >= PROP_NONE) && (prop.type <= PROP_LAST)) && - ((prop.encod >= ENC_NONE) && (prop.encod <= ENC_LAST)) && - ((prop.value >= VAL_NONE) && (prop.value <= VAL_LAST))) - return TRUE; - - return FALSE; -} - -extern void -card_prop_free (CardProperty prop) -{ - GList *l; - - g_free (prop.charset); - g_free (prop.lang); - - for (l = prop.xtension; l; l = l->next) { - CardXAttribute *xa = (CardXAttribute *) l->data; - g_free (xa->name); - g_free (xa->data); - } - - g_list_free (l); - - prop.used = FALSE; -} - -e_card_deladdr_free (ECardDelAddr *c) -{ - card_prop_free (c->prop); - - g_free (p->pobox); - g_free (p->ext); - g_free (p->street); - g_free (p->city); - g_free (p->region); - g_free (p->code); - g_free (p->country); -} - -void -card_free (Card *crd) -{ -} - -static tree * -new_tree (char c, int id) -{ - tree *t; - - t = malloc (sizeof (tree)); - t->c = c; - t->id = id; - t->sons = NULL; - - return t; -} - -static void -add_branch (tree *t, char *str, int id) -{ - tree *tmp; - char *end; - - end = str + strlen (str) + 1; - - while (str != end) { - tmp = new_tree (*str, id); - t->sons = g_list_append (t->sons, (gpointer) tmp); - t = tmp; - - str ++; - } -} - -static tree * -add_to_tree (tree *t, struct pair p) -{ - GList *node; - char *c, *end; - tree *tmp; - - c = p.str; - end = c + strlen (c) + 1; - tmp = t; - - while (c != end) { - for (node = tmp->sons; node; node = node->next) - if (((tree *) node->data)->c == *c) { - break; - } - - if (node) { - tmp = (tree *) node->data; - tmp->id = 0; - c++; - } - else { - add_branch (tmp, c, p.id); - break; - } - } - - return t; -} - -static tree * -create_search_tree (void) -{ - tree *t; - int i; - - t = new_tree (0, 0); - for (i = 0; prop_lookup[i].str; i++) - t = add_to_tree (t, prop_lookup[i]); - - return t; -} - -static int -card_lookup_name (const char *c) -{ - static tree *search_tree = NULL; - GList *node; - tree *tmp; - const char *end; - - if (!search_tree) - search_tree = create_search_tree (); - - tmp = search_tree; - end = c + strlen (c) + 1; - - while (tmp->id == 0 && c != end) { - for (node = tmp->sons; node; node = node->next) - if (((tree *) node->data)->c == *c) { - break; - } - - if (node) { - tmp = (tree *) node->data; - c++; - } - else - return 0; - } - - return tmp->id; -} - -static enum PhotoType -get_photo_type (VObject *o) -{ - VObject *vo; - int i; - - for (i = 0; photo_pairs[i].str; i++) - if (has (o, photo_pairs[i].str)) - return photo_pairs[i].id; - - g_warning ("? < No PhotoType for Photo property. Falling back to JPEG."); - return PHOTO_JPEG; -} - -static CardProperty -get_CardProperty (VObject *o) -{ - VObjectIterator i; - CardProperty prop; - - prop = card_prop_empty (); - prop.used = TRUE; - - initPropIterator (&i, o); - while (moreIteration (&i)) { - VObject *vo = nextVObject (&i); - const char *n = vObjectName (vo); - int propid; - - propid = card_lookup_name (n); - - switch (propid) { - - case PROP_VALUE: - - if (has (vo, VCContentIDProp)) - prop.value = VAL_CID; - break; - - case PROP_ENCODING: - if (has (vo, VCQuotedPrintableProp)) - prop.encod = ENC_QUOTED_PRINTABLE; - else if (has (vo, VC8bitProp)) - prop.encod = ENC_8BIT; - else if (has (vo, VCBase64Prop)) - prop.encod = ENC_BASE64; - break; - - case PROP_QUOTED_PRINTABLE: - prop.encod = ENC_QUOTED_PRINTABLE; - break; - - case PROP_8BIT: - prop.encod = ENC_8BIT; - break; - - case PROP_BASE64: - prop.encod = ENC_BASE64; - break; - - case PROP_LANG: - if (vObjectValueType (vo)) { - prop.lang = - g_strdup (vObjectStringZValue (vo)); - } else - g_warning ("? < No value for LANG attribute."); - break; - - case PROP_CHARSET: - if (vObjectValueType (vo)) { - prop.charset = - g_strdup (vObjectStringZValue (vo)); - g_warning (prop.charset); - } else - g_warning ("? < No value for CHARSET attribute."); - break; - default: - { - CardXAttribute *c; - - c = malloc (sizeof (CardXAttribute)); - c->name = g_strdup (n); - - if (vObjectValueType (vo)) - c->data = - g_strdup (vObjectStringZValue (vo)); - else - c->data = NULL; - - prop.xtension = - g_list_append (prop.xtension, c); - } - } - } - - return prop; -} - -static gboolean -e_card_prop_has (VObject *o, - const char *id) -{ - g_assert (o != NULL); - g_assert (id != NULL); - - if (isAPropertyOf (o, id) == NULL) - return FALSE; - - return TRUE; -} - -static const char * -e_card_prop_get_str (VObject *o, - const char *id) -{ - VObject *strobj; - - g_assert (o != NULL); - g_assert (id != NULL); - - strobj = isAPropertyOf (o, id); - - if (strobj == NULL) - return g_strdup (""); - - if (vObjectValueType (strobj) != NULL) { - char *str; - char *g_str; - - str = fakeCString (vObjectStringZValue (strobj)); - g_str = g_strdup (str); - free (str); - - return g_str; - } - - return g_strdup (""); -} - -static ECardName * -e_card_get_name (VObject *o) -{ - CardName *name; - VObject *vo; - char *the_str; - - name = g_new0 (ECardName, 1); - - name->family = e_card_prop_get_substr (o, VCFamilyNameProp); - name->given = e_card_prop_get_substr (o, VCGivenNameProp); - name->additional = e_card_prop_get_substr (o, VCAdditionalNamesProp); - name->prefix = e_card_prop_get_substr (o, VCNamePrefixesProp); - name->suffix = e_card_prop_get_substr (o, VCNameSuffixesProp); - - return name; -} - -static CardDelLabel * -get_CardDelLabel (VObject *o) -{ - CardDelLabel *dellabel; - char *the_str; - - dellabel = malloc (sizeof (CardDelLabel)); - - dellabel->type = get_addr_type (o); - dellabel->data = g_strdup (str_val (o)); - - free (the_str); - return dellabel; -} - -static CardPhone * -get_CardPhone (VObject *o) -{ - CardPhone *ret; - char *the_str; - - ret = malloc (sizeof (CardPhone)); - ret->type = get_phone_type (o); - ret->data = g_strdup (str_val (o)); - - free (the_str); - - return ret; -} - -static CardEMail * -get_CardEMail (VObject *o) -{ - CardEMail *ret; - char *the_str; - - ret = malloc (sizeof (CardEMail)); - ret->type = get_email_type (o); - ret->data = g_strdup (str_val (o)); - - free (the_str); - - return ret; -} - -static CardTimeZone -strtoCardTimeZone (char *str) -{ - char s[3]; - CardTimeZone tz; - - if (*str == '-') { - tz.sign = -1; - str++; - } else - tz.sign = 1; - - tz.hours = 0; - tz.mins = 0; - - s[2] = 0; - if (strlen (str) > 2) { - s[0] = str[0]; - s[1] = str[1]; - tz.hours = atoi (s); - } else { - g_warning ("? < TimeZone value is too short."); - return tz; - } - - str += 2; - if (*str == ':') - str++; - - if (strlen (str) >= 2) { - s[0] = str[0]; - s[1] = str[1]; - tz.mins = atoi (s); - } else { - g_warning ("? < TimeZone value is too short."); - return tz; - } - - if (strlen (str) > 3) - g_warning ("? < TimeZone value is too long."); - - return tz; -} - -static CardGeoPos -strtoCardGeoPos (char *str) -{ - CardGeoPos gp; - char *s; - - gp.lon = 0; - gp.lat = 0; - - s = strchr (str, ','); - - if (! s) { - g_warning ("? < Bad format for GeoPos property."); - return gp; - } - - *s = 0; - s++; - - gp.lon = atof (str); - gp.lat = atof (s); - - return gp; -} - -static CardOrg * -e_card_vobject_to_org (VObject *o) -{ - VObject *vo; - char *the_str; - CardOrg *org; - - org = g_new0 (CardOrg, 1); - - if (has (o, VCOrgNameProp)) { - org.name = g_strdup (str_val (vo)); - free (the_str); - } - if (has (o, VCOrgUnitProp)) { - org.unit1 = g_strdup (str_val (vo)); - free (the_str); - } - if (has (o, VCOrgUnit2Prop)) { - org.unit2 = g_strdup (str_val (vo)); - free (the_str); - } - if (has (o, VCOrgUnit3Prop)) { - org.unit3 = g_strdup (str_val (vo)); - free (the_str); - } - if (has (o, VCOrgUnit4Prop)) { - org.unit4 = g_strdup (str_val (vo)); - free (the_str); - } - - return org; -} - -static CardXProperty * -get_XProp (VObject *o) -{ - char *the_str; - CardXProperty *ret; - - ret = malloc (sizeof (CardXProperty)); - ret->name = g_strdup (vObjectName (o)); - ret->data = g_strdup (str_val (o)); - free (the_str); - - return ret; -} - -static CardRev -strtoCardRev (char *str) -{ - char s[3], *t, *ss; - int len, i; - CardRev rev; - - rev.utc = 0; - len = strlen (str); - - if (str[len] == 'Z') { /* Is it UTC? */ - rev.utc = 1; - str[len] = 0; - } - - s[2] = 0; - t = strchr (str, 'T'); - if (t) { /* Take the Time */ - *t = 0; - t++; - if (strlen (t) > 2) { - s[0] = t[0]; - s[1] = t[1]; - rev.tm.tm_hour = atoi (s); - } else { - g_warning ("? < Rev value is too short."); - return rev; - } - - t += 2; - if (*t == ':') /* Ignore ':' separator */ - t++; - - if (strlen (t) > 2) { - s[0] = t[0]; - s[1] = t[1]; - rev.tm.tm_min = atoi (s); - } else { - g_warning ("? < Rev value is too short."); - return rev; - } - - t += 2; - if (*t == ':') - t++; - - if (strlen (t) > 2) { - s[0] = t[0]; - s[1] = t[1]; - rev.tm.tm_sec = atoi (s); - } else { - g_warning ("? < Rev value is too short."); - return rev; - } - - if (strlen (str) > 3) - g_warning ("? < Rev value is too long."); - - } else { - g_warning ("? < No time value for Rev property."); - } - - /* Now the date (the part before the T) */ - - if (strchr (str, '-')) { /* extended iso 8601 */ - for (ss = strtok (str, "-"), i = 0; ss; - ss = strtok (NULL, "-"), i++) - switch (i) { - case 0: - rev.tm.tm_year = atoi (ss); - break; - case 1: - rev.tm.tm_mon = atoi (ss); - break; - case 2: - rev.tm.tm_mday = atoi (ss); - break; - default: - g_warning ("? < Too many values for Rev property."); - } - - if (i < 2) - g_warning ("? < Too few values for Rev property."); - } else { - if (strlen (str) >= 8) { /* short representation */ - rev.tm.tm_mday = atoi (str + 6); - str[6] = 0; - rev.tm.tm_mon = atoi (str + 4); - str[4] = 0; - rev.tm.tm_year = atoi (str); - } else - g_warning ("? < Bad format for Rev property."); - } - - return rev; -} - -static enum KeyType -get_key_type (VObject *o) -{ - VObject *vo; - int i; - - for (i = 0; key_pairs[i].str; i++) - if (has (o, key_pairs[i].str)) - return key_pairs[i].id; - - g_warning ("? < No KeyType for Key property. Falling back to PGP."); - return KEY_PGP; -} - -static CardPhoto -get_CardPhoto (VObject *o) -{ - VObject *vo; - char *the_str; - CardPhoto photo; - - photo.type = get_photo_type (o); - - if (has (o, VCDataSizeProp)) { - photo.size = vObjectIntegerValue (vo); - photo.data = malloc (photo.size); - memcpy (photo.data, vObjectAnyValue (o), photo.size); - } else { - photo.size = strlen (str_val (o)) + 1; - photo.data = g_strdup (the_str); - free (the_str); - } - - return photo; -} - -static enum SoundType -get_sound_type (VObject *o) -{ - VObject *vo; - int i; - - for (i = 0; sound_pairs[i].str; i++) - if (has (o, sound_pairs[i].str)) - return sound_pairs[i].id; - - return SOUND_PHONETIC; -} - -static CardSound -get_CardSound (VObject *o) -{ - VObject *vo; - char *the_str; - CardSound sound; - - sound.type = get_sound_type (o); - - if (has (o, VCDataSizeProp)) { - sound.size = vObjectIntegerValue (vo); - sound.data = malloc (sound.size); - memcpy (sound.data, vObjectAnyValue (o), sound.size); - } else { - sound.size = strlen (str_val (o)); - sound.data = g_strdup (the_str); - free (the_str); - } - - return sound; -} - -/* Loads our card contents from a VObject */ -static ECard * -e_card_construct_from_vobject (ECard *card, - VObject *vcrd) -{ - VObjectIterator i; - Card *crd; - char *the_str; - - initPropIterator (&i, vcrd); - crd = card_new (); - - while (moreIteration (&i)) { - VObject *o = nextVObject (&i); - const char *n = vObjectName (o); - int propid; - CardProperty *prop = NULL; - - propid = card_lookup_name (n); - - switch (propid) { - case PROP_FNAME: - prop = &crd->fname.prop; - crd->fname.str = g_strdup (str_val (o)); - free (the_str); - break; - case PROP_NAME: - prop = &crd->name.prop; - crd->name = e_card_get_name (o); - break; - case PROP_PHOTO: - prop = &crd->photo.prop; - crd->photo = get_CardPhoto (o); - break; - case PROP_BDAY: - prop = &crd->bday.prop; - crd->bday = strtoCardBDay (str_val (o)); - free (the_str); - break; - case PROP_DELADDR: - { - CardDelAddr *c; - c = get_CardDelAddr (o); - prop = &c->prop; - crd->deladdr.l = g_list_append (crd->deladdr.l, c); - } - break; - case PROP_DELLABEL: - { - CardDelLabel *c; - c = get_CardDelLabel (o); - prop = &c->prop; - crd->dellabel.l = g_list_append (crd->dellabel.l, c); - } - break; - case PROP_PHONE: - { - CardPhone *c; - - c = get_CardPhone (o); - prop = &c->prop; - crd->phone.l = g_list_append (crd->phone.l, c); - } - break; - case PROP_EMAIL: - { - CardEMail *c; - - c = get_CardEMail (o); - prop = &c->prop; - crd->email.l = g_list_append (crd->email.l, c); - } - break; - case PROP_MAILER: - prop = &crd->mailer.prop; - crd->mailer.str = g_strdup (str_val (o)); - free (the_str); - break; - case PROP_TIMEZN: - prop = &crd->timezn.prop; - crd->timezn = strtoCardTimeZone (str_val (o)); - free (the_str); - break; - case PROP_GEOPOS: - prop = &crd->geopos.prop; - crd->geopos = strtoCardGeoPos (str_val (o)); - break; - case PROP_ROLE: - prop = &crd->role.prop; - crd->role.str = g_strdup (str_val (o)); - free (the_str); - break; - case PROP_LOGO: - prop = &crd->logo.prop; - crd->logo = get_CardPhoto (o); - break; - case PROP_AGENT: - crd->agent = card_create_from_vobject (o); - break; - case PROP_ORG: - prop = &crd->org.prop; - crd->org = get_CardOrg (o); - break; - case PROP_CATEGORIES: - prop = &crd->categories.prop; - crd->categories.str = g_strdup (str_val (o)); - crd->categories.prop.encod = ENC_QUOTED_PRINTABLE; - free (the_str); - break; - case PROP_COMMENT: - prop = &crd->comment.prop; - crd->comment.str = g_strdup (str_val (o)); - crd->comment.prop.encod = ENC_QUOTED_PRINTABLE; - free (the_str); - break; - case PROP_REV: - prop = &crd->rev.prop; - crd->rev = strtoCardRev (str_val (o)); - free (the_str); - break; - case PROP_SOUND: - prop = &crd->sound.prop; - crd->sound = get_CardSound (o); - break; - case PROP_VERSION: - { - char *str; - str = str_val (o); - if (strcmp (str, "2.1")) - g_warning ("? < Version doesn't match."); - free (the_str); - } - break; - case PROP_KEY: - prop = &crd->key.prop; - crd->key.type = get_key_type (o); - crd->key.data = g_strdup (str_val (o)); - free (the_str); - break; - default: - { - CardXProperty *c; - - c = get_XProp (o); - prop = &c->prop; - crd->xtension.l = g_list_append (crd->xtension.l, c); - } - break; - } - - if (prop) { - *prop = get_CardProperty (o); - prop->type = propid; - } - } - - return crd; -} - -/* Loads a card from a file */ -GList * -card_load (GList *crdlist, char *fname) -{ - VObject *vobj, *tmp; - - vobj = Parse_MIME_FromFileName (fname); - if (!vobj) { - g_warning ("Could not load the cardfile"); - return NULL; - } - - while (vobj) { - const char *n = vObjectName (vobj); - - if (strcmp (n, VCCardProp) == 0) { - crdlist = g_list_append (crdlist, (gpointer) - card_create_from_vobject (vobj)); - } - tmp = vobj; - vobj = nextVObjectInList (vobj); - cleanVObject (tmp); - } - - cleanVObject (vobj); - cleanStrTbl (); - return crdlist; -} - -static VObject * -add_strProp (VObject *o, const char *id, char *val) -{ - VObject *vo = NULL; - - if (val) - vo = addPropValue (o, id, val); - - return vo; -} - -static VObject * -add_CardProperty (VObject *o, CardProperty *prop) -{ - GList *node; - - switch (prop->encod) { - case ENC_BASE64: - addProp (o, VCBase64Prop); - break; - case ENC_QUOTED_PRINTABLE: - addProp (o, VCQuotedPrintableProp); - break; - case ENC_8BIT: - addProp (o, VC8bitProp); - break; - case ENC_7BIT: - /* Do nothing: 7BIT is the default. Avoids file clutter. */ - break; - default: - g_warning ("? < Card had invalid encoding type."); - } - - switch (prop->value) { - case VAL_CID: - addProp (o, VCContentIDProp); - break; - case VAL_INLINE: - /* Do nothing: INLINE is the default. Avoids file clutter. */ - break; - default: - g_warning ("? < Card had invalid value type."); - } - - for (node = prop->xtension; node; node = node->next) { - CardXAttribute *xa = (CardXAttribute *) node->data; - if (xa->data) - addPropValue (o, xa->name, xa->data); - else - addProp (o, xa->name); - } - - add_strProp (o, VCCharSetProp, prop->charset); - add_strProp (o, VCLanguageProp, prop->lang); - - return o; -} - -static VObject * -add_CardStrProperty (VObject *vobj, const char *id, CardStrProperty *strprop) -{ - VObject *vprop; - - if (strprop->prop.used) { - vprop = add_strProp (vobj, id, strprop->str); - add_CardProperty (vprop, &strprop->prop); - } - - return vobj; -} - -static VObject * -add_PhotoType (VObject *o, enum PhotoType photo_type) -{ - int i; - - for (i = 0; photo_pairs[i].str; i++) - if (photo_type == photo_pairs[i].id) { - addProp (o, photo_pairs[i].str); - return o; - } - - g_warning ("? > No PhotoType for Photo property. Falling back to JPEG."); - addProp (o, VCJPEGProp); - - return o; -} - -static VObject * -add_AddrType (VObject *o, int addr_type) -{ - int i; - - for (i = 0; addr_pairs[i].str; i++) - if (addr_type & addr_pairs[i].id) - addProp (o, addr_pairs[i].str); - - return o; -} - -static void -add_strAddrType (GString *string, int addr_type) -{ - int i, first = 1; - char *str; - - if (addr_type) { - g_string_append (string, " ("); - - for (i = 0; addr_pairs[i].str; i++) - if (addr_type & addr_pairs[i].id) { - if (!first) - g_string_append (string, ", "); - first = 0; - str = my_cap (addr_pairs[i].str); - g_string_append (string, str); - g_free (str); - } - - g_string_append_c (string, ')'); - } -} - -static VObject * -add_PhoneType (VObject *o, int phone_type) -{ - int i; - - for (i = 0; phone_pairs[i].str; i++) - if (phone_type & phone_pairs[i].id) - addProp (o, phone_pairs[i].str); - - return o; -} - -static void -add_strPhoneType (GString *string, int phone_type) -{ - int i, first = 1; - char *str; - - if (phone_type) { - g_string_append (string, " ("); - - for (i = 0; phone_pairs[i].str; i++) - if (phone_type & phone_pairs[i].id) { - if (!first) - g_string_append (string, ", "); - first = 0; - str = my_cap (phone_pairs[i].str); - g_string_append (string, str); - g_free (str); - } - - g_string_append_c (string, ')'); - } -} - -static VObject * -add_EMailType (VObject *o, enum EMailType email_type) -{ - int i; - - for (i = 0; email_pairs[i].str; i++) - if (email_type == email_pairs[i].id) { - addProp (o, email_pairs[i].str); - return o; - } - - g_warning ("? > No EMailType for EMail property. Falling back to INET."); - addProp (o, VCInternetProp); - - return o; -} - -static void -add_strEMailType (GString *string, int email_type) -{ - int i; - char *str; - - if (email_type) { - g_string_append (string, " ("); - - for (i = 0; email_pairs[i].str; i++) - if (email_type == email_pairs[i].id) { - str = my_cap (email_pairs[i].str); - g_string_append (string, str); - g_free (str); - break; - } - - g_string_append_c (string, ')'); - } -} - -static VObject * -add_KeyType (VObject *o, enum KeyType key_type) -{ - int i; - - for (i = 0; key_pairs[i].str; i++) - if (key_type == key_pairs[i].id) { - addProp (o, key_pairs[i].str); - return o; - } - - g_warning ("? > No KeyType for Key property. Falling back to PGP."); - addProp (o, VCPGPProp); - - return o; -} - -static void -add_strKeyType (GString *string, int key_type) -{ - int i; - char *str; - - if (key_type) { - g_string_append (string, " ("); - - for (i = 0; key_pairs[i].str; i++) - if (key_type == key_pairs[i].id) { - str = my_cap (key_pairs[i].str); - g_string_append (string, str); - g_free (str); - break; - } - - g_string_append_c (string, ')'); - } -} - -static VObject * -add_SoundType (VObject *o, enum SoundType sound_type) -{ - int i; - - for (i = 0; sound_pairs[i].str; i++) - if (sound_type == sound_pairs[i].id) { - addProp (o, sound_pairs[i].str); - return o; - } - - return o; -} - -char *card_timezn_str (CardTimeZone timezn) -{ - char *str; - - str = malloc (7); - snprintf (str, 7, (timezn.sign == -1)? "-%02d:%02d" : "%02d:%02d", - timezn.hours, timezn.mins); - return str; -} - -char *card_geopos_str (CardGeoPos geopos) -{ - char *str; - - str = malloc (15); - snprintf (str, 15, "%03.02f,%03.02f", geopos.lon, geopos.lat); - return str; -} - -static void add_CardStrProperty_to_string (GString *string, char *prop_name, - CardStrProperty *strprop) -{ - if (strprop->prop.used) { - if (prop_name) - g_string_append (string, prop_name); - - g_string_append (string, strprop->str); - } -} - -static void add_strProp_to_string (GString *string, char *prop_name, char *val) -{ - if (val) { - if (prop_name) - g_string_append (string, prop_name); - - g_string_append (string, val); - } -} - -static void addProp_to_string (GString *string, char *prop_name) -{ - if (prop_name) - g_string_append (string, prop_name); -} - -char * -card_to_string (Card *crd) -{ - GString *string; - char *ret; - - string = g_string_new (""); - - add_CardStrProperty_to_string (string, _("Card: "), &crd->fname); - if (crd->name.prop.used) { - addProp_to_string (string, N_("\nName: ")); - add_strProp_to_string (string, N_("\n Prefix: "), crd->name.prefix); - add_strProp_to_string (string, N_("\n Given: "), crd->name.given); - add_strProp_to_string (string, N_("\n Additional: "), crd->name.additional); - add_strProp_to_string (string, N_("\n Family: "), crd->name.family); - add_strProp_to_string (string, N_("\n Suffix: "), crd->name.suffix); - g_string_append_c (string, '\n'); - } - -/* if (crd->photo.prop.used) { - addPropSizedValue (string, _ ("\nPhoto: "), - crd->photo.data, crd->photo.size); - add_PhotoType (string, crd->photo.type); - }*/ - - if (crd->bday.prop.used) { - char *date_str; - - date_str = card_bday_str (crd->bday); - add_strProp_to_string (string, N_("\nBirth Date: "), date_str); - free (date_str); - } - - if (crd->deladdr.l) { - GList *node; - - for (node = crd->deladdr.l; node; node = node->next) { - CardDelAddr *deladdr = (CardDelAddr *) node->data; - - if (deladdr->prop.used) { - addProp_to_string (string, N_("\nAddress:")); - add_strAddrType (string, deladdr->type); - add_strProp_to_string (string, N_("\n Postal Box: "), deladdr->po); - add_strProp_to_string (string, N_("\n Ext: "), deladdr->ext); - add_strProp_to_string (string, N_("\n Street: "), deladdr->street); - add_strProp_to_string (string, N_("\n City: "), deladdr->city); - add_strProp_to_string (string, N_("\n Region: "), deladdr->region); - add_strProp_to_string (string, N_("\n Postal Code: "), deladdr->code); - add_strProp_to_string (string, N_("\n Country: "), deladdr->country); - } - } - - g_string_append_c (string, '\n'); - } - - if (crd->dellabel.l) { - GList *node; - - for (node = crd->dellabel.l; node; node = node->next) { - CardDelLabel *dellabel = (CardDelLabel *) node->data; - - add_strProp_to_string (string, N_("\nDelivery Label: "), - dellabel->data); - add_strAddrType (string, dellabel->type); - } - } - - if (crd->phone.l) { - GList *node; - char *sep; - - if (crd->phone.l->next) { - sep = " "; - g_string_append (string, N_("\nTelephones:\n")); - } else { - sep = " "; - g_string_append (string, N_("\nTelephone:")); - } - - for (node = crd->phone.l; node; node = node->next) { - CardPhone *phone = (CardPhone *) node->data; - - if (phone->prop.used) { - g_string_append (string, sep); - g_string_append (string, phone->data); - add_strPhoneType (string, phone->type); - g_string_append_c (string, '\n'); - } - } - - if (crd->phone.l->next) - g_string_append_c (string, '\n'); - } - - if (crd->email.l) { - GList *node; - char *sep; - - if (crd->email.l->next) { - sep = " "; - g_string_append (string, N_("\nE-mail:\n")); - } else { - sep = " "; - g_string_append (string, N_("\nE-mail:")); - } - - - for (node = crd->email.l; node; node = node->next) { - CardEMail *email = (CardEMail *) node->data; - - if (email->prop.used) { - g_string_append (string, sep); - g_string_append (string, email->data); - add_strEMailType (string, email->type); - g_string_append_c (string, '\n'); - } - } - - if (crd->email.l->next) - g_string_append_c (string, '\n'); - } - - add_CardStrProperty_to_string (string, N_("\nMailer: "), &crd->mailer); - - if (crd->timezn.prop.used) { - char *str; - - str = card_timezn_str (crd->timezn); - add_strProp_to_string (string, N_("\nTime Zone: "), str); - free (str); - } - - if (crd->geopos.prop.used) { - char *str; - - str = card_geopos_str (crd->geopos); - add_strProp_to_string (string, N_("\nGeo Location: "), str); - free (str); - } - - add_CardStrProperty_to_string (string, N_("\nBusiness Role: "), &crd->role); - -/* if (crd->logo.prop.used) { - addPropSizedValue (string, _ ("\nLogo: "), - crd->logo.data, crd->logo.size); - add_PhotoType (string, crd->logo.type); - }*/ - -/* if (crd->agent) - addstringectProp (string, card_convert_to_stringect (crd->agent));*/ - - if (crd->org.prop.used) { - addProp_to_string (string, N_("\nOrg: ")); - add_strProp_to_string (string, N_("\n Name: "), crd->org.name); - add_strProp_to_string (string, N_("\n Unit: "), crd->org.unit1); - add_strProp_to_string (string, N_("\n Unit2: "), crd->org.unit2); - add_strProp_to_string (string, N_("\n Unit3: "), crd->org.unit3); - add_strProp_to_string (string, N_("\n Unit4: "), crd->org.unit4); - g_string_append_c (string, '\n'); - } - - add_CardStrProperty_to_string (string, N_("\nCategories: "), &crd->categories); - add_CardStrProperty_to_string (string, N_("\nComment: "), &crd->comment); - -/* if (crd->sound.prop.used) { - if (crd->sound.type != SOUND_PHONETIC) - addPropSizedValue (string, _ ("\nPronunciation: "), - crd->sound.data, crd->sound.size); - else - add_strProp_to_string (string, _ ("\nPronunciation: "), - crd->sound.data); - - add_SoundType (string, crd->sound.type); - }*/ - - add_CardStrProperty_to_string (string, N_("\nUnique String: "), &crd->uid); - - if (crd->key.prop.used) { - add_strProp_to_string (string, N_("\nPublic Key: "), crd->key.data); - add_strKeyType (string, crd->key.type); - } - - ret = g_strdup (string->str); - g_string_free (string, TRUE); - - return ret; -} -#endif - -static ECardDate -e_card_date_from_string (char *str) -{ - ECardDate date; - int length; - - date.year = 0; - date.month = 0; - date.day = 0; - - length = strlen(str); - - if (length == 10 ) { - date.year = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3] - '0' * 1111; - date.month = str[5] * 10 + str[6] - '0' * 11; - date.day = str[8] * 10 + str[9] - '0' * 11; - } else if ( length == 8 ) { - date.year = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3] - '0' * 1111; - date.month = str[4] * 10 + str[5] - '0' * 11; - date.day = str[6] * 10 + str[7] - '0' * 11; - } - - return date; -} - -char * -e_v_object_get_child_value(VObject *vobj, char *name) -{ - char *ret_val; - VObjectIterator iterator; - initPropIterator(&iterator, vobj); - while(moreIteration (&iterator)) { - VObject *attribute = nextVObject(&iterator); - const char *id = vObjectName(attribute); - if ( ! strcmp(id, name) ) { - assign_string(attribute, &ret_val); - return ret_val; - } - } - return NULL; -} - -static ECardPhoneFlags -get_phone_flags (VObject *vobj) -{ - ECardPhoneFlags ret = 0; - int i; - - struct { - char *id; - ECardPhoneFlags flag; - } phone_pairs[] = { - { VCPreferredProp, E_CARD_PHONE_PREF }, - { VCWorkProp, E_CARD_PHONE_WORK }, - { VCHomeProp, E_CARD_PHONE_HOME }, - { VCVoiceProp, E_CARD_PHONE_VOICE }, - { VCFaxProp, E_CARD_PHONE_FAX }, - { VCMessageProp, E_CARD_PHONE_MSG }, - { VCCellularProp, E_CARD_PHONE_CELL }, - { VCPagerProp, E_CARD_PHONE_PAGER }, - { VCBBSProp, E_CARD_PHONE_BBS }, - { VCModemProp, E_CARD_PHONE_MODEM }, - { VCCarProp, E_CARD_PHONE_CAR }, - { VCISDNProp, E_CARD_PHONE_ISDN }, - { VCVideoProp, E_CARD_PHONE_VIDEO }, - { "X-EVOLUTION-ASSISTANT", E_CARD_PHONE_ASSISTANT }, - { "X-EVOLUTION-CALLBACK", E_CARD_PHONE_CALLBACK }, - { "X-EVOLUTION-RADIO", E_CARD_PHONE_RADIO }, - { "X-EVOLUTION-TELEX", E_CARD_PHONE_TELEX }, - { "X-EVOLUTION-TTYTDD", E_CARD_PHONE_TTYTDD }, - }; - - for (i = 0; i < sizeof(phone_pairs) / sizeof(phone_pairs[0]); i++) { - if (isAPropertyOf (vobj, phone_pairs[i].id)) { - ret |= phone_pairs[i].flag; - } - } - - return ret; -} - -static void -set_phone_flags (VObject *vobj, ECardPhoneFlags flags) -{ - int i; - - struct { - char *id; - ECardPhoneFlags flag; - } phone_pairs[] = { - { VCPreferredProp, E_CARD_PHONE_PREF }, - { VCWorkProp, E_CARD_PHONE_WORK }, - { VCHomeProp, E_CARD_PHONE_HOME }, - { VCVoiceProp, E_CARD_PHONE_VOICE }, - { VCFaxProp, E_CARD_PHONE_FAX }, - { VCMessageProp, E_CARD_PHONE_MSG }, - { VCCellularProp, E_CARD_PHONE_CELL }, - { VCPagerProp, E_CARD_PHONE_PAGER }, - { VCBBSProp, E_CARD_PHONE_BBS }, - { VCModemProp, E_CARD_PHONE_MODEM }, - { VCCarProp, E_CARD_PHONE_CAR }, - { VCISDNProp, E_CARD_PHONE_ISDN }, - { VCVideoProp, E_CARD_PHONE_VIDEO }, - { "X-EVOLUTION-ASSISTANT", E_CARD_PHONE_ASSISTANT }, - { "X-EVOLUTION-CALLBACK", E_CARD_PHONE_CALLBACK }, - { "X-EVOLUTION-RADIO", E_CARD_PHONE_RADIO }, - { "X-EVOLUTION-TELEX", E_CARD_PHONE_TELEX }, - { "X-EVOLUTION-TTYTDD", E_CARD_PHONE_TTYTDD }, - }; - - for (i = 0; i < sizeof(phone_pairs) / sizeof(phone_pairs[0]); i++) { - if (flags & phone_pairs[i].flag) { - addProp (vobj, phone_pairs[i].id); - } - } -} - -static ECardAddressFlags -get_address_flags (VObject *vobj) -{ - ECardAddressFlags ret = 0; - int i; - - struct { - char *id; - ECardAddressFlags flag; - } addr_pairs[] = { - { VCDomesticProp, E_CARD_ADDR_DOM }, - { VCInternationalProp, E_CARD_ADDR_INTL }, - { VCPostalProp, E_CARD_ADDR_POSTAL }, - { VCParcelProp, E_CARD_ADDR_PARCEL }, - { VCHomeProp, E_CARD_ADDR_HOME }, - { VCWorkProp, E_CARD_ADDR_WORK }, - }; - - for (i = 0; i < sizeof(addr_pairs) / sizeof(addr_pairs[0]); i++) { - if (isAPropertyOf (vobj, addr_pairs[i].id)) { - ret |= addr_pairs[i].flag; - } - } - - return ret; -} - -static void -set_address_flags (VObject *vobj, ECardAddressFlags flags) -{ - int i; - - struct { - char *id; - ECardAddressFlags flag; - } addr_pairs[] = { - { VCDomesticProp, E_CARD_ADDR_DOM }, - { VCInternationalProp, E_CARD_ADDR_INTL }, - { VCPostalProp, E_CARD_ADDR_POSTAL }, - { VCParcelProp, E_CARD_ADDR_PARCEL }, - { VCHomeProp, E_CARD_ADDR_HOME }, - { VCWorkProp, E_CARD_ADDR_WORK }, - }; - - for (i = 0; i < sizeof(addr_pairs) / sizeof(addr_pairs[0]); i++) { - if (flags & addr_pairs[i].flag) { - addProp (vobj, addr_pairs[i].id); - } - } -} - -#include <Evolution-Composer.h> - -#define COMPOSER_OAFID "OAFIID:GNOME_Evolution_Mail_Composer" - -void -e_card_list_send (GList *cards, ECardDisposition disposition) -{ - BonoboObjectClient *bonobo_server; - GNOME_Evolution_Composer composer_server; - CORBA_Environment ev; - - if (cards == NULL) - return; - - /* First, I obtain an object reference that represents the Composer. */ - bonobo_server = bonobo_object_activate (COMPOSER_OAFID, 0); - - g_return_if_fail (bonobo_server != NULL); - - composer_server = bonobo_object_corba_objref (BONOBO_OBJECT (bonobo_server)); - - CORBA_exception_init (&ev); - - if (disposition == E_CARD_DISPOSITION_AS_TO) { - GNOME_Evolution_Composer_RecipientList *to_list, *cc_list, *bcc_list; - CORBA_char *subject; - int length; - int i; - - length = g_list_length (cards); - - /* Now I have to make a CORBA sequence that represents a recipient list with - one item, for the card. */ - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = length; - to_list->_length = length; - to_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (length); - - for (i = 0; - cards; - i++, cards = cards->next) { - ECard *card = cards->data; - EIterator *iterator; - char *file_as; - EList *email; - GNOME_Evolution_Composer_Recipient *recipient; - - recipient = &(to_list->_buffer[i]); - gtk_object_get (GTK_OBJECT (card), - "file_as", &file_as, - "email", &email, - NULL); - - iterator = e_list_get_iterator (email); - if (e_iterator_is_valid (iterator)) { - recipient->address = CORBA_string_dup (e_iterator_get (iterator)); - } else { - recipient->address = CORBA_string_dup(""); - } - gtk_object_unref (GTK_OBJECT (iterator)); - recipient->name = CORBA_string_dup (file_as); - } - - cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - cc_list->_maximum = cc_list->_length = 0; - bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - bcc_list->_maximum = bcc_list->_length = 0; - - subject = CORBA_string_dup (""); - - GNOME_Evolution_Composer_setHeaders (composer_server, to_list, cc_list, bcc_list, subject, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_printerr ("gui/e-meeting-edit.c: I couldn't set the composer headers via CORBA! Aagh.\n"); - CORBA_exception_free (&ev); - return; - } - - CORBA_free (to_list); - CORBA_free (cc_list); - CORBA_free (bcc_list); - CORBA_free (subject); - } - - if (disposition == E_CARD_DISPOSITION_AS_ATTACHMENT) { - CORBA_char *content_type, *filename, *description; - GNOME_Evolution_Composer_AttachmentData *attach_data; - CORBA_boolean show_inline; - char *tempstr; - - content_type = CORBA_string_dup ("text/x-vcard"); - filename = CORBA_string_dup (""); - - if (cards->next) { - description = CORBA_string_dup (_("Multiple VCards")); - } else { - char *file_as; - - gtk_object_get(GTK_OBJECT(cards->data), - "file_as", &file_as, - NULL); - - tempstr = g_strdup_printf (_("VCard for %s"), file_as); - description = CORBA_string_dup (tempstr); - g_free (tempstr); - } - - show_inline = FALSE; - - tempstr = e_card_list_get_vcard (cards); - attach_data = GNOME_Evolution_Composer_AttachmentData__alloc(); - attach_data->_maximum = attach_data->_length = strlen (tempstr); - attach_data->_buffer = CORBA_sequence_CORBA_char_allocbuf (attach_data->_length); - strcpy (attach_data->_buffer, tempstr); - g_free (tempstr); - - GNOME_Evolution_Composer_attachData (composer_server, - content_type, filename, description, - show_inline, attach_data, - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_printerr ("gui/e-meeting-edit.c: I couldn't attach data to the composer via CORBA! Aagh.\n"); - CORBA_exception_free (&ev); - return; - } - - CORBA_free (content_type); - CORBA_free (filename); - CORBA_free (description); - CORBA_free (attach_data); - } - - GNOME_Evolution_Composer_show (composer_server, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_printerr ("gui/e-meeting-edit.c: I couldn't show the composer via CORBA! Aagh.\n"); - CORBA_exception_free (&ev); - return; - } - - CORBA_exception_free (&ev); -} - -void -e_card_send (ECard *card, ECardDisposition disposition) -{ - GList *list; - list = g_list_prepend (NULL, card); - e_card_list_send (list, disposition); - g_list_free (list); -} - -gboolean -e_card_evolution_list (ECard *card) -{ - g_return_val_if_fail (card && E_IS_CARD (card), FALSE); - return card->list; -} - -gboolean -e_card_evolution_list_show_addresses (ECard *card) -{ - g_return_val_if_fail (card && E_IS_CARD (card), FALSE); - return card->list_show_addresses; -} - -static gchar * -e_card_uri_extract_book_uri (const gchar *uri) -{ - gchar *lastslash; - - if (uri == NULL) - return NULL; - - lastslash = strrchr (uri, '/'); - if (lastslash == NULL) - return NULL; - - return g_strndup (uri, lastslash - uri); -} - -static gchar * -e_card_uri_extract_card_id (const gchar *uri) -{ - gchar *lastslash; - - if (uri == NULL) - return NULL; - - lastslash = strrchr (uri, '/'); - return lastslash ? g_strdup (lastslash+1) : NULL; -} - -typedef struct _CardLoadData CardLoadData; -struct _CardLoadData { - gchar *card_id; - ECardCallback cb; - gpointer closure; -}; - -static void -card_load_cb (EBook *book, EBookStatus status, gpointer closure) -{ - CardLoadData *data = (CardLoadData *) closure; - ECard *card = NULL; - - if (status == E_BOOK_STATUS_SUCCESS) - card = e_book_get_card (book, data->card_id); - - if (data->cb != NULL) - data->cb (card, data->closure); - - g_free (data->card_id); - g_free (data); -} - -void -e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure) -{ - CardLoadData *data; - gchar *book_uri; - gchar *card_id; - EBook *book; - - g_return_if_fail (uri != NULL); - - book_uri = e_card_uri_extract_book_uri (uri); - card_id = e_card_uri_extract_card_id (uri); - - data = g_new (CardLoadData, 1); - data->card_id = g_strdup (card_id); - data->cb = cb; - data->closure = closure; - - book = e_book_new (); - e_book_load_uri (book, book_uri, card_load_cb, data); - - g_free (book_uri); -} diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h deleted file mode 100644 index 3aaeddb813..0000000000 --- a/addressbook/backend/ebook/e-card.h +++ /dev/null @@ -1,201 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * Arturo Espinosa - * Nat Friedman (nat@ximian.com) - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_CARD_H__ -#define __E_CARD_H__ - -#include <time.h> -#include <gtk/gtkobject.h> -#include <stdio.h> -#include <addressbook/backend/ebook/e-card-types.h> -#include <e-util/e-list.h> - -#define E_TYPE_CARD (e_card_get_type ()) -#define E_CARD(obj) (GTK_CHECK_CAST ((obj), E_TYPE_CARD, ECard)) -#define E_CARD_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_CARD, ECardClass)) -#define E_IS_CARD(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_CARD)) -#define E_IS_CARD_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_CARD)) - -typedef struct _ECard ECard; -typedef struct _ECardClass ECardClass; - -struct _EBook; /* Forward reference */ - -struct _ECard { - GtkObject object; - char *id; - - struct _EBook *book; /* The EBook this card is from. */ - gchar *uri; /* The card's uri (book uri + id) */ - - char *file_as; /* The File As field. */ - char *fname; /* The full name. */ - ECardName *name; /* The structured name. */ - EList *address; /* Delivery addresses (ECardDeliveryAddress *) */ - EList *address_label; /* Delivery address labels - * (ECardAddrLabel *) */ - - EList *phone; /* Phone numbers (ECardPhone *) */ - EList *email; /* Email addresses (char *) */ - char *url; /* The person's web page. */ - - ECardDate *bday; /* The person's birthday. */ - - char *note; - - - char *org; /* The person's organization. */ - char *org_unit; /* The person's organization unit. */ - char *office; /* The person's office. */ - char *role; /* The person's role w/in his org */ - char *title; /* The person's title w/in his org */ - - char *manager; - char *assistant; - - char *nickname; /* The person's nickname */ - - char *spouse; /* The person's spouse. */ - ECardDate *anniversary; /* The person's anniversary. */ - - char *mailer; /* Mailer */ - - char *fburl; /* Free Busy URL */ - - gint timezone; /* number of minutes from UTC as an int */ - - ECardDate *last_use; - float raw_use_score; - - char *related_contacts; /* EDestinationV (serialized) of related contacts. */ - - EList *categories; /* Categories. */ - - EList *arbitrary; /* Arbitrary fields. */ - - - - guint32 wants_html : 1; /* Wants html mail. */ - guint32 wants_html_set : 1; /* Wants html mail. */ - guint32 list : 1; /* If the card corresponds to a contact list */ - guint32 list_show_addresses : 1; /* Whether to show the addresses - in the To: or Bcc: field */ - -#if 0 - ECardPhoto *logo; /* This person's org's logo. */ - - ECardPhoto *photo; /* A photo of the person. */ - - ECard *agent; /* A person who sereves as this - guy's agent/secretary/etc. */ - - ECardSound *sound; - - ECardKey *key; /* The person's public key. */ - ECardTimeZone *timezn; /* The person's time zone. */ - ECardGeoPos *geopos; /* The person's long/lat. */ - - ECardRev *rev; /* The time this card was last - modified. */ - - EList xtension; -#endif -}; - -struct _ECardClass { - GtkObjectClass parent_class; - GHashTable *attribute_jump_table; -}; - - -/* Simple functions */ -ECard *e_card_new (char *vcard); -const char *e_card_get_id (ECard *card); -void e_card_set_id (ECard *card, - const char *character); - -struct _EBook *e_card_get_book (ECard *card); -const char *e_card_get_uri (ECard *card); - - -char *e_card_get_vcard (ECard *card); -char *e_card_list_get_vcard (GList *list); -ECard *e_card_duplicate (ECard *card); - -float e_card_get_use_score (ECard *card); -void e_card_touch (ECard *card); - -/* Evolution List convenience functions */ -/* used for encoding uids in email addresses */ -gboolean e_card_evolution_list (ECard *card); -gboolean e_card_evolution_list_show_addresses(ECard *card); - -/* ECardPhone manipulation */ -ECardPhone *e_card_phone_new (void); -ECardPhone *e_card_phone_copy (const ECardPhone *phone); -void e_card_phone_free (ECardPhone *phone); - -/* ECardDeliveryAddress manipulation */ -ECardDeliveryAddress *e_card_delivery_address_new (void); -ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr); -void e_card_delivery_address_free (ECardDeliveryAddress *addr); -gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr); -char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr); -ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label); -ECardAddrLabel *e_card_delivery_address_to_label (const ECardDeliveryAddress *addr); - -/* ECardAddrLabel manipulation */ -ECardAddrLabel *e_card_address_label_new (void); -ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr); -void e_card_address_label_free (ECardAddrLabel *addr); - -/* ECardName manipulation */ -ECardName *e_card_name_new (void); -ECardName *e_card_name_copy (const ECardName *name); -void e_card_name_free (ECardName *name); -char *e_card_name_to_string (const ECardName *name); -ECardName *e_card_name_from_string (const char *full_name); -gboolean e_card_name_match_string (const ECardName *name, - const gchar *str); - -/* ECardArbitrary manipulation */ -ECardArbitrary *e_card_arbitrary_new (void); -ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary); -void e_card_arbitrary_free (ECardArbitrary *arbitrary); - -/* ECard email manipulation */ -gboolean e_card_email_match_string (const ECard *card, - const gchar *str); - -/* Specialized functionality */ -GList *e_card_load_cards_from_file (const char *filename); -GList *e_card_load_cards_from_string (const char *str); -void e_card_free_empty_lists (ECard *card); - -enum _ECardDisposition { - E_CARD_DISPOSITION_AS_ATTACHMENT, - E_CARD_DISPOSITION_AS_TO, -}; -typedef enum _ECardDisposition ECardDisposition; -void e_card_send (ECard *card, - ECardDisposition disposition); -void e_card_list_send (GList *cards, - ECardDisposition disposition); - -/* Getting ECards via their URIs */ -typedef void (*ECardCallback) (ECard *card, gpointer closure); -void e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure); - - -/* Standard Gtk function */ -GtkType e_card_get_type (void); - -#endif /* ! __E_CARD_H__ */ diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c deleted file mode 100644 index bed6fc1b7d..0000000000 --- a/addressbook/backend/ebook/e-destination.c +++ /dev/null @@ -1,961 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-destination.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#include <config.h> -#include "e-destination.h" - -#include <stdlib.h> -#include <ctype.h> -#include <string.h> -#include <gtk/gtkobject.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include "e-book.h" -#include "e-book-util.h" -#include <gal/widgets/e-unicode.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> -#include <camel/camel-internet-address.h> - -struct _EDestinationPrivate { - - gchar *raw; - - gchar *card_uri; - ECard *card; - gint card_email_num; - - gchar *name; - gchar *email; - gchar *addr; - - gboolean html_mail_override; - gboolean wants_html_mail; - - GList *list_dests; -}; - -static void e_destination_clear_card (EDestination *); -static void e_destination_clear_strings (EDestination *); - -static GtkObjectClass *parent_class; - -static void -e_destination_destroy (GtkObject *obj) -{ - EDestination *dest = E_DESTINATION (obj); - - e_destination_clear (dest); - g_free (dest->priv); - - if (parent_class->destroy) - parent_class->destroy (obj); -} - -static void -e_destination_class_init (EDestinationClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); - - parent_class = GTK_OBJECT_CLASS (gtk_type_class (GTK_TYPE_OBJECT)); - - object_class->destroy = e_destination_destroy; -} - -static void -e_destination_init (EDestination *dest) -{ - dest->priv = g_new0 (struct _EDestinationPrivate, 1); -} - -GtkType -e_destination_get_type (void) -{ - static GtkType dest_type = 0; - - if (!dest_type) { - GtkTypeInfo dest_info = { - "EDestination", - sizeof (EDestination), - sizeof (EDestinationClass), - (GtkClassInitFunc) e_destination_class_init, - (GtkObjectInitFunc) e_destination_init, - NULL, NULL, /* reserved */ - (GtkClassInitFunc) NULL - }; - - dest_type = gtk_type_unique (gtk_object_get_type (), &dest_info); - } - - return dest_type; -} - -EDestination * -e_destination_new (void) -{ - return E_DESTINATION (gtk_type_new (E_TYPE_DESTINATION)); -} - -EDestination * -e_destination_copy (const EDestination *dest) -{ - EDestination *new_dest; - GList *iter; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - new_dest = e_destination_new (); - - new_dest->priv->card_uri = g_strdup (dest->priv->card_uri); - new_dest->priv->name = g_strdup (dest->priv->name); - new_dest->priv->email = g_strdup (dest->priv->email); - new_dest->priv->addr = g_strdup (dest->priv->addr); - new_dest->priv->card_email_num = dest->priv->card_email_num; - - new_dest->priv->card = dest->priv->card; - if (new_dest->priv->card) - gtk_object_ref (GTK_OBJECT (new_dest->priv->card)); - - new_dest->priv->html_mail_override = dest->priv->html_mail_override; - new_dest->priv->wants_html_mail = dest->priv->wants_html_mail; - - for (iter = dest->priv->list_dests; iter != NULL; iter = g_list_next (iter)) { - new_dest->priv->list_dests = g_list_append (new_dest->priv->list_dests, - e_destination_copy (E_DESTINATION (iter->data))); - } - - return new_dest; -} - -static void -e_destination_clear_card (EDestination *dest) -{ - g_free (dest->priv->card_uri); - dest->priv->card_uri = NULL; - - if (dest->priv->card) - gtk_object_unref (GTK_OBJECT (dest->priv->card)); - dest->priv->card = NULL; - - dest->priv->card_email_num = -1; - - g_list_foreach (dest->priv->list_dests, (GFunc) gtk_object_unref, NULL); - g_list_free (dest->priv->list_dests); - dest->priv->list_dests = NULL; -} - -static void -e_destination_clear_strings (EDestination *dest) -{ - g_free (dest->priv->raw); - dest->priv->raw = NULL; - - g_free (dest->priv->name); - dest->priv->name = NULL; - - g_free (dest->priv->email); - dest->priv->email = NULL; - - g_free (dest->priv->addr); - dest->priv->addr = NULL; -} - -void -e_destination_clear (EDestination *dest) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - e_destination_clear_card (dest); - e_destination_clear_strings (dest); -} - -gboolean -e_destination_is_empty (const EDestination *dest) -{ - struct _EDestinationPrivate *p; - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), TRUE); - p = dest->priv; - - return !(p->card != NULL - || (p->card_uri && *p->card_uri) - || (p->raw && *p->raw) - || (p->name && *p->name) - || (p->email && *p->email) - || (p->addr && *p->addr) - || (p->list_dests != NULL)); -} - -void -e_destination_set_card (EDestination *dest, ECard *card, gint email_num) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - g_return_if_fail (card && E_IS_CARD (card)); - - e_destination_clear (dest); - - dest->priv->card = card; - gtk_object_ref (GTK_OBJECT (dest->priv->card)); - - dest->priv->card_email_num = email_num; -} - -void -e_destination_set_card_uri (EDestination *dest, const gchar *uri, gint email_num) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - g_return_if_fail (uri != NULL); - - g_free (dest->priv->card_uri); - dest->priv->card_uri = g_strdup (uri); - dest->priv->card_email_num = email_num; - - /* If we already have a card, remove it unless it's uri matches the one - we just set. */ - if (dest->priv->card && strcmp (uri, e_card_get_uri (dest->priv->card))) { - gtk_object_unref (GTK_OBJECT (dest->priv->card)); - dest->priv->card = NULL; - } -} - -void -e_destination_set_name (EDestination *dest, const gchar *name) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - g_return_if_fail (name != NULL); - - g_free (dest->priv->name); - dest->priv->name = g_strdup (name); - - if (dest->priv->addr != NULL) { - g_free (dest->priv->addr); - dest->priv->addr = NULL; - } -} - -void -e_destination_set_email (EDestination *dest, const gchar *email) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - g_return_if_fail (email != NULL); - - g_free (dest->priv->email); - dest->priv->email = g_strdup (email); - - if (dest->priv->addr != NULL) { - g_free (dest->priv->addr); - dest->priv->addr = NULL; - } -} - -void -e_destination_set_html_mail_pref (EDestination *dest, gboolean x) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - dest->priv->html_mail_override = TRUE; - dest->priv->wants_html_mail = x; -} - -gboolean -e_destination_contains_card (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - return dest->priv->card != NULL; -} - -gboolean -e_destination_from_card (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - return dest->priv->card != NULL || dest->priv->card_uri != NULL; -} - - -typedef struct _UseCard UseCard; -struct _UseCard { - EDestination *dest; - EDestinationCardCallback cb; - gpointer closure; -}; - -static void -use_card_cb (ECard *card, gpointer closure) -{ - UseCard *uc = (UseCard *) closure; - - if (card != NULL && uc->dest->priv->card == NULL) { - - uc->dest->priv->card = card; - gtk_object_ref (GTK_OBJECT (uc->dest->priv->card)); - - } - - if (uc->cb) { - uc->cb (uc->dest, uc->dest->priv->card, uc->closure); - } - - /* We held a copy of the destination during the callback. */ - gtk_object_unref (GTK_OBJECT (uc->dest)); - g_free (uc); -} - -void -e_destination_use_card (EDestination *dest, EDestinationCardCallback cb, gpointer closure) -{ - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - if (dest->priv->card != NULL) { - - if (cb) { - cb (dest, dest->priv->card, closure); - } - - } else if (dest->priv->card_uri != NULL) { - - UseCard *uc = g_new (UseCard, 1); - uc->dest = dest; - /* Hold a reference to the destination during the callback. */ - gtk_object_ref (GTK_OBJECT (uc->dest)); - uc->cb = cb; - uc->closure = closure; - e_card_load_uri (dest->priv->card_uri, use_card_cb, uc); - } -} - -ECard * -e_destination_get_card (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - return dest->priv->card; -} - -const gchar * -e_destination_get_card_uri (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - if (dest->priv->card_uri) - return dest->priv->card_uri; - - if (dest->priv->card) - return e_card_get_uri (dest->priv->card); - - return NULL; -} - -gint -e_destination_get_email_num (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), -1); - - if (dest->priv->card == NULL && dest->priv->card_uri == NULL) - return -1; - - return dest->priv->card_email_num; -} - -const gchar * -e_destination_get_name (const EDestination *dest) -{ - struct _EDestinationPrivate *priv; - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */ - - if (priv->name == NULL) { - - if (priv->card != NULL) { - - priv->name = e_card_name_to_string (priv->card->name); - - if (priv->name == NULL || *priv->name == '\0') { - g_free (priv->name); - priv->name = g_strdup (priv->card->file_as); - } - - if (priv->name == NULL || *priv->name == '\0') { - g_free (priv->name); - priv->name = g_strdup (e_destination_get_email (dest)); - } - - } else if (priv->raw != NULL) { - - CamelInternetAddress *addr = camel_internet_address_new (); - - if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) { - const gchar *camel_name = NULL; - camel_internet_address_get (addr, 0, &camel_name, NULL); - priv->name = g_strdup (camel_name); - } - - camel_object_unref (CAMEL_OBJECT (addr)); - } - } - - return priv->name; - -} - -const gchar * -e_destination_get_email (const EDestination *dest) -{ - struct _EDestinationPrivate *priv; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */ - - if (priv->email == NULL) { - - if (priv->card != NULL) { /* Pull the address out of the card. */ - - EIterator *iter = e_list_get_iterator (priv->card->email); - gint n = priv->card_email_num; - - if (n >= 0) { - while (n > 0) { - e_iterator_next (iter); - --n; - } - - if (e_iterator_is_valid (iter)) { - gconstpointer ptr = e_iterator_get (iter); - priv->email = g_strdup ((gchar *) ptr); - } - } - - } else if (priv->raw != NULL) { - - CamelInternetAddress *addr = camel_internet_address_new (); - - if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) { - const gchar *camel_email = NULL; - camel_internet_address_get (addr, 0, NULL, &camel_email); - priv->email = g_strdup (camel_email); - } - - camel_object_unref (CAMEL_OBJECT (addr)); - } - } - - return priv->email; -} - -const gchar * -e_destination_get_address (const EDestination *dest) -{ - struct _EDestinationPrivate *priv; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */ - - if (priv->addr == NULL) { - CamelInternetAddress *addr = camel_internet_address_new (); - - if (e_destination_is_evolution_list (dest)) { - GList *iter = dest->priv->list_dests; - - while (iter) { - EDestination *list_dest = E_DESTINATION (iter->data); - if (!e_destination_is_empty (list_dest)) { - camel_internet_address_add (addr, - e_destination_get_name (list_dest), - e_destination_get_email (list_dest)); - } - iter = g_list_next (iter); - } - - priv->addr = camel_address_encode (CAMEL_ADDRESS (addr)); - - } else if (priv->raw) { - - if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) { - priv->addr = camel_address_encode (CAMEL_ADDRESS (addr)); - } - - } else { - - camel_internet_address_add (addr, - e_destination_get_name (dest), - e_destination_get_email (dest)); - - priv->addr = camel_address_encode (CAMEL_ADDRESS (addr)); - } - - camel_object_unref (CAMEL_OBJECT (addr)); - } - - return priv->addr; -} - -void -e_destination_set_raw (EDestination *dest, const gchar *raw) -{ - g_return_if_fail (E_IS_DESTINATION (dest)); - g_return_if_fail (raw != NULL); - - e_destination_clear (dest); - - dest->priv->raw = g_strdup (raw); - -} - -const gchar * -e_destination_get_textrep (const EDestination *dest) -{ - const gchar *txt; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - if (dest->priv->raw) - return dest->priv->raw; - - txt = e_destination_get_name (dest); - if (txt != NULL) - return txt; - - txt = e_destination_get_email (dest); - if (txt != NULL) - return txt; - - return ""; -} - -gboolean -e_destination_is_evolution_list (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - - if (dest->priv->list_dests == NULL - && dest->priv->card != NULL - && dest->priv->card->email != NULL - && e_card_evolution_list (dest->priv->card)) { - - EIterator *iter = e_list_get_iterator (dest->priv->card->email); - e_iterator_reset (iter); - while (e_iterator_is_valid (iter)) { - const gchar *dest_xml = (const gchar *) e_iterator_get (iter); - EDestination *list_dest = e_destination_import (dest_xml); - if (list_dest) - dest->priv->list_dests = g_list_append (dest->priv->list_dests, list_dest); - e_iterator_next (iter); - } - } - - return dest->priv->list_dests != NULL; -} - -gboolean -e_destination_get_html_mail_pref (const EDestination *dest) -{ - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - - if (dest->priv->html_mail_override || dest->priv->card == NULL) - return dest->priv->wants_html_mail; - - return dest->priv->card->wants_html; -} - -gchar * -e_destination_get_address_textv (EDestination **destv) -{ - gint i, j, len = 0; - gchar **strv; - gchar *str; - - g_return_val_if_fail (destv, NULL); - - /* Q: Please tell me this is only for assertion - reasons. If this is considered to be ok behavior then you - shouldn't use g_return's. Just a reminder ;-) - - A: Yes, this is just an assertion. (Though it does find the - length of the vector in the process...) - */ - while (destv[len]) { - g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL); - ++len; - } - - strv = g_new0 (gchar *, len+1); - for (i = 0, j = 0; destv[i]; i++) { - if (!e_destination_is_empty (destv[i])) { - const gchar *addr = e_destination_get_address (destv[i]); - strv[j++] = addr ? (gchar *) addr : ""; - } - } - - str = g_strjoinv (", ", strv); - - g_free (strv); - - return str; -} - -xmlNodePtr -e_destination_xml_encode (const EDestination *dest) -{ - xmlNodePtr dest_node; - const gchar *str; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - dest_node = xmlNewNode (NULL, "destination"); - - str = e_destination_get_name (dest); - if (str) - xmlNewTextChild (dest_node, NULL, "name", str); - - if (! e_destination_is_evolution_list (dest)) { - str = e_destination_get_email (dest); - if (str) - xmlNewTextChild (dest_node, NULL, "email", str); - } else { - GList *iter = dest->priv->list_dests; - - while (iter) { - EDestination *list_dest = E_DESTINATION (iter->data); - xmlNodePtr list_node = xmlNewNode (NULL, "list_entry"); - - str = e_destination_get_name (list_dest); - if (str) - xmlNewTextChild (list_node, NULL, "name", str); - - str = e_destination_get_email (list_dest); - if (str) - xmlNewTextChild (list_node, NULL, "email", str); - - xmlAddChild (dest_node, list_node); - - iter = g_list_next (iter); - } - - xmlNewProp (dest_node, "is_list", "yes"); - } - - str = e_destination_get_card_uri (dest); - if (str) { - gchar buf[16]; - xmlNodePtr uri_node = xmlNewTextChild (dest_node, NULL, "card_uri", str); - g_snprintf (buf, 16, "%d", e_destination_get_email_num (dest)); - xmlNewProp (uri_node, "email_num", buf); - } - - xmlNewProp (dest_node, "html_mail", e_destination_get_html_mail_pref (dest) ? "yes" : "no"); - - return dest_node; -} - -gboolean -e_destination_xml_decode (EDestination *dest, xmlNodePtr node) -{ - gchar *name = NULL, *email = NULL, *card_uri = NULL; - gint email_num = -1; - gboolean html_mail = FALSE; - gboolean is_list = FALSE; - gchar *tmp; - GList *list_dests = NULL; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - g_return_val_if_fail (node != NULL, FALSE); - - if (strcmp (node->name, "destination")) - return FALSE; - - tmp = xmlGetProp (node, "html_mail"); - if (tmp) { - html_mail = !strcmp (tmp, "yes"); - xmlFree (tmp); - } - - tmp = xmlGetProp (node, "is_list"); - if (tmp) { - is_list = !strcmp (tmp, "yes"); - xmlFree (tmp); - } - - node = node->xmlChildrenNode; - while (node) { - if (!strcmp (node->name, "name")) { - tmp = xmlNodeGetContent (node); - g_free (name); - name = g_strdup (tmp); - xmlFree (tmp); - } else if (!is_list && !strcmp (node->name, "email")) { - tmp = xmlNodeGetContent (node); - g_free (email); - email = g_strdup (tmp); - xmlFree (tmp); - } else if (is_list && !strcmp (node->name, "list_entry")) { - xmlNodePtr subnode = node->xmlChildrenNode; - gchar *list_name = NULL, *list_email = NULL; - - while (subnode) { - if (!strcmp (subnode->name, "name")) { - tmp = xmlNodeGetContent (subnode); - g_free (list_name); - list_name = g_strdup (tmp); - xmlFree (tmp); - } else if (!strcmp (subnode->name, "email")) { - tmp = xmlNodeGetContent (subnode); - g_free (list_email); - list_email = g_strdup (tmp); - xmlFree (tmp); - } - - subnode = subnode->next; - } - - if (list_name || list_email) { - EDestination *list_dest = e_destination_new (); - if (list_name) - e_destination_set_name (list_dest, list_name); - if (list_email) - e_destination_set_email (list_dest, list_email); - - list_dests = g_list_append (list_dests, list_dest); - } - } else if (!strcmp (node->name, "card_uri")) { - tmp = xmlNodeGetContent (node); - g_free (card_uri); - card_uri = g_strdup (tmp); - xmlFree (tmp); - - tmp = xmlGetProp (node, "email_num"); - email_num = atoi (tmp); - xmlFree (tmp); - } - - node = node->next; - } - - e_destination_clear (dest); - - if (name) - e_destination_set_name (dest, name); - if (email) - e_destination_set_email (dest, email); - if (card_uri) - e_destination_set_card_uri (dest, card_uri, email_num); - if (list_dests) - dest->priv->list_dests = list_dests; - - return TRUE; -} - -/* FIXME: Make utf-8 safe */ -static gchar * -null_terminate_and_remove_extra_whitespace (xmlChar *xml_in, gint size) -{ - gchar *xml; - gchar *r, *w; - gboolean skip_white = FALSE; - - if (xml_in == NULL || size <= 0) - return NULL; - - xml = g_strndup (xml_in, size); - r = w = xml; - - while (*r) { - if (*r == '\n' || *r == '\r') { - skip_white = TRUE; - } else { - gboolean is_space = isspace (*r); - - *w = *r; - - if (! (skip_white && is_space)) - ++w; - if (! is_space) - skip_white = FALSE; - } - ++r; - } - - *w = '\0'; - - return xml; -} - -gchar * -e_destination_export (const EDestination *dest) -{ - xmlNodePtr dest_node; - xmlDocPtr dest_doc; - xmlChar *buffer = NULL; - gint size = -1; - gchar *str; - - g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - - dest_node = e_destination_xml_encode (dest); - if (dest_node == NULL) - return NULL; - - dest_doc = xmlNewDoc (XML_DEFAULT_VERSION); - xmlDocSetRootElement (dest_doc, dest_node); - - xmlDocDumpMemory (dest_doc, &buffer, &size); - xmlFreeDoc (dest_doc); - - str = null_terminate_and_remove_extra_whitespace (buffer, size); - xmlFree (buffer); - - return str; -} - -EDestination * -e_destination_import (const gchar *str) -{ - EDestination *dest = NULL; - xmlDocPtr dest_doc; - - if (! (str && *str)) - return NULL; - - dest_doc = xmlParseMemory ((gchar *) str, strlen (str)); - if (dest_doc && dest_doc->xmlRootNode) { - dest = e_destination_new (); - if (! e_destination_xml_decode (dest, dest_doc->xmlRootNode)) { - gtk_object_unref (GTK_OBJECT (dest)); - dest = NULL; - } - } - xmlFreeDoc (dest_doc); - - return dest; -} - -gchar * -e_destination_exportv (EDestination **destv) -{ - xmlDocPtr destv_doc; - xmlNodePtr destv_node; - xmlChar *buffer = NULL; - gint size = -1; - gchar *str; - gint i; - - if (destv == NULL || *destv == NULL) - return NULL; - - destv_doc = xmlNewDoc (XML_DEFAULT_VERSION); - destv_node = xmlNewNode (NULL, "destinations"); - xmlDocSetRootElement (destv_doc, destv_node); - - for (i=0; destv[i]; ++i) { - if (! e_destination_is_empty (destv[i])) { - xmlNodePtr dest_node = e_destination_xml_encode (destv[i]); - if (dest_node) - xmlAddChild (destv_node, dest_node); - } - } - - xmlDocDumpMemory (destv_doc, &buffer, &size); - xmlFreeDoc (destv_doc); - - str = null_terminate_and_remove_extra_whitespace (buffer, size); - xmlFree (buffer); - - return str; -} - -EDestination ** -e_destination_importv (const gchar *str) -{ - GPtrArray *dest_array = NULL; - xmlDocPtr destv_doc; - xmlNodePtr node; - EDestination **destv = NULL; - - if (!(str && *str)) - return NULL; - - destv_doc = xmlParseMemory ((gchar *)str, strlen (str)); - if (destv_doc == NULL) - return NULL; - - node = destv_doc->xmlRootNode; - - if (strcmp (node->name, "destinations")) - goto finished; - - node = node->xmlChildrenNode; - - dest_array = g_ptr_array_new (); - - while (node) { - EDestination *dest; - - dest = e_destination_new (); - if (e_destination_xml_decode (dest, node)) { - g_ptr_array_add (dest_array, dest); - } else { - gtk_object_unref (GTK_OBJECT (dest)); - } - - node = node->next; - } - - /* we need destv to be NULL terminated */ - g_ptr_array_add (dest_array, NULL); - - destv = (EDestination **) dest_array->pdata; - g_ptr_array_free (dest_array, FALSE); - - finished: - xmlFreeDoc (destv_doc); - - return destv; -} - -static void -touch_cb (EBook *book, const gchar *addr, ECard *card, gpointer closure) -{ - if (book != NULL && card != NULL) { - e_card_touch (card); - g_message ("Use score for \"%s\" is now %f", addr, e_card_get_use_score (card)); - e_book_commit_card (book, card, NULL, NULL); - } -} - -void -e_destination_touch (EDestination *dest) -{ - const gchar *email; - - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - email = e_destination_get_email (dest); - - if (email) { - e_book_query_address_locally (email, touch_cb, NULL); - } -} diff --git a/addressbook/backend/ebook/e-destination.h b/addressbook/backend/ebook/e-destination.h deleted file mode 100644 index 96a3989d9a..0000000000 --- a/addressbook/backend/ebook/e-destination.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-destination.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#ifndef __E_DESTINATION_H__ -#define __E_DESTINATION_H__ - -#include <gtk/gtkobject.h> -#include <addressbook/backend/ebook/e-card.h> -#include <addressbook/backend/ebook/e-book.h> -#include <gnome-xml/tree.h> - -#define E_TYPE_DESTINATION (e_destination_get_type ()) -#define E_DESTINATION(o) (GTK_CHECK_CAST ((o), E_TYPE_DESTINATION, EDestination)) -#define E_DESTINATION_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), E_TYPE_DESTINATION, EDestinationClass)) -#define E_IS_DESTINATION(o) (GTK_CHECK_TYPE ((o), E_TYPE_DESTINATION)) -#define E_IS_DESTINATION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TYPE_DESTINATION)) - -typedef struct _EDestination EDestination; -typedef struct _EDestinationClass EDestinationClass; - -typedef void (*EDestinationCardCallback) (EDestination *dest, ECard *card, gpointer closure); - -struct _EDestinationPrivate; - -struct _EDestination { - GtkObject object; - - struct _EDestinationPrivate *priv; -}; - -struct _EDestinationClass { - GtkObjectClass parent_class; -}; - -GtkType e_destination_get_type (void); - - -EDestination *e_destination_new (void); -EDestination *e_destination_copy (const EDestination *); -void e_destination_clear (EDestination *); - -gboolean e_destination_is_empty (const EDestination *); - -void e_destination_set_card (EDestination *, ECard *card, gint email_num); -void e_destination_set_card_uri (EDestination *, const gchar *uri, gint email_num); - -void e_destination_set_name (EDestination *, const gchar *name); -void e_destination_set_email (EDestination *, const gchar *email); - -void e_destination_set_html_mail_pref (EDestination *, gboolean); - -gboolean e_destination_contains_card (const EDestination *); -gboolean e_destination_from_card (const EDestination *); - -void e_destination_use_card (EDestination *, EDestinationCardCallback cb, gpointer closure); - -ECard *e_destination_get_card (const EDestination *); -const gchar *e_destination_get_card_uri (const EDestination *); -gint e_destination_get_email_num (const EDestination *); - -const gchar *e_destination_get_name (const EDestination *); /* "Jane Smith" */ -const gchar *e_destination_get_email (const EDestination *); /* "jane@assbarn.com" */ -const gchar *e_destination_get_address (const EDestination *); /* "Jane Smith <jane@assbarn.com>" (or a comma-sep set of such for a list) */ - -void e_destination_set_raw (EDestination *, const gchar *free_form_string); -const gchar *e_destination_get_textrep (const EDestination *); /* "Jane Smith" or "jane@assbarn.com" */ - -gboolean e_destination_is_evolution_list (const EDestination *); - -/* If true, they want HTML mail. */ -gboolean e_destination_get_html_mail_pref (const EDestination *); - -gchar *e_destination_get_address_textv (EDestination **); - -xmlNodePtr e_destination_xml_encode (const EDestination *dest); -gboolean e_destination_xml_decode (EDestination *dest, xmlNodePtr node); - -gchar *e_destination_export (const EDestination *); -EDestination *e_destination_import (const gchar *str); - -gchar *e_destination_exportv (EDestination **); -EDestination **e_destination_importv (const gchar *str); - -void e_destination_touch (EDestination *); - - -#endif /* __E_DESTINATION_H__ */ - diff --git a/addressbook/backend/ebook/evolution-vcard-importer.c b/addressbook/backend/ebook/evolution-vcard-importer.c deleted file mode 100644 index c838fbc1d7..0000000000 --- a/addressbook/backend/ebook/evolution-vcard-importer.c +++ /dev/null @@ -1,257 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#include <config.h> -#include <stdio.h> - -#include <liboaf/liboaf.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-main.h> - -#include <e-book.h> - -#include <importer/evolution-importer.h> -#include <importer/GNOME_Evolution_Importer.h> - -#include <e-util/e-path.h> - -#define COMPONENT_FACTORY_IID "OAFIID:GNOME_Evolution_Addressbook_VCard_ImporterFactory" - -static BonoboGenericFactory *factory = NULL; - -typedef struct { - char *filename; - char *folderpath; - GList *cardlist; - GList *iterator; - EBook *book; - gboolean ready; -} VCardImporter; - -static void -add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) -{ - ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); - - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - VCardImporter *gci = (VCardImporter *) closure; - - gci->cardlist = e_card_load_cards_from_file(gci->filename); - gci->ready = TRUE; -} - -static void -ebook_create (VCardImporter *gci) -{ - gchar *path, *uri; - gchar *epath; - - gci->book = e_book_new (); - - if (!gci->book) { - printf ("%s: %s(): Couldn't create EBook, bailing.\n", - __FILE__, - __FUNCTION__); - return; - } - - path = g_concat_dir_and_file (g_get_home_dir (), "evolution/local"); - uri = g_strdup_printf ("file://%s", path); - g_free (path); - - epath = e_path_to_physical (uri, gci->folderpath); - g_free (uri); - uri = g_strdup_printf ("%s/addressbook.db", epath); - g_free (epath); - - if (! e_book_load_uri (gci->book, uri, book_open_cb, gci)) { - printf ("error calling load_uri!\n"); - } - g_free(uri); -} - -/* EvolutionImporter methods */ -static void -process_item_fn (EvolutionImporter *importer, - CORBA_Object listener, - void *closure, - CORBA_Environment *ev) -{ - VCardImporter *gci = (VCardImporter *) closure; - ECard *card; - - if (gci->iterator == NULL) - gci->iterator = gci->cardlist; - - if (gci->ready == FALSE) { - GNOME_Evolution_ImporterListener_notifyResult (listener, - GNOME_Evolution_ImporterListener_NOT_READY, - gci->iterator ? TRUE : FALSE, - ev); - return; - } - - if (gci->iterator == NULL) { - GNOME_Evolution_ImporterListener_notifyResult (listener, - GNOME_Evolution_ImporterListener_UNSUPPORTED_OPERATION, - FALSE, ev); - return; - } - - card = gci->iterator->data; - e_book_add_card (gci->book, card, add_card_cb, card); - - gci->iterator = gci->iterator->next; - - GNOME_Evolution_ImporterListener_notifyResult (listener, - GNOME_Evolution_ImporterListener_OK, - gci->iterator ? TRUE : FALSE, - ev); - if (ev->_major != CORBA_NO_EXCEPTION) { - g_warning ("Error notifying listeners."); - } - - return; -} - -static char *supported_extensions[3] = { - ".vcf", - ".gcrd", - NULL -}; - -/* Actually check the contents of this file */ -static gboolean -check_file_is_vcard (const char *filename) -{ - FILE *handle; - char line[4096]; - gboolean result; - - handle = fopen (filename, "r"); - if (handle == NULL) { - return FALSE; - } - - fgets (line, 4096, handle); - if (line == NULL) { - fclose (handle); - return FALSE; - } - - if (strcmp (line, "BEGIN:VCARD") == 0) { - result = TRUE; - } else { - result = FALSE; - } - - fclose (handle); - return result; -} - -static gboolean -support_format_fn (EvolutionImporter *importer, - const char *filename, - void *closure) -{ - char *ext; - int i; - - ext = strrchr (filename, '.'); - if (ext == NULL) { - return check_file_is_vcard (filename); - } - for (i = 0; supported_extensions[i] != NULL; i++) { - if (strcmp (supported_extensions[i], ext) == 0) - return check_file_is_vcard (filename); - } - - return FALSE; -} - -static void -importer_destroy_cb (GtkObject *object, - VCardImporter *gci) -{ - gtk_main_quit (); -} - -static gboolean -load_file_fn (EvolutionImporter *importer, - const char *filename, - const char *folderpath, - void *closure) -{ - VCardImporter *gci; - - gci = (VCardImporter *) closure; - gci->filename = g_strdup (filename); - gci->folderpath = g_strdup (folderpath); - gci->cardlist = NULL; - gci->iterator = NULL; - gci->ready = FALSE; - ebook_create (gci); - - return TRUE; -} - -static BonoboObject * -factory_fn (BonoboGenericFactory *_factory, - void *closure) -{ - EvolutionImporter *importer; - VCardImporter *gci; - - gci = g_new (VCardImporter, 1); - importer = evolution_importer_new (support_format_fn, load_file_fn, - process_item_fn, NULL, gci); - - gtk_signal_connect (GTK_OBJECT (importer), "destroy", - GTK_SIGNAL_FUNC (importer_destroy_cb), gci); - - return BONOBO_OBJECT (importer); -} - -static void -importer_init (void) -{ - if (factory != NULL) - return; - - factory = bonobo_generic_factory_new (COMPONENT_FACTORY_IID, - factory_fn, NULL); - - if (factory == NULL) { - g_error ("Unable to create factory"); - } - - bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory)); -} - -int -main (int argc, - char **argv) -{ - CORBA_ORB orb; - - gnome_init_with_popt_table ("Evolution-VCard-Importer", - PACKAGE, argc, argv, oaf_popt_options, 0, - NULL); - orb = oaf_init (argc, argv); - if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) { - g_error ("Could not initialize Bonobo."); - } - - importer_init (); - bonobo_main (); - - return 0; -} - - diff --git a/addressbook/backend/ebook/load-gnomecard-addressbook.c b/addressbook/backend/ebook/load-gnomecard-addressbook.c deleted file mode 100644 index 5d16a26a7c..0000000000 --- a/addressbook/backend/ebook/load-gnomecard-addressbook.c +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#include <config.h> -#include <stdio.h> -#include <glib.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-init.h> -#include <bonobo/bonobo-main.h> -#include <liboaf/liboaf.h> - -#include "e-book.h" - -static CORBA_Environment ev; - -static void -init_bonobo (int argc, char **argv) -{ - if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); -} - -static void -add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) -{ - ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); - g_print ("Saved card: %s\n", vcard); - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - GList *list = e_card_load_cards_from_file("gnomecard.vcf"); - GList *iterator; - for (iterator = list; iterator; iterator = g_list_next(iterator)) { - ECard *card = iterator->data; - e_book_add_card(book, card, add_card_cb, card); - } - g_list_free(list); -} - -static guint -ebook_create (void) -{ - EBook *book; - gchar *path, *uri; - - book = e_book_new (); - - if (!book) { - printf ("%s: %s(): Couldn't create EBook, bailing.\n", - __FILE__, - __FUNCTION__); - return FALSE; - } - - - path = g_concat_dir_and_file (g_get_home_dir (), - "evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf ("file://%s", path); - g_free (path); - - if (! e_book_load_uri (book, uri, book_open_cb, NULL)) { - printf ("error calling load_uri!\n"); - } - g_free(uri); - - - return FALSE; -} - -int -main (int argc, char **argv) -{ - - CORBA_exception_init (&ev); - - gnome_init_with_popt_table("blah", "0.0", argc, argv, NULL, 0, NULL); - oaf_init (argc, argv); - init_bonobo (argc, argv); - - gtk_idle_add ((GtkFunction) ebook_create, NULL); - - bonobo_main (); - - return 0; -} diff --git a/addressbook/backend/ebook/load-pine-addressbook.c b/addressbook/backend/ebook/load-pine-addressbook.c deleted file mode 100644 index 2c18efb7c8..0000000000 --- a/addressbook/backend/ebook/load-pine-addressbook.c +++ /dev/null @@ -1,172 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#include <config.h> -#include <ctype.h> -#include <stdio.h> -#include <glib.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-init.h> -#include <bonobo/bonobo-main.h> -#include <liboaf/liboaf.h> - -#include "e-book.h" - -static CORBA_Environment ev; - -static void -init_bonobo (int argc, char **argv) -{ - if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); -} - -static void -add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) -{ - ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); - g_print ("Saved card: %s\n", vcard); - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); -} - -static void -parse_line (EBook *book, char *line) -{ - char **strings; - ECardName *name; - ECard *card; - EList *list; - - card = e_card_new(""); - strings = g_strsplit(line, "\t", 3); - if (strings[0] && strings[1] && strings[2]) { - name = e_card_name_from_string(strings[1]); - gtk_object_set(GTK_OBJECT(card), - "nickname", strings[0], - "full_name", strings[1], - "name", name, - NULL); - gtk_object_get(GTK_OBJECT(card), - "email", &list, - NULL); - e_list_append(list, strings[2]); - g_strfreev(strings); - e_book_add_card(book, card, add_card_cb, card); - } -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - FILE *fp = fopen (".addressbook", "r"); - char line[2 * 1024]; - int which = 0; - char *lastline = NULL; - - if (!fp) { - g_warning ("Can't find .addressbook"); - return; - } - - while(fgets(line + which * 1024, 1024, fp)) { - int length; - char *thisline = line + which * 1024; - length = strlen(thisline); - if (thisline[length - 1] == '\n') - line[--length] = 0; - if (lastline && *thisline && isspace(*thisline)) { - char *temp; - while(*thisline && isspace(*thisline)) - thisline ++; - temp = lastline; - lastline = g_strdup_printf("%s%s", lastline, thisline); - g_free(temp); - continue; - } - if (lastline) { - parse_line (book, lastline); - g_free(lastline); - } - lastline = g_strdup(thisline); - } - - if (lastline) { - parse_line (book, lastline); - g_free(lastline); - } -} - -static guint -ebook_create (void) -{ - EBook *book; - gchar *path, *uri; - - book = e_book_new (); - - if (!book) { - printf ("%s: %s(): Couldn't create EBook, bailing.\n", - __FILE__, - __FUNCTION__); - return FALSE; - } - - - path = g_concat_dir_and_file (g_get_home_dir (), - "evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf ("file://%s", path); - g_free (path); - - if (! e_book_load_uri (book, uri, book_open_cb, NULL)) { - printf ("error calling load_uri!\n"); - } - g_free(uri); - - - return FALSE; -} - -#if 0 -static char * -read_file (char *name) -{ - int len; - char buff[65536]; - char line[1024]; - FILE *f; - - f = fopen (name, "r"); - if (f == NULL) - g_error ("Unable to open %s!\n", name); - - len = 0; - while (fgets (line, sizeof (line), f) != NULL) { - strcpy (buff + len, line); - len += strlen (line); - } - - fclose (f); - - return g_strdup (buff); -} -#endif - -int -main (int argc, char **argv) -{ - - CORBA_exception_init (&ev); - - gnome_init_with_popt_table("blah", "0.0", argc, argv, NULL, 0, NULL); - oaf_init (argc, argv); - init_bonobo (argc, argv); - - gtk_idle_add ((GtkFunction) ebook_create, NULL); - - bonobo_main (); - - return 0; -} diff --git a/addressbook/backend/ebook/test-card.c b/addressbook/backend/ebook/test-card.c deleted file mode 100644 index 239ce4069f..0000000000 --- a/addressbook/backend/ebook/test-card.c +++ /dev/null @@ -1,196 +0,0 @@ -#include <string.h> -#include <libgnome/gnome-defs.h> -#include <libgnomeui/gnome-init.h> -#include "e-card.h" - -#define TEST_VCARD \ -"BEGIN:VCARD -" \ -"FN:Nat -" \ -"N:Friedman;Nat;D;Mr. -" \ -"ORG:Ximian, Inc. -" \ -"TITLE:Head Geek -" \ -"ROLE:Programmer/Executive -" \ -"BDAY:1977-08-06 -" \ -"TEL;WORK:617 679 1984 -" \ -"TEL;CELL:123 456 7890 -" \ -"EMAIL;INTERNET:nat@nat.org -" \ -"EMAIL;INTERNET:nat@ximian.com -" \ -"ADR;WORK;POSTAL:P.O. Box 101;;;Any Town;CA;91921-1234; -" \ -"ADR;HOME;POSTAL;INTL:P.O. Box 202;;;Any Town 2;MI;12344-4321;USA -" \ -"END:VCARD -" \ -" -" - -static char * -read_file (char *name) -{ - int len; - char buff[65536]; - char line[1024]; - FILE *f; - - f = fopen (name, "r"); - if (f == NULL) - g_error ("Unable to open %s!\n", name); - - len = 0; - while (fgets (line, sizeof (line), f) != NULL) { - strcpy (buff + len, line); - len += strlen (line); - } - - fclose (f); - - return g_strdup (buff); -} - - - -int -main (int argc, char **argv) -{ - char *cardstr; - ECard *card; - - /* Fields */ - char *fname; - char *org; - char *org_unit; - char *title; - char *role; - char *nickname; - char *fburl; - ECardName *name; - EList *address; - EList *phone; - EList *email; - EIterator *iterator; - ECardDate *bday; - - gnome_init ("TestCard", "0.0", argc, argv); - - cardstr = NULL; - if (argc == 2) - cardstr = read_file (argv [1]); - - if (cardstr == NULL) - cardstr = TEST_VCARD; -#if 0 - { - int i; - for ( i = 0; i < 100000; i++ ) { - card = e_card_new (cardstr); - - gtk_object_unref (GTK_OBJECT (card)); - } - } -#endif - card = e_card_new (cardstr); - gtk_object_get(GTK_OBJECT(card), - "full_name", &fname, - "name", &name, - "address", &address, - "phone", &phone, - "email", &email, - "org", &org, - "org_unit", &org_unit, - "title", &title, - "role", &role, - "nickname", &nickname, - "fburl", &fburl, - "birth_date", &bday, - NULL); - if ( fname ) { - printf("Name : %s\n", fname); - g_free(fname); - } - if ( name ) { - printf("Full Name:\n"); - if ( name->prefix ) - printf(" prefix : %s\n", name->prefix); - if ( name->given ) - printf(" given : %s\n", name->given); - if ( name->additional ) - printf(" additional : %s\n", name->additional); - if ( name->family ) - printf(" family : %s\n", name->family); - if ( name->suffix ) - printf(" suffix : %s\n", name->suffix); - } - if ( org ) { - printf("Company : %s\n", org); - } - if ( org_unit ) { - printf("Department : %s\n", org_unit); - } - if ( title ) { - printf("Title : %s\n", title); - } - if ( role ) { - printf("Profession : %s\n", role); - } - if ( nickname ) { - printf("Nickname : %s\n", nickname); - } - if ( fburl ) { - printf("Free Busy URL : %s\n", fburl); - } - if ( bday ) { - printf("BDay : %4d-%02d-%02d\n", bday->year, bday->month, bday->day); - } - if ( email ) { - iterator = e_list_get_iterator(address); - for (; e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - printf("Email : %s\n", (char *) e_iterator_get(iterator)); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - if ( phone ) { - iterator = e_list_get_iterator(address); - for (; e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - ECardPhone *e_card_phone = (ECardPhone *) e_iterator_get(iterator); - printf("Phone ; %d : %s\n", e_card_phone->flags, e_card_phone->number); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - if ( address ) { - iterator = e_list_get_iterator(address); - for (; e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - ECardDeliveryAddress *del_address = (ECardDeliveryAddress *) e_iterator_get(iterator); - printf("Address ; %d:\n", del_address->flags); - if ( del_address->po ) - printf(" Po : %s\n", del_address->po); - if ( del_address->ext ) - printf(" Ext : %s\n", del_address->ext); - if ( del_address->street ) - printf(" Street : %s\n", del_address->street); - if ( del_address->city ) - printf(" City : %s\n", del_address->city); - if ( del_address->region ) - printf(" Region : %s\n", del_address->region); - if ( del_address->code ) - printf(" Code : %s\n", del_address->code); - if ( del_address->country ) - printf(" Country : %s\n", del_address->country); - } - gtk_object_unref(GTK_OBJECT(iterator)); - } - printf("%s", e_card_get_vcard(card)); - gtk_object_unref (GTK_OBJECT (card)); - - return 0; -} diff --git a/addressbook/backend/ebook/test-client-list.c b/addressbook/backend/ebook/test-client-list.c deleted file mode 100644 index 0de62d701c..0000000000 --- a/addressbook/backend/ebook/test-client-list.c +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#include <config.h> - -#include <glib.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-init.h> -#include <liboaf/liboaf.h> -#include <bonobo/bonobo-main.h> - -#include "e-book.h" - -CORBA_Environment ev; - -static void -init_bonobo (int argc, char **argv) -{ - gnome_init ("blah", "0.0", argc, argv); - oaf_init (argc, argv); - - if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); -} - -static void -get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure) -{ - long length = e_card_cursor_get_length(cursor); - long i; - - printf ("Length: %d\n", (int) length); - for ( i = 0; i < length; i++ ) { - ECard *card = e_card_cursor_get_nth(cursor, i); - char *vcard = e_card_get_vcard(card); - printf("[%s]\n", vcard); - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); - } -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - printf ("Book opened.\n"); - e_book_get_cursor(book, "", get_cursor_cb, NULL); -} - -static guint -ebook_create (void) -{ - EBook *book; - - book = e_book_new (); - - if (! e_book_load_uri (book, "file:/tmp/test.db", book_open_cb, NULL)) { - printf ("error calling load_uri!\n"); - } - - - return FALSE; -} - -int -main (int argc, char **argv) -{ - - CORBA_exception_init (&ev); - init_bonobo (argc, argv); - - gtk_idle_add ((GtkFunction) ebook_create, NULL); - - bonobo_main (); - - return 0; -} diff --git a/addressbook/backend/ebook/test-client.c b/addressbook/backend/ebook/test-client.c deleted file mode 100644 index 6ffa099ab3..0000000000 --- a/addressbook/backend/ebook/test-client.c +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#include <config.h> -#include <glib.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-init.h> -#include <bonobo/bonobo-main.h> -#include <liboaf/liboaf.h> - -#include "e-book.h" - -#define TEST_VCARD \ -"BEGIN:VCARD -" \ -"FN:Nat -" \ -"N:Friedman;Nat;D;Mr. -" \ -"BDAY:1977-08-06 -" \ -"TEL;WORK:617 679 1984 -" \ -"TEL;CELL:123 456 7890 -" \ -"EMAIL;INTERNET:nat@nat.org -" \ -"EMAIL;INTERNET:nat@ximian.com -" \ -"ADR;WORK;POSTAL:P.O. Box 101;;;Any Town;CA;91921-1234; -" \ -"END:VCARD -" \ -" -" - -static CORBA_Environment ev; -static char *cardstr; - -static void -init_bonobo (int argc, char **argv) -{ - if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); -} - -static void -get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure) -{ - long length = e_card_cursor_get_length(cursor); - long i; - - /* we just added a card, so the length should be >1 */ - printf ("\n%s: %s(): Number of cards is %ld\n", - __FILE__, __FUNCTION__, length); - if (length < 1) - printf ("*** Why isn't this above zero?? ***\n\n"); - - for ( i = 0; i < length; i++ ) { - ECard *card = e_card_cursor_get_nth(cursor, i); - char *vcard = e_card_get_vcard(card); - printf("Get all cards callback: [%s]\n", vcard); - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); - } -} - -static void -add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) -{ - char *vcard; - ECard *card; - GTimer *timer; - - printf ("Status: %d\n", status); - - printf ("Id: %s\n", id); - - timer = g_timer_new (); - g_timer_start (timer); - card = e_book_get_card (book, id); - g_timer_stop (timer); - - vcard = e_card_get_vcard(card); - printf ("%g\n", g_timer_elapsed (timer, NULL)); - printf ("Card added: [%s]\n", vcard); - g_free(vcard); - gtk_object_unref(GTK_OBJECT(card)); - - printf ("Getting cards..\n"); - e_book_get_cursor(book, "", get_cursor_cb, NULL); - printf ("Done getting all cards.\n"); -} - -static void -get_fields_cb (EBook *book, EBookStatus status, EList *fields, gpointer closure) -{ - if (fields) { - EIterator *iter = e_list_get_iterator (fields); - - printf ("Supported fields:\n"); - - for (; e_iterator_is_valid (iter); e_iterator_next (iter)) { - printf (" %s\n", (char*)e_iterator_get (iter)); - } - - gtk_object_unref(GTK_OBJECT(fields)); - } - else { - printf ("No supported fields?\n"); - } - - e_book_add_vcard(book, cardstr, add_card_cb, NULL); -} - - -static void -auth_user_cb (EBook *book, EBookStatus status, gpointer closure) -{ - printf ("user authenticated\n"); - e_book_get_supported_fields (book, get_fields_cb, closure); -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - e_book_authenticate_user (book, "username", "password", auth_user_cb, NULL); -} - -static guint -ebook_create (void) -{ - EBook *book; - - book = e_book_new (); - - if (!book) { - printf ("%s: %s(): Couldn't create EBook, bailing.\n", - __FILE__, - __FUNCTION__); - return FALSE; - } - - - if (! e_book_load_uri (book, "file:/tmp/test.db", book_open_cb, NULL)) { - printf ("error calling load_uri!\n"); - } - - - return FALSE; -} - -static char * -read_file (char *name) -{ - int len; - char buff[65536]; - char line[1024]; - FILE *f; - - f = fopen (name, "r"); - if (f == NULL) - g_error ("Unable to open %s!\n", name); - - len = 0; - while (fgets (line, sizeof (line), f) != NULL) { - strcpy (buff + len, line); - len += strlen (line); - } - - fclose (f); - - return g_strdup (buff); -} - - -int -main (int argc, char **argv) -{ - - CORBA_exception_init (&ev); - - gnome_init_with_popt_table ("blah", "0.0", argc, argv, NULL, 0, NULL); - oaf_init (argc, argv); - init_bonobo (argc, argv); - - cardstr = NULL; - if (argc == 2) - cardstr = read_file (argv [1]); - - if (cardstr == NULL) - cardstr = TEST_VCARD; - - gtk_idle_add ((GtkFunction) ebook_create, NULL); - - bonobo_main (); - - return 0; -} |