kpilot

time-conduit.cc

Go to the documentation of this file.
00001 /* 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., 51 Franklin Street, Fifth Floor, Boston,
00021 ** MA 02110-1301, 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 <pilotSysInfo.h>
00033 
00034 #include <kconfig.h>
00035 #include <kdebug.h>
00036 
00037 #include "time-factory.h"
00038 #include "time-conduit.h"
00039 #include "timeConduitSettings.h"
00040 
00041 
00042 // Something to allow us to check what revision
00043 // the modules are that make up a binary distribution.
00044 extern "C"
00045 {
00046 unsigned long version_conduit_time = Pilot::PLUGIN_API ;
00047 }
00048 
00049 
00050 
00051 TimeConduit::TimeConduit(KPilotLink * o,
00052     const char *n,
00053     const QStringList & a) :
00054     ConduitAction(o, n, a)
00055 {
00056     FUNCTIONSETUP;
00057     fConduitName=i18n("Time");
00058 }
00059 
00060 
00061 
00062 TimeConduit::~TimeConduit()
00063 {
00064     FUNCTIONSETUP;
00065 }
00066 
00067 
00068 
00069 void TimeConduit::readConfig()
00070 {
00071     FUNCTIONSETUP;
00072     TimeConduitSettings::self()->readConfig();
00073 }
00074 
00075 
00076 /* virtual */ bool TimeConduit::exec()
00077 {
00078     FUNCTIONSETUP;
00079 
00080     readConfig();
00081 
00082     if (syncMode().isLocal())
00083     {
00084 #ifdef DEBUG
00085         DEBUGKPILOT << fname << ": Would have set time to "
00086             << QDateTime::currentDateTime().toString() << endl;
00087 #endif
00088         return delayDone();
00089     }
00090 
00091     emit logMessage(i18n("Setting the clock on the handheld"));
00092     syncHHfromPC();
00093     return delayDone();
00094 }
00095 
00096 
00097 void TimeConduit::syncHHfromPC()
00098 {
00099     FUNCTIONSETUP;
00100     time_t ltime;
00101     time(&ltime);
00102 
00103     long int major=fHandle->getSysInfo().getMajorVersion(), 
00104          minor=fHandle->getSysInfo().getMinorVersion();
00105 
00106     if (major==3 && (minor==25 || minor==30))
00107     {
00108         emit logMessage(i18n("PalmOS 3.25 and 3.3 do not support setting the system time. Skipping the time conduit..."));
00109         return;
00110     }
00111 
00112     int sd = pilotSocket();
00113     if ( sd > 0 )
00114     {
00115         dlp_SetSysDateTime( sd, ltime );
00116     }
00117     else
00118     {
00119         WARNINGKPILOT << "Link is not a real device." << endl;
00120     }
00121 }