-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathconfiguration.cpp
More file actions
1513 lines (1350 loc) · 64.3 KB
/
configuration.cpp
File metadata and controls
1513 lines (1350 loc) · 64.3 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
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
// Author: Ulf Hermann <ulfonk_mennhar@gmx.de> (Alve)
// Author: Marek Krejza <krejza@gmail.com> (Caligor)
// Author: Nils Schimmelmann <nschimme@gmail.com> (Jahara)
#include "configuration.h"
#include "../global/utils.h"
#include "../map/infomark.h"
#include <cassert>
#include <mutex>
#include <optional>
#include <thread>
#include <QByteArray>
#include <QChar>
#include <QDir>
#include <QHostInfo>
#include <QSslSocket>
#include <QString>
#include <QStringList>
#undef TRANSPARENT // Bad dog, Microsoft; bad dog!!!
namespace { // anonymous
std::thread::id g_thread{};
std::atomic_bool g_config_enteredMain{false};
thread_local SharedCanvasNamedColorOptions tl_canvas_named_color_options;
thread_local SharedNamedColorOptions tl_named_color_options;
NODISCARD const char *getPlatformEditor()
{
switch (CURRENT_PLATFORM) {
case PlatformEnum::Windows:
return "notepad";
case PlatformEnum::Mac:
return "open -W -n -t";
case PlatformEnum::Linux:
// add .txt extension and use xdg-open instead?
// or if xdg-open doesn't exist, then you can
// look for gnome-open, mate-open, etc.
return "gedit";
case PlatformEnum::Unknown:
default:
return "";
}
}
NODISCARD TextureSetEnum intToTextureSet(int value)
{
switch (value) {
case 0:
return TextureSetEnum::CLASSIC;
case 1:
return TextureSetEnum::MODERN;
case 2:
return TextureSetEnum::CUSTOM;
default:
return TextureSetEnum::MODERN; // Default to Modern
}
}
NODISCARD int textureSetToInt(TextureSetEnum value)
{
return static_cast<int>(value);
}
} // namespace
Configuration::Configuration()
{
read(); // read the settings or set them to the default values
}
/*
* TODO: Make a dialog asking if the user wants to import settings
* from an older version of MMapper, and then change the organization name
* to reflect that it's an open source project that's not Caligor's
* personal project anymore.
*
* Also, don't use space, because it will be a file name on disk.
*/
#define ConstString static constexpr const char *const
ConstString SETTINGS_ORGANIZATION = "MUME";
ConstString OLD_SETTINGS_ORGANIZATION = "Caligor soft";
ConstString SETTINGS_APPLICATION = "MMapper2";
ConstString SETTINGS_FIRST_TIME_KEY = "General/Run first time";
class NODISCARD Settings final
{
private:
static constexpr const char *const MMAPPER_PROFILE_PATH = "MMAPPER_PROFILE_PATH";
private:
std::optional<QSettings> m_settings;
private:
NODISCARD static bool isValid(const QFile &file)
{
const QFileInfo info{file};
return !info.isDir() && info.exists() && info.isReadable() && info.isWritable();
}
NODISCARD static bool isValid(const QString &fileName)
{
const QFile file{fileName};
return isValid(file);
}
static void tryCopyOldSettings();
private:
void initSettings();
public:
DELETE_CTORS_AND_ASSIGN_OPS(Settings);
Settings() { initSettings(); }
~Settings() = default;
explicit operator QSettings &()
{
if (!m_settings) {
throw std::runtime_error("object does not exist");
}
return m_settings.value();
}
};
void Settings::initSettings()
{
if (m_settings) {
throw std::runtime_error("object already exists");
}
// NOTE: mutex guards read/write access to g_path from multiple threads,
// since the static variable can be set to nullptr on spurious failure.
static std::mutex g_mutex;
std::lock_guard<std::mutex> lock{g_mutex};
static auto g_path = qgetenv(MMAPPER_PROFILE_PATH);
if (g_path != nullptr) {
// NOTE: QMessageLogger quotes QString by default, but doesn't quote const char*.
const QString pathString{g_path};
static std::once_flag attempt_flag;
std::call_once(attempt_flag, [&pathString] {
qInfo() << "Attempting to use settings from" << pathString
<< "(specified by environment variable" << QString{MMAPPER_PROFILE_PATH}
<< ")...";
});
if (!isValid(pathString)) {
qWarning() << "Falling back to default settings path because" << pathString
<< "is not a writable file.";
g_path = nullptr;
} else {
try {
m_settings.emplace(pathString, QSettings::IniFormat);
} catch (...) {
qInfo() << "Exception loading settings for " << pathString
<< "; falling back to default settings...";
g_path = nullptr;
}
}
}
if (!m_settings) {
tryCopyOldSettings();
m_settings.emplace(SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
}
static std::once_flag success_flag;
std::call_once(success_flag, [this] {
auto &&info = qInfo();
info << "Using settings from" << QString{static_cast<QSettings &>(*this).fileName()};
if (g_path == nullptr) {
info << "(Hint: Environment variable" << QString{MMAPPER_PROFILE_PATH}
<< "overrides the default).";
} else {
info << ".";
}
});
}
//
// NOTES:
//
// * Avoiding using global QSettings& getSettings() because the QSettings object
// maintains some state, so it's better to construct a new one each time.
//
// * Declaring an object via macro instead of just calling a function is necessary
// because we have two object construction paths, and we attempt to access the
// value after its construction, so we can't use RVO to avoid copy/move
// construction of the QSettings object.
//
// * Using a separate reference because macros use "conf.beginGroup()", but
// "operator T&" is never selected when used with (non-existent) "operator.".
// Instead, we could use "conf->beginGroup()" with "QSettings* operator->()"
// to avoid needing to declare a QSettings& reference.
#define SETTINGS(conf) \
Settings settings; \
QSettings &conf = static_cast<QSettings &>(settings)
ConstString GRP_ADVENTURE_PANEL = "Adventure Panel";
ConstString GRP_ACCOUNT = "Account";
ConstString GRP_AUTO_LOAD_WORLD = "Auto load world";
ConstString GRP_AUTO_LOG = "Auto log";
ConstString GRP_CANVAS = "Canvas";
ConstString GRP_COMMS = "Communications";
ConstString GRP_CONNECTION = "Connection";
ConstString GRP_FINDROOMS_DIALOG = "FindRooms Dialog";
ConstString GRP_GENERAL = "General";
ConstString GRP_GROUP_MANAGER = "Group Manager";
ConstString GRP_HOTKEYS = "Hotkeys";
ConstString GRP_INFOMARKS_DIALOG = "InfoMarks Dialog";
ConstString GRP_INTEGRATED_MUD_CLIENT = "Integrated Mud Client";
ConstString GRP_MUME_CLIENT_PROTOCOL = "Mume client protocol";
ConstString GRP_MUME_CLOCK = "Mume Clock";
ConstString GRP_MUME_NATIVE = "Mume native";
ConstString GRP_PARSER = "Parser";
ConstString GRP_PATH_MACHINE = "Path Machine";
ConstString GRP_ROOM_PANEL = "Room Panel";
ConstString GRP_ROOMEDIT_DIALOG = "RoomEdit Dialog";
ConstString KEY_ABSOLUTE_PATH_ACCEPTANCE = "absolute path acceptance";
ConstString KEY_ACCOUNT_NAME = "account name";
ConstString KEY_ACCOUNT_PASSWORD = "account password";
ConstString KEY_ALWAYS_ON_TOP = "Always On Top";
ConstString KEY_SHOW_STATUS_BAR = "Show Status Bar";
ConstString KEY_SHOW_SCROLL_BARS = "Show Scroll Bars";
ConstString KEY_SHOW_MENU_BAR = "Show Menu Bar";
ConstString KEY_AUTO_LOAD = "Auto load";
ConstString KEY_AUTO_RESIZE_TERMINAL = "Auto resize terminal";
ConstString KEY_BACKGROUND_COLOR = "Background color";
ConstString KEY_CHARACTER_ENCODING = "Character encoding";
ConstString KEY_CHECK_FOR_UPDATE = "Check for update";
ConstString KEY_CLEAR_INPUT_ON_ENTER = "Clear input on enter";
ConstString KEY_COLUMNS = "Columns";
ConstString KEY_COMMAND_PREFIX_CHAR = "Command prefix character";
ConstString KEY_CONNECTION_NORMAL_COLOR = "Connection normal color";
ConstString KEY_CORRECT_POSITION_BONUS = "correct position bonus";
ConstString KEY_DISPLAY_XP_STATUS = "Display XP status bar widget";
ConstString KEY_DISPLAY_CLOCK = "Display clock";
ConstString KEY_GMCP_BROADCAST_CLOCK = "GMCP broadcast clock";
ConstString KEY_GMCP_BROADCAST_INTERVAL = "GMCP broadcast interval";
ConstString KEY_DRAW_DOOR_NAMES = "Draw door names";
ConstString KEY_DRAW_NOT_MAPPED_EXITS = "Draw not mapped exits";
ConstString KEY_DRAW_UPPER_LAYERS_TEXTURED = "Draw upper layers textured";
ConstString KEY_LAYER_TRANSPARENCY = "Layer transparency";
ConstString KEY_EMOJI_ENCODE = "encode emoji";
ConstString KEY_EMOJI_DECODE = "decode emoji";
ConstString KEY_EMULATED_EXITS = "Emulated Exits";
ConstString KEY_EXTERNAL_EDITOR_COMMAND = "External editor command";
ConstString KEY_FILE_NAME = "File name";
ConstString KEY_GROUP_YOUR_COLOR = "color";
ConstString KEY_GROUP_NPC_COLOR = "npc color";
ConstString KEY_GROUP_NPC_COLOR_OVERRIDE = "npc color override";
ConstString KEY_GROUP_NPC_SORT_BOTTOM = "npc sort bottom";
ConstString KEY_GROUP_NPC_HIDE = "npc hide";
ConstString KEY_AUTO_LOG = "Auto log";
ConstString KEY_AUTO_LOG_ASK_DELETE = "Auto log ask before deleting";
ConstString KEY_AUTO_LOG_CLEANUP_STRATEGY = "Auto log cleanup strategy";
ConstString KEY_AUTO_LOG_DELETE_AFTER_DAYS = "Auto log delete after X days";
ConstString KEY_AUTO_LOG_DELETE_AFTER_BYTES = "Auto log delete after X bytes";
ConstString KEY_AUTO_LOG_DIRECTORY = "Auto log directory";
ConstString KEY_AUTO_LOG_ROTATE_SIZE_BYTES = "Auto log rotate after X bytes";
ConstString KEY_FONT = "Font";
ConstString KEY_FOREGROUND_COLOR = "Foreground color";
ConstString KEY_3D_CANVAS = "canvas.advanced.use3D";
ConstString KEY_3D_AUTO_TILT = "canvas.advanced.autoTilt";
ConstString KEY_3D_PERFSTATS = "canvas.advanced.printPerfStats";
ConstString KEY_3D_FOV = "canvas.advanced.fov";
ConstString KEY_3D_VERTICAL_ANGLE = "canvas.advanced.verticalAngle";
ConstString KEY_3D_HORIZONTAL_ANGLE = "canvas.advanced.horizontalAngle";
ConstString KEY_3D_LAYER_HEIGHT = "canvas.advanced.layerHeight";
ConstString KEY_BACKGROUND_IMAGE_ENABLED = "canvas.advanced.backgroundImageEnabled";
ConstString KEY_BACKGROUND_IMAGE_PATH = "canvas.advanced.backgroundImagePath";
ConstString KEY_BACKGROUND_IMAGE_FIT_MODE = "canvas.advanced.backgroundFitMode";
ConstString KEY_BACKGROUND_IMAGE_OPACITY = "canvas.advanced.backgroundOpacity";
ConstString KEY_BACKGROUND_IMAGE_FOCUSED_SCALE = "canvas.advanced.backgroundFocusedScale";
ConstString KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_X = "canvas.advanced.backgroundFocusedOffsetX";
ConstString KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_Y = "canvas.advanced.backgroundFocusedOffsetY";
ConstString KEY_VISIBLE_MARKER_GENERIC = "canvas.visibleMarkers.generic";
ConstString KEY_VISIBLE_MARKER_HERB = "canvas.visibleMarkers.herb";
ConstString KEY_VISIBLE_MARKER_RIVER = "canvas.visibleMarkers.river";
ConstString KEY_VISIBLE_MARKER_PLACE = "canvas.visibleMarkers.place";
ConstString KEY_VISIBLE_MARKER_MOB = "canvas.visibleMarkers.mob";
ConstString KEY_VISIBLE_MARKER_COMMENT = "canvas.visibleMarkers.comment";
ConstString KEY_VISIBLE_MARKER_ROAD = "canvas.visibleMarkers.road";
ConstString KEY_VISIBLE_MARKER_OBJECT = "canvas.visibleMarkers.object";
ConstString KEY_VISIBLE_MARKER_ACTION = "canvas.visibleMarkers.action";
ConstString KEY_VISIBLE_MARKER_LOCALITY = "canvas.visibleMarkers.locality";
ConstString KEY_VISIBLE_CONNECTIONS = "canvas.visibilityFilter.connections";
// Hotkey configuration keys
ConstString KEY_HOTKEY_FILE_OPEN = "hotkeys.fileOpen";
ConstString KEY_HOTKEY_FILE_SAVE = "hotkeys.fileSave";
ConstString KEY_HOTKEY_FILE_RELOAD = "hotkeys.fileReload";
ConstString KEY_HOTKEY_FILE_QUIT = "hotkeys.fileQuit";
ConstString KEY_HOTKEY_EDIT_UNDO = "hotkeys.editUndo";
ConstString KEY_HOTKEY_EDIT_REDO = "hotkeys.editRedo";
ConstString KEY_HOTKEY_EDIT_PREFERENCES = "hotkeys.editPreferences";
ConstString KEY_HOTKEY_EDIT_PREFERENCES_ALT = "hotkeys.editPreferencesAlt";
ConstString KEY_HOTKEY_EDIT_FIND_ROOMS = "hotkeys.editFindRooms";
ConstString KEY_HOTKEY_EDIT_ROOM = "hotkeys.editRoom";
ConstString KEY_HOTKEY_VIEW_ZOOM_IN = "hotkeys.viewZoomIn";
ConstString KEY_HOTKEY_VIEW_ZOOM_OUT = "hotkeys.viewZoomOut";
ConstString KEY_HOTKEY_VIEW_ZOOM_RESET = "hotkeys.viewZoomReset";
ConstString KEY_HOTKEY_VIEW_LAYER_UP = "hotkeys.viewLayerUp";
ConstString KEY_HOTKEY_VIEW_LAYER_DOWN = "hotkeys.viewLayerDown";
ConstString KEY_HOTKEY_VIEW_LAYER_RESET = "hotkeys.viewLayerReset";
ConstString KEY_HOTKEY_VIEW_RADIAL_TRANSPARENCY = "hotkeys.viewRadialTransparency";
ConstString KEY_HOTKEY_VIEW_STATUS_BAR = "hotkeys.viewStatusBar";
ConstString KEY_HOTKEY_VIEW_SCROLL_BARS = "hotkeys.viewScrollBars";
ConstString KEY_HOTKEY_VIEW_MENU_BAR = "hotkeys.viewMenuBar";
ConstString KEY_HOTKEY_VIEW_ALWAYS_ON_TOP = "hotkeys.viewAlwaysOnTop";
ConstString KEY_HOTKEY_PANEL_LOG = "hotkeys.panelLog";
ConstString KEY_HOTKEY_PANEL_CLIENT = "hotkeys.panelClient";
ConstString KEY_HOTKEY_PANEL_GROUP = "hotkeys.panelGroup";
ConstString KEY_HOTKEY_PANEL_ROOM = "hotkeys.panelRoom";
ConstString KEY_HOTKEY_PANEL_ADVENTURE = "hotkeys.panelAdventure";
ConstString KEY_HOTKEY_PANEL_COMMS = "hotkeys.panelComms";
ConstString KEY_HOTKEY_PANEL_DESCRIPTION = "hotkeys.panelDescription";
ConstString KEY_HOTKEY_MODE_MOVE_MAP = "hotkeys.modeMoveMap";
ConstString KEY_HOTKEY_MODE_RAYPICK = "hotkeys.modeRaypick";
ConstString KEY_HOTKEY_MODE_SELECT_ROOMS = "hotkeys.modeSelectRooms";
ConstString KEY_HOTKEY_MODE_SELECT_MARKERS = "hotkeys.modeSelectMarkers";
ConstString KEY_HOTKEY_MODE_SELECT_CONNECTION = "hotkeys.modeSelectConnection";
ConstString KEY_HOTKEY_MODE_CREATE_MARKER = "hotkeys.modeCreateMarker";
ConstString KEY_HOTKEY_MODE_CREATE_ROOM = "hotkeys.modeCreateRoom";
ConstString KEY_HOTKEY_MODE_CREATE_CONNECTION = "hotkeys.modeCreateConnection";
ConstString KEY_HOTKEY_MODE_CREATE_ONEWAY_CONNECTION = "hotkeys.modeCreateOnewayConnection";
ConstString KEY_HOTKEY_ROOM_CREATE = "hotkeys.roomCreate";
ConstString KEY_HOTKEY_ROOM_MOVE_UP = "hotkeys.roomMoveUp";
ConstString KEY_HOTKEY_ROOM_MOVE_DOWN = "hotkeys.roomMoveDown";
ConstString KEY_HOTKEY_ROOM_MERGE_UP = "hotkeys.roomMergeUp";
ConstString KEY_HOTKEY_ROOM_MERGE_DOWN = "hotkeys.roomMergeDown";
ConstString KEY_HOTKEY_ROOM_DELETE = "hotkeys.roomDelete";
ConstString KEY_HOTKEY_ROOM_CONNECT_NEIGHBORS = "hotkeys.roomConnectNeighbors";
ConstString KEY_HOTKEY_ROOM_MOVE_TO_SELECTED = "hotkeys.roomMoveToSelected";
ConstString KEY_HOTKEY_ROOM_UPDATE_SELECTED = "hotkeys.roomUpdateSelected";
ConstString KEY_LAST_MAP_LOAD_DIRECTORY = "Last map load directory";
ConstString KEY_LINES_OF_INPUT_HISTORY = "Lines of input history";
ConstString KEY_LINES_OF_PEEK_PREVIEW = "Lines of peek preview";
ConstString KEY_LINES_OF_SCROLLBACK = "Lines of scrollback";
ConstString KEY_PROXY_LOCAL_PORT = "Local port number";
ConstString KEY_MAP_MODE = "Map Mode";
ConstString KEY_MAXIMUM_NUMBER_OF_PATHS = "maximum number of paths";
ConstString KEY_MULTIPLE_CONNECTIONS_PENALTY = "multiple connections penalty";
ConstString KEY_MUME_START_EPOCH = "Mume start epoch";
ConstString KEY_NUMBER_OF_ANTI_ALIASING_SAMPLES = "Number of anti-aliasing samples";
ConstString KEY_PROXY_CONNECTION_STATUS = "Proxy connection status";
ConstString KEY_PROXY_LISTENS_ON_ANY_INTERFACE = "Proxy listens on any interface";
ConstString KEY_RELATIVE_PATH_ACCEPTANCE = "relative path acceptance";
ConstString KEY_RESOURCES_DIRECTORY = "canvas.resourcesDir";
ConstString KEY_TEXTURE_SET = "canvas.textureSet";
ConstString KEY_ENABLE_SEASONAL_TEXTURES = "canvas.enableSeasonalTextures";
ConstString KEY_MUME_REMOTE_PORT = "Remote port number";
ConstString KEY_REMEMBER_LOGIN = "remember login";
ConstString KEY_ROOM_CREATION_PENALTY = "room creation penalty";
ConstString KEY_ROOM_DARK_COLOR = "Room dark color";
ConstString KEY_ROOM_DARK_LIT_COLOR = "Room dark lit color";
ConstString KEY_ROOM_DESC_ANSI_COLOR = "Room desc ansi color";
ConstString KEY_ROOM_MATCHING_TOLERANCE = "room matching tolerance";
ConstString KEY_ROOM_NAME_ANSI_COLOR = "Room name ansi color";
ConstString KEY_ROWS = "Rows";
ConstString KEY_RUN_FIRST_TIME = "Run first time";
ConstString KEY_SERVER_NAME = "Server name";
ConstString KEY_SHOW_HIDDEN_EXIT_FLAGS = "Show hidden exit flags";
ConstString KEY_SHOW_NOTES = "Show notes";
ConstString KEY_SHOW_UNSAVED_CHANGES = "Show unsaved changes";
ConstString KEY_SHOW_MISSING_MAP_ID = "Show missing map id";
ConstString KEY_TAB_COMPLETION_DICTIONARY_SIZE = "Tab completion dictionary size";
ConstString KEY_TLS_ENCRYPTION = "TLS encryption";
ConstString KEY_USE_INTERNAL_EDITOR = "Use internal editor";
ConstString KEY_USE_TRILINEAR_FILTERING = "Use trilinear filtering";
ConstString KEY_WINDOW_GEOMETRY = "Window Geometry";
ConstString KEY_WINDOW_STATE = "Window State";
void Settings::tryCopyOldSettings()
{
QSettings sNew(SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
if (!sNew.allKeys().contains(SETTINGS_FIRST_TIME_KEY)) {
const QSettings sOld(OLD_SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
if (!sOld.allKeys().isEmpty()) {
qInfo() << "Copying old config" << sOld.fileName() << "to" << sNew.fileName() << "...";
for (const QString &key : sOld.allKeys()) {
sNew.setValue(key, sOld.value(key));
}
}
}
// News 2340, changing domain from fire.pvv.org to mume.org:
sNew.beginGroup(GRP_CONNECTION);
if (sNew.value(KEY_SERVER_NAME, "").toString().contains("pvv.org")) {
sNew.setValue(KEY_SERVER_NAME, "mume.org");
}
sNew.endGroup();
}
NODISCARD static bool isValidAnsi(const QString &input)
{
static constexpr const auto MAX = static_cast<uint32_t>(std::numeric_limits<uint8_t>::max());
if (!input.startsWith("[") || !input.endsWith("m")) {
return false;
}
for (const auto &part : input.mid(1, input.length() - 2).split(";")) {
for (const QChar c : part) {
if (!c.isDigit()) {
return false;
}
}
bool ok = false;
const auto n = part.toUInt(&ok, 10);
if (!ok || n > MAX) {
return false;
}
}
return true;
}
NODISCARD static bool isValidMapMode(const MapModeEnum mode)
{
switch (mode) {
case MapModeEnum::PLAY:
case MapModeEnum::MAP:
case MapModeEnum::OFFLINE:
return true;
}
return false;
}
NODISCARD static bool isValidCharacterEncoding(const CharacterEncodingEnum encoding)
{
switch (encoding) {
case CharacterEncodingEnum::ASCII:
case CharacterEncodingEnum::LATIN1:
case CharacterEncodingEnum::UTF8:
return true;
}
return false;
}
NODISCARD static bool isValidAutoLoggerState(const AutoLoggerEnum strategy)
{
switch (strategy) {
case AutoLoggerEnum::DeleteDays:
case AutoLoggerEnum::DeleteSize:
case AutoLoggerEnum::KeepForever:
return true;
}
return false;
}
NODISCARD static QString sanitizeAnsi(const QString &input, const QString &defaultValue)
{
assert(isValidAnsi(defaultValue));
if (isValidAnsi(input)) {
return input;
}
if (!input.isEmpty()) {
qWarning() << "invalid ansi code: " << input;
}
return defaultValue;
}
NODISCARD static MapModeEnum sanitizeMapMode(const uint32_t input)
{
const auto mode = static_cast<MapModeEnum>(input);
if (isValidMapMode(mode)) {
return mode;
}
qWarning() << "invalid MapMode:" << input;
return MapModeEnum::PLAY;
}
NODISCARD static CharacterEncodingEnum sanitizeCharacterEncoding(const uint32_t input)
{
const auto encoding = static_cast<CharacterEncodingEnum>(input);
if (isValidCharacterEncoding(encoding)) {
return encoding;
}
qWarning() << "invalid CharacterEncodingEnum:" << input;
return CharacterEncodingEnum::LATIN1;
}
NODISCARD static AutoLoggerEnum sanitizeAutoLoggerState(const int input)
{
const auto state = static_cast<AutoLoggerEnum>(input);
if (isValidAutoLoggerState(state)) {
return state;
}
qWarning() << "invalid AutoLoggerEnum:" << input;
return AutoLoggerEnum::DeleteDays;
}
NODISCARD static uint16_t sanitizeUint16(const int input, const uint16_t defaultValue)
{
static constexpr const auto MIN = static_cast<int>(std::numeric_limits<uint16_t>::min());
static constexpr const auto MAX = static_cast<int>(std::numeric_limits<uint16_t>::max());
if (isClamped(input, MIN, MAX)) {
return static_cast<uint16_t>(input);
}
qWarning() << "invalid uint16: " << input;
return defaultValue;
}
#define GROUP_CALLBACK(callback, name, ref) \
do { \
conf.beginGroup(name); \
ref.callback(conf); \
conf.endGroup(); \
} while (false)
#define FOREACH_CONFIG_GROUP(callback) \
do { \
GROUP_CALLBACK(callback, GRP_GENERAL, general); \
GROUP_CALLBACK(callback, GRP_CONNECTION, connection); \
GROUP_CALLBACK(callback, GRP_CANVAS, canvas); \
GROUP_CALLBACK(callback, GRP_HOTKEYS, hotkeys); \
GROUP_CALLBACK(callback, GRP_COMMS, comms); \
GROUP_CALLBACK(callback, GRP_ACCOUNT, account); \
GROUP_CALLBACK(callback, GRP_AUTO_LOAD_WORLD, autoLoad); \
GROUP_CALLBACK(callback, GRP_AUTO_LOG, autoLog); \
GROUP_CALLBACK(callback, GRP_PARSER, parser); \
GROUP_CALLBACK(callback, GRP_MUME_CLIENT_PROTOCOL, mumeClientProtocol); \
GROUP_CALLBACK(callback, GRP_MUME_NATIVE, mumeNative); \
GROUP_CALLBACK(callback, GRP_PATH_MACHINE, pathMachine); \
GROUP_CALLBACK(callback, GRP_GROUP_MANAGER, groupManager); \
GROUP_CALLBACK(callback, GRP_MUME_CLOCK, mumeClock); \
GROUP_CALLBACK(callback, GRP_ADVENTURE_PANEL, adventurePanel); \
GROUP_CALLBACK(callback, GRP_INTEGRATED_MUD_CLIENT, integratedClient); \
GROUP_CALLBACK(callback, GRP_INFOMARKS_DIALOG, infomarksDialog); \
GROUP_CALLBACK(callback, GRP_ROOMEDIT_DIALOG, roomEditDialog); \
GROUP_CALLBACK(callback, GRP_ROOM_PANEL, roomPanel); \
GROUP_CALLBACK(callback, GRP_FINDROOMS_DIALOG, findRoomsDialog); \
} while (false)
void Configuration::read()
{
// reset to defaults before reading colors that might override them
colorSettings.resetToDefaults();
SETTINGS(conf);
FOREACH_CONFIG_GROUP(read);
// This logic only runs once on a MMapper fresh install (or factory reset)
// Subsequent MMapper starts will always read "firstRun" as false
if (general.firstRun) {
// New users get the 3D canvas but old users do not
canvas.advanced.use3D.set(true);
// New users get autologger turned on by default
autoLog.autoLog = true;
}
assert(canvas.backgroundColor == colorSettings.BACKGROUND);
assert(canvas.roomDarkColor == colorSettings.ROOM_DARK);
assert(canvas.roomDarkLitColor == colorSettings.ROOM_NO_SUNDEATH);
assert(colorSettings.TRANSPARENT.isInitialized()
&& colorSettings.TRANSPARENT.getColor().isTransparent());
assert(colorSettings.BACKGROUND.isInitialized()
&& !colorSettings.BACKGROUND.getColor().isTransparent());
}
void Configuration::write() const
{
SETTINGS(conf);
FOREACH_CONFIG_GROUP(write);
}
void Configuration::reset()
{
{
// Purge old organization settings first to prevent them from being migrated
QSettings oldConf(OLD_SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
oldConf.clear();
}
{
// Purge new organization settings
SETTINGS(conf);
conf.clear();
}
// Reload defaults
read();
}
#undef FOREACH_CONFIG_GROUP
#undef GROUP_CALLBACK
ConstString DEFAULT_MMAPPER_SUBDIR = "/MMapper";
ConstString DEFAULT_LOGS_SUBDIR = "/Logs";
ConstString DEFAULT_RESOURCES_SUBDIR = "/Resources";
NODISCARD static QString getDefaultDirectory()
{
return QDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).absolutePath();
}
void Configuration::GeneralSettings::read(const QSettings &conf)
{
firstRun = conf.value(KEY_RUN_FIRST_TIME, true).toBool();
/*
* REVISIT: It's basically impossible to verify that this state is valid,
* because we have no idea what it contains!
*
* This setting is inherently non-portable between OSes
* (and possibly even window managers), so it doesn't belong here!
*
* If we're going to save it, then we should probably least checksum it
* (or better yet sign it), and record the OS config, so that we won't
* try to apply Windows settings to Mac, or Gnome settings to KDE, etc?
*/
windowGeometry = conf.value(KEY_WINDOW_GEOMETRY).toByteArray();
windowState = conf.value(KEY_WINDOW_STATE).toByteArray();
alwaysOnTop = conf.value(KEY_ALWAYS_ON_TOP, false).toBool();
showStatusBar = conf.value(KEY_SHOW_STATUS_BAR, true).toBool();
showScrollBars = conf.value(KEY_SHOW_SCROLL_BARS, true).toBool();
showMenuBar = conf.value(KEY_SHOW_MENU_BAR, true).toBool();
mapMode = sanitizeMapMode(
conf.value(KEY_MAP_MODE, static_cast<uint32_t>(MapModeEnum::PLAY)).toUInt());
checkForUpdate = conf.value(KEY_CHECK_FOR_UPDATE, true).toBool();
characterEncoding = sanitizeCharacterEncoding(
conf.value(KEY_CHARACTER_ENCODING, static_cast<uint32_t>(CharacterEncodingEnum::LATIN1))
.toUInt());
}
void Configuration::ConnectionSettings::read(const QSettings &conf)
{
static constexpr const int DEFAULT_PORT = 4242;
remoteServerName = conf.value(KEY_SERVER_NAME, "mume.org").toString();
remotePort = sanitizeUint16(conf.value(KEY_MUME_REMOTE_PORT, DEFAULT_PORT).toInt(),
static_cast<uint16_t>(DEFAULT_PORT));
localPort = sanitizeUint16(conf.value(KEY_PROXY_LOCAL_PORT, DEFAULT_PORT).toInt(),
static_cast<uint16_t>(DEFAULT_PORT));
tlsEncryption = QSslSocket::supportsSsl() ? conf.value(KEY_TLS_ENCRYPTION, true).toBool()
: false;
proxyConnectionStatus = conf.value(KEY_PROXY_CONNECTION_STATUS, false).toBool();
proxyListensOnAnyInterface = conf.value(KEY_PROXY_LISTENS_ON_ANY_INTERFACE, false).toBool();
}
// closest well-known color is "Outer Space"
static constexpr const std::string_view DEFAULT_BGCOLOR = "#161f21";
// closest well-known color is "Dusty Gray"
static constexpr const std::string_view DEFAULT_DARK_COLOR = "#A19494";
// closest well-known color is "Cold Turkey"
static constexpr const std::string_view DEFAULT_NO_SUNDEATH_COLOR = "#D4C7C7";
void Configuration::CanvasSettings::read(const QSettings &conf)
{
// REVISIT: Consider just using the "current" value of the named color object,
// since we can assume they're initialized before the values are read.
const auto lookupColor = [&conf](const char *const key, std::string_view def) {
// NOTE: string_view isn't guaranteed to be null-terminated,
// but wow... this is a complicated way of passing the exact same value.
const auto qdef = QColor(QString(std::string{def}.c_str())).name();
return Color(QColor(conf.value(key, qdef).toString()));
};
resourcesDirectory = conf.value(KEY_RESOURCES_DIRECTORY,
getDefaultDirectory()
.append(DEFAULT_MMAPPER_SUBDIR)
.append(DEFAULT_RESOURCES_SUBDIR))
.toString();
textureSet = intToTextureSet(conf.value(KEY_TEXTURE_SET, 1).toInt()); // Default: MODERN
enableSeasonalTextures = conf.value(KEY_ENABLE_SEASONAL_TEXTURES, true).toBool();
showMissingMapId.set(conf.value(KEY_SHOW_MISSING_MAP_ID, true).toBool());
showUnsavedChanges.set(conf.value(KEY_SHOW_UNSAVED_CHANGES, true).toBool());
showUnmappedExits.set(conf.value(KEY_DRAW_NOT_MAPPED_EXITS, true).toBool());
drawUpperLayersTextured = conf.value(KEY_DRAW_UPPER_LAYERS_TEXTURED, false).toBool();
drawDoorNames = conf.value(KEY_DRAW_DOOR_NAMES, true).toBool();
layerTransparency = conf.value(KEY_LAYER_TRANSPARENCY, 1.0).toFloat();
backgroundColor = lookupColor(KEY_BACKGROUND_COLOR, DEFAULT_BGCOLOR);
connectionNormalColor = lookupColor(KEY_CONNECTION_NORMAL_COLOR, Colors::white.toHex());
roomDarkColor = lookupColor(KEY_ROOM_DARK_COLOR, DEFAULT_DARK_COLOR);
roomDarkLitColor = lookupColor(KEY_ROOM_DARK_LIT_COLOR, DEFAULT_NO_SUNDEATH_COLOR);
antialiasingSamples = conf.value(KEY_NUMBER_OF_ANTI_ALIASING_SAMPLES, 0).toInt();
trilinearFiltering = conf.value(KEY_USE_TRILINEAR_FILTERING, true).toBool();
advanced.use3D.set(conf.value(KEY_3D_CANVAS, false).toBool());
advanced.autoTilt.set(conf.value(KEY_3D_AUTO_TILT, true).toBool());
advanced.printPerfStats.set(conf.value(KEY_3D_PERFSTATS, IS_DEBUG_BUILD).toBool());
advanced.fov.set(conf.value(KEY_3D_FOV, 765).toInt());
advanced.verticalAngle.set(conf.value(KEY_3D_VERTICAL_ANGLE, 450).toInt());
advanced.horizontalAngle.set(conf.value(KEY_3D_HORIZONTAL_ANGLE, 0).toInt());
advanced.layerHeight.set(conf.value(KEY_3D_LAYER_HEIGHT, 15).toInt());
// Load background image settings
advanced.useBackgroundImage = conf.value(KEY_BACKGROUND_IMAGE_ENABLED, false).toBool();
advanced.backgroundImagePath = conf.value(KEY_BACKGROUND_IMAGE_PATH, "").toString();
advanced.backgroundFitMode = conf.value(KEY_BACKGROUND_IMAGE_FIT_MODE, 0).toInt();
advanced.backgroundOpacity = conf.value(KEY_BACKGROUND_IMAGE_OPACITY, 1.0f).toFloat();
advanced.backgroundFocusedScale = conf.value(KEY_BACKGROUND_IMAGE_FOCUSED_SCALE, 1.0f).toFloat();
advanced.backgroundFocusedOffsetX = conf.value(KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_X, 0.0f)
.toFloat();
advanced.backgroundFocusedOffsetY = conf.value(KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_Y, 0.0f)
.toFloat();
// Load visible markers settings
visibilityFilter.generic.set(conf.value(KEY_VISIBLE_MARKER_GENERIC, true).toBool());
visibilityFilter.herb.set(conf.value(KEY_VISIBLE_MARKER_HERB, true).toBool());
visibilityFilter.river.set(conf.value(KEY_VISIBLE_MARKER_RIVER, true).toBool());
visibilityFilter.place.set(conf.value(KEY_VISIBLE_MARKER_PLACE, true).toBool());
visibilityFilter.mob.set(conf.value(KEY_VISIBLE_MARKER_MOB, true).toBool());
visibilityFilter.comment.set(conf.value(KEY_VISIBLE_MARKER_COMMENT, true).toBool());
visibilityFilter.road.set(conf.value(KEY_VISIBLE_MARKER_ROAD, true).toBool());
visibilityFilter.object.set(conf.value(KEY_VISIBLE_MARKER_OBJECT, true).toBool());
visibilityFilter.action.set(conf.value(KEY_VISIBLE_MARKER_ACTION, true).toBool());
visibilityFilter.locality.set(conf.value(KEY_VISIBLE_MARKER_LOCALITY, true).toBool());
visibilityFilter.connections.set(conf.value(KEY_VISIBLE_CONNECTIONS, true).toBool());
}
void Configuration::AccountSettings::read(const QSettings &conf)
{
accountName = conf.value(KEY_ACCOUNT_NAME, "").toString();
accountPassword = conf.value(KEY_ACCOUNT_PASSWORD, false).toBool();
rememberLogin = NO_QTKEYCHAIN ? false : conf.value(KEY_REMEMBER_LOGIN, false).toBool();
}
void Configuration::AutoLoadSettings::read(const QSettings &conf)
{
autoLoadMap = conf.value(KEY_AUTO_LOAD, true).toBool();
fileName = conf.value(KEY_FILE_NAME, "").toString();
lastMapDirectory = conf.value(KEY_LAST_MAP_LOAD_DIRECTORY,
getDefaultDirectory().append(DEFAULT_MMAPPER_SUBDIR))
.toString();
}
void Configuration::AutoLogSettings::read(const QSettings &conf)
{
autoLogDirectory = conf.value(KEY_AUTO_LOG_DIRECTORY,
getDefaultDirectory()
.append(DEFAULT_MMAPPER_SUBDIR)
.append(DEFAULT_LOGS_SUBDIR))
.toString();
autoLog = conf.value(KEY_AUTO_LOG, false).toBool();
rotateWhenLogsReachBytes = conf.value(KEY_AUTO_LOG_ROTATE_SIZE_BYTES, 10 * 1000000)
.toInt(); // 10 Megabytes
askDelete = conf.value(KEY_AUTO_LOG_ASK_DELETE, false).toBool();
cleanupStrategy = sanitizeAutoLoggerState(
conf.value(KEY_AUTO_LOG_CLEANUP_STRATEGY, static_cast<int>(AutoLoggerEnum::DeleteDays))
.toInt());
deleteWhenLogsReachDays = conf.value(KEY_AUTO_LOG_DELETE_AFTER_DAYS, 30).toInt();
deleteWhenLogsReachBytes = conf.value(KEY_AUTO_LOG_DELETE_AFTER_BYTES, 100 * 1000000).toInt();
}
void Configuration::ParserSettings::read(const QSettings &conf)
{
static constexpr const char *const ANSI_GREEN = "[32m";
static constexpr const char *const ANSI_RESET = "[0m";
roomNameColor = sanitizeAnsi(conf.value(KEY_ROOM_NAME_ANSI_COLOR, ANSI_GREEN).toString(),
QString(ANSI_GREEN));
roomDescColor = sanitizeAnsi(conf.value(KEY_ROOM_DESC_ANSI_COLOR, ANSI_RESET).toString(),
QString(ANSI_RESET));
prefixChar = conf.value(KEY_COMMAND_PREFIX_CHAR, QChar::fromLatin1(char_consts::C_UNDERSCORE))
.toChar()
.toLatin1();
encodeEmoji = conf.value(KEY_EMOJI_ENCODE, true).toBool();
decodeEmoji = conf.value(KEY_EMOJI_DECODE, true).toBool();
}
void Configuration::MumeClientProtocolSettings::read(const QSettings &conf)
{
internalRemoteEditor = conf.value(KEY_USE_INTERNAL_EDITOR, true).toBool();
externalRemoteEditorCommand = conf.value(KEY_EXTERNAL_EDITOR_COMMAND, getPlatformEditor())
.toString();
}
void Configuration::MumeNativeSettings::read(const QSettings &conf)
{
emulatedExits = conf.value(KEY_EMULATED_EXITS, true).toBool();
showHiddenExitFlags = conf.value(KEY_SHOW_HIDDEN_EXIT_FLAGS, true).toBool();
showNotes = conf.value(KEY_SHOW_NOTES, true).toBool();
}
void Configuration::PathMachineSettings::read(const QSettings &conf)
{
acceptBestRelative = conf.value(KEY_RELATIVE_PATH_ACCEPTANCE, 25).toDouble();
acceptBestAbsolute = conf.value(KEY_ABSOLUTE_PATH_ACCEPTANCE, 6).toDouble();
newRoomPenalty = conf.value(KEY_ROOM_CREATION_PENALTY, 5).toDouble();
correctPositionBonus = conf.value(KEY_CORRECT_POSITION_BONUS, 5).toDouble();
multipleConnectionsPenalty = conf.value(KEY_MULTIPLE_CONNECTIONS_PENALTY, 2.0).toDouble();
maxPaths = utils::clampNonNegative(conf.value(KEY_MAXIMUM_NUMBER_OF_PATHS, 1000).toInt());
matchingTolerance = utils::clampNonNegative(conf.value(KEY_ROOM_MATCHING_TOLERANCE, 8).toInt());
}
void Configuration::GroupManagerSettings::read(const QSettings &conf)
{
color = QColor(conf.value(KEY_GROUP_YOUR_COLOR, "#FFFF00").toString());
npcColor = QColor(conf.value(KEY_GROUP_NPC_COLOR, QColor(Qt::lightGray)).toString());
npcColorOverride = conf.value(KEY_GROUP_NPC_COLOR_OVERRIDE, false).toBool();
npcHide = conf.value(KEY_GROUP_NPC_HIDE, false).toBool();
npcSortBottom = conf.value(KEY_GROUP_NPC_SORT_BOTTOM, false).toBool();
}
Configuration::MumeClockSettings::MumeClockSettings() = default;
void Configuration::MumeClockSettings::read(const QSettings &conf)
{
// NOTE: old values might be stored as int32
startEpoch = conf.value(KEY_MUME_START_EPOCH, 1517443173).toLongLong();
display = conf.value(KEY_DISPLAY_CLOCK, true).toBool();
gmcpBroadcast.set(conf.value(KEY_GMCP_BROADCAST_CLOCK, true).toBool());
gmcpBroadcastInterval.set(conf.value(KEY_GMCP_BROADCAST_INTERVAL, 2500).toInt());
}
void Configuration::AdventurePanelSettings::read(const QSettings &conf)
{
m_displayXPStatus = conf.value(KEY_DISPLAY_XP_STATUS, true).toBool();
}
void Configuration::IntegratedMudClientSettings::read(const QSettings &conf)
{
font = conf.value(KEY_FONT, "").toString();
backgroundColor = conf.value(KEY_BACKGROUND_COLOR, QColor(Qt::black).name()).toString();
foregroundColor = conf.value(KEY_FOREGROUND_COLOR, QColor(Qt::lightGray).name()).toString();
columns = conf.value(KEY_COLUMNS, 80).toInt();
rows = conf.value(KEY_ROWS, 24).toInt();
linesOfScrollback = conf.value(KEY_LINES_OF_SCROLLBACK, 10000).toInt();
linesOfInputHistory = conf.value(KEY_LINES_OF_INPUT_HISTORY, 100).toInt();
tabCompletionDictionarySize = conf.value(KEY_TAB_COMPLETION_DICTIONARY_SIZE, 100).toInt();
clearInputOnEnter = conf.value(KEY_CLEAR_INPUT_ON_ENTER, false).toBool();
autoResizeTerminal = conf.value(KEY_AUTO_RESIZE_TERMINAL, true).toBool();
linesOfPeekPreview = conf.value(KEY_LINES_OF_PEEK_PREVIEW, 7).toInt();
}
void Configuration::RoomPanelSettings::read(const QSettings &conf)
{
geometry = conf.value(KEY_WINDOW_GEOMETRY).toByteArray();
}
void Configuration::InfomarksDialog::read(const QSettings &conf)
{
geometry = conf.value(KEY_WINDOW_GEOMETRY).toByteArray();
}
void Configuration::RoomEditDialog::read(const QSettings &conf)
{
geometry = conf.value(KEY_WINDOW_GEOMETRY).toByteArray();
}
void Configuration::FindRoomsDialog::read(const QSettings &conf)
{
geometry = conf.value(KEY_WINDOW_GEOMETRY).toByteArray();
}
void Configuration::GeneralSettings::write(QSettings &conf) const
{
conf.setValue(KEY_RUN_FIRST_TIME, false);
conf.setValue(KEY_WINDOW_GEOMETRY, windowGeometry);
conf.setValue(KEY_WINDOW_STATE, windowState);
conf.setValue(KEY_ALWAYS_ON_TOP, alwaysOnTop);
conf.setValue(KEY_SHOW_STATUS_BAR, showStatusBar);
conf.setValue(KEY_SHOW_SCROLL_BARS, showScrollBars);
conf.setValue(KEY_SHOW_MENU_BAR, showMenuBar);
conf.setValue(KEY_MAP_MODE, static_cast<uint32_t>(mapMode));
conf.setValue(KEY_CHECK_FOR_UPDATE, checkForUpdate);
conf.setValue(KEY_CHARACTER_ENCODING, static_cast<uint32_t>(characterEncoding));
}
void Configuration::ConnectionSettings::write(QSettings &conf) const
{
conf.setValue(KEY_SERVER_NAME, remoteServerName);
conf.setValue(KEY_MUME_REMOTE_PORT, static_cast<int>(remotePort));
conf.setValue(KEY_PROXY_LOCAL_PORT, static_cast<int>(localPort));
conf.setValue(KEY_TLS_ENCRYPTION, tlsEncryption);
conf.setValue(KEY_PROXY_CONNECTION_STATUS, proxyConnectionStatus);
conf.setValue(KEY_PROXY_LISTENS_ON_ANY_INTERFACE, proxyListensOnAnyInterface);
}
NODISCARD static auto getQColorName(const XNamedColor &color)
{
return color.getColor().getQColor().name();
}
void Configuration::CanvasSettings::write(QSettings &conf) const
{
conf.setValue(KEY_RESOURCES_DIRECTORY, resourcesDirectory);
conf.setValue(KEY_TEXTURE_SET, textureSetToInt(textureSet));
conf.setValue(KEY_ENABLE_SEASONAL_TEXTURES, enableSeasonalTextures);
conf.setValue(KEY_SHOW_MISSING_MAP_ID, showMissingMapId.get());
conf.setValue(KEY_SHOW_UNSAVED_CHANGES, showUnsavedChanges.get());
conf.setValue(KEY_DRAW_NOT_MAPPED_EXITS, showUnmappedExits.get());
conf.setValue(KEY_DRAW_UPPER_LAYERS_TEXTURED, drawUpperLayersTextured);
conf.setValue(KEY_DRAW_DOOR_NAMES, drawDoorNames);
conf.setValue(KEY_LAYER_TRANSPARENCY, layerTransparency);
conf.setValue(KEY_BACKGROUND_COLOR, getQColorName(backgroundColor));
conf.setValue(KEY_ROOM_DARK_COLOR, getQColorName(roomDarkColor));
conf.setValue(KEY_ROOM_DARK_LIT_COLOR, getQColorName(roomDarkLitColor));
conf.setValue(KEY_CONNECTION_NORMAL_COLOR, getQColorName(connectionNormalColor));
conf.setValue(KEY_NUMBER_OF_ANTI_ALIASING_SAMPLES, antialiasingSamples);
conf.setValue(KEY_USE_TRILINEAR_FILTERING, trilinearFiltering);
conf.setValue(KEY_3D_CANVAS, advanced.use3D.get());
conf.setValue(KEY_3D_AUTO_TILT, advanced.autoTilt.get());
conf.setValue(KEY_3D_PERFSTATS, advanced.printPerfStats.get());
conf.setValue(KEY_3D_FOV, advanced.fov.get());
conf.setValue(KEY_3D_VERTICAL_ANGLE, advanced.verticalAngle.get());
conf.setValue(KEY_3D_HORIZONTAL_ANGLE, advanced.horizontalAngle.get());
conf.setValue(KEY_3D_LAYER_HEIGHT, advanced.layerHeight.get());
// Save background image settings
conf.setValue(KEY_BACKGROUND_IMAGE_ENABLED, advanced.useBackgroundImage);
conf.setValue(KEY_BACKGROUND_IMAGE_PATH, advanced.backgroundImagePath);
conf.setValue(KEY_BACKGROUND_IMAGE_FIT_MODE, advanced.backgroundFitMode);
conf.setValue(KEY_BACKGROUND_IMAGE_OPACITY, advanced.backgroundOpacity);
conf.setValue(KEY_BACKGROUND_IMAGE_FOCUSED_SCALE, advanced.backgroundFocusedScale);
conf.setValue(KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_X, advanced.backgroundFocusedOffsetX);
conf.setValue(KEY_BACKGROUND_IMAGE_FOCUSED_OFFSET_Y, advanced.backgroundFocusedOffsetY);
// Save visible markers settings
conf.setValue(KEY_VISIBLE_MARKER_GENERIC, visibilityFilter.generic.get());
conf.setValue(KEY_VISIBLE_MARKER_HERB, visibilityFilter.herb.get());
conf.setValue(KEY_VISIBLE_MARKER_RIVER, visibilityFilter.river.get());
conf.setValue(KEY_VISIBLE_MARKER_PLACE, visibilityFilter.place.get());
conf.setValue(KEY_VISIBLE_MARKER_MOB, visibilityFilter.mob.get());
conf.setValue(KEY_VISIBLE_MARKER_COMMENT, visibilityFilter.comment.get());
conf.setValue(KEY_VISIBLE_MARKER_ROAD, visibilityFilter.road.get());
conf.setValue(KEY_VISIBLE_MARKER_OBJECT, visibilityFilter.object.get());
conf.setValue(KEY_VISIBLE_MARKER_ACTION, visibilityFilter.action.get());
conf.setValue(KEY_VISIBLE_MARKER_LOCALITY, visibilityFilter.locality.get());
conf.setValue(KEY_VISIBLE_CONNECTIONS, visibilityFilter.connections.get());
}
void Configuration::Hotkeys::read(const QSettings &conf)
{
// File operations
fileOpen.set(conf.value(KEY_HOTKEY_FILE_OPEN, "Ctrl+O").toString());
fileSave.set(conf.value(KEY_HOTKEY_FILE_SAVE, "Ctrl+S").toString());
fileReload.set(conf.value(KEY_HOTKEY_FILE_RELOAD, "Ctrl+R").toString());
fileQuit.set(conf.value(KEY_HOTKEY_FILE_QUIT, "Ctrl+Q").toString());
// Edit operations
editUndo.set(conf.value(KEY_HOTKEY_EDIT_UNDO, "Ctrl+Z").toString());
editRedo.set(conf.value(KEY_HOTKEY_EDIT_REDO, "Ctrl+Y").toString());
editPreferences.set(conf.value(KEY_HOTKEY_EDIT_PREFERENCES, "Ctrl+P").toString());
editPreferencesAlt.set(conf.value(KEY_HOTKEY_EDIT_PREFERENCES_ALT, "Esc").toString());
editFindRooms.set(conf.value(KEY_HOTKEY_EDIT_FIND_ROOMS, "Ctrl+F").toString());
editRoom.set(conf.value(KEY_HOTKEY_EDIT_ROOM, "Ctrl+E").toString());
// View operations
viewZoomIn.set(conf.value(KEY_HOTKEY_VIEW_ZOOM_IN, "").toString());
viewZoomOut.set(conf.value(KEY_HOTKEY_VIEW_ZOOM_OUT, "").toString());
viewZoomReset.set(conf.value(KEY_HOTKEY_VIEW_ZOOM_RESET, "Ctrl+0").toString());
viewLayerUp.set(conf.value(KEY_HOTKEY_VIEW_LAYER_UP, "").toString());
viewLayerDown.set(conf.value(KEY_HOTKEY_VIEW_LAYER_DOWN, "").toString());
viewLayerReset.set(conf.value(KEY_HOTKEY_VIEW_LAYER_RESET, "").toString());
// View toggles
viewRadialTransparency.set(conf.value(KEY_HOTKEY_VIEW_RADIAL_TRANSPARENCY, "").toString());
viewStatusBar.set(conf.value(KEY_HOTKEY_VIEW_STATUS_BAR, "").toString());
viewScrollBars.set(conf.value(KEY_HOTKEY_VIEW_SCROLL_BARS, "").toString());
viewMenuBar.set(conf.value(KEY_HOTKEY_VIEW_MENU_BAR, "").toString());
viewAlwaysOnTop.set(conf.value(KEY_HOTKEY_VIEW_ALWAYS_ON_TOP, "").toString());
// Side panels
panelLog.set(conf.value(KEY_HOTKEY_PANEL_LOG, "Ctrl+L").toString());
panelClient.set(conf.value(KEY_HOTKEY_PANEL_CLIENT, "").toString());
panelGroup.set(conf.value(KEY_HOTKEY_PANEL_GROUP, "").toString());
panelRoom.set(conf.value(KEY_HOTKEY_PANEL_ROOM, "").toString());
panelAdventure.set(conf.value(KEY_HOTKEY_PANEL_ADVENTURE, "").toString());
panelComms.set(conf.value(KEY_HOTKEY_PANEL_COMMS, "").toString());
panelDescription.set(conf.value(KEY_HOTKEY_PANEL_DESCRIPTION, "").toString());
// Mouse modes
modeMoveMap.set(conf.value(KEY_HOTKEY_MODE_MOVE_MAP, "").toString());
modeRaypick.set(conf.value(KEY_HOTKEY_MODE_RAYPICK, "").toString());
modeSelectRooms.set(conf.value(KEY_HOTKEY_MODE_SELECT_ROOMS, "").toString());
modeSelectMarkers.set(conf.value(KEY_HOTKEY_MODE_SELECT_MARKERS, "").toString());
modeSelectConnection.set(conf.value(KEY_HOTKEY_MODE_SELECT_CONNECTION, "").toString());
modeCreateMarker.set(conf.value(KEY_HOTKEY_MODE_CREATE_MARKER, "").toString());
modeCreateRoom.set(conf.value(KEY_HOTKEY_MODE_CREATE_ROOM, "").toString());
modeCreateConnection.set(conf.value(KEY_HOTKEY_MODE_CREATE_CONNECTION, "").toString());
modeCreateOnewayConnection.set(
conf.value(KEY_HOTKEY_MODE_CREATE_ONEWAY_CONNECTION, "").toString());
// Room operations
roomCreate.set(conf.value(KEY_HOTKEY_ROOM_CREATE, "").toString());
roomMoveUp.set(conf.value(KEY_HOTKEY_ROOM_MOVE_UP, "").toString());
roomMoveDown.set(conf.value(KEY_HOTKEY_ROOM_MOVE_DOWN, "").toString());