ProgressWindow.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "ProgressWindow.h"
  8. #include <LibCore/EventLoop.h>
  9. #include <LibGUI/BoxLayout.h>
  10. #include <LibGUI/Label.h>
  11. ErrorOr<NonnullRefPtr<ProgressWindow>> ProgressWindow::try_create(StringView title, Window* parent)
  12. {
  13. auto window = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProgressWindow(title, parent)));
  14. auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
  15. main_widget->set_fill_with_background_color(true);
  16. TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
  17. auto label = TRY(main_widget->try_add<GUI::Label>("Analyzing storage space..."));
  18. label->set_fixed_height(22);
  19. window->m_progress_label = TRY(main_widget->try_add<GUI::Label>());
  20. window->m_progress_label->set_fixed_height(22);
  21. window->update_progress_label(0);
  22. return window;
  23. }
  24. ProgressWindow::ProgressWindow(StringView title, GUI::Window* parent)
  25. : GUI::Window(parent)
  26. {
  27. set_title(title);
  28. set_resizable(false);
  29. set_closeable(false);
  30. resize(240, 50);
  31. center_on_screen();
  32. }
  33. ProgressWindow::~ProgressWindow() = default;
  34. void ProgressWindow::update_progress_label(size_t files_encountered_count)
  35. {
  36. m_progress_label->set_text(DeprecatedString::formatted("{} files...", files_encountered_count));
  37. // FIXME: Why is this necessary to make the window repaint?
  38. Core::EventLoop::current().pump(Core::EventLoop::WaitMode::PollForEvents);
  39. }