source: src/gui/alarmdialog.cpp @ 6df32f2

qt5
Last change on this file since 6df32f2 was 6df32f2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of ConfClerk.
5 *
6 * ConfClerk is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * ConfClerk is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
18 */
19#include "alarmdialog.h"
20#include <conference.h>
21
22#include <QApplication>
23#include <alarm.h>
24#include <event.h>
25
26#include <QDir>
27#include <QProcess>
28
29const int SNOOZE_TIME = 5; // in minutes
30
31AlarmDialog::AlarmDialog(int argc, char *argv[], QWidget *aParent)
32    : QDialog(aParent)
33    , mEventId(0)
34    , mAlarmId(0)
35{
36    setupUi(this);
37
38    if(argc<3)
39    {
40        // not enough arguments passed to the dialog
41        // Usage: $ ./dialog eventId alarmId
42        // Example: $ ./dialog 521 13
43        //
44        // TODO: handle this case
45    }
46    else
47    {
48        mEventId = QString(argv[1]).toInt();
49        mAlarmId = QString(argv[2]).toInt();
50    }
51
52    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
53    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
54    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
55
56    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
57    database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
58    database.open();
59
60    QString titleStr;
61    QString messageStr;
62    QString timeStr;
63    QString personsStr;
64    QString roomStr;
65    try
66    {
67        Event event = Event::getById(mEventId,Conference::activeConference());
68        titleStr = "Event alarm";
69        messageStr = event.title();
70        timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
71        personsStr = event.persons().join(" and ");
72        roomStr = event.room();
73    }
74    catch(OrmNoObjectException&)
75    {
76        titleStr = QString("ERROR");
77        messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
78    }
79    catch(...) {} // TODO: implement
80    message->setText(messageStr);
81    setWindowTitle(titleStr);
82    time->setText(timeStr);
83    persons->setText(personsStr);
84    room->setText(roomStr);
85}
86
87void AlarmDialog::runApp()
88{
89    QString program = QDir::currentPath() + "/" + *qApp->argv();
90    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
91    closeDialog();
92}
93
94void AlarmDialog::snooze()
95{
96    if(mEventId==0) // not valid event ID
97        return;
98
99    Alarm alarm;
100    alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
101    qApp->quit();
102}
103
104void AlarmDialog::closeDialog()
105{
106    // before closing the dialog, it is necessary to remove alarm flag from the DB
107    try
108    {
109        Event event = Event::getById(mEventId,Conference::activeConference());
110        event.setHasAlarm(false);
111        event.update("alarm");
112    }
113    catch(OrmNoObjectException &) {} // TODO: implement
114    catch(...) {} // just close dialog
115    qApp->quit();
116}
117
Note: See TracBrowser for help on using the repository browser.