Qtopia library API Documentation

AlarmServer Class Reference

The AlarmServer class allows alarms to be scheduled and unscheduled. More...

#include <alarmserver.h>

List of all members.

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()

Sound::soundAlarm()

Definition at line 26 of file alarmserver.h.


Member Function Documentation

void AlarmServer::addAlarm QDateTime  when,
const QCString channel,
const QCString message,
int  data = 0
[static]
 

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.

Parameters:
when The QDateTime of the alarm
channel The channel which gets called once the alarm is emitted
message The message to be send to the channel
data Additional data as integer
See also:
QCopChannel

deleteAlarm()

Definition at line 394 of file alarmserver.cpp.

void AlarmServer::deleteAlarm QDateTime  when,
const QCString channel,
const QCString message,
int  data = 0
[static]
 

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.

See also:
addAlarm()

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:
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001