2022-03-25 18:31:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Maciej <sppmacd@pm.me>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGUI/SettingsWindow.h>
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
|
|
|
namespace NetworkSettings {
|
|
|
|
|
|
|
|
class NetworkSettingsWidget : public GUI::SettingsWindow::Tab {
|
2023-05-09 20:57:02 +00:00
|
|
|
C_OBJECT_ABSTRACT(NetworkSettingsWidget)
|
2022-03-25 18:31:47 +00:00
|
|
|
|
|
|
|
public:
|
2024-01-22 15:52:25 +00:00
|
|
|
static ErrorOr<NonnullRefPtr<NetworkSettingsWidget>> try_create();
|
|
|
|
ErrorOr<void> initialize();
|
2023-05-09 20:57:02 +00:00
|
|
|
|
2022-03-25 18:31:47 +00:00
|
|
|
virtual void apply_settings() override;
|
2023-12-16 14:19:34 +00:00
|
|
|
void switch_adapter(ByteString const& adapter);
|
2022-03-25 18:31:47 +00:00
|
|
|
|
|
|
|
private:
|
2023-05-09 20:57:02 +00:00
|
|
|
NetworkSettingsWidget() = default;
|
2022-03-25 18:31:47 +00:00
|
|
|
|
|
|
|
struct NetworkAdapterData {
|
|
|
|
bool enabled = false;
|
|
|
|
bool dhcp = false;
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString ip_address;
|
2022-03-25 18:31:47 +00:00
|
|
|
int cidr = 0;
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString default_gateway;
|
2022-03-25 18:31:47 +00:00
|
|
|
};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
void on_switch_adapter(ByteString const& adapter);
|
2022-03-25 18:31:47 +00:00
|
|
|
void on_switch_enabled_or_dhcp();
|
2023-04-27 19:07:07 +00:00
|
|
|
ErrorOr<void> apply_settings_impl();
|
|
|
|
ErrorOr<Optional<JsonObject>> create_settings_object();
|
2022-03-25 18:31:47 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
HashMap<ByteString, NetworkAdapterData> m_network_adapters;
|
|
|
|
Vector<ByteString> m_adapter_names;
|
2022-03-25 18:31:47 +00:00
|
|
|
NetworkAdapterData* m_current_adapter_data = nullptr;
|
|
|
|
|
|
|
|
RefPtr<GUI::CheckBox> m_enabled_checkbox;
|
|
|
|
RefPtr<GUI::CheckBox> m_dhcp_checkbox;
|
|
|
|
RefPtr<GUI::ComboBox> m_adapters_combobox;
|
|
|
|
RefPtr<GUI::TextBox> m_ip_address_textbox;
|
|
|
|
RefPtr<GUI::SpinBox> m_cidr_spinbox;
|
|
|
|
RefPtr<GUI::TextBox> m_default_gateway_textbox;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|