Esempio n. 1
0
void KSystemTimeZonesPrivate::setLocalZone()
{
    QString filename;
    if (m_localZoneName.startsWith(QLatin1Char('/'))) {
        // The time zone is specified by a file outside the zoneinfo directory
        filename = m_localZoneName;
    } else {
        // The zone name is either a known zone, or it's a relative file name
        // in zoneinfo directory which isn't in zone.tab.
        m_localZone = m_instance->zone(m_localZoneName);
        if (m_localZone.isValid())
            return;
        // It's a relative file name
        filename = m_zoneinfoDir + QLatin1Char('/') + m_localZoneName;
    }

    // Parse the specified time zone data file
    QString zonename = filename;
    if (zonename.startsWith(m_zoneinfoDir + QLatin1Char('/')))
        zonename = zonename.mid(m_zoneinfoDir.length() + 1);
    m_localZone = KTzfileTimeZone(KSystemTimeZonesPrivate::tzfileSource(), zonename);
    if (m_localZone.isValid() && m_instance)
    {
        // Add the new time zone to the list
        const KTimeZone oldzone = m_instance->zone(zonename);
        if (!oldzone.isValid() || oldzone.type() != "KTzfileTimeZone")
        {
            m_instance->remove(oldzone);
            m_instance->add(m_localZone);
        }
    }
}
Esempio n. 2
0
void KSystemTimeZonesPrivate::setLocalZone()
{
    if (m_localZoneName.startsWith('/'))
    {
        // The time zone is specified by a file outside the zoneinfo directory
        m_localZone = KTzfileTimeZone(KSystemTimeZonesPrivate::tzfileSource(), m_localZoneName);
        if (m_localZone.isValid() && m_instance)
        {
            // Add the new time zone to the list
            KTimeZone oldzone = m_instance->zone(m_localZoneName);
            if (!oldzone.isValid() || oldzone.type() != "KTzfileTimeZone")
            {
                m_instance->remove(oldzone);
                m_instance->add(m_localZone);
            }
        }
    }
    else
        m_localZone = m_instance->zone(m_localZoneName);
}
Esempio n. 3
0
// 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;
}
Esempio n. 4
0
// 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;
}