-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
1420 lines (1224 loc) · 44.5 KB
/
Copy pathmainwindow.cpp
File metadata and controls
1420 lines (1224 loc) · 44.5 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
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include <QLocale>
#include <QFontDatabase>
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QStandardPaths>
#include <QNetworkRequest>
#include <QNetworkReply>
#include "chatwidget.h"
#include "matchmakingplayerinfo.h"
#include "matchmakingsearchprogresswidget.h"
#include "erostitlebar.h"
#include "util.h"
MainWindow::MainWindow(Eros *eros, QWidget *parent )
: QMainWindow(parent)
{
QFontDatabase::addApplicationFont(":/font/NotoSans-Regular");
QFontDatabase::addApplicationFont(":/font/NotoSans-Bold");
QFontDatabase::addApplicationFont(":/font/NotoSans-Italic");
QFontDatabase::addApplicationFont(":/font/NotoSans-BoldItalic");
QFontDatabase::addApplicationFont(":/font/Gobold");
QFontDatabase::addApplicationFont(":/font/Gobold-bold");
QFontDatabase::addApplicationFont(":/font/Gobold-thin");
QFile version(":/data/version_info");
if(!version.open(QIODevice::ReadOnly))
{
this->local_version_ = 1;
}
else
{
QByteArray data = version.readAll();
QStringList tokens = QString::fromUtf8(data).split('|');
this->local_version_ = tokens[0].toInt();
version.close();
}
ui.setupUi(this);
ui.centralWidget->setMouseTracking(true);
this->setWindowTitle(tr("Alpha Version %1").arg(this->local_version_));
setUiEnabled(false);
this->eros_ = eros;
this->config_ = new Config(this);
this->connection_timer_ = new QTimer(this);
this->matchmaking_timer_ = new QTimer(this);
this->matchmaking_timer_->setInterval(500);
this->matchmaking_start_ = new QTime();
this->matchmaking_result_time_ = new QTime();
this->long_process_start_time_ = new QTime();
this->watcher_ = new DirectoryWatcher(this);
this->watches_ = QList<DirectoryWatch*>();
this->update_checker_nam_ = new QNetworkAccessManager(this);
this->update_timer_ = new QTimer(this);
this->long_process_timer_ = new QTimer(this);
this->tray_icon_ = new QSystemTrayIcon(this);
this->tray_icon_menu_ = new QMenu(this);
this->preview_loader_nam_ = new QNetworkAccessManager(this);
this->preview_cache_ = QMap<QString, QPixmap*>();
this->upload_queue_ = QMap<QString, QTime*>();
this->upload_queue_timer_ = new QTimer(this);
tray_icon_action_show_ = new QAction("Hide Eros", this);
tray_icon_action_close_ = new QAction("Close Eros", this);
QObject::connect(tray_icon_action_show_, SIGNAL(triggered()), this, SLOT(toggleWindow()));
QObject::connect(tray_icon_action_close_, SIGNAL(triggered()), qApp, SLOT(quit()));
QObject::connect(this->tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
this->tray_icon_->setIcon(QIcon(":/img/client/icons/icon_32x32"));
this->tray_icon_menu_->addAction(tray_icon_action_show_);
this->tray_icon_menu_->addAction(tray_icon_action_close_);
this->tray_icon_->setContextMenu(this->tray_icon_menu_);
#if !defined(Q_OS_MAC)
title_bar_ = ErosTitleBar::addToLayout(this, ui.verticalLayout);
title_bar_->setMenu(this->tray_icon_menu_);
#endif
// File watcher
QObject::connect(this->watcher_, SIGNAL(added(const QString &, const QString &)), this, SLOT(fileAdded(const QString &, const QString&)));
// Update checker
QObject::connect(update_checker_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(updateCheckerFinished(QNetworkReply*)));
QObject::connect(this->update_timer_, SIGNAL(timeout()), this, SLOT(updateCheckerTimerWorker()));
//Preview loader
QObject::connect(preview_loader_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(previewDownloadFinished(QNetworkReply*)));
// Set up Eros signals
/// Eros Signals
QObject::connect(eros_, SIGNAL(stateChanged(ErosState)), this, SLOT(erosStateChanged(ErosState)));
QObject::connect(eros_, SIGNAL(connectionError(QAbstractSocket::SocketError, const QString)), this, SLOT(erosConnectionError(QAbstractSocket::SocketError, const QString)));
QObject::connect(eros_, SIGNAL(connected()), this, SLOT(erosConnected()));
QObject::connect(eros_, SIGNAL(disconnected()), this, SLOT(erosDisconnected()));
QObject::connect(eros_, SIGNAL(authenticationFailed()), this, SLOT(erosAuthenticationFailed()));
QObject::connect(eros_, SIGNAL(alreadyLoggedIn()), this, SLOT(erosAlreadyLoggedIn()));
QObject::connect(eros_, SIGNAL(broadcastAlert(const QString, int)), this, SLOT(erosBroadcastAlert(const QString, int)));
QObject::connect(eros_, SIGNAL(chatRoomAdded(ChatRoom*)), this, SLOT(erosChatRoomAdded(ChatRoom*)));
QObject::connect(eros_, SIGNAL(chatRoomRemoved(ChatRoom*)), this, SLOT(erosChatRoomRemoved(ChatRoom*)));
QObject::connect(eros_, SIGNAL(chatRoomJoined(ChatRoom*)), this, SLOT(erosChatRoomJoined(ChatRoom*)));
QObject::connect(eros_, SIGNAL(chatRoomLeft(ChatRoom*)), this, SLOT(erosChatRoomLeft(ChatRoom*)));
QObject::connect(eros_, SIGNAL(chatMessageReceieved(User*, const QString)), this, SLOT(erosChatMessageReceieved(User*, const QString)));
QObject::connect(eros_, SIGNAL(localUserUpdated(LocalUser*)), this, SLOT(erosLocalUserUpdated(LocalUser*)));
QObject::connect(eros_, SIGNAL(matchmakingStateChanged(ErosMatchmakingState)), this, SLOT(erosMatchmakingStateChanged(ErosMatchmakingState)));
QObject::connect(eros_, SIGNAL(matchmakingMatchFound(MatchmakingMatch *)), this, SLOT(erosMatchmakingMatchFound(MatchmakingMatch *)));
//QObject::connect(eros_, SIGNAL(regionStatsUpdated(ErosRegion, int)), this, SLOT(erosRegionStatsUpdated(ErosRegion, int)));
QObject::connect(eros_, SIGNAL(statsUpdated(int, int)), this, SLOT(erosStatsUpdated(int, int)));
QObject::connect(eros_, SIGNAL(replayUploadError(ErosError)), this, SLOT(erosReplayUploadError(ErosError)));
QObject::connect(eros_, SIGNAL(replayUploaded()), this, SLOT(erosReplayUploaded()));
QObject::connect(eros_, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(erosUploadProgress(qint64, qint64)));
QObject::connect(eros_, SIGNAL(longProcessStateChanged(ErosLongProcessState)), this, SLOT(erosLongProcessStateChanged(ErosLongProcessState)));
QObject::connect(eros_, SIGNAL(drawRequested()), this, SLOT(erosDrawRequested()));
QObject::connect(eros_, SIGNAL(drawRequestFailed()), this, SLOT(erosDrawRequestFailed()));
QObject::connect(eros_, SIGNAL(noShowRequested()), this, SLOT(erosNoShowRequested()));
QObject::connect(eros_, SIGNAL(noShowRequestFailed()), this, SLOT(erosNoShowRequestFailed()));
QObject::connect(eros_, SIGNAL(acknowledgeLongProcessFailed()), this, SLOT(erosAcknowledgeLongProcessFailed()));
QObject::connect(eros_, SIGNAL(acknowledgedLongProcess()), this, SLOT(erosAcknowledgedLongProcess()));
QObject::connect(eros_, SIGNAL(vetoesUpdated()), this, SLOT(erosVetoesUpdated()));
QObject::connect(eros_, SIGNAL(toggleVetoFailed(Map*,ErosError)), this, SLOT(erosToggleVetoFailed(Map*,ErosError)));
/// Eros Slots
QObject::connect(this, SIGNAL(connectToEros(const QString, const QString, const QString)), eros_, SLOT(connectToEros(const QString, const QString, const QString)));
QObject::connect(this, SIGNAL(disconnectFromEros()), eros_, SLOT(disconnectFromEros()));
QObject::connect(ui.btnRefreshChats, SIGNAL(clicked()), eros_, SLOT(refreshChatRooms()));
QObject::connect(this, SIGNAL(joinChatRoom(ChatRoom *, const QString)), eros_, SLOT(joinChatRoom(ChatRoom *, const QString)));
QObject::connect(this, SIGNAL(leaveChatRoom(ChatRoom *)), eros_, SLOT(leaveChatRoom(ChatRoom *)));
QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegion, int)), eros_, SLOT(queueMatchmaking(ErosRegion, int)));
QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegionList, int)), eros_, SLOT(queueMatchmaking(ErosRegionList, int)));
QObject::connect(this, SIGNAL(dequeueMatchmaking()), eros_, SLOT(dequeueMatchmaking()));
QObject::connect(this, SIGNAL(forfeitMatchmaking()), eros_, SLOT(forfeitMatchmaking()));
QObject::connect(this, SIGNAL(uploadReplay(QIODevice*)), eros_, SLOT(uploadReplay(QIODevice*)));
QObject::connect(this, SIGNAL(uploadReplay(const QString)), eros_, SLOT(uploadReplay(const QString)));
QObject::connect(this, SIGNAL(requestDraw()), eros_, SLOT(requestDraw()));
QObject::connect(this, SIGNAL(requestNoShow()), eros_, SLOT(requestNoShow()));
QObject::connect(this, SIGNAL(acknowledgeLongProcess(bool)), eros_, SLOT(acknowledgeLongProcess(bool)));
QObject::connect(this, SIGNAL(toggleVeto(Map*)), eros_, SLOT(toggleVeto(Map*)));
// timers
QObject::connect(this->connection_timer_, SIGNAL(timeout()), this, SLOT(connectionTimerWorker()));
QObject::connect(this->matchmaking_timer_, SIGNAL(timeout()), this, SLOT(matchmakingTimerWorker()));
QObject::connect(this->long_process_timer_, SIGNAL(timeout()), this, SLOT(longProcessTimerWorker()));
QObject::connect(this->upload_queue_timer_, SIGNAL(timeout()), this, SLOT(uploadTimerWorker()));
this->long_process_timer_->setInterval(250);
// UI Stuff
settings_window_ = nullptr;
bnetsettings_window_ = nullptr;
// Remove the close box from the first 2 tabs.
// On mac it's LeftSide. Assuming RightSide causes a nullptr.
for (int i = 0; i < 3; i++)
{
QWidget *tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::RightSide);
if (tab != nullptr)
tab->resize(0, 0);
tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::LeftSide);
if (tab != nullptr)
tab->resize(0, 0);
}
ui.tabContainer->tabBar()->setUsesScrollButtons(true);
QObject::connect(ui.tabContainer, SIGNAL(tabCloseRequested(int)), this, SLOT(tabContainer_tabCloseRequested(int)));
QObject::connect(ui.tabContainer, SIGNAL(currentChanged(int)), this, SLOT(tabContainer_currentChanged(int)));
QObject::connect(ui.lblBottomMenu, SIGNAL(linkActivated(const QString &)), this, SLOT(label_linkActivated(const QString&)));
QObject::connect(ui.btnJoinRoom, SIGNAL(clicked()), this, SLOT(btnJoinRoom_pressed()));
QObject::connect(ui.lstChats, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstChats_currentItemChanged(QListWidgetItem *, QListWidgetItem *)));
QObject::connect(ui.lstChats, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(lstChats_itemDoubleClicked(QListWidgetItem*)));
QObject::connect(ui.cmbRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbRegion_currentIndexChanged(int)));
QObject::connect(ui.cmbMapRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbMapRegion_currentIndexChanged(int)));
QObject::connect(ui.btnQueue, SIGNAL(clicked()), this, SLOT(btnQueue_pressed()));
QObject::connect(ui.btnDraw, SIGNAL(clicked()), this, SLOT(btnDraw_pressed()));
QObject::connect(ui.btnNoShow, SIGNAL(clicked()), this, SLOT(btnNoShow_pressed()));
QObject::connect(ui.lstMaps, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstMaps_currentItemChanged(QListWidgetItem *, QListWidgetItem *)));
QObject::connect(ui.btnToggleVeto, SIGNAL(clicked()), this, SLOT(btnToggleVeto_clicked()));
QObject::connect(ui.chkQueueRegion, SIGNAL(stateChanged(int)), this, SLOT(chkQueueRegion_stateChanged(int)));
#if !defined(Q_OS_MAC)
this->tray_icon_->show();
#endif
// The user should be prevented from emptying invalid values in the settings dialog.
if (this->config_->profiles().count() == 0)
{
QMessageBox::information(this, "Eros", tr("Welcome to Eros! You need to configure some settings in order to continue. The settings window will now open."));
openSettings();
}
else
{
this->connection_timer_->setInterval(500);
this->connection_timer_->start();
}
QTimer::singleShot(0, this, SLOT(updateCheckerTimerWorker()));
this->update_timer_->setInterval(1000 * 60 * 10);
this->update_timer_->start();
notification_sound_ = new QSound(":/sound/notification", this);
}
MainWindow::~MainWindow()
{
}
void MainWindow::changeEvent(QEvent* e)
{
if (e != nullptr)
{
switch (e->type())
{
case QEvent::LanguageChange:
ui.retranslateUi(this);
this->setWindowTitle(tr("Alpha Version %1").arg(this->local_version_));
erosStateChanged(this->eros_->state());
if (this->eros_->state() == ErosState::ConnectedState)
erosConnected();
break;
}
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
#if !defined(Q_OS_MAC)
this->title_bar_->mouseMoveEvent(e);
#endif
}
void MainWindow::mousePressEvent(QMouseEvent *e)
{
#if !defined(Q_OS_MAC)
this->title_bar_->mousePressEvent(e);
#endif
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
#if !defined(Q_OS_MAC)
this->title_bar_->mouseReleaseEvent(e);
#endif
}
void MainWindow::uploadTimerWorker()
{
QMutableMapIterator<QString, QTime*> i(this->upload_queue_);
while (i.hasNext())
{
i.next();
if (i.value()->elapsed() > 5000)
{
emit uploadReplay(i.key());
i.remove();
}
}
}
void MainWindow::longProcessTimerWorker()
{
if (this->eros_->matchmakingMatch() != nullptr)
{
const MatchmakingMatch *match = this->eros_->matchmakingMatch();
int secs;
int mins;
ErosLongProcessState state = this->eros_->longProcessState();
switch (state)
{
case ErosLongProcessState::LongProcessIdle:
secs = match->longProcessUnlockTime() - (this->matchmaking_result_time_->elapsed() / 1000);
if (secs <= 0)
{
this->ui.frmLongProcessInterface->setEnabled(true);
this->ui.frmLongProcessButtons->setEnabled(true);
this->long_process_timer_->stop();
this->ui.lblLongProcess->setText(tr("Abusing these options will result in a ban."));
}
else
{
mins = (secs / 60) % 60;
secs = secs - (mins * 60);
this->ui.lblLongProcess->setText(QString("These options will unlock in %1:%2.").arg(mins,2, 10, QLatin1Char('0')).arg(secs,2,10,QLatin1Char('0')));
}
break;
case ErosLongProcessState::DrawRequest:
case ErosLongProcessState::FlaggedNoShow:
case ErosLongProcessState::OpponentFlaggedDrawRequest:
case ErosLongProcessState::OpponentFlaggedNoShow:
secs = match->longProcessResponseTime() - (this->long_process_start_time_->elapsed() / 1000);
if (secs <= 0)
{
this->ui.frmLongProcessInterface->setEnabled(true);
this->long_process_timer_->stop();
this->ui.lblLongProcess->setText(tr("Response timeout."));
}
else
{
mins = (secs / 60) % 60;
secs = secs - (mins * 60);
if (state == ErosLongProcessState::DrawRequest || state == ErosLongProcessState::FlaggedNoShow)
{
this->ui.lblLongProcess->setText(QString("Request pending. Auto-yes in %1:%2.").arg(mins,2, 10, QLatin1Char('0')).arg(secs,2,10,QLatin1Char('0')));
}
else
{
this->ui.lblLongProcess->setText(QString("Opponent request pending. Auto-yes in %1:%2.").arg(mins,2, 10, QLatin1Char('0')).arg(secs,2,10,QLatin1Char('0')));
}
}
}
}
int elapsed = this->matchmaking_result_time_->elapsed() / 1000;
}
void MainWindow::btnDraw_pressed()
{
emit requestDraw();
}
void MainWindow::btnNoShow_pressed()
{
emit requestNoShow();
}
void MainWindow::erosLongProcessStateChanged(ErosLongProcessState state)
{
switch (state)
{
case ErosLongProcessState::DrawRequest:
case ErosLongProcessState::FlaggedNoShow:
case ErosLongProcessState::OpponentFlaggedDrawRequest:
case ErosLongProcessState::OpponentFlaggedNoShow:
this->long_process_start_time_->restart();
this->long_process_timer_->start();
ui.frmLongProcessButtons->setDisabled(true);
break;
case ErosLongProcessState::LongProcessIdle:
this->ui.lblLongProcess->setText(tr("Abusing these options will result in a ban."));
break;
}
}
void MainWindow::erosDrawRequested()
{
this->showNormal();
this->raise();
this->activateWindow();
this->notification_sound_->setLoops(3);
this->notification_sound_->play();
QMessageBox::StandardButton result = QMessageBox::critical(this, tr("Draw Request"), tr("Your opponent has requested this game be marked as a draw. Do you wish to accept this request? Clicking yes or not responding will result in this game ending in a draw."), QMessageBox::StandardButton::Yes|QMessageBox::StandardButton::No, QMessageBox::StandardButton::No);
bool response = (result == QMessageBox::StandardButton::Yes);
emit acknowledgeLongProcess(response);
}
void MainWindow::erosDrawRequestFailed()
{
ui.lblInformation->setText("Draw request failed.");
}
void MainWindow::erosNoShowRequested()
{
this->showNormal();
this->raise();
this->activateWindow();
this->notification_sound_->setLoops(3);
this->notification_sound_->play();
QMessageBox::StandardButton result = QMessageBox::critical(this, tr("Forfeit Request"), tr("Your opponent has flagged you as a no-show. Do you wish to accept this request? Clicking yes or not responding will result in you forfeiting this game."), QMessageBox::StandardButton::Yes|QMessageBox::StandardButton::No, QMessageBox::StandardButton::No);
bool response = (result == QMessageBox::StandardButton::Yes);
emit acknowledgeLongProcess(response);
}
void MainWindow::erosNoShowRequestFailed()
{
}
void MainWindow::erosAcknowledgeLongProcessFailed()
{
}
void MainWindow::erosAcknowledgedLongProcess()
{
}
void MainWindow::closeEvent(QCloseEvent *event)
{
#if !defined(Q_OS_MAC)
if (this->tray_icon_->isVisible()) {
toggleWindow();
event->ignore();
this->config_->setTrayNotificationShown(true);
this->tray_icon_->showMessage("Eros", tr("Eros is still running in the notification tray. Right click the icon if you want to exit."));
}
#else
QApplication::exit();
#endif
}
void MainWindow::toggleWindow()
{
if(this->isVisible())
{
this->hide();
this->tray_icon_action_show_->setText("Show Eros");
}
else
{
this->showNormal();
this->raise();
this->activateWindow();
this->tray_icon_action_show_->setText("Hide Eros");
}
}
void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::DoubleClick)
toggleWindow();
}
void MainWindow::erosBroadcastAlert(const QString message, int hint)
{
if (hint == 1)
{
QMessageBox::information(this, tr("Server Broadcast Message"), tr("The server is shutting down. %1").arg(message));
}
else if (hint == 2)
{
QMessageBox::information(this, tr("Server Broadcast Message"), tr("You were forfeited from your matchmaking match by an admin. %1").arg(message));
}
else if (hint == 3)
{
QMessageBox::information(this, tr("Server Broadcast Message"), tr("Your opponent was forfeited from your matchmaking match by an admin. %1").arg(message));
}
else if (hint == 4)
{
QMessageBox::information(this, tr("Server Broadcast Message"), tr("Your matchmaking match was ended by an admin. %1").arg(message));
}
else
{
QMessageBox::information(this, tr("Server Broadcast Message"), message);
}
}
void MainWindow::updateCheckerTimerWorker()
{
QUrl url("http://www.starbowmod.com/static/version.txt");
QNetworkReply* reply = this->update_checker_nam_->get(QNetworkRequest(url));
}
void MainWindow::updateCheckerFinished(QNetworkReply* reply)
{
if (reply->error() == QNetworkReply::NoError)
{
QByteArray data = reply->readAll();
QStringList tokens = QString::fromUtf8(data).split('|');
if (tokens.count() == 3)
{
int version = tokens[0].toInt();
if (version > this->local_version_)
{
ui.lblUpdateInfo->setText(tr("<strong>Update:</strong> <a href=\"%1\">%2</a>").arg(tokens[2], tokens[1]));
ui.lblUpdateInfo->setMaximumHeight(8888);
}
}
}
}
void MainWindow::refreshChatRoomList()
{
if (this->eros_->state() == ErosState::ConnectedState)
{
ui.lstChats->clear();
for (int i =0; i < this->eros_->chatRooms().count(); i++)
{
ui.lstChats->addItem(this->eros_->chatRooms()[i]->name());
}
ui.lstChats->sortItems();
}
}
void MainWindow::erosRegionStatsUpdated(ErosRegion region, int count)
{
int regionIndex = ui.cmbRegion->currentData().toInt();
ErosRegion current_region = eros_->activeRegions()[regionIndex];
if (current_region == region)
{
ui.lblRegionStats->setText(tr("%n (person/people) currently queueing on this region.", "", count));
}
}
void MainWindow::erosStatsUpdated(int online, int searching)
{
ui.lblRegionStats->setText(tr("%n (person/people) currently online.", "", online));
}
void MainWindow::erosMatchmakingStateChanged(ErosMatchmakingState status)
{
switch (status)
{
case ErosMatchmakingState::Queued:
setQueueState(true);
break;
case ErosMatchmakingState::Aborted:
case ErosMatchmakingState::Idle:
setQueueState(false);
break;
case ErosMatchmakingState::InvalidRegion:
setQueueState(false);
QMessageBox::warning(this, tr("Eros Matchmaking"), tr("Your queue was aborted because you do not have any verified StarCraft 2 profiles for the selected region."));
break;
}
}
void MainWindow::erosMatchmakingMatchFound(MatchmakingMatch *match)
{
setQueueState(true);
this->matchmaking_result_time_->restart();
this->matchmaking_timer_->stop();
this->long_process_timer_->start();
this->ui.frmLongProcessInterface->setMaximumHeight(400);
ErosRegion region = match->region();
QLayoutItem* item;
while ( ( item = ui.frmMatchmakingOpponent->layout()->takeAt(0)) != NULL )
{
delete item->widget();
delete item;
}
const UserLadderStats *stats = match->opponent()->ladderStatsGlobal();
MatchmakingPlayerInfo *region_info = new MatchmakingPlayerInfo(match->opponent()->username(), match->opponent()->division(), stats, true, this);
ui.frmMatchmakingOpponent->layout()->addWidget(region_info);
ui.lblVS->setText("VS");
ui.lblVS->setMaximumHeight(9999);
QString map = tr("1v1 on <a href=\"starcraft://map/%1/%2\"><img src=\":/img/client/icons/flags/%4\"> %3</a>", "Please keep the link intact.").arg(QString::number((int)region), QString::number(match->mapId()), match->mapName(), Eros::regionToString(region));
ui.lblMapInfo->setText(map);
ui.lblMapInfo->setMaximumHeight(9999);
ui.btnQueue->setText(tr("Forfeit Match"));
this->showNormal();
this->raise();
this->activateWindow();
this->notification_sound_->setLoops(0);
this->notification_sound_->play();
}
void MainWindow::matchmakingTimerWorker()
{
int secs = this->matchmaking_start_->elapsed() / 1000;
int mins = (secs / 60) % 60;
secs = secs - (mins * 60);
ui.lblVS->setText(QString("%1:%2").arg(mins,2, 10, QLatin1Char('0')).arg(secs,2,10,QLatin1Char('0')));
ui.btnQueue->setText(QString("Abort Queue"));
}
void MainWindow::setQueueState(bool queueing)
{
if (queueing)
{
ui.btnQueue->setText(tr("Queued"));
ui.cmbRegion->setDisabled(true);
ui.chkQueueRegion->setDisabled(true);
this->matchmaking_start_->restart();
this->matchmaking_timer_->start();
MatchmakingSearchProgressWidget *search = new MatchmakingSearchProgressWidget(this->eros_->activeUserCount(), this->eros_->searchingUserCount(), this);
QObject::connect(this->eros_, SIGNAL(statsUpdated(int, int)), search, SLOT(statsUpdated(int, int)));
ui.frmMatchmakingOpponent->layout()->addWidget(search);
ui.lblVS->setText("00:00");
ui.lblVS->setMaximumHeight(16777215);
}
else
{
this->long_process_timer_->stop();
this->matchmaking_timer_->stop();
this->ui.frmLongProcessInterface->setMaximumHeight(0);
this->ui.frmLongProcessInterface->setDisabled(true);
ui.cmbRegion->setEnabled(true);
ui.chkQueueRegion->setEnabled(true);
ui.btnQueue->setText(tr("Queue"));
QLayoutItem* item;
while ( ( item = ui.frmMatchmakingOpponent->layout()->takeAt(0)) != NULL )
{
delete item->widget();
delete item;
}
while ( ( item = ui.frmMatchmakingOpponent->layout()->takeAt(0)) != NULL )
{
delete item->widget();
delete item;
}
ui.lblVS->setMaximumHeight(0);
}
ui.btnQueue->setEnabled(true);
ui.lblMapInfo->setText("");
}
void MainWindow::btnQueue_pressed()
{
if (eros_->state() == ErosState::ConnectedState)
{
if (eros_->matchmakingState() == ErosMatchmakingState::Queued)
{
emit dequeueMatchmaking();
}
else if (eros_->matchmakingState() == ErosMatchmakingState::Idle || eros_->matchmakingState() == ErosMatchmakingState::Aborted || eros_->matchmakingState() == ErosMatchmakingState::InvalidRegion)
{
const QList<ErosRegion> ®ions = this->config_->activeProfile()->queueRegions();
if (regions.length() == 0)
{
return;
}
int regionIndex = ui.cmbRegion->currentData().toInt();
ErosRegion region = eros_->activeRegions()[regionIndex];
this->config_->setPreferredRegion(region);
emit queueMatchmaking(regions, this->config_->activeProfile()->searchRange());
ui.btnQueue->setEnabled(false);
}
else if (eros_->matchmakingState() == ErosMatchmakingState::Matched)
{
QMessageBox::StandardButton reply = QMessageBox::warning(this, tr("Confirm Forfeit"), tr("Are you sure you want to forfeit? This will be recorded as a loss for you and a win for your opponent."), QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::StandardButton::Yes)
{
emit forfeitMatchmaking();
}
}
}
}
void MainWindow::cmbRegion_currentIndexChanged (int index)
{
if (index < 0)
return;
if (eros_->state() != ErosState::ConnectedState)
return;
LocalUser *user = eros_->localUser();
int regionIndex = ui.cmbRegion->currentData().toInt();
ErosRegion region = eros_->activeRegions()[regionIndex];
if (user != nullptr)
{
const UserLadderStats *stats = user->ladderStatsGlobal();
QLayoutItem* item;
while ( ( item = ui.frmLocalInfo->layout()->takeAt(0)) != NULL )
{
delete item->widget();
delete item;
}
MatchmakingPlayerInfo *region_info = new MatchmakingPlayerInfo(user->username(), user->division(), stats, false, this);
ui.frmLocalInfo->layout()->addWidget(region_info);
}
const QList<Character*> &characters = this->eros_->localUser()->characters();
for (int i = 0; i < characters.length(); i++)
{
if (characters[i]->region() == region)
{
ui.chkQueueRegion->setEnabled(true);
ui.chkQueueRegion->setChecked(this->config_->activeProfile()->queueRegions().contains(region));
return;
}
}
ui.chkQueueRegion->setDisabled(true);
ui.chkQueueRegion->setChecked(false);
}
void MainWindow::cmbMapRegion_currentIndexChanged (int index)
{
if (this->eros_->state() != ErosState::ConnectedState)
return;
ui.lstMaps->clear();
if (index < 0)
return;
LocalUser *user = eros_->localUser();
int regionIndex = ui.cmbMapRegion->currentData().toInt();
ErosRegion region = eros_->activeRegions()[regionIndex];
for (int i = 0; i < eros_->mapPool().size(); i++)
{
Map *map = eros_->mapPool()[i];
if (map->region() == region)
{
QListWidgetItem *item = new QListWidgetItem(map->name());
item->setData(101, (int)region);
item->setData(102, (int)map->battleNetId());
if (eros_->localUser()->vetoes().contains(map))
{
item->setIcon(QIcon(":/img/client/icons/cross"));
}
ui.lstMaps->addItem(item);
}
}
ui.lstMaps->sortItems();
if (this->selected_map_ != nullptr)
{
for (int i = 0; i < ui.lstMaps->count(); i++)
{
QListWidgetItem *item = ui.lstMaps->item(i);
if (item->data(101).toInt() == this->selected_map_->region() && item->data(102).toInt() == this->selected_map_->battleNetId())
{
ui.lstMaps->setCurrentItem(item);
break;
}
}
}
}
void MainWindow::erosConnectionError(QAbstractSocket::SocketError error, const QString error_string)
{
ui.lblInformation->setText(tr("Connection error (%1): %2").arg(QString::number(error), error_string));
}
void MainWindow::erosConnected()
{
setupWatches();
ui.cmbRegion->clear();
ui.cmbMapRegion->clear();
ui.lstMaps->clear();
ui.lstChats->clear();
this->selected_map_ = nullptr;
int set_index = 0;
int pref_region = this->config_->preferredRegion();
for (int i =0; i < this->eros_->activeRegions().count(); i++)
{
ui.cmbRegion->addItem(QIcon(QString(":/img/client/icons/flags/%1").arg(Eros::regionToString(this->eros_->activeRegions()[i]))), Eros::regionToLongString(this->eros_->activeRegions()[i]), i);
int vetoes = 0;
for (int j = 0; j < eros_->localUser()->vetoes().size(); j++)
{
if (eros_->localUser()->vetoes()[j]->region() == this->eros_->activeRegions()[i])
vetoes++;
}
ui.cmbMapRegion->addItem(QIcon(QString(":/img/client/icons/flags/%1").arg(Eros::regionToString(this->eros_->activeRegions()[i]))), QString("%1 (%2)").arg(Eros::regionToLongString(this->eros_->activeRegions()[i]), tr("%1/%n veto(es) used", "", eros_->maxVetoes()).arg(vetoes)), i);
if (this->eros_->activeRegions()[i] == pref_region)
set_index = i;
}
if (pref_region < 1)
set_index = 0;
if (ui.cmbRegion->count() > 0)
ui.cmbRegion->setCurrentIndex(set_index);
if (ui.cmbMapRegion->count() > 0)
ui.cmbMapRegion->setCurrentIndex(set_index);
erosLocalUserUpdated(this->eros_->localUser());
if (this->config_->autoJoin())
{
ChatRoom *room = this->eros_->getChatRoom("Starbow");
emit joinChatRoom(room);
}
setUiEnabled(true);
QTimer::singleShot(0, this->eros_, SLOT(refreshChatRooms()));
this->upload_queue_timer_->start(250);
}
void MainWindow::erosDisconnected()
{
setUiEnabled(false);
setQueueState(false);
ui.lstChats->clear();
ui.lstMaps->clear();
this->selected_map_ = nullptr;
this->upload_queue_timer_->stop();
}
void MainWindow::erosAuthenticationFailed()
{
ui.lblInformation->setText(tr("Authentication failed. Server error if you previously connected fine."));
}
void MainWindow::erosAlreadyLoggedIn()
{
ui.lblInformation->setText(tr("Already logged in. Check that you're not running another client."));
}
void MainWindow::erosLocalUserUpdated(LocalUser *user)
{
cmbRegion_currentIndexChanged(ui.cmbRegion->currentIndex());
cmbMapRegion_currentIndexChanged(ui.cmbMapRegion->currentIndex());
}
// Handle updating the status label and toggling the connection timer.
void MainWindow::erosStateChanged(ErosState state)
{
setQueueState(false);
switch (state)
{
case ErosState::ConnectingState:
this->ui.lblInformation->setText(tr("Connecting"));
this->connection_timer_->stop();
break;
case ErosState::DisconnectingState:
this->ui.lblInformation->setText(tr("Disconnecting"));
break;
case ErosState::UnconnectedState:
this->ui.lblInformation->setText(tr("Not connected"));
this->connection_timer_->start();
break;
case ErosState::HandshakingState:
this->ui.lblInformation->setText(tr("Logging in"));
break;
case ErosState::ConnectedState:
this->ui.lblInformation->setText(tr("Connected as %1").arg(this->eros_->localUser()->username()));
break;
}
}
void MainWindow::connectionTimerWorker()
{
this->connection_timer_->setInterval(10000);
if (this->config_->activeProfile() != nullptr)
{
if (this->eros_->state() == ErosState::UnconnectedState)
{
const QString &server = this->config_->server();
const QString &username = this->config_->activeProfile()->username();
const QString &token = this->config_->activeProfile()->token();
if (server.isEmpty())
{
this->ui.lblInformation->setText(tr("Cannot connect. No server specified."));
}
else if (token.isEmpty())
{
this->ui.lblInformation->setText(tr("Cannot connect. No authentication token specified."));
}
else
{
emit connectToEros(server, username, token);
this->connection_timer_->stop();
}
}
}
else
{
this->ui.lblInformation->setText(tr("Cannot connect. No profile specified."));
}
}
void MainWindow::label_linkActivated(const QString &link)
{
if (link == "#settings")
{
openSettings();
}
else if (link == "#upload")
{
QString filename = QFileDialog::getOpenFileName(this, tr("Select Replay"), this->config_->activeProfile()->replayFolder(), tr("Replay Files (*.SC2Replay);;All Files (*.*)"));
if (!filename.isEmpty())
{
emit uploadReplay(filename);
}
}
else if (link == "#battlenet")
{
if (this->eros_->state() != ErosState::ConnectedState)
{
QMessageBox::information(this, tr("Unable to open Battle.Net Settings"), tr("You must be logged in before you can manage your Battle.net settings."));
}
else
{
openBnetSettings();
}
}
}
void MainWindow::tabContainer_currentChanged(int index)
{
if (ChatWidget* widget = dynamic_cast<ChatWidget*>(ui.tabContainer->widget(index)))
{
widget->resetEventCount();
}
}
void MainWindow::tabContainer_tabCloseRequested(int index)
{
if (this->settings_window_ != nullptr && ui.tabContainer->widget(index) == this->settings_window_)
{
ui.tabContainer->removeTab(index);
delete this->settings_window_;
this->settings_window_ = nullptr;
if (this->eros_->state() == ErosState::ConnectedState)
{
if (this->eros_->localUser()->username().toLower().trimmed() != this->config_->activeProfile()->username().toLower().trimmed())
{
emit disconnectFromEros();
QTimer::singleShot(0, this, SLOT(connectionTimerWorker()));
}
}
setupWatches();
}
else if (ChatWidget* widget = dynamic_cast<ChatWidget*>(ui.tabContainer->widget(index)))
{
if (widget->chatroom() != nullptr)
{
emit leaveChatRoom(widget->chatroom());
}
delete widget;
}
else if(bnetsettings_window_ != nullptr && ui.tabContainer->widget(index) == bnetsettings_window_)
{
ui.tabContainer->removeTab(index);
delete bnetsettings_window_;
bnetsettings_window_ = nullptr;
}
}
void MainWindow::setUiEnabled(bool enabled)
{
if (enabled)
{
ui.tabMatchmaking->setEnabled(true);
ui.tabChat->setEnabled(true);
ui.tabMaps->setEnabled(true);
}
else
{
ui.tabMatchmaking->setDisabled(true);
ui.tabChat->setDisabled(true);
ui.tabMaps->setDisabled(true);
}
}
//////// CHAT
void MainWindow::lstChats_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
if (current != nullptr)
{
ui.txtRoomName->setText(current->text());
}
}
void MainWindow::lstChats_itemDoubleClicked(QListWidgetItem *item)
{
if (item != nullptr)
{
ui.txtRoomName->setText(item->text());
btnJoinRoom_pressed();
}
}
void MainWindow::btnJoinRoom_pressed()