-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmarttimerlog.cpp
More file actions
191 lines (151 loc) · 4.4 KB
/
smarttimerlog.cpp
File metadata and controls
191 lines (151 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "smarttimerlog.h"
#include "timerwidget.h"
#include "widgetsettings.h"
#include "widgetsettings.h"
#include <iostream>
#include <fstream>
#include <QTextStream>
#include <QUrl>
#include <QString>
#include <QJsonDocument>
smartTimerLog::smartTimerLog(QObject *parent) : par(parent)
{
this->par = parent;
connect(par, SIGNAL(del(QList<TimerWidget*>,QList<alertwidget*>,GlobalSettings)), this, SLOT(saveLog(QList<TimerWidget*>,QList<alertwidget*>,GlobalSettings)));
}
void smartTimerLog::runLogger()
{
int tim;
std::string tmpstr;
QString str;
bool turned;
int boolTmp;
QString signalPath;
QFile logFile("save.txt");
if (!logFile.exists())
return;
if (!logFile.open(QIODevice::ReadOnly))
{
// std::cerr << "Can't open log file." << std::endl;
return;
}
QTextStream stream( &logFile );
while(!stream.atEnd())
{
stream >> tim >> str >> signalPath;
if (str != "")
{
str = toLoadFormat(str);
emit createTimer(WidgetSettings(tim,str,true,toLoadFormat(signalPath)));
}
}
logFile.close();
// alarm part
QFile logFile2("saveA.txt");
if (!logFile2.exists())
return;
if (!logFile2.open(QIODevice::ReadOnly))
{
// std::cerr << "Can't open log file." << std::endl;
return;
}
QTextStream stream2( &logFile2 );
while(!stream2.atEnd())
{
stream2 >> tim >> str >> boolTmp >> signalPath;
turned = boolTmp;
if (str != "")
{
str = toLoadFormat(str);
emit createAlarm(WidgetSettings(tim,str,turned,toLoadFormat(signalPath)));
}
}
logFile2.close();
// global settings
QFile logFile3("saveSettings.txt");
if (!logFile3.exists())
return;
if (!logFile3.open(QIODevice::ReadOnly))
{
// std::cerr << "Can't open log file." << std::endl;
return;
}
QTextStream stream3( &logFile3 );
double opacity;
QString alarmFormat;
QString timerFormat;
int DDenable;
int DDmin;
int DDmax;
stream3 >> opacity >> alarmFormat >> timerFormat >> DDenable >> DDmin >> DDmax;
emit createSettings(GlobalSettings(opacity,toLoadFormat(alarmFormat), toLoadFormat(timerFormat),static_cast<bool>(DDenable),DDmin,DDmax));
logFile3.close();
}
void smartTimerLog::saveLog(QList<TimerWidget*> timers, QList<alertwidget*> alarms, GlobalSettings settings)
{
int tim;
std::string tmpstr;
QString str;
bool turned;
QString signalPath;
QFile logFile("save.txt");
if (!logFile.open(QIODevice::WriteOnly))
{
std::cerr << "Log file can't be created.";
}
QTextStream stream( &logFile );
for (auto timer : timers)
{
tim = timer->getTimerDuration();
str = timer->getTimerName();
str = toSaveFormat(str);
signalPath = toSaveFormat(timer->getSettings().signalPath);
stream << tim << " " << str << " " << signalPath << " \n";
}
logFile.close();
// alarm part
QFile logFile2("saveA.txt");
if (!logFile2.open(QIODevice::WriteOnly))
{
std::cerr << "Log file can't be created.";
}
QTextStream stream2( &logFile2 );
for (auto alarm : alarms)
{
tim = alarm->getAlertTime();
str = alarm->getName();
turned = alarm->getState();
signalPath = toSaveFormat(alarm->getSettings().signalPath);
str = toSaveFormat(str);
stream2 << tim << " " << str << " " << static_cast<int>(turned) << " " << signalPath << " \n";
}
logFile2.close();
// Global settings
QFile logFile3("saveSettings.txt");
if (!logFile3.open(QIODevice::WriteOnly))
{
std::cerr << "Log file can't be created.";
}
QTextStream stream3( &logFile3 );
stream3 << settings.windowOpacity << " \n";
stream3 << toSaveFormat(settings.alarmTimeFormat) << " \n";
stream3 << toSaveFormat(settings.timerTimeFormat) << " \n";
stream3 << settings.DDenabled << " " << settings.DDstart << " " << settings.DDend << " \n";
logFile3.close();
}
QString smartTimerLog::toLoadFormat(const QString &str)
{
if (str == "&")
return "";
QString res = str;
res.replace("*"," ");
return res;
}
QString smartTimerLog::toSaveFormat(const QString &str)
{
if (str == "")
return "&";
QString res = str;
res.replace(" ","*");
return res;
}