From: <svn...@op...> - 2010-09-23 01:07:24
|
Author: deloptes Date: Thu Sep 23 03:07:14 2010 New Revision: 6136 URL: http://www.opensync.org/changeset/6136 Log: - fixed the connect function TODO: need to fix get_changes 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 Modified: plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Tue Sep 21 09:02:06 2010 (r6135) +++ plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Thu Sep 23 03:07:14 2010 (r6136) @@ -93,6 +93,8 @@ else continue; kDebug() << "Info:"<< osync_plugin_info_get_groupname(info); + + osync_objtype_sink_set_userdata(sink, ds); if ( !ds->initialize( plugin, info, sink, error ) ) { delete ds; delete mainSink; Modified: plugins/akonadi-sync/trunk/src/akonadisink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadisink.cpp Tue Sep 21 09:02:06 2010 (r6135) +++ plugins/akonadi-sync/trunk/src/akonadisink.cpp Thu Sep 23 03:07:14 2010 (r6136) @@ -24,6 +24,10 @@ #include <KDebug> +#include <opensync/opensync-plugin.h> +#include <opensync/opensync-data.h> +#include <opensync/opensync-format.h> + AkonadiSink::AkonadiSink() : SinkBase( Connect ) { @@ -45,6 +49,11 @@ osync_plugin_info_set_main_sink( info, sink ); wrapSink( sink ); // osync_objtype_sink_unref(sink); +// OSyncHashTable * hashtable = osync_objtype_sink_get_hashtable(sink); +// if( hashtable ) +// osync_objtype_sink_enable_hashtable(sink, TRUE); +// if( ! hashtable ) +// kDebug() << "No hashtable for sync"; return true; } Modified: plugins/akonadi-sync/trunk/src/datasink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/datasink.cpp Tue Sep 21 09:02:06 2010 (r6135) +++ plugins/akonadi-sync/trunk/src/datasink.cpp Thu Sep 23 03:07:14 2010 (r6136) @@ -24,16 +24,10 @@ // #include <glib/ghash.h> #include "datasink.h" -// #include "plugin/opensync_plugin_info_internals.h" -// #include "plugin/opensync_objtype_sink_internals.h" -// #include "helper/opensync_hashtable_internals.h" - -#include <opensync/opensync.h> -#include <opensync/opensync-helper.h> -#include <opensync/opensync-plugin.h> -// #include <opensync/helper/opensync_hashtable.h> -// #include <opensync/helper/opensync_sink_state_db.h> -// #include <opensync/helper/opensync_hashtable.h> + +// #include <opensync/opensync.h> +// #include <opensync/opensync-helper.h> +// #include <opensync/opensync-plugin.h> // calendar includes #include <kcal/incidence.h> @@ -75,35 +69,42 @@ bool DataSink::initialize(OSyncPlugin * plugin, OSyncPluginInfo * info, OSyncObjTypeSink *sink, OSyncError ** error) { -// Q_UNUSED( plugin ); -// Q_ASSERT( info ); -// Q_ASSERT( sink ); kDebug() << "initializing" << osync_objtype_sink_get_name(sink); -// Q_UNUSED(plugin); - bool enabled = osync_objtype_sink_is_enabled( sink ); - if ( ! enabled ) { - kDebug() << "sink is not enabled.."; - return false; - } + Q_UNUSED( plugin ); + Q_UNUSED( info ); + Q_UNUSED( error ); + + bool enabled = osync_objtype_sink_is_enabled( sink ); + if( ! enabled ) { + kDebug() << "sink is not enabled.."; + 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; } - + wrapSink( sink ); + osync_objtype_sink_enable_hashtable(sink , TRUE); + m_hashtable = osync_objtype_sink_get_hashtable(sink); -kDebug() << "Sink wrapped: " << osync_objtype_sink_get_name(sink); -// osync_objtype_sink_set_userdata(sink, env); + if ( ! m_hashtable ) + kDebug() << ">> NO hashtable for objtype:" << osync_objtype_sink_get_name(sink); + +// kDebug() << "Sink wrapped: " << osync_objtype_sink_get_name(sink); + +// TODO +// m_hashtable = osync_objtype_sink_get_hashtable(sink); +// if( m_hashtable ) +// osync_objtype_sink_enable_hashtable(sink, TRUE); +// if( ! m_hashtable ) { +// kDebug() << "No hashtable for sync"; +// osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print( error ) ); +// return false; +// } -/* osync_objtype_sink_enable_hashtable(sink, TRUE); - m_hashtable = osync_objtype_sink_get_hashtable(sink); - if ( ! m_hashtable ) { - kDebug() << "No hashtable for sync"; -// return false; - } */ return true; } @@ -137,6 +138,7 @@ // #if 1 Collection col = collection(); if ( !col.isValid() ) { + kDebug() << "No collection"; osync_trace( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print( &oerror ) ); return; } @@ -158,7 +160,7 @@ ItemFetchJob *job = new ItemFetchJob( col ); job->fetchScope().fetchFullPayload(); - osync_trace( TRACE_INTERNAL, "EKO fetchFullPayload" ); + 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 * ) ) ); @@ -393,10 +395,10 @@ KABC::VCardConverter converter; KABC::Addressee vcard = converter.parseVCard( str.toLatin1() ); kDebug() << vcard.uid() << vcard.name(); - item->setMimeType( KABC::Addressee::mimeType() ); - // item->setPayload<KABC::Addressee>( str ); // FIXME - item->setPayloadFromData( str.toLatin1() ); // FIXME + //item->setPayload<KABC::Addressee>( vcard ); // FIXME + item->setPayloadFromData( vcard.toString().toLatin1() ); // FIXME + //item->setPayload<KABC::Addressee>( vcard.toString() ); // FIXME break; } case Notes: { @@ -470,10 +472,12 @@ void DataSink::syncDone() { - kDebug(); + kDebug() << "sync for sink member done"; +// OSyncError *error = 0; +// osync_objtype_sink_save_hashtable( sink, &error ); // OSyncError *error = 0; -// osync_objtype_sink_sync_done( m_hashtable, &error ); - +// OSyncObjTypeSink *sink =sink(); +// osync_objtype_sink_save_hashtable( sink , &error ); //TODO check for errors success(); } Modified: plugins/akonadi-sync/trunk/src/sinkbase.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.cpp Tue Sep 21 09:02:06 2010 (r6135) +++ plugins/akonadi-sync/trunk/src/sinkbase.cpp Thu Sep 23 03:07:14 2010 (r6136) @@ -1,7 +1,7 @@ /* Copyright (c) 2008 Volker Krause <vk...@kd...> Copyright (c) 2010 Emanoil Kotsev <del...@ya...> - + $Id$ This library is free software; you can redistribute it and/or modify it @@ -23,60 +23,39 @@ #include "sinkbase.h" #include <KDebug> -#define WRAP0(X) \ - osync_trace( TRACE_ENTRY, "%s(%p,%p, %p, %p)", __PRETTY_FUNCTION__, sink, userdata, info, ctx); \ - SinkBase *sb = reinterpret_cast<SinkBase*>(userdata ); \ - sb->setContext( ctx ); \ - sb->setPluginInfo( info ); \ - sb->X; \ - osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); - -#define WRAP1(X) \ - osync_trace( TRACE_ENTRY, "%s(%p,%p, %p, %p)", __PRETTY_FUNCTION__, sink, userdata, info, ctx); \ +#define WRAP(X) \ + osync_trace( TRACE_ENTRY, "%s(%p,%p, %p, %p)", __PRETTY_FUNCTION__, sink, info, ctx, userdata); \ SinkBase *sb = reinterpret_cast<SinkBase*>(userdata ); \ - if ( slow_sync ) sb->setSlowSink(slow_sync); \ sb->setContext( ctx ); \ sb->setPluginInfo( info ); \ sb->X; \ osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); - - extern "C" { static void connect_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata ) { - WRAP0( connect() ) + WRAP( connect() ) } static void disconnect_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) { - WRAP0( disconnect() ) + WRAP( disconnect() ) } - static void contact_get_changes_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { - - WRAP1 ( getChanges() ) - } - - static void event_get_changes_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { - WRAP1 ( getChanges() ) - } + static void get_changes_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { - static void todo_get_changes_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { - WRAP1( getChanges() ) - } - - static void journal_get_changes_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { - WRAP1( getChanges() ) + WRAP ( getChanges() ) + if ( slow_sync ) + sb->setSlowSink(slow_sync); } static void sync_done_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) { - WRAP0( syncDone() ) + WRAP( syncDone() ) } static void commit_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata) { - WRAP0( commit(change) ) + WRAP( commit(change) ) } } // extern C @@ -109,6 +88,8 @@ void SinkBase::connect() { Q_ASSERT( false ); + // Success! + osync_context_report_success(mContext); } void SinkBase::setSlowSink(osync_bool s) @@ -175,21 +156,14 @@ Q_ASSERT( mSink == 0 ); mSink = sink; - if ( ! m_canConnect ) + if ( ! m_canConnect && ( m_hasEvent || m_hasContact) ) osync_objtype_sink_set_connect_func(sink, connect_wrapper); - if ( ! m_canDisconnect ) + if ( ! m_canDisconnect && ( m_hasEvent || m_hasContact) ) osync_objtype_sink_set_disconnect_func(sink, disconnect_wrapper); + if ( ! m_canGetChanges && ( m_hasEvent || m_hasContact) ) + osync_objtype_sink_set_get_changes_func(sink, get_changes_wrapper); - if ( ! m_canGetChanges && m_hasContact ) - osync_objtype_sink_set_get_changes_func(sink, contact_get_changes_wrapper); - if ( ! m_canGetChanges && m_hasEvent ) - osync_objtype_sink_set_get_changes_func(sink, event_get_changes_wrapper); - if ( ! m_canGetChanges && m_hasTodo ) - osync_objtype_sink_set_get_changes_func(sink, todo_get_changes_wrapper); - if ( ! m_canGetChanges && m_hasNote ) - osync_objtype_sink_set_get_changes_func(sink, journal_get_changes_wrapper); - - if ( ! m_canCommit ) + if ( ! m_canCommit && ( m_hasEvent || m_hasContact) ) osync_objtype_sink_set_commit_func(sink, commit_wrapper); // TODO: check if relevant for akonadi // if ( m_canWrite ) @@ -200,7 +174,7 @@ // osync_objtype_sink_set_commit_func(sink, 0); // if ( m_canBatchCommit ) // osync_objtype_sink_set_commit_func(sink, 0); - if ( ! m_canSyncDone ) + if ( ! m_canSyncDone && ( m_hasEvent || m_hasContact) ) osync_objtype_sink_set_sync_done_func(sink, sync_done_wrapper); } |