-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjukeboxconfig.cpp
291 lines (265 loc) · 6.47 KB
/
jukeboxconfig.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "jukeboxconfig.h"
#include "lib/skglib.h"
#include <QFile>
#include <QTextStream>
#include <QErrorMessage>
#include <QDir>
#include <QApplication>
#include <exception>
JukeboxConfig::JukeboxConfig()
{
OperatingMode = modeNone;
CustomListName = "";
Connected = true;
SlidingSound = true;
AnimationEnabled = true;
RandomTrackEnabled = false;
CollectionSize = sizeSmall;
LoadConfigFile();
}
void JukeboxConfig::LoadConfigFile()
{
QFile configfile(ConfigFile());
QString cf = ConfigFile();
QString nextline;
QStringList parts;
QString key;
SKG_MusicLibrary *lib;
QDir *musicdir;
QErrorMessage errormsg;
SplashForm = new frmSplash;
bool x;
errorType = configErrorTypeNone;
lib = NULL;
x=configfile.exists();
if (!configfile.open(QIODevice::ReadOnly | QIODevice::Text))
{
//errormsg.showMessage("Unable to open config file");
//return;
SplashForm->ShowFirstTime();
MusicDirectories.append(SplashForm->GetMusicDirectory());
if (SplashForm->NormalSelected())
OperatingMode = modeNormal;
else
OperatingMode = modeNetbook;
if (SplashForm->Connected())
Connected = true;
else
Connected = false;
if (SplashForm->LargeSelected())
CollectionSize = sizeLarge;
else
CollectionSize = sizeSmall;
SaveConfigFile();
//delete SplashForm;
return;
}
SplashForm->ShowLoading();
QTextStream instream(&configfile);
while (!instream.atEnd())
{
nextline = instream.readLine();
parts = nextline.split("|");
key = QString(parts.at(0)).trimmed().toUpper();
if (key == "MODE")
{
if (QString(parts.at(1)).trimmed().toUpper() == "NETBOOK")
OperatingMode = modeNetbook;
else if (QString(parts.at(1)).trimmed().toUpper() == "NORMAL")
OperatingMode = modeNormal;
else
{
OperatingMode = modeNone;
errorType = configErrorTypeInvalidMode;
errormsg.showMessage("Invalid Operating Mode. Please fix the config file");
}
}
else if (key == "MUSICDIR")
{
//if (lib == NULL)
// lib = new SKG_MusicLibrary();
try
{
MusicDirectories.append(parts.at(1));
musicdir = new QDir(QString(parts.at(1)).trimmed());
if (musicdir->exists())
{
//lib->AddDirectory(musicdir);
}
}
catch (...)
{
errormsg.showMessage(QString("Unable to add directory %1").arg(parts.at(1)));
errorType = configErrorTypeMusicLibrary;
}
}
else if (key == "CUSTOMLIST")
{
CustomListName = QString(parts.at(1)).trimmed();
}
else if (key == "CONNECTED")
{
if (parts.at(1).toUpper() == "F")
Connected = false;
}
else if (key == "SIZE")
{
if (parts.at(1).toUpper() == "L")
CollectionSize = sizeLarge;
else if(parts.at(1).toUpper() == "S")
CollectionSize = sizeSmall;
}
else if (key == "SLIDINGSOUND")
{
if (parts.at(1).toUpper() == "F")
SlidingSound = false;
else
SlidingSound = true;
}
else if (key == "ANIMATION")
{
if (parts.at(1).toUpper() == "F")
AnimationEnabled = false;
else
AnimationEnabled = true;
}
else if (key == "RANDOMTRACK")
{
if (parts.at(1).toUpper() == "F")
RandomTrackEnabled = false;
else
RandomTrackEnabled = true;
}
}
configfile.close();
}
void JukeboxConfig::DeleteDirectory(QString dirname)
{
int i;
for(i = 0; i < MusicDirectories.count(); i++)
{
if (MusicDirectories.at(i) == dirname)
MusicDirectories.removeAt(i);
}
}
void JukeboxConfig::SaveConfigFile()
{
QString line;
int i;
QFile file(ConfigFile());
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
if (OperatingMode == modeNetbook)
line = "mode|netbook\n";
else
line = "mode|normal\n";
file.write(line.toAscii());
for (i = 0; i < MusicDirectories.count(); i++)
{
line = "musicdir|" + MusicDirectories.at(i) + "\n";
file.write(line.toAscii());
}
//
if (CustomListName != "")
{
line = "customlist|" + CustomListName + "\n";
file.write(line.toAscii());
}
//
if (Connected)
{
line = "connected|T\n";
}
else
{
line = "connected|F\n";
}
file.write(line.toAscii());
//
if (SlidingSound)
{
line = "SlidingSound|T\n";
}
else
{
line = "SlidingSound|F\n";
}
file.write(line.toAscii());
//
if (AnimationEnabled)
{
line = "Animation|T\n";
}
else
{
line = "Animation|F\n";
}
file.write(line.toAscii());
//
if (RandomTrackEnabled)
{
line = "RandomTrack|T\n";
}
else
{
line = "RandomTrack|F\n";
}
file.write(line.toAscii());
//
if (CollectionSize == sizeLarge)
{
line = "size|L";
}
else
{
line = "size|S";
}
file.write(line.toAscii());
file.close();
}
void JukeboxConfig::KillSplashForm()
{
SplashForm->close();
delete SplashForm;
}
QString ResourcesDirectory()
{
QString tmpstr;
tmpstr = QApplication::applicationDirPath();
if (tmpstr.right(1) != "/")
tmpstr = tmpstr + "/";
tmpstr = tmpstr + "resources";
QDir d(tmpstr);
if (d.exists())
return tmpstr;
else
return "C:/SKG_Jukebox/resources";
}
QString UpArrow()
{
return ResourcesDirectory() + "/arrow-bold-up.jpg";
}
QString DownArrow()
{
return ResourcesDirectory() + "/arrow-bold-down.jpg";
}
QString LeftArrow()
{
return ResourcesDirectory() + "/arrow-bold-left.jpg";
}
QString RightArrow()
{
return ResourcesDirectory() + "/arrow-bold-right.jpg";
}
QString ConfigFile()
{
return ResourcesDirectory() + "/Config.txt";
}
QString TrackListFile()
{
return ResourcesDirectory() + "/TrackList.txt";
}
QString LibraryFile()
{
return ResourcesDirectory() + "/Library.xml";
}