-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfileio.cpp
196 lines (163 loc) · 5.57 KB
/
fileio.cpp
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
192
193
194
195
196
#include "fileio.h"
#include "schedulemodel.h"
#include "schedules.h"
#include <QFile>
#include <QDir>
#include <QSettings>
#include <QString>
#include <QDateTime>
#include <QTime>
#include <QList>
#include <QDebug>
FileIO::FileIO(QObject *parent) :
QObject(parent)
{
}
bool FileIO::ExtractAudio()
{
if(QFile::copy(":/new/sounds/alarm.ogg", QDir::tempPath()+"/QTalarm.ogg"))
{
return true;
}
return false;
}
bool FileIO::DelExtracted()
{
return QFile::remove(QDir::tempPath()+"/QTalarm.ogg");
}
QList<ScheduleModel*> FileIO::LoadConfig()
{
QList<ScheduleModel*> scheduleList;
QString indexStr;
qInfo() << "Loading Config values";
for(int index=0;index<this->_Settings.value("AlarmCount").toInt();index++)
{
ScheduleModel *sched=new ScheduleModel(this);
indexStr.setNum(index);
sched->AlarmTime = this->_Settings.value(indexStr+"Time").toTime();
if(sched->AlarmTime.isNull())
{
QTime reset;
reset.setHMS(0,0,0,0);
sched->AlarmTime = reset;
}
sched->isMonEnabled = this->_Settings.value(indexStr+"MonEnabled").toBool();
sched->isTueEnabled = this->_Settings.value(indexStr+"TueEnabled").toBool();
sched->isWedEnabled = this->_Settings.value(indexStr+"WedEnabled").toBool();
sched->isThurEnabled = this->_Settings.value(indexStr+"ThurEnabled").toBool();
sched->isFriEnabled = this->_Settings.value(indexStr+"FriEnabled").toBool();
sched->isSatEnabled = this->_Settings.value(indexStr+"SatEnabled").toBool();
sched->isSunEnabled = this->_Settings.value(indexStr+"SunEnabled").toBool();
sched->isBastard = this->_Settings.value(indexStr+"Bastard").toBool();
sched->isCustomAlarmEnabled = this->_Settings.value(indexStr+"CustEnabled").toBool();
sched->CustomAlarm = this->_Settings.value(indexStr+"CustDate").toDate();
sched->isCustomSoundEnabled = this->_Settings.value(indexStr+"CustomSoundEnabled").toBool();
sched->CustomSoundPath = this->_Settings.value(indexStr+"CustomSound").toString();
sched->Index = index;
sched->isOneshot = this->_Settings.value(indexStr+"isOneshot").toBool();
scheduleList.append(sched);
}
return scheduleList;
}
bool FileIO::Save(Schedules *Collection)
{
try
{
QList<ScheduleModel*> SchedList=Collection->GetScheduleList();
ScheduleModel *currentSche;
int index=0;
this->_Settings.setValue("AlarmCount",SchedList.count());
qInfo() << "Saving settings";
foreach(currentSche,SchedList)
{
QString IndexStr;
IndexStr.setNum(index);
this->_Settings.setValue(IndexStr+"MonEnabled",currentSche->isMonEnabled);
this->_Settings.setValue(IndexStr+"TueEnabled",currentSche->isTueEnabled);
this->_Settings.setValue(IndexStr+"WedEnabled",currentSche->isWedEnabled);
this->_Settings.setValue(IndexStr+"ThurEnabled",currentSche->isThurEnabled);
this->_Settings.setValue(IndexStr+"FriEnabled",currentSche->isFriEnabled);
this->_Settings.setValue(IndexStr+"SatEnabled",currentSche->isSatEnabled);
this->_Settings.setValue(IndexStr+"SunEnabled",currentSche->isSunEnabled);
this->_Settings.setValue(IndexStr+"Bastard",currentSche->isBastard);
this->_Settings.setValue(IndexStr+"Time",currentSche->AlarmTime);
this->_Settings.setValue(IndexStr+"CustEnabled",currentSche->isCustomAlarmEnabled);
this->_Settings.setValue(IndexStr+"CustDate",currentSche->CustomAlarm);
this->_Settings.setValue(IndexStr+"CustomSoundEnabled",currentSche->isCustomSoundEnabled);
this->_Settings.setValue(IndexStr+"CustomSound",currentSche->CustomSoundPath);
this->_Settings.setValue(IndexStr+"isOneshot",currentSche->isOneshot);
this->_Settings.sync();
index++;
}
}
catch(...)
{
return false;
}
return true;
}
//static lazy loaded methods
int FileIO::LoadVolume()
{
QSettings settings;
return settings.value("Volume").toInt();
}
void FileIO::SaveVolume(int vol)
{
QSettings settings;
settings.setValue("Volume",vol);
}
bool FileIO::LoadWindowShow()
{
QSettings settings;
if(!settings.contains("ShowWindowDefault"))
{
return true;
}
return settings.value("ShowWindowDefault").toBool();
}
void FileIO::SaveWindowShow(bool showWindow)
{
QSettings settings;
settings.setValue("ShowWindowDefault",showWindow);
}
bool FileIO::isMilTime()
{
QSettings settings;
return settings.value("isMilTime").toBool();
}
bool FileIO::LoadisMono()
{
QSettings settings;
return settings.value("isMono").toBool();
}
void FileIO::SaveisMono(bool isMono)
{
QSettings settings;
settings.setValue("isMono",isMono);
}
void FileIO::SaveisMilTime(bool isMilTime)
{
QSettings settings;
settings.setValue("isMilTime",isMilTime);
}
bool FileIO::LoadWarnOnPm()
{
QSettings settings;
return settings.value("WarnOnPm").toBool();
}
bool FileIO::LoadSeenSolveText()
{
QSettings settings;
return settings.value("SeenSolvedText").toBool();
}
void FileIO::SaveWarnOnPm(bool warn)
{
QSettings settings;
settings.setValue("WarnOnPm",warn);
}
void FileIO::SaveSeenSolveText()
{
QSettings settings;
settings.setValue("SeenSolvedText",true);
}