kpilot

pctohhstate.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 PCToHHState.
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 "vcal-conduitbase.h"
00035 #include "pctohhstate.h"
00036 #include "cleanupstate.h"
00037 #include "deleteunsyncedhhstate.h"
00038 
00039 PCToHHState::PCToHHState()
00040 {
00041     fState = ePCToHH;
00042 }
00043 
00044 PCToHHState::~PCToHHState()
00045 {
00046 }
00047 
00048 void PCToHHState::startSync( ConduitAction *ca )
00049 {
00050     FUNCTIONSETUP;
00051     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00052     if( !vccb )
00053     {
00054         return;
00055     }
00056     
00057     DEBUGKPILOT << fname << ": Starting PCToHHState." << endl;
00058 
00059     // if we are asked to copy HH to PC, we shouldn't look for deleted records
00060     // on the Palm, since we've just copied them all.  =:)  Otherwise, look for
00061     // data on the palm that shouldn't be there and delete it if we find it....
00062     if ( vccb->syncMode() == ConduitAction::SyncMode::eCopyHHToPC )
00063     {
00064         fNextState = new CleanUpState();
00065     }
00066     else
00067     {
00068         fNextState = new DeleteUnsyncedHHState();
00069     }
00070 
00071     vccb->addLogMessage( i18n( "Copying records to Pilot ..." ) );
00072 
00073     fStarted = true;
00074     vccb->setHasNextRecord( true );
00075 }
00076 
00077 void PCToHHState::handleRecord( ConduitAction *ca )
00078 {
00079     FUNCTIONSETUP;
00080     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00081     if( !vccb )
00082     {
00083         return;
00084     }
00085 
00086     KCal::Incidence *e = 0L;
00087 
00088     if( vccb->isFullSync() )
00089     {
00090         e = vccb->privateBase()->getNextIncidence();
00091     }
00092     else
00093     {
00094         e = vccb->privateBase()->getNextModifiedIncidence();
00095     }
00096 
00097     // No more incidences to sync
00098     if( !e )
00099     {
00100         vccb->setHasNextRecord( false );
00101         return;
00102     }
00103     
00104     // let subclasses do something with the event
00105     vccb->preIncidence( e );
00106 
00107     // find the corresponding index on the palm and sync. If there is none, 
00108     // create it.
00109     recordid_t id = e->pilotId();
00110     
00111     DEBUGKPILOT << fname << ": found PC entry with pilotID " << id <<endl;
00112     DEBUGKPILOT << fname << ": Description: " << e->summary() << endl;
00113 
00114     QDateTime start_time = e->dtStart();
00115     QDateTime end_time = e->dtEnd();
00116     DEBUGKPILOT << fname << ": Time: "<< start_time.toString() << " until "
00117         << end_time.toString() << endl;
00118 
00119     PilotRecord *s = 0L;
00120 
00121     if( id > 0 && ( s = vccb->database()->readRecordById( id ) ) )
00122     {
00123         if( e->syncStatus() == KCal::Incidence::SYNCDEL )
00124         {
00125             vccb->deletePalmRecord( e, s );
00126         }
00127         else
00128         {
00129             vccb->changePalmRecord( e, s );
00130         }
00131 
00132         KPILOT_DELETE( s );
00133     } else {
00134 #ifdef DEBUG
00135         if (id > 0 )
00136         {
00137             DEBUGKPILOT << "-------------------------------------------------"
00138                 << "--------------------------" << endl;
00139             DEBUGKPILOT << fname << ": Could not read palm record with ID "
00140                 << id << endl;
00141         }
00142 #endif
00143         vccb->addPalmRecord( e );
00144     }
00145 }
00146 
00147 void PCToHHState::finishSync( ConduitAction *ca )
00148 {
00149     FUNCTIONSETUP;
00150     
00151     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00152     if( !vccb )
00153     {
00154         return;
00155     }
00156 
00157     DEBUGKPILOT << fname << ": Finished PCToHHState." << endl;
00158     vccb->setState( fNextState );
00159 }