From: <svn...@op...> - 2010-10-02 21:13:10
|
Author: deloptes Date: Sat Oct 2 23:13:00 2010 New Revision: 6141 URL: http://www.opensync.org/changeset/6141 Log: - sync with evolution TODO: fix the setPayload in createAkonadiItem, to create a real akonadi item It's broken and it does not create any item. Modified: plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp plugins/akonadi-sync/trunk/src/akonadisink.cpp plugins/akonadi-sync/trunk/src/datasink.cpp plugins/akonadi-sync/trunk/src/sinkbase.cpp plugins/akonadi-sync/trunk/src/sinkbase.h Modified: plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Sat Oct 2 13:11:43 2010 (r6140) +++ plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Sat Oct 2 23:13:00 2010 (r6141) @@ -234,7 +234,8 @@ osync_trace(TRACE_ENTRY, "%s(%p)", __func__, userdata); kDebug(); AkonadiSink *sink = reinterpret_cast<AkonadiSink*>( userdata ); - delete sink; + sink->disconnect(); +// delete sink; delete kcd; kcd = 0; delete app; Modified: plugins/akonadi-sync/trunk/src/akonadisink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadisink.cpp Sat Oct 2 13:11:43 2010 (r6140) +++ plugins/akonadi-sync/trunk/src/akonadisink.cpp Sat Oct 2 23:13:00 2010 (r6141) @@ -54,8 +54,8 @@ return false; } osync_plugin_info_set_main_sink( info, sink ); - osync_objtype_sink_set_userdata(sink, this); wrapSink( sink ); + osync_objtype_sink_set_userdata(sink, this); return true; } @@ -70,7 +70,7 @@ osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, "Could not start Akonadi."); return; } -// success(); + success(); osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } Modified: plugins/akonadi-sync/trunk/src/datasink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/datasink.cpp Sat Oct 2 13:11:43 2010 (r6140) +++ plugins/akonadi-sync/trunk/src/datasink.cpp Sat Oct 2 23:13:00 2010 (r6141) @@ -53,558 +53,606 @@ typedef boost::shared_ptr<KCal::Incidence> IncidencePtr; -DataSink::DataSink( int type ) : - SinkBase( GetChanges | Commit | SyncDone ) +DataSink::DataSink ( int type ) : + SinkBase ( GetChanges | Commit | SyncDone ) { - kDebug() << "Create obj:" << type; - m_type = type; + kDebug() << "Create obj:" << type; + m_type = type; - m_isEvent = ( type == DataSink::Calendars ) ? true : false; - m_isContact = ( type == DataSink::Contacts ) ? true : false; - m_isNote = ( type == DataSink::Notes ) ? true : false; - m_isTodo = ( type == DataSink::Todos ) ? true : false; - m_isJournal = ( type == DataSink::Journals ) ? true : false; + m_isEvent = ( type == DataSink::Calendars ) ? true : false; + m_isContact = ( type == DataSink::Contacts ) ? true : false; + m_isNote = ( type == DataSink::Notes ) ? true : false; + m_isTodo = ( type == DataSink::Todos ) ? true : false; + m_isJournal = ( type == DataSink::Journals ) ? true : false; } -DataSink::~DataSink() { - kDebug() << "DataSink destructor called"; // TODO still needed +DataSink::~DataSink() +{ + kDebug() << "DataSink destructor called"; // TODO still needed } -bool DataSink::initialize(OSyncPlugin * plugin, OSyncPluginInfo * info, OSyncObjTypeSink *sink, OSyncError ** error) +bool DataSink::initialize ( OSyncPlugin * plugin, OSyncPluginInfo * info, OSyncObjTypeSink *sink, OSyncError ** error ) { - kDebug() << "initializing" << osync_objtype_sink_get_name(sink); - kDebug() << "TYPE " << m_type; - Q_UNUSED( plugin ); - Q_UNUSED( info ); - Q_UNUSED( error ); + kDebug() << "initializing" << osync_objtype_sink_get_name ( sink ); + kDebug() << "TYPE " << m_type; + Q_UNUSED ( plugin ); + Q_UNUSED ( info ); + Q_UNUSED ( error ); - OSyncPluginConfig *config = osync_plugin_info_get_config(info); - if (!config) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); - return false; + OSyncPluginConfig *config = osync_plugin_info_get_config ( info ); + if ( !config ) + { + osync_error_set ( error, OSYNC_ERROR_GENERIC, "Unable to get config." ); + return false; } + + osync_bool enabled = osync_objtype_sink_is_enabled ( sink ); + if ( ! enabled ) + { + kDebug() << "sink is not enabled.."; +// osync_objtype_sink_remove_objformat_sink( sink ); + return false; + } + + wrapSink ( sink ); + + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink ); + if ( ! hashtable ) + kDebug() << ">> NO hashtable for objtype:" << osync_objtype_sink_get_name ( sink ); -// kDebug() << "Sink wrapped: " << osync_objtype_sink_get_name(sink); + OSyncPluginResource *resource = osync_plugin_config_find_active_resource ( config, osync_objtype_sink_get_name ( sink ) ); + OSyncList *objfrmtList = osync_plugin_resource_get_objformat_sinks ( resource ); -// TODO -// OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); -// if( hashtable ) -// osync_objtype_sink_enable_hashtable(sink, TRUE); -// if( ! hashtable ) { -// kDebug() << "No hashtable for sync"; -// osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print( error ) ); -// return false; -// } - - osync_bool enabled = osync_objtype_sink_is_enabled( sink ); - if ( ! enabled ) { - kDebug() << "sink is not enabled.."; -// osync_objtype_sink_remove_objformat_sink( sink ); - return false; + OSyncList *r; + bool hasObjFormat; + for ( r = objfrmtList;r;r = r->next ) + { + OSyncObjFormatSink *objformatsink = ( OSyncObjFormatSink * ) r->data; + + switch ( m_type ) + { + case Contacts: + { + if ( !strcmp ( "vcard21", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vcard21"; + break; + } + else + kDebug() << "No objformat vcard21"; + + if ( !strcmp ( "vcard30", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vcard30"; + break; + } + else + kDebug() << "No objformat vcard30"; + + break; + } + case Calendars: + { + if ( !strcmp ( "vevent10", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vevent10"; + break; + } + else + kDebug() << "No objformat vevent10"; + break; + if ( !strcmp ( "vevent20", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vevent20"; + break; + } + else + kDebug() << "No objformat vevent20"; + break; + } + case Notes: + { + if ( !strcmp ( "vnote11", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vnote11"; + break; + } + else + kDebug() << "No objformat vnote11"; + break; + } + case Journals: + { + if ( !strcmp ( "vjournal", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vjournal"; + break; + } + else + kDebug() << "No objformat vjournal"; + break; + } + case Todos: + { + if ( !strcmp ( "vtodo10", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vtodo10"; + break; + } + else + kDebug() << "No objformat vtodo10"; + if ( !strcmp ( "vtodo20", osync_objformat_sink_get_objformat ( objformatsink ) ) ) + { + hasObjFormat = true; + kDebug() << "Has objformat vtodo20"; + break; + } + else + kDebug() << "No objformat vtodo20"; + break; + } + + default: + continue; + } } - - osync_objtype_sink_set_userdata(sink, this); - osync_objtype_sink_enable_hashtable(sink , TRUE); - OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); - - if ( ! hashtable ) - kDebug() << ">> NO hashtable for objtype:" << osync_objtype_sink_get_name(sink); - - OSyncPluginResource *resource = osync_plugin_config_find_active_resource(config, osync_objtype_sink_get_name(sink)); - OSyncList *objfrmtList = osync_plugin_resource_get_objformat_sinks(resource); - - OSyncList *r; - bool hasObjFormat; - for(r = objfrmtList;r;r = r->next) { - OSyncObjFormatSink *objformatsink = (OSyncObjFormatSink *) r->data; - - switch (m_type) { - case Contacts: { - if(!strcmp("vcard21", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vcard21"; - break; - } else - kDebug() << "No objformat vcard21"; - - if(!strcmp("vcard30", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vcard30"; - break; - } else - kDebug() << "No objformat vcard30"; - - break; - } - case Calendars: { - if(!strcmp("vevent10", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vevent10"; - break; - } else - kDebug() << "No objformat vevent10"; - break; - if(!strcmp("vevent20", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vevent20"; - break; - } else - kDebug() << "No objformat vevent20"; - break; - } - case Notes: { - if(!strcmp("vnote11", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vnote11"; - break; - } else - kDebug() << "No objformat vnote11"; - break; - } - case Journals: { - if(!strcmp("vjournal", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vjournal"; - break; - } else - kDebug() << "No objformat vjournal"; - break; - } - case Todos: { - if(!strcmp("vtodo10", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vtodo10"; - break; - } else - kDebug() << "No objformat vtodo10"; - if(!strcmp("vtodo20", osync_objformat_sink_get_objformat(objformatsink))) { - hasObjFormat = true; - kDebug() << "Has objformat vtodo20"; - break; - } else - kDebug() << "No objformat vtodo20"; - break; - } - - default: - continue; - } - } // if (!hasObjFormat) { // kDebug() << "No objformat vcard30"; // return false; // } - - wrapSink( sink ); - - return true; + osync_objtype_sink_set_userdata ( sink, this ); + osync_objtype_sink_enable_hashtable ( sink , TRUE ); + + return true; } Akonadi::Collection DataSink::collection() const -{ - OSyncPluginConfig *config = osync_plugin_info_get_config( pluginInfo() ); - Q_ASSERT( config ); + { + OSyncPluginConfig *config = osync_plugin_info_get_config ( pluginInfo() ); + Q_ASSERT ( config ); - const char *objtype = osync_objtype_sink_get_name( sink() ); + const char *objtype = osync_objtype_sink_get_name ( sink() ); - OSyncPluginResource *res = osync_plugin_config_find_active_resource( config, objtype ); + OSyncPluginResource *res = osync_plugin_config_find_active_resource ( config, objtype ); - if ( !res ) { - error( OSYNC_ERROR_MISCONFIGURATION, i18n("No active resource for type \"%1\" found", objtype ) ); + if ( !res ) + { + error ( OSYNC_ERROR_MISCONFIGURATION, i18n ( "No active resource for type \"%1\" found", objtype ) ); return Collection(); - } + } - const KUrl url = KUrl( osync_plugin_resource_get_url( res ) ); + const KUrl url = KUrl ( osync_plugin_resource_get_url ( res ) ); // TODO osync_plugin_resource_get_mime() ; - if ( url.isEmpty() ) { - error( OSYNC_ERROR_MISCONFIGURATION, i18n("Url for object type \"%1\" is not configured.", objtype ) ); + if ( url.isEmpty() ) + { + error ( OSYNC_ERROR_MISCONFIGURATION, i18n ( "Url for object type \"%1\" is not configured.", objtype ) ); return Collection(); - } + } - return Collection::fromUrl( url ); -} + return Collection::fromUrl ( url ); + } void DataSink::getChanges() { - kDebug() << " DataSink::getChanges() called"; - OSyncError *oerror = 0; - OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink()); - - Collection col = collection(); // osync_objtype_sink_get_name(sink()) - if ( !col.isValid() ) { - kDebug() << "No collection"; - osync_trace( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print( &oerror ) ); - return; - } + kDebug() << " DataSink::getChanges() called"; + OSyncError *oerror = 0; + + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); + Collection col = collection(); // osync_objtype_sink_get_name(sink()) + if ( !col.isValid() ) + { + kDebug() << "No collection"; + osync_trace ( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print ( &oerror ) ); + return; + } // FIXME - if ( getSlowSink() ) { - kDebug() << "we're in the middle of slow-syncing..."; - osync_trace( TRACE_INTERNAL, "resetting hashtable" ); - if ( ! osync_hashtable_slowsync( hashtable, &oerror ) ) { - warning( oerror ); - osync_trace( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print( &oerror ) ); - return; + if ( getSlowSink() ) + { + kDebug() << "we're in the middle of slow-syncing..."; + osync_trace ( TRACE_INTERNAL, "resetting hashtable" ); + if ( ! osync_hashtable_slowsync ( hashtable, &oerror ) ) + { + warning ( oerror ); + osync_trace ( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print ( &oerror ) ); + return; } } + ItemFetchJob *job = new ItemFetchJob ( col ); + job->fetchScope().fetchFullPayload ( true ); + kDebug() << "Fetched FullPayload" ; - ItemFetchJob *job = new ItemFetchJob( col ); - job->fetchScope().fetchFullPayload(true); - kDebug() << "Fetched FullPayload" ; - - QObject::connect( job, SIGNAL( itemsReceived( const Akonadi::Item::List & ) ), this, SLOT( slotItemsReceived( const Akonadi::Item::List & ) ) ); - QObject::connect( job, SIGNAL( result( KJob * ) ), this, SLOT( slotGetChangesFinished( KJob * ) ) ); + QObject::connect ( job, SIGNAL ( itemsReceived ( const Akonadi::Item::List & ) ), this, SLOT ( slotItemsReceived ( const Akonadi::Item::List & ) ) ); + QObject::connect ( job, SIGNAL ( result ( KJob * ) ), this, SLOT ( slotGetChangesFinished ( KJob * ) ) ); - // FIXME give me a real eventloop please! - if ( !job->exec() ) { - error( OSYNC_ERROR_IO_ERROR, job->errorText() ); - return; + // FIXME give me a real eventloop please! + if ( !job->exec() ) + { + error ( OSYNC_ERROR_IO_ERROR, job->errorText() ); + return; } - success(); + + success(); } -void DataSink::slotItemsReceived( const Item::List &items ) +void DataSink::slotItemsReceived ( const Item::List &items ) { - kDebug() << "retrieved" << items.count() << "items"; - Q_FOREACH( const Item& item, items ) { - kDebug() << "Id:" << item.id() << "\n"; - kDebug() << "Mime:" << item.mimeType() << "\n"; - kDebug() << "availablePayloadParts:" << item.availablePayloadParts() << "\n"; - kDebug() << "storageCollectionId:" << item.storageCollectionId() << "\n"; - kDebug() << "url:" << item.url() << "\n"; - reportChange( item ); - } + kDebug() << "retrieved" << items.count() << "items"; + Q_FOREACH ( const Item& item, items ) + { + kDebug() << "Id:" << item.id() << "\n"; + kDebug() << "Mime:" << item.mimeType() << "\n"; + kDebug() << "Revision:" << item.revision() << "\n"; + kDebug() << "StorageCollectionId:" << item.storageCollectionId() << "\n"; + kDebug() << "Url:" << item.url() << "\n"; + reportChange ( item ); + } } -void DataSink::reportChange( const Item& item ) +void DataSink::reportChange ( const Item& item ) { - kDebug() << item.id() << "\n" ; - kDebug() << "item.payloadData().data():" << item.payloadData().data() << "\n" ; - OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env( pluginInfo() ); - OSyncObjFormat *format = osync_format_env_find_objformat( formatenv, formatName().toLatin1() ); +// kDebug() << item.id() << "\n" ; + kDebug() << "item.payloadData().data():" << item.payloadData().data() << "\n" ; + + OSyncError *error = 0; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); - OSyncError *error = 0; - OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink()); - OSyncChange *change = osync_change_new( &error ); - if ( !change ) { - warning( error ); - return; + OSyncChange *change = osync_change_new ( &error ); + if ( !change ) + { + osync_change_unref ( change ); + warning ( error ); + return; } - osync_change_set_uid( change, QString::number( item.id() ).toLatin1() ); + osync_change_set_uid ( change, QString::number ( item.id() ).toLatin1() ); - error = 0; - - OSyncData *odata = osync_data_new( item.payloadData().data(), item.payloadData().size(), format, &error ); - if ( !odata ) { - osync_change_unref( change ); - warning( error ); - return; + + OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env ( pluginInfo() ); + OSyncObjFormat *format = osync_format_env_find_objformat ( formatenv, formatName().toLatin1() ); + +// + error = 0; + // Now you can set the data for the object + // Set the last argument to FALSE if the real data + // should be queried later in a "get_data" function +// odata = osync_data_new(NULL, 0, format, &error); + OSyncData *odata = osync_data_new ( item.payloadData().data() , item.payloadData().size(), format, &error ); + if ( !odata ) + { + osync_change_unref ( change ); + return; } - osync_data_set_objtype( odata, osync_objtype_sink_get_name( sink() ) ); - osync_change_set_data( change, odata ); +// // osync_data_set_objtype( odata, osync_objtype_sink_get_name( sink() ) ); +// + osync_change_set_data ( change, odata ); + osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); + OSyncChangeType changetype = osync_hashtable_get_changetype ( hashtable, change ); + osync_change_set_changetype ( change, changetype ); + osync_hashtable_update_change ( hashtable, change ); -// kDebug() << item.id() << "\n" << "DATA:" << osync_data_get_printable( odata , &error) << "\n" ; + osync_data_unref ( odata ); - osync_data_unref( odata ); - osync_change_set_hash( change, QString::number( item.revision() ).toLatin1() ); - OSyncChangeType changeType = osync_hashtable_get_changetype( hashtable, change ); - osync_change_set_changetype( change, changeType ); + /* */ + kDebug() << "changeid:" << osync_change_get_uid ( change ) << "; " + << "itemid:" << item.id() << "; " + << "revision:" << item.revision() << "; " + << "changetype:" << changetype << "; " + << "hash:" << osync_hashtable_get_hash ( hashtable, osync_change_get_uid ( change ) ) << "; " + << "objtype:" << osync_change_get_objtype ( change ) << "; " + << "objform:" << osync_objformat_get_name ( osync_change_get_objformat ( change ) ) << "; " + << "sinkname:" << osync_objtype_sink_get_name ( sink() ); + /* */ + if ( changetype != OSYNC_CHANGE_TYPE_UNMODIFIED ) + osync_context_report_change ( context(), change ); - /* */ - kDebug() << "changeid:" << osync_change_get_uid( change ) << "; " - << "itemid:" << item.id()<< "; " - << "revision:" << item.revision()<< "; " - << "changetype:" << changeType << "; " - << "hash:" << osync_hashtable_get_hash( hashtable, osync_change_get_uid( change ) ) << "; " - << "objtype:" << osync_change_get_objtype( change ) << "; " - << "objform:" << osync_objformat_get_name( osync_change_get_objformat( change ) ) << "; " - << "sinkname:" << osync_objtype_sink_get_name( sink() ); - /* */ - if ( changeType != OSYNC_CHANGE_TYPE_UNMODIFIED ) - osync_context_report_change( context(), change ); - else - // perhaps this should be only called when an error has happened ie. never after _context_report_change()? - osync_change_unref( change ); // if this gets called, we get broken pipes. any ideas? } -void DataSink::slotGetChangesFinished( KJob * ) +void DataSink::slotGetChangesFinished ( KJob * ) { - OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env( pluginInfo() ); - OSyncObjFormat *format = osync_format_env_find_objformat( formatenv, formatName().toLatin1() ); + OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env ( pluginInfo() ); + OSyncObjFormat *format = osync_format_env_find_objformat ( formatenv, formatName().toLatin1() ); - // after the items have been processed, see what's been deleted and send them to opensync - OSyncError *error = 0; + // after the items have been processed, see what's been deleted and send them to opensync + OSyncError *error = 0; // FIXME: - OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink()); - OSyncList *u, *uids = osync_hashtable_get_deleted( hashtable ); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); + OSyncList *u, *uids = osync_hashtable_get_deleted ( hashtable ); // - for ( u = uids; u; u = u->next) { - QString uid( (char *)u->data ); - kDebug() << "going to delete with uid:" << uid; - - OSyncChange *change = osync_change_new( &error ); - if ( !change ) { - warning( error ); - continue; + for ( u = uids; u; u = u->next ) + { + QString uid ( ( char * ) u->data ); + kDebug() << "going to delete with uid:" << uid; + + OSyncChange *change = osync_change_new ( &error ); + if ( !change ) + { + osync_change_unref ( change ); + warning ( error ); + continue; } // - osync_change_set_changetype( change, OSYNC_CHANGE_TYPE_DELETED ); - osync_change_set_uid( change, uid.toLatin1() ); - - error = 0; - OSyncData *data = osync_data_new( 0, 0, format, &error ); - if ( !data ) { - osync_change_unref( change ); - warning( error ); - continue; + osync_change_set_uid ( change, uid.toLatin1() ); + osync_change_set_changetype ( change, OSYNC_CHANGE_TYPE_DELETED ); + error = 0; + OSyncData *odata = osync_data_new ( NULL, 0, format, &error ); + if ( !odata ) + { + osync_change_unref ( change ); + warning ( error ); + continue; } -// - osync_data_set_objtype( data, osync_objtype_sink_get_name( sink() ) ); - osync_change_set_data( change, data ); - osync_hashtable_update_change( hashtable, change ); + osync_data_set_objtype ( odata, osync_objtype_sink_get_name ( sink() ) ); + osync_change_set_data ( change, odata ); + osync_data_unref ( odata ); + +// osync_context_report_change(context(), change); + osync_hashtable_update_change ( hashtable, change ); - osync_change_unref( change ); + osync_change_unref ( change ); } - osync_list_free( uids ); + osync_list_free ( uids ); - kDebug() << "got all changes.."; + kDebug() << "got all changes.."; } -void DataSink::commit(OSyncChange *change) +void DataSink::commit ( OSyncChange *change ) { - kDebug() << "change uid:" << osync_change_get_uid( change ); - kDebug() << "objtype:" << osync_change_get_objtype( change ); - kDebug() << "objform:" << osync_objformat_get_name (osync_change_get_objformat( change ) ); - OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink()); + kDebug() << "change uid:" << osync_change_get_uid ( change ); + kDebug() << "objtype:" << osync_change_get_objtype ( change ); + kDebug() << "objform:" << osync_objformat_get_name ( osync_change_get_objformat ( change ) ); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); - switch ( osync_change_get_changetype( change ) ) { - case OSYNC_CHANGE_TYPE_ADDED: { - const Item item = createItem( change ); - osync_change_set_uid( change, QString::number( item.id() ).toLatin1() ); - osync_change_set_hash( change, QString::number( item.revision() ).toLatin1() ); - kDebug() << "ADDED:" << osync_change_get_uid( change ); - break; + switch ( osync_change_get_changetype ( change ) ) + { + case OSYNC_CHANGE_TYPE_ADDED: + { + const Item item = createItem ( change ); + osync_change_set_uid ( change, QString::number ( item.id() ).toLatin1() ); + osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); + kDebug() << "ADDED:" << osync_change_get_uid ( change ); + break; } - case OSYNC_CHANGE_TYPE_MODIFIED: { - const Item item = modifyItem( change ); - osync_change_set_uid( change, QString::number( item.id() ).toLatin1() ); - osync_change_set_hash( change, QString::number( item.revision() ).toLatin1() ); - kDebug() << "MODIFIED:" << osync_change_get_uid( change ); - break; + case OSYNC_CHANGE_TYPE_MODIFIED: + { + const Item item = modifyItem ( change ); + osync_change_set_uid ( change, QString::number ( item.id() ).toLatin1() ); + osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); + kDebug() << "MODIFIED:" << osync_change_get_uid ( change ); + break; } - case OSYNC_CHANGE_TYPE_DELETED: { - deleteItem( change ); - kDebug() << "DELETED:" << osync_change_get_uid( change ); - break; + case OSYNC_CHANGE_TYPE_DELETED: + { + deleteItem ( change ); + kDebug() << "DELETED:" << osync_change_get_uid ( change ); + break; } - case OSYNC_CHANGE_TYPE_UNMODIFIED: { - kDebug() << "UNMODIFIED"; - // should we do something here? - break; + case OSYNC_CHANGE_TYPE_UNMODIFIED: + { + kDebug() << "UNMODIFIED"; + // should we do something here? + break; } default: - kDebug() << "got invalid changetype?"; + kDebug() << "got invalid changetype?"; } - osync_hashtable_update_change( hashtable, change ); - success(); + osync_hashtable_update_change ( hashtable, change ); + success(); } -const Item DataSink::createItem( OSyncChange *change ) +const Item DataSink::createAkonadiItem ( OSyncChange *change ) { - Collection col = collection(); - if ( !col.isValid() ) // error handling - return Item(); - kDebug() << "cuid:" << osync_change_get_uid( change ); + char *plain = 0; + osync_data_get_data ( osync_change_get_data ( change ), &plain, /*size*/0 ); + QString str = QString::fromLatin1 ( plain ); + Akonadi::Item item; + setPayload ( &item, str.toUtf8() ); + return item; +} - ItemCreateJob *job = new Akonadi::ItemCreateJob( createAkonadiItem( change ), col ); +const Item DataSink::createItem ( OSyncChange *change ) +{ + Collection col = collection(); + if ( !col.isValid() ) // error handling + return Item(); + kDebug() << "cuid:" << osync_change_get_uid ( change ); - if ( ! job->exec() ) - kDebug() << "creating an item failed"; + ItemCreateJob *job = new Akonadi::ItemCreateJob ( createAkonadiItem ( change ), col ); - return job->item(); // handle !job->exec in return too.. + if ( ! job->exec() ) + kDebug() << "creating an item failed"; + + return job->item(); // handle !job->exec in return too.. } -const Item DataSink::modifyItem( OSyncChange *change ) +const Item DataSink::modifyItem ( OSyncChange *change ) { - char *plain = 0; - osync_data_get_data( osync_change_get_data( change ), &plain, /*size*/0 ); - QString str = QString::fromUtf8( plain ); + char *plain = 0; + osync_data_get_data ( osync_change_get_data ( change ), &plain, /*size*/0 ); + QString str = QString::fromLatin1 ( plain ); - QString id = QString( osync_change_get_uid( change ) ); - Item item = fetchItem( id ); - if ( ! item.isValid() ) // TODO proper error handling - return Item(); + QString id = QString ( osync_change_get_uid ( change ) ); + Item item = fetchItem ( id ); + if ( ! item.isValid() ) // TODO proper error handling + return Item(); - //event.setMimeType( "application/x-vnd.akonadi.calendar.event" ); - //Item newItem = createAkonadiItem( change ); - setPayload(&item, str); - ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob( item ); - if ( modifyJob->exec() ) { - kDebug() << "modification completed"; - return modifyJob->item(); + //event.setMimeType( "application/x-vnd.akonadi.calendar.event" ); + //Item newItem = createAkonadiItem( change ); + setPayload ( &item, str.toUtf8() ); + ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob ( item ); + if ( modifyJob->exec() ) + { + kDebug() << "modification completed"; + return modifyJob->item(); } - else - kDebug() << "unable to modify"; + else + kDebug() << "unable to modify"; - return Item(); + return Item(); } -void DataSink::deleteItem( OSyncChange *change ) +void DataSink::deleteItem ( OSyncChange *change ) { - QString id = QString( osync_change_get_uid( change ) ); - Item item = fetchItem( id ); - if ( ! item.isValid() ) // TODO proper error handling - return; + QString id = QString ( osync_change_get_uid ( change ) ); + Item item = fetchItem ( id ); + if ( ! item.isValid() ) // TODO proper error handling + return; - kDebug() << "delete with id: " << item.id(); - /*ItemDeleteJob *job = new ItemDeleteJob( item ); + kDebug() << "delete with id: " << item.id(); + // TODO + /*ItemDeleteJob *job = new ItemDeleteJob( item ); - if( job->exec() ) { - kDebug() << "item deleted"; - } - else - kDebug() << "unable to delete item";*/ - success(); // TODO + if( job->exec() ) { + kDebug() << "item deleted"; + } + else + kDebug() << "unable to delete item";*/ + + success(); // TODO } -bool DataSink::setPayload( Item *item, const QString &str ) +bool DataSink::setPayload ( Item *item, const QString &str ) { - switch ( m_type ) { - case Contacts: { - KABC::VCardConverter converter; - KABC::Addressee vcard = converter.parseVCard( str.toLatin1() ); - kDebug() << vcard.uid() << vcard.name(); - item->setMimeType( KABC::Addressee::mimeType() ); - //item->setPayload<KABC::Addressee>( vcard ); // FIXME - item->setPayloadFromData( vcard.toString().toLatin1() ); // FIXME - //item->setPayload<KABC::Addressee>( vcard.toString() ); // FIXME - break; - } - case Calendars: { - KCal::ICalFormat format; - KCal::Incidence *calEntry = format.fromString( str ); - - item->setMimeType( "application/x-vnd.akonadi.calendar.event" ); - item->setPayload<IncidencePtr>( IncidencePtr( calEntry->clone() ) ); - - break; + switch ( m_type ) + { + case Contacts: + { + KABC::VCardConverter converter; + KABC::Addressee vcard = converter.parseVCard ( str.toUtf8() ); + item->setMimeType ( KABC::Addressee::mimeType() ); + item->setPayloadFromData ( vcard.toString().toLatin1() ); + break; } - case Todos: { - KCal::ICalFormat format; - KCal::Incidence *todoEntry = format.fromString(str); //format.fromString( str ); - - item->setMimeType( "application/x-vnd.akonadi.calendar.todo" ); - item->setPayload<IncidencePtr>( IncidencePtr( todoEntry->clone() ) ); + case Calendars: + { + KCal::ICalFormat format; + KCal::Incidence *calEntry = format.fromString ( str.toUtf8() ); + item->setMimeType ( "application/x-vnd.akonadi.calendar.event" ); + item->setPayload<IncidencePtr> ( IncidencePtr ( calEntry->clone() ) ); - break; + break; } - case Notes: { - kDebug() << "notes"; - KCal::ICalFormat format; - KCal::Incidence *noteEntry = format.fromString(str); - - item->setMimeType( "application/x-vnd.kde.notes" ); - item->setPayload<IncidencePtr>( IncidencePtr( noteEntry->clone() ) ); + case Todos: + { + KCal::ICalFormat format; + KCal::Incidence *todoEntry = format.fromString ( str.toUtf8() ); + item->setMimeType ( "application/x-vnd.akonadi.calendar.todo" ); + item->setPayload<IncidencePtr> ( IncidencePtr ( todoEntry->clone() ) ); - break; + break; } - case Journals: { - kDebug() << "journals"; - KCal::ICalFormat format; - KCal::Incidence *journalEntry = format.fromString(str); - - item->setMimeType( "application/x-vnd.akonadi.calendar.journal" ); - item->setPayload<IncidencePtr>( IncidencePtr( journalEntry->clone() ) ); + case Notes: + { + kDebug() << "notes"; + KCal::ICalFormat format; + KCal::Incidence *noteEntry = format.fromString ( str.toUtf8() ); + item->setMimeType ( "application/x-vnd.kde.notes" ); + item->setPayload<IncidencePtr> ( IncidencePtr ( noteEntry->clone() ) ); + + break; + } + case Journals: + { + kDebug() << "journals"; + KCal::ICalFormat format; + KCal::Incidence *journalEntry = format.fromString ( str.toUtf8() ); + item->setMimeType ( "application/x-vnd.akonadi.calendar.journal" ); + item->setPayload<IncidencePtr> ( IncidencePtr ( journalEntry->clone() ) ); - break; + break; } default: - // should not happen - return false; + // should not happen + return false; } - return true; -} - -const Item DataSink::createAkonadiItem( OSyncChange *change ) -{ - char *plain = 0; - osync_data_get_data( osync_change_get_data( change ), &plain, /*size*/0 ); - QString str = QString::fromUtf8( plain ); - Akonadi::Item item; - setPayload(&item, str); - return item; + return true; } const QString DataSink::formatName() { - // FIXME -- this should be saved somewhere in the config, why settign and checking here: - QString formatName; - switch ( m_type ) { + // FIXME -- this should be saved somewhere in the config, why settign and checking here: + QString formatName; + switch ( m_type ) + { case Calendars: - formatName = "vevent20"; - break; + formatName = "vevent20"; + break; case Contacts: - formatName = "vcard30"; - break; + formatName = "vcard30"; + break; case Notes: - formatName = "vjournal"; - break; + formatName = "vjournal"; + break; case Todos: - formatName = "vtodo20"; - break; + formatName = "vtodo20"; + break; default: - kDebug() << "invalid datasink type"; - return QString(); + kDebug() << "invalid datasink type"; + return QString(); } - return formatName; + return formatName; } -const Item DataSink::fetchItem( const QString& id ) +const Item DataSink::fetchItem ( const QString& id ) { - ItemFetchJob *fetchJob = new ItemFetchJob( Item( id ) ); - fetchJob->fetchScope().fetchFullPayload(); + ItemFetchJob *fetchJob = new ItemFetchJob ( Item ( id ) ); + fetchJob->fetchScope().fetchFullPayload(); - if ( fetchJob->exec() ) { - foreach ( const Item &item, fetchJob->items() ) { - if ( QString::number( item.id() ) == id ) { - kDebug() << "got item"; - return item; - } - } + if ( fetchJob->exec() ) + { + foreach ( const Item &item, fetchJob->items() ) + { + if ( QString::number ( item.id() ) == id ) + { + kDebug() << "got item"; + return item; + } + } } - // no such item found? - return Item(); + // no such item found? + return Item(); } void DataSink::syncDone() { - kDebug() << "sync for sink member done"; - OSyncError *error = 0; - osync_objtype_sink_save_hashtable( sink() , &error ); - //TODO check for errors - success(); + kDebug() << "sync for sink member done"; + OSyncError *error = 0; + osync_objtype_sink_save_hashtable ( sink() , &error ); + //TODO check for errors + if ( error ) + { + warning ( error ); + return; + } + success(); } #include "datasink.moc" Modified: plugins/akonadi-sync/trunk/src/sinkbase.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.cpp Sat Oct 2 13:11:43 2010 (r6140) +++ plugins/akonadi-sync/trunk/src/sinkbase.cpp Sat Oct 2 23:13:00 2010 (r6141) @@ -36,7 +36,7 @@ { WRAP( ) sb->connect(); - osync_context_report_success(ctx); +// osync_context_report_success(ctx); osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); } @@ -71,20 +71,20 @@ osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); } - static void read_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata) { - WRAP( ) - sb->commit(change); -// osync_context_report_success(ctx); - osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); - } - +// static void read_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata) { +// WRAP( ) +// sb->commit(change); +// // osync_context_report_success(ctx); +// osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); +// } +// static void commitAll_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) { WRAP( ) sb->commitAll(); // osync_context_report_success(ctx); osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); } - +// // static void commit_all_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata) { // WRAP( ) // sb->commitAll(change); @@ -249,10 +249,10 @@ // if ( m_canWrite ) // osync_objtype_sink_set_write(sink, TRUE); // if ( m_canCommitAll || m_isContact || m_isEvent || m_isNote || m_isJournal || m_isTodo) { -// if ( m_canCommitAll ) { -// osync_objtype_sink_set_committed_all_func(sink, commitAll_wrapper); -// osync_objtype_sink_set_committedall_timeout(sink, 5); -// } + if ( m_canCommitAll ) { + osync_objtype_sink_set_committed_all_func(sink, commitAll_wrapper); + osync_objtype_sink_set_committedall_timeout(sink, 5); + } // if ( m_canRead ) { // osync_objtype_sink_set_read_func(sink, read_wrapper); // osync_objtype_sink_set_read_timeout(sink, 5); Modified: plugins/akonadi-sync/trunk/src/sinkbase.h ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.h Sat Oct 2 13:11:43 2010 (r6140) +++ plugins/akonadi-sync/trunk/src/sinkbase.h Sat Oct 2 23:13:00 2010 (r6141) @@ -83,7 +83,8 @@ OSyncObjTypeSink *mSink; OSyncPluginInfo *mPluginInfo; // what do we have and what can we do - bool m_canConnect, m_canDisconnect, m_canCommit, m_canCommitAll, m_canGetChanges, m_canWrite, m_canRead, m_canSyncDone; + bool m_canConnect, m_canDisconnect, m_canCommit, m_canCommitAll, + m_canGetChanges, m_canWrite, m_canRead, m_canSyncDone; // bool m_canCommitRead, m_canBatchCommit; osync_bool m_SlowSync; }; |