-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Expand file tree
/
Copy pathcore_settings.cpp
More file actions
1867 lines (1739 loc) · 56.9 KB
/
Copy pathcore_settings.cpp
File metadata and controls
1867 lines (1739 loc) · 56.9 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
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/core_settings.h"
#include "base/platform/base_platform_info.h"
#include "calls/group/calls_group_common.h"
#include "history/view/history_view_quick_action.h"
#include "lang/lang_keys.h"
#include "platform/platform_notifications_manager.h"
#include "spellcheck/spellcheck_types.h"
#include "storage/serialize_common.h"
#include "ui/gl/gl_detection.h"
#include "ui/widgets/fields/input_field.h"
#include "webrtc/webrtc_create_adm.h"
#include "webrtc/webrtc_device_common.h"
#include "window/section_widget.h"
namespace Core {
namespace {
constexpr auto kInitialVideoQuality = 480; // Start with SD.
constexpr auto kMinIvZoom = 25;
constexpr auto kMaxIvZoom = 400;
[[nodiscard]] int DefaultIvZoom() {
const auto exact = cScale() * 100 / cScreenScale();
const auto snap10 = ((exact + 5) / 10) * 10;
const auto snap25 = ((exact + 12) / 25) * 25;
return (std::abs(exact - snap25) <= std::abs(exact - snap10))
? snap25
: snap10;
}
[[nodiscard]] int ResolveIvZoom(int value) {
return std::clamp(
(value > 0) ? value : DefaultIvZoom(),
kMinIvZoom,
kMaxIvZoom);
}
[[nodiscard]] WindowPosition Deserialize(const QByteArray &data) {
QDataStream stream(data);
stream.setVersion(QDataStream::Qt_5_1);
auto result = WindowPosition();
stream
>> result.x
>> result.y
>> result.w
>> result.h
>> result.moncrc
>> result.maximized
>> result.scale;
return result;
}
void LogPosition(const WindowPosition &position, const QString &name) {
DEBUG_LOG(("%1 Pos: Writing to storage %2, %3, %4, %5"
" (scale %6%, maximized %7)")
.arg(name)
.arg(position.x)
.arg(position.y)
.arg(position.w)
.arg(position.h)
.arg(position.scale)
.arg(position.maximized));
}
[[nodiscard]] QByteArray Serialize(const WindowPosition &position) {
auto result = QByteArray();
const auto size = 7 * sizeof(qint32);
result.reserve(size);
{
QDataStream stream(&result, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_5_1);
stream
<< qint32(position.x)
<< qint32(position.y)
<< qint32(position.w)
<< qint32(position.h)
<< qint32(position.moncrc)
<< qint32(position.maximized)
<< qint32(position.scale);
}
return result;
}
[[nodiscard]] QString Serialize(RecentEmojiDocument document) {
return u"%1-%2"_q.arg(document.id).arg(document.test ? 1 : 0);
}
[[nodiscard]] std::optional<RecentEmojiDocument> ParseRecentEmojiDocument(
const QString &serialized) {
const auto parts = QStringView(serialized).split('-');
if (parts.size() != 2 || parts[1].size() != 1) {
return {};
}
const auto id = parts[0].toULongLong();
const auto test = parts[1][0];
if (!id || (test != '0' && test != '1')) {
return {};
}
return RecentEmojiDocument{ id, (test == '1') };
}
[[nodiscard]] quint32 SerializeVideoQuality(Media::VideoQuality quality) {
static_assert(sizeof(Media::VideoQuality) == sizeof(uint32));
auto result = uint32();
const auto data = static_cast<const void*>(&quality);
memcpy(&result, data, sizeof(quality));
return result;
}
[[nodiscard]] Media::VideoQuality DeserializeVideoQuality(quint32 value) {
auto result = Media::VideoQuality();
const auto data = static_cast<void*>(&result);
memcpy(data, &value, sizeof(result));
return (result.height <= 4320) ? result : Media::VideoQuality();
}
} // namespace
[[nodiscard]] WindowPosition AdjustToScale(
WindowPosition position,
const QString &name) {
DEBUG_LOG(("%1 Pos: Initializing first %2, %3, %4, %5 "
"(scale %6%, maximized %7)")
.arg(name)
.arg(position.x)
.arg(position.y)
.arg(position.w)
.arg(position.h)
.arg(position.scale)
.arg(position.maximized));
if (!position.scale) {
return position;
}
const auto scaleFactor = cScale() / float64(position.scale);
if (scaleFactor != 1.) {
// Change scale while keeping the position center in place.
position.x += position.w / 2;
position.y += position.h / 2;
position.w *= scaleFactor;
position.h *= scaleFactor;
position.x -= position.w / 2;
position.y -= position.h / 2;
}
return position;
}
Settings::Settings()
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
, _floatPlayerColumn(Window::Column::Second)
, _floatPlayerCorner(RectPart::TopRight)
, _dialogsWithChatWidthRatio(DefaultDialogsWidthRatio())
, _dialogsNoChatWidthRatio(DefaultDialogsWidthRatio())
, _videoQuality({ .height = kInitialVideoQuality }) {
}
Settings::~Settings() = default;
QByteArray Settings::serialize() const {
const auto themesAccentColors = _themesAccentColors.serialize();
const auto windowPosition = Serialize(_windowPosition);
LogPosition(_windowPosition, u"Window"_q);
const auto mediaViewPosition = Serialize(_mediaViewPosition);
LogPosition(_mediaViewPosition, u"Viewer"_q);
const auto ivPosition = Serialize(_ivPosition);
LogPosition(_ivPosition, u"IV"_q);
const auto callPanelPosition = Serialize(_callPanelPosition);
LogPosition(_callPanelPosition, u"CallPanel"_q);
const auto proxy = _proxy.serialize();
const auto skipLanguages = _skipTranslationLanguages.current();
auto recentEmojiPreloadGenerated = std::vector<RecentEmojiPreload>();
if (_recentEmojiPreload.empty()) {
recentEmojiPreloadGenerated.reserve(_recentEmoji.size());
for (const auto &[id, rating] : _recentEmoji) {
auto string = QString();
if (const auto document = std::get_if<RecentEmojiDocument>(
&id.data)) {
string = Serialize(*document);
} else if (const auto emoji = std::get_if<EmojiPtr>(&id.data)) {
string = (*emoji)->id();
}
recentEmojiPreloadGenerated.push_back({ string, rating });
}
}
const auto &recentEmojiPreloadData = _recentEmojiPreload.empty()
? recentEmojiPreloadGenerated
: _recentEmojiPreload;
const auto noWarningExtensions = QStringList(
begin(_noWarningExtensions),
end(_noWarningExtensions)
).join(' ');
auto size = Serialize::bytearraySize(themesAccentColors)
+ sizeof(qint32) * 5
+ Serialize::stringSize(_downloadPath.current())
+ Serialize::bytearraySize(_downloadPathBookmark)
+ sizeof(qint32) * 9
+ Serialize::stringSize(QString()) // legacy call output device id
+ Serialize::stringSize(QString()) // legacy call input device id
+ sizeof(qint32) * 5;
for (const auto &[key, value] : _soundOverrides) {
size += Serialize::stringSize(key) + Serialize::stringSize(value);
}
size += sizeof(qint32) * 13
+ Serialize::bytearraySize(_videoPipGeometry)
+ sizeof(qint32)
+ (_dictionariesEnabled.current().size() * sizeof(quint64))
+ sizeof(qint32) * 12
+ Serialize::stringSize(_cameraDeviceId.current())
+ sizeof(qint32) * 2
+ Serialize::bytearraySize(_groupCallPushToTalkShortcut)
+ sizeof(qint64)
+ sizeof(qint32) * 2
+ Serialize::bytearraySize(windowPosition)
+ sizeof(qint32);
for (const auto &[id, rating] : recentEmojiPreloadData) {
size += Serialize::stringSize(id) + sizeof(quint16);
}
size += sizeof(qint32);
for (const auto &[id, variant] : _emojiVariants) {
size += Serialize::stringSize(id) + sizeof(quint8);
}
size += sizeof(qint32) * 3
+ Serialize::bytearraySize(proxy)
+ sizeof(qint32) * 2
+ Serialize::bytearraySize(_photoEditorBrush)
+ sizeof(qint32) * 3
+ Serialize::stringSize(_customDeviceModel.current())
+ sizeof(qint32) * 4
+ (_accountsOrder.size() * sizeof(quint64))
+ sizeof(qint32) * 7
+ (skipLanguages.size() * sizeof(quint64))
+ sizeof(qint32) * 2
+ sizeof(quint64)
+ sizeof(qint32) * 3
+ Serialize::bytearraySize(mediaViewPosition)
+ sizeof(qint32)
+ sizeof(quint64)
+ sizeof(qint32) * 2;
for (const auto &id : _recentEmojiSkip) {
size += Serialize::stringSize(id);
}
size += sizeof(qint32) * 2
+ Serialize::stringSize(_playbackDeviceId.current())
+ Serialize::stringSize(_captureDeviceId.current())
+ Serialize::stringSize(_callPlaybackDeviceId.current())
+ Serialize::stringSize(_callCaptureDeviceId.current())
+ Serialize::bytearraySize(ivPosition)
+ Serialize::stringSize(noWarningExtensions)
+ Serialize::stringSize(_customFontFamily)
+ sizeof(qint32) * 3
+ Serialize::bytearraySize(_tonsiteStorageToken)
+ sizeof(qint32) * 8
+ sizeof(ushort)
+ sizeof(qint32) // _notificationsDisplayChecksum
+ Serialize::bytearraySize(callPanelPosition)
+ sizeof(qint32) * 4;
size += sizeof(quint32);
for (const auto &[key, value] : _prefs) {
size += Serialize::bytearraySize(key)
+ Serialize::bytearraySize(value);
}
size += sizeof(qint32); // _audioPlaybackSpeed
size += sizeof(qint32); // _defaultScheduleTime
auto result = QByteArray();
result.reserve(size);
{
QDataStream stream(&result, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_5_1);
stream
<< themesAccentColors
<< qint32(_adaptiveForWide.current() ? 1 : 0)
<< qint32(_moderateModeEnabled ? 1 : 0)
<< qint32(qRound(_songVolume.current() * 1e6))
<< qint32(qRound(_videoVolume.current() * 1e6))
<< qint32(_askDownloadPath ? 1 : 0)
<< _downloadPath.current()
<< _downloadPathBookmark
<< qint32(1)
<< qint32(_soundNotify ? 1 : 0)
<< qint32(_desktopNotify ? 1 : 0)
<< qint32(_flashBounceNotify ? 1 : 0)
<< static_cast<qint32>(_notifyView)
<< qint32(_nativeNotifications ? (*_nativeNotifications ? 1 : 2) : 0)
<< qint32(_notificationsCount)
<< static_cast<qint32>(_notificationsCorner)
<< qint32(_autoLock)
<< QString() // legacy call output device id
<< QString() // legacy call input device id
<< qint32(_callOutputVolume)
<< qint32(_callInputVolume)
<< qint32(_callAudioDuckingEnabled ? 1 : 0)
<< qint32(_lastSeenWarningSeen ? 1 : 0)
<< qint32(_soundOverrides.size());
for (const auto &[key, value] : _soundOverrides) {
stream << key << value;
}
stream
<< qint32(_sendFilesWay.serialize())
<< qint32(_sendSubmitWay.current())
<< qint32(_includeMutedCounter ? 1 : 0)
<< qint32(_countUnreadMessages ? 1 : 0)
<< qint32(1) // legacy exe launch warning
<< qint32(_notifyAboutPinned.current() ? 1 : 0)
<< qint32(_loopAnimatedStickers ? 1 : 0)
<< qint32(_largeEmoji.current() ? 1 : 0)
<< qint32(_replaceEmoji.current() ? 1 : 0)
<< qint32(_suggestEmoji ? 1 : 0)
<< qint32(_suggestStickersByEmoji ? 1 : 0)
<< qint32(_spellcheckerEnabled.current() ? 1 : 0)
<< qint32(SerializePlaybackSpeed(_videoPlaybackSpeed))
<< _videoPipGeometry
<< qint32(_dictionariesEnabled.current().size());
for (const auto i : _dictionariesEnabled.current()) {
stream << quint64(i);
}
stream
<< qint32(_autoDownloadDictionaries.current() ? 1 : 0)
<< qint32(_mainMenuAccountsShown.current() ? 1 : 0)
<< qint32(_tabbedSelectorSectionEnabled ? 1 : 0)
<< qint32(_floatPlayerColumn)
<< qint32(_floatPlayerCorner)
<< qint32(_thirdSectionInfoEnabled ? 1 : 0)
<< qint32(std::clamp(
qRound(_dialogsWithChatWidthRatio.current() * 1000000),
0,
1000000))
<< qint32(_thirdColumnWidth.current())
<< qint32(_thirdSectionExtendedBy)
<< qint32(_notifyFromAll ? 1 : 0)
<< qint32(_nativeWindowFrame.current() ? 1 : 0)
<< qint32(0) // Legacy system dark mode
<< _cameraDeviceId.current()
<< qint32(_ipRevealWarning ? 1 : 0)
<< qint32(_groupCallPushToTalk ? 1 : 0)
<< _groupCallPushToTalkShortcut
<< qint64(_groupCallPushToTalkDelay)
<< qint32(0) // Call audio backend
<< qint32(0) // Legacy disable calls, now in session settings
<< windowPosition
<< qint32(recentEmojiPreloadData.size());
for (const auto &[id, rating] : recentEmojiPreloadData) {
stream << id << quint16(rating);
}
stream
<< qint32(_emojiVariants.size());
for (const auto &[id, variant] : _emojiVariants) {
stream << id << quint8(variant);
}
stream
<< qint32(0) // Old Disable OpenGL
<< qint32(0) // Old Noise Suppression
<< qint32(_workMode.current())
<< proxy
<< qint32(_hiddenGroupCallTooltips.value())
<< qint32(_disableOpenGL ? 1 : 0)
<< _photoEditorBrush
<< qint32(_groupCallNoiseSuppression ? 1 : 0)
<< qint32(SerializePlaybackSpeed(_voicePlaybackSpeed.current()))
<< qint32(_closeBehavior)
<< _customDeviceModel.current()
<< qint32(_playerRepeatMode.current())
<< qint32(_playerOrderMode.current())
<< qint32(_macWarnBeforeQuit ? 1 : 0);
stream
<< qint32(_accountsOrder.size());
for (const auto &id : _accountsOrder) {
stream << quint64(id);
}
stream
<< qint32(0) // old hardwareAcceleratedVideo
<< qint32(_chatQuickAction)
<< qint32(_hardwareAcceleratedVideo ? 1 : 0)
<< qint32(_suggestAnimatedEmoji ? 1 : 0)
<< qint32(_cornerReaction.current() ? 1 : 0)
<< qint32(_translateButtonEnabled ? 1 : 0);
stream
<< qint32(skipLanguages.size());
for (const auto &id : skipLanguages) {
stream << quint64(id.value);
}
stream
<< qint32(_rememberedDeleteMessageOnlyForYou ? 1 : 0)
<< qint32(_translateChatEnabled.current() ? 1 : 0)
<< quint64(QLocale::Language(_translateToRaw.current()))
<< qint32(_windowTitleContent.current().hideChatName ? 1 : 0)
<< qint32(_windowTitleContent.current().hideAccountName ? 1 : 0)
<< qint32(_windowTitleContent.current().hideTotalUnread ? 1 : 0)
<< mediaViewPosition
<< qint32(_ignoreBatterySaving.current() ? 1 : 0)
<< quint64(_macRoundIconDigest.value_or(0))
<< qint32(_storiesClickTooltipHidden.current() ? 1 : 0)
<< qint32(_recentEmojiSkip.size());
for (const auto &id : _recentEmojiSkip) {
stream << id;
}
stream
<< qint32(_trayIconMonochrome.current() ? 1 : 0)
<< qint32(_ttlVoiceClickTooltipHidden.current() ? 1 : 0)
<< _playbackDeviceId.current()
<< _captureDeviceId.current()
<< _callPlaybackDeviceId.current()
<< _callCaptureDeviceId.current()
<< ivPosition
<< noWarningExtensions
<< _customFontFamily
<< qint32(std::clamp(
qRound(_dialogsNoChatWidthRatio.current() * 1000000),
0,
1000000))
<< qint32(_systemUnlockEnabled ? 1 : 0)
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2)
<< _tonsiteStorageToken
<< qint32(_includeMutedCounterFolders ? 1 : 0)
<< qint32(_chatFiltersHorizontal.current() ? 1 : 0)
<< qint32(_skipToastsInFocus ? 1 : 0)
<< qint32(_recordVideoMessages ? 1 : 0)
<< SerializeVideoQuality(_videoQuality)
<< qint32(_ivZoom.current())
<< qint32(_systemDarkModeEnabled.current() ? 1 : 0)
<< qint32(_quickDialogAction)
<< _notificationsVolume
<< _notificationsDisplayChecksum
<< callPanelPosition
<< qint32(_cornerReply.current() ? 1 : 0)
<< qint32(_systemAccentColorEnabled ? 1 : 0)
<< qint32(_usePlatformTranslation ? 1 : 0)
<< qint32(_systemTextReplace.current() ? 1 : 0);
stream << quint32(_prefs.size());
for (const auto &[key, value] : _prefs) {
stream << key << value;
}
stream << qint32(SerializePlaybackSpeed(_audioPlaybackSpeed.current()));
stream << qint32(_defaultScheduleTime);
}
Ensures(result.size() == size);
return result;
}
void Settings::addFromSerialized(const QByteArray &serialized) {
if (serialized.isEmpty()) {
return;
}
QDataStream stream(serialized);
stream.setVersion(QDataStream::Qt_5_1);
QByteArray themesAccentColors;
qint32 adaptiveForWide = _adaptiveForWide.current() ? 1 : 0;
qint32 moderateModeEnabled = _moderateModeEnabled ? 1 : 0;
qint32 songVolume = qint32(qRound(_songVolume.current() * 1e6));
qint32 videoVolume = qint32(qRound(_videoVolume.current() * 1e6));
qint32 askDownloadPath = _askDownloadPath ? 1 : 0;
QString downloadPath = _downloadPath.current();
QByteArray downloadPathBookmark = _downloadPathBookmark;
qint32 nonDefaultVoicePlaybackSpeed = 1;
qint32 soundNotify = _soundNotify ? 1 : 0;
qint32 desktopNotify = _desktopNotify ? 1 : 0;
qint32 flashBounceNotify = _flashBounceNotify ? 1 : 0;
qint32 notifyView = static_cast<qint32>(_notifyView);
qint32 nativeNotifications = _nativeNotifications ? (*_nativeNotifications ? 1 : 2) : 0;
qint32 notificationsCount = _notificationsCount;
qint32 notificationsCorner = static_cast<qint32>(_notificationsCorner);
qint32 notificationsDisplayChecksum = _notificationsDisplayChecksum;
qint32 autoLock = _autoLock;
QString playbackDeviceId = _playbackDeviceId.current();
QString captureDeviceId = _captureDeviceId.current();
QString cameraDeviceId = _cameraDeviceId.current();
QString legacyCallPlaybackDeviceId = _callPlaybackDeviceId.current();
QString legacyCallCaptureDeviceId = _callCaptureDeviceId.current();
QString callPlaybackDeviceId = _callPlaybackDeviceId.current();
QString callCaptureDeviceId = _callCaptureDeviceId.current();
qint32 callOutputVolume = _callOutputVolume;
qint32 callInputVolume = _callInputVolume;
qint32 callAudioDuckingEnabled = _callAudioDuckingEnabled ? 1 : 0;
qint32 lastSeenWarningSeen = _lastSeenWarningSeen ? 1 : 0;
qint32 soundOverridesCount = 0;
base::flat_map<QString, QString> soundOverrides;
qint32 sendFilesWay = _sendFilesWay.serialize();
qint32 sendSubmitWay = static_cast<qint32>(_sendSubmitWay.current());
qint32 includeMutedCounter = _includeMutedCounter ? 1 : 0;
qint32 includeMutedCounterFolders = _includeMutedCounterFolders ? 1 : 0;
qint32 countUnreadMessages = _countUnreadMessages ? 1 : 0;
std::optional<QString> noWarningExtensions;
qint32 legacyExeLaunchWarning = 1;
qint32 notifyAboutPinned = _notifyAboutPinned.current() ? 1 : 0;
qint32 loopAnimatedStickers = _loopAnimatedStickers ? 1 : 0;
qint32 largeEmoji = _largeEmoji.current() ? 1 : 0;
qint32 replaceEmoji = _replaceEmoji.current() ? 1 : 0;
qint32 suggestEmoji = _suggestEmoji ? 1 : 0;
qint32 suggestStickersByEmoji = _suggestStickersByEmoji ? 1 : 0;
qint32 spellcheckerEnabled = _spellcheckerEnabled.current() ? 1 : 0;
qint32 videoPlaybackSpeed = SerializePlaybackSpeed(_videoPlaybackSpeed);
qint32 voicePlaybackSpeed = SerializePlaybackSpeed(
_voicePlaybackSpeed.current());
auto audioPlaybackSpeed = std::optional<qint32>();
QByteArray videoPipGeometry = _videoPipGeometry;
qint32 dictionariesEnabledCount = 0;
std::vector<int> dictionariesEnabled;
qint32 autoDownloadDictionaries = _autoDownloadDictionaries.current() ? 1 : 0;
qint32 mainMenuAccountsShown = _mainMenuAccountsShown.current() ? 1 : 0;
qint32 tabbedSelectorSectionEnabled = 1;
qint32 floatPlayerColumn = static_cast<qint32>(Window::Column::Second);
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
qint32 thirdSectionInfoEnabled = 0;
float64 dialogsWithChatWidthRatio = _dialogsWithChatWidthRatio.current();
float64 dialogsNoChatWidthRatio = _dialogsNoChatWidthRatio.current();
qint32 thirdColumnWidth = _thirdColumnWidth.current();
qint32 thirdSectionExtendedBy = _thirdSectionExtendedBy;
qint32 notifyFromAll = _notifyFromAll ? 1 : 0;
qint32 nativeWindowFrame = _nativeWindowFrame.current() ? 1 : 0;
qint32 systemDarkModeEnabled = _systemDarkModeEnabled.current() ? 1 : 0;
qint32 ipRevealWarning = _ipRevealWarning ? 1 : 0;
qint32 groupCallPushToTalk = _groupCallPushToTalk ? 1 : 0;
QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut;
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
qint32 legacyCallAudioBackend = 0;
qint32 disableCallsLegacy = 0;
QByteArray windowPosition;
std::vector<RecentEmojiPreload> recentEmojiPreload;
base::flat_map<QString, uint8> emojiVariants;
qint32 disableOpenGL = _disableOpenGL ? 1 : 0;
qint32 groupCallNoiseSuppression = _groupCallNoiseSuppression ? 1 : 0;
qint32 workMode = static_cast<qint32>(_workMode.current());
QByteArray proxy;
qint32 hiddenGroupCallTooltips = qint32(_hiddenGroupCallTooltips.value());
QByteArray photoEditorBrush = _photoEditorBrush;
qint32 closeBehavior = qint32(_closeBehavior);
QString customDeviceModel = _customDeviceModel.current();
qint32 playerRepeatMode = static_cast<qint32>(_playerRepeatMode.current());
qint32 playerOrderMode = static_cast<qint32>(_playerOrderMode.current());
qint32 macWarnBeforeQuit = _macWarnBeforeQuit ? 1 : 0;
qint32 accountsOrderCount = 0;
std::vector<uint64> accountsOrder;
qint32 hardwareAcceleratedVideo = _hardwareAcceleratedVideo ? 1 : 0;
qint32 chatQuickAction = static_cast<qint32>(_chatQuickAction);
qint32 suggestAnimatedEmoji = _suggestAnimatedEmoji ? 1 : 0;
qint32 cornerReply = _cornerReply.current() ? 1 : 0;
qint32 cornerReaction = _cornerReaction.current() ? 1 : 0;
qint32 legacySkipTranslationForLanguage = _translateButtonEnabled ? 1 : 0;
qint32 skipTranslationLanguagesCount = 0;
std::vector<LanguageId> skipTranslationLanguages;
qint32 rememberedDeleteMessageOnlyForYou = _rememberedDeleteMessageOnlyForYou ? 1 : 0;
qint32 translateChatEnabled = _translateChatEnabled.current() ? 1 : 0;
quint64 translateToRaw = _translateToRaw.current();
qint32 hideChatName = _windowTitleContent.current().hideChatName ? 1 : 0;
qint32 hideAccountName = _windowTitleContent.current().hideAccountName ? 1 : 0;
qint32 hideTotalUnread = _windowTitleContent.current().hideTotalUnread ? 1 : 0;
QByteArray mediaViewPosition;
qint32 ignoreBatterySaving = _ignoreBatterySaving.current() ? 1 : 0;
quint64 macRoundIconDigest = _macRoundIconDigest.value_or(0);
qint32 storiesClickTooltipHidden = _storiesClickTooltipHidden.current() ? 1 : 0;
base::flat_set<QString> recentEmojiSkip;
qint32 trayIconMonochrome = (_trayIconMonochrome.current() ? 1 : 0);
qint32 ttlVoiceClickTooltipHidden = _ttlVoiceClickTooltipHidden.current() ? 1 : 0;
QByteArray ivPosition;
QByteArray callPanelPosition;
QString customFontFamily = _customFontFamily;
qint32 systemUnlockEnabled = _systemUnlockEnabled ? 1 : 0;
qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2;
QByteArray tonsiteStorageToken = _tonsiteStorageToken;
qint32 ivZoom = _ivZoom.current();
qint32 skipToastsInFocus = _skipToastsInFocus ? 1 : 0;
qint32 recordVideoMessages = _recordVideoMessages ? 1 : 0;
quint32 videoQuality = SerializeVideoQuality(_videoQuality);
quint32 chatFiltersHorizontal = _chatFiltersHorizontal.current() ? 1 : 0;
quint32 quickDialogAction = quint32(_quickDialogAction);
ushort notificationsVolume = _notificationsVolume;
qint32 systemAccentColorEnabled = _systemAccentColorEnabled
? 1
: 0;
qint32 usePlatformTranslation = _usePlatformTranslation ? 1 : 0;
qint32 systemTextReplace = _systemTextReplace.current() ? 1 : 0;
stream >> themesAccentColors;
if (!stream.atEnd()) {
stream
>> adaptiveForWide
>> moderateModeEnabled
>> songVolume
>> videoVolume
>> askDownloadPath
>> downloadPath
>> downloadPathBookmark
>> nonDefaultVoicePlaybackSpeed
>> soundNotify
>> desktopNotify
>> flashBounceNotify
>> notifyView
>> nativeNotifications
>> notificationsCount
>> notificationsCorner
>> autoLock
>> legacyCallPlaybackDeviceId
>> legacyCallCaptureDeviceId
>> callOutputVolume
>> callInputVolume
>> callAudioDuckingEnabled
>> lastSeenWarningSeen
>> soundOverridesCount;
if (stream.status() == QDataStream::Ok) {
for (auto i = 0; i != soundOverridesCount; ++i) {
QString key, value;
stream >> key >> value;
soundOverrides.emplace(key, value);
}
}
stream
>> sendFilesWay
>> sendSubmitWay
>> includeMutedCounter
>> countUnreadMessages
>> legacyExeLaunchWarning
>> notifyAboutPinned
>> loopAnimatedStickers
>> largeEmoji
>> replaceEmoji
>> suggestEmoji
>> suggestStickersByEmoji
>> spellcheckerEnabled
>> videoPlaybackSpeed
>> videoPipGeometry
>> dictionariesEnabledCount;
if (stream.status() == QDataStream::Ok) {
for (auto i = 0; i != dictionariesEnabledCount; ++i) {
qint64 langId;
stream >> langId;
dictionariesEnabled.emplace_back(langId);
}
}
stream
>> autoDownloadDictionaries
>> mainMenuAccountsShown;
}
if (!stream.atEnd()) {
auto dialogsWithChatWidthRatioInt = qint32();
stream
>> tabbedSelectorSectionEnabled
>> floatPlayerColumn
>> floatPlayerCorner
>> thirdSectionInfoEnabled
>> dialogsWithChatWidthRatioInt
>> thirdColumnWidth
>> thirdSectionExtendedBy
>> notifyFromAll;
dialogsWithChatWidthRatio = std::clamp(
dialogsWithChatWidthRatioInt / 1000000.,
0.,
1.);
}
if (!stream.atEnd()) {
stream >> nativeWindowFrame;
}
if (!stream.atEnd()) {
// Read over this one below, if was in the file.
stream >> systemDarkModeEnabled;
}
if (!stream.atEnd()) {
stream >> cameraDeviceId;
}
if (!stream.atEnd()) {
stream >> ipRevealWarning;
}
if (!stream.atEnd()) {
stream
>> groupCallPushToTalk
>> groupCallPushToTalkShortcut
>> groupCallPushToTalkDelay;
}
if (!stream.atEnd()) {
stream >> legacyCallAudioBackend;
}
if (!stream.atEnd()) {
stream >> disableCallsLegacy;
}
if (!stream.atEnd()) {
stream >> windowPosition;
}
if (!stream.atEnd()) {
auto recentCount = qint32(0);
stream >> recentCount;
if (recentCount > 0 && recentCount < 10000) {
recentEmojiPreload.reserve(recentCount);
for (auto i = 0; i != recentCount; ++i) {
auto id = QString();
auto rating = quint16();
stream >> id >> rating;
recentEmojiPreload.push_back({ id, rating });
}
}
auto variantsCount = qint32(0);
stream >> variantsCount;
if (variantsCount > 0 && variantsCount < 10000) {
emojiVariants.reserve(variantsCount);
for (auto i = 0; i != variantsCount; ++i) {
auto id = QString();
auto variant = quint8();
stream >> id >> variant;
emojiVariants.emplace(id, variant);
}
}
}
if (!stream.atEnd()) {
qint32 disableOpenGLOld;
stream >> disableOpenGLOld;
}
if (!stream.atEnd()) {
qint32 groupCallNoiseSuppressionOld;
stream >> groupCallNoiseSuppressionOld;
}
if (!stream.atEnd()) {
stream >> workMode;
}
if (!stream.atEnd()) {
stream >> proxy;
}
if (!stream.atEnd()) {
stream >> hiddenGroupCallTooltips;
}
if (!stream.atEnd()) {
stream >> disableOpenGL;
}
if (!stream.atEnd()) {
stream >> photoEditorBrush;
}
if (!stream.atEnd()) {
stream >> groupCallNoiseSuppression;
}
if (!stream.atEnd()) {
stream >> voicePlaybackSpeed;
}
if (!stream.atEnd()) {
stream >> closeBehavior;
}
if (!stream.atEnd()) {
stream >> customDeviceModel;
}
if (!stream.atEnd()) {
stream
>> playerRepeatMode
>> playerOrderMode;
}
if (!stream.atEnd()) {
stream >> macWarnBeforeQuit;
}
if (!stream.atEnd()) {
stream >> accountsOrderCount;
if (stream.status() == QDataStream::Ok) {
for (auto i = 0; i != accountsOrderCount; ++i) {
quint64 sessionUniqueId;
stream >> sessionUniqueId;
accountsOrder.emplace_back(sessionUniqueId);
}
}
}
if (!stream.atEnd()) {
qint32 legacyHardwareAcceleratedVideo = 0;
stream >> legacyHardwareAcceleratedVideo;
}
if (!stream.atEnd()) {
stream >> chatQuickAction;
}
if (!stream.atEnd()) {
stream >> hardwareAcceleratedVideo;
}
if (!stream.atEnd()) {
stream >> suggestAnimatedEmoji;
}
if (!stream.atEnd()) {
stream >> cornerReaction;
}
if (!stream.atEnd()) {
stream >> legacySkipTranslationForLanguage;
}
if (!stream.atEnd()) {
stream >> skipTranslationLanguagesCount;
if (stream.status() == QDataStream::Ok) {
for (auto i = 0; i != skipTranslationLanguagesCount; ++i) {
quint64 language;
stream >> language;
skipTranslationLanguages.push_back({
QLocale::Language(language)
});
}
}
}
if (!stream.atEnd()) {
stream >> rememberedDeleteMessageOnlyForYou;
}
if (!stream.atEnd()) {
stream
>> translateChatEnabled
>> translateToRaw;
}
if (!stream.atEnd()) {
stream
>> hideChatName
>> hideAccountName
>> hideTotalUnread;
}
if (!stream.atEnd()) {
stream >> mediaViewPosition;
}
if (!stream.atEnd()) {
stream >> ignoreBatterySaving;
}
if (!stream.atEnd()) {
stream >> macRoundIconDigest;
}
if (!stream.atEnd()) {
stream >> storiesClickTooltipHidden;
}
if (!stream.atEnd()) {
auto count = qint32();
stream >> count;
if (stream.status() == QDataStream::Ok) {
for (auto i = 0; i != count; ++i) {
auto id = QString();
stream >> id;
if (stream.status() == QDataStream::Ok) {
recentEmojiSkip.emplace(id);
}
}
}
}
if (!stream.atEnd()) {
stream >> trayIconMonochrome;
} else {
// Let existing clients use the old value.
trayIconMonochrome = 0;
}
if (!stream.atEnd()) {
stream >> ttlVoiceClickTooltipHidden;
}
if (!stream.atEnd()) {
stream
>> playbackDeviceId
>> captureDeviceId;
}
if (!stream.atEnd()) {
stream
>> callPlaybackDeviceId
>> callCaptureDeviceId;
} else {
const auto &defaultId = Webrtc::kDefaultDeviceId;
callPlaybackDeviceId = (legacyCallPlaybackDeviceId == defaultId)
? QString()
: legacyCallPlaybackDeviceId;
callCaptureDeviceId = (legacyCallCaptureDeviceId == defaultId)
? QString()
: legacyCallCaptureDeviceId;
}
if (!stream.atEnd()) {
stream >> ivPosition;
}
if (!stream.atEnd()) {
noWarningExtensions = QString();
stream >> *noWarningExtensions;
}
if (!stream.atEnd()) {
stream >> customFontFamily;
}
if (!stream.atEnd()) {
auto dialogsNoChatWidthRatioInt = qint32();
stream
>> dialogsNoChatWidthRatioInt;
dialogsNoChatWidthRatio = std::clamp(
dialogsNoChatWidthRatioInt / 1000000.,
0.,
1.);
}
if (!stream.atEnd()) {
stream >> systemUnlockEnabled;
}
if (!stream.atEnd()) {
stream >> weatherInCelsius;
}
if (!stream.atEnd()) {
stream >> tonsiteStorageToken;
}
if (!stream.atEnd()) {
stream >> includeMutedCounterFolders;
}
if (!stream.atEnd()) {
stream >> chatFiltersHorizontal;
}
if (!stream.atEnd()) {
stream >> skipToastsInFocus;
}
if (!stream.atEnd()) {
stream >> recordVideoMessages;
}
if (!stream.atEnd()) {
stream >> videoQuality;
}
if (!stream.atEnd()) {
stream >> ivZoom;
}
if (!stream.atEnd()) {
stream >> systemDarkModeEnabled;
}
if (!stream.atEnd()) {
stream >> quickDialogAction;
}
if (!stream.atEnd()) {
stream >> notificationsVolume;
}
if (!stream.atEnd()) {
stream >> notificationsDisplayChecksum;
}
if (!stream.atEnd()) {
stream >> callPanelPosition;
}
if (!stream.atEnd()) {
stream >> cornerReply;
}
if (!stream.atEnd()) {
stream >> systemAccentColorEnabled;
}
if (!stream.atEnd()) {
stream >> usePlatformTranslation;
}
if (!stream.atEnd()) {
stream >> systemTextReplace;
}
if (!stream.atEnd()) {
auto prefsCount = quint32();
stream >> prefsCount;
auto prefs = base::flat_map<QByteArray, QByteArray>();
prefs.reserve(prefsCount);
for (auto i = quint32(); i != prefsCount; ++i) {
auto key = QByteArray();
auto value = QByteArray();
stream >> key >> value;
prefs.emplace(std::move(key), std::move(value));
}
if (stream.status() == QDataStream::Ok) {
_prefs = std::move(prefs);
}
}
if (!stream.atEnd()) {
auto speed = qint32();
stream >> speed;
if (stream.status() == QDataStream::Ok) {
audioPlaybackSpeed = speed;
}
}
if (!stream.atEnd()) {
auto defaultScheduleTime = qint32();
stream >> defaultScheduleTime;
if (stream.status() == QDataStream::Ok) {
_defaultScheduleTime = defaultScheduleTime;
}
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()"));
return;
} else if (!_themesAccentColors.setFromSerialized(themesAccentColors)) {
return;
} else if (!_proxy.setFromSerialized(proxy)) {
return;
}
_adaptiveForWide = (adaptiveForWide == 1);
_moderateModeEnabled = (moderateModeEnabled == 1);
_songVolume = std::clamp(songVolume / 1e6, 0., 1.);
_videoVolume = std::clamp(videoVolume / 1e6, 0., 1.);
_askDownloadPath = (askDownloadPath == 1);
_downloadPath = downloadPath;
_downloadPathBookmark = downloadPathBookmark;
_soundNotify = (soundNotify == 1);
_desktopNotify = (desktopNotify == 1);
_flashBounceNotify = (flashBounceNotify == 1);
const auto uncheckedNotifyView = static_cast<NotifyView>(notifyView);
switch (uncheckedNotifyView) {
case NotifyView::ShowNothing:
case NotifyView::ShowName:
case NotifyView::ShowPreview: _notifyView = uncheckedNotifyView; break;
}
switch (nativeNotifications) {
case 0: _nativeNotifications = std::nullopt; break;
case 1: _nativeNotifications = true; break;
case 2: _nativeNotifications = false; break;
default: break;