source: src/gui/alarmdialog.cpp @ 68b2df2

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

Add copyright to source.

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