From e4a7c015418485f900fdccce8bd21a5bc816f06b Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Feb 2022 15:50:19 +0300 Subject: [PATCH] Move window_outdated_bar to td_ui subproject. --- Telegram/CMakeLists.txt | 2 - .../controls}/window_outdated_bar.cpp | 42 ++++++++++--------- .../controls}/window_outdated_bar.h | 12 +++--- Telegram/SourceFiles/window/main_window.cpp | 4 +- Telegram/cmake/td_ui.cmake | 2 + 5 files changed, 33 insertions(+), 29 deletions(-) rename Telegram/SourceFiles/{window => ui/controls}/window_outdated_bar.cpp (82%) rename Telegram/SourceFiles/{window => ui/controls}/window_outdated_bar.h (75%) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index a64fe1222c..02567967b1 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1173,8 +1173,6 @@ PRIVATE window/window_main_menu.h window/window_media_preview.cpp window/window_media_preview.h - window/window_outdated_bar.cpp - window/window_outdated_bar.h window/window_peer_menu.cpp window/window_peer_menu.h window/window_section_common.h diff --git a/Telegram/SourceFiles/window/window_outdated_bar.cpp b/Telegram/SourceFiles/ui/controls/window_outdated_bar.cpp similarity index 82% rename from Telegram/SourceFiles/window/window_outdated_bar.cpp rename to Telegram/SourceFiles/ui/controls/window_outdated_bar.cpp index e68703e70d..538e3fcda4 100644 --- a/Telegram/SourceFiles/window/window_outdated_bar.cpp +++ b/Telegram/SourceFiles/ui/controls/window_outdated_bar.cpp @@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -#include "window/window_outdated_bar.h" +#include "ui/controls/window_outdated_bar.h" #include "ui/widgets/labels.h" // Ui::FlatLabel #include "ui/widgets/buttons.h" // Ui::IconButton @@ -15,7 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "styles/style_window.h" -namespace Window { +#include + +namespace Ui { namespace { #ifdef DESKTOP_APP_SPECIAL_TARGET @@ -23,22 +25,22 @@ constexpr auto kMinimalSkip = 7; constexpr auto kSoonSkip = 30; constexpr auto kNowSkip = 90; -class Bar : public Ui::RpWidget { +class Bar final : public RpWidget { public: Bar(not_null parent, QDate date); int resizeGetHeight(int newWidth) override; - rpl::producer<> hideClicks() const; + [[nodiscard]] rpl::producer<> hideClicks() const; protected: void paintEvent(QPaintEvent *e) override; private: QDate _date; - object_ptr _title; - object_ptr _details; - object_ptr _close; + object_ptr _title; + object_ptr _details; + object_ptr _close; bool _soon = false; }; @@ -54,7 +56,7 @@ Bar::Bar(not_null parent, QDate date) : _date(date) , _title( this, - OutdatedReasonPhrase() | Ui::Text::ToUpper(), + OutdatedReasonPhrase() | Text::ToUpper(), st::windowOutdatedTitle) , _details(this, QString(), @@ -97,12 +99,12 @@ void Bar::paintEvent(QPaintEvent *e) { _soon ? st::outdateSoonBg : st::outdatedBg); } -QString LastHiddenPath() { - return cWorkingDir() + qsl("tdata/outdated_hidden"); +[[nodiscard]] QString LastHiddenPath(const QString &workingDir) { + return workingDir + u"tdata/outdated_hidden"_q; } -[[nodiscard]] bool Skip(const QDate &date) { - auto file = QFile(LastHiddenPath()); +[[nodiscard]] bool Skip(const QDate &date, const QString &workingDir) { + auto file = QFile(LastHiddenPath(workingDir)); if (!file.open(QIODevice::ReadOnly) || file.size() != sizeof(qint32)) { return false; } @@ -132,8 +134,8 @@ QString LastHiddenPath() { } } -void Closed() { - auto file = QFile(LastHiddenPath()); +void Closed(const QString &workingDir) { + auto file = QFile(LastHiddenPath(workingDir)); if (!file.open(QIODevice::WriteOnly)) { return; } @@ -150,16 +152,18 @@ void Closed() { } // namespace -object_ptr CreateOutdatedBar(not_null parent) { +object_ptr CreateOutdatedBar( + not_null parent, + const QString &workingPath) { #ifdef DESKTOP_APP_SPECIAL_TARGET const auto date = Platform::WhenSystemBecomesOutdated(); if (date.isNull()) { return { nullptr }; - } else if (Skip(date)) { + } else if (Skip(date, workingPath)) { return { nullptr }; } - auto result = object_ptr>( + auto result = object_ptr>( parent.get(), object_ptr(parent.get(), date)); const auto wrap = result.data(); @@ -167,7 +171,7 @@ object_ptr CreateOutdatedBar(not_null parent) { wrap->entity()->hideClicks( ) | rpl::start_with_next([=] { wrap->toggle(false, anim::type::normal); - Closed(); + Closed(workingPath); }, wrap->lifetime()); return result; @@ -176,4 +180,4 @@ object_ptr CreateOutdatedBar(not_null parent) { #endif // DESKTOP_APP_SPECIAL_TARGET } -} // namespace Window +} // namespace Ui diff --git a/Telegram/SourceFiles/window/window_outdated_bar.h b/Telegram/SourceFiles/ui/controls/window_outdated_bar.h similarity index 75% rename from Telegram/SourceFiles/window/window_outdated_bar.h rename to Telegram/SourceFiles/ui/controls/window_outdated_bar.h index 5f4d373792..887f15d4a7 100644 --- a/Telegram/SourceFiles/window/window_outdated_bar.h +++ b/Telegram/SourceFiles/ui/controls/window_outdated_bar.h @@ -10,11 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/object_ptr.h" namespace Ui { + class RpWidget; + +[[nodiscard]] object_ptr CreateOutdatedBar( + not_null parent, + const QString &workingPath); + } // namespace Ui - -namespace Window { - -object_ptr CreateOutdatedBar(not_null parent); - -} // namespace Window diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index ad345c786d..32b8af910e 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -15,7 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "window/window_session_controller.h" #include "window/window_lock_widgets.h" -#include "window/window_outdated_bar.h" #include "window/window_controller.h" #include "main/main_account.h" // Account::sessionValue. #include "core/application.h" @@ -27,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/crc32hash.h" #include "ui/toast/toast.h" #include "ui/widgets/shadow.h" +#include "ui/controls/window_outdated_bar.h" #include "ui/ui_utility.h" #include "apiwrap.h" #include "mainwindow.h" @@ -307,7 +307,7 @@ QImage WithSmallCounter(QImage image, CounterLayerArgs &&args) { MainWindow::MainWindow(not_null controller) : _controller(controller) , _positionUpdatedTimer([=] { savePosition(); }) -, _outdated(CreateOutdatedBar(body())) +, _outdated(Ui::CreateOutdatedBar(body(), cWorkingDir())) , _body(body()) { style::PaletteChanged( ) | rpl::start_with_next([=] { diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 90aef77581..ceaea64664 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -204,6 +204,8 @@ PRIVATE ui/controls/send_button.h ui/controls/who_reacted_context_action.cpp ui/controls/who_reacted_context_action.h + ui/controls/window_outdated_bar.cpp + ui/controls/window_outdated_bar.h ui/text/format_song_name.cpp ui/text/format_song_name.h ui/text/format_values.cpp