Blame SOURCES/0002-subman-Add-InstalledProducts-dbus-property-for-g-c-c.patch

6486b0
From f723ed1078e050c4d966d40b2aea74970c74279c Mon Sep 17 00:00:00 2001
6486b0
From: Kalev Lember <klember@redhat.com>
6486b0
Date: Thu, 27 Jun 2019 16:12:00 +0200
6486b0
Subject: [PATCH 02/15] subman: Add InstalledProducts dbus property for g-c-c
6486b0
6486b0
---
6486b0
 plugins/subman/gsd-subscription-manager.c | 135 ++++++++++++++++++++++
6486b0
 1 file changed, 135 insertions(+)
6486b0
6486b0
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
6486b0
index 08b13fa6..a8c18a26 100644
6486b0
--- a/plugins/subman/gsd-subscription-manager.c
6486b0
+++ b/plugins/subman/gsd-subscription-manager.c
6486b0
@@ -1,186 +1,304 @@
6486b0
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
6486b0
  *
6486b0
  * Copyright (C) 2019 Richard Hughes <richard@hughsie.com>
6486b0
+ * Copyright (C) 2019 Kalev Lember <klember@redhat.com>
6486b0
  *
6486b0
  * This program is free software; you can redistribute it and/or modify
6486b0
  * it under the terms of the GNU General Public License as published by
6486b0
  * the Free Software Foundation; either version 2 of the License, or
6486b0
  * (at your option) any later version.
6486b0
  *
6486b0
  * This program is distributed in the hope that it will be useful,
6486b0
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
6486b0
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6486b0
  * GNU General Public License for more details.
6486b0
  *
6486b0
  * You should have received a copy of the GNU General Public License
6486b0
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
6486b0
  *
6486b0
  */
6486b0
 
6486b0
 #include "config.h"
6486b0
 
6486b0
 #include <glib/gi18n.h>
6486b0
 #include <gdk/gdk.h>
6486b0
 #include <gtk/gtk.h>
6486b0
 #include <json-glib/json-glib.h>
6486b0
 #include <libnotify/notify.h>
6486b0
 
6486b0
 #include "gnome-settings-profile.h"
6486b0
 #include "gsd-subman-common.h"
6486b0
 #include "gsd-subscription-manager.h"
6486b0
 
6486b0
 #define GSD_DBUS_NAME "org.gnome.SettingsDaemon"
6486b0
 #define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
6486b0
 #define GSD_DBUS_BASE_INTERFACE "org.gnome.SettingsDaemon"
6486b0
 
6486b0
 #define GSD_SUBSCRIPTION_DBUS_NAME		GSD_DBUS_NAME ".Subscription"
6486b0
 #define GSD_SUBSCRIPTION_DBUS_PATH		GSD_DBUS_PATH "/Subscription"
6486b0
 #define GSD_SUBSCRIPTION_DBUS_INTERFACE		GSD_DBUS_BASE_INTERFACE ".Subscription"
6486b0
 
6486b0
 static const gchar introspection_xml[] =
6486b0
 "<node>"
6486b0
 "  <interface name='org.gnome.SettingsDaemon.Subscription'>"
6486b0
 "    <method name='Register'>"
6486b0
 "      <arg type='a{sv}' name='options' direction='in'/>"
6486b0
 "    </method>"
6486b0
 "    <method name='Unregister'/>"
6486b0
+"    <property name='InstalledProducts' type='aa{sv}' access='read'/>"
6486b0
 "    <property name='SubscriptionStatus' type='u' access='read'/>"
6486b0
 "  </interface>"
6486b0
 "</node>";
6486b0
 
6486b0
 #define GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SUBSCRIPTION_MANAGER, GsdSubscriptionManagerPrivate))
6486b0
 
6486b0
 typedef enum {
6486b0
 	_RHSM_INTERFACE_CONFIG,
6486b0
 	_RHSM_INTERFACE_REGISTER_SERVER,
6486b0
 	_RHSM_INTERFACE_ATTACH,
6486b0
 	_RHSM_INTERFACE_ENTITLEMENT,
6486b0
 	_RHSM_INTERFACE_PRODUCTS,
6486b0
 	_RHSM_INTERFACE_CONSUMER,
6486b0
 	_RHSM_INTERFACE_SYSPURPOSE,
6486b0
 	_RHSM_INTERFACE_LAST
6486b0
 } _RhsmInterface;
6486b0
 
6486b0
 struct GsdSubscriptionManagerPrivate
6486b0
 {
6486b0
 	/* D-Bus */
6486b0
 	guint		 name_id;
6486b0
 	GDBusNodeInfo	*introspection_data;
6486b0
 	GDBusConnection	*connection;
6486b0
 	GCancellable	*bus_cancellable;
6486b0
 
6486b0
 	GDBusProxy	*proxies[_RHSM_INTERFACE_LAST];
6486b0
 	const gchar	*userlang;	/* owned by GLib internally */
6486b0
 	GHashTable	*config; 	/* str:str */
6486b0
+	GPtrArray	*installed_products;
6486b0
 	gchar		*address;
6486b0
 
6486b0
 	GTimer		*timer_last_notified;
6486b0
 	NotifyNotification	*notification_expired;
6486b0
 	NotifyNotification	*notification_registered;
6486b0
 	NotifyNotification	*notification_registration_required;
6486b0
 	GsdSubmanSubscriptionStatus	 subscription_status;
6486b0
 	GsdSubmanSubscriptionStatus	 subscription_status_last;
6486b0
 };
6486b0
 
6486b0
 enum {
6486b0
 	PROP_0,
6486b0
 };
6486b0
 
6486b0
 static void     gsd_subscription_manager_class_init  (GsdSubscriptionManagerClass *klass);
6486b0
 static void     gsd_subscription_manager_init        (GsdSubscriptionManager      *subscription_manager);
6486b0
 static void     gsd_subscription_manager_finalize    (GObject             *object);
6486b0
 
6486b0
 G_DEFINE_TYPE (GsdSubscriptionManager, gsd_subscription_manager, G_TYPE_OBJECT)
6486b0
 
6486b0
+typedef struct
6486b0
+{
6486b0
+	gchar *product_name;
6486b0
+	gchar *product_id;
6486b0
+	gchar *version;
6486b0
+	gchar *arch;
6486b0
+	gchar *status;
6486b0
+	gchar *starts;
6486b0
+	gchar *ends;
6486b0
+} ProductData;
6486b0
+
6486b0
+static void
6486b0
+product_data_free (ProductData *product)
6486b0
+{
6486b0
+	g_free (product->product_name);
6486b0
+	g_free (product->product_id);
6486b0
+	g_free (product->version);
6486b0
+	g_free (product->arch);
6486b0
+	g_free (product->status);
6486b0
+	g_free (product->starts);
6486b0
+	g_free (product->ends);
6486b0
+	g_free (product);
6486b0
+}
6486b0
+
6486b0
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProductData, product_data_free);
6486b0
+
6486b0
 static gpointer manager_object = NULL;
6486b0
 
6486b0
 GQuark
6486b0
 gsd_subscription_manager_error_quark (void)
6486b0
 {
6486b0
 	static GQuark quark = 0;
6486b0
 	if (!quark)
6486b0
 		quark = g_quark_from_static_string ("gsd_subscription_manager_error");
6486b0
 	return quark;
6486b0
 }
6486b0
 
6486b0
 static GsdSubmanSubscriptionStatus
6486b0
 _client_subscription_status_from_text (const gchar *status_txt)
6486b0
 {
6486b0
 	if (g_strcmp0 (status_txt, "Unknown") == 0)
6486b0
 		return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
6486b0
 	if (g_strcmp0 (status_txt, "Current") == 0)
6486b0
 		return GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
6486b0
 	if (g_strcmp0 (status_txt, "Invalid") == 0)
6486b0
 		return GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
6486b0
 	if (g_strcmp0 (status_txt, "Disabled") == 0)
6486b0
 		return GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
6486b0
 	if (g_strcmp0 (status_txt, "Insufficient") == 0)
6486b0
 		return GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
6486b0
 	g_warning ("Unknown subscription status: %s", status_txt); // 'Current'?
6486b0
 	return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
6486b0
 }
6486b0
 
6486b0
+static GVariant *
6486b0
+_make_installed_products_variant (GPtrArray *installed_products)
6486b0
+{
6486b0
+	GVariantBuilder builder;
6486b0
+	g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
6486b0
+
6486b0
+	for (guint i = 0; i < installed_products->len; i++) {
6486b0
+		ProductData *product = g_ptr_array_index (installed_products, i);
6486b0
+		g_auto(GVariantDict) dict;
6486b0
+
6486b0
+		g_variant_dict_init (&dict, NULL);
6486b0
+
6486b0
+		g_variant_dict_insert (&dict, "product-name", "s", product->product_name);
6486b0
+		g_variant_dict_insert (&dict, "product-id", "s", product->product_id);
6486b0
+		g_variant_dict_insert (&dict, "version", "s", product->version);
6486b0
+		g_variant_dict_insert (&dict, "arch", "s", product->arch);
6486b0
+		g_variant_dict_insert (&dict, "status", "s", product->status);
6486b0
+		g_variant_dict_insert (&dict, "starts", "s", product->starts);
6486b0
+		g_variant_dict_insert (&dict, "ends", "s", product->ends);
6486b0
+
6486b0
+		g_variant_builder_add_value (&builder, g_variant_dict_end (&dict));
6486b0
+	}
6486b0
+
6486b0
+	return g_variant_builder_end (&builder);
6486b0
+}
6486b0
+
6486b0
 static void
6486b0
 _emit_property_changed (GsdSubscriptionManager *manager,
6486b0
 		        const gchar *property_name,
6486b0
 		        GVariant *property_value)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	GVariantBuilder builder;
6486b0
 	GVariantBuilder invalidated_builder;
6486b0
 
6486b0
 	/* not yet connected */
6486b0
 	if (priv->connection == NULL)
6486b0
 		return;
6486b0
 
6486b0
 	/* build the dict */
6486b0
 	g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
6486b0
 	g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
6486b0
 	g_variant_builder_add (&builder,
6486b0
 			       "{sv}",
6486b0
 			       property_name,
6486b0
 			       property_value);
6486b0
 	g_dbus_connection_emit_signal (priv->connection,
6486b0
 				       NULL,
6486b0
 				       GSD_SUBSCRIPTION_DBUS_PATH,
6486b0
 				       "org.freedesktop.DBus.Properties",
6486b0
 				       "PropertiesChanged",
6486b0
 				       g_variant_new ("(sa{sv}as)",
6486b0
 				       GSD_SUBSCRIPTION_DBUS_INTERFACE,
6486b0
 				       &builder,
6486b0
 				       &invalidated_builder),
6486b0
 				       NULL);
6486b0
 	g_variant_builder_clear (&builder);
6486b0
 	g_variant_builder_clear (&invalidated_builder);
6486b0
 }
6486b0
 
6486b0
+static gboolean
6486b0
+_client_installed_products_update (GsdSubscriptionManager *manager, GError **error)
6486b0
+{
6486b0
+	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
+	JsonNode *json_root;
6486b0
+	JsonArray *json_products_array;
6486b0
+	const gchar *json_txt = NULL;
6486b0
+	g_autoptr(GVariant) val = NULL;
6486b0
+	g_autoptr(JsonParser) json_parser = json_parser_new ();
6486b0
+
6486b0
+	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_PRODUCTS],
6486b0
+				      "ListInstalledProducts",
6486b0
+				      g_variant_new ("(sa{sv}s)",
6486b0
+						     ""   /* filter_string */,
6486b0
+						     NULL /* proxy_options */,
6486b0
+						     priv->userlang),
6486b0
+				      G_DBUS_CALL_FLAGS_NONE,
6486b0
+				      -1, NULL, error);
6486b0
+	if (val == NULL)
6486b0
+		return FALSE;
6486b0
+	g_variant_get (val, "(&s)", &json_txt);
6486b0
+	g_debug ("Products.ListInstalledProducts JSON: %s", json_txt);
6486b0
+	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
6486b0
+		return FALSE;
6486b0
+	json_root = json_parser_get_root (json_parser);
6486b0
+	json_products_array = json_node_get_array (json_root);
6486b0
+	if (json_products_array == NULL) {
6486b0
+		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
6486b0
+			     "no InstalledProducts array in %s", json_txt);
6486b0
+		return FALSE;
6486b0
+	}
6486b0
+
6486b0
+	g_ptr_array_set_size (priv->installed_products, 0);
6486b0
+
6486b0
+	for (guint i = 0; i < json_array_get_length (json_products_array); i++) {
6486b0
+		JsonArray *json_product = json_array_get_array_element (json_products_array, i);
6486b0
+		g_autoptr(ProductData) product = g_new0 (ProductData, 1);
6486b0
+
6486b0
+		if (json_product == NULL)
6486b0
+			continue;
6486b0
+		if (json_array_get_length (json_product) < 8) {
6486b0
+			g_debug ("Unexpected number of array elements in InstalledProducts JSON");
6486b0
+			continue;
6486b0
+		}
6486b0
+
6486b0
+		product->product_name = g_strdup (json_array_get_string_element (json_product, 0));
6486b0
+		product->product_id = g_strdup (json_array_get_string_element (json_product, 1));
6486b0
+		product->version = g_strdup (json_array_get_string_element (json_product, 2));
6486b0
+		product->arch = g_strdup (json_array_get_string_element (json_product, 3));
6486b0
+		product->status = g_strdup (json_array_get_string_element (json_product, 4));
6486b0
+		product->starts = g_strdup (json_array_get_string_element (json_product, 6));
6486b0
+		product->ends = g_strdup (json_array_get_string_element (json_product, 7));
6486b0
+
6486b0
+		g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
6486b0
+	}
6486b0
+
6486b0
+	/* emit notification for g-c-c */
6486b0
+	_emit_property_changed (manager, "InstalledProducts",
6486b0
+			       _make_installed_products_variant (priv->installed_products));
6486b0
+
6486b0
+	return TRUE;
6486b0
+}
6486b0
+
6486b0
 static gboolean
6486b0
 _client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	JsonNode *json_root;
6486b0
 	JsonObject *json_obj;
6486b0
 	const gchar *json_txt = NULL;
6486b0
 	const gchar *status_txt = NULL;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
6486b0
 
6486b0
 	/* save old value */
6486b0
 	priv->subscription_status_last = priv->subscription_status;
6486b0
 
6486b0
 	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
6486b0
 				      "GetStatus",
6486b0
 				      g_variant_new ("(ss)",
6486b0
 						     "", /* assumed as 'now' */
6486b0
 						     priv->userlang),
6486b0
 				      G_DBUS_CALL_FLAGS_NONE,
6486b0
 				      -1, NULL, error);
6486b0
 	if (val == NULL)
6486b0
 		return FALSE;
6486b0
 	g_variant_get (val, "(&s)", &json_txt);
6486b0
 	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
6486b0
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
6486b0
 		return FALSE;
6486b0
 	json_root = json_parser_get_root (json_parser);
6486b0
 	json_obj = json_node_get_object (json_root);
6486b0
 	if (!json_object_has_member (json_obj, "status")) {
6486b0
@@ -423,185 +541,195 @@ _client_register_with_keys (GsdSubscriptionManager *manager,
6486b0
 				  GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
6486b0
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
 				       "--kind", "register-with-key",
6486b0
 				       "--address", priv->address,
6486b0
 				       "--hostname", hostname,
6486b0
 				       "--organisation", organisation,
6486b0
 				       "--activation-key", activation_key,
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	if (!_client_subprocess_wait_check (subprocess, error))
6486b0
 		return FALSE;
6486b0
 
6486b0
 	/* FIXME: also do on error? */
6486b0
 	if (!_client_register_stop (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
+	if (!_client_installed_products_update (manager, error))
6486b0
+		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 
6486b0
 	/* success */
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_register (GsdSubscriptionManager *manager,
6486b0
 			 const gchar *hostname,
6486b0
 			 const gchar *organisation,
6486b0
 			 const gchar *username,
6486b0
 			 const gchar *password,
6486b0
 			 GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 
6486b0
 	/* fallback */
6486b0
 	if (organisation == NULL)
6486b0
 		organisation = "";
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
6486b0
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
 				       "--kind", "register-with-username",
6486b0
 				       "--address", priv->address,
6486b0
 				       "--hostname", hostname,
6486b0
 				       "--organisation", organisation,
6486b0
 				       "--username", username,
6486b0
 				       "--password", password,
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	if (!_client_subprocess_wait_check (subprocess, error))
6486b0
 		return FALSE;
6486b0
 
6486b0
 	/* FIXME: also do on error? */
6486b0
 	if (!_client_register_stop (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
+	if (!_client_installed_products_update (manager, error))
6486b0
+		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_unregister (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
6486b0
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
 				       "--kind", "unregister",
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	if (!_client_subprocess_wait_check (subprocess, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
+	if (!_client_installed_products_update (manager, error))
6486b0
+		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_update_config (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 	g_autoptr(GVariant) val_server = NULL;
6486b0
 	g_autoptr(GVariantDict) dict = NULL;
6486b0
 	GVariantIter iter;
6486b0
 	gchar *key;
6486b0
 	gchar *value;
6486b0
 
6486b0
 	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONFIG],
6486b0
 				      "GetAll",
6486b0
 				      g_variant_new ("(s)", priv->userlang),
6486b0
 				      G_DBUS_CALL_FLAGS_NONE,
6486b0
 				      -1, NULL, error);
6486b0
 	if (val == NULL)
6486b0
 		return FALSE;
6486b0
 	dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
6486b0
 	val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
6486b0
 	if (val_server != NULL) {
6486b0
 		g_variant_iter_init (&iter, val_server);
6486b0
 		while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
6486b0
 			g_debug ("%s=%s", key, value);
6486b0
 			g_hash_table_insert (priv->config,
6486b0
 					     g_steal_pointer (&key),
6486b0
 					     g_steal_pointer (&value));
6486b0
 		}
6486b0
 	}
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _subman_proxy_signal_cb (GDBusProxy *proxy,
6486b0
 			 const gchar *sender_name,
6486b0
 			 const gchar *signal_name,
6486b0
 			 GVariant *parameters,
6486b0
 			 GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_autoptr(GError) error = NULL;
6486b0
 	if (!_client_syspurpose_update (manager, &error)) {
6486b0
 		g_warning ("failed to update syspurpose: %s", error->message);
6486b0
 		g_clear_error (&error);
6486b0
 	}
6486b0
 	if (!_client_subscription_status_update (manager, &error)) {
6486b0
 		g_warning ("failed to update subscription status: %s", error->message);
6486b0
 		g_clear_error (&error);
6486b0
 	}
6486b0
+	if (!_client_installed_products_update (manager, &error)) {
6486b0
+		g_warning ("failed to update installed products: %s", error->message);
6486b0
+		g_clear_error (&error);
6486b0
+	}
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _client_unload (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++)
6486b0
 		g_clear_object (&priv->proxies[i]);
6486b0
 	g_hash_table_unref (priv->config);
6486b0
 }
6486b0
 
6486b0
 static const gchar *
6486b0
 _rhsm_interface_to_string (_RhsmInterface kind)
6486b0
 {
6486b0
 	if (kind == _RHSM_INTERFACE_CONFIG)
6486b0
 		return "Config";
6486b0
 	if (kind == _RHSM_INTERFACE_REGISTER_SERVER)
6486b0
 		return "RegisterServer";
6486b0
 	if (kind == _RHSM_INTERFACE_ATTACH)
6486b0
 		return "Attach";
6486b0
 	if (kind == _RHSM_INTERFACE_ENTITLEMENT)
6486b0
 		return "Entitlement";
6486b0
 	if (kind == _RHSM_INTERFACE_PRODUCTS)
6486b0
 		return "Products";
6486b0
 	if (kind == _RHSM_INTERFACE_CONSUMER)
6486b0
 		return "Consumer";
6486b0
 	if (kind == _RHSM_INTERFACE_SYSPURPOSE)
6486b0
 		return "Syspurpose";
6486b0
 	return NULL;
6486b0
@@ -613,60 +741,62 @@ _client_load (GsdSubscriptionManager *manager, GError **error)
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 
6486b0
 	priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
6486b0
 
6486b0
 	/* connect to all the interfaces on the *different* objects :| */
6486b0
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++) {
6486b0
 		const gchar *kind = _rhsm_interface_to_string (i);
6486b0
 		g_autofree gchar *opath = g_strdup_printf ("/com/redhat/RHSM1/%s", kind);
6486b0
 		g_autofree gchar *iface = g_strdup_printf ("com.redhat.RHSM1.%s", kind);
6486b0
 		priv->proxies[i] =
6486b0
 			g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
6486b0
 						       G_DBUS_PROXY_FLAGS_NONE,
6486b0
 						       NULL,
6486b0
 						       "com.redhat.RHSM1",
6486b0
 						       opath, iface,
6486b0
 						       NULL,
6486b0
 						       error);
6486b0
 		if (priv->proxies[i] == NULL)
6486b0
 			return FALSE;
6486b0
 		/* we want to get notified if the status of the system changes */
6486b0
 		g_signal_connect (priv->proxies[i], "g-signal",
6486b0
 				  G_CALLBACK (_subman_proxy_signal_cb), manager);
6486b0
 	}
6486b0
 
6486b0
 	/* get initial status */
6486b0
 	priv->userlang = "";
6486b0
 	if (!_client_update_config (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
+	if (!_client_installed_products_update (manager, error))
6486b0
+		return FALSE;
6486b0
 	if (!_client_syspurpose_update (manager, error))
6486b0
 		return FALSE;
6486b0
 
6486b0
 	/* success */
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 gboolean
6486b0
 gsd_subscription_manager_start (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	gboolean ret;
6486b0
 	g_debug ("Starting subscription manager");
6486b0
 	gnome_settings_profile_start (NULL);
6486b0
 	ret = _client_load (manager, error);
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	gnome_settings_profile_end (NULL);
6486b0
 	return ret;
6486b0
 }
6486b0
 
6486b0
 void
6486b0
 gsd_subscription_manager_stop (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_debug ("Stopping subscription manager");
6486b0
 	_client_unload (manager);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass)
6486b0
 {
6486b0
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
6486b0
@@ -676,60 +806,61 @@ gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass)
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _launch_info_overview (void)
6486b0
 {
6486b0
 	const gchar *argv[] = { "gnome-control-center", "info-overview", NULL };
6486b0
 	g_debug ("Running gnome-control-center info-overview");
6486b0
 	g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH,
6486b0
 		       NULL, NULL, NULL, NULL);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _notify_closed_cb (NotifyNotification *notification, gpointer user_data)
6486b0
 {
6486b0
 	/* FIXME: only launch when clicking on the main body, not the window close */
6486b0
 	if (notify_notification_get_closed_reason (notification) == 0x400)
6486b0
 		_launch_info_overview ();
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _notify_clicked_cb (NotifyNotification *notification, char *action, gpointer user_data)
6486b0
 {
6486b0
 	_launch_info_overview ();
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 gsd_subscription_manager_init (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv = GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE (manager);
6486b0
 
6486b0
+	priv->installed_products = g_ptr_array_new_with_free_func ((GDestroyNotify) product_data_free);
6486b0
 	priv->timer_last_notified = g_timer_new ();
6486b0
 
6486b0
 	/* expired */
6486b0
 	priv->notification_expired =
6486b0
 		notify_notification_new (_("Subscription Has Expired"),
6486b0
 					 _("Add or renew a subscription to continue receiving software updates."),
6486b0
 					 NULL);
6486b0
 	notify_notification_set_app_name (priv->notification_expired, _("Subscription"));
6486b0
 	notify_notification_set_hint_string (priv->notification_expired, "desktop-entry", "subman-panel");
6486b0
 	notify_notification_set_hint_string (priv->notification_expired, "x-gnome-privacy-scope", "system");
6486b0
 	notify_notification_set_urgency (priv->notification_expired, NOTIFY_URGENCY_CRITICAL);
6486b0
 	notify_notification_add_action (priv->notification_expired,
6486b0
 					"info-overview", _("Subscribe System…"),
6486b0
 					_notify_clicked_cb,
6486b0
 					manager, NULL);
6486b0
 	g_signal_connect (priv->notification_expired, "closed",
6486b0
 			  G_CALLBACK (_notify_closed_cb), manager);
6486b0
 
6486b0
 	/* registered */
6486b0
 	priv->notification_registered =
6486b0
 		notify_notification_new (_("Registration Successful"),
6486b0
 					 _("The system has been registered and software updates have been enabled."),
6486b0
 					 NULL);
6486b0
 	notify_notification_set_app_name (priv->notification_registered, _("Subscription"));
6486b0
 	notify_notification_set_hint_string (priv->notification_registered, "desktop-entry", "subman-panel");
6486b0
 	notify_notification_set_hint_string (priv->notification_registered, "x-gnome-privacy-scope", "system");
6486b0
 	notify_notification_set_urgency (priv->notification_registered, NOTIFY_URGENCY_CRITICAL);
6486b0
 	g_signal_connect (priv->notification_registered, "closed",
6486b0
 			  G_CALLBACK (_notify_closed_cb), manager);
6486b0
 
6486b0
@@ -740,60 +871,61 @@ gsd_subscription_manager_init (GsdSubscriptionManager *manager)
6486b0
 					 NULL);
6486b0
 	notify_notification_set_app_name (priv->notification_registration_required, _("Subscription"));
6486b0
 	notify_notification_set_hint_string (priv->notification_registration_required, "desktop-entry", "subman-panel");
6486b0
 	notify_notification_set_hint_string (priv->notification_registration_required, "x-gnome-privacy-scope", "system");
6486b0
 	notify_notification_set_urgency (priv->notification_registration_required, NOTIFY_URGENCY_CRITICAL);
6486b0
 	notify_notification_add_action (priv->notification_registration_required,
6486b0
 					"info-overview", _("Register System…"),
6486b0
 					_notify_clicked_cb,
6486b0
 					manager, NULL);
6486b0
 	g_signal_connect (priv->notification_registration_required, "closed",
6486b0
 			  G_CALLBACK (_notify_closed_cb), manager);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 gsd_subscription_manager_finalize (GObject *object)
6486b0
 {
6486b0
 	GsdSubscriptionManager *manager;
6486b0
 
6486b0
 	g_return_if_fail (object != NULL);
6486b0
 	g_return_if_fail (GSD_IS_SUBSCRIPTION_MANAGER (object));
6486b0
 
6486b0
 	manager = GSD_SUBSCRIPTION_MANAGER (object);
6486b0
 
6486b0
 	gsd_subscription_manager_stop (manager);
6486b0
 
6486b0
 	if (manager->priv->bus_cancellable != NULL) {
6486b0
 		g_cancellable_cancel (manager->priv->bus_cancellable);
6486b0
 		g_clear_object (&manager->priv->bus_cancellable);
6486b0
 	}
6486b0
 
6486b0
+	g_clear_pointer (&manager->priv->installed_products, g_ptr_array_unref);
6486b0
 	g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref);
6486b0
 	g_clear_object (&manager->priv->connection);
6486b0
 	g_clear_object (&manager->priv->notification_expired);
6486b0
 	g_clear_object (&manager->priv->notification_registered);
6486b0
 	g_timer_destroy (manager->priv->timer_last_notified);
6486b0
 
6486b0
 	if (manager->priv->name_id != 0) {
6486b0
 		g_bus_unown_name (manager->priv->name_id);
6486b0
 		manager->priv->name_id = 0;
6486b0
 	}
6486b0
 
6486b0
 	G_OBJECT_CLASS (gsd_subscription_manager_parent_class)->finalize (object);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 handle_method_call (GDBusConnection       *connection,
6486b0
 		    const gchar           *sender,
6486b0
 		    const gchar           *object_path,
6486b0
 		    const gchar           *interface_name,
6486b0
 		    const gchar           *method_name,
6486b0
 		    GVariant              *parameters,
6486b0
 		    GDBusMethodInvocation *invocation,
6486b0
 		    gpointer               user_data)
6486b0
 {
6486b0
 	GsdSubscriptionManager *manager = GSD_SUBSCRIPTION_MANAGER (user_data);
6486b0
 	g_autoptr(GError) error = NULL;
6486b0
 
6486b0
 	if (g_strcmp0 (method_name, "Register") == 0) {
6486b0
 		const gchar *organisation = NULL;
6486b0
 		const gchar *hostname = NULL;
6486b0
@@ -857,60 +989,63 @@ handle_method_call (GDBusConnection       *connection,
6486b0
 		if (!_client_unregister (manager, &error)) {
6486b0
 			g_dbus_method_invocation_return_gerror (invocation, error);
6486b0
 			return;
6486b0
 		}
6486b0
 		g_dbus_method_invocation_return_value (invocation, NULL);
6486b0
 	} else {
6486b0
 		g_assert_not_reached ();
6486b0
 	}
6486b0
 }
6486b0
 
6486b0
 static GVariant *
6486b0
 handle_get_property (GDBusConnection *connection,
6486b0
 		     const gchar *sender,
6486b0
 		     const gchar *object_path,
6486b0
 		     const gchar *interface_name,
6486b0
 		     const gchar *property_name,
6486b0
 		     GError **error, gpointer user_data)
6486b0
 {
6486b0
 	GsdSubscriptionManager *manager = GSD_SUBSCRIPTION_MANAGER (user_data);
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 
6486b0
 	if (g_strcmp0 (interface_name, GSD_SUBSCRIPTION_DBUS_INTERFACE) != 0) {
6486b0
 		g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 			     "No such interface: %s", interface_name);
6486b0
 		return NULL;
6486b0
 	}
6486b0
 
6486b0
 	if (g_strcmp0 (property_name, "SubscriptionStatus") == 0)
6486b0
 		return g_variant_new_uint32 (priv->subscription_status);
6486b0
 
6486b0
+	if (g_strcmp0 (property_name, "InstalledProducts") == 0)
6486b0
+		return _make_installed_products_variant (priv->installed_products);
6486b0
+
6486b0
 	g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 		     "Failed to get property: %s", property_name);
6486b0
 	return NULL;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 handle_set_property (GDBusConnection *connection,
6486b0
 		     const gchar *sender,
6486b0
 		     const gchar *object_path,
6486b0
 		     const gchar *interface_name,
6486b0
 		     const gchar *property_name,
6486b0
 		     GVariant *value,
6486b0
 		     GError **error, gpointer user_data)
6486b0
 {
6486b0
 	if (g_strcmp0 (interface_name, GSD_SUBSCRIPTION_DBUS_INTERFACE) != 0) {
6486b0
 		g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 			     "No such interface: %s", interface_name);
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 		     "No such property: %s", property_name);
6486b0
 	return FALSE;
6486b0
 }
6486b0
 
6486b0
 static const GDBusInterfaceVTable interface_vtable =
6486b0
 {
6486b0
 	handle_method_call,
6486b0
 	handle_get_property,
6486b0
 	handle_set_property
6486b0
 };
6486b0
-- 
6486b0
2.30.0
6486b0