-
-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathmudlet.cpp
More file actions
8838 lines (7567 loc) · 361 KB
/
mudlet.cpp
File metadata and controls
8838 lines (7567 loc) · 361 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
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2013-2025 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016 by Chris Leacy - cleacy1972@gmail.com *
* Copyright (C) 2016-2018 by Ian Adkins - ieadkins@gmail.com *
* Copyright (C) 2017 by Tom Scheper - scheper@gmail.com *
* Copyright (C) 2011-2021 by Vadim Peretokin - vperetokin@gmail.com *
* Copyright (C) 2022 by Thiago Jung Bauermann - bauermann@kolabnow.com *
* Copyright (C) 2023-2025 by Lecker Kebap - Leris@mudlet.org *
* *
* 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 2 of the License, or *
* (at your option) 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "mudlet.h"
#include "AltFocusMenuBarDisable.h"
#include "CredentialManager.h"
#include "DarkTheme.h"
#include "EAction.h"
#include "LuaInterface.h"
#include "TCommandLine.h"
#include "TConsole.h"
#include "TDebug.h"
#include "TDetachedWindow.h"
#include "TDockWidget.h"
#include "TEvent.h"
#include "TLabel.h"
#include "TMainConsole.h"
#include "TMap.h"
#include "TMedia.h"
#include "TGameDetails.h"
#include "TRoomDB.h"
#include "TTabBar.h"
#include "TTextEdit.h"
#include "TToolBar.h"
#include "XMLimport.h"
#include "dlgAboutDialog.h"
#include "dlgConnectionProfiles.h"
#include "FileOpenHandler.h"
#include "dlgIRC.h"
#include "dlgMapper.h"
#include "dlgModuleManager.h"
#include "dlgNotepad.h"
#include "dlgPackageExporter.h"
#include "dlgPackageManager.h"
#include "dlgProfilePreferences.h"
#include "dlgTriggerEditor.h"
#include "TMediaData.h"
#include "VarUnit.h"
#include "MMCPServer.h"
#include "edbee/models/textautocompleteprovider.h"
#include "edbee/views/texttheme.h"
#include <QAccessible>
#include <QAccessibleAnnouncementEvent>
#include <QApplication>
#include <QtUiTools/quiloader.h>
#include <QDesktopServices>
#include <QFile>
#include <QFileDialog>
#include <QJsonDocument>
#include <QImage>
#include <QJsonObject>
#include <QJsonValue>
#include <QNetworkDiskCache>
#include <QMediaDevices>
#include <QMediaPlayer>
#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
#include <QPoint>
#include <QScreen>
#include <QScrollBar>
#include <QShortcut>
#include <QSplitter>
#include <QStyleFactory>
#include <QStyleHints>
#include <QTableWidget>
#include <QTextStream>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
#include <QToolTip>
#include <QVariantHash>
#include <QRandomGenerator>
#include <cmath>
#include <memory>
#include <zip.h>
#include <QStyle>
#if defined(Q_OS_WINDOWS)
#include <QSettings>
#endif
// for system physical memory info
#if defined(Q_OS_WINDOWS)
#include <Windows.h>
#include <Psapi.h>
#elif defined(Q_OS_MACOS)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <array>
#elif defined(Q_OS_HURD)
#include <errno.h>
#include <unistd.h>
#elif defined(Q_OS_OPENBSD)
// OpenBSD doesn't have a sysinfo.h
#include <sys/sysctl.h>
#include <unistd.h>
#elif defined(Q_OS_UNIX)
// Including both GNU/Linux and FreeBSD
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <unistd.h>
#else
// Any other OS?
#endif
// We are now using code that won't work with really old versions of libzip;
// some of the error handling was improved in 1.0 . Unfortunately libzip 1.7.0
// (and one or two other recent versions) forgot to include the version defines
// and thus broke a test depending on them:
#if defined(LIBZIP_VERSION_MAJOR) && (LIBZIP_VERSION_MAJOR < 1)
#error Mudlet requires a version of libzip of at least 1.0
#endif
#if defined(Q_OS_MACOS)
// wrap in namespace since `Collection` defined in these headers will clash with Boost
namespace coreMacOS {
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
}
#endif
// PLACEMARKER: sample benchmarking code
// #include <nanobench.h>
using namespace std::chrono_literals;
bool TConsoleMonitor::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::Close) {
mudlet::smDebugMode = false;
mudlet::self()->refreshTabBar();
return QObject::eventFilter(obj, event);
}
return QObject::eventFilter(obj, event);
}
/*static*/ void mudlet::start()
{
smpSelf = new mudlet;
}
/*static*/ mudlet* mudlet::self()
{
return smpSelf;
}
mudlet::mudlet()
: QMainWindow()
{
// Initialisation happens later in setupConfig() and init()
}
void mudlet::init()
{
smFirstLaunch = !QFile::exists(mudlet::getMudletPath(enums::profilesPath));
QFile gitShaFile(":/app-build.txt");
if (!gitShaFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "mudlet: failed to open app-build.txt for reading:" << gitShaFile.errorString();
}
const QString gitSha = QString::fromUtf8(gitShaFile.readAll()).trimmed();
mAppBuild = gitSha;
releaseVersion = mAppBuild.isEmpty();
publicTestVersion = mAppBuild.startsWith("-ptb");
developmentVersion = !releaseVersion && !publicTestVersion;
scmVersion = qsl("Mudlet ") + QString(APP_VERSION) + gitSha;
mShowIconsOnMenuOriginally = !qApp->testAttribute(Qt::AA_DontShowIconsInMenus);
readEarlySettings(*mpSettings);
if (mShowIconsOnMenuCheckedState != Qt::PartiallyChecked) {
// If the setting is not the "tri-state" one then force the setting,
// have to invert the sense because the attribute is a negative one:
qApp->setAttribute(Qt::AA_DontShowIconsInMenus, (mShowIconsOnMenuCheckedState == Qt::Unchecked));
}
// We need to record this before we clobber it with our own substitute...
mDefaultStyle = qApp->style()->objectName();
// ... which is applied here:
setAppearance(mAppearance, true);
scanForMudletTranslations(qsl(":/lang"));
scanForQtTranslations(getMudletPath(enums::qtTranslationsPath));
loadTranslators(mInterfaceLanguage);
// Cannot assign a value in the constructor list as it requires the
// translations to be loaded first:
//: Formatting string for elapsed time display in replay playback - see QDateTime::toString(const QString&) for the gory details...!
mTimeFormat = tr("hh:mm:ss");
if (QStringList{qsl("windowsvista"), qsl("macintosh"), qsl("macos")}.contains(mDefaultStyle, Qt::CaseInsensitive)) {
qDebug().nospace().noquote() << "mudlet::mudlet() INFO - '" << mDefaultStyle << "' has been detected as the style factory in use - QPushButton styling fix applied!";
mBG_ONLY_STYLESHEET = qsl("QPushButton {background-color: %1; border: 1px solid #8f8f91;}");
mTEXT_ON_BG_STYLESHEET = qsl("QPushButton {color: %1; background-color: %2; border: 1px solid #8f8f91;}");
} else {
qDebug().nospace().noquote() << "mudlet::mudlet() INFO - '" << mDefaultStyle << "' has been detected as the style factory in use - no styling fixes applied.";
mBG_ONLY_STYLESHEET = qsl("QPushButton {background-color: %1;}");
mTEXT_ON_BG_STYLESHEET = qsl("QPushButton {color: %1; background-color: %2;}");
}
setupUi(this);
setUnifiedTitleAndToolBarOnMac(true);
setContentsMargins(0, 0, 0, 0);
setAcceptDrops(true); // Enable drag and drop for profile tabs
menuGames->setToolTipsVisible(true);
menuEditor->setToolTipsVisible(true);
menuOptions->setToolTipsVisible(true);
menuWindow->setToolTipsVisible(true);
menuHelp->setToolTipsVisible(true);
menuAbout->setToolTipsVisible(true);
setAttribute(Qt::WA_DeleteOnClose);
const QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setWindowTitle(scmVersion);
if (releaseVersion) {
setWindowIcon(QIcon(qsl(":/icons/mudlet.png")));
} else if (publicTestVersion) {
setWindowIcon(QIcon(qsl(":/icons/mudlet_ptb_256px.png")));
} else { // developmentVersion
setWindowIcon(QIcon(qsl(":/icons/mudlet_dev_256px.png")));
}
mpMainToolBar = new QToolBar(this);
mpMainToolBar->setObjectName(qsl("mpMainToolBar"));
//: Name of the main toolbar shown in Qt's built-in toolbar toggle menus and right-click context menus
mpMainToolBar->setWindowTitle(tr("Main Toolbar"));
addToolBar(mpMainToolBar);
mpMainToolBar->setMovable(false);
addToolBarBreak();
auto frame = new QWidget(this);
setCentralWidget(frame);
mpTabBar = new TTabBar(frame);
mpTabBar->setMaximumHeight(30);
mpTabBar->setFocusPolicy(Qt::NoFocus);
mpTabBar->setTabsClosable(true);
mpTabBar->setAutoHide(true);
connect(mpTabBar, &QTabBar::tabCloseRequested, this, &mudlet::slot_closeProfileRequested);
mpTabBar->setMovable(true);
// This only reports changing the tab by the user clicking on the tab
connect(mpTabBar, &QTabBar::currentChanged, this, &mudlet::slot_tabChanged);
connect(mpTabBar, &QTabBar::tabMoved, this, &mudlet::slot_tabMoved);
// Connect the tab bar's detach signal
connect(mpTabBar, &TTabBar::tabDetachRequested, this, &mudlet::slot_tabDetachRequested);
// Connect the tab bar's reattach signal (for drag and drop reattachment)
connect(mpTabBar, &TTabBar::tabReattachRequested, this, &mudlet::slot_tabReattachRequested);
// Add context menu to tab bar for toolbar visibility options
mpTabBar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mpTabBar, &QWidget::customContextMenuRequested, this, &mudlet::slot_showTabContextMenu);
auto layoutTopLevel = new QVBoxLayout(frame);
layoutTopLevel->setContentsMargins(0, 0, 0, 0);
layoutTopLevel->addWidget(mpTabBar);
mpWidget_profileContainer = new QWidget(frame);
const QPalette mainPalette;
mpWidget_profileContainer->setPalette(mainPalette);
mpWidget_profileContainer->setContentsMargins(0, 0, 0, 0);
mpWidget_profileContainer->setSizePolicy(sizePolicy);
mpWidget_profileContainer->setAutoFillBackground(true);
layoutTopLevel->addWidget(mpWidget_profileContainer);
mpHBoxLayout_profileContainer = new QHBoxLayout(mpWidget_profileContainer);
mpHBoxLayout_profileContainer->setContentsMargins(0, 0, 0, 0);
mpSplitter_profileContainer = new QSplitter(Qt::Horizontal, mpWidget_profileContainer);
mpSplitter_profileContainer->setContentsMargins(0, 0, 0, 0);
mpSplitter_profileContainer->setChildrenCollapsible(false);
mpHBoxLayout_profileContainer->addWidget(mpSplitter_profileContainer);
mpButtonConnect = new QToolButton(this);
mpButtonConnect->setText(tr("Connect"));
mpButtonConnect->setObjectName(qsl("connect"));
mpButtonConnect->setContextMenuPolicy(Qt::ActionsContextMenu);
mpButtonConnect->setPopupMode(QToolButton::MenuButtonPopup);
mpButtonConnect->setAutoRaise(true);
mpMainToolBar->addWidget(mpButtonConnect);
mpActionConnect = new QAction(tr("Connect"), this);
mpActionConnect->setIcon(QIcon(qsl(":/icons/preferences-web-browser-cache.png")));
mpActionConnect->setIconText(tr("Connect"));
mpActionConnect->setObjectName(qsl("connect"));
mpActionDisconnect = new QAction(tr("Disconnect"), this);
mpActionDisconnect->setObjectName(qsl("disconnect"));
mpActionCloseProfile = new QAction(tr("Close profile"), this);
mpActionCloseProfile->setIcon(QIcon(qsl(":/icons/profile-close.png")));
mpActionCloseProfile->setIconText(tr("Close profile"));
mpActionCloseProfile->setObjectName(qsl("close_profile"));
mpActionCloseApplication = new QAction(tr("Close Mudlet"), this);
mpActionCloseApplication->setIcon(QIcon::fromTheme(qsl("application-exit"), QIcon(qsl(":/icons/application-exit.png"))));
mpActionCloseApplication->setIconText(tr("Close Mudlet"));
mpActionCloseApplication->setObjectName(qsl("close_application"));
mpButtonConnect->addAction(mpActionConnect);
mpButtonConnect->addAction(mpActionDisconnect);
mpButtonConnect->addAction(mpActionCloseProfile);
mpButtonConnect->addAction(mpActionCloseApplication);
mpButtonConnect->setDefaultAction(mpActionConnect);
mpActionTriggers = new QAction(QIcon(qsl(":/icons/tools-wizard.png")), tr("Triggers"), this);
mpActionTriggers->setToolTip(utils::richText(tr("Show and edit triggers")));
mpMainToolBar->addAction(mpActionTriggers);
mpActionTriggers->setObjectName(qsl("triggers_action"));
// add name to the action's widget in the toolbar, which doesn't have one by default
// see https://stackoverflow.com/a/32460562/72944
mpMainToolBar->widgetForAction(mpActionTriggers)->setObjectName(mpActionTriggers->objectName());
mpActionAliases = new QAction(QIcon(qsl(":/icons/system-users.png")), tr("Aliases"), this);
mpActionAliases->setToolTip(utils::richText(tr("Show and edit aliases")));
mpMainToolBar->addAction(mpActionAliases);
mpActionAliases->setObjectName(qsl("aliases_action"));
mpMainToolBar->widgetForAction(mpActionAliases)->setObjectName(mpActionAliases->objectName());
mpActionTimers = new QAction(QIcon(qsl(":/icons/chronometer.png")), tr("Timers"), this);
mpActionTimers->setToolTip(utils::richText(tr("Show and edit timers")));
mpMainToolBar->addAction(mpActionTimers);
mpActionTimers->setObjectName(qsl("timers_action"));
mpMainToolBar->widgetForAction(mpActionTimers)->setObjectName(mpActionTimers->objectName());
mpActionButtons = new QAction(QIcon(qsl(":/icons/bookmarks.png")), tr("Buttons"), this);
mpActionButtons->setToolTip(utils::richText(tr("Show and edit easy buttons")));
mpMainToolBar->addAction(mpActionButtons);
mpActionButtons->setObjectName(qsl("buttons_action"));
mpMainToolBar->widgetForAction(mpActionButtons)->setObjectName(mpActionButtons->objectName());
mpActionScripts = new QAction(QIcon(qsl(":/icons/document-properties.png")), tr("Scripts"), this);
mpActionScripts->setToolTip(utils::richText(tr("Show and edit scripts")));
mpMainToolBar->addAction(mpActionScripts);
mpActionScripts->setObjectName(qsl("scripts_action"));
mpMainToolBar->widgetForAction(mpActionScripts)->setObjectName(mpActionScripts->objectName());
mpActionKeys = new QAction(QIcon(qsl(":/icons/preferences-desktop-keyboard.png")), tr("Keys"), this);
mpActionKeys->setToolTip(utils::richText(tr("Show and edit keys")));
mpMainToolBar->addAction(mpActionKeys);
mpActionKeys->setObjectName(qsl("keys_action"));
mpMainToolBar->widgetForAction(mpActionKeys)->setObjectName(mpActionKeys->objectName());
mpActionVariables = new QAction(QIcon(qsl(":/icons/variables.png")), tr("Variables"), this);
mpActionVariables->setToolTip(utils::richText(tr("Show and edit Lua variables")));
mpMainToolBar->addAction(mpActionVariables);
mpActionVariables->setObjectName(qsl("variables_action"));
mpMainToolBar->widgetForAction(mpActionVariables)->setObjectName(mpActionVariables->objectName());
mpButtonMute = new QToolButton(this);
mpButtonMute->setText(tr("Mute"));
mpButtonMute->setObjectName(qsl("mute"));
mpButtonMute->setContextMenuPolicy(Qt::ActionsContextMenu);
mpButtonMute->setPopupMode(QToolButton::MenuButtonPopup);
mpButtonMute->setAutoRaise(true);
mpMainToolBar->addWidget(mpButtonMute);
mpActionMuteMedia = new QAction(tr("Mute all media"), this);
mpActionMuteMedia->setIcon(QIcon(qsl(":/icons/mute.png")));
mpActionMuteMedia->setIconText(tr("Mute all media"));
mpActionMuteMedia->setObjectName(qsl("muteMedia"));
mpActionMuteMedia->setCheckable(true);
mpActionMuteAPI = new QAction(tr("Mute sounds from Mudlet (triggers, scripts, etc.)"), this);
mpActionMuteAPI->setIcon(QIcon(qsl(":/icons/mute.png")));
mpActionMuteAPI->setIconText(tr("Mute sounds from Mudlet (triggers, scripts, etc.)"));
mpActionMuteAPI->setObjectName(qsl("muteAPI"));
mpActionMuteAPI->setCheckable(true);
mpActionMuteGame = new QAction(tr("Mute sounds from the game (MCMP, MSP)"), this);
mpActionMuteGame->setIcon(QIcon(qsl(":/icons/mute.png")));
mpActionMuteGame->setIconText(tr("Mute sounds from the game (MCMP, MSP)"));
mpActionMuteGame->setObjectName(qsl("muteGame"));
mpActionMuteGame->setCheckable(true);
mpButtonMute->addAction(mpActionMuteMedia);
mpButtonMute->addAction(mpActionMuteAPI);
mpButtonMute->addAction(mpActionMuteGame);
mpButtonMute->setDefaultAction(mpActionMuteMedia);
mpButtonDiscord = new QToolButton(this);
mpButtonDiscord->setText(qsl("Discord"));
mpButtonDiscord->setObjectName(qsl("discord"));
mpButtonDiscord->setContextMenuPolicy(Qt::DefaultContextMenu);
mpButtonDiscord->setAutoRaise(true);
mpMainToolBar->addWidget(mpButtonDiscord);
mpActionDiscord = new QAction(tr("Open Discord"), this);
mpActionDiscord->setIcon(QIcon(qsl(":/icons/Discord-Logo-Color.png")));
mpActionDiscord->setIconText(qsl("Discord"));
mpActionDiscord->setObjectName(qsl("openDiscord"));
mpActionMudletDiscord = new QAction(QIcon(qsl(":/icons/mudlet_discord.png")), tr("Mudlet chat"), this);
mpActionMudletDiscord->setToolTip(utils::richText(tr("Open a link to the Mudlet server on Discord")));
mpMainToolBar->addAction(mpActionMudletDiscord);
mpActionMudletDiscord->setObjectName(qsl("mudlet_discord"));
mpMainToolBar->widgetForAction(mpActionMudletDiscord)->setObjectName(mpActionMudletDiscord->objectName());
mpActionMudletDiscord->setVisible(false); // Mudlet Discord becomes visible if game has custom invite
mpButtonDiscord->addAction(mpActionDiscord);
mpButtonDiscord->setDefaultAction(mpActionDiscord);
mpActionMapper = new QAction(QIcon(qsl(":/icons/applications-internet.png")), tr("Map"), this);
mpActionMapper->setToolTip(utils::richText(tr("Show/hide the map")));
mpMainToolBar->addAction(mpActionMapper);
mpActionMapper->setObjectName(qsl("map_action"));
mpMainToolBar->widgetForAction(mpActionMapper)->setObjectName(mpActionMapper->objectName());
mpActionHelp = new QAction(QIcon(qsl(":/icons/help-hint.png")), tr("Manual"), this);
mpActionHelp->setToolTip(utils::richText(tr("Browse reference material and documentation")));
mpMainToolBar->addAction(mpActionHelp);
mpActionHelp->setObjectName(qsl("manual_action"));
mpMainToolBar->widgetForAction(mpActionHelp)->setObjectName(mpActionHelp->objectName());
mpActionOptions = new QAction(QIcon(qsl(":/icons/configure.png")), tr("Settings"), this);
mpActionOptions->setToolTip(utils::richText(tr("See and edit profile preferences")));
mpMainToolBar->addAction(mpActionOptions);
mpActionOptions->setObjectName(qsl("settings_action"));
mpMainToolBar->widgetForAction(mpActionOptions)->setObjectName(mpActionOptions->objectName());
// TODO: Consider changing to ":/icons/mudlet_notepad.png" as per the icon
// now used for the window when the visual change to the toolbar caused can
// be managed
mpActionNotes = new QAction(QIcon(qsl(":/icons/applications-accessories.png")), tr("Notepad"), this);
mpActionNotes->setToolTip(utils::richText(tr("Open a notepad that you can store your notes in")));
mpMainToolBar->addAction(mpActionNotes);
mpActionNotes->setObjectName(qsl("notepad_action"));
mpMainToolBar->widgetForAction(mpActionNotes)->setObjectName(mpActionNotes->objectName());
// Create toolbar toggle action
mpActionToggleMainToolBar = new QAction(tr("Show Main Toolbar"), this);
mpActionToggleMainToolBar->setCheckable(true);
mpActionToggleMainToolBar->setChecked(true); // Initially checked
mpActionToggleMainToolBar->setObjectName(qsl("toggle_main_toolbar_action"));
mpButtonPackageManagers = new QToolButton(this);
mpButtonPackageManagers->setText(tr("Packages"));
mpButtonPackageManagers->setObjectName(qsl("package_manager"));
mpButtonPackageManagers->setContextMenuPolicy(Qt::ActionsContextMenu);
mpButtonPackageManagers->setPopupMode(QToolButton::MenuButtonPopup);
mpButtonPackageManagers->setAutoRaise(true);
mpMainToolBar->addWidget(mpButtonPackageManagers);
mpActionPackageManager = new QAction(tr("Package Manager"), this);
mpActionPackageManager->setIcon(QIcon(qsl(":/icons/package-manager.png")));
mpActionPackageManager->setIconText(tr("Packages"));
mpActionPackageManager->setObjectName(qsl("package_manager"));
mpActionModuleManager = new QAction(tr("Module Manager"), this);
mpActionModuleManager->setIcon(QIcon(qsl(":/icons/module-manager.png")));
mpActionModuleManager->setObjectName(qsl("module_manager"));
mpActionPackageExporter = new QAction(tr("Package Exporter"), this);
mpActionPackageExporter->setIcon(QIcon(qsl(":/icons/package-exporter.png")));
mpActionPackageExporter->setObjectName(qsl("package_exporter"));
mpButtonPackageManagers->addAction(mpActionPackageManager);
mpButtonPackageManagers->addAction(mpActionModuleManager);
mpButtonPackageManagers->addAction(mpActionPackageExporter);
mpButtonPackageManagers->setDefaultAction(mpActionPackageManager);
mpActionReplay = new QAction(QIcon(qsl(":/icons/media-optical.png")), tr("Replay"), this);
mpActionReplay->setObjectName(qsl("replay_action"));
mpMainToolBar->addAction(mpActionReplay);
mpMainToolBar->widgetForAction(mpActionReplay)->setObjectName(mpActionReplay->objectName());
mpActionReconnect = new QAction(QIcon(qsl(":/icons/system-restart.png")), tr("Reconnect"), this);
mpActionReconnect->setToolTip(utils::richText(tr("Disconnects you from the game and connects once again")));
mpMainToolBar->addAction(mpActionReconnect);
mpActionReconnect->setObjectName(qsl("reconnect_action"));
mpMainToolBar->widgetForAction(mpActionReconnect)->setObjectName(mpActionReconnect->objectName());
mpActionMultiView = new QAction(QIcon(qsl(":/icons/view-split-left-right.png")), tr("MultiView"), this);
//: Same text is used in 2 places.
mpActionMultiView->setToolTip(utils::richText(tr("Splits the Mudlet screen to show multiple profiles at once; disabled when less than two are loaded.")));
mpMainToolBar->addAction(mpActionMultiView);
mpActionMultiView->setCheckable(true);
mpActionMultiView->setChecked(false);
mpActionMultiView->setEnabled(false);
dactionMultiView->setEnabled(false);
mpActionMultiView->setObjectName(qsl("multiview_action"));
mpMainToolBar->widgetForAction(mpActionMultiView)->setObjectName(mpActionMultiView->objectName());
#if defined(INCLUDE_UPDATER)
if (publicTestVersion) {
mpActionReportIssue = new QAction(tr("Report issue"), this);
const QStringList issueReportIcons{"face-uncertain.png", "face-surprise.png", "face-smile.png", "face-sad.png", "face-plain.png"};
auto randomIcon = QRandomGenerator::global()->bounded(issueReportIcons.size());
mpActionReportIssue->setIcon(QIcon(qsl(":/icons/%1").arg(issueReportIcons.at(randomIcon))));
mpActionReportIssue->setToolTip(
utils::richText(tr("The public test build gets newer features to you quicker, and you help us find issues in them quicker. Spotted something odd? Let us know asap!")));
mpMainToolBar->addAction(mpActionReportIssue);
mpActionReportIssue->setObjectName(qsl("reportissue_action"));
mpMainToolBar->widgetForAction(mpActionReportIssue)->setObjectName(mpActionReportIssue->objectName());
}
#endif
mpActionAbout = new QAction(QIcon(qsl(":/icons/mudlet_information.png")), tr("About"), this);
//: Tooltip for About Mudlet sub-menu item and main toolbar button (or menu item if an update has changed that control to have a popup menu instead) (Used in 3 places - please ensure all have the same translation).
mpActionAbout->setToolTip(utils::richText(tr("Inform yourself about this version of Mudlet, the people who made it and the licence under which you can share it.")));
mpMainToolBar->addAction(mpActionAbout);
mpActionAbout->setObjectName(qsl("about_action"));
mpMainToolBar->widgetForAction(mpActionAbout)->setObjectName(mpActionAbout->objectName());
disableToolbarButtons();
QIcon fullScreenIcon;
fullScreenIcon.addPixmap(qsl(":/icons/view-fullscreen.png"), QIcon::Normal, QIcon::Off);
fullScreenIcon.addPixmap(qsl(":/icons/view-restore.png"), QIcon::Normal, QIcon::On);
mpActionFullScreenView = new QAction(fullScreenIcon, tr("Full Screen"), this);
mpActionFullScreenView->setToolTip(utils::richText(tr("Toggle Full Screen View")));
mpActionFullScreenView->setCheckable(true);
mpActionFullScreenView->setObjectName(qsl("fullscreen_action"));
mpMainToolBar->addAction(mpActionFullScreenView);
mpMainToolBar->widgetForAction(mpActionFullScreenView)->setObjectName(mpActionFullScreenView->objectName());
const QFont mainFont = QFont(qsl("Bitstream Vera Sans Mono"), 8, QFont::Normal);
mpWidget_profileContainer->setFont(mainFont);
mpWidget_profileContainer->show();
connect(mpActionConnect.data(), &QAction::triggered, this, &mudlet::slot_showConnectionDialog);
connect(mpActionHelp.data(), &QAction::triggered, this, &mudlet::slot_showHelpDialog);
connect(mpActionTimers.data(), &QAction::triggered, this, &mudlet::slot_showTimerDialog);
connect(mpActionAliases.data(), &QAction::triggered, this, &mudlet::slot_showAliasDialog);
connect(mpActionScripts.data(), &QAction::triggered, this, &mudlet::slot_showScriptDialog);
connect(mpActionKeys.data(), &QAction::triggered, this, &mudlet::slot_showKeyDialog);
connect(mpActionVariables.data(), &QAction::triggered, this, &mudlet::slot_showVariableDialog);
connect(mpActionButtons.data(), &QAction::triggered, this, &mudlet::slot_showActionDialog);
connect(mpActionOptions.data(), &QAction::triggered, this, &mudlet::slot_showPreferencesDialog);
connect(mpActionToggleMainToolBar.data(), &QAction::triggered, this, &mudlet::slot_toolbarToggleActionTriggered);
connect(mpActionAbout.data(), &QAction::triggered, this, &mudlet::slot_showAboutDialog);
connect(mpActionMultiView.data(), &QAction::triggered, this, &mudlet::slot_multiView);
connect(mpActionReconnect.data(), &QAction::triggered, this, &mudlet::slot_reconnect);
connect(mpActionDisconnect.data(), &QAction::triggered, this, &mudlet::slot_disconnect);
connect(mpActionCloseProfile.data(), &QAction::triggered, this, &mudlet::slot_closeCurrentProfile);
connect(mpActionReplay.data(), &QAction::triggered, this, &mudlet::slot_replay);
connect(mpActionNotes.data(), &QAction::triggered, this, &mudlet::slot_notes);
connect(mpActionMapper.data(), &QAction::triggered, this, &mudlet::slot_showMapperDialog);
connect(mpActionDiscord.data(), &QAction::triggered, this, &mudlet::slot_profileDiscord);
connect(mpActionMudletDiscord.data(), &QAction::triggered, this, &mudlet::slot_mudletDiscord);
connect(mpActionPackageManager.data(), &QAction::triggered, this, &mudlet::slot_packageManager);
connect(mpActionModuleManager.data(), &QAction::triggered, this, &mudlet::slot_moduleManager);
connect(mpActionPackageExporter.data(), &QAction::triggered, this, &mudlet::slot_packageExporter);
connect(mpActionMuteMedia.data(), &QAction::triggered, this, &mudlet::slot_muteMedia);
connect(mpActionMuteAPI.data(), &QAction::triggered, this, &mudlet::slot_muteAPI);
connect(mpActionMuteGame.data(), &QAction::triggered, this, &mudlet::slot_muteGame);
connect(dactionConnect, &QAction::triggered, this, &mudlet::slot_showConnectionDialog);
connect(dactionReconnect, &QAction::triggered, this, &mudlet::slot_reconnect);
connect(dactionDisconnect, &QAction::triggered, this, &mudlet::slot_disconnect);
connect(dactionCloseProfile, &QAction::triggered, this, &mudlet::slot_closeCurrentProfile);
connect(dactionCloseApplication, &QAction::triggered, this, &mudlet::close);
connect(mpActionCloseApplication, &QAction::triggered, this, &mudlet::close);
connect(dactionNotepad, &QAction::triggered, this, &mudlet::slot_notes);
connect(dactionReplay, &QAction::triggered, this, &mudlet::slot_replay);
// Window menu connections
connect(dactionReattachDetachedWindows, &QAction::triggered, this, &mudlet::slot_reattachAllDetachedWindows);
connect(dactionToggleAlwaysOnTop, &QAction::triggered, this, &mudlet::slot_toggleAlwaysOnTop);
connect(dactionMinimize, &QAction::triggered, this, &mudlet::slot_minimize);
connect(dactionNewMapWindow, &QAction::triggered, this, &mudlet::slot_newMapWindow);
connect(dactionHelp, &QAction::triggered, this, &mudlet::slot_showHelpDialog);
connect(dactionVideo, &QAction::triggered, this, &mudlet::slot_showHelpDialogVideo);
connect(dactionForum, &QAction::triggered, this, &mudlet::slot_showHelpDialogForum);
connect(dactionDiscord, &QAction::triggered, this, &mudlet::slot_profileDiscord);
connect(dactionMudletDiscord, &QAction::triggered, this, &mudlet::slot_mudletDiscord);
connect(dactionLiveHelpChat, &QAction::triggered, this, &mudlet::slot_showHelpDialogIrc);
connect(dactionShowErrors, &QAction::triggered, this, [=, this]() {
auto host = getActiveHost();
if (!host) {
return;
}
if (!host->mpEditorDialog && !createMudletEditor()) {
qWarning() << "Failed to create editor dialog";
return;
}
host->mpEditorDialog->showCurrentTriggerItem();
host->mpEditorDialog->raise();
host->mpEditorDialog->showNormal();
host->mpEditorDialog->activateWindow();
host->mpEditorDialog->mpErrorConsole->setVisible(true);
});
#if defined(INCLUDE_UPDATER)
// Show the update option if the code is present AND if this is a
// release OR a public test version, or if you're specifically trying to test Sparkle.
dactionUpdate->setVisible(releaseVersion || publicTestVersion || qEnvironmentVariableIsSet("DEV_UPDATER"));
dactionChangelog->setVisible(releaseVersion || publicTestVersion || qEnvironmentVariableIsSet("DEV_UPDATER"));
// Show the report issue option if the updater code is present (as it is
// less likely to be for: {Linux} distribution packaged versions of Mudlet
// - or people hacking their own versions and neither of those types are
// going to want the updater to change things for them) AND only for a
// public test version:
if (publicTestVersion) {
dactionReportIssue->setVisible(true);
connect(mpActionReportIssue.data(), &QAction::triggered, this, &mudlet::slot_reportIssue);
connect(dactionReportIssue, &QAction::triggered, this, &mudlet::slot_reportIssue);
} else {
dactionReportIssue->setVisible(false);
}
#else
// Unconditionally hide the update and report bug menu items if the updater
// code is not included:
dactionUpdate->setVisible(false);
dactionChangelog->setVisible(false);
dactionReportIssue->setVisible(false);
#endif
connect(dactionPackageManager, &QAction::triggered, this, &mudlet::slot_packageManager);
connect(dactionPackageExporter, &QAction::triggered, this, &mudlet::slot_packageExporter);
connect(dactionModuleManager, &QAction::triggered, this, &mudlet::slot_moduleManager);
connect(dactionMultiView, &QAction::triggered, this, &mudlet::slot_multiView);
connect(dactionMuteMedia, &QAction::triggered, this, &mudlet::slot_muteMedia);
connect(dactionMuteAPI, &QAction::triggered, this, &mudlet::slot_muteAPI);
connect(dactionMuteGame, &QAction::triggered, this, &mudlet::slot_muteGame);
connect(dactionInputLine, &QAction::triggered, this, &mudlet::slot_compactInputLine);
connect(mpActionTriggers.data(), &QAction::triggered, this, &mudlet::slot_showTriggerDialog);
connect(dactionScriptEditor, &QAction::triggered, this, &mudlet::slot_showEditorDialog);
connect(dactionShowMap, &QAction::triggered, this, &mudlet::slot_mapper);
connect(dactionOptions, &QAction::triggered, this, &mudlet::slot_showPreferencesDialog);
connect(dactionAbout, &QAction::triggered, this, &mudlet::slot_showAboutDialog);
connect(dactionToggleTimeStamp, &QAction::triggered, this, &mudlet::slot_toggleTimeStamp);
connect(dactionToggleReplay, &QAction::triggered, this, &mudlet::slot_toggleReplay);
connect(dactionToggleLogging, &QAction::triggered, this, &mudlet::slot_toggleLogging);
connect(dactionToggleEmergencyStop, &QAction::triggered, this, &mudlet::slot_toggleEmergencyStop);
// we historically use Alt on Windows and Linux, but that is uncomfortable on macOS
#if defined(Q_OS_MACOS)
mKeySequenceTriggers = QKeySequence(Qt::CTRL | Qt::Key_E);
mKeySequenceShowMap = QKeySequence(Qt::CTRL | Qt::Key_M);
mKeySequenceInputLine = QKeySequence(Qt::CTRL | Qt::Key_L);
mKeySequenceOptions = QKeySequence(Qt::CTRL | Qt::Key_P);
mKeySequenceNotepad = QKeySequence(Qt::CTRL | Qt::Key_N);
mKeySequencePackages = QKeySequence(Qt::CTRL | Qt::Key_O);
mKeySequenceModules = QKeySequence(Qt::CTRL | Qt::Key_I);
mKeySequenceMultiView = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_V);
mKeySequenceMute = QKeySequence(Qt::CTRL | Qt::Key_K);
mKeySequenceConnect = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_C);
mKeySequenceDisconnect = QKeySequence(Qt::CTRL | Qt::Key_D);
mKeySequenceReconnect = QKeySequence(Qt::CTRL | Qt::Key_R);
mKeySequenceCloseProfile = QKeySequence(Qt::CTRL | Qt::Key_W);
mKeySequenceToggleTimeStamp = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T);
mKeySequenceToggleReplay = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_R);
mKeySequenceToggleLogging = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_L);
mKeySequenceToggleEmergencyStop = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_S);
#else
mKeySequenceTriggers = QKeySequence(Qt::ALT | Qt::Key_E);
mKeySequenceShowMap = QKeySequence(Qt::ALT | Qt::Key_M);
mKeySequenceInputLine = QKeySequence(Qt::ALT | Qt::Key_L);
mKeySequenceOptions = QKeySequence(Qt::ALT | Qt::Key_P);
mKeySequenceNotepad = QKeySequence(Qt::ALT | Qt::Key_N);
mKeySequencePackages = QKeySequence(Qt::ALT | Qt::Key_O);
mKeySequenceModules = QKeySequence(Qt::ALT | Qt::Key_I);
mKeySequenceMultiView = QKeySequence(Qt::ALT | Qt::Key_V);
mKeySequenceMute = QKeySequence(Qt::ALT | Qt::Key_K);
mKeySequenceConnect = QKeySequence(Qt::ALT | Qt::Key_C);
mKeySequenceDisconnect = QKeySequence(Qt::ALT | Qt::Key_D);
mKeySequenceReconnect = QKeySequence(Qt::ALT | Qt::Key_R);
mKeySequenceCloseProfile = QKeySequence(Qt::ALT | Qt::Key_W);
mKeySequenceToggleTimeStamp = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T);
mKeySequenceToggleReplay = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_R);
mKeySequenceToggleLogging = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_L);
mKeySequenceToggleEmergencyStop = QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_S);
#endif
connect(this, &mudlet::signal_menuBarVisibilityChanged, this, &mudlet::slot_updateShortcuts);
connect(this, &mudlet::signal_hostCreated, this, &mudlet::slot_assignShortcutsFromProfile);
connect(this, &mudlet::signal_profileActivated, this, &mudlet::slot_assignShortcutsFromProfile);
mpShortcutsManager = new ShortcutsManager(this);
mpShortcutsManager->registerShortcut(qsl("Script editor"), tr("Script editor"), &mKeySequenceTriggers);
mpShortcutsManager->registerShortcut(qsl("Show Map"), tr("Show Map"), &mKeySequenceShowMap);
mpShortcutsManager->registerShortcut(qsl("Compact input line"), tr("Compact input line"), &mKeySequenceInputLine);
mpShortcutsManager->registerShortcut(qsl("Preferences"), tr("Preferences"), &mKeySequenceOptions);
mpShortcutsManager->registerShortcut(qsl("Notepad"), tr("Notepad"), &mKeySequenceNotepad);
mpShortcutsManager->registerShortcut(qsl("Package manager"), tr("Package manager"), &mKeySequencePackages);
mpShortcutsManager->registerShortcut(qsl("Module manager"), tr("Module manager"), &mKeySequenceModules);
mpShortcutsManager->registerShortcut(qsl("MultiView"), tr("MultiView"), &mKeySequenceMultiView);
mpShortcutsManager->registerShortcut(qsl("Mute all media"), tr("Mute all media"), &mKeySequenceMute);
mpShortcutsManager->registerShortcut(qsl("Play"), tr("Play"), &mKeySequenceConnect);
mpShortcutsManager->registerShortcut(qsl("Disconnect"), tr("Disconnect"), &mKeySequenceDisconnect);
mpShortcutsManager->registerShortcut(qsl("Reconnect"), tr("Reconnect"), &mKeySequenceReconnect);
mpShortcutsManager->registerShortcut(qsl("Close profile"), tr("Close profile"), &mKeySequenceCloseProfile);
mpShortcutsManager->registerShortcut(qsl("Toggle Time Stamps"), tr("Toggle Time Stamps"), &mKeySequenceToggleTimeStamp);
mpShortcutsManager->registerShortcut(qsl("Toggle Replay"), tr("Toggle Replay"), &mKeySequenceToggleReplay);
mpShortcutsManager->registerShortcut(qsl("Toggle Logging"), tr("Toggle Logging"), &mKeySequenceToggleLogging);
mpShortcutsManager->registerShortcut(qsl("Toggle Emergency Stop"), tr("Toggle Emergency Stop"), &mKeySequenceToggleEmergencyStop);
readLateSettings(*mpSettings);
// The previous line will set an option used in the slot method:
connect(mpMainToolBar, &QToolBar::visibilityChanged, this, &mudlet::slot_handleToolbarVisibilityChanged);
connect(mpMainToolBar->toggleViewAction(), &QAction::triggered, this, &mudlet::slot_toolbarToggleActionTriggered);
dactionToggleFullScreen->setToolTip(utils::richText(tr("Toggle Full Screen View")));
// The readLateSetting(...) call will set the initial
// Full-Screen/Maximised/Normal state - we just need to set the knobs to
// match
mpActionFullScreenView->setChecked(windowState() & Qt::WindowFullScreen);
dactionToggleFullScreen->setChecked(windowState() & Qt::WindowFullScreen);
// Now we wire up the knobs, after they've been set to the right state:
connect(mpActionFullScreenView, &QAction::triggered, this, &mudlet::slot_toggleFullScreenView);
connect(dactionToggleFullScreen, &QAction::triggered, this, &mudlet::slot_toggleFullScreenView);
// And we also need to track outside causes that can change it:
connect(this, &mudlet::signal_windowStateChanged, this, &mudlet::slot_windowStateChanged);
#if defined(INCLUDE_UPDATER)
pUpdater = new Updater(this, mpSettings, !releaseVersion);
connect(pUpdater, &Updater::signal_updateAvailable, this, &mudlet::slot_updateAvailable);
connect(pUpdater, &Updater::signal_updateCheckFailed, this, &mudlet::slot_updateCheckFailed);
connect(dactionUpdate, &QAction::triggered, this, &mudlet::slot_manualUpdateCheck);
connect(dactionChangelog, &QAction::triggered, this, &mudlet::slot_showFullChangelog);
#if defined(Q_OS_MACOS)
// ensure that 'Check for updates' and 'Changelog' are under the Applications menu per convention
dactionUpdate->setMenuRole(QAction::ApplicationSpecificRole);
dactionChangelog->setMenuRole(QAction::ApplicationSpecificRole);
#else
connect(pUpdater, &Updater::signal_updateInstalled, this, &mudlet::slot_updateInstalled);
#endif // !Q_OS_MACOS
#endif // INCLUDE_UPDATER
if (!mToolbarIconSize) {
// If the button size has not been previously set - on the first run
// set it according to whether we are full-screen - originally this
// would have been because it was likely running on a small screen
// device; this may no longer be useful:
setToolBarIconSize((windowState() & Qt::WindowFullScreen) ? 2 : 3);
}
// Allow mute functionality always
mpButtonMute->setEnabled(true);
mpActionMuteMedia->setEnabled(true);
mpActionMuteAPI->setEnabled(true);
mpActionMuteGame->setEnabled(true);
dactionMuteMedia->setEnabled(true);
dactionMuteAPI->setEnabled(true);
dactionMuteGame->setEnabled(true);
// Edbee has a singleton that needs some initialisation
initEdbee();
// load bundled fonts
mFontManager.addFonts();
// Configure emoji font support
mFontManager.addEmojiFont();
// Initialise a couple of QMaps and some other elements that must be
// translated into the current GUI Language
loadMaps();
setupTrayIcon();
// emit the signal for adjusting accessible names
QTimer::singleShot(0, this, [this]() {
emit signal_adjustAccessibleNames();
});
// 200ms interval for WCAG 2.3.1 compliance (max 3 Hz)
// 4-state counter per ISO/IEC 8613-6: slow blink < 150 cycles/min, fast > 150
mpBlinkTimer = new QTimer(this);
mpBlinkTimer->setInterval(33);
connect(mpBlinkTimer, &QTimer::timeout, this, [this]() {
// Use actual elapsed time so the animation phase stays accurate even
// when the main thread is busy (map loads, incoming MUD data floods, etc.)
mBlinkTimeMs += static_cast<qreal>(mBlinkElapsedTimer.restart());
// Prevent floating-point drift; both periods (1000ms, 2000ms) divide evenly into 2000ms
if (mBlinkTimeMs >= 2000.0) {
mBlinkTimeMs = std::fmod(mBlinkTimeMs, 2000.0);
}
emit signal_blinkStateChanged();
});
// Monitor audio device changes to automatically refresh media players
mpMediaDevices = new QMediaDevices(this);
connect(mpMediaDevices, &QMediaDevices::audioOutputsChanged, this, &mudlet::slot_audioOutputDeviceChanged);
// Initialize the window menu on startup
updateWindowMenu();
// Connect the Window menu's aboutToShow signal to update the window list
connect(menuWindow, &QMenu::aboutToShow, this, &mudlet::updateWindowMenu);
// PLACEMARKER: sample benchmarking code
// looking to benchmark old/new code? Use this example
// full docs at https://nanobench.ankerl.com
// ankerl::nanobench::Bench benchmark;
// benchmark.title("Example benchmark")
// .minEpochIterations(2000)
// .warmup(100)
// .relative(true);
// benchmark.run("old code", [this] {
// loadMaps();
// });
// benchmark.run("new code", [this] {
// for (int i = 0; i < 2; i++) {
// loadMaps();
// }
// });
}
static QString findExecutableDir()
{
// Linux AppImage support
QProcessEnvironment systemEnvironment = QProcessEnvironment::systemEnvironment();
if (systemEnvironment.contains(qsl("APPIMAGE"))) {
QString appimgPath = systemEnvironment.value(qsl("APPIMAGE"), QString());
return QFileInfo(appimgPath).dir().path();
}
return QCoreApplication::applicationDirPath();
}
static QString readMarkerFile(const QString& path)
{
QString line;
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "mudlet: failed to open file for reading:" << path << file.errorString();
return QString();
}
QTextStream(&file).readLineInto(&line);
file.close();
return line;
}
static bool validateConfDir(QString& path)
{
if (path.isEmpty()) {
qWarning("WARN: portable data path not specified");
return false;
}
QFileInfo pathInfo(path);
if (pathInfo.isFile()) {
qWarning("WARN: specified portable data path is an existing file: %s", qPrintable(path));
return false;
}
QFileInfo parentInfo(pathInfo.dir().path());
if (!parentInfo.isDir()) {
qWarning("WARN: parent directory of specified portable data path doesn't exist: %s", qPrintable(parentInfo.filePath()));
return false;
}
return true;
}
static void migrateConfig(QSettings& settings)
{
if (settings.contains(qsl("pos"))) {
return;
}
// Old default configs, stored in NativeFormat
const QSettings settings_old2(qsl("mudlet"), qsl("Mudlet"));
if (settings_old2.contains(qsl("pos"))) {
for (auto& key : settings_old2.allKeys()) {
settings.setValue(key, settings_old2.value(key));
}
return;
}
const QSettings settings_old1(qsl("Mudlet"), qsl("Mudlet 1.0"));
if (settings_old1.contains(qsl("pos"))) {
for (auto& key : settings_old1.allKeys()) {
settings.setValue(key, settings_old1.value(key));
}
return;
}
}
void mudlet::setupConfig()
{
QString confDirDefault = qsl("%1/.config/mudlet").arg(QDir::homePath());
QString execDir = findExecutableDir();
QString markerExecDir = qsl("%1/portable.txt").arg(execDir);
QString markerHomeDir = qsl("%1/portable.txt").arg(confDirDefault);
if (QFileInfo(markerExecDir).isFile()) {
QString portPath = readMarkerFile(markerExecDir);
if (portPath.isEmpty()) {
portPath = qsl("./portable"); // fallback value for empty portable.txt
}
portPath = utils::pathResolveRelative(QDir::cleanPath(portPath), execDir);
if (!validateConfDir(portPath)) {
qFatal("FATAL: portable data path invalid");
}
confPath = portPath;
} else if (QFileInfo(markerHomeDir).isFile()) {
QString portPath = readMarkerFile(markerHomeDir);
portPath = utils::pathResolveRelative(QDir::cleanPath(portPath), execDir);
if (!validateConfDir(portPath)) {
qFatal("FATAL: portable data path invalid");
}
confPath = portPath;
} else {
confPath = confDirDefault;
}
qDebug() << "mudlet::setupConfig() INFO:" << "using config dir:" << confPath;
mpSettings = new QSettings(qsl("%1/Mudlet.ini").arg(confPath), QSettings::IniFormat);
migrateConfig(*mpSettings);
}
// This is a static wrapper for singleton instance method
// Should only be called after mudlet has been initialised
/*static*/ QSettings* mudlet::getQSettings()
{
return self()->mpSettings;
}
void mudlet::initEdbee()
{
auto edbee = edbee::Edbee::instance();
edbee->init();
edbee->autoShutDownOnAppExit();
auto grammarManager = edbee->grammarManager();
// We only need the single Lua lexer, probably ever
grammarManager->readGrammarFile(QLatin1String(":/edbee_defaults/Lua.tmLanguage"));
//Open and parse the luaFunctionList document into a stringlist for use with autocomplete
loadLuaFunctionList();
//QFile file(fileName);
//if( file.exists() && file.open(QIODevice::ReadOnly) ) {
loadEdbeeTheme(qsl("Mudlet"), qsl("Mudlet.tmTheme"));
}
void mudlet::loadMaps()
{
// Used to identify Hunspell dictionaries (some of which are not useful -
// the "_med" ones are suppliments and no good for Mudlet) - all keys are to
// be lower cased so that the values can be looked up with a
// QMap<T1, T2>::value(const T1&) where the parameter has been previously
// converted to all-lower case:
// From https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes:
// More useful is the cross-referenced (Country <-> Languages):
// https://www.unicode.org/cldr/charts/latest/supplemental/language_territory_information.html
// Initially populated from the dictionaries provided within the Debian
// GNU/Linux distribution:
//: In the translation source texts the language is the leading term, with, generally, the (primary) country(ies) in the brackets, with a trailing language disabiguation after a '-' Chinese is an exception!
mDictionaryLanguageCodeMap = {
{qsl("af"), tr("Afrikaans")},
{qsl("af_za"), tr("Afrikaans (South Africa)")},
{qsl("an"), tr("Aragonese")},
{qsl("an_es"), tr("Aragonese (Spain)")},
{qsl("ar"), tr("Arabic")},
{qsl("ar_ae"), tr("Arabic (United Arab Emirates)")},
{qsl("ar_bh"), tr("Arabic (Bahrain)")},
{qsl("ar_dz"), tr("Arabic (Algeria)")},
{qsl("ar_eg"), tr("Arabic (Egypt)")},
{qsl("ar_in"), tr("Arabic (India)")},
{qsl("ar_iq"), tr("Arabic (Iraq)")},
{qsl("ar_jo"), tr("Arabic (Jordan)")},
{qsl("ar_kw"), tr("Arabic (Kuwait)")},
{qsl("ar_lb"), tr("Arabic (Lebanon)")},
{qsl("ar_ly"), tr("Arabic (Libya)")},
{qsl("ar_ma"), tr("Arabic (Morocco)")},
{qsl("ar_om"), tr("Arabic (Oman)")},
{qsl("ar_qa"), tr("Arabic (Qatar)")},
{qsl("ar_sa"), tr("Arabic (Saudi Arabia)")},
{qsl("ar_sd"), tr("Arabic (Sudan)")},
{qsl("ar_sy"), tr("Arabic (Syria)")},
{qsl("ar_tn"), tr("Arabic (Tunisia)")},
{qsl("ar_ye"), tr("Arabic (Yemen)")},
{qsl("be"), tr("Belarusian")},
{qsl("be_by"), tr("Belarusian (Belarus)")},
{qsl("be_ru"), tr("Belarusian (Russia)")},