summaryrefslogtreecommitdiff
path: root/gui/src/tracker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/tracker.cpp')
-rw-r--r--gui/src/tracker.cpp134
1 files changed, 66 insertions, 68 deletions
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 <turnsmm/participant.hpp>
+#include <turnsmm/turn-order.hpp>
#include <sigc++/adaptors/bind.h>
#include <sigc++/functors/mem_fun.h>
+#include <gtk/gtk.h>
+
+#include <adwaitamm/application.hpp>
+#include <adwaitamm/applicationwindow.hpp>
+#include <adwaitamm/toast.hpp>
+#include <adwaitamm/toastoverlay.hpp>
+#include <adwaitamm/windowtitle.hpp>
+#include <giomm/file.h>
+#include <giomm/liststore.h>
+#include <giomm/settings.h>
#include <glibmm/binding.h>
#include <glibmm/i18n.h>
#include <glibmm/objectbase.h>
@@ -22,11 +33,6 @@
#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>
@@ -39,22 +45,14 @@
#include <gtkmm/styleprovider.h>
#include <gtkmm/widget.h>
-#include <adwaitamm/application.hpp>
-#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 <memory>
#include <print>
#include <string>
#include <utility>
-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<Gtk::Stack>("stack")}
, m_start{get_widget<Gtk::Button>("start")}
, m_title{get_widget<Adwaita::WindowTitle>("title")}
- , m_turn_order{core::TurnOderModel::create()}
+ , m_turn_order{std::make_shared<TurnOrder>()}
, m_turn_order_view{Gtk::make_managed<TurnOrderView>(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