source: src/gui/alarmdialog.cpp @ df884b3

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

Somewhere a slash was missing ...

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
[68b2df2]3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
[ca90cb1]4 *
[6df32f2]5 * This file is part of ConfClerk.
[ca90cb1]6 *
[6df32f2]7 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]12 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]19 */
[6ae1026]20#include "alarmdialog.h"
[0bb39f5]21#include <conference.h>
[6ae1026]22
23#include <QApplication>
24#include <alarm.h>
[cfd615d]25#include <event.h>
26
27#include <QDir>
[d4a8bbf]28#include <QProcess>
[6ae1026]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
[cfd615d]53    connect(stopPB, SIGNAL(clicked()), SLOT(closeDialog()));
[6ae1026]54    connect(appPB, SIGNAL(clicked()), SLOT(runApp()));
55    connect(snoozePB, SIGNAL(clicked()), SLOT(snooze()));
56
[52d0741]57    qString databaseFileName;
[df884b3]58    databaseFileName = QDesktopServices::storageLocation(QDesktopServices::DataLocation + "/ConfClerk.sqlite"
[52d0741]59    // TODO: check existence
[cfd615d]60    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
[52d0741]61    database.setDatabaseName(databaseFileName);
[cfd615d]62    database.open();
63
[7ec8838]64    QString titleStr;
65    QString messageStr;
66    QString timeStr;
67    QString personsStr;
68    QString roomStr;
[95596f6]69    try
70    {
[0bb39f5]71        Event event = Event::getById(mEventId,Conference::activeConference());
[7ec8838]72        titleStr = "Event alarm";
73        messageStr = event.title();
74        timeStr = event.start().toString("hh:mm") + "-" + event.start().addSecs(event.duration()).toString("hh:mm");
75        personsStr = event.persons().join(" and ");
76        roomStr = event.room();
[95596f6]77    }
[06570e9]78    catch(OrmNoObjectException&)
[95596f6]79    {
[7ec8838]80        titleStr = QString("ERROR");
81        messageStr = QString("No such event in the DB: %1").arg(QString::number(mEventId));
[95596f6]82    }
83    catch(...) {} // TODO: implement
[7ec8838]84    message->setText(messageStr);
85    setWindowTitle(titleStr);
86    time->setText(timeStr);
87    persons->setText(personsStr);
88    room->setText(roomStr);
[6ae1026]89}
90
91void AlarmDialog::runApp()
92{
[d4a8bbf]93    QString program = QDir::currentPath() + "/" + *qApp->argv();
94    QProcess::startDetached(program,QStringList()<<QString::number(mEventId));
[7ec8838]95    closeDialog();
[6ae1026]96}
97
98void AlarmDialog::snooze()
99{
100    if(mEventId==0) // not valid event ID
101        return;
102
103    Alarm alarm;
104    alarm.addAlarm(mEventId,QDateTime::currentDateTime().addSecs(60*SNOOZE_TIME));
105    qApp->quit();
106}
107
[cfd615d]108void AlarmDialog::closeDialog()
109{
110    // before closing the dialog, it is necessary to remove alarm flag from the DB
[95596f6]111    try
112    {
[0bb39f5]113        Event event = Event::getById(mEventId,Conference::activeConference());
[95596f6]114        event.setHasAlarm(false);
115        event.update("alarm");
116    }
[806b992]117    catch(OrmNoObjectException &) {} // TODO: implement
[95596f6]118    catch(...) {} // just close dialog
[cfd615d]119    qApp->quit();
120}
121
Note: See TracBrowser for help on using the repository browser.