diff options
author | 2016-06-24 16:19:10 +0200 | |
---|---|---|
committer | 2016-06-24 16:19:10 +0200 | |
commit | ca3605ea664834acdf712e691be8f0358b1c6b6f (patch) | |
tree | 58b60fe19816136209a4a7302ed6d44e733fcc37 /SampleAppTimeDate/src | |
parent | ff25a2a06428ffb0d6d8aeddb5faaa301b4201fe (diff) |
v0.1.0
06/24/2016
- reworked status bar
- reviewed D-Bus interfaces, now using signals instead of methods for day/night mode
- created new home screen simulator app
- license changed to Apache 2.0
- put D-Bus introspections in one central place
- disabled "only one instance allowed" for development
Diffstat (limited to 'SampleAppTimeDate/src')
-rw-r--r-- | SampleAppTimeDate/src/main.cpp | 12 | ||||
-rw-r--r-- | SampleAppTimeDate/src/timedateprovider.cpp | 77 | ||||
-rw-r--r-- | SampleAppTimeDate/src/timedateprovider.h | 27 |
3 files changed, 116 insertions, 0 deletions
diff --git a/SampleAppTimeDate/src/main.cpp b/SampleAppTimeDate/src/main.cpp new file mode 100644 index 0000000..d432cba --- /dev/null +++ b/SampleAppTimeDate/src/main.cpp @@ -0,0 +1,12 @@ +#include <QCoreApplication> +#include "timedateprovider.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + 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..91d5e30 --- /dev/null +++ b/SampleAppTimeDate/src/timedateprovider.cpp @@ -0,0 +1,77 @@ +#include "timedateprovider.h" +#include <QTimerEvent> + +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.mainwindow /StatusBar"); + mp_dBusStatusBarProxy = new org::agl::statusbar("org.agl.homescreen", + "/StatusBar", + QDBusConnection::sessionBus(), + 0); +} + +TimeDateProvider::~TimeDateProvider() +{ + stop(); + + if (0 != mp_dBusStatusBarProxy) + { + qDebug("x"); + 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<int> 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.h b/SampleAppTimeDate/src/timedateprovider.h new file mode 100644 index 0000000..039104a --- /dev/null +++ b/SampleAppTimeDate/src/timedateprovider.h @@ -0,0 +1,27 @@ +#ifndef TIMEDATEPROVIDER_H +#define TIMEDATEPROVIDER_H + +#include <QObject> +#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_H |