time-conduit.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00040
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 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
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
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
00118 }
00119
00120
00121
00122 void TimeConduit::syncPCToPalm()
00123 {
00124 FUNCTIONSETUP;
00125 time_t ltime;
00126 time(<ime);
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
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 }
This file is part of the documentation for kdelibs Version 3.1.4.