source: src/gui/alarmdialog.cpp @ a5c1179

qt5
Last change on this file since a5c1179 was d4a8bbf, checked in by pavelpa <pavelpa@…>, 13 years ago

MAEMO: work on alarm

  • snooze alarm
  • cancel alarm
  • run application which automatically display Event dialog for given Event ID
  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include "alarmdialog.h"
2
3#include <QApplication>
4#include <alarm.h>
5#include <event.h>
6
7#include <QDir>
8#include <QProcess>
9
10const int SNOOZE_TIME = 5; // in minutes
11
12const int confId = 1;
13
14AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
15    : QDialog(aParent)
16    , mEventId(0)
17    , mAlarmId(0)
18{
19    setupUi(this);
20
21    if(argc<3)
22    {
23        // not enough arguments passed to the dialog
24        // Usage: $ ./dialog eventId alarmId
25        // Example: $ ./dialog 521 13
26        //
27        // TODO: handle this case
28    }
29    else
30    {
31        mEventId = QString(argv[1]).toInt();
32        mAlarmId = QString(argv[2]).toInt();
33    }
34
35    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
36    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
37    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
38
39    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
40    database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
41    database.open();
42
43    Event event = Event::getById(mEventId,confId);
44    message->setText(QString(argv[1]).append("-").append(QString(argv[2])));
45    message->setText(event.title());
46    setWindowTitle(event.title());
47}
48
49void AlarmDialog::runApp()
50{
51    QString program = QDir::currentPath() + "/" + *qApp->argv();
52    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
53    qApp->quit();
54}
55
56void AlarmDialog::snooze()
57{
58    if(mEventId==0) // not valid event ID
59        return;
60
61    Alarm alarm;
62    alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
63    qApp->quit();
64}
65
66void AlarmDialog::closeDialog()
67{
68    // before closing the dialog, it is necessary to remove alarm flag from the DB
69    Event event = Event::getById(mEventId,confId);
70    event.setHasAlarm(false);
71    event.update("alarm");
72    qApp->quit();
73}
74
Note: See TracBrowser for help on using the repository browser.