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
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
[6df32f2]4 * This file is part of ConfClerk.
[ca90cb1]5 *
[6df32f2]6 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]11 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]18 */
[6ae1026]19#include "alarmdialog.h"
[0bb39f5]20#include <conference.h>
[6ae1026]21
22#include <QApplication>
23#include <alarm.h>
[cfd615d]24#include <event.h>
25
26#include <QDir>
[d4a8bbf]27#include <QProcess>
[6ae1026]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
[cfd615d]52    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
[6ae1026]53    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
54    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
55
[cfd615d]56    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
57    database.setDatabaseName(QDir::homePath() + "/.fosdem/fosdem.sqlite");
58    database.open();
59
[7ec8838]60    QString titleStr;
61    QString messageStr;
62    QString timeStr;
63    QString personsStr;
64    QString roomStr;
[95596f6]65    try
66    {
[0bb39f5]67        Event event = Event::getById(mEventId,Conference::activeConference());
[7ec8838]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();
[95596f6]73    }
[06570e9]74    catch(OrmNoObjectException&)
[95596f6]75    {
[7ec8838]76        titleStr = QString("ERROR");
77        messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
[95596f6]78    }
79    catch(...) {} // TODO: implement
[7ec8838]80    message->setText(messageStr);
81    setWindowTitle(titleStr);
82    time->setText(timeStr);
83    persons->setText(personsStr);
84    room->setText(roomStr);
[6ae1026]85}
86
87void AlarmDialog::runApp()
88{
[d4a8bbf]89    QString program = QDir::currentPath() + "/" + *qApp->argv();
90    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
[7ec8838]91    closeDialog();
[6ae1026]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
[cfd615d]104void AlarmDialog::closeDialog()
105{
106    // before closing the dialog, it is necessary to remove alarm flag from the DB
[95596f6]107    try
108    {
[0bb39f5]109        Event event = Event::getById(mEventId,Conference::activeConference());
[95596f6]110        event.setHasAlarm(false);
111        event.update("alarm");
112    }
[806b992]113    catch(OrmNoObjectException &) {} // TODO: implement
[95596f6]114    catch(...) {} // just close dialog
[cfd615d]115    qApp->quit();
116}
117
Note: See TracBrowser for help on using the repository browser.