mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
SpaceAnalyzer: Extract ProgressWindow into its own class
This commit is contained in:
parent
bcc4e5ee0b
commit
16bbdc812d
4 changed files with 77 additions and 38 deletions
48
Userland/Applications/SpaceAnalyzer/ProgressWindow.cpp
Normal file
48
Userland/Applications/SpaceAnalyzer/ProgressWindow.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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);
|
||||
(void)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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue