2021-11-20 14:28:54 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2021-2022, the SerenityOS developers.
|
2022-04-21 15:12:09 +01:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2021-11-20 14:28:54 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-04-21 15:12:09 +01:00
|
|
|
#include <AK/HashMap.h>
|
2021-11-20 14:28:54 +00:00
|
|
|
#include <LibGUI/Button.h>
|
|
|
|
|
#include <LibGUI/TabWidget.h>
|
|
|
|
|
#include <LibGUI/Window.h>
|
|
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class SettingsWindow : public GUI::Window {
|
|
|
|
|
C_OBJECT(SettingsWindow)
|
|
|
|
|
public:
|
|
|
|
|
class Tab : public GUI::Widget {
|
|
|
|
|
public:
|
|
|
|
|
virtual void apply_settings() = 0;
|
2021-11-21 00:57:07 +01:00
|
|
|
virtual void cancel_settings() { }
|
|
|
|
|
virtual void reset_default_values() { }
|
2022-04-29 17:00:24 +01:00
|
|
|
|
|
|
|
|
SettingsWindow& settings_window() { return *m_window; }
|
|
|
|
|
void set_settings_window(SettingsWindow& settings_window) { m_window = settings_window; }
|
|
|
|
|
|
|
|
|
|
void set_modified(bool modified)
|
|
|
|
|
{
|
|
|
|
|
if (m_window)
|
|
|
|
|
m_window->set_modified(modified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
WeakPtr<SettingsWindow> m_window;
|
2021-11-20 14:28:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class ShowDefaultsButton {
|
|
|
|
|
Yes,
|
|
|
|
|
No,
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-28 08:34:04 +01:00
|
|
|
static ErrorOr<NonnullRefPtr<SettingsWindow>> create(String title, ShowDefaultsButton = ShowDefaultsButton::No);
|
|
|
|
|
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~SettingsWindow() override = default;
|
2021-11-20 14:28:54 +00:00
|
|
|
|
|
|
|
|
template<class T, class... Args>
|
2022-04-21 15:12:09 +01:00
|
|
|
ErrorOr<NonnullRefPtr<T>> add_tab(String title, StringView id, Args&&... args)
|
2021-11-20 14:28:54 +00:00
|
|
|
{
|
2021-11-27 17:37:00 +01:00
|
|
|
auto tab = TRY(m_tab_widget->try_add_tab<T>(move(title), forward<Args>(args)...));
|
2022-04-21 15:12:09 +01:00
|
|
|
TRY(m_tabs.try_set(id, tab));
|
2022-04-29 17:00:24 +01:00
|
|
|
tab->set_settings_window(*this);
|
2021-11-27 17:37:00 +01:00
|
|
|
return tab;
|
2021-11-20 14:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-21 15:34:53 +01:00
|
|
|
Optional<NonnullRefPtr<Tab>> get_tab(StringView id) const;
|
|
|
|
|
void set_active_tab(StringView id);
|
|
|
|
|
|
2022-04-29 17:00:24 +01:00
|
|
|
void apply_settings();
|
|
|
|
|
void cancel_settings();
|
|
|
|
|
void reset_default_values();
|
|
|
|
|
|
|
|
|
|
void set_modified(bool);
|
|
|
|
|
|
2021-11-20 14:28:54 +00:00
|
|
|
private:
|
2022-02-26 10:50:04 -07:00
|
|
|
SettingsWindow() = default;
|
2021-11-20 14:28:54 +00:00
|
|
|
|
|
|
|
|
RefPtr<GUI::TabWidget> m_tab_widget;
|
2022-04-21 15:12:09 +01:00
|
|
|
HashMap<StringView, NonnullRefPtr<Tab>> m_tabs;
|
2021-11-20 14:28:54 +00:00
|
|
|
|
|
|
|
|
RefPtr<GUI::Button> m_ok_button;
|
|
|
|
|
RefPtr<GUI::Button> m_cancel_button;
|
|
|
|
|
RefPtr<GUI::Button> m_apply_button;
|
|
|
|
|
RefPtr<GUI::Button> m_reset_button;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|