1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#include "turns/app/windows/tracker.hpp"
#include "turns/app/widgets/participant_row.hpp"
#include "turns/app/windows/participant_editor.hpp"
#include "turns/lang/messages.hpp"
#include <format>
#include <ranges>
#include <adwaita.h>
#include <glibmm/i18n.h>
#include <gtkmm/stringobject.h>
namespace turns::app::windows
{
namespace
{
auto editor_for(Glib::RefPtr<domain::participant> participant)
{
auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui");
return std::pair{builder, Gtk::Builder::get_widget_derived<windows::participant_editor>(builder, "participant_editor", participant)};
}
} // namespace
tracker::tracker(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder)
: Gtk::ApplicationWindow{base}
, m_adw{ADW_APPLICATION_WINDOW(gobj())}
, m_controls{builder->get_widget<Gtk::Revealer>("controls")}
, m_empty(builder->get_widget<Gtk::Widget>("empty"))
, m_stack{builder->get_widget<Gtk::Stack>("stack")}
, m_start{builder->get_widget<Gtk::Button>("start")}
, m_title(ADW_WINDOW_TITLE(builder->get_widget<Gtk::Widget>("title")->gobj()))
, m_turn_order{Gtk::make_managed<widgets::turn_order_view>()}
, m_subtitle{Glib::wrap(GTK_WIDGET(m_title)), "subtitle"}
{
setup_actions();
m_stack->add(*m_turn_order);
Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(),
m_stack->property_visible_child(),
Glib::Binding::Flags::SYNC_CREATE,
[this](auto empty) { return empty ? m_empty : m_turn_order; });
Glib::Binding::bind_property(m_turn_order->get_model()->property_running(),
m_controls->property_reveal_child(),
Glib::Binding::Flags::SYNC_CREATE);
// clang-format off
Glib::Binding::bind_property(m_turn_order->get_model()->property_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->get_model()->add(n, p, d); });
}
auto tracker::handle_delete_participant(Glib::VariantBase param) -> void
{
auto index = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(param);
m_turn_order->get_model()->remove(index.get());
}
auto tracker::handle_edit_participant(Glib::VariantBase param) -> void
{
static_cast<void>(param);
auto index = Glib::VariantBase::cast_dynamic<Glib::Variant<int>>(param);
auto participant = m_turn_order->get_model()->get(index.get());
auto [lifeline, dialog] = editor_for(participant);
dialog->present(this);
}
auto tracker::handle_stop() -> void
{
m_turn_order->get_model()->stop();
}
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->get_model()->property_running(),
action->property_enabled(),
Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
}
// win.clear
// depends-on: turn_order:empty == false
{
auto action = add_action("clear", sigc::mem_fun(*m_turn_order->get_model(), &domain::turn_order::clear));
Glib::Binding::bind_property(m_turn_order->get_model()->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->get_model(), &domain::turn_order::next));
Glib::Binding::bind_property(m_turn_order->get_model()->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->get_model(), &domain::turn_order::previous));
Glib::Binding::bind_property(m_turn_order->get_model()->property_has_previous(),
action->property_enabled(),
Glib::Binding::Flags::SYNC_CREATE);
}
// win.start
// depends-on: turn_order:empty == false
{
auto action = add_action("start", sigc::mem_fun(*m_turn_order->get_model(), &domain::turn_order::start));
Glib::Binding::bind_property(m_turn_order->get_model()->property_empty(),
action->property_enabled(),
Glib::Binding::Flags::SYNC_CREATE | Glib::Binding::Flags::INVERT_BOOLEAN);
Glib::Binding::bind_property(m_turn_order->get_model()->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::handle_stop));
Glib::Binding::bind_property(m_turn_order->get_model()->property_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
|