From 0592a405aa68f3baf6773795efa5522e4ee16779 Mon Sep 17 00:00:00 2001 From: "Bocklage, Jens" Date: Wed, 18 Jan 2017 15:25:38 +0100 Subject: Initial source commit Taken from https://gerrit.automotivelinux.org/gerrit/p/staging/HomeScreen.git Signed-off-by: Bocklage, Jens --- sampleapptimedate/src/main.cpp | 36 ++++++++++++++ sampleapptimedate/src/timedateprovider.cpp | 76 ++++++++++++++++++++++++++++++ sampleapptimedate/src/timedateprovider.hpp | 27 +++++++++++ 3 files changed, 139 insertions(+) create mode 100644 sampleapptimedate/src/main.cpp create mode 100644 sampleapptimedate/src/timedateprovider.cpp create mode 100644 sampleapptimedate/src/timedateprovider.hpp (limited to 'sampleapptimedate/src') diff --git a/sampleapptimedate/src/main.cpp b/sampleapptimedate/src/main.cpp new file mode 100644 index 0000000..5140b48 --- /dev/null +++ b/sampleapptimedate/src/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "timedateprovider.hpp" + +void noOutput(QtMsgType, const QMessageLogContext &, const QString &) +{ +} + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + QCoreApplication::setOrganizationDomain("LinuxFoundation"); + QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); + QCoreApplication::setApplicationName("SampleAppTimeDate"); + QCoreApplication::setApplicationVersion("0.7.0"); + + QCommandLineParser parser; + parser.setApplicationDescription("AGL Sample app for StatusBar interface - see wwww... for more details"); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption quietOption(QStringList() << "q" << "quiet", + QCoreApplication::translate("main", "Be quiet. No outputs.")); + parser.addOption(quietOption); + parser.process(a); + + if (parser.isSet(quietOption)) + { + qInstallMessageHandler(noOutput); + } + + TimeDateProvider *tdp = new TimeDateProvider(); + tdp->start(); + + return a.exec(); +} diff --git a/sampleapptimedate/src/timedateprovider.cpp b/sampleapptimedate/src/timedateprovider.cpp new file mode 100644 index 0000000..2511432 --- /dev/null +++ b/sampleapptimedate/src/timedateprovider.cpp @@ -0,0 +1,76 @@ +#include "timedateprovider.hpp" +#include + +TimeDateProvider::TimeDateProvider(QObject *parent) : + QObject(parent), + m_secondsTimerId(-1), + mp_dBusStatusBarProxy(0), + m_statusBarPlaceholder(-1) +{ + qDebug("D-Bus: register as org.agl.SampleAppTimeDate"); + // dbus setup + QDBusConnection dbus = QDBusConnection::sessionBus(); + + dbus.registerObject("/", this); + dbus.registerService("org.agl.sampleapptimedate"); + + + qDebug("D-Bus: connect to org.agl.homescreen /StatusBar"); + mp_dBusStatusBarProxy = new org::agl::statusbar("org.agl.homescreen", + "/StatusBar", + QDBusConnection::sessionBus(), + 0); +} + +TimeDateProvider::~TimeDateProvider() +{ + stop(); + + if (0 != mp_dBusStatusBarProxy) + { + mp_dBusStatusBarProxy->setStatusText(1, ""); + delete mp_dBusStatusBarProxy; + } +} + +void TimeDateProvider::start() +{ + qDebug("trying to start timer (if this lasts long, maybe the Home Screen Application is not launched."); + if ((-1 == m_statusBarPlaceholder) && (0 != mp_dBusStatusBarProxy)) + { + QList availablePlaceholder = mp_dBusStatusBarProxy->getAvailablePlaceholders(); + if (availablePlaceholder.size() > 0) + { + // just take the first available placeholder + m_statusBarPlaceholder = availablePlaceholder[0]; + qDebug("- using statusbar placeholder %d", m_statusBarPlaceholder); + + qDebug("- timer started"); + // callback every second + m_secondsTimerId = startTimer(1000); + } + } +} + +void TimeDateProvider::stop() +{ + if (-1 != m_secondsTimerId) + { + killTimer(m_secondsTimerId); + m_secondsTimerId = -1; + m_statusBarPlaceholder = -1; + } +} + +void TimeDateProvider::timerEvent(QTimerEvent *e) +{ + if (e->timerId() == m_secondsTimerId) + { + if (0 != mp_dBusStatusBarProxy) + { + QString toDisplay = QDateTime::currentDateTime().toString("hh:mm"); + qDebug("%s", toDisplay.toStdString().c_str()); + mp_dBusStatusBarProxy->setStatusText(m_statusBarPlaceholder, toDisplay); + } + } +} diff --git a/sampleapptimedate/src/timedateprovider.hpp b/sampleapptimedate/src/timedateprovider.hpp new file mode 100644 index 0000000..5ff663f --- /dev/null +++ b/sampleapptimedate/src/timedateprovider.hpp @@ -0,0 +1,27 @@ +#ifndef TIMEDATEPROVIDER_HPP +#define TIMEDATEPROVIDER_HPP + +#include +#include "statusbar_proxy.h" + +class TimeDateProvider : public QObject +{ + Q_OBJECT +public: + explicit TimeDateProvider(QObject *parent = 0); + ~TimeDateProvider(); + void start(); + void stop(); +protected: + void timerEvent(QTimerEvent *e); +private: + int m_secondsTimerId; + org::agl::statusbar *mp_dBusStatusBarProxy; + int m_statusBarPlaceholder; +signals: + +public slots: + +}; + +#endif // TIMEDATEPROVIDER_HPP -- cgit 1.2.3-korg