void KSystemTimeZonesPrivate::updateTimezoneInformation(bool update) { if (!m_source) m_source = new KSystemTimeZoneSourceWindows; QStringList newZones; Q_FOREACH(const QString & tz, KSystemTimeZoneWindows::listTimeZones()) { // const std::wstring wstr = tz.toStdWString(); // const KTimeZone info = make_time_zone( wstr.c_str() ); KSystemTimeZoneWindows stz(m_source, tz); if (update) { // Update the existing collection with the new zone definition newZones += stz.name(); KTimeZone oldTz = zone(stz.name()); if (oldTz.isValid()) oldTz.updateBase(stz); // the zone previously existed, so update its definition else add(stz); // the zone didn't previously exist, so add it } else add(stz); }
/* * Find the location of the zoneinfo files and store in mZoneinfoDir. * Parse zone.tab and for each time zone, create a KSystemTimeZone instance. */ void KSystemTimeZonesPrivate::readZoneTab(bool update) { kDebug(161) << "readZoneTab(" << m_zonetab<< ")"; QStringList newZones; QFile f; f.setFileName(m_zonetab); if (!f.open(QIODevice::ReadOnly)) return; QTextStream str(&f); QRegExp lineSeparator("[ \t]"); QRegExp ordinateSeparator("[+-]"); if (!m_source) m_source = new KSystemTimeZoneSource; while (!str.atEnd()) { QString line = str.readLine(); if (line.isEmpty() || line[0] == '#') continue; QStringList tokens = KStringHandler::perlSplit(lineSeparator, line, 4); int n = tokens.count(); if (n < 3) { kError(161) << "readZoneTab(): invalid record: " << line << endl; continue; } // Got three tokens. Now check for two ordinates plus first one is "". int i = tokens[1].indexOf(ordinateSeparator, 1); if (i < 0) { kError(161) << "readZoneTab() " << tokens[2] << ": invalid coordinates: " << tokens[1] << endl; continue; } float latitude = convertCoordinate(tokens[1].left(i)); float longitude = convertCoordinate(tokens[1].mid(i)); // Add entry to list. if (tokens[0] == "??") tokens[0] = ""; // Solaris sets the empty Comments field to '-', making it not empty. // Clean it up. if (n > 3 && tokens[3] == "-") tokens[3] = ""; KSystemTimeZone tz(m_source, tokens[2], tokens[0], latitude, longitude, (n > 3 ? tokens[3] : QString())); if (update) { // Update the existing collection with the new zone definition newZones += tz.name(); KTimeZone oldTz = zone(tz.name()); if (oldTz.isValid()) oldTz.updateBase(tz); // the zone previously existed, so update its definition else add(tz); // the zone didn't previously exist, so add it } else add(tz); } f.close(); if (update) { // Remove any zones from the collection which no longer exist const ZoneMap oldZones = zones(); for (ZoneMap::ConstIterator it = oldZones.constBegin(); it != oldZones.constEnd(); ++it) { if (newZones.indexOf(it.key()) < 0) remove(it.value()); } } }