void KSystemTimeZonesPrivate::readConfig(bool init) { KConfig config(QLatin1String("ktimezonedrc")); if (!init) config.reparseConfiguration(); KConfigGroup group(&config, "TimeZones"); if (!group.exists()) { kError(161) << "No time zone information obtained from ktimezoned"; m_ktimezonedError = true; } m_zoneinfoDir = group.readEntry("ZoneinfoDir"); m_zonetab = group.readEntry("Zonetab"); m_localZoneName = group.readEntry("LocalZone"); if (m_zoneinfoDir.length() > 1 && m_zoneinfoDir.endsWith(QLatin1Char('/'))) m_zoneinfoDir.truncate(m_zoneinfoDir.length() - 1); // strip trailing '/' if (!init) setLocalZone(); kDebug(161) << "readConfig(): local zone=" << m_localZoneName; }
// Perform initialization, create the unique KSystemTimeZones instance, // whose only function is to receive D-Bus signals from KTimeZoned, // and create the unique KSystemTimeZonesPrivate instance. KSystemTimeZonesPrivate *KSystemTimeZonesPrivate::instance() { if (!m_instance) { m_instance = new KSystemTimeZonesPrivate; // A KSystemTimeZones instance is required only to catch D-Bus signals. m_parent = new KSystemTimeZones; // Ensure that the KDED time zones module has initialized. The call loads the module on demand. if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.kded"))) KToolInvocation::klauncher(); // this calls startKdeinit, and blocks until it returns const QString dbusIface = QString::fromLatin1(KTIMEZONED_DBUS_IFACE); QDBusInterface *ktimezoned = new QDBusInterface(QLatin1String("org.kde.kded"), QLatin1String("/modules/ktimezoned"), dbusIface); QDBusReply<void> reply = ktimezoned->call(QLatin1String("initialize"), false); m_ktimezonedError = !reply.isValid(); if (m_ktimezonedError) kError(161) << "KSystemTimeZones: ktimezoned initialize() D-Bus call failed: " << reply.error().message() << endl; kDebug(161)<<"instance(): ... initialised"; delete ktimezoned; // Read the time zone config written by ktimezoned readConfig(true); // Go read the database. #ifdef Q_OS_WIN // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure. m_instance->updateTimezoneInformation(false); #else // For Unix, read zone.tab. if (!m_zonetab.isEmpty()) m_instance->readZoneTab(false); #endif setLocalZone(); if (!m_localZone.isValid()) m_localZone = KTimeZone::utc(); // ensure a time zone is always returned qAddPostRoutine(KSystemTimeZonesPrivate::cleanup); } return m_instance; }
// Perform initialization, create the unique KSystemTimeZones instance, // whose only function is to receive D-Bus signals from KTimeZoned, // and create the unique KSystemTimeZonesPrivate instance. KSystemTimeZonesPrivate *KSystemTimeZonesPrivate::instance() { if (!m_instance) { m_instance = new KSystemTimeZonesPrivate; #if !defined(TIMED_SUPPORT) && !defined(KCALCORE_FOR_MEEGO) // A KSystemTimeZones instance is required only to catch D-Bus signals. m_parent = new KSystemTimeZones; // Ensure that the KDED time zones module has initialized. The call loads the module on demand. QDBusInterface *ktimezoned = new QDBusInterface("org.kde.kded", "/modules/ktimezoned", KTIMEZONED_DBUS_IFACE); QDBusReply<void> reply = ktimezoned->call("initialize", false); if (!reply.isValid()) kError(161) << "KSystemTimeZones: ktimezoned initialize() D-Bus call failed: " << reply.error().message() << endl; kDebug(161)<<"instance(): ... initialised"; delete ktimezoned; #endif // Read the time zone config written by ktimezoned readConfig(true); // Go read the database. #ifdef Q_OS_WIN // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure. #else // For Unix, read zone.tab. if (!m_zonetab.isEmpty()) m_instance->readZoneTab(false); #endif setLocalZone(); if (!m_localZone.isValid()) { kDebug() << "m_localZone invalid"; m_localZone = KTimeZone::utc(); // ensure a time zone is always returned } qAddPostRoutine(KSystemTimeZonesPrivate::cleanup); } return m_instance; }
void KSystemTimeZonesPrivate::readConfig(bool init) { #ifdef TIMED_SUPPORT m_zoneinfoDir = QLatin1String("/usr/share/zoneinfo"); m_zonetab = QLatin1String("/usr/share/zoneinfo/zone.tab"); Maemo::Timed::Interface timed; QDBusReply<Maemo::Timed::WallClock::Info> reply = timed.get_wall_clock_info_sync(); if (reply.isValid()) { Maemo::Timed::WallClock::Info info = reply.value(); QString localzone = info.etcLocaltime(); kDebug() << "localzone" << localzone; // TODO now we have to parse local timezone from symlink, Ilya will // possibly change this to support previous solution, commented below m_localZoneName = localzone.mid(m_zoneinfoDir.size() + 1); //QFile f("/etc/timezone"); //if (f.open(QIODevice::ReadOnly)) { //QTextStream str(&f); //m_localZoneName = str.readLine(); //f.close(); //} } else { #if !defined(QT_NO_DEBUG_OUTPUT) kError() << "cannot get wall_clock_info (localzone) -" << timed.lastError(); // assumption: running timed is not officially supported in scratcbox, // getting localzone from /etc/timezone kDebug() << "get localzone from /etc/timezone"; #endif QFile f("/etc/timezone"); if (f.open(QIODevice::ReadOnly)) { QTextStream str(&f); m_localZoneName = str.readLine(); f.close(); } } #elif defined(KCALCORE_FOR_MEEGO) m_zoneinfoDir = QLatin1String("/usr/share/zoneinfo"); m_zonetab = QLatin1String("/usr/share/zoneinfo/zone.tab"); QFileInfo info("/etc/localtime"); if (info.isSymLink()) { m_localZoneName = info.symLinkTarget().mid(m_zoneinfoDir.size() + 1); kDebug() << "localzone from /etc/localtime: " << m_localZoneName; } else { #if !defined(QT_NO_DEBUG_OUTPUT) kError() << "cannot get localzone from /etc/localtime"; kDebug() << "get localzone from /etc/timezone"; #endif QFile f("/etc/timezone"); if (f.open(QIODevice::ReadOnly)) { QTextStream str(&f); m_localZoneName = str.readLine(); f.close(); } } #else KConfig config(QLatin1String("ktimezonedrc")); if (!init) config.reparseConfiguration(); KConfigGroup group(&config, "TimeZones"); m_zoneinfoDir = group.readEntry("ZoneinfoDir"); m_zonetab = group.readEntry("Zonetab"); m_localZoneName = group.readEntry("LocalZone"); #endif if (!init) setLocalZone(); kDebug(161) << "readConfig(): local zone=" << m_localZoneName; }