From 5d6a4949341c18cb08db2aec22190d413c0ab40d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 25 Jun 2020 16:16:09 +0400 Subject: [PATCH] Move some more settings to Core::App. --- Telegram/SourceFiles/core/core_settings.cpp | 85 ++++++- Telegram/SourceFiles/core/core_settings.h | 67 +++++- .../SourceFiles/history/history_widget.cpp | 8 +- .../view/history_view_compose_controls.cpp | 10 +- .../view/history_view_top_bar_widget.cpp | 31 +-- .../main/main_session_settings.cpp | 210 ++++++------------ .../SourceFiles/main/main_session_settings.h | 65 ------ Telegram/SourceFiles/mainwidget.cpp | 61 ++--- Telegram/SourceFiles/mainwindow.cpp | 3 +- .../media/player/media_player_float.cpp | 51 ++--- .../media/player/media_player_float.h | 3 - .../details/storage_settings_scheme.cpp | 2 +- Telegram/SourceFiles/window/main_window.cpp | 4 +- .../SourceFiles/window/window_peer_menu.cpp | 5 +- .../window/window_session_controller.cpp | 52 +++-- 15 files changed, 334 insertions(+), 323 deletions(-) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 21454d1a9d..c88373baf2 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -11,13 +11,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/input_fields.h" #include "storage/serialize_common.h" #include "window/themes/window_theme.h" +#include "window/section_widget.h" +#include "base/platform/base_platform_info.h" #include "facades.h" namespace Core { Settings::Settings() : _sendFilesWay(SendFilesWay::Album) -, _sendSubmitWay(Ui::InputSubmitSettings::Enter) { +, _sendSubmitWay(Ui::InputSubmitSettings::Enter) +, _floatPlayerColumn(Window::Column::Second) +, _floatPlayerCorner(RectPart::TopRight) +, _dialogsWidthRatio(DefaultDialogsWidthRatio()) { } QByteArray Settings::serialize() const { @@ -291,6 +296,66 @@ QString Settings::getSoundPath(const QString &key) const { return qsl(":/sounds/") + key + qsl(".mp3"); } +void Settings::setTabbedSelectorSectionEnabled(bool enabled) { + _tabbedSelectorSectionEnabled = enabled; + if (enabled) { + setThirdSectionInfoEnabled(false); + } + setTabbedReplacedWithInfo(false); +} + +rpl::producer Settings::tabbedReplacedWithInfoValue() const { + return _tabbedReplacedWithInfoValue.events_starting_with( + tabbedReplacedWithInfo()); +} + +void Settings::setThirdSectionInfoEnabled(bool enabled) { + if (_thirdSectionInfoEnabled != enabled) { + _thirdSectionInfoEnabled = enabled; + if (enabled) { + setTabbedSelectorSectionEnabled(false); + } + setTabbedReplacedWithInfo(false); + _thirdSectionInfoEnabledValue.fire_copy(enabled); + } +} + +rpl::producer Settings::thirdSectionInfoEnabledValue() const { + return _thirdSectionInfoEnabledValue.events_starting_with( + thirdSectionInfoEnabled()); +} + +void Settings::setTabbedReplacedWithInfo(bool enabled) { + if (_tabbedReplacedWithInfo != enabled) { + _tabbedReplacedWithInfo = enabled; + _tabbedReplacedWithInfoValue.fire_copy(enabled); + } +} + +void Settings::setDialogsWidthRatio(float64 ratio) { + _dialogsWidthRatio = ratio; +} + +float64 Settings::dialogsWidthRatio() const { + return _dialogsWidthRatio.current(); +} + +rpl::producer Settings::dialogsWidthRatioChanges() const { + return _dialogsWidthRatio.changes(); +} + +void Settings::setThirdColumnWidth(int width) { + _thirdColumnWidth = width; +} + +int Settings::thirdColumnWidth() const { + return _thirdColumnWidth.current(); +} + +rpl::producer Settings::thirdColumnWidthChanges() const { + return _thirdColumnWidth.changes(); +} + void Settings::resetOnLastLogout() { _adaptiveForWide = true; _moderateModeEnabled = false; @@ -340,6 +405,24 @@ void Settings::resetOnLastLogout() { _dictionariesEnabled = std::vector(); _autoDownloadDictionaries = true; _mainMenuAccountsShown = false; + _tabbedSelectorSectionEnabled = false; // per-window + _floatPlayerColumn = Window::Column::Second; // per-window + _floatPlayerCorner = RectPart::TopRight; // per-window + _thirdSectionInfoEnabled = true; // per-window + _thirdSectionExtendedBy = -1; // per-window + _dialogsWidthRatio = DefaultDialogsWidthRatio(); // per-window + _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w + _tabbedReplacedWithInfo = false; // per-window +} + +bool Settings::ThirdColumnByDefault() { + return Platform::IsMacStoreBuild(); +} + +float64 Settings::DefaultDialogsWidthRatio() { + return ThirdColumnByDefault() + ? kDefaultBigDialogsWidthRatio + : kDefaultDialogsWidthRatio; } } // namespace Core diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 7bfcc1d179..907e37fd5a 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -10,11 +10,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_themes_embedded.h" enum class SendFilesWay; +enum class RectPart; namespace Ui { enum class InputSubmitSettings; } // namespace Ui +namespace Window { +enum class Column; +} // namespace Window + namespace Core { class Settings final { @@ -358,7 +363,47 @@ public: void setMainMenuAccountsShown(bool value) { _mainMenuAccountsShown = value; } + [[nodiscard]] bool tabbedSelectorSectionEnabled() const { + return _tabbedSelectorSectionEnabled; + } + void setTabbedSelectorSectionEnabled(bool enabled); + [[nodiscard]] bool thirdSectionInfoEnabled() const { + return _thirdSectionInfoEnabled; + } + void setThirdSectionInfoEnabled(bool enabled); + [[nodiscard]] rpl::producer thirdSectionInfoEnabledValue() const; + [[nodiscard]] int thirdSectionExtendedBy() const { + return _thirdSectionExtendedBy; + } + void setThirdSectionExtendedBy(int savedValue) { + _thirdSectionExtendedBy = savedValue; + } + [[nodiscard]] bool tabbedReplacedWithInfo() const { + return _tabbedReplacedWithInfo; + } + void setTabbedReplacedWithInfo(bool enabled); + [[nodiscard]] rpl::producer tabbedReplacedWithInfoValue() const; + void setFloatPlayerColumn(Window::Column column) { + _floatPlayerColumn = column; + } + [[nodiscard]] Window::Column floatPlayerColumn() const { + return _floatPlayerColumn; + } + void setFloatPlayerCorner(RectPart corner) { + _floatPlayerCorner = corner; + } + [[nodiscard]] RectPart floatPlayerCorner() const { + return _floatPlayerCorner; + } + void setDialogsWidthRatio(float64 ratio); + [[nodiscard]] float64 dialogsWidthRatio() const; + [[nodiscard]] rpl::producer dialogsWidthRatioChanges() const; + void setThirdColumnWidth(int width); + [[nodiscard]] int thirdColumnWidth() const; + [[nodiscard]] rpl::producer thirdColumnWidthChanges() const; + [[nodiscard]] static bool ThirdColumnByDefault(); + [[nodiscard]] float64 DefaultDialogsWidthRatio(); [[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) { return int(std::round(std::clamp(speed * 4., 2., 8.))) - 2; } @@ -369,16 +414,17 @@ public: void resetOnLastLogout(); private: + static constexpr auto kDefaultThirdColumnWidth = 0; + static constexpr auto kDefaultDialogsWidthRatio = 5. / 14; + static constexpr auto kDefaultBigDialogsWidthRatio = 0.275; + bool _adaptiveForWide = true; bool _moderateModeEnabled = false; - rpl::variable _songVolume = kDefaultVolume; rpl::variable _videoVolume = kDefaultVolume; - bool _askDownloadPath = false; rpl::variable _downloadPath; QByteArray _downloadPathBookmark; - bool _voiceMsgPlaybackDoubled = false; bool _soundNotify = true; bool _desktopNotify = true; @@ -391,20 +437,16 @@ private: bool _countUnreadMessages = true; rpl::variable _notifyAboutPinned = true; int _autoLock = 3600; - QString _callOutputDeviceID = u"default"_q; QString _callInputDeviceID = u"default"_q; int _callOutputVolume = 100; int _callInputVolume = 100; bool _callAudioDuckingEnabled = true; - Window::Theme::AccentColors _themesAccentColors; - bool _lastSeenWarningSeen = false; SendFilesWay _sendFilesWay; Ui::InputSubmitSettings _sendSubmitWay; base::flat_map _soundOverrides; - bool _exeLaunchWarning = true; bool _loopAnimatedStickers = true; rpl::variable _largeEmoji = true; @@ -417,6 +459,17 @@ private: rpl::variable> _dictionariesEnabled; rpl::variable _autoDownloadDictionaries = true; rpl::variable _mainMenuAccountsShown = false; + bool _tabbedSelectorSectionEnabled = false; // per-window + Window::Column _floatPlayerColumn; // per-window + RectPart _floatPlayerCorner; // per-window + bool _thirdSectionInfoEnabled = true; // per-window + rpl::event_stream _thirdSectionInfoEnabledValue; // per-window + int _thirdSectionExtendedBy = -1; // per-window + rpl::variable _dialogsWidthRatio; // per-window + rpl::variable _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w + + bool _tabbedReplacedWithInfo = false; // per-window + rpl::event_stream _tabbedReplacedWithInfoValue; // per-window float64 _rememberedSongVolume = kDefaultVolume; bool _rememberedSoundNotifyFromTray = false; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 11dc83b5b1..77fc7cedc5 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4154,11 +4154,11 @@ bool HistoryWidget::pushTabbedSelectorToThirdSection( if (!_tabbedPanel) { return true; } else if (!peer->canWrite()) { - session().settings().setTabbedReplacedWithInfo(true); + Core::App().settings().setTabbedReplacedWithInfo(true); controller()->showPeerInfo(peer, params.withThirdColumn()); return false; } - session().settings().setTabbedReplacedWithInfo(false); + Core::App().settings().setTabbedReplacedWithInfo(false); controller()->resizeForThirdSection(); controller()->showSection( ChatHelpers::TabbedMemento(), @@ -4198,8 +4198,8 @@ void HistoryWidget::toggleTabbedSelectorMode() { } if (_tabbedPanel) { if (controller()->canShowThirdSection() && !Adaptive::OneColumn()) { - session().settings().setTabbedSelectorSectionEnabled(true); - session().saveSettingsDelayed(); + Core::App().settings().setTabbedSelectorSectionEnabled(true); + Core::App().saveSettingsDelayed(); pushTabbedSelectorToThirdSection( _peer, Window::SectionShow::Way::ClearStack); diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index 49e04c63fa..58ae9df3d7 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -21,8 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/message_field.h" #include "chat_helpers/emoji_suggestions_widget.h" #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" @@ -347,11 +345,11 @@ bool ComposeControls::pushTabbedSelectorToThirdSection( if (!_tabbedPanel) { return true; //} else if (!_canSendMessages) { - // session().settings().setTabbedReplacedWithInfo(true); + // Core::App().settings().setTabbedReplacedWithInfo(true); // _window->showPeerInfo(_peer, params.withThirdColumn()); // return; } - session().settings().setTabbedReplacedWithInfo(false); + Core::App().settings().setTabbedReplacedWithInfo(false); _tabbedSelectorToggle->setColorOverrides( &st::historyAttachEmojiActive, &st::historyRecordVoiceFgActive, @@ -396,8 +394,8 @@ void ComposeControls::toggleTabbedSelectorMode() { } if (_tabbedPanel) { if (_window->canShowThirdSection() && !Adaptive::OneColumn()) { - session().settings().setTabbedSelectorSectionEnabled(true); - session().saveSettingsDelayed(); + Core::App().settings().setTabbedSelectorSectionEnabled(true); + Core::App().saveSettingsDelayed(); pushTabbedSelectorToThirdSection( _history->peer, Window::SectionShow::Way::ClearStack); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 76920c293b..ecd1add0b1 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -18,10 +18,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mainwindow.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "mtproto/mtproto_config.h" #include "lang/lang_keys.h" #include "core/shortcuts.h" +#include "core/application.h" +#include "core/core_settings.h" #include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" #include "ui/effects/radial_animation.h" @@ -137,17 +138,17 @@ TopBarWidget::TopBarWidget( }, lifetime()); rpl::combine( - session().settings().thirdSectionInfoEnabledValue(), - session().settings().tabbedReplacedWithInfoValue() - ) | rpl::start_with_next( - [this] { updateInfoToggleActive(); }, - lifetime()); + Core::App().settings().thirdSectionInfoEnabledValue(), + Core::App().settings().tabbedReplacedWithInfoValue() + ) | rpl::start_with_next([=] { + updateInfoToggleActive(); + }, lifetime()); rpl::single(rpl::empty_value()) | rpl::then( base::ObservableViewer(Global::RefConnectionTypeChanged()) - ) | rpl::start_with_next( - [=] { updateConnectingState(); }, - lifetime()); + ) | rpl::start_with_next([=] { + updateConnectingState(); + }, lifetime()); setCursor(style::cur_pointer); } @@ -252,13 +253,13 @@ void TopBarWidget::showMenu() { void TopBarWidget::toggleInfoSection() { if (Adaptive::ThreeColumn() - && (session().settings().thirdSectionInfoEnabled() - || session().settings().tabbedReplacedWithInfo())) { + && (Core::App().settings().thirdSectionInfoEnabled() + || Core::App().settings().tabbedReplacedWithInfo())) { _controller->closeThirdSection(); } else if (_activeChat.peer()) { if (_controller->canShowThirdSection()) { - session().settings().setThirdSectionInfoEnabled(true); - session().saveSettingsDelayed(); + Core::App().settings().setThirdSectionInfoEnabled(true); + Core::App().saveSettingsDelayed(); if (Adaptive::ThreeColumn()) { _controller->showSection( Info::Memento::Default(_activeChat.peer()), @@ -791,8 +792,8 @@ void TopBarWidget::updateUnreadBadge() { void TopBarWidget::updateInfoToggleActive() { auto infoThirdActive = Adaptive::ThreeColumn() - && (session().settings().thirdSectionInfoEnabled() - || session().settings().tabbedReplacedWithInfo()); + && (Core::App().settings().thirdSectionInfoEnabled() + || Core::App().settings().tabbedReplacedWithInfo()); auto iconOverride = infoThirdActive ? &st::topBarInfoActive : nullptr; diff --git a/Telegram/SourceFiles/main/main_session_settings.cpp b/Telegram/SourceFiles/main/main_session_settings.cpp index 8d8a8125e3..4a80fe280a 100644 --- a/Telegram/SourceFiles/main/main_session_settings.cpp +++ b/Telegram/SourceFiles/main/main_session_settings.cpp @@ -8,14 +8,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session_settings.h" #include "chat_helpers/tabbed_selector.h" -#include "window/section_widget.h" #include "ui/widgets/input_fields.h" +#include "window/section_widget.h" #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 { namespace { @@ -29,18 +28,9 @@ constexpr auto kMaxSavedPlaybackPositions = 16; SessionSettings::SessionSettings() : _selectorTab(ChatHelpers::SelectorTab::Emoji) -, _floatPlayerColumn(Window::Column::Second) -, _floatPlayerCorner(RectPart::TopRight) -, _dialogsWidthRatio(ThirdColumnByDefault() - ? kDefaultBigDialogsWidthRatio - : kDefaultDialogsWidthRatio) , _supportSwitch(Support::SwitchSettings::Next) { } -bool SessionSettings::ThirdColumnByDefault() { - return Platform::IsMacStoreBuild(); -} - QByteArray SessionSettings::serialize() const { const auto autoDownload = _autoDownload.serialize(); auto size = sizeof(qint32) * 38; @@ -56,21 +46,10 @@ QByteArray SessionSettings::serialize() const { stream.setVersion(QDataStream::Qt_5_1); stream << qint32(kVersionTag) << qint32(kVersion); stream << static_cast(_selectorTab); - stream << qint32(_tabbedSelectorSectionEnabled ? 1 : 0); - stream << qint32(_floatPlayerColumn); - stream << qint32(_floatPlayerCorner); stream << qint32(_groupStickersSectionHidden.size()); for (auto peerId : _groupStickersSectionHidden) { stream << quint64(peerId); } - stream << qint32(_thirdSectionInfoEnabled ? 1 : 0); - stream << qint32(_smallDialogsList ? 1 : 0); - stream << qint32(snap( - qRound(_dialogsWidthRatio.current() * 1000000), - 0, - 1000000)); - stream << qint32(_thirdColumnWidth.current()); - stream << qint32(_thirdSectionExtendedBy); stream << qint32(_supportSwitch); stream << qint32(_supportFixChatsOrder ? 1 : 0); stream << qint32(_supportTemplatesAutocomplete ? 1 : 0); @@ -106,17 +85,17 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { qint32 version = 0; qint32 selectorTab = static_cast(ChatHelpers::SelectorTab::Emoji); qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0; - qint32 tabbedSelectorSectionEnabled = 1; + qint32 appTabbedSelectorSectionEnabled = 1; qint32 legacyTabbedSelectorSectionTooltipShown = 0; - qint32 floatPlayerColumn = static_cast(Window::Column::Second); - qint32 floatPlayerCorner = static_cast(RectPart::TopRight); + qint32 appFloatPlayerColumn = static_cast(Window::Column::Second); + qint32 appFloatPlayerCorner = static_cast(RectPart::TopRight); base::flat_map appSoundOverrides; base::flat_set groupStickersSectionHidden; - qint32 thirdSectionInfoEnabled = 0; - qint32 smallDialogsList = 0; - float64 dialogsWidthRatio = _dialogsWidthRatio.current(); - int thirdColumnWidth = _thirdColumnWidth.current(); - int thirdSectionExtendedBy = _thirdSectionExtendedBy; + qint32 appThirdSectionInfoEnabled = 0; + qint32 legacySmallDialogsList = 0; + float64 appDialogsWidthRatio = app.dialogsWidthRatio(); + int appThirdColumnWidth = app.thirdColumnWidth(); + int appThirdSectionExtendedBy = app.thirdSectionExtendedBy(); qint32 appSendFilesWay = static_cast(app.sendFilesWay()); qint32 legacyCallsPeerToPeer = qint32(0); qint32 appSendSubmitWay = static_cast(app.sendSubmitWay()); @@ -157,11 +136,9 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { } if (version < 2) { stream >> appLastSeenWarningSeen; - } - if (!stream.atEnd()) { - stream >> tabbedSelectorSectionEnabled; - } - if (version < 2) { + if (!stream.atEnd()) { + stream >> appTabbedSelectorSectionEnabled; + } if (!stream.atEnd()) { auto count = qint32(0); stream >> count; @@ -169,6 +146,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { for (auto i = 0; i != count; ++i) { QString key, value; stream >> key >> value; + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for SessionSettings::addFromSerialized()")); + return; + } appSoundOverrides.emplace(key, value); } } @@ -176,9 +158,9 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> legacyTabbedSelectorSectionTooltipShown; } - } - if (!stream.atEnd()) { - stream >> floatPlayerColumn >> floatPlayerCorner; + if (!stream.atEnd()) { + stream >> appFloatPlayerColumn >> appFloatPlayerCorner; + } } if (!stream.atEnd()) { auto count = qint32(0); @@ -187,26 +169,31 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { for (auto i = 0; i != count; ++i) { quint64 peerId; stream >> peerId; + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for SessionSettings::addFromSerialized()")); + return; + } groupStickersSectionHidden.insert(peerId); } } } - if (!stream.atEnd()) { - stream >> thirdSectionInfoEnabled; - stream >> smallDialogsList; - } - if (!stream.atEnd()) { - qint32 value = 0; - stream >> value; - dialogsWidthRatio = snap(value / 1000000., 0., 1.); - - stream >> value; - thirdColumnWidth = value; - - stream >> value; - thirdSectionExtendedBy = value; - } if (version < 2) { + if (!stream.atEnd()) { + stream >> appThirdSectionInfoEnabled; + stream >> legacySmallDialogsList; + } + if (!stream.atEnd()) { + qint32 value = 0; + stream >> value; + appDialogsWidthRatio = snap(value / 1000000., 0., 1.); + + stream >> value; + appThirdColumnWidth = value; + + stream >> value; + appThirdSectionExtendedBy = value; + } if (!stream.atEnd()) { stream >> appSendFilesWay; } @@ -277,6 +264,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { quint64 documentId; qint64 time; stream >> documentId >> time; + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for SessionSettings::addFromSerialized()")); + return; + } mediaLastPlaybackPosition.emplace_back(documentId, time); } } @@ -295,6 +287,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { for (auto i = 0; i != count; ++i) { qint64 langId; stream >> langId; + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for SessionSettings::addFromSerialized()")); + return; + } appDictionariesEnabled.emplace_back(langId); } } @@ -311,6 +308,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { auto key = quint64(); auto value = qint32(); stream >> key >> value; + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for SessionSettings::addFromSerialized()")); + return; + } hiddenPinnedMessages.emplace(key, value); } } @@ -320,7 +322,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " - "Bad data for Main::SessionSettings::FromSerialized()")); + "Bad data for SessionSettings::addFromSerialized()")); return; } if (!autoDownload.isEmpty() @@ -340,29 +342,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { case ChatHelpers::SelectorTab::Stickers: case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break; } - _tabbedSelectorSectionEnabled = (tabbedSelectorSectionEnabled == 1); - auto uncheckedColumn = static_cast(floatPlayerColumn); - switch (uncheckedColumn) { - case Window::Column::First: - case Window::Column::Second: - case Window::Column::Third: _floatPlayerColumn = uncheckedColumn; break; - } - auto uncheckedCorner = static_cast(floatPlayerCorner); - switch (uncheckedCorner) { - case RectPart::TopLeft: - case RectPart::TopRight: - case RectPart::BottomLeft: - case RectPart::BottomRight: _floatPlayerCorner = uncheckedCorner; break; - } _groupStickersSectionHidden = std::move(groupStickersSectionHidden); - _thirdSectionInfoEnabled = thirdSectionInfoEnabled; - _smallDialogsList = smallDialogsList; - _dialogsWidthRatio = dialogsWidthRatio; - _thirdColumnWidth = thirdColumnWidth; - _thirdSectionExtendedBy = thirdSectionExtendedBy; - if (_thirdSectionInfoEnabled) { - _tabbedSelectorSectionEnabled = false; - } auto uncheckedSupportSwitch = static_cast( supportSwitch); switch (uncheckedSupportSwitch) { @@ -413,6 +393,24 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { app.setVideoPipGeometry(appVideoPipGeometry); app.setDictionariesEnabled(std::move(appDictionariesEnabled)); app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1); + app.setTabbedSelectorSectionEnabled(appTabbedSelectorSectionEnabled == 1); + auto uncheckedColumn = static_cast(appFloatPlayerColumn); + switch (uncheckedColumn) { + case Window::Column::First: + case Window::Column::Second: + case Window::Column::Third: app.setFloatPlayerColumn(uncheckedColumn); break; + } + auto uncheckedCorner = static_cast(appFloatPlayerCorner); + switch (uncheckedCorner) { + case RectPart::TopLeft: + case RectPart::TopRight: + case RectPart::BottomLeft: + case RectPart::BottomRight: app.setFloatPlayerCorner(uncheckedCorner); break; + } + app.setThirdSectionInfoEnabled(appThirdSectionInfoEnabled); + app.setDialogsWidthRatio(appDialogsWidthRatio); + app.setThirdColumnWidth(appThirdColumnWidth); + app.setThirdSectionExtendedBy(appThirdSectionExtendedBy); } } @@ -440,66 +438,6 @@ rpl::producer SessionSettings::supportAllSearchResultsValue() const { return _supportAllSearchResults.value(); } -void SessionSettings::setTabbedSelectorSectionEnabled(bool enabled) { - _tabbedSelectorSectionEnabled = enabled; - if (enabled) { - setThirdSectionInfoEnabled(false); - } - setTabbedReplacedWithInfo(false); -} - -rpl::producer SessionSettings::tabbedReplacedWithInfoValue() const { - return _tabbedReplacedWithInfoValue.events_starting_with( - tabbedReplacedWithInfo()); -} - -void SessionSettings::setThirdSectionInfoEnabled(bool enabled) { - if (_thirdSectionInfoEnabled != enabled) { - _thirdSectionInfoEnabled = enabled; - if (enabled) { - setTabbedSelectorSectionEnabled(false); - } - setTabbedReplacedWithInfo(false); - _thirdSectionInfoEnabledValue.fire_copy(enabled); - } -} - -rpl::producer SessionSettings::thirdSectionInfoEnabledValue() const { - return _thirdSectionInfoEnabledValue.events_starting_with( - thirdSectionInfoEnabled()); -} - -void SessionSettings::setTabbedReplacedWithInfo(bool enabled) { - if (_tabbedReplacedWithInfo != enabled) { - _tabbedReplacedWithInfo = enabled; - _tabbedReplacedWithInfoValue.fire_copy(enabled); - } -} - -void SessionSettings::setDialogsWidthRatio(float64 ratio) { - _dialogsWidthRatio = ratio; -} - -float64 SessionSettings::dialogsWidthRatio() const { - return _dialogsWidthRatio.current(); -} - -rpl::producer SessionSettings::dialogsWidthRatioChanges() const { - return _dialogsWidthRatio.changes(); -} - -void SessionSettings::setThirdColumnWidth(int width) { - _thirdColumnWidth = width; -} - -int SessionSettings::thirdColumnWidth() const { - return _thirdColumnWidth.current(); -} - -rpl::producer SessionSettings::thirdColumnWidthChanges() const { - return _thirdColumnWidth.changes(); -} - void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time) { auto &map = _mediaLastPlaybackPosition; const auto i = ranges::find( diff --git a/Telegram/SourceFiles/main/main_session_settings.h b/Telegram/SourceFiles/main/main_session_settings.h index fde64675c3..e8c8b15520 100644 --- a/Telegram/SourceFiles/main/main_session_settings.h +++ b/Telegram/SourceFiles/main/main_session_settings.h @@ -14,10 +14,6 @@ namespace Support { enum class SwitchSettings; } // namespace Support -namespace Window { -enum class Column; -} // namespace Window - namespace ChatHelpers { enum class SelectorTab; } // namespace ChatHelpers @@ -62,50 +58,6 @@ public: void setSelectorTab(ChatHelpers::SelectorTab tab) { _selectorTab = tab; } - [[nodiscard]] bool tabbedSelectorSectionEnabled() const { - return _tabbedSelectorSectionEnabled; - } - void setTabbedSelectorSectionEnabled(bool enabled); - [[nodiscard]] bool thirdSectionInfoEnabled() const { - return _thirdSectionInfoEnabled; - } - void setThirdSectionInfoEnabled(bool enabled); - [[nodiscard]] rpl::producer thirdSectionInfoEnabledValue() const; - [[nodiscard]] int thirdSectionExtendedBy() const { - return _thirdSectionExtendedBy; - } - void setThirdSectionExtendedBy(int savedValue) { - _thirdSectionExtendedBy = savedValue; - } - [[nodiscard]] bool tabbedReplacedWithInfo() const { - return _tabbedReplacedWithInfo; - } - void setTabbedReplacedWithInfo(bool enabled); - [[nodiscard]] rpl::producer tabbedReplacedWithInfoValue() const; - void setSmallDialogsList(bool enabled) { - _smallDialogsList = enabled; - } - [[nodiscard]] bool smallDialogsList() const { - return _smallDialogsList; - } - void setFloatPlayerColumn(Window::Column column) { - _floatPlayerColumn = column; - } - [[nodiscard]] Window::Column floatPlayerColumn() const { - return _floatPlayerColumn; - } - void setFloatPlayerCorner(RectPart corner) { - _floatPlayerCorner = corner; - } - [[nodiscard]] RectPart floatPlayerCorner() const { - return _floatPlayerCorner; - } - void setDialogsWidthRatio(float64 ratio); - [[nodiscard]] float64 dialogsWidthRatio() const; - [[nodiscard]] rpl::producer dialogsWidthRatioChanges() const; - void setThirdColumnWidth(int width); - [[nodiscard]] int thirdColumnWidth() const; - [[nodiscard]] rpl::producer thirdColumnWidthChanges() const; void setGroupStickersSectionHidden(PeerId peerId) { _groupStickersSectionHidden.insert(peerId); @@ -162,24 +114,11 @@ public: _dialogsFiltersEnabled = value; } - [[nodiscard]] static bool ThirdColumnByDefault(); - private: - 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; ChatHelpers::SelectorTab _selectorTab; // per-window - bool _tabbedSelectorSectionEnabled = false; // per-window - Window::Column _floatPlayerColumn; // per-window - RectPart _floatPlayerCorner; // per-window base::flat_set _groupStickersSectionHidden; - bool _thirdSectionInfoEnabled = true; // per-window - bool _smallDialogsList = false; // per-window - int _thirdSectionExtendedBy = -1; // per-window - rpl::variable _dialogsWidthRatio; // per-window - rpl::variable _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w bool _hadLegacyCallsPeerToPeerNobody = false; Data::AutoDownload::Full _autoDownload; rpl::variable _archiveCollapsed = false; @@ -196,10 +135,6 @@ private: = kDefaultSupportChatsLimitSlice; rpl::variable _supportAllSearchResults = false; - rpl::event_stream _thirdSectionInfoEnabledValue; - bool _tabbedReplacedWithInfo = false; - rpl::event_stream _tabbedReplacedWithInfoValue; - }; } // namespace Main diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 404b52276c..f181494e3c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -280,11 +280,11 @@ MainWidget::MainWidget( updateDialogsWidthAnimated(); }); rpl::merge( - session().settings().dialogsWidthRatioChanges() | rpl::to_empty, - session().settings().thirdColumnWidthChanges() | rpl::to_empty - ) | rpl::start_with_next( - [this] { updateControlsGeometry(); }, - lifetime()); + Core::App().settings().dialogsWidthRatioChanges() | rpl::to_empty, + Core::App().settings().thirdColumnWidthChanges() | rpl::to_empty + ) | rpl::start_with_next([=] { + updateControlsGeometry(); + }, lifetime()); session().changes().historyUpdates( Data::HistoryUpdate::Flag::MessageSent @@ -2107,7 +2107,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) { void MainWidget::updateControlsGeometry() { updateWindowAdaptiveLayout(); - if (session().settings().dialogsWidthRatio() > 0) { + if (Core::App().settings().dialogsWidthRatio() > 0) { _a_dialogsWidth.stop(); } if (!_a_dialogsWidth.animating()) { @@ -2122,9 +2122,9 @@ void MainWidget::updateControlsGeometry() { anim::activation::background); const auto active = _controller->activeChatCurrent(); if (const auto peer = active.peer()) { - if (session().settings().tabbedSelectorSectionEnabled()) { + if (Core::App().settings().tabbedSelectorSectionEnabled()) { _history->pushTabbedSelectorToThirdSection(peer, params); - } else if (session().settings().thirdSectionInfoEnabled()) { + } else if (Core::App().settings().thirdSectionInfoEnabled()) { _controller->showSection( Info::Memento::Default(peer), params.withThirdColumn()); @@ -2258,17 +2258,17 @@ void MainWidget::ensureFirstColumnResizeAreaCreated() { auto newRatio = (newWidth < st::columnMinimalWidthLeft / 2) ? 0. : float64(newWidth) / width(); - session().settings().setDialogsWidthRatio(newRatio); + Core::App().settings().setDialogsWidthRatio(newRatio); }; auto moveFinishedCallback = [=] { if (Adaptive::OneColumn()) { return; } - if (session().settings().dialogsWidthRatio() > 0) { - session().settings().setDialogsWidthRatio( + if (Core::App().settings().dialogsWidthRatio() > 0) { + Core::App().settings().setDialogsWidthRatio( float64(_dialogsWidth) / width()); } - session().saveSettings(); + Core::App().saveSettingsDelayed(); }; createResizeArea( _firstColumnResizeArea, @@ -2282,17 +2282,17 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() { } auto moveLeftCallback = [=](int globalLeft) { auto newWidth = mapToGlobal(QPoint(width(), 0)).x() - globalLeft; - session().settings().setThirdColumnWidth(newWidth); + Core::App().settings().setThirdColumnWidth(newWidth); }; auto moveFinishedCallback = [=] { if (!Adaptive::ThreeColumn() || !_thirdSection) { return; } - session().settings().setThirdColumnWidth(snap( - session().settings().thirdColumnWidth(), + Core::App().settings().setThirdColumnWidth(snap( + Core::App().settings().thirdColumnWidth(), st::columnMinimalWidthThird, st::columnMaximalWidthThird)); - session().saveSettings(); + Core::App().saveSettingsDelayed(); }; createResizeArea( _thirdColumnResizeArea, @@ -2301,12 +2301,12 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() { } void MainWidget::updateDialogsWidthAnimated() { - if (session().settings().dialogsWidthRatio() > 0) { + if (Core::App().settings().dialogsWidthRatio() > 0) { return; } auto dialogsWidth = _dialogsWidth; updateWindowAdaptiveLayout(); - if (!session().settings().dialogsWidthRatio() + if (!Core::App().settings().dialogsWidthRatio() && (_dialogsWidth != dialogsWidth || _a_dialogsWidth.animating())) { _dialogs->startWidthAnimation(); @@ -2353,6 +2353,7 @@ void MainWidget::updateThirdColumnToCurrentChat( _thirdSection.destroy(); } }; + auto &settings = Core::App().settings(); auto params = Window::SectionShow( Window::SectionShow::Way::ClearStack, anim::type::instant, @@ -2364,9 +2365,9 @@ void MainWidget::updateThirdColumnToCurrentChat( // Like in _controller->showPeerInfo() // if (Adaptive::ThreeColumn() - && !session().settings().thirdSectionInfoEnabled()) { - session().settings().setThirdSectionInfoEnabled(true); - session().saveSettingsDelayed(); + && !settings.thirdSectionInfoEnabled()) { + settings.setThirdSectionInfoEnabled(true); + Core::App().saveSettingsDelayed(); } _controller->showSection( @@ -2378,19 +2379,19 @@ void MainWidget::updateThirdColumnToCurrentChat( return _history->pushTabbedSelectorToThirdSection(peer, params); }; if (Adaptive::ThreeColumn() - && session().settings().tabbedSelectorSectionEnabled() + && settings.tabbedSelectorSectionEnabled() && key) { if (!canWrite) { switchInfoFast(); - session().settings().setTabbedSelectorSectionEnabled(true); - session().settings().setTabbedReplacedWithInfo(true); - } else if (session().settings().tabbedReplacedWithInfo() + settings.setTabbedSelectorSectionEnabled(true); + settings.setTabbedReplacedWithInfo(true); + } else if (settings.tabbedReplacedWithInfo() && key.history() && switchTabbedFast(key.history()->peer)) { - session().settings().setTabbedReplacedWithInfo(false); + settings.setTabbedReplacedWithInfo(false); } } else { - session().settings().setTabbedReplacedWithInfo(false); + settings.setTabbedReplacedWithInfo(false); if (!key) { if (_thirdSection) { _thirdSection.destroy(); @@ -2398,7 +2399,7 @@ void MainWidget::updateThirdColumnToCurrentChat( updateControlsGeometry(); } } else if (Adaptive::ThreeColumn() - && session().settings().thirdSectionInfoEnabled()) { + && settings.thirdSectionInfoEnabled()) { switchInfoFast(); } } @@ -2487,7 +2488,7 @@ void MainWidget::handleHistoryBack() { void MainWidget::updateWindowAdaptiveLayout() { auto layout = _controller->computeColumnLayout(); - auto dialogsWidthRatio = session().settings().dialogsWidthRatio(); + auto dialogsWidthRatio = Core::App().settings().dialogsWidthRatio(); // Check if we are in a single-column layout in a wide enough window // for the normal layout. If so, switch to the normal layout. @@ -2530,7 +2531,7 @@ void MainWidget::updateWindowAdaptiveLayout() { //} } - session().settings().setDialogsWidthRatio(dialogsWidthRatio); + Core::App().settings().setDialogsWidthRatio(dialogsWidthRatio); auto useSmallColumnWidth = !Adaptive::OneColumn() && !dialogsWidthRatio diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 17c2f77cee..6b1119a69c 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -284,8 +284,9 @@ void MainWindow::setupMain() { auto animated = (_intro || _passcodeLock); auto bg = animated ? grabInner() : QPixmap(); + auto created = object_ptr(bodyWidget(), sessionController()); clearWidgets(); - _main.create(bodyWidget(), sessionController()); + _main = std::move(created); if (_passcodeLock) { _main->hide(); } else { diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index aac8a94ccc..698169dfe9 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "history/view/media/history_view_media.h" #include "history/history_item.h" +#include "history/history.h" #include "history/view/history_view_element.h" #include "media/audio/media_audio.h" #include "media/streaming/media_streaming_instance.h" @@ -20,8 +21,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "window/window_session_controller.h" #include "window/section_widget.h" +#include "core/application.h" +#include "core/core_settings.h" #include "main/main_session.h" -#include "main/main_session_settings.h" #include "facades.h" #include "app.h" #include "styles/style_media_player.h" @@ -34,12 +36,10 @@ namespace Player { Float::Float( QWidget *parent, - not_null controller, not_null item, Fn toggleCallback, Fn draggedCallback) : RpWidget(parent) -, _controller(controller) , _item(item) , _toggleCallback(std::move(toggleCallback)) , _draggedCallback(std::move(draggedCallback)) { @@ -56,14 +56,14 @@ Float::Float( prepareShadow(); - _controller->session().data().itemRepaintRequest( + document->session().data().itemRepaintRequest( ) | rpl::start_with_next([this](auto item) { if (_item == item) { repaintItem(); } }, lifetime()); - _controller->session().data().itemRemoved( + document->session().data().itemRemoved( ) | rpl::start_with_next([this](auto item) { if (_item == item) { detach(); @@ -267,7 +267,6 @@ void Float::repaintItem() { template FloatController::Item::Item( not_null parent, - not_null controller, not_null item, ToggleCallback toggle, DraggedCallback dragged) @@ -276,7 +275,6 @@ FloatController::Item::Item( , corner(RectPart::TopRight) , widget( parent, - controller, item, [=, toggle = std::move(toggle)](bool visible) { toggle(this, visible); @@ -310,9 +308,6 @@ void FloatController::replaceDelegate(not_null delegate) { _delegate = delegate; _parent = _delegate->floatPlayerWidget(); - // Currently moving floats between windows is not supported. - Assert(_controller == _delegate->floatPlayerController()); - startDelegateHandling(); for (const auto &item : _items) { @@ -356,17 +351,23 @@ void FloatController::startDelegateHandling() { void FloatController::checkCurrent() { const auto state = Media::Player::instance()->current(AudioMsgId::Type::Voice); + const auto audio = state.audio(); const auto fullId = state.contextId(); const auto last = current(); if (last + && audio && !last->widget->detached() - && last->widget->item()->fullId() == fullId) { + && (&last->widget->item()->history()->session() == &audio->session()) + && (last->widget->item()->fullId() == fullId)) { return; } if (last) { last->widget->detach(); } - if (const auto item = _controller->session().data().message(fullId)) { + if (!audio) { + return; + } + if (const auto item = audio->session().data().message(fullId)) { if (const auto media = item->media()) { if (const auto document = media->document()) { if (document->isVideoMessage()) { @@ -380,7 +381,6 @@ void FloatController::checkCurrent() { void FloatController::create(not_null item) { _items.push_back(std::make_unique( _parent, - _controller, item, [=](not_null instance, bool visible) { instance->hiddenByWidget = !visible; @@ -389,8 +389,8 @@ void FloatController::create(not_null item) { [=](not_null instance, bool closed) { finishDrag(instance, closed); })); - current()->column = _controller->session().settings().floatPlayerColumn(); - current()->corner = _controller->session().settings().floatPlayerCorner(); + current()->column = Core::App().settings().floatPlayerColumn(); + current()->corner = Core::App().settings().floatPlayerCorner(); checkVisibility(); } @@ -563,8 +563,8 @@ void FloatController::updateColumnCorner(QPoint center) { auto size = _items.back()->widget->size(); auto min = INT_MAX; - auto column = _controller->session().settings().floatPlayerColumn(); - auto corner = _controller->session().settings().floatPlayerCorner(); + auto column = Core::App().settings().floatPlayerColumn(); + auto corner = Core::App().settings().floatPlayerCorner(); auto checkSection = [&]( not_null widget, Window::Column widgetColumn) { @@ -589,13 +589,14 @@ void FloatController::updateColumnCorner(QPoint center) { _delegate->floatPlayerEnumerateSections(checkSection); - if (_controller->session().settings().floatPlayerColumn() != column) { - _controller->session().settings().setFloatPlayerColumn(column); - _controller->session().saveSettingsDelayed(); + auto &settings = Core::App().settings(); + if (settings.floatPlayerColumn() != column) { + settings.setFloatPlayerColumn(column); + Core::App().saveSettingsDelayed(); } - if (_controller->session().settings().floatPlayerCorner() != corner) { - _controller->session().settings().setFloatPlayerCorner(corner); - _controller->session().saveSettingsDelayed(); + if (settings.floatPlayerCorner() != corner) { + settings.setFloatPlayerCorner(corner); + Core::App().saveSettingsDelayed(); } } @@ -607,8 +608,8 @@ void FloatController::finishDrag(not_null instance, bool closed) { instance->animationSide = getSide(center); } updateColumnCorner(center); - instance->column = _controller->session().settings().floatPlayerColumn(); - instance->corner = _controller->session().settings().floatPlayerCorner(); + instance->column = Core::App().settings().floatPlayerColumn(); + instance->corner = Core::App().settings().floatPlayerCorner(); instance->draggedAnimation.stop(); instance->draggedAnimation.start( diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index 8106f63bc1..51fbffff1a 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -37,7 +37,6 @@ class Float : public Ui::RpWidget, private base::Subscriber { public: Float( QWidget *parent, - not_null controller, not_null item, Fn toggleCallback, Fn draggedCallback); @@ -90,7 +89,6 @@ private: void finishDrag(bool closed); void pauseResume(); - not_null _controller; HistoryItem *_item = nullptr; Fn _toggleCallback; @@ -194,7 +192,6 @@ private: template Item( not_null parent, - not_null controller, not_null item, ToggleCallback toggle, DraggedCallback dragged); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 50ffccaabe..b5ce08ff92 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -375,7 +375,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - context.sessionSettings().setDialogsWidthRatio(v / 1000000.); + Core::App().settings().setDialogsWidthRatio(v / 1000000.); } break; case dbiLastSeenWarningSeenOld: { diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 7249f8f779..ff9b77f178 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -324,10 +324,10 @@ void MainWindow::initSize() { ? primaryScreen->availableGeometry() : QRect(0, 0, st::windowDefaultWidth, st::windowDefaultHeight); bool maximized = false; - const auto initialWidth = Main::SessionSettings::ThirdColumnByDefault() + const auto initialWidth = Core::Settings::ThirdColumnByDefault() ? st::windowBigDefaultWidth : st::windowDefaultWidth; - const auto initialHeight = Main::SessionSettings::ThirdColumnByDefault() + const auto initialHeight = Core::Settings::ThirdColumnByDefault() ? st::windowBigDefaultHeight : st::windowDefaultHeight; auto geometry = QRect( diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 2eefb268a4..fbbacdd83f 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -258,9 +258,8 @@ bool Filler::showInfo() { return true; } else if (!Adaptive::ThreeColumn()) { return true; - } else if ( - !_peer->session().settings().thirdSectionInfoEnabled() && - !_peer->session().settings().tabbedReplacedWithInfo()) { + } else if (!Core::App().settings().thirdSectionInfoEnabled() + && !Core::App().settings().tabbedReplacedWithInfo()) { return true; } return false; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index f32dd939c8..69e1d2aa58 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "passport/passport_form_controller.h" #include "chat_helpers/tabbed_selector.h" #include "core/shortcuts.h" +#include "core/application.h" +#include "core/core_settings.h" #include "base/unixtime.h" #include "boxes/calendar_box.h" #include "boxes/sticker_set_box.h" // requestAttachedStickerSets. @@ -81,9 +83,9 @@ void SessionNavigation::showPeerInfo( not_null peer, const SectionShow ¶ms) { //if (Adaptive::ThreeColumn() - // && !_session->settings().thirdSectionInfoEnabled()) { - // _session->settings().setThirdSectionInfoEnabled(true); - // _session->saveSettingsDelayed(); + // && !Core::App().settings().thirdSectionInfoEnabled()) { + // Core::App().settings().setThirdSectionInfoEnabled(true); + // Core::App().saveSettingsDelayed(); //} showSection(Info::Memento(peer), params); } @@ -451,8 +453,8 @@ auto SessionController::computeColumnLayout() const -> ColumnLayout { if (bodyWidth < minimalThreeColumnWidth()) { return true; } - if (!session().settings().tabbedSelectorSectionEnabled() - && !session().settings().thirdSectionInfoEnabled()) { + if (!Core::App().settings().tabbedSelectorSectionEnabled() + && !Core::App().settings().thirdSectionInfoEnabled()) { return true; } return false; @@ -482,14 +484,14 @@ auto SessionController::computeColumnLayout() const -> ColumnLayout { } int SessionController::countDialogsWidthFromRatio(int bodyWidth) const { - auto result = qRound(bodyWidth * session().settings().dialogsWidthRatio()); + auto result = qRound(bodyWidth * Core::App().settings().dialogsWidthRatio()); accumulate_max(result, st::columnMinimalWidthLeft); // accumulate_min(result, st::columnMaximalWidthLeft); return result; } int SessionController::countThirdColumnWidthFromRatio(int bodyWidth) const { - auto result = session().settings().thirdColumnWidth(); + auto result = Core::App().settings().thirdColumnWidth(); accumulate_max(result, st::columnMinimalWidthThird); accumulate_min(result, st::columnMaximalWidthThird); return result; @@ -540,13 +542,14 @@ void SessionController::resizeForThirdSection() { return; } + auto &settings = Core::App().settings(); auto layout = computeColumnLayout(); auto tabbedSelectorSectionEnabled = - session().settings().tabbedSelectorSectionEnabled(); + settings.tabbedSelectorSectionEnabled(); auto thirdSectionInfoEnabled = - session().settings().thirdSectionInfoEnabled(); - session().settings().setTabbedSelectorSectionEnabled(false); - session().settings().setThirdSectionInfoEnabled(false); + settings.thirdSectionInfoEnabled(); + settings.setTabbedSelectorSectionEnabled(false); + settings.setThirdSectionInfoEnabled(false); auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth); auto minimal = st::columnMinimalWidthThird; @@ -567,46 +570,47 @@ void SessionController::resizeForThirdSection() { return widget()->tryToExtendWidthBy(minimal); }(); if (extendedBy) { - if (extendBy != session().settings().thirdColumnWidth()) { - session().settings().setThirdColumnWidth(extendBy); + if (extendBy != settings.thirdColumnWidth()) { + settings.setThirdColumnWidth(extendBy); } auto newBodyWidth = layout.bodyWidth + extendedBy; - auto currentRatio = session().settings().dialogsWidthRatio(); - session().settings().setDialogsWidthRatio( + auto currentRatio = settings.dialogsWidthRatio(); + settings.setDialogsWidthRatio( (currentRatio * layout.bodyWidth) / newBodyWidth); } auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy; - session().settings().setThirdSectionExtendedBy(savedValue); + settings.setThirdSectionExtendedBy(savedValue); - session().settings().setTabbedSelectorSectionEnabled( + settings.setTabbedSelectorSectionEnabled( tabbedSelectorSectionEnabled); - session().settings().setThirdSectionInfoEnabled( + settings.setThirdSectionInfoEnabled( thirdSectionInfoEnabled); } void SessionController::closeThirdSection() { + auto &settings = Core::App().settings(); auto newWindowSize = widget()->size(); auto layout = computeColumnLayout(); if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) { auto noResize = widget()->isFullScreen() || widget()->isMaximized(); - auto savedValue = session().settings().thirdSectionExtendedBy(); + auto savedValue = settings.thirdSectionExtendedBy(); auto extendedBy = (savedValue == -1) ? layout.thirdWidth : savedValue; auto newBodyWidth = noResize ? layout.bodyWidth : (layout.bodyWidth - extendedBy); - auto currentRatio = session().settings().dialogsWidthRatio(); - session().settings().setDialogsWidthRatio( + auto currentRatio = settings.dialogsWidthRatio(); + settings.setDialogsWidthRatio( (currentRatio * layout.bodyWidth) / newBodyWidth); newWindowSize = QSize( widget()->width() + (newBodyWidth - layout.bodyWidth), widget()->height()); } - session().settings().setTabbedSelectorSectionEnabled(false); - session().settings().setThirdSectionInfoEnabled(false); - session().saveSettingsDelayed(); + settings.setTabbedSelectorSectionEnabled(false); + settings.setThirdSectionInfoEnabled(false); + Core::App().saveSettingsDelayed(); if (widget()->size() != newWindowSize) { widget()->resize(newWindowSize); } else {