~nik90/ubuntu-clock-app/engine-fixes

« back to all changes in this revision

Viewing changes to backend/modules/Stopwatch/engine.cpp

  • Committer: Nekhelesh Ramananthan
  • Date: 2015-09-10 20:38:50 UTC
  • Revision ID: krnekhelesh@gmail.com-20150910203850-c1jhyncnrqku6kt7
Fixed engine

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
     when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return
29
29
     /home/phablet/.config/com.ubuntu.clock path.
30
30
    */
31
 
    m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat)
 
31
    m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat),
 
32
    m_isStopwatchRunning(false),
 
33
    m_previousTimeInmsecs(0),
 
34
    m_totalTimeInmsecs(0)
32
35
{
33
36
    qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
34
37
    QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();
36
39
    {
37
40
        m_stopwatchStartDateTime = startTime;
38
41
    }
39
 
    else
40
 
    {
41
 
        startStopwatch();
42
 
    }
43
42
 
44
43
    m_isStopwatchRunning = m_settings.value("Stopwatch/isStopwatchRunning").toBool();
45
44
    m_previousTimeInmsecs = m_settings.value("Stopwatch/previousTimeInmsecs").toInt();
 
45
    if(m_previousTimeInmsecs != 0) {
 
46
        setTotalTimeOfStopwatch(m_previousTimeInmsecs);
 
47
    }
46
48
}
47
49
 
48
50
int StopwatchEngine::rowCount(const QModelIndex &parent) const
102
104
    endRemoveRows();
103
105
}
104
106
 
 
107
void StopwatchEngine::setStopwatchStartDateTime()
 
108
{
 
109
    m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();
 
110
    m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
 
111
}
 
112
 
105
113
void StopwatchEngine::startStopwatch()
106
114
{
107
 
    if(m_isStopwatchRunning == false)
108
 
    {
109
 
        m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();
110
 
        m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
 
115
    setStopwatchStartDateTime();
 
116
    setRunning(true);
 
117
}
111
118
 
112
 
        setIsRunning(true);
113
 
    }
 
119
void StopwatchEngine::updateStopwatch()
 
120
{
 
121
    setTotalTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
114
122
}
115
123
 
116
124
void StopwatchEngine::pauseStopwatch()
117
125
{
118
126
    setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
119
 
    setIsRunning(false);
 
127
    setTotalTimeOfStopwatch(m_previousTimeInmsecs);
 
128
    setRunning(false);
120
129
}
121
130
 
122
131
void StopwatchEngine::clearStopwatch()
123
132
{
 
133
    setPreviousTimeOfStopwatch(0);
124
134
    setTotalTimeOfStopwatch(0);
125
 
    setPreviousTimeOfStopwatch(0);
126
135
 
127
136
    beginResetModel();
128
137
    m_settings.setValue("Stopwatch/laps", QVariantList());
129
138
    endResetModel();
130
 
 
131
 
    setIsRunning(false);
132
139
}
133
140
 
134
 
bool StopwatchEngine::getIsRunning()
 
141
bool StopwatchEngine::getRunning()
135
142
{
136
143
    return m_isStopwatchRunning;
137
144
}
143
150
 
144
151
int StopwatchEngine::getTotalTimeOfStopwatch()
145
152
{
146
 
    if(m_isStopwatchRunning == false)
147
 
    {
148
 
        m_totalTimeInmsecs = m_previousTimeInmsecs;
149
 
    }
150
 
    else
151
 
    {
152
 
        m_totalTimeInmsecs = m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc());
153
 
    }
154
153
    return m_totalTimeInmsecs;
155
154
}
156
155
 
157
 
void StopwatchEngine::setIsRunning(bool value)
 
156
void StopwatchEngine::setRunning(bool value)
158
157
{
159
158
    m_isStopwatchRunning = value;
160
159
    m_settings.setValue("Stopwatch/isStopwatchRunning", m_isStopwatchRunning);
161
 
    emit isRunningChanged();
 
160
    emit runningChanged();
162
161
}
163
162
 
164
163
void StopwatchEngine::setPreviousTimeOfStopwatch(int value)