From: <svn...@op...> - 2005-04-04 16:12:00
|
Author: abauer Date: 2005-04-04 18:13:16 +0200 (Mon, 04 Apr 2005) New Revision: 436 Modified: branches/experimental-kdepim/Makefile.am branches/experimental-kdepim/src/knotes-test.cpp branches/experimental-kdepim/src/knotes.cpp branches/experimental-kdepim/src/knotes.h Log: More updates to make the notes part use dcop Modified: branches/experimental-kdepim/Makefile.am =================================================================== --- branches/experimental-kdepim/Makefile.am 2005-04-04 15:28:27 UTC (rev 435) +++ branches/experimental-kdepim/Makefile.am 2005-04-04 16:13:16 UTC (rev 436) @@ -1,31 +1,20 @@ -#FIXME kdepimlibdir=@OPENSYNC_LIBDIR@/kdepim plugindir=@OPENSYNC_PLUGINDIR@ -#configdir=@OPENSYNC_CONFIGDIR@ -#FIXME: set EXTRA_DIST - INCLUDES = $(OSYNC_CFLAGS) $(XML_CFLAGS) $(GLIB_CFLAGS) $(KDE_INCLUDES) $(QT_INCLUDES) AM_CXXFLAGS = -Wall -Werror -# Temporary hack to fix difference between <opensync/opensync.h> and <opensync.h> -INCLUDES += -I@OPENSYNC_INCLUDEDIR@/opensync-1.0/opensync - #FIXME: Is there a KDE macro to set this? LIB_KCAL = -lkcal plugin_LTLIBRARIES = kdepim_sync.la kdepim_lib.la -# format_LTLIBRARIES = kcal_format.la EXTRA_DIST = \ src/kaddrbook.h \ src/kcal.h \ src/osyncbase.h \ - src/knotes.h + src/knotes.h \ + src/KNotesIface.h -# kcal_format_la_SOURCES = src/kcal_format.cpp -# kcal_format_la_LDFLAGS = -avoid-version -export-dynamic -module -# kcal_format_la_LIBADD = $(KDE_RPATH) $(LIB_KABC) - kdepim_sync_la_SOURCES = src/kdepim_sync.cpp kdepim_sync_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall -Werror kdepim_sync_la_LDFLAGS = -avoid-version -export-dynamic -module @@ -35,14 +24,13 @@ kdepim_lib_la_SOURCES = src/kdepim_impl.cpp \ src/kcal.cpp \ - src/knotes.cpp + src/knotes.cpp \ + src/kaddrbook.cpp \ + src/KNotesIface_stub.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 -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@ +KNotesIface_stub.cpp: + dcopidl src/KNotesIface.h > src/KNotesIface.kidl + dcopidl2cpp src/KNotesIface.kidl \ No newline at end of file Modified: branches/experimental-kdepim/src/knotes-test.cpp =================================================================== --- branches/experimental-kdepim/src/knotes-test.cpp 2005-04-04 15:28:27 UTC (rev 435) +++ branches/experimental-kdepim/src/knotes-test.cpp 2005-04-04 16:13:16 UTC (rev 436) @@ -50,9 +50,8 @@ } } - KNotesIface_stub *fKNotes = new KNotesIface_stub(knotesAppname,"KNotesIface"); - + fNotes = fKNotes->notes(); if (fKNotes->status() != DCOPStub::CallSucceeded) { Modified: branches/experimental-kdepim/src/knotes.cpp =================================================================== --- branches/experimental-kdepim/src/knotes.cpp 2005-04-04 15:28:27 UTC (rev 435) +++ branches/experimental-kdepim/src/knotes.cpp 2005-04-04 16:13:16 UTC (rev 436) @@ -42,60 +42,72 @@ bool KNotesDataSource::connect(OSyncContext *ctx) { - //connect to dcop + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); //check knotes running - //start knotes if not running + + //connect to dcop + DCOPClient *kn_dcop = KApplication::kApplication()->dcopClient(); + if (!kndcop) { + 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; + } - // Terminate knotes because we will change its data - // Yes, it is _very_ ugly - //FIXME: use dcop programming interface, not the commandline utility - if (!system("dcop knotes MainApplication-Interface quit")) - /* Restart knotes later */ - knotesWasRunning = true; - else + if (!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(); + if (!apps.contains("knotes")) { + //start knotes if not running knotesWasRunning = false; + } else + knotesWasRunning = true; - calendar = new KCal::CalendarLocal; - if (!calendar) { - osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Couldn't allocate calendar object"); - return false; - } - - QString notes_loc = KGlobal::dirs()->saveLocation( "data" , "knotes/" ) + "notes.ics"; + kn_iface = new KNotesIface_stub(knotesAppname,"KNotesIface"); - if (!calendar->load(notes_loc)) { - osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Couldn't load notes"); - return false; - } - - return true; + osync_trace(TRACE_EXIT, "%s", __func__); + return true; } bool KNotesDataSource::disconnect(OSyncContext *ctx) { - if (!saveNotes(ctx)) - return false; - - delete calendar; - calendar = NULL; - - // FIXME: ugly, but necessary - if (knotesWasRunning) - system("knotes"); - return true; + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); + //call sync on knotes dcop + + // FIXME: ugly, but necessary + if (!knotesWasRunning) { + //Terminate knotes + } + + //detach dcop + //destroy dcop + + osync_trace(TRACE_EXIT, "%s", __func__); + return true; } bool KNotesDataSource::get_changeinfo(OSyncContext *ctx) { - KCal::Journal::List notes = calendar->journals(); - - for (KCal::Journal::List::ConstIterator i = notes.begin(); i != notes.end(); i++) { - osync_debug("knotes", 4, "Note summary: %s", (const char*)(*i)->summary().local8Bit()); - osync_debug("knotes", 4, "Note contents:\n%s\n====", (const char*)(*i)->description().local8Bit()); - + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); + QMap <KNoteID_t,QString> fNotes; + + fNotes = fKNotes->notes(); + if (fKNotes->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()) { + 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 hash = calc_hash(*i); // Create osxml doc containing the note xmlDoc *doc = xmlNewDoc((const xmlChar*)"1.0"); @@ -124,16 +136,6 @@ osync_change_set_objformat_string(chg, "xml-note"); osync_change_set_data(chg, (char*)doc, sizeof(doc), 1); - - //XXX: workaround to a bug on osync_change_multiply_master: - // convert it to vnote - OSyncFormatEnv *env = osync_member_get_format_env(member); - OSyncError *e = NULL; - if (!osync_change_convert_fmtname(env, chg, "vnote11", &e)) { - osync_context_report_error(ctx, OSYNC_ERROR_CONVERT, "Error converting data to vnote: %s", osync_error_print(&e)); - return false; - } - // Use the hash table to check if the object // needs to be reported osync_change_set_hash(chg, hash.data()); @@ -164,31 +166,18 @@ QString summary = osxml_find_node(root, "Summary"); QString body = osxml_find_node(root, "Body"); - - KCal::Journal *j = calendar->journal(uid); - - if (type == CHANGE_MODIFIED && !j) - type = CHANGE_ADDED; - QString hash, uid; // end of the ugly-format parsing switch (type) { case CHANGE_ADDED: - j = new KCal::Journal; - j->setUid(uid); - j->setSummary(summary); - j->setDescription(body); - hash = calc_hash(j); - calendar->addJournal(j); - uid = j->uid(); + uid = newNote(); osync_change_set_uid(chg, uid); osync_change_set_hash(chg, hash); - break; case CHANGE_MODIFIED: - j->setSummary(summary); - j->setDescription(body); - hash = calc_hash(j); + setText + setBody + hash = calc_hash(); osync_change_set_hash(chg, hash); break; default: @@ -196,10 +185,7 @@ return false; } } else { - KCal::Journal *j = calendar->journal(uid); - if (j) { - calendar->deleteJournal(j); - } + //dcop killNote } osync_context_report_success(ctx); Modified: branches/experimental-kdepim/src/knotes.h =================================================================== --- branches/experimental-kdepim/src/knotes.h 2005-04-04 15:28:27 UTC (rev 435) +++ branches/experimental-kdepim/src/knotes.h 2005-04-04 16:13:16 UTC (rev 436) @@ -52,9 +52,10 @@ { private: OSyncMember *member; - OSyncHashTable *hashtable; - KCal::CalendarLocal *calendar; - + KNotesIface_stub *fKNotes; + DCOPClient *kn_dcop + KNotesIface_stub kn_iface; + /** Ugly hack to restart KNotes if it * was running */ |