1 /**************************************************************************
4 Copyright (C) 2010 Heli Hyvättinen
6 This file is part of KitchenAlert.
8 Kitchen Alert is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 **************************************************************************/
28 #include "currentalertstablemodel.h"
31 Timer::Timer(QObject *parent) :
36 _actualTimer.setInterval(1000); // 1 s
37 connect(&_actualTimer, SIGNAL(timeout()), this, SLOT(secondPassed()));
43 int Timer::getOriginalTimeInSeconds()
48 void Timer::setOriginalTimeInSeconds(int seconds)
50 _originalTime = seconds;
53 int Timer::getRemainingTimeInSeconds()
55 return _remainingTime;
58 QString Timer::getAlertText()
63 void Timer::setAlertText(QString text)
68 void Timer::secondPassed()
73 if (_remainingTime == 0)
77 emit alert(whereAmI());
78 // qDebug() << "alerting";
81 emit remainingTimeChanged(); //after alerting in case of alert so that status gets updated immediately
86 _remainingTime = _originalTime;
91 if (_originalTime == 0) //a 00:00:00 alert has to be checked here, since it's already negative when checked for the next time
95 emit alert(whereAmI());
96 qDebug () << "Alerting 00:00:00 from row: " << whereAmI().row();
111 _remainingTime = 0; //Stopped timer shows 00:00:00
119 _remainingTime = 120;
126 bool Timer::isAlerting()
131 QModelIndex Timer::whereAmI()
135 QObject * p_parent = parent();
138 CurrentAlertsTableModel* p_parentModel = qobject_cast<CurrentAlertsTableModel *> (p_parent);
140 if (p_parentModel == NULL) //If no parent or parent is not of right class, return an invalid index
141 return QModelIndex();
144 return p_parentModel->giveIndexForTimer(this);
149 void Timer::enableDefaultSound()
151 alertSound_.setDefaultSound();
154 void Timer::changeAlertSound(QString filename)
156 alertSound_.setSound(filename);