1 /**************************************************************************
5 Copyright (C) 2010 Heli Hyvättinen
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **************************************************************************/
26 #include "kitchenalertmainwindow.h"
27 #include "ui_kitchenalertmainwindow.h"
32 #include "choosetimersequencedialog.h"
33 #include "createtimersequencedialog.h"
37 #include <QMessageBox>
38 #include <QMediaPlayer>
40 KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
42 ui(new Ui::KitchenAlertMainWindow)
46 connect(ui->LoadTimerScheduleButton, SIGNAL (pressed()), this, SLOT (openTimerSequence()));
47 connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
49 ui->ComingAlertsTableView->setModel(&model_);
50 ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
51 ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
54 //Buttons used to reacting an alarm are hidden by default
56 ui->DoneButton->setDisabled(true);
57 ui->SnoozeButton->setDisabled(true);
58 ui->RestartButton->setDisabled(true);
61 connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection)));
63 connect(ui->DoneButton,SIGNAL(clicked()),this,SLOT(stop()));
64 connect(ui->RestartButton,SIGNAL(clicked()),this,SLOT(restart()));
65 connect(ui->SnoozeButton,SIGNAL(clicked()),this, SLOT(snooze()));
70 KitchenAlertMainWindow::~KitchenAlertMainWindow()
75 void KitchenAlertMainWindow::changeEvent(QEvent *e)
77 QMainWindow::changeEvent(e);
79 case QEvent::LanguageChange:
80 ui->retranslateUi(this);
89 void KitchenAlertMainWindow::openTimerSequence()
91 ChooseTimerSequenceDialog opendialog;
98 void KitchenAlertMainWindow::newTimerSequence()
100 CreateTimerSequenceDialog createdialog;
103 if (createdialog.exec() == QDialog::Accepted) //if user pressed OK
107 QList<Timer *> alltimers = createdialog.getTimers(); //get user input from the dialog
109 Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!)
114 // ui->nextAlertText->setText( timer1->getAlertText());
118 connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
122 model_.addTimers(alltimers); // give timers to the model
123 // ui->ComingAlertsTableView->update();
128 // if cancelled, do nothing
135 void KitchenAlertMainWindow::updateTime(int seconds)
139 // ui->hoursLcdNumber->display(seconds/360);
140 // ui->minutesLcdNumber->display((seconds%360)/60);
141 // ui->secondsLcdNumber->display((seconds%60));
147 void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
149 // QMessageBox::information ( NULL, "KitchenAlert","Alert!!!");
151 // The program is brought to front and activated when alerted
156 // The alerting timer is selected
157 ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
158 qDebug() << "Should be selected now";
162 //Snooze button is enabled
165 ui->SnoozeButton->setEnabled(true);
167 //The alert sound is played
177 void KitchenAlertMainWindow::timerSelected(QItemSelection,QItemSelection)
179 ui->DoneButton->setEnabled(true);
180 ui->RestartButton->setEnabled(true);
184 void KitchenAlertMainWindow::snooze()
187 model_.snoozeTimer(selectedRow());
188 ui->SnoozeButton->setDisabled(true);
192 void KitchenAlertMainWindow::restart()
195 model_.startTimer(selectedRow());
196 ui->SnoozeButton->setDisabled(true);
200 void KitchenAlertMainWindow::stop()
202 model_.stopTimer(selectedRow());
203 ui->SnoozeButton->setDisabled(true);
206 QModelIndex KitchenAlertMainWindow::selectedRow()
208 QModelIndexList chosenRows = ui->ComingAlertsTableView->selectionModel()->selectedRows();
210 //The selection mode used allows only one row to be selected at time, so we just take the first
211 //There are indexes for all coloumns in the row in the list, but as we only use the row, it does not matter which one we take
213 return chosenRows.takeFirst();