AlarmServer Class Reference
The AlarmServer class allows alarms to be scheduled and unscheduled. More...
#include <alarmserver.h>
Static Public Member Functions | |
| void | addAlarm (QDateTime when, const QCString &channel, const QCString &msg, int data=0) |
| void | deleteAlarm (QDateTime when, const QCString &channel, const QCString &msg, int data=0) |
Friends | |
| int | initApplication (int, char **) |
Detailed Description
The AlarmServer class allows alarms to be scheduled and unscheduled.Applications can schedule alarms with addAlarm() and can unschedule alarms with deleteAlarm(). When the time for an alarm to go off is reached the specified QCop message is sent on the specified channel (optionally with additional data).
Scheduling an alarm using this class is important (rather just using a QTimer) since the machine may be asleep and needs to get woken up using the Linux kernel which implements this at the kernel level to minimize battery usage while asleep.
A small example on how to use AlarmServer.
First we need to connect a slot the AppMessage QCOP call. appMessage will be emitted if QPE/Application/appname gets called.
TestApp::TestApp(QWidget *parent, const char* name, WFlags fl ) : QMainWindow(parent,name,fl){ connect(qApp,SIGNAL(appMessage(const QCString&,const QByteArray&)), this,SLOT(slotAppMessage(const QCString&,const QByteArray&))); }
To add / delete an alarm, you can use the static method AlarmServer::addAlarm and AlarmServer::deleteAlarm. Note that an old (expired) alarm will automatically be deleted from the alarmserver list, but a change in timing will have the effect, that both alarms will be emitted. So if you change an Alarm be sure to delete the old one!
- See also:
- addAlarm
QDateTime oldDt = oldAlarmDateTime(); QPEApplication::execDialog(ourDlg); QDateTime newDt = ourDlg->dateTime(); if(newDt == oldDt ) return; /* code is missing for unsetting an alarm */ AlarmServer::deleteAlarm(oldDt,"QPE/Application/appname","checkAlarm(QDateTime,int)",0); AlarmServer::addAlarm( newDt,"QPE/AlarmServer/appname","checkAlarm(QDateTime,int)",0);
Now once the Alarm is emitted you need to check the appMessage and then do what you want.
void TestApp::slotAppMessage(const QCString& str, const QByteArray& ar ){ QDataStream stream(ar,IO_ReadOnly); if(str == "checkAlarm(QDateTime,int)" ){ QDateTime dt; int a; stream >> dt >> a; // fire up alarm } }
- See also:
- QCopEnvelope
QPEApplication::appMessage(const QCString&,const QByteArray&)
OPimMainWindow
ODevice::alarmSound()
Definition at line 26 of file alarmserver.h.
Member Function Documentation
|
||||||||||||||||||||
|
Schedules an alarm to go off at (or soon after) time when. When the alarm goes off, the QCop message will be sent to channel, with data as a parameter. If this function is called with exactly the same data as a previous call the subsequent call is ignored, so there is only ever one alarm with a given set of parameters. Once an alarm is emitted. The channel with a message will be emitted and data will be send. The QDateTime and int are the two parameters included in the QCOP message. You can specify channel, message and the integer parameter. QDateTime will be the datetime of the QCop call.
Definition at line 394 of file alarmserver.cpp. |
|
||||||||||||||||||||
|
Deletes previously scheduled alarms which match when, channel, message, and data. Passing null values for when, channel, or for the QCop message, acts as a wildcard meaning "any". Similarly, passing -1 for data indicates "any". If there is no matching alarm, nothing happens.
Definition at line 454 of file alarmserver.cpp. References QCString::isNull(), and QDateTime::isNull(). |
The documentation for this class was generated from the following files:
