-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.cpp
525 lines (352 loc) · 12 KB
/
config.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
/**
* -----------------------------------------------------
* File config.cpp
* Authors David Ordnung, Impact
* License GPLv3
* Web http://dordnung.de, http://gugyclan.eu
* -----------------------------------------------------
*
* Copyright (C) 2013-2017 David Ordnung, Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
// c++
#include <sstream>
// Include Project
#include "config.h"
#include "call.h"
#include "log.h"
#include "main.h"
#include "opensteam.h"
#include "taskbar.h"
#include "calladmin-client.h"
// Wx
#include <wx/statline.h>
#include <wx/stdpaths.h>
#include <wx/gbsizer.h>
// Settings
int step = 5;
int timeout = 3;
int maxAttempts = 3;
int lastCalls = 25;
wxString page = "";
wxString key = "";
// Steam Enabled?
bool steamEnabled = true;
bool hideOnMinimize = false;
// The config
wxConfig *g_config = NULL;
// Button ID's for Config Panel
enum
{
wxID_SetConfig = wxID_HIGHEST+400,
wxID_SteamUpdate,
wxID_HideUpdate,
};
// Button Events for Config Panel
BEGIN_EVENT_TABLE(ConfigPanel, wxPanel)
EVT_BUTTON(wxID_SetConfig, ConfigPanel::OnSet)
EVT_CHECKBOX(wxID_SteamUpdate, ConfigPanel::OnCheckBox)
EVT_CHECKBOX(wxID_HideUpdate, ConfigPanel::OnCheckBox2)
END_EVENT_TABLE()
// Create Config Panel
ConfigPanel::ConfigPanel(wxNotebook* note) : wxPanel(note, wxID_ANY)
{
// Current Position
int currentPos = 1;
// Create Box
wxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL);
// Grid
wxGridBagSizer *gridSizer = new wxGridBagSizer(10, 2);
gridSizer->AddGrowableCol(0);
// Flags and Text
wxSizerFlags flags;
wxStaticText* text;
// Border and Centre
flags.Border(wxALL &~ wxBOTTOM, 10);
flags.Centre();
// Add Grid
sizerTop->Add(gridSizer, 1, wxALL | wxEXPAND, 10);
// Ask for Page
text = new wxStaticText(this, wxID_ANY, "Your url to the call admin directory: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
pageText = new wxTextCtrl(this, wxID_ANY, "http://yourpage.com/calladmin/", wxDefaultPosition, wxSize(300, -1));
pageText->SetMaxLength(256);
pageText->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(pageText, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Ask for Key
text = new wxStaticText(this, wxID_ANY, "Your private access key: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
keyText = new wxTextCtrl(this, wxID_ANY, "accesskey");
keyText->SetMaxLength(64);
keyText->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(keyText, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Static line
gridSizer->Add(new wxStaticLine(this, wxID_ANY), wxGBPosition(currentPos++, 0), wxGBSpan(1, 2), wxEXPAND | (wxALL &~ wxLEFT &~ wxRIGHT), 10);
// Ask for Step
text = new wxStaticText(this, wxID_ANY, "Time intervall to search for calls (in seconds): ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
stepSlider = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS | wxALIGN_RIGHT, 5, 20, 10, "Time Inverall");
stepSlider->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(stepSlider, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Ask for Timeout
text = new wxStaticText(this, wxID_ANY, "Timeout for connection (in seconds): ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
timeoutSlider = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS | wxALIGN_RIGHT, 3, 10, 5, "Timeout");
timeoutSlider->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(timeoutSlider, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Ask for Attempts
text = new wxStaticText(this, wxID_ANY, "Maximum auto. reconnect attempts: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
attemptsSlider = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS | wxALIGN_RIGHT, 3, 10, 3, "Max Attempts");
attemptsSlider->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(attemptsSlider, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Ask for Last Calls
text = new wxStaticText(this, wxID_ANY, "Number of last calls to load at start: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
callsSlider = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS | wxALIGN_RIGHT, 0, 50, 25, "Load Calls");
callsSlider->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Grid
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(callsSlider, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxEXPAND);
// Static line
gridSizer->Add(new wxStaticLine(this, wxID_ANY), wxGBPosition(currentPos++, 0), wxGBSpan(1, 2), wxEXPAND | (wxALL &~ wxLEFT &~ wxRIGHT), 10);
// Ask for Steam
text = new wxStaticText(this, wxID_ANY, "Steam support to write messages and load Avatars: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Steam support
steamEnable = new wxCheckBox(this, wxID_SteamUpdate, "Enable Steam Support");
steamEnable->SetValue(true);
// Add Steam
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(steamEnable, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxRIGHT);
// Ask for hide on mini
text = new wxStaticText(this, wxID_ANY, "Hide windows on minimize: ");
text->SetFont(wxFont(11, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add
hideMini = new wxCheckBox(this, wxID_HideUpdate, "Hide on Minimize");
hideMini->SetValue(false);
// Add Hide on minimize
gridSizer->Add(text, wxGBPosition(currentPos, 0), wxDefaultSpan, 0, 10);
gridSizer->Add(hideMini, wxGBPosition(currentPos++, 1), wxDefaultSpan, wxRIGHT);
wxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL);
// Hide and Exit Button
sizerBtns->Add(new wxButton(this, wxID_SetConfig, "Update Settings"), flags.Border(wxALL, 5));
// Add Buttons to Box
sizerTop->Add(sizerBtns, flags.Align(wxALIGN_CENTER_HORIZONTAL));
// Auto Size
SetSizerAndFit(sizerTop, true);
// Parse Config
parseConfig();
}
// Steam Updated -> Set Config
void ConfigPanel::OnCheckBox(wxCommandEvent& WXUNUSED(event))
{
// Read config value
if (steamEnable != NULL && g_config != NULL)
{
steamEnabled = steamEnable->GetValue();
// Write to config file
g_config->Write("steam", steamEnabled);
// Log Action
LogAction("Changed Steam Status");
}
}
// Hide On Minimize Updated -> Set Config
void ConfigPanel::OnCheckBox2(wxCommandEvent& WXUNUSED(event))
{
// Read config value
if (hideMini != NULL && g_config != NULL)
{
hideOnMinimize = hideMini->GetValue();
// Write to config file
g_config->Write("hideonminimize", hideOnMinimize);
// Log Action
LogAction("Changed Hide on Minimize Status");
}
}
// Button Event -> Try to set new config
void ConfigPanel::OnSet(wxCommandEvent& WXUNUSED(event))
{
// Valid?
if (hideMini == NULL || timeoutSlider == NULL || stepSlider == NULL || attemptsSlider == NULL || lastCalls == NULL || pageText == NULL || keyText == NULL || g_config == NULL || main_dialog == NULL || notebook == NULL)
{
return;
}
// Read config values
timeout = timeoutSlider->GetValue();
step = stepSlider->GetValue();
maxAttempts = attemptsSlider->GetValue();
lastCalls = callsSlider->GetValue();
page = pageText->GetValue();
key = keyText->GetValue();
// Write to new config file
g_config->Write("step", step);
g_config->Write("timeout", timeout);
g_config->Write("attempts", maxAttempts);
g_config->Write("lastcalls", lastCalls);
g_config->Write("page", page);
g_config->Write("key", key);
// Refresh main dialog
main_dialog->SetTitle("Call Admin Client");
main_dialog->setEventText("Enable new Settings...");
// Log Action
LogAction("Saved the config");
// Goto Main
notebook->SetSelection(0);
// Parse again
parseConfig();
}
// parse Config
void ConfigPanel::parseConfig()
{
// Valid?
if (hideMini == NULL || timeoutSlider == NULL || stepSlider == NULL || attemptsSlider == NULL || lastCalls == NULL || pageText == NULL || keyText == NULL || g_config == NULL || main_dialog == NULL)
{
return;
}
bool foundConfigError = false;
// Log Action
LogAction("Parse the config");
// Was parsing good?
if (!g_config->Exists("page") || !g_config->Exists("key"))
{
foundConfigError = true;
}
else
{
// Get files out of config
try
{
step = g_config->ReadLong("step", 5l);
timeout = g_config->ReadLong("timeout", 3l);
maxAttempts = g_config->ReadLong("attempts", 5l);
lastCalls = g_config->ReadLong("lastcalls", 25l);
steamEnabled = g_config->ReadBool("steam", true);
hideOnMinimize = g_config->ReadBool("hideonminimize", false);
g_config->Read("page", &page, "");
// Strip last /
int lastSlash = page.find_last_of("/");
int length = page.length() - 1;
if (lastSlash == length)
{
// Delete it
page.RemoveLast();
}
g_config->Read("key", &key, "");
}
catch(...) {foundConfigError = true;}
}
// Everything good?
if (!foundConfigError)
{
// Check invalid values
if (step < 5)
{
step = 5;
}
if (step > 20)
{
step = 20;
}
if (timeout < 3)
{
timeout = 3;
}
if (timeout > 10)
{
timeout = 10;
}
if (maxAttempts < 3)
{
maxAttempts = 3;
}
if (maxAttempts > 10)
{
maxAttempts = 10;
}
if (lastCalls < 0)
{
lastCalls = 0;
}
if (lastCalls > 50)
{
lastCalls = 50;
}
if (timeout >= step)
{
timeout = step - 1;
}
// Set Config Values
timeoutSlider->SetValue(timeout);
stepSlider->SetValue(step);
attemptsSlider->SetValue(maxAttempts);
callsSlider->SetValue(lastCalls);
pageText->SetValue(page);
keyText->SetValue(key);
steamEnable->SetValue(steamEnabled);
hideMini->SetValue(hideOnMinimize);
// Calls are unimportant
for (int i=0; i < MAXCALLS; i++)
{
if (call_dialogs[i] != NULL)
{
// Stop Avatar Timer
if (call_dialogs[i]->avatarTimer != NULL && call_dialogs[i]->avatarTimer->IsRunning())
{
call_dialogs[i]->avatarTimer->Stop();
}
call_dialogs[i]->Destroy();
call_dialogs[i] = NULL;
}
}
// Timer... STOP!
if (timer != NULL)
{
timer->Stop();
timer = NULL;
}
// Log Action
LogAction("Loaded the config");
// Updated Main Interface
main_dialog->resetCalls();
// First Start again ;D
timerStarted = false;
// Start Timer
timer = new Timer();
timer->run(step*1000);
// Reset Attempts
attempts = 0;
// Start Steam Thread
steamThreader = new steamThread();
}
else
{
// Refresh main dialog
main_dialog->SetTitle("Call Admin Client");
main_dialog->setEventText("Please configurate your settings...");
// Log Action
LogAction("Couldn't load/find the config");
}
}