From 4d0a7d99ebf55ad2d0e583759699b8b4d77a7907 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 24 Jul 2024 13:23:55 +0200 Subject: app: move ui code to ui library --- app/CMakeLists.txt | 71 +-------- app/include/turns/app/application.hpp | 2 +- app/include/turns/app/widgets/participant_row.hpp | 49 ------ app/include/turns/app/widgets/template_widget.hpp | 64 -------- app/include/turns/app/widgets/turn_order_view.hpp | 36 ----- .../turns/app/windows/participant_editor.hpp | 54 ------- app/include/turns/app/windows/tracker.hpp | 48 ------ app/src/application.cpp | 6 +- app/src/widgets/participant_row.cpp | 133 ---------------- app/src/widgets/turn_order_view.cpp | 49 ------ app/src/windows/participant_editor.cpp | 91 ----------- app/src/windows/tracker.cpp | 177 --------------------- app/tests/widgets/participant_row.cpp | 24 --- app/tests/windows/participant_editor.cpp | 111 ------------- app/tests/windows/tracker.cpp | 75 --------- 15 files changed, 11 insertions(+), 979 deletions(-) delete mode 100644 app/include/turns/app/widgets/participant_row.hpp delete mode 100644 app/include/turns/app/widgets/template_widget.hpp delete mode 100644 app/include/turns/app/widgets/turn_order_view.hpp delete mode 100644 app/include/turns/app/windows/participant_editor.hpp delete mode 100644 app/include/turns/app/windows/tracker.hpp delete mode 100644 app/src/widgets/participant_row.cpp delete mode 100644 app/src/widgets/turn_order_view.cpp delete mode 100644 app/src/windows/participant_editor.cpp delete mode 100644 app/src/windows/tracker.cpp delete mode 100644 app/tests/widgets/participant_row.cpp delete mode 100644 app/tests/windows/participant_editor.cpp delete mode 100644 app/tests/windows/tracker.cpp (limited to 'app') diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 22cf9bf..c39bdf8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,30 +1,15 @@ -# Library +# Application -add_library("app" +add_executable("app" "src/application.cpp" - "src/widgets/participant_row.cpp" - "src/widgets/turn_order_view.cpp" - "src/windows/participant_editor.cpp" - "src/windows/tracker.cpp" -) - -add_library("turns::app" ALIAS "app") - -target_compile_options("app" PUBLIC - "$<$:-Wall>" - "$<$:-Wextra>" - "$<$:-Werror>" - "$<$:-pedantic-errors>" - PRIVATE - "$<$,$>:-fprofile-arcs>" - "$<$,$>:-ftest-coverage>" + "src/main.cpp" ) -target_include_directories("app" PUBLIC +target_include_directories("app" PRIVATE "include" ) -target_link_libraries("app" PUBLIC +target_link_libraries("app" PRIVATE "$<$,$>:gcov>" "PkgConfig::adwaita" @@ -34,49 +19,7 @@ target_link_libraries("app" PUBLIC "turns::lang" "$<$:-Wl,--whole-archive>" - "turns::res" + "turns::ui" + "turns::style" "$<$:-Wl,--no-whole-archive>" ) - -# Application - -add_executable("exe" - "src/main.cpp" -) - -target_link_libraries("exe" PRIVATE - "turns::app" -) - -set_target_properties("exe" PROPERTIES - OUTPUT_NAME "turns" -) - -install(TARGETS "exe" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" -) - -configure_file("desktop.in" - "turns.desktop" -) - -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/turns.desktop" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" -) - -# Tests - -add_executable("app-tests" - "tests/widgets/participant_row.cpp" - "tests/windows/participant_editor.cpp" - "tests/windows/tracker.cpp" -) - -target_link_libraries("app-tests" PRIVATE - "Catch2::Catch2" - "turns::app" - "turns::gtk-test-main" -) - -catch_discover_tests("app-tests") \ No newline at end of file diff --git a/app/include/turns/app/application.hpp b/app/include/turns/app/application.hpp index 67217f0..c8bc862 100644 --- a/app/include/turns/app/application.hpp +++ b/app/include/turns/app/application.hpp @@ -1,7 +1,7 @@ #ifndef TURNS_APP_APPLICATION_HPP #define TURNS_APP_APPLICATION_HPP -#include "turns/app/windows/tracker.hpp" +#include "turns/ui/windows/fwd.hpp" #include diff --git a/app/include/turns/app/widgets/participant_row.hpp b/app/include/turns/app/widgets/participant_row.hpp deleted file mode 100644 index 88360db..0000000 --- a/app/include/turns/app/widgets/participant_row.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef TURNS_APP_WIDGETS_PARTICIPANT_ROW_HPP -#define TURNS_APP_WIDGETS_PARTICIPANT_ROW_HPP - -#include "turns/app/widgets/template_widget.hpp" -#include "turns/core/fwd.hpp" - -#include -#include - -#include -#include -#include -#include - -#include - -namespace turns::app::widgets -{ - struct participant_row : template_widget - { - auto constexpr inline static children = std::array{ - "delete", - "edit", - "subtitle", - "title", - "toggle_defeated", - }; - - participant_row(Glib::RefPtr participant); - - auto property_delete_enabled() -> Glib::PropertyProxy; - auto property_edit_enabled() -> Glib::PropertyProxy; - - private: - auto handle_delete() -> void; - auto handle_edit() -> void; - - Gtk::Button * m_delete; - Gtk::Button * m_edit; - Gtk::Label * m_subtitle; - Gtk::Label * m_title; - Gtk::ToggleButton * m_toggle_defeated; - - Glib::Property m_delete_enabled; - Glib::Property m_edit_enabled; - }; -} // namespace turns::app::widgets - -#endif \ No newline at end of file diff --git a/app/include/turns/app/widgets/template_widget.hpp b/app/include/turns/app/widgets/template_widget.hpp deleted file mode 100644 index 5643cb4..0000000 --- a/app/include/turns/app/widgets/template_widget.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef TURNS_APP_WIDGETS_TEMPLATE_WIDGET_HPP -#define TURNS_APP_WIDGETS_TEMPLATE_WIDGET_HPP - -#include -#include - -#include - -#include - -#include -#include - -namespace turns::app::widgets -{ - - template - struct template_widget : Glib::ExtraClassInit, - BaseWidgetType - { - template - template_widget(Glib::ustring && resource_path, BaseWidgetCtorArgTypes &&... base_widget_ctor_args) - : Glib::ExtraClassInit{class_init, &resource_path, instance_init} - , BaseWidgetType{std::forward(base_widget_ctor_args)...} - { - } - - protected: - template - auto get_widget(char const * name) -> WidgetType * - { - auto self = static_cast(this); - auto widget = GTK_WIDGET(self->gobj()); - auto type = G_OBJECT_TYPE(self->gobj()); - auto child = GTK_WIDGET(gtk_widget_get_template_child(widget, type, name)); - g_assert_nonnull(child); - return dynamic_cast(Glib::wrap(child)); - } - - private: - auto static class_init(void * g_class, void * g_class_data) -> void - { - g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class)); - - auto resource_path = static_cast(g_class_data); - - gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(g_class), resource_path->c_str()); - - std::ranges::for_each(CustomWidgetType::children, [g_class](auto const & child) { - gtk_widget_class_bind_template_child_full(GTK_WIDGET_CLASS(g_class), child, false, 0); - }); - } - - auto static instance_init(GTypeInstance * instance, void * /* type_class */) -> void - { - g_return_if_fail(GTK_IS_WIDGET(instance)); - - gtk_widget_init_template(GTK_WIDGET(instance)); - } - }; - -} // namespace turns::app::widgets - -#endif \ No newline at end of file diff --git a/app/include/turns/app/widgets/turn_order_view.hpp b/app/include/turns/app/widgets/turn_order_view.hpp deleted file mode 100644 index 88dcde1..0000000 --- a/app/include/turns/app/widgets/turn_order_view.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TURNS_APP_WIDGETS_TURN_ORDER_VIEW_HPP -#define TURNS_APP_WIDGETS_TURN_ORDER_VIEW_HPP - -#include "turns/app/widgets/template_widget.hpp" -#include "turns/core/fwd.hpp" - -#include -#include - -#include -#include -#include - -#include - -namespace turns::app::widgets -{ - struct turn_order_view : template_widget - { - using model_type = core::turn_order; - - auto constexpr inline static children = std::array{ - "view", - }; - - explicit turn_order_view(Glib::RefPtr model = {}); - - private: - auto handle_create_row(Glib::RefPtr const item) -> Gtk::Widget *; - - Glib::RefPtr m_model; - Gtk::ListBox * m_view; - }; -} // namespace turns::app::widgets - -#endif \ No newline at end of file diff --git a/app/include/turns/app/windows/participant_editor.hpp b/app/include/turns/app/windows/participant_editor.hpp deleted file mode 100644 index 1fa42bb..0000000 --- a/app/include/turns/app/windows/participant_editor.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef TURNS_APP_WINDOWS_PARTICIPANT_EDITOR_HPP -#define TURNS_APP_WINDOWS_PARTICIPANT_EDITOR_HPP - -#include "turns/core/fwd.hpp" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace turns::app::windows -{ - - struct participant_editor : Gtk::Widget - { - using signal_finished_type = sigc::signal; - - participant_editor(BaseObjectType * base, Glib::RefPtr const builder, Glib::RefPtr obj = {}); - - auto present(Gtk::Widget * parent) -> void; - - auto signal_finished() -> signal_finished_type; - - private: - auto handle_finish_clicked() -> void; - auto handle_item_bind(Glib::RefPtr item) -> void; - auto handle_item_setup(Glib::RefPtr item) -> void; - - AdwDialog * m_adw; - AdwComboRow * m_disposition; - Gtk::Button * m_finish; - AdwEntryRow * m_name; - AdwSpinRow * m_priority; - - Glib::RefPtr m_disposition_factory; - Glib::RefPtr m_disposition_model; - - Glib::RefPtr m_participant; - - signal_finished_type m_signal_finished{}; - }; - -} // namespace turns::app::windows - -#endif \ No newline at end of file diff --git a/app/include/turns/app/windows/tracker.hpp b/app/include/turns/app/windows/tracker.hpp deleted file mode 100644 index bf3531a..0000000 --- a/app/include/turns/app/windows/tracker.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef TURNS_APP_WINDOWS_TRACKER_HPP -#define TURNS_APP_WINDOWS_TRACKER_HPP - -#include "turns/app/widgets/turn_order_view.hpp" -#include "turns/core/turn_order.hpp" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace turns::app::windows -{ - - struct tracker : Gtk::ApplicationWindow - { - tracker(BaseObjectType * base, Glib::RefPtr const builder); - - private: - auto handle_add_participant() -> void; - auto handle_delete_participant(Glib::VariantBase param) -> void; - auto handle_edit_participant(Glib::VariantBase param) -> void; - auto handle_stop() -> void; - - auto setup_actions() -> void; - - AdwApplicationWindow * m_adw; - Gtk::Revealer * m_controls; - Gtk::Widget * m_empty; - Gtk::Stack * m_stack; - Gtk::Button * m_start; - AdwWindowTitle * m_title; - Glib::RefPtr m_turn_order; - widgets::turn_order_view * m_turn_order_view; - Glib::PropertyProxy m_subtitle; - }; - -} // namespace turns::app::windows - -#endif \ No newline at end of file diff --git a/app/src/application.cpp b/app/src/application.cpp index 211d7d9..c0aba86 100644 --- a/app/src/application.cpp +++ b/app/src/application.cpp @@ -1,7 +1,7 @@ #include "turns/app/application.hpp" -#include "turns/app/widgets/turn_order_view.hpp" -#include "turns/app/windows/tracker.hpp" +#include "turns/ui/widgets/turn_order_view.hpp" +#include "turns/ui/windows/tracker.hpp" #include @@ -41,7 +41,7 @@ namespace turns::app auto application::on_activate() -> void { - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/tracker.ui"); + auto builder = Gtk::Builder::create_from_resource("/windows/tracker.ui"); m_tracker = Gtk::Builder::get_widget_derived(builder, "tracker"); m_application->add_window(*m_tracker); diff --git a/app/src/widgets/participant_row.cpp b/app/src/widgets/participant_row.cpp deleted file mode 100644 index c04eee0..0000000 --- a/app/src/widgets/participant_row.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "turns/app/widgets/participant_row.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" -#include "turns/lang/messages.hpp" - -#include -#include -#include -#include - -#include -#include - -namespace turns::app::widgets -{ - namespace - { - auto constexpr static TYPE_NAME = "participant_row"; - auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/participant_row.ui"; - - auto css_class_for(core::disposition value) -> Glib::ustring - { - switch (value) - { - case core::disposition::friendly: - return "disposition-friendly"; - case core::disposition::hostile: - return "disposition-hostile"; - case core::disposition::secret: - return "disposition-secret"; - default: - return ""; - } - } - } // namespace - - participant_row::participant_row(Glib::RefPtr participant) - : Glib::ObjectBase(TYPE_NAME) - , template_widget{TEMPLATE} - , m_delete{get_widget("delete")} - , m_edit{get_widget("edit")} - , m_subtitle{get_widget("subtitle")} - , m_title{get_widget("title")} - , m_toggle_defeated{get_widget("toggle_defeated")} - , m_delete_enabled{*this, "delete-enabled", true} - , m_edit_enabled{*this, "edit-enabled", true} - - { - m_delete->signal_clicked().connect(sigc::mem_fun(*this, &participant_row::handle_delete)); - m_edit->signal_clicked().connect(sigc::mem_fun(*this, &participant_row::handle_edit)); - - Glib::Binding::bind_property(m_subtitle->property_label(), - m_subtitle->property_visible(), - Glib::Binding::Flags::DEFAULT, - sigc::mem_fun(&Glib::ustring::size)); - Glib::Binding::bind_property(m_title->property_label(), - m_title->property_visible(), - Glib::Binding::Flags::INVERT_BOOLEAN, - sigc::mem_fun(&Glib::ustring::size)); - Glib::Binding::bind_property(m_toggle_defeated->property_active(), - m_toggle_defeated->property_icon_name(), - Glib::Binding::Flags::SYNC_CREATE, - [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); - - // clang-format off - Glib::Binding::bind_property(property_delete_enabled(), - m_delete->property_sensitive(), - Glib::Binding::Flags::SYNC_CREATE); - Glib::Binding::bind_property(property_edit_enabled(), - m_edit->property_sensitive(), - Glib::Binding::Flags::SYNC_CREATE); - // clang-format on - - if (participant) - { - Glib::Binding::bind_property(participant->name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE); - - Glib::Binding::bind_property(participant->priority(), m_subtitle->property_label(), Glib::Binding::Flags::SYNC_CREATE, [](auto n) { - return std::vformat(_(lang::priority_number), std::make_format_args(n)); - }); - - Glib::Binding::bind_property(participant->disposition(), - m_toggle_defeated->property_css_classes(), - Glib::Binding::Flags::SYNC_CREATE, - [this](auto value) { - auto classes = m_toggle_defeated->get_css_classes(); - auto removed = std::ranges::remove_if(classes, [](auto cls) { - return (cls == "disposition-friendly") | (cls == "disposition-hostile") || (cls == "disposition-secret"); - }); - classes.erase(removed.begin(), removed.end()); - classes.push_back(css_class_for(value)); - return classes; - }); - - Glib::Binding::bind_property(participant->is_active(), property_css_classes(), Glib::Binding::Flags::SYNC_CREATE, [this](auto value) { - auto classes = get_css_classes(); - if (!value) - { - std::erase(classes, "active-participant"); - } - else - { - classes.push_back("active-participant"); - } - return classes; - }); - } - } - - auto participant_row::property_delete_enabled() -> Glib::PropertyProxy - { - return m_delete_enabled.get_proxy(); - } - - auto participant_row::property_edit_enabled() -> Glib::PropertyProxy - { - return m_edit_enabled.get_proxy(); - } - - auto participant_row::handle_delete() -> void - { - auto index = Glib::Variant::create(get_index()); - activate_action("win.delete", index); - } - - auto participant_row::handle_edit() -> void - { - auto index = Glib::Variant::create(get_index()); - activate_action("win.edit", index); - } - -} // namespace turns::app::widgets \ No newline at end of file diff --git a/app/src/widgets/turn_order_view.cpp b/app/src/widgets/turn_order_view.cpp deleted file mode 100644 index 9e69127..0000000 --- a/app/src/widgets/turn_order_view.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "turns/app/widgets/turn_order_view.hpp" - -#include "turns/app/widgets/participant_row.hpp" -#include "turns/core/participant.hpp" -#include "turns/core/turn_order.hpp" - -#include - -#include - -#include - -namespace turns::app::widgets -{ - namespace - { - auto constexpr static TYPE_NAME = "turn_order_view"; - auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/turn_order_view.ui"; - } // namespace - - turn_order_view::turn_order_view(Glib::RefPtr model) - : Glib::ObjectBase(TYPE_NAME) - , template_widget{TEMPLATE} - , m_model{model} - , m_view{get_widget("view")} - { - if (model) - { - m_view->bind_model(m_model, sigc::mem_fun(*this, &turn_order_view::handle_create_row)); - } - } - - auto turn_order_view::handle_create_row(Glib::RefPtr const item) -> Gtk::Widget * - { - auto participant = std::dynamic_pointer_cast(item); - auto row = Gtk::make_managed(participant); - - Glib::Binding::bind_property(m_model->is_running(), - row->property_delete_enabled(), - Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); - - Glib::Binding::bind_property(m_model->is_running(), - row->property_edit_enabled(), - Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); - - return row; - } - -} // namespace turns::app::widgets \ No newline at end of file diff --git a/app/src/windows/participant_editor.cpp b/app/src/windows/participant_editor.cpp deleted file mode 100644 index 1c8d05c..0000000 --- a/app/src/windows/participant_editor.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "turns/app/windows/participant_editor.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" -#include "turns/lang/messages.hpp" - -#include - -#include -#include -#include -#include - -#include - -namespace turns::app::windows -{ - - participant_editor::participant_editor(BaseObjectType * base, Glib::RefPtr const builder, Glib::RefPtr obj) - : Gtk::Widget{base} - , m_adw{ADW_DIALOG(gobj())} - , m_disposition{ADW_COMBO_ROW(builder->get_widget("disposition")->gobj())} - , m_finish{builder->get_widget("finish")} - , m_name{ADW_ENTRY_ROW(builder->get_widget("name")->gobj())} - , m_priority{ADW_SPIN_ROW(builder->get_widget("priority")->gobj())} - , m_disposition_factory{Gtk::SignalListItemFactory::create()} - , m_disposition_model{Gtk::StringList::create()} - , m_participant{obj} - - { - adw_dialog_set_title(m_adw, _(obj ? lang::edit_participant : lang::add_participant)); - m_finish->signal_clicked().connect(sigc::mem_fun(*this, &participant_editor::handle_finish_clicked)); - - for (auto n : std::views::iota(std::uint8_t{}, static_cast(core::disposition::END))) - { - m_disposition_model->append(presentation_name_for(core::disposition{n})); - } - - m_disposition_factory->signal_bind().connect(sigc::mem_fun(*this, &participant_editor::handle_item_bind)); - m_disposition_factory->signal_setup().connect(sigc::mem_fun(*this, &participant_editor::handle_item_setup)); - - adw_combo_row_set_factory(m_disposition, GTK_LIST_ITEM_FACTORY(m_disposition_factory->gobj())); - adw_combo_row_set_model(m_disposition, G_LIST_MODEL(m_disposition_model->gobj())); - - if (m_participant) - { - gtk_editable_set_text(GTK_EDITABLE(m_name), m_participant->name().get_value().c_str()); - adw_spin_row_set_value(m_priority, m_participant->priority()); - adw_combo_row_set_selected(m_disposition, static_cast(m_participant->disposition().get_value())); - } - } - - auto participant_editor::present(Gtk::Widget * parent) -> void - { - adw_dialog_present(m_adw, parent->gobj()); - } - - auto participant_editor::signal_finished() -> signal_finished_type - { - return m_signal_finished; - } - - auto participant_editor::handle_finish_clicked() -> void - { - auto name = gtk_editable_get_text(GTK_EDITABLE(m_name)); - auto priority = adw_spin_row_get_value(m_priority); - auto disposition = static_cast(adw_combo_row_get_selected(m_disposition)); - - if (m_participant) - { - m_participant->name() = name; - m_participant->priority() = priority; - m_participant->disposition() = disposition; - } - - m_signal_finished.emit(name, priority, disposition); - adw_dialog_close(m_adw); - } - - auto participant_editor::handle_item_bind(Glib::RefPtr item) -> void - { - auto value = std::dynamic_pointer_cast(item->get_item())->get_string(); - dynamic_cast(item->get_child())->set_label(value); - } - - auto participant_editor::handle_item_setup(Glib::RefPtr item) -> void - { - item->set_child(*Gtk::make_managed()); - } - -} // namespace turns::app::windows \ No newline at end of file diff --git a/app/src/windows/tracker.cpp b/app/src/windows/tracker.cpp deleted file mode 100644 index 7188968..0000000 --- a/app/src/windows/tracker.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include "turns/app/windows/tracker.hpp" - -#include "turns/app/windows/participant_editor.hpp" -#include "turns/core/participant.hpp" -#include "turns/core/turn_order.hpp" -#include "turns/lang/messages.hpp" - -#include -#include - -#include - -#include - -namespace turns::app::windows -{ - - namespace - { - auto editor_for(Glib::RefPtr participant) - { - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui"); - return std::pair{builder, Gtk::Builder::get_widget_derived(builder, "participant_editor", participant)}; - } - - auto stop_dialog_callback(AdwAlertDialog * dialog, GAsyncResult * result, core::turn_order * order) - { - auto response = adw_alert_dialog_choose_finish(dialog, result); - if (response == Glib::ustring{"clear"}) - { - order->clear(); - } - order->stop(); - } - - } // namespace - - tracker::tracker(BaseObjectType * base, Glib::RefPtr const builder) - : Gtk::ApplicationWindow{base} - , m_adw{ADW_APPLICATION_WINDOW(gobj())} - , m_controls{builder->get_widget("controls")} - , m_empty(builder->get_widget("empty")) - , m_stack{builder->get_widget("stack")} - , m_start{builder->get_widget("start")} - , m_title(ADW_WINDOW_TITLE(builder->get_widget("title")->gobj())) - , m_turn_order{core::turn_order::create()} - , m_turn_order_view{Gtk::make_managed(m_turn_order)} - , m_subtitle{Glib::wrap(GTK_WIDGET(m_title)), "subtitle"} - { - setup_actions(); - - m_stack->add(*m_turn_order_view); - - // 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); - - Glib::Binding::bind_property(m_turn_order->is_empty(), - m_subtitle, - Glib::Binding::Flags::SYNC_CREATE, - [](auto empty) { return empty ? _(lang::no_active_turn_order) : ""; }); - // clang-format on - } - - auto tracker::handle_add_participant() -> void - { - auto [lifeline, dialog] = editor_for(nullptr); - dialog->present(this); - dialog->signal_finished().connect([this](auto n, auto p, auto d) { m_turn_order->add(n, p, d); }); - } - - auto tracker::handle_delete_participant(Glib::VariantBase param) -> void - { - auto index = Glib::VariantBase::cast_dynamic>(param); - m_turn_order->remove(index.get()); - } - - auto tracker::handle_edit_participant(Glib::VariantBase param) -> void - { - static_cast(param); - auto index = Glib::VariantBase::cast_dynamic>(param); - auto participant = m_turn_order->get_typed_object(index.get()); - auto [lifeline, dialog] = editor_for(participant); - dialog->present(this); - } - - auto tracker::handle_stop() -> void - { - auto dialog = ADW_ALERT_DIALOG(adw_alert_dialog_new("Stop turn order", "Do you want to clear the turn order?")); - adw_alert_dialog_add_response(dialog, "stop", "Stop"); - adw_alert_dialog_set_response_appearance(dialog, "stop", ADW_RESPONSE_SUGGESTED); - adw_alert_dialog_add_response(dialog, "clear", "Stop and clear"); - adw_alert_dialog_set_response_appearance(dialog, "clear", ADW_RESPONSE_DESTRUCTIVE); - adw_alert_dialog_set_close_response(dialog, "stop"); - adw_alert_dialog_set_default_response(dialog, "stop"); - adw_alert_dialog_choose(dialog, - GTK_WIDGET(this->gobj()), - NULL, - reinterpret_cast(stop_dialog_callback), - m_turn_order.get()); - } - - 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::handle_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_running(), - 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::handle_stop)); - - Glib::Binding::bind_property(m_turn_order->is_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE); - } - - // win.delete - // win.edit - { - add_action_with_parameter("delete", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::handle_delete_participant)); - add_action_with_parameter("edit", Glib::VARIANT_TYPE_INT32, sigc::mem_fun(*this, &tracker::handle_edit_participant)); - } - } - -} // namespace turns::app::windows diff --git a/app/tests/widgets/participant_row.cpp b/app/tests/widgets/participant_row.cpp deleted file mode 100644 index 8f20f56..0000000 --- a/app/tests/widgets/participant_row.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "turns/app/widgets/participant_row.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" - -#include - -namespace turns::app::widgets::tests -{ - - TEST_CASE("A freshly constructed participant row") - { - SECTION("can be created without a participant") - { - REQUIRE(Gtk::make_managed(Glib::RefPtr{})); - } - - SECTION("can be created with a participant") - { - REQUIRE(Gtk::make_managed(core::participant::create("Tazmyla Fireforge", 13, core::disposition::secret))); - } - } - -} // namespace turns::app::widgets::tests \ No newline at end of file diff --git a/app/tests/windows/participant_editor.cpp b/app/tests/windows/participant_editor.cpp deleted file mode 100644 index f9f59ee..0000000 --- a/app/tests/windows/participant_editor.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "turns/app/windows/participant_editor.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" -#include "turns/lang/messages.hpp" - -#include -#include - -#include -#include - -#include -#include -#include - -#include - -namespace turns::app::windows::tests -{ - - TEST_CASE("A freshly constructed participant editor without a participant", "[windows]") - { - auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); - setlocale(LC_ALL, locale); - - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui"); - auto instance = Gtk::Builder::get_widget_derived(builder, "participant_editor"); - auto window = Gtk::Window{}; - - SECTION("was successfully constructed") - { - REQUIRE(instance); - } - - SECTION("has a non-empty title") - { - auto widget = ADW_DIALOG(instance->gobj()); - REQUIRE(adw_dialog_get_title(widget)); - } - - SECTION("has its title set according to the active language") - { - auto widget = ADW_DIALOG(instance->gobj()); - REQUIRE(adw_dialog_get_title(widget) == Glib::ustring{_(lang::add_participant)}); - } - - SECTION("has an empty name field") - { - auto widget = GTK_EDITABLE(builder->get_widget("name")->gobj()); - REQUIRE(Glib::ustring{gtk_editable_get_text(widget)}.empty()); - } - - SECTION("has a zero priority field") - { - auto widget = ADW_SPIN_ROW(builder->get_widget("priority")->gobj()); - REQUIRE(adw_spin_row_get_value(widget) == 0); - } - - SECTION("allows binding to the finished signal") - { - REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); - } - } - - TEST_CASE("A freshly constructed participant editor with a participant", "[windows]") - { - auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); - setlocale(LC_ALL, locale); - - auto participant = core::participant::create("Qibi Babblebranch", 12, core::disposition::neutral); - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui"); - auto instance = Gtk::Builder::get_widget_derived(builder, "participant_editor", participant); - auto window = Gtk::Window{}; - - SECTION("was successfully constructed") - { - REQUIRE(instance); - } - - SECTION("has a non-empty title") - { - auto widget = ADW_DIALOG(instance->gobj()); - REQUIRE(adw_dialog_get_title(widget)); - } - - SECTION("has its title set according to the active language") - { - auto widget = ADW_DIALOG(instance->gobj()); - REQUIRE(adw_dialog_get_title(widget) == Glib::ustring{_(lang::edit_participant)}); - } - - SECTION("has its name field set according to its participant") - { - auto widget = GTK_EDITABLE(builder->get_widget("name")->gobj()); - REQUIRE(gtk_editable_get_text(widget) == participant->name().get_value()); - } - - SECTION("has its priority field set according to its participant") - { - auto widget = ADW_SPIN_ROW(builder->get_widget("priority")->gobj()); - REQUIRE(adw_spin_row_get_value(widget) == participant->priority()); - } - - SECTION("allows binding to the finished signal") - { - REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); - } - } - -} // namespace turns::app::windows::tests \ No newline at end of file diff --git a/app/tests/windows/tracker.cpp b/app/tests/windows/tracker.cpp deleted file mode 100644 index 3d7f0c2..0000000 --- a/app/tests/windows/tracker.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "turns/app/windows/tracker.hpp" - -#include "turns/lang/messages.hpp" - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - -namespace turns::app::windows::tests -{ - - TEST_CASE("A freshly constructed tracker window", "[windows]") - { - auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); - setlocale(LC_ALL, locale); - - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/tracker.ui"); - auto instance = Gtk::Builder::get_widget_derived(builder, "tracker"); - - SECTION("was successfully constructed") - { - REQUIRE(instance); - } - - SECTION("has a non-empty subtitle") - { - auto widget = builder->get_widget("title"); - auto adw = ADW_WINDOW_TITLE(widget->gobj()); - REQUIRE(adw_window_title_get_subtitle(adw)); - } - - SECTION("has its subtitle set according to the active language") - { - auto widget = builder->get_widget("title"); - auto adw = ADW_WINDOW_TITLE(widget->gobj()); - REQUIRE(adw_window_title_get_subtitle(adw) == Glib::ustring{_(lang::no_active_turn_order)}); - } - - SECTION("has a non-empty title") - { - auto widget = builder->get_widget("title"); - auto adw = ADW_WINDOW_TITLE(widget->gobj()); - REQUIRE(adw_window_title_get_title(adw)); - } - - SECTION("has its title set according to the active language") - { - auto widget = builder->get_widget("title"); - auto adw = ADW_WINDOW_TITLE(widget->gobj()); - REQUIRE(adw_window_title_get_title(adw) == Glib::ustring{_(lang::turns)}); - } - - SECTION("has its add_participant button's tooltip set according to the active language") - { - auto widget = builder->get_widget("add_participant"); - REQUIRE(widget->get_tooltip_text() == Glib::ustring{_(lang::add_participant)}); - } - - SECTION("as its open_main_menu button's tooltip set according to the active language") - { - auto widget = builder->get_widget("open_main_menu"); - REQUIRE(widget->get_tooltip_text() == Glib::ustring{_(lang::main_menu)}); - } - } - -} // namespace turns::app::windows::tests \ No newline at end of file -- cgit v1.2.3