1 #include "timedateprovider.hpp"
4 TimeDateProvider::TimeDateProvider(QObject *parent) :
7 mp_dBusStatusBarProxy(0),
8 m_statusBarPlaceholder(-1)
10 qDebug("D-Bus: register as org.agl.SampleAppTimeDate");
12 QDBusConnection dbus = QDBusConnection::sessionBus();
14 dbus.registerObject("/", this);
15 dbus.registerService("org.agl.sampleapptimedate");
18 qDebug("D-Bus: connect to org.agl.homescreen /StatusBar");
19 mp_dBusStatusBarProxy = new org::agl::statusbar("org.agl.homescreen",
21 QDBusConnection::sessionBus(),
25 TimeDateProvider::~TimeDateProvider()
29 if (0 != mp_dBusStatusBarProxy)
31 mp_dBusStatusBarProxy->setStatusText(1, "");
32 delete mp_dBusStatusBarProxy;
36 void TimeDateProvider::start()
38 qDebug("trying to start timer (if this lasts long, maybe the Home Screen Application is not launched.");
39 if ((-1 == m_statusBarPlaceholder) && (0 != mp_dBusStatusBarProxy))
41 QList<int> availablePlaceholder = mp_dBusStatusBarProxy->getAvailablePlaceholders();
42 if (availablePlaceholder.size() > 0)
44 // just take the first available placeholder
45 m_statusBarPlaceholder = availablePlaceholder[0];
46 qDebug("- using statusbar placeholder %d", m_statusBarPlaceholder);
48 qDebug("- timer started");
49 // callback every second
50 m_secondsTimerId = startTimer(1000);
55 void TimeDateProvider::stop()
57 if (-1 != m_secondsTimerId)
59 killTimer(m_secondsTimerId);
60 m_secondsTimerId = -1;
61 m_statusBarPlaceholder = -1;
65 void TimeDateProvider::timerEvent(QTimerEvent *e)
67 if (e->timerId() == m_secondsTimerId)
69 if (0 != mp_dBusStatusBarProxy)
71 QString toDisplay = QDateTime::currentDateTime().toString("hh:mm");
72 qDebug("%s", toDisplay.toStdString().c_str());
73 mp_dBusStatusBarProxy->setStatusText(m_statusBarPlaceholder, toDisplay);