• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

timeengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2008 Alex Merry <alex.merry@kdemail.net>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2 or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 //timezone is defined in msvc
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     // To have translated timezone names
00044     // (effectively a noop if the catalog is already present).
00045     KGlobal::locale()->insertCatalog("timezones4");
00046 }
00047 
00048 void TimeEngine::init()
00049 {
00050     //QDBusInterface *ktimezoned = new QDBusInterface("org.kde.kded", "/modules/ktimezoned", "org.kde.KTimeZoned");
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         // this is relatively cheap - KSTZ::local() is cached
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"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal