Newer
Older
* SPDX-FileCopyrightText: 2017-2022 Bruce Cowan <bruce@bcowan.me.uk>
* SPDX-License-Identifier: GPL-3.0-or-later
#include "rugby-possibility-widget.h"
#include <glib/gi18n.h>
G_DEFINE_TYPE (RugbyAppWindow, rugby_app_window, ADW_TYPE_APPLICATION_WINDOW)
RugbyPossibility *possibility = gtk_list_item_get_item (item);
int tries, utries, kicks;
GString *tooltip = g_string_new (NULL);
g_object_get (possibility,
"tries", &tries,
"utries", &utries,
"kicks", &kicks,
NULL);
g_string_printf (tooltip, ngettext ("%d converted try",
"%d converted tries",
tries),
tries);
g_string_printf (tooltip, ngettext ("%d unconverted try",
"%d unconverted tries",
utries),
utries);
}
else if (tries + utries > 0)
{
g_string_printf (tooltip, ngettext ("%d try, %d converted",
"%d tries, %d converted",
tries + utries),
tries + utries, tries);
}
if (kicks > 0)
{
if (tries > 0 || utries > 0)
g_string_append_printf (tooltip, ", ");
kicks);
}
return g_string_free (tooltip, FALSE);
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
static void
activate_score_changed (G_GNUC_UNUSED GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data);
double current_value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (self->scorespin));
const char *direction = g_variant_get_string (parameter, NULL);
if (g_strcmp0 (direction, "up") == 0)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->scorespin), current_value + 1.0);
else if (g_strcmp0 (direction, "down") == 0)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->scorespin), current_value - 1.0);
else
g_assert_not_reached ();
}
static void
activate_show_primary_menu (G_GNUC_UNUSED GSimpleAction *action,
G_GNUC_UNUSED GVariant *parameter,
gpointer user_data)
{
RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data);
gtk_menu_button_popup (GTK_MENU_BUTTON (self->menu_button));
}
const GActionEntry win_entries[] = {
{ .name = "score-changed", .activate = activate_score_changed, .parameter_type = "s" },
{ .name = "show-primary-menu", .activate = activate_show_primary_menu },
};
static void
rugby_app_window_dispose (GObject *object)
{
gtk_widget_dispose_template (GTK_WIDGET (object), RUGBY_TYPE_APP_WINDOW);
G_OBJECT_CLASS (rugby_app_window_parent_class)->dispose (object);
}
static void
rugby_app_window_init (RugbyAppWindow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
g_action_map_add_action_entries (G_ACTION_MAP (self),
win_entries,
G_N_ELEMENTS (win_entries),
self);
}
static void
rugby_app_window_class_init (RugbyAppWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
g_type_ensure (RUGBY_TYPE_POSSIBILITY_WIDGET);
g_type_ensure (RUGBY_TYPE_LIST_STORE);
object_class->dispose = rugby_app_window_dispose;
gtk_widget_class_set_template_from_resource (widget_class,
"/uk/me/bcowan/Rugby/window.ui");
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, scorespin);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, menu_button);
gtk_widget_class_bind_template_callback (widget_class, item_tooltip_cb);
return g_object_new (RUGBY_TYPE_APP_WINDOW,
"application", app,
NULL);