2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Renato Araujo Oliveira Filho <renato@canonical.com>
18
* Ubo Riboni <ugo.riboni@canonical.com>
21
#include "chewie_datetimeplugin.h"
23
#include <qdbusmenumodel.h>
24
#include <qdbusactiongroup.h>
25
#include <qstateaction.h>
29
ChewieDateTimePlugin::ChewieDateTimePlugin(QObject *parent)
30
: ChewieCommonPlugin(parent),
33
connect(&m_timer, SIGNAL(timeout()), SLOT(onTimeout()));
36
ChewieDateTimePlugin::~ChewieDateTimePlugin()
43
void ChewieDateTimePlugin::init(const QJsonObject &config)
45
ChewieCommonPlugin::init(config);
46
m_timer.start(1000 * 10);
49
void ChewieDateTimePlugin::shutdown()
55
QString ChewieDateTimePlugin::dateTime() const
57
static char timestr[255];
67
int size = strftime(timestr, 255, m_format.toUtf8().data(), tmp);
72
return QString::fromLatin1(timestr, size);
75
bool ChewieDateTimePlugin::parseRootElement(const QString &type, QMap<int, QVariant> data)
77
if (type == "com.canonical.indicator.root.time") {
82
QVariant action = data[QDBusMenuModel::Action];
83
m_action = actionGroup()->action(action.toString());
84
if (m_action->isValid()) {
85
updateTimeFormat(m_action->state());
87
QObject::connect(m_action, SIGNAL(stateChanged(QVariant)), this, SLOT(updateTimeFormat(QVariant)));
94
void ChewieDateTimePlugin::updateTimeFormat(const QVariant &state)
96
if (state.isValid()) {
97
// (sssb) : time format, icon, accessible name format, visible
98
QVariantList states = state.toList();
99
if (states.size() == 4) {
100
m_format = states[0].toString();
101
setIcon(QUrl(states[1].toString()));
102
setVisible(states[2].toBool());
103
setAccessibleName(states[3].toString());
109
QQmlComponent *ChewieDateTimePlugin::createComponent(QQmlEngine *engine, QObject *parent) const
111
return new QQmlComponent(engine, QUrl("qrc:/datetimeplugin/qml/ClockPage.qml"), parent);
114
void ChewieDateTimePlugin::onTimeout()
116
QString newValue = dateTime();