From 51ba7f32ced89bde135127bef3e08dbc03ee6a24 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 5 Jun 2025 17:35:58 +0200 Subject: gui: reintroduce tracker --- gui/CMakeLists.txt | 3 + gui/include/tracker.hpp | 38 +++++------ gui/src/main.cpp | 67 +++++++++---------- gui/src/tracker.cpp | 134 ++++++++++++++++++------------------- gui/src/tracker_actions.cpp | 56 ++++++++-------- gui/src/tracker_event_handlers.cpp | 70 +++++++++---------- 6 files changed, 175 insertions(+), 193 deletions(-) (limited to 'gui') diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 902fdd0..2979224 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -70,6 +70,9 @@ add_library("gui_impl" "src/participant_row.cpp" "src/preferences.cpp" "src/settings.cpp" + "src/tracker.cpp" + "src/tracker_actions.cpp" + "src/tracker_event_handlers.cpp" "src/turn_order_view.cpp" ) diff --git a/gui/include/tracker.hpp b/gui/include/tracker.hpp index d639aee..2360f5d 100644 --- a/gui/include/tracker.hpp +++ b/gui/include/tracker.hpp @@ -3,24 +3,25 @@ * SPDX-License-Identifier: LGPL-2.1-only */ -#ifndef TURNS_UI_TRACKER_HPP -#define TURNS_UI_TRACKER_HPP +#ifndef TURNS_GUI_TRACKER_HPP +#define TURNS_GUI_TRACKER_HPP -#include "turns/core/turn_order_model.hpp" -#include "turns/ui/template_widget.hpp" -#include "turns/ui/turn_order_view.hpp" +#include "template_widget.hpp" +#include "turn_order_view.hpp" -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include - -#include -#include +#include +#include +#include +#include #include #include #include @@ -28,16 +29,11 @@ #include #include -#include -#include -#include -#include - #include #include #include -namespace turns::ui +namespace Turns::gui { struct Tracker : template_widget @@ -59,7 +55,7 @@ namespace turns::ui friend auto register_types() -> void; Tracker(); - /** Setup */ + /** Setup */ auto setup_actions() -> void; auto setup_colors() -> void; @@ -92,7 +88,7 @@ namespace turns::ui Gtk::Stack * m_stack; Gtk::Button * m_start; Adwaita::WindowTitle * m_title; - Glib::RefPtr m_turn_order; + Glib::RefPtr m_turn_order; TurnOrderView * m_turn_order_view; Glib::RefPtr m_settings{}; Glib::PropertyProxy m_subtitle; @@ -104,6 +100,6 @@ namespace turns::ui Glib::RefPtr m_css{}; }; -} // namespace turns::ui +} // namespace Turns::gui #endif \ No newline at end of file diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 61fdde3..8931382 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -5,6 +5,7 @@ #include "init.hpp" #include "settings.hpp" +#include "tracker.hpp" #include @@ -64,41 +65,35 @@ auto main(int argc, char ** argv) -> int auto settings = Turns::gui::get_settings(); - // app->signal_activate().connect([app, settings] { - // auto window = new turns::ui::Tracker{app, settings}; - // window->present(); - // }); + app->signal_activate().connect([app, settings] { + auto window = new Turns::gui::Tracker{app, settings}; + window->present(); + }); + + app->signal_open().connect([app, settings](auto files, auto) { + auto windows = app->get_windows(); + auto window = static_cast(nullptr); + + if (windows.empty()) + { + window = new Turns::gui::Tracker{app, settings}; + } + else + { + window = dynamic_cast(windows[0]); + } + + window->present(); + window->load(files[0]); + }); + + app->signal_window_removed().connect([](auto window) { + auto tracker = dynamic_cast(window); + if (tracker) + { + delete tracker; + } + }); return app->run(argc, argv); -} - -// auto main(int argc, char * argv[]) -> int -// { - -// app->signal_open().connect([app, settings](auto files, auto) { -// auto windows = app->get_windows(); -// auto window = static_cast(nullptr); - -// if (windows.empty()) -// { -// window = new turns::ui::Tracker{app, settings}; -// } -// else -// { -// window = dynamic_cast(windows[0]); -// } - -// window->present(); -// window->load(files[0]); -// }); - -// app->signal_window_removed().connect([](auto window) { -// auto tracker = dynamic_cast(window); -// if (tracker) -// { -// delete tracker; -// } -// }); - -// return app->run(argc, argv); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/gui/src/tracker.cpp b/gui/src/tracker.cpp index dd926b5..66970e9 100644 --- a/gui/src/tracker.cpp +++ b/gui/src/tracker.cpp @@ -3,17 +3,28 @@ * SPDX-License-Identifier: LGPL-2.1-only */ -#include "turns/ui/tracker.hpp" +#include "tracker.hpp" -#include "turns/core/settings.hpp" -#include "turns/core/turn_order_model.hpp" -#include "turns/lang/messages.hpp" -#include "turns/ui/template_widget.hpp" -#include "turns/ui/turn_order_view.hpp" +#include "messages.hpp" +#include "settings.hpp" +#include "turn_order_view.hpp" + +#include +#include #include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -22,11 +33,6 @@ #include #include #include - -#include -#include -#include - #include #include #include @@ -39,22 +45,14 @@ #include #include -#include -#include -#include -#include -#include - -#include -#include - #include #include +#include #include #include #include -namespace turns::ui +namespace Turns::gui { namespace { @@ -63,7 +61,7 @@ namespace turns::ui } // namespace Tracker::Tracker() - : Tracker{{}, core::get_settings()} + : Tracker{{}, gui::get_settings()} { } @@ -76,7 +74,7 @@ namespace turns::ui , m_stack{get_widget("stack")} , m_start{get_widget("start")} , m_title{get_widget("title")} - , m_turn_order{core::TurnOderModel::create()} + , m_turn_order{std::make_shared()} , m_turn_order_view{Gtk::make_managed(m_turn_order)} , m_settings{std::move(settings)} , m_subtitle{m_title->property_subtitle()} @@ -87,22 +85,22 @@ namespace turns::ui 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)); + m_turn_order->property_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(), + Glib::Binding::bind_property(m_turn_order->property_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(), + Glib::Binding::bind_property(m_turn_order->property_running(), m_controls->property_reveal_child(), Glib::Binding::Flags::SYNC_CREATE); // clang-format on - m_settings->bind("skip-defeated", m_turn_order->skip_defeated()); + // m_settings->bind("skip-defeated", m_turn_order->skip_defeated()); } auto Tracker::setup_actions() -> void @@ -112,57 +110,57 @@ namespace turns::ui { auto action = add_action("add_participant", sigc::mem_fun(*this, &Tracker::add_participant)); - Glib::Binding::bind_property(m_turn_order->is_running(), + Glib::Binding::bind_property(m_turn_order->property_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); } // win.clear - // depends-on: turn_order:is_empty == false + // depends-on: turn_order:property_empty == false { - auto action = add_action("clear", sigc::mem_fun(*m_turn_order, &core::TurnOderModel::clear)); + auto action = add_action("clear", sigc::mem_fun(*m_turn_order, &TurnOrder::clear)); - Glib::Binding::bind_property(m_turn_order->is_empty(), + Glib::Binding::bind_property(m_turn_order->property_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::TurnOderModel::next)); + // // win.next + // // depends-on: turn_order:state == running + // { + // auto action = add_action("next", sigc::mem_fun(*m_turn_order, &TurnOrder::next)); - Glib::Binding::bind_property(m_turn_order->is_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE); - } + // Glib::Binding::bind_property(m_turn_order->property_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::TurnOderModel::previous)); + // // win.previous + // // depends-on: turn_order:has_previous == true + // { + // auto action = add_action("previous", sigc::mem_fun(*m_turn_order, &TurnOrder::previous)); - Glib::Binding::bind_property(m_turn_order->has_previous(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE); - } + // 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::TurnOderModel::start)); + // // win.start + // // depends-on: turn_order:property_empty == false + // { + // auto action = add_action("start", sigc::mem_fun(*m_turn_order, &TurnOrder::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->property_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); - } + // Glib::Binding::bind_property(m_turn_order->property_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); + Glib::Binding::bind_property(m_turn_order->property_running(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE); } // win.delete @@ -177,21 +175,21 @@ namespace turns::ui } // win.save - // depends-on: turn_order:is_empty == false + // depends-on: turn_order:property_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(), + Glib::Binding::bind_property(m_turn_order->property_empty(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); } // win.save-as - // depends-on: turn_order:is_empty == false + // depends-on: turn_order:property_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(), + Glib::Binding::bind_property(m_turn_order->property_empty(), action->property_enabled(), Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN); } @@ -206,14 +204,14 @@ namespace turns::ui 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); + // 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))); + show_toast(std::vformat(_(message::saving_failed_format), std::make_format_args(error))); } auto Tracker::show_toast(std::string const & message) -> void @@ -236,14 +234,14 @@ namespace turns::ui auto Tracker::update_subtitle() -> void { - if (m_turn_order->is_empty()) + if (m_turn_order->property_empty()) { - m_subtitle = _(lang::no_active_turn_order); + m_subtitle = _(message::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 round_number = m_turn_order->round_number() + 1; + // m_subtitle = round_number == 0 ? "" : std::vformat(_(message::round_number), std::make_format_args(round_number)); } } @@ -257,4 +255,4 @@ namespace turns::ui } } -} // namespace turns::ui +} // namespace Turns::gui diff --git a/gui/src/tracker_actions.cpp b/gui/src/tracker_actions.cpp index 7149f0e..8c9820a 100644 --- a/gui/src/tracker_actions.cpp +++ b/gui/src/tracker_actions.cpp @@ -3,40 +3,38 @@ * SPDX-License-Identifier: LGPL-2.1-only */ -#include "turns/core/participant.hpp" -#include "turns/lang/messages.hpp" -#include "turns/ui/participant_editor.hpp" -#include "turns/ui/preferences.hpp" -#include "turns/ui/tracker.hpp" +#include "messages.hpp" +#include "participant_editor.hpp" +#include "preferences.hpp" +#include "tracker.hpp" + +#include #include #include +#include +#include + +#include +#include +#include +#include +#include +#include #include #include #include #include #include - -#include -#include - #include #include #include #include -#include -#include -#include -#include - -#include -#include - #include -namespace turns::ui +namespace Turns::gui { namespace { @@ -54,20 +52,20 @@ namespace turns::ui auto Tracker::add_participant() -> void { auto dialog = Gtk::make_managed(nullptr); - dialog->signal_finished().connect([this](auto n, auto p, auto d) { m_turn_order->add(n, p, d); }); + dialog->signal_finished().connect([this](auto n, auto p, auto d) { m_turn_order->add(Participant::create(n, p, d)); }); dialog->present(this); } auto Tracker::delete_participant(Glib::VariantBase param) -> void { auto index = Glib::VariantBase::cast_dynamic>(param); - m_turn_order->remove(index.get()); + m_turn_order->remove_at(index.get()); } auto Tracker::edit_participant(Glib::VariantBase param) -> void { auto index = Glib::VariantBase::cast_dynamic>(param); - auto participant = m_turn_order->get_typed_object(index.get()); + auto participant = m_turn_order->get_typed_object(index.get()); auto dialog = Gtk::make_managed(participant); dialog->present(this); } @@ -81,7 +79,7 @@ namespace turns::ui auto Tracker::preferences() -> void { - auto preferences = Gtk::make_managed(m_settings); + auto preferences = Gtk::make_managed(m_settings); auto dialog = Gtk::make_managed(); dialog->add(*preferences); dialog->set_visible_page(*preferences); @@ -97,7 +95,7 @@ namespace turns::ui else { auto dialog = Gtk::FileDialog::create(); - m_file ? dialog->set_initial_file(m_file) : dialog->set_initial_name(_(lang::new_turn_order_file_name)); + m_file ? dialog->set_initial_file(m_file) : dialog->set_initial_name(_(message::new_turn_order_file_name)); dialog->set_filters(file_filters()); dialog->save(*this, sigc::bind(sigc::mem_fun(*this, &Tracker::on_save_response), dialog)); } @@ -105,12 +103,12 @@ namespace turns::ui auto Tracker::stop() -> void { - auto dialog = Adwaita::AlertDialog::create(_(lang::stop_turn_order), _(lang::question_clear_turn_order)); - dialog->add_response("stop", _(lang::stop)); + auto dialog = Adwaita::AlertDialog::create(_(message::stop_turn_order), _(message::question_clear_turn_order)); + dialog->add_response("stop", _(message::stop)); dialog->set_response_appearance("stop", Adwaita::ResponseAppearance::Suggested); - dialog->add_response("clear", _(lang::stop_and_clear)); + dialog->add_response("clear", _(message::stop_and_clear)); dialog->set_response_appearance("clear", Adwaita::ResponseAppearance::Destructive); - dialog->add_response("cancel", _(lang::cancel)); + dialog->add_response("cancel", _(message::cancel)); dialog->set_response_appearance("cancel", Adwaita::ResponseAppearance::Default); dialog->set_close_response("cancel"); dialog->set_default_response("cancel"); @@ -124,7 +122,7 @@ namespace turns::ui { m_turn_order->clear(); } - m_turn_order->stop(); + // m_turn_order->stop(); }); } -} // namespace turns::ui \ No newline at end of file +} // namespace Turns::gui \ No newline at end of file diff --git a/gui/src/tracker_event_handlers.cpp b/gui/src/tracker_event_handlers.cpp index ae0328c..571b7e3 100644 --- a/gui/src/tracker_event_handlers.cpp +++ b/gui/src/tracker_event_handlers.cpp @@ -3,55 +3,47 @@ * SPDX-License-Identifier: LGPL-2.1-only */ -#include "turns/lang/messages.hpp" -#include "turns/ui/tracker.hpp" +#include "messages.hpp" +#include "tracker.hpp" #include +#include +#include #include #include #include - -#include -#include - #include -#include - -#include -#include -#include -#include - -namespace turns::ui +namespace Turns::gui { auto Tracker::on_load_content_done(Glib::RefPtr 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)); + static_cast(result); + // 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 result) -> void @@ -68,8 +60,8 @@ namespace turns::ui } 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)); + show_toast(std::vformat(_(message::successfully_saved_format), std::make_format_args(name))); + set_title(std::format("{} - {}", _(message::turns), name)); } auto Tracker::on_open_response(Glib::RefPtr result, Glib::RefPtr dialog) -> void -- cgit v1.2.3