From: <svn...@op...> - 2005-04-05 14:39:44
|
Author: abauer Date: 2005-04-05 16:41:00 +0200 (Tue, 05 Apr 2005) New Revision: 440 Added: branches/experimental-kdepim/src/kaddrbook.cpp Removed: branches/experimental-kdepim/src/kaddrbook.c branches/experimental-kdepim/src/knotes-test.cpp Modified: branches/experimental-kdepim/ branches/experimental-kdepim/Makefile.am branches/experimental-kdepim/src/ branches/experimental-kdepim/src/kaddrbook.h branches/experimental-kdepim/src/kdepim_impl.cpp branches/experimental-kdepim/src/kdepim_sync.cpp branches/experimental-kdepim/src/knotes.cpp branches/experimental-kdepim/src/knotes.h branches/experimental-kdepim/src/osyncbase.h Log: Finished implementing the vnotes access through dcop Moved the addressbook implementation into its own file Property changes on: branches/experimental-kdepim ___________________________________________________________________ Name: svn:ignore - .libs .deps configure Makefile.in config.log config.status stamp-h1 config.h autom4te.cache libtool aclocal.m4 Makefile kdepim_sync.loT mkinstalldirs depcomp config.guess config.sub ltmain.sh missing install-sh configure.files subdirs stamp-h.in config.cache kdepim_impl_la-kcal.loT config.h.in libopensync-plugin-kdepim* + .libs .deps configure Makefile.in config.log config.status stamp-h1 config.h autom4te.cache libtool aclocal.m4 Makefile kdepim_sync.loT mkinstalldirs depcomp config.guess config.sub ltmain.sh missing install-sh configure.files subdirs stamp-h.in config.cache kdepim_impl_la-kcal.loT config.h.in libopensync-plugin-kdepim* .project .cdtproject Modified: branches/experimental-kdepim/Makefile.am =================================================================== --- branches/experimental-kdepim/Makefile.am 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/Makefile.am 2005-04-05 14:41:00 UTC (rev 440) @@ -14,6 +14,12 @@ src/osyncbase.h \ src/knotes.h \ src/KNotesIface.h + +CLEANFILES = \ + src/KNotesIface_stub.h \ + src/KNotesIface_skel.cpp \ + src/KNotesIface_stub.cpp \ + src/KNotesIface.kidl kdepim_sync_la_SOURCES = src/kdepim_sync.cpp kdepim_sync_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall -Werror @@ -22,15 +28,16 @@ # ugly hack to make the c++ library work kdepim_sync_la_LIBADD = -lstdc++ -L@OPENSYNC_LIBDIR@ -kdepim_lib_la_SOURCES = src/kdepim_impl.cpp \ - src/kcal.cpp \ - src/knotes.cpp \ - src/kaddrbook.cpp \ - src/KNotesIface_stub.cpp +kdepim_lib_la_SOURCES = \ + src/KNotesIface_stub.cpp \ + src/kdepim_impl.cpp \ + src/kcal.cpp \ + src/knotes.cpp \ + src/kaddrbook.cpp kdepim_lib_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall -Werror kdepim_lib_la_LDFLAGS = $(KDE_LDFLAGS) -avoid-version -export-dynamic -module kdepim_lib_la_LIBADD = $(KDE_RPATH) $(LIB_KABC) $(LIB_KCAL) -L$(libdir) -L@OPENSYNC_LIBDIR@ -lopensync-xml -KNotesIface_stub.cpp: +src/KNotesIface_stub.cpp: dcopidl src/KNotesIface.h > src/KNotesIface.kidl dcopidl2cpp src/KNotesIface.kidl \ No newline at end of file Property changes on: branches/experimental-kdepim/src ___________________________________________________________________ Name: svn:ignore - .libs Makefile.in *.loT .deps Makefile + .libs Makefile.in *.loT .deps Makefile KNotesIface_stub.cpp KNotesIface_skel.cpp KNotesIface.kidl KNotesIface_stub.h Deleted: branches/experimental-kdepim/src/kaddrbook.c Added: branches/experimental-kdepim/src/kaddrbook.cpp =================================================================== --- branches/experimental-kdepim/src/kaddrbook.cpp 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/kaddrbook.cpp 2005-04-05 14:41:00 UTC (rev 440) @@ -0,0 +1,235 @@ +/*********************************************************************** +KAddressbook support for OpenSync kdepim-sync plugin +Copyright (C) 2004 Conectiva S. A. +Copyright (C) 2005 Armin Bauer + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation; + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY +CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, +COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS +SOFTWARE IS DISCLAIMED. +*************************************************************************/ +/** + * @autor Eduardo Pereira Habkost <eha...@co...> + * @autor Armin Bauer <arm...@op...> + */ + +#include "kaddrbook.h" + +KContactDataSource::KContactDataSource(OSyncMember *member, OSyncHashTable *hashtable) + : hashtable(hashtable), member(member) +{ +} + +/** Calculate the hash value for an Addressee. + * Should be called before returning/writing the + * data, because the revision of the Addressee + * can be changed. + */ +QString KContactDataSource::calc_hash(KABC::Addressee &e) +{ + //Get the revision date of the KDE addressbook entry. + //Regard entries with invalid revision dates as having just been changed. + QDateTime revdate = e.revision(); + osync_debug("kde", 3, "Getting hash: %s", revdate.toString().data()); + if (!revdate.isValid()) + { + revdate = QDateTime::currentDateTime(); + e.setRevision(revdate); + } + + return revdate.toString(); +} + +bool KContactDataSource::connect(OSyncContext *ctx) +{ + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); + + //get a handle to the standard KDE addressbook + addressbookptr = KABC::StdAddressBook::self(); + + OSyncError *error = NULL; + + if (!osync_hashtable_load(hashtable, member, &error)) { + osync_context_report_osyncerror(ctx, &error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); + return FALSE; + } + + //Detection mechanismn if this is the first sync + if (!osync_anchor_compare(member, "synced", "true")) { + osync_trace(TRACE_INTERNAL, "Setting slow-sync"); + osync_member_set_slow_sync(member, "contact", TRUE); + osync_anchor_update(member, "synced", "true"); + } + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; +} + +bool KContactDataSource::disconnect(OSyncContext *ctx) +{ + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); + + KABC::Ticket *ticket = addressbookptr->requestSaveTicket(); + if ( !ticket ) { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save ticket"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get save ticket", __func__); + return FALSE; + } + + if ( !addressbookptr->save( ticket ) ) { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to use ticket"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to save", __func__); + return FALSE; + } + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; +} + + +bool KContactDataSource::contact_get_changeinfo(OSyncContext *ctx) +{ + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); + + if (osync_member_get_slow_sync(member, "contact")) { + osync_trace(TRACE_INTERNAL, "Got slow-sync"); + osync_hashtable_set_slow_sync(hashtable, "contact"); + } + + // We must reload the KDE addressbook in order to retrieve the latest changes. + if (!addressbookptr->load()) { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Couldn't reload KDE addressbook"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to reload addrbook", __func__); + return false; + } + + KABC::VCardConverter converter; + + for (KABC::AddressBook::Iterator it=addressbookptr->begin(); it!=addressbookptr->end(); it++ ) { + QString uid = it->uid(); + + OSyncChange *chg = osync_change_new(); + + osync_change_set_member(chg, member); + osync_change_set_uid(chg, uid.local8Bit()); + + QString hash = calc_hash(*it); + + // Convert the VCARD data into a string + const char *data = converter.createVCard(*it).utf8(); + osync_change_set_data(chg, strdup(data), strlen(data) + 1, TRUE); + + // object type and format + osync_change_set_objtype_string(chg, "contact"); + osync_change_set_objformat_string(chg, "vcard21"); + + // Use the hash table to check if the object + // needs to be reported + osync_change_set_hash(chg, hash.data()); + if (osync_hashtable_detect_change(hashtable, chg)) { + osync_context_report_change(ctx, chg); + osync_hashtable_update_hash(hashtable, chg); + } + } + + // Use the hashtable to report deletions + osync_hashtable_report_deleted(hashtable, ctx, "contact"); + + osync_trace(TRACE_EXIT, "%s", __func__); + return true; +} + +/*void kabc_get_data(OSyncContext *ctx, OSyncChange *chg) +{ + QString uid = osync_change_get_uid(chg); + KABC::Addressee a = addressbookptr->findByUid(uid); + KABC::VCardConverter converter; + QCString card = converter.createVCard(a).utf8(); + const char *data = card; + //FIXME: deallocate data somewhere + osync_change_set_data(chg, strdup(data), strlen(data), 1); + osync_context_report_success(ctx); +}*/ + +bool KContactDataSource::vcard_access(OSyncContext *ctx, OSyncChange *chg) +{ + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); + KABC::VCardConverter converter; + + // convert VCARD string from obj->comp into an Addresse object. + char *data = osync_change_get_data(chg); + size_t data_size = osync_change_get_datasize(chg); + QString uid = osync_change_get_uid(chg); + + OSyncChangeType chtype = osync_change_get_changetype(chg); + switch(chtype) { + case CHANGE_MODIFIED: { + KABC::Addressee addressee = converter.parseVCard(QString::fromUtf8(data, data_size)); + + // ensure it has the correct UID and revision + addressee.setUid(uid); + addressee.setRevision(QDateTime::currentDateTime()); + + // replace the current addressbook entry (if any) with the new one + + addressbookptr->insertAddressee(addressee); + + QString hash = calc_hash(addressee); + osync_change_set_hash(chg, hash); + osync_debug("kde", 3, "KDE ADDRESSBOOK ENTRY UPDATED (UID=%s)", (const char *)uid.local8Bit()); + break; + } + case CHANGE_ADDED: { + KABC::Addressee addressee = converter.parseVCard(QString::fromUtf8(data, data_size)); + + // ensure it has the correct revision + addressee.setRevision(QDateTime::currentDateTime()); + + // add the new address to the addressbook + addressbookptr->insertAddressee(addressee); + + osync_change_set_uid(chg, addressee.uid().local8Bit()); + + QString hash = calc_hash(addressee); + osync_change_set_hash(chg, hash); + osync_debug("kde", 3, "KDE ADDRESSBOOK ENTRY ADDED (UID=%s)", (const char *)addressee.uid().local8Bit()); + break; + } + case CHANGE_DELETED: { + if (uid.isEmpty()) { + osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Trying to delete entry with empty UID"); + osync_trace(TRACE_EXIT_ERROR, "%s: Trying to delete but uid is empty", __func__); + return FALSE; + } + + //find addressbook entry with matching UID and delete it + KABC::Addressee addressee = addressbookptr->findByUid(uid); + if(!addressee.isEmpty()) + addressbookptr->removeAddressee(addressee); + + osync_debug("kde", 3, "KDE ADDRESSBOOK ENTRY DELETED (UID=%s)", (const char*)uid.local8Bit()); + + break; + } + default: + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Operation not supported"); + osync_trace(TRACE_EXIT_ERROR, "%s: Operation not supported", __func__); + return FALSE; + } + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; +} Modified: branches/experimental-kdepim/src/kaddrbook.h =================================================================== --- branches/experimental-kdepim/src/kaddrbook.h 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/kaddrbook.h 2005-04-05 14:41:00 UTC (rev 440) @@ -23,7 +23,28 @@ #ifndef KADDRBOOK_H #define KADDRBOOK_H +#include <kabc/stdaddressbook.h> +#include <kabc/vcardconverter.h> +#include <kabc/resource.h> + #include "osyncbase.h" +class KContactDataSource { + private: + KABC::AddressBook* addressbookptr; + + OSyncHashTable *hashtable; + OSyncMember *member; + + public: + KContactDataSource(OSyncMember *member, OSyncHashTable *hashtable); + + QString calc_hash(KABC::Addressee &e); + bool connect(OSyncContext *ctx); + bool disconnect(OSyncContext *ctx); + bool contact_get_changeinfo(OSyncContext *ctx); + bool vcard_access(OSyncContext *ctx, OSyncChange *chg); +}; + #endif Modified: branches/experimental-kdepim/src/kdepim_impl.cpp =================================================================== --- branches/experimental-kdepim/src/kdepim_impl.cpp 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/kdepim_impl.cpp 2005-04-05 14:41:00 UTC (rev 440) @@ -24,14 +24,9 @@ * @autor Eduardo Pereira Habkost <eha...@co...> */ -extern "C" -{ -#include <opensync/opensync.h> -} -#include <kabc/stdaddressbook.h> -#include <kabc/vcardconverter.h> -#include <kabc/resource.h> + + #include <libkcal/resourcecalendar.h> #include <kinstance.h> #include <klocale.h> @@ -50,41 +45,15 @@ #include "kcal.h" #include "knotes.h" - -/*TODO: check why/if the function below is necessary */ -static -void unfold_vcard(char *vcard, size_t *size) -{ - char* in = vcard; - char* out = vcard; - char *end = vcard + *size; - while ( in < end) - { - /* remove any occurrences of "=[CR][LF]" */ - /* these denote folded line markers in VCARD format. */ - /* Dont know why, but Evolution uses the leading "=" */ - /* character to (presumably) denote a control sequence. */ - /* This is not quite how I interpret the VCARD RFC2426 */ - /* spec (section 2.6 line delimiting and folding). */ - /* This seems to work though, so thats the main thing! */ - if (in[0]=='=' && in[1]==13 && in[2]==10) - in+=3; - else - *out++ = *in++; - } - *size = out - vcard; -} - class KdePluginImplementation: public KdePluginImplementationBase { private: - KABC::AddressBook* addressbookptr; - KCalDataSource *kcal; KNotesDataSource *knotes; - + KContactDataSource *kaddrbook; + + OSyncHashTable *hashtable; OSyncMember *member; - OSyncHashTable *hashtable; KApplication *application; @@ -99,10 +68,10 @@ //osync_debug("kde", 3, "%s(%s)", __FUNCTION__); KAboutData aboutData( - "opensync-kdepim-plugin", // internal program name - I18N_NOOP( "OpenSync-KDE-plugin"), // displayable program name. + "libopensync-kdepim-plugin", // internal program name + "OpenSync-KDE-plugin", // displayable program name. "0.1", // version string - I18N_NOOP( "OpenSync KDEPIM plugin" ), // short porgram description + "OpenSync KDEPIM plugin", // short porgram description KAboutData::License_GPL, // license type "(c) 2005, Eduardo Pereira Habkost", // copyright statement 0, // any free form text @@ -113,13 +82,11 @@ KCmdLineArgs::init(&aboutData); application = new KApplication(); - //get a handle to the standard KDE addressbook - addressbookptr = KABC::StdAddressBook::self(); + hashtable = osync_hashtable_new(); - hashtable = osync_hashtable_new(); - kcal = new KCalDataSource(member, hashtable); knotes = new KNotesDataSource(member, hashtable); + kaddrbook = new KContactDataSource(member, hashtable); return true; } @@ -130,35 +97,89 @@ delete kcal; kcal = NULL; } + if (knotes) { delete knotes; knotes = NULL; } + if (application) { delete application; application = NULL; } + if (hashtable) osync_hashtable_free(hashtable); } + virtual void connect(OSyncContext *ctx) + { + if (kcal && !kcal->connect(ctx)) + return; + + if (knotes && !knotes->connect(ctx)) + return; + + if (kaddrbook && !kaddrbook->connect(ctx)) + return; + + osync_context_report_success(ctx); + } + + virtual void disconnect(OSyncContext *ctx) + { + osync_hashtable_close(hashtable); + + if (kcal && !kcal->disconnect(ctx)) + return; + if (knotes && !knotes->disconnect(ctx)) + return; + if (kaddrbook && !kaddrbook->disconnect(ctx)) + return; + + osync_context_report_success(ctx); + } + + virtual void get_changeinfo(OSyncContext *ctx) + { + if (!kaddrbook && !kaddrbook->contact_get_changeinfo(ctx)) + return; + + if (kcal && !kcal->get_changeinfo_events(ctx)) + return; + + if (kcal && !kcal->get_changeinfo_todos(ctx)) + return; + + if (knotes && !knotes->get_changeinfo(ctx)) + return; + + osync_context_report_success(ctx); + } + virtual bool vcard_access(OSyncContext *ctx, OSyncChange *chg) { - if (__vcard_access(ctx, chg) < 0) - return false; - osync_context_report_success(ctx); - /*FIXME: What should be returned? */ - return true; + if (kaddrbook) + return kaddrbook->vcard_access(ctx, chg); + else { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); + return false; + } + return true; } virtual bool vcard_commit_change(OSyncContext *ctx, OSyncChange *chg) { - if ( __vcard_access(ctx, chg) < 0) - return false; - osync_hashtable_update_hash(hashtable, chg); - osync_context_report_success(ctx); - /*FIXME: What should be returned? */ - return true; + if (kaddrbook) + if (kaddrbook->vcard_access(ctx, chg)) + osync_hashtable_update_hash(hashtable, chg); + else + return FALSE; + else { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); + return false; + } + return true; } virtual bool event_access(OSyncContext *ctx, OSyncChange *chg) Modified: branches/experimental-kdepim/src/kdepim_sync.cpp =================================================================== --- branches/experimental-kdepim/src/kdepim_sync.cpp 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/kdepim_sync.cpp 2005-04-05 14:41:00 UTC (rev 440) @@ -102,14 +102,6 @@ impl_object->get_changeinfo(ctx); } -static void kde_get_data(OSyncContext *ctx, OSyncChange *chg) -{ - KdePluginImplementationBase *impl_object = impl_object_for_context(ctx); - osync_debug("kde", 3, "%s",__FUNCTION__); - - impl_object->get_data(ctx, chg); -} - static osync_bool kde_vcard_commit_change(OSyncContext *ctx, OSyncChange *change) { KdePluginImplementationBase *impl_object = impl_object_for_context(ctx); @@ -196,7 +188,6 @@ info->functions.disconnect = kde_disconnect; info->functions.finalize = kde_finalize; info->functions.get_changeinfo = kde_get_changeinfo; - info->functions.get_data = kde_get_data; osync_plugin_accept_objtype(info, "contact"); osync_plugin_accept_objformat(info, "contact", "vcard30", "kde"); Deleted: branches/experimental-kdepim/src/knotes-test.cpp Modified: branches/experimental-kdepim/src/knotes.cpp =================================================================== --- branches/experimental-kdepim/src/knotes.cpp 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/knotes.cpp 2005-04-05 14:41:00 UTC (rev 440) @@ -43,31 +43,30 @@ bool KNotesDataSource::connect(OSyncContext *ctx) { osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); - //check knotes running - //connect to dcop - DCOPClient *kn_dcop = KApplication::kApplication()->dcopClient(); - if (!kndcop) { + kn_dcop = KApplication::kApplication()->dcopClient(); + if (!kn_dcop) { osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to make new dcop for knotes"); osync_trace(TRACE_EXIT_ERROR, "%s: Unable to make new dcop for knotes", __func__); return FALSE; } - if (!dcop->attach()) { + if (!kn_dcop->attach()) { osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to attach dcop for knotes"); osync_trace(TRACE_EXIT_ERROR, "%s: Unable to attach dcop for knotes", __func__); return FALSE; } - QCStringList apps = dcop->registeredApplications(); + //check knotes running + QCStringList apps = kn_dcop->registeredApplications(); if (!apps.contains("knotes")) { //start knotes if not running knotesWasRunning = false; } else knotesWasRunning = true; - kn_iface = new KNotesIface_stub(knotesAppname,"KNotesIface"); + kn_iface = new KNotesIface_stub("knotes", "KNotesIface"); osync_trace(TRACE_EXIT, "%s", __func__); return true; @@ -76,7 +75,6 @@ bool KNotesDataSource::disconnect(OSyncContext *ctx) { osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); - //call sync on knotes dcop // FIXME: ugly, but necessary if (!knotesWasRunning) { @@ -84,7 +82,16 @@ } //detach dcop + if (!kn_dcop->detach()) { + osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to detach dcop for knotes"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to detach dcop for knotes", __func__); + return FALSE; + } //destroy dcop + delete kn_iface; + kn_iface = NULL; + //delete kn_dcop; + //kn_dcop = NULL; osync_trace(TRACE_EXIT, "%s", __func__); return true; @@ -95,20 +102,20 @@ osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); QMap <KNoteID_t,QString> fNotes; - fNotes = fKNotes->notes(); - if (fKNotes->status() != DCOPStub::CallSucceeded) { + fNotes = kn_iface->notes(); + if (kn_iface->status() != DCOPStub::CallSucceeded) { osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get changed notes"); osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get changed notes", __func__); return FALSE; } - QMap<KNoteID_t,QString>::ConstIterator i = fNotes.begin(); - while (i != fNotes.end()) { + QMap<KNoteID_t,QString>::ConstIterator i; + for (i = fNotes.begin(); i != fNotes.end(); i++) { osync_debug("knotes", 4, "Note key: %s", (const char*)i.key().local8Bit()); osync_debug("knotes", 4, "Note contents:\n%s\n====", (const char*)i.data().local8Bit()); - QString uid = (*i)->uid(); - + QString uid = i.key(); + QString hash = NULL; // Create osxml doc containing the note xmlDoc *doc = xmlNewDoc((const xmlChar*)"1.0"); xmlNode *root = osxml_node_add_root(doc, "note"); @@ -119,11 +126,13 @@ // Set the right attributes xmlNode *sum = xmlNewChild(root, NULL, (const xmlChar*)"", NULL); - QCString utf8str = (*i)->summary().utf8(); + QCString utf8str = i.data().utf8(); + hash = utf8str; osxml_node_set(sum, "Summary", utf8str, enc); xmlNode *body = xmlNewChild(root, NULL, (const xmlChar*)"", NULL); - utf8str = (*i)->description().utf8(); + utf8str = kn_iface->text(i.key()).utf8(); + hash += utf8str; osxml_node_set(body, "Body", utf8str, enc); // initialize the change object @@ -145,11 +154,13 @@ } } + osync_trace(TRACE_EXIT, "%s", __func__); return true; } bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg) { + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); OSyncChangeType type = osync_change_get_changetype(chg); QString uid = osync_change_get_uid(chg); @@ -161,7 +172,8 @@ xmlNode *root = osxml_node_get_root(doc, "note", NULL); if (!root) { osync_context_report_error(ctx, OSYNC_ERROR_CONVERT, "Invalid data"); - return false; + osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data", __func__); + return false; } QString summary = osxml_find_node(root, "Summary"); QString body = osxml_find_node(root, "Body"); @@ -170,32 +182,64 @@ // end of the ugly-format parsing switch (type) { case CHANGE_ADDED: - uid = newNote(); + uid = kn_iface->newNote(summary, body); + if (kn_iface->status() != DCOPStub::CallSucceeded) { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to add new note"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to add new note", __func__); + return false; + } + + kn_iface->hideNote(uid); + if (kn_iface->status() != DCOPStub::CallSucceeded) + osync_trace(TRACE_INTERNAL, "ERROR: Unable to hide note"); + osync_change_set_uid(chg, uid); osync_change_set_hash(chg, hash); - break; + break; case CHANGE_MODIFIED: - setText - setBody - hash = calc_hash(); + kn_iface->setName(uid, summary); + if (kn_iface->status() != DCOPStub::CallSucceeded) { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set name"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set name", __func__); + return false; + } + + kn_iface->setText(uid, body); + if (kn_iface->status() != DCOPStub::CallSucceeded) { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set text"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set text", __func__); + return false; + } + hash = summary + body; osync_change_set_hash(chg, hash); - break; + break; default: osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Invalid change type"); - return false; + osync_trace(TRACE_EXIT_ERROR, "%s: Invalid change type", __func__); + return false; } } else { - //dcop killNote + kn_iface->killNote(uid, true); + if (kn_iface->status() != DCOPStub::CallSucceeded) { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to delete note"); + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); + return false; + } } osync_context_report_success(ctx); + osync_trace(TRACE_EXIT, "%s", __func__); return true; } bool KNotesDataSource::commit_change(OSyncContext *ctx, OSyncChange *chg) { - if (!access(ctx, chg)) - return false; + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); + if (!access(ctx, chg)) { + osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); + return false; + } osync_hashtable_update_hash(hashtable, chg); + osync_trace(TRACE_EXIT, "%s", __func__); return true; } Modified: branches/experimental-kdepim/src/knotes.h =================================================================== --- branches/experimental-kdepim/src/knotes.h 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/knotes.h 2005-04-05 14:41:00 UTC (rev 440) @@ -29,32 +29,39 @@ #include <kstandarddirs.h> #include <kio/netaccess.h> #include <klocale.h> +#include <kapplication.h> +#include <qmap.h> +#include "KNotesIface.h" +#include "KNotesIface_stub.h" +#include <stdio.h> +#include <qtimer.h> +#include <dcopclient.h> +#include <qstring.h> +#include <qstringlist.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +typedef QString KNoteID_t; + extern "C" { #include <opensync/opensync.h> #include <opensync/opensync-xml.h> } -// Forward declaration -namespace KCal { - class CalendarLocal; -} - /** KNotes access implementation interface */ class KNotesDataSource { private: OSyncMember *member; - KNotesIface_stub *fKNotes; - DCOPClient *kn_dcop - KNotesIface_stub kn_iface; + OSyncHashTable *hashtable; + + DCOPClient *kn_dcop; + KNotesIface_stub *kn_iface; /** Ugly hack to restart KNotes if it * was running Modified: branches/experimental-kdepim/src/osyncbase.h =================================================================== --- branches/experimental-kdepim/src/osyncbase.h 2005-04-05 14:37:54 UTC (rev 439) +++ branches/experimental-kdepim/src/osyncbase.h 2005-04-05 14:41:00 UTC (rev 440) @@ -16,7 +16,6 @@ virtual void disconnect(OSyncContext *ctx) = 0; virtual void get_changeinfo(OSyncContext *ctx) = 0; - virtual void get_data(OSyncContext *ctx, OSyncChange *chg) = 0; virtual bool vcard_access(OSyncContext *ctx, OSyncChange *chg) = 0; virtual bool vcard_commit_change(OSyncContext *ctx, OSyncChange *chg) = 0; @@ -38,25 +37,4 @@ typedef KdePluginImplementationBase *(*KdeImplInitFunc)(OSyncMember *m, OSyncError **e); -/*TODO: provide base classes like below, - * for hiding the implementation details of a plugin - */ -#if 0 -/** Base class to a OpenSync plugin */ -class OSyncPluginBase { - public: - virtual void connect(OSyncContext *ctx) = 0; - void disconnect(OSyncContext *ctx) = 0; - - virtual void get_changes(OSyncContext *ctx) = 0; -}; - -/** Base class to OpenSync objtype data sink */ -class OSyncDataSinkBase { - public: - virtual void access(OSyncContext *ctx, OSyncChange *chg) = 0; - virtual void commit_change(OSyncContext *ctx, OSyncChange *chg) = 0; -}; -#endif - #endif // KDEPIM_OSYNC_BASE_H |