From: <svn...@op...> - 2005-04-04 15:27:19
|
Author: abauer Date: 2005-04-04 17:28:27 +0200 (Mon, 04 Apr 2005) New Revision: 435 Added: branches/experimental-kdepim/src/KNotesIface.h branches/experimental-kdepim/src/kaddrbook.c branches/experimental-kdepim/src/knotes-test.cpp Modified: branches/experimental-kdepim/Makefile.am branches/experimental-kdepim/src/kcal.cpp branches/experimental-kdepim/src/kcal.h branches/experimental-kdepim/src/kdepim_impl.cpp branches/experimental-kdepim/src/knotes.cpp branches/experimental-kdepim/src/knotes.h Log: Started the changes to the notes access in the kdepim plugin Modified: branches/experimental-kdepim/Makefile.am =================================================================== --- branches/experimental-kdepim/Makefile.am 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/Makefile.am 2005-04-04 15:28:27 UTC (rev 435) @@ -40,4 +40,9 @@ 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 +bin_PROGRAMS = notestest + +notestest_SOURCES = src/knotes-test.cpp src/KNotesIface_stub.cpp +notestest_LDFLAGS = $(KDE_LDFLAGS) +notestest_LDADD = $(KDE_RPATH) $(LIB_KABC) $(LIB_KCAL) -L$(libdir) -L@OPENSYNC_LIBDIR@ Added: branches/experimental-kdepim/src/KNotesIface.h =================================================================== --- branches/experimental-kdepim/src/KNotesIface.h 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/KNotesIface.h 2005-04-04 15:28:27 UTC (rev 435) @@ -0,0 +1,139 @@ +/******************************************************************* + KNotesIface.h -- This file defines the DCOP interface for KNotes. + + Copyright (C) 2000 by Adriaan de Groot + 2001-2003 by Michael Brade <br...@kd...> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*******************************************************************/ + +#ifndef __KNotesIface_h__ +#define __KNotesIface_h__ + +#include <qstring.h> +#include <qmap.h> + +#include <dcopobject.h> + + +class KNotesIface : virtual public DCOPObject +{ + K_DCOP +k_dcop: + /** + * Create a new note. + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @param text the body of the new note + * @return the new notes' id + */ + virtual QString newNote( const QString& name = QString::null, + const QString& text = QString::null ) = 0; + + /** + * Create a new note and inserts the current text in the clipboard + * as text. + * + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @return the new notes' id + */ + virtual QString newNoteFromClipboard( const QString& name = QString::null ) = 0; + + /** + * Show a note as if it had been selected from the "notes" menu. + * @param noteId the id of the note to show + */ + virtual ASYNC showNote( const QString& noteId ) const = 0; + + /** + * Hide a note. + * @param noteId the id of the note to hide + */ + virtual ASYNC hideNote( const QString& noteId ) const = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + */ + virtual ASYNC killNote( const QString& noteId ) = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + * @param force do not request confirmation + */ + virtual ASYNC killNote( const QString& noteId, bool force ) = 0; + + /** + * Get all the notes including their ids. + * @return a QMap that maps the id of a note to its name + */ + virtual QMap<QString,QString> notes() const = 0; + + /** + * Changes the title/name of a note. + * @param noteId the id of the note to be modified + * @param newName the new title + */ + virtual ASYNC setName( const QString& noteId, const QString& newName ) = 0; + + /** + * Sets the text of a note. This will delete the old text! + * @param noteId the id of the note + * @param newText the new text for the note + */ + virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0; + + /** + * Returns the title/name of a note. + * @param noteId the id of the note in question + * @return the name as a QString + */ + virtual QString name( const QString& noteId ) const = 0; + + /** + * Returns the text of a note. + * @param noteId the id of the note in question + * @return the body as a QString + */ + virtual QString text( const QString& noteId ) const = 0; + + /** + * This tells KNotes that a specific app has synchronized with all the notes. + * @param app the app that has synced with KNotes + */ + virtual ASYNC sync( const QString& app ) = 0; + + /** + * Test if a note was created new after the last sync. + * @param app the app that wants to get the status since the last sync + * @param noteId the id of the note + * @return true if the note is new, false if not or if the note does + * not exist + */ + virtual bool isNew( const QString& app, const QString& noteId ) const = 0; + + /** + * Test if a note was modified since the last sync. + * @param app the app that wants to get the status since the last sync + * @param noteId the id of the note + * @return true if modified (note that this will return true if the note is + * new as well!) and false if the note is not modified or doesn't exist + */ + virtual bool isModified( const QString& app, const QString& noteId ) const = 0; +}; + +#endif Added: branches/experimental-kdepim/src/kaddrbook.c =================================================================== --- branches/experimental-kdepim/src/kaddrbook.c 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/kaddrbook.c 2005-04-04 15:28:27 UTC (rev 435) @@ -0,0 +1,260 @@ +/** 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 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(); + } + + virtual void connect(OSyncContext *ctx) + { + //Lock the addressbook + //addressbookticket = addressbookptr->requestSaveTicket(); + + OSyncError *error = NULL; + if (!osync_hashtable_load(hashtable, member, &error)) + { + osync_context_report_osyncerror(ctx, &error); + return; + } + + //Detection mechanismn if this is the first sync + if (!osync_anchor_compare(member, "synced", "true")) { + osync_member_set_slow_sync(member, "contact", TRUE); + osync_anchor_update(member, "synced", "true"); + } + + /*if (!addressbookticket) + { + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Couldn't lock KDE addressbook"); + return; + }*/ + osync_debug("kde", 3, "KDE addressbook locked OK."); + + if (kcal && !kcal->connect(ctx)) + return; + if (knotes && !knotes->connect(ctx)) + return; + osync_context_report_success(ctx); + } + + virtual void disconnect(OSyncContext *ctx) + { + //Unlock the addressbook + //addressbookptr->save(addressbookticket); + //addressbookticket = NULL; + + KABC::Ticket *ticket = addressbookptr->requestSaveTicket(); + if ( !ticket ) { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save ticket"); + return; + } + + if ( !addressbookptr->save( ticket ) ) { + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save using ticket"); + return; + } + + osync_hashtable_close(hashtable); + + if (kcal && !kcal->disconnect(ctx)) + return; + if (knotes && !knotes->disconnect(ctx)) + return; + osync_context_report_success(ctx); + } + + + /*FIXME: move kaddrbook implementation to kaddrbook.cpp */ + bool addrbook_get_changeinfo(OSyncContext *ctx) + { + //osync_debug("kde", 3, "kaddrbook::%s(newdbs=%d)", __FUNCTION__, newdbs); + + if (osync_member_get_slow_sync(member, "contact")) + 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"); + return false; + } + osync_debug("kde", 3, "KDE addressbook reloaded OK."); + + 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"); + + return true; + } + + virtual void get_changeinfo(OSyncContext *ctx) + { + if (!addrbook_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); + } + + 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); + } + + + virtual void get_data(OSyncContext *ctx, OSyncChange *) + { + /* + switch (osync_change_get_objtype(chg)) { + case contact: + kabc_get_data(ctx, chg); + break; + case calendar: + kcal->get_data(ctx, chg); + break; + default: + osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Invalid UID"); + return; + } + osync_context_report_success(ctx); + */ + osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Not implemented yet"); + } + + + + /** Access an object, without returning success + * + * returns 0 on success, < 0 on error. + * If an error occurss, the error will be already reported + * using osync_context_report_error() + */ + int __vcard_access(OSyncContext *ctx, OSyncChange *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: + { + unfold_vcard(data, &data_size); + 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: + { + unfold_vcard(data, &data_size); + 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"); + return -1; + } + + //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"); + return -1; + } + + return 0; + } \ No newline at end of file Modified: branches/experimental-kdepim/src/kcal.cpp =================================================================== --- branches/experimental-kdepim/src/kcal.cpp 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/kcal.cpp 2005-04-04 15:28:27 UTC (rev 435) @@ -23,12 +23,6 @@ * @autor Eduardo Pereira Habkost <eha...@co...> */ -#include <libkcal/calendarresources.h> -#include <libkcal/icalformat.h> -#include <libkcal/calendarlocal.h> -#include <kdeversion.h> - -#include "osyncbase.h" #include "kcal.h" KCalDataSource::KCalDataSource(OSyncMember *member, OSyncHashTable *hashtable) Modified: branches/experimental-kdepim/src/kcal.h =================================================================== --- branches/experimental-kdepim/src/kcal.h 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/kcal.h 2005-04-04 15:28:27 UTC (rev 435) @@ -25,6 +25,9 @@ #include <libkcal/calendarresources.h> #include <libkcal/incidence.h> +#include <libkcal/icalformat.h> +#include <libkcal/calendarlocal.h> +#include <kdeversion.h> #include "osyncbase.h" Modified: branches/experimental-kdepim/src/kdepim_impl.cpp =================================================================== --- branches/experimental-kdepim/src/kdepim_impl.cpp 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/kdepim_impl.cpp 2005-04-04 15:28:27 UTC (rev 435) @@ -142,267 +142,6 @@ osync_hashtable_free(hashtable); } - /** 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 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(); - } - - virtual void connect(OSyncContext *ctx) - { - //Lock the addressbook - //addressbookticket = addressbookptr->requestSaveTicket(); - - OSyncError *error = NULL; - if (!osync_hashtable_load(hashtable, member, &error)) - { - osync_context_report_osyncerror(ctx, &error); - return; - } - - //Detection mechanismn if this is the first sync - if (!osync_anchor_compare(member, "synced", "true")) { - osync_member_set_slow_sync(member, "contact", TRUE); - osync_anchor_update(member, "synced", "true"); - } - - /*if (!addressbookticket) - { - osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Couldn't lock KDE addressbook"); - return; - }*/ - osync_debug("kde", 3, "KDE addressbook locked OK."); - - if (kcal && !kcal->connect(ctx)) - return; - if (knotes && !knotes->connect(ctx)) - return; - osync_context_report_success(ctx); - } - - virtual void disconnect(OSyncContext *ctx) - { - //Unlock the addressbook - //addressbookptr->save(addressbookticket); - //addressbookticket = NULL; - - KABC::Ticket *ticket = addressbookptr->requestSaveTicket(); - if ( !ticket ) { - osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save ticket"); - return; - } - - if ( !addressbookptr->save( ticket ) ) { - osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save using ticket"); - return; - } - - osync_hashtable_close(hashtable); - - if (kcal && !kcal->disconnect(ctx)) - return; - if (knotes && !knotes->disconnect(ctx)) - return; - osync_context_report_success(ctx); - } - - - /*FIXME: move kaddrbook implementation to kaddrbook.cpp */ - bool addrbook_get_changeinfo(OSyncContext *ctx) - { - //osync_debug("kde", 3, "kaddrbook::%s(newdbs=%d)", __FUNCTION__, newdbs); - - if (osync_member_get_slow_sync(member, "contact")) - 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"); - return false; - } - osync_debug("kde", 3, "KDE addressbook reloaded OK."); - - 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"); - - return true; - } - - virtual void get_changeinfo(OSyncContext *ctx) - { - if (!addrbook_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); - } - - 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); - } - - - virtual void get_data(OSyncContext *ctx, OSyncChange *) - { - /* - switch (osync_change_get_objtype(chg)) { - case contact: - kabc_get_data(ctx, chg); - break; - case calendar: - kcal->get_data(ctx, chg); - break; - default: - osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Invalid UID"); - return; - } - osync_context_report_success(ctx); - */ - osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Not implemented yet"); - } - - - - /** Access an object, without returning success - * - * returns 0 on success, < 0 on error. - * If an error occurss, the error will be already reported - * using osync_context_report_error() - */ - int __vcard_access(OSyncContext *ctx, OSyncChange *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: - { - unfold_vcard(data, &data_size); - 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: - { - unfold_vcard(data, &data_size); - 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"); - return -1; - } - - //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"); - return -1; - } - - return 0; - } - virtual bool vcard_access(OSyncContext *ctx, OSyncChange *chg) { if (__vcard_access(ctx, chg) < 0) Added: branches/experimental-kdepim/src/knotes-test.cpp =================================================================== --- branches/experimental-kdepim/src/knotes-test.cpp 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/knotes-test.cpp 2005-04-04 15:28:27 UTC (rev 435) @@ -0,0 +1,84 @@ +#include "KNotesIface.h" +#include "KNotesIface_stub.h" +#include <stdio.h> +#include <qmap.h> +#include <qtimer.h> + +#include <kapplication.h> + +#include <dcopclient.h> +#include <qstring.h> +#include <qstringlist.h> + +typedef QString KNoteID_t; + +bool isRunning(const QCString &n) +{ + DCOPClient *dcop = KApplication::kApplication()->dcopClient(); + + if (!dcop->attach()) + printf("nix is\n"); + QCStringList apps = dcop->registeredApplications(); + + QStringList lst; + printf("asd %i, %s", lst.count(), (const char*)lst.join("\n").local8Bit()); + return apps.contains(n); +} + + +int main(void) +{ + printf("test \n"); + + QMap <KNoteID_t,QString> fNotes; + + + /*DCOPClient *fdp = new DCOPClient; + fdp = KApplication::kApplication()->dcopClient(); + + if (!fdp) { + printf("No DCOP connection could be made. The conduit cannot function without DCOP.\n"); + return 1; + }*/ + + QCString knotesAppname = "knotes" ; + if (!isRunning(knotesAppname)) { + knotesAppname = "kontact" ; + if (!isRunning(knotesAppname)) { + printf("KNotes is not running.\n"); + return 1; + } + } + + KNotesIface_stub *fKNotes = new KNotesIface_stub(knotesAppname,"KNotesIface"); + + + fNotes = fKNotes->notes(); + if (fKNotes->status() != DCOPStub::CallSucceeded) + { + printf("Could not retrieve list of notes from KNotes.\n"); + return 1; + +} + + QMap<KNoteID_t,QString>::ConstIterator i = fNotes.begin(); + while (i != fNotes.end()) + { + printf("%s -> %s %s\n", (const char*)i.key().local8Bit(), (const char*)i.data().local8Bit(), (fKNotes->isNew("opensync",i.key())) ? " (new)" : ""); + i++; + } + + QString id = fKNotes->newNote("test1", "test2"); + if (fKNotes->status() != DCOPStub::CallSucceeded) { + printf("Could not add note to KNotes.\n"); + return 1; + } + + fKNotes->hideNote(id); + if (fKNotes->status() != DCOPStub::CallSucceeded) { + printf("Could not hide note to KNotes.\n"); + return 1; + } + + return 0; +} Modified: branches/experimental-kdepim/src/knotes.cpp =================================================================== --- branches/experimental-kdepim/src/knotes.cpp 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/knotes.cpp 2005-04-04 15:28:27 UTC (rev 435) @@ -30,25 +30,10 @@ * (http://www.opensync.org/ticket/34) */ -#include <libkcal/calendarlocal.h> -#include <libkcal/icalformat.h> -#include <kglobal.h> -#include <kstandarddirs.h> -#include <kio/netaccess.h> -#include <klocale.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - #include "knotes.h" -extern "C" -{ -#include <opensync/opensync-xml.h> -} KNotesDataSource::KNotesDataSource(OSyncMember *m, OSyncHashTable *h) :member(m), hashtable(h) @@ -57,6 +42,11 @@ bool KNotesDataSource::connect(OSyncContext *ctx) { + //connect to dcop + //check knotes running + //start knotes if not running + + // Terminate knotes because we will change its data // Yes, it is _very_ ugly //FIXME: use dcop programming interface, not the commandline utility @@ -71,7 +61,10 @@ osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Couldn't allocate calendar object"); return false; } - if (!calendar->load(KGlobal::dirs()->saveLocation( "data" , "knotes/" ) + "notes.ics")) { + + QString notes_loc = KGlobal::dirs()->saveLocation( "data" , "knotes/" ) + "notes.ics"; + + if (!calendar->load(notes_loc)) { osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Couldn't load notes"); return false; } @@ -79,71 +72,6 @@ return true; } -/** Quick hack to avoid using KIO::NetAccess (that needs a KApplication instance */ -static bool copy_file(const char *from, const char *to) -{ - int f1 = open(from, O_RDONLY); - if (f1 < 0) - return false; - int f2 = open(to, O_WRONLY); - if (f2 < 0) { - close(f1); - return false; - } - - char buf[1024]; - int ret; - bool result = true; - for (;;) { - ret = read(f1, buf, 1024); - if (ret == 0) - break; - if (ret < 0) { - if (errno == EINTR) - continue; - result = false; - break; - } - int wret = write(f2, buf, ret); - if (wret < ret) { - result = false; - break; - } - } - close(f1); - close(f2); - return result; -} - -bool KNotesDataSource::saveNotes(OSyncContext *ctx) -{ - // shamelessly copied from KNotes source code - QString file = KGlobal::dirs()->saveLocation( "data" , "knotes/" ) + "notes.ics"; - QString backup = file + "~"; - - // if the backup fails don't even try to save the current notes - // (might just destroy the file that's already there) - - if ( !copy_file(file, backup) ) - { - osync_context_report_error(ctx, OSYNC_ERROR_IO_ERROR, - i18n("Unable to save the notes backup to " - "%1! Check that there is sufficient " - "disk space!").arg( backup ) ); - return false; - } - else if ( !calendar->save( file, new KCal::ICalFormat() ) ) - { - osync_context_report_error(ctx, OSYNC_ERROR_IO_ERROR, - i18n("Unable to save the notes to %1! " - "Check that there is sufficient disk space." - "There should be a backup in %2 " - "though.").arg( file ).arg( backup ) ); - return false; - } - return true; -} - bool KNotesDataSource::disconnect(OSyncContext *ctx) { if (!saveNotes(ctx)) @@ -158,15 +86,6 @@ return true; } -static QString calc_hash(const KCal::Journal *note) -{ - QDateTime d = note->lastModified(); - if (!d.isValid()) - d = QDateTime::currentDateTime(); - /*FIXME: not i18ned string */ - return d.toString(); -} - bool KNotesDataSource::get_changeinfo(OSyncContext *ctx) { KCal::Journal::List notes = calendar->journals(); @@ -227,13 +146,8 @@ return true; } -void KNotesDataSource::get_data(OSyncContext *ctx, OSyncChange *) +bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg) { - osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Not implemented yet"); -} - -bool KNotesDataSource::__access(OSyncContext *ctx, OSyncChange *chg) -{ OSyncChangeType type = osync_change_get_changetype(chg); QString uid = osync_change_get_uid(chg); @@ -288,23 +202,14 @@ } } - return true; -} - -bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg) -{ - if (!__access(ctx, chg)) - return false; - osync_context_report_success(ctx); return true; } bool KNotesDataSource::commit_change(OSyncContext *ctx, OSyncChange *chg) { - if (!__access(ctx, chg)) + if (!access(ctx, chg)) return false; osync_hashtable_update_hash(hashtable, chg); - osync_context_report_success(ctx); return true; } Modified: branches/experimental-kdepim/src/knotes.h =================================================================== --- branches/experimental-kdepim/src/knotes.h 2005-04-04 15:26:13 UTC (rev 434) +++ branches/experimental-kdepim/src/knotes.h 2005-04-04 15:28:27 UTC (rev 435) @@ -1,6 +1,7 @@ /*********************************************************************** KNotes OSyncDataSource class 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 @@ -21,10 +22,23 @@ *************************************************************************/ /** * @autor Eduardo Pereira Habkost <eha...@co...> + * @autor Armin Bauer <arm...@op...> */ -extern "C" { +#include <kglobal.h> +#include <kstandarddirs.h> +#include <kio/netaccess.h> +#include <klocale.h> + +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +extern "C" +{ #include <opensync/opensync.h> +#include <opensync/opensync-xml.h> } // Forward declaration |