kpilot
hhtopcstate.cc
Go to the documentation of this file.00001 /* KPilot 00002 ** 00003 ** Copyright (C) 2006 by Bertjan Broeksema <b.broeksema@gmail.com> 00004 ** 00005 ** This file is the implementation of the HHtoPCState 00006 */ 00007 00008 /* 00009 ** This program is free software; you can redistribute it and/or modify 00010 ** it under the terms of the GNU General Public License as published by 00011 ** the Free Software Foundation; either version 2 of the License, or 00012 ** (at your option) any later version. 00013 ** 00014 ** This program is distributed in the hope that it will be useful, 00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 ** GNU General Public License for more details. 00018 ** 00019 ** You should have received a copy of the GNU General Public License 00020 ** along with this program in a file called COPYING; if not, write to 00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 ** MA 02110-1301, USA. 00023 */ 00024 00025 /* 00026 ** Bug reports and questions can be sent to kde-pim@kde.org 00027 */ 00028 00029 #include <options.h> 00030 00031 #include "pilotDatabase.h" 00032 #include "pilotRecord.h" 00033 00034 #include "vcalconduitSettings.h" 00035 #include "vcal-conduitbase.h" 00036 #include "hhtopcstate.h" 00037 #include "pctohhstate.h" 00038 #include "cleanupstate.h" 00039 00040 HHToPCState::HHToPCState() 00041 { 00042 fState = eHHToPC; 00043 fPilotindex = 0; 00044 } 00045 00046 HHToPCState::~HHToPCState() 00047 { 00048 } 00049 00050 void HHToPCState::startSync( ConduitAction *ca ) 00051 { 00052 FUNCTIONSETUP; 00053 00054 VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca); 00055 if( !vccb ) 00056 { 00057 return; 00058 } 00059 00060 DEBUGKPILOT << fname << ": Starting HHToPCState." << endl; 00061 00062 if ( vccb->syncMode() == ConduitAction::SyncMode::eCopyHHToPC ) 00063 { 00064 fNextState = new CleanUpState(); 00065 } 00066 else 00067 { 00068 fNextState = new PCToHHState(); 00069 } 00070 00071 fStarted = true; 00072 vccb->setHasNextRecord( true ); 00073 } 00074 00075 void HHToPCState::handleRecord( ConduitAction *ca ) 00076 { 00077 FUNCTIONSETUP; 00078 00079 VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca); 00080 if( !vccb ) 00081 { 00082 return; 00083 } 00084 00085 PilotRecord *r = 0L; 00086 PilotRecord *s = 0L; 00087 00088 if ( vccb->isFullSync() ) 00089 { 00090 r = vccb->database()->readRecordByIndex( fPilotindex++ ); 00091 } 00092 else 00093 { 00094 r = vccb->database()->readNextModifiedRec(); 00095 } 00096 00097 if (!r) 00098 { 00099 vccb->privateBase()->updateIncidences(); 00100 vccb->setHasNextRecord( false ); 00101 return; 00102 } 00103 00104 // let subclasses do something with the record before we try to sync 00105 vccb->preRecord( r ); 00106 00107 bool archiveRecord = ( r->isArchived() ); 00108 s = vccb->localDatabase()->readRecordById( r->id() ); 00109 00110 if ( !s || vccb->isFirstSync() ) 00111 { 00112 #ifdef DEBUG 00113 if ( r->id() > 0 && !s ) 00114 { 00115 DEBUGKPILOT << "-------------------------------------------------"; 00116 DEBUGKPILOT << "--------------------------" << endl; 00117 DEBUGKPILOT << fname << ": Could not read palm record with ID "; 00118 DEBUGKPILOT << r->id() << endl; 00119 } 00120 #endif 00121 if ( !r->isDeleted() 00122 || ( vccb->config()->syncArchived() && archiveRecord ) ) 00123 { 00124 KCal::Incidence *e = vccb->addRecord( r ); 00125 if ( vccb->config()->syncArchived() && archiveRecord ) { 00126 e->setSyncStatus( KCal::Incidence::SYNCDEL ); 00127 } 00128 } 00129 } 00130 else 00131 { 00132 if ( r->isDeleted() ) 00133 { 00134 if ( vccb->config()->syncArchived() && archiveRecord ) 00135 { 00136 vccb->changeRecord( r, s ); 00137 } 00138 else 00139 { 00140 vccb->deleteRecord( r, s ); 00141 } 00142 } 00143 else 00144 { 00145 vccb->changeRecord( r, s ); 00146 } 00147 } 00148 00149 KPILOT_DELETE(r); 00150 KPILOT_DELETE(s); 00151 } 00152 00153 void HHToPCState::finishSync( ConduitAction *ca ) 00154 { 00155 FUNCTIONSETUP; 00156 00157 VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca); 00158 if( !vccb ) 00159 { 00160 return; 00161 } 00162 00163 DEBUGKPILOT << fname << ": Finished HHToPCState." << endl; 00164 vccb->setState( fNextState ); 00165 } 00166 00167 /* 00168 void VCalConduitBase::slotPalmRecToPC() 00169 { 00170 FUNCTIONSETUP; 00171 00172 PilotRecord *r; 00173 if (isFullSync()) 00174 { 00175 r = fDatabase->readRecordByIndex(pilotindex++); 00176 } 00177 else 00178 { 00179 r = fDatabase->readNextModifiedRec(); 00180 } 00181 PilotRecord *s = 0L; 00182 00183 if (!r) 00184 { 00185 fP->updateIncidences(); 00186 if ( syncMode()==SyncMode::eCopyHHToPC ) 00187 { 00188 emit logMessage(i18n("Cleaning up ...")); 00189 QTimer::singleShot(0, this, SLOT(cleanup())); 00190 return; 00191 } 00192 else 00193 { 00194 emit logMessage(i18n("Copying records to Pilot ...")); 00195 QTimer::singleShot(0 ,this,SLOT(slotPCRecToPalm())); 00196 return; 00197 } 00198 } 00199 00200 // let subclasses do something with the record before we try to sync 00201 preRecord(r); 00202 00203 // DEBUGKPILOT<<fname<<": Event: "<<e->dtStart()<<" until "<<e->dtEnd()<<endl; 00204 // DEBUGKPILOT<<fname<<": Time: "<<e->dtStart()<<" until "<<e->dtEnd()<<endl; 00205 bool archiveRecord=(r->isArchived()); 00206 00207 s = fLocalDatabase->readRecordById(r->id()); 00208 if (!s || isFirstSync()) 00209 { 00210 #ifdef DEBUG 00211 if (r->id()>0 && !s) 00212 { 00213 DEBUGKPILOT<<"---------------------------------------------------------------------------"<<endl; 00214 DEBUGKPILOT<< fname<<": Could not read palm record with ID "<<r->id()<<endl; 00215 } 00216 #endif 00217 if (!r->isDeleted() || (config()->syncArchived() && archiveRecord)) 00218 { 00219 KCal::Incidence*e=addRecord(r); 00220 if (config()->syncArchived() && archiveRecord) { 00221 e->setSyncStatus(KCal::Incidence::SYNCDEL); 00222 } 00223 } 00224 } 00225 else 00226 { 00227 if (r->isDeleted()) 00228 { 00229 if (config()->syncArchived() && archiveRecord) 00230 { 00231 changeRecord(r,s); 00232 } 00233 else 00234 { 00235 deleteRecord(r,s); 00236 } 00237 } 00238 else 00239 { 00240 changeRecord(r,s); 00241 } 00242 } 00243 00244 KPILOT_DELETE(r); 00245 KPILOT_DELETE(s); 00246 00247 QTimer::singleShot(0,this,SLOT(slotPalmRecToPC())); 00248 } 00249 */