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




commit d90ca7a2f47e5bd4292181c3cf1b643323038f50
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.

 .../pages/software/gis-software-page.c             | 164 ++++++---------------
 meson.build                                        |   8 +-
 meson_options.txt                                  |   6 -
 3 files changed, 51 insertions(+), 127 deletions(-)
---
diff --git a/gnome-initial-setup/pages/software/gis-software-page.c 
b/gnome-initial-setup/pages/software/gis-software-page.c
index 62fc90dc..7aa00297 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
@@ -31,10 +31,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 +39,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,97 +49,45 @@ 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 *
+third_party_software_program (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);
+  g_autofree char *fedora_third_party = g_build_filename (BINDIR, "fedora-third-party", NULL);
+  if (g_file_test (fedora_third_party, G_FILE_TEST_IS_EXECUTABLE))
+    return g_steal_pointer (&fedora_third_party);
+  return NULL;
 }
 
-#ifdef ENABLE_SOFTWARE_SOURCES
-static void
-repo_enabled_cb (GObject      *source,
-                 GAsyncResult *res,
-                 gpointer      data)
+static char **
+third_party_software_command (GisSoftwarePage *page)
 {
-  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;
+  g_autofree char *program = third_party_software_program ();
+  g_auto (GStrv) command = NULL;
 
-  results = pk_client_generic_finish (PK_CLIENT (source),
-                                      res,
-                                      &error);
-  if (!results)
+  if (program && strstr (program, "fedora-third-party"))
     {
-      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);
+      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);
     }
 
-  priv->enable_count--;
-  if (priv->enable_count == 0)
-    {
-      /* all done */
-      gis_page_apply_complete (GIS_PAGE (page), TRUE);
-    }
-}
-#endif
-
-gboolean
-enable_repos (GisSoftwarePage *page,
-              gchar **repo_ids,
-              gboolean enable,
-              GCancellable *cancellable)
-{
-#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;
+  return NULL;
 }
 
 static gboolean
@@ -157,23 +95,27 @@ 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_auto (GStrv) command = third_party_software_command (page);
+  g_autoptr (GSubprocessLauncher) launcher = NULL;
+  g_autoptr (GSubprocess) subprocess = NULL;
+  g_autoptr (GError) error = NULL;
 
-  g_debug ("%s proprietary software repositories", enable ? "Enable" : "Disable");
-
-  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 +177,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 +192,14 @@ GisPage *
 gis_prepare_software_page (GisDriver *driver)
 {
   GisPage *page = NULL;
+  g_autofree char *program = third_party_software_program ();
 
-#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 (program)
+    {
+      page = g_object_new (GIS_TYPE_SOFTWARE_PAGE,
+                           "driver", driver,
+                           NULL);
+    }
 
   return page;
 }
diff --git a/meson.build b/meson.build
index 7ca342c8..9e3d683c 100644
--- a/meson.build
+++ b/meson.build
@@ -11,6 +11,7 @@ i18n = import('i18n')
 
 prefix = get_option('prefix')
 po_dir = join_paths(meson.source_root(), 'po')
+bin_dir = join_paths(prefix, get_option('bindir'))
 data_dir = join_paths(prefix, get_option('datadir'))
 locale_dir = join_paths(prefix, get_option('localedir'))
 libexec_dir = join_paths(prefix, get_option('libexecdir'))
@@ -22,6 +23,7 @@ pkgsysconf_dir = join_paths(sysconf_dir, meson.project_name())
 conf = configuration_data()
 conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
 conf.set_quoted('GNOMELOCALEDIR', locale_dir)
+conf.set_quoted('BINDIR', bin_dir)
 conf.set_quoted('PKGDATADIR', pkgdata_dir)
 conf.set_quoted('DATADIR', data_dir)
 conf.set_quoted('PKGSYSCONFDIR', pkgsysconf_dir)
@@ -54,12 +56,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]