• Skip to content
  • Skip to link menu
KDE 4.1 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  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2 or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     // To have translated timezone names
00041     // (effectively a noop if the catalog is already present).
00042     KGlobal::locale()->insertCatalog("timezones4");
00043 }
00044 
00045 TimeEngine::~TimeEngine()
00046 {
00047 }
00048 
00049 bool TimeEngine::sourceRequestEvent(const QString &name)
00050 {
00051     //kDebug() << "TimeEngine::sourceRequested " << name;
00052     return updateSourceEvent(name);
00053 }
00054 
00055 bool TimeEngine::updateSourceEvent(const QString &tz)
00056 {
00057     //kDebug() << "TimeEngine::updateTime()";
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         // this is relatively cheap - KSTZ::local() is cached
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"

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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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