summaryrefslogtreecommitdiff
path: root/ui/src/windows
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-04-29 16:33:32 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-04-29 16:33:32 +0200
commit3ff5bd46952144926d9bd9beedf50023a51913ee (patch)
tree2c579fe13bbb5cc90f8f50e7af35218c98e123d5 /ui/src/windows
parent873bf396b904ce477a238f22d1891e1b03f24eff (diff)
downloadturns-3ff5bd46952144926d9bd9beedf50023a51913ee.tar.xz
turns-3ff5bd46952144926d9bd9beedf50023a51913ee.zip
ui: flatten namespace hierarchy
Diffstat (limited to 'ui/src/windows')
-rw-r--r--ui/src/windows/tracker.cpp240
-rw-r--r--ui/src/windows/tracker.ui153
-rw-r--r--ui/src/windows/tracker/actions.cpp125
-rw-r--r--ui/src/windows/tracker/event_handlers.cpp105
4 files changed, 0 insertions, 623 deletions
diff --git a/ui/src/windows/tracker.cpp b/ui/src/windows/tracker.cpp
deleted file mode 100644
index 851d233..0000000
--- a/ui/src/windows/tracker.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-#include "turns/ui/windows/tracker.hpp"
-
-#include "turns/core/turn_order.hpp"
-#include "turns/lang/messages.hpp"
-#include "turns/ui/widgets/turn_order_view.hpp"
-
-#include <sigc++/adaptors/bind.h>
-#include <sigc++/functors/mem_fun.h>
-
-#include <glibmm/binding.h>
-#include <glibmm/i18n.h>
-#include <glibmm/propertyproxy.h>
-#include <glibmm/refptr.h>
-#include <glibmm/ustring.h>
-#include <glibmm/varianttype.h>
-#include <glibmm/wrap.h>
-
-#include <giomm/file.h>
-#include <giomm/liststore.h>
-#include <giomm/settings.h>
-
-#include <gtkmm/applicationwindow.h>
-#include <gtkmm/builder.h>
-#include <gtkmm/button.h>
-#include <gtkmm/cssprovider.h>
-#include <gtkmm/error.h>
-#include <gtkmm/filedialog.h>
-#include <gtkmm/object.h>
-#include <gtkmm/revealer.h>
-#include <gtkmm/stack.h>
-#include <gtkmm/styleprovider.h>
-#include <gtkmm/widget.h>
-
-#include <adwaitamm/applicationwindow.hpp>
-#include <adwaitamm/toast.hpp>
-#include <adwaitamm/toastoverlay.hpp>
-#include <adwaitamm/windowtitle.hpp>
-
-#include <gtk/gtk.h>
-#include <nlohmann/json.hpp>
-
-#include <exception>
-#include <format>
-#include <print>
-#include <string>
-#include <utility>
-
-namespace turns::ui::windows
-{
-
- tracker::tracker(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder, Glib::RefPtr<Gio::Settings> settings)
- : ApplicationWindow{base}
- , m_controls{builder->get_widget<Gtk::Revealer>("controls")}
- , m_empty{builder->get_widget<Gtk::Widget>("empty")}
- , m_overlay{builder->get_widget<Adwaita::ToastOverlay>("overlay")}
- , m_stack{builder->get_widget<Gtk::Stack>("stack")}
- , m_start{builder->get_widget<Gtk::Button>("start")}
- , m_title{builder->get_widget<Adwaita::WindowTitle>("title")}
- , m_turn_order{core::turn_order::create()}
- , m_turn_order_view{Gtk::make_managed<widgets::turn_order_view>(m_turn_order)}
- , m_settings{std::move(settings)}
- , m_subtitle{m_title->property_subtitle()}
- , m_css{Gtk::CssProvider::create()}
- {
- setup_colors();
- setup_actions();
-
- m_stack->add(*m_turn_order_view);
-
- m_turn_order->is_empty().signal_changed().connect(sigc::mem_fun(*this, &tracker::update_subtitle));
- m_turn_order->round_number().signal_changed().connect(sigc::mem_fun(*this, &tracker::update_subtitle));
- update_subtitle();
-
- // clang-format off
- Glib::Binding::bind_property(m_turn_order->is_empty(),
- m_stack->property_visible_child(),
- Glib::Binding::Flags::SYNC_CREATE,
- [this](auto empty) { return empty ? m_empty : m_turn_order_view; });
-
- Glib::Binding::bind_property(m_turn_order->is_running(),
- m_controls->property_reveal_child(),
- Glib::Binding::Flags::SYNC_CREATE);
- // clang-format on
-
- m_settings->bind("skip-defeated", m_turn_order->skip_defeated());
- }
-
- auto tracker::setup_actions() -> void
- {
- // win.add_participant
- // depends-on: turn_order:state == stopped
- {
- auto action = add_action("add_participant", sigc::mem_fun(*this, &tracker::add_participant));
-
- Glib::Binding::bind_property(m_turn_order->is_running(),
- action->property_enabled(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
- }
-
- // win.clear
- // depends-on: turn_order:is_empty == false
- {
- auto action = add_action("clear", sigc::mem_fun(*m_turn_order, &core::turn_order::clear));
-
- Glib::Binding::bind_property(m_turn_order->is_empty(),
- action->property_enabled(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
- }
-
- // win.next
- // depends-on: turn_order:state == running
- {
- auto action = add_action("next", sigc::mem_fun(*m_turn_order, &core::turn_order::next));
-
- Glib::Binding::bind_property(m_turn_order->is_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE);
- }
-
- // win.previous
- // depends-on: turn_order:has_previous == true
- {
- auto action = add_action("previous", sigc::mem_fun(*m_turn_order, &core::turn_order::previous));
-
- Glib::Binding::bind_property(m_turn_order->has_previous(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE);
- }
-
- // win.start
- // depends-on: turn_order:is_empty == false
- {
- auto action = add_action("start", sigc::mem_fun(*m_turn_order, &core::turn_order::start));
-
- Glib::Binding::bind_property(m_turn_order->is_empty(),
- action->property_enabled(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
-
- Glib::Binding::bind_property(m_turn_order->is_running(),
- m_start->property_visible(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
- }
-
- // win.stop
- // depends-on: turn_order:running == true
- {
- auto action = add_action("stop", sigc::mem_fun(*this, &tracker::stop));
-
- Glib::Binding::bind_property(m_turn_order->is_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE);
- }
-
- // win.delete
- // win.edit
- // win.open
- // win.preferences
- {
- add_action_with_parameter("delete", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::delete_participant));
- add_action_with_parameter("edit", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::edit_participant));
- add_action("open", sigc::mem_fun(*this, &tracker::open));
- add_action("preferences", sigc::mem_fun(*this, &tracker::preferences));
- }
-
- // win.save
- // depends-on: turn_order:is_empty == false
- {
- auto action = add_action("save", sigc::bind(sigc::mem_fun(*this, &tracker::save), false));
-
- Glib::Binding::bind_property(m_turn_order->is_empty(),
- action->property_enabled(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
- }
-
- // win.save-as
- // depends-on: turn_order:is_empty == false
- {
- auto action = add_action("save-as", sigc::bind(sigc::mem_fun(*this, &tracker::save), true));
-
- Glib::Binding::bind_property(m_turn_order->is_empty(),
- action->property_enabled(),
- Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
- }
- }
-
- auto tracker::setup_colors() -> void
- {
- Gtk::CssProvider::add_provider_for_display(get_display(), m_css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- m_settings->signal_changed().connect(sigc::mem_fun(*this, &tracker::on_settings_changed));
- update_colors();
- }
-
- auto tracker::start_replace_content() -> void
- {
- m_file_buffer = m_turn_order->serialize().dump(2);
- m_file->replace_contents_async(sigc::mem_fun(*this, &tracker::on_replace_content_done), m_file_buffer, m_file_etag);
- }
-
- auto tracker::show_error(std::exception const & e) -> void
- {
- auto error = e.what();
- show_toast(std::vformat(_(lang::saving_failed_format), std::make_format_args(error)));
- }
-
- auto tracker::show_toast(std::string const & message) -> void
- {
- m_overlay->add_toast(*Adwaita::Toast::create(message));
- }
-
- auto tracker::update_colors() -> void
- {
- auto friendly_color = m_settings->get_string("disposition-color-friendly");
- auto hostile_color = m_settings->get_string("disposition-color-hostile");
- auto secret_color = m_settings->get_string("disposition-color-secret");
- m_css->load_from_string(std::format("@define-color friendly {};\n"
- "@define-color hostile {};\n"
- "@define-color secret {};\n",
- friendly_color.c_str(),
- hostile_color.c_str(),
- secret_color.c_str()));
- }
-
- auto tracker::update_subtitle() -> void
- {
- if (m_turn_order->is_empty())
- {
- m_subtitle = _(lang::no_active_turn_order);
- }
- else
- {
- auto round_number = m_turn_order->round_number() + 1;
- m_subtitle = round_number == 0 ? "" : std::vformat(_(lang::round_number), std::make_format_args(round_number));
- }
- }
-
- auto tracker::load(Glib::RefPtr<Gio::File> file) -> void
- {
- if (file->query_exists())
- {
- m_file = file;
- m_file->load_contents_async(sigc::mem_fun(*this, &tracker::on_load_content_done));
- set_sensitive(false);
- }
- }
-
-} // namespace turns::ui::windows
diff --git a/ui/src/windows/tracker.ui b/ui/src/windows/tracker.ui
deleted file mode 100644
index b875d10..0000000
--- a/ui/src/windows/tracker.ui
+++ /dev/null
@@ -1,153 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Created with Cambalache 0.96.0 -->
-<interface>
- <!-- interface-name tracker.ui -->
- <requires lib="gio" version="2.0"/>
- <requires lib="gtk" version="4.18"/>
- <requires lib="libadwaita" version="1.7"/>
- <object class="AdwApplicationWindow" id="tracker">
- <property name="content">
- <object class="AdwToolbarView">
- <property name="content">
- <object class="AdwToastOverlay" id="overlay">
- <property name="child">
- <object class="GtkStack" id="stack">
- <child>
- <object class="AdwStatusPage" id="empty">
- <property name="child">
- <object class="GtkButton">
- <property name="action-name">win.add_participant</property>
- <property name="halign">center</property>
- <property name="label" translatable="yes">Add participant</property>
- <style>
- <class name="pill"/>
- <class name="suggested-action"/>
- </style>
- </object>
- </property>
- <property name="icon-name">contact-new-symbolic</property>
- </object>
- </child>
- </object>
- </property>
- </object>
- </property>
- <child type="top">
- <object class="AdwHeaderBar" id="header">
- <property name="centering-policy">strict</property>
- <property name="title-widget">
- <object class="AdwWindowTitle" id="title">
- <property name="hexpand">True</property>
- <property name="subtitle" translatable="yes">No active turn order</property>
- <property name="title" translatable="yes">Turns</property>
- </object>
- </property>
- <child type="end">
- <object class="GtkMenuButton" id="open_main_menu">
- <property name="icon-name">open-menu</property>
- <property name="menu-model">main_menu</property>
- <property name="tooltip-text" translatable="yes">Main Menu</property>
- <property name="use-underline">True</property>
- </object>
- </child>
- <child type="start">
- <object class="GtkButton" id="add_participant">
- <property name="action-name">win.add_participant</property>
- <property name="icon-name">contact-new</property>
- <property name="tooltip-text" translatable="yes">Add participant</property>
- </object>
- </child>
- <child type="start">
- <object class="GtkButton" id="start">
- <property name="action-name">win.start</property>
- <property name="icon-name">media-playback-start-symbolic</property>
- <property name="tooltip-text" translatable="yes">Start turn order</property>
- </object>
- </child>
- <style/>
- </object>
- </child>
- <child type="bottom">
- <object class="GtkRevealer" id="controls">
- <property name="child">
- <object class="GtkActionBar">
- <child type="start">
- <object class="GtkButton">
- <property name="action-name">win.previous</property>
- <property name="icon-name">media-skip-backward-symbolic</property>
- <property name="tooltip-markup" translatable="yes">Previous participant</property>
- <style>
- <class name="pill"/>
- <class name="suggested-action"/>
- </style>
- </object>
- </child>
- <child type="center">
- <object class="GtkButton">
- <property name="action-name">win.stop</property>
- <property name="icon-name">media-playback-stop-symbolic</property>
- <property name="tooltip-markup" translatable="yes">End turn order</property>
- <style>
- <class name="pill"/>
- <class name="destructive-action"/>
- </style>
- </object>
- </child>
- <child type="end">
- <object class="GtkButton">
- <property name="action-name">win.next</property>
- <property name="icon-name">media-skip-forward-symbolic</property>
- <property name="tooltip-markup" translatable="yes">Next participant</property>
- <style>
- <class name="pill"/>
- <class name="suggested-action"/>
- </style>
- </object>
- </child>
- <style>
- <class name="toolbar"/>
- </style>
- </object>
- </property>
- <property name="transition-type">slide-up</property>
- </object>
- </child>
- <style/>
- </object>
- </property>
- <property name="default-height">720</property>
- <property name="default-width">360</property>
- <property name="height-request">480</property>
- <property name="width-request">360</property>
- </object>
- <menu id="main_menu">
- <item>
- <attribute name="action">win.clear</attribute>
- <attribute name="label" translatable="yes">_Clear</attribute>
- </item>
- <item>
- <attribute name="action">win.open</attribute>
- <attribute name="label" translatable="yes">_Open...</attribute>
- </item>
- <item>
- <attribute name="action">win.save</attribute>
- <attribute name="label" translatable="yes">_Save</attribute>
- </item>
- <item>
- <attribute name="action">win.save-as</attribute>
- <attribute name="label" translatable="yes">Save as...</attribute>
- </item>
- <item>
- <attribute name="action">win.preferences</attribute>
- <attribute name="label" translatable="yes">_Preferences</attribute>
- </item>
- <item>
- <attribute name="action">app.quit</attribute>
- <attribute name="label" translatable="yes">_Quit</attribute>
- </item>
- <item>
- <attribute name="action">app.about</attribute>
- <attribute name="label">About</attribute>
- </item>
- </menu>
-</interface>
diff --git a/ui/src/windows/tracker/actions.cpp b/ui/src/windows/tracker/actions.cpp
deleted file mode 100644
index 54580ca..0000000
--- a/ui/src/windows/tracker/actions.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-#include "turns/core/participant.hpp"
-#include "turns/lang/messages.hpp"
-#include "turns/ui/widgets/participant_editor.hpp"
-#include "turns/ui/widgets/preferences.hpp"
-#include "turns/ui/windows/tracker.hpp"
-
-#include <sigc++/adaptors/bind.h>
-#include <sigc++/functors/mem_fun.h>
-
-#include <glibmm/i18n.h>
-#include <glibmm/refptr.h>
-#include <glibmm/ustring.h>
-#include <glibmm/variant.h>
-#include <glibmm/wrap.h>
-
-#include <giomm/liststore.h>
-#include <giomm/settings.h>
-
-#include <gtkmm/builder.h>
-#include <gtkmm/filedialog.h>
-#include <gtkmm/filefilter.h>
-#include <gtkmm/object.h>
-
-#include <adwaitamm/alertdialog.hpp>
-#include <adwaitamm/dialog.hpp>
-#include <adwaitamm/enums.hpp>
-#include <adwaitamm/preferencesdialog.hpp>
-
-#include <gio/gio.h>
-#include <gtk/gtk.h>
-
-#include <utility>
-
-namespace turns::ui::windows
-{
- namespace
- {
- auto file_filters()
- {
- auto filters = Gio::ListStore<Gtk::FileFilter>::create();
- auto filter = Gtk::FileFilter::create();
- filter->set_name(_("Turns Files"));
- filter->add_pattern("*.trns");
- filters->append(filter);
- return filters;
- }
- } // namespace
-
- auto tracker::add_participant() -> void
- {
- auto dialog = Gtk::make_managed<widgets::ParticipantEditor>(nullptr);
- dialog->present(this);
- dialog->signal_finished().connect([this](auto n, auto p, auto d) { m_turn_order->add(n, p, d); });
- }
-
- auto tracker::delete_participant(Glib::VariantBase param) -> void
- {
- auto index = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(param);
- m_turn_order->remove(index.get());
- }
-
- auto tracker::edit_participant(Glib::VariantBase param) -> void
- {
- auto index = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(param);
- auto participant = m_turn_order->get_typed_object<core::participant>(index.get());
- auto dialog = Gtk::make_managed<widgets::ParticipantEditor>(participant);
- dialog->present(this);
- }
-
- auto tracker::open() -> void
- {
- auto dialog = Gtk::FileDialog::create();
- dialog->set_filters(file_filters());
- dialog->open(sigc::bind(sigc::mem_fun(*this, &tracker::on_open_response), dialog));
- }
-
- auto tracker::preferences() -> void
- {
- auto preferences = Gtk::make_managed<widgets::preferences>(m_settings);
- auto dialog = Gtk::make_managed<Adwaita::PreferencesDialog>();
- dialog->add(*preferences);
- dialog->set_visible_page(*preferences);
- dialog->present(this);
- }
-
- auto tracker::save(bool force_ask) -> void
- {
- if (m_file && !force_ask)
- {
- start_replace_content();
- }
- else
- {
- auto dialog = Gtk::FileDialog::create();
- m_file ? dialog->set_initial_file(m_file) : dialog->set_initial_name(_(lang::new_turn_order_file_name));
- dialog->set_filters(file_filters());
- dialog->save(*this, sigc::bind(sigc::mem_fun(*this, &tracker::on_save_response), dialog));
- }
- }
-
- auto tracker::stop() -> void
- {
- auto dialog = Adwaita::AlertDialog::create(_(lang::stop_turn_order), _(lang::question_clear_turn_order));
- dialog->add_response("stop", _(lang::stop));
- dialog->set_response_appearance("stop", Adwaita::ResponseAppearance::Suggested);
- dialog->add_response("clear", _(lang::stop_and_clear));
- dialog->set_response_appearance("clear", Adwaita::ResponseAppearance::Destructive);
- dialog->add_response("cancel", _(lang::cancel));
- dialog->set_response_appearance("cancel", Adwaita::ResponseAppearance::Default);
- dialog->set_close_response("cancel");
- dialog->set_default_response("cancel");
- dialog->choose(*this, nullptr, [dialog = std::move(dialog), this](auto const & result) {
- auto response = dialog->choose_finish(result);
- if (response == "cancel")
- {
- return;
- }
- if (response == "clear")
- {
- m_turn_order->clear();
- }
- m_turn_order->stop();
- });
- }
-} // namespace turns::ui::windows \ No newline at end of file
diff --git a/ui/src/windows/tracker/event_handlers.cpp b/ui/src/windows/tracker/event_handlers.cpp
deleted file mode 100644
index a3cf788..0000000
--- a/ui/src/windows/tracker/event_handlers.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-#include "turns/lang/messages.hpp"
-#include "turns/ui/windows/tracker.hpp"
-
-#include <sigc++/functors/mem_fun.h>
-
-#include <glibmm/i18n.h>
-#include <glibmm/refptr.h>
-#include <glibmm/ustring.h>
-
-#include <giomm/asyncresult.h>
-#include <giomm/error.h>
-
-#include <gtkmm/filedialog.h>
-
-#include <nlohmann/json.hpp>
-
-#include <cstddef>
-#include <exception>
-#include <format>
-#include <string_view>
-
-namespace turns::ui::windows
-{
-
- auto tracker::on_load_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void
- {
- set_sensitive();
- char * data{};
- auto size = std::size_t{};
-
- try
- {
- if (!m_file->load_contents_finish(result, data, size, m_file_etag))
- {
- m_file.reset();
- m_file_etag.clear();
- return;
- }
-
- m_turn_order->load(nlohmann::json::parse(std::string_view{data, size}));
- }
- catch (std::exception const & e)
- {
- return show_error(e);
- }
-
- auto name = m_file->get_basename();
- show_toast(std::vformat(_(lang::successfully_opened_format), std::make_format_args(name)));
- set_title(std::format("{} - {}", _(lang::turns), name));
- }
-
- auto tracker::on_replace_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void
- {
- set_sensitive();
-
- try
- {
- m_file->replace_contents_finish(result, m_file_etag);
- }
- catch (Gio::Error const & e)
- {
- return show_error(e);
- }
-
- auto name = m_file->get_basename();
- show_toast(std::vformat(_(lang::successfully_saved_format), std::make_format_args(name)));
- set_title(std::format("{} - {}", _(lang::turns), name));
- }
-
- auto tracker::on_open_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void
- {
- try
- {
- m_file = dialog->open_finish(result);
- }
- catch (std::exception const & e)
- {
- return show_error(e);
- }
-
- m_file->load_contents_async(sigc::mem_fun(*this, &tracker::on_load_content_done));
- set_sensitive(false);
- }
-
- auto tracker::on_save_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void
- {
- try
- {
- m_file = dialog->save_finish(result);
- }
- catch (std::exception const & e)
- {
- show_error(e);
- }
-
- start_replace_content();
- set_sensitive(false);
- }
-
- auto tracker::on_settings_changed(Glib::ustring) -> void
- {
- update_colors();
- }
-
-} // namespace turns::ui::windows \ No newline at end of file