summaryrefslogtreecommitdiff
path: root/gui/include/tracker.hpp
blob: 2360f5d1ef956e572b1a350ce62503df86f43831 (plain)
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
/*
 * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
 * SPDX-License-Identifier: LGPL-2.1-only
 */

#ifndef TURNS_GUI_TRACKER_HPP
#define TURNS_GUI_TRACKER_HPP

#include "template_widget.hpp"
#include "turn_order_view.hpp"

#include <turnsmm/turn-order.hpp>

#include <adwaitamm/application.hpp>
#include <adwaitamm/applicationwindow.hpp>
#include <adwaitamm/toastoverlay.hpp>
#include <adwaitamm/windowtitle.hpp>
#include <giomm/asyncresult.h>
#include <giomm/file.h>
#include <giomm/settings.h>
#include <glibmm/propertyproxy.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glibmm/variant.h>
#include <gtkmm/button.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/filedialog.h>
#include <gtkmm/revealer.h>
#include <gtkmm/stack.h>
#include <gtkmm/widget.h>

#include <array>
#include <exception>
#include <string>

namespace Turns::gui
{

  struct Tracker : template_widget<Tracker, Adwaita::ApplicationWindow>
  {
    auto constexpr inline static children = std::array{
        "controls",
        "empty",
        "overlay",
        "stack",
        "start",
        "title",
    };

    Tracker(Glib::RefPtr<Adwaita::Application> const & app, Glib::RefPtr<Gio::Settings> const & settings);

    auto load(Glib::RefPtr<Gio::File> file) -> void;

  private:
    friend auto register_types() -> void;
    Tracker();

    /** Setup */
    auto setup_actions() -> void;
    auto setup_colors() -> void;

    /** Actions */
    auto add_participant() -> void;
    auto delete_participant(Glib::VariantBase param) -> void;
    auto edit_participant(Glib::VariantBase param) -> void;
    auto open() -> void;
    auto preferences() -> void;
    auto save(bool force_ask) -> void;
    auto stop() -> void;

    /** Event Handlers */
    auto on_open_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void;
    auto on_save_response(Glib::RefPtr<Gio::AsyncResult> result, Glib::RefPtr<Gtk::FileDialog> dialog) -> void;
    auto on_load_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void;
    auto on_replace_content_done(Glib::RefPtr<Gio::AsyncResult> result) -> void;
    auto on_settings_changed(Glib::ustring key) -> void;

    /** Helpers */
    auto show_error(std::exception const & e) -> void;
    auto show_toast(std::string const & message) -> void;
    auto start_replace_content() -> void;
    auto update_colors() -> void;
    auto update_subtitle() -> void;

    Gtk::Revealer * m_controls;
    Gtk::Widget * m_empty;
    Adwaita::ToastOverlay * m_overlay;
    Gtk::Stack * m_stack;
    Gtk::Button * m_start;
    Adwaita::WindowTitle * m_title;
    Glib::RefPtr<TurnOrder> m_turn_order;
    TurnOrderView * m_turn_order_view;
    Glib::RefPtr<Gio::Settings> m_settings{};
    Glib::PropertyProxy<Glib::ustring> m_subtitle;

    Glib::RefPtr<Gio::File> m_file{};
    std::string m_file_etag{};
    std::string m_file_buffer{};

    Glib::RefPtr<Gtk::CssProvider> m_css{};
  };

}  // namespace Turns::gui

#endif