From 0af66478a2657e014b13477ead48d3861f462bb6 Mon Sep 17 00:00:00 2001
From: Bruce Cowan <bruce@bcowan.me.uk>
Date: Wed, 25 Sep 2024 18:38:53 +0100
Subject: [PATCH] Migrate to AdwPreferencesDialog

---
 data/gtk/prefs.blp                            |  7 ++--
 src/main.c                                    |  6 ++--
 src/meson.build                               |  4 +--
 ...ugby-pref-window.c => rugby-pref-dialog.c} | 36 +++++++++----------
 src/rugby-pref-dialog.h                       | 21 +++++++++++
 src/rugby-pref-window.h                       | 21 -----------
 6 files changed, 45 insertions(+), 50 deletions(-)
 rename src/{rugby-pref-window.c => rugby-pref-dialog.c} (56%)
 create mode 100644 src/rugby-pref-dialog.h
 delete mode 100644 src/rugby-pref-window.h

diff --git a/data/gtk/prefs.blp b/data/gtk/prefs.blp
index 50be7f1..abf38e3 100644
--- a/data/gtk/prefs.blp
+++ b/data/gtk/prefs.blp
@@ -1,15 +1,12 @@
-// SPDX-FileCopyrightText: 2022-2023 Bruce Cowan <bruce@bcowan.me.uk>
+// SPDX-FileCopyrightText: 2022-2024 Bruce Cowan <bruce@bcowan.me.uk>
 //
 // SPDX-License-Identifier: GPL-3.0-or-later
 
 using Gtk 4.0;
 using Adw 1;
 
-template $RugbyPrefWindow : Adw.PreferencesWindow {
-  default-width: -1;
-  default-height: -1;
+template $RugbyPrefDialog : Adw.PreferencesDialog {
   title: "Preferences";
-  modal: true;
   search-enabled: false;
 
   Adw.PreferencesPage {
diff --git a/src/main.c b/src/main.c
index bc9e344..a6acc9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
 #include <config.h>
 
 #include "rugby-app-window.h"
-#include "rugby-pref-window.h"
+#include "rugby-pref-dialog.h"
 
 static void
 on_activate (              GApplication *app,
@@ -48,8 +48,8 @@ preferences_activated (G_GNUC_UNUSED GSimpleAction *simple,
     GtkApplication *app = GTK_APPLICATION (user_data);
     GtkWindow *window = gtk_application_get_active_window (app);
 
-    RugbyPrefWindow *pref_window = rugby_pref_window_new (RUGBY_APP_WINDOW (window));
-    gtk_window_present (GTK_WINDOW (pref_window));
+    RugbyPrefDialog *pref_window = rugby_pref_dialog_new ();
+    adw_dialog_present (ADW_DIALOG (pref_window), GTK_WIDGET (window));
 }
 
 static void
diff --git a/src/meson.build b/src/meson.build
index c49d2bd..2f7f618 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: 2016-2023 Bruce Cowan <bruce@bcowan.me.uk>
+# SPDX-FileCopyrightText: 2016-2024 Bruce Cowan <bruce@bcowan.me.uk>
 #
 # SPDX-License-Identifier: GPL-3.0-or-later
 sources = [
@@ -7,7 +7,7 @@ sources = [
     'rugby-list-store.c',
     'rugby-possibility.c',
     'rugby-possibility-widget.c',
-    'rugby-pref-window.c',
+    'rugby-pref-dialog.c',
 ]
 
 config_h = vcs_tag(
diff --git a/src/rugby-pref-window.c b/src/rugby-pref-dialog.c
similarity index 56%
rename from src/rugby-pref-window.c
rename to src/rugby-pref-dialog.c
index a4c3c3c..dcd30f4 100644
--- a/src/rugby-pref-window.c
+++ b/src/rugby-pref-dialog.c
@@ -4,11 +4,11 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include "rugby-pref-window.h"
+#include "rugby-pref-dialog.h"
 
-struct _RugbyPrefWindow
+struct _RugbyPrefDialog
 {
-  AdwPreferencesWindow parent_instance;
+  AdwPreferencesDialog parent_instance;
 
   GtkWidget *try_spin;
   GtkWidget *utry_spin;
@@ -17,38 +17,37 @@ struct _RugbyPrefWindow
   GSettings *settings;
 };
 
-G_DEFINE_TYPE (RugbyPrefWindow, rugby_pref_window, ADW_TYPE_PREFERENCES_WINDOW)
+G_DEFINE_TYPE (RugbyPrefDialog, rugby_pref_dialog, ADW_TYPE_PREFERENCES_DIALOG)
 
 static void
-rugby_pref_window_dispose (GObject *object)
+rugby_pref_dialog_dispose (GObject *object)
 {
-  RugbyPrefWindow *self = RUGBY_PREF_WINDOW (object);
+  RugbyPrefDialog *self = RUGBY_PREF_DIALOG (object);
 
   g_clear_object (&self->settings);
-  gtk_widget_dispose_template (GTK_WIDGET (object), RUGBY_TYPE_PREF_WINDOW);
+  gtk_widget_dispose_template (GTK_WIDGET (object), RUGBY_TYPE_PREF_DIALOG);
 
-  G_OBJECT_CLASS (rugby_pref_window_parent_class)->dispose (object);
+  G_OBJECT_CLASS (rugby_pref_dialog_parent_class)->dispose (object);
 }
 
 static void
-rugby_pref_window_class_init (RugbyPrefWindowClass *klass)
+rugby_pref_dialog_class_init (RugbyPrefDialogClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  object_class->dispose = rugby_pref_window_dispose;
+  object_class->dispose = rugby_pref_dialog_dispose;
 
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/uk/me/bcowan/Rugby/gtk/prefs.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, RugbyPrefWindow, try_spin);
-  gtk_widget_class_bind_template_child (widget_class, RugbyPrefWindow, utry_spin);
-  gtk_widget_class_bind_template_child (widget_class, RugbyPrefWindow, kick_spin);
-
+  gtk_widget_class_bind_template_child (widget_class, RugbyPrefDialog, try_spin);
+  gtk_widget_class_bind_template_child (widget_class, RugbyPrefDialog, utry_spin);
+  gtk_widget_class_bind_template_child (widget_class, RugbyPrefDialog, kick_spin);
 }
 
 static void
-rugby_pref_window_init (RugbyPrefWindow *self)
+rugby_pref_dialog_init (RugbyPrefDialog *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -65,10 +64,9 @@ rugby_pref_window_init (RugbyPrefWindow *self)
                    G_SETTINGS_BIND_DEFAULT);
 }
 
-RugbyPrefWindow *
-rugby_pref_window_new (RugbyAppWindow *window)
+RugbyPrefDialog *
+rugby_pref_dialog_new (void)
 {
-  return g_object_new (RUGBY_TYPE_PREF_WINDOW,
-                       "transient-for", window,
+  return g_object_new (RUGBY_TYPE_PREF_DIALOG,
                        NULL);
 }
diff --git a/src/rugby-pref-dialog.h b/src/rugby-pref-dialog.h
new file mode 100644
index 0000000..d3e2a7e
--- /dev/null
+++ b/src/rugby-pref-dialog.h
@@ -0,0 +1,21 @@
+/*
+ * SPDX-FileCopyrightText: 2020-2024 Bruce Cowan <bruce@bcowan.me.uk>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "rugby-app-window.h"
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define RUGBY_TYPE_PREF_DIALOG (rugby_pref_dialog_get_type())
+
+G_DECLARE_FINAL_TYPE (RugbyPrefDialog, rugby_pref_dialog, RUGBY, PREF_DIALOG, AdwPreferencesDialog)
+
+RugbyPrefDialog *rugby_pref_dialog_new (void);
+
+G_END_DECLS
diff --git a/src/rugby-pref-window.h b/src/rugby-pref-window.h
deleted file mode 100644
index 555b890..0000000
--- a/src/rugby-pref-window.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2020-2022 Bruce Cowan <bruce@bcowan.me.uk>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-#pragma once
-
-#include "rugby-app-window.h"
-
-#include <adwaita.h>
-
-G_BEGIN_DECLS
-
-#define RUGBY_TYPE_PREF_WINDOW (rugby_pref_window_get_type())
-
-G_DECLARE_FINAL_TYPE (RugbyPrefWindow, rugby_pref_window, RUGBY, PREF_WINDOW, AdwPreferencesWindow)
-
-RugbyPrefWindow *rugby_pref_window_new (RugbyAppWindow *window);
-
-G_END_DECLS
-- 
GitLab