2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Redesign languages box with a search filter.

This commit is contained in:
John Preston
2018-10-30 15:23:54 +04:00
parent 162da089ec
commit 6d65cf2382
10 changed files with 852 additions and 136 deletions

View File

@@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "mainwindow.h"
#include "lang/lang_keys.h"
#include "lang/lang_cloud_manager.h"
#include "media/media_audio.h"
#include "mtproto/dc_options.h"
#include "messenger.h"
@@ -599,6 +600,7 @@ enum {
dbiAnimationsDisabled = 0x57,
dbiScalePercent = 0x58,
dbiPlaybackSpeed = 0x59,
dbiLanguagesKey = 0x5a,
dbiEncryptedWithSalt = 333,
dbiEncrypted = 444,
@@ -664,6 +666,7 @@ FileKey _exportSettingsKey = 0;
FileKey _savedPeersKey = 0;
FileKey _langPackKey = 0;
FileKey _languagesKey = 0;
bool _mapChanged = false;
int32 _oldMapVersion = 0, _oldSettingsVersion = 0;
@@ -1354,6 +1357,14 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
_langPackKey = langPackKey;
} break;
case dbiLanguagesKey: {
quint64 languagesKey = 0;
stream >> languagesKey;
if (!_checkStreamStatus(stream)) return false;
_languagesKey = languagesKey;
} break;
case dbiTryIPv6: {
qint32 v;
stream >> v;
@@ -2629,6 +2640,9 @@ void writeSettings() {
if (_langPackKey) {
data.stream << quint32(dbiLangPackKey) << quint64(_langPackKey);
}
if (_languagesKey) {
data.stream << quint32(dbiLanguagesKey) << quint64(_languagesKey);
}
auto position = cWindowPos();
data.stream << quint32(dbiWindowPosition) << qint32(position.x) << qint32(position.y) << qint32(position.w) << qint32(position.h);
@@ -4117,6 +4131,74 @@ void writeLangPack() {
file.writeEncrypted(data, SettingsKey);
}
void pushRecentLanguage(const Lang::Language &language) {
if (language.id.startsWith('#')) {
return;
}
auto list = readRecentLanguages();
list.erase(
ranges::remove_if(
list,
[&](const Lang::Language &v) { return (v.id == language.id); }),
list.end());
list.insert(list.begin(), language);
auto size = sizeof(qint32);
for (const auto &language : list) {
size += Serialize::stringSize(language.id)
+ Serialize::stringSize(language.pluralId)
+ Serialize::stringSize(language.baseId)
+ Serialize::stringSize(language.name)
+ Serialize::stringSize(language.nativeName);
}
if (!_languagesKey) {
_languagesKey = genKey(FileOption::Safe);
writeSettings();
}
EncryptedDescriptor data(size);
data.stream << qint32(list.size());
for (const auto &language : list) {
data.stream
<< language.id
<< language.pluralId
<< language.baseId
<< language.name
<< language.nativeName;
}
FileWriteDescriptor file(_languagesKey, FileOption::Safe);
file.writeEncrypted(data, SettingsKey);
}
QVector<Lang::Language> readRecentLanguages() {
FileReadDescriptor languages;
if (!_languagesKey || !readEncryptedFile(languages, _languagesKey, FileOption::Safe, SettingsKey)) {
return {};
}
qint32 count = 0;
languages.stream >> count;
if (count <= 0) {
return {};
}
auto result = QVector<Lang::Language>();
result.reserve(count);
for (auto i = 0; i != count; ++i) {
auto language = Lang::Language();
languages.stream
>> language.id
>> language.pluralId
>> language.baseId
>> language.name
>> language.nativeName;
result.push_back(language);
}
if (languages.stream.status() != QDataStream::Ok) {
return {};
}
return result;
}
bool copyThemeColorsToPalette(const QString &path) {
auto &themeKey = Window::Theme::IsNightMode()
? _themeKeyNight