Remove namespace App.

This commit is contained in:
John Preston 2022-11-30 17:28:09 +04:00
parent 01139e1b04
commit ad3f8e72a0
24 changed files with 80 additions and 74 deletions

View file

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/abstract_box.h"
#include "core/application.h"
#include "window/window_controller.h"
#include "mainwidget.h"
#include "mainwindow.h"
@ -17,25 +19,30 @@ void showBox(
object_ptr<BoxContent> content,
LayerOptions options,
anim::type animated) {
if (auto w = App::wnd()) {
w->ui_showBox(std::move(content), options, animated);
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
window->show(std::move(content), options, animated);
}
}
} // namespace internal
void hideLayer(anim::type animated) {
if (auto w = App::wnd()) {
w->ui_showBox(
{ nullptr },
LayerOption::CloseOther,
animated);
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
window->hideLayer(animated);
}
}
bool isLayerShown() {
if (auto w = App::wnd()) return w->ui_isLayerShown();
return false;
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
return window && window->isLayerShown();
}
} // namespace Ui

View file

@ -47,6 +47,5 @@ QPointer<BoxType> show(
}
void hideLayer(anim::type animated = anim::type::normal);
bool isLayerShown();
} // namespace Ui

View file

@ -855,7 +855,9 @@ void Application::switchDebugMode() {
Logs::SetDebugEnabled(true);
_launcher->writeDebugModeSetting();
DEBUG_LOG(("Debug logs started."));
Ui::hideLayer();
if (_primaryWindow) {
_primaryWindow->hideLayer();
}
}
}
@ -966,6 +968,12 @@ bool Application::canApplyLangPackWithoutRestart() const {
return true;
}
void Application::checkSendPaths() {
if (!cSendPaths().isEmpty() && _primaryWindow && !_primaryWindow->locked()) {
_primaryWindow->widget()->sendPaths();
}
}
void Application::checkStartUrl() {
if (!cStartUrl().isEmpty() && _primaryWindow && !_primaryWindow->locked()) {
const auto url = cStartUrl();

View file

@ -236,6 +236,7 @@ public:
// Internal links.
void checkStartUrl();
void checkSendPaths();
bool openLocalUrl(const QString &url, QVariant context);
bool openInternalUrl(const QString &url, QVariant context);
[[nodiscard]] QString changelogLink() const;

View file

@ -162,7 +162,7 @@ void ShowInFolder(const QString &filepath) {
Ui::PreventDelayedActivation();
if (Platform::IsLinux()) {
// Hide mediaview to make other apps visible.
Ui::hideLayer(anim::type::instant);
Core::App().hideMediaView();
}
base::Platform::ShowInFolder(filepath);
});

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "storage/localstorage.h"
#include "window/notifications_manager.h"
#include "window/window_controller.h"
#include "core/crash_reports.h"
#include "core/crash_report_window.h"
#include "core/application.h"
@ -460,10 +461,8 @@ void Sandbox::readClients() {
paths.append(toSend);
cSetSendPaths(paths);
}
if (!cSendPaths().isEmpty()) {
if (App::wnd()) {
App::wnd()->sendPaths();
}
if (_application) {
_application->checkSendPaths();
}
if (!startUrl.isEmpty()) {
cSetStartUrl(startUrl);
@ -647,8 +646,8 @@ void Sandbox::closeApplication() {
void Sandbox::execExternal(const QString &cmd) {
DEBUG_LOG(("Sandbox Info: executing external command '%1'").arg(cmd));
if (cmd == "show") {
if (App::wnd()) {
App::wnd()->activate();
if (Core::IsAppLaunched() && Core::App().primaryWindow()) {
Core::App().primaryWindow()->activate();
} else if (PreLaunchWindow::instance()) {
PreLaunchWindow::instance()->activate();
}

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_account.h"
#include "main/main_session.h"
#include "main/main_app_config.h"
#include "window/window_controller.h"
#include "mainwindow.h"
namespace Core {
@ -123,8 +124,8 @@ QString UiIntegration::angleBackendFilePath() {
}
void UiIntegration::textActionsUpdated() {
if (const auto window = App::wnd()) {
window->updateGlobalMenu();
if (const auto window = Core::App().primaryWindow()) {
window->widget()->updateGlobalMenu();
}
}

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_domain.h"
#include "info/info_memento.h"
#include "info/info_controller.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "settings/settings_advanced.h"
#include "settings/settings_intro.h"
@ -1648,7 +1649,10 @@ void UpdateApplication() {
UrlClickHandler::Open(url);
} else {
cSetAutoUpdate(true);
if (const auto window = App::wnd()) {
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
if (const auto controller = window->sessionController()) {
controller->showSection(
std::make_shared<Info::Memento>(
@ -1656,11 +1660,11 @@ void UpdateApplication() {
::Settings::Advanced::Id()),
Window::SectionShow());
} else {
window->showSpecialLayer(
Box<::Settings::LayerWidget>(&window->controller()),
window->widget()->showSpecialLayer(
Box<::Settings::LayerWidget>(window),
anim::type::normal);
}
window->showFromTray();
window->widget()->showFromTray();
}
cSetLastUpdateCheck(0);
Core::UpdateChecker().start();

View file

@ -3615,7 +3615,7 @@ void InnerWidget::setupShortcuts() {
Shortcuts::Requests(
) | rpl::filter([=] {
return isActiveWindow()
&& !Ui::isLayerShown()
&& !_controller->isLayerShown()
&& !_controller->window().locked();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;

View file

@ -663,7 +663,7 @@ void Widget::setupShortcuts() {
) | rpl::filter([=] {
return isActiveWindow()
&& Ui::InFocusChain(this)
&& !Ui::isLayerShown()
&& !controller()->isLayerShown()
&& !controller()->window().locked();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
@ -2027,7 +2027,7 @@ void Widget::showSearchFrom() {
auto box = SearchFromBox(
peer,
crl::guard(this, [=](not_null<PeerData*> from) {
Ui::hideLayer();
controller()->hideLayer();
if (!chat.topic()) {
setSearchInChat(chat, from);
} else if (const auto strong = weak.get()) {

View file

@ -397,7 +397,7 @@ void Widget::setupShortcuts() {
) | rpl::filter([=] {
return Ui::AppInFocus()
&& Ui::InFocusChain(this)
&& !Ui::isLayerShown()
&& !controller()->isLayerShown()
&& isActiveWindow();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;

View file

@ -1838,7 +1838,7 @@ void HistoryWidget::setupShortcuts() {
return _history
&& Ui::AppInFocus()
&& Ui::InFocusChain(this)
&& !Ui::isLayerShown()
&& !controller()->isLayerShown()
&& (Core::App().activeWindow() == &controller()->window());
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
@ -4059,7 +4059,7 @@ void HistoryWidget::checkSuggestToGigagroup() {
return;
}
InvokeQueued(_list, [=] {
if (!Ui::isLayerShown()) {
if (!controller()->isLayerShown()) {
group->owner().setSuggestToGigagroup(group, false);
group->session().api().request(MTPhelp_DismissSuggestion(
group->input,
@ -7351,7 +7351,8 @@ void HistoryWidget::updateTopBarSelection() {
: tr::lng_report_messages_none(tr::now)));
updateControlsVisibility();
updateHistoryGeometry();
if (!Ui::isLayerShown() && !Core::App().passcodeLocked()) {
if (!controller()->isLayerShown()
&& !Core::App().passcodeLocked()) {
if (isSearching()) {
_composeSearch->setInnerFocus();
} else if (_nonEmptySelection

View file

@ -2588,7 +2588,7 @@ void RepliesWidget::setupShortcuts() {
return _topic
&& Ui::AppInFocus()
&& Ui::InFocusChain(this)
&& !Ui::isLayerShown()
&& !controller()->isLayerShown()
&& (Core::App().activeWindow() == &controller()->window());
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;

View file

@ -493,7 +493,7 @@ void Widget::resetAccount() {
)).done([=] {
_resetRequest = 0;
Ui::hideLayer();
getData()->controller->hideLayer();
if (getData()->phone.isEmpty()) {
moveToStep(
new QrWidget(this, _account, getData()),
@ -556,7 +556,7 @@ void Widget::resetAccount() {
Ui::show(Ui::MakeInformBox(
tr::lng_signin_reset_cancelled()));
} else {
Ui::hideLayer();
getData()->controller->hideLayer();
getStep()->showError(rpl::single(Lang::Hard::ServerError()));
}
}).send();

View file

@ -2676,7 +2676,7 @@ void MainWidget::activate() {
} else if (_hider) {
Assert(_dialogs != nullptr);
_dialogs->setInnerFocus();
} else if (!Ui::isLayerShown()) {
} else if (!_controller->isLayerShown()) {
if (_history->peer()) {
_history->activate();
} else {
@ -2702,14 +2702,3 @@ bool MainWidget::isNormalColumn() const {
bool MainWidget::isThreeColumn() const {
return _controller->adaptive().isThreeColumn();
}
namespace App {
MainWidget *main() {
if (const auto window = wnd()) {
return window->sessionContent();
}
return nullptr;
}
} // namespace App

View file

@ -390,7 +390,3 @@ private:
const std::unique_ptr<Core::Changelogs> _changelogs;
};
namespace App {
MainWidget *main();
} // namespace App

View file

@ -724,13 +724,3 @@ void MainWindow::sendPaths() {
}
MainWindow::~MainWindow() = default;
namespace App {
MainWindow *wnd() {
return (Core::IsAppLaunched() && Core::App().primaryWindow())
? Core::App().primaryWindow()->widget().get()
: nullptr;
}
} // namespace App

View file

@ -147,7 +147,3 @@ private:
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
};
namespace App {
MainWindow *wnd();
} // namespace App

View file

@ -308,7 +308,7 @@ void Instance::clearStreamed(not_null<Data*> data, bool savePosition) {
data->streamed = nullptr;
_roundPlaying = false;
if (const auto window = App::wnd()) {
if (const auto window = Core::App().primaryWindow()) {
if (const auto controller = window->sessionController()) {
controller->disableGifPauseReason(
Window::GifPauseReason::RoundPlaying);
@ -1292,7 +1292,7 @@ void Instance::handleStreamingUpdate(
requestRoundVideoRepaint();
});
_roundPlaying = true;
if (const auto window = App::wnd()) {
if (const auto window = Core::App().primaryWindow()) {
if (const auto controller = window->sessionController()) {
controller->enableGifPauseReason(
Window::GifPauseReason::RoundPlaying);

View file

@ -303,8 +303,11 @@ void LaunchGApplication() {
app->signal_activate().connect([] {
Core::Sandbox::Instance().customEnterFromEventLoop([] {
if (const auto w = App::wnd()) {
w->activate();
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
window->activate();
}
});
}, true);
@ -329,17 +332,19 @@ void LaunchGApplication() {
continue;
}
if (Core::StartUrlRequiresActivate(url)) {
if (const auto w = App::wnd()) {
w->activate();
const auto window = Core::IsAppLaunched()
? Core::App().primaryWindow()
: nullptr;
if (window) {
window->activate();
}
}
cSetStartUrl(url);
Core::App().checkStartUrl();
}
if (!cSendPaths().isEmpty()) {
if (const auto w = App::wnd()) {
w->sendPaths();
}
Core::App().checkSendPaths();
}
});
}, true);
@ -429,7 +434,7 @@ bool GenerateDesktopFile(
}
return std::string();
}();
if (sourceText.empty()) {
if (!silent) {
LOG(("App Error: Could not open '%1' for read").arg(sourceFile));

View file

@ -341,6 +341,10 @@ void Controller::hideSettingsAndLayer(anim::type animated) {
_widget.ui_hideSettingsAndLayer(animated);
}
bool Controller::isLayerShown() const {
return _widget.ui_isLayerShown();
}
void Controller::sideBarChanged() {
_widget.recountGeometryConstraints();
}

View file

@ -90,6 +90,7 @@ public:
void hideLayer(anim::type animated = anim::type::normal);
void hideSettingsAndLayer(anim::type animated = anim::type::normal);
[[nodiscard]] bool isLayerShown() const;
void activate();
void reActivate();

View file

@ -1769,6 +1769,10 @@ void SessionController::removeLayerBlackout() {
widget()->ui_removeLayerBlackout();
}
bool SessionController::isLayerShown() const {
return _window->isLayerShown();
}
not_null<MainWidget*> SessionController::content() const {
return widget()->sessionContent();
}

View file

@ -446,6 +446,7 @@ public:
showSpecialLayer(nullptr, animated);
}
void removeLayerBlackout();
[[nodiscard]] bool isLayerShown() const;
void showCalendar(
Dialogs::Key chat,