[gnome-initial-setup/mcatanzaro/resurrect-software-page: 2/3] software: replace use of obsolete settings with fedora-third-party




commit 8cf8fa9081da1551109fbc981f989bd68abaf26a
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Fri Jul 30 16:48:18 2021 -0500

    software: replace use of obsolete settings with fedora-third-party
    
    The original repo enablement code relies on two GNOME Software settings
    that no longer exist: one setting to toggle whether properietary repos
    are enabled, and another that lists which proprietary repos to enable.
    gnome-initial-setup would then use PackageKit to enable said repos. This
    was nice in that it worked using entirely upstream code, but since it no
    longer exists that does us no good.
    
    Instead we'll just have distro-specific implementation here, which is a
    little non-ideal but not the end of the world. We'll just call a
    Fedora-specific script depending on whether the setting is enabled or
    disabled. Feel free to add logic for your distro.

 data/20-gnome-initial-setup.rules                  |   6 +
 gnome-initial-setup/meson.build                    |   1 -
 .../pages/software/gis-software-page.c             | 154 +++++----------------
 meson.build                                        |   6 -
 meson_options.txt                                  |   6 -
 5 files changed, 42 insertions(+), 131 deletions(-)
---
diff --git a/data/20-gnome-initial-setup.rules b/data/20-gnome-initial-setup.rules
index 33d7e300..9d451b0f 100644
--- a/data/20-gnome-initial-setup.rules
+++ b/data/20-gnome-initial-setup.rules
@@ -17,6 +17,12 @@ polkit.addRule(function(action, subject) {
                          action.id.indexOf('org.freedesktop.realmd.') === 0 ||
                          action.id.indexOf('com.endlessm.ParentalControls.') === 0);
 
+    if (action.id === 'org.freedesktop.policykit.exec') {
+        let basename = path => path.substring(path.lastIndexOf('/') + 1);
+        if (basename(action.lookup('program')) === 'fedora-third-party')
+            actionMatches = true;
+    }
+
     if (actionMatches) {
         if (subject.local)
             return 'yes';
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index b08c3892..1d2388ba 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -54,7 +54,6 @@ dependencies = [
     dependency ('webkit2gtk-4.0', version: '>= 2.26.0'),
     cheese_dep,
     cheese_gtk_dep,
-    pkgkit_dep,
     ibus_dep,
     libmalcontent_dep,
     libmalcontent_ui_dep,
diff --git a/gnome-initial-setup/pages/software/gis-software-page.c 
b/gnome-initial-setup/pages/software/gis-software-page.c
index 62fc90dc..59a89c5d 100644
--- a/gnome-initial-setup/pages/software/gis-software-page.c
+++ b/gnome-initial-setup/pages/software/gis-software-page.c
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2016 Red Hat
+ * Copyright (C) 2016, 2021 Red Hat
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -18,6 +18,7 @@
  * Written by:
  *     Matthias Clasen <mclasen redhat com>
  *     Kalev Lember <klember redhat com>
+ *     Michael Catanzaro <mcatanzaro redhat com>
  */
 
 /* SOFTWARE pages {{{1 */
@@ -31,10 +32,6 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 #include <gtk/gtk.h>
-#ifdef ENABLE_SOFTWARE_SOURCES
-#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
-#include <packagekit-glib2/packagekit.h>
-#endif
 
 #include "gis-page-header.h"
 
@@ -43,12 +40,6 @@ struct _GisSoftwarePagePrivate
   GtkWidget *more_popover;
   GtkWidget *proprietary_switch;
   GtkWidget *header;
-
-  GSettings *software_settings;
-  guint enable_count;
-#ifdef ENABLE_SOFTWARE_SOURCES
-  PkTask *task;
-#endif
 };
 
 typedef struct _GisSoftwarePagePrivate GisSoftwarePagePrivate;
@@ -59,121 +50,58 @@ static void
 gis_software_page_constructed (GObject *object)
 {
   GisSoftwarePage *page = GIS_SOFTWARE_PAGE (object);
-  GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
 
   G_OBJECT_CLASS (gis_software_page_parent_class)->constructed (object);
 
-  priv->software_settings = g_settings_new ("org.gnome.software");
-#ifdef ENABLE_SOFTWARE_SOURCES
-  priv->task = pk_task_new ();
-#endif
-
-  gtk_switch_set_active (GTK_SWITCH (priv->proprietary_switch),
-                         g_settings_get_boolean (priv->software_settings, "show-nonfree-software"));
-
   gis_page_set_complete (GIS_PAGE (page), TRUE);
 
   gtk_widget_show (GTK_WIDGET (page));
 }
 
-static void
-gis_software_page_dispose (GObject *object)
-{
-  GisSoftwarePage *page = GIS_SOFTWARE_PAGE (object);
-  GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
-
-  g_clear_object (&priv->software_settings);
-#ifdef ENABLE_SOFTWARE_SOURCES
-  g_clear_object (&priv->task);
-#endif
-
-  G_OBJECT_CLASS (gis_software_page_parent_class)->dispose (object);
-}
-
-#ifdef ENABLE_SOFTWARE_SOURCES
-static void
-repo_enabled_cb (GObject      *source,
-                 GAsyncResult *res,
-                 gpointer      data)
+/* Distro-specific stuff is isolated here so that the rest of this page can be
+ * used by other distros. Feel free to add your distro here.
+ */
+static char *
+find_fedora_third_party (void)
 {
-  GisSoftwarePage *page = GIS_SOFTWARE_PAGE (data);
-  GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
-  g_autoptr(GError) error = NULL;
-  g_autoptr(PkResults) results = NULL;
-
-  results = pk_client_generic_finish (PK_CLIENT (source),
-                                      res,
-                                      &error);
-  if (!results)
-    {
-      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-        return;
-#if PK_CHECK_VERSION(1,1,4)
-      if (!g_error_matches (error, PK_CLIENT_ERROR, 0xff + PK_ERROR_ENUM_REPO_ALREADY_SET))
-#endif
-        g_critical ("Failed to enable repository: %s", error->message);
-    }
-
-  priv->enable_count--;
-  if (priv->enable_count == 0)
-    {
-      /* all done */
-      gis_page_apply_complete (GIS_PAGE (page), TRUE);
-    }
+  return g_find_program_in_path ("fedora-third-party");
 }
-#endif
 
-gboolean
-enable_repos (GisSoftwarePage *page,
-              gchar **repo_ids,
-              gboolean enable,
-              GCancellable *cancellable)
+static gboolean
+should_show_software_page (void)
 {
-#ifdef ENABLE_SOFTWARE_SOURCES
-  GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
-  guint i;
-
-  /* enable each repo */
-  for (i = 0; repo_ids[i] != NULL; i++)
-    {
-      g_debug ("%s proprietary software source: %s", enable ? "Enable" : "Disable", repo_ids[i]);
-
-      priv->enable_count++;
-      pk_client_repo_enable_async (PK_CLIENT (priv->task),
-                                   repo_ids[i],
-                                   enable,
-                                   cancellable,
-                                   NULL, NULL,
-                                   repo_enabled_cb,
-                                   page);
-    }
-#endif
-
-  return TRUE;
+  g_autofree char *has_fedora_third_party = find_fedora_third_party ();
+  return has_fedora_third_party != NULL;
 }
 
 static gboolean
-gis_software_page_apply (GisPage *gis_page,
+gis_software_page_apply (GisPage      *gis_page,
                          GCancellable *cancellable)
 {
   GisSoftwarePage *page = GIS_SOFTWARE_PAGE (gis_page);
   GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
-  gboolean enable;
-  g_auto(GStrv) repo_ids = NULL;
+  g_autofree char *program = NULL;
+  g_autoptr (GSubprocessLauncher) launcher = NULL;
+  g_autoptr (GSubprocess) subprocess = NULL;
+  g_autoptr (GError) error = NULL;
 
-  enable = gtk_switch_get_active (GTK_SWITCH (priv->proprietary_switch));
+  program = find_fedora_third_party ();
 
-  g_debug ("%s proprietary software repositories", enable ? "Enable" : "Disable");
+  if (program)
+    {
+      const char *arg1;
 
-  g_settings_set_boolean (priv->software_settings, "show-nonfree-software", enable);
-  /* don't prompt for the same thing again in gnome-software */
-  g_settings_set_boolean (priv->software_settings, "show-nonfree-prompt", FALSE);
+      if (gtk_switch_get_state (GTK_SWITCH (priv->proprietary_switch)))
+        arg1 = "enabled";
+      else
+        arg1 = "disabled";
 
-  repo_ids = g_settings_get_strv (priv->software_settings, "nonfree-sources");
-  if (repo_ids == NULL || g_strv_length (repo_ids) == 0)
-    return FALSE;
+      gis_pkexec (program, arg1, "root", &error);
+      if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("%s failed: %s", program, error->message);
+    }
 
-  return enable_repos (page, repo_ids, enable, cancellable);
+  return FALSE;
 }
 
 static void
@@ -235,7 +163,6 @@ gis_software_page_class_init (GisSoftwarePageClass *klass)
   page_class->locale_changed = gis_software_page_locale_changed;
   page_class->apply = gis_software_page_apply;
   object_class->constructed = gis_software_page_constructed;
-  object_class->dispose = gis_software_page_dispose;
 }
 
 static void
@@ -251,21 +178,12 @@ GisPage *
 gis_prepare_software_page (GisDriver *driver)
 {
   GisPage *page = NULL;
-
-#ifdef ENABLE_SOFTWARE_SOURCES
-  GSettingsSchemaSource *source;
-  GSettingsSchema *schema;
-
-  source = g_settings_schema_source_get_default ();
-  schema = g_settings_schema_source_lookup (source, "org.gnome.software", TRUE);
-  if (schema != NULL && g_settings_schema_has_key (schema, "show-nonfree-software"))
-    page = g_object_new (GIS_TYPE_SOFTWARE_PAGE,
-                         "driver", driver,
-                         NULL);
-
-  if (schema != NULL)
-    g_settings_schema_unref (schema);
-#endif
+  if (should_show_software_page ())
+    {
+      page = g_object_new (GIS_TYPE_SOFTWARE_PAGE,
+                           "driver", driver,
+                           NULL);
+    }
 
   return page;
 }
diff --git a/meson.build b/meson.build
index 7ca342c8..6f129697 100644
--- a/meson.build
+++ b/meson.build
@@ -54,12 +54,6 @@ cheese_gtk_dep = dependency ('cheese-gtk',
                          required: get_option('cheese'))
 conf.set('HAVE_CHEESE', cheese_dep.found() and cheese_gtk_dep.found())
 
-# Needed for the 'software' page
-pkgkit_dep = dependency ('packagekit-glib2',
-                         version: '>= 1.1.4',
-                         required: get_option('software-sources'))
-conf.set('ENABLE_SOFTWARE_SOURCES', pkgkit_dep.found())
-
 # Needed for the 'keyboard' page
 ibus_dep = dependency ('ibus-1.0',
                        version: '>= 1.4.99',
diff --git a/meson_options.txt b/meson_options.txt
index ebe92a65..be386b59 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -9,12 +9,6 @@ option('cheese',
        value: 'auto'
 )
 
-option('software-sources',
-       description: 'enable the Software Sources page',
-       type: 'feature',
-       value: 'auto'
-)
-
 option('ibus',
        description: 'enable support for IBus',
        type: 'feature',


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