diff options
author | Fritz Elfert <felfert@to.com> | 2001-02-02 06:33:42 +0000 |
---|---|---|
committer | Fritz Elfert <felfert@to.com> | 2001-02-02 06:33:42 +0000 |
commit | f1840173ca21b3668c25b3fdec73f9bbcbb8cb12 (patch) | |
tree | f780e4afd9d7ab7c51ad1d98a4b6789827a8350e | |
parent | 9fac7af37460c6a73a7debac1ba82b094a8f066c (diff) | |
download | plptools-f1840173ca21b3668c25b3fdec73f9bbcbb8cb12.tar.gz plptools-f1840173ca21b3668c25b3fdec73f9bbcbb8cb12.tar.bz2 plptools-f1840173ca21b3668c25b3fdec73f9bbcbb8cb12.zip |
Added automatic initialization of the timezone info in PsTime.
-rw-r--r-- | kde2/kioslave/kio_plp.cpp | 21 | ||||
-rw-r--r-- | kde2/kioslave/kio_plp.h | 3 | ||||
-rw-r--r-- | lib/psitime.cc | 45 | ||||
-rw-r--r-- | lib/psitime.h | 26 | ||||
-rw-r--r-- | lib/rpcs32.cc | 2 |
5 files changed, 95 insertions, 2 deletions
diff --git a/kde2/kioslave/kio_plp.cpp b/kde2/kioslave/kio_plp.cpp index 4e7dbf0..72b1060 100644 --- a/kde2/kioslave/kio_plp.cpp +++ b/kde2/kioslave/kio_plp.cpp @@ -37,6 +37,7 @@ #include <kconfig.h> #include <rfsvfactory.h> +#include <rpcsfactory.h> #include <bufferarray.h> #include <string> @@ -226,6 +227,26 @@ openConnection() { error(ERR_COULD_NOT_CONNECT, i18n("Could not read version info")); return; } + + /* If we have a S5, get the Psion's Owner- and Mach- info. + * This implicitely sets the Timezone info of the Psion also. + */ + + ppsocket rpcsSocket; + if (rpcsSocket.connect((char *)(currentHost.data()), currentPort)) { + rpcsfactory factory(&rpcsSocket); + rpcs *Rpcs = factory.create(false); + if (Rpcs != 0L) { + bufferArray b; + Enum <rfsv::errs> res; + if ((res = Rpcs->getOwnerInfo(b)) == rfsv::E_PSI_GEN_NONE) { + Rpcs->getMachineType(machType); + if (machType == rpcs::PSI_MACH_S5) + Rpcs->getMachineInfo(mi); + } + } + } + long devbits; Enum<rfsv::errs> res; diff --git a/kde2/kioslave/kio_plp.h b/kde2/kioslave/kio_plp.h index 49176f0..c17436e 100644 --- a/kde2/kioslave/kio_plp.h +++ b/kde2/kioslave/kio_plp.h @@ -26,6 +26,7 @@ #include <qstringlist.h> #include <qmap.h> #include <rfsv.h> +#include <rpcs.h> #include <ppsocket.h> typedef QMap<PlpUID,QString> UidMap; @@ -77,6 +78,8 @@ private: int currentPort; time_t t_last; time_t t_start; + Enum<rpcs::machs> machType; + rpcs::machineInfo mi; }; #endif diff --git a/lib/psitime.cc b/lib/psitime.cc index bb4ea78..d79ca80 100644 --- a/lib/psitime.cc +++ b/lib/psitime.cc @@ -4,6 +4,7 @@ PsiTime::PsiTime(void) { ptzValid = false; + tryPsiZone(); setUnixNow(); } @@ -19,8 +20,10 @@ PsiTime::PsiTime(psi_timeval *_ptv, psi_timezone *_ptz) { if (_ptz != 0L) { ptz = *_ptz; ptzValid = true; - } else + } else { ptzValid = false; + tryPsiZone(); + } /* get our own timezone */ gettimeofday(NULL, &utz); psi2unix(); @@ -30,6 +33,7 @@ PsiTime::PsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo) { ptv.tv_high = _ptvHi; ptv.tv_low = _ptvLo; ptzValid = false; + tryPsiZone(); /* get our own timezone */ gettimeofday(NULL, &utz); psi2unix(); @@ -40,6 +44,7 @@ PsiTime::PsiTime(struct timeval *_utv = 0L, struct timezone *_utz = 0L) { utv = *_utv; if (_utz != 0L) utz = *_utz; + tryPsiZone(); unix2psi(); } @@ -49,9 +54,11 @@ PsiTime::PsiTime(const PsiTime &t) { ptv = t.ptv; ptz = t.ptz; ptzValid = t.ptzValid; + tryPsiZone(); } PsiTime::~PsiTime() { + tryPsiZone(); } void PsiTime::setUnixTime(struct timeval *_utv) { @@ -118,6 +125,7 @@ PsiTime &PsiTime::operator=(const PsiTime &t) { ptv = t.ptv; ptz = t.ptz; ptzValid = t.ptzValid; + tryPsiZone(); return *this; } @@ -143,7 +151,7 @@ evalOffset(psi_timezone ptz, time_t time, bool valid) { if (valid) { offset = ptz.utc_offset; - if ((ptz.dst_zones & 0x40000000) || (ptz.dst_zones & ptz.home_zone)) + if (!(ptz.dst_zones & 0x40000000) || (ptz.dst_zones & ptz.home_zone)) offset += 3600; } else { /** @@ -196,3 +204,36 @@ void PsiTime::unix2psi(void) { ptv.tv_low = micro & 0x0ffffffff; ptv.tv_high = (micro >> 32) & 0x0ffffffff; } + +void PsiTime::tryPsiZone() { + if (ptzValid) + return; + if (PsiZone::getInstance().getZone(ptz)) + ptzValid = true; +} + +PsiZone *PsiZone::_instance = 0L; + +PsiZone &PsiZone:: +getInstance() { + if (_instance == 0L) + _instance = new PsiZone(); + return *_instance; +} + +PsiZone::PsiZone() { + _ptzValid = false; +} + +void PsiZone:: +setZone(psi_timezone &ptz) { + _ptz = ptz; + _ptzValid = true; +} + +bool PsiZone:: +getZone(psi_timezone &ptz) { + if (_ptzValid) + ptz = _ptz; + return _ptzValid; +} diff --git a/lib/psitime.h b/lib/psitime.h index 7072711..74d05af 100644 --- a/lib/psitime.h +++ b/lib/psitime.h @@ -252,6 +252,7 @@ public: private: void psi2unix(void); void unix2psi(void); + void tryPsiZone(); psi_timeval ptv; psi_timezone ptz; @@ -259,4 +260,29 @@ private: struct timezone utz; bool ptzValid; }; + +class PsiZone { + friend class rpcs32; + +public: + static PsiZone &getInstance(); + + bool getZone(psi_timezone &ptz); + +private: + /** + * This objects instance (singleton) + */ + static PsiZone *_instance; + + /** + * Private constructor. + */ + PsiZone(); + + void setZone(psi_timezone &ptz); + + bool _ptzValid; + psi_timezone _ptz; +}; #endif diff --git a/lib/rpcs32.cc b/lib/rpcs32.cc index 7a7982f..772dea6 100644 --- a/lib/rpcs32.cc +++ b/lib/rpcs32.cc @@ -146,6 +146,8 @@ getMachineInfo(machineInfo &mi) mi.tz.dst_zones = a.getDWord(64); mi.tz.home_zone = a.getDWord(68); + PsiZone::getInstance().setZone(mi.tz); + mi.mainBatteryInsertionTime.tv_low = a.getDWord(72); mi.mainBatteryInsertionTime.tv_high = a.getDWord(76); mi.mainBatteryStatus = (enum rpcs::batterystates)a.getDWord(80); |