kpilot

deleteunsyncedhhstate.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 DeleteUnsyncedHHState.
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 #include <plugin.h>
00031 
00032 #include "pilotDatabase.h"
00033 #include "pilotRecord.h"
00034 
00035 #include "vcal-conduitbase.h"
00036 #include "deleteunsyncedhhstate.h"
00037 #include "deleteunsyncedpcstate.h"
00038 #include "cleanupstate.h"
00039 
00040 DeleteUnsyncedHHState::DeleteUnsyncedHHState()
00041 {
00042     fState = eDeleteUnsyncedHH;
00043 }
00044 
00045 DeleteUnsyncedHHState::~DeleteUnsyncedHHState()
00046 {
00047 }
00048 
00049 void DeleteUnsyncedHHState::startSync( ConduitAction *ca )
00050 {
00051     FUNCTIONSETUP;
00052 
00053     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00054     if( !vccb )
00055     {
00056         return;
00057     }
00058 
00059     DEBUGKPILOT << fname << ": Starting DeleteUnsyncedHHState." << endl;
00060     
00061     fPilotIndex = 0;
00062     fNextState = new DeleteUnsyncedPCState();
00063     
00064     vccb->setHasNextRecord( true );
00065     fStarted = true;
00066 }
00067 
00068 void DeleteUnsyncedHHState::handleRecord( ConduitAction *ca )
00069 {
00070     FUNCTIONSETUP;
00071 
00072     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00073     if( !vccb )
00074     {
00075         return;
00076     }
00077 
00078     PilotRecord *r = vccb->localDatabase()->readRecordByIndex( fPilotIndex++ );
00079     // if either we don't have a record, or if we're copying everything
00080     // from the handheld to the pc, then we don't have anything to do
00081     // here.  the latter is because if we're copying HH->PC, then by
00082     // definition, we will have everything from the HH on the PC and
00083     // therefore can't possibly have anything that needs to be deleted
00084     // from it.
00085     if ( !r
00086         || ( vccb->syncMode().mode() == ConduitAction::SyncMode::eCopyHHToPC ) )
00087     {
00088         vccb->setHasNextRecord( false );
00089         return;
00090     }
00091 
00092     KCal::Incidence *e = vccb->privateBase()->findIncidence( r->id() );
00093     if ( !e )
00094     {
00095         DEBUGKPILOT << "Didn't find incidence with id = " << r->id()
00096             << ", deleting it" << endl;
00097         vccb->deletePalmRecord( NULL, r );
00098     }
00099 
00100     KPILOT_DELETE( r );
00101 }
00102 
00103 void DeleteUnsyncedHHState::finishSync( ConduitAction *ca )
00104 {
00105     FUNCTIONSETUP;
00106 
00107     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00108     if( !vccb )
00109     {
00110         return;
00111     }
00112 
00113     DEBUGKPILOT << fname << ": Finishing DeleteUnsyncedHHState." << endl;
00114     vccb->setState( fNextState );
00115 }