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
00021 #include "timeengine.h"
00022
00023 #include <QDate>
00024 #include <QDBusConnection>
00025 #include <QStringList>
00026 #include <QTime>
00027
00028 #include <KLocale>
00029 #include <KSystemTimeZones>
00030 #include <KDateTime>
00031
00032
00033 #ifdef timezone
00034 #undef timezone
00035 #endif
00036
00037 TimeEngine::TimeEngine(QObject *parent, const QVariantList &args)
00038 : Plasma::DataEngine(parent, args)
00039 {
00040 Q_UNUSED(args)
00041 setMinimumPollingInterval(333);
00042
00043
00044
00045 KGlobal::locale()->insertCatalog("timezones4");
00046 }
00047
00048 void TimeEngine::init()
00049 {
00050
00051 QDBusConnection dbus = QDBusConnection::sessionBus();
00052 dbus.connect(QString(), QString(), "org.kde.KTimeZoned", "configChanged", this, SLOT(updateAllSources()));
00053 }
00054
00055 QStringList TimeEngine::sources() const
00056 {
00057 QStringList timezones(KSystemTimeZones::zones().keys());
00058 timezones << "Local";
00059 return timezones;
00060 }
00061
00062 bool TimeEngine::sourceRequestEvent(const QString &name)
00063 {
00064 return updateSourceEvent(name);
00065 }
00066
00067 bool TimeEngine::updateSourceEvent(const QString &tz)
00068 {
00069 QString timezone;
00070
00071 static const QString localName = I18N_NOOP("Local");
00072 if (tz == localName) {
00073 setData(localName, I18N_NOOP("Time"), QTime::currentTime());
00074 setData(localName, I18N_NOOP("Date"), QDate::currentDate());
00075
00076 timezone = KSystemTimeZones::local().name();
00077 } else {
00078 KTimeZone newTz = KSystemTimeZones::zone(tz);
00079 if (!newTz.isValid()) {
00080 return false;
00081 }
00082
00083 KDateTime dt = KDateTime::currentDateTime(newTz);
00084 setData(tz, I18N_NOOP("Time"), dt.time());
00085 setData(tz, I18N_NOOP("Date"), dt.date());
00086 timezone = tz;
00087 }
00088
00089 QString trTimezone = i18n(timezone.toUtf8());
00090 setData(tz, I18N_NOOP("Timezone"), trTimezone);
00091 QStringList tzParts = trTimezone.split("/");
00092
00093 setData(tz, I18N_NOOP("Timezone Continent"), tzParts.value(0));
00094 setData(tz, I18N_NOOP("Timezone City"), tzParts.value(1));
00095
00096 return true;
00097 }
00098
00099
00100 K_EXPORT_PLASMA_DATAENGINE(time, TimeEngine)
00101
00102 #include "timeengine.moc"