1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 18:55:07 +00:00
serenity/Userland/Applications/SpaceAnalyzer/ProgressWindow.cpp
Sam Atkins 6b66e39df4 LibGUI+Userland: Stop returning Layout from Widget::(try_)set_layout()
Nobody uses this return value any more. It also lets us remove a whole
bunch of `(void)` casts. :^)
2023-02-18 16:56:56 +00:00

48 lines
1.5 KiB
C++

/*
* Copyright (c) 2021-2022, the SerenityOS developers.
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ProgressWindow.h"
#include <LibCore/EventLoop.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Label.h>
ErrorOr<NonnullRefPtr<ProgressWindow>> ProgressWindow::try_create(StringView title, Window* parent)
{
auto window = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProgressWindow(title, parent)));
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
main_widget->set_fill_with_background_color(true);
TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
auto label = TRY(main_widget->try_add<GUI::Label>("Analyzing storage space..."));
label->set_fixed_height(22);
window->m_progress_label = TRY(main_widget->try_add<GUI::Label>());
window->m_progress_label->set_fixed_height(22);
window->update_progress_label(0);
return window;
}
ProgressWindow::ProgressWindow(StringView title, GUI::Window* parent)
: GUI::Window(parent)
{
set_title(title);
set_resizable(false);
set_closeable(false);
resize(240, 50);
center_on_screen();
}
ProgressWindow::~ProgressWindow() = default;
void ProgressWindow::update_progress_label(size_t files_encountered_count)
{
m_progress_label->set_text(DeprecatedString::formatted("{} files...", files_encountered_count));
// FIXME: Why is this necessary to make the window repaint?
Core::EventLoop::current().pump(Core::EventLoop::WaitMode::PollForEvents);
}