[gnome-color-manager] Do the request to PackageKit async, to avoid a 200ms lag in the GUI at startup



commit 7b4a619f64ac946b6a7cd8fc22f3900d0489fbea
Author: Richard Hughes <richard hughsie com>
Date:   Sat Oct 9 22:30:12 2010 +0100

    Do the request to PackageKit async, to avoid a 200ms lag in the GUI at startup

 src/cc-color-panel.c |   84 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gcm-utils.c      |   56 ---------------------------------
 src/gcm-utils.h      |    1 -
 3 files changed, 82 insertions(+), 59 deletions(-)
---
diff --git a/src/cc-color-panel.c b/src/cc-color-panel.c
index 261170a..0b05bc4 100644
--- a/src/cc-color-panel.c
+++ b/src/cc-color-panel.c
@@ -73,6 +73,10 @@ static void cc_color_panel_finalize (GObject *object);
 
 #define CC_COLOR_PREFS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_COLOR_PANEL, CcColorPanelPrivate))
 
+#define PK_DBUS_SERVICE					"org.freedesktop.PackageKit"
+#define PK_DBUS_PATH					"/org/freedesktop/PackageKit"
+#define PK_DBUS_INTERFACE_QUERY				"org.freedesktop.PackageKit.Query"
+
 enum {
 	GCM_DEVICES_COLUMN_ID,
 	GCM_DEVICES_COLUMN_SORT,
@@ -2313,6 +2317,83 @@ cc_color_panel_setup_rendering_combobox (GtkWidget *widget, GcmIntent intent)
 }
 
 /**
+ * cc_color_panel_is_color_profiles_extra_installed_ready_cb:
+ **/
+static void
+cc_color_panel_is_color_profiles_extra_installed_ready_cb (GObject *source_object,
+							   GAsyncResult *res,
+							   gpointer user_data)
+{
+	GVariant *response = NULL;
+	GError *error = NULL;
+	gboolean installed = TRUE;
+	CcColorPanel *panel = CC_COLOR_PANEL (user_data);
+
+	/* get details */
+	response = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error);
+	if (response == NULL) {
+		/* TRANSLATORS: the DBus method failed */
+		egg_warning ("%s %s\n", _("The request failed:"), error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* get value */
+	g_variant_get (response, "(b)", &installed);
+
+	/* show control */
+	gtk_widget_set_visible (panel->priv->info_bar_profiles, !installed);
+out:
+	if (response != NULL)
+		g_variant_unref (response);
+}
+
+/**
+ * cc_color_panel_is_color_profiles_extra_installed:
+ **/
+static void
+cc_color_panel_is_color_profiles_extra_installed (CcColorPanel *panel)
+{
+	GDBusConnection *connection;
+	GVariant *args = NULL;
+	GError *error = NULL;
+
+#ifndef HAVE_PACKAGEKIT
+	egg_warning ("cannot query %s: this package was not compiled with --enable-packagekit", package_name);
+	return;
+#endif
+
+	/* get a session bus connection */
+	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+	if (connection == NULL) {
+		/* TRANSLATORS: no DBus session bus */
+		g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* execute sync method */
+	args = g_variant_new ("(ss)",
+			      GCM_PREFS_PACKAGE_NAME_COLOR_PROFILES_EXTRA,
+			      "timeout=5");
+	g_dbus_connection_call (connection,
+				PK_DBUS_SERVICE,
+				PK_DBUS_PATH,
+				PK_DBUS_INTERFACE_QUERY,
+				"IsInstalled",
+				args,
+				G_VARIANT_TYPE ("(b)"),
+				G_DBUS_CALL_FLAGS_NONE,
+				G_MAXINT, NULL,
+				cc_color_panel_is_color_profiles_extra_installed_ready_cb,
+				panel);
+out:
+	if (args != NULL)
+		g_variant_unref (args);
+	return;
+}
+
+/**
  * cc_color_panel_startup_idle_cb:
  **/
 static gboolean
@@ -2397,8 +2478,7 @@ cc_color_panel_startup_idle_cb (CcColorPanel *panel)
 
 	/* do we show the shared-color-profiles-extra installer? */
 	egg_debug ("getting installed");
-	ret = gcm_utils_is_package_installed (GCM_PREFS_PACKAGE_NAME_COLOR_PROFILES_EXTRA);
-	gtk_widget_set_visible (panel->priv->info_bar_profiles, !ret);
+	cc_color_panel_is_color_profiles_extra_installed (panel);
 out:
 	g_free (colorspace_rgb);
 	g_free (colorspace_cmyk);
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 314fd08..1e6398d 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -210,62 +210,6 @@ out:
 }
 
 /**
- * gcm_utils_is_package_installed:
- **/
-gboolean
-gcm_utils_is_package_installed (const gchar *package_name)
-{
-	GDBusConnection *connection;
-	GVariant *args = NULL;
-	GVariant *response = NULL;
-	GError *error = NULL;
-	gboolean installed = TRUE;
-
-	g_return_val_if_fail (package_name != NULL, FALSE);
-
-#ifndef HAVE_PACKAGEKIT
-	egg_warning ("cannot query %s: this package was not compiled with --enable-packagekit", package_name);
-	return TRUE;
-#endif
-
-	/* get a session bus connection */
-	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-	if (connection == NULL) {
-		/* TRANSLATORS: no DBus session bus */
-		g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* execute sync method */
-	args = g_variant_new ("(ss)", package_name, "timeout=5");
-	response = g_dbus_connection_call_sync (connection,
-						PK_DBUS_SERVICE,
-						PK_DBUS_PATH,
-						PK_DBUS_INTERFACE_QUERY,
-						"IsInstalled",
-						args,
-						G_VARIANT_TYPE ("(b)"),
-						G_DBUS_CALL_FLAGS_NONE,
-						G_MAXINT, NULL, &error);
-	if (response == NULL) {
-		/* TRANSLATORS: the DBus method failed */
-		egg_warning ("%s %s\n", _("The request failed:"), error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* get value */
-	g_variant_get (response, "(b)", &installed);
-out:
-	if (args != NULL)
-		g_variant_unref (args);
-	if (response != NULL)
-		g_variant_unref (response);
-	return installed;
-}
-
-/**
  * gcm_utils_output_is_lcd_internal:
  * @output_name: the output name
  *
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 9eac806..95139fe 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -98,7 +98,6 @@ gchar		*gcm_utils_get_default_config_location	(void);
 GcmProfileKind	 gcm_utils_device_kind_to_profile_kind	(GcmDeviceKind		 kind);
 gboolean	 gcm_utils_install_package		(const gchar		*package_name,
 							 GtkWindow		*window);
-gboolean	 gcm_utils_is_package_installed		(const gchar		*package_name);
 gboolean	 gcm_utils_is_icc_profile		(GFile			*file);
 gchar		*gcm_utils_linkify			(const gchar		*text);
 const gchar	*gcm_intent_to_localized_text		(GcmIntent	 intent);



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