mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
ClockSettings: Add a GUI application to set the system time zone
This application can be expanded with other clock-related options. For an initial iteration, it has just an option to change the time zone.
This commit is contained in:
parent
6057a2ca30
commit
d365559839
7 changed files with 177 additions and 0 deletions
53
Userland/Applications/ClockSettings/ClockSettingsWidget.cpp
Normal file
53
Userland/Applications/ClockSettings/ClockSettingsWidget.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ClockSettingsWidget.h"
|
||||
#include <Applications/ClockSettings/ClockSettingsWidgetGML.h>
|
||||
#include <LibGUI/ComboBox.h>
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibTimeZone/TimeZone.h>
|
||||
#include <spawn.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using StringViewListModel = GUI::ItemListModel<StringView, Span<StringView const>>;
|
||||
|
||||
ClockSettingsWidget::ClockSettingsWidget()
|
||||
{
|
||||
load_from_gml(clock_settings_widget_gml);
|
||||
|
||||
static auto time_zones = TimeZone::all_time_zones();
|
||||
m_time_zone = TimeZone::current_time_zone();
|
||||
|
||||
m_time_zone_combo_box = *find_descendant_of_type_named<GUI::ComboBox>("time_zone_input");
|
||||
m_time_zone_combo_box->set_only_allow_values_from_model(true);
|
||||
m_time_zone_combo_box->set_model(*StringViewListModel::create(time_zones));
|
||||
m_time_zone_combo_box->set_text(m_time_zone);
|
||||
}
|
||||
|
||||
void ClockSettingsWidget::reset_default_values()
|
||||
{
|
||||
m_time_zone = "UTC"sv;
|
||||
m_time_zone_combo_box->set_text(m_time_zone);
|
||||
set_time_zone();
|
||||
}
|
||||
|
||||
void ClockSettingsWidget::apply_settings()
|
||||
{
|
||||
m_time_zone = m_time_zone_combo_box->text();
|
||||
set_time_zone();
|
||||
}
|
||||
|
||||
void ClockSettingsWidget::set_time_zone() const
|
||||
{
|
||||
pid_t child_pid = 0;
|
||||
char const* argv[] = { "/bin/timezone", m_time_zone.characters(), nullptr };
|
||||
|
||||
if ((errno = posix_spawn(&child_pid, "/bin/timezone", nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
||||
perror("posix_spawn");
|
||||
exit(1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue