From f1840173ca21b3668c25b3fdec73f9bbcbb8cb12 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Fri, 2 Feb 2001 06:33:42 +0000 Subject: Added automatic initialization of the timezone info in PsTime. --- kde2/kioslave/kio_plp.cpp | 21 +++++++++++++++++++++ kde2/kioslave/kio_plp.h | 3 +++ lib/psitime.cc | 45 +++++++++++++++++++++++++++++++++++++++++++-- lib/psitime.h | 26 ++++++++++++++++++++++++++ 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 #include +#include #include #include @@ -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 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 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 #include #include +#include #include typedef QMap UidMap; @@ -77,6 +78,8 @@ private: int currentPort; time_t t_last; time_t t_start; + Enum 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); -- cgit v1.2.3