kpilot

teststate.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 TestState.
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 <qdatetime.h>
00032 #include <qfile.h>
00033 
00034 #include "pilotSerialDatabase.h"
00035 #include "pilotLocalDatabase.h"
00036 #include "pilotDateEntry.h"
00037 
00038 #include "teststate.h"
00039 #include "vcal-conduitbase.h"
00040 
00041 TestState::TestState() : fCalendar( QString::null )
00042 {
00043     fState = eTest;
00044 }
00045 
00046 TestState::~TestState()
00047 {
00048     FUNCTIONSETUP;
00049 }
00050 
00051 void TestState::startSync( ConduitAction *ca )
00052 {
00053     FUNCTIONSETUP;
00054     
00055     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00056     if( !vccb )
00057     {
00058         return;
00059     }
00060     
00061     DEBUGKPILOT << fname << ": Starting teststate." << endl;
00062 
00063     vccb->setHasNextRecord( true );
00064     fPilotindex = 0;
00065     fStarted = true;
00066 }
00067 
00068 void TestState::handleRecord( ConduitAction *ca )
00069 {
00070     FUNCTIONSETUP;
00071 
00072     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00073     if( !vccb )
00074     {
00075         return;
00076     }
00077 
00078     DEBUGKPILOT << fname << ": Handling record " << fPilotindex << endl;
00079 
00080     PilotRecord *record = vccb->readRecordByIndex( fPilotindex );
00081     
00082     if( record )
00083     {
00084         KCal::Incidence *i = vccb->incidenceFromRecord( record );
00085         fCalendar.addIncidence( i );
00086     
00087         KPILOT_DELETE(record);
00088     
00089         // Schedule more work.
00090         ++fPilotindex;
00091     }
00092     else
00093     {
00094         vccb->setHasNextRecord( false );
00095     }
00096 }
00097 
00098 void TestState::finishSync( ConduitAction *ca )
00099 {
00100     FUNCTIONSETUP;
00101     
00102     VCalConduitBase *vccb = dynamic_cast<VCalConduitBase*>(ca);
00103     if( !vccb )
00104     {
00105         return;
00106     }
00107 
00108     DEBUGKPILOT << fname << ": finishing teststate." << endl;
00109 
00110     // No more records present on the device so lets dump the
00111     // readed records in a file.
00112     QFile f( CSL1("dump.ics") );
00113     if( !f.exists() )
00114     {
00115         f.open( IO_WriteOnly );
00116         f.close();
00117     }
00118 
00119     if( !fCalendar.save( CSL1("dump.ics") ) )
00120     {
00121         DEBUGKPILOT << fname << ": Can't save calendar file." << endl;
00122     }
00123 
00124     fCalendar.close();
00125 
00126     vccb->setState( 0L );
00127 }