~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/time/timeengine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2007 Aaron Seigo <aseigo@kde.org>
 
3
 *   Copyright 2008 Alex Merry <alex.merry@kdemail.net>
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU Library General Public License as
 
7
 *   published by the Free Software Foundation; either version 2 or
 
8
 *   (at your option) any later version.
 
9
 *
 
10
 *   This program is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *   GNU General Public License for more details
 
14
 *
 
15
 *   You should have received a copy of the GNU Library General Public
 
16
 *   License along with this program; if not, write to the
 
17
 *   Free Software Foundation, Inc.,
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "timeengine.h"
 
22
 
 
23
#include <QDate>
 
24
#include <QDBusConnection>
 
25
#include <QStringList>
 
26
#include <QTime>
 
27
 
 
28
#include <KLocale>
 
29
#include <KSystemTimeZones>
 
30
#include <KDateTime>
 
31
 
 
32
#include "timesource.h"
 
33
 
 
34
//timezone is defined in msvc
 
35
#ifdef timezone
 
36
#undef timezone
 
37
#endif
 
38
 
 
39
TimeEngine::TimeEngine(QObject *parent, const QVariantList &args)
 
40
    : Plasma::DataEngine(parent, args)
 
41
{
 
42
    Q_UNUSED(args)
 
43
    setMinimumPollingInterval(333);
 
44
 
 
45
    // To have translated timezone names
 
46
    // (effectively a noop if the catalog is already present).
 
47
    KGlobal::locale()->insertCatalog("timezones4");
 
48
}
 
49
 
 
50
TimeEngine::~TimeEngine()
 
51
{
 
52
}
 
53
 
 
54
void TimeEngine::init()
 
55
{
 
56
    //QDBusInterface *ktimezoned = new QDBusInterface("org.kde.kded", "/modules/ktimezoned", "org.kde.KTimeZoned");
 
57
    QDBusConnection dbus = QDBusConnection::sessionBus();
 
58
    dbus.connect(QString(), QString(), "org.kde.KTimeZoned", "configChanged", this, SLOT(tzConfigChanged()));
 
59
    dbus.connect("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "resumingFromSuspend", this, SLOT(clockSkewed()));
 
60
}
 
61
 
 
62
void TimeEngine::clockSkewed()
 
63
{
 
64
    kDebug() << "Time engine Clock skew signaled";
 
65
    updateAllSources();
 
66
    forceImmediateUpdateOfAllVisualizations();
 
67
}
 
68
 
 
69
void TimeEngine::tzConfigChanged()
 
70
{
 
71
    TimeSource *s = qobject_cast<TimeSource *>(containerForSource("Local"));
 
72
 
 
73
    if (s) {
 
74
        s->setTimeZone("Local");
 
75
    }
 
76
 
 
77
    updateAllSources();
 
78
}
 
79
 
 
80
QStringList TimeEngine::sources() const
 
81
{
 
82
    QStringList timezones(KSystemTimeZones::zones().keys());
 
83
    timezones << "Local";
 
84
    return timezones;
 
85
}
 
86
 
 
87
bool TimeEngine::sourceRequestEvent(const QString &name)
 
88
{
 
89
    addSource(new TimeSource(name, this));
 
90
    return true;
 
91
}
 
92
 
 
93
bool TimeEngine::updateSourceEvent(const QString &tz)
 
94
{
 
95
    TimeSource *s = qobject_cast<TimeSource *>(containerForSource(tz));
 
96
 
 
97
    if (s) {
 
98
        s->updateTime();
 
99
        scheduleSourcesUpdated();
 
100
        return true;
 
101
    }
 
102
 
 
103
    return false;
 
104
}
 
105
 
 
106
K_EXPORT_PLASMA_DATAENGINE(time, TimeEngine)
 
107
 
 
108
#include "timeengine.moc"