Move some more settings to Core::App.

This commit is contained in:
John Preston 2020-06-25 16:16:09 +04:00
parent 90a9cb4f8d
commit 5d6a494934
15 changed files with 334 additions and 323 deletions

View file

@ -11,13 +11,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "storage/serialize_common.h" #include "storage/serialize_common.h"
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
#include "window/section_widget.h"
#include "base/platform/base_platform_info.h"
#include "facades.h" #include "facades.h"
namespace Core { namespace Core {
Settings::Settings() Settings::Settings()
: _sendFilesWay(SendFilesWay::Album) : _sendFilesWay(SendFilesWay::Album)
, _sendSubmitWay(Ui::InputSubmitSettings::Enter) { , _sendSubmitWay(Ui::InputSubmitSettings::Enter)
, _floatPlayerColumn(Window::Column::Second)
, _floatPlayerCorner(RectPart::TopRight)
, _dialogsWidthRatio(DefaultDialogsWidthRatio()) {
} }
QByteArray Settings::serialize() const { QByteArray Settings::serialize() const {
@ -291,6 +296,66 @@ QString Settings::getSoundPath(const QString &key) const {
return qsl(":/sounds/") + key + qsl(".mp3"); return qsl(":/sounds/") + key + qsl(".mp3");
} }
void Settings::setTabbedSelectorSectionEnabled(bool enabled) {
_tabbedSelectorSectionEnabled = enabled;
if (enabled) {
setThirdSectionInfoEnabled(false);
}
setTabbedReplacedWithInfo(false);
}
rpl::producer<bool> 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<bool> 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<float64> Settings::dialogsWidthRatioChanges() const {
return _dialogsWidthRatio.changes();
}
void Settings::setThirdColumnWidth(int width) {
_thirdColumnWidth = width;
}
int Settings::thirdColumnWidth() const {
return _thirdColumnWidth.current();
}
rpl::producer<int> Settings::thirdColumnWidthChanges() const {
return _thirdColumnWidth.changes();
}
void Settings::resetOnLastLogout() { void Settings::resetOnLastLogout() {
_adaptiveForWide = true; _adaptiveForWide = true;
_moderateModeEnabled = false; _moderateModeEnabled = false;
@ -340,6 +405,24 @@ void Settings::resetOnLastLogout() {
_dictionariesEnabled = std::vector<int>(); _dictionariesEnabled = std::vector<int>();
_autoDownloadDictionaries = true; _autoDownloadDictionaries = true;
_mainMenuAccountsShown = false; _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 } // namespace Core

View file

@ -10,11 +10,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/themes/window_themes_embedded.h" #include "window/themes/window_themes_embedded.h"
enum class SendFilesWay; enum class SendFilesWay;
enum class RectPart;
namespace Ui { namespace Ui {
enum class InputSubmitSettings; enum class InputSubmitSettings;
} // namespace Ui } // namespace Ui
namespace Window {
enum class Column;
} // namespace Window
namespace Core { namespace Core {
class Settings final { class Settings final {
@ -358,7 +363,47 @@ public:
void setMainMenuAccountsShown(bool value) { void setMainMenuAccountsShown(bool value) {
_mainMenuAccountsShown = 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<bool> 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<bool> 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<float64> dialogsWidthRatioChanges() const;
void setThirdColumnWidth(int width);
[[nodiscard]] int thirdColumnWidth() const;
[[nodiscard]] rpl::producer<int> thirdColumnWidthChanges() const;
[[nodiscard]] static bool ThirdColumnByDefault();
[[nodiscard]] float64 DefaultDialogsWidthRatio();
[[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) { [[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) {
return int(std::round(std::clamp(speed * 4., 2., 8.))) - 2; return int(std::round(std::clamp(speed * 4., 2., 8.))) - 2;
} }
@ -369,16 +414,17 @@ public:
void resetOnLastLogout(); void resetOnLastLogout();
private: private:
static constexpr auto kDefaultThirdColumnWidth = 0;
static constexpr auto kDefaultDialogsWidthRatio = 5. / 14;
static constexpr auto kDefaultBigDialogsWidthRatio = 0.275;
bool _adaptiveForWide = true; bool _adaptiveForWide = true;
bool _moderateModeEnabled = false; bool _moderateModeEnabled = false;
rpl::variable<float64> _songVolume = kDefaultVolume; rpl::variable<float64> _songVolume = kDefaultVolume;
rpl::variable<float64> _videoVolume = kDefaultVolume; rpl::variable<float64> _videoVolume = kDefaultVolume;
bool _askDownloadPath = false; bool _askDownloadPath = false;
rpl::variable<QString> _downloadPath; rpl::variable<QString> _downloadPath;
QByteArray _downloadPathBookmark; QByteArray _downloadPathBookmark;
bool _voiceMsgPlaybackDoubled = false; bool _voiceMsgPlaybackDoubled = false;
bool _soundNotify = true; bool _soundNotify = true;
bool _desktopNotify = true; bool _desktopNotify = true;
@ -391,20 +437,16 @@ private:
bool _countUnreadMessages = true; bool _countUnreadMessages = true;
rpl::variable<bool> _notifyAboutPinned = true; rpl::variable<bool> _notifyAboutPinned = true;
int _autoLock = 3600; int _autoLock = 3600;
QString _callOutputDeviceID = u"default"_q; QString _callOutputDeviceID = u"default"_q;
QString _callInputDeviceID = u"default"_q; QString _callInputDeviceID = u"default"_q;
int _callOutputVolume = 100; int _callOutputVolume = 100;
int _callInputVolume = 100; int _callInputVolume = 100;
bool _callAudioDuckingEnabled = true; bool _callAudioDuckingEnabled = true;
Window::Theme::AccentColors _themesAccentColors; Window::Theme::AccentColors _themesAccentColors;
bool _lastSeenWarningSeen = false; bool _lastSeenWarningSeen = false;
SendFilesWay _sendFilesWay; SendFilesWay _sendFilesWay;
Ui::InputSubmitSettings _sendSubmitWay; Ui::InputSubmitSettings _sendSubmitWay;
base::flat_map<QString, QString> _soundOverrides; base::flat_map<QString, QString> _soundOverrides;
bool _exeLaunchWarning = true; bool _exeLaunchWarning = true;
bool _loopAnimatedStickers = true; bool _loopAnimatedStickers = true;
rpl::variable<bool> _largeEmoji = true; rpl::variable<bool> _largeEmoji = true;
@ -417,6 +459,17 @@ private:
rpl::variable<std::vector<int>> _dictionariesEnabled; rpl::variable<std::vector<int>> _dictionariesEnabled;
rpl::variable<bool> _autoDownloadDictionaries = true; rpl::variable<bool> _autoDownloadDictionaries = true;
rpl::variable<bool> _mainMenuAccountsShown = false; rpl::variable<bool> _mainMenuAccountsShown = false;
bool _tabbedSelectorSectionEnabled = false; // per-window
Window::Column _floatPlayerColumn; // per-window
RectPart _floatPlayerCorner; // per-window
bool _thirdSectionInfoEnabled = true; // per-window
rpl::event_stream<bool> _thirdSectionInfoEnabledValue; // per-window
int _thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> _dialogsWidthRatio; // per-window
rpl::variable<int> _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
bool _tabbedReplacedWithInfo = false; // per-window
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
float64 _rememberedSongVolume = kDefaultVolume; float64 _rememberedSongVolume = kDefaultVolume;
bool _rememberedSoundNotifyFromTray = false; bool _rememberedSoundNotifyFromTray = false;

View file

@ -4154,11 +4154,11 @@ bool HistoryWidget::pushTabbedSelectorToThirdSection(
if (!_tabbedPanel) { if (!_tabbedPanel) {
return true; return true;
} else if (!peer->canWrite()) { } else if (!peer->canWrite()) {
session().settings().setTabbedReplacedWithInfo(true); Core::App().settings().setTabbedReplacedWithInfo(true);
controller()->showPeerInfo(peer, params.withThirdColumn()); controller()->showPeerInfo(peer, params.withThirdColumn());
return false; return false;
} }
session().settings().setTabbedReplacedWithInfo(false); Core::App().settings().setTabbedReplacedWithInfo(false);
controller()->resizeForThirdSection(); controller()->resizeForThirdSection();
controller()->showSection( controller()->showSection(
ChatHelpers::TabbedMemento(), ChatHelpers::TabbedMemento(),
@ -4198,8 +4198,8 @@ void HistoryWidget::toggleTabbedSelectorMode() {
} }
if (_tabbedPanel) { if (_tabbedPanel) {
if (controller()->canShowThirdSection() && !Adaptive::OneColumn()) { if (controller()->canShowThirdSection() && !Adaptive::OneColumn()) {
session().settings().setTabbedSelectorSectionEnabled(true); Core::App().settings().setTabbedSelectorSectionEnabled(true);
session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
pushTabbedSelectorToThirdSection( pushTabbedSelectorToThirdSection(
_peer, _peer,
Window::SectionShow::Way::ClearStack); Window::SectionShow::Way::ClearStack);

View file

@ -21,8 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/message_field.h" #include "chat_helpers/message_field.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "inline_bots/inline_results_widget.h" #include "inline_bots/inline_results_widget.h"
@ -347,11 +345,11 @@ bool ComposeControls::pushTabbedSelectorToThirdSection(
if (!_tabbedPanel) { if (!_tabbedPanel) {
return true; return true;
//} else if (!_canSendMessages) { //} else if (!_canSendMessages) {
// session().settings().setTabbedReplacedWithInfo(true); // Core::App().settings().setTabbedReplacedWithInfo(true);
// _window->showPeerInfo(_peer, params.withThirdColumn()); // _window->showPeerInfo(_peer, params.withThirdColumn());
// return; // return;
} }
session().settings().setTabbedReplacedWithInfo(false); Core::App().settings().setTabbedReplacedWithInfo(false);
_tabbedSelectorToggle->setColorOverrides( _tabbedSelectorToggle->setColorOverrides(
&st::historyAttachEmojiActive, &st::historyAttachEmojiActive,
&st::historyRecordVoiceFgActive, &st::historyRecordVoiceFgActive,
@ -396,8 +394,8 @@ void ComposeControls::toggleTabbedSelectorMode() {
} }
if (_tabbedPanel) { if (_tabbedPanel) {
if (_window->canShowThirdSection() && !Adaptive::OneColumn()) { if (_window->canShowThirdSection() && !Adaptive::OneColumn()) {
session().settings().setTabbedSelectorSectionEnabled(true); Core::App().settings().setTabbedSelectorSectionEnabled(true);
session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
pushTabbedSelectorToThirdSection( pushTabbedSelectorToThirdSection(
_history->peer, _history->peer,
Window::SectionShow::Way::ClearStack); Window::SectionShow::Way::ClearStack);

View file

@ -18,10 +18,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h" #include "mainwidget.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "core/shortcuts.h" #include "core/shortcuts.h"
#include "core/application.h"
#include "core/core_settings.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/dropdown_menu.h" #include "ui/widgets/dropdown_menu.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
@ -137,17 +138,17 @@ TopBarWidget::TopBarWidget(
}, lifetime()); }, lifetime());
rpl::combine( rpl::combine(
session().settings().thirdSectionInfoEnabledValue(), Core::App().settings().thirdSectionInfoEnabledValue(),
session().settings().tabbedReplacedWithInfoValue() Core::App().settings().tabbedReplacedWithInfoValue()
) | rpl::start_with_next( ) | rpl::start_with_next([=] {
[this] { updateInfoToggleActive(); }, updateInfoToggleActive();
lifetime()); }, lifetime());
rpl::single(rpl::empty_value()) | rpl::then( rpl::single(rpl::empty_value()) | rpl::then(
base::ObservableViewer(Global::RefConnectionTypeChanged()) base::ObservableViewer(Global::RefConnectionTypeChanged())
) | rpl::start_with_next( ) | rpl::start_with_next([=] {
[=] { updateConnectingState(); }, updateConnectingState();
lifetime()); }, lifetime());
setCursor(style::cur_pointer); setCursor(style::cur_pointer);
} }
@ -252,13 +253,13 @@ void TopBarWidget::showMenu() {
void TopBarWidget::toggleInfoSection() { void TopBarWidget::toggleInfoSection() {
if (Adaptive::ThreeColumn() if (Adaptive::ThreeColumn()
&& (session().settings().thirdSectionInfoEnabled() && (Core::App().settings().thirdSectionInfoEnabled()
|| session().settings().tabbedReplacedWithInfo())) { || Core::App().settings().tabbedReplacedWithInfo())) {
_controller->closeThirdSection(); _controller->closeThirdSection();
} else if (_activeChat.peer()) { } else if (_activeChat.peer()) {
if (_controller->canShowThirdSection()) { if (_controller->canShowThirdSection()) {
session().settings().setThirdSectionInfoEnabled(true); Core::App().settings().setThirdSectionInfoEnabled(true);
session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
if (Adaptive::ThreeColumn()) { if (Adaptive::ThreeColumn()) {
_controller->showSection( _controller->showSection(
Info::Memento::Default(_activeChat.peer()), Info::Memento::Default(_activeChat.peer()),
@ -791,8 +792,8 @@ void TopBarWidget::updateUnreadBadge() {
void TopBarWidget::updateInfoToggleActive() { void TopBarWidget::updateInfoToggleActive() {
auto infoThirdActive = Adaptive::ThreeColumn() auto infoThirdActive = Adaptive::ThreeColumn()
&& (session().settings().thirdSectionInfoEnabled() && (Core::App().settings().thirdSectionInfoEnabled()
|| session().settings().tabbedReplacedWithInfo()); || Core::App().settings().tabbedReplacedWithInfo());
auto iconOverride = infoThirdActive auto iconOverride = infoThirdActive
? &st::topBarInfoActive ? &st::topBarInfoActive
: nullptr; : nullptr;

View file

@ -8,14 +8,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "chat_helpers/tabbed_selector.h" #include "chat_helpers/tabbed_selector.h"
#include "window/section_widget.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "window/section_widget.h"
#include "support/support_common.h" #include "support/support_common.h"
#include "storage/serialize_common.h" #include "storage/serialize_common.h"
#include "boxes/send_files_box.h" #include "boxes/send_files_box.h"
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "base/platform/base_platform_info.h"
namespace Main { namespace Main {
namespace { namespace {
@ -29,18 +28,9 @@ constexpr auto kMaxSavedPlaybackPositions = 16;
SessionSettings::SessionSettings() SessionSettings::SessionSettings()
: _selectorTab(ChatHelpers::SelectorTab::Emoji) : _selectorTab(ChatHelpers::SelectorTab::Emoji)
, _floatPlayerColumn(Window::Column::Second)
, _floatPlayerCorner(RectPart::TopRight)
, _dialogsWidthRatio(ThirdColumnByDefault()
? kDefaultBigDialogsWidthRatio
: kDefaultDialogsWidthRatio)
, _supportSwitch(Support::SwitchSettings::Next) { , _supportSwitch(Support::SwitchSettings::Next) {
} }
bool SessionSettings::ThirdColumnByDefault() {
return Platform::IsMacStoreBuild();
}
QByteArray SessionSettings::serialize() const { QByteArray SessionSettings::serialize() const {
const auto autoDownload = _autoDownload.serialize(); const auto autoDownload = _autoDownload.serialize();
auto size = sizeof(qint32) * 38; auto size = sizeof(qint32) * 38;
@ -56,21 +46,10 @@ QByteArray SessionSettings::serialize() const {
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream << qint32(kVersionTag) << qint32(kVersion); stream << qint32(kVersionTag) << qint32(kVersion);
stream << static_cast<qint32>(_selectorTab); stream << static_cast<qint32>(_selectorTab);
stream << qint32(_tabbedSelectorSectionEnabled ? 1 : 0);
stream << qint32(_floatPlayerColumn);
stream << qint32(_floatPlayerCorner);
stream << qint32(_groupStickersSectionHidden.size()); stream << qint32(_groupStickersSectionHidden.size());
for (auto peerId : _groupStickersSectionHidden) { for (auto peerId : _groupStickersSectionHidden) {
stream << quint64(peerId); 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(_supportSwitch);
stream << qint32(_supportFixChatsOrder ? 1 : 0); stream << qint32(_supportFixChatsOrder ? 1 : 0);
stream << qint32(_supportTemplatesAutocomplete ? 1 : 0); stream << qint32(_supportTemplatesAutocomplete ? 1 : 0);
@ -106,17 +85,17 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
qint32 version = 0; qint32 version = 0;
qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji); qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0; qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0;
qint32 tabbedSelectorSectionEnabled = 1; qint32 appTabbedSelectorSectionEnabled = 1;
qint32 legacyTabbedSelectorSectionTooltipShown = 0; qint32 legacyTabbedSelectorSectionTooltipShown = 0;
qint32 floatPlayerColumn = static_cast<qint32>(Window::Column::Second); qint32 appFloatPlayerColumn = static_cast<qint32>(Window::Column::Second);
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight); qint32 appFloatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
base::flat_map<QString, QString> appSoundOverrides; base::flat_map<QString, QString> appSoundOverrides;
base::flat_set<PeerId> groupStickersSectionHidden; base::flat_set<PeerId> groupStickersSectionHidden;
qint32 thirdSectionInfoEnabled = 0; qint32 appThirdSectionInfoEnabled = 0;
qint32 smallDialogsList = 0; qint32 legacySmallDialogsList = 0;
float64 dialogsWidthRatio = _dialogsWidthRatio.current(); float64 appDialogsWidthRatio = app.dialogsWidthRatio();
int thirdColumnWidth = _thirdColumnWidth.current(); int appThirdColumnWidth = app.thirdColumnWidth();
int thirdSectionExtendedBy = _thirdSectionExtendedBy; int appThirdSectionExtendedBy = app.thirdSectionExtendedBy();
qint32 appSendFilesWay = static_cast<qint32>(app.sendFilesWay()); qint32 appSendFilesWay = static_cast<qint32>(app.sendFilesWay());
qint32 legacyCallsPeerToPeer = qint32(0); qint32 legacyCallsPeerToPeer = qint32(0);
qint32 appSendSubmitWay = static_cast<qint32>(app.sendSubmitWay()); qint32 appSendSubmitWay = static_cast<qint32>(app.sendSubmitWay());
@ -157,11 +136,9 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
} }
if (version < 2) { if (version < 2) {
stream >> appLastSeenWarningSeen; stream >> appLastSeenWarningSeen;
}
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> tabbedSelectorSectionEnabled; stream >> appTabbedSelectorSectionEnabled;
} }
if (version < 2) {
if (!stream.atEnd()) { if (!stream.atEnd()) {
auto count = qint32(0); auto count = qint32(0);
stream >> count; stream >> count;
@ -169,6 +146,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
for (auto i = 0; i != count; ++i) { for (auto i = 0; i != count; ++i) {
QString key, value; QString key, value;
stream >> key >> value; stream >> key >> value;
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
return;
}
appSoundOverrides.emplace(key, value); appSoundOverrides.emplace(key, value);
} }
} }
@ -176,9 +158,9 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> legacyTabbedSelectorSectionTooltipShown; stream >> legacyTabbedSelectorSectionTooltipShown;
} }
}
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> floatPlayerColumn >> floatPlayerCorner; stream >> appFloatPlayerColumn >> appFloatPlayerCorner;
}
} }
if (!stream.atEnd()) { if (!stream.atEnd()) {
auto count = qint32(0); auto count = qint32(0);
@ -187,26 +169,31 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
for (auto i = 0; i != count; ++i) { for (auto i = 0; i != count; ++i) {
quint64 peerId; quint64 peerId;
stream >> peerId; stream >> peerId;
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
return;
}
groupStickersSectionHidden.insert(peerId); groupStickersSectionHidden.insert(peerId);
} }
} }
} }
if (version < 2) {
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> thirdSectionInfoEnabled; stream >> appThirdSectionInfoEnabled;
stream >> smallDialogsList; stream >> legacySmallDialogsList;
} }
if (!stream.atEnd()) { if (!stream.atEnd()) {
qint32 value = 0; qint32 value = 0;
stream >> value; stream >> value;
dialogsWidthRatio = snap(value / 1000000., 0., 1.); appDialogsWidthRatio = snap(value / 1000000., 0., 1.);
stream >> value; stream >> value;
thirdColumnWidth = value; appThirdColumnWidth = value;
stream >> value; stream >> value;
thirdSectionExtendedBy = value; appThirdSectionExtendedBy = value;
} }
if (version < 2) {
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> appSendFilesWay; stream >> appSendFilesWay;
} }
@ -277,6 +264,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
quint64 documentId; quint64 documentId;
qint64 time; qint64 time;
stream >> documentId >> time; stream >> documentId >> time;
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
return;
}
mediaLastPlaybackPosition.emplace_back(documentId, time); mediaLastPlaybackPosition.emplace_back(documentId, time);
} }
} }
@ -295,6 +287,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
for (auto i = 0; i != count; ++i) { for (auto i = 0; i != count; ++i) {
qint64 langId; qint64 langId;
stream >> langId; stream >> langId;
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
return;
}
appDictionariesEnabled.emplace_back(langId); appDictionariesEnabled.emplace_back(langId);
} }
} }
@ -311,6 +308,11 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
auto key = quint64(); auto key = quint64();
auto value = qint32(); auto value = qint32();
stream >> key >> value; stream >> key >> value;
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
return;
}
hiddenPinnedMessages.emplace(key, value); hiddenPinnedMessages.emplace(key, value);
} }
} }
@ -320,7 +322,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
} }
if (stream.status() != QDataStream::Ok) { if (stream.status() != QDataStream::Ok) {
LOG(("App Error: " LOG(("App Error: "
"Bad data for Main::SessionSettings::FromSerialized()")); "Bad data for SessionSettings::addFromSerialized()"));
return; return;
} }
if (!autoDownload.isEmpty() if (!autoDownload.isEmpty()
@ -340,29 +342,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
case ChatHelpers::SelectorTab::Stickers: case ChatHelpers::SelectorTab::Stickers:
case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break; case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break;
} }
_tabbedSelectorSectionEnabled = (tabbedSelectorSectionEnabled == 1);
auto uncheckedColumn = static_cast<Window::Column>(floatPlayerColumn);
switch (uncheckedColumn) {
case Window::Column::First:
case Window::Column::Second:
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: _floatPlayerCorner = uncheckedCorner; break;
}
_groupStickersSectionHidden = std::move(groupStickersSectionHidden); _groupStickersSectionHidden = std::move(groupStickersSectionHidden);
_thirdSectionInfoEnabled = thirdSectionInfoEnabled;
_smallDialogsList = smallDialogsList;
_dialogsWidthRatio = dialogsWidthRatio;
_thirdColumnWidth = thirdColumnWidth;
_thirdSectionExtendedBy = thirdSectionExtendedBy;
if (_thirdSectionInfoEnabled) {
_tabbedSelectorSectionEnabled = false;
}
auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>( auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>(
supportSwitch); supportSwitch);
switch (uncheckedSupportSwitch) { switch (uncheckedSupportSwitch) {
@ -413,6 +393,24 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
app.setVideoPipGeometry(appVideoPipGeometry); app.setVideoPipGeometry(appVideoPipGeometry);
app.setDictionariesEnabled(std::move(appDictionariesEnabled)); app.setDictionariesEnabled(std::move(appDictionariesEnabled));
app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1); app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1);
app.setTabbedSelectorSectionEnabled(appTabbedSelectorSectionEnabled == 1);
auto uncheckedColumn = static_cast<Window::Column>(appFloatPlayerColumn);
switch (uncheckedColumn) {
case Window::Column::First:
case Window::Column::Second:
case Window::Column::Third: app.setFloatPlayerColumn(uncheckedColumn); break;
}
auto uncheckedCorner = static_cast<RectPart>(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<bool> SessionSettings::supportAllSearchResultsValue() const {
return _supportAllSearchResults.value(); return _supportAllSearchResults.value();
} }
void SessionSettings::setTabbedSelectorSectionEnabled(bool enabled) {
_tabbedSelectorSectionEnabled = enabled;
if (enabled) {
setThirdSectionInfoEnabled(false);
}
setTabbedReplacedWithInfo(false);
}
rpl::producer<bool> 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<bool> 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<float64> SessionSettings::dialogsWidthRatioChanges() const {
return _dialogsWidthRatio.changes();
}
void SessionSettings::setThirdColumnWidth(int width) {
_thirdColumnWidth = width;
}
int SessionSettings::thirdColumnWidth() const {
return _thirdColumnWidth.current();
}
rpl::producer<int> SessionSettings::thirdColumnWidthChanges() const {
return _thirdColumnWidth.changes();
}
void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time) { void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time) {
auto &map = _mediaLastPlaybackPosition; auto &map = _mediaLastPlaybackPosition;
const auto i = ranges::find( const auto i = ranges::find(

View file

@ -14,10 +14,6 @@ namespace Support {
enum class SwitchSettings; enum class SwitchSettings;
} // namespace Support } // namespace Support
namespace Window {
enum class Column;
} // namespace Window
namespace ChatHelpers { namespace ChatHelpers {
enum class SelectorTab; enum class SelectorTab;
} // namespace ChatHelpers } // namespace ChatHelpers
@ -62,50 +58,6 @@ public:
void setSelectorTab(ChatHelpers::SelectorTab tab) { void setSelectorTab(ChatHelpers::SelectorTab tab) {
_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<bool> 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<bool> 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<float64> dialogsWidthRatioChanges() const;
void setThirdColumnWidth(int width);
[[nodiscard]] int thirdColumnWidth() const;
[[nodiscard]] rpl::producer<int> thirdColumnWidthChanges() const;
void setGroupStickersSectionHidden(PeerId peerId) { void setGroupStickersSectionHidden(PeerId peerId) {
_groupStickersSectionHidden.insert(peerId); _groupStickersSectionHidden.insert(peerId);
@ -162,24 +114,11 @@ public:
_dialogsFiltersEnabled = value; _dialogsFiltersEnabled = value;
} }
[[nodiscard]] static bool ThirdColumnByDefault();
private: 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; static constexpr auto kDefaultSupportChatsLimitSlice = 7 * 24 * 60 * 60;
ChatHelpers::SelectorTab _selectorTab; // per-window ChatHelpers::SelectorTab _selectorTab; // per-window
bool _tabbedSelectorSectionEnabled = false; // per-window
Window::Column _floatPlayerColumn; // per-window
RectPart _floatPlayerCorner; // per-window
base::flat_set<PeerId> _groupStickersSectionHidden; 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; bool _hadLegacyCallsPeerToPeerNobody = false;
Data::AutoDownload::Full _autoDownload; Data::AutoDownload::Full _autoDownload;
rpl::variable<bool> _archiveCollapsed = false; rpl::variable<bool> _archiveCollapsed = false;
@ -196,10 +135,6 @@ private:
= kDefaultSupportChatsLimitSlice; = kDefaultSupportChatsLimitSlice;
rpl::variable<bool> _supportAllSearchResults = false; rpl::variable<bool> _supportAllSearchResults = false;
rpl::event_stream<bool> _thirdSectionInfoEnabledValue;
bool _tabbedReplacedWithInfo = false;
rpl::event_stream<bool> _tabbedReplacedWithInfoValue;
}; };
} // namespace Main } // namespace Main

View file

@ -280,11 +280,11 @@ MainWidget::MainWidget(
updateDialogsWidthAnimated(); updateDialogsWidthAnimated();
}); });
rpl::merge( rpl::merge(
session().settings().dialogsWidthRatioChanges() | rpl::to_empty, Core::App().settings().dialogsWidthRatioChanges() | rpl::to_empty,
session().settings().thirdColumnWidthChanges() | rpl::to_empty Core::App().settings().thirdColumnWidthChanges() | rpl::to_empty
) | rpl::start_with_next( ) | rpl::start_with_next([=] {
[this] { updateControlsGeometry(); }, updateControlsGeometry();
lifetime()); }, lifetime());
session().changes().historyUpdates( session().changes().historyUpdates(
Data::HistoryUpdate::Flag::MessageSent Data::HistoryUpdate::Flag::MessageSent
@ -2107,7 +2107,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) {
void MainWidget::updateControlsGeometry() { void MainWidget::updateControlsGeometry() {
updateWindowAdaptiveLayout(); updateWindowAdaptiveLayout();
if (session().settings().dialogsWidthRatio() > 0) { if (Core::App().settings().dialogsWidthRatio() > 0) {
_a_dialogsWidth.stop(); _a_dialogsWidth.stop();
} }
if (!_a_dialogsWidth.animating()) { if (!_a_dialogsWidth.animating()) {
@ -2122,9 +2122,9 @@ void MainWidget::updateControlsGeometry() {
anim::activation::background); anim::activation::background);
const auto active = _controller->activeChatCurrent(); const auto active = _controller->activeChatCurrent();
if (const auto peer = active.peer()) { if (const auto peer = active.peer()) {
if (session().settings().tabbedSelectorSectionEnabled()) { if (Core::App().settings().tabbedSelectorSectionEnabled()) {
_history->pushTabbedSelectorToThirdSection(peer, params); _history->pushTabbedSelectorToThirdSection(peer, params);
} else if (session().settings().thirdSectionInfoEnabled()) { } else if (Core::App().settings().thirdSectionInfoEnabled()) {
_controller->showSection( _controller->showSection(
Info::Memento::Default(peer), Info::Memento::Default(peer),
params.withThirdColumn()); params.withThirdColumn());
@ -2258,17 +2258,17 @@ void MainWidget::ensureFirstColumnResizeAreaCreated() {
auto newRatio = (newWidth < st::columnMinimalWidthLeft / 2) auto newRatio = (newWidth < st::columnMinimalWidthLeft / 2)
? 0. ? 0.
: float64(newWidth) / width(); : float64(newWidth) / width();
session().settings().setDialogsWidthRatio(newRatio); Core::App().settings().setDialogsWidthRatio(newRatio);
}; };
auto moveFinishedCallback = [=] { auto moveFinishedCallback = [=] {
if (Adaptive::OneColumn()) { if (Adaptive::OneColumn()) {
return; return;
} }
if (session().settings().dialogsWidthRatio() > 0) { if (Core::App().settings().dialogsWidthRatio() > 0) {
session().settings().setDialogsWidthRatio( Core::App().settings().setDialogsWidthRatio(
float64(_dialogsWidth) / width()); float64(_dialogsWidth) / width());
} }
session().saveSettings(); Core::App().saveSettingsDelayed();
}; };
createResizeArea( createResizeArea(
_firstColumnResizeArea, _firstColumnResizeArea,
@ -2282,17 +2282,17 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() {
} }
auto moveLeftCallback = [=](int globalLeft) { auto moveLeftCallback = [=](int globalLeft) {
auto newWidth = mapToGlobal(QPoint(width(), 0)).x() - globalLeft; auto newWidth = mapToGlobal(QPoint(width(), 0)).x() - globalLeft;
session().settings().setThirdColumnWidth(newWidth); Core::App().settings().setThirdColumnWidth(newWidth);
}; };
auto moveFinishedCallback = [=] { auto moveFinishedCallback = [=] {
if (!Adaptive::ThreeColumn() || !_thirdSection) { if (!Adaptive::ThreeColumn() || !_thirdSection) {
return; return;
} }
session().settings().setThirdColumnWidth(snap( Core::App().settings().setThirdColumnWidth(snap(
session().settings().thirdColumnWidth(), Core::App().settings().thirdColumnWidth(),
st::columnMinimalWidthThird, st::columnMinimalWidthThird,
st::columnMaximalWidthThird)); st::columnMaximalWidthThird));
session().saveSettings(); Core::App().saveSettingsDelayed();
}; };
createResizeArea( createResizeArea(
_thirdColumnResizeArea, _thirdColumnResizeArea,
@ -2301,12 +2301,12 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() {
} }
void MainWidget::updateDialogsWidthAnimated() { void MainWidget::updateDialogsWidthAnimated() {
if (session().settings().dialogsWidthRatio() > 0) { if (Core::App().settings().dialogsWidthRatio() > 0) {
return; return;
} }
auto dialogsWidth = _dialogsWidth; auto dialogsWidth = _dialogsWidth;
updateWindowAdaptiveLayout(); updateWindowAdaptiveLayout();
if (!session().settings().dialogsWidthRatio() if (!Core::App().settings().dialogsWidthRatio()
&& (_dialogsWidth != dialogsWidth && (_dialogsWidth != dialogsWidth
|| _a_dialogsWidth.animating())) { || _a_dialogsWidth.animating())) {
_dialogs->startWidthAnimation(); _dialogs->startWidthAnimation();
@ -2353,6 +2353,7 @@ void MainWidget::updateThirdColumnToCurrentChat(
_thirdSection.destroy(); _thirdSection.destroy();
} }
}; };
auto &settings = Core::App().settings();
auto params = Window::SectionShow( auto params = Window::SectionShow(
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,
anim::type::instant, anim::type::instant,
@ -2364,9 +2365,9 @@ void MainWidget::updateThirdColumnToCurrentChat(
// Like in _controller->showPeerInfo() // Like in _controller->showPeerInfo()
// //
if (Adaptive::ThreeColumn() if (Adaptive::ThreeColumn()
&& !session().settings().thirdSectionInfoEnabled()) { && !settings.thirdSectionInfoEnabled()) {
session().settings().setThirdSectionInfoEnabled(true); settings.setThirdSectionInfoEnabled(true);
session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
} }
_controller->showSection( _controller->showSection(
@ -2378,19 +2379,19 @@ void MainWidget::updateThirdColumnToCurrentChat(
return _history->pushTabbedSelectorToThirdSection(peer, params); return _history->pushTabbedSelectorToThirdSection(peer, params);
}; };
if (Adaptive::ThreeColumn() if (Adaptive::ThreeColumn()
&& session().settings().tabbedSelectorSectionEnabled() && settings.tabbedSelectorSectionEnabled()
&& key) { && key) {
if (!canWrite) { if (!canWrite) {
switchInfoFast(); switchInfoFast();
session().settings().setTabbedSelectorSectionEnabled(true); settings.setTabbedSelectorSectionEnabled(true);
session().settings().setTabbedReplacedWithInfo(true); settings.setTabbedReplacedWithInfo(true);
} else if (session().settings().tabbedReplacedWithInfo() } else if (settings.tabbedReplacedWithInfo()
&& key.history() && key.history()
&& switchTabbedFast(key.history()->peer)) { && switchTabbedFast(key.history()->peer)) {
session().settings().setTabbedReplacedWithInfo(false); settings.setTabbedReplacedWithInfo(false);
} }
} else { } else {
session().settings().setTabbedReplacedWithInfo(false); settings.setTabbedReplacedWithInfo(false);
if (!key) { if (!key) {
if (_thirdSection) { if (_thirdSection) {
_thirdSection.destroy(); _thirdSection.destroy();
@ -2398,7 +2399,7 @@ void MainWidget::updateThirdColumnToCurrentChat(
updateControlsGeometry(); updateControlsGeometry();
} }
} else if (Adaptive::ThreeColumn() } else if (Adaptive::ThreeColumn()
&& session().settings().thirdSectionInfoEnabled()) { && settings.thirdSectionInfoEnabled()) {
switchInfoFast(); switchInfoFast();
} }
} }
@ -2487,7 +2488,7 @@ void MainWidget::handleHistoryBack() {
void MainWidget::updateWindowAdaptiveLayout() { void MainWidget::updateWindowAdaptiveLayout() {
auto layout = _controller->computeColumnLayout(); 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 // 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. // 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() auto useSmallColumnWidth = !Adaptive::OneColumn()
&& !dialogsWidthRatio && !dialogsWidthRatio

View file

@ -284,8 +284,9 @@ void MainWindow::setupMain() {
auto animated = (_intro || _passcodeLock); auto animated = (_intro || _passcodeLock);
auto bg = animated ? grabInner() : QPixmap(); auto bg = animated ? grabInner() : QPixmap();
auto created = object_ptr<MainWidget>(bodyWidget(), sessionController());
clearWidgets(); clearWidgets();
_main.create(bodyWidget(), sessionController()); _main = std::move(created);
if (_passcodeLock) { if (_passcodeLock) {
_main->hide(); _main->hide();
} else { } else {

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "history/view/media/history_view_media.h" #include "history/view/media/history_view_media.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "media/audio/media_audio.h" #include "media/audio/media_audio.h"
#include "media/streaming/media_streaming_instance.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 "media/player/media_player_instance.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/section_widget.h" #include "window/section_widget.h"
#include "core/application.h"
#include "core/core_settings.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h"
#include "facades.h" #include "facades.h"
#include "app.h" #include "app.h"
#include "styles/style_media_player.h" #include "styles/style_media_player.h"
@ -34,12 +36,10 @@ namespace Player {
Float::Float( Float::Float(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
Fn<void(bool visible)> toggleCallback, Fn<void(bool visible)> toggleCallback,
Fn<void(bool closed)> draggedCallback) Fn<void(bool closed)> draggedCallback)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller)
, _item(item) , _item(item)
, _toggleCallback(std::move(toggleCallback)) , _toggleCallback(std::move(toggleCallback))
, _draggedCallback(std::move(draggedCallback)) { , _draggedCallback(std::move(draggedCallback)) {
@ -56,14 +56,14 @@ Float::Float(
prepareShadow(); prepareShadow();
_controller->session().data().itemRepaintRequest( document->session().data().itemRepaintRequest(
) | rpl::start_with_next([this](auto item) { ) | rpl::start_with_next([this](auto item) {
if (_item == item) { if (_item == item) {
repaintItem(); repaintItem();
} }
}, lifetime()); }, lifetime());
_controller->session().data().itemRemoved( document->session().data().itemRemoved(
) | rpl::start_with_next([this](auto item) { ) | rpl::start_with_next([this](auto item) {
if (_item == item) { if (_item == item) {
detach(); detach();
@ -267,7 +267,6 @@ void Float::repaintItem() {
template <typename ToggleCallback, typename DraggedCallback> template <typename ToggleCallback, typename DraggedCallback>
FloatController::Item::Item( FloatController::Item::Item(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller,
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
ToggleCallback toggle, ToggleCallback toggle,
DraggedCallback dragged) DraggedCallback dragged)
@ -276,7 +275,6 @@ FloatController::Item::Item(
, corner(RectPart::TopRight) , corner(RectPart::TopRight)
, widget( , widget(
parent, parent,
controller,
item, item,
[=, toggle = std::move(toggle)](bool visible) { [=, toggle = std::move(toggle)](bool visible) {
toggle(this, visible); toggle(this, visible);
@ -310,9 +308,6 @@ void FloatController::replaceDelegate(not_null<FloatDelegate*> delegate) {
_delegate = delegate; _delegate = delegate;
_parent = _delegate->floatPlayerWidget(); _parent = _delegate->floatPlayerWidget();
// Currently moving floats between windows is not supported.
Assert(_controller == _delegate->floatPlayerController());
startDelegateHandling(); startDelegateHandling();
for (const auto &item : _items) { for (const auto &item : _items) {
@ -356,17 +351,23 @@ void FloatController::startDelegateHandling() {
void FloatController::checkCurrent() { void FloatController::checkCurrent() {
const auto state = Media::Player::instance()->current(AudioMsgId::Type::Voice); const auto state = Media::Player::instance()->current(AudioMsgId::Type::Voice);
const auto audio = state.audio();
const auto fullId = state.contextId(); const auto fullId = state.contextId();
const auto last = current(); const auto last = current();
if (last if (last
&& audio
&& !last->widget->detached() && !last->widget->detached()
&& last->widget->item()->fullId() == fullId) { && (&last->widget->item()->history()->session() == &audio->session())
&& (last->widget->item()->fullId() == fullId)) {
return; return;
} }
if (last) { if (last) {
last->widget->detach(); 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 media = item->media()) {
if (const auto document = media->document()) { if (const auto document = media->document()) {
if (document->isVideoMessage()) { if (document->isVideoMessage()) {
@ -380,7 +381,6 @@ void FloatController::checkCurrent() {
void FloatController::create(not_null<HistoryItem*> item) { void FloatController::create(not_null<HistoryItem*> item) {
_items.push_back(std::make_unique<Item>( _items.push_back(std::make_unique<Item>(
_parent, _parent,
_controller,
item, item,
[=](not_null<Item*> instance, bool visible) { [=](not_null<Item*> instance, bool visible) {
instance->hiddenByWidget = !visible; instance->hiddenByWidget = !visible;
@ -389,8 +389,8 @@ void FloatController::create(not_null<HistoryItem*> item) {
[=](not_null<Item*> instance, bool closed) { [=](not_null<Item*> instance, bool closed) {
finishDrag(instance, closed); finishDrag(instance, closed);
})); }));
current()->column = _controller->session().settings().floatPlayerColumn(); current()->column = Core::App().settings().floatPlayerColumn();
current()->corner = _controller->session().settings().floatPlayerCorner(); current()->corner = Core::App().settings().floatPlayerCorner();
checkVisibility(); checkVisibility();
} }
@ -563,8 +563,8 @@ void FloatController::updateColumnCorner(QPoint center) {
auto size = _items.back()->widget->size(); auto size = _items.back()->widget->size();
auto min = INT_MAX; auto min = INT_MAX;
auto column = _controller->session().settings().floatPlayerColumn(); auto column = Core::App().settings().floatPlayerColumn();
auto corner = _controller->session().settings().floatPlayerCorner(); auto corner = Core::App().settings().floatPlayerCorner();
auto checkSection = [&]( auto checkSection = [&](
not_null<Window::AbstractSectionWidget*> widget, not_null<Window::AbstractSectionWidget*> widget,
Window::Column widgetColumn) { Window::Column widgetColumn) {
@ -589,13 +589,14 @@ void FloatController::updateColumnCorner(QPoint center) {
_delegate->floatPlayerEnumerateSections(checkSection); _delegate->floatPlayerEnumerateSections(checkSection);
if (_controller->session().settings().floatPlayerColumn() != column) { auto &settings = Core::App().settings();
_controller->session().settings().setFloatPlayerColumn(column); if (settings.floatPlayerColumn() != column) {
_controller->session().saveSettingsDelayed(); settings.setFloatPlayerColumn(column);
Core::App().saveSettingsDelayed();
} }
if (_controller->session().settings().floatPlayerCorner() != corner) { if (settings.floatPlayerCorner() != corner) {
_controller->session().settings().setFloatPlayerCorner(corner); settings.setFloatPlayerCorner(corner);
_controller->session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
} }
} }
@ -607,8 +608,8 @@ void FloatController::finishDrag(not_null<Item*> instance, bool closed) {
instance->animationSide = getSide(center); instance->animationSide = getSide(center);
} }
updateColumnCorner(center); updateColumnCorner(center);
instance->column = _controller->session().settings().floatPlayerColumn(); instance->column = Core::App().settings().floatPlayerColumn();
instance->corner = _controller->session().settings().floatPlayerCorner(); instance->corner = Core::App().settings().floatPlayerCorner();
instance->draggedAnimation.stop(); instance->draggedAnimation.stop();
instance->draggedAnimation.start( instance->draggedAnimation.start(

View file

@ -37,7 +37,6 @@ class Float : public Ui::RpWidget, private base::Subscriber {
public: public:
Float( Float(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
Fn<void(bool visible)> toggleCallback, Fn<void(bool visible)> toggleCallback,
Fn<void(bool closed)> draggedCallback); Fn<void(bool closed)> draggedCallback);
@ -90,7 +89,6 @@ private:
void finishDrag(bool closed); void finishDrag(bool closed);
void pauseResume(); void pauseResume();
not_null<Window::SessionController*> _controller;
HistoryItem *_item = nullptr; HistoryItem *_item = nullptr;
Fn<void(bool visible)> _toggleCallback; Fn<void(bool visible)> _toggleCallback;
@ -194,7 +192,6 @@ private:
template <typename ToggleCallback, typename DraggedCallback> template <typename ToggleCallback, typename DraggedCallback>
Item( Item(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller,
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
ToggleCallback toggle, ToggleCallback toggle,
DraggedCallback dragged); DraggedCallback dragged);

View file

@ -375,7 +375,7 @@ bool ReadSetting(
stream >> v; stream >> v;
if (!CheckStreamStatus(stream)) return false; if (!CheckStreamStatus(stream)) return false;
context.sessionSettings().setDialogsWidthRatio(v / 1000000.); Core::App().settings().setDialogsWidthRatio(v / 1000000.);
} break; } break;
case dbiLastSeenWarningSeenOld: { case dbiLastSeenWarningSeenOld: {

View file

@ -324,10 +324,10 @@ void MainWindow::initSize() {
? primaryScreen->availableGeometry() ? primaryScreen->availableGeometry()
: QRect(0, 0, st::windowDefaultWidth, st::windowDefaultHeight); : QRect(0, 0, st::windowDefaultWidth, st::windowDefaultHeight);
bool maximized = false; bool maximized = false;
const auto initialWidth = Main::SessionSettings::ThirdColumnByDefault() const auto initialWidth = Core::Settings::ThirdColumnByDefault()
? st::windowBigDefaultWidth ? st::windowBigDefaultWidth
: st::windowDefaultWidth; : st::windowDefaultWidth;
const auto initialHeight = Main::SessionSettings::ThirdColumnByDefault() const auto initialHeight = Core::Settings::ThirdColumnByDefault()
? st::windowBigDefaultHeight ? st::windowBigDefaultHeight
: st::windowDefaultHeight; : st::windowDefaultHeight;
auto geometry = QRect( auto geometry = QRect(

View file

@ -258,9 +258,8 @@ bool Filler::showInfo() {
return true; return true;
} else if (!Adaptive::ThreeColumn()) { } else if (!Adaptive::ThreeColumn()) {
return true; return true;
} else if ( } else if (!Core::App().settings().thirdSectionInfoEnabled()
!_peer->session().settings().thirdSectionInfoEnabled() && && !Core::App().settings().tabbedReplacedWithInfo()) {
!_peer->session().settings().tabbedReplacedWithInfo()) {
return true; return true;
} }
return false; return false;

View file

@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "passport/passport_form_controller.h" #include "passport/passport_form_controller.h"
#include "chat_helpers/tabbed_selector.h" #include "chat_helpers/tabbed_selector.h"
#include "core/shortcuts.h" #include "core/shortcuts.h"
#include "core/application.h"
#include "core/core_settings.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "boxes/calendar_box.h" #include "boxes/calendar_box.h"
#include "boxes/sticker_set_box.h" // requestAttachedStickerSets. #include "boxes/sticker_set_box.h" // requestAttachedStickerSets.
@ -81,9 +83,9 @@ void SessionNavigation::showPeerInfo(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const SectionShow &params) { const SectionShow &params) {
//if (Adaptive::ThreeColumn() //if (Adaptive::ThreeColumn()
// && !_session->settings().thirdSectionInfoEnabled()) { // && !Core::App().settings().thirdSectionInfoEnabled()) {
// _session->settings().setThirdSectionInfoEnabled(true); // Core::App().settings().setThirdSectionInfoEnabled(true);
// _session->saveSettingsDelayed(); // Core::App().saveSettingsDelayed();
//} //}
showSection(Info::Memento(peer), params); showSection(Info::Memento(peer), params);
} }
@ -451,8 +453,8 @@ auto SessionController::computeColumnLayout() const -> ColumnLayout {
if (bodyWidth < minimalThreeColumnWidth()) { if (bodyWidth < minimalThreeColumnWidth()) {
return true; return true;
} }
if (!session().settings().tabbedSelectorSectionEnabled() if (!Core::App().settings().tabbedSelectorSectionEnabled()
&& !session().settings().thirdSectionInfoEnabled()) { && !Core::App().settings().thirdSectionInfoEnabled()) {
return true; return true;
} }
return false; return false;
@ -482,14 +484,14 @@ auto SessionController::computeColumnLayout() const -> ColumnLayout {
} }
int SessionController::countDialogsWidthFromRatio(int bodyWidth) const { 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_max(result, st::columnMinimalWidthLeft);
// accumulate_min(result, st::columnMaximalWidthLeft); // accumulate_min(result, st::columnMaximalWidthLeft);
return result; return result;
} }
int SessionController::countThirdColumnWidthFromRatio(int bodyWidth) const { int SessionController::countThirdColumnWidthFromRatio(int bodyWidth) const {
auto result = session().settings().thirdColumnWidth(); auto result = Core::App().settings().thirdColumnWidth();
accumulate_max(result, st::columnMinimalWidthThird); accumulate_max(result, st::columnMinimalWidthThird);
accumulate_min(result, st::columnMaximalWidthThird); accumulate_min(result, st::columnMaximalWidthThird);
return result; return result;
@ -540,13 +542,14 @@ void SessionController::resizeForThirdSection() {
return; return;
} }
auto &settings = Core::App().settings();
auto layout = computeColumnLayout(); auto layout = computeColumnLayout();
auto tabbedSelectorSectionEnabled = auto tabbedSelectorSectionEnabled =
session().settings().tabbedSelectorSectionEnabled(); settings.tabbedSelectorSectionEnabled();
auto thirdSectionInfoEnabled = auto thirdSectionInfoEnabled =
session().settings().thirdSectionInfoEnabled(); settings.thirdSectionInfoEnabled();
session().settings().setTabbedSelectorSectionEnabled(false); settings.setTabbedSelectorSectionEnabled(false);
session().settings().setThirdSectionInfoEnabled(false); settings.setThirdSectionInfoEnabled(false);
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth); auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
auto minimal = st::columnMinimalWidthThird; auto minimal = st::columnMinimalWidthThird;
@ -567,46 +570,47 @@ void SessionController::resizeForThirdSection() {
return widget()->tryToExtendWidthBy(minimal); return widget()->tryToExtendWidthBy(minimal);
}(); }();
if (extendedBy) { if (extendedBy) {
if (extendBy != session().settings().thirdColumnWidth()) { if (extendBy != settings.thirdColumnWidth()) {
session().settings().setThirdColumnWidth(extendBy); settings.setThirdColumnWidth(extendBy);
} }
auto newBodyWidth = layout.bodyWidth + extendedBy; auto newBodyWidth = layout.bodyWidth + extendedBy;
auto currentRatio = session().settings().dialogsWidthRatio(); auto currentRatio = settings.dialogsWidthRatio();
session().settings().setDialogsWidthRatio( settings.setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth); (currentRatio * layout.bodyWidth) / newBodyWidth);
} }
auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy; auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
session().settings().setThirdSectionExtendedBy(savedValue); settings.setThirdSectionExtendedBy(savedValue);
session().settings().setTabbedSelectorSectionEnabled( settings.setTabbedSelectorSectionEnabled(
tabbedSelectorSectionEnabled); tabbedSelectorSectionEnabled);
session().settings().setThirdSectionInfoEnabled( settings.setThirdSectionInfoEnabled(
thirdSectionInfoEnabled); thirdSectionInfoEnabled);
} }
void SessionController::closeThirdSection() { void SessionController::closeThirdSection() {
auto &settings = Core::App().settings();
auto newWindowSize = widget()->size(); auto newWindowSize = widget()->size();
auto layout = computeColumnLayout(); auto layout = computeColumnLayout();
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) { if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
auto noResize = widget()->isFullScreen() auto noResize = widget()->isFullScreen()
|| widget()->isMaximized(); || widget()->isMaximized();
auto savedValue = session().settings().thirdSectionExtendedBy(); auto savedValue = settings.thirdSectionExtendedBy();
auto extendedBy = (savedValue == -1) auto extendedBy = (savedValue == -1)
? layout.thirdWidth ? layout.thirdWidth
: savedValue; : savedValue;
auto newBodyWidth = noResize auto newBodyWidth = noResize
? layout.bodyWidth ? layout.bodyWidth
: (layout.bodyWidth - extendedBy); : (layout.bodyWidth - extendedBy);
auto currentRatio = session().settings().dialogsWidthRatio(); auto currentRatio = settings.dialogsWidthRatio();
session().settings().setDialogsWidthRatio( settings.setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth); (currentRatio * layout.bodyWidth) / newBodyWidth);
newWindowSize = QSize( newWindowSize = QSize(
widget()->width() + (newBodyWidth - layout.bodyWidth), widget()->width() + (newBodyWidth - layout.bodyWidth),
widget()->height()); widget()->height());
} }
session().settings().setTabbedSelectorSectionEnabled(false); settings.setTabbedSelectorSectionEnabled(false);
session().settings().setThirdSectionInfoEnabled(false); settings.setThirdSectionInfoEnabled(false);
session().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
if (widget()->size() != newWindowSize) { if (widget()->size() != newWindowSize) {
widget()->resize(newWindowSize); widget()->resize(newWindowSize);
} else { } else {