ClockSettingsWidget.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2022, cflip <cflip@cflip.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "ClockSettingsWidget.h"
  7. #include <Applications/ClockSettings/ClockSettingsWidgetGML.h>
  8. #include <LibConfig/Client.h>
  9. #include <LibGUI/RadioButton.h>
  10. #include <LibGUI/TextBox.h>
  11. ClockSettingsWidget::ClockSettingsWidget()
  12. {
  13. load_from_gml(clock_settings_widget_gml);
  14. m_24_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("24hour_radio");
  15. auto& twelve_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("12hour_radio");
  16. auto& custom_radio = *find_descendant_of_type_named<GUI::RadioButton>("custom_radio");
  17. custom_radio.set_checked(true);
  18. m_custom_format_input = *find_descendant_of_type_named<GUI::TextBox>("custom_format_input");
  19. m_custom_format_input->set_text(Config::read_string("Taskbar", "Clock", "TimeFormat"));
  20. m_24_hour_radio->on_checked = [&](bool) {
  21. m_custom_format_input->set_enabled(false);
  22. m_custom_format_input->set_text("%T");
  23. };
  24. twelve_hour_radio.on_checked = [&](bool) {
  25. m_custom_format_input->set_enabled(false);
  26. m_custom_format_input->set_text("%I:%M %p");
  27. };
  28. custom_radio.on_checked = [&](bool) {
  29. m_custom_format_input->set_enabled(true);
  30. };
  31. }
  32. void ClockSettingsWidget::apply_settings()
  33. {
  34. Config::write_string("Taskbar", "Clock", "TimeFormat", m_custom_format_input->text());
  35. }
  36. void ClockSettingsWidget::reset_default_values()
  37. {
  38. m_24_hour_radio->set_checked(true);
  39. Config::write_string("Taskbar", "Clock", "TimeFormat", "%T");
  40. }