Changeset 1619

Show
Ignore:
Timestamp:
01/20/07 11:56:41 (23 months ago)
Author:
mjahn
Message:

- apply fix based one XMPM changes against opensync kdepim-plugin 0630-make_hash_for_add.patch
- fix identation based on linux style

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/kdepim/src/knotes.cpp

    r1618 r1619  
    1 /***********************************************************************  
     1/*********************************************************************** 
    22KNotes support for OpenSync kdepim-sync plugin 
    33Copyright (C) 2004 Conectiva S. A. 
    4  
     4  
    55This program is free software; you can redistribute it and/or modify 
    66it under the terms of the GNU General Public License version 2 as 
    77published by the Free Software Foundation; 
    8  
     8  
    99THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
    1010OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     
    1515ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  
    1616OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
    17  
     17  
    1818ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,  
    1919COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS  
     
    3535 
    3636KNotesDataSource::KNotesDataSource(OSyncMember *m, OSyncHashTable *h) 
    37     :member(m), hashtable(h) 
     37                :member(m), hashtable(h) 
    3838{ 
    3939        connected = false; 
     
    4343{ 
    4444        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
    45          
     45 
    4646        //connect to dcop 
    4747        kn_dcop = KApplication::kApplication()->dcopClient(); 
     
    5151                return FALSE; 
    5252        } 
    53          
     53 
    5454        /*if (!kn_dcop->attach()) { 
    5555                osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to attach dcop for knotes"); 
     
    5757                return FALSE; 
    5858        }*/ 
    59          
     59 
    6060        QString appId = kn_dcop->registerAs("opensync"); 
    61          
     61 
    6262        //check if kontact is running, and return an error if it 
    6363        //is running 
     
    7272        if (!apps.contains("knotes")) { 
    7373                //start knotes if not running 
    74         knotesWasRunning = false; 
    75         system("knotes"); 
     74                knotesWasRunning = false; 
     75                system("knotes"); 
    7676                system("dcop knotes KNotesIface hideAllNotes"); 
    7777        } else 
    78         knotesWasRunning = true; 
     78                knotesWasRunning = true; 
    7979 
    8080        kn_iface = new KNotesIface_stub("knotes", "KNotesIface"); 
     
    8888{ 
    8989        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
    90          
     90 
    9191        // FIXME: ugly, but necessary 
    9292        if (!knotesWasRunning) { 
    9393                system("dcop knotes MainApplication-Interface quit"); 
    9494        } 
    95          
     95 
    9696        //detach dcop 
    9797        /*if (!kn_dcop->detach()) { 
     
    105105        //delete kn_dcop; 
    106106        //kn_dcop = NULL; 
    107          
     107 
    108108        connected = false; 
    109109        osync_trace(TRACE_EXIT, "%s", __func__); 
     
    223223{ 
    224224        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 data 
    232         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); 
    235235                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__); 
    238238                        return false; 
    239         } 
    240                  
     239                } 
     240 
    241241                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__); 
    244244                        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); 
    267267                                if (kn_iface->status() != DCOPStub::CallSucceeded) { 
    268268                                        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__); 
    270270                                        return false; 
    271271                                } 
    272                                  
     272 
    273273                                kn_iface->hideNote(uid); 
    274274                                if (kn_iface->status() != DCOPStub::CallSucceeded) 
    275275                                        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); 
    279280                                break; 
    280             case CHANGE_MODIFIED: 
     281                        case CHANGE_MODIFIED: 
    281282                                kn_iface->setName(uid, summary); 
    282283                                if (kn_iface->status() != DCOPStub::CallSucceeded) { 
     
    285286                                        return false; 
    286287                                } 
    287                                  
     288 
    288289                                kn_iface->setText(uid, body); 
    289290                                if (kn_iface->status() != DCOPStub::CallSucceeded) { 
     
    292293                                        return false; 
    293294                                } 
    294                 hash = summary + body; 
    295                 osync_change_set_hash(chg, hash); 
     295                                hash = summary + body; 
     296                                osync_change_set_hash(chg, hash); 
    296297                                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__); 
    300301                                return false; 
    301         } 
    302     } else { 
     302                } 
     303        } else { 
    303304                system("dcop knotes KNotesIface hideAllNotes"); 
    304305                QString asdasd = "dcop knotes KNotesIface killNote " + uid + " true"; 
    305306                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()); 
    307308                /*kn_iface->killNote(uid, true); 
    308309                if (kn_iface->status() != DCOPStub::CallSucceeded) { 
     
    311312                        return false; 
    312313                }*/ 
    313     } 
    314  
    315         osync_trace(TRACE_EXIT, "%s", __func__); 
    316     return true; 
     314        } 
     315 
     316        osync_trace(TRACE_EXIT, "%s", __func__); 
     317        return true; 
    317318} 
    318319 
    319320bool 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) 
    333321{ 
    334322        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 
     
    336324                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete note", __func__); 
    337325                return false; 
    338     } 
     326        } 
     327        osync_hashtable_update_hash(hashtable, chg); 
    339328        osync_context_report_success(ctx); 
    340329        osync_trace(TRACE_EXIT, "%s", __func__); 
    341330        return true; 
    342331} 
     332 
     333bool 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}