Stopped timers now show full time and "stopped"
[kitchenalert] / src / timer.h
1 /**************************************************************************
2         KitchenAlert
3
4         Copyright (C) 2010-2011  Heli Hyvättinen
5
6         This file is part of KitchenAlert.
7
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.
12
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.
17
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/>.
20
21 **************************************************************************/
22
23
24
25
26
27 #ifndef TIMER_H
28 #define TIMER_H
29
30 #include <QObject>
31 #include <QString>
32 #include <QTimer>
33
34
35 #include <QModelIndex>
36
37 #include "alertsound.h"
38
39 /*! The timer class of KitchenAlert'
40
41   @author Heli Hyvättinen
42   @date 2011-04-05
43   @version 0.2.1
44
45 The timer class of KitchenAlert.
46
47 */
48
49 class Timer : public QObject
50 {
51     Q_OBJECT
52 public:
53     explicit Timer(QObject *parent = 0);
54
55     /*! Returns the original time in seconds
56         When the alert restarts, it is set to this time.
57     */
58      int getOriginalTimeInSeconds();
59
60     /*! Sets the original time in seconds */
61     void setOriginalTimeInSeconds(int seconds);
62
63     /*! Returns the time remaining before the alert in seconds       */
64     int getRemainingTimeInSeconds();
65
66     /*! Returns the alert text */
67     QString getAlertText();
68
69     /*! Sets the alert text */
70     void setAlertText(QString text);
71
72     /*! Returns whether the timer is alerting */
73     bool isAlerting();
74
75     /*! Saves the timer to a file
76       @param filename The file to which to save.
77     */
78     bool save(QString filename);
79
80     /*! Loads a timer from a file
81       @param filename The file from which to load.
82     */
83     bool load(QString filename);
84
85     /*! Returns wheter the alert is running or not.
86       Alerting timers are considered running. */
87     bool isRunning();
88
89
90 signals:
91     /*! Emitted when the remaining time in the timer has changed */
92     void remainingTimeChanged();
93
94     /*! Emitted when the timer alerts */
95     void alert(QModelIndex indexOfAlerter);
96
97 public slots:
98     /*! The internal QTimer is connected to this slot */
99     void secondPassed();
100
101     /*! Start the timer */
102     void start();
103
104     /*! Stop the timer*/
105     void stop();
106
107     /*! Snooze the timer
108         Currently sets the timer to alert again in two minutes.
109     */
110     void snooze();
111
112     /*! Switches to use the default sound (and saves it to settings */
113     void enableDefaultSound();
114
115     /*! Changes the sound file used and saves it to settings */
116     void changeAlertSound(QString filename);
117
118
119
120
121 private:
122     int _originalTime; //seconds!
123     int _remainingTime; //seconds!
124     QString _alertText;
125     QTimer _actualTimer;
126     bool alerting_;
127
128     QString filenameWithPath_; /*! Name (with full path) of the file where the timer was loaded from. Empty if timer not loaded from file. */
129
130     QModelIndex whereAmI();
131
132     AlertSound alertSound_;
133
134
135
136
137
138 };
139
140 #endif // TIMER_H