From 5533f5b75fb8fb3f12c8d9baa5faf7ca6c8ef1fb Mon Sep 17 00:00:00 2001
From: Bruce Cowan <bruce.cowan@strath.ac.uk>
Date: Thu, 9 Jan 2020 11:46:56 +0000
Subject: [PATCH] Various small changes

* Represent window if it already exists
* Always include config.h
* Make RugbyListScore:score not unsigned
* Remove drawing frame because it doesn't do anything
---
 src/main.c                     | 11 +++++++----
 src/rugby-app-window.c         |  6 ++----
 src/rugby-list-store.c         | 22 +++++++++++-----------
 src/rugby-list-store.h         |  4 ++--
 src/rugby-possibility-widget.c |  2 +-
 src/rugby-possibility.c        |  1 +
 6 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/main.c b/src/main.c
index a783419..e309cb5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,17 +3,20 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include <gtk/gtk.h>
-
 #include "config.h"
+
 #include "rugby-app-window.h"
 
+static GtkWidget *window = NULL;
+
 static void
 on_activate (GApplication *app,
              gpointer      user_data)
 {
-    RugbyAppWindow *win = rugby_app_window_new (GTK_APPLICATION (app));
-    gtk_window_present (GTK_WINDOW (win));
+    if (!window)
+        window = GTK_WIDGET (rugby_app_window_new (GTK_APPLICATION (app)));
+
+    gtk_window_present (GTK_WINDOW (window));
 }
 
 static void
diff --git a/src/rugby-app-window.c b/src/rugby-app-window.c
index 26ed1b8..9200cda 100644
--- a/src/rugby-app-window.c
+++ b/src/rugby-app-window.c
@@ -3,10 +3,9 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include <gtk/gtk.h>
-
 #include "config.h"
 #include "rugby-app-window.h"
+
 #include "rugby-list-store.h"
 #include "rugby-possibility.h"
 #include "rugby-possibility-widget.h"
@@ -27,7 +26,6 @@ scorespin_value_changed_cb (GtkSpinButton  *spin,
                             RugbyAppWindow *self)
 {
     int score = gtk_spin_button_get_value_as_int (spin);
-
     rugby_list_store_set_score (self->store, score);
 }
 
@@ -73,8 +71,8 @@ rugby_app_window_class_init (RugbyAppWindowClass *klass)
 
     gtk_widget_class_set_template_from_resource (widget_class,
                                                  "/uk/me/bcowan/rugby/interface.ui");
-    gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, listbox);
 
+    gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, listbox);
     gtk_widget_class_bind_template_callback (widget_class, scorespin_value_changed_cb);
 }
 
diff --git a/src/rugby-list-store.c b/src/rugby-list-store.c
index c103481..95b1f1f 100644
--- a/src/rugby-list-store.c
+++ b/src/rugby-list-store.c
@@ -2,9 +2,9 @@
  * SPDX-FileCopyrightText: 2018 Bruce Cowan <bruce@bcowan.me.uk>
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
-
 #include "config.h"
 #include "rugby-list-store.h"
+
 #include "rugby-possibility.h"
 
 #include <gio/gio.h>
@@ -13,8 +13,8 @@ struct _RugbyListStore
 {
     GObject parent_instance;
 
-    unsigned score;
     GPtrArray *items;
+    int score;
 };
 
 static void rugby_list_store_list_model_iface_init (GListModelInterface *iface);
@@ -157,7 +157,7 @@ rugby_list_store_get_property (GObject    *object,
     switch (prop_id)
     {
         case PROP_SCORE:
-            g_value_set_uint (value, rugby_list_store_get_score (self));
+            g_value_set_int (value, rugby_list_store_get_score (self));
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -175,7 +175,7 @@ rugby_list_store_set_property (GObject      *object,
     switch (prop_id)
     {
         case PROP_SCORE:
-            rugby_list_store_set_score (self, g_value_get_uint (value));
+            rugby_list_store_set_score (self, g_value_get_int (value));
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -191,11 +191,11 @@ rugby_list_store_class_init (RugbyListStoreClass *klass)
     object_class->get_property = rugby_list_store_get_property;
     object_class->set_property = rugby_list_store_set_property;
 
-    properties[PROP_SCORE] = g_param_spec_uint ("score",
-                                                "Score",
-                                                "Score of the match",
-                                                0, 200, 0,
-                                                G_PARAM_READWRITE);
+    properties[PROP_SCORE] = g_param_spec_int ("score",
+                                               "Score",
+                                               "Score of the match",
+                                               0, 200, 0,
+                                               G_PARAM_READWRITE);
 
     g_object_class_install_properties (object_class,
                                        N_PROPS,
@@ -214,7 +214,7 @@ rugby_list_store_init (RugbyListStore *self)
 
 // Public functions
 
-unsigned
+int
 rugby_list_store_get_score (RugbyListStore *self)
 {
     g_return_val_if_fail (RUGBY_IS_LIST_STORE (self), 0);
@@ -224,7 +224,7 @@ rugby_list_store_get_score (RugbyListStore *self)
 
 void
 rugby_list_store_set_score (RugbyListStore *self,
-                            unsigned        score)
+                            int             score)
 {
     g_return_if_fail (RUGBY_IS_LIST_STORE (self));
 
diff --git a/src/rugby-list-store.h b/src/rugby-list-store.h
index d0966a9..0f420db 100644
--- a/src/rugby-list-store.h
+++ b/src/rugby-list-store.h
@@ -14,8 +14,8 @@ G_DECLARE_FINAL_TYPE (RugbyListStore, rugby_list_store, RUGBY, LIST_STORE, GObje
 
 RugbyListStore * rugby_list_store_new       (void);
 
-unsigned         rugby_list_store_get_score (RugbyListStore *self);
+int              rugby_list_store_get_score (RugbyListStore *self);
 void             rugby_list_store_set_score (RugbyListStore *self,
-                                             unsigned        score);
+                                             int             score);
 
 G_END_DECLS
diff --git a/src/rugby-possibility-widget.c b/src/rugby-possibility-widget.c
index 173d0e7..c150377 100644
--- a/src/rugby-possibility-widget.c
+++ b/src/rugby-possibility-widget.c
@@ -3,6 +3,7 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#include "config.h"
 #include "rugby-possibility-widget.h"
 
 struct _RugbyPossibilityWidget
@@ -112,7 +113,6 @@ rugby_possibility_widget_draw (GtkWidget *widget,
     gtk_style_context_add_class (context, "possibility");
 
     gtk_render_background (context, cr, x, y, width, height);
-    gtk_render_frame (context, cr, x, y, width, height);
 
     int tries, utries, kicks;
 
diff --git a/src/rugby-possibility.c b/src/rugby-possibility.c
index ed4c6ae..0cadfbb 100644
--- a/src/rugby-possibility.c
+++ b/src/rugby-possibility.c
@@ -3,6 +3,7 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#include "config.h"
 #include "rugby-possibility.h"
 
 struct _RugbyPossibility
-- 
GitLab