diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 23f33eced..cbd0ed302 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -668,10 +668,10 @@ PRIVATE lang/lang_values.h main/main_account.cpp main/main_account.h - main/main_accounts.cpp - main/main_accounts.h main/main_app_config.cpp main/main_app_config.h + main/main_domain.cpp + main/main_domain.h main/main_session.cpp main/main_session.h main/main_session_settings.cpp @@ -914,10 +914,10 @@ PRIVATE storage/serialize_peer.h storage/storage_account.cpp storage/storage_account.h - storage/storage_accounts.cpp - storage/storage_accounts.h storage/storage_cloud_blob.cpp storage/storage_cloud_blob.h + storage/storage_domain.cpp + storage/storage_domain.h storage/storage_facade.cpp storage/storage_facade.h # storage/storage_feed_messages.cpp diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index b58b2220f..d75e20d3a 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -470,9 +470,12 @@ void ApiWrap::importChatInvite(const QString &hash) { return PeerId(0); }); if (const auto peer = _session->data().peerLoaded(peerId)) { - App::wnd()->sessionController()->showPeerHistory( - peer, - Window::SectionShow::Way::Forward); + const auto &windows = _session->windows(); + if (!windows.empty()) { + windows.front()->showPeerHistory( + peer, + Window::SectionShow::Way::Forward); + } } }; result.match([&](const MTPDupdates &data) { @@ -2727,9 +2730,12 @@ void ApiWrap::requestAttachedStickerSets(not_null photo) { const auto setId = (setData->vid().v && setData->vaccess_hash().v) ? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) : MTP_inputStickerSetShortName(setData->vshort_name()); - Ui::show( - Box(App::wnd()->sessionController(), setId), - Ui::LayerOption::KeepOther); + const auto &windows = _session->windows(); + if (!windows.empty()) { + Ui::show( + Box(windows.front(), setId), + Ui::LayerOption::KeepOther); + } }).fail([=](const RPCError &error) { Ui::show(Box(tr::lng_stickers_not_found(tr::now))); }).send(); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index f83587791..94dc88f20 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -40,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "apiwrap.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "facades.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -482,7 +481,7 @@ void GroupInfoBox::prepare() { _title->setMaxLength(kMaxGroupChannelTitle); _title->setInstantReplaces(Ui::InstantReplaces::Default()); _title->setInstantReplacesEnabled( - _navigation->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), _title, @@ -498,8 +497,9 @@ void GroupInfoBox::prepare() { _description->setMaxLength(kMaxChannelDescription); _description->setInstantReplaces(Ui::InstantReplaces::Default()); _description->setInstantReplacesEnabled( - _navigation->session().settings().replaceEmojiValue()); - _description->setSubmitSettings(_navigation->session().settings().sendSubmitWay()); + Core::App().settings().replaceEmojiValue()); + _description->setSubmitSettings( + Core::App().settings().sendSubmitWay()); connect(_description, &Ui::InputField::resized, [=] { descriptionResized(); }); connect(_description, &Ui::InputField::submitted, [=] { submit(); }); diff --git a/Telegram/SourceFiles/boxes/auto_lock_box.cpp b/Telegram/SourceFiles/boxes/auto_lock_box.cpp index aa6ab468a..94cf9da88 100644 --- a/Telegram/SourceFiles/boxes/auto_lock_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_lock_box.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "core/application.h" #include "mainwindow.h" -#include "main/main_session.h" #include "ui/widgets/checkbox.h" #include "facades.h" #include "styles/style_layers.h" @@ -28,7 +27,8 @@ void AutoLockBox::prepare() { auto options = { 60, 300, 3600, 18000 }; - auto group = std::make_shared(Global::AutoLock()); + auto group = std::make_shared( + Core::App().settings().autoLock()); auto y = st::boxOptionListPadding.top() + st::autolockButton.margin.top(); auto count = int(options.size()); _options.reserve(count); @@ -43,8 +43,8 @@ void AutoLockBox::prepare() { } void AutoLockBox::durationChanged(int seconds) { - Global::SetAutoLock(seconds); - _session->saveSettingsDelayed(); + Core::App().settings().setAutoLock(seconds); + Core::App().saveSettingsDelayed(); Global::RefLocalPasscodeChanged().notify(); Core::App().checkAutoLock(); diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 0de763d7b..51446bb1c 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -770,9 +770,10 @@ void DeleteMessagesBox::deleteAndClear() { if (justClear) { peer->session().api().clearHistory(peer, revoke); } else { - const auto controller = App::wnd()->sessionController(); - if (controller->activeChatCurrent().peer() == peer) { - Ui::showChatsList(); + for (const auto controller : peer->session().windows()) { + if (controller->activeChatCurrent().peer() == peer) { + Ui::showChatsList(&peer->session()); + } } // Don't delete old history by default, // because Android app doesn't. diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 4ab656946..321b88153 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -20,7 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/checkbox.h" #include "ui/toast/toast.h" #include "main/main_session.h" -#include "main/main_session_settings.h" +#include "core/application.h" +#include "core/core_settings.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/message_field.h" #include "history/view/history_view_schedule_box.h" @@ -161,7 +162,7 @@ void InitField( not_null session) { field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( - session->settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); auto options = Ui::Emoji::SuggestionsController::Options(); options.suggestExactFirstWord = false; Ui::Emoji::SuggestionsController::Init( @@ -841,7 +842,7 @@ not_null CreatePollBox::setupSolution( solution->setMaxLength(kSolutionLimit + kErrorLimit); solution->setInstantReplaces(Ui::InstantReplaces::Default()); solution->setInstantReplacesEnabled( - session->settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); solution->setMarkdownReplacesEnabled(rpl::single(true)); solution->setEditLinkCallback( DefaultEditLinkCallback(_controller, solution)); diff --git a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp index 0a9e10640..f7776a0ad 100644 --- a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp +++ b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp @@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/spellchecker_common.h" #include "core/application.h" #include "main/main_account.h" -#include "main/main_session.h" -#include "main/main_session_settings.h" #include "mainwidget.h" #include "mtproto/dedicated_file_loader.h" #include "spellcheck/spellcheck_utils.h" @@ -405,7 +403,7 @@ void ManageDictionariesBox::prepare() { object_ptr( this, _controller, - session->settings().dictionariesEnabled()), + Core::App().settings().dictionariesEnabled()), st::boxScroll, multiSelect->height() ); @@ -423,9 +421,9 @@ void ManageDictionariesBox::prepare() { setTitle(tr::lng_settings_manage_dictionaries()); addButton(tr::lng_settings_save(), [=] { - session->settings().setDictionariesEnabled( + Core::App().settings().setDictionariesEnabled( FilterEnabledDict(inner->enabledRows())); - session->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); // Ignore boxClosing() when the Save button was pressed. lifetime().destroy(); closeBox(); @@ -433,9 +431,9 @@ void ManageDictionariesBox::prepare() { addButton(tr::lng_close(), [=] { closeBox(); }); boxClosing() | rpl::start_with_next([=] { - session->settings().setDictionariesEnabled( + Core::App().settings().setDictionariesEnabled( FilterEnabledDict(initialEnabledRows)); - session->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); }, lifetime()); setDimensionsToContent(st::boxWidth, inner); diff --git a/Telegram/SourceFiles/boxes/download_path_box.cpp b/Telegram/SourceFiles/boxes/download_path_box.cpp index 4ddae0f47..a484225e0 100644 --- a/Telegram/SourceFiles/boxes/download_path_box.cpp +++ b/Telegram/SourceFiles/boxes/download_path_box.cpp @@ -12,9 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "platform/platform_specific.h" -#include "facades.h" -#include "window/window_session_controller.h" -#include "main/main_session.h" +#include "core/application.h" +#include "core/core_settings.h" #include "storage/storage_account.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -23,8 +22,8 @@ DownloadPathBox::DownloadPathBox( QWidget *parent, not_null controller) : _controller(controller) -, _path(Global::DownloadPath()) -, _pathBookmark(Global::DownloadPathBookmark()) +, _path(Core::App().settings().downloadPath()) +, _pathBookmark(Core::App().settings().downloadPathBookmark()) , _group(std::make_shared>(typeFromPath(_path))) , _default(this, _group, Directory::Downloads, tr::lng_download_path_default_radio(tr::now), st::defaultBoxCheckbox) , _temp(this, _group, Directory::Temp, tr::lng_download_path_temp_radio(tr::now), st::defaultBoxCheckbox) @@ -91,8 +90,9 @@ void DownloadPathBox::radioChanged(Directory value) { void DownloadPathBox::editPath() { const auto initialPath = [] { - if (!Global::DownloadPath().isEmpty() && Global::DownloadPath() != qstr("tmp")) { - return Global::DownloadPath().left(Global::DownloadPath().size() - (Global::DownloadPath().endsWith('/') ? 1 : 0)); + const auto path = Core::App().settings().downloadPath(); + if (!path.isEmpty() && path != qstr("tmp")) { + return path.left(path.size() - (path.endsWith('/') ? 1 : 0)); } return QString(); }(); @@ -122,10 +122,10 @@ void DownloadPathBox::save() { } return QString(); }; - Global::SetDownloadPath(computePath()); - Global::SetDownloadPathBookmark((value == Directory::Custom) ? _pathBookmark : QByteArray()); - _controller->session().saveSettings(); - Global::RefDownloadPathChanged().notify(); + Core::App().settings().setDownloadPathBookmark( + (value == Directory::Custom) ? _pathBookmark : QByteArray()); + Core::App().settings().setDownloadPath(computePath()); + Core::App().saveSettings(); closeBox(); #endif // OS_WIN_STORE } diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 972df7d07..0c331acfa 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -10,12 +10,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "api/api_text_entities.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/message_field.h" #include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_selector.h" #include "base/event_filter.h" +#include "core/application.h" +#include "core/core_settings.h" #include "core/file_utilities.h" #include "core/mime_type.h" #include "data/data_document.h" @@ -309,10 +310,10 @@ EditCaptionBox::EditCaptionBox( _field->setMaxLength( _controller->session().serverConfig().captionLengthMax); _field->setSubmitSettings( - _controller->session().settings().sendSubmitWay()); + Core::App().settings().sendSubmitWay()); _field->setInstantReplaces(Ui::InstantReplaces::Default()); _field->setInstantReplacesEnabled( - _controller->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback( DefaultEditLinkCallback(_controller, _field)); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index a9d601823..081503c4f 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -19,12 +19,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat_filters.h" #include "data/data_peer.h" #include "data/data_session.h" +#include "core/application.h" +#include "core/core_settings.h" #include "settings/settings_common.h" #include "base/event_filter.h" #include "lang/lang_keys.h" #include "history/history.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "window/window_session_controller.h" #include "window/window_controller.h" #include "apiwrap.h" @@ -501,7 +502,7 @@ void EditFilterBox( name->setMaxLength(kMaxFilterTitleLength); name->setInstantReplaces(Ui::InstantReplaces::Default()); name->setInstantReplacesEnabled( - window->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( box->getDelegate()->outerContainer(), name, diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 166062615..624bd2c91 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -14,9 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "apiwrap.h" #include "main/main_session.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "core/application.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" @@ -452,7 +452,7 @@ void PasscodeBox::save(bool force) { return; } - if (Core::App().accounts().local().checkPasscode(old.toUtf8())) { + if (Core::App().domain().local().checkPasscode(old.toUtf8())) { cSetPasscodeBadTries(0); if (_turningOff) pwd = conf = QString(); } else { @@ -520,7 +520,7 @@ void PasscodeBox::save(bool force) { closeReplacedBy(); const auto weak = Ui::MakeWeak(this); cSetPasscodeBadTries(0); - Core::App().accounts().local().setPasscode(pwd.toUtf8()); + Core::App().domain().local().setPasscode(pwd.toUtf8()); Core::App().localPasscodeChanged(); if (weak) { closeBox(); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index c082c447f..67a19c655 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_cloud_password.h" #include "base/unixtime.h" #include "apiwrap.h" -#include "facades.h" #include "main/main_session.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 1b51a116e..2d107db94 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "boxes/add_contact_box.h" #include "boxes/confirm_box.h" #include "boxes/peer_list_controllers.h" @@ -20,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_linked_chat_box.h" #include "boxes/stickers_box.h" #include "chat_helpers/emoji_suggestions_widget.h" +#include "core/application.h" +#include "core/core_settings.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_peer.h" @@ -465,7 +466,7 @@ object_ptr Controller::createTitleEdit() { result->entity()->setMaxLength(kMaxGroupChannelTitle); result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplacesEnabled( - _peer->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( _wrap->window(), result->entity(), @@ -499,8 +500,8 @@ object_ptr Controller::createDescriptionEdit() { result->entity()->setMaxLength(kMaxChannelDescription); result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplacesEnabled( - _peer->session().settings().replaceEmojiValue()); - result->entity()->setSubmitSettings(_peer->session().settings().sendSubmitWay()); + Core::App().settings().replaceEmojiValue()); + result->entity()->setSubmitSettings(Core::App().settings().sendSubmitWay()); Ui::Emoji::SuggestionsController::Init( _wrap->window(), result->entity(), @@ -1443,7 +1444,7 @@ void Controller::deleteChannel() { const auto session = &_peer->session(); Ui::hideLayer(); - Ui::showChatsList(); + Ui::showChatsList(session); if (chat) { session->api().deleteConversation(chat, false); } diff --git a/Telegram/SourceFiles/boxes/rate_call_box.cpp b/Telegram/SourceFiles/boxes/rate_call_box.cpp index 265963de1..1e8914201 100644 --- a/Telegram/SourceFiles/boxes/rate_call_box.cpp +++ b/Telegram/SourceFiles/boxes/rate_call_box.cpp @@ -14,7 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/input_fields.h" #include "mainwindow.h" #include "main/main_session.h" -#include "main/main_session_settings.h" +#include "core/application.h" +#include "core/core_settings.h" #include "apiwrap.h" #include "styles/style_layers.h" #include "styles/style_calls.h" @@ -86,7 +87,7 @@ void RateCallBox::ratingChanged(int value) { Ui::InputField::Mode::MultiLine, tr::lng_call_rate_comment()); _comment->show(); - _comment->setSubmitSettings(_session->settings().sendSubmitWay()); + _comment->setSubmitSettings(Core::App().settings().sendSubmitWay()); _comment->setMaxLength(kRateCallCommentLengthMax); _comment->resize(width() - (st::callRatingPadding.left() + st::callRatingPadding.right()), _comment->height()); diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index 72e9e85b6..4d6cb79a1 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -10,13 +10,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "data/data_peer.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "boxes/confirm_box.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/toast/toast.h" #include "mainwindow.h" +#include "core/core_settings.h" +#include "core/application.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_profile.h" @@ -109,7 +110,7 @@ void ReportBox::reasonChanged(Reason reason) { Ui::InputField::Mode::MultiLine, tr::lng_report_reason_description()); _reasonOtherText->show(); - _reasonOtherText->setSubmitSettings(_peer->session().settings().sendSubmitWay()); + _reasonOtherText->setSubmitSettings(Core::App().settings().sendSubmitWay()); _reasonOtherText->setMaxLength(kReportReasonLengthMax); _reasonOtherText->resize(width() - (st::boxPadding.left() + st::boxOptionListPadding.left() + st::boxPadding.right()), _reasonOtherText->height()); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 0ea2a109e..2594bfd64 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "mainwidget.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "chat_helpers/message_field.h" #include "chat_helpers/emoji_suggestions_widget.h" @@ -38,6 +37,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/clip/media_clip_reader.h" #include "api/api_common.h" #include "window/window_session_controller.h" +#include "core/application.h" +#include "core/core_settings.h" #include "layout.h" #include "facades.h" // App::LambdaDelayed. #include "app.h" @@ -1913,7 +1914,7 @@ void SendFilesBox::initSendWay() { ? SendFilesWay::Album : SendFilesWay::Photos; } - const auto way = _controller->session().settings().sendFilesWay(); + const auto way = Core::App().settings().sendFilesWay(); if (way == SendFilesWay::Files) { return way; } else if (way == SendFilesWay::Album) { @@ -2047,7 +2048,7 @@ void SendFilesBox::setupCaption() { _caption->setMaxLength( _controller->session().serverConfig().captionLengthMax); _caption->setSubmitSettings( - _controller->session().settings().sendSubmitWay()); + Core::App().settings().sendSubmitWay()); connect(_caption, &Ui::InputField::resized, [=] { captionResized(); }); @@ -2071,7 +2072,7 @@ void SendFilesBox::setupCaption() { }); _caption->setInstantReplaces(Ui::InstantReplaces::Default()); _caption->setInstantReplacesEnabled( - _controller->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); _caption->setMarkdownReplacesEnabled(rpl::single(true)); _caption->setEditLinkCallback( DefaultEditLinkCallback(_controller, _caption)); @@ -2344,7 +2345,7 @@ void SendFilesBox::send( const auto way = _sendWay ? _sendWay->value() : Way::Files; if (_compressConfirm == CompressConfirm::Auto) { - const auto oldWay = _controller->session().settings().sendFilesWay(); + const auto oldWay = Core::App().settings().sendFilesWay(); if (way != oldWay) { // Check if the user _could_ use the old value, but didn't. if ((oldWay == Way::Album && _sendAlbum) @@ -2352,8 +2353,8 @@ void SendFilesBox::send( || (oldWay == Way::Files && _sendFiles) || (way == Way::Files && (_sendAlbum || _sendPhotos))) { // And in that case save it to settings. - _controller->session().settings().setSendFilesWay(way); - _controller->session().saveSettingsDelayed(); + Core::App().settings().setSendFilesWay(way); + Core::App().saveSettingsDelayed(); } } } diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 573c6efb1..11f1264a5 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -36,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_folder.h" #include "data/data_changes.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "core/application.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -200,11 +199,11 @@ void ShareBox::prepareCommentField() { field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( - _navigation->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback( DefaultEditLinkCallback(_navigation->parentController(), field)); - field->setSubmitSettings(_navigation->session().settings().sendSubmitWay()); + field->setSubmitSettings(Core::App().settings().sendSubmitWay()); InitSpellchecker(_navigation->parentController(), field); Ui::SendPendingMoveResizeEvents(_comment); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 3ebeb1053..d533c5aaf 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "window/window_session_controller.h" #include "main/main_session.h" -#include "facades.h" #include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index b3eb152be..e7ff96d7f 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_media_types.h" #include "data/data_user.h" -#include "facades.h" #include "app.h" namespace Calls { diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 565441bc6..e317b6a38 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_call.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "apiwrap.h" #include "lang/lang_keys.h" #include "boxes/confirm_box.h" @@ -17,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "mtproto/mtproto_dh_utils.h" #include "mtproto/mtproto_config.h" +#include "core/application.h" +#include "core/core_settings.h" #include "media/audio/media_audio_track.h" #include "base/platform/base_platform_info.h" #include "calls/calls_panel.h" @@ -308,7 +309,7 @@ QString Call::getDebugLog() const { void Call::startWaitingTrack() { _waitingTrack = Media::Audio::Current().createTrack(); - auto trackFileName = _user->session().settings().getSoundPath( + auto trackFileName = Core::App().settings().getSoundPath( (_type == Type::Outgoing) ? qsl("call_outgoing") : qsl("call_incoming")); @@ -610,13 +611,14 @@ void Call::createAndStartController(const MTPDphoneCall &call) { if (_mute) { raw->setMuteMicrophone(_mute); } + const auto &settings = Core::App().settings(); raw->setAudioOutputDevice( - Global::CallOutputDeviceID().toStdString()); + settings.callOutputDeviceID().toStdString()); raw->setAudioInputDevice( - Global::CallInputDeviceID().toStdString()); - raw->setOutputVolume(Global::CallOutputVolume() / 100.0f); - raw->setInputVolume(Global::CallInputVolume() / 100.0f); - raw->setAudioOutputDuckingEnabled(Global::CallAudioDuckingEnabled()); + settings.callInputDeviceID().toStdString()); + raw->setOutputVolume(settings.callOutputVolume() / 100.0f); + raw->setInputVolume(settings.callInputVolume() / 100.0f); + raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled()); } void Call::handleControllerStateChange( diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 3c590171b..ffd331214 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtproto_dh_utils.h" #include "core/application.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "apiwrap.h" #include "lang/lang_keys.h" #include "boxes/confirm_box.h" @@ -74,7 +73,7 @@ void Instance::playSound(Sound sound) { if (!_callBusyTrack) { _callBusyTrack = Media::Audio::Current().createTrack(); _callBusyTrack->fillFromFile( - _session->settings().getSoundPath(qsl("call_busy"))); + Core::App().settings().getSoundPath(qsl("call_busy"))); } _callBusyTrack->playOnce(); } break; @@ -83,7 +82,7 @@ void Instance::playSound(Sound sound) { if (!_callEndedTrack) { _callEndedTrack = Media::Audio::Current().createTrack(); _callEndedTrack->fillFromFile( - _session->settings().getSoundPath(qsl("call_end"))); + Core::App().settings().getSoundPath(qsl("call_end"))); } _callEndedTrack->playOnce(); } break; @@ -92,7 +91,7 @@ void Instance::playSound(Sound sound) { if (!_callConnectingTrack) { _callConnectingTrack = Media::Audio::Current().createTrack(); _callConnectingTrack->fillFromFile( - _session->settings().getSoundPath(qsl("call_connect"))); + Core::App().settings().getSoundPath(qsl("call_connect"))); } _callConnectingTrack->playOnce(); } break; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index dc93f4561..5897e014f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "base/platform/base_platform_info.h" #include "ui/emoji_config.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_session.h" #include "apiwrap.h" @@ -516,7 +516,7 @@ void EmojiKeywords::langPackRefreshed() { } void EmojiKeywords::handleSessionChanges() { - Core::App().accounts().activeSessionValue( // #TODO multi someSessionValue + Core::App().domain().activeSessionValue( // #TODO multi someSessionValue ) | rpl::map([](Main::Session *session) { return session ? &session->api() : nullptr; }) | rpl::start_with_next([=](ApiWrap *api) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 7b098d228..ec66b0cfc 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -16,7 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "emoji_suggestions_data.h" #include "emoji_suggestions_helper.h" #include "main/main_session.h" -#include "main/main_session_settings.h" +#include "core/core_settings.h" +#include "core/application.h" #include "window/window_session_controller.h" #include "facades.h" #include "app.h" @@ -837,8 +838,7 @@ void EmojiListWidget::setSelected(int newSelected) { _selected = newSelected; updateSelected(); - if (_selected >= 0 - && controller()->session().settings().suggestEmoji()) { + if (_selected >= 0 && Core::App().settings().suggestEmoji()) { Ui::Tooltip::Show(1000, this); } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp index f33bb7b6c..d5df3086d 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp @@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_keywords.h" +#include "core/core_settings.h" +#include "core/application.h" #include "emoji_suggestions_helper.h" #include "ui/effects/ripple_animation.h" #include "ui/widgets/shadow.h" @@ -19,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "base/event_filter.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "app.h" #include "styles/style_chat_helpers.h" @@ -608,7 +609,7 @@ void SuggestionsController::setReplaceCallback( } void SuggestionsController::handleTextChange() { - if (_session->settings().suggestEmoji() + if (Core::App().settings().suggestEmoji() && _field->textCursor().position() > 0) { Core::App().emojiKeywords().refresh(); } @@ -638,7 +639,7 @@ void SuggestionsController::showWithQuery(const QString &query) { } QString SuggestionsController::getEmojiQuery() { - if (!_session->settings().suggestEmoji()) { + if (!Core::App().settings().suggestEmoji()) { return QString(); } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index c1480a007..790adb725 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -21,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "main/main_session.h" #include "storage/storage_account.h" +#include "core/application.h" +#include "core/core_settings.h" #include "lottie/lottie_single_player.h" #include "ui/widgets/scroll_area.h" #include "ui/image/image.h" @@ -563,7 +565,7 @@ bool FieldAutocomplete::chooseSelected(ChooseMethod method) const { bool FieldAutocomplete::eventFilter(QObject *obj, QEvent *e) { auto hidden = isHidden(); - auto moderate = Global::ModerateModeEnabled(); + auto moderate = Core::App().settings().moderateModeEnabled(); if (hidden && !moderate) return QWidget::eventFilter(obj, e); if (e->type() == QEvent::KeyPress) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index cefddad5c..1418490ce 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "window/window_session_controller.h" #include "history/view/history_view_cursor_state.h" -#include "facades.h" #include "app.h" #include "styles/style_chat_helpers.h" diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 297601ad0..9c6db61ba 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/event_filter.h" #include "boxes/abstract_box.h" #include "core/shortcuts.h" +#include "core/application.h" +#include "core/core_settings.h" #include "ui/wrap/vertical_layout.h" #include "ui/widgets/popup_menu.h" #include "ui/ui_utility.h" @@ -25,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "mainwindow.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_history.h" @@ -142,7 +143,7 @@ void EditLinkBox::prepare() { st::markdownLinkFieldPadding); text->setInstantReplaces(Ui::InstantReplaces::Default()); text->setInstantReplacesEnabled( - session->settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), text, @@ -289,7 +290,7 @@ void InitMessageField( field->customTab(true); field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( - controller->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback(DefaultEditLinkCallback(controller, field)); } @@ -300,7 +301,7 @@ void InitSpellchecker( #ifndef TDESKTOP_DISABLE_SPELLCHECK const auto s = Ui::CreateChild( field.get(), - controller->session().settings().spellcheckerEnabledValue(), + Core::App().settings().spellcheckerEnabledValue(), Spellchecker::SpellingHighlighter::CustomContextMenuItem{ tr::lng_settings_manage_dictionaries(tr::now), [=] { Ui::show(Box(controller)); } diff --git a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp index bc1d18804..1b01ee48f 100644 --- a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp +++ b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp @@ -15,11 +15,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_instance.h" #include "lang/lang_keys.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mainwidget.h" #include "spellcheck/platform/platform_spellcheck.h" #include "spellcheck/spellcheck_utils.h" #include "spellcheck/spellcheck_value.h" +#include "core/application.h" +#include "core/core_settings.h" #include #include @@ -143,11 +144,11 @@ void DownloadDictionaryInBackground( BackgroundLoaderChanged.fire(0); if (DictionaryExists(id)) { - auto dicts = session->settings().dictionariesEnabled(); + auto dicts = Core::App().settings().dictionariesEnabled(); if (!ranges::contains(dicts, id)) { dicts.push_back(id); - session->settings().setDictionariesEnabled(std::move(dicts)); - session->saveSettingsDelayed(); + Core::App().settings().setDictionariesEnabled(std::move(dicts)); + Core::App().saveSettingsDelayed(); } } @@ -312,18 +313,18 @@ bool WriteDefaultDictionary() { } rpl::producer ButtonManageDictsState( - not_null session) { + not_null session) { if (Platform::Spellchecker::IsSystemSpellchecker()) { return rpl::single(QString()); } const auto computeString = [=] { - if (!session->settings().spellcheckerEnabled()) { + if (!Core::App().settings().spellcheckerEnabled()) { return QString(); } - if (!session->settings().dictionariesEnabled().size()) { + if (!Core::App().settings().dictionariesEnabled().size()) { return QString(); } - const auto dicts = session->settings().dictionariesEnabled(); + const auto dicts = Core::App().settings().dictionariesEnabled(); const auto filtered = ranges::view::all( dicts ) | ranges::views::filter( @@ -341,9 +342,9 @@ rpl::producer ButtonManageDictsState( ) | rpl::then( rpl::merge( Spellchecker::SupportedScriptsChanged(), - session->settings().dictionariesEnabledChanges( + Core::App().settings().dictionariesEnabledChanges( ) | rpl::map(emptyValue), - session->settings().spellcheckerEnabledChanges( + Core::App().settings().spellcheckerEnabledChanges( ) | rpl::map(emptyValue) ) | rpl::map(computeString) ); @@ -377,7 +378,7 @@ void Start(not_null session) { { &ph::lng_spellchecker_remove, tr::lng_spellchecker_remove() }, { &ph::lng_spellchecker_ignore, tr::lng_spellchecker_ignore() }, } }); - const auto settings = &session->settings(); + const auto settings = &Core::App().settings(); const auto onEnabled = [=](auto enabled) { Platform::Spellchecker::UpdateLanguages( diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 4d501ce54..93cd1604c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -13,10 +13,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_isolated_emoji.h" #include "ui/image/image.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "data/data_file_origin.h" #include "data/data_session.h" #include "data/data_document.h" +#include "core/core_settings.h" +#include "core/application.h" #include "base/call_delayed.h" #include "apiwrap.h" #include "app.h" @@ -209,7 +210,7 @@ QSize LargeEmojiImage::Size() { EmojiPack::EmojiPack(not_null session) : _session(session) -, _imageLoader(prepareSourceImages(), session->settings().largeEmoji()) +, _imageLoader(prepareSourceImages(), Core::App().settings().largeEmoji()) , _clearTimer([=] { clearSourceImages(); }) { refresh(); @@ -220,7 +221,7 @@ EmojiPack::EmojiPack(not_null session) remove(item); }, _lifetime); - _session->settings().largeEmojiChanges( + Core::App().settings().largeEmojiChanges( ) | rpl::start_with_next([=](bool large) { if (large) { _clearTimer.cancel(); @@ -392,7 +393,7 @@ void EmojiPack::refreshItems( auto EmojiPack::prepareSourceImages() -> std::shared_ptr { const auto &images = Ui::Emoji::SourceImages(); - if (_session->settings().largeEmoji()) { + if (Core::App().settings().largeEmoji()) { return images; } Ui::Emoji::ClearSourceImages(images); diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 859684f0d..2a959d40d 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -36,7 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "core/file_utilities.h" #include "main/main_account.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_session.h" #include "media/view/media_view_overlay_widget.h" #include "mtproto/mtproto_dc_options.h" @@ -56,7 +56,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/emoji_config.h" #include "ui/effects/animations.h" #include "storage/serialize_common.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "storage/storage_databases.h" #include "storage/localstorage.h" #include "window/window_session_controller.h" @@ -98,7 +98,7 @@ Application::Application(not_null launcher) , _animationsManager(std::make_unique()) , _fallbackProductionConfig( std::make_unique(MTP::Environment::Production)) -, _accounts(std::make_unique(cDataFile())) +, _domain(std::make_unique(cDataFile())) , _langpack(std::make_unique()) , _langCloudManager(std::make_unique(langpack())) , _emojiKeywords(std::make_unique()) @@ -116,14 +116,14 @@ Application::Application(not_null launcher) _shouldLockAt = 0; }, _lifetime); - accounts().activeSessionChanges( + _domain->activeSessionChanges( ) | rpl::start_with_next([=](Main::Session *session) { if (session && !UpdaterDisabled()) { // #TODO multi someSessionValue UpdateChecker().setMtproto(session); } }, _lifetime); - accounts().activeValue( + _domain->activeValue( ) | rpl::filter(rpl::mappers::_1 != nullptr ) | rpl::take(1) | rpl::start_with_next([=] { if (_window) { @@ -147,7 +147,7 @@ Application::~Application() { } unlockTerms(); - accounts().finish(); + _domain->finish(); Local::finish(); @@ -220,7 +220,7 @@ void Application::run() { QMimeDatabase().mimeTypeForName(qsl("text/plain")); _window = std::make_unique(); - accounts().activeChanges( + _domain->activeChanges( ) | rpl::start_with_next([=](not_null account) { _window->showAccount(account); }, _window->widget()->lifetime()); @@ -239,7 +239,7 @@ void Application::run() { App::initMedia(); - const auto state = accounts().start(QByteArray()); + const auto state = _domain->start(QByteArray()); if (state == Storage::StartResult::IncorrectPasscode) { Global::SetLocalPasscode(true); Global::RefLocalPasscodeChanged().notify(); @@ -390,6 +390,10 @@ void Application::saveSettingsDelayed(crl::time delay) { _saveSettingsTimer.callOnce(delay); } +void Application::saveSettings() { + Local::writeSettings(); +} + MTP::Config &Application::fallbackProductionConfig() const { if (!_fallbackProductionConfig) { _fallbackProductionConfig = std::make_unique( @@ -451,14 +455,14 @@ void Application::badMtprotoConfigurationError() { void Application::startLocalStorage() { Local::start(); - _saveSettingsTimer.setCallback([=] { Local::writeSettings(); }); + _saveSettingsTimer.setCallback([=] { saveSettings(); }); } void Application::logout(Main::Account *account) { if (account) { account->logOut(); } else { - accounts().resetWithForgottenPasscode(); + _domain->resetWithForgottenPasscode(); } } @@ -549,11 +553,11 @@ void Application::writeInstallBetaVersionsSetting() { } Main::Account &Application::activeAccount() const { - return _accounts->active(); + return _domain->active(); } Main::Session *Application::maybeActiveSession() const { - return (_accounts->started() && activeAccount().sessionExists()) + return (_domain->started() && activeAccount().sessionExists()) ? &activeAccount().session() : nullptr; } @@ -571,23 +575,24 @@ bool Application::exportPreventsQuit() { } int Application::unreadBadge() const { - return accounts().unreadBadge(); + return _domain->unreadBadge(); } bool Application::unreadBadgeMuted() const { - return accounts().unreadBadgeMuted(); + return _domain->unreadBadgeMuted(); } rpl::producer<> Application::unreadBadgeChanges() const { - return accounts().unreadBadgeChanges(); + return _domain->unreadBadgeChanges(); } bool Application::offerLegacyLangPackSwitch() const { - return (accounts().list().size() == 1) && activeAccount().sessionExists(); + return (_domain->accounts().size() == 1) + && activeAccount().sessionExists(); } bool Application::canApplyLangPackWithoutRestart() const { - for (const auto &[index, account] : accounts().list()) { + for (const auto &[index, account] : _domain->accounts()) { if (account->sessionExists()) { return false; } @@ -687,8 +692,7 @@ void Application::lockByTerms(const Window::TermsLock &data) { } bool Application::someSessionExists() const { - const auto &list = _accounts->list(); - for (const auto &[index, account] : list) { + for (const auto &[index, account] : _domain->accounts()) { if (account->sessionExists()) { return true; } @@ -707,7 +711,7 @@ void Application::checkAutoLock() { checkLocalTime(); const auto now = crl::now(); - const auto shouldLockInMs = Global::AutoLock() * 1000LL; + const auto shouldLockInMs = _settings.autoLock() * 1000LL; const auto checkTimeMs = now - lastNonIdleTime(); if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) { _shouldLockAt = 0; @@ -828,8 +832,8 @@ void Application::notifyFileDialogShown(bool shown) { } QWidget *Application::getModalParent() { - return Platform::IsWayland() - ? App::wnd() + return (Platform::IsWayland() && activeWindow()) + ? activeWindow()->widget() : nullptr; } @@ -918,7 +922,7 @@ void Application::quitDelayed() { void Application::startShortcuts() { Shortcuts::Start(); - _accounts->activeSessionChanges( + _domain->activeSessionChanges( ) | rpl::start_with_next([=](Main::Session *session) { const auto support = session && session->supportMode(); Shortcuts::ToggleSupportShortcuts(support); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 9c34d9969..24da238bf 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -36,7 +36,7 @@ void quit(); } // namespace App namespace Main { -class Accounts; +class Domain; class Account; class Session; } // namespace Main @@ -136,6 +136,7 @@ public: return _settings; } void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay); + void saveSettings(); // Fallback config and proxy. [[nodiscard]] MTP::Config &fallbackProductionConfig() const; @@ -152,9 +153,9 @@ public: return *_databases; } - // Accounts component. - [[nodiscard]] Main::Accounts &accounts() const { - return *_accounts; + // Domain component. + [[nodiscard]] Main::Domain &domain() const { + return *_domain; } [[nodiscard]] Main::Account &activeAccount() const; [[nodiscard]] bool someSessionExists() const; @@ -282,7 +283,7 @@ private: const std::unique_ptr _databases; const std::unique_ptr _animationsManager; mutable std::unique_ptr _fallbackProductionConfig; - const std::unique_ptr _accounts; + const std::unique_ptr _domain; std::unique_ptr _window; std::unique_ptr _mediaView; const std::unique_ptr _langpack; diff --git a/Telegram/SourceFiles/core/changelogs.cpp b/Telegram/SourceFiles/core/changelogs.cpp index 995ff2bad..f0e93179d 100644 --- a/Telegram/SourceFiles/core/changelogs.cpp +++ b/Telegram/SourceFiles/core/changelogs.cpp @@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "core/application.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_session.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "data/data_session.h" #include "mainwindow.h" #include "apiwrap.h" @@ -82,7 +82,7 @@ Changelogs::Changelogs(not_null session, int oldVersion) std::unique_ptr Changelogs::Create( not_null session) { - auto &local = Core::App().accounts().local(); + auto &local = Core::App().domain().local(); const auto oldVersion = local.oldVersion(); local.clearOldVersion(); return (oldVersion > 0 && oldVersion < AppVersion) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index a9c577cf2..64c113fbe 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -7,45 +7,284 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "core/core_settings.h" +#include "boxes/send_files_box.h" +#include "ui/widgets/input_fields.h" #include "storage/serialize_common.h" +#include "facades.h" namespace Core { -Settings::Variables::Variables() { +Settings::Settings() +: _sendFilesWay(SendFilesWay::Album) +, _sendSubmitWay(Ui::InputSubmitSettings::Enter) { } QByteArray Settings::serialize() const { - const auto themesAccentColors = _variables.themesAccentColors.serialize(); - auto size = Serialize::bytearraySize(themesAccentColors); + const auto themesAccentColors = _themesAccentColors.serialize(); + auto size = Serialize::bytearraySize(themesAccentColors) + + sizeof(qint32) * 5 + + Serialize::stringSize(_downloadPath.current()) + + Serialize::bytearraySize(_downloadPathBookmark) + + sizeof(qint32) * 12 + + Serialize::stringSize(_callOutputDeviceID) + + Serialize::stringSize(_callInputDeviceID) + + sizeof(qint32) * 3; + for (const auto &[key, value] : _soundOverrides) { + size += Serialize::stringSize(key) + Serialize::stringSize(value); + } + size += Serialize::bytearraySize(_videoPipGeometry); auto result = QByteArray(); result.reserve(size); { QDataStream stream(&result, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); - stream << themesAccentColors; + stream + << themesAccentColors + << qint32(_adaptiveForWide ? 1 : 0) + << qint32(_moderateModeEnabled ? 1 : 0) + << qint32(qRound(_songVolume.current() * 1e6)) + << qint32(qRound(_videoVolume.current() * 1e6)) + << qint32(_askDownloadPath ? 1 : 0) + << _downloadPath.current() + << _downloadPathBookmark + << qint32(_voiceMsgPlaybackDoubled ? 1 : 0) + << qint32(_soundNotify ? 1 : 0) + << qint32(_desktopNotify ? 1 : 0) + << qint32(_flashBounceNotify ? 1 : 0) + << static_cast(_notifyView) + << qint32(_nativeNotifications ? 1 : 0) + << qint32(_notificationsCount) + << static_cast(_notificationsCorner) + << qint32(_autoLock) + << _callOutputDeviceID + << _callInputDeviceID + << 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) + << qint32(_sendSubmitWay) + << qint32(_includeMutedCounter ? 1 : 0) + << qint32(_countUnreadMessages ? 1 : 0) + << qint32(_exeLaunchWarning ? 1 : 0) + << 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.current())) + << _videoPipGeometry + << qint32(_dictionariesEnabled.current().size()); + for (const auto i : _dictionariesEnabled.current()) { + stream << quint64(i); + } + stream + << qint32(_autoDownloadDictionaries.current() ? 1 : 0); + } return result; } -void Settings::constructFromSerialized(const QByteArray &serialized) { +void Settings::addFromSerialized(const QByteArray &serialized) { if (serialized.isEmpty()) { return; } QDataStream stream(serialized); stream.setVersion(QDataStream::Qt_5_1); + QByteArray themesAccentColors; + qint32 adaptiveForWide = _adaptiveForWide ? 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 voiceMsgPlaybackDoubled = _voiceMsgPlaybackDoubled ? 1 : 0; + qint32 soundNotify = _soundNotify ? 1 : 0; + qint32 desktopNotify = _desktopNotify ? 1 : 0; + qint32 flashBounceNotify = _flashBounceNotify ? 1 : 0; + qint32 notifyView = static_cast(_notifyView); + qint32 nativeNotifications = _nativeNotifications ? 1 : 0; + qint32 notificationsCount = _notificationsCount; + qint32 notificationsCorner = static_cast(_notificationsCorner); + qint32 autoLock = _autoLock; + QString callOutputDeviceID = _callOutputDeviceID; + QString callInputDeviceID = _callInputDeviceID; + qint32 callOutputVolume = _callOutputVolume; + qint32 callInputVolume = _callInputVolume; + qint32 callAudioDuckingEnabled = _callAudioDuckingEnabled ? 1 : 0; + qint32 lastSeenWarningSeen = _lastSeenWarningSeen ? 1 : 0; + qint32 soundOverridesCount = 0; + base::flat_map soundOverrides; + qint32 sendFilesWay = static_cast(_sendFilesWay); + qint32 sendSubmitWay = static_cast(_sendSubmitWay); + qint32 includeMutedCounter = _includeMutedCounter ? 1 : 0; + qint32 countUnreadMessages = _countUnreadMessages ? 1 : 0; + qint32 exeLaunchWarning = _exeLaunchWarning ? 1 : 0; + 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 = Core::Settings::SerializePlaybackSpeed(_videoPlaybackSpeed.current()); + QByteArray videoPipGeometry = _videoPipGeometry; + qint32 dictionariesEnabledCount = 0; + std::vector dictionariesEnabled; + qint32 autoDownloadDictionaries = _autoDownloadDictionaries.current() ? 1 : 0; stream >> themesAccentColors; + if (!stream.atEnd()) { + stream + >> adaptiveForWide + >> moderateModeEnabled + >> songVolume + >> videoVolume + >> askDownloadPath + >> downloadPath + >> downloadPathBookmark + >> voiceMsgPlaybackDoubled + >> soundNotify + >> desktopNotify + >> flashBounceNotify + >> notifyView + >> nativeNotifications + >> notificationsCount + >> notificationsCorner + >> autoLock + >> callOutputDeviceID + >> callInputDeviceID + >> 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 + >> exeLaunchWarning + >> 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; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); return; - } - if (!_variables.themesAccentColors.setFromSerialized(themesAccentColors)) { + } else if (!_themesAccentColors.setFromSerialized(themesAccentColors)) { 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; + _voiceMsgPlaybackDoubled = (voiceMsgPlaybackDoubled == 1); + _soundNotify = (soundNotify == 1); + _desktopNotify = (desktopNotify == 1); + _flashBounceNotify = (flashBounceNotify == 1); + const auto uncheckedNotifyView = static_cast(notifyView); + switch (uncheckedNotifyView) { + case dbinvShowNothing: + case dbinvShowName: + case dbinvShowPreview: _notifyView = uncheckedNotifyView; break; + } + _nativeNotifications = (nativeNotifications == 1); + _notificationsCount = (notificationsCount > 0) ? notificationsCount : 3; + const auto uncheckedNotificationsCorner = static_cast(notificationsCorner); + switch (uncheckedNotificationsCorner) { + case ScreenCorner::TopLeft: + case ScreenCorner::TopRight: + case ScreenCorner::BottomRight: + case ScreenCorner::BottomLeft: _notificationsCorner = uncheckedNotificationsCorner; break; + } + _includeMutedCounter = (includeMutedCounter == 1); + _countUnreadMessages = (countUnreadMessages == 1); + _notifyAboutPinned = (notifyAboutPinned == 1); + _autoLock = autoLock; + _callOutputDeviceID = callOutputDeviceID; + _callInputDeviceID = callInputDeviceID; + _callOutputVolume = callOutputVolume; + _callInputVolume = callInputVolume; + _callAudioDuckingEnabled = (callAudioDuckingEnabled == 1); + _lastSeenWarningSeen = (lastSeenWarningSeen == 1); + _soundOverrides = std::move(soundOverrides); + auto uncheckedSendFilesWay = static_cast(sendFilesWay); + switch (uncheckedSendFilesWay) { + case SendFilesWay::Album: + case SendFilesWay::Photos: + case SendFilesWay::Files: _sendFilesWay = uncheckedSendFilesWay; break; + } + auto uncheckedSendSubmitWay = static_cast(sendSubmitWay); + switch (uncheckedSendSubmitWay) { + case Ui::InputSubmitSettings::Enter: + case Ui::InputSubmitSettings::CtrlEnter: _sendSubmitWay = uncheckedSendSubmitWay; break; + } + _includeMutedCounter = (includeMutedCounter == 1); + _countUnreadMessages = (countUnreadMessages == 1); + _exeLaunchWarning = (exeLaunchWarning == 1); + _notifyAboutPinned = (notifyAboutPinned == 1); + _loopAnimatedStickers = (loopAnimatedStickers == 1); + _largeEmoji = (largeEmoji == 1); + _replaceEmoji = (replaceEmoji == 1); + _suggestEmoji = (suggestEmoji == 1); + _suggestStickersByEmoji = (suggestStickersByEmoji == 1); + _spellcheckerEnabled = (spellcheckerEnabled == 1); + _videoPlaybackSpeed = DeserializePlaybackSpeed(videoPlaybackSpeed); + _videoPipGeometry = (videoPipGeometry); + _dictionariesEnabled = std::move(dictionariesEnabled); + _autoDownloadDictionaries = (autoDownloadDictionaries == 1); +} + +bool Settings::chatWide() const { + return _adaptiveForWide + && (Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide); +} + +QString Settings::getSoundPath(const QString &key) const { + auto it = _soundOverrides.find(key); + if (it != _soundOverrides.end()) { + return it->second; + } + return qsl(":/sounds/") + key + qsl(".mp3"); } } // namespace Core diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index a3bcbdd89..cb1953211 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -9,32 +9,408 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_themes_embedded.h" +enum class SendFilesWay; + +namespace Ui { +enum class InputSubmitSettings; +} // namespace Ui + namespace Core { class Settings final { public: - void moveFrom(Settings &&other) { - _variables = std::move(other._variables); - } - [[nodiscard]] QByteArray serialize() const; - void constructFromSerialized(const QByteArray &serialized); + enum class ScreenCorner { + TopLeft = 0, + TopRight = 1, + BottomRight = 2, + BottomLeft = 3, + }; - void setThemesAccentColors(Window::Theme::AccentColors &&colors) { - _variables.themesAccentColors = std::move(colors); + static constexpr auto kDefaultVolume = 0.9; + + Settings(); + + [[nodiscard]] static bool IsLeftCorner(ScreenCorner corner) { + return (corner == ScreenCorner::TopLeft) + || (corner == ScreenCorner::BottomLeft); + } + [[nodiscard]] static bool IsTopCorner(ScreenCorner corner) { + return (corner == ScreenCorner::TopLeft) + || (corner == ScreenCorner::TopRight); + } + + [[nodiscard]] QByteArray serialize() const; + void addFromSerialized(const QByteArray &serialized); + + [[nodiscard]] bool chatWide() const; + [[nodiscard]] bool adaptiveForWide() const { + return _adaptiveForWide; + } + void setAdaptiveForWide(bool value) { + _adaptiveForWide = value; + } + [[nodiscard]] bool moderateModeEnabled() const { + return _moderateModeEnabled; + } + void setModerateModeEnabled(bool value) { + _moderateModeEnabled = value; + } + [[nodiscard]] float64 songVolume() const { + return _songVolume.current(); + } + [[nodiscard]] rpl::producer songVolumeChanges() const { + return _songVolume.changes(); + } + void setSongVolume(float64 value) { + _songVolume = value; + } + [[nodiscard]] float64 videoVolume() const { + return _videoVolume.current(); + } + [[nodiscard]] rpl::producer videoVolumeChanges() const { + return _videoVolume.changes(); + } + void setVideoVolume(float64 value) { + _videoVolume = value; + } + [[nodiscard]] bool askDownloadPath() const { + return _askDownloadPath; + } + void setAskDownloadPath(bool value) { + _askDownloadPath = value; + } + [[nodiscard]] QString downloadPath() const { + return _downloadPath.current(); + } + [[nodiscard]] rpl::producer downloadPathValue() const { + return _downloadPath.value(); + } + void setDownloadPath(const QString &value) { + _downloadPath = value; + } + [[nodiscard]] QByteArray downloadPathBookmark() const { + return _downloadPathBookmark; + } + void setDownloadPathBookmark(const QByteArray &value) { + _downloadPathBookmark = value; + } + [[nodiscard]] bool voiceMsgPlaybackDoubled() const { + return _voiceMsgPlaybackDoubled; + } + void setVoiceMsgPlaybackDoubled(bool value) { + _voiceMsgPlaybackDoubled = value; + } + [[nodiscard]] bool soundNotify() const { + return _soundNotify; + } + void setSoundNotify(bool value) { + _soundNotify = value; + } + [[nodiscard]] bool desktopNotify() const { + return _desktopNotify; + } + void setDesktopNotify(bool value) { + _desktopNotify = value; + } + [[nodiscard]] bool flashBounceNotify() const { + return _flashBounceNotify; + } + void setFlashBounceNotify(bool value) { + _flashBounceNotify = value; + } + [[nodiscard]] DBINotifyView notifyView() const { + return _notifyView; + } + void setNotifyView(DBINotifyView value) { + _notifyView = value; + } + [[nodiscard]] bool nativeNotifications() const { + return _nativeNotifications; + } + void setNativeNotifications(bool value) { + _nativeNotifications = value; + } + [[nodiscard]] int notificationsCount() const { + return _notificationsCount; + } + void setNotificationsCount(int value) { + _notificationsCount = value; + } + [[nodiscard]] ScreenCorner notificationsCorner() const { + return _notificationsCorner; + } + void setNotificationsCorner(ScreenCorner corner) { + _notificationsCorner = corner; + } + [[nodiscard]] bool includeMutedCounter() const { + return _includeMutedCounter; + } + void setIncludeMutedCounter(bool value) { + _includeMutedCounter = value; + } + [[nodiscard]] bool countUnreadMessages() const { + return _countUnreadMessages; + } + void setCountUnreadMessages(bool value) { + _countUnreadMessages = value; + } + void setNotifyAboutPinned(bool notify) { + _notifyAboutPinned = notify; + } + [[nodiscard]] bool notifyAboutPinned() const { + return _notifyAboutPinned.current(); + } + [[nodiscard]] rpl::producer notifyAboutPinnedChanges() const { + return _notifyAboutPinned.changes(); + } + [[nodiscard]] int autoLock() const { + return _autoLock; + } + void setAutoLock(int value) { + _autoLock = value; + } + [[nodiscard]] QString callOutputDeviceID() const { + return _callOutputDeviceID; + } + void setCallOutputDeviceID(const QString &value) { + _callOutputDeviceID = value; + } + [[nodiscard]] QString callInputDeviceID() const { + return _callInputDeviceID; + } + void setCallInputDeviceID(const QString &value) { + _callInputDeviceID = value; + } + [[nodiscard]] int callOutputVolume() const { + return _callOutputVolume; + } + void setCallOutputVolume(int value) { + _callOutputVolume = value; + } + [[nodiscard]] int callInputVolume() const { + return _callInputVolume; + } + void setCallInputVolume(int value) { + _callInputVolume = value; + } + [[nodiscard]] bool callAudioDuckingEnabled() const { + return _callAudioDuckingEnabled; + } + void setCallAudioDuckingEnabled(bool value) { + _callAudioDuckingEnabled = value; } [[nodiscard]] Window::Theme::AccentColors &themesAccentColors() { - return _variables.themesAccentColors; + return _themesAccentColors; + } + void setThemesAccentColors(Window::Theme::AccentColors &&colors) { + _themesAccentColors = std::move(colors); + } + void setLastSeenWarningSeen(bool lastSeenWarningSeen) { + _lastSeenWarningSeen = lastSeenWarningSeen; + } + [[nodiscard]] bool lastSeenWarningSeen() const { + return _lastSeenWarningSeen; + } + void setSendFilesWay(SendFilesWay way) { + _sendFilesWay = way; + } + [[nodiscard]] SendFilesWay sendFilesWay() const { + return _sendFilesWay; + } + void setSendSubmitWay(Ui::InputSubmitSettings value) { + _sendSubmitWay = value; + } + [[nodiscard]] Ui::InputSubmitSettings sendSubmitWay() const { + return _sendSubmitWay; + } + void setSoundOverride(const QString &key, const QString &path) { + _soundOverrides.emplace(key, path); + } + void clearSoundOverrides() { + _soundOverrides.clear(); + } + [[nodiscard]] QString getSoundPath(const QString &key) const; + + [[nodiscard]] bool exeLaunchWarning() const { + return _exeLaunchWarning; + } + void setExeLaunchWarning(bool warning) { + _exeLaunchWarning = warning; + } + [[nodiscard]] bool loopAnimatedStickers() const { + return _loopAnimatedStickers; + } + void setLoopAnimatedStickers(bool value) { + _loopAnimatedStickers = value; + } + void setLargeEmoji(bool value) { + _largeEmoji = value; + } + [[nodiscard]] bool largeEmoji() const { + return _largeEmoji.current(); + } + [[nodiscard]] rpl::producer largeEmojiValue() const { + return _largeEmoji.value(); + } + [[nodiscard]] rpl::producer largeEmojiChanges() const { + return _largeEmoji.changes(); + } + void setReplaceEmoji(bool value) { + _replaceEmoji = value; + } + [[nodiscard]] bool replaceEmoji() const { + return _replaceEmoji.current(); + } + [[nodiscard]] rpl::producer replaceEmojiValue() const { + return _replaceEmoji.value(); + } + [[nodiscard]] rpl::producer replaceEmojiChanges() const { + return _replaceEmoji.changes(); + } + [[nodiscard]] bool suggestEmoji() const { + return _suggestEmoji; + } + void setSuggestEmoji(bool value) { + _suggestEmoji = value; + } + [[nodiscard]] bool suggestStickersByEmoji() const { + return _suggestStickersByEmoji; + } + void setSuggestStickersByEmoji(bool value) { + _suggestStickersByEmoji = value; + } + + void setSpellcheckerEnabled(bool value) { + _spellcheckerEnabled = value; + } + bool spellcheckerEnabled() const { + return _spellcheckerEnabled.current(); + } + rpl::producer spellcheckerEnabledValue() const { + return _spellcheckerEnabled.value(); + } + rpl::producer spellcheckerEnabledChanges() const { + return _spellcheckerEnabled.changes(); + } + + void setDictionariesEnabled(std::vector dictionaries) { + _dictionariesEnabled = std::move(dictionaries); + } + + std::vector dictionariesEnabled() const { + return _dictionariesEnabled.current(); + } + + rpl::producer> dictionariesEnabledChanges() const { + return _dictionariesEnabled.changes(); + } + + void setAutoDownloadDictionaries(bool value) { + _autoDownloadDictionaries = value; + } + bool autoDownloadDictionaries() const { + return _autoDownloadDictionaries.current(); + } + rpl::producer autoDownloadDictionariesValue() const { + return _autoDownloadDictionaries.value(); + } + rpl::producer autoDownloadDictionariesChanges() const { + return _autoDownloadDictionaries.changes(); + } + + [[nodiscard]] float64 videoPlaybackSpeed() const { + return _videoPlaybackSpeed.current(); + } + void setVideoPlaybackSpeed(float64 speed) { + _videoPlaybackSpeed = speed; + } + [[nodiscard]] QByteArray videoPipGeometry() const { + return _videoPipGeometry; + } + void setVideoPipGeometry(QByteArray geometry) { + _videoPipGeometry = geometry; + } + + [[nodiscard]] float64 rememberedSongVolume() const { + return _rememberedSongVolume; + } + void setRememberedSongVolume(float64 value) { + _rememberedSongVolume = value; + } + [[nodiscard]] bool rememberedSoundNotifyFromTray() const { + return _rememberedSoundNotifyFromTray; + } + void setRememberedSoundNotifyFromTray(bool value) { + _rememberedSoundNotifyFromTray = value; + } + [[nodiscard]] bool rememberedFlashBounceNotifyFromTray() const { + return _rememberedFlashBounceNotifyFromTray; + } + void setRememberedFlashBounceNotifyFromTray(bool value) { + _rememberedFlashBounceNotifyFromTray = value; + } + + [[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) { + return int(std::round(std::clamp(speed * 4., 2., 8.))) - 2; + } + [[nodiscard]] static float64 DeserializePlaybackSpeed(qint32 speed) { + return (std::clamp(speed, 0, 6) + 2) / 4.; } private: - struct Variables { - Variables(); + bool _adaptiveForWide = true; + bool _moderateModeEnabled = false; - Window::Theme::AccentColors themesAccentColors; - }; + rpl::variable _songVolume = kDefaultVolume; + rpl::variable _videoVolume = kDefaultVolume; - Variables _variables; + bool _askDownloadPath = false; + rpl::variable _downloadPath; + QByteArray _downloadPathBookmark; + + bool _voiceMsgPlaybackDoubled = false; + bool _soundNotify = true; + bool _desktopNotify = true; + bool _flashBounceNotify = true; + DBINotifyView _notifyView = dbinvShowPreview; + bool _nativeNotifications = false; + int _notificationsCount = 3; + ScreenCorner _notificationsCorner = ScreenCorner::BottomRight; + bool _includeMutedCounter = true; + bool _countUnreadMessages = true; + rpl::variable _notifyAboutPinned = true; + int _autoLock = 3600; + + QString _callOutputDeviceID = u"default"_q; + QString _callInputDeviceID = u"default"_q; + int _callOutputVolume = 100; + int _callInputVolume = 100; + bool _callAudioDuckingEnabled = true; + + Window::Theme::AccentColors _themesAccentColors; + + bool _lastSeenWarningSeen = false; + SendFilesWay _sendFilesWay; + Ui::InputSubmitSettings _sendSubmitWay; + base::flat_map _soundOverrides; + + bool _exeLaunchWarning = true; + bool _loopAnimatedStickers = true; + rpl::variable _largeEmoji = true; + rpl::variable _replaceEmoji = true; + bool _suggestEmoji = true; + bool _suggestStickersByEmoji = true; + rpl::variable _spellcheckerEnabled = true; + rpl::variable _videoPlaybackSpeed = 1.; + QByteArray _videoPipGeometry; + rpl::variable> _dictionariesEnabled; + rpl::variable _autoDownloadDictionaries = true; + + float64 _rememberedSongVolume = kDefaultVolume; + bool _rememberedSoundNotifyFromTray = false; + bool _rememberedFlashBounceNotifyFromTray = false; }; } // namespace Core + diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 85ef0654e..006639ec0 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "core/sandbox.h" #include "base/concurrent_timer.h" -#include "facades.h" namespace Core { namespace { diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 29a59d6ca..2b5e5c494 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -59,9 +59,12 @@ bool JoinGroupByHash( })); }, [=](const MTPDchatInviteAlready &data) { if (const auto chat = session->data().processChat(data.vchat())) { - App::wnd()->sessionController()->showPeerHistory( - chat, - Window::SectionShow::Way::Forward); + for (const auto controller : session->windows()) { + controller->showPeerHistory( + chat, + Window::SectionShow::Way::Forward); + break; + } } }); }, [=](const RPCError &error) { diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 5df6c06c4..9f908c4ce 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -17,7 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "main/main_account.h" #include "main/main_session.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "info/info_memento.h" #include "info/settings/info_settings_widget.h" #include "window/window_session_controller.h" @@ -1392,7 +1392,7 @@ Updater::~Updater() { UpdateChecker::UpdateChecker() : _updater(GetUpdaterInstance()) { - if (IsAppLaunched() && Core::App().accounts().started()) { + if (IsAppLaunched() && Core::App().domain().started()) { const auto &account = Core::App().activeAccount(); if (account.sessionExists()) { _updater->setMtproto(&account.session()); diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index b493efd98..b29e898ae 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "inline_bots/inline_bot_layout_item.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mainwidget.h" #include "core/file_utilities.h" #include "core/mime_type.h" @@ -41,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "core/application.h" #include "lottie/lottie_animation.h" -#include "facades.h" #include "app.h" namespace { @@ -74,7 +72,7 @@ void LaunchWithWarning( const auto warn = [&] { if (!Data::IsExecutableName(name)) { return false; - } else if (!session->settings().exeLaunchWarning()) { + } else if (!Core::App().settings().exeLaunchWarning()) { return false; } else if (item && item->history()->peer->isVerified()) { return false; @@ -86,13 +84,13 @@ void LaunchWithWarning( return; } const auto extension = '.' + Data::FileExtension(name); - const auto callback = crl::guard(session, [=](bool checked) { + const auto callback = [=](bool checked) { if (checked) { - session->settings().setExeLaunchWarning(false); - session->saveSettingsDelayed(); + Core::App().settings().setExeLaunchWarning(false); + Core::App().saveSettingsDelayed(); } File::Launch(name); - }); + }; Ui::show(Box( tr::lng_launch_exe_warning( lt_extension, @@ -133,7 +131,7 @@ QString FileNameUnsafe( bool savingAs, const QDir &dir) { name = base::FileNameFromUserString(name); - if (Global::AskDownloadPath() || savingAs) { + if (Core::App().settings().askDownloadPath() || savingAs) { if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) { name = filedialogDefaultName(prefix, name); } else if (dir.path() != qsl(".")) { @@ -177,14 +175,16 @@ QString FileNameUnsafe( return filedialogGetSaveFile(name, title, fil, name) ? name : QString(); } - QString path; - if (Global::DownloadPath().isEmpty()) { - path = File::DefaultDownloadPath(session); - } else if (Global::DownloadPath() == qsl("tmp")) { - path = cTempDir(); - } else { - path = Global::DownloadPath(); - } + auto path = [&] { + const auto path = Core::App().settings().downloadPath(); + if (path.isEmpty()) { + return File::DefaultDownloadPath(session); + } else if (path == qsl("tmp")) { + return cTempDir(); + } else { + return path; + } + }(); if (name.isEmpty()) name = qsl(".unknown"); if (name.at(0) == QChar::fromLatin1('.')) { if (!QDir().exists(path)) QDir().mkpath(path); @@ -1056,10 +1056,9 @@ void DocumentData::handleLoaderUpdates() { // Sometimes FILE_REFERENCE_EXPIRED could not be handled. // //const auto openSettings = [=] { - // Global::SetDownloadPath(QString()); - // Global::SetDownloadPathBookmark(QByteArray()); + // Core::App().settings().etDownloadPathBookmark(QByteArray()); + // Core::App().settings().setDownloadPath(QString()); // Ui::show(Box()); - // Global::RefDownloadPathChanged().notify(); //}; //Ui::show(Box( // tr::lng_download_path_failed(tr::now), @@ -1175,7 +1174,8 @@ bool DocumentData::saveFromData() { bool DocumentData::saveFromDataSilent() { return !filepath(true).isEmpty() - || (!Global::AskDownloadPath() && saveFromDataChecked()); + || (!Core::App().settings().askDownloadPath() + && saveFromDataChecked()); } bool DocumentData::saveFromDataChecked() { diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index 5d51d2d57..d8c222cba 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -19,9 +19,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history.h" #include "window/themes/window_theme_preview.h" +#include "core/core_settings.h" +#include "core/application.h" #include "storage/file_download.h" #include "ui/image/image.h" -#include "facades.h" #include "app.h" #include @@ -259,7 +260,7 @@ void DocumentMedia::automaticLoad( return; } const auto toCache = _owner->saveToCache(); - if (!toCache && Global::AskDownloadPath()) { + if (!toCache && Core::App().settings().askDownloadPath()) { // We need a filename, but we're supposed to ask user for it. // No automatic download in this case. return; diff --git a/Telegram/SourceFiles/data/data_folder.cpp b/Telegram/SourceFiles/data/data_folder.cpp index cf65e3cf5..ef9e83a17 100644 --- a/Telegram/SourceFiles/data/data_folder.cpp +++ b/Telegram/SourceFiles/data/data_folder.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" //#include "storage/storage_feed_messages.h" // #feed #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "apiwrap.h" #include "mainwidget.h" @@ -372,7 +371,7 @@ bool Folder::shouldBeInChatList() const { int Folder::chatListUnreadCount() const { const auto state = chatListUnreadState(); return state.marks - + (session().settings().countUnreadMessages() + + (Core::App().settings().countUnreadMessages() ? state.messages : state.chats); } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 00cdd0773..cbc890b0d 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "apiwrap.h" #include "mainwidget.h" #include "api/api_text_entities.h" @@ -2067,7 +2066,7 @@ int Session::unreadBadgeIgnoreOne(const Dialogs::Key &key) const { } bool Session::unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const { - if (!_session->settings().includeMutedCounter()) { + if (!Core::App().settings().includeMutedCounter()) { return false; } const auto remove = (key && key.entry()->inChatList()) @@ -2078,7 +2077,7 @@ bool Session::unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const { int Session::unreadOnlyMutedBadge() const { const auto state = _chatsList.unreadState(); - return _session->settings().countUnreadMessages() + return Core::App().settings().countUnreadMessages() ? state.messagesMuted : state.chatsMuted; } @@ -2092,20 +2091,20 @@ void Session::notifyUnreadBadgeChanged() { } int Session::computeUnreadBadge(const Dialogs::UnreadState &state) const { - const auto all = _session->settings().includeMutedCounter(); + const auto all = Core::App().settings().includeMutedCounter(); return std::max(state.marks - (all ? 0 : state.marksMuted), 0) - + (_session->settings().countUnreadMessages() + + (Core::App().settings().countUnreadMessages() ? std::max(state.messages - (all ? 0 : state.messagesMuted), 0) : std::max(state.chats - (all ? 0 : state.chatsMuted), 0)); } bool Session::computeUnreadBadgeMuted( const Dialogs::UnreadState &state) const { - if (!_session->settings().includeMutedCounter()) { + if (!Core::App().settings().includeMutedCounter()) { return false; } return (state.marksMuted >= state.marks) - && (_session->settings().countUnreadMessages() + && (Core::App().settings().countUnreadMessages() ? (state.messagesMuted >= state.messages) : (state.chatsMuted >= state.chats)); } diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index c3c6d1f6d..682a457c3 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text_options.h" #include "apiwrap.h" #include "lang/lang_keys.h" -#include "facades.h" namespace { diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index af46d8809..08ef4297c 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -18,8 +18,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_components.h" #include "apiwrap.h" #include "storage/storage_account.h" +#include "core/application.h" +#include "core/core_settings.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "ui/toast/toast.h" #include "ui/image/image_location_factory.h" @@ -1051,7 +1052,7 @@ std::vector> Stickers::getListByEmoji( session().api().requestStickerSets(); } - if (session().settings().suggestStickersByEmoji()) { + if (Core::App().settings().suggestStickersByEmoji()) { const auto others = session().api().stickersByEmoji(original); if (!others) { return {}; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 966be7e0e..61d486522 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -49,7 +49,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/unread_badge.h" #include "boxes/filters/edit_filter_box.h" #include "api/api_chat_filters.h" -#include "facades.h" #include "styles/style_dialogs.h" #include "styles/style_chat_helpers.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 273f47d6d..6d294c09e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -284,7 +284,7 @@ Widget::Widget( updateControlsGeometry(); }, lifetime()); _mainMenuToggle->setClickedCallback([=] { showMainMenu(); }); - _searchForNarrowFilters->setClickedCallback([=] { Ui::showChatsList(); }); + _searchForNarrowFilters->setClickedCallback([=] { Ui::showChatsList(&session()); }); _chooseByDragTimer.setSingleShot(true); connect(&_chooseByDragTimer, SIGNAL(timeout()), this, SLOT(onChooseByDrag())); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index dd878c954..284635127 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -211,29 +211,28 @@ void showSettings() { namespace Ui { -void showPeerProfile(const PeerId &peer) { - if (const auto window = App::wnd()) { +void showPeerProfile(not_null peer) { + if (const auto window = App::wnd()) { // multi good if (const auto controller = window->sessionController()) { - controller->showPeerInfo(peer); + if (&controller->session() == &peer->session()) { + controller->showPeerInfo(peer); + } } } } -void showPeerProfile(const PeerData *peer) { - showPeerProfile(peer->id); -} void showPeerProfile(not_null history) { - showPeerProfile(history->peer->id); + showPeerProfile(history->peer); } -void showPeerHistory( - const PeerId &peer, - MsgId msgId) { +void showChatsList(not_null session) { if (const auto m = App::main()) { // multi good - m->ui_showPeerHistory( - peer, - Window::SectionShow::Way::ClearStack, - msgId); + if (&m->session() == session) { + m->ui_showPeerHistory( + 0, + Window::SectionShow::Way::ClearStack, + 0); + } } } @@ -332,37 +331,11 @@ namespace Global { namespace internal { struct Data { + bool ScreenIsLocked = false; Adaptive::WindowLayout AdaptiveWindowLayout = Adaptive::WindowLayout::Normal; Adaptive::ChatLayout AdaptiveChatLayout = Adaptive::ChatLayout::Normal; - bool AdaptiveForWide = true; base::Observable AdaptiveChanged; - bool DialogsFiltersEnabled = false; - bool ModerateModeEnabled = false; - - bool ScreenIsLocked = false; - - float64 RememberedSongVolume = kDefaultVolume; - float64 SongVolume = kDefaultVolume; - base::Observable SongVolumeChanged; - float64 VideoVolume = kDefaultVolume; - base::Observable VideoVolumeChanged; - - bool AskDownloadPath = false; - QString DownloadPath; - QByteArray DownloadPathBookmark; - base::Observable DownloadPathChanged; - - bool VoiceMsgPlaybackDoubled = false; - bool SoundNotify = true; - bool DesktopNotify = true; - bool FlashBounceNotify = true; - bool RestoreSoundNotifyFromTray = false; - bool RestoreFlashBounceNotifyFromTray = false; - DBINotifyView NotifyView = dbinvShowPreview; - bool NativeNotifications = false; - int NotificationsCount = 3; - Notify::ScreenCorner NotificationsCorner = Notify::ScreenCorner::BottomRight; bool NotificationsDemoIsShown = false; bool TryIPv6 = !Platform::IsWindows(); @@ -372,19 +345,12 @@ struct Data { bool UseProxyForCalls = false; base::Observable ConnectionTypeChanged; - int AutoLock = 3600; bool LocalPasscode = false; base::Observable LocalPasscodeChanged; base::Variable WorkMode = { dbiwmWindowAndTray }; base::Observable PeerChooseCancel; - - QString CallOutputDeviceID = qsl("default"); - QString CallInputDeviceID = qsl("default"); - int CallOutputVolume = 100; - int CallInputVolume = 100; - bool CallAudioDuckingEnabled = true; }; } // namespace internal @@ -407,37 +373,11 @@ void finish() { GlobalData = nullptr; } +DefineVar(Global, bool, ScreenIsLocked); DefineVar(Global, Adaptive::WindowLayout, AdaptiveWindowLayout); DefineVar(Global, Adaptive::ChatLayout, AdaptiveChatLayout); -DefineVar(Global, bool, AdaptiveForWide); DefineRefVar(Global, base::Observable, AdaptiveChanged); -DefineVar(Global, bool, DialogsFiltersEnabled); -DefineVar(Global, bool, ModerateModeEnabled); - -DefineVar(Global, bool, ScreenIsLocked); - -DefineVar(Global, float64, RememberedSongVolume); -DefineVar(Global, float64, SongVolume); -DefineRefVar(Global, base::Observable, SongVolumeChanged); -DefineVar(Global, float64, VideoVolume); -DefineRefVar(Global, base::Observable, VideoVolumeChanged); - -DefineVar(Global, bool, AskDownloadPath); -DefineVar(Global, QString, DownloadPath); -DefineVar(Global, QByteArray, DownloadPathBookmark); -DefineRefVar(Global, base::Observable, DownloadPathChanged); - -DefineVar(Global, bool, VoiceMsgPlaybackDoubled); -DefineVar(Global, bool, SoundNotify); -DefineVar(Global, bool, DesktopNotify); -DefineVar(Global, bool, FlashBounceNotify); -DefineVar(Global, bool, RestoreSoundNotifyFromTray); -DefineVar(Global, bool, RestoreFlashBounceNotifyFromTray); -DefineVar(Global, DBINotifyView, NotifyView); -DefineVar(Global, bool, NativeNotifications); -DefineVar(Global, int, NotificationsCount); -DefineVar(Global, Notify::ScreenCorner, NotificationsCorner); DefineVar(Global, bool, NotificationsDemoIsShown); DefineVar(Global, bool, TryIPv6); @@ -447,7 +387,6 @@ DefineVar(Global, MTP::ProxyData::Settings, ProxySettings); DefineVar(Global, bool, UseProxyForCalls); DefineRefVar(Global, base::Observable, ConnectionTypeChanged); -DefineVar(Global, int, AutoLock); DefineVar(Global, bool, LocalPasscode); DefineRefVar(Global, base::Observable, LocalPasscodeChanged); @@ -455,10 +394,4 @@ DefineRefVar(Global, base::Variable, WorkMode); DefineRefVar(Global, base::Observable, PeerChooseCancel); -DefineVar(Global, QString, CallOutputDeviceID); -DefineVar(Global, QString, CallInputDeviceID); -DefineVar(Global, int, CallOutputVolume); -DefineVar(Global, int, CallInputVolume); -DefineVar(Global, bool, CallAudioDuckingEnabled); - } // namespace Global diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 56693bcf1..cf456a4cf 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -56,18 +56,13 @@ namespace Ui { // Legacy global methods. -void showPeerProfile(const PeerId &peer); -void showPeerProfile(const PeerData *peer); +void showPeerProfile(not_null peer); void showPeerProfile(not_null history); -void showPeerHistory(const PeerId &peer, MsgId msgId); void showPeerHistoryAtItem(not_null item); - void showPeerHistory(not_null peer, MsgId msgId); void showPeerHistory(not_null history, MsgId msgId); -inline void showChatsList() { - showPeerHistory(PeerId(0), 0); -} +void showChatsList(not_null session); PeerData *getPeerForMouseAction(); bool skipPaintEvent(QWidget *widget, QPaintEvent *event); @@ -92,23 +87,6 @@ bool switchInlineBotButtonReceived( UserData *samePeerBot = nullptr, MsgId samePeerReplyTo = 0); -void unreadCounterUpdated(); - -enum class ScreenCorner { - TopLeft = 0, - TopRight = 1, - BottomRight = 2, - BottomLeft = 3, -}; - -inline bool IsLeftCorner(ScreenCorner corner) { - return (corner == ScreenCorner::TopLeft) || (corner == ScreenCorner::BottomLeft); -} - -inline bool IsTopCorner(ScreenCorner corner) { - return (corner == ScreenCorner::TopLeft) || (corner == ScreenCorner::TopRight); -} - } // namespace Notify #define DeclareReadOnlyVar(Type, Name) const Type &Name(); @@ -139,43 +117,10 @@ void start(); void finish(); DeclareVar(bool, ScreenIsLocked); - -DeclareVar(Adaptive::WindowLayout, AdaptiveWindowLayout); DeclareVar(Adaptive::ChatLayout, AdaptiveChatLayout); -DeclareVar(bool, AdaptiveForWide); +DeclareVar(Adaptive::WindowLayout, AdaptiveWindowLayout); DeclareRefVar(base::Observable, AdaptiveChanged); -DeclareVar(bool, DialogsFiltersEnabled); -DeclareVar(bool, ModerateModeEnabled); - -constexpr auto kDefaultVolume = 0.9; - -DeclareVar(float64, RememberedSongVolume); -DeclareVar(float64, SongVolume); -DeclareRefVar(base::Observable, SongVolumeChanged); -DeclareVar(float64, VideoVolume); -DeclareRefVar(base::Observable, VideoVolumeChanged); -DeclareVar(bool, AskDownloadPath); -DeclareVar(QString, DownloadPath); -DeclareVar(QByteArray, DownloadPathBookmark); -DeclareRefVar(base::Observable, DownloadPathChanged); -DeclareVar(bool, VoiceMsgPlaybackDoubled); -DeclareVar(bool, SoundNotify); -DeclareVar(bool, DesktopNotify); -DeclareVar(bool, FlashBounceNotify); -DeclareVar(bool, RestoreSoundNotifyFromTray); -DeclareVar(bool, RestoreFlashBounceNotifyFromTray); -DeclareVar(DBINotifyView, NotifyView); -DeclareVar(int, NotificationsCount); -DeclareVar(Notify::ScreenCorner, NotificationsCorner); - -DeclareVar(QString, CallOutputDeviceID); -DeclareVar(QString, CallInputDeviceID); -DeclareVar(int, CallOutputVolume); -DeclareVar(int, CallInputVolume); -DeclareVar(bool, CallAudioDuckingEnabled); - -DeclareVar(bool, NativeNotifications); DeclareVar(bool, NotificationsDemoIsShown); DeclareVar(bool, TryIPv6); @@ -185,7 +130,6 @@ DeclareVar(MTP::ProxyData::Settings, ProxySettings); DeclareVar(bool, UseProxyForCalls); DeclareRefVar(base::Observable, ConnectionTypeChanged); -DeclareVar(int, AutoLock); DeclareVar(bool, LocalPasscode); DeclareRefVar(base::Observable, LocalPasscodeChanged); @@ -213,13 +157,4 @@ inline bool ThreeColumn() { return Global::AdaptiveWindowLayout() == WindowLayout::ThreeColumn; } -inline bool ChatNormal() { - return !Global::AdaptiveForWide() - || (Global::AdaptiveChatLayout() == ChatLayout::Normal); -} - -inline bool ChatWide() { - return !ChatNormal(); -} - } // namespace Adaptive diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 713b4932f..a5adc761d 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -44,7 +44,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text_options.h" #include "core/crash_reports.h" #include "base/unixtime.h" -#include "facades.h" #include "styles/style_dialogs.h" namespace { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index f1c9b1eb0..ebdb0169d 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -391,7 +391,7 @@ void HistoryInner::enumerateItemsInHistory(History *history, int historytop, Met } bool HistoryInner::canHaveFromUserpics() const { - if (_peer->isUser() && !_peer->isSelf() && !Adaptive::ChatWide()) { + if (_peer->isUser() && !_peer->isSelf() && !Core::App().settings().chatWide()) { return false; } else if (_peer->isChannel() && !_peer->isMegagroup()) { return false; @@ -2131,7 +2131,7 @@ void HistoryInner::recountHistoryGeometry() { int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom(); int32 descMaxWidth = _scroll->width(); - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left(); @@ -2329,7 +2329,7 @@ void HistoryInner::updateSize() { if (_botAbout && _botAbout->height > 0) { int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom(); int32 descMaxWidth = _scroll->width(); - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left(); @@ -2680,7 +2680,7 @@ void HistoryInner::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = _contentWidth; - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 3a39883a6..df0659649 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_shared_media.h" //#include "storage/storage_feed_messages.h" // #feed #include "main/main_session.h" -#include "main/main_session_settings.h" #include "apiwrap.h" #include "media/audio/media_audio.h" #include "core/application.h" @@ -304,7 +303,7 @@ bool HistoryItem::isUnreadMention() const { bool HistoryItem::mentionsMe() const { if (Has() - && !history()->session().settings().notifyAboutPinned()) { + && !Core::App().settings().notifyAboutPinned()) { return false; } return _flags & MTPDmessage::Flag::f_mentioned; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 91d09be90..2d8eb53b9 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -506,7 +506,7 @@ HistoryWidget::HistoryWidget( } }, lifetime()); - session().settings().largeEmojiChanges( + Core::App().settings().largeEmojiChanges( ) | rpl::start_with_next([=] { crl::on_main(this, [=] { updateHistoryGeometry(); @@ -1554,7 +1554,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U if (h == _history) { applyDraft(); } else { - Ui::showPeerHistory(toPeerId, ShowAtUnreadMsgId); + Ui::showPeerHistory(h->peer, ShowAtUnreadMsgId); } return true; } @@ -2051,7 +2051,7 @@ void HistoryWidget::clearAllLoadRequests() { void HistoryWidget::updateFieldSubmitSettings() { const auto settings = _isInlineBot ? Ui::InputField::SubmitSettings::None - : session().settings().sendSubmitWay(); + : Core::App().settings().sendSubmitWay(); _field->setSubmitSettings(settings); } @@ -5475,7 +5475,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { } if (!_canSendMessages) { const auto submitting = Ui::InputField::ShouldSubmit( - session().settings().sendSubmitWay(), + Core::App().settings().sendSubmitWay(), e->modifiers()); if (submitting) { sendWithModifiers(e->modifiers()); diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index 59568d756..5d1d76cc8 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "main/main_session.h" #include "main/main_session_settings.h" +#include "core/application.h" +#include "core/core_settings.h" #include "inline_bots/inline_results_widget.h" #include "facades.h" #include "styles/style_history.h" @@ -207,7 +209,7 @@ void ComposeControls::init() { void ComposeControls::initField() { _field->setMaxHeight(st::historyComposeFieldMaxHeight); - _field->setSubmitSettings(_window->session().settings().sendSubmitWay()); + _field->setSubmitSettings(Core::App().settings().sendSubmitWay()); //Ui::Connect(_field, &Ui::InputField::submitted, [=] { send(); }); Ui::Connect(_field, &Ui::InputField::cancelled, [=] { escape(); }); //Ui::Connect(_field, &Ui::InputField::tabbed, [=] { fieldTabbed(); }); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 92977cdb7..1e9f793c0 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -16,15 +16,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_sticker.h" #include "history/view/media/history_view_large_emoji.h" #include "history/history.h" +#include "core/application.h" +#include "core/core_settings.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "chat_helpers/stickers_emoji_pack.h" #include "data/data_session.h" #include "data/data_groups.h" #include "data/data_media_types.h" #include "lang/lang_keys.h" #include "layout.h" -#include "facades.h" #include "app.h" #include "styles/style_history.h" @@ -164,7 +164,7 @@ void UnreadBar::paint(Painter &p, int y, int w) const { int left = st::msgServiceMargin.left(); int maxwidth = w; - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { maxwidth = qMin( maxwidth, st::msgMaxWidth @@ -363,7 +363,7 @@ void Element::refreshMedia(Element *replacing) { if (const auto media = _data->media()) { _media = media->createView(this, replacing); } else if (_data->isIsolatedEmoji() - && session->settings().largeEmoji()) { + && Core::App().settings().largeEmoji()) { const auto emoji = _data->isolatedEmoji(); const auto emojiStickers = &session->emojiStickersPack(); if (const auto sticker = emojiStickers->stickerForEmoji(emoji)) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 84b8ba105..4c915162e 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2168,7 +2168,7 @@ void ListWidget::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = view->width(); - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 049b5decb..180050360 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_media.h" #include "history/view/media/history_view_web_page.h" #include "history/history.h" +#include "core/application.h" +#include "core/core_settings.h" #include "ui/toast/toast.h" #include "ui/text/text_utilities.h" #include "ui/text/text_entity.h" @@ -454,7 +456,7 @@ void Message::draw( auto skipTail = isAttachedToNext() || (media && media->skipBubbleTail()) || (keyboard != nullptr); - auto displayTail = skipTail ? RectPart::None : (outbg && !Adaptive::ChatWide()) ? RectPart::Right : RectPart::Left; + auto displayTail = skipTail ? RectPart::None : (outbg && !Core::App().settings().chatWide()) ? RectPart::Right : RectPart::Left; PaintBubble(p, g, width(), selected, outbg, displayTail); // Entry page is always a bubble bottom. @@ -796,7 +798,7 @@ bool Message::hasFromPhoto() const { const auto item = message(); if (item->isPost() || item->isEmpty()) { return false; - } else if (Adaptive::ChatWide()) { + } else if (Core::App().settings().chatWide()) { return true; } else if (item->history()->peer->isSelf()) { return item->Has(); @@ -1786,7 +1788,7 @@ QRect Message::countGeometry() const { const auto availableWidth = width() - st::msgMargin.left() - st::msgMargin.right(); - auto contentLeft = (outbg && !Adaptive::ChatWide()) + auto contentLeft = (outbg && !Core::App().settings().chatWide()) ? st::msgMargin.right() : st::msgMargin.left(); auto contentWidth = availableWidth; @@ -1809,7 +1811,7 @@ QRect Message::countGeometry() const { contentWidth = mediaWidth; } } - if (contentWidth < availableWidth && outbg && !Adaptive::ChatWide()) { + if (contentWidth < availableWidth && outbg && !Core::App().settings().chatWide()) { contentLeft += availableWidth - contentWidth; } diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index b8be48278..c72050603 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -16,10 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat.h" #include "data/data_channel.h" #include "ui/text_options.h" +#include "core/core_settings.h" +#include "core/application.h" #include "mainwidget.h" #include "layout.h" #include "lang/lang_keys.h" -#include "facades.h" #include "app.h" #include "styles/style_history.h" @@ -164,7 +165,7 @@ void paintBubblePart(Painter &p, int x, int y, int width, int height, SideStyle void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) { int left = st::msgServiceMargin.left(); int maxwidth = w; - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { maxwidth = qMin(maxwidth, WideChatWidth()); } w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); @@ -320,7 +321,7 @@ not_null Service::message() const { QRect Service::countGeometry() const { auto result = QRect(0, 0, width(), height()); - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { result.setWidth(qMin(result.width(), st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } return result.marginsRemoved(st::msgServiceMargin); @@ -343,7 +344,7 @@ QSize Service::performCountCurrentSize(int newWidth) { item->_textHeight = 0; } else { auto contentWidth = newWidth; - if (Adaptive::ChatWide()) { + if (Core::App().settings().chatWide()) { accumulate_min(contentWidth, st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()); } contentWidth -= st::msgServiceMargin.left() + st::msgServiceMargin.left(); // two small margins diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index db75eed40..62f1f5a6b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -13,8 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history_item_components.h" #include "lottie/lottie_single_player.h" +#include "core/application.h" +#include "core/core_settings.h" #include "layout.h" -#include "facades.h" #include "app.h" #include "styles/style_history.h" @@ -87,7 +88,7 @@ QSize UnwrappedMedia::countCurrentSize(int newWidth) { } } auto newHeight = minHeight(); - if (_parent->hasOutLayout() && !Adaptive::ChatWide()) { + if (_parent->hasOutLayout() && !Core::App().settings().chatWide()) { // Add some height to isolated emoji for the timestamp info. const auto infoHeight = st::msgDateImgPadding.y() * 2 + st::msgDateFont->height; @@ -109,7 +110,7 @@ void UnwrappedMedia::draw( } bool selected = (selection == FullSelection); - const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -177,7 +178,7 @@ void UnwrappedMedia::drawSurrounding( const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { - const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); const auto rightAction = _parent->displayRightAction(); const auto fullRight = calculateFullRight(inner); auto fullBottom = height(); @@ -236,7 +237,7 @@ PointState UnwrappedMedia::pointState(QPoint point) const { return PointState::Outside; } - const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -276,7 +277,7 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { return result; } - const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); @@ -387,7 +388,7 @@ std::unique_ptr UnwrappedMedia::stickerTakeLottie() { } int UnwrappedMedia::calculateFullRight(const QRect &inner) const { - const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto rightAligned = _parent->hasOutLayout() && !Core::App().settings().chatWide(); const auto infoWidth = _parent->infoWidth() + st::msgDateImgPadding.x() * 2 + st::msgReplyPadding.left(); @@ -432,7 +433,7 @@ bool UnwrappedMedia::needInfoDisplay() const { || (_parent->displayRightAction()) || (_parent->isLastAndSelfMessage()) || (_parent->hasOutLayout() - && !Adaptive::ChatWide() + && !Core::App().settings().chatWide() && _content->alwaysShowOutTimestamp()); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 4f2bf0f58..946cd76e1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -17,8 +17,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_media_common.h" #include "ui/image/image.h" #include "ui/emoji_config.h" +#include "core/application.h" +#include "core/core_settings.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "main/main_account.h" #include "main/main_app_config.h" #include "mainwindow.h" // App::wnd()->sessionController. @@ -190,7 +191,7 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) { : (_diceIndex == 0) ? false : (isEmojiSticker() - || !_data->session().settings().loopAnimatedStickers()); + || !Core::App().settings().loopAnimatedStickers()); const auto count = _lottie->information().framesCount; _atTheEnd = (frame.index + 1 == count); _nextLastDiceFrame = !paused diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index 46c9dd7b0..db5b04a61 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" #include "main/main_session.h" #include "main/main_session_settings.h" +#include "core/application.h" +#include "core/core_settings.h" #include "apiwrap.h" #include "mainwindow.h" #include "boxes/confirm_box.h" @@ -26,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_auto_download.h" #include "window/window_controller.h" #include "window/themes/window_theme.h" -#include "facades.h" #include "app.h" #include "styles/style_intro.h" #include "styles/style_window.h" @@ -39,11 +40,11 @@ void PrepareSupportMode(not_null session) { using ::Data::AutoDownload::Full; anim::SetDisabled(true); - Local::writeSettings(); + Core::App().settings().setDesktopNotify(false); + Core::App().settings().setSoundNotify(false); + Core::App().settings().setFlashBounceNotify(false); + Core::App().saveSettings(); - Global::SetDesktopNotify(false); - Global::SetSoundNotify(false); - Global::SetFlashBounceNotify(false); session->settings().autoDownload() = Full::FullDisabled(); session->saveSettings(); } diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index 33f1c3198..c4476a5c9 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -29,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_connecting_widget.h" #include "base/platform/base_platform_info.h" #include "api/api_text_entities.h" -#include "facades.h" #include "app.h" #include "styles/style_layers.h" #include "styles/style_intro.h" diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 0351b03ea..aac839edd 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "core/application.h" #include "main/main_account.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "boxes/confirm_box.h" #include "ui/wrap/padding_wrap.h" #include "ui/widgets/labels.h" @@ -158,7 +158,7 @@ Language ParseLanguage(const MTPLangPackLanguage &data) { CloudManager::CloudManager(Instance &langpack) : _langpack(langpack) { - Core::App().accounts().activeValue( + Core::App().domain().activeValue( ) | rpl::map([=](Main::Account *account) { if (!account) { _api.reset(); diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index 1ad1054c9..2ec05db8e 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/launcher.h" #include "core/shortcuts.h" #include "storage/storage_account.h" -#include "storage/storage_accounts.h" // Storage::StartResult. +#include "storage/storage_domain.h" // Storage::StartResult. #include "storage/serialize_common.h" #include "storage/serialize_peer.h" #include "storage/localstorage.h" @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "main/main_app_config.h" #include "main/main_session.h" +#include "main/main_domain.h" #include "main/main_session_settings.h" #include "facades.h" @@ -45,8 +46,9 @@ namespace { } // namespace -Account::Account(const QString &dataName, int index) -: _local(std::make_unique( +Account::Account(not_null domain, const QString &dataName, int index) +: _domain(domain) +, _local(std::make_unique( this, ComposeDataString(dataName, index))) { } @@ -58,6 +60,10 @@ Account::~Account() { destroySession(); } +Storage::Domain &Account::domainLocal() const { + return _domain->local(); +} + [[nodiscard]] Storage::StartResult Account::legacyStart( const QByteArray &passcode) { Expects(!_appConfig); @@ -493,7 +499,7 @@ void Account::forcedLogOut() { void Account::loggedOut() { _loggingOut = false; Media::Player::mixer()->stopAndClear(); - Global::SetVoiceMsgPlaybackDoubled(false); + Core::App().settings().setVoiceMsgPlaybackDoubled(false); // #TODO multi properly reset settings if (const auto window = Core::App().activeWindow()) { window->tempDirDelete(Local::ClearManagerAll); } diff --git a/Telegram/SourceFiles/main/main_account.h b/Telegram/SourceFiles/main/main_account.h index c1af51663..551baf55b 100644 --- a/Telegram/SourceFiles/main/main_account.h +++ b/Telegram/SourceFiles/main/main_account.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Storage { class Account; +class Domain; enum class StartResult : uchar; } // namespace Storage @@ -23,17 +24,21 @@ class Config; namespace Main { +class Domain; class Session; class SessionSettings; class AppConfig; class Account final : public base::has_weak_ptr { public: - Account(const QString &dataName, int index); + Account(not_null domain, const QString &dataName, int index); ~Account(); - Account(const Account &other) = delete; - Account &operator=(const Account &other) = delete; + [[nodiscard]] Domain &domain() const { + return *_domain; + } + + [[nodiscard]] Storage::Domain &domainLocal() const; [[nodiscard]] Storage::StartResult legacyStart( const QByteArray &passcode); @@ -100,6 +105,8 @@ public: } private: + static constexpr auto kDefaultSaveDelay = crl::time(1000); + void startMtp(std::unique_ptr config); void createSession( const MTPUser &user, @@ -116,6 +123,7 @@ private: void loggedOut(); + const not_null _domain; const std::unique_ptr _local; std::unique_ptr _mtp; diff --git a/Telegram/SourceFiles/main/main_accounts.cpp b/Telegram/SourceFiles/main/main_domain.cpp similarity index 79% rename from Telegram/SourceFiles/main/main_accounts.cpp rename to Telegram/SourceFiles/main/main_domain.cpp index 8979fd5ed..ebdfed1f0 100644 --- a/Telegram/SourceFiles/main/main_accounts.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -5,7 +5,7 @@ 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 "main/main_accounts.h" +#include "main/main_domain.h" #include "core/application.h" #include "core/shortcuts.h" @@ -14,24 +14,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "mtproto/mtproto_config.h" #include "mtproto/mtproto_dc_options.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "storage/localstorage.h" #include "facades.h" namespace Main { -Accounts::Accounts(const QString &dataName) +Domain::Domain(const QString &dataName) : _dataName(dataName) -, _local(std::make_unique(this, dataName)) { +, _local(std::make_unique(this, dataName)) { } -Accounts::~Accounts() = default; +Domain::~Domain() = default; -bool Accounts::started() const { +bool Domain::started() const { return !_accounts.empty(); } -Storage::StartResult Accounts::start(const QByteArray &passcode) { +Storage::StartResult Domain::start(const QByteArray &passcode) { Expects(!started()); const auto result = _local->start(passcode); @@ -46,13 +46,13 @@ Storage::StartResult Accounts::start(const QByteArray &passcode) { return result; } -void Accounts::finish() { +void Domain::finish() { _activeIndex = -1; _active = nullptr; base::take(_accounts); } -void Accounts::accountAddedInStorage( +void Domain::accountAddedInStorage( int index, std::unique_ptr account) { Expects(account != nullptr); @@ -64,7 +64,7 @@ void Accounts::accountAddedInStorage( _accounts.emplace(index, std::move(account)); }; -void Accounts::resetWithForgottenPasscode() { +void Domain::resetWithForgottenPasscode() { if (_accounts.empty()) { _local->startFromScratch(); activateAfterStarting(); @@ -75,7 +75,7 @@ void Accounts::resetWithForgottenPasscode() { } } -void Accounts::activateAfterStarting() { +void Domain::activateAfterStarting() { Expects(started()); for (const auto &[index, account] : _accounts) { @@ -86,57 +86,57 @@ void Accounts::activateAfterStarting() { removePasscodeIfEmpty(); } -const base::flat_map> &Accounts::list() const { +const base::flat_map> &Domain::accounts() const { return _accounts; } -rpl::producer Accounts::activeValue() const { +rpl::producer Domain::activeValue() const { return _active.value(); } -int Accounts::activeIndex() const { +int Domain::activeIndex() const { Expects(_accounts.contains(_activeIndex)); return _activeIndex; } -Account &Accounts::active() const { +Account &Domain::active() const { Expects(!_accounts.empty()); Ensures(_active.current() != nullptr); return *_active.current(); } -rpl::producer> Accounts::activeChanges() const { +rpl::producer> Domain::activeChanges() const { return _active.changes() | rpl::map([](Account *value) { return not_null{ value }; }); } -rpl::producer Accounts::activeSessionChanges() const { +rpl::producer Domain::activeSessionChanges() const { return _activeSessions.events(); } -rpl::producer Accounts::activeSessionValue() const { +rpl::producer Domain::activeSessionValue() const { const auto current = (_accounts.empty() || !active().sessionExists()) ? nullptr : &active().session(); return rpl::single(current) | rpl::then(_activeSessions.events()); } -int Accounts::unreadBadge() const { +int Domain::unreadBadge() const { return _unreadBadge; } -bool Accounts::unreadBadgeMuted() const { +bool Domain::unreadBadgeMuted() const { return _unreadBadgeMuted; } -rpl::producer<> Accounts::unreadBadgeChanges() const { +rpl::producer<> Domain::unreadBadgeChanges() const { return _unreadBadgeChanges.events(); } -void Accounts::notifyUnreadBadgeChanged() { +void Domain::notifyUnreadBadgeChanged() { for (const auto &[index, account] : _accounts) { if (account->sessionExists()) { account->session().data().notifyUnreadBadgeChanged(); @@ -144,7 +144,7 @@ void Accounts::notifyUnreadBadgeChanged() { } } -void Accounts::updateUnreadBadge() { +void Domain::updateUnreadBadge() { _unreadBadge = 0; _unreadBadgeMuted = true; for (const auto &[index, account] : _accounts) { @@ -159,7 +159,7 @@ void Accounts::updateUnreadBadge() { _unreadBadgeChanges.fire({}); } -void Accounts::scheduleUpdateUnreadBadge() { +void Domain::scheduleUpdateUnreadBadge() { if (_unreadBadgeUpdateScheduled) { return; } @@ -170,7 +170,7 @@ void Accounts::scheduleUpdateUnreadBadge() { })); } -int Accounts::add(MTP::Environment environment) { +int Domain::add(MTP::Environment environment) { Expects(_active.current() != nullptr); static const auto cloneConfig = [](const MTP::Config &config) { @@ -183,7 +183,7 @@ int Accounts::add(MTP::Environment environment) { if (_active.current()->mtp().environment() == environment) { return accountConfig(_active.current()); } - for (const auto &[index, account] : list()) { + for (const auto &[index, account] : _accounts) { if (account->mtp().environment() == environment) { return accountConfig(account.get()); } @@ -198,14 +198,14 @@ int Accounts::add(MTP::Environment environment) { } const auto account = _accounts.emplace( index, - std::make_unique(_dataName, index) + std::make_unique(this, _dataName, index) ).first->second.get(); _local->startAdded(account, std::move(config)); watchSession(account); return index; } -void Accounts::watchSession(not_null account) { +void Domain::watchSession(not_null account) { account->sessionValue( ) | rpl::filter([=](Session *session) { return session != nullptr; @@ -230,7 +230,7 @@ void Accounts::watchSession(not_null account) { }, account->lifetime()); } -void Accounts::activateAuthedAccount() { +void Domain::activateAuthedAccount() { Expects(started()); if (_active.current()->sessionExists()) { @@ -244,7 +244,7 @@ void Accounts::activateAuthedAccount() { } } -bool Accounts::removePasscodeIfEmpty() { +bool Domain::removePasscodeIfEmpty() { if (_accounts.size() != 1 || _active.current()->sessionExists()) { return false; } @@ -258,7 +258,7 @@ bool Accounts::removePasscodeIfEmpty() { return true; } -void Accounts::removeRedundantAccounts() { +void Domain::removeRedundantAccounts() { Expects(started()); const auto was = _accounts.size(); @@ -278,7 +278,7 @@ void Accounts::removeRedundantAccounts() { } } -void Accounts::checkForLastProductionConfig( +void Domain::checkForLastProductionConfig( not_null account) { const auto mtp = &account->mtp(); if (mtp->environment() != MTP::Environment::Production) { @@ -293,7 +293,7 @@ void Accounts::checkForLastProductionConfig( Core::App().refreshFallbackProductionConfig(mtp->config()); } -void Accounts::activate(int index) { +void Domain::activate(int index) { Expects(_accounts.contains(index)); const auto changed = (_activeIndex != index); @@ -308,7 +308,7 @@ void Accounts::activate(int index) { } } -void Accounts::scheduleWriteAccounts() { +void Domain::scheduleWriteAccounts() { if (_writeAccountsScheduled) { return; } diff --git a/Telegram/SourceFiles/main/main_accounts.h b/Telegram/SourceFiles/main/main_domain.h similarity index 87% rename from Telegram/SourceFiles/main/main_accounts.h rename to Telegram/SourceFiles/main/main_domain.h index 53dd13437..032dcbab8 100644 --- a/Telegram/SourceFiles/main/main_accounts.h +++ b/Telegram/SourceFiles/main/main_domain.h @@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/timer.h" + namespace Storage { -class Accounts; +class Domain; enum class StartResult : uchar; } // namespace Storage @@ -21,21 +23,23 @@ namespace Main { class Account; class Session; -class Accounts final { +class Domain final { public: - explicit Accounts(const QString &dataName); - ~Accounts(); + static constexpr auto kMaxAccounts = 3; + + explicit Domain(const QString &dataName); + ~Domain(); [[nodiscard]] bool started() const; [[nodiscard]] Storage::StartResult start(const QByteArray &passcode); void resetWithForgottenPasscode(); void finish(); - [[nodiscard]] Storage::Accounts &local() const { + [[nodiscard]] Storage::Domain &local() const { return *_local; } - [[nodiscard]] auto list() const + [[nodiscard]] auto accounts() const -> const base::flat_map> &; [[nodiscard]] rpl::producer activeValue() const; @@ -55,7 +59,7 @@ public: [[nodiscard]] int add(MTP::Environment environment); void activate(int index); - // Interface for Storage::Accounts. + // Interface for Storage::Domain. void accountAddedInStorage(int index, std::unique_ptr account); private: @@ -70,7 +74,7 @@ private: void scheduleUpdateUnreadBadge(); const QString _dataName; - const std::unique_ptr _local; + const std::unique_ptr _local; base::flat_map> _accounts; rpl::variable _active = nullptr; diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 44d07aa44..ea4f432f2 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "core/application.h" #include "main/main_account.h" +#include "main/main_domain.h" #include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "chat_helpers/stickers_emoji_pack.h" @@ -42,7 +43,7 @@ namespace { constexpr auto kLegacyCallsPeerToPeerNobody = 4; [[nodiscard]] QString ValidatedInternalLinksDomain( - not_null session) { + not_null session) { // This domain should start with 'http[s]://' and end with '/'. // Like 'https://telegram.me/' or 'https://t.me/'. const auto &domain = session->serverConfig().internalLinksDomain; @@ -63,7 +64,7 @@ constexpr auto kLegacyCallsPeerToPeerNobody = 4; } // namespace Session::Session( - not_null account, + not_null account, const MTPUser &user, std::unique_ptr settings) : _account(account) @@ -140,7 +141,7 @@ Session::~Session() { ClickHandler::unpressed(); } -Main::Account &Session::account() const { +Account &Session::account() const { return *_account; } @@ -148,6 +149,14 @@ Storage::Account &Session::local() const { return _account->local(); } +Domain &Session::domain() const { + return _account->domain(); +} + +Storage::Domain &Session::domainLocal() const { + return _account->domainLocal(); +} + base::Observable &Session::downloaderTaskFinished() { return downloader().taskFinished(); } @@ -172,10 +181,21 @@ bool Session::validateSelf(const MTPUser &user) { return true; } +void Session::saveSettings() { + local().writeSessionSettings(); +} + void Session::saveSettingsDelayed(crl::time delay) { _saveSettingsTimer.callOnce(delay); } +void Session::saveSettingsNowIfNeeded() { + if (_saveSettingsTimer.isActive()) { + _saveSettingsTimer.cancel(); + saveSettings(); + } +} + MTP::DcId Session::mainDcId() const { return _account->mtp().mainDcId(); } @@ -227,17 +247,6 @@ Support::Templates& Session::supportTemplates() const { return supportHelper().templates(); } -void Session::saveSettingsNowIfNeeded() { - if (_saveSettingsTimer.isActive()) { - _saveSettingsTimer.cancel(); - saveSettings(); - } -} - -void Session::saveSettings() { - local().writeSessionSettings(); -} - void Session::addWindow(not_null controller) { _windows.emplace(controller); controller->lifetime().add([=] { diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 35300ff04..253d293d9 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -38,6 +38,7 @@ class DownloadManagerMtproto; class Uploader; class Facade; class Account; +class Domain; } // namespace Storage namespace Window { @@ -59,6 +60,7 @@ class DicePacks; namespace Main { class Account; +class Domain; class SessionSettings; class Session final @@ -66,7 +68,7 @@ class Session final , private base::Subscriber { public: Session( - not_null account, + not_null account, const MTPUser &user, std::unique_ptr settings); ~Session(); @@ -74,8 +76,10 @@ public: Session(const Session &other) = delete; Session &operator=(const Session &other) = delete; - [[nodiscard]] Main::Account &account() const; + [[nodiscard]] Account &account() const; [[nodiscard]] Storage::Account &local() const; + [[nodiscard]] Domain &domain() const; + [[nodiscard]] Storage::Domain &domainLocal() const; [[nodiscard]] UserId userId() const; [[nodiscard]] PeerId userPeerId() const; @@ -102,18 +106,19 @@ public: [[nodiscard]] Stickers::DicePacks &diceStickersPacks() const { return *_diceStickersPacks; } - [[nodiscard]] Window::Notifications::System ¬ifications() { + [[nodiscard]] Window::Notifications::System ¬ifications() const { return *_notifications; } - [[nodiscard]] Data::Changes &changes() { + [[nodiscard]] Data::Changes &changes() const { return *_changes; } - [[nodiscard]] Data::Session &data() { + [[nodiscard]] Data::Session &data() const { return *_data; } - [[nodiscard]] SessionSettings &settings() { + [[nodiscard]] SessionSettings &settings() const { return *_settings; } + void saveSettings(); void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay); void saveSettingsNowIfNeeded(); @@ -137,7 +142,6 @@ public: void termsDeleteNow(); - void setInternalLinkDomain(const QString &domain) const; [[nodiscard]] QString createInternalLink(const QString &query) const; [[nodiscard]] QString createInternalLinkFull(const QString &query) const; @@ -155,7 +159,7 @@ public: private: static constexpr auto kDefaultSaveDelay = crl::time(1000); - const not_null _account; + const not_null _account; const std::unique_ptr _settings; const std::unique_ptr _api; diff --git a/Telegram/SourceFiles/main/main_session_settings.cpp b/Telegram/SourceFiles/main/main_session_settings.cpp index f1e9f0982..8d8a8125e 100644 --- a/Telegram/SourceFiles/main/main_session_settings.cpp +++ b/Telegram/SourceFiles/main/main_session_settings.cpp @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "support/support_common.h" #include "storage/serialize_common.h" #include "boxes/send_files_box.h" +#include "core/application.h" +#include "core/core_settings.h" #include "base/platform/base_platform_info.h" namespace Main { @@ -20,29 +22,19 @@ namespace { constexpr auto kLegacyCallsPeerToPeerNobody = 4; constexpr auto kVersionTag = -1; -constexpr auto kVersion = 1; +constexpr auto kVersion = 2; constexpr auto kMaxSavedPlaybackPositions = 16; -[[nodiscard]] qint32 SerializePlaybackSpeed(float64 speed) { - return int(std::round(std::clamp(speed * 4., 2., 8.))) - 2; -} - -float64 DeserializePlaybackSpeed(qint32 speed) { - return (std::clamp(speed, 0, 6) + 2) / 4.; -} - } // namespace -SessionSettings::Variables::Variables() -: sendFilesWay(SendFilesWay::Album) -, selectorTab(ChatHelpers::SelectorTab::Emoji) -, floatPlayerColumn(Window::Column::Second) -, floatPlayerCorner(RectPart::TopRight) -, dialogsWidthRatio(ThirdColumnByDefault() +SessionSettings::SessionSettings() +: _selectorTab(ChatHelpers::SelectorTab::Emoji) +, _floatPlayerColumn(Window::Column::Second) +, _floatPlayerCorner(RectPart::TopRight) +, _dialogsWidthRatio(ThirdColumnByDefault() ? kDefaultBigDialogsWidthRatio : kDefaultDialogsWidthRatio) -, sendSubmitWay(Ui::InputSubmitSettings::Enter) -, supportSwitch(Support::SwitchSettings::Next) { +, _supportSwitch(Support::SwitchSettings::Next) { } bool SessionSettings::ThirdColumnByDefault() { @@ -50,16 +42,12 @@ bool SessionSettings::ThirdColumnByDefault() { } QByteArray SessionSettings::serialize() const { - const auto autoDownload = _variables.autoDownload.serialize(); + const auto autoDownload = _autoDownload.serialize(); auto size = sizeof(qint32) * 38; - for (const auto &[key, value] : _variables.soundOverrides) { - size += Serialize::stringSize(key) + Serialize::stringSize(value); - } - size += _variables.groupStickersSectionHidden.size() * sizeof(quint64); - size += _variables.mediaLastPlaybackPosition.size() * 2 * sizeof(quint64); + size += _groupStickersSectionHidden.size() * sizeof(quint64); + size += _mediaLastPlaybackPosition.size() * 2 * sizeof(quint64); size += Serialize::bytearraySize(autoDownload); - size += Serialize::bytearraySize(_variables.videoPipGeometry); - size += sizeof(qint32) + _variables.hiddenPinnedMessages.size() * (sizeof(quint64) + sizeof(qint32)); + size += sizeof(qint32) + _hiddenPinnedMessages.size() * (sizeof(quint64) + sizeof(qint32)); auto result = QByteArray(); result.reserve(size); @@ -67,125 +55,98 @@ QByteArray SessionSettings::serialize() const { QDataStream stream(&result, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); stream << qint32(kVersionTag) << qint32(kVersion); - stream << static_cast(_variables.selectorTab); - stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0); - stream << qint32(_variables.tabbedSelectorSectionEnabled ? 1 : 0); - stream << qint32(_variables.soundOverrides.size()); - for (const auto &[key, value] : _variables.soundOverrides) { - stream << key << value; - } - stream << qint32(_variables.tabbedSelectorSectionTooltipShown); - stream << qint32(_variables.floatPlayerColumn); - stream << qint32(_variables.floatPlayerCorner); - stream << qint32(_variables.groupStickersSectionHidden.size()); - for (auto peerId : _variables.groupStickersSectionHidden) { + stream << static_cast(_selectorTab); + stream << qint32(_tabbedSelectorSectionEnabled ? 1 : 0); + stream << qint32(_floatPlayerColumn); + stream << qint32(_floatPlayerCorner); + stream << qint32(_groupStickersSectionHidden.size()); + for (auto peerId : _groupStickersSectionHidden) { stream << quint64(peerId); } - stream << qint32(_variables.thirdSectionInfoEnabled ? 1 : 0); - stream << qint32(_variables.smallDialogsList ? 1 : 0); + stream << qint32(_thirdSectionInfoEnabled ? 1 : 0); + stream << qint32(_smallDialogsList ? 1 : 0); stream << qint32(snap( - qRound(_variables.dialogsWidthRatio.current() * 1000000), + qRound(_dialogsWidthRatio.current() * 1000000), 0, 1000000)); - stream << qint32(_variables.thirdColumnWidth.current()); - stream << qint32(_variables.thirdSectionExtendedBy); - stream << qint32(_variables.sendFilesWay); - stream << qint32(0);// LEGACY _variables.callsPeerToPeer.current()); - stream << qint32(_variables.sendSubmitWay); - stream << qint32(_variables.supportSwitch); - stream << qint32(_variables.supportFixChatsOrder ? 1 : 0); - stream << qint32(_variables.supportTemplatesAutocomplete ? 1 : 0); - stream << qint32(_variables.supportChatsTimeSlice.current()); - stream << qint32(_variables.includeMutedCounter ? 1 : 0); - stream << qint32(_variables.countUnreadMessages ? 1 : 0); - stream << qint32(_variables.exeLaunchWarning ? 1 : 0); + stream << qint32(_thirdColumnWidth.current()); + stream << qint32(_thirdSectionExtendedBy); + stream << qint32(_supportSwitch); + stream << qint32(_supportFixChatsOrder ? 1 : 0); + stream << qint32(_supportTemplatesAutocomplete ? 1 : 0); + stream << qint32(_supportChatsTimeSlice.current()); stream << autoDownload; - stream << qint32(_variables.supportAllSearchResults.current() ? 1 : 0); - stream << qint32(_variables.archiveCollapsed.current() ? 1 : 0); - stream << qint32(_variables.notifyAboutPinned.current() ? 1 : 0); - stream << qint32(_variables.archiveInMainMenu.current() ? 1 : 0); - stream << qint32(_variables.skipArchiveInSearch.current() ? 1 : 0); - stream << qint32(0);// LEGACY _variables.autoplayGifs ? 1 : 0); - stream << qint32(_variables.loopAnimatedStickers ? 1 : 0); - stream << qint32(_variables.largeEmoji.current() ? 1 : 0); - stream << qint32(_variables.replaceEmoji.current() ? 1 : 0); - stream << qint32(_variables.suggestEmoji ? 1 : 0); - stream << qint32(_variables.suggestStickersByEmoji ? 1 : 0); - stream << qint32(_variables.spellcheckerEnabled.current() ? 1 : 0); - stream << qint32(_variables.mediaLastPlaybackPosition.size()); - for (const auto &[id, time] : _variables.mediaLastPlaybackPosition) { + stream << qint32(_supportAllSearchResults.current() ? 1 : 0); + stream << qint32(_archiveCollapsed.current() ? 1 : 0); + stream << qint32(_archiveInMainMenu.current() ? 1 : 0); + stream << qint32(_skipArchiveInSearch.current() ? 1 : 0); + stream << qint32(_mediaLastPlaybackPosition.size()); + for (const auto &[id, time] : _mediaLastPlaybackPosition) { stream << quint64(id) << qint64(time); } - stream << qint32(SerializePlaybackSpeed(_variables.videoPlaybackSpeed.current())); - stream << _variables.videoPipGeometry; - stream << qint32(_variables.dictionariesEnabled.current().size()); - for (const auto i : _variables.dictionariesEnabled.current()) { - stream << quint64(i); - } - stream << qint32(_variables.autoDownloadDictionaries.current() ? 1 : 0); - stream << qint32(_variables.hiddenPinnedMessages.size()); - for (const auto &[key, value] : _variables.hiddenPinnedMessages) { + stream << qint32(_hiddenPinnedMessages.size()); + for (const auto &[key, value] : _hiddenPinnedMessages) { stream << quint64(key) << qint32(value); } + stream << qint32(_dialogsFiltersEnabled ? 1 : 0); } return result; } -std::unique_ptr SessionSettings::FromSerialized( - const QByteArray &serialized) { +void SessionSettings::addFromSerialized(const QByteArray &serialized) { if (serialized.isEmpty()) { - return nullptr; + return; } - auto result = std::make_unique(); - const auto variables = &result->_variables; + auto &app = Core::App().settings(); QDataStream stream(serialized); stream.setVersion(QDataStream::Qt_5_1); qint32 versionTag = 0; qint32 version = 0; qint32 selectorTab = static_cast(ChatHelpers::SelectorTab::Emoji); - qint32 lastSeenWarningSeen = 0; + qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0; qint32 tabbedSelectorSectionEnabled = 1; - qint32 tabbedSelectorSectionTooltipShown = 0; + qint32 legacyTabbedSelectorSectionTooltipShown = 0; qint32 floatPlayerColumn = static_cast(Window::Column::Second); qint32 floatPlayerCorner = static_cast(RectPart::TopRight); - base::flat_map soundOverrides; + base::flat_map appSoundOverrides; base::flat_set groupStickersSectionHidden; qint32 thirdSectionInfoEnabled = 0; qint32 smallDialogsList = 0; - float64 dialogsWidthRatio = variables->dialogsWidthRatio.current(); - int thirdColumnWidth = variables->thirdColumnWidth.current(); - int thirdSectionExtendedBy = variables->thirdSectionExtendedBy; - qint32 sendFilesWay = static_cast(variables->sendFilesWay); + float64 dialogsWidthRatio = _dialogsWidthRatio.current(); + int thirdColumnWidth = _thirdColumnWidth.current(); + int thirdSectionExtendedBy = _thirdSectionExtendedBy; + qint32 appSendFilesWay = static_cast(app.sendFilesWay()); qint32 legacyCallsPeerToPeer = qint32(0); - qint32 sendSubmitWay = static_cast(variables->sendSubmitWay); - qint32 supportSwitch = static_cast(variables->supportSwitch); - qint32 supportFixChatsOrder = variables->supportFixChatsOrder ? 1 : 0; - qint32 supportTemplatesAutocomplete = variables->supportTemplatesAutocomplete ? 1 : 0; - qint32 supportChatsTimeSlice = variables->supportChatsTimeSlice.current(); - qint32 includeMutedCounter = variables->includeMutedCounter ? 1 : 0; - qint32 countUnreadMessages = variables->countUnreadMessages ? 1 : 0; - qint32 exeLaunchWarning = variables->exeLaunchWarning ? 1 : 0; + qint32 appSendSubmitWay = static_cast(app.sendSubmitWay()); + qint32 supportSwitch = static_cast(_supportSwitch); + qint32 supportFixChatsOrder = _supportFixChatsOrder ? 1 : 0; + qint32 supportTemplatesAutocomplete = _supportTemplatesAutocomplete ? 1 : 0; + qint32 supportChatsTimeSlice = _supportChatsTimeSlice.current(); + qint32 appIncludeMutedCounter = app.includeMutedCounter() ? 1 : 0; + qint32 appCountUnreadMessages = app.countUnreadMessages() ? 1 : 0; + qint32 appExeLaunchWarning = app.exeLaunchWarning() ? 1 : 0; QByteArray autoDownload; - qint32 supportAllSearchResults = variables->supportAllSearchResults.current() ? 1 : 0; - qint32 archiveCollapsed = variables->archiveCollapsed.current() ? 1 : 0; - qint32 notifyAboutPinned = variables->notifyAboutPinned.current() ? 1 : 0; - qint32 archiveInMainMenu = variables->archiveInMainMenu.current() ? 1 : 0; - qint32 skipArchiveInSearch = variables->skipArchiveInSearch.current() ? 1 : 0; - qint32 autoplayGifs = 1; - qint32 loopAnimatedStickers = variables->loopAnimatedStickers ? 1 : 0; - qint32 largeEmoji = variables->largeEmoji.current() ? 1 : 0; - qint32 replaceEmoji = variables->replaceEmoji.current() ? 1 : 0; - qint32 suggestEmoji = variables->suggestEmoji ? 1 : 0; - qint32 suggestStickersByEmoji = variables->suggestStickersByEmoji ? 1 : 0; - qint32 spellcheckerEnabled = variables->spellcheckerEnabled.current() ? 1 : 0; + qint32 supportAllSearchResults = _supportAllSearchResults.current() ? 1 : 0; + qint32 archiveCollapsed = _archiveCollapsed.current() ? 1 : 0; + qint32 appNotifyAboutPinned = app.notifyAboutPinned() ? 1 : 0; + qint32 archiveInMainMenu = _archiveInMainMenu.current() ? 1 : 0; + qint32 skipArchiveInSearch = _skipArchiveInSearch.current() ? 1 : 0; + qint32 legacyAutoplayGifs = 1; + qint32 appLoopAnimatedStickers = app.loopAnimatedStickers() ? 1 : 0; + qint32 appLargeEmoji = app.largeEmoji() ? 1 : 0; + qint32 appReplaceEmoji = app.replaceEmoji() ? 1 : 0; + qint32 appSuggestEmoji = app.suggestEmoji() ? 1 : 0; + qint32 appSuggestStickersByEmoji = app.suggestStickersByEmoji() ? 1 : 0; + qint32 appSpellcheckerEnabled = app.spellcheckerEnabled() ? 1 : 0; std::vector> mediaLastPlaybackPosition; - qint32 videoPlaybackSpeed = SerializePlaybackSpeed(variables->videoPlaybackSpeed.current()); - QByteArray videoPipGeometry = variables->videoPipGeometry; - std::vector dictionariesEnabled; - qint32 autoDownloadDictionaries = variables->autoDownloadDictionaries.current() ? 1 : 0; + qint32 appVideoPlaybackSpeed = Core::Settings::SerializePlaybackSpeed(app.videoPlaybackSpeed()); + QByteArray appVideoPipGeometry = app.videoPipGeometry(); + std::vector appDictionariesEnabled; + qint32 appAutoDownloadDictionaries = app.autoDownloadDictionaries() ? 1 : 0; base::flat_map hiddenPinnedMessages; + qint32 dialogsFiltersEnabled = _dialogsFiltersEnabled ? 1 : 0; stream >> versionTag; if (versionTag == kVersionTag) { @@ -194,23 +155,27 @@ std::unique_ptr SessionSettings::FromSerialized( } else { selectorTab = versionTag; } - stream >> lastSeenWarningSeen; + if (version < 2) { + stream >> appLastSeenWarningSeen; + } if (!stream.atEnd()) { stream >> tabbedSelectorSectionEnabled; } - if (!stream.atEnd()) { - auto count = qint32(0); - stream >> count; - if (stream.status() == QDataStream::Ok) { - for (auto i = 0; i != count; ++i) { - QString key, value; - stream >> key >> value; - soundOverrides.emplace(key, value); + if (version < 2) { + if (!stream.atEnd()) { + auto count = qint32(0); + stream >> count; + if (stream.status() == QDataStream::Ok) { + for (auto i = 0; i != count; ++i) { + QString key, value; + stream >> key >> value; + appSoundOverrides.emplace(key, value); + } } } - } - if (!stream.atEnd()) { - stream >> tabbedSelectorSectionTooltipShown; + if (!stream.atEnd()) { + stream >> legacyTabbedSelectorSectionTooltipShown; + } } if (!stream.atEnd()) { stream >> floatPlayerColumn >> floatPlayerCorner; @@ -241,14 +206,18 @@ std::unique_ptr SessionSettings::FromSerialized( stream >> value; thirdSectionExtendedBy = value; } - if (!stream.atEnd()) { - stream >> sendFilesWay; + if (version < 2) { + if (!stream.atEnd()) { + stream >> appSendFilesWay; + } + if (!stream.atEnd()) { + stream >> legacyCallsPeerToPeer; + } } if (!stream.atEnd()) { - stream >> legacyCallsPeerToPeer; - } - if (!stream.atEnd()) { - stream >> sendSubmitWay; + if (version < 2) { + stream >> appSendSubmitWay; + } stream >> supportSwitch; stream >> supportFixChatsOrder; } @@ -258,12 +227,14 @@ std::unique_ptr SessionSettings::FromSerialized( if (!stream.atEnd()) { stream >> supportChatsTimeSlice; } - if (!stream.atEnd()) { - stream >> includeMutedCounter; - stream >> countUnreadMessages; - } - if (!stream.atEnd()) { - stream >> exeLaunchWarning; + if (version < 2) { + if (!stream.atEnd()) { + stream >> appIncludeMutedCounter; + stream >> appCountUnreadMessages; + } + if (!stream.atEnd()) { + stream >> appExeLaunchWarning; + } } if (!stream.atEnd()) { stream >> autoDownload; @@ -274,8 +245,10 @@ std::unique_ptr SessionSettings::FromSerialized( if (!stream.atEnd()) { stream >> archiveCollapsed; } - if (!stream.atEnd()) { - stream >> notifyAboutPinned; + if (version < 2) { + if (!stream.atEnd()) { + stream >> appNotifyAboutPinned; + } } if (!stream.atEnd()) { stream >> archiveInMainMenu; @@ -283,16 +256,18 @@ std::unique_ptr SessionSettings::FromSerialized( if (!stream.atEnd()) { stream >> skipArchiveInSearch; } - if (!stream.atEnd()) { - stream >> autoplayGifs; - stream >> loopAnimatedStickers; - stream >> largeEmoji; - stream >> replaceEmoji; - stream >> suggestEmoji; - stream >> suggestStickersByEmoji; - } - if (!stream.atEnd()) { - stream >> spellcheckerEnabled; + if (version < 2) { + if (!stream.atEnd()) { + stream >> legacyAutoplayGifs; + stream >> appLoopAnimatedStickers; + stream >> appLargeEmoji; + stream >> appReplaceEmoji; + stream >> appSuggestEmoji; + stream >> appSuggestStickersByEmoji; + } + if (!stream.atEnd()) { + stream >> appSpellcheckerEnabled; + } } if (!stream.atEnd()) { auto count = qint32(0); @@ -306,25 +281,27 @@ std::unique_ptr SessionSettings::FromSerialized( } } } - if (!stream.atEnd()) { - stream >> videoPlaybackSpeed; - } - if (!stream.atEnd()) { - stream >> videoPipGeometry; - } - if (!stream.atEnd()) { - auto count = qint32(0); - stream >> count; - if (stream.status() == QDataStream::Ok) { - for (auto i = 0; i != count; ++i) { - qint64 langId; - stream >> langId; - dictionariesEnabled.emplace_back(langId); + if (version < 2) { + if (!stream.atEnd()) { + stream >> appVideoPlaybackSpeed; + } + if (!stream.atEnd()) { + stream >> appVideoPipGeometry; + } + if (!stream.atEnd()) { + auto count = qint32(0); + stream >> count; + if (stream.status() == QDataStream::Ok) { + for (auto i = 0; i != count; ++i) { + qint64 langId; + stream >> langId; + appDictionariesEnabled.emplace_back(langId); + } } } - } - if (!stream.atEnd()) { - stream >> autoDownloadDictionaries; + if (!stream.atEnd()) { + stream >> appAutoDownloadDictionaries; + } } if (!stream.atEnd()) { auto count = qint32(0); @@ -338,20 +315,22 @@ std::unique_ptr SessionSettings::FromSerialized( } } } + if (!stream.atEnd()) { + stream >> dialogsFiltersEnabled; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Main::SessionSettings::FromSerialized()")); - return nullptr; + return; } if (!autoDownload.isEmpty() - && !variables->autoDownload.setFromSerialized(autoDownload)) { - return nullptr; + && !_autoDownload.setFromSerialized(autoDownload)) { + return; } if (!version) { - if (!autoplayGifs) { + if (!legacyAutoplayGifs) { using namespace Data::AutoDownload; - variables->autoDownload = WithDisabledAutoPlay( - variables->autoDownload); + _autoDownload = WithDisabledAutoPlay(_autoDownload); } } @@ -359,106 +338,110 @@ std::unique_ptr SessionSettings::FromSerialized( switch (uncheckedTab) { case ChatHelpers::SelectorTab::Emoji: case ChatHelpers::SelectorTab::Stickers: - case ChatHelpers::SelectorTab::Gifs: variables->selectorTab = uncheckedTab; break; + case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break; } - variables->lastSeenWarningSeen = (lastSeenWarningSeen == 1); - variables->tabbedSelectorSectionEnabled = (tabbedSelectorSectionEnabled == 1); - variables->soundOverrides = std::move(soundOverrides); - variables->tabbedSelectorSectionTooltipShown = tabbedSelectorSectionTooltipShown; + _tabbedSelectorSectionEnabled = (tabbedSelectorSectionEnabled == 1); auto uncheckedColumn = static_cast(floatPlayerColumn); switch (uncheckedColumn) { case Window::Column::First: case Window::Column::Second: - case Window::Column::Third: variables->floatPlayerColumn = uncheckedColumn; break; + case Window::Column::Third: _floatPlayerColumn = uncheckedColumn; break; } auto uncheckedCorner = static_cast(floatPlayerCorner); switch (uncheckedCorner) { case RectPart::TopLeft: case RectPart::TopRight: case RectPart::BottomLeft: - case RectPart::BottomRight: variables->floatPlayerCorner = uncheckedCorner; break; + case RectPart::BottomRight: _floatPlayerCorner = uncheckedCorner; break; } - variables->groupStickersSectionHidden = std::move(groupStickersSectionHidden); - variables->thirdSectionInfoEnabled = thirdSectionInfoEnabled; - variables->smallDialogsList = smallDialogsList; - variables->dialogsWidthRatio = dialogsWidthRatio; - variables->thirdColumnWidth = thirdColumnWidth; - variables->thirdSectionExtendedBy = thirdSectionExtendedBy; - if (variables->thirdSectionInfoEnabled) { - variables->tabbedSelectorSectionEnabled = false; - } - auto uncheckedSendFilesWay = static_cast(sendFilesWay); - switch (uncheckedSendFilesWay) { - case SendFilesWay::Album: - case SendFilesWay::Photos: - case SendFilesWay::Files: variables->sendFilesWay = uncheckedSendFilesWay; break; - } - auto uncheckedSendSubmitWay = static_cast( - sendSubmitWay); - switch (uncheckedSendSubmitWay) { - case Ui::InputSubmitSettings::Enter: - case Ui::InputSubmitSettings::CtrlEnter: variables->sendSubmitWay = uncheckedSendSubmitWay; break; + _groupStickersSectionHidden = std::move(groupStickersSectionHidden); + _thirdSectionInfoEnabled = thirdSectionInfoEnabled; + _smallDialogsList = smallDialogsList; + _dialogsWidthRatio = dialogsWidthRatio; + _thirdColumnWidth = thirdColumnWidth; + _thirdSectionExtendedBy = thirdSectionExtendedBy; + if (_thirdSectionInfoEnabled) { + _tabbedSelectorSectionEnabled = false; } auto uncheckedSupportSwitch = static_cast( supportSwitch); switch (uncheckedSupportSwitch) { case Support::SwitchSettings::None: case Support::SwitchSettings::Next: - case Support::SwitchSettings::Previous: variables->supportSwitch = uncheckedSupportSwitch; break; + case Support::SwitchSettings::Previous: _supportSwitch = uncheckedSupportSwitch; break; + } + _supportFixChatsOrder = (supportFixChatsOrder == 1); + _supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1); + _supportChatsTimeSlice = supportChatsTimeSlice; + _hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody); + _supportAllSearchResults = (supportAllSearchResults == 1); + _archiveCollapsed = (archiveCollapsed == 1); + _archiveInMainMenu = (archiveInMainMenu == 1); + _skipArchiveInSearch = (skipArchiveInSearch == 1); + _mediaLastPlaybackPosition = std::move(mediaLastPlaybackPosition); + _hiddenPinnedMessages = std::move(hiddenPinnedMessages); + _dialogsFiltersEnabled = (dialogsFiltersEnabled == 1); + + if (version < 2) { + app.setLastSeenWarningSeen(appLastSeenWarningSeen == 1); + for (const auto &[key, value] : appSoundOverrides) { + app.setSoundOverride(key, value); + } + auto uncheckedSendFilesWay = static_cast(appSendFilesWay); + switch (uncheckedSendFilesWay) { + case SendFilesWay::Album: + case SendFilesWay::Photos: + case SendFilesWay::Files: app.setSendFilesWay(uncheckedSendFilesWay); break; + } + auto uncheckedSendSubmitWay = static_cast( + appSendSubmitWay); + switch (uncheckedSendSubmitWay) { + case Ui::InputSubmitSettings::Enter: + case Ui::InputSubmitSettings::CtrlEnter: app.setSendSubmitWay(uncheckedSendSubmitWay); break; + } + app.setIncludeMutedCounter(appIncludeMutedCounter == 1); + app.setCountUnreadMessages(appCountUnreadMessages == 1); + app.setExeLaunchWarning(appExeLaunchWarning == 1); + app.setNotifyAboutPinned(appNotifyAboutPinned == 1); + app.setLoopAnimatedStickers(appLoopAnimatedStickers == 1); + app.setLargeEmoji(appLargeEmoji == 1); + app.setReplaceEmoji(appReplaceEmoji == 1); + app.setSuggestEmoji(appSuggestEmoji == 1); + app.setSuggestStickersByEmoji(appSuggestStickersByEmoji == 1); + app.setSpellcheckerEnabled(appSpellcheckerEnabled == 1); + app.setVideoPlaybackSpeed(Core::Settings::DeserializePlaybackSpeed(appVideoPlaybackSpeed)); + app.setVideoPipGeometry(appVideoPipGeometry); + app.setDictionariesEnabled(std::move(appDictionariesEnabled)); + app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1); } - variables->supportFixChatsOrder = (supportFixChatsOrder == 1); - variables->supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1); - variables->supportChatsTimeSlice = supportChatsTimeSlice; - variables->hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody); - variables->includeMutedCounter = (includeMutedCounter == 1); - variables->countUnreadMessages = (countUnreadMessages == 1); - variables->exeLaunchWarning = (exeLaunchWarning == 1); - variables->supportAllSearchResults = (supportAllSearchResults == 1); - variables->archiveCollapsed = (archiveCollapsed == 1); - variables->notifyAboutPinned = (notifyAboutPinned == 1); - variables->archiveInMainMenu = (archiveInMainMenu == 1); - variables->skipArchiveInSearch = (skipArchiveInSearch == 1); - variables->loopAnimatedStickers = (loopAnimatedStickers == 1); - variables->largeEmoji = (largeEmoji == 1); - variables->replaceEmoji = (replaceEmoji == 1); - variables->suggestEmoji = (suggestEmoji == 1); - variables->suggestStickersByEmoji = (suggestStickersByEmoji == 1); - variables->spellcheckerEnabled = (spellcheckerEnabled == 1); - variables->mediaLastPlaybackPosition = std::move(mediaLastPlaybackPosition); - variables->videoPlaybackSpeed = DeserializePlaybackSpeed(videoPlaybackSpeed); - variables->videoPipGeometry = videoPipGeometry; - variables->dictionariesEnabled = std::move(dictionariesEnabled); - variables->autoDownloadDictionaries = (autoDownloadDictionaries == 1); - variables->hiddenPinnedMessages = std::move(hiddenPinnedMessages); - return result; } void SessionSettings::setSupportChatsTimeSlice(int slice) { - _variables.supportChatsTimeSlice = slice; + _supportChatsTimeSlice = slice; } int SessionSettings::supportChatsTimeSlice() const { - return _variables.supportChatsTimeSlice.current(); + return _supportChatsTimeSlice.current(); } rpl::producer SessionSettings::supportChatsTimeSliceValue() const { - return _variables.supportChatsTimeSlice.value(); + return _supportChatsTimeSlice.value(); } void SessionSettings::setSupportAllSearchResults(bool all) { - _variables.supportAllSearchResults = all; + _supportAllSearchResults = all; } bool SessionSettings::supportAllSearchResults() const { - return _variables.supportAllSearchResults.current(); + return _supportAllSearchResults.current(); } rpl::producer SessionSettings::supportAllSearchResultsValue() const { - return _variables.supportAllSearchResults.value(); + return _supportAllSearchResults.value(); } void SessionSettings::setTabbedSelectorSectionEnabled(bool enabled) { - _variables.tabbedSelectorSectionEnabled = enabled; + _tabbedSelectorSectionEnabled = enabled; if (enabled) { setThirdSectionInfoEnabled(false); } @@ -471,8 +454,8 @@ rpl::producer SessionSettings::tabbedReplacedWithInfoValue() const { } void SessionSettings::setThirdSectionInfoEnabled(bool enabled) { - if (_variables.thirdSectionInfoEnabled != enabled) { - _variables.thirdSectionInfoEnabled = enabled; + if (_thirdSectionInfoEnabled != enabled) { + _thirdSectionInfoEnabled = enabled; if (enabled) { setTabbedSelectorSectionEnabled(false); } @@ -493,40 +476,32 @@ void SessionSettings::setTabbedReplacedWithInfo(bool enabled) { } } -QString SessionSettings::getSoundPath(const QString &key) const { - auto it = _variables.soundOverrides.find(key); - if (it != _variables.soundOverrides.end()) { - return it->second; - } - return qsl(":/sounds/") + key + qsl(".mp3"); -} - void SessionSettings::setDialogsWidthRatio(float64 ratio) { - _variables.dialogsWidthRatio = ratio; + _dialogsWidthRatio = ratio; } float64 SessionSettings::dialogsWidthRatio() const { - return _variables.dialogsWidthRatio.current(); + return _dialogsWidthRatio.current(); } rpl::producer SessionSettings::dialogsWidthRatioChanges() const { - return _variables.dialogsWidthRatio.changes(); + return _dialogsWidthRatio.changes(); } void SessionSettings::setThirdColumnWidth(int width) { - _variables.thirdColumnWidth = width; + _thirdColumnWidth = width; } int SessionSettings::thirdColumnWidth() const { - return _variables.thirdColumnWidth.current(); + return _thirdColumnWidth.current(); } rpl::producer SessionSettings::thirdColumnWidthChanges() const { - return _variables.thirdColumnWidth.changes(); + return _thirdColumnWidth.changes(); } void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time) { - auto &map = _variables.mediaLastPlaybackPosition; + auto &map = _mediaLastPlaybackPosition; const auto i = ranges::find( map, id, @@ -547,90 +522,46 @@ void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time crl::time SessionSettings::mediaLastPlaybackPosition(DocumentId id) const { const auto i = ranges::find( - _variables.mediaLastPlaybackPosition, + _mediaLastPlaybackPosition, id, &std::pair::first); - return (i != _variables.mediaLastPlaybackPosition.end()) ? i->second : 0; + return (i != _mediaLastPlaybackPosition.end()) ? i->second : 0; } void SessionSettings::setArchiveCollapsed(bool collapsed) { - _variables.archiveCollapsed = collapsed; + _archiveCollapsed = collapsed; } bool SessionSettings::archiveCollapsed() const { - return _variables.archiveCollapsed.current(); + return _archiveCollapsed.current(); } rpl::producer SessionSettings::archiveCollapsedChanges() const { - return _variables.archiveCollapsed.changes(); + return _archiveCollapsed.changes(); } void SessionSettings::setArchiveInMainMenu(bool inMainMenu) { - _variables.archiveInMainMenu = inMainMenu; + _archiveInMainMenu = inMainMenu; } bool SessionSettings::archiveInMainMenu() const { - return _variables.archiveInMainMenu.current(); + return _archiveInMainMenu.current(); } rpl::producer SessionSettings::archiveInMainMenuChanges() const { - return _variables.archiveInMainMenu.changes(); -} - -void SessionSettings::setNotifyAboutPinned(bool notify) { - _variables.notifyAboutPinned = notify; -} - -bool SessionSettings::notifyAboutPinned() const { - return _variables.notifyAboutPinned.current(); -} - -rpl::producer SessionSettings::notifyAboutPinnedChanges() const { - return _variables.notifyAboutPinned.changes(); + return _archiveInMainMenu.changes(); } void SessionSettings::setSkipArchiveInSearch(bool skip) { - _variables.skipArchiveInSearch = skip; + _skipArchiveInSearch = skip; } bool SessionSettings::skipArchiveInSearch() const { - return _variables.skipArchiveInSearch.current(); + return _skipArchiveInSearch.current(); } rpl::producer SessionSettings::skipArchiveInSearchChanges() const { - return _variables.skipArchiveInSearch.changes(); -} - -void SessionSettings::setLargeEmoji(bool value) { - _variables.largeEmoji = value; -} - -bool SessionSettings::largeEmoji() const { - return _variables.largeEmoji.current(); -} - -rpl::producer SessionSettings::largeEmojiValue() const { - return _variables.largeEmoji.value(); -} - -rpl::producer SessionSettings::largeEmojiChanges() const { - return _variables.largeEmoji.changes(); -} - -void SessionSettings::setReplaceEmoji(bool value) { - _variables.replaceEmoji = value; -} - -bool SessionSettings::replaceEmoji() const { - return _variables.replaceEmoji.current(); -} - -rpl::producer SessionSettings::replaceEmojiValue() const { - return _variables.replaceEmoji.value(); -} - -rpl::producer SessionSettings::replaceEmojiChanges() const { - return _variables.replaceEmoji.changes(); + return _skipArchiveInSearch.changes(); } } // namespace Main diff --git a/Telegram/SourceFiles/main/main_session_settings.h b/Telegram/SourceFiles/main/main_session_settings.h index eb25b1e01..22840e735 100644 --- a/Telegram/SourceFiles/main/main_session_settings.h +++ b/Telegram/SourceFiles/main/main_session_settings.h @@ -10,12 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_auto_download.h" #include "ui/rect_part.h" -enum class SendFilesWay; - -namespace Ui { -enum class InputSubmitSettings; -} // namespace Ui - namespace Support { enum class SwitchSettings; } // namespace Support @@ -32,46 +26,28 @@ namespace Main { class SessionSettings final { public: - [[nodiscard]] QByteArray serialize() const; - [[nodiscard]] static std::unique_ptr FromSerialized( - const QByteArray &serialized); + SessionSettings(); - void setLastSeenWarningSeen(bool lastSeenWarningSeen) { - _variables.lastSeenWarningSeen = lastSeenWarningSeen; - } - [[nodiscard]] bool lastSeenWarningSeen() const { - return _variables.lastSeenWarningSeen; - } - void setSendFilesWay(SendFilesWay way) { - _variables.sendFilesWay = way; - } - [[nodiscard]] SendFilesWay sendFilesWay() const { - return _variables.sendFilesWay; - } - void setSendSubmitWay(Ui::InputSubmitSettings value) { - _variables.sendSubmitWay = value; - } - [[nodiscard]] Ui::InputSubmitSettings sendSubmitWay() const { - return _variables.sendSubmitWay; - } + [[nodiscard]] QByteArray serialize() const; + [[nodiscard]] void addFromSerialized(const QByteArray &serialized); void setSupportSwitch(Support::SwitchSettings value) { - _variables.supportSwitch = value; + _supportSwitch = value; } [[nodiscard]] Support::SwitchSettings supportSwitch() const { - return _variables.supportSwitch; + return _supportSwitch; } void setSupportFixChatsOrder(bool fix) { - _variables.supportFixChatsOrder = fix; + _supportFixChatsOrder = fix; } [[nodiscard]] bool supportFixChatsOrder() const { - return _variables.supportFixChatsOrder; + return _supportFixChatsOrder; } void setSupportTemplatesAutocomplete(bool enabled) { - _variables.supportTemplatesAutocomplete = enabled; + _supportTemplatesAutocomplete = enabled; } [[nodiscard]] bool supportTemplatesAutocomplete() const { - return _variables.supportTemplatesAutocomplete; + return _supportTemplatesAutocomplete; } void setSupportChatsTimeSlice(int slice); [[nodiscard]] int supportChatsTimeSlice() const; @@ -81,25 +57,25 @@ public: [[nodiscard]] rpl::producer supportAllSearchResultsValue() const; [[nodiscard]] ChatHelpers::SelectorTab selectorTab() const { - return _variables.selectorTab; + return _selectorTab; } void setSelectorTab(ChatHelpers::SelectorTab tab) { - _variables.selectorTab = tab; + _selectorTab = tab; } [[nodiscard]] bool tabbedSelectorSectionEnabled() const { - return _variables.tabbedSelectorSectionEnabled; + return _tabbedSelectorSectionEnabled; } void setTabbedSelectorSectionEnabled(bool enabled); [[nodiscard]] bool thirdSectionInfoEnabled() const { - return _variables.thirdSectionInfoEnabled; + return _thirdSectionInfoEnabled; } void setThirdSectionInfoEnabled(bool enabled); [[nodiscard]] rpl::producer thirdSectionInfoEnabledValue() const; [[nodiscard]] int thirdSectionExtendedBy() const { - return _variables.thirdSectionExtendedBy; + return _thirdSectionExtendedBy; } void setThirdSectionExtendedBy(int savedValue) { - _variables.thirdSectionExtendedBy = savedValue; + _thirdSectionExtendedBy = savedValue; } [[nodiscard]] bool tabbedReplacedWithInfo() const { return _tabbedReplacedWithInfo; @@ -107,35 +83,22 @@ public: void setTabbedReplacedWithInfo(bool enabled); [[nodiscard]] rpl::producer tabbedReplacedWithInfoValue() const; void setSmallDialogsList(bool enabled) { - _variables.smallDialogsList = enabled; + _smallDialogsList = enabled; } [[nodiscard]] bool smallDialogsList() const { - return _variables.smallDialogsList; - } - void setSoundOverride(const QString &key, const QString &path) { - _variables.soundOverrides.emplace(key, path); - } - void clearSoundOverrides() { - _variables.soundOverrides.clear(); - } - [[nodiscard]] QString getSoundPath(const QString &key) const; - void setTabbedSelectorSectionTooltipShown(int shown) { - _variables.tabbedSelectorSectionTooltipShown = shown; - } - [[nodiscard]] int tabbedSelectorSectionTooltipShown() const { - return _variables.tabbedSelectorSectionTooltipShown; + return _smallDialogsList; } void setFloatPlayerColumn(Window::Column column) { - _variables.floatPlayerColumn = column; + _floatPlayerColumn = column; } [[nodiscard]] Window::Column floatPlayerColumn() const { - return _variables.floatPlayerColumn; + return _floatPlayerColumn; } void setFloatPlayerCorner(RectPart corner) { - _variables.floatPlayerCorner = corner; + _floatPlayerCorner = corner; } [[nodiscard]] RectPart floatPlayerCorner() const { - return _variables.floatPlayerCorner; + return _floatPlayerCorner; } void setDialogsWidthRatio(float64 ratio); [[nodiscard]] float64 dialogsWidthRatio() const; @@ -145,23 +108,23 @@ public: [[nodiscard]] rpl::producer thirdColumnWidthChanges() const; void setGroupStickersSectionHidden(PeerId peerId) { - _variables.groupStickersSectionHidden.insert(peerId); + _groupStickersSectionHidden.insert(peerId); } [[nodiscard]] bool isGroupStickersSectionHidden(PeerId peerId) const { - return _variables.groupStickersSectionHidden.contains(peerId); + return _groupStickersSectionHidden.contains(peerId); } void removeGroupStickersSectionHidden(PeerId peerId) { - _variables.groupStickersSectionHidden.remove(peerId); + _groupStickersSectionHidden.remove(peerId); } void setMediaLastPlaybackPosition(DocumentId id, crl::time time); [[nodiscard]] crl::time mediaLastPlaybackPosition(DocumentId id) const; [[nodiscard]] Data::AutoDownload::Full &autoDownload() { - return _variables.autoDownload; + return _autoDownload; } [[nodiscard]] const Data::AutoDownload::Full &autoDownload() const { - return _variables.autoDownload; + return _autoDownload; } void setArchiveCollapsed(bool collapsed); @@ -172,191 +135,71 @@ public: [[nodiscard]] bool archiveInMainMenu() const; [[nodiscard]] rpl::producer archiveInMainMenuChanges() const; - void setNotifyAboutPinned(bool notify); - [[nodiscard]] bool notifyAboutPinned() const; - [[nodiscard]] rpl::producer notifyAboutPinnedChanges() const; - void setSkipArchiveInSearch(bool skip); [[nodiscard]] bool skipArchiveInSearch() const; [[nodiscard]] rpl::producer skipArchiveInSearchChanges() const; [[nodiscard]] bool hadLegacyCallsPeerToPeerNobody() const { - return _variables.hadLegacyCallsPeerToPeerNobody; - } - - [[nodiscard]] bool includeMutedCounter() const { - return _variables.includeMutedCounter; - } - void setIncludeMutedCounter(bool value) { - _variables.includeMutedCounter = value; - } - [[nodiscard]] bool countUnreadMessages() const { - return _variables.countUnreadMessages; - } - void setCountUnreadMessages(bool value) { - _variables.countUnreadMessages = value; - } - [[nodiscard]] bool exeLaunchWarning() const { - return _variables.exeLaunchWarning; - } - void setExeLaunchWarning(bool warning) { - _variables.exeLaunchWarning = warning; - } - [[nodiscard]] bool loopAnimatedStickers() const { - return _variables.loopAnimatedStickers; - } - void setLoopAnimatedStickers(bool value) { - _variables.loopAnimatedStickers = value; - } - void setLargeEmoji(bool value); - [[nodiscard]] bool largeEmoji() const; - [[nodiscard]] rpl::producer largeEmojiValue() const; - [[nodiscard]] rpl::producer largeEmojiChanges() const; - void setReplaceEmoji(bool value); - [[nodiscard]] bool replaceEmoji() const; - [[nodiscard]] rpl::producer replaceEmojiValue() const; - [[nodiscard]] rpl::producer replaceEmojiChanges() const; - [[nodiscard]] bool suggestEmoji() const { - return _variables.suggestEmoji; - } - void setSuggestEmoji(bool value) { - _variables.suggestEmoji = value; - } - [[nodiscard]] bool suggestStickersByEmoji() const { - return _variables.suggestStickersByEmoji; - } - void setSuggestStickersByEmoji(bool value) { - _variables.suggestStickersByEmoji = value; - } - - void setSpellcheckerEnabled(bool value) { - _variables.spellcheckerEnabled = value; - } - bool spellcheckerEnabled() const { - return _variables.spellcheckerEnabled.current(); - } - rpl::producer spellcheckerEnabledValue() const { - return _variables.spellcheckerEnabled.value(); - } - rpl::producer spellcheckerEnabledChanges() const { - return _variables.spellcheckerEnabled.changes(); - } - - void setDictionariesEnabled(std::vector dictionaries) { - _variables.dictionariesEnabled = std::move(dictionaries); - } - - std::vector dictionariesEnabled() const { - return _variables.dictionariesEnabled.current(); - } - - rpl::producer> dictionariesEnabledChanges() const { - return _variables.dictionariesEnabled.changes(); - } - - void setAutoDownloadDictionaries(bool value) { - _variables.autoDownloadDictionaries = value; - } - bool autoDownloadDictionaries() const { - return _variables.autoDownloadDictionaries.current(); - } - rpl::producer autoDownloadDictionariesValue() const { - return _variables.autoDownloadDictionaries.value(); - } - rpl::producer autoDownloadDictionariesChanges() const { - return _variables.autoDownloadDictionaries.changes(); - } - - [[nodiscard]] float64 videoPlaybackSpeed() const { - return _variables.videoPlaybackSpeed.current(); - } - void setVideoPlaybackSpeed(float64 speed) { - _variables.videoPlaybackSpeed = speed; - } - [[nodiscard]] QByteArray videoPipGeometry() const { - return _variables.videoPipGeometry; - } - void setVideoPipGeometry(QByteArray geometry) { - _variables.videoPipGeometry = geometry; + return _hadLegacyCallsPeerToPeerNobody; } [[nodiscard]] MsgId hiddenPinnedMessageId(PeerId peerId) const { - const auto i = _variables.hiddenPinnedMessages.find(peerId); - return (i != end(_variables.hiddenPinnedMessages)) ? i->second : 0; + const auto i = _hiddenPinnedMessages.find(peerId); + return (i != end(_hiddenPinnedMessages)) ? i->second : 0; } void setHiddenPinnedMessageId(PeerId peerId, MsgId msgId) { if (msgId) { - _variables.hiddenPinnedMessages[peerId] = msgId; + _hiddenPinnedMessages[peerId] = msgId; } else { - _variables.hiddenPinnedMessages.remove(peerId); + _hiddenPinnedMessages.remove(peerId); } } + [[nodiscard]] bool dialogsFiltersEnabled() const { + return _dialogsFiltersEnabled; + } + void setDialogsFiltersEnabled(bool value) { + _dialogsFiltersEnabled = value; + } + [[nodiscard]] static bool ThirdColumnByDefault(); private: - struct Variables { - Variables(); + static constexpr auto kDefaultDialogsWidthRatio = 5. / 14; + static constexpr auto kDefaultBigDialogsWidthRatio = 0.275; + static constexpr auto kDefaultThirdColumnWidth = 0; + static constexpr auto kDefaultSupportChatsLimitSlice = 7 * 24 * 60 * 60; - static constexpr auto kDefaultDialogsWidthRatio = 5. / 14; - static constexpr auto kDefaultBigDialogsWidthRatio = 0.275; - static constexpr auto kDefaultThirdColumnWidth = 0; + ChatHelpers::SelectorTab _selectorTab; // per-window + bool _tabbedSelectorSectionEnabled = false; // per-window + Window::Column _floatPlayerColumn; // per-window + RectPart _floatPlayerCorner; // per-window + base::flat_set _groupStickersSectionHidden; + bool _thirdSectionInfoEnabled = true; // per-window + bool _smallDialogsList = false; // per-window + int _thirdSectionExtendedBy = -1; // per-window + rpl::variable _dialogsWidthRatio; // per-window + rpl::variable _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w + bool _hadLegacyCallsPeerToPeerNobody = false; + Data::AutoDownload::Full _autoDownload; + rpl::variable _archiveCollapsed = false; + rpl::variable _archiveInMainMenu = false; + rpl::variable _skipArchiveInSearch = false; + std::vector> _mediaLastPlaybackPosition; + base::flat_map _hiddenPinnedMessages; + bool _dialogsFiltersEnabled = false; - bool lastSeenWarningSeen = false; - SendFilesWay sendFilesWay; - ChatHelpers::SelectorTab selectorTab; // per-window - bool tabbedSelectorSectionEnabled = false; // per-window - int tabbedSelectorSectionTooltipShown = 0; - base::flat_map soundOverrides; - Window::Column floatPlayerColumn; // per-window - RectPart floatPlayerCorner; // per-window - base::flat_set groupStickersSectionHidden; - bool thirdSectionInfoEnabled = true; // per-window - bool smallDialogsList = false; // per-window - int thirdSectionExtendedBy = -1; // per-window - rpl::variable dialogsWidthRatio; // per-window - rpl::variable thirdColumnWidth - = kDefaultThirdColumnWidth; // per-window - Ui::InputSubmitSettings sendSubmitWay; - bool hadLegacyCallsPeerToPeerNobody = false; - bool includeMutedCounter = true; - bool countUnreadMessages = true; - bool exeLaunchWarning = true; - Data::AutoDownload::Full autoDownload; - rpl::variable archiveCollapsed = false; - rpl::variable archiveInMainMenu = false; - rpl::variable notifyAboutPinned = true; - rpl::variable skipArchiveInSearch = false; - bool loopAnimatedStickers = true; - rpl::variable largeEmoji = true; - rpl::variable replaceEmoji = true; - bool suggestEmoji = true; - bool suggestStickersByEmoji = true; - rpl::variable spellcheckerEnabled = true; - std::vector> mediaLastPlaybackPosition; - rpl::variable videoPlaybackSpeed = 1.; - QByteArray videoPipGeometry; - rpl::variable> dictionariesEnabled; - rpl::variable autoDownloadDictionaries = true; - base::flat_map hiddenPinnedMessages; - - static constexpr auto kDefaultSupportChatsLimitSlice - = 7 * 24 * 60 * 60; - - Support::SwitchSettings supportSwitch; - bool supportFixChatsOrder = true; - bool supportTemplatesAutocomplete = true; - rpl::variable supportChatsTimeSlice - = kDefaultSupportChatsLimitSlice; - rpl::variable supportAllSearchResults = false; - }; + Support::SwitchSettings _supportSwitch; + bool _supportFixChatsOrder = true; + bool _supportTemplatesAutocomplete = true; + rpl::variable _supportChatsTimeSlice + = kDefaultSupportChatsLimitSlice; + rpl::variable _supportAllSearchResults = false; rpl::event_stream _thirdSectionInfoEnabledValue; bool _tabbedReplacedWithInfo = false; rpl::event_stream _tabbedReplacedWithInfoValue; - Variables _variables; - }; } // namespace Main diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e1cda0e61..69758b310 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -872,7 +872,7 @@ bool MainWidget::insertBotCommand(const QString &cmd) { void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) { _dialogs->searchMessages(query, inChat); if (Adaptive::OneColumn()) { - Ui::showChatsList(); + Ui::showChatsList(&session()); } else { _dialogs->setInnerFocus(); } @@ -1353,8 +1353,10 @@ void MainWidget::viewsIncrementFail(const RPCError &error, mtpRequestId requestI void MainWidget::choosePeer(PeerId peerId, MsgId showAtMsgId) { if (selectingPeer()) { _hider->offerPeer(peerId); + } else if (peerId) { + Ui::showPeerHistory(session().data().peer(peerId), showAtMsgId); } else { - Ui::showPeerHistory(peerId, showAtMsgId); + Ui::showChatsList(&session()); } } @@ -2570,7 +2572,7 @@ void MainWidget::searchInChat(Dialogs::Key chat) { } _dialogs->searchInChat(chat); if (Adaptive::OneColumn()) { - Ui::showChatsList(); + Ui::showChatsList(&session()); } else { _dialogs->setInnerFocus(); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 403c6ad50..567153b14 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -133,7 +133,7 @@ void MainWindow::createTrayIconMenu() { trayIconMenu = new QMenu(this); #endif // else for Q_OS_WIN - auto notificationActionText = Global::DesktopNotify() + auto notificationActionText = Core::App().settings().desktopNotify() ? tr::lng_disable_notifications_from_tray(tr::now) : tr::lng_enable_notifications_from_tray(tr::now); @@ -620,7 +620,7 @@ void MainWindow::updateTrayMenu(bool force) { : tr::lng_open_from_tray(tr::now)); } auto notificationAction = actions.at(Platform::IsLinux() && !Platform::IsWayland() ? 2 : 1); - auto notificationActionText = Global::DesktopNotify() + auto notificationActionText = Core::App().settings().desktopNotify() ? tr::lng_disable_notifications_from_tray(tr::now) : tr::lng_enable_notifications_from_tray(tr::now); notificationAction->setText(notificationActionText); @@ -781,33 +781,35 @@ void MainWindow::toggleDisplayNotifyFromTray() { auto soundNotifyChanged = false; auto flashBounceNotifyChanged = false; - Global::SetDesktopNotify(!Global::DesktopNotify()); - if (Global::DesktopNotify()) { - if (Global::RestoreSoundNotifyFromTray() && !Global::SoundNotify()) { - Global::SetSoundNotify(true); - Global::SetRestoreSoundNotifyFromTray(false); + auto &settings = Core::App().settings(); + settings.setDesktopNotify(!settings.desktopNotify()); + if (settings.desktopNotify()) { + if (settings.rememberedSoundNotifyFromTray() + && !settings.soundNotify()) { + settings.setSoundNotify(true); + settings.setRememberedSoundNotifyFromTray(false); soundNotifyChanged = true; } - if (Global::RestoreFlashBounceNotifyFromTray() - && !Global::FlashBounceNotify()) { - Global::SetFlashBounceNotify(true); - Global::SetRestoreFlashBounceNotifyFromTray(false); + if (settings.rememberedFlashBounceNotifyFromTray() + && !settings.flashBounceNotify()) { + settings.setFlashBounceNotify(true); + settings.setRememberedFlashBounceNotifyFromTray(false); flashBounceNotifyChanged = true; } } else { - if (Global::SoundNotify()) { - Global::SetSoundNotify(false); - Global::SetRestoreSoundNotifyFromTray(true); + if (settings.soundNotify()) { + settings.setSoundNotify(false); + settings.setRememberedSoundNotifyFromTray(true); soundNotifyChanged = true; } else { - Global::SetRestoreSoundNotifyFromTray(false); + settings.setRememberedSoundNotifyFromTray(false); } - if (Global::FlashBounceNotify()) { - Global::SetFlashBounceNotify(false); - Global::SetRestoreFlashBounceNotifyFromTray(true); + if (settings.flashBounceNotify()) { + settings.setFlashBounceNotify(false); + settings.setRememberedFlashBounceNotifyFromTray(true); flashBounceNotifyChanged = true; } else { - Global::SetRestoreFlashBounceNotifyFromTray(false); + settings.setRememberedFlashBounceNotifyFromTray(false); } } account().session().saveSettings(); diff --git a/Telegram/SourceFiles/media/audio/media_audio.cpp b/Telegram/SourceFiles/media/audio/media_audio.cpp index 9a86955bd..473bf691c 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio.cpp @@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_audio.h" #include "core/application.h" #include "main/main_session.h" -#include "facades.h" #include "app.h" #include @@ -575,12 +574,17 @@ Mixer::Mixer(not_null instance) connect(this, SIGNAL(suppressSong()), _fader, SLOT(onSuppressSong())); connect(this, SIGNAL(unsuppressSong()), _fader, SLOT(onUnsuppressSong())); connect(this, SIGNAL(suppressAll(qint64)), _fader, SLOT(onSuppressAll(qint64))); - subscribe(Global::RefSongVolumeChanged(), [this] { + + Core::App().settings().songVolumeChanges( + ) | rpl::start_with_next([=] { QMetaObject::invokeMethod(_fader, "onSongVolumeChanged"); - }); - subscribe(Global::RefVideoVolumeChanged(), [this] { + }, _lifetime); + + Core::App().settings().videoVolumeChanges( + ) | rpl::start_with_next([=] { QMetaObject::invokeMethod(_fader, "onVideoVolumeChanged"); - }); + }, _lifetime); + connect(this, SIGNAL(loaderOnStart(const AudioMsgId&, qint64)), _loader, SLOT(onStart(const AudioMsgId&, qint64))); connect(this, SIGNAL(loaderOnCancel(const AudioMsgId&)), _loader, SLOT(onCancel(const AudioMsgId&))); connect(_loader, SIGNAL(needToCheck()), _fader, SLOT(onTimer())); @@ -756,8 +760,8 @@ void Mixer::play( Expects(externalData != nullptr); Expects(audio.externalPlayId() != 0); - setSongVolume(Global::SongVolume()); - setVideoVolume(Global::VideoVolume()); + setSongVolume(Core::App().settings().songVolume()); + setVideoVolume(Core::App().settings().videoVolume()); auto type = audio.type(); AudioMsgId stopped; diff --git a/Telegram/SourceFiles/media/audio/media_audio.h b/Telegram/SourceFiles/media/audio/media_audio.h index 83bbbb568..57bbaa01e 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.h +++ b/Telegram/SourceFiles/media/audio/media_audio.h @@ -126,7 +126,7 @@ struct TrackState { bool waitingForData = false; }; -class Mixer : public QObject, private base::Subscriber { +class Mixer final : public QObject { Q_OBJECT public: @@ -296,6 +296,8 @@ private: Fader *_fader; Loaders *_loader; + rpl::lifetime _lifetime; + }; Mixer *mixer(); diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index a793d1b86..7514e2084 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -23,11 +23,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "core/shortcuts.h" #include "core/application.h" -#include "main/main_accounts.h" // Accounts::activeSessionValue. +#include "main/main_domain.h" // Domain::activeSessionValue. #include "mainwindow.h" #include "main/main_session.h" #include "main/main_session_settings.h" -#include "facades.h" namespace Media { namespace Player { @@ -115,7 +114,7 @@ Instance::Instance() }); // While we have one Media::Player::Instance for all sessions we have to do this. - Core::App().accounts().activeSessionValue( + Core::App().domain().activeSessionValue( ) | rpl::start_with_next([=](Main::Session *session) { if (session) { subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) { @@ -449,7 +448,7 @@ Streaming::PlaybackOptions Instance::streamingOptions( : Streaming::Mode::Audio; result.speed = (document && (document->isVoiceMessage() || document->isVideoMessage()) - && Global::VoiceMsgPlaybackDoubled()) + && Core::App().settings().voiceMsgPlaybackDoubled()) ? kVoicePlaybackSpeedMultiplier : 1.; result.audioId = audioId; @@ -599,7 +598,7 @@ void Instance::cancelSeeking(AudioMsgId::Type type) { void Instance::updateVoicePlaybackSpeed() { if (const auto data = getData(AudioMsgId::Type::Voice)) { if (const auto streamed = data->streamed.get()) { - streamed->instance.setSpeed(Global::VoiceMsgPlaybackDoubled() + streamed->instance.setSpeed(Core::App().settings().voiceMsgPlaybackDoubled() ? kVoicePlaybackSpeedMultiplier : 1.); } diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp index 6ebfeb77c..135453ba5 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp @@ -16,7 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "main/main_session.h" #include "window/window_session_controller.h" -#include "facades.h" +#include "core/application.h" +#include "core/core_settings.h" #include "app.h" #include "styles/style_media_player.h" #include "styles/style_widgets.h" @@ -27,7 +28,7 @@ namespace Player { VolumeController::VolumeController( QWidget *parent, not_null controller) -: TWidget(parent) +: RpWidget(parent) , _slider(this, st::mediaPlayerPanelPlayback) { _slider->setMoveByWheel(true); _slider->setChangeProgressCallback([=](float64 volume) { @@ -35,17 +36,18 @@ VolumeController::VolumeController( }); _slider->setChangeFinishedCallback([=](float64 volume) { if (volume > 0) { - Global::SetRememberedSongVolume(volume); + Core::App().settings().setRememberedSongVolume(volume); } applyVolumeChange(volume); controller->session().saveSettingsDelayed(); }); - subscribe(Global::RefSongVolumeChanged(), [this] { + Core::App().settings().songVolumeChanges( + ) | rpl::start_with_next([=](float64 volume) { if (!_slider->isChanging()) { - _slider->setValue(Global::SongVolume()); + _slider->setValue(volume); } - }); - setVolume(Global::SongVolume()); + }, lifetime()); + setVolume(Core::App().settings().songVolume()); resize(st::mediaPlayerPanelVolumeWidth, 2 * st::mediaPlayerPanelPlaybackPadding + st::mediaPlayerPanelPlayback.width); } @@ -63,16 +65,15 @@ void VolumeController::resizeEvent(QResizeEvent *e) { void VolumeController::setVolume(float64 volume) { _slider->setValue(volume); if (volume > 0) { - Global::SetRememberedSongVolume(volume); + Core::App().settings().setRememberedSongVolume(volume); } applyVolumeChange(volume); } void VolumeController::applyVolumeChange(float64 volume) { - if (volume != Global::SongVolume()) { - Global::SetSongVolume(volume); - mixer()->setSongVolume(Global::SongVolume()); - Global::RefSongVolumeChanged().notify(); + if (volume != Core::App().settings().songVolume()) { + Core::App().settings().setSongVolume(volume); + mixer()->setSongVolume(Core::App().settings().songVolume()); } } diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.h b/Telegram/SourceFiles/media/player/media_player_volume_controller.h index f45223523..95ea84179 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.h +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.h @@ -25,7 +25,7 @@ class SessionController; namespace Media { namespace Player { -class VolumeController : public TWidget, private base::Subscriber { +class VolumeController : public Ui::RpWidget, private base::Subscriber { public: VolumeController( QWidget *parent, diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index c904233f7..0bc26ebf4 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_session.h" #include "data/data_peer.h" +#include "core/application.h" +#include "core/core_settings.h" #include "ui/widgets/labels.h" #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/shadow.h" @@ -126,11 +128,16 @@ Widget::Widget(QWidget *parent, not_null session) updateVolumeToggleIcon(); _volumeToggle->setClickedCallback([=] { - Global::SetSongVolume((Global::SongVolume() > 0) ? 0. : Global::RememberedSongVolume()); - mixer()->setSongVolume(Global::SongVolume()); - Global::RefSongVolumeChanged().notify(); + const auto volume = (Core::App().settings().songVolume() > 0) + ? 0. + : Core::App().settings().rememberedSongVolume(); + Core::App().settings().setSongVolume(volume); + mixer()->setSongVolume(volume); }); - subscribe(Global::RefSongVolumeChanged(), [this] { updateVolumeToggleIcon(); }); + Core::App().settings().songVolumeChanges( + ) | rpl::start_with_next([=] { + updateVolumeToggleIcon(); + }, lifetime()); updateRepeatTrackIcon(); _repeatTrack->setClickedCallback([=] { @@ -139,11 +146,11 @@ Widget::Widget(QWidget *parent, not_null session) updatePlaybackSpeedIcon(); _playbackSpeed->setClickedCallback([=] { - const auto doubled = !Global::VoiceMsgPlaybackDoubled(); - Global::SetVoiceMsgPlaybackDoubled(doubled); + const auto doubled = !Core::App().settings().voiceMsgPlaybackDoubled(); + Core::App().settings().setVoiceMsgPlaybackDoubled(doubled); instance()->updateVoicePlaybackSpeed(); updatePlaybackSpeedIcon(); - _session->saveSettings(); + Core::App().saveSettingsDelayed(); }); subscribe(instance()->repeatChangedNotifier(), [this](AudioMsgId::Type type) { @@ -178,7 +185,7 @@ Widget::Widget(QWidget *parent, not_null session) void Widget::updateVolumeToggleIcon() { auto icon = []() -> const style::icon * { - auto volume = Global::SongVolume(); + auto volume = Core::App().settings().songVolume(); if (volume > 0) { if (volume < 1 / 3.) { return &st::mediaPlayerVolumeIcon1; @@ -385,7 +392,7 @@ void Widget::updateRepeatTrackIcon() { } void Widget::updatePlaybackSpeedIcon() { - const auto doubled = Global::VoiceMsgPlaybackDoubled(); + const auto doubled = Core::App().settings().voiceMsgPlaybackDoubled(); const auto isDefaultSpeed = !doubled; _playbackSpeed->setIconOverride( isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIcon : nullptr, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index bc2842418..76cd24a4d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -49,7 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "base/unixtime.h" #include "main/main_account.h" -#include "main/main_accounts.h" // Accounts::activeSessionValue. +#include "main/main_domain.h" // Domain::activeSessionValue. #include "main/main_session.h" #include "main/main_session_settings.h" #include "layout.h" @@ -108,16 +108,16 @@ PipDelegate::PipDelegate(QWidget *parent, not_null session) } void PipDelegate::pipSaveGeometry(QByteArray geometry) { - _session->settings().setVideoPipGeometry(geometry); - _session->saveSettingsDelayed(); + Core::App().settings().setVideoPipGeometry(geometry); + Core::App().saveSettingsDelayed(); } QByteArray PipDelegate::pipLoadGeometry() { - return _session->settings().videoPipGeometry(); + return Core::App().settings().videoPipGeometry(); } float64 PipDelegate::pipPlaybackSpeed() { - return _session->settings().videoPlaybackSpeed(); + return Core::App().settings().videoPlaybackSpeed(); } QWidget *PipDelegate::pipParentWidget() { @@ -301,9 +301,9 @@ OverlayWidget::OverlayWidget() , _dropdownShowTimer(this) { subscribe(Lang::Current().updated(), [this] { refreshLang(); }); - _lastPositiveVolume = (Global::VideoVolume() > 0.) - ? Global::VideoVolume() - : Global::kDefaultVolume; + _lastPositiveVolume = (Core::App().settings().videoVolume() > 0.) + ? Core::App().settings().videoVolume() + : Core::Settings::kDefaultVolume; setWindowTitle(qsl("Media viewer")); @@ -320,7 +320,7 @@ OverlayWidget::OverlayWidget() connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); // While we have one mediaview for all sessions we have to do this. - Core::App().accounts().activeSessionValue( + Core::App().domain().activeSessionValue( ) | rpl::start_with_next([=](Main::Session *session) { if (!isHidden()) { close(); @@ -1157,7 +1157,7 @@ void OverlayWidget::showSaveMsgFile() { void OverlayWidget::updateMixerVideoVolume() const { if (_streamed) { - Player::mixer()->setVideoVolume(Global::VideoVolume()); + Player::mixer()->setVideoVolume(Core::App().settings().videoVolume()); } } @@ -1358,18 +1358,18 @@ void OverlayWidget::onDownload() { if (!_photo && !_document) { return; } - if (Global::AskDownloadPath()) { + if (Core::App().settings().askDownloadPath()) { return onSaveAs(); } QString path; const auto session = _photo ? &_photo->session() : &_document->session(); - if (Global::DownloadPath().isEmpty()) { + if (Core::App().settings().downloadPath().isEmpty()) { path = File::DefaultDownloadPath(session); - } else if (Global::DownloadPath() == qsl("tmp")) { + } else if (Core::App().settings().downloadPath() == qsl("tmp")) { path = cTempDir(); } else { - path = Global::DownloadPath(); + path = Core::App().settings().downloadPath(); } QString toName; if (_document) { @@ -2629,7 +2629,7 @@ void OverlayWidget::restartAtSeekPosition(crl::time position) { options.mode = Streaming::Mode::Video; options.loop = true; } else { - options.speed = _document->session().settings().videoPlaybackSpeed(); + options.speed = Core::App().settings().videoPlaybackSpeed(); if (_pip) { _pip = nullptr; } @@ -2664,25 +2664,24 @@ void OverlayWidget::playbackControlsSeekFinished(crl::time position) { } void OverlayWidget::playbackControlsVolumeChanged(float64 volume) { - Global::SetVideoVolume(volume); + Core::App().settings().setVideoVolume(volume); updateMixerVideoVolume(); - Global::RefVideoVolumeChanged().notify(); if (_document) { _document->session().saveSettingsDelayed(); } } float64 OverlayWidget::playbackControlsCurrentVolume() { - return Global::VideoVolume(); + return Core::App().settings().videoVolume(); } void OverlayWidget::playbackControlsVolumeToggled() { - const auto volume = Global::VideoVolume(); + const auto volume = Core::App().settings().videoVolume(); playbackControlsVolumeChanged(volume ? 0. : _lastPositiveVolume); } void OverlayWidget::playbackControlsVolumeChangeFinished() { - const auto volume = Global::VideoVolume(); + const auto volume = Core::App().settings().videoVolume(); if (volume > 0.) { _lastPositiveVolume = volume; } @@ -2692,8 +2691,8 @@ void OverlayWidget::playbackControlsSpeedChanged(float64 speed) { DEBUG_LOG(("Media playback speed: change to %1.").arg(speed)); if (_document) { DEBUG_LOG(("Media playback speed: %1 to settings.").arg(speed)); - _document->session().settings().setVideoPlaybackSpeed(speed); - _document->session().saveSettingsDelayed(); + Core::App().settings().setVideoPlaybackSpeed(speed); + Core::App().saveSettingsDelayed(); } if (_streamed && !videoIsGifv()) { DEBUG_LOG(("Media playback speed: %1 to _streamed.").arg(speed)); @@ -2702,12 +2701,8 @@ void OverlayWidget::playbackControlsSpeedChanged(float64 speed) { } float64 OverlayWidget::playbackControlsCurrentSpeed() { - const auto result = _document - ? _document->session().settings().videoPlaybackSpeed() - : 1.; - DEBUG_LOG(("Media playback speed: now %1 (doc %2)." - ).arg(result - ).arg(Logs::b(_document != nullptr))); + const auto result = Core::App().settings().videoPlaybackSpeed(); + DEBUG_LOG(("Media playback speed: now %1.").arg(result)); return result; } diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 1b6de5a6d..b2461cc10 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -855,7 +855,6 @@ void Instance::Private::configLoadDone(const MTPConfig &result) { if (const auto prefix = data.vautoupdate_url_prefix()) { Local::writeAutoupdatePrefix(qs(*prefix)); } - Local::writeSettings(); _configExpiresAt = crl::now() + (data.vexpires().v - base::unixtime::now()) * crl::time(1000); diff --git a/Telegram/SourceFiles/mtproto/special_config_request.cpp b/Telegram/SourceFiles/mtproto/special_config_request.cpp index ab8bd0c6a..0d99e881c 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.cpp +++ b/Telegram/SourceFiles/mtproto/special_config_request.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "base/openssl_help.h" #include "base/call_delayed.h" -#include "facades.h" #include #include diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index 01dcc27c3..fe81c30a4 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "base/platform/base_platform_file_utilities.h" #include "base/call_delayed.h" -#include "facades.h" #include #include diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 51ee31a92..ddb381bef 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -11,9 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION #include "base/platform/base_platform_info.h" #include "platform/linux/specific_linux.h" +#include "core/application.h" +#include "core/core_settings.h" #include "history/history.h" #include "lang/lang_keys.h" -#include "facades.h" #include #include @@ -71,7 +72,8 @@ void GetSupported() { } Checked = true; - if (Global::NativeNotifications() && !Platform::IsWayland()) { + if (Core::App().settings().nativeNotifications() + && !Platform::IsWayland()) { ComputeSupported(true); } else { ComputeSupported(); @@ -271,7 +273,7 @@ NotificationData::NotificationData( // suppress system sound if telegram sound activated, otherwise use system sound if (capabilities.contains(qsl("sound"))) { - if (Global::SoundNotify()) { + if (Core::App().settings().soundNotify()) { _hints["suppress-sound"] = true; } else { // sound name according to http://0pointer.de/public/sound-naming-spec.html @@ -475,7 +477,7 @@ std::unique_ptr Create( #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION GetSupported(); - if ((Global::NativeNotifications() && Supported()) + if ((Core::App().settings().nativeNotifications() && Supported()) || Platform::IsWayland()) { return std::make_unique(system); } diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 4a3f2ec62..f806ea53d 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_widget.h" #include "history/history_inner_widget.h" #include "main/main_account.h" -#include "main/main_accounts.h" // Accounts::activeSessionValue +#include "main/main_domain.h" // Domain::activeSessionValue #include "media/player/media_player_instance.h" #include "media/audio/media_audio.h" #include "storage/localstorage.h" @@ -196,7 +196,7 @@ private: } - (void) darkModeChanged:(NSNotification *)aNotification { - Core::App().accounts().notifyUnreadBadgeChanged(); + Core::App().domain().notifyUnreadBadgeChanged(); } - (void) screenIsLocked:(NSNotification *)aNotification { @@ -478,7 +478,7 @@ void MainWindow::initTouchBar() { return; } - Core::App().accounts().activeSessionValue( + Core::App().domain().activeSessionValue( ) | rpl::start_with_next([=](Main::Session *session) { if (session) { // We need only common pinned dialogs. diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index 1c24cb1d7..27f27a088 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "core/sandbox.h" #include "core/application.h" +#include "core/core_settings.h" #include "core/crash_reports.h" #include "storage/localstorage.h" #include "media/audio/media_audio.h" @@ -19,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "lang/lang_keys.h" #include "base/timer.h" -#include "facades.h" #include "styles/style_window.h" #include @@ -422,12 +422,12 @@ void objc_downloadPathEnableAccess(const QByteArray &bookmark) { } _downloadPathUrl = [url retain]; - Global::SetDownloadPath(NS2QString([_downloadPathUrl path]) + '/'); + Core::App().settings().setDownloadPath(NS2QString([_downloadPathUrl path]) + '/'); if (isStale) { NSData *data = [_downloadPathUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error]; if (data) { - Global::SetDownloadPathBookmark(QByteArray::fromNSData(data)); - Local::writeUserSettings(); + Core::App().settings().setDownloadPathBookmark(QByteArray::fromNSData(data)); + Local::writeSettings(); } } } diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 522a4ba92..3b3c0d5bc 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "window/themes/window_theme.h" #include "history/history.h" -#include "facades.h" #include "app.h" #include diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index bffb0bae7..a8febba65 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -12,8 +12,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/win/windows_event_filter.h" #include "platform/win/windows_dlls.h" #include "history/history.h" +#include "core/application.h" +#include "core/core_settings.h" #include "mainwindow.h" -#include "facades.h" #include #include @@ -323,7 +324,7 @@ bool Supported() { std::unique_ptr Create(Window::Notifications::System *system) { #ifndef __MINGW32__ - if (Global::NativeNotifications() && Supported()) { + if (Core::App().settings().nativeNotifications() && Supported()) { auto result = std::make_unique(system); if (result->init()) { return std::move(result); diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index ab0711376..066787347 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -92,7 +92,7 @@ void GroupMembersWidget::removePeer(PeerData *selectedPeer) { Ui::hideLayer(); if (const auto chat = peer->asChat()) { chat->session().api().kickParticipant(chat, user); - Ui::showPeerHistory(chat->id, ShowAtTheEndMsgId); + Ui::showPeerHistory(chat, ShowAtTheEndMsgId); } else if (const auto channel = peer->asChannel()) { channel->session().api().kickParticipant( channel, diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index c91978655..5cd4af457 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "main/main_account.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mtproto/facade.h" #include "layout.h" #include "facades.h" @@ -266,7 +265,7 @@ void SetupSpellchecker( not_null container) { #ifndef TDESKTOP_DISABLE_SPELLCHECK const auto session = &controller->session(); - const auto settings = &session->settings(); + const auto settings = &Core::App().settings(); const auto isSystem = Platform::Spellchecker::IsSystemSpellchecker(); const auto button = AddButton( container, @@ -283,7 +282,7 @@ void SetupSpellchecker( return (enabled != settings->spellcheckerEnabled()); }) | rpl::start_with_next([=](bool enabled) { settings->setSpellcheckerEnabled(enabled); - session->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); }, container->lifetime()); if (isSystem) { @@ -306,7 +305,7 @@ void SetupSpellchecker( return (enabled != settings->autoDownloadDictionaries()); }) | rpl::start_with_next([=](bool enabled) { settings->setAutoDownloadDictionaries(enabled); - session->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); }, sliding->entity()->lifetime()); AddButtonWithLabel( diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index a05bc8266..b5cf1d3c1 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_settings.h" #include "ui/widgets/continuous_sliders.h" #include "window/window_session_controller.h" +#include "core/application.h" +#include "core/core_settings.h" #include "calls/calls_instance.h" #include "facades.h" @@ -72,32 +74,33 @@ void Calls::setupContent() { return QString::fromStdString(device.displayName); }; + const auto &settings = Core::App().settings(); const auto currentOutputName = [&] { - if (Global::CallOutputDeviceID() == qsl("default")) { + if (settings.callOutputDeviceID() == qsl("default")) { return tr::lng_settings_call_device_default(tr::now); } const auto &list = VoIP::EnumerateAudioOutputs(); const auto i = ranges::find( list, - Global::CallOutputDeviceID(), + settings.callOutputDeviceID(), getId); return (i != end(list)) ? getName(*i) - : Global::CallOutputDeviceID(); + : settings.callOutputDeviceID(); }(); const auto currentInputName = [&] { - if (Global::CallInputDeviceID() == qsl("default")) { + if (settings.callInputDeviceID() == qsl("default")) { return tr::lng_settings_call_device_default(tr::now); } const auto &list = VoIP::EnumerateAudioInputs(); const auto i = ranges::find( list, - Global::CallInputDeviceID(), + settings.callInputDeviceID(), getId); return (i != end(list)) ? getName(*i) - : Global::CallInputDeviceID(); + : settings.callInputDeviceID(); }(); AddSkip(content); @@ -119,7 +122,7 @@ void Calls::setupContent() { ) | ranges::to_vector; const auto i = ranges::find( devices, - Global::CallOutputDeviceID(), + Core::App().settings().callOutputDeviceID(), getId); const auto currentOption = (i != end(devices)) ? int(i - begin(devices) + 1) @@ -129,7 +132,8 @@ void Calls::setupContent() { const auto deviceId = option ? devices[option - 1].id : "default"; - Global::SetCallOutputDeviceID(QString::fromStdString(deviceId)); + Core::App().settings().setCallOutputDeviceID( + QString::fromStdString(deviceId)); _controller->session().saveSettingsDelayed(); if (const auto call = _controller->session().calls().currentCall()) { call->setCurrentAudioDevice(false, deviceId); @@ -160,7 +164,7 @@ void Calls::setupContent() { const auto updateOutputVolume = [=](int value) { _needWriteSettings = true; updateOutputLabel(value); - Global::SetCallOutputVolume(value); + Core::App().settings().setCallOutputVolume(value); if (const auto call = _controller->session().calls().currentCall()) { call->setAudioVolume(false, value / 100.0f); } @@ -169,9 +173,9 @@ void Calls::setupContent() { outputSlider->setPseudoDiscrete( 201, [](int val) { return val; }, - Global::CallOutputVolume(), + settings.callOutputVolume(), updateOutputVolume); - updateOutputLabel(Global::CallOutputVolume()); + updateOutputLabel(Core::App().settings().callOutputVolume()); AddSkip(content); AddDivider(content); @@ -194,7 +198,7 @@ void Calls::setupContent() { ) | ranges::to_vector; const auto i = ranges::find( devices, - Global::CallInputDeviceID(), + Core::App().settings().callInputDeviceID(), getId); const auto currentOption = (i != end(devices)) ? int(i - begin(devices) + 1) @@ -204,7 +208,8 @@ void Calls::setupContent() { const auto deviceId = option ? devices[option - 1].id : "default"; - Global::SetCallInputDeviceID(QString::fromStdString(deviceId)); + Core::App().settings().setCallInputDeviceID( + QString::fromStdString(deviceId)); _controller->session().saveSettingsDelayed(); if (_micTester) { stopTestingMicrophone(); @@ -238,7 +243,7 @@ void Calls::setupContent() { const auto updateInputVolume = [=](int value) { _needWriteSettings = true; updateInputLabel(value); - Global::SetCallInputVolume(value); + Core::App().settings().setCallInputVolume(value); if (const auto call = _controller->session().calls().currentCall()) { call->setAudioVolume(true, value / 100.0f); } @@ -246,9 +251,9 @@ void Calls::setupContent() { inputSlider->resize(st::settingsAudioVolumeSlider.seekSize); inputSlider->setPseudoDiscrete(101, [](int val) { return val; }, - Global::CallInputVolume(), + settings.callInputVolume(), updateInputVolume); - updateInputLabel(Global::CallInputVolume()); + updateInputLabel(settings.callInputVolume()); AddButton( content, @@ -350,7 +355,7 @@ void Calls::startTestingMicrophone() { _micTestTextStream.fire(tr::lng_settings_call_stop_mic_test(tr::now)); _levelUpdateTimer.callEach(50); _micTester = std::make_unique( - Global::CallInputDeviceID().toStdString()); + Core::App().settings().callInputDeviceID().toStdString()); if (_micTester->Failed()) { stopTestingMicrophone(); Ui::show(Box(tr::lng_call_error_audio_io(tr::now))); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 4478b64fa..0c7b04c07 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -641,15 +641,6 @@ void ChooseFromFile( crl::guard(parent, callback)); } -QString DownloadPathText() { - if (Global::DownloadPath().isEmpty()) { - return tr::lng_download_path_default(tr::now); - } else if (Global::DownloadPath() == qsl("tmp")) { - return tr::lng_download_path_temp(tr::now); - } - return QDir::toNativeSeparators(Global::DownloadPath()); -} - void SetupStickersEmoji( not_null controller, not_null container) { @@ -686,42 +677,42 @@ void SetupStickersEmoji( add( tr::lng_settings_large_emoji(tr::now), - session->settings().largeEmoji(), + Core::App().settings().largeEmoji(), [=](bool checked) { - session->settings().setLargeEmoji(checked); - session->saveSettingsDelayed(); + Core::App().settings().setLargeEmoji(checked); + Core::App().saveSettingsDelayed(); }); add( tr::lng_settings_replace_emojis(tr::now), - session->settings().replaceEmoji(), + Core::App().settings().replaceEmoji(), [=](bool checked) { - session->settings().setReplaceEmoji(checked); - session->saveSettingsDelayed(); + Core::App().settings().setReplaceEmoji(checked); + Core::App().saveSettingsDelayed(); }); add( tr::lng_settings_suggest_emoji(tr::now), - session->settings().suggestEmoji(), + Core::App().settings().suggestEmoji(), [=](bool checked) { - session->settings().setSuggestEmoji(checked); - session->saveSettingsDelayed(); + Core::App().settings().setSuggestEmoji(checked); + Core::App().saveSettingsDelayed(); }); add( tr::lng_settings_suggest_by_emoji(tr::now), - session->settings().suggestStickersByEmoji(), + Core::App().settings().suggestStickersByEmoji(), [=](bool checked) { - session->settings().setSuggestStickersByEmoji(checked); - session->saveSettingsDelayed(); + Core::App().settings().setSuggestStickersByEmoji(checked); + Core::App().saveSettingsDelayed(); }); add( tr::lng_settings_loop_stickers(tr::now), - session->settings().loopAnimatedStickers(), + Core::App().settings().loopAnimatedStickers(), [=](bool checked) { - session->settings().setLoopAnimatedStickers(checked); - session->saveSettingsDelayed(); + Core::App().settings().setLoopAnimatedStickers(checked); + Core::App().saveSettingsDelayed(); }); AddButton( @@ -769,7 +760,7 @@ void SetupMessages( QMargins(0, skip, 0, skip))); const auto group = std::make_shared>( - controller->session().settings().sendSubmitWay()); + Core::App().settings().sendSubmitWay()); const auto add = [&](SendByType value, const QString &text) { inner->add( object_ptr>( @@ -790,9 +781,9 @@ void SetupMessages( : tr::lng_settings_send_ctrlenter(tr::now))); group->setChangedCallback([=](SendByType value) { - controller->session().settings().setSendSubmitWay(value); + Core::App().settings().setSendSubmitWay(value); + Core::App().saveSettingsDelayed(); controller->content()->ctrlEnterSubmitUpdated(); - controller->session().saveSettingsDelayed(); }); AddSkip(inner, st::settingsCheckboxesSkip); @@ -841,7 +832,7 @@ void SetupDataStorage( container, tr::lng_download_path_ask(), st::settingsButton - )->toggleOn(rpl::single(Global::AskDownloadPath())); + )->toggleOn(rpl::single(Core::App().settings().askDownloadPath())); #ifndef OS_WIN_STORE const auto showpath = Ui::CreateChild>(ask); @@ -852,12 +843,14 @@ void SetupDataStorage( container, tr::lng_download_path(), st::settingsButton))); - auto pathtext = rpl::single( - rpl::empty_value() - ) | rpl::then(base::ObservableViewer( - Global::RefDownloadPathChanged() - )) | rpl::map([] { - return DownloadPathText(); + auto pathtext = Core::App().settings().downloadPathValue( + ) | rpl::map([](const QString &text) { + if (text.isEmpty()) { + return tr::lng_download_path_default(tr::now); + } else if (text == qsl("tmp")) { + return tr::lng_download_path_temp(tr::now); + } + return QDir::toNativeSeparators(text); }); CreateRightLabel( path->entity(), @@ -872,10 +865,10 @@ void SetupDataStorage( ask->toggledValue( ) | rpl::filter([](bool checked) { - return (checked != Global::AskDownloadPath()); + return (checked != Core::App().settings().askDownloadPath()); }) | rpl::start_with_next([=](bool checked) { - Global::SetAskDownloadPath(checked); - controller->session().saveSettingsDelayed(); + Core::App().settings().setAskDownloadPath(checked); + Core::App().saveSettingsDelayed(); #ifndef OS_WIN_STORE showpath->fire_copy(!checked); @@ -951,7 +944,7 @@ void SetupChatBackground( object_ptr( inner, tr::lng_settings_adaptive_wide(tr::now), - Global::AdaptiveForWide(), + Core::App().settings().adaptiveForWide(), st::settingsCheckbox), st::settingsSendTypePadding)); @@ -981,9 +974,9 @@ void SetupChatBackground( adaptive->entity()->checkedChanges( ) | rpl::start_with_next([=](bool checked) { - Global::SetAdaptiveForWide(checked); + Core::App().settings().setAdaptiveForWide(checked); + Core::App().saveSettingsDelayed(); Adaptive::Changed().notify(); - controller->session().saveSettingsDelayed(); }, adaptive->lifetime()); } diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index aad82e0d8..f0a3fc972 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -13,9 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "data/data_session.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "main/main_account.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "boxes/confirm_box.h" #include "lang/lang_cloud_manager.h" #include "lang/lang_instance.h" @@ -30,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/audio/media_audio_track.h" #include "settings/settings_common.h" #include "api/api_updates.h" -#include "facades.h" namespace Settings { namespace { @@ -63,13 +61,10 @@ auto GenerateCodes() { Unexpected("Crashed in Settings!"); }); codes.emplace(qsl("moderate"), [](SessionController *window) { - if (!window) { - return; - } - auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?"); + auto text = Core::App().settings().moderateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?"); Ui::show(Box(text, [=] { - Global::SetModerateModeEnabled(!Global::ModerateModeEnabled()); - window->session().saveSettingsDelayed(); + Core::App().settings().setModerateModeEnabled(!Core::App().settings().moderateModeEnabled()); + Core::App().saveSettingsDelayed(); Ui::hideLayer(); })); }); @@ -97,7 +92,7 @@ auto GenerateCodes() { })); }); codes.emplace(qsl("endpoints"), [](SessionController *window) { - if (!Core::App().accounts().started()) { + if (!Core::App().domain().started()) { return; } const auto weak = window @@ -113,7 +108,7 @@ auto GenerateCodes() { if (const auto strong = weak.get()) { loadFor(strong); } else { - for (const auto &[index, account] : Core::App().accounts().list()) { + for (const auto &[index, account] : Core::App().domain().accounts()) { loadFor(account.get()); } } @@ -130,10 +125,10 @@ auto GenerateCodes() { crl::on_main(&Core::App(), [=] { if (window && !Core::App().locked() - && Core::App().accounts().started() - && Core::App().accounts().list().size() < 3) { - Core::App().accounts().activate( - Core::App().accounts().add(MTP::Environment::Production)); + && Core::App().domain().started() + && Core::App().domain().accounts().size() < 3) { + Core::App().domain().activate( + Core::App().domain().add(MTP::Environment::Production)); } }); }); @@ -142,10 +137,10 @@ auto GenerateCodes() { crl::on_main(&Core::App(), [=] { if (window && !Core::App().locked() - && Core::App().accounts().started() - && Core::App().accounts().list().size() < 3) { - Core::App().accounts().activate( - Core::App().accounts().add(MTP::Environment::Test)); + && Core::App().domain().started() + && Core::App().domain().accounts().size() < 3) { + Core::App().domain().activate( + Core::App().domain().add(MTP::Environment::Test)); } }); }); @@ -154,11 +149,11 @@ auto GenerateCodes() { codes.emplace(qsl("account%1").arg(i + 1), [=]( SessionController *window) { crl::on_main(&Core::App(), [=] { - const auto &list = Core::App().accounts().list(); + const auto &list = Core::App().domain().accounts(); const auto j = list.find(i); if (j != list.end() && !Core::App().locked()) { if (&Core::App().activeAccount() != j->second.get()) { - Core::App().accounts().activate(i); + Core::App().domain().activate(i); } } }); @@ -201,34 +196,27 @@ auto GenerateCodes() { }; for (auto &key : audioKeys) { codes.emplace(key, [=](SessionController *window) { - if (!window) { - return; - } - - const auto weak = base::make_weak(&window->session()); - FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, crl::guard(&window->session(), [=](const FileDialog::OpenResult &result) { - if (weak && !result.paths.isEmpty()) { + FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, [=](const FileDialog::OpenResult &result) { + if (!result.paths.isEmpty()) { auto track = Media::Audio::Current().createTrack(); track->fillFromFile(result.paths.front()); if (track->failed()) { Ui::show(Box( "Could not audio :( Errors in 'log.txt'.")); } else { - weak->settings().setSoundOverride( + Core::App().settings().setSoundOverride( key, result.paths.front()); - weak->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); } } - })); + }); }); } codes.emplace(qsl("sounds_reset"), [](SessionController *window) { - if (window) { - window->session().settings().clearSoundOverrides(); - window->session().saveSettingsDelayed(); - Ui::show(Box("All sound overrides were reset.")); - } + Core::App().settings().clearSoundOverrides(); + Core::App().saveSettingsDelayed(); + Ui::show(Box("All sound overrides were reset.")); }); return codes; diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 15270b3c2..476c6ba32 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -16,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/widgets/box_content_divider.h" #include "ui/special_buttons.h" +#include "core/application.h" +#include "core/core_settings.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "boxes/add_contact_box.h" #include "boxes/confirm_box.h" @@ -26,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "window/window_session_controller.h" #include "apiwrap.h" #include "core/file_utilities.h" @@ -397,7 +398,7 @@ BioManager SetupBio( QObject::connect(bio, &Ui::InputField::changed, updated); bio->setInstantReplaces(Ui::InstantReplaces::Default()); bio->setInstantReplacesEnabled( - self->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( container->window(), bio, diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 460ac7c86..e4f0281ed 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "main/main_session.h" +#include "main/main_session_settings.h" #include "main/main_account.h" #include "main/main_app_config.h" #include "apiwrap.h" @@ -117,7 +118,7 @@ void SetupSections( st::settingsSectionButton, &st::settingsIconFolders)))->setDuration(0); if (!controller->session().data().chatsFilters().list().empty() - || Global::DialogsFiltersEnabled()) { + || controller->session().settings().dialogsFiltersEnabled()) { slided->show(anim::type::instant); preload(); } else { diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index bf953e29f..d9390aa57 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "core/application.h" #include "main/main_session.h" -#include "main/main_session_settings.h" +#include "main/main_domain.h" #include "apiwrap.h" #include "facades.h" #include "app.h" @@ -38,8 +38,11 @@ namespace { constexpr auto kMaxNotificationsCount = 5; -int CurrentCount() { - return snap(Global::NotificationsCount(), 1, kMaxNotificationsCount); +[[nodiscard]] int CurrentCount() { + return snap( + Core::App().settings().notificationsCount(), + 1, + kMaxNotificationsCount); } using ChangeType = Window::Notifications::ChangeType; @@ -64,7 +67,7 @@ protected: int resizeGetHeight(int newWidth) override; private: - using ScreenCorner = Notify::ScreenCorner; + using ScreenCorner = Core::Settings::ScreenCorner; void setOverCorner(ScreenCorner corner); void clearOverCorner(); @@ -126,7 +129,7 @@ NotificationsCount::NotificationsCount( QWidget *parent, not_null controller) : _controller(controller) -, _chosenCorner(Global::NotificationsCorner()) +, _chosenCorner(Core::App().settings().notificationsCorner()) , _oldCount(CurrentCount()) { setMouseTracking(true); @@ -153,9 +156,9 @@ void NotificationsCount::paintEvent(QPaintEvent *e) { st::notificationsBoxMonitor.paint(p, contentLeft, monitorTop, width()); for (int corner = 0; corner != 4; ++corner) { - auto screenCorner = static_cast(corner); - auto isLeft = Notify::IsLeftCorner(screenCorner); - auto isTop = Notify::IsTopCorner(screenCorner); + auto screenCorner = static_cast(corner); + auto isLeft = Core::Settings::IsLeftCorner(screenCorner); + auto isTop = Core::Settings::IsTopCorner(screenCorner); auto sampleLeft = isLeft ? (screenRect.x() + st::notificationsSampleSkip) : (screenRect.x() + screenRect.width() - st::notificationsSampleSkip - st::notificationSampleSize.width()); auto sampleTop = isTop ? (screenRect.y() + st::notificationsSampleTopSkip) : (screenRect.y() + screenRect.height() - st::notificationsSampleBottomSkip - st::notificationSampleSize.height()); if (corner == static_cast(_chosenCorner)) { @@ -185,11 +188,11 @@ void NotificationsCount::setCount(int count) { _sampleOpacities[_oldCount + animatedDelta].start([this] { update(); }, from, to, st::notifyFastAnim); } - if (count != Global::NotificationsCount()) { - Global::SetNotificationsCount(count); + if (count != Core::App().settings().notificationsCount()) { + Core::App().settings().setNotificationsCount(count); + Core::App().saveSettingsDelayed(); _controller->session().notifications().settingsChanged().notify( ChangeType::MaxCount); - _controller->session().saveSettingsDelayed(); } } @@ -324,13 +327,13 @@ void NotificationsCount::mouseMoveEvent(QMouseEvent *e) { auto bottomRight = style::rtlrect(screenRect.x() + screenRect.width() - cornerWidth, screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); auto bottomLeft = style::rtlrect(screenRect.x(), screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); if (topLeft.contains(e->pos())) { - setOverCorner(Notify::ScreenCorner::TopLeft); + setOverCorner(ScreenCorner::TopLeft); } else if (topRight.contains(e->pos())) { - setOverCorner(Notify::ScreenCorner::TopRight); + setOverCorner(ScreenCorner::TopRight); } else if (bottomRight.contains(e->pos())) { - setOverCorner(Notify::ScreenCorner::BottomRight); + setOverCorner(ScreenCorner::BottomRight); } else if (bottomLeft.contains(e->pos())) { - setOverCorner(Notify::ScreenCorner::BottomLeft); + setOverCorner(ScreenCorner::BottomLeft); } else { clearOverCorner(); } @@ -340,7 +343,7 @@ void NotificationsCount::leaveEventHook(QEvent *e) { clearOverCorner(); } -void NotificationsCount::setOverCorner(Notify::ScreenCorner corner) { +void NotificationsCount::setOverCorner(ScreenCorner corner) { if (_isOverCorner) { if (corner == _overCorner) { return; @@ -366,8 +369,8 @@ void NotificationsCount::setOverCorner(Notify::ScreenCorner corner) { } if (samplesNeeded > samplesLeave) { auto r = psDesktopRect(); - auto isLeft = Notify::IsLeftCorner(_overCorner); - auto isTop = Notify::IsTopCorner(_overCorner); + auto isLeft = Core::Settings::IsLeftCorner(_overCorner); + auto isTop = Core::Settings::IsTopCorner(_overCorner); auto sampleLeft = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX); auto sampleTop = isTop ? (r.y() + st::notifyDeltaY) : (r.y() + r.height() - st::notifyDeltaY - st::notifyMinHeight); for (int i = samplesLeave; i != samplesNeeded; ++i) { @@ -412,11 +415,11 @@ void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) { _chosenCorner = _downCorner; update(); - if (_chosenCorner != Global::NotificationsCorner()) { - Global::SetNotificationsCorner(_chosenCorner); + if (_chosenCorner != Core::App().settings().notificationsCorner()) { + Core::App().settings().setNotificationsCorner(_chosenCorner); + Core::App().saveSettingsDelayed(); _controller->session().notifications().settingsChanged().notify( ChangeType::Corner); - _controller->session().saveSettingsDelayed(); } } } @@ -562,25 +565,26 @@ void SetupNotificationsContent( checkbox(label, checked), st::settingsCheckboxPadding)); }; + const auto &settings = Core::App().settings(); const auto desktop = addCheckbox( tr::lng_settings_desktop_notify(tr::now), - Global::DesktopNotify()); + settings.desktopNotify()); const auto name = addSlidingCheckbox( tr::lng_settings_show_name(tr::now), - (Global::NotifyView() <= dbinvShowName)); + (settings.notifyView() <= dbinvShowName)); const auto preview = addSlidingCheckbox( tr::lng_settings_show_preview(tr::now), - (Global::NotifyView() <= dbinvShowPreview)); + (settings.notifyView() <= dbinvShowPreview)); const auto sound = addCheckbox( tr::lng_settings_sound_notify(tr::now), - Global::SoundNotify()); + settings.soundNotify()); const auto flashbounce = addCheckbox( (Platform::IsWindows() ? tr::lng_settings_alert_windows : Platform::IsMac() ? tr::lng_settings_alert_mac : tr::lng_settings_alert_linux)(tr::now), - Global::FlashBounceNotify()); + settings.flashBounceNotify()); AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); @@ -589,10 +593,10 @@ void SetupNotificationsContent( const auto muted = addCheckbox( tr::lng_settings_include_muted(tr::now), - session->settings().includeMutedCounter()); + settings.includeMutedCounter()); const auto count = addCheckbox( tr::lng_settings_count_unread(tr::now), - session->settings().countUnreadMessages()); + settings.countUnreadMessages()); AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); @@ -616,17 +620,17 @@ void SetupNotificationsContent( const auto pinned = addCheckbox( tr::lng_settings_events_pinned(tr::now), - session->settings().notifyAboutPinned()); - session->settings().notifyAboutPinnedChanges( + settings.notifyAboutPinned()); + settings.notifyAboutPinnedChanges( ) | rpl::start_with_next([=](bool notify) { pinned->setChecked(notify); }, pinned->lifetime()); pinned->checkedChanges( ) | rpl::filter([=](bool notify) { - return (notify != session->settings().notifyAboutPinned()); + return (notify != Core::App().settings().notifyAboutPinned()); }) | rpl::start_with_next([=](bool notify) { - session->settings().setNotifyAboutPinned(notify); - session->saveSettingsDelayed(); + Core::App().settings().setNotifyAboutPinned(notify); + Core::App().saveSettingsDelayed(); }, joined->lifetime()); const auto nativeText = [&] { @@ -648,7 +652,7 @@ void SetupNotificationsContent( AddDivider(container); AddSkip(container, st::settingsCheckboxesSkip); AddSubsectionTitle(container, tr::lng_settings_native_title()); - return addCheckbox(nativeText, Global::NativeNotifications()); + return addCheckbox(nativeText, settings.nativeNotifications()); }(); const auto advancedSlide = !Platform::IsMac10_8OrGreater() @@ -674,20 +678,20 @@ void SetupNotificationsContent( name->hide(anim::type::instant); preview->hide(anim::type::instant); } - if (native && advancedSlide && Global::NativeNotifications()) { + if (native && advancedSlide && settings.nativeNotifications()) { advancedSlide->hide(anim::type::instant); } using Change = Window::Notifications::ChangeType; const auto changed = [=](Change change) { - session->saveSettingsDelayed(); + Core::App().saveSettingsDelayed(); session->notifications().settingsChanged().notify(change); }; desktop->checkedChanges( ) | rpl::filter([](bool checked) { - return (checked != Global::DesktopNotify()); + return (checked != Core::App().settings().desktopNotify()); }) | rpl::start_with_next([=](bool checked) { - Global::SetDesktopNotify(checked); + Core::App().settings().setDesktopNotify(checked); changed(Change::DesktopEnabled); }, desktop->lifetime()); @@ -700,9 +704,9 @@ void SetupNotificationsContent( } return dbinvShowPreview; }) | rpl::filter([=](DBINotifyView value) { - return (value != Global::NotifyView()); + return (value != Core::App().settings().notifyView()); }) | rpl::start_with_next([=](DBINotifyView value) { - Global::SetNotifyView(value); + Core::App().settings().setNotifyView(value); changed(Change::ViewParams); }, name->lifetime()); @@ -715,41 +719,41 @@ void SetupNotificationsContent( } return dbinvShowNothing; }) | rpl::filter([=](DBINotifyView value) { - return (value != Global::NotifyView()); + return (value != Core::App().settings().notifyView()); }) | rpl::start_with_next([=](DBINotifyView value) { - Global::SetNotifyView(value); + Core::App().settings().setNotifyView(value); changed(Change::ViewParams); }, preview->lifetime()); sound->checkedChanges( ) | rpl::filter([](bool checked) { - return (checked != Global::SoundNotify()); + return (checked != Core::App().settings().soundNotify()); }) | rpl::start_with_next([=](bool checked) { - Global::SetSoundNotify(checked); + Core::App().settings().setSoundNotify(checked); changed(Change::SoundEnabled); }, sound->lifetime()); flashbounce->checkedChanges( ) | rpl::filter([](bool checked) { - return (checked != Global::FlashBounceNotify()); + return (checked != Core::App().settings().flashBounceNotify()); }) | rpl::start_with_next([=](bool checked) { - Global::SetFlashBounceNotify(checked); + Core::App().settings().setFlashBounceNotify(checked); changed(Change::FlashBounceEnabled); }, flashbounce->lifetime()); muted->checkedChanges( ) | rpl::filter([=](bool checked) { - return (checked != session->settings().includeMutedCounter()); + return (checked != Core::App().settings().includeMutedCounter()); }) | rpl::start_with_next([=](bool checked) { - session->settings().setIncludeMutedCounter(checked); + Core::App().settings().setIncludeMutedCounter(checked); changed(Change::IncludeMuted); }, muted->lifetime()); count->checkedChanges( ) | rpl::filter([=](bool checked) { - return (checked != session->settings().countUnreadMessages()); + return (checked != Core::App().settings().countUnreadMessages()); }) | rpl::start_with_next([=](bool checked) { - session->settings().setCountUnreadMessages(checked); + Core::App().settings().setCountUnreadMessages(checked); changed(Change::CountMessages); }, count->lifetime()); @@ -757,32 +761,35 @@ void SetupNotificationsContent( session->notifications().settingsChanged() ) | rpl::start_with_next([=](Change change) { if (change == Change::DesktopEnabled) { - desktop->setChecked(Global::DesktopNotify()); - name->toggle(Global::DesktopNotify(), anim::type::normal); + desktop->setChecked(Core::App().settings().desktopNotify()); + name->toggle( + Core::App().settings().desktopNotify(), + anim::type::normal); preview->toggle( - Global::DesktopNotify() && name->entity()->checked(), + (Core::App().settings().desktopNotify() + && name->entity()->checked()), anim::type::normal); } else if (change == Change::ViewParams) { preview->toggle(name->entity()->checked(), anim::type::normal); } else if (change == Change::SoundEnabled) { - sound->setChecked(Global::SoundNotify()); + sound->setChecked(Core::App().settings().soundNotify()); } else if (change == Change::FlashBounceEnabled) { - flashbounce->setChecked(Global::FlashBounceNotify()); + flashbounce->setChecked(Core::App().settings().flashBounceNotify()); } }, desktop->lifetime()); if (native) { native->checkedChanges( ) | rpl::filter([](bool checked) { - return (checked != Global::NativeNotifications()); + return (checked != Core::App().settings().nativeNotifications()); }) | rpl::start_with_next([=](bool checked) { - Global::SetNativeNotifications(checked); - session->saveSettingsDelayed(); + Core::App().settings().setNativeNotifications(checked); + Core::App().saveSettingsDelayed(); session->notifications().createManager(); if (advancedSlide) { advancedSlide->toggle( - !Global::NativeNotifications(), + !Core::App().settings().nativeNotifications(), anim::type::normal); } }, native->lifetime()); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index f7ea9bda7..ab08a5789 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -12,10 +12,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "mainwidget.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "data/data_user.h" #include "data/data_session.h" #include "data/data_changes.h" +#include "core/application.h" +#include "core/core_settings.h" #include "history/admin_log/history_admin_log_item.h" #include "history/view/history_view_element.h" #include "history/view/history_view_message.h" @@ -252,8 +253,8 @@ void BlockedBoxController::loadMoreRows() { void BlockedBoxController::rowClicked(not_null row) { const auto peer = row->peer(); - crl::on_main(&peer->session(), [peerId = peer->id] { - Ui::showPeerHistory(peerId, ShowAtUnreadMsgId); + crl::on_main(&peer->session(), [=] { + Ui::showPeerHistory(peer, ShowAtUnreadMsgId); }); } @@ -511,7 +512,7 @@ rpl::producer LastSeenPrivacyController::exceptionsDescription() { void LastSeenPrivacyController::confirmSave( bool someAreDisallowed, FnMut saveCallback) { - if (someAreDisallowed && !_session->settings().lastSeenWarningSeen()) { + if (someAreDisallowed && !Core::App().settings().lastSeenWarningSeen()) { const auto session = _session; auto weakBox = std::make_shared>(); auto callback = [=, saveCallback = std::move(saveCallback)]() mutable { @@ -519,8 +520,8 @@ void LastSeenPrivacyController::confirmSave( box->closeBox(); } saveCallback(); - session->settings().setLastSeenWarningSeen(true); - session->saveSettingsDelayed(); + Core::App().settings().setLastSeenWarningSeen(true); + Core::App().saveSettingsDelayed(); }; auto box = Box( tr::lng_edit_privacy_lastseen_warning(tr::now), diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 24bc5bdaa..2321c206e 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/sessions_box.h" #include "boxes/confirm_box.h" #include "boxes/self_destruction_box.h" +#include "core/application.h" +#include "core/core_settings.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/fade_wrap.h" @@ -238,7 +240,7 @@ void SetupLocalPasscode( : tr::lng_passcode_autolock_inactive; auto value = PasscodeChanges( ) | rpl::map([] { - const auto autolock = Global::AutoLock(); + const auto autolock = Core::App().settings().autoLock(); return (autolock % 3600) ? tr::lng_passcode_autolock_minutes(tr::now, lt_count, autolock / 60) : tr::lng_passcode_autolock_hours(tr::now, lt_count, autolock / 3600); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index ce5962b9a..72637b07e 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -85,7 +85,7 @@ bool ReadSetting( stream >> serialized; if (!CheckStreamStatus(stream)) return false; - Core::App().settings().constructFromSerialized(serialized); + Core::App().settings().addFromSerialized(serialized); } break; case dbiChatSizeMaxOld: { @@ -234,13 +234,13 @@ bool ReadSetting( anim::SetDisabled(disabled == 1); } break; - case dbiSoundFlashBounceNotify: { + case dbiSoundFlashBounceNotifyOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetSoundNotify((v & 0x01) == 0x01); - Global::SetFlashBounceNotify((v & 0x02) == 0x00); + Core::App().settings().setSoundNotify((v & 0x01) == 0x01); + Core::App().settings().setFlashBounceNotify((v & 0x02) == 0x00); } break; case dbiAutoDownloadOld: { @@ -302,20 +302,20 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) return false; } break; - case dbiDialogsFilters: { + case dbiDialogsFiltersOld: { qint32 enabled; stream >> enabled; if (!CheckStreamStatus(stream)) return false; - Global::SetDialogsFiltersEnabled(enabled == 1); + context.sessionSettings().setDialogsFiltersEnabled(enabled == 1); } break; - case dbiModerateMode: { + case dbiModerateModeOld: { qint32 enabled; stream >> enabled; if (!CheckStreamStatus(stream)) return false; - Global::SetModerateModeEnabled(enabled == 1); + Core::App().settings().setModerateModeEnabled(enabled == 1); } break; case dbiIncludeMutedOld: { @@ -323,7 +323,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setIncludeMutedCounter(v == 1); + Core::App().settings().setIncludeMutedCounter(v == 1); } break; case dbiShowingSavedGifsOld: { @@ -332,12 +332,12 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) return false; } break; - case dbiDesktopNotify: { + case dbiDesktopNotifyOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetDesktopNotify(v == 1); + Core::App().settings().setDesktopNotify(v == 1); } break; case dbiWindowsNotificationsOld: { @@ -346,28 +346,28 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) return false; } break; - case dbiNativeNotifications: { + case dbiNativeNotificationsOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetNativeNotifications(v == 1); + Core::App().settings().setNativeNotifications(v == 1); } break; - case dbiNotificationsCount: { + case dbiNotificationsCountOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetNotificationsCount((v > 0 ? v : 3)); + Core::App().settings().setNotificationsCount((v > 0 ? v : 3)); } break; - case dbiNotificationsCorner: { + case dbiNotificationsCornerOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetNotificationsCorner(static_cast((v >= 0 && v < 4) ? v : 2)); + Core::App().settings().setNotificationsCorner(static_cast((v >= 0 && v < 4) ? v : 2)); } break; case dbiDialogsWidthRatioOld: { @@ -383,7 +383,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setLastSeenWarningSeen(v == 1); + Core::App().settings().setLastSeenWarningSeen(v == 1); } break; case dbiSessionSettings: { @@ -391,8 +391,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettingsStorage - = Main::SessionSettings::FromSerialized(v); + context.sessionSettings().addFromSerialized(v); } break; case dbiWorkMode: { @@ -720,7 +719,7 @@ bool ReadSetting( && unchecked != SendSettings::CtrlEnter) { return false; } - context.sessionSettings().setSendSubmitWay(unchecked); + Core::App().settings().setSendSubmitWay(unchecked); } break; case dbiCatsAndDogs: { // deprecated @@ -753,20 +752,20 @@ bool ReadSetting( context.tileNight = (tileNight == 1); } break; - case dbiAdaptiveForWide: { + case dbiAdaptiveForWideOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetAdaptiveForWide(v == 1); + Core::App().settings().setAdaptiveForWide(v == 1); } break; - case dbiAutoLock: { + case dbiAutoLockOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetAutoLock(v); + Core::App().settings().setAutoLock(v); Global::RefLocalPasscodeChanged().notify(); } break; @@ -775,7 +774,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setReplaceEmoji(v == 1); + Core::App().settings().setReplaceEmoji(v == 1); } break; case dbiSuggestEmojiOld: { @@ -783,7 +782,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setSuggestEmoji(v == 1); + Core::App().settings().setSuggestEmoji(v == 1); } break; case dbiSuggestStickersByEmojiOld: { @@ -791,7 +790,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setSuggestStickersByEmoji(v == 1); + Core::App().settings().setSuggestStickersByEmoji(v == 1); } break; case dbiDefaultAttach: { @@ -800,39 +799,38 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) return false; } break; - case dbiNotifyView: { + case dbiNotifyViewOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; switch (v) { - case dbinvShowNothing: Global::SetNotifyView(dbinvShowNothing); break; - case dbinvShowName: Global::SetNotifyView(dbinvShowName); break; - default: Global::SetNotifyView(dbinvShowPreview); break; + case dbinvShowNothing: Core::App().settings().setNotifyView(dbinvShowNothing); break; + case dbinvShowName: Core::App().settings().setNotifyView(dbinvShowName); break; + default: Core::App().settings().setNotifyView(dbinvShowPreview); break; } } break; - case dbiAskDownloadPath: { + case dbiAskDownloadPathOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetAskDownloadPath(v == 1); + Core::App().settings().setAskDownloadPath(v == 1); } break; - case dbiDownloadPathOld: { + case dbiDownloadPathOldOld: { QString v; stream >> v; if (!CheckStreamStatus(stream)) return false; #ifndef OS_WIN_STORE if (!v.isEmpty() && v != qstr("tmp") && !v.endsWith('/')) v += '/'; - Global::SetDownloadPath(v); - Global::SetDownloadPathBookmark(QByteArray()); - Global::RefDownloadPathChanged().notify(); + Core::App().settings().setDownloadPathBookmark(QByteArray()); + Core::App().settings().setDownloadPath(v); #endif // OS_WIN_STORE } break; - case dbiDownloadPath: { + case dbiDownloadPathOld: { QString v; QByteArray bookmark; stream >> v >> bookmark; @@ -840,19 +838,18 @@ bool ReadSetting( #ifndef OS_WIN_STORE if (!v.isEmpty() && v != qstr("tmp") && !v.endsWith('/')) v += '/'; - Global::SetDownloadPath(v); - Global::SetDownloadPathBookmark(bookmark); + Core::App().settings().setDownloadPathBookmark(bookmark); + Core::App().settings().setDownloadPath(v); psDownloadPathEnableAccess(); - Global::RefDownloadPathChanged().notify(); #endif // OS_WIN_STORE } break; - case dbiCompressPastedImage: { + case dbiCompressPastedImageOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setSendFilesWay((v == 1) + Core::App().settings().setSendFilesWay((v == 1) ? SendFilesWay::Album : SendFilesWay::Files); } break; @@ -976,36 +973,56 @@ bool ReadSetting( cSetDialogLastPath(path); } break; - case dbiSongVolume: { + case dbiSongVolumeOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetSongVolume(snap(v / 1e6, 0., 1.)); + Core::App().settings().setSongVolume(snap(v / 1e6, 0., 1.)); } break; - case dbiVideoVolume: { + case dbiVideoVolumeOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetVideoVolume(snap(v / 1e6, 0., 1.)); + Core::App().settings().setVideoVolume(snap(v / 1e6, 0., 1.)); } break; - case dbiPlaybackSpeed: { + case dbiPlaybackSpeedOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - Global::SetVoiceMsgPlaybackDoubled(v == 2); + Core::App().settings().setVoiceMsgPlaybackDoubled(v == 2); } break; - case dbiCallSettings: { + case dbiCallSettingsOld: { QByteArray callSettings; stream >> callSettings; if (!CheckStreamStatus(stream)) return false; - context.callSettings = callSettings; + QDataStream settingsStream(&callSettings, QIODevice::ReadOnly); + settingsStream.setVersion(QDataStream::Qt_5_1); + QString outputDeviceID; + QString inputDeviceID; + qint32 outputVolume; + qint32 inputVolume; + qint32 duckingEnabled; + + settingsStream >> outputDeviceID; + settingsStream >> outputVolume; + settingsStream >> inputDeviceID; + settingsStream >> inputVolume; + settingsStream >> duckingEnabled; + if (CheckStreamStatus(settingsStream)) { + auto &app = Core::App().settings(); + app.setCallOutputDeviceID(outputDeviceID); + app.setCallOutputVolume(outputVolume); + app.setCallInputDeviceID(inputDeviceID); + app.setCallInputVolume(inputVolume); + app.setCallAudioDuckingEnabled(duckingEnabled); + } } break; case dbiFallbackProductionConfig: { diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index 60024db73..44e425543 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -54,8 +54,6 @@ struct ReadSettingsContext { FileKey langPackKey = 0; FileKey languagesKey = 0; - QByteArray callSettings; - QByteArray mtpAuthorization; std::vector> mtpLegacyKeys; qint32 mtpLegacyMainDcId = 0; @@ -82,10 +80,10 @@ enum { dbiSendKeyOld = 0x05, dbiAutoStart = 0x06, dbiStartMinimized = 0x07, - dbiSoundFlashBounceNotify = 0x08, + dbiSoundFlashBounceNotifyOld = 0x08, dbiWorkMode = 0x09, dbiSeenTrayTooltip = 0x0a, - dbiDesktopNotify = 0x0b, + dbiDesktopNotifyOld = 0x0b, dbiAutoUpdate = 0x0c, dbiLastUpdateCheck = 0x0d, dbiWindowPosition = 0x0e, @@ -94,47 +92,47 @@ enum { dbiDefaultAttach = 0x11, dbiCatsAndDogs = 0x12, dbiReplaceEmojiOld = 0x13, - dbiAskDownloadPath = 0x14, - dbiDownloadPathOld = 0x15, + dbiAskDownloadPathOld = 0x14, + dbiDownloadPathOldOld = 0x15, dbiScaleOld = 0x16, dbiEmojiTabOld = 0x17, dbiRecentEmojiOldOld = 0x18, dbiLoggedPhoneNumberOld = 0x19, dbiMutedPeersOld = 0x1a, // 0x1b reserved - dbiNotifyView = 0x1c, + dbiNotifyViewOld = 0x1c, dbiSendToMenu = 0x1d, - dbiCompressPastedImage = 0x1e, + dbiCompressPastedImageOld = 0x1e, dbiLangOld = 0x1f, dbiLangFileOld = 0x20, dbiTileBackgroundOld = 0x21, - dbiAutoLock = 0x22, + dbiAutoLockOld = 0x22, dbiDialogLastPath = 0x23, dbiRecentEmojiOld = 0x24, dbiEmojiVariantsOld = 0x25, dbiRecentStickers = 0x26, dbiDcOptionOld = 0x27, dbiTryIPv6 = 0x28, - dbiSongVolume = 0x29, + dbiSongVolumeOld = 0x29, dbiWindowsNotificationsOld = 0x30, dbiIncludeMutedOld = 0x31, dbiMegagroupSizeMaxOld = 0x32, - dbiDownloadPath = 0x33, + dbiDownloadPathOld = 0x33, dbiAutoDownloadOld = 0x34, dbiSavedGifsLimitOld = 0x35, dbiShowingSavedGifsOld = 0x36, dbiAutoPlayOld = 0x37, - dbiAdaptiveForWide = 0x38, + dbiAdaptiveForWideOld = 0x38, dbiHiddenPinnedMessagesOld = 0x39, dbiRecentEmoji = 0x3a, dbiEmojiVariants = 0x3b, dbiDialogsModeOld = 0x40, - dbiModerateMode = 0x41, - dbiVideoVolume = 0x42, + dbiModerateModeOld = 0x41, + dbiVideoVolumeOld = 0x42, dbiStickersRecentLimitOld = 0x43, - dbiNativeNotifications = 0x44, - dbiNotificationsCount = 0x45, - dbiNotificationsCorner = 0x46, + dbiNativeNotificationsOld = 0x44, + dbiNotificationsCountOld = 0x45, + dbiNotificationsCornerOld = 0x46, dbiThemeKeyOld = 0x47, dbiDialogsWidthRatioOld = 0x48, dbiUseExternalVideoPlayer = 0x49, @@ -153,13 +151,13 @@ enum { dbiCacheSettingsOld = 0x56, dbiAnimationsDisabled = 0x57, dbiScalePercent = 0x58, - dbiPlaybackSpeed = 0x59, + dbiPlaybackSpeedOld = 0x59, dbiLanguagesKey = 0x5a, - dbiCallSettings = 0x5b, + dbiCallSettingsOld = 0x5b, dbiCacheSettings = 0x5c, dbiTxtDomainStringOld = 0x5d, dbiApplicationSettings = 0x5e, - dbiDialogsFilters = 0x5f, + dbiDialogsFiltersOld = 0x5f, dbiFallbackProductionConfig = 0x60, dbiEncryptedWithSalt = 333, diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index f5a056b01..d78a8ab36 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "base/bytes.h" #include "base/openssl_help.h" -#include "facades.h" #include "app.h" namespace { diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 9d88cd77e..97fd4279c 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -21,7 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtproto_config.h" #include "mtproto/mtproto_dc_options.h" #include "core/application.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_account.h" #include "main/main_session.h" #include "window/themes/window_theme.h" @@ -98,15 +98,15 @@ bool CheckStreamStatus(QDataStream &stream) { : nullptr; }; const auto &app = Core::App(); - const auto &accounts = app.accounts(); + const auto &domain = app.domain(); const auto production = MTP::Environment::Production; - if (!accounts.started()) { + if (!domain.started()) { return app.fallbackProductionConfig(); } if (const auto result = lookupConfig(&app.activeAccount())) { return *result; } - for (const auto &[_, account] : accounts.list()) { + for (const auto &[_, account] : domain.accounts()) { if (const auto result = lookupConfig(account.get())) { return *result; } diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 56c92503a..904b455ed 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_account.h" #include "storage/localstorage.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "storage/storage_encryption.h" #include "storage/storage_clear_legacy.h" #include "storage/cache/storage_cache_types.h" @@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_drafts.h" #include "export/export_settings.h" #include "window/themes/window_theme.h" -#include "facades.h" namespace Storage { namespace { @@ -708,43 +707,6 @@ void Account::readLocations() { } } -QByteArray Account::serializeCallSettings() { - QByteArray result = QByteArray(); - uint32 size = 3 * sizeof(qint32) + Serialize::stringSize(Global::CallOutputDeviceID()) + Serialize::stringSize(Global::CallInputDeviceID()); - result.reserve(size); - QDataStream stream(&result, QIODevice::WriteOnly); - stream.setVersion(QDataStream::Qt_5_1); - stream << Global::CallOutputDeviceID(); - stream << qint32(Global::CallOutputVolume()); - stream << Global::CallInputDeviceID(); - stream << qint32(Global::CallInputVolume()); - stream << qint32(Global::CallAudioDuckingEnabled() ? 1 : 0); - return result; -} - -void Account::deserializeCallSettings(QByteArray &settings) { - QDataStream stream(&settings, QIODevice::ReadOnly); - stream.setVersion(QDataStream::Qt_5_1); - QString outputDeviceID; - QString inputDeviceID; - qint32 outputVolume; - qint32 inputVolume; - qint32 duckingEnabled; - - stream >> outputDeviceID; - stream >> outputVolume; - stream >> inputDeviceID; - stream >> inputVolume; - stream >> duckingEnabled; - if (CheckStreamStatus(stream)) { - Global::SetCallOutputDeviceID(outputDeviceID); - Global::SetCallOutputVolume(outputVolume); - Global::SetCallInputDeviceID(inputDeviceID); - Global::SetCallInputVolume(inputVolume); - Global::SetCallAudioDuckingEnabled(duckingEnabled); - } -} - void Account::writeSessionSettings() { writeSessionSettings(nullptr); } @@ -774,7 +736,6 @@ void Account::writeSessionSettings(Main::SessionSettings *stored) { auto userData = userDataInstance ? userDataInstance->serialize() : QByteArray(); - auto callSettings = serializeCallSettings(); auto recentStickers = cRecentStickersPreload(); if (recentStickers.isEmpty() && _owner->sessionExists()) { @@ -786,7 +747,7 @@ void Account::writeSessionSettings(Main::SessionSettings *stored) { } uint32 size = 24 * (sizeof(quint32) + sizeof(qint32)); - size += sizeof(quint32) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); + size += sizeof(quint32); size += sizeof(quint32) + sizeof(qint32); for (auto &item : recentEmojiPreloadData) { @@ -801,40 +762,20 @@ void Account::writeSessionSettings(Main::SessionSettings *stored) { if (!userData.isEmpty()) { size += sizeof(quint32) + Serialize::bytearraySize(userData); } - size += sizeof(quint32) + Serialize::bytearraySize(callSettings); - - const auto soundFlashBounce = (Global::SoundNotify() ? 0x01 : 0x00) - | (Global::FlashBounceNotify() ? 0x00 : 0x02); EncryptedDescriptor data(size); data.stream << quint32(dbiTileBackground) << qint32(Window::Theme::Background()->tileDay() ? 1 : 0) << qint32(Window::Theme::Background()->tileNight() ? 1 : 0); - data.stream << quint32(dbiAdaptiveForWide) << qint32(Global::AdaptiveForWide() ? 1 : 0); - data.stream << quint32(dbiAutoLock) << qint32(Global::AutoLock()); - data.stream << quint32(dbiSoundFlashBounceNotify) << qint32(soundFlashBounce); - data.stream << quint32(dbiDesktopNotify) << qint32(Global::DesktopNotify()); - data.stream << quint32(dbiNotifyView) << qint32(Global::NotifyView()); - data.stream << quint32(dbiNativeNotifications) << qint32(Global::NativeNotifications()); - data.stream << quint32(dbiNotificationsCount) << qint32(Global::NotificationsCount()); - data.stream << quint32(dbiNotificationsCorner) << qint32(Global::NotificationsCorner()); - data.stream << quint32(dbiAskDownloadPath) << qint32(Global::AskDownloadPath()); - data.stream << quint32(dbiDownloadPath) << (Global::AskDownloadPath() ? QString() : Global::DownloadPath()) << (Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); - data.stream << quint32(dbiSongVolume) << qint32(qRound(Global::SongVolume() * 1e6)); - data.stream << quint32(dbiVideoVolume) << qint32(qRound(Global::VideoVolume() * 1e6)); - data.stream << quint32(dbiDialogsFilters) << qint32(Global::DialogsFiltersEnabled() ? 1 : 0); - data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); data.stream << quint32(dbiCacheSettings) << qint64(_cacheTotalSizeLimit) << qint32(_cacheTotalTimeLimit) << qint64(_cacheBigFileTotalSizeLimit) << qint32(_cacheBigFileTotalTimeLimit); if (!userData.isEmpty()) { data.stream << quint32(dbiSessionSettings) << userData; } - data.stream << quint32(dbiPlaybackSpeed) << qint32(Global::VoiceMsgPlaybackDoubled() ? 2 : 1); data.stream << quint32(dbiRecentEmoji) << recentEmojiPreloadData; data.stream << quint32(dbiEmojiVariants) << cEmojiVariants(); data.stream << quint32(dbiRecentStickers) << recentStickers; - data.stream << qint32(dbiCallSettings) << callSettings; FileWriteDescriptor file(_settingsKey, _basePath); file.writeEncrypted(data, _localKey); @@ -892,9 +833,6 @@ std::unique_ptr Account::applyReadContext( _cacheBigFileTotalSizeLimit = context.cacheBigFileTotalSizeLimit; _cacheBigFileTotalTimeLimit = context.cacheBigFileTotalTimeLimit; - if (!context.callSettings.isEmpty()) { - deserializeCallSettings(context.callSettings); - } if (!context.mtpAuthorization.isEmpty()) { _owner->setMtpAuthorization(context.mtpAuthorization); } else { diff --git a/Telegram/SourceFiles/storage/storage_account.h b/Telegram/SourceFiles/storage/storage_account.h index 728987f7e..eb922fb64 100644 --- a/Telegram/SourceFiles/storage/storage_account.h +++ b/Telegram/SourceFiles/storage/storage_account.h @@ -180,9 +180,6 @@ private: std::unique_ptr applyReadContext( details::ReadSettingsContext &&context); - [[nodiscard]] QByteArray serializeCallSettings(); - void deserializeCallSettings(QByteArray &settings); - void readDraftCursors( const PeerId &peer, MessageCursor &localCursor, diff --git a/Telegram/SourceFiles/storage/storage_accounts.cpp b/Telegram/SourceFiles/storage/storage_domain.cpp similarity index 85% rename from Telegram/SourceFiles/storage/storage_accounts.cpp rename to Telegram/SourceFiles/storage/storage_domain.cpp index 5626226a1..32170246a 100644 --- a/Telegram/SourceFiles/storage/storage_accounts.cpp +++ b/Telegram/SourceFiles/storage/storage_domain.cpp @@ -5,12 +5,12 @@ 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 "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "storage/details/storage_file_utilities.h" #include "storage/serialize_common.h" #include "mtproto/mtproto_config.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_account.h" #include "facades.h" @@ -19,8 +19,6 @@ namespace { using namespace details; -constexpr auto kMaxAccounts = 3; - [[nodiscard]] QString BaseGlobalPath() { return cWorkingDir() + qsl("tdata/"); } @@ -39,14 +37,14 @@ constexpr auto kMaxAccounts = 3; } // namespace -Accounts::Accounts(not_null owner, const QString &dataName) +Domain::Domain(not_null owner, const QString &dataName) : _owner(owner) , _dataName(dataName) { } -Accounts::~Accounts() = default; +Domain::~Domain() = default; -StartResult Accounts::start(const QByteArray &passcode) { +StartResult Domain::start(const QByteArray &passcode) { const auto modern = startModern(passcode); if (modern == StartModernResult::Success) { if (_oldVersion < AppVersion) { @@ -59,7 +57,7 @@ StartResult Accounts::start(const QByteArray &passcode) { startFromScratch(); return StartResult::Success; } - auto legacy = std::make_unique(_dataName, 0); + auto legacy = std::make_unique(_owner, _dataName, 0); const auto result = legacy->legacyStart(passcode); if (result == StartResult::Success) { _oldVersion = legacy->local().oldMapVersion(); @@ -68,7 +66,7 @@ StartResult Accounts::start(const QByteArray &passcode) { return result; } -void Accounts::startAdded( +void Domain::startAdded( not_null account, std::unique_ptr config) { Expects(_localKey != nullptr); @@ -77,7 +75,7 @@ void Accounts::startAdded( account->start(std::move(config)); } -void Accounts::startWithSingleAccount( +void Domain::startWithSingleAccount( const QByteArray &passcode, std::unique_ptr account) { Expects(account != nullptr); @@ -93,7 +91,7 @@ void Accounts::startWithSingleAccount( writeAccounts(); } -void Accounts::generateLocalKey() { +void Domain::generateLocalKey() { Expects(_localKey == nullptr); Expects(_passcodeKeySalt.isEmpty()); Expects(_passcodeKeyEncrypted.isEmpty()); @@ -107,7 +105,7 @@ void Accounts::generateLocalKey() { encryptLocalKey(QByteArray()); } -void Accounts::encryptLocalKey(const QByteArray &passcode) { +void Domain::encryptLocalKey(const QByteArray &passcode) { _passcodeKeySalt.resize(LocalEncryptSaltSize); memset_rand(_passcodeKeySalt.data(), _passcodeKeySalt.size()); _passcodeKey = CreateLocalKey(passcode, _passcodeKeySalt); @@ -117,7 +115,7 @@ void Accounts::encryptLocalKey(const QByteArray &passcode) { _passcodeKeyEncrypted = PrepareEncrypted(passKeyData, _passcodeKey); } -Accounts::StartModernResult Accounts::startModern( +Domain::StartModernResult Domain::startModern( const QByteArray &passcode) { const auto name = ComputeKeyName(_dataName); @@ -163,7 +161,7 @@ Accounts::StartModernResult Accounts::startModern( LOG(("App Info: reading encrypted info...")); auto count = qint32(); info.stream >> count; - if (count <= 0 || count > kMaxAccounts) { + if (count <= 0 || count > Main::Domain::kMaxAccounts) { LOG(("App Error: bad accounts count: %1").arg(count)); return StartModernResult::Failed; } @@ -176,9 +174,12 @@ Accounts::StartModernResult Accounts::startModern( auto index = qint32(); info.stream >> index; if (index >= 0 - && index < kMaxAccounts + && index < Main::Domain::kMaxAccounts && tried.emplace(index).second) { - auto account = std::make_unique(_dataName, index); + auto account = std::make_unique( + _owner, + _dataName, + index); auto config = account->prepareToStart(_localKey); const auto userId = account->willHaveUserId(); if (!users.contains(userId) @@ -194,8 +195,8 @@ Accounts::StartModernResult Accounts::startModern( return StartModernResult::Success; } -void Accounts::writeAccounts() { - Expects(!_owner->list().empty()); +void Domain::writeAccounts() { + Expects(!_owner->accounts().empty()); const auto path = BaseGlobalPath(); if (!QDir().exists(path)) { @@ -206,7 +207,7 @@ void Accounts::writeAccounts() { key.writeData(_passcodeKeySalt); key.writeData(_passcodeKeyEncrypted); - const auto &list = _owner->list(); + const auto &list = _owner->accounts(); const auto active = _owner->activeIndex(); auto keySize = sizeof(qint32) + sizeof(qint32) * list.size(); @@ -222,13 +223,13 @@ void Accounts::writeAccounts() { key.writeEncrypted(keyData, _localKey); } -void Accounts::startFromScratch() { +void Domain::startFromScratch() { startWithSingleAccount( QByteArray(), - std::make_unique(_dataName, 0)); + std::make_unique(_owner, _dataName, 0)); } -bool Accounts::checkPasscode(const QByteArray &passcode) const { +bool Domain::checkPasscode(const QByteArray &passcode) const { Expects(!_passcodeKeySalt.isEmpty()); Expects(_passcodeKey != nullptr); @@ -236,7 +237,7 @@ bool Accounts::checkPasscode(const QByteArray &passcode) const { return checkKey->equals(_passcodeKey); } -void Accounts::setPasscode(const QByteArray &passcode) { +void Domain::setPasscode(const QByteArray &passcode) { Expects(!_passcodeKeySalt.isEmpty()); Expects(_localKey != nullptr); @@ -247,11 +248,11 @@ void Accounts::setPasscode(const QByteArray &passcode) { Global::RefLocalPasscodeChanged().notify(); } -int Accounts::oldVersion() const { +int Domain::oldVersion() const { return _oldVersion; } -void Accounts::clearOldVersion() { +void Domain::clearOldVersion() { _oldVersion = 0; } diff --git a/Telegram/SourceFiles/storage/storage_accounts.h b/Telegram/SourceFiles/storage/storage_domain.h similarity index 88% rename from Telegram/SourceFiles/storage/storage_accounts.h rename to Telegram/SourceFiles/storage/storage_domain.h index 9434f8a67..1c78f6e0b 100644 --- a/Telegram/SourceFiles/storage/storage_accounts.h +++ b/Telegram/SourceFiles/storage/storage_domain.h @@ -15,7 +15,7 @@ using AuthKeyPtr = std::shared_ptr; namespace Main { class Account; -class Accounts; +class Domain; } // namespace Main namespace Storage { @@ -25,10 +25,10 @@ enum class StartResult : uchar { IncorrectPasscode, }; -class Accounts final { +class Domain final { public: - Accounts(not_null owner, const QString &dataName); - ~Accounts(); + Domain(not_null owner, const QString &dataName); + ~Domain(); [[nodiscard]] StartResult start(const QByteArray &passcode); void startAdded( @@ -57,9 +57,8 @@ private: std::unique_ptr account); void generateLocalKey(); void encryptLocalKey(const QByteArray &passcode); - void writeInfo(); - const not_null _owner; + const not_null _owner; const QString _dataName; MTP::AuthKeyPtr _localKey; diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index ab70bf740..5b73d2c00 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -27,8 +27,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/localimageloader.h" #include "core/sandbox.h" +#include "core/application.h" +#include "core/core_settings.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "apiwrap.h" #include "facades.h" #include "styles/style_layers.h" @@ -79,10 +80,10 @@ EditInfoBox::EditInfoBox( , _submit(std::move(submit)) { _field->setMaxLength(kMaxSupportInfoLength); _field->setSubmitSettings( - controller->session().settings().sendSubmitWay()); + Core::App().settings().sendSubmitWay()); _field->setInstantReplaces(Ui::InstantReplaces::Default()); _field->setInstantReplacesEnabled( - controller->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field)); } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 2dda52102..ebe6dad15 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -264,14 +264,18 @@ bool MainWindow::hideNoQuit() { } if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) { if (minimizeToTray()) { - Ui::showChatsList(); + if (const auto controller = sessionController()) { + Ui::showChatsList(&controller->session()); + } return true; } } else if (Platform::IsMac()) { closeWithoutDestroy(); controller().updateIsActiveBlur(); updateGlobalMenu(); - Ui::showChatsList(); + if (const auto controller = sessionController()) { + Ui::showChatsList(&controller->session()); + } return true; } return false; @@ -529,7 +533,9 @@ void MainWindow::updateControlsGeometry() { } void MainWindow::updateUnreadCounter() { - if (!Global::started() || App::quitting()) return; + if (App::quitting()) { + return; + } const auto counter = Core::App().unreadBadge(); _titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 12ace85d9..e527268e6 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -25,8 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_updates.h" #include "apiwrap.h" #include "main/main_session.h" -#include "main/main_session_settings.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "facades.h" #include "app.h" @@ -62,7 +61,7 @@ System::System(not_null session) updateAll(); } else if (type == ChangeType::IncludeMuted || type == ChangeType::CountMessages) { - Core::App().accounts().notifyUnreadBadgeChanged(); + Core::App().domain().notifyUnreadBadgeChanged(); } }); } @@ -138,7 +137,8 @@ void System::schedule(not_null item) { if (!skip.silent) { _whenAlerts[history].insert(when, notifyBy); } - if (Global::DesktopNotify() && !Platform::Notifications::SkipToast()) { + if (Core::App().settings().desktopNotify() + && !Platform::Notifications::SkipToast()) { auto &whenMap = _whenMaps[history]; if (whenMap.constFind(item->id) == whenMap.cend()) { whenMap.insert(item->id, when); @@ -302,8 +302,9 @@ void System::showNext() { ++i; } } + const auto &settings = Core::App().settings(); if (alert) { - if (Global::FlashBounceNotify() && !Platform::Notifications::SkipFlashBounce()) { + if (settings.flashBounceNotify() && !Platform::Notifications::SkipFlashBounce()) { if (const auto widget = App::wnd()) { if (const auto window = widget->windowHandle()) { window->alert(kSystemAlertDuration); @@ -311,7 +312,7 @@ void System::showNext() { } } } - if (Global::SoundNotify() && !Platform::Notifications::SkipAudio()) { + if (settings.soundNotify() && !Platform::Notifications::SkipAudio()) { ensureSoundCreated(); _soundTrack->playOnce(); emit Media::Player::mixer()->suppressAll(_soundTrack->getLengthMs()); @@ -319,7 +320,7 @@ void System::showNext() { } } - if (_waiters.isEmpty() || !Global::DesktopNotify() || Platform::Notifications::SkipToast()) { + if (_waiters.isEmpty() || !settings.desktopNotify() || Platform::Notifications::SkipToast()) { if (nextAlert) { _waitTimer.callOnce(nextAlert - ms); } @@ -474,7 +475,7 @@ void System::ensureSoundCreated() { _soundTrack = Media::Audio::Current().createTrack(); _soundTrack->fillFromFile( - session().settings().getSoundPath(qsl("msg_incoming"))); + Core::App().settings().getSoundPath(qsl("msg_incoming"))); } void System::updateAll() { @@ -485,11 +486,10 @@ Manager::DisplayOptions Manager::getNotificationOptions(HistoryItem *item) { const auto hideEverything = Core::App().locked() || Global::ScreenIsLocked(); + const auto view = Core::App().settings().notifyView(); DisplayOptions result; - result.hideNameAndPhoto = hideEverything - || (Global::NotifyView() > dbinvShowName); - result.hideMessageText = hideEverything - || (Global::NotifyView() > dbinvShowPreview); + result.hideNameAndPhoto = hideEverything || (view > dbinvShowName); + result.hideMessageText = hideEverything || (view > dbinvShowPreview); result.hideReplyButton = result.hideMessageText || !item || ((item->out() || item->history()->peer->isSelf()) diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index b976775c8..c528fe774 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_theme.h" #include "storage/file_download.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "history/history.h" #include "history/history_item.h" #include "platform/platform_specific.h" @@ -45,16 +44,17 @@ int notificationMaxHeight() { } QPoint notificationStartPosition() { - auto r = psDesktopRect(); - auto isLeft = Notify::IsLeftCorner(Global::NotificationsCorner()); - auto isTop = Notify::IsTopCorner(Global::NotificationsCorner()); - auto x = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX); - auto y = isTop ? r.y() : (r.y() + r.height()); + const auto corner = Core::App().settings().notificationsCorner(); + const auto r = psDesktopRect(); + const auto isLeft = Core::Settings::IsLeftCorner(corner); + const auto isTop = Core::Settings::IsTopCorner(corner); + const auto x = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX); + const auto y = isTop ? r.y() : (r.y() + r.height()); return QPoint(x, y); } internal::Widget::Direction notificationShiftDirection() { - auto isTop = Notify::IsTopCorner(Global::NotificationsCorner()); + auto isTop = Core::Settings::IsTopCorner(Core::App().settings().notificationsCorner()); return isTop ? internal::Widget::Direction::Down : internal::Widget::Direction::Up; } @@ -116,7 +116,7 @@ void Manager::settingsChanged(ChangeType change) { _hideAll->updatePosition(startPosition, shiftDirection); } } else if (change == ChangeType::MaxCount) { - int allow = Global::NotificationsCount(); + int allow = Core::App().settings().notificationsCount(); for (int i = _notifications.size(); i != 0;) { auto ¬ification = _notifications[--i]; if (notification->isUnlinked()) continue; @@ -196,7 +196,7 @@ void Manager::showNextFromQueue() { if (_queuedNotifications.empty()) { return; } - int count = Global::NotificationsCount(); + int count = Core::App().settings().notificationsCount(); for_const (auto ¬ification, _notifications) { if (notification->isUnlinked()) continue; --count; @@ -833,7 +833,7 @@ bool Notification::canReply() const { return !_hideReplyButton && (_item != nullptr) && !Core::App().locked() - && (Global::NotifyView() <= dbinvShowPreview); + && (Core::App().settings().notifyView() <= dbinvShowPreview); } void Notification::unlinkHistoryInManager() { @@ -878,7 +878,7 @@ void Notification::showReplyField() { _replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both); _replyArea->setInstantReplaces(Ui::InstantReplaces::Default()); _replyArea->setInstantReplacesEnabled( - _item->history()->session().settings().replaceEmojiValue()); + Core::App().settings().replaceEmojiValue()); _replyArea->setMarkdownReplacesEnabled(rpl::single(true)); // Catch mouse press event to activate the window. diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index e6f3b8912..f5f8bbc8d 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -23,7 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/crc32hash.h" #include "data/data_session.h" #include "main/main_account.h" // Account::local. -#include "main/main_accounts.h" // Accounts::activeSessionValue. +#include "main/main_domain.h" // Domain::activeSessionValue. #include "ui/image/image.h" #include "boxes/background_box.h" #include "core/application.h" @@ -548,7 +548,7 @@ void ChatBackground::start() { set(Data::ThemeWallPaper()); } - Core::App().accounts().activeSessionValue( + Core::App().domain().activeSessionValue( ) | rpl::filter([=](Main::Session *session) { return session != _session; }) | rpl::start_with_next([=](Main::Session *session) { diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index b906131ff..26576a73f 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -9,8 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "main/main_account.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "main/main_session.h" +#include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "ui/layers/box_content.h" #include "ui/layers/layer_widget.h" @@ -58,7 +59,7 @@ void Controller::showAccount(not_null account) { sideBarChanged(); }, session->lifetime()); } - if (_sessionController && Global::DialogsFiltersEnabled()) { + if (session && session->settings().dialogsFiltersEnabled()) { _sessionController->toggleFiltersMenu(true); } else { sideBarChanged(); diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index 7ae4b9199..4ee071e5e 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_lock_widgets.h" #include "lang/lang_keys.h" -#include "storage/storage_accounts.h" +#include "storage/storage_domain.h" #include "mainwindow.h" #include "core/application.h" #include "api/api_text_entities.h" @@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "window/window_slide_animation.h" #include "window/window_session_controller.h" -#include "main/main_accounts.h" +#include "main/main_domain.h" #include "facades.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -76,7 +76,9 @@ void LockWidget::animationCallback() { void LockWidget::showFinished() { showChildren(); _window->widget()->setInnerFocus(); - Ui::showChatsList(); + if (const auto controller = _window->sessionController()) { + Ui::showChatsList(&controller->session()); + } _cacheUnder = _cacheOver = QPixmap(); } @@ -149,10 +151,10 @@ void PasscodeLockWidget::submit() { } const auto passcode = _passcode->text().toUtf8(); - auto &accounts = Core::App().accounts(); - const auto correct = accounts.started() - ? accounts.local().checkPasscode(passcode) - : (accounts.start(passcode) + auto &domain = Core::App().domain(); + const auto correct = domain.started() + ? domain.local().checkPasscode(passcode) + : (domain.start(passcode) != Storage::StartResult::IncorrectPasscode); if (!correct) { cSetPasscodeBadTries(cPasscodeBadTries() + 1); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 939a1b21a..c1a7a2e0f 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -217,8 +217,8 @@ void SessionController::toggleFiltersMenu(bool enabled) { void SessionController::refreshFiltersMenu() { const auto enabled = !session().data().chatsFilters().list().empty(); - if (enabled != Global::DialogsFiltersEnabled()) { - Global::SetDialogsFiltersEnabled(enabled); + if (enabled != session().settings().dialogsFiltersEnabled()) { + session().settings().setDialogsFiltersEnabled(enabled); session().saveSettingsDelayed(); toggleFiltersMenu(enabled); } @@ -801,7 +801,7 @@ void SessionController::setActiveChatsFilter(FilterId id) { closeFolder(); } if (Adaptive::OneColumn()) { - Ui::showChatsList(); + Ui::showChatsList(&session()); } }