Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / dataengines / time / timeengine.cpp
blobb8b9c2b93edafc7a0f4a889879b4ab95bc66a663
1 /*
2 * Copyright 2007 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "timeengine.h"
22 #include <QDate>
23 #include <QStringList>
24 #include <QTime>
25 #include <QTimer>
27 #include <KDebug>
28 #include <KLocale>
29 #include <KSystemTimeZones>
30 #include <KDateTime>
32 #include "plasma/datacontainer.h"
34 TimeEngine::TimeEngine(QObject* parent, const QVariantList& args)
35 : Plasma::DataEngine(parent, args)
37 Q_UNUSED(args)
38 setMinimumUpdateInterval(333);
40 // To have translated timezone names
41 // (effectively a noop if the catalog is already present).
42 KGlobal::locale()->insertCatalog("timezones4");
45 TimeEngine::~TimeEngine()
49 bool TimeEngine::sourceRequested(const QString &name)
51 //kDebug() << "TimeEngine::sourceRequested " << name;
53 return updateSource(name);
56 bool TimeEngine::updateSource(const QString &tz)
58 //kDebug() << "TimeEngine::updateTime()";
60 QString timezone;
62 static const QString localName = I18N_NOOP("Local");
63 if (tz == localName) {
64 setData(localName, I18N_NOOP("Time"), QTime::currentTime());
65 setData(localName, I18N_NOOP("Date"), QDate::currentDate());
66 // this is relatively cheap - KSTZ::local() is cached
67 timezone = KSystemTimeZones::local().name();
68 } else {
69 KTimeZone newTz = KSystemTimeZones::zone(tz);
70 if (!newTz.isValid()) {
71 return false;
74 KDateTime dt = KDateTime::currentDateTime(newTz);
75 setData(tz, I18N_NOOP("Time"), dt.time());
76 setData(tz, I18N_NOOP("Date"), dt.date());
77 timezone = tz;
80 QString trTimezone = i18n(timezone.toUtf8());
81 setData(tz, I18N_NOOP("Timezone"), trTimezone);
82 QStringList tzParts = trTimezone.split("/");
84 setData(tz, I18N_NOOP("Timezone Continent"), tzParts.value(0));
85 setData(tz, I18N_NOOP("Timezone City"), tzParts.value(1));
87 return true;
90 #include "timeengine.moc"