[gnome-initial-setup/wip/port-to-gtk4: 16/16] WIP: Port app & summary page to GTK 4




commit d4c2df9325d2e5f7e7d109863ff0044d9a9a77af
Author: Will Thompson <will willthompson co uk>
Date:   Thu Dec 16 21:52:12 2021 +0000

    WIP: Port app & summary page to GTK 4
    
    All other pages are temporarily disabled and will be addressed one by
    one.
    
    Initial Setup is meant to resize itself based on the screen size, both
    on startup and when the screen size changes. This is also disabled in
    this patch, to be readded later.

 gnome-initial-setup/gis-assistant.c                |  2 +-
 gnome-initial-setup/gis-assistant.ui               | 63 +++++++---------------
 gnome-initial-setup/gis-driver.c                   | 27 +++++++---
 gnome-initial-setup/gis-page-header.c              |  2 +
 gnome-initial-setup/gis-page-header.ui             | 13 ++---
 gnome-initial-setup/gis-page.c                     |  2 +-
 gnome-initial-setup/gis-page.h                     |  4 +-
 gnome-initial-setup/gnome-initial-setup.c          | 11 ++--
 gnome-initial-setup/gnome-initial-setup.h          |  1 +
 gnome-initial-setup/meson.build                    |  3 +-
 gnome-initial-setup/pages/meson.build              | 18 +++----
 .../pages/summary/gis-summary-page.ui              | 60 +++++++--------------
 12 files changed, 91 insertions(+), 115 deletions(-)
---
diff --git a/gnome-initial-setup/gis-assistant.c b/gnome-initial-setup/gis-assistant.c
index 8405357e..72cbff44 100644
--- a/gnome-initial-setup/gis-assistant.c
+++ b/gnome-initial-setup/gis-assistant.c
@@ -310,7 +310,7 @@ gis_assistant_add_page (GisAssistant *assistant,
   g_signal_connect (page, "destroy", G_CALLBACK (widget_destroyed), assistant);
   g_signal_connect (page, "notify", G_CALLBACK (page_notify), assistant);
 
-  gtk_container_add (GTK_CONTAINER (assistant->stack), GTK_WIDGET (page));
+  gtk_stack_add_child (GTK_STACK (assistant->stack), GTK_WIDGET (page));
 
   /* Update buttons if current page is now the second last page */
   if (assistant->current_page && link &&
diff --git a/gnome-initial-setup/gis-assistant.ui b/gnome-initial-setup/gis-assistant.ui
index 936f829f..19b2f188 100644
--- a/gnome-initial-setup/gis-assistant.ui
+++ b/gnome-initial-setup/gis-assistant.ui
@@ -1,75 +1,55 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <!-- interface-requires gtk+ 3.10 -->
+  <requires lib="gtk" version="4.0"/>
   <object class="GtkHeaderBar" id="titlebar">
-    <property name="visible">True</property>
     <child type="title">
       <object class="GtkLabel" id="title">
-        <property name="visible">True</property>
         <attributes>
-          <attribute name="weight" value="bold"/>
+          <attribute name="weight" value="bold"></attribute>
         </attributes>
       </object>
     </child>
     <child>
       <object class="GtkButton" id="cancel">
-        <property name="visible">True</property>
-        <property name="use-underline">True</property>
+        <property name="use-underline">1</property>
       </object>
     </child>
     <child>
       <object class="GtkButton" id="back">
-        <property name="visible">True</property>
-        <property name="use-underline">True</property>
+        <property name="use-underline">1</property>
       </object>
     </child>
     <child>
-      <object class="GtkLabel" id="placeholder">
-        <property name="visible">True</property>
-      </object>
+      <object class="GtkLabel" id="placeholder"/>
     </child>
-    <child>
-      <object class="GtkSpinner" id="spinner">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
+    <child type="end">
+      <object class="GtkSpinner" id="spinner"/>
     </child>
-    <child>
+    <child type="end">
       <object class="GtkButton" id="skip">
-        <property name="use-underline">True</property>
+        <property name="visible">0</property>
+        <property name="use-underline">1</property>
       </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
     </child>
-    <child>
+    <child type="end">
       <object class="GtkButton" id="forward">
-        <property name="use-underline">True</property>
-        <property name="can-default">True</property>
+        <property name="visible">0</property>
+        <property name="use-underline">1</property>
         <style>
           <class name="suggested-action"/>
         </style>
       </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
     </child>
-    <child>
+    <child type="end">
       <object class="GtkButton" id="accept">
-        <property name="use-underline">True</property>
-        <property name="can-default">True</property>
+        <property name="visible">0</property>
+        <property name="use-underline">1</property>
         <style>
           <class name="suggested-action"/>
         </style>
       </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
     </child>
   </object>
-
   <object class="GtkSizeGroup" id="headerheight">
     <property name="mode">vertical</property>
     <widgets>
@@ -77,22 +57,19 @@
       <widget name="placeholder"/>
     </widgets>
   </object>
-
   <template class="GisAssistant" parent="GtkBox">
     <property name="orientation">vertical</property>
     <child>
       <object class="GtkBox" id="main_layout">
-        <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child>
           <object class="GtkStack" id="stack">
-            <property name="visible">True</property>
             <property name="transition-type">slide-left-right</property>
-            <property name="vexpand">True</property>
-            <property name="hexpand">True</property>
-            <property name="hhomogeneous">False</property>
-            <property name="vhomogeneous">False</property>
+            <property name="vexpand">1</property>
+            <property name="hexpand">1</property>
+            <property name="hhomogeneous">0</property>
+            <property name="vhomogeneous">0</property>
             <signal name="notify::visible-child" handler="visible_child_changed" object="GisAssistant" 
swapped="yes"/>
           </object>
         </child>
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index ea04cf57..5153b0bd 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -157,12 +157,12 @@ prepare_main_window (GisDriver *driver)
 {
   GtkWidget *child, *sw;
 
-  child = g_object_ref (gtk_bin_get_child (GTK_BIN (driver->main_window)));
-  gtk_container_remove (GTK_CONTAINER (driver->main_window), child);
-  sw = gtk_scrolled_window_new (NULL, NULL);
+  child = g_object_ref (gtk_window_get_child (GTK_WINDOW (driver->main_window)));
+  gtk_window_set_child (GTK_WINDOW (driver->main_window), NULL);
+  sw = gtk_scrolled_window_new ();
   gtk_widget_show (sw);
-  gtk_container_add (GTK_CONTAINER (driver->main_window), sw);
-  gtk_container_add (GTK_CONTAINER (sw), child);
+  gtk_window_set_child (GTK_WINDOW (driver->main_window), sw);
+  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), child);
   g_object_unref (child);
 
   g_signal_connect_swapped (driver->assistant,
@@ -591,6 +591,7 @@ gis_driver_is_small_screen (GisDriver *driver)
   return driver->small_screen;
 }
 
+#if 0
 static gboolean
 monitor_is_small (GdkMonitor *monitor)
 {
@@ -602,6 +603,7 @@ monitor_is_small (GdkMonitor *monitor)
   gdk_monitor_get_geometry (monitor, &geom);
   return geom.height < 800;
 }
+#endif
 
 static void
 gis_driver_get_property (GObject      *object,
@@ -679,6 +681,7 @@ gis_driver_activate (GApplication *app)
   gtk_window_present (GTK_WINDOW (driver->main_window));
 }
 
+#if 0
 static void
 set_small_screen_based_on_primary_monitor (GisDriver *driver)
 {
@@ -785,11 +788,14 @@ screen_size_changed (GdkScreen *screen, GisDriver *driver)
 {
   update_screen_size (driver);
 }
+#endif
 
 static void
 window_realize_cb (GtkWidget *widget, gpointer user_data)
 {
+#if 0
   update_screen_size (GIS_DRIVER (user_data));
+#endif
 }
 
 static void
@@ -830,9 +836,12 @@ gis_driver_startup (GApplication *app)
 
   driver->main_window = g_object_new (GTK_TYPE_APPLICATION_WINDOW,
                                     "application", app,
-                                    "type", GTK_WINDOW_TOPLEVEL,
                                     "icon-name", "preferences-system",
                                     "deletable", FALSE,
+                                    "resizable", FALSE,
+                                    "modal", TRUE,
+                                    "default-width", 1024,
+                                    "default-height", 768,
                                     NULL);
 
   g_signal_connect (driver->main_window,
@@ -841,7 +850,7 @@ gis_driver_startup (GApplication *app)
                     (gpointer)app);
 
   driver->assistant = g_object_new (GIS_TYPE_ASSISTANT, NULL);
-  gtk_container_add (GTK_CONTAINER (driver->main_window), GTK_WIDGET (driver->assistant));
+  gtk_window_set_child (GTK_WINDOW (driver->main_window), GTK_WIDGET (driver->assistant));
 
   gtk_widget_show (GTK_WIDGET (driver->assistant));
 
@@ -854,17 +863,21 @@ gis_driver_startup (GApplication *app)
 static void
 gis_driver_init (GisDriver *driver)
 {
+#if 0
   GdkScreen *screen;
 
   screen = gdk_screen_get_default ();
 
   set_small_screen_based_on_primary_monitor (driver);
+#endif
 
   load_vendor_conf_file (driver);
 
+#if 0
   if (screen != NULL)
     g_signal_connect (screen, "size-changed",
                       G_CALLBACK (screen_size_changed), driver);
+#endif
 }
 
 static void
diff --git a/gnome-initial-setup/gis-page-header.c b/gnome-initial-setup/gis-page-header.c
index 8da1ee44..a67efe03 100644
--- a/gnome-initial-setup/gis-page-header.c
+++ b/gnome-initial-setup/gis-page-header.c
@@ -197,7 +197,9 @@ gis_page_header_class_init (GisPageHeaderClass *klass)
 
   g_autoptr(GtkCssProvider) provider = gtk_css_provider_new ();
   gtk_css_provider_load_from_resource (provider, "/org/gnome/initial-setup/gis-page-header.css");
+#if 0
   gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                              GTK_STYLE_PROVIDER (provider),
                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+#endif
 }
diff --git a/gnome-initial-setup/gis-page-header.ui b/gnome-initial-setup/gis-page-header.ui
index e5e17958..4fde7b89 100644
--- a/gnome-initial-setup/gis-page-header.ui
+++ b/gnome-initial-setup/gis-page-header.ui
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
-  <!-- interface-requires gtk+ 3.10 -->
+  <requires lib="gtk" version="4.0"/>
   <template class="GisPageHeader" parent="GtkBox">
     <property name="orientation">vertical</property>
     <property name="spacing">18</property>
     <child>
       <object class="GtkImage" id="icon">
-        <property name="can_focus">False</property>
+        <property name="visible">0</property>
         <property name="pixel_size">96</property>
         <style>
           <class name="dim-label"/>
@@ -15,14 +15,15 @@
     </child>
     <child>
       <object class="GtkBox" id="box">
+        <property name="visible">0</property>
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkLabel" id="title">
-            <property name="can_focus">False</property>
+            <property name="visible">0</property>
             <property name="justify">center</property>
             <property name="max_width_chars">65</property>
-            <property name="wrap">True</property>
+            <property name="wrap">1</property>
             <style>
               <class name="title-1"/>
             </style>
@@ -30,10 +31,10 @@
         </child>
         <child>
           <object class="GtkLabel" id="subtitle">
-            <property name="can_focus">False</property>
+            <property name="visible">0</property>
             <property name="justify">center</property>
             <property name="max_width_chars">65</property>
-            <property name="wrap">True</property>
+            <property name="wrap">1</property>
           </object>
         </child>
       </object>
diff --git a/gnome-initial-setup/gis-page.c b/gnome-initial-setup/gis-page.c
index 25729d09..75a8ae11 100644
--- a/gnome-initial-setup/gis-page.c
+++ b/gnome-initial-setup/gis-page.c
@@ -42,7 +42,7 @@ struct _GisPagePrivate
 };
 typedef struct _GisPagePrivate GisPagePrivate;
 
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GisPage, gis_page, GTK_TYPE_BIN);
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GisPage, gis_page, ADW_TYPE_BIN);
 
 enum
 {
diff --git a/gnome-initial-setup/gis-page.h b/gnome-initial-setup/gis-page.h
index ecc38b62..25a41b5c 100644
--- a/gnome-initial-setup/gis-page.h
+++ b/gnome-initial-setup/gis-page.h
@@ -44,14 +44,14 @@ typedef void (* GisPageApplyCallback) (GisPage *page,
 
 struct _GisPage
 {
-  GtkBin parent;
+  AdwBin parent;
 
   GisDriver *driver;
 };
 
 struct _GisPageClass
 {
-  GtkBinClass parent_class;
+  AdwBinClass parent_class;
   char *page_id;
 
   void         (*locale_changed) (GisPage *page);
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index c7ac54e6..f8e3a253 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -65,6 +65,7 @@ typedef struct {
 #define PAGE(name, new_user_only) { #name, gis_prepare_ ## name ## _page, new_user_only }
 
 static PageData page_table[] = {
+#if 0
   PAGE (welcome, FALSE),
   PAGE (language, FALSE),
   PAGE (keyboard, FALSE),
@@ -80,6 +81,7 @@ static PageData page_table[] = {
 #ifdef HAVE_PARENTAL_CONTROLS
   PAGE (parental_controls, TRUE),
   PAGE (parent_password, TRUE),
+#endif
 #endif
   PAGE (summary,  FALSE),
   { NULL },
@@ -178,7 +180,8 @@ destroy_pages_after (GisAssistant *assistant,
   l = l->next;
   for (; l != NULL; l = next) {
     next = l->next;
-    gtk_widget_destroy (GTK_WIDGET (l->data));
+    // TODO: remove from parent
+    g_object_unref (GTK_WIDGET (l->data));
   }
 }
 
@@ -197,7 +200,7 @@ rebuild_pages_cb (GisDriver *driver)
   page_data = page_table;
 
   g_ptr_array_free (skipped_pages, TRUE);
-  skipped_pages = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_widget_destroy);
+  skipped_pages = g_ptr_array_new_with_free_func (g_object_unref);
 
   if (current_page != NULL) {
     destroy_pages_after (assistant, current_page);
@@ -290,7 +293,7 @@ main (int argc, char *argv[])
   cheese_gtk_init (NULL, NULL);
 #endif
 
-  gtk_init (&argc, &argv);
+  gtk_init ();
 
   g_message ("Starting gnome-initial-setup");
   if (gis_get_mock_mode ())
@@ -298,7 +301,7 @@ main (int argc, char *argv[])
   else
     g_message ("Production mode: changes will be saved to disk");
 
-  skipped_pages = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_widget_destroy);
+  skipped_pages = g_ptr_array_new_with_free_func (g_object_unref);
   mode = get_mode ();
 
   /* When we are running as the gnome-initial-setup user we
diff --git a/gnome-initial-setup/gnome-initial-setup.h b/gnome-initial-setup/gnome-initial-setup.h
index 88806345..2dd74126 100644
--- a/gnome-initial-setup/gnome-initial-setup.h
+++ b/gnome-initial-setup/gnome-initial-setup.h
@@ -25,6 +25,7 @@
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 #include <glib/gi18n.h>
+#include <adwaita.h>
 
 typedef struct _GisDriver    GisDriver;
 typedef struct _GisAssistant GisAssistant;
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index 28ae5ea6..702f6d12 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -38,7 +38,8 @@ dependencies = [
     dependency ('gweather4', fallback: ['libgweather', 'libgweather_dep']),
     goa_dep,
     goa_backend_dep,
-    dependency ('gtk+-3.0', version: '>= 3.11.3'),
+    dependency ('libadwaita', fallback: ['libadwaita', 'libadwaita_dep']),
+    dependency ('gtk4', version: '>= 4.5.0'),
     dependency ('glib-2.0', version: '>= 2.63.1'),
     dependency ('gio-unix-2.0', version: '>= 2.53.0'),
     dependency ('gdm', version: '>= 3.8.3'),
diff --git a/gnome-initial-setup/pages/meson.build b/gnome-initial-setup/pages/meson.build
index e82c5574..4488f332 100644
--- a/gnome-initial-setup/pages/meson.build
+++ b/gnome-initial-setup/pages/meson.build
@@ -1,14 +1,14 @@
 pages = [
-   'account',
-   'language',
-   'keyboard',
-   'network',
-   'timezone',
-   'privacy',
-   'password',
-   'software',
+#   'account',
+#   'language',
+#   'keyboard',
+#   'network',
+#   'timezone',
+#   'privacy',
+#   'password',
+#   'software',
    'summary',
-   'welcome',
+#   'welcome',
 ]
 
 if libmalcontent_dep.found() and libmalcontent_ui_dep.found()
diff --git a/gnome-initial-setup/pages/summary/gis-summary-page.ui 
b/gnome-initial-setup/pages/summary/gis-summary-page.ui
index cf2c2dee..14a57ebc 100644
--- a/gnome-initial-setup/pages/summary/gis-summary-page.ui
+++ b/gnome-initial-setup/pages/summary/gis-summary-page.ui
@@ -1,75 +1,53 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk" version="4.0"/>
   <template class="GisSummaryPage" parent="GisPage">
     <child>
       <object class="GtkBox" id="box">
-        <property name="visible">True</property>
         <property name="halign">center</property>
         <property name="valign">center</property>
         <property name="orientation">vertical</property>
         <property name="spacing">16</property>
         <child type="center">
           <object class="GtkImage" id="image">
-            <property name="visible">True</property>
             <property name="resource">/org/gnome/initial-setup/ready-to-go.svg</property>
             <property name="width_request">128</property>
             <property name="height_request">128</property>
           </object>
-          <packing>
-            <property name="pack_type">start</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkButton" id="start_button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="use_underline">True</property>
-            <property name="halign">center</property>
+          <object class="GtkLabel" id="title">
+            <property name="justify">center</property>
+            <property name="label" translatable="yes">All done!</property>
+            <property name="wrap">1</property>
             <style>
-              <class name="suggested-action"/>
+              <class name="large-title"/>
             </style>
-            <child>
-              <object class="GtkLabel" id="start_button_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="justify">center</property>
-                <property name="wrap">True</property>
-                <property name="xpad">8</property>
-                <property name="ypad">8</property>
-                <property name="use_underline">True</property>
-              </object>
-            </child>
           </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="tagline">
-            <property name="visible">True</property>
             <property name="justify">center</property>
-            <property name="wrap">True</property>
+            <property name="wrap">1</property>
             <property name="max-width-chars">60</property>
           </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="title">
-            <property name="visible">True</property>
-            <property name="justify">center</property>
-            <property name="label" translatable="yes">All done!</property>
-            <property name="wrap">True</property>
+          <object class="GtkButton" id="start_button">
+            <property name="focusable">1</property>
+            <property name="use_underline">1</property>
+            <property name="halign">center</property>
             <style>
-              <class name="large-title"/>
+              <class name="suggested-action"/>
             </style>
+            <child>
+              <object class="GtkLabel" id="start_button_label">
+                <property name="justify">center</property>
+                <property name="wrap">1</property>
+                <property name="use_underline">1</property>
+              </object>
+            </child>
           </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
         </child>
       </object>
     </child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]