adapted to Sync4j C++ client API 3.x

git-svn-id: https://zeitsenke.de/svn/SyncEvolution/trunk@5 15ad00c4-1369-45f4-8270-35d70d36bdcd
This commit is contained in:
Patrick Ohly 2005-11-25 20:53:04 +00:00
parent 29ae19e174
commit 3a81621f3e
8 changed files with 48 additions and 34 deletions

View File

@ -1,7 +1,8 @@
Basic Installation
==================
These are generic installation instructions.
These are generic installation instructions. Specific installation
instructions for Sync4jEvolution are in the README file.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses

14
README
View File

@ -138,3 +138,17 @@ If the Evolution data source requires authentication, the
"evolutionuser" and "evolutionpassword" are used as credentials. In
this case the directory that contains the source's config.txt should
only be accessible by the user.
Compiling from Source
---------------------
To compile the code the 3.x version of the Sync4j C++
client library is needed. Also needed are the Evolution
development files. The code was tested with Evolution
2.0.4 and it is unclear which other versions it is
compatible with.
The build system is the normal autotools system.
See INSTALL for general instructions how to use that
and "./configure --help" for Sync4jEvolution specific
options.

2
configure vendored
View File

@ -1921,7 +1921,7 @@ INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s"
# Check whether --with-sync4j or --without-sync4j was given.
if test "${with_sync4j+set}" = set; then
withval="$with_sync4j"
SYNC4J_CFLAGS="-I$withval/include/sync4j"; SYNC4J_LIBS="-L$withval/lib"
SYNC4J_CFLAGS="-I$withval/include/sync4j/common -I$withval/include/sync4j"; SYNC4J_LIBS="-L$withval/lib"
fi;
SYNC4J_LIBS="${SYNC4J_LIBS} -lsync4j"

View File

@ -7,7 +7,7 @@ AM_CONFIG_HEADER(config.h)
AC_ARG_WITH(sync4j,
AS_HELP_STRING([--with-sync4j=<base directory>],
[specifies location of Sync4j client library]),
[SYNC4J_CFLAGS="-I$withval/include/sync4j"; SYNC4J_LIBS="-L$withval/lib"])
[SYNC4J_CFLAGS="-I$withval/include/sync4j/common -I$withval/include/sync4j"; SYNC4J_LIBS="-L$withval/lib"])
SYNC4J_LIBS="${SYNC4J_LIBS} -lsync4j"
AC_SUBST(SYNC4J_CFLAGS)
AC_SUBST(SYNC4J_LIBS)

View File

@ -139,7 +139,7 @@ void EvolutionContactSource::close()
}
SyncItem *EvolutionContactSource::createItem( const string &uid )
SyncItem *EvolutionContactSource::createItem( const string &uid, SyncState state )
{
// this function must never throw an exception
// because it is called inside the Sync4j C++ API library
@ -162,8 +162,10 @@ SyncItem *EvolutionContactSource::createItem( const string &uid )
}
auto_ptr<SyncItem> item( new SyncItem( uid.c_str() ) );
item->setData( vcardstr, strlen( vcardstr ) + 1 );
item->setData( vcardstr, strlen( vcardstr ) );
item->setDataType( getMimeType() );
item->setModificationTime( 0 );
item->setState( state );
return item.release();
} catch (...) {
@ -173,14 +175,11 @@ SyncItem *EvolutionContactSource::createItem( const string &uid )
return NULL;
}
void EvolutionContactSource::setSyncItemStatus(char *key, int status)
{
}
int EvolutionContactSource::addItem(SyncItem& item)
{
try {
gptr<EContact, GObject> contact( e_contact_new_from_vcard( (const char *)item.getData() ) );
string data = getData(item);
gptr<EContact, GObject> contact(e_contact_new_from_vcard(data.c_str()));
if( contact ) {
GError *gerror = NULL;
e_contact_set(contact, E_CONTACT_UID, NULL);
@ -190,7 +189,7 @@ int EvolutionContactSource::addItem(SyncItem& item)
throwError( "storing new contact", gerror );
}
} else {
throwError( string( "parsing vcard" ) + (const char *)item.getData(),
throwError( string( "parsing vcard" ) + data,
NULL );
}
} catch ( ... ) {
@ -202,20 +201,21 @@ int EvolutionContactSource::addItem(SyncItem& item)
int EvolutionContactSource::updateItem(SyncItem& item)
{
try {
gptr<EContact, GObject> contact( e_contact_new_from_vcard( (const char *)item.getData() ) );
string data = getData(item);
gptr<EContact, GObject> contact(e_contact_new_from_vcard(data.c_str()));
if( contact ) {
GError *gerror = NULL;
e_contact_set( contact, E_CONTACT_UID, item.getKey( NULL ) );
e_contact_set( contact, E_CONTACT_UID, item.getKey() );
if ( e_book_commit_contact(m_addressbook, contact, &gerror) ) {
const char *uid = (const char *)e_contact_get_const(contact, E_CONTACT_UID);
if (uid) {
item.setKey( uid );
}
} else {
throwError( string( "updating contact" ) + item.getKey( NULL ), gerror );
throwError( string( "updating contact" ) + item.getKey(), gerror );
}
} else {
throwError( string( "parsing vcard" ) + (const char *)item.getData(),
throwError( string( "parsing vcard" ) + data,
NULL );
}
} catch ( ... ) {
@ -228,8 +228,8 @@ int EvolutionContactSource::deleteItem(SyncItem& item)
{
try {
GError *gerror = NULL;
if (!e_book_remove_contact( m_addressbook, item.getKey( NULL ), &gerror ) ) {
throwError( string( "deleting contact" ) + item.getKey( NULL ),
if (!e_book_remove_contact( m_addressbook, item.getKey(), &gerror ) ) {
throwError( string( "deleting contact" ) + item.getKey(),
gerror );
}
} catch( ... ) {

View File

@ -48,16 +48,15 @@ class EvolutionContactSource : public EvolutionSyncSource
virtual sources getSyncBackends();
virtual void open();
virtual void close();
virtual SyncItem *createItem( const string &uid );
virtual SyncItem *createItem( const string &uid, SyncState state );
//
// implementation of SyncSource
//
virtual void setSyncItemStatus(char *key, int status);
virtual int addItem(SyncItem& item);
virtual int updateItem(SyncItem& item);
virtual int deleteItem(SyncItem& item);
private:
/** valid after open(): the address book that this source references */
gptr<EBook, GObject> m_addressbook;

View File

@ -182,8 +182,8 @@ void TestEvolution::testContactSimpleInsert()
SyncItem item;
item.setData( vcard, strlen(vcard) + 1 );
EVOLUTION_ASSERT_NO_THROW( source, source.addItem( item ) );
CPPUNIT_ASSERT( item.getKey( NULL ) != NULL );
CPPUNIT_ASSERT( strlen( item.getKey( NULL ) ) > 0 );
CPPUNIT_ASSERT( item.getKey() != NULL );
CPPUNIT_ASSERT( strlen( item.getKey() ) > 0 );
EVOLUTION_ASSERT_NO_THROW( source, source.close() );
EVOLUTION_ASSERT_NO_THROW( source, source.open() );
@ -194,9 +194,9 @@ void TestEvolution::testContactSimpleInsert()
SyncItem *sameItem;
EVOLUTION_ASSERT_NO_THROW(
source,
sameItem = source.createItem( item.getKey( NULL ) ) );
sameItem = source.createItem( item.getKey(), item.getState() ) );
CPPUNIT_ASSERT( sameItem != NULL );
CPPUNIT_ASSERT( !strcmp( sameItem->getKey( NULL ), item.getKey( NULL ) ) );
CPPUNIT_ASSERT( !strcmp( sameItem->getKey(), item.getKey() ) );
delete sameItem;
}
@ -294,8 +294,8 @@ void TestEvolution::contactUpdate()
CPPUNIT_ASSERT( countDeletedItems( source ) == 0 );
SyncItem *modifiedItem;
EVOLUTION_ASSERT_NO_THROW( source, modifiedItem = source.getFirstItem() );
CPPUNIT_ASSERT( strlen( item->getKey( NULL ) ) );
CPPUNIT_ASSERT( !strcmp( item->getKey( NULL ), modifiedItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( strlen( item->getKey() ) );
CPPUNIT_ASSERT( !strcmp( item->getKey(), modifiedItem->getKey() ) );
delete item;
delete modifiedItem;
@ -341,9 +341,9 @@ void TestEvolution::testContactChanges()
CPPUNIT_ASSERT( countDeletedItems( source ) == 1 );
SyncItem *deletedItem;
EVOLUTION_ASSERT_NO_THROW( source, deletedItem = source.getFirstDeletedItem() );
CPPUNIT_ASSERT( strlen( item->getKey( NULL ) ) );
CPPUNIT_ASSERT( strlen( deletedItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( !strcmp( item->getKey( NULL ), deletedItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( strlen( item->getKey() ) );
CPPUNIT_ASSERT( strlen( deletedItem->getKey() ) );
CPPUNIT_ASSERT( !strcmp( item->getKey(), deletedItem->getKey() ) );
EVOLUTION_ASSERT_NO_THROW( source, source.close() );
delete item;
@ -359,9 +359,9 @@ void TestEvolution::testContactChanges()
EVOLUTION_ASSERT_NO_THROW( source, item = source.getFirstItem() );
SyncItem *newItem;
EVOLUTION_ASSERT_NO_THROW( source, newItem = source.getFirstNewItem() );
CPPUNIT_ASSERT( strlen( item->getKey( NULL ) ) );
CPPUNIT_ASSERT( strlen( newItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( !strcmp( item->getKey( NULL ), newItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( strlen( item->getKey() ) );
CPPUNIT_ASSERT( strlen( newItem->getKey() ) );
CPPUNIT_ASSERT( !strcmp( item->getKey(), newItem->getKey() ) );
EVOLUTION_ASSERT_NO_THROW( source, source.close() );
delete newItem;
@ -375,7 +375,7 @@ void TestEvolution::testContactChanges()
CPPUNIT_ASSERT( countDeletedItems( source ) == 0 );
SyncItem *updatedItem;
EVOLUTION_ASSERT_NO_THROW( source, updatedItem = source.getFirstUpdatedItem() );
CPPUNIT_ASSERT( !strcmp( item->getKey( NULL ), updatedItem->getKey( NULL ) ) );
CPPUNIT_ASSERT( !strcmp( item->getKey(), updatedItem->getKey() ) );
delete item;
delete updatedItem;

View File

@ -17,7 +17,7 @@
*/
#include <base/Log.h>
#include <base/autotools/Log.h>
#include <posix/base/posixlog.h>
#include <iostream>
using namespace std;