From: <svn...@op...> - 2010-11-07 13:07:22
|
Author: deloptes Date: Sun Nov 7 14:07:12 2010 New Revision: 6154 URL: http://www.opensync.org/changeset/6154 Log: - clean up and fix smaller issues - consolidated version info - updated debugging info Modified: plugins/akonadi-sync/trunk/README 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/README ============================================================================== --- plugins/akonadi-sync/trunk/README Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/README Sun Nov 7 14:07:12 2010 (r6154) @@ -32,16 +32,22 @@ ============ 1. After installation configure the plugin with "--configure" option. - (I'm planning to make this step optional) + (This is optional if you want to have all supported sync types) 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. + file for further setup (but will be disabled by default). 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. + the configuration file (step2 above). 4. Sync with the "--sync" or similar option +Known Issues +============ + +If you modify an item try to sync and reject, then things got messed up. +I'm still trying to understand why. + Links ===== Modified: plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/src/akonadi_opensync.cpp Sun Nov 7 14:07:12 2010 (r6154) @@ -130,7 +130,7 @@ /* FIXME: this is probably a bug in opoensync * replace & */ - static QString toXml(QString str) { + QString toXml(QString str) { str.replace("<","<").replace(">",">").replace("&","and"); return str; } @@ -214,11 +214,11 @@ if ( !strcmp(myObjType, osync_objtype_sink_get_name(sink)) ) { 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() ); + osync_plugin_resource_set_name( myRes, toXml(col.name()).toLatin1().data() ); + osync_plugin_resource_set_url(myRes, col.url().url().toLatin1().data() ); + osync_plugin_resource_set_mime(myRes, mimeType.toLatin1().data() ); configured = true; - } else if ( !strcmp(myUrl, col.url().url().toLatin1()) && !strcmp(myMimeType, mimeType.toLatin1()) ) { + } else if ( !strcmp(myUrl, col.url().url().toLatin1().data()) && !strcmp(myMimeType, mimeType.toLatin1().data()) ) { kDebug() << "aleady configured" << myObjType; configured = true; } @@ -307,8 +307,10 @@ { OSyncVersion *version = osync_version_new(error); osync_version_set_plugin(version, "akonadi-sync"); - osync_version_set_softwareversion(version, "0.40"); - osync_version_set_identifier(version, "akonadi-sync"); + osync_version_set_modelversion(version, "1"); +// osync_version_set_softwareversion(version, "0.40"); + osync_version_set_vendor(version, "Deloptes"); +// osync_version_set_identifier(version, "akonadi-sync"); osync_plugin_info_set_version(info, version); osync_version_unref(version); } @@ -344,6 +346,7 @@ osync_plugin_set_name(plugin, "akonadi-sync"); osync_plugin_set_longname(plugin, "Akonadi OpenSync Plugin"); osync_plugin_set_description(plugin, "Plugin to synchronize with Akonadi"); + osync_plugin_set_config_type(plugin, OSYNC_PLUGIN_OPTIONAL_CONFIGURATION); osync_plugin_set_initialize(plugin, akonadi_initialize); osync_plugin_set_finalize(plugin, akonadi_finalize); Modified: plugins/akonadi-sync/trunk/src/akonadisink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/akonadisink.cpp Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/src/akonadisink.cpp Sun Nov 7 14:07:12 2010 (r6154) @@ -38,6 +38,7 @@ kDebug(); OSyncObjTypeSink *sink = osync_objtype_main_sink_new( error ); wrapSink( sink ); +// osync_objtype_sink_set_userdata ( sink, this ); osync_plugin_info_set_main_sink( info, sink ); osync_objtype_sink_unref(sink); return true; Modified: plugins/akonadi-sync/trunk/src/datasink.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/datasink.cpp Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/src/datasink.cpp Sun Nov 7 14:07:12 2010 (r6154) @@ -151,13 +151,14 @@ } } +// this adds preffered to the resource configuration if not set if ( ! preferred || strcmp(preferred,m_Format.toLatin1().data() ) ) osync_plugin_resource_set_preferred_format( resource, m_Format.toLatin1().data() ); kDebug() << "Has objformat: " << m_Format; - osync_objtype_sink_set_userdata ( sink, this ); wrapSink ( sink ); +// osync_objtype_sink_set_userdata ( sink, this ); osync_objtype_sink_enable_hashtable ( sink , true ); @@ -215,6 +216,7 @@ { kDebug() << "No collection"; osync_trace ( TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print ( &oerror ) ); + error ( OSYNC_ERROR_GENERIC, "No collection"); return; } @@ -245,92 +247,100 @@ if ( checker.isWantedItem( item ) ) reportChange ( item ); else - kDebug() << item.mimeType() << "skipped!"; + kDebug() << item.id() << item.mimeType() << "skipped!"; } kDebug() << "slotItemsReceived done"; } void DataSink::reportChange ( const Item& item ) { - kDebug(); + kDebug() << ">>>>>>>>>>>>>>>>>>>"; kDebug() << "Id:" << item.id() << "\n"; kDebug() << "RemoteId:" << item.remoteId() << "\n"; kDebug() << "Mime:" << item.mimeType() << "\n"; kDebug() << "Revision:" << item.revision() << "\n"; kDebug() << "StorageCollectionId:" << item.storageCollectionId() << "\n"; kDebug() << "Url:" << item.url() << "\n"; - + kDebug() << "mtime:" << item.modificationTime().toString(Qt::ISODate) << "\n"; +// kDebug() << "mtime:" << (uint) item.modificationTime().toTime_t () << "\n"; + + if ( item.remoteId().isEmpty() ) + { + error( OSYNC_ERROR_EXPECTED, "item remote identifier missing" ); + return; + } + OSyncChange *change = 0; QString hash = getHash( item.id(), item.revision() ) ; - + kDebug() << hash; kDebug() << "item.payloadData().data()" << "\n" << item.payloadData().data(); OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env ( pluginInfo() ); - - OSyncError *error = 0; + + OSyncError *oerror = 0; OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); - OSyncChange *change = osync_change_new ( &error ); + change = osync_change_new ( &oerror ); if ( !change ) { osync_change_unref ( change ); - warning ( error ); + warning ( oerror ); return; } osync_change_set_uid ( change, item.remoteId().toLatin1().data() ); // osync_change_set_uid ( change, QString::number( item.id() ).toLatin1() ); osync_change_set_hash ( change, getHash( item.id(), item.revision() ).toLatin1().data() ); + OSyncChangeType changetype = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, changetype); - osync_hashtable_update_change ( hashtable, change ); + osync_hashtable_update_change ( hashtable, change ); if ( changetype == OSYNC_CHANGE_TYPE_UNMODIFIED ) { + kDebug()<< "skipped (unmodified)" << change; osync_change_unref(change); - osync_error_unref(&error); + osync_error_unref(&oerror); return; } // 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 OSyncObjFormat *format = osync_format_env_find_objformat ( formatenv, m_Format.toLatin1().data() ); int newDataSize = item.payloadData().size(); char newData[newDataSize]; memcpy(newData, item.payloadData().data(), newDataSize); // OSyncData *odata = osync_data_new ( item.payloadData().data() , item.payloadData().size(), format, &error ); - OSyncData *odata = osync_data_new ( newData, newDataSize, format, &error ); + OSyncData *odata = osync_data_new ( newData, newDataSize, format, &oerror ); if ( !odata ) { - osync_change_unref(change); - warning(error); - return; + osync_change_unref((OSyncChange*) change); + warning(oerror); + return; } - - osync_error_unref(&error); - - kDebug()<< "change" << change; - kDebug()<< "data " << odata; - kDebug()<< "context" << context(); + osync_error_unref(&oerror); + kDebug()<< "context" << context(); // do I need this here - osync_data_set_objtype( odata, m_Name.toLatin1().data() ); +// osync_data_set_objtype( odata, m_Name.toLatin1().data() ); osync_change_set_data ( change, odata ); + kDebug()<< "data " << odata; +// not sure but it gets probably delete together with change below +// osync_data_unref ( (OSyncData *) odata ); +// osync_hashtable_update_change ( hashtable, change ); //Do we need an update after setting data? -// not sure but it gets probably delete together with data -// osync_data_unref ( odata ); osync_context_report_change ( context(), change ); -// osync_hashtable_update_change ( hashtable, change ); //????? - +// osync_hashtable_update_change ( hashtable, change ); +// kDebug()<< "change" << change; osync_change_unref ( change ); + kDebug()<< "<<<<<<<<<<<<<< change done"; + } void DataSink::slotGetChangesFinished ( KJob * ) { kDebug(); - OSyncError *error = 0; + OSyncError *oerror = 0; OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env( pluginInfo() ); OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); @@ -340,11 +350,11 @@ QString uid ( ( char * ) u->data ); kDebug() << "going to delete with uid:" << uid; - OSyncChange *change = osync_change_new ( &error ); + OSyncChange *change = osync_change_new ( &oerror ); if ( !change ) { osync_change_unref ( change ); - warning ( error ); + warning ( oerror ); continue; } @@ -354,28 +364,27 @@ osync_change_set_changetype ( change, OSYNC_CHANGE_TYPE_DELETED ); OSyncObjFormat *format = osync_format_env_find_objformat( formatenv, m_Format.toLatin1().data() ); - error = 0; - OSyncData *data = osync_data_new( NULL, 0, format, &error ); + oerror = 0; + OSyncData *data = osync_data_new( NULL, 0, format, &oerror ); if ( !data ) { - osync_data_unref ( data ); osync_change_unref( change ); - warning( error ); + warning( oerror ); continue; } osync_data_set_objtype( data, m_Name.toLatin1().data() ); osync_change_set_data( change, data ); - osync_data_unref(data); - osync_hashtable_update_change ( hashtable, change ); + osync_data_unref((OSyncData *)data); +// osync_hashtable_update_change ( hashtable, change ); osync_context_report_change ( context(), change ); -// osync_hashtable_update_change ( hashtable, change ); + osync_hashtable_update_change ( hashtable, change ); osync_change_unref ( change ); } osync_list_free ( uids ); - osync_error_unref(&error); + osync_error_unref(&oerror); kDebug() << "got all changes success()."; success(); @@ -387,13 +396,12 @@ OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable ( sink() ); -// kDebug() << "change hash:" << osync_change_get_hash ( change ) ; - QString remoteId = QString::fromLatin1 ( osync_change_get_uid ( change ) ); QString hash = QString::fromLatin1 ( osync_change_get_hash ( change ) ); - + //TODO: use id to identify items int id = idFromHash(hash); + kDebug() << "change id:" << id; kDebug() << "change uid:" << remoteId; kDebug() << "change hash:" << hash; @@ -403,7 +411,7 @@ Akonadi::Collection col = collection(); if ( !col.isValid() ) { - error( OSYNC_ERROR_GENERIC, "Invalid collction."); + error( OSYNC_ERROR_GENERIC, "Invalid collection."); return; } @@ -412,7 +420,7 @@ case OSYNC_CHANGE_TYPE_ADDED: { Item item; - char *plain = 0; + char *plain = 0; // plain is freed by data osync_data_get_data ( osync_change_get_data ( change ), &plain, /*size*/0 ); QString str = QString::fromUtf8( plain ); // QString str = QString::fromLatin1( plain ); @@ -440,26 +448,27 @@ case OSYNC_CHANGE_TYPE_MODIFIED: { - char *plain = 0; + char *plain = 0; // plain is freed by data osync_data_get_data ( osync_change_get_data ( change ), &plain, /*size*/0 ); QString str = QString::fromUtf8( plain ); - kDebug() << "data" << str; - Item item = fetchItem ( remoteId ); + + Item item = fetchItem ( remoteId ); if ( ! item.isValid() ) { error( OSYNC_ERROR_GENERIC, "Unable to fetch item."); return; } setPayload ( &item, str ); + kDebug() << "data" << str; ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob ( item ); if ( ! modifyJob->exec() ) { - error ( OSYNC_ERROR_GENERIC, "Unable to fetch item."); + error ( OSYNC_ERROR_GENERIC, "Unable to run modify job."); return; } else { item = modifyJob->item(); if ( ! item.isValid() ) { - error( OSYNC_ERROR_GENERIC, "Unable to fetch item."); + error( OSYNC_ERROR_GENERIC, "Unable to modify item."); return; } osync_change_set_uid ( change, item.remoteId().toLatin1().data() ); @@ -473,17 +482,19 @@ { Item item = fetchItem ( remoteId ); if ( ! item.isValid() ) { + // FIXME break or return? // error( OSYNC_ERROR_GENERIC, "Unable to fetch item"); - break; // FIXME break or return? + break; } +// kDebug() << "deleted: (testing skipped)" << remoteId; +// comment out to skip deleting for testing ItemDeleteJob *job = new ItemDeleteJob( item ); if ( ! job->exec() ) { -// error( OSYNC_ERROR_GENERIC, "Unable to delete item"); - break; + error( OSYNC_ERROR_GENERIC, "Unable to delete item"); + return; } - osync_change_set_uid ( change, item.remoteId().toLatin1().data() ); - kDebug() << "deleted: (testing skipped)" << remoteId; + osync_change_set_uid ( change, item.remoteId().toLatin1().data() ); break; } @@ -571,6 +582,7 @@ } // no such item found? + // we'll check after calling this function return Item(); } @@ -585,9 +597,10 @@ if ( item.remoteId() == remoteId ) return item; // no such item found? - // this will be handled as invalid item + // we'll check after calling this function return Item(); } + void DataSink::syncDone() { kDebug() << "sync for sink member done"; Modified: plugins/akonadi-sync/trunk/src/sinkbase.cpp ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.cpp Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/src/sinkbase.cpp Sun Nov 7 14:07:12 2010 (r6154) @@ -44,7 +44,7 @@ static void disconnect_wrapper(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) { WRAP( ) sb->disconnect(); - osync_objtype_sink_unref(sink); + osync_objtype_sink_unref(sink); //needed? osync_trace( TRACE_EXIT, "%s", __PRETTY_FUNCTION__ ); } @@ -97,11 +97,11 @@ m_canDisconnect(false), m_canCommit (false), m_canCommitAll (false), -// unused m_canBatchCommit(false), m_canGetChanges(false), m_canWrite (false), m_canRead (false), m_canSyncDone (false), + m_canBatchCommit(false), m_SlowSync (false) { @@ -112,7 +112,7 @@ m_canWrite = ( features & Write ) ? true : false; m_canCommitAll = ( features & CommittedAll ) ? true : false; m_canRead = ( features & Read ) ? true : false; -// unused m_canBatchCommit = ( features & BatchCommit ) ? true : false; + m_canBatchCommit = ( features & BatchCommit ) ? true : false; m_canSyncDone = ( features & SyncDone ) ? true : false; } @@ -228,6 +228,7 @@ kDebug() << ">> m_canCommitAll:" << m_canCommitAll; kDebug() << ">> m_canRead:" << m_canRead; kDebug() << ">> m_canSyncDone:" << m_canSyncDone; + kDebug() << ">> m_canBatchCommit:" << m_canBatchCommit; if ( m_canConnect ) { osync_objtype_sink_set_connect_func(sink, connect_wrapper); Modified: plugins/akonadi-sync/trunk/src/sinkbase.h ============================================================================== --- plugins/akonadi-sync/trunk/src/sinkbase.h Thu Nov 4 00:31:40 2010 (r6153) +++ plugins/akonadi-sync/trunk/src/sinkbase.h Sun Nov 7 14:07:12 2010 (r6154) @@ -91,8 +91,8 @@ mutable OSyncContext *mContext; // 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; -// unused bool m_canCommitRead, m_canBatchCommit; + m_canGetChanges, m_canWrite, m_canRead, m_canSyncDone, m_canBatchCommit; +// unused bool m_canCommitRead; osync_bool m_SlowSync; }; |