Serenity Operating System
1/*
2 * Copyright (c) 2021-2022, the SerenityOS developers.
3 * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#include "ProgressWindow.h"
9#include <LibCore/EventLoop.h>
10#include <LibGUI/BoxLayout.h>
11#include <LibGUI/Label.h>
12
13ErrorOr<NonnullRefPtr<ProgressWindow>> ProgressWindow::try_create(StringView title, Window* parent)
14{
15 auto window = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProgressWindow(title, parent)));
16
17 auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
18 main_widget->set_fill_with_background_color(true);
19 TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
20
21 auto label = TRY(main_widget->try_add<GUI::Label>("Analyzing storage space..."));
22 label->set_fixed_height(22);
23
24 window->m_progress_label = TRY(main_widget->try_add<GUI::Label>());
25 window->m_progress_label->set_fixed_height(22);
26
27 window->update_progress_label(0);
28 return window;
29}
30
31ProgressWindow::ProgressWindow(StringView title, GUI::Window* parent)
32 : GUI::Window(parent)
33{
34 set_title(title);
35 set_resizable(false);
36 set_closeable(false);
37 resize(240, 50);
38 center_on_screen();
39}
40
41ProgressWindow::~ProgressWindow() = default;
42
43void ProgressWindow::update_progress_label(size_t files_encountered_count)
44{
45 m_progress_label->set_text(DeprecatedString::formatted("{} files...", files_encountered_count));
46 // FIXME: Why is this necessary to make the window repaint?
47 Core::EventLoop::current().pump(Core::EventLoop::WaitMode::PollForEvents);
48}