Move a lot of settings to Core::Settings.

This commit is contained in:
John Preston 2020-06-18 22:04:16 +04:00
parent 4d6cc58f0d
commit 83538675ce
112 changed files with 1761 additions and 1482 deletions

View file

@ -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

View file

@ -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<PhotoData*> 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<StickerSetBox>(App::wnd()->sessionController(), setId),
Ui::LayerOption::KeepOther);
const auto &windows = _session->windows();
if (!windows.empty()) {
Ui::show(
Box<StickerSetBox>(windows.front(), setId),
Ui::LayerOption::KeepOther);
}
}).fail([=](const RPCError &error) {
Ui::show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
}).send();

View file

@ -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(); });

View file

@ -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<Ui::RadiobuttonGroup>(Global::AutoLock());
auto group = std::make_shared<Ui::RadiobuttonGroup>(
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();

View file

@ -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.

View file

@ -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<Main::Session*> 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<Ui::InputField*> 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));

View file

@ -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<Inner>(
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);

View file

@ -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<Window::SessionController*> controller)
: _controller(controller)
, _path(Global::DownloadPath())
, _pathBookmark(Global::DownloadPathBookmark())
, _path(Core::App().settings().downloadPath())
, _pathBookmark(Core::App().settings().downloadPathBookmark())
, _group(std::make_shared<Ui::RadioenumGroup<Directory>>(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
}

View file

@ -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));

View file

@ -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,

View file

@ -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();

View file

@ -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"

View file

@ -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<Ui::RpWidget> 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<Ui::RpWidget> 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);
}

View file

@ -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());

View file

@ -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());

View file

@ -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();
}
}
}

View file

@ -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);

View file

@ -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"

View file

@ -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 {

View file

@ -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(

View file

@ -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;

View file

@ -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) {

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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) {

View file

@ -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"

View file

@ -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<Spellchecker::SpellingHighlighter>(
field.get(),
controller->session().settings().spellcheckerEnabledValue(),
Core::App().settings().spellcheckerEnabledValue(),
Spellchecker::SpellingHighlighter::CustomContextMenuItem{
tr::lng_settings_manage_dictionaries(tr::now),
[=] { Ui::show(Box<Ui::ManageDictionariesBox>(controller)); }

View file

@ -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 <QtGui/QGuiApplication>
#include <QtGui/QInputMethod>
@ -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<QString> ButtonManageDictsState(
not_null<Main::Session*> session) {
not_null<Main::Session*> 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<QString> 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<Main::Session*> 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(

View file

@ -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<Main::Session*> 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<Main::Session*> 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<Ui::Emoji::UniversalImages> {
const auto &images = Ui::Emoji::SourceImages();
if (_session->settings().largeEmoji()) {
if (Core::App().settings().largeEmoji()) {
return images;
}
Ui::Emoji::ClearSourceImages(images);

View file

@ -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*> launcher)
, _animationsManager(std::make_unique<Ui::Animations::Manager>())
, _fallbackProductionConfig(
std::make_unique<MTP::Config>(MTP::Environment::Production))
, _accounts(std::make_unique<Main::Accounts>(cDataFile()))
, _domain(std::make_unique<Main::Domain>(cDataFile()))
, _langpack(std::make_unique<Lang::Instance>())
, _langCloudManager(std::make_unique<Lang::CloudManager>(langpack()))
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
@ -116,14 +116,14 @@ Application::Application(not_null<Launcher*> 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<Window::Controller>();
accounts().activeChanges(
_domain->activeChanges(
) | rpl::start_with_next([=](not_null<Main::Account*> 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<MTP::Config>(
@ -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);

View file

@ -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<Storage::Databases> _databases;
const std::unique_ptr<Ui::Animations::Manager> _animationsManager;
mutable std::unique_ptr<MTP::Config> _fallbackProductionConfig;
const std::unique_ptr<Main::Accounts> _accounts;
const std::unique_ptr<Main::Domain> _domain;
std::unique_ptr<Window::Controller> _window;
std::unique_ptr<Media::View::OverlayWidget> _mediaView;
const std::unique_ptr<Lang::Instance> _langpack;

View file

@ -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<Main::Session*> session, int oldVersion)
std::unique_ptr<Changelogs> Changelogs::Create(
not_null<Main::Session*> 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)

View file

@ -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<qint32>(_notifyView)
<< qint32(_nativeNotifications ? 1 : 0)
<< qint32(_notificationsCount)
<< static_cast<qint32>(_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<qint32>(_notifyView);
qint32 nativeNotifications = _nativeNotifications ? 1 : 0;
qint32 notificationsCount = _notificationsCount;
qint32 notificationsCorner = static_cast<qint32>(_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<QString, QString> soundOverrides;
qint32 sendFilesWay = static_cast<qint32>(_sendFilesWay);
qint32 sendSubmitWay = static_cast<qint32>(_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<int> 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<DBINotifyView>(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<ScreenCorner>(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>(sendFilesWay);
switch (uncheckedSendFilesWay) {
case SendFilesWay::Album:
case SendFilesWay::Photos:
case SendFilesWay::Files: _sendFilesWay = uncheckedSendFilesWay; break;
}
auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(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

View file

@ -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<float64> songVolumeChanges() const {
return _songVolume.changes();
}
void setSongVolume(float64 value) {
_songVolume = value;
}
[[nodiscard]] float64 videoVolume() const {
return _videoVolume.current();
}
[[nodiscard]] rpl::producer<float64> 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<QString> 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<bool> 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<bool> largeEmojiValue() const {
return _largeEmoji.value();
}
[[nodiscard]] rpl::producer<bool> largeEmojiChanges() const {
return _largeEmoji.changes();
}
void setReplaceEmoji(bool value) {
_replaceEmoji = value;
}
[[nodiscard]] bool replaceEmoji() const {
return _replaceEmoji.current();
}
[[nodiscard]] rpl::producer<bool> replaceEmojiValue() const {
return _replaceEmoji.value();
}
[[nodiscard]] rpl::producer<bool> 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<bool> spellcheckerEnabledValue() const {
return _spellcheckerEnabled.value();
}
rpl::producer<bool> spellcheckerEnabledChanges() const {
return _spellcheckerEnabled.changes();
}
void setDictionariesEnabled(std::vector<int> dictionaries) {
_dictionariesEnabled = std::move(dictionaries);
}
std::vector<int> dictionariesEnabled() const {
return _dictionariesEnabled.current();
}
rpl::producer<std::vector<int>> dictionariesEnabledChanges() const {
return _dictionariesEnabled.changes();
}
void setAutoDownloadDictionaries(bool value) {
_autoDownloadDictionaries = value;
}
bool autoDownloadDictionaries() const {
return _autoDownloadDictionaries.current();
}
rpl::producer<bool> autoDownloadDictionariesValue() const {
return _autoDownloadDictionaries.value();
}
rpl::producer<bool> 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<float64> _songVolume = kDefaultVolume;
rpl::variable<float64> _videoVolume = kDefaultVolume;
Variables _variables;
bool _askDownloadPath = false;
rpl::variable<QString> _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<bool> _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<QString, QString> _soundOverrides;
bool _exeLaunchWarning = true;
bool _loopAnimatedStickers = true;
rpl::variable<bool> _largeEmoji = true;
rpl::variable<bool> _replaceEmoji = true;
bool _suggestEmoji = true;
bool _suggestStickersByEmoji = true;
rpl::variable<bool> _spellcheckerEnabled = true;
rpl::variable<float64> _videoPlaybackSpeed = 1.;
QByteArray _videoPipGeometry;
rpl::variable<std::vector<int>> _dictionariesEnabled;
rpl::variable<bool> _autoDownloadDictionaries = true;
float64 _rememberedSongVolume = kDefaultVolume;
bool _rememberedSoundNotifyFromTray = false;
bool _rememberedFlashBounceNotifyFromTray = false;
};
} // namespace Core

View file

@ -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 {

View file

@ -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) {

View file

@ -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());

View file

@ -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<ConfirmDontWarnBox>(
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<DownloadPathBox>());
// Global::RefDownloadPathChanged().notify();
//};
//Ui::show(Box<ConfirmBox>(
// 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() {

View file

@ -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 <QtCore/QBuffer>
@ -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;

View file

@ -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);
}

View file

@ -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));
}

View file

@ -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 {

View file

@ -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<not_null<DocumentData*>> Stickers::getListByEmoji(
session().api().requestStickerSets();
}
if (session().settings().suggestStickersByEmoji()) {
if (Core::App().settings().suggestStickersByEmoji()) {
const auto others = session().api().stickersByEmoji(original);
if (!others) {
return {};

View file

@ -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"

View file

@ -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()));

View file

@ -211,29 +211,28 @@ void showSettings() {
namespace Ui {
void showPeerProfile(const PeerId &peer) {
if (const auto window = App::wnd()) {
void showPeerProfile(not_null<PeerData*> 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<const History*> history) {
showPeerProfile(history->peer->id);
showPeerProfile(history->peer);
}
void showPeerHistory(
const PeerId &peer,
MsgId msgId) {
void showChatsList(not_null<Main::Session*> 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<void> AdaptiveChanged;
bool DialogsFiltersEnabled = false;
bool ModerateModeEnabled = false;
bool ScreenIsLocked = false;
float64 RememberedSongVolume = kDefaultVolume;
float64 SongVolume = kDefaultVolume;
base::Observable<void> SongVolumeChanged;
float64 VideoVolume = kDefaultVolume;
base::Observable<void> VideoVolumeChanged;
bool AskDownloadPath = false;
QString DownloadPath;
QByteArray DownloadPathBookmark;
base::Observable<void> 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<void> ConnectionTypeChanged;
int AutoLock = 3600;
bool LocalPasscode = false;
base::Observable<void> LocalPasscodeChanged;
base::Variable<DBIWorkMode> WorkMode = { dbiwmWindowAndTray };
base::Observable<void> 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<void>, 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<void>, SongVolumeChanged);
DefineVar(Global, float64, VideoVolume);
DefineRefVar(Global, base::Observable<void>, VideoVolumeChanged);
DefineVar(Global, bool, AskDownloadPath);
DefineVar(Global, QString, DownloadPath);
DefineVar(Global, QByteArray, DownloadPathBookmark);
DefineRefVar(Global, base::Observable<void>, 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<void>, ConnectionTypeChanged);
DefineVar(Global, int, AutoLock);
DefineVar(Global, bool, LocalPasscode);
DefineRefVar(Global, base::Observable<void>, LocalPasscodeChanged);
@ -455,10 +394,4 @@ DefineRefVar(Global, base::Variable<DBIWorkMode>, WorkMode);
DefineRefVar(Global, base::Observable<void>, PeerChooseCancel);
DefineVar(Global, QString, CallOutputDeviceID);
DefineVar(Global, QString, CallInputDeviceID);
DefineVar(Global, int, CallOutputVolume);
DefineVar(Global, int, CallInputVolume);
DefineVar(Global, bool, CallAudioDuckingEnabled);
} // namespace Global

View file

@ -56,18 +56,13 @@ namespace Ui {
// Legacy global methods.
void showPeerProfile(const PeerId &peer);
void showPeerProfile(const PeerData *peer);
void showPeerProfile(not_null<PeerData*> peer);
void showPeerProfile(not_null<const History*> history);
void showPeerHistory(const PeerId &peer, MsgId msgId);
void showPeerHistoryAtItem(not_null<const HistoryItem*> item);
void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId);
void showPeerHistory(not_null<const History*> history, MsgId msgId);
inline void showChatsList() {
showPeerHistory(PeerId(0), 0);
}
void showChatsList(not_null<Main::Session*> 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<void>, AdaptiveChanged);
DeclareVar(bool, DialogsFiltersEnabled);
DeclareVar(bool, ModerateModeEnabled);
constexpr auto kDefaultVolume = 0.9;
DeclareVar(float64, RememberedSongVolume);
DeclareVar(float64, SongVolume);
DeclareRefVar(base::Observable<void>, SongVolumeChanged);
DeclareVar(float64, VideoVolume);
DeclareRefVar(base::Observable<void>, VideoVolumeChanged);
DeclareVar(bool, AskDownloadPath);
DeclareVar(QString, DownloadPath);
DeclareVar(QByteArray, DownloadPathBookmark);
DeclareRefVar(base::Observable<void>, 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<void>, ConnectionTypeChanged);
DeclareVar(int, AutoLock);
DeclareVar(bool, LocalPasscode);
DeclareRefVar(base::Observable<void>, 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

View file

@ -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 {

View file

@ -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();

View file

@ -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<HistoryServicePinned>()
&& !history()->session().settings().notifyAboutPinned()) {
&& !Core::App().settings().notifyAboutPinned()) {
return false;
}
return _flags & MTPDmessage::Flag::f_mentioned;

View file

@ -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());

View file

@ -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(); });

View file

@ -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)) {

View file

@ -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();

View file

@ -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<HistoryMessageForwarded>();
@ -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;
}

View file

@ -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<HistoryService*> 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

View file

@ -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<HistoryMessageVia>();
@ -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<HistoryMessageVia>();
@ -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<HistoryMessageVia>();
@ -387,7 +388,7 @@ std::unique_ptr<Lottie::SinglePlayer> 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());
}

View file

@ -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

View file

@ -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<Main::Session*> 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();
}

View file

@ -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"

View file

@ -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();

View file

@ -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<Storage::Account>(
Account::Account(not_null<Domain*> domain, const QString &dataName, int index)
: _domain(domain)
, _local(std::make_unique<Storage::Account>(
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);
}

View file

@ -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*> 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<MTP::Config> config);
void createSession(
const MTPUser &user,
@ -116,6 +123,7 @@ private:
void loggedOut();
const not_null<Domain*> _domain;
const std::unique_ptr<Storage::Account> _local;
std::unique_ptr<MTP::Instance> _mtp;

View file

@ -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<Storage::Accounts>(this, dataName)) {
, _local(std::make_unique<Storage::Domain>(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> 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<int, std::unique_ptr<Account>> &Accounts::list() const {
const base::flat_map<int, std::unique_ptr<Account>> &Domain::accounts() const {
return _accounts;
}
rpl::producer<Account*> Accounts::activeValue() const {
rpl::producer<Account*> 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<not_null<Account*>> Accounts::activeChanges() const {
rpl::producer<not_null<Account*>> Domain::activeChanges() const {
return _active.changes() | rpl::map([](Account *value) {
return not_null{ value };
});
}
rpl::producer<Session*> Accounts::activeSessionChanges() const {
rpl::producer<Session*> Domain::activeSessionChanges() const {
return _activeSessions.events();
}
rpl::producer<Session*> Accounts::activeSessionValue() const {
rpl::producer<Session*> 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<Account>(_dataName, index)
std::make_unique<Account>(this, _dataName, index)
).first->second.get();
_local->startAdded(account, std::move(config));
watchSession(account);
return index;
}
void Accounts::watchSession(not_null<Account*> account) {
void Domain::watchSession(not_null<Account*> account) {
account->sessionValue(
) | rpl::filter([=](Session *session) {
return session != nullptr;
@ -230,7 +230,7 @@ void Accounts::watchSession(not_null<Account*> 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<Main::Account*> 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;
}

View file

@ -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<int, std::unique_ptr<Account>> &;
[[nodiscard]] rpl::producer<Account*> 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> account);
private:
@ -70,7 +74,7 @@ private:
void scheduleUpdateUnreadBadge();
const QString _dataName;
const std::unique_ptr<Storage::Accounts> _local;
const std::unique_ptr<Storage::Domain> _local;
base::flat_map<int, std::unique_ptr<Account>> _accounts;
rpl::variable<Account*> _active = nullptr;

View file

@ -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<const Main::Session*> session) {
not_null<const Session*> 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<Main::Account*> account,
not_null<Account*> account,
const MTPUser &user,
std::unique_ptr<SessionSettings> 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<void> &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<Window::SessionController*> controller) {
_windows.emplace(controller);
controller->lifetime().add([=] {

View file

@ -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<Main::Account*> account,
not_null<Account*> account,
const MTPUser &user,
std::unique_ptr<SessionSettings> 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 &notifications() {
[[nodiscard]] Window::Notifications::System &notifications() 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<Main::Account*> _account;
const not_null<Account*> _account;
const std::unique_ptr<SessionSettings> _settings;
const std::unique_ptr<ApiWrap> _api;

View file

@ -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<qint32>(_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<qint32>(_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> SessionSettings::FromSerialized(
const QByteArray &serialized) {
void SessionSettings::addFromSerialized(const QByteArray &serialized) {
if (serialized.isEmpty()) {
return nullptr;
return;
}
auto result = std::make_unique<SessionSettings>();
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<qint32>(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<qint32>(Window::Column::Second);
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
base::flat_map<QString, QString> soundOverrides;
base::flat_map<QString, QString> appSoundOverrides;
base::flat_set<PeerId> 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<qint32>(variables->sendFilesWay);
float64 dialogsWidthRatio = _dialogsWidthRatio.current();
int thirdColumnWidth = _thirdColumnWidth.current();
int thirdSectionExtendedBy = _thirdSectionExtendedBy;
qint32 appSendFilesWay = static_cast<qint32>(app.sendFilesWay());
qint32 legacyCallsPeerToPeer = qint32(0);
qint32 sendSubmitWay = static_cast<qint32>(variables->sendSubmitWay);
qint32 supportSwitch = static_cast<qint32>(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<qint32>(app.sendSubmitWay());
qint32 supportSwitch = static_cast<qint32>(_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<std::pair<DocumentId, crl::time>> mediaLastPlaybackPosition;
qint32 videoPlaybackSpeed = SerializePlaybackSpeed(variables->videoPlaybackSpeed.current());
QByteArray videoPipGeometry = variables->videoPipGeometry;
std::vector<int> dictionariesEnabled;
qint32 autoDownloadDictionaries = variables->autoDownloadDictionaries.current() ? 1 : 0;
qint32 appVideoPlaybackSpeed = Core::Settings::SerializePlaybackSpeed(app.videoPlaybackSpeed());
QByteArray appVideoPipGeometry = app.videoPipGeometry();
std::vector<int> appDictionariesEnabled;
qint32 appAutoDownloadDictionaries = app.autoDownloadDictionaries() ? 1 : 0;
base::flat_map<PeerId, MsgId> hiddenPinnedMessages;
qint32 dialogsFiltersEnabled = _dialogsFiltersEnabled ? 1 : 0;
stream >> versionTag;
if (versionTag == kVersionTag) {
@ -194,23 +155,27 @@ std::unique_ptr<SessionSettings> 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> 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> 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> 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> 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> 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> 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> 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<Window::Column>(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<RectPart>(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>(sendFilesWay);
switch (uncheckedSendFilesWay) {
case SendFilesWay::Album:
case SendFilesWay::Photos:
case SendFilesWay::Files: variables->sendFilesWay = uncheckedSendFilesWay; break;
}
auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
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<Support::SwitchSettings>(
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<SendFilesWay>(appSendFilesWay);
switch (uncheckedSendFilesWay) {
case SendFilesWay::Album:
case SendFilesWay::Photos:
case SendFilesWay::Files: app.setSendFilesWay(uncheckedSendFilesWay); break;
}
auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
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<int> 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<bool> 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<bool> 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<float64> 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<int> 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<DocumentId, crl::time>::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<bool> 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<bool> 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<bool> 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<bool> 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<bool> SessionSettings::largeEmojiValue() const {
return _variables.largeEmoji.value();
}
rpl::producer<bool> 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<bool> SessionSettings::replaceEmojiValue() const {
return _variables.replaceEmoji.value();
}
rpl::producer<bool> SessionSettings::replaceEmojiChanges() const {
return _variables.replaceEmoji.changes();
return _skipArchiveInSearch.changes();
}
} // namespace Main

View file

@ -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<SessionSettings> 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<bool> 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<bool> 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<bool> 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<int> 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<bool> archiveInMainMenuChanges() const;
void setNotifyAboutPinned(bool notify);
[[nodiscard]] bool notifyAboutPinned() const;
[[nodiscard]] rpl::producer<bool> notifyAboutPinnedChanges() const;
void setSkipArchiveInSearch(bool skip);
[[nodiscard]] bool skipArchiveInSearch() const;
[[nodiscard]] rpl::producer<bool> 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<bool> largeEmojiValue() const;
[[nodiscard]] rpl::producer<bool> largeEmojiChanges() const;
void setReplaceEmoji(bool value);
[[nodiscard]] bool replaceEmoji() const;
[[nodiscard]] rpl::producer<bool> replaceEmojiValue() const;
[[nodiscard]] rpl::producer<bool> 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<bool> spellcheckerEnabledValue() const {
return _variables.spellcheckerEnabled.value();
}
rpl::producer<bool> spellcheckerEnabledChanges() const {
return _variables.spellcheckerEnabled.changes();
}
void setDictionariesEnabled(std::vector<int> dictionaries) {
_variables.dictionariesEnabled = std::move(dictionaries);
}
std::vector<int> dictionariesEnabled() const {
return _variables.dictionariesEnabled.current();
}
rpl::producer<std::vector<int>> dictionariesEnabledChanges() const {
return _variables.dictionariesEnabled.changes();
}
void setAutoDownloadDictionaries(bool value) {
_variables.autoDownloadDictionaries = value;
}
bool autoDownloadDictionaries() const {
return _variables.autoDownloadDictionaries.current();
}
rpl::producer<bool> autoDownloadDictionariesValue() const {
return _variables.autoDownloadDictionaries.value();
}
rpl::producer<bool> autoDownloadDictionariesChanges() const {
return _variables.autoDownloadDictionaries.changes();
}
[[nodiscard]] float64 videoPlaybackSpeed() const {
return _variables.videoPlaybackSpeed.current();
}
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<PeerId> _groupStickersSectionHidden;
bool _thirdSectionInfoEnabled = true; // per-window
bool _smallDialogsList = false; // per-window
int _thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> _dialogsWidthRatio; // per-window
rpl::variable<int> _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
bool _hadLegacyCallsPeerToPeerNobody = false;
Data::AutoDownload::Full _autoDownload;
rpl::variable<bool> _archiveCollapsed = false;
rpl::variable<bool> _archiveInMainMenu = false;
rpl::variable<bool> _skipArchiveInSearch = false;
std::vector<std::pair<DocumentId, crl::time>> _mediaLastPlaybackPosition;
base::flat_map<PeerId, MsgId> _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<QString, QString> soundOverrides;
Window::Column floatPlayerColumn; // per-window
RectPart floatPlayerCorner; // per-window
base::flat_set<PeerId> groupStickersSectionHidden;
bool thirdSectionInfoEnabled = true; // per-window
bool smallDialogsList = false; // per-window
int thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> dialogsWidthRatio; // per-window
rpl::variable<int> 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<bool> archiveCollapsed = false;
rpl::variable<bool> archiveInMainMenu = false;
rpl::variable<bool> notifyAboutPinned = true;
rpl::variable<bool> skipArchiveInSearch = false;
bool loopAnimatedStickers = true;
rpl::variable<bool> largeEmoji = true;
rpl::variable<bool> replaceEmoji = true;
bool suggestEmoji = true;
bool suggestStickersByEmoji = true;
rpl::variable<bool> spellcheckerEnabled = true;
std::vector<std::pair<DocumentId, crl::time>> mediaLastPlaybackPosition;
rpl::variable<float64> videoPlaybackSpeed = 1.;
QByteArray videoPipGeometry;
rpl::variable<std::vector<int>> dictionariesEnabled;
rpl::variable<bool> autoDownloadDictionaries = true;
base::flat_map<PeerId, MsgId> hiddenPinnedMessages;
static constexpr auto kDefaultSupportChatsLimitSlice
= 7 * 24 * 60 * 60;
Support::SwitchSettings supportSwitch;
bool supportFixChatsOrder = true;
bool supportTemplatesAutocomplete = true;
rpl::variable<int> supportChatsTimeSlice
= kDefaultSupportChatsLimitSlice;
rpl::variable<bool> supportAllSearchResults = false;
};
Support::SwitchSettings _supportSwitch;
bool _supportFixChatsOrder = true;
bool _supportTemplatesAutocomplete = true;
rpl::variable<int> _supportChatsTimeSlice
= kDefaultSupportChatsLimitSlice;
rpl::variable<bool> _supportAllSearchResults = false;
rpl::event_stream<bool> _thirdSectionInfoEnabledValue;
bool _tabbedReplacedWithInfo = false;
rpl::event_stream<bool> _tabbedReplacedWithInfoValue;
Variables _variables;
};
} // namespace Main

View file

@ -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();
}

View file

@ -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();

View file

@ -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 <al.h>
@ -575,12 +574,17 @@ Mixer::Mixer(not_null<Audio::Instance*> 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;

View file

@ -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();

View file

@ -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.);
}

View file

@ -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<Window::SessionController*> 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());
}
}

View file

@ -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,

View file

@ -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<Main::Session*> 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<Main::Session*> 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<Main::Session*> 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,

View file

@ -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<Main::Session*> 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;
}

View file

@ -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);

View file

@ -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 <QtCore/QJsonDocument>
#include <QtCore/QJsonArray>

View file

@ -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 <QtCore/QProcess>
#include <QtGui/QDesktopServices>

View file

@ -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 <QtCore/QVersionNumber>
#include <QtDBus/QDBusMessage>
@ -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<Window::Notifications::Manager> Create(
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
GetSupported();
if ((Global::NativeNotifications() && Supported())
if ((Core::App().settings().nativeNotifications() && Supported())
|| Platform::IsWayland()) {
return std::make_unique<Manager>(system);
}

View file

@ -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.

View file

@ -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 <QtGui/QWindow>
@ -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();
}
}
}

View file

@ -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 <QtWidgets/QDesktopWidget>

View file

@ -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 <Shobjidl.h>
#include <shellapi.h>
@ -323,7 +324,7 @@ bool Supported() {
std::unique_ptr<Window::Notifications::Manager> Create(Window::Notifications::System *system) {
#ifndef __MINGW32__
if (Global::NativeNotifications() && Supported()) {
if (Core::App().settings().nativeNotifications() && Supported()) {
auto result = std::make_unique<Manager>(system);
if (result->init()) {
return std::move(result);

View file

@ -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,

View file

@ -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<Ui::VerticalLayout*> 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(

View file

@ -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<tgvoip::AudioInputTester>(
Global::CallInputDeviceID().toStdString());
Core::App().settings().callInputDeviceID().toStdString());
if (_micTester->Failed()) {
stopTestingMicrophone();
Ui::show(Box<InformBox>(tr::lng_call_error_audio_io(tr::now)));

View file

@ -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<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> 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<Ui::RadioenumGroup<SendByType>>(
controller->session().settings().sendSubmitWay());
Core::App().settings().sendSubmitWay());
const auto add = [&](SendByType value, const QString &text) {
inner->add(
object_ptr<Ui::Radioenum<SendByType>>(
@ -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<rpl::event_stream<bool>>(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<Ui::Checkbox>(
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());
}

View file

@ -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<ConfirmBox>(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<InformBox>(
"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<InformBox>("All sound overrides were reset."));
}
Core::App().settings().clearSoundOverrides();
Core::App().saveSettingsDelayed();
Ui::show(Box<InformBox>("All sound overrides were reset."));
});
return codes;

View file

@ -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,

View file

@ -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 {

View file

@ -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<Window::SessionController*> 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<Notify::ScreenCorner>(corner);
auto isLeft = Notify::IsLeftCorner(screenCorner);
auto isTop = Notify::IsTopCorner(screenCorner);
auto screenCorner = static_cast<ScreenCorner>(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<int>(_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());

View file

@ -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<PeerListRow*> 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<QString> LastSeenPrivacyController::exceptionsDescription() {
void LastSeenPrivacyController::confirmSave(
bool someAreDisallowed,
FnMut<void()> saveCallback) {
if (someAreDisallowed && !_session->settings().lastSeenWarningSeen()) {
if (someAreDisallowed && !Core::App().settings().lastSeenWarningSeen()) {
const auto session = _session;
auto weakBox = std::make_shared<QPointer<ConfirmBox>>();
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<ConfirmBox>(
tr::lng_edit_privacy_lastseen_warning(tr::now),

View file

@ -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);

View file

@ -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<Notify::ScreenCorner>((v >= 0 && v < 4) ? v : 2));
Core::App().settings().setNotificationsCorner(static_cast<Core::Settings::ScreenCorner>((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: {

View file

@ -54,8 +54,6 @@ struct ReadSettingsContext {
FileKey langPackKey = 0;
FileKey languagesKey = 0;
QByteArray callSettings;
QByteArray mtpAuthorization;
std::vector<std::shared_ptr<MTP::AuthKey>> 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,

View file

@ -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 {

View file

@ -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;
}

Some files were not shown because too many files have changed in this diff Show more