Changeset 1619
- Timestamp:
- 01/20/07 11:56:41 (23 months ago)
- Files:
-
- 1 modified
-
plugins/kdepim/src/knotes.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/kdepim/src/knotes.cpp
r1618 r1619 1 /*********************************************************************** 1 /*********************************************************************** 2 2 KNotes support for OpenSync kdepim-sync plugin 3 3 Copyright (C) 2004 Conectiva S. A. 4 4 5 5 This program is free software; you can redistribute it and/or modify 6 6 it under the terms of the GNU General Public License version 2 as 7 7 published by the Free Software Foundation; 8 8 9 9 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 10 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, … … 15 15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 17 18 18 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 19 19 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS … … 35 35 36 36 KNotesDataSource::KNotesDataSource(OSyncMember *m, OSyncHashTable *h) 37 :member(m), hashtable(h)37 :member(m), hashtable(h) 38 38 { 39 39 connected = false; … … 43 43 { 44 44 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 45 45 46 46 //connect to dcop 47 47 kn_dcop = KApplication::kApplication()->dcopClient(); … … 51 51 return FALSE; 52 52 } 53 53 54 54 /*if (!kn_dcop->attach()) { 55 55 osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to attach dcop for knotes"); … … 57 57 return FALSE; 58 58 }*/ 59 59 60 60 QString appId = kn_dcop->registerAs("opensync"); 61 61 62 62 //check if kontact is running, and return an error if it 63 63 //is running … … 72 72 if (!apps.contains("knotes")) { 73 73 //start knotes if not running 74 knotesWasRunning = false;75 system("knotes");74 knotesWasRunning = false; 75 system("knotes"); 76 76 system("dcop knotes KNotesIface hideAllNotes"); 77 77 } else 78 knotesWasRunning = true;78 knotesWasRunning = true; 79 79 80 80 kn_iface = new KNotesIface_stub("knotes", "KNotesIface"); … … 88 88 { 89 89 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 90 90 91 91 // FIXME: ugly, but necessary 92 92 if (!knotesWasRunning) { 93 93 system("dcop knotes MainApplication-Interface quit"); 94 94 } 95 95 96 96 //detach dcop 97 97 /*if (!kn_dcop->detach()) { … … 105 105 //delete kn_dcop; 106 106 //kn_dcop = NULL; 107 107 108 108 connected = false; 109 109 osync_trace(TRACE_EXIT, "%s", __func__); … … 223 223 { 224 224 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 225 OSyncChangeType type = osync_change_get_changetype(chg);226 227 QString uid = osync_change_get_uid(chg);228 229 if (type != CHANGE_DELETED) {230 231 // Get osxml data232 xmlDoc *doc = (xmlDoc*)osync_change_get_data(chg);233 234 xmlNode *root = xmlDocGetRootElement(doc);225 OSyncChangeType type = osync_change_get_changetype(chg); 226 227 QString uid = osync_change_get_uid(chg); 228 229 if (type != CHANGE_DELETED) { 230 231 // Get osxml data 232 xmlDoc *doc = (xmlDoc*)osync_change_get_data(chg); 233 234 xmlNode *root = xmlDocGetRootElement(doc); 235 235 if (!root) { 236 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get xml root element");237 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data", __func__);236 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get xml root element"); 237 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data", __func__); 238 238 return false; 239 }240 239 } 240 241 241 if (xmlStrcmp((root)->name, (const xmlChar *) "Note")) { 242 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Wrong root element");243 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data2", __func__);242 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Wrong root element"); 243 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid data2", __func__); 244 244 return false; 245 }246 247 xmlChar *xmlStr;248 char * tmpStr;249 250 tmpStr = osync_change_get_printable(chg);251 xmlStr = (xmlChar*) osxml_find_node(root, "Summary");252 osync_trace(TRACE_INTERNAL, "Getting note %s and %s\n", tmpStr, xmlStr);253 254 QString summary = (char*)xmlStr;255 xmlFree(xmlStr);256 g_free(tmpStr);257 258 xmlStr = (xmlChar*) osxml_find_node(root, "Body");259 QString body = (char*)xmlStr;260 xmlFree(xmlStr);261 262 QString hash;263 switch (type) {264 case CHANGE_ADDED:265 osync_trace(TRACE_INTERNAL, "addding new \"%s\" and \"%s\"\n", (const char*)summary.local8Bit(), (const char*)body.local8Bit());266 uid = kn_iface->newNote(summary, body);245 } 246 247 xmlChar *xmlStr; 248 char * tmpStr; 249 250 tmpStr = osync_change_get_printable(chg); 251 xmlStr = (xmlChar*) osxml_find_node(root, "Summary"); 252 osync_trace(TRACE_INTERNAL, "Getting note %s and %s\n", tmpStr, xmlStr); 253 254 QString summary = (char*)xmlStr; 255 xmlFree(xmlStr); 256 g_free(tmpStr); 257 258 xmlStr = (xmlChar*) osxml_find_node(root, "Body"); 259 QString body = (char*)xmlStr; 260 xmlFree(xmlStr); 261 262 QString hash; 263 switch (type) { 264 case CHANGE_ADDED: 265 osync_trace(TRACE_INTERNAL, "addding new \"%s\" and \"%s\"\n", (const char*)summary.local8Bit(), (const char*)body.local8Bit()); 266 uid = kn_iface->newNote(summary, body); 267 267 if (kn_iface->status() != DCOPStub::CallSucceeded) { 268 268 osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to add new note"); 269 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to add new note", __func__);269 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to add new note", __func__); 270 270 return false; 271 271 } 272 272 273 273 kn_iface->hideNote(uid); 274 274 if (kn_iface->status() != DCOPStub::CallSucceeded) 275 275 osync_trace(TRACE_INTERNAL, "ERROR: Unable to hide note"); 276 277 osync_change_set_uid(chg, uid); 278 osync_change_set_hash(chg, hash); 276 277 hash = summary + body; 278 osync_change_set_uid(chg, uid); 279 osync_change_set_hash(chg, hash); 279 280 break; 280 case CHANGE_MODIFIED:281 case CHANGE_MODIFIED: 281 282 kn_iface->setName(uid, summary); 282 283 if (kn_iface->status() != DCOPStub::CallSucceeded) { … … 285 286 return false; 286 287 } 287 288 288 289 kn_iface->setText(uid, body); 289 290 if (kn_iface->status() != DCOPStub::CallSucceeded) { … … 292 293 return false; 293 294 } 294 hash = summary + body;295 osync_change_set_hash(chg, hash);295 hash = summary + body; 296 osync_change_set_hash(chg, hash); 296 297 break; 297 default:298 osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Invalid change type");299 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid change type", __func__);298 default: 299 osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Invalid change type"); 300 osync_trace(TRACE_EXIT_ERROR, "%s: Invalid change type", __func__); 300 301 return false; 301 }302 } else {302 } 303 } else { 303 304 system("dcop knotes KNotesIface hideAllNotes"); 304 305 QString asdasd = "dcop knotes KNotesIface killNote " + uid + " true"; 305 306 system((const char*)asdasd.local8Bit()); 306 osync_debug("knotes", 4, "Deleting note %s", (const char*)uid.local8Bit());307 osync_debug("knotes", 4, "Deleting note %s", (const char*)uid.local8Bit()); 307 308 /*kn_iface->killNote(uid, true); 308 309 if (kn_iface->status() != DCOPStub::CallSucceeded) { … … 311 312 return false; 312 313 }*/ 313 }314 315 osync_trace(TRACE_EXIT, "%s", __func__); 316 return true;314 } 315 316 osync_trace(TRACE_EXIT, "%s", __func__); 317 return true; 317 318 } 318 319 319 320 bool KNotesDataSource::commit_change(OSyncContext *ctx, OSyncChange *chg) 320 {321 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg);322 if (!__access(ctx, chg)) {323 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__);324 return false;325 }326 osync_hashtable_update_hash(hashtable, chg);327 osync_context_report_success(ctx);328 osync_trace(TRACE_EXIT, "%s", __func__);329 return true;330 }331 332 bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg)333 321 { 334 322 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); … … 336 324 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); 337 325 return false; 338 } 326 } 327 osync_hashtable_update_hash(hashtable, chg); 339 328 osync_context_report_success(ctx); 340 329 osync_trace(TRACE_EXIT, "%s", __func__); 341 330 return true; 342 331 } 332 333 bool KNotesDataSource::access(OSyncContext *ctx, OSyncChange *chg) 334 { 335 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 336 if (!__access(ctx, chg)) { 337 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); 338 return false; 339 } 340 osync_context_report_success(ctx); 341 osync_trace(TRACE_EXIT, "%s", __func__); 342 return true; 343 }
