From fd0719db6d8fb4686d9c9b87c9b567b74ae1144d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Sep 2018 20:56:45 +0300 Subject: [PATCH] Add animations enable/disable setting. Open chats / users on mouse press if animations are disabled. --- Telegram/Resources/langs/lang.strings | 13 +++-- Telegram/SourceFiles/boxes/connection_box.cpp | 20 ++------ Telegram/SourceFiles/boxes/connection_box.h | 8 +--- Telegram/SourceFiles/boxes/peer_list_box.cpp | 3 ++ Telegram/SourceFiles/core/update_checker.cpp | 1 + .../dialogs/dialogs_inner_widget.cpp | 5 ++ .../settings/settings_advanced.cpp | 48 ++++++++++++++++++- .../SourceFiles/settings/settings_advanced.h | 1 + .../SourceFiles/settings/settings_intro.cpp | 7 +++ .../SourceFiles/settings/settings_main.cpp | 20 ++++++-- .../settings/settings_privacy_controllers.cpp | 16 ++++--- Telegram/SourceFiles/storage/localstorage.cpp | 12 +++++ 12 files changed, 113 insertions(+), 41 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7c9b3c0719..eefb1d56c0 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -336,7 +336,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_use_night_mode" = "Use night mode"; "lng_settings_privacy_title" = "Privacy"; "lng_settings_last_seen" = "Last seen"; -"lng_settings_calls" = "Calls"; +"lng_settings_calls" = "Voice calls"; "lng_settings_groups_invite" = "Groups"; "lng_settings_group_privacy_about" = "Change who can add you to groups and channel."; "lng_settings_sessions_about" = "Control your sessions on other devices."; @@ -348,7 +348,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_phone_label" = "Phone number"; "lng_settings_username_add" = "Add username"; "lng_settings_close_sure" = "Are you sure you want to close this page? You didn't save your changes."; -"lng_settings_calls_title" = "Calls"; "lng_settings_peer_to_peer" = "Peer-to-Peer"; "lng_settings_peer_to_peer_about" = "Disabling peer-to-peer will relay all calls through Telegram servers to avoid revealing your IP address, but may slightly decrease audio quality."; "lng_settings_advanced" = "Advanced"; @@ -364,6 +363,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_network_proxy" = "Network and proxy"; "lng_settings_version_info" = "Version and updates"; "lng_settings_system_integration" = "System integration"; +"lng_settings_performance" = "Performance"; +"lng_settings_enable_animations" = "Enable animations"; +"lng_settings_autoplay_gifs" = "Autoplay GIFs"; "lng_backgrounds_header" = "Choose your new chat background"; "lng_theme_sure_keep" = "Keep this theme?"; @@ -515,9 +517,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_proxy_sponsor_warning" = "This proxy may display a sponsored channel in your chat list. This doesn't reveal any of your Telegram traffic."; "lng_settings_blocked_users" = "Blocked users"; -"lng_settings_last_seen_privacy" = "Last seen privacy"; -"lng_settings_calls_privacy" = "Phone calls privacy"; -"lng_settings_groups_invite_privacy" = "Group invite settings"; "lng_settings_show_sessions" = "Show all sessions"; "lng_settings_export_data" = "Export Telegram data"; "lng_settings_destroy_if" = "If away for..."; @@ -578,7 +577,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_edit_privacy_groups_always_title" = "Always allow"; "lng_edit_privacy_groups_never_title" = "Never allow"; -"lng_edit_privacy_calls_title" = "Telegram call privacy"; +"lng_edit_privacy_calls_title" = "Voice calls privacy"; "lng_edit_privacy_calls_header" = "Who can call you"; "lng_edit_privacy_calls_always_empty" = "Always allow"; "lng_edit_privacy_calls_never_empty" = "Never allow"; @@ -1015,7 +1014,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_stickers_packs_archived" = "Some of your unused stickers have been archived to make room for the sets you've activated."; "lng_stickers_copied" = "Sticker pack link copied to clipboard."; "lng_stickers_default_set" = "Great Minds"; -"lng_stickers_you_have" = "Manage and reorder sticker packs"; +"lng_stickers_you_have" = "Manage sticker packs"; "lng_stickers_return" = "Undo"; "lng_stickers_count#one" = "{count} sticker"; "lng_stickers_count#other" = "{count} stickers"; diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 580d3b95b7..3c20b420c4 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -924,15 +924,14 @@ AutoDownloadBox::AutoDownloadBox(QWidget *parent) , _audioGroups(this, lang(lng_media_auto_groups), !(cAutoDownloadAudio() & dbiadNoGroups), st::defaultBoxCheckbox) , _gifPrivate(this, lang(lng_media_auto_private_chats), !(cAutoDownloadGif() & dbiadNoPrivate), st::defaultBoxCheckbox) , _gifGroups(this, lang(lng_media_auto_groups), !(cAutoDownloadGif() & dbiadNoGroups), st::defaultBoxCheckbox) -, _gifPlay(this, lang(lng_media_auto_play), cAutoPlayGif(), st::defaultBoxCheckbox) , _sectionHeight(st::boxTitleHeight + 2 * (st::defaultCheck.diameter + st::setLittleSkip)) { } void AutoDownloadBox::prepare() { - addButton(langFactory(lng_connection_save), [this] { onSave(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(langFactory(lng_connection_save), [=] { save(); }); + addButton(langFactory(lng_cancel), [=] { closeBox(); }); - setDimensions(st::boxWidth, 3 * _sectionHeight - st::autoDownloadTopDelta + st::setLittleSkip + _gifPlay->heightNoMargins() + st::setLittleSkip); + setDimensions(st::boxWidth, 3 * _sectionHeight - st::autoDownloadTopDelta + st::setLittleSkip); } void AutoDownloadBox::paintEvent(QPaintEvent *e) { @@ -959,13 +958,11 @@ void AutoDownloadBox::resizeEvent(QResizeEvent *e) { _gifPrivate->moveToLeft(st::boxTitlePosition.x(), 2 * _sectionHeight + top + st::setLittleSkip); _gifGroups->moveToLeft(st::boxTitlePosition.x(), _gifPrivate->bottomNoMargins() + st::setLittleSkip); - _gifPlay->moveToLeft(st::boxTitlePosition.x(), _gifGroups->bottomNoMargins() + st::setLittleSkip); } -void AutoDownloadBox::onSave() { +void AutoDownloadBox::save() { auto photosChanged = false; auto documentsChanged = false; - auto autoplayChanged = false; auto photosEnabled = false; auto voiceEnabled = false; auto animationsEnabled = false; @@ -1002,14 +999,7 @@ void AutoDownloadBox::onSave() { documentsChanged = true; cSetAutoDownloadGif(autoDownloadGif); } - if (cAutoPlayGif() != _gifPlay->checked()) { - cSetAutoPlayGif(_gifPlay->checked()); - if (!cAutoPlayGif()) { - Auth().data().stopAutoplayAnimations(); - } - autoplayChanged = true; - } - if (photosChanged || documentsChanged || autoplayChanged) { + if (photosChanged || documentsChanged) { Local::writeUserSettings(); } if (photosEnabled) { diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index fd422ab6d6..e8e2373026 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -23,8 +23,6 @@ class Radioenum; } // namespace Ui class AutoDownloadBox : public BoxContent { - Q_OBJECT - public: AutoDownloadBox(QWidget *parent); @@ -34,17 +32,15 @@ protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; -private slots: - void onSave(); - private: + void save(); + object_ptr _photoPrivate; object_ptr _photoGroups; object_ptr _audioPrivate; object_ptr _audioGroups; object_ptr _gifPrivate; object_ptr _gifGroups; - object_ptr _gifPlay; int _sectionHeight = 0; diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 3c6afd5d73..a3cdd6e7ba 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -982,6 +982,9 @@ void PeerListContent::mousePressEvent(QMouseEvent *e) { row->addRipple(_st.item, size, point, std::move(updateCallback)); } } + if (anim::Disabled()) { + mousePressReleased(e->button()); + } } void PeerListContent::mouseReleaseEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 31f8e5adc1..d8bbe1e5cc 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -2127,6 +2127,7 @@ void UpdateApplication() { }(); UrlClickHandler::Open(url); } else { + cSetAutoUpdate(true); if (const auto window = App::wnd()) { if (const auto controller = window->controller()) { controller->showSection( diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 7f6c4e01af..c27affb315 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -834,6 +834,10 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) { rtlupdate(0, searchedOffset() + index * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight); }); } + if (anim::Disabled() + && (!_pressed || !_pressed->entry()->isPinnedDialog())) { + mousePressReleased(e->button()); + } } void DialogsInner::checkReorderPinnedStart(QPoint localPosition) { @@ -1002,6 +1006,7 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { void DialogsInner::step_pinnedShifting(TimeMs ms, bool timer) { if (anim::Disabled()) { ms += st::stickersRowDuration; + update(); } auto animating = false; diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index fcfdf9b04a..cc4627d3cd 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -22,6 +22,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "core/update_checker.h" #include "storage/localstorage.h" +#include "data/data_session.h" +#include "auth_session.h" #include "layout.h" #include "styles/style_settings.h" @@ -380,12 +382,49 @@ void SetupTray(not_null container) { AddSkip(container, st::settingsCheckboxesSkip); } -General::General(QWidget *parent, UserData *self) +void SetupAnimations(not_null container) { + AddButton( + container, + lng_settings_enable_animations, + st::settingsButton + )->toggleOn( + rpl::single(!anim::Disabled()) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled == anim::Disabled()); + }) | rpl::start_with_next([](bool enabled) { + anim::SetDisabled(!enabled); + Local::writeSettings(); + }, container->lifetime()); +} + +void SetupPerformance(not_null container) { + SetupAnimations(container); + + AddButton( + container, + lng_settings_autoplay_gifs, + st::settingsButton + )->toggleOn( + rpl::single(cAutoPlayGif()) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != cAutoPlayGif()); + }) | rpl::start_with_next([](bool enabled) { + cSetAutoPlayGif(enabled); + if (!cAutoPlayGif()) { + Auth().data().stopAutoplayAnimations(); + } + Local::writeUserSettings(); + }, container->lifetime()); +} + +Advanced::Advanced(QWidget *parent, UserData *self) : Section(parent) { setupContent(); } -void General::setupContent() { +void Advanced::setupContent() { const auto content = Ui::CreateChild(this); auto empty = true; @@ -423,6 +462,11 @@ void General::setupContent() { SetupTray(content); AddSkip(content); } + addDivider(); + AddSkip(content); + AddSubsectionTitle(content, lng_settings_performance); + SetupPerformance(content); + AddSkip(content); if (cAutoUpdate()) { addUpdate(); } diff --git a/Telegram/SourceFiles/settings/settings_advanced.h b/Telegram/SourceFiles/settings/settings_advanced.h index 15f6a5ea55..b816e136ea 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.h +++ b/Telegram/SourceFiles/settings/settings_advanced.h @@ -17,6 +17,7 @@ bool HasUpdate(); void SetupUpdate(not_null container); bool HasTray(); void SetupTray(not_null container); +void SetupAnimations(not_null container); class Advanced : public Section { public: diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index dc5f3ef25c..0e31088dd2 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -83,6 +83,13 @@ object_ptr CreateIntroSettings(QWidget *parent) { SetupUseDefaultTheme(result); AddSkip(result); + if (anim::Disabled()) { + AddDivider(result); + AddSkip(result); + SetupAnimations(result); + AddSkip(result); + } + AddDivider(result); AddSkip(result); SetupFaq(result, false); diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 71e016de17..89d70fb329 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -199,15 +199,17 @@ void SetupInterfaceScale( }, slider->lifetime()); } +void OpenFaq() { + QDesktopServices::openUrl(telegramFaqLink()); +} + void SetupFaq(not_null container, bool icon) { AddButton( container, lng_settings_faq, icon ? st::settingsSectionButton : st::settingsButton, icon ? &st::settingsIconFaq : nullptr - )->addClickHandler([] { - QDesktopServices::openUrl(telegramFaqLink()); - }); + )->addClickHandler(OpenFaq); } void SetupHelp(not_null container) { @@ -228,7 +230,17 @@ void SetupHelp(not_null container) { Ui::showPeerHistory(user, ShowAtUnreadMsgId); } }); - Auth().api().requestSupportContact(ready); + const auto sure = crl::guard(button, [=] { + Auth().api().requestSupportContact(ready); + }); + auto box = Box( + lang(lng_settings_ask_sure), + lang(lng_settings_ask_ok), + lang(lng_settings_faq_button), + sure, + OpenFaq); + box->setStrictCancel(true); + Ui::show(std::move(box)); }); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 4f57baaea2..bcbe040be9 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -214,15 +214,17 @@ bool BlockedBoxController::prependRow(UserData *user) { std::unique_ptr BlockedBoxController::createRow(UserData *user) const { auto row = std::make_unique(user); row->setActionLink(lang(lng_blocked_list_unblock)); - auto status = [user]() -> QString { - if (user->botInfo) { + const auto status = [&] { + if (!user->phone().isEmpty()) { + return App::formatPhone(user->phone()); + } else if (!user->username.isEmpty()) { + return '@' + user->username; + } else if (user->botInfo) { return lang(lng_status_bot); - } else if (user->phone().isEmpty()) { - return lang(lng_blocked_list_unknown_phone); } - return App::formatPhone(user->phone()); - }; - row->setCustomStatus(status()); + return lang(lng_blocked_list_unknown_phone); + }(); + row->setCustomStatus(status); return std::move(row); } diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 0d9707b93c..d442c5fd9e 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -594,6 +594,7 @@ enum { dbiThemeKey = 0x54, dbiTileBackground = 0x55, dbiCacheSettings = 0x56, + dbiAnimationsDisabled = 0x57, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, @@ -1030,6 +1031,16 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting _cacheTotalTimeLimit = time; } break; + case dbiAnimationsDisabled: { + qint32 disabled; + stream >> disabled; + if (!_checkStreamStatus(stream)) { + return false; + } + + anim::SetDisabled(disabled == 1); + } break; + case dbiSoundNotify: { qint32 v; stream >> v; @@ -2541,6 +2552,7 @@ void writeSettings() { data.stream << quint32(dbiDcOptions) << dcOptionsSerialized; data.stream << quint32(dbiLoggedPhoneNumber) << cLoggedPhoneNumber(); data.stream << quint32(dbiTxtDomainString) << Global::TxtDomainString(); + data.stream << quint32(dbiAnimationsDisabled) << qint32(anim::Disabled() ? 1 : 0); data.stream << quint32(dbiConnectionType) << qint32(dbictProxiesList); data.stream << qint32(proxies.size());