--- /dev/null
+#include "alarm.h"
+
+#include <QDateTime>
+
+int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime)
+{
+ cookie_t cookie = 0;
+ alarm_event_t *event = 0;
+ alarm_action_t *action = 0;
+
+ /* Create alarm event structure and set application identifier */
+ event = alarm_event_create();
+ alarm_event_set_alarm_appid(event, APPID);
+ alarm_event_set_message(event, QString::number(aEventId).toLocal8Bit().data()); // for Deleting purposes
+
+ /* Use absolute time triggering */
+ event->alarm_time = aDateTime.toTime_t();
+
+ /* Add exec command action */
+ action = alarm_event_add_actions(event, 1);
+ QString command = QString("/home/maemo/work/alarm/bin/alarmdialog %1").arg(QString::number(aEventId));
+ alarm_action_set_exec_command(action, command.toLocal8Bit().data());
+ action->flags |= ALARM_ACTION_TYPE_EXEC;
+ action->flags |= ALARM_ACTION_WHEN_TRIGGERED;
+ action->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; // adds assigned cookie at the end of command string
+
+ /* Send the alarm to alarmd */
+ cookie = alarmd_event_add(event);
+ if(cookie==0) // adding alarm failed
+ emit(addAlarmFailed(aEventId));
+ else
+ emit(alarmAdded(aEventId));
+
+ /* Free all dynamic memory associated with the alarm event */
+ alarm_event_delete(event);
+
+ return cookie;
+}
+
+void Alarm::deleteAlarm(int aEventId)
+{
+ cookie_t *list = 0;
+ cookie_t cookie = 0;
+ alarm_event_t *event = 0;
+
+ // query the APPID's list of alarms
+ if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
+ {
+ for( int i = 0; (cookie = list[i]) != 0; ++i )
+ {
+ alarm_event_delete(event);
+
+ // get the event for specified alarm cookie (alarmId)
+ if( (event = alarmd_event_get(cookie)) == 0 )
+ {
+ // should we inform user about it ???
+ continue;
+ }
+
+ if(aEventId==atoi(alarm_event_get_message(event)))
+ {
+ // delete cookie
+ if( alarmd_event_del(cookie) == -1 )
+ {
+ // was not able to delete alarm for given aEventId
+ emit(deleteAlarmFailed(aEventId));
+ break;
+ }
+ else
+ {
+ emit(alarmDeleted(aEventId));
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ // query failed
+ }
+
+ free(list);
+ alarm_event_delete(event);
+}
+
--- /dev/null
+#ifndef ALARM_H
+#define ALARM_H
+
+#include <QObject>
+#include <QDateTime>
+
+extern "C"
+{
+#include <alarmd/libalarm.h>
+}
+
+#define APPID "alarm-example"
+
+class Alarm : public QObject
+{
+ Q_OBJECT
+ public:
+ Alarm() {}
+ ~Alarm() {}
+ int addAlarm(int aEventId, const QDateTime &aDateTime);
+ void deleteAlarm(int aEventId);
+ signals:
+ void alarmAdded(int aEventId);
+ void addAlarmFailed(int aEventId);
+ void alarmDeleted(int aEventId);
+ void deleteAlarmFailed(int aEventId);
+};
+
+#endif /* ALARM_H */
+
--- /dev/null
+TEMPLATE = lib
+TARGET = qalarm
+DESTDIR = ../bin
+CONFIG += static
+
+# module dependencies
+LIBS += -lalarm
+DEPENDPATH += .
+
+HEADERS += alarm.h
+
+SOURCES += alarm.cpp
+
+include(global.pri)
TEMPLATE = subdirs
SUBDIRS = orm mvc sql gui app
+maemo : SUBDIRS += alarm
#SUBDIRS += test
CONFIG += ordered
--- /dev/null
+#include "alarmdialog.h"
+
+#include <QApplication>
+#include <alarm.h>
+
+const int SNOOZE_TIME = 5; // in minutes
+
+AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
+ : QDialog(aParent)
+ , mEventId(0)
+ , mAlarmId(0)
+{
+ setupUi(this);
+
+ if(argc<3)
+ {
+ // not enough arguments passed to the dialog
+ // Usage: $ ./dialog eventId alarmId
+ // Example: $ ./dialog 521 13
+ //
+ // TODO: handle this case
+ }
+ else
+ {
+ mEventId = QString(argv[1]).toInt();
+ mAlarmId = QString(argv[2]).toInt();
+ }
+
+ connect(stopPB, SIGNAL(clicked()), qApp, SLOT(quit()));
+ connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
+ connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
+
+ message->setText(QString(argv[1]).append("-").append(QString(argv[2])));
+}
+
+void AlarmDialog::runApp()
+{
+}
+
+void AlarmDialog::snooze()
+{
+ if(mEventId==0) // not valid event ID
+ return;
+
+ Alarm alarm;
+ alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
+ qApp->quit();
+}
+
--- /dev/null
+#ifndef ALARMDIALOG_H
+#define ALARMDIALOG_H
+
+#include <QDialog>
+#include "ui_alarmdialog.h"
+
+class AlarmDialog : public QDialog, Ui::AlarmDialog
+{
+ Q_OBJECT
+ public:
+ AlarmDialog(int argc, char *argv[], QWidget *aParent = NULL);
+ ~AlarmDialog() {}
+ private slots:
+ void runApp();
+ void snooze();
+ private:
+ int mEventId; // event ID obtained from 'schedule'
+ int mAlarmId; // cookie assigned by alarmd
+};
+
+#endif /* ALARMDIALOG_H */
+
--- /dev/null
+<ui version="4.0" >
+ <class>AlarmDialog</class>
+ <widget class="QDialog" name="AlarmDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>334</width>
+ <height>135</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="pixmap" >
+ <pixmap resource="../icons.qrc" >:/icons/fosdem.png</pixmap>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="message" >
+ <property name="text" >
+ <string>Alarm message goes here</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QPushButton" name="appPB" >
+ <property name="text" >
+ <string>App</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="snoozePB" >
+ <property name="text" >
+ <string>Snooze</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stopPB" >
+ <property name="text" >
+ <string>Stop</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="../icons.qrc" />
+ </resources>
+ <connections/>
+</ui>
QT += sql xml
# module dependencies
-LIBS += -L$$DESTDIR -lmvc -lorm -lsql
-INCLUDEPATH += ../orm ../mvc ../sql
-DEPENDPATH += . ../orm ../mvc ../sql
-TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmvc.a $$DESTDIR/libsql.a
+LIBS += -L$$DESTDIR -lmvc -lorm -lsql -lqalarm
+INCLUDEPATH += ../orm ../mvc ../sql ../alarm
+DEPENDPATH += . ../orm ../mvc ../sql ../alarm
+TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmvc.a $$DESTDIR/libsql.a $$DESTDIR/libqalarm.a
# A shamelessly long list of sources, headers and forms.
FORMS += mainwindow.ui \
daynavigatorwidget.ui \
- about.ui
+ about.ui \
+ alarmdialog.ui
HEADERS += mainwindow.h \
- daynavigatorwidget.h
+ daynavigatorwidget.h \
+ alarmdialog.h
SOURCES += mainwindow.cpp \
- daynavigatorwidget.cpp
+ daynavigatorwidget.cpp \
+ alarmdialog.cpp