kpilot Library API Documentation

time-conduit.cc

00001 /* time-conduit.cc                           KPilot
00002 **
00003 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00004 **
00005 */
00006 
00007 /*
00008 ** This program is free software; you can redistribute it and/or modify
00009 ** it under the terms of the GNU General Public License as published by
00010 ** the Free Software Foundation; either version 2 of the License, or
00011 ** (at your option) any later version.
00012 **
00013 ** This program is distributed in the hope that it will be useful,
00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016 ** GNU General Public License for more details.
00017 **
00018 ** You should have received a copy of the GNU General Public License
00019 ** along with this program in a file called COPYING; if not, write to
00020 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00021 ** MA 02111-1307, USA.
00022 */
00023 
00024 /*
00025 ** Bug reports and questions can be sent to kde-pim@kde.org.
00026 */
00027 
00028 #include "options.h"
00029 
00030 #include <time.h>
00031 
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034 
00035 #include "time-factory.h"
00036 #include "time-conduit.moc"
00037 
00038 
00039 // Something to allow us to check what revision
00040 // the modules are that make up a binary distribution.
00041 const char *Time_conduit_id =
00042         "$Id: time-conduit.cc,v 1.8.4.4 2003/03/12 23:31:12 adridg Exp $";
00043 
00044 
00045  
00046  
00047 TimeConduit::TimeConduit(KPilotDeviceLink * o,
00048         const char *n, 
00049         const QStringList & a) :
00050         ConduitAction(o, n, a),
00051         fDirection(0)
00052 {
00053         FUNCTIONSETUP;
00054 #ifdef DEBUG
00055         DEBUGCONDUIT<<Time_conduit_id<<endl;
00056 #endif
00057 }
00058 
00059 
00060 
00061 TimeConduit::~TimeConduit()
00062 {
00063         FUNCTIONSETUP;
00064 }
00065 
00066 
00067 
00068 void TimeConduit::readConfig()
00069 {
00070         FUNCTIONSETUP;
00071         KConfigGroupSaver g(fConfig, TimeConduitFactory::group());
00072         fDirection = fConfig->readNumEntry(TimeConduitFactory::direction(),DIR_PCToPalm);
00073 }
00074 
00075 
00076 /* virtual */ bool TimeConduit::exec()
00077 {
00078         FUNCTIONSETUP;
00079 
00080         if (!fConfig)
00081         {
00082                 kdWarning() << k_funcinfo << ": No config file was set!" << endl;
00083                 return false;
00084         }
00085 
00086         readConfig();
00087 
00088         switch (fDirection) 
00089         {
00090                 case DIR_PCToPalm:
00091                         emit logMessage(i18n("Setting the clock on the handheld"));
00092 //                      fHandle->addSyncLogEntry(i18n("Setting the clock on the handheld"));
00093                         syncPCToPalm();
00094                         break;
00095                 case DIR_PalmToPC:
00096                         emit logMessage(i18n("Setting the clock on the PC from the time on the handheld"));
00097 //                      fHandle->addSyncLogEntry(i18n("Setting the clock on the PC from the time on the handheld"));
00098                         syncPalmToPC();
00099                         break;
00100                 default:
00101                         emit logError(i18n("Unknown setting for time synchronization."));
00102                         kdWarning() << k_funcinfo << ": unknown sync direction "<<fDirection<<endl;
00103                         return false;
00104         }
00105         emit syncDone(this);
00106         return true;
00107 }
00108 
00109 void TimeConduit::syncPalmToPC()
00110 {
00111         FUNCTIONSETUP;
00112         QDateTime pdaTime=fHandle->getTime();
00113 #ifdef DEBUG
00114         DEBUGCONDUIT<<fname<<": syncing time "<<pdaTime.toString()<<" to the PC"<<endl;
00115 #endif
00116         emit logError(i18n("The system clock was not adjusted to %1 (not implemented)").arg(pdaTime.toString()));
00117         // TODO: Set the system time from this QDateTime
00118 }
00119 
00120 
00121 
00122 void TimeConduit::syncPCToPalm()
00123 {
00124         FUNCTIONSETUP;
00125         time_t ltime;
00126         time(&ltime);
00127         QDateTime time=QDateTime::currentDateTime();
00128         
00129         long int major=fHandle->majorVersion(), minor=fHandle->minorVersion();
00130         
00131         if (major==3 && (minor==25 || minor==30)) 
00132         {
00133                 emit logMessage(i18n("PalmOS 3.25 and 3.3 do not support setting the system time. Skipping the time conduit..."));
00134                 return;
00135         }
00136 
00137 //      fHandle->setTime(QDateTime::currentDateTime());
00138         fHandle->setTime(ltime);
00139 #ifdef DEBUG
00140         time.setTime_t(ltime);
00141         DEBUGCONDUIT<<fname<<": synced time "<<time.toString()<<" to the handheld"<<endl;
00142 #endif
00143 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:15 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001