-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
526 lines (328 loc) · 10.5 KB
/
main.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
526
/**
* -----------------------------------------------------
* File main.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++ lib
#include <sstream>
// Include Project
#include "main.h"
#include "log.h"
#include "about.h"
#include "trackers.h"
#include "taskbar.h"
#include "config.h"
#include "calladmin-client.h"
// Wx
#include <wx/statline.h>
#include <wx/listbox.h>
#include <wx/tooltip.h>
// Main Dialog
MainDialog *main_dialog = NULL;
// Notebook
wxNotebook* notebook = NULL;
// Button Events for Main Dialog
BEGIN_EVENT_TABLE(MainDialog, wxDialog)
EVT_BUTTON(wxID_Hide, MainDialog::OnHide)
EVT_BUTTON(wxID_Reconnect, MainDialog::OnReconnect)
EVT_CHECKBOX(wxID_CheckBox, MainDialog::OnCheckBox)
EVT_COMMAND(wxID_ThreadHandled, wxEVT_COMMAND_MENU_SELECTED, MainDialog::OnThread)
EVT_COMMAND(wxID_SteamChanged, wxEVT_COMMAND_MENU_SELECTED, MainDialog::OnSteamChange)
EVT_CLOSE(MainDialog::OnCloseWindow)
EVT_ICONIZE(MainDialog::OnMinimizeWindow)
EVT_LISTBOX_DCLICK(wxID_BoxClick, MainDialog::OnBoxClick)
END_EVENT_TABLE()
// Create Main Window
void MainDialog::createWindow(bool taskbar)
{
// Create Notebook and panel
notebook = new wxNotebook(this, wxID_ANY);
// Valid?
if (notebook == NULL)
{
return;
}
panel = new wxPanel(notebook, wxID_ANY);
// Valid?
if (panel == NULL)
{
return;
}
// Add Main Page
notebook->AddPage(panel, ("Main"));
// Border and Center
wxSizerFlags flags;
wxStaticText* text;
// Hole Body
sizerBody = new wxBoxSizer(wxHORIZONTAL);
// Box Body
wxStaticBoxSizer* sizerBox = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, wxT("Latest Calls")), wxHORIZONTAL);
// Box for all Calls
callBox = new wxListBox(panel, wxID_BoxClick, wxDefaultPosition, wxSize(280, -1), 0, NULL, wxLB_HSCROLL | wxLB_SINGLE);
callBox->SetFont(wxFont(9, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add to Body
sizerBox->Add(callBox, 0, wxEXPAND | wxALL, 5);
sizerBody->Add(sizerBox, 0, wxEXPAND | wxALL, 5);
// Create Box
wxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL);
// Border and Centre
flags.Border(wxALL, 10);
flags.Centre();
// Space
sizerTop->Add(0, 0, 0, wxBOTTOM, 15);
// Welcome Text
text = new wxStaticText(panel, wxID_ANY, "The Admin Caller");
text->SetFont(wxFont(30, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add it
sizerTop->Add(text, flags.Border(wxALL &~ wxTOP, 40));
// Restore Border
flags.Border(wxALL, 10);
// Space
sizerTop->Add(0, 0, 0, wxTOP, 20);
// Static line
sizerTop->Add(new wxStaticLine(panel, wxID_ANY), 0, wxEXPAND | wxALL, 5);
// Steam Text
steamText = new wxStaticText(panel, wxID_ANY, "Steam is currently not running");
steamText->SetFont(wxFont(16, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
steamText->SetForegroundColour(wxColor("red"));
// Add it
sizerTop->Add(steamText, flags);
// Static line
sizerTop->Add(new wxStaticLine(panel, wxID_ANY), 0, wxEXPAND | wxALL, 5);
sizerTop->Add(new wxStaticLine(panel, wxID_ANY), 0, wxEXPAND | wxALL, 5);
eventText = new wxStaticText(panel, wxID_ANY, "Waiting for a new report...");
eventText->SetFont(wxFont(16, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
eventText->SetForegroundColour(wxColor("blue"));
sizerTop->Add(eventText, flags);
// Static line
sizerTop->Add(new wxStaticLine(panel, wxID_ANY), 0, wxEXPAND | wxALL, 5);
// Space
sizerTop->Add(0, 0, 0, wxBOTTOM, 40);
wxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL);
wxSizer* const sizerChecks = new wxBoxSizer(wxHORIZONTAL);
// With tooltip :)
// ToolTip for first Checkbox
wxToolTip* tipAvailable = new wxToolTip("You will receive no more calls when you uncheck this.");
tipAvailable->SetDelay(500);
tipAvailable->Enable(true);
// The available Checkbox
available = new wxCheckBox(panel, wxID_CheckBox, "I'm available");
available->SetValue(g_config->ReadBool("available", true));
available->SetToolTip(tipAvailable);
sizerChecks->Add(available , flags.Border(wxALL, 5));
// ToolTip for second Checkbox
wxToolTip* tipSound = new wxToolTip("You will hear a notification sound on an incoming call.");
tipSound->SetDelay(500);
tipSound->Enable(true);
// The sound Checkbox
sound = new wxCheckBox(panel, wxID_CheckBox, "Sound on call");
sound->SetValue(g_config->ReadBool("sound", true));
sound->SetToolTip(tipSound);
sizerChecks->Add(sound, flags.Border(wxALL, 5));
// ToolTip for third Checkbox
wxToolTip* specAvailable = new wxToolTip("You will only receive calls but you will not be stored in the trackers database");
specAvailable->SetDelay(500);
specAvailable->Enable(true);
// The store Checkbox
store = new wxCheckBox(panel, wxID_CheckBox, "Spectate only");
store->SetValue(g_config->ReadBool("spectate", false));
store->SetToolTip(specAvailable);
sizerChecks->Add(store, flags.Border(wxALL, 5));
// Hide, Check
sizerBtns->Add(new wxButton(panel, wxID_Hide, "Hide"), flags.Border(wxALL &~ wxBOTTOM &~ wxRIGHT, 5));
// If max attempts reached, add a reconnect button
reconnectButton = new wxButton(panel, wxID_Reconnect, "Reconnect");
reconnectButton->Enable(false);
sizerBtns->Add(reconnectButton, flags.Border(wxALL &~ wxBOTTOM &~ wxLEFT, 5));
// Add Checks to Box
sizerTop->Add(sizerChecks, flags.Align(wxALIGN_CENTER_HORIZONTAL));
// Add Buttons to Box
sizerTop->Add(sizerBtns, flags.Align(wxALIGN_CENTER_HORIZONTAL).Border(wxALL &~ wxBOTTOM, 5));
// Author + Version Text
text = new wxStaticText(panel, wxID_ANY, "v" + version + " (c) David Ordnung and Impact");
text->SetFont(wxFont(8, FONT_FAMILY, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add it
sizerTop->Add(text, flags.Align(wxALIGN_RIGHT).Border(wxALL &~ wxBOTTOM, 10));
// Add to Body
sizerBody->Add(sizerTop, flags.Right());
// Auto Size
panel->SetSizerAndFit(sizerBody, true);
// Add Config Page
notebook->AddPage(new ConfigPanel(notebook), ("Settings"));
// Add trackers Page
notebook->AddPage(new TrackerPanel(notebook), ("Trackers"));
// Add Log Page
notebook->AddPage(new LogPanel(notebook), ("Logging"));
// Add about Page
notebook->AddPage(new AboutPanel(notebook), ("About"));
// Log Action
LogAction("Start the main Window");
// Start in taskbar
if (taskbar && m_taskBarIcon != NULL)
{
main_dialog->Show(false);
m_taskBarIcon->ShowMessage("Call Admin Started", "Call Admin started in taskbar", panel);
}
else
{
// Show
Show(true);
}
// Set the Icon
#if defined(__WXMSW__)
SetIcon(wxIcon("calladmin_icon", wxBITMAP_TYPE_ICO_RESOURCE));
#else
wxLogNull nolog;
SetIcon(wxIcon(getAppPath("resources/calladmin_icon.ico"), wxBITMAP_TYPE_ICON));
#endif
// Fit Notebook
notebook->Fit();
// Fit Main
this->Fit();
// Centre to Screen
Centre();
// Update Call List
updateCall();
}
// Button Event -> Hide to Taskbar
void MainDialog::OnHide(wxCommandEvent& WXUNUSED(event))
{
// Log Action
LogAction("Hided Window");
if (m_taskBarIcon != NULL)
{
m_taskBarIcon->ShowMessage("Call Admin", "Call Admin is now in the taskbar!", this);
Show(false);
}
else
{
Iconize(true);
}
}
// Check Box Event -> Write To Config
void MainDialog::OnCheckBox(wxCommandEvent& WXUNUSED(event))
{
g_config->Write("available", available->IsChecked());
g_config->Write("sound", sound->IsChecked());
g_config->Write("spectate", store->IsChecked());
}
// Button Event -> Reconnect
void MainDialog::OnReconnect(wxCommandEvent& WXUNUSED(event))
{
// Log Action
LogAction("Reconnecting...");
// Reset attempts
attempts = 0;
if (main_dialog != NULL)
{
main_dialog->SetTitle("Call Admin Client");
main_dialog->setEventText("Trying to reconnect...");
main_dialog->setReconnectButton(false);
main_dialog->Show(true);
main_dialog->Restore();
}
// Start the Timer again
timer->Start(step*1000);
}
// Thread Handled -> Call Function
void MainDialog::OnThread(wxCommandEvent& event)
{
// Get Content
ThreadData* data = static_cast<ThreadData *>(event.GetClientObject());
// Get Function
callback function = data->getCallback();
// Call it
function(data->getError(), data->getContent(), data->getExtra());
// Delete data
delete data;
}
// Steam Changed -> Set Text
void MainDialog::OnSteamChange(wxCommandEvent& event)
{
// Get Status
int id = event.GetInt();
if (id == 0)
{
main_dialog->setSteamStatus("Steam support is disabled", wxColour("red"));
}
else if (id == 1)
{
main_dialog->setSteamStatus("Steam is currently not running", wxColour("red"));
}
else
{
main_dialog->setSteamStatus("Steam is currently running", wxColour(34, 139, 34));
}
}
// Window Event -> Open Call
void MainDialog::OnBoxClick(wxCommandEvent& WXUNUSED(event))
{
int selection = callBox->GetSelection();
if (call_dialogs != NULL && call_dialogs[selection] != NULL)
{
call_dialogs[selection]->Show(true);
call_dialogs[selection]->Restore();
}
}
// Window Event -> exit programm
void MainDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
exitProgramm();
}
// Window Event -> Hide Window
void MainDialog::OnMinimizeWindow(wxIconizeEvent& WXUNUSED(event))
{
if (hideOnMinimize)
{
// Log Action
LogAction("Hided Window");
if (m_taskBarIcon != NULL)
{
m_taskBarIcon->ShowMessage("Call Admin", "Call Admin is now in the taskbar!", this);
Show(false);
}
else
{
Iconize(true);
}
}
}
// Update Call List
void MainDialog::updateCall()
{
callBox->Clear();
for (int i=0; i < MAXCALLS; i++)
{
if (call_dialogs != NULL && call_dialogs[i] != NULL)
{
int item;
if (call_dialogs[i]->getHandled())
{
item = callBox->Append("F - " + wxString::FromUTF8(call_dialogs[i]->getBoxText()));
}
else
{
item = callBox->Append("U - " + wxString::FromUTF8(call_dialogs[i]->getBoxText()));
}
callBox->SetSelection(item);
}
}
}