Changeset 2327
- Timestamp:
- 07/13/07 07:55:36 (1 year ago)
- Files:
-
- plugins/kdepim/Makefile.am (modified) (2 diffs)
- plugins/kdepim/src/kdepim_impl.cpp (modified) (5 diffs)
- plugins/kdepim/src/knotes.cpp (modified) (21 diffs)
- plugins/kdepim/src/knotes.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/kdepim/Makefile.am
r2293 r2327 37 37 kdepim_sync_la_LIBADD = -lstdc++ -L@OPENSYNC_LIBDIR@ -lopensync 38 38 39 #src/kdepim_impl.cpp: KNotesIface_stub.h40 #KNotesIface_stub.cpp: KNotesIface_stub.h39 src/kdepim_impl.cpp: KNotesIface_stub.h 40 KNotesIface_stub.cpp: KNotesIface_stub.h 41 41 42 #KNotesIface_stub.cpp:43 #dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl44 #dcopidl2cpp KNotesIface.kidl45 #KNotesIface_stub.h:46 #dcopidl $(top_srcdir)/src/KNotesIface.h > KNotesIface.kidl47 #dcopidl2cpp KNotesIface.kidl42 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 48 48 49 49 dist_kdepim_lib_la_SOURCES = \ … … 51 51 src/datasource.cpp \ 52 52 src/kaddrbook.cpp \ 53 src/kcal.cpp 54 #src/knotes.cpp55 #nodist_kdepim_lib_la_SOURCES = KNotesIface_stub.cpp53 src/kcal.cpp \ 54 src/knotes.cpp 55 nodist_kdepim_lib_la_SOURCES = KNotesIface_stub.cpp 56 56 kdepim_lib_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall 57 57 kdepim_lib_la_LDFLAGS = $(KDE_LDFLAGS) -avoid-version -export-dynamic -module plugins/kdepim/src/kdepim_impl.cpp
r2293 r2327 40 40 #include "kaddrbook.h" 41 41 #include "kcal.h" 42 //#include "knotes.h"42 #include "knotes.h" 43 43 44 44 static bool sentinel = false; … … 51 51 KCalEventDataSource *kcal_event; 52 52 KCalTodoDataSource *kcal_todo; 53 KNotesDataSource *knotes; 53 54 54 55 KApplication *application; … … 90 91 kcal_event = new KCalEventDataSource(&kcal); 91 92 kcal_todo = new KCalTodoDataSource(&kcal); 93 knotes = new KNotesDataSource(); 92 94 } 93 95 … … 107 109 goto error; 108 110 111 if (!knotes->initialize(plugin, info, error)) 112 goto error; 113 109 114 osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 110 115 return true; … … 120 125 delete kcal_event; 121 126 delete kcal_todo; 127 delete knotes; 122 128 123 129 if ( newApplication ) { plugins/kdepim/src/knotes.cpp
r1760 r2327 22 22 /** @file 23 23 * 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> 25 26 * 26 27 * This module implements the access to the KDE 3.2 Notes, that are … … 29 30 */ 30 31 31 32 33 32 #include "knotes.h" 34 33 #include <glib.h> … … 36 35 #include <kmdcodec.h> 37 36 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 37 bool 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 52 void KNotesDataSource::connect(OSyncPluginInfo *info, OSyncContext *ctx) 53 { 54 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); 55 48 56 //connect to dcop 49 57 kn_dcop = KApplication::kApplication()->dcopClient(); … … 51 59 osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to make new dcop for knotes"); 52 60 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to make new dcop for knotes", __func__); 53 return FALSE;61 return; 54 62 } 55 63 … … 67 75 osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "Kontact is running. Please finish it"); 68 76 osync_trace(TRACE_EXIT_ERROR, "%s: Kontact is running", __func__); 69 return false;77 return; 70 78 } 71 79 … … 82 90 kn_iface = new KNotesIface_stub("knotes", "KNotesIface"); 83 91 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 97 void KNotesDataSource::disconnect(OSyncPluginInfo *, OSyncContext *ctx) 95 98 { 96 99 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); … … 113 116 //kn_dcop = NULL; 114 117 115 connected = false;118 osync_context_report_success(ctx); 116 119 osync_trace(TRACE_EXIT, "%s", __func__); 117 return true;118 120 } 119 121 … … 139 141 } 140 142 141 bool KNotesDataSource::get_changeinfo(OSyncContext *ctx)143 void KNotesDataSource::get_changes(OSyncPluginInfo *info, OSyncContext *ctx) 142 144 { 143 145 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 144 146 QMap <KNoteID_t,QString> fNotes; 145 147 //set Digest to rawResult 146 KMD5::Digest rawResult;148 //KMD5::Digest rawResult; 147 149 KMD5 hash_value; 150 OSyncError *error = NULL; 148 151 149 152 fNotes = kn_iface->notes(); … … 151 154 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get changed notes"); 152 155 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; 160 170 161 171 QMap<KNoteID_t,QString>::ConstIterator i; … … 177 187 // Create osxml doc containing the note 178 188 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"); 180 190 181 191 OSyncXMLEncoding enc; … … 198 208 199 209 // initialize the change object 200 OSyncChange *chg = osync_change_new(); 210 chg = osync_change_new(&error); 211 if (!chg) 212 goto error; 201 213 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); 208 224 209 225 // osync_debug("knotes", 4, "Reporting note:\%s", osync_change_get_printable(chg)); … … 212 228 // needs to be reported 213 229 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) { 215 237 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 218 241 hash_value.reset(); 219 242 } 220 243 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); 223 250 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 253 error: 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 261 void KNotesDataSource::commit(OSyncPluginInfo *, OSyncContext *ctx, OSyncChange *chg) 235 262 { 236 263 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); … … 240 267 241 268 //set Digest to rawResult 242 KMD5::Digest rawResult;269 //KMD5::Digest rawResult; 243 270 KMD5 hash_value; 244 271 … … 246 273 247 274 // 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); 249 277 250 278 xmlNode *root = xmlDocGetRootElement(doc); … … 252 280 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get xml root element"); 253 281 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")) { 258 286 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Wrong root element"); 259 287 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data2", __func__); 260 return false;288 return; 261 289 } 262 290 … … 264 292 char * tmpStr; 265 293 266 tmpStr = osync_ change_get_printable(chg);294 tmpStr = osync_data_get_printable(odata); 267 295 xmlStr = (xmlChar*) osxml_find_node(root, "Summary"); 268 296 osync_trace(TRACE_INTERNAL, "Getting note %s and %s\n", tmpStr, xmlStr); … … 284 312 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to add new note"); 285 313 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to add new note", __func__); 286 return false;314 return; 287 315 } 288 316 … … 302 330 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set name"); 303 331 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set name", __func__); 304 return false;332 return; 305 333 } 306 334 … … 309 337 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to set text"); 310 338 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to set text", __func__); 311 return false;339 return; 312 340 } 313 341 hash_value.update(summary); … … 320 348 osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Invalid change type"); 321 349 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid change type", __func__); 322 return false;350 return; 323 351 } 324 352 } … … 336 364 } 337 365 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)); 350 367 osync_context_report_success(ctx); 351 368 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 22 22 *************************************************************************/ 23 23 /** 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> 26 27 */ 27 28 … … 47 48 typedef QString KNoteID_t; 48 49 49 extern "C" 50 { 51 #include <opensync/opensync.h> 50 #include "osyncbase.h" 51 #include "datasource.h" 52 52 #include <opensync/opensync_xml.h> 53 }54 53 55 54 /** KNotes access implementation interface 56 55 */ 57 class KNotesDataSource 56 class KNotesDataSource : public OSyncDataSource 58 57 { 59 58 private: 60 OSyncMember *member;61 OSyncHashTable *hashtable;62 63 59 DCOPClient *kn_dcop; 64 60 KNotesIface_stub *kn_iface; 65 61 66 /** Ugly hack to restart KNotes if it 67 * was running 68 */ 62 /** Ugly hack to restart KNotes if it was running */ 69 63 bool knotesWasRunning; 70 64 71 /** access() method, used by commit() and access()72 *73 * Returns true on succes, but don't send success reporting74 * to context, because the caller may need to do more75 * operations76 */77 bool __access(OSyncContext *ctx, OSyncChange *chg);78 65 bool saveNotes(OSyncContext *ctx); 79 public: 80 KNotesDataSource(OSyncMember *member, OSyncHashTable *hashtable); 66 67 public: 68 KNotesDataSource() : OSyncDataSource("note") {}; 69 virtual ~KNotesDataSource() {}; 81 70 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); 119 76 };
