Plasma
timeengine.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "timeengine.h"
00021
00022 #include <QDate>
00023 #include <QStringList>
00024 #include <QTime>
00025 #include <QTimer>
00026
00027 #include <KDebug>
00028 #include <KLocale>
00029 #include <KSystemTimeZones>
00030 #include <KDateTime>
00031
00032 #include "plasma/datacontainer.h"
00033
00034 TimeEngine::TimeEngine(QObject* parent, const QVariantList& args)
00035 : Plasma::DataEngine(parent, args)
00036 {
00037 Q_UNUSED(args)
00038 setMinimumPollingInterval(333);
00039
00040
00041
00042 KGlobal::locale()->insertCatalog("timezones4");
00043 }
00044
00045 TimeEngine::~TimeEngine()
00046 {
00047 }
00048
00049 bool TimeEngine::sourceRequestEvent(const QString &name)
00050 {
00051
00052 return updateSourceEvent(name);
00053 }
00054
00055 bool TimeEngine::updateSourceEvent(const QString &tz)
00056 {
00057
00058
00059 QString timezone;
00060
00061 static const QString localName = I18N_NOOP("Local");
00062 if (tz == localName) {
00063 setData(localName, I18N_NOOP("Time"), QTime::currentTime());
00064 setData(localName, I18N_NOOP("Date"), QDate::currentDate());
00065
00066 timezone = KSystemTimeZones::local().name();
00067 } else {
00068 KTimeZone newTz = KSystemTimeZones::zone(tz);
00069 if (!newTz.isValid()) {
00070 return false;
00071 }
00072
00073 KDateTime dt = KDateTime::currentDateTime(newTz);
00074 setData(tz, I18N_NOOP("Time"), dt.time());
00075 setData(tz, I18N_NOOP("Date"), dt.date());
00076 timezone = tz;
00077 }
00078
00079 QString trTimezone = i18n(timezone.toUtf8());
00080 setData(tz, I18N_NOOP("Timezone"), trTimezone);
00081 QStringList tzParts = trTimezone.split("/");
00082
00083 setData(tz, I18N_NOOP("Timezone Continent"), tzParts.value(0));
00084 setData(tz, I18N_NOOP("Timezone City"), tzParts.value(1));
00085
00086 return true;
00087 }
00088
00089 #include "timeengine.moc"