1 /**************************************************************************
5 Copyright (C) 2010 Heli Hyvättinen
7 This file is part of KitchenAlert.
9 Kitchen Alert is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **************************************************************************/
28 #include "kitchenalertmainwindow.h"
29 #include "ui_kitchenalertmainwindow.h"
34 #include "choosetimersequencedialog.h"
35 #include "createtimersequencedialog.h"
40 #include <QMessageBox>
44 KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
46 ui(new Ui::KitchenAlertMainWindow)
50 connect(ui->LoadTimerScheduleButton, SIGNAL (pressed()), this, SLOT (openTimerSequence()));
51 connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
53 ui->ComingAlertsTableView->setModel(&model_);
54 ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
55 ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
58 //Buttons used to reacting an alarm are hidden by default
60 ui->DoneButton->setDisabled(true);
61 ui->SnoozeButton->setDisabled(true);
62 ui->RestartButton->setDisabled(true);
65 connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection)));
67 connect(ui->DoneButton,SIGNAL(clicked()),this,SLOT(stop()));
68 connect(ui->RestartButton,SIGNAL(clicked()),this,SLOT(restart()));
69 connect(ui->SnoozeButton,SIGNAL(clicked()),this, SLOT(snooze()));
74 KitchenAlertMainWindow::~KitchenAlertMainWindow()
79 void KitchenAlertMainWindow::changeEvent(QEvent *e)
81 QMainWindow::changeEvent(e);
83 case QEvent::LanguageChange:
84 ui->retranslateUi(this);
93 void KitchenAlertMainWindow::openTimerSequence()
95 ChooseTimerSequenceDialog opendialog;
102 void KitchenAlertMainWindow::newTimerSequence()
104 CreateTimerSequenceDialog createdialog;
107 if (createdialog.exec() == QDialog::Accepted) //if user pressed OK
111 QList<Timer *> alltimers = createdialog.getTimers(); //get user input from the dialog
113 Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!)
118 // ui->nextAlertText->setText( timer1->getAlertText());
122 connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
126 model_.addTimers(alltimers); // give timers to the model
127 // ui->ComingAlertsTableView->update();
132 // if cancelled, do nothing
139 void KitchenAlertMainWindow::updateTime(int seconds)
143 // ui->hoursLcdNumber->display(seconds/360);
144 // ui->minutesLcdNumber->display((seconds%360)/60);
145 // ui->secondsLcdNumber->display((seconds%60));
151 void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
153 // QMessageBox::information ( NULL, "KitchenAlert","Alert!!!");
155 // The program is brought to front and activated when alerted
160 // The alerting timer is selected
161 ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
162 qDebug() << "Should be selected now";
166 //Snooze button is enabled
169 ui->SnoozeButton->setEnabled(true);
171 //The alert sound is played
183 void KitchenAlertMainWindow::timerSelected(QItemSelection,QItemSelection)
185 ui->DoneButton->setEnabled(true);
186 ui->RestartButton->setEnabled(true);
190 void KitchenAlertMainWindow::snooze()
193 model_.snoozeTimer(selectedRow());
194 ui->SnoozeButton->setDisabled(true);
199 void KitchenAlertMainWindow::restart()
202 model_.startTimer(selectedRow());
203 ui->SnoozeButton->setDisabled(true);
208 void KitchenAlertMainWindow::stop()
210 model_.stopTimer(selectedRow());
211 ui->SnoozeButton->setDisabled(true);
215 QModelIndex KitchenAlertMainWindow::selectedRow()
217 QModelIndexList chosenRows = ui->ComingAlertsTableView->selectionModel()->selectedRows();
219 //The selection mode used allows only one row to be selected at time, so we just take the first
220 //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
222 return chosenRows.takeFirst();