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




commit 9281e29986066ba52c6b8d9b78d97057f80f106e
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.

 gnome-initial-setup/meson.build                    |   1 -
 .../pages/software/gis-software-page.c             | 166 +++++++--------------
 meson.build                                        |   6 -
 meson_options.txt                                  |   6 -
 4 files changed, 52 insertions(+), 127 deletions(-)
---
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index a23b160c..75c44831 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -52,7 +52,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..55a7a133 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,78 @@ 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)
+/* 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 (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);
+  return g_find_program_in_path ("fedora-third-party");
 }
 
-#ifdef ENABLE_SOFTWARE_SOURCES
-static void
-repo_enabled_cb (GObject      *source,
-                 GAsyncResult *res,
-                 gpointer      data)
+static gboolean
+should_show_software_page (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);
-    }
+  g_autofree char *has_fedora_third_party = find_fedora_third_party ();
+  return has_fedora_third_party != NULL;
 }
-#endif
 
-gboolean
-enable_repos (GisSoftwarePage *page,
-              gchar **repo_ids,
-              gboolean enable,
-              GCancellable *cancellable)
+static char **
+third_party_software_command (GisSoftwarePage *page)
 {
-#ifdef ENABLE_SOFTWARE_SOURCES
   GisSoftwarePagePrivate *priv = gis_software_page_get_instance_private (page);
-  guint i;
+  g_autofree char *program = NULL;
+  g_auto (GStrv) command = NULL;
 
-  /* enable each repo */
-  for (i = 0; repo_ids[i] != NULL; i++)
+  program = find_fedora_third_party ();
+  if (program)
     {
-      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);
+      command = g_new0 (char *, 3);
+      command[0] = g_strdup (program);
+      if (gtk_switch_get_state (GTK_SWITCH (priv->proprietary_switch)))
+        command[1] = g_strdup ("enabled");
+      else
+        command[1] = g_strdup ("disabled");
+      return g_steal_pointer (&command);
     }
-#endif
 
-  return TRUE;
+  return 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;
-
-  enable = gtk_switch_get_active (GTK_SWITCH (priv->proprietary_switch));
-
-  g_debug ("%s proprietary software repositories", enable ? "Enable" : "Disable");
+  g_auto (GStrv) command = third_party_software_command (page);
+  g_autoptr (GSubprocessLauncher) launcher = NULL;
+  g_autoptr (GSubprocess) subprocess = NULL;
+  g_autoptr (GError) error = NULL;
 
-  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);
-
-  repo_ids = g_settings_get_strv (priv->software_settings, "nonfree-sources");
-  if (repo_ids == NULL || g_strv_length (repo_ids) == 0)
-    return FALSE;
+  if (command)
+    {
+      launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
+      subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *)command, &error);
+      if (error)
+        {
+          g_warning ("Failed to spawn %s: %s", command[0], error->message);
+          return FALSE;
+        }
+
+      if (!g_subprocess_wait_check (subprocess, cancellable, &error) &&
+          !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("%s failed: %s", command[0], error->message);
+    }
 
-  return enable_repos (page, repo_ids, enable, cancellable);
+  return FALSE;
 }
 
 static void
@@ -235,7 +183,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 +198,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]