From: <svn...@op...> - 2010-10-10 21:46:11
|
Author: deloptes Date: Sun Oct 10 23:46:01 2010 New Revision: 6144 URL: http://www.opensync.org/changeset/6144 Log: I took advantage to add support for multiple collection. The thing is that I have to run --discover after each --configure and I am not sure if it is intended to work like this. TODO: A. check for ressources and report syncs only if format is supported by the other member(s) in the discover phase B. Work the event/note/todo sync out C. Check why todo is reporting XML validation error. Modified: plugins/akonadi-sync/trunk/README plugins/akonadi-sync/trunk/src/akonadi-sync plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp plugins/akonadi-sync/trunk/src/datasink.cpp plugins/akonadi-sync/trunk/src/datasink.h plugins/akonadi-sync/trunk/src/sinkbase.cpp Modified: plugins/akonadi-sync/trunk/README ============================================================================== --- plugins/akonadi-sync/trunk/README Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/README Sun Oct 10 23:46:01 2010 (r6144) @@ -4,7 +4,14 @@ OpenSync is a plugin-based application that basically provides a framework for syncing groups which can have two or more members. -This is the Akonadi (KDE 4.x) PIM synchronisation framework +This is the Akonadi (KDE 4.x) PIM synchronisation framework. +It provides sync ability with KDE > 4.5 using the akonadi interface. + +Important +========= + +Currently Calendar does not work. + Requirements ============ @@ -13,14 +20,28 @@ Installation ============ -export PKG_CONFIG_PATH=/opt/custom/opensync/lib/pkgconfig +export PKG_CONFIG_PATH=/path/to/opensync/installation_prefix/lib/pkgconfig mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=$prefix /path/to/opensync/source/ +cmake -DCMAKE_INSTALL_PREFIX=$installation_prefix /path/to/opensync/source/ make make install +Usage +============ + +1. After installation configure the plugin with "--configure" option. + (I'm planning to make this step optional) +2. Discover supported features on both sides (sync members and akonadi) + with "--discover" option. This step will discover sync features (supported + formats) and akonadi collection. They will be available in the configuration + file for further setup. +3. Reconfigure the plugin with "--configure" option. Most likely you will need + to enable or disable sync with given collection represented as a ressource in + the configuration file. +4. Sync with the "--sync" or similar option + Links ===== Modified: plugins/akonadi-sync/trunk/src/akonadi-sync ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadi-sync Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/src/akonadi-sync Sun Oct 10 23:46:01 2010 (r6144) @@ -5,11 +5,9 @@ <Enabled>1</Enabled> <Formats> <Format> - <Config>VCARD_EXTENSION=KDE</Config> <Name>vcard21</Name> </Format> <Format> - <Config>VCARD_EXTENSION=KDE</Config> <Name>vcard30</Name> </Format> </Formats> @@ -33,6 +31,9 @@ <Enabled>1</Enabled> <Formats> <Format> + <Name>vtodo10</Name> + </Format> + <Format> <Name>vtodo20</Name> </Format> </Formats> Modified: plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Sun Oct 10 23:46:01 2010 (r6144) @@ -55,6 +55,7 @@ static void* akonadi_initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { + kDebug(); osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, plugin, info, error); if ( !app ) @@ -75,6 +76,9 @@ // 10) List looping is more standard // --------------------------------- // osync_plugin_get_config_type(); + + unsigned int objects_supported = 4; + OSyncList *s = NULL, *list = osync_plugin_info_get_objtype_sinks(info); for ( s = list; s; s = s->next ) { OSyncObjTypeSink *sink = (OSyncObjTypeSink*) s->data; @@ -87,97 +91,169 @@ ds = new DataSink( DataSink::Calendars ); else if ( sinkName == "contact" ) ds = new DataSink( DataSink::Contacts ); -// FIXME: implement todos an journal (notes) else if ( sinkName == "note" ) - ds = new DataSink( DataSink::Journals ); + ds = new DataSink( DataSink::Notes ); else if ( sinkName == "todo" ) ds = new DataSink( DataSink::Todos ); -// else if ( sinkName == "note" ) -// ds = new DataSink( DataSink::Notes ); else continue; + // there might be someting more intelligent to check when to return below if ( !ds->initialize( plugin, info, sink, error ) ) { - delete ds; - delete mainSink; - osync_trace(TRACE_EXIT_ERROR, " %s: NULL", __func__); - return 0; + osync_objtype_sink_set_enabled(sink, false); + osync_objtype_sink_set_available(sink, false); + delete ds; + objects_supported--; } } - osync_trace(TRACE_EXIT, " %s: %p", __func__, mainSink); - return mainSink; + + +// if we support at least one object return the mainSink + if ( objects_supported >= 1 ) { + osync_trace(TRACE_EXIT, " %s: %p", __func__, mainSink); + return mainSink; + } + else { + delete mainSink; + osync_trace(TRACE_EXIT_ERROR, " %s: NULL", __func__); + return 0; + } } - - - //FIXME: this probably a bug in opoensync - // replace & + + /* FIXME: this is probably a bug in opoensync + * replace & + */ static QString toXml(QString str) { str.replace("<","<").replace(">",">").replace("&","and"); return str; } - - static osync_bool testSupport(OSyncPluginInfo *info, - OSyncPluginConfig *config, - const char* mType, - const char* mimeType, - const char* objFormat, - OSyncError **error ) { - // fetch all akonadi calendar collections + + static OSyncPluginResource *create_resource (const char* mType , OSyncError **error ) { + //TODO + // check for supported objformat + kDebug(); + OSyncPluginResource *res= osync_plugin_resource_new( error ); + osync_plugin_resource_set_objtype( res, mType ); + + if ( !strcmp(mType,"contact") ) { + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vcard21", error ) ); + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vcard30", error ) ); + osync_plugin_resource_set_preferred_format( res, "vcard30" ); + } else if ( !strcmp(mType,"event") ) { + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vevent10", error ) ); + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vevent20", error ) ); + osync_plugin_resource_set_preferred_format( res, "vevent20" ); + } else if ( !strcmp(mType,"todo") ) { + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vtodo10", error ) ); + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vtodo20", error ) ); + osync_plugin_resource_set_preferred_format( res, "vtodo20" ); + } else if ( !strcmp(mType,"note") ) { + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vnote11", error ) ); + osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( "vjournal", error ) ); + osync_plugin_resource_set_preferred_format( res, "vjournal" ); + } else + return NULL; + kDebug() << "create resource for" << mType << "done"; + return res; + } + + + /* + Check for support of following types + text/directory - this is the addressbook + application/x-vnd.kde.contactgroup - is contact group ... I'm not sure about it ATM + text/calendar - this is general mime for the whole calendar, but we are interested in the details + application/x-vnd.akonadi.calendar.event, + application/x-vnd.akonadi.calendar.todo, + application/x-vnd.akonadi.calendar.journal, + application/x-vnd.akonadi.calendar.freebusy - this will be most probably ignored, so not checking for it + */ + + static osync_bool testSupport(OSyncObjTypeSink *sink, OSyncPluginConfig *config, OSyncError **error ) { + + kDebug(); + QString mimeType; + + const char *myType = osync_objtype_sink_get_name(sink); Akonadi::CollectionFetchScope scope; scope.setIncludeUnsubscribed( true ); + if ( ! strcmp(myType,"contact") ) + mimeType = "application/x-vnd.kde.contactgroup" ; // text/directory + else if ( ! strcmp(myType,"event") ) + mimeType = "application/x-vnd.akonadi.calendar.event"; + else if ( ! strcmp(myType,"note") ) + mimeType = "application/x-vnd.akonadi.calendar.journal"; + else if ( ! strcmp(myType,"todo") ) + mimeType = "application/x-vnd.akonadi.calendar.todo"; + else + return false; + scope.setContentMimeTypes( QStringList() << mimeType ); - Akonadi::CollectionFetchJob *jobCal = new Akonadi::CollectionFetchJob( + // fetch all akonadi collections for this mimetype + Akonadi::CollectionFetchJob *jobCol = new Akonadi::CollectionFetchJob( Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive ); - jobCal->setFetchScope(scope); - if ( !jobCal->exec() ) - return FALSE; - - Akonadi::Collection::List colsCal = jobCal->collections(); - kDebug() << "found" << colsCal.count() << "collections"; - -// OSyncFormatEnv *formatEnv = osync_plugin_info_get_format_env(info); - OSyncObjTypeSink *sinkEvent = osync_objtype_sink_new(mType, error); - OSyncPluginResource *res = NULL; - foreach ( const Akonadi::Collection &col, colsCal ) { + jobCol->setFetchScope(scope); + if ( !jobCol->exec() ) + return false; + + Akonadi::Collection::List colsList = jobCol->collections(); + int col_count = colsList.count(); + kDebug() << "found" << col_count << "collections"; + bool enabled = false; + bool configured = false; + + foreach ( const Akonadi::Collection &col, colsList ) { kDebug() << "processing resource " << col.name() << col.contentMimeTypes(); - kDebug() << " " << col.name() << col.url().url(); + kDebug() << "url " << col.name() << col.url().url(); + configured = false; - res = osync_plugin_config_find_active_resource(config ,mType); - if ( ! res) { -// res = osync_plugin_resource_new( error ); -// osync_plugin_resource_add_objformat_sink( res, osync_objformat_sink_new( objFormat, error ) ); -// osync_plugin_resource_enable(res,FALSE); -// osync_plugin_config_add_resource( config, res ); - kDebug() << "No support for " << mType << " disabled"; -// osync_objtype_sink_set_enabled( sinkEvent, FALSE ); - osync_objtype_sink_set_enabled( sinkEvent, FALSE ); - osync_objtype_sink_set_available( sinkEvent, FALSE ); - continue; + OSyncList *resList = osync_plugin_config_get_resources(config); + for ( OSyncList *r = resList; r; r = r->next ) { + OSyncPluginResource *myRes = (OSyncPluginResource*) r->data; + + const char *myObjType = osync_plugin_resource_get_objtype(myRes); + const char *myMimeType = osync_plugin_resource_get_mime(myRes); + const char *myUrl = osync_plugin_resource_get_url(myRes); + + if ( !strcmp(myObjType, myType) ) { + if ( !strcmp(myUrl , "default") ) { + osync_plugin_resource_set_name( myRes, toXml(col.name()).toLatin1() ); + osync_plugin_resource_set_url(myRes, col.url().url().toLatin1()); + osync_plugin_resource_set_mime(myRes, mimeType.toLatin1() ); + configured = true; + } else if ( !strcmp(myUrl, col.url().url().toLatin1()) && !strcmp(myMimeType, mimeType.toLatin1()) ) { + kDebug() << "aleady configured" << myObjType; + configured = true; + } + if (! enabled ) + enabled = osync_plugin_resource_is_enabled(myRes); + } } + + if ( ! configured ) { + OSyncPluginResource *newRes = create_resource(myType, error ) ; + osync_plugin_resource_set_name( newRes, toXml(col.name()).toLatin1() ); + osync_plugin_resource_set_url(newRes, col.url().url().toLatin1()); + osync_plugin_resource_set_mime(newRes, mimeType.toLatin1() ); + if ( ! enabled ) { + osync_plugin_resource_enable( newRes, true ); + enabled = true; + } + else { + osync_plugin_resource_enable( newRes, false ); + } + + osync_plugin_config_add_resource(config , newRes); + configured = true; + } + + } - osync_plugin_resource_set_objtype( res, mType ); - QString myname =QString::fromLatin1( osync_plugin_resource_get_name( res ) ); // - if ( myname.size() > 0 ) - myname.append(';').append(toXml(col.name())); - else - myname = toXml(col.name()); - osync_plugin_resource_set_name( res, myname.toUtf8() ); // TODO: full path instead of the name - // - osync_plugin_resource_set_url( res, col.url().url().toLatin1() ); - osync_plugin_resource_set_mime( res, mimeType ); -// if (osync_plugin_resource_is_enabled(res)) { -// osync_plugin_resource_set_preferred_format( res, objFormat ); -// } - osync_plugin_resource_enable(res,TRUE); - osync_objtype_sink_set_enabled( sinkEvent, TRUE ); - osync_objtype_sink_set_available( sinkEvent, TRUE ); - } - - osync_plugin_info_add_objtype( info, sinkEvent ); - return TRUE; + + return configured; } static osync_bool akonadi_discover(OSyncPluginInfo *info, void *userdata, OSyncError **error ) @@ -191,42 +267,35 @@ osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); return false; } - if ( !Akonadi::Control::start() ) + if ( !Akonadi::Control::start() ) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "Akonadi not running."); return false; + } - /* - Check for support of following types - text/directory - this is the addressbook - application/x-vnd.kde.contactgroup - is contact group ... I'm not sure about it ATM - text/calendar - this is general mime for the whole calendar, but we are interested in the details - application/x-vnd.akonadi.calendar.event, - application/x-vnd.akonadi.calendar.todo, - application/x-vnd.akonadi.calendar.journal, - application/x-vnd.akonadi.calendar.freebusy - this will be most probably ignored, so not checkign for it - */ - -// testSupport(info, config, "contact", "application/x-vnd.kde.contactgroup", "vcard20" ,error); - testSupport(info, config, "contact", "application/x-vnd.kde.contactgroup", "vcard30" ,error); - - testSupport(info, config, "event", "application/x-vnd.akonadi.calendar.event", "vevent20" ,error); - -// testSupport(info, config, "todo", "application/x-vnd.akonadi.calendar.todo", "vtodo10" ,error); - testSupport(info, config, "todo", "application/x-vnd.akonadi.calendar.todo", "vtodo20" ,error); - - testSupport(info, config, "note", "application/x-vnd.akonadi.calendar.journal", "vjournal" ,error); -// testSupport(info, config, "note", "application/x-vnd.kde.notes", "vnote11" ,error); - - // set information about the peer (KDE itself) + OSyncList *sinks = osync_plugin_info_get_objtype_sinks(info); + for ( OSyncList *s = sinks; s; s = s->next ) { + OSyncObjTypeSink *sink = (OSyncObjTypeSink*) s->data; + // check if sync supported + if ( ! testSupport(sink, config, error) ) { + osync_objtype_sink_set_available(sink, false); + } + else { + osync_objtype_sink_set_available(sink, true); + } + osync_plugin_info_add_objtype( info, sink ); + } + // set information about the peer (KDE itself) { OSyncVersion *version = osync_version_new(error); osync_version_set_plugin(version, "Akonadi-sync"); - osync_version_set_softwareversion(version, "4.5"); + osync_version_set_softwareversion(version, "0.40"); osync_version_set_identifier(version, "akonadi-sync"); osync_plugin_info_set_version(info, version); osync_version_unref(version); } + osync_list_free(sinks); osync_trace(TRACE_EXIT, "%s", __func__); - return TRUE; + return true; } static void akonadi_finalize(void *userdata) @@ -235,7 +304,6 @@ kDebug(); AkonadiSink *sink = reinterpret_cast<AkonadiSink*>( userdata ); sink->disconnect(); -// delete sink; delete kcd; kcd = 0; delete app; @@ -251,7 +319,7 @@ if ( !plugin ) { osync_trace(TRACE_EXIT_ERROR, "%s: Unable to instantiate: %s", __func__, osync_error_print(error)); osync_error_unref(error); - return FALSE; + return false; } osync_plugin_set_name(plugin, "akonadi-sync"); @@ -267,12 +335,12 @@ if ( ! osync_plugin_env_register_plugin(env, plugin, error) ) { osync_trace(TRACE_EXIT_ERROR, "%s: Unable to register: %s", __func__, osync_error_print(error)); osync_error_unref(error); - return FALSE; + return false; } osync_plugin_unref(plugin); osync_trace(TRACE_EXIT, "%s", __func__); - return TRUE; + return true; } Modified: plugins/akonadi-sync/trunk/src/datasink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/datasink.cpp Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/src/datasink.cpp Sun Oct 10 23:46:01 2010 (r6144) @@ -43,7 +43,6 @@ #include <KDebug> #include <KLocale> -#include <KUrl> using namespace Akonadi; @@ -51,7 +50,9 @@ DataSink::DataSink ( int type ) : SinkBase ( GetChanges | Commit | SyncDone ), - m_Format(0) + m_Format(0), + m_Enabled(false), + m_Url(0) { kDebug() << "Constr.objtype:" << type; m_type = type; @@ -60,7 +61,6 @@ 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; } @@ -74,7 +74,8 @@ kDebug() << "initializing" << osync_objtype_sink_get_name ( sink ); Q_UNUSED ( plugin ); Q_UNUSED ( info ); - Q_UNUSED ( error ); + Q_UNUSED ( error ); + OSyncPluginConfig *config = osync_plugin_info_get_config ( info ); if ( !config ) @@ -83,23 +84,19 @@ 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 ); - osync_objtype_sink_set_available(sink, FALSE); -// return false; - } else { - osync_objtype_sink_set_available(sink, TRUE); - } - +// FIXME enable checks on sync/commit etc!! OSyncPluginResource *resource = osync_plugin_config_find_active_resource ( config, osync_objtype_sink_get_name ( sink ) ); - OSyncList *objfrmtList = osync_plugin_resource_get_objformat_sinks ( resource ); + if ( resource && ! osync_plugin_resource_is_enabled(resource) ) { +// osync_error_set( error, OSYNC_ERROR_MISCONFIGURATION, i18n ( "No active resource for type \"%s\" found", m_type ).toLatin1() ); + m_Enabled = FALSE; + return false; + } else + m_Enabled = TRUE; + + m_Url = osync_plugin_resource_get_url ( resource ); - OSyncList *r; -// bool hasObjFormat; - for ( r = objfrmtList;r;r = r->next ) + OSyncList *objfrmtList = osync_plugin_resource_get_objformat_sinks ( resource ); + for ( OSyncList *r = objfrmtList;r;r = r->next ) { OSyncObjFormatSink *objformatsink = ( OSyncObjFormatSink * ) r->data; const char* tobjformat = osync_objformat_sink_get_objformat ( objformatsink ); @@ -124,13 +121,7 @@ m_Format = "vevent20"; break; } -// case Notes: -// { -// if ( !strcmp ( "vnote11", tobjformat ) ) -// m_Format = "vnote11"; -// break; -// } - case Journals: + case Notes: { if ( !strcmp ( "vnote11", tobjformat ) ) m_Format = "vnote11"; @@ -151,45 +142,34 @@ default: return false; } + kDebug() << "Has objformat: " << m_Format; } - + + wrapSink ( sink ); osync_objtype_sink_set_userdata ( sink, this ); osync_objtype_sink_enable_hashtable ( sink , TRUE ); - wrapSink ( sink ); - return true; } Akonadi::Collection DataSink::collection() const { kDebug(); - OSyncPluginConfig *config = osync_plugin_info_get_config ( pluginInfo() ); - Q_ASSERT ( config ); - - const char *objtype = osync_objtype_sink_get_name ( sink() ); - - 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 ) ); - return Collection(); - } - - const KUrl url = KUrl ( osync_plugin_resource_get_url ( res ) ); - // TODO osync_plugin_resource_get_mime() ; + + const KUrl url = KUrl ( m_Url); + if ( url.isEmpty() ) { - error ( OSYNC_ERROR_MISCONFIGURATION, i18n ( "Url for object type \"%1\" is not configured.", objtype ) ); + error ( OSYNC_ERROR_MISCONFIGURATION, i18n ( "Url for object type \"%s\" is not configured.", m_type) ); return Collection(); } return Collection::fromUrl ( url ); } + void DataSink::getChanges() { kDebug(); @@ -205,38 +185,38 @@ return; } - Collection col = collection(); - 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 ) ) + Akonadi::Collection col = collection() ; + if ( !col.isValid() ) { - warning ( oerror ); + kDebug() << "No collection"; 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" ; +// 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; + } + } + + ItemFetchJob *job = new ItemFetchJob ( col ); + job->fetchScope().fetchFullPayload(); + kDebug() << "Fetched full payload"; - 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 * ) ) ); - if ( !job->exec() ) - { - error ( OSYNC_ERROR_IO_ERROR, job->errorText() ); - return; - } + if ( !job->exec() ) + { + error ( OSYNC_ERROR_IO_ERROR, job->errorText() ); + return; + } kDebug() << "success()"; success(); @@ -279,11 +259,11 @@ // 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); QString cvtToString = item.payloadData().data() ; OSyncData *odata = osync_data_new ( cvtToString.toLatin1().data() , cvtToString.size(), format, &error ); if ( !odata ) { + warning(error); osync_data_unref ( odata ); return; } @@ -326,8 +306,8 @@ OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); OSyncList *u, *uids = osync_hashtable_get_deleted ( hashtable ); - OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env( pluginInfo() ); - OSyncObjFormat *format = osync_format_env_find_objformat( formatenv, m_Format.toLatin1() ); + OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env( pluginInfo() ); + OSyncObjFormat *format = osync_format_env_find_objformat( formatenv, m_Format.toLatin1() ); for ( u = uids; u; u = u->next ) { QString uid ( ( char * ) u->data ); @@ -354,7 +334,7 @@ osync_data_set_objtype( data, osync_objtype_sink_get_name( sink() ) ); osync_change_set_data( change, data ); osync_hashtable_update_change ( hashtable, change ); - //FIXME raport if change is at our side + osync_context_report_change ( context(), change ); osync_change_unref ( change ); osync_data_unref(data); @@ -366,86 +346,104 @@ void DataSink::commit ( OSyncChange *change ) { -// kDebug(); -// 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 ) ); + kDebug(); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); char *plain = 0; osync_data_get_data ( osync_change_get_data ( change ), &plain, /*size*/0 ); QString str = QString::fromLatin1 ( plain ); QString id = QString::fromLatin1 ( osync_change_get_uid ( change ) ); - Collection col = collection(); - switch ( osync_change_get_changetype ( change ) ) - { - case OSYNC_CHANGE_TYPE_ADDED: - { - // TODO: proper error handling (report errors to the sync engine) - if ( !col.isValid() ) // error handling - return; + kDebug() << "change uid:" << id; + kDebug() << "objform:" << osync_objformat_get_name ( osync_change_get_objformat ( change ) ); + kDebug(); + kDebug() << "data" << str; - Item item; - setPayload ( &item, str ); - item.setRemoteId( id.toLatin1() ); + Akonadi::Collection col = collection(); - ItemCreateJob *job = new Akonadi::ItemCreateJob ( item, col ); - if ( ! job->exec() ) - return; - item = job->item(); // handle !job->exec in return too.. - if ( ! item.isValid() ) // error handling - return; - osync_change_set_uid ( change, item.remoteId().toLatin1() ); - osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); - break; - } + switch ( osync_change_get_changetype ( change ) ) + { + case OSYNC_CHANGE_TYPE_ADDED: + { - case OSYNC_CHANGE_TYPE_MODIFIED: - { - Item item = fetchItem ( id ); - setPayload ( &item, str ); + if ( !col.isValid() ) { + error( OSYNC_ERROR_GENERIC, "Invalid collction."); + return; + } + + Item item; + setPayload ( &item, str ); + item.setRemoteId( id.toLatin1() ); + + ItemCreateJob *job = new Akonadi::ItemCreateJob ( item, col ); + if ( ! job->exec() ) { + error( OSYNC_ERROR_GENERIC, "Unable to create job for item."); + return; + } + + item = job->item(); // handle !job->exec in return too.. + if ( ! item.isValid() ) { + error( OSYNC_ERROR_GENERIC, "Unable to fetch item."); + return; + } + osync_change_set_uid ( change, item.remoteId().toLatin1() ); + osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); + break; + } - if ( ! item.isValid() ) // TODO proper error handling - return; + case OSYNC_CHANGE_TYPE_MODIFIED: + { + Item item = fetchItem ( id ); + setPayload ( &item, str ); + + if ( ! item.isValid() ) { + error( OSYNC_ERROR_GENERIC, "Unable to fetch item."); + return; + } + + ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob ( item ); + if ( ! modifyJob->exec() ) { + error ( OSYNC_ERROR_GENERIC, "Unable to fetch item."); + return; + } - ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob ( item ); - if ( ! modifyJob->exec() ) - return; - else item = modifyJob->item(); - osync_change_set_uid ( change, item.remoteId().toLatin1() ); - osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); - break; - } + osync_change_set_uid ( change, item.remoteId().toLatin1() ); + osync_change_set_hash ( change, QString::number ( item.revision() ).toLatin1() ); + break; + } - case OSYNC_CHANGE_TYPE_DELETED: - { - Item item = fetchItem ( id ); - if ( ! item.isValid() ) // TODO proper error handling - return; - kDebug() << "delete with id: " << item.id(); - ItemDeleteJob *job = new ItemDeleteJob( item ); + case OSYNC_CHANGE_TYPE_DELETED: + { + Item item = fetchItem ( id ); + if ( ! item.isValid() ) { + error( OSYNC_ERROR_GENERIC, "Unable to fetch item"); + return; + } + + ItemDeleteJob *job = new ItemDeleteJob( item ); + if ( ! job->exec() ) { + error( OSYNC_ERROR_GENERIC, "Unable to delete item"); + return; + } + break; + } - if ( ! job->exec() ) { - kDebug() << "unable to delete item"; + case OSYNC_CHANGE_TYPE_UNMODIFIED: + { + kDebug() << "UNMODIFIED"; + // should we do something here? + break; + } + default: + kDebug() << "got invalid changetype?"; + error(OSYNC_ERROR_GENERIC, "got invalid changetype"); return; } - break; - } - case OSYNC_CHANGE_TYPE_UNMODIFIED: - { - kDebug() << "UNMODIFIED"; - // should we do something here? - break; - } - default: - kDebug() << "got invalid changetype?"; - return; - } + osync_hashtable_update_change ( hashtable, change ); - osync_hashtable_update_change ( hashtable, change ); success(); } @@ -471,7 +469,7 @@ KCal::Incidence *calEntry = format.fromString ( str.toUtf8() ); item->setMimeType ( "application/x-vnd.akonadi.calendar.event" ); item->setPayload<IncidencePtr> ( IncidencePtr ( calEntry->clone() ) ); - + kDebug() << "payload: " << str.toUtf8(); break; } case Todos: @@ -481,7 +479,7 @@ KCal::Incidence *todoEntry = format.fromString ( str.toUtf8() ); item->setMimeType ( "application/x-vnd.akonadi.calendar.todo" ); item->setPayload<IncidencePtr> ( IncidencePtr ( todoEntry->clone() ) ); - + kDebug() << "payload: " << str.toUtf8(); break; } case Notes: @@ -489,19 +487,10 @@ 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.kde.notes" ); item->setMimeType ( "application/x-vnd.akonadi.calendar.journal" ); - item->setPayload<IncidencePtr> ( IncidencePtr ( journalEntry->clone() ) ); - + item->setPayload<IncidencePtr> ( IncidencePtr ( noteEntry->clone() ) ); + kDebug() << "payload: " << str.toUtf8(); break; } default: @@ -515,15 +504,16 @@ const Item DataSink::fetchItem ( const QString& id ) { kDebug(); - ItemFetchJob *fetchJob = new ItemFetchJob ( collection() ); - fetchJob->fetchScope().fullPayload(); - if ( fetchJob->exec() ) - foreach ( const Item &item, fetchJob->items() ) - if ( !strcmp(item.remoteId().toLatin1(), id.toLatin1() )) - return item; + ItemFetchJob *fetchJob = new ItemFetchJob ( collection() ); + fetchJob->fetchScope(); + if ( fetchJob->exec() ) + foreach ( const Item &item, fetchJob->items() ) + if ( !strcmp(item.remoteId().toLatin1(), id.toLatin1() )) + return item; // no such item found? + // this will be handled as invalid item return Item(); } @@ -532,9 +522,7 @@ kDebug() << "sync for sink member done"; OSyncError *error = 0; osync_objtype_sink_save_hashtable ( sink() , &error ); - //TODO check for errors - if ( error ) - { + if ( error ) { warning ( error ); return; } Modified: plugins/akonadi-sync/trunk/src/datasink.h ============================================================================== --- plugins/akonadi-sync/trunk/src/datasink.h Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/src/datasink.h Sun Oct 10 23:46:01 2010 (r6144) @@ -36,6 +36,8 @@ #include <opensync/opensync-data.h> #include <opensync/opensync-format.h> +#include <KUrl> + #include <boost/shared_ptr.hpp> using namespace Akonadi; @@ -48,7 +50,7 @@ Q_OBJECT public: - enum Type { Calendars = 0, Contacts, Todos, Notes, Journals }; + enum Type { Calendars = 0, Contacts, Todos, Notes }; DataSink( int type ); ~DataSink(); @@ -64,6 +66,7 @@ void slotItemsReceived( const Akonadi::Item::List & ); protected: + /** * Returns the collection we are supposed to sync with. */ @@ -89,11 +92,14 @@ private: const Item fetchItem( const QString& id ); bool setPayload( Item *item, const QString &str ); - QString m_Format; private: OSyncHashTable *m_hashtable; int m_type; + QString m_Format; + bool m_Enabled; + QString m_Url; + QString m_MimeType; }; #endif Modified: plugins/akonadi-sync/trunk/src/sinkbase.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.cpp Wed Oct 6 10:55:48 2010 (r6143) +++ plugins/akonadi-sync/trunk/src/sinkbase.cpp Sun Oct 10 23:46:01 2010 (r6144) @@ -219,27 +219,27 @@ if ( m_canConnect ) { osync_objtype_sink_set_connect_func(sink, connect_wrapper); - osync_objtype_sink_set_connect_timeout(sink, 5); + osync_objtype_sink_set_connect_timeout(sink, 15); } if ( m_canDisconnect ) { osync_objtype_sink_set_disconnect_func(sink, disconnect_wrapper); - osync_objtype_sink_set_disconnect_timeout(sink, 5); + osync_objtype_sink_set_disconnect_timeout(sink, 15); } if ( m_canGetChanges ) { osync_objtype_sink_set_get_changes_func(sink, get_changes_wrapper); - osync_objtype_sink_set_getchanges_timeout(sink, 5); + osync_objtype_sink_set_getchanges_timeout(sink, 15); } if ( m_canCommit ) { osync_objtype_sink_set_commit_func(sink, commit_wrapper); - osync_objtype_sink_set_commit_timeout(sink, 5); + osync_objtype_sink_set_commit_timeout(sink, 15); } if ( m_canCommitAll ) { osync_objtype_sink_set_committed_all_func(sink, commitAll_wrapper); - osync_objtype_sink_set_committedall_timeout(sink, 5); + osync_objtype_sink_set_committedall_timeout(sink, 15); } if ( m_canSyncDone ) { osync_objtype_sink_set_sync_done_func(sink, sync_done_wrapper); - osync_objtype_sink_set_syncdone_timeout(sink, 5); + osync_objtype_sink_set_syncdone_timeout(sink, 15); } // TODO: check if relevant for akonadi // if ( m_canWrite ) |