[gnome-initial-setup/wip/port-to-gtk4: 101/110] privacy: Port to GTK4




commit e2a4d2b3a75b76c82c16aa84baa49d5edd976d61
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jul 6 12:39:45 2022 -0300

    privacy: Port to GTK4
    
    Port the Privacy page to GTK4. Because it is easier, just use
    preferences groups and rows to also make this port closer to
    the proposed mockups (although it's still slightly different).

 gnome-initial-setup/gnome-initial-setup.c          |   4 +-
 gnome-initial-setup/pages/meson.build              |   2 +-
 .../pages/privacy/gis-privacy-page.c               |  57 +++-----
 .../pages/privacy/gis-privacy-page.ui              | 153 +++++++--------------
 4 files changed, 75 insertions(+), 141 deletions(-)
---
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 748d2256..82963e21 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -34,7 +34,7 @@
 #include "pages/keyboard/gis-keyboard-page.h"
 #include "pages/network/gis-network-page.h"
 //#include "pages/timezone/gis-timezone-page.h"
-//#include "pages/privacy/gis-privacy-page.h"
+#include "pages/privacy/gis-privacy-page.h"
 //#include "pages/software/gis-software-page.h"
 //#include "pages/goa/gis-goa-page.h"
 //#include "pages/account/gis-account-pages.h"
@@ -66,7 +66,7 @@ static PageData page_table[] = {
   PAGE (language, FALSE),
   PAGE (keyboard, FALSE),
   PAGE (network,  FALSE),
-  //PAGE (privacy,  FALSE),
+  PAGE (privacy,  FALSE),
   //PAGE (timezone, TRUE),
   //PAGE (software, TRUE),
   //PAGE (goa,      FALSE),
diff --git a/gnome-initial-setup/pages/meson.build b/gnome-initial-setup/pages/meson.build
index beed10f1..208b775f 100644
--- a/gnome-initial-setup/pages/meson.build
+++ b/gnome-initial-setup/pages/meson.build
@@ -4,7 +4,7 @@ pages = [
    'keyboard',
    'network',
    #'timezone',
-   #'privacy',
+   'privacy',
    #'goa',
    #'password',
    #'software',
diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.c 
b/gnome-initial-setup/pages/privacy/gis-privacy-page.c
index 80c40c36..40cfd882 100644
--- a/gnome-initial-setup/pages/privacy/gis-privacy-page.c
+++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.c
@@ -37,11 +37,9 @@
 struct _GisPrivacyPagePrivate
 {
   GtkWidget *location_switch;
+  GtkWidget *reporting_group;
   GtkWidget *reporting_row;
   GtkWidget *reporting_switch;
-  GtkWidget *reporting_label;
-  GtkWidget *mozilla_privacy_policy_label;
-  GtkWidget *distro_privacy_policy_label;
   GSettings *location_settings;
   GSettings *privacy_settings;
   guint abrt_watch_id;
@@ -56,34 +54,31 @@ update_os_data (GisPrivacyPage *page)
   GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page);
   g_autofree char *name = g_get_os_info (G_OS_INFO_KEY_NAME);
   g_autofree char *privacy_policy = g_get_os_info (G_OS_INFO_KEY_PRIVACY_POLICY_URL);
-  char *text;
+  g_autofree char *subtitle = NULL;
 
   if (!name)
     name = g_strdup ("GNOME");
 
-  /* Translators: the parameter here is the name of a distribution,
-   * like "Fedora" or "Ubuntu". It falls back to "GNOME" if we can't
-   * detect any distribution.
-   */
-  text = g_strdup_printf (_("Sending reports of technical problems helps us to improve %s. Reports are sent 
anonymously and are scrubbed of personal data."), name);
-  gtk_label_set_label (GTK_LABEL (priv->reporting_label), text);
-  g_free (text);
-
   if (privacy_policy)
     {
-      /* Translators: the parameter here is the name of a distribution,
+      /* Translators: the first parameter here is the name of a distribution,
        * like "Fedora" or "Ubuntu". It falls back to "GNOME" if we can't
        * detect any distribution.
        */
-      g_autofree char *distro_label = g_strdup_printf (_("Problem data will be collected by %s:"), name);
-      text = g_strdup_printf ("%s <a href='%s'>%s</a>", distro_label, privacy_policy, _("Privacy Policy"));
-      gtk_label_set_markup (GTK_LABEL (priv->distro_privacy_policy_label), text);
-      g_free (text);
+      subtitle = g_strdup_printf (_("Sends technical reports that have personal information automatically "
+                                    "removed. Data is collected by %1$s (<a href='%2$s'>privacy 
policy</a>)."),
+                                  name, privacy_policy);
     }
   else
     {
-      gtk_widget_hide (priv->distro_privacy_policy_label);
+      /* Translators: the parameter here is the name of a distribution,
+       * like "Fedora" or "Ubuntu". It falls back to "GNOME" if we can't
+       * detect any distribution.
+       */
+      subtitle = g_strdup_printf (_("Sends technical reports that have personal information automatically "
+                                    "removed. Data is collected by %s."), name);
     }
+  adw_action_row_set_subtitle (ADW_ACTION_ROW (priv->reporting_row), subtitle);
 }
 
 static void
@@ -95,9 +90,7 @@ abrt_appeared_cb (GDBusConnection *connection,
   GisPrivacyPage *page = user_data;
   GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page);
 
-  gtk_widget_show (priv->reporting_row);
-  gtk_widget_show (priv->reporting_label);
-  gtk_widget_show (priv->distro_privacy_policy_label);
+  gtk_widget_show (priv->reporting_group);
 }
 
 static void
@@ -108,9 +101,7 @@ abrt_vanished_cb (GDBusConnection *connection,
   GisPrivacyPage *page = user_data;
   GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page);
 
-  gtk_widget_hide (priv->reporting_row);
-  gtk_widget_hide (priv->reporting_label);
-  gtk_widget_hide (priv->distro_privacy_policy_label);
+  gtk_widget_hide (priv->reporting_group);
 }
 
 static void
@@ -118,7 +109,6 @@ gis_privacy_page_constructed (GObject *object)
 {
   GisPrivacyPage *page = GIS_PRIVACY_PAGE (object);
   GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page);
-  char *text;
 
   G_OBJECT_CLASS (gis_privacy_page_parent_class)->constructed (object);
 
@@ -132,10 +122,6 @@ gis_privacy_page_constructed (GObject *object)
 
   update_os_data (page);
 
-  text = g_strdup_printf ("%s <a href='%s'>%s</a>", _("Uses Mozilla Location Service:"), 
"https://location.services.mozilla.com/privacy";, _("Privacy Policy"));
-  gtk_label_set_markup (GTK_LABEL (priv->mozilla_privacy_policy_label), text);
-  g_free (text);
-
   priv->abrt_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
                                           "org.freedesktop.problems.daemon",
                                           G_BUS_NAME_WATCHER_FLAGS_NONE,
@@ -208,17 +194,17 @@ activate_link (GtkLabel       *label,
   GtkWidget *progress_bar;
 
   dialog = gtk_dialog_new_with_buttons (_("Privacy Policy"),
-                                        GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page))),
+                                        GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (page))),
                                         GTK_DIALOG_MODAL
                                         | GTK_DIALOG_DESTROY_WITH_PARENT
                                         | GTK_DIALOG_USE_HEADER_BAR,
                                         NULL, NULL);
 
   overlay = gtk_overlay_new ();
-  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), overlay);
+  gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), overlay);
 
   progress_bar = gtk_progress_bar_new ();
-  gtk_style_context_add_class (gtk_widget_get_style_context (progress_bar), GTK_STYLE_CLASS_OSD);
+  gtk_widget_add_css_class (progress_bar, "osd");
   gtk_widget_set_halign (progress_bar, GTK_ALIGN_FILL);
   gtk_widget_set_valign (progress_bar, GTK_ALIGN_START);
   gtk_overlay_add_overlay (GTK_OVERLAY (overlay), progress_bar);
@@ -229,9 +215,8 @@ activate_link (GtkLabel       *label,
   gtk_widget_set_vexpand (view, TRUE);
   g_signal_connect (view, "notify::estimated-load-progress",
                     G_CALLBACK (notify_progress_cb), progress_bar);
+  gtk_overlay_set_child (GTK_OVERLAY (overlay), view);
 
-  gtk_container_add (GTK_CONTAINER (overlay), view);
-  gtk_widget_show_all (overlay);
 
   gtk_window_present (GTK_WINDOW (dialog));
 
@@ -254,11 +239,9 @@ gis_privacy_page_class_init (GisPrivacyPageClass *klass)
 
   gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/initial-setup/gis-privacy-page.ui");
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, location_switch);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_group);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_row);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_switch);
-  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_label);
-  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, 
mozilla_privacy_policy_label);
-  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, 
distro_privacy_policy_label);
   gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), activate_link);
 
   page_class->page_id = PAGE_ID;
diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.ui 
b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui
index 1afde98e..84ea8e3c 100644
--- a/gnome-initial-setup/pages/privacy/gis-privacy-page.ui
+++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui
@@ -2,127 +2,78 @@
 <interface>
   <requires lib="gtk+" version="3.0"/>
   <template class="GisPrivacyPage" parent="GisPage">
-    <property name="visible">True</property>
+
     <child>
-      <object class="GtkBox" id="box">
-        <property name="visible">True</property>
-        <property name="halign">center</property>
-        <property name="valign">fill</property>
-        <property name="orientation">vertical</property>
+      <object class="AdwPreferencesPage">
+
         <child>
-          <object class="GisPageHeader" id="header">
-            <property name="visible">True</property>
-            <property name="margin_top">24</property>
-            <property name="title" translatable="yes">Privacy</property>
-            <property name="icon_name">preferences-system-privacy-symbolic</property>
-            <property name="show_icon" bind-source="GisPrivacyPage" bind-property="small-screen" 
bind-flags="invert-boolean|sync-create"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="margin-top">40</property>
-            <property name="orientation">horizontal</property>
-            <property name="homogeneous">True</property>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-                <property name="label" translatable="yes">Location Services</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-            </child>
+          <object class="AdwPreferencesGroup">
             <child>
-              <object class="GtkSwitch" id="location_switch">
-                <property name="halign">end</property>
-                <property name="visible">True</property>
+              <object class="GisPageHeader" id="header">
+                <property name="margin_top">24</property>
+                <property name="title" translatable="yes">Privacy</property>
+                <property name="icon_name">preferences-system-privacy-symbolic</property>
+                <property name="show_icon" bind-source="GisPrivacyPage" bind-property="small-screen" 
bind-flags="invert-boolean|sync-create"/>
               </object>
             </child>
           </object>
         </child>
+
         <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="margin-top">10</property>
-            <property name="xalign">0</property>
-            <property name="max-width-chars">50</property>
-            <property name="wrap">True</property>
-            <property name="label" translatable="yes">Allows applications to determine your geographical 
location. An indication is shown when location services are in use.</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="mozilla_privacy_policy_label">
-            <property name="visible">True</property>
-            <property name="margin-top">10</property>
-            <property name="xalign">0</property>
-            <property name="halign">start</property>
-            <property name="use-markup">True</property>
-            <signal name="activate-link" handler="activate_link"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkBox" id="reporting_row">
-            <property name="margin-top">20</property>
-            <property name="orientation">horizontal</property>
-            <property name="homogeneous">True</property>
+          <object class="AdwPreferencesGroup">
             <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-                <property name="label" translatable="yes">Automatic Problem Reporting</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
+              <object class="AdwActionRow">
+                <property name="use-markup">True</property>
+                <property name="title" translatable="yes">Location Services</property>
+                <property name="subtitle" translatable="yes">Allows applications to determine your 
geographical location. Uses the Mozilla Location Service (&lt;a 
href='https://location.services.mozilla.com/privacy'&gt;privacy policy&lt;/a&gt;).</property>
+                <property name="activatable-widget">location_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="location_switch">
+                    <property name="valign">center</property>
+                  </object>
+                </child>
               </object>
             </child>
-            <child>
-              <object class="GtkSwitch" id="reporting_switch">
-                <property name="visible">True</property>
-                <property name="halign">end</property>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="reporting_label">
-            <property name="margin-top">10</property>
-            <property name="xalign">0</property>
-            <property name="max-width-chars">50</property>
-            <property name="wrap">True</property>
           </object>
         </child>
+
         <child>
-          <object class="GtkLabel" id="distro_privacy_policy_label">
-            <property name="visible">True</property>
-            <property name="margin-top">10</property>
-            <property name="xalign">0</property>
-            <property name="halign">start</property>
-            <property name="use-markup">True</property>
-            <signal name="activate-link" handler="activate_link"/>
+          <object class="AdwPreferencesGroup" id="reporting_group">
+            <child>
+              <object class="AdwActionRow" id="reporting_row">
+                <property name="title" translatable="yes">Automatic Problem Reporting</property>
+                <property name="activatable-widget">reporting_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="reporting_switch">
+                    <property name="valign">center</property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
+
         <child>
-          <object class="GtkLabel" id="footer_label">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Privacy controls can be changed at any time from the 
Settings application.</property>
-            <property name="justify">center</property>
-            <property name="wrap">True</property>
-            <property name="margin_bottom">18</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+          <object class="AdwPreferencesGroup">
+            <child>
+              <object class="GtkLabel" id="footer_label">
+                <property name="valign">end</property>
+                <property name="vexpand">True</property>
+                <property name="label" translatable="yes">Privacy controls can be changed at any time from 
the Settings application.</property>
+                <property name="xalign">0.5</property>
+                <property name="justify">center</property>
+                <property name="wrap">True</property>
+                <property name="margin_bottom">18</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+            </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">4</property>
-          </packing>
         </child>
+
       </object>
     </child>
+
   </template>
 </interface>


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