Changeset 2327

Show
Ignore:
Timestamp:
07/13/07 07:55:36 (1 year ago)
Author:
abaumann
Message:

Re-add support for syncing notes, based on old code from v0.2x.
This doesn't break event/contact syncing, but is otherwise untested.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/kdepim/Makefile.am

    r2293 r2327  
    3737kdepim_sync_la_LIBADD = -lstdc++ -L@OPENSYNC_LIBDIR@ -lopensync 
    3838 
    39 #src/kdepim_impl.cpp: KNotesIface_stub.h 
    40 #KNotesIface_stub.cpp: KNotesIface_stub.h 
     39src/kdepim_impl.cpp: KNotesIface_stub.h 
     40KNotesIface_stub.cpp: KNotesIface_stub.h 
    4141 
    42 #KNotesIface_stub.cpp: 
    43 #     dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl 
    44 #     dcopidl2cpp KNotesIface.kidl 
    45 #KNotesIface_stub.h: 
    46 #     dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl 
    47 #     dcopidl2cpp KNotesIface.kidl 
     42KNotesIface_stub.cpp: 
     43      dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl 
     44      dcopidl2cpp KNotesIface.kidl 
     45KNotesIface_stub.h: 
     46      dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl 
     47      dcopidl2cpp KNotesIface.kidl 
    4848 
    4949dist_kdepim_lib_la_SOURCES = \ 
     
    5151        src/datasource.cpp \ 
    5252        src/kaddrbook.cpp \ 
    53         src/kcal.cpp 
    54 #     src/knotes.cpp 
    55 #nodist_kdepim_lib_la_SOURCES = KNotesIface_stub.cpp 
     53        src/kcal.cpp \ 
     54      src/knotes.cpp 
     55nodist_kdepim_lib_la_SOURCES = KNotesIface_stub.cpp 
    5656kdepim_lib_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall 
    5757kdepim_lib_la_LDFLAGS = $(KDE_LDFLAGS) -avoid-version -export-dynamic -module 
  • plugins/kdepim/src/kdepim_impl.cpp

    r2293 r2327  
    4040#include "kaddrbook.h" 
    4141#include "kcal.h" 
    42 //#include "knotes.h" 
     42#include "knotes.h" 
    4343 
    4444static bool sentinel = false; 
     
    5151                KCalEventDataSource *kcal_event; 
    5252                KCalTodoDataSource *kcal_todo; 
     53                KNotesDataSource *knotes; 
    5354 
    5455                KApplication *application; 
     
    9091                        kcal_event = new KCalEventDataSource(&kcal); 
    9192                        kcal_todo = new KCalTodoDataSource(&kcal); 
     93                        knotes = new KNotesDataSource(); 
    9294                } 
    9395 
     
    107109                                goto error; 
    108110 
     111                        if (!knotes->initialize(plugin, info, error)) 
     112                                goto error; 
     113 
    109114                        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
    110115                        return true; 
     
    120125                        delete kcal_event; 
    121126                        delete kcal_todo; 
     127                        delete knotes; 
    122128 
    123129                        if ( newApplication ) { 
  • plugins/kdepim/src/knotes.cpp

    r1760 r2327  
    2222/** @file 
    2323 * 
    24  * @autor Eduardo Pereira Habkost <ehabkost@conectiva.com.br> 
     24 * @author Eduardo Pereira Habkost <ehabkost@conectiva.com.br> 
     25 * @author Andrew Baumann <andrewb@cse.unsw.edu.au> 
    2526 * 
    2627 * This module implements the access to the KDE 3.2 Notes, that are 
     
    2930 */ 
    3031 
    31  
    32  
    3332#include "knotes.h" 
    3433#include <glib.h> 
     
    3635#include <kmdcodec.h> 
    3736 
    38 KNotesDataSource::KNotesDataSource(OSyncMember *m, OSyncHashTable *h) 
    39                 :member(m), hashtable(h) 
    40 
    41         connected = false; 
    42 
    43  
    44 bool KNotesDataSource::connect(OSyncContext *ctx) 
    45 
    46         osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
    47  
     37bool KNotesDataSource::initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
     38
     39        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, plugin, info); 
     40 
     41        if (!OSyncDataSource::initialize(plugin, info, error)) { 
     42                osync_trace(TRACE_EXIT_ERROR, "%s", __PRETTY_FUNCTION__); 
     43                return false; 
     44        } 
     45 
     46        osync_objtype_sink_add_objformat(sink, "xmlformat-note"); 
     47 
     48        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     49        return true; 
     50
     51 
     52void KNotesDataSource::connect(OSyncPluginInfo *info, OSyncContext *ctx) 
     53
     54        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); 
     55         
    4856        //connect to dcop 
    4957        kn_dcop = KApplication::kApplication()->dcopClient(); 
     
    5159                osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to make new dcop for knotes"); 
    5260                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to make new dcop for knotes", __func__); 
    53                 return FALSE
     61                return
    5462        } 
    5563 
     
    6775                osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "Kontact is running. Please finish it"); 
    6876                osync_trace(TRACE_EXIT_ERROR, "%s: Kontact is running", __func__); 
    69                 return false
     77                return
    7078        } 
    7179 
     
    8290        kn_iface = new KNotesIface_stub("knotes", "KNotesIface"); 
    8391 
    84         if (!osync_anchor_compare(member, "note", "true")) { 
    85                 osync_trace(TRACE_INTERNAL, "Setting slow-sync for note"); 
    86                 osync_member_set_slow_sync(member, "note", TRUE); 
    87         } 
    88  
    89         connected = true; 
    90         osync_trace(TRACE_EXIT, "%s", __func__); 
    91         return true; 
    92 
    93  
    94 bool KNotesDataSource::disconnect(OSyncContext *ctx) 
     92        OSyncDataSource::connect(info, ctx); 
     93         
     94        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     95
     96 
     97void KNotesDataSource::disconnect(OSyncPluginInfo *, OSyncContext *ctx) 
    9598{ 
    9699        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
     
    113116        //kn_dcop = NULL; 
    114117 
    115         connected = false
     118        osync_context_report_success(ctx)
    116119        osync_trace(TRACE_EXIT, "%s", __func__); 
    117         return true; 
    118120} 
    119121 
     
    139141} 
    140142 
    141 bool KNotesDataSource::get_changeinfo(OSyncContext *ctx) 
     143void KNotesDataSource::get_changes(OSyncPluginInfo *info, OSyncContext *ctx) 
    142144{ 
    143145        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
    144146        QMap <KNoteID_t,QString> fNotes; 
    145147        //set Digest to rawResult 
    146         KMD5::Digest rawResult; 
     148        //KMD5::Digest rawResult; 
    147149        KMD5 hash_value; 
     150        OSyncError *error = NULL; 
    148151 
    149152        fNotes = kn_iface->notes(); 
     
    151154                osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get changed notes"); 
    152155                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get changed notes", __func__); 
    153                 return FALSE; 
    154         } 
    155  
    156         if (osync_member_get_slow_sync(member, "note")) { 
    157 //              osync_debug("kcal", 3, "Setting slow-sync for notes"); 
    158                 osync_hashtable_set_slow_sync(hashtable, "note"); 
    159         } 
     156                return; 
     157        } 
     158 
     159        if (osync_objtype_sink_get_slowsync(sink)) { 
     160                osync_trace(TRACE_INTERNAL, "Got slow-sync, resetting hashtable"); 
     161                osync_hashtable_reset(hashtable); 
     162        } 
     163 
     164        OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 
     165        OSyncObjFormat *objformat = osync_format_env_find_objformat(formatenv, "xml-note"); 
     166 
     167        OSyncChange *chg = NULL; 
     168        OSyncData *odata = NULL; 
     169        OSyncChangeType changetype; 
    160170 
    161171        QMap<KNoteID_t,QString>::ConstIterator i; 
     
    177187                // Create osxml doc containing the note 
    178188                xmlDoc *doc = xmlNewDoc((const xmlChar*)"1.0"); 
    179                 xmlNode *root = osxml_node_add_root(doc, "Note"); 
     189                xmlNode *root = osxml_node_add_root(doc, "note"); 
    180190 
    181191                OSyncXMLEncoding enc; 
     
    198208 
    199209                // initialize the change object 
    200                 OSyncChange *chg = osync_change_new(); 
     210                chg = osync_change_new(&error); 
     211                if (!chg) 
     212                        goto error; 
    201213                osync_change_set_uid(chg, uid.local8Bit()); 
    202                 osync_change_set_member(chg, member); 
    203  
    204                 // object type and format 
    205                 osync_change_set_objtype_string(chg, "note"); 
    206                 osync_change_set_objformat_string(chg, "xml-note"); 
    207                 osync_change_set_data(chg, (char*)doc, sizeof(doc), 1); 
     214 
     215                odata = osync_data_new((char*)doc, sizeof(doc), objformat, &error); 
     216                if (!odata) 
     217                        goto error; 
     218 
     219                osync_data_set_objtype(odata, osync_objtype_sink_get_name(sink)); 
     220 
     221                //Now you can set the data for the object 
     222                osync_change_set_data(chg, odata); 
     223                osync_data_unref(odata); 
    208224 
    209225//              osync_debug("knotes", 4, "Reporting note:\%s", osync_change_get_printable(chg)); 
     
    212228                // needs to be reported 
    213229                osync_change_set_hash(chg, hash.data()); 
    214                 if (osync_hashtable_detect_change(hashtable, chg)) { 
     230 
     231                // Report entry ... otherwise it gets deleted! 
     232                osync_hashtable_report(hashtable, uid); 
     233                 
     234                changetype = osync_hashtable_get_changetype(hashtable, uid, hash.data()); 
     235                osync_change_set_changetype(chg, changetype); 
     236                if (OSYNC_CHANGE_TYPE_UNMODIFIED != changetype) { 
    215237                        osync_context_report_change(ctx, chg); 
    216                         osync_hashtable_update_hash(hashtable, chg); 
    217                 } 
     238                        osync_hashtable_update_hash(hashtable, changetype, uid, hash.data()); 
     239                } 
     240 
    218241                hash_value.reset(); 
    219242        } 
    220243 
    221         osync_hashtable_report_deleted(hashtable, ctx, "note"); 
    222  
     244        if (!report_deleted(info, ctx)) { 
     245                osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 
     246                return; 
     247        } 
     248 
     249        osync_context_report_success(ctx); 
    223250        osync_trace(TRACE_EXIT, "%s", __func__); 
    224         return true
    225 
    226  
    227 /** basic access method 
    228  * 
    229  * This method is used by both access() and commit_change() method, 
    230  * so it shouldn't call osync_context_report_success(). On success, 
    231  * it should just return true and let the caller report success() to 
    232  * OpenSync 
    233  */ 
    234 bool KNotesDataSource::__access(OSyncContext *ctx, OSyncChange *chg) 
     251        return
     252 
     253error: 
     254        if (chg) 
     255                osync_change_unref(chg); 
     256        osync_context_report_osyncerror(ctx, error); 
     257        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); 
     258        osync_error_unref(&error); 
     259
     260 
     261void KNotesDataSource::commit(OSyncPluginInfo *, OSyncContext *ctx, OSyncChange *chg) 
    235262{ 
    236263        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 
     
    240267 
    241268        //set Digest to rawResult 
    242         KMD5::Digest rawResult; 
     269        //KMD5::Digest rawResult; 
    243270        KMD5 hash_value; 
    244271 
     
    246273 
    247274                // Get osxml data 
    248                 xmlDoc *doc = (xmlDoc*)osync_change_get_data(chg); 
     275                OSyncData *odata = osync_change_get_data(chg); 
     276                xmlDoc *doc = (xmlDoc*)osync_data_get_data_ptr(odata); 
    249277 
    250278                xmlNode *root = xmlDocGetRootElement(doc); 
     
    252280                        osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get xml root element"); 
    253281                        osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data", __func__); 
    254                         return false
    255                 } 
    256  
    257                 if (xmlStrcmp((root)->name, (const xmlChar *) "Note")) { 
     282                        return
     283                } 
     284 
     285                if (xmlStrcmp((root)->name, (const xmlChar *) "note")) { 
    258286                        osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Wrong root element"); 
    259287                        osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data2", __func__); 
    260                         return false
     288                        return
    261289                } 
    262290 
     
    264292                char * tmpStr; 
    265293 
    266                 tmpStr = osync_change_get_printable(chg); 
     294                tmpStr = osync_data_get_printable(odata); 
    267295                xmlStr = (xmlChar*) osxml_find_node(root, "Summary"); 
    268296                osync_trace(TRACE_INTERNAL, "Getting note %s and %s\n", tmpStr, xmlStr); 
     
    284312                                        osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to add new note"); 
    285313                                        osync_trace(TRACE_EXIT_ERROR, "%s: Unable to add new note", __func__); 
    286                                         return false
     314                                        return
    287315                                } 
    288316 
     
    302330                                        osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set name"); 
    303331                                        osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set name", __func__); 
    304                                         return false
     332                                        return
    305333                                } 
    306334 
     
    309337                                        osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set text"); 
    310338                                        osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set text", __func__); 
    311                                         return false
     339                                        return
    312340                                } 
    313341                                hash_value.update(summary); 
     
    320348                                osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Invalid change type"); 
    321349                                osync_trace(TRACE_EXIT_ERROR, "%s: Invalid change type", __func__); 
    322                                 return false
     350                                return
    323351                        } 
    324352                } 
     
    336364        } 
    337365 
    338         osync_trace(TRACE_EXIT, "%s", __func__); 
    339         return true; 
    340 
    341  
    342 bool KNotesDataSource::commit_change(OSyncContext *ctx, OSyncChange *chg) 
    343 
    344         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 
    345         if (!__access(ctx, chg)) { 
    346                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); 
    347                 return false; 
    348         } 
    349         osync_hashtable_update_hash(hashtable, chg); 
     366        osync_hashtable_update_hash(hashtable, type, uid, osync_change_get_hash(chg)); 
    350367        osync_context_report_success(ctx); 
    351368        osync_trace(TRACE_EXIT, "%s", __func__); 
    352         return true; 
    353 
    354  
    355 bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg) 
    356 
    357         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 
    358         if (!__access(ctx, chg)) { 
    359                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); 
    360                 return false; 
    361         } 
    362         osync_context_report_success(ctx); 
    363         osync_trace(TRACE_EXIT, "%s", __func__); 
    364         return true; 
    365 
     369
  • plugins/kdepim/src/knotes.h

    r1620 r2327  
    2222*************************************************************************/ 
    2323/** 
    24  * @autor Eduardo Pereira Habkost <ehabkost@conectiva.com.br> 
    25  * @autor Armin Bauer <armin.bauer@opensync.org> 
     24 * @author Eduardo Pereira Habkost <ehabkost@conectiva.com.br> 
     25 * @author Armin Bauer <armin.bauer@opensync.org> 
     26 * @author Andrew Baumann <andrewb@cse.unsw.edu.au> 
    2627 */ 
    2728 
     
    4748typedef QString KNoteID_t; 
    4849 
    49 extern "C" 
    50 
    51 #include <opensync/opensync.h> 
     50#include "osyncbase.h" 
     51#include "datasource.h" 
    5252#include <opensync/opensync_xml.h> 
    53 } 
    5453 
    5554/** KNotes access implementation interface 
    5655 */ 
    57 class KNotesDataSource 
     56class KNotesDataSource : public OSyncDataSource 
    5857{ 
    5958        private: 
    60                 OSyncMember *member; 
    61                 OSyncHashTable *hashtable; 
    62  
    6359                DCOPClient *kn_dcop; 
    6460                KNotesIface_stub *kn_iface; 
    6561 
    66                 /** Ugly hack to restart KNotes if it 
    67                  * was running 
    68                  */ 
     62                /** Ugly hack to restart KNotes if it was running */ 
    6963                bool knotesWasRunning; 
    7064 
    71                 /** access() method, used by commit() and access() 
    72                  * 
    73                  * Returns true on succes, but don't send success reporting 
    74                  * to context, because the caller may need to do more 
    75                  * operations 
    76                  */ 
    77                 bool __access(OSyncContext *ctx, OSyncChange *chg); 
    7865                bool saveNotes(OSyncContext *ctx); 
    79         public: 
    80                 KNotesDataSource(OSyncMember *member, OSyncHashTable *hashtable); 
     66         
     67public: 
     68                KNotesDataSource() : OSyncDataSource("note") {}; 
     69                virtual ~KNotesDataSource() {}; 
    8170 
    82                 /** connect() method 
    83                  * 
    84                  * On success, returns true, but doesn't call osync_context_report_success() 
    85                  * On error, returns false, after calling osync_context_report_error() 
    86                  */ 
    87                 bool connect(OSyncContext *ctx); 
    88  
    89                 /** disconnect() method 
    90                  * 
    91                  * On success, returns true, but doesn't call osync_context_report_success() 
    92                  * On error, returns false, after calling osync_context_report_error() 
    93                  */ 
    94                 bool disconnect(OSyncContext *ctx); 
    95  
    96                 /** get_changeinfo() method 
    97                  * 
    98                  * On success, returns true, but doesn't call osync_context_report_success() 
    99                  * On error, returns false, after calling osync_context_report_error() 
    100                  */ 
    101                 bool get_changeinfo(OSyncContext *ctx); 
    102  
    103                 void get_data(OSyncContext *ctx, OSyncChange *chg); 
    104  
    105                 /** access() method 
    106                  * 
    107                  * On success, returns true, after calling osync_context_report_success() 
    108                  * On error, returns false, after calling osync_context_report_error() 
    109                  */ 
    110                 bool access(OSyncContext *ctx, OSyncChange *chg); 
    111  
    112                 /** commit_change() method 
    113                  * 
    114                  * On success, returns true, after calling osync_context_report_success() 
    115                  * On error, returns false, after calling osync_context_report_error() 
    116                  */ 
    117                 bool commit_change(OSyncContext *ctx, OSyncChange *chg); 
    118                 bool connected; 
     71                bool initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error); 
     72                virtual void connect(OSyncPluginInfo *info, OSyncContext *ctx); 
     73                virtual void disconnect(OSyncPluginInfo *info, OSyncContext *ctx); 
     74                virtual void get_changes(OSyncPluginInfo *info, OSyncContext *ctx); 
     75                virtual void commit(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg); 
    11976};