kpilot

deleteunsyncedpcstate.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 DeleteUnsyncedPCState.
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 "deleteunsyncedpcstate.h"
00037 #include "cleanupstate.h"
00038 
00039 DeleteUnsyncedPCState::DeleteUnsyncedPCState()
00040 {
00041     fState = eDeleteUnsyncedPC;
00042 }
00043 
00044 DeleteUnsyncedPCState::~DeleteUnsyncedPCState()
00045 {
00046 }
00047 
00048 void DeleteUnsyncedPCState::startSync( ConduitAction *ca )
00049 {
00050     FUNCTIONSETUP;
00051 
00052     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00053     if( !vccb )
00054     {
00055         return;
00056     }
00057 
00058     DEBUGKPILOT << fname << ": Starting DeleteUnsyncedPCState." << endl;
00059     
00060     fPilotIndex = 0;
00061     fNextState = new CleanUpState();
00062     
00063     vccb->setHasNextRecord( true );
00064     fStarted = true;
00065 }
00066 
00067 void DeleteUnsyncedPCState::handleRecord( ConduitAction *ca )
00068 {
00069     FUNCTIONSETUP;
00070 
00071     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00072     if( !vccb )
00073     {
00074         return;
00075     }
00076 
00077     KCal::Incidence *e = 0L;
00078     e = vccb->privateBase()->getNextIncidence();
00079 
00080     // if we don't have a record, then we can't do anything.  also, if
00081     // we're copying everything from the PC to our handheld, then we're
00082     // guaranteed not to have anything extra on our PC that's not on
00083     // our handheld that needs to get deleted, so we can return in that
00084     // case too...
00085 
00086     if( !e || ( vccb->syncMode().mode() == ConduitAction::SyncMode::eCopyPCToHH ) )
00087     {
00088         vccb->setHasNextRecord( false );
00089         return;
00090     }
00091 
00092 
00093     // try to find the corresponding index on the palm.  if we can't
00094     // find it, then we have a pc record that needs to be deleted.
00095     recordid_t id = e->pilotId();
00096     
00097     PilotRecord *s = 0L;
00098 
00099     if( id > 0 )
00100     {
00101         s = vccb->database()->readRecordById( id );
00102     }
00103 
00104     // if we either have a pc record with no palm id or if we can't
00105     // find a palm record that matches, then we need to delete this PC
00106     // record.
00107     if ( id <=0 || !s )
00108     {
00109 #ifdef DEBUG
00110         DEBUGKPILOT << fname << ": found PC entry with pilotID: [" << id 
00111             << "], Description: [" << e->summary() 
00112             << "], Time: ["<< e->dtStart().toString() << "] until: ["
00113             << e->dtEnd().toString() << "]. Can't find it on Palm, "
00114             << "so I'm deleting it from the local calendar." << endl;
00115 #endif
00116         vccb->privateBase()->removeIncidence(e);
00117     }
00118 
00119     KPILOT_DELETE( s );
00120 
00121 }
00122 
00123 void DeleteUnsyncedPCState::finishSync( ConduitAction *ca )
00124 {
00125     FUNCTIONSETUP;
00126 
00127     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00128     if( !vccb )
00129     {
00130         return;
00131     }
00132 
00133     DEBUGKPILOT << fname << ": Finishing DeleteUnsyncedPCState." << endl;
00134     vccb->setState( fNextState );
00135 }