QVariant TimezoneModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) { const QTimeZone tz(m_ids.at(index.row())); switch (index.column()) { case TimezoneModelColumns::IanaIdColumn: return tz.id(); case TimezoneModelColumns::CountryColumn: return QLocale::countryToString(tz.country()); case TimezoneModelColumns::StandardDisplayNameColumn: return tz.displayName(QTimeZone::StandardTime); case TimezoneModelColumns::DSTColumn: return tz.hasDaylightTime(); case TimezoneModelColumns::WindowsIdColumn: return QTimeZone::ianaIdToWindowsId(tz.id()); } } else if (role == Qt::ToolTipRole && index.column() == 0) { const QTimeZone tz(m_ids.at(index.row())); return tz.comment(); } else if (role == TimezoneModelRoles::LocalZoneRole && index.column() == 0) { if (m_ids.at(index.row()) == QTimeZone::systemTimeZoneId()) return true; return QVariant(); } return QVariant(); }
QDateTime GoogleCalHandler::parseDateTime(const QString &time, const QTimeZone &destZone) { QDateTime result; // format year-month-dayThour:min:sec... we skip the rest, assuming is part of timezone. QTimeZone sourceZone = parseTimeZone(time); int year = time.mid(0,4).toInt(); int month = time.mid(5,2).toInt(); int day = time.mid(8,2).toInt(); result.setDate(QDate(year, month, day)); if (time.length() >= 19) { int hour = time.mid(11,2).toInt(); int minute = time.mid(14,2).toInt(); int second = time.mid(17,2).toInt(); result.setTime(QTime(hour, minute, second)); } if (destZone.isValid() && sourceZone.isValid()) return destZone.convert(result, sourceZone); return result; }
static QDateTime fromTimeZone(const QDateTime &dt, const QTimeZone &timeZone) { Q_ASSERT(dt.timeSpec() == Qt::LocalTime); QDateTime result(dt); if (timeZone.isValid()) { result.setTimeZone(timeZone); result = result.toLocalTime(); } return result; }
void WorldTime::slotNewTz( const QTimeZone& zone ) { if( Qtopia::mousePreferred()) { changed = true; return; } QTimeZone curZone; int selButton = findCurrentButton(); if(selButton > -1 ) { strCityTz[selButton] = zone.id(); // qWarning()<< "slotNewTz"<<strCityTz[selButton]; listCities.at(selButton)->setText( zone.city()); listTimes.at(selButton)->setZone( zone.id()); if( !isEditMode) { changed = true; } } }
void WorldTime::selected() { if(!changed) { changed = true; } else { QTimeZone zone = frmMap->zone(); int selButton = findCurrentButton(); if(selButton != -1 ) { strCityTz[selButton] = zone.id(); // qWarning() << "selected" << strCityTz[selButton] << zone.id(); listCities.at(selButton)->setText( zone.city()); listTimes.at(selButton)->setZone( zone.id()); saveChanges(); changed = false; } viewMode(); } }
void InputRoku::handleQueryDeviceInfo(QHttpRequest* request, QHttpResponse* response) { QByteArray data; QXmlStreamWriter writer(&data); writer.setAutoFormatting(true); writer.writeStartDocument(); writer.writeStartElement("device-info"); writer.writeTextElement("udn", Utils::ClientUUID()); writer.writeTextElement("serial-number", ROKU_SERIAL_NUMBER); writer.writeTextElement("device-id", ROKU_SERIAL_NUMBER); writer.writeTextElement("vendor-name", "Roku"); writer.writeTextElement("model-number", "4200X"); writer.writeTextElement("model-name", "Roku 3"); writer.writeTextElement("wifi-mac", "00:00:00:00:00:00"); writer.writeTextElement("ethernet-mac", "00:00:00:00:00:00"); writer.writeTextElement("network-type", "ethernet"); writer.writeTextElement("user-device-name", Utils::ComputerName()); writer.writeTextElement("software-version", "7.00"); writer.writeTextElement("software-build", "09021"); QLocale locale = QLocale::system(); QString lcl = locale.name(); QStringList landc = lcl.split("_"); writer.writeTextElement("language", landc.value(0)); writer.writeTextElement("country", landc.value(1)); writer.writeTextElement("locale", locale.name()); QTimeZone tz = QTimeZone::systemTimeZone(); writer.writeTextElement("time-zone", tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName)); writer.writeTextElement("time-zone-offset", QString::number(tz.offsetFromUtc(QDateTime::currentDateTime()) / 60)); writer.writeEndElement(); // device-info writer.writeEndDocument(); response->setStatusCode(qhttp::ESTATUS_OK); response->write(data); response->end(); }
void TimeDateModule::updateFields() { if ( m_timeDate->canNtp() ) ui->isNtpEnabledCheckBox->setChecked( m_timeDate->isNtpEnabled() ); else { ui->isNtpEnabledCheckBox->setChecked( false ); ui->isNtpEnabledCheckBox->setEnabled( false ); } ui->isRtcLocalCheckBox->setChecked( m_timeDate->isRtcInLocalTimeZone() ); QTimeZone timeZone = QTimeZone( m_timeZone.toLatin1() ); if ( timeZone.isValid() ) { ui->timeZoneLabel_2->setText( m_timeZone ); ui->countryLabel_2->setText( QLocale::countryToString( timeZone.country() ) ); QIcon yesIcon = QIcon(); yesIcon.addFile( ":/images/yes.svg", QSize( 16, 16 ) ); QIcon noIcon = QIcon(); noIcon.addFile( ":/images/no.svg", QSize( 16, 16 ) ); if ( timeZone.hasDaylightTime() ) ui->hasDaylightTimeIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) ); else ui->hasDaylightTimeIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) ); if ( timeZone.isDaylightTime( QDateTime::currentDateTime() ) ) ui->isDaylightTimeIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) ); else ui->isDaylightTimeIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) ); if ( timeZone.hasTransitions() ) ui->hasTransitionsIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) ); else ui->hasTransitionsIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) ); QTimeZone::OffsetData offset = timeZone.nextTransition( QDateTime::currentDateTime() ); if ( offset.atUtc != QDateTime() ) { ui->nextTransitionLabel->setEnabled( true ); ui->nextTransitionTimeLabel->setEnabled( true ); ui->nextTransitionTimeLabel->setText( offset.atUtc.toString( "dddd yyyy-MM-dd HH:mm:ss" ) ); } else { ui->nextTransitionLabel->setEnabled( false ); ui->nextTransitionTimeLabel->setEnabled( false ); ui->nextTransitionTimeLabel->setText( tr( "none" ) ); } } }
void Schedule::addEvent(const QDate& startDate, const QTime& startTime, const QString& subject, const QString& location, const QTimeZone& timeZone) { Event event; event.subject = subject; event.location = location; event.startTime = QDateTime(startDate, startTime); if (timeZone.isValid()) event.startTime.setTimeZone(timeZone); events_.insert(startDate, event); }
DateTime DateTime::fromString( const QString &dts, const QTimeZone &timeZone ) { if (dts.isEmpty()) { return DateTime(); } QDateTime dt = QDateTime::fromString(dts, Qt::ISODate); if ( ! dt.isValid() ) { // try to parse in qt default format (used in early version) dt = QDateTime::fromString(dts, Qt::TextDate); if (timeZone.isValid()) { dt.setTimeZone(timeZone); } return DateTime(dt); } return DateTime(dt); }
QString LXQtWorldClock::preformat(const QString &format, const QTimeZone &timeZone, const QDateTime &dateTime) { QString result = format; int from = 0; for (;;) { int apos = result.indexOf(QLatin1Char('\''), from); int tz = result.indexOf(QLatin1Char('T'), from); if ((apos != -1) && (tz != -1)) { if (apos > tz) apos = -1; else tz = -1; } if (apos != -1) { from = apos + 1; apos = result.indexOf(QLatin1Char('\''), from); if (apos == -1) // misformat break; from = apos + 1; } else if (tz != -1) { int length = 1; for (; result[tz + length] == QLatin1Char('T'); ++length); if (length > 6) length = 6; QString replacement; switch (length) { case 1: replacement = timeZone.displayName(dateTime, QTimeZone::OffsetName); if (replacement.startsWith(QLatin1String("UTC"))) replacement = replacement.mid(3); break; case 2: replacement = QString::fromLatin1(timeZone.id()); break; case 3: replacement = timeZone.abbreviation(dateTime); break; case 4: replacement = timeZone.displayName(dateTime, QTimeZone::ShortName); break; case 5: replacement = timeZone.displayName(dateTime, QTimeZone::LongName); break; case 6: replacement = mTimeZoneCustomNames[QString::fromLatin1(timeZone.id())]; } if ((tz > 0) && (result[tz - 1] == QLatin1Char('\''))) { --tz; ++length; } else replacement.prepend(QLatin1Char('\'')); if (result[tz + length] == QLatin1Char('\'')) ++length; else replacement.append(QLatin1Char('\'')); result.replace(tz, length, replacement); from = tz + replacement.length(); } else break; } return result; }
#include <QCoreApplication> #include <QtCore/QCoreApplication> #include <QtCore/QCommandLineParser> #include <QtCore/QCommandLineOption> #include <QtSql> #include <QtSerialPort> #include <QtSerialPort/QSerialPortInfo> #include <unistd.h> #include <stdlib.h> #include "../SupportRoutines/supportfunctions.h" #include "messages.h" /* ******** Global variable declarations ***************/ QTimeZone LocalTimeZone = QTimeZone(QTimeZone::systemTimeZoneId()); //!< The local timezone, either Standard time or Daylight time. QTimeZone LocalStandardTimeZone = QTimeZone(LocalTimeZone.standardTimeOffset(QDateTime::currentDateTime())); //!< Timezone for Local Standard time. /* ******** Global function declarations ***************/ bool ConnectSerial(const QString &serialDeviceName, QSerialPort **serialPortPtr); bool SaveV3ResponseToDatabase(const ResponseV3Data &responseData); bool SaveV4ResponseToDatabase(const uint8_t responseType, const ResponseV4Generic &response); bool GetMeterV4Data(QSerialPort *serialPort, const QString meterId, const uint8_t requestType, ResponseV4Generic *response); bool GetMeterV3Data(QSerialPort *serialPort, const QString meterId, ResponseV3Data *response); bool ReadResponse(QSerialPort *serialPort, qint8 *msg, const qint64 msgSize); bool WriteSerialMsg(QSerialPort *serialPort, const char *msg, const qint64 msgSize); bool ValidateCRC(const uint8_t *msg, int numBytes); bool SendControl(QSerialPort *serialPort, QString &meterId, OutputControlDef *ctrlMsg, const int msgSize); bool SetMeterTime(QSerialPort *serialPort, QString &meterId); bool InitializeMeters(QSerialPort *serialPort, const QStringList &args);
void TimeAxis::setTimeZone(QTimeZone& newtz) { newtz.swap(this->tz); QString newlabel = TimeAxis::labelformat.arg(this->tz.displayName(QTimeZone::GenericTime)); this->label.setText(newlabel); }
/*! \internal */ void QWorldmapDialog::selected( const QTimeZone& zone ) { if (zone.isValid()) { mZone = zone; } }
DateTime::DateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone) : QDateTime( timeZone.isValid() ? QDateTime(date, time, timeZone).toLocalTime() : QDateTime(date, time, Qt::LocalTime) ) { }
QString TClockForm::formatTimeZone(const QTimeZone &timeZone) { return timeZone.id(); }
QString TimeZone::TimeZone::readAllCities() { // get translation list QString lines = cityTranslations(); QSettings settings; int sortOrder = settings.value("sortorder_completeList", "").toInt(); QList<QByteArray> ids = QTimeZone::availableTimeZoneIds(); QString output; QString sign; QString timeoffset; QMultiMap<int, QString> map; QMultiMap<QString, QString> sorted_map; // QMultiMap is sorted by key by default // We use QMultiMap (not QMap) so we can have duplicates int dummy_counter_for_sort = 0; // to inverse reverted sorting foreach (QByteArray id, ids) { QTimeZone zone = QTimeZone(id); QDateTime zoneTime = QDateTime(QDate::currentDate(), QTime::currentTime(), zone).toLocalTime(); int offset = zone.offsetFromUtc(QDateTime::currentDateTime()); QString countryName = QLocale::countryToString(zone.country()); QString countryNameOrg = countryName; // insert space where appropriate. Can't be done in one regex replace? QRegularExpression rx("([a-z])([A-Z])"); QRegularExpressionMatch match = rx.match(countryName); for (int i = 1; i <= 6; i++) { match = rx.match(countryName); if (match.hasMatch()) { QString lowerChar1 = match.captured(1); QString upperChar1 = match.captured(2); countryName.replace(lowerChar1+upperChar1,lowerChar1 + " " + upperChar1); } } int index = lines.indexOf('\n'+countryName+';', 0, Qt::CaseInsensitive); if (index != -1) { index++; // Replace countryName with translation countryName = lines.mid(index+countryName.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1); } if ( countryName == "Default") { // UTC name countryName = ""; } else { countryName = " [" + countryName + "]"; } if (offset < 0) sign = "-"; else sign = "+"; if((offset % 3600)==0) // offset equals to whole hour timeoffset = QString("UTC %3").arg(sign+QString::number(abs(offset)/3600)); else { int minutes = offset/60 %60; timeoffset = QString("UTC %3:%4").arg(sign+QString::number(abs(offset)/3600)).arg(abs(minutes)); } const int delimiter = id.lastIndexOf('/'); int nbrSlashes = id.count("/"); QString cityNameTr = id.mid(delimiter + 1).replace("_"," "); QString continentTr = id.mid(0, delimiter); QString stateTr = ""; if ( nbrSlashes == 2) { // eg (America/North Dakota/Beulah) continentTr = id.mid(0, id.indexOf('/')); //first part stateTr = id.mid(id.indexOf('/')+1, delimiter - continentTr.length() - 1 ); //second part } if (!lines.isEmpty()) { int index = lines.indexOf(cityNameTr+';', 0, Qt::CaseInsensitive); if (index != -1) { cityNameTr = lines.mid(index+cityNameTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1); } index = lines.indexOf(continentTr+';', 0, Qt::CaseInsensitive); if (index != -1) { continentTr = lines.mid(index+continentTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1); } if (!stateTr.isEmpty()) { index = lines.indexOf(stateTr+';', 0, Qt::CaseInsensitive); if (index != -1) { stateTr = lines.mid(index+stateTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1); } continentTr = continentTr + "/" + stateTr; } } if (sortOrder == 1) { dummy_counter_for_sort ++; map.insert(offset + dummy_counter_for_sort,timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg); } else if (sortOrder == 2) { sorted_map.insert(cityNameTr, timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg); } else if (sortOrder == 3) { sorted_map.insert(countryName, timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg); } else { output += timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + + ";" + countryNameOrg + "\n"; } }
QSXE_APP_KEY #include "qtopiaserverapplication.h" #include <QDesktopWidget> #include <QLibraryInfo> #include <sys/types.h> #include <unistd.h> #include <QValueSpaceItem> #include <QKeyEvent> #include <ThemedView> // Not currently supported, available for demonstration purposes. //#define QTOPIA_ANIMATED_SPLASH static void refreshTimeZoneConfig() { // We need to help WorldTime in setting up its configuration for // the current translation // BEGIN no tr const char *defaultTz[] = { "America/New_York", "Asia/Beijing", "America/Los_Angeles", "Europe/London", "Asia/Tokyo", "Europe/Paris", 0 }; // END no tr QTimeZone curZone; QString zoneID; int zoneIndex; QSettings cfg( "Trolltech", "WorldTime" ); cfg.beginGroup( "TimeZones" ); if (!cfg.contains( "Zone0" )){ // We have no existing timezones - use the defaults that are untranslated strings QString currTz = QTimeZone::current().id(); QStringList zoneDefaults; zoneDefaults.append( currTz ); for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { if ( defaultTz[i] != currTz ) zoneDefaults.append( defaultTz[i] ); } zoneIndex = 0; for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ cfg.setValue( "Zone" + QString::number( zoneIndex ) , *it); zoneIndex++; } } // We have an existing list of timezones - refresh the // translations of QTimeZone name zoneIndex = 0; while (cfg.contains( "Zone"+ QString::number( zoneIndex ))){ zoneID = cfg.value( "Zone" + QString::number( zoneIndex )).toString(); curZone = QTimeZone( zoneID.toLatin1() ); if ( !curZone.isValid() ){ qWarning( "initEnvironment() Invalid QTimeZone %s", (const char *)zoneID.toLatin1() ); break; } zoneIndex++; } }