mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Added new setting for automatic dictionaries download.
This commit is contained in:
parent
bb8aead078
commit
bc6e1e7a0d
@ -423,6 +423,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_settings_spellchecker" = "Spell checker";
|
||||
"lng_settings_system_spellchecker" = "Use system spell checker";
|
||||
"lng_settings_custom_spellchecker" = "Use spell checker";
|
||||
"lng_settings_auto_download_dictionaries" = "Automatic dictionaries download";
|
||||
"lng_settings_manage_dictionaries" = "Manage dictionaries";
|
||||
"lng_settings_manage_enabled_dictionary" = "Dictionary is enabled";
|
||||
"lng_settings_manage_remove_dictionary" = "Remove Dictionary";
|
||||
|
@ -343,37 +343,39 @@ void Start(not_null<Main::Session*> session) {
|
||||
{ &ph::lng_spellchecker_remove, tr::lng_spellchecker_remove() },
|
||||
{ &ph::lng_spellchecker_ignore, tr::lng_spellchecker_ignore() },
|
||||
} });
|
||||
const auto settings = &session->settings();
|
||||
|
||||
if (!Platform::Spellchecker::IsSystemSpellchecker()) {
|
||||
Spellchecker::SetWorkingDirPath(DictionariesPath());
|
||||
|
||||
session->settings().dictionariesEnabledChanges(
|
||||
settings->dictionariesEnabledChanges(
|
||||
) | rpl::start_with_next([](auto dictionaries) {
|
||||
Platform::Spellchecker::UpdateLanguages(dictionaries);
|
||||
}, session->lifetime());
|
||||
|
||||
session->settings().spellcheckerEnabledChanges(
|
||||
settings->spellcheckerEnabledChanges(
|
||||
) | rpl::start_with_next([=](auto enabled) {
|
||||
Platform::Spellchecker::UpdateLanguages(
|
||||
enabled
|
||||
? session->settings().dictionariesEnabled()
|
||||
? settings->dictionariesEnabled()
|
||||
: std::vector<int>());
|
||||
}, session->lifetime());
|
||||
|
||||
session->data().contactsLoaded().changes(
|
||||
) | rpl::start_with_next([=](bool loaded) {
|
||||
if (!loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
DownloadDictionaryInBackground(session, 0, DefaultLanguages());
|
||||
}, session->lifetime());
|
||||
if (settings->autoDownloadDictionaries()) {
|
||||
session->data().contactsLoaded().changes(
|
||||
) | rpl::start_with_next([=](bool loaded) {
|
||||
if (!loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
DownloadDictionaryInBackground(session, 0, DefaultLanguages());
|
||||
}, session->lifetime());
|
||||
}
|
||||
|
||||
}
|
||||
if (session->settings().spellcheckerEnabled()) {
|
||||
if (settings->spellcheckerEnabled()) {
|
||||
Platform::Spellchecker::UpdateLanguages(
|
||||
session->settings().dictionariesEnabled());
|
||||
settings->dictionariesEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ QByteArray Settings::serialize() const {
|
||||
for (const auto i : _variables.dictionariesEnabled.current()) {
|
||||
stream << quint64(i);
|
||||
}
|
||||
stream << qint32(_variables.autoDownloadDictionaries.current() ? 1 : 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -175,6 +176,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
|
||||
qint32 videoPlaybackSpeed = SerializePlaybackSpeed(_variables.videoPlaybackSpeed.current());
|
||||
QByteArray videoPipGeometry = _variables.videoPipGeometry;
|
||||
std::vector<int> dictionariesEnabled;
|
||||
qint32 autoDownloadDictionaries = _variables.autoDownloadDictionaries.current() ? 1 : 0;
|
||||
|
||||
stream >> versionTag;
|
||||
if (versionTag == kVersionTag) {
|
||||
@ -312,6 +314,9 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream >> autoDownloadDictionaries;
|
||||
}
|
||||
if (stream.status() != QDataStream::Ok) {
|
||||
LOG(("App Error: "
|
||||
"Bad data for Main::Settings::constructFromSerialized()"));
|
||||
@ -402,6 +407,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
|
||||
_variables.videoPlaybackSpeed = DeserializePlaybackSpeed(videoPlaybackSpeed);
|
||||
_variables.videoPipGeometry = videoPipGeometry;
|
||||
_variables.dictionariesEnabled = std::move(dictionariesEnabled);
|
||||
_variables.autoDownloadDictionaries = (autoDownloadDictionaries == 1);
|
||||
}
|
||||
|
||||
void Settings::setSupportChatsTimeSlice(int slice) {
|
||||
|
@ -253,6 +253,19 @@ public:
|
||||
return _variables.dictionariesEnabled.changes();
|
||||
}
|
||||
|
||||
void setAutoDownloadDictionaries(bool value) {
|
||||
_variables.autoDownloadDictionaries = value;
|
||||
}
|
||||
bool autoDownloadDictionaries() const {
|
||||
return _variables.autoDownloadDictionaries.current();
|
||||
}
|
||||
rpl::producer<bool> autoDownloadDictionariesValue() const {
|
||||
return _variables.autoDownloadDictionaries.value();
|
||||
}
|
||||
rpl::producer<bool> autoDownloadDictionariesChanges() const {
|
||||
return _variables.autoDownloadDictionaries.changes();
|
||||
}
|
||||
|
||||
[[nodiscard]] float64 videoPlaybackSpeed() const {
|
||||
return _variables.videoPlaybackSpeed.current();
|
||||
}
|
||||
@ -311,6 +324,7 @@ private:
|
||||
rpl::variable<float64> videoPlaybackSpeed = 1.;
|
||||
QByteArray videoPipGeometry;
|
||||
rpl::variable<std::vector<int>> dictionariesEnabled;
|
||||
rpl::variable<bool> autoDownloadDictionaries = true;
|
||||
|
||||
static constexpr auto kDefaultSupportChatsLimitSlice
|
||||
= 7 * 24 * 60 * 60;
|
||||
|
@ -261,6 +261,7 @@ void SetupSpellchecker(
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
||||
const auto session = &controller->session();
|
||||
const auto settings = &session->settings();
|
||||
const auto isSystem = Platform::Spellchecker::IsSystemSpellchecker();
|
||||
const auto button = AddButton(
|
||||
container,
|
||||
@ -269,14 +270,14 @@ void SetupSpellchecker(
|
||||
: tr::lng_settings_custom_spellchecker(),
|
||||
st::settingsButton
|
||||
)->toggleOn(
|
||||
rpl::single(session->settings().spellcheckerEnabled())
|
||||
rpl::single(settings->spellcheckerEnabled())
|
||||
);
|
||||
|
||||
button->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != session->settings().spellcheckerEnabled());
|
||||
return (enabled != settings->spellcheckerEnabled());
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
session->settings().setSpellcheckerEnabled(enabled);
|
||||
settings->setSpellcheckerEnabled(enabled);
|
||||
session->saveSettingsDelayed();
|
||||
}, container->lifetime());
|
||||
|
||||
@ -289,6 +290,20 @@ void SetupSpellchecker(
|
||||
container,
|
||||
object_ptr<Ui::VerticalLayout>(container)));
|
||||
|
||||
AddButton(
|
||||
sliding->entity(),
|
||||
tr::lng_settings_auto_download_dictionaries(),
|
||||
st::settingsButton
|
||||
)->toggleOn(
|
||||
rpl::single(settings->autoDownloadDictionaries())
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->autoDownloadDictionaries());
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->setAutoDownloadDictionaries(enabled);
|
||||
session->saveSettingsDelayed();
|
||||
}, sliding->entity()->lifetime());
|
||||
|
||||
AddButtonWithLabel(
|
||||
sliding->entity(),
|
||||
tr::lng_settings_manage_dictionaries(),
|
||||
|
Loading…
Reference in New Issue
Block a user