[gnome-packagekit/glib2: 14/79] moo



commit 2fb2e82a8cdd80eafe894a3b57af7e7480a94eae
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 15 15:34:32 2009 +0100

    moo

 src/gpk-auto-refresh.c |  177 ++++++++++++++++++++++++++++++------------------
 src/gpk-firmware.c     |   48 +++-----------
 src/gpk-prefs.c        |   10 ++-
 3 files changed, 127 insertions(+), 108 deletions(-)
---
diff --git a/src/gpk-auto-refresh.c b/src/gpk-auto-refresh.c
index 443717e..b935041 100644
--- a/src/gpk-auto-refresh.c
+++ b/src/gpk-auto-refresh.c
@@ -171,142 +171,187 @@ gpk_auto_refresh_get_frequency_prefs (GpkAutoRefresh *arefresh, const gchar *key
 }
 
 /**
+ * gpk_auto_refresh_get_time_refresh_cache_cb:
+ **/
+static void
+gpk_auto_refresh_get_time_refresh_cache_cb (GObject *object, GAsyncResult *res, GpkAutoRefresh *arefresh)
+{
+	PkControl *control = PK_CONTROL (object);
+	GError *error = NULL;
+	guint seconds;
+	guint thresh;
+
+	/* get the result */
+	seconds = pk_control_get_time_since_action_finish (control, res, &error);
+	if (seconds == 0) {
+		egg_warning ("failed to get time: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+
+	/* have we passed the timout? */
+	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPDATES);
+	if (seconds < thresh) {
+		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds);
+		return;
+	}
+
+	/* send signal */
+	gpk_auto_refresh_signal_refresh_cache (arefresh);
+}
+
+/**
  * gpk_auto_refresh_maybe_refresh_cache:
  **/
-static gboolean
+static void
 gpk_auto_refresh_maybe_refresh_cache (GpkAutoRefresh *arefresh)
 {
-	guint time_s;
 	guint thresh;
-	gboolean ret;
 
-	g_return_val_if_fail (GPK_IS_AUTO_REFRESH (arefresh), FALSE);
+	g_return_if_fail (GPK_IS_AUTO_REFRESH (arefresh));
 
 	/* if we don't want to auto check for updates, don't do this either */
 	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPDATES);
 	if (thresh == 0) {
-		egg_debug ("not when policy is to never refresh");
-		return FALSE;
+		egg_debug ("not when policy is to never get updates");
+		return;
 	}
 
 	/* not on battery */
 	if (arefresh->priv->on_battery) {
 		egg_debug ("not when on battery");
-		return FALSE;
+		return;
 	}
 
 	/* only do the refresh cache when the user is idle */
 	if (!arefresh->priv->session_idle) {
 		egg_debug ("not when session active");
-		return FALSE;
+		return;
 	}
 
 	/* get this each time, as it may have changed behind out back */
 	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_REFRESH_CACHE);
 	if (thresh == 0) {
 		egg_debug ("not when policy is to never refresh");
-		return FALSE;
+		return;
 	}
 
 	/* get the time since the last refresh */
-	ret = pk_control_get_time_since_action (arefresh->priv->control,
-						PK_ROLE_ENUM_REFRESH_CACHE, &time_s, NULL);
-	if (!ret) {
-		egg_warning ("failed to get last time");
-		return FALSE;
+	pk_control_get_time_since_action_async (arefresh->priv->control, PK_ROLE_ENUM_REFRESH_CACHE, NULL,
+						(GAsyncReadyCallback) gpk_auto_refresh_get_time_refresh_cache_cb, arefresh);
+}
+
+/**
+ * gpk_auto_refresh_get_time_get_updates_cb:
+ **/
+static void
+gpk_auto_refresh_get_time_get_updates_cb (GObject *object, GAsyncResult *res, GpkAutoRefresh *arefresh)
+{
+	PkControl *control = PK_CONTROL (object);
+	GError *error = NULL;
+	guint seconds;
+	guint thresh;
+
+	/* get the result */
+	seconds = pk_control_get_time_since_action_finish (control, res, &error);
+	if (seconds == 0) {
+		egg_warning ("failed to get time: %s", error->message);
+		g_error_free (error);
+		return;
 	}
 
 	/* have we passed the timout? */
-	if (time_s < thresh) {
-		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, time_s);
-		return FALSE;
+	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPDATES);
+	if (seconds < thresh) {
+		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds);
+		return;
 	}
 
-	gpk_auto_refresh_signal_refresh_cache (arefresh);
-	return TRUE;
+	/* send signal */
+	gpk_auto_refresh_signal_get_updates (arefresh);
 }
 
 /**
  * gpk_auto_refresh_maybe_get_updates:
  **/
-static gboolean
+static void
 gpk_auto_refresh_maybe_get_updates (GpkAutoRefresh *arefresh)
 {
-	guint time_s;
 	guint thresh;
-	gboolean ret;
 
-	g_return_val_if_fail (GPK_IS_AUTO_REFRESH (arefresh), FALSE);
+	g_return_if_fail (GPK_IS_AUTO_REFRESH (arefresh));
 
 	if (!arefresh->priv->force_get_updates_login) {
 		arefresh->priv->force_get_updates_login = TRUE;
 		if (gconf_client_get_bool (arefresh->priv->gconf_client, GPK_CONF_FORCE_GET_UPDATES_LOGIN, NULL)) {
 			egg_debug ("forcing get update due to GConf");
 			gpk_auto_refresh_signal_get_updates (arefresh);
-			return TRUE;
+			return;
 		}
 	}
 
-	/* get this each time, as it may have changed behind out back */
+	/* if we don't want to auto check for updates, don't do this either */
 	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPDATES);
 	if (thresh == 0) {
-		egg_debug ("not when policy is set to never get updates");
-		return FALSE;
+		egg_debug ("not when policy is to never get updates");
+		return;
 	}
 
 	/* get the time since the last refresh */
-	ret = pk_control_get_time_since_action (arefresh->priv->control,
-						PK_ROLE_ENUM_GET_UPDATES, &time_s, NULL);
-	if (!ret) {
-		egg_warning ("failed to get last time");
-		return FALSE;
+	pk_control_get_time_since_action_async (arefresh->priv->control, PK_ROLE_ENUM_GET_UPDATES, NULL,
+						(GAsyncReadyCallback) gpk_auto_refresh_get_time_get_updates_cb, arefresh);
+}
+
+/**
+ * gpk_auto_refresh_get_time_get_upgrades_cb:
+ **/
+static void
+gpk_auto_refresh_get_time_get_upgrades_cb (GObject *object, GAsyncResult *res, GpkAutoRefresh *arefresh)
+{
+	PkControl *control = PK_CONTROL (object);
+	GError *error = NULL;
+	guint seconds;
+	guint thresh;
+
+	/* get the result */
+	seconds = pk_control_get_time_since_action_finish (control, res, &error);
+	if (seconds == 0) {
+		egg_warning ("failed to get time: %s", error->message);
+		g_error_free (error);
+		return;
 	}
 
 	/* have we passed the timout? */
-	if (time_s < thresh) {
-		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, time_s);
-		return FALSE;
+	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPDATES);
+	if (seconds < thresh) {
+		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds);
+		return;
 	}
 
-	gpk_auto_refresh_signal_get_updates (arefresh);
-	return TRUE;
+	/* send signal */
+	gpk_auto_refresh_signal_get_upgrades (arefresh);
 }
 
 /**
  * gpk_auto_refresh_maybe_get_upgrades:
  **/
-static gboolean
+static void
 gpk_auto_refresh_maybe_get_upgrades (GpkAutoRefresh *arefresh)
 {
-	guint time_s;
 	guint thresh;
-	gboolean ret;
 
-	g_return_val_if_fail (GPK_IS_AUTO_REFRESH (arefresh), FALSE);
+	g_return_if_fail (GPK_IS_AUTO_REFRESH (arefresh));
 
 	/* get this each time, as it may have changed behind out back */
 	thresh = gpk_auto_refresh_get_frequency_prefs (arefresh, GPK_CONF_FREQUENCY_GET_UPGRADES);
 	if (thresh == 0) {
 		egg_debug ("not when policy is set to never check for upgrades");
-		return FALSE;
+		return;
 	}
 
 	/* get the time since the last refresh */
-	ret = pk_control_get_time_since_action (arefresh->priv->control,
-						PK_ROLE_ENUM_GET_DISTRO_UPGRADES, &time_s, NULL);
-	if (!ret) {
-		egg_debug ("failed to get last time");
-		return FALSE;
-	}
-
-	/* have we passed the timout? */
-	if (time_s < thresh) {
-		egg_debug ("not before timeout, thresh=%u, now=%u", thresh, time_s);
-		return FALSE;
-	}
-
-	gpk_auto_refresh_signal_get_upgrades (arefresh);
-	return TRUE;
+	pk_control_get_time_since_action_async (arefresh->priv->control, PK_ROLE_ENUM_GET_DISTRO_UPGRADES, NULL,
+						(GAsyncReadyCallback) gpk_auto_refresh_get_time_get_upgrades_cb, arefresh);
 }
 
 /**
@@ -445,13 +490,16 @@ gpk_auto_refresh_convert_network_state (GpkAutoRefresh *arefresh, PkNetworkEnum
 }
 
 /**
- * gpk_auto_refresh_network_status_changed_cb:
+ * gpk_auto_refresh_notify_network_state_cb:
  **/
 static void
-gpk_auto_refresh_network_status_changed_cb (PkControl *control, PkNetworkEnum state, GpkAutoRefresh *arefresh)
+gpk_auto_refresh_notify_network_state_cb (PkControl *control, GParamSpec *pspec, GpkAutoRefresh *arefresh)
 {
+	PkNetworkEnum state;
+
 	g_return_if_fail (GPK_IS_AUTO_REFRESH (arefresh));
 
+	g_object_get (control, "network-state", &state, NULL);
 	arefresh->priv->network_active = gpk_auto_refresh_convert_network_state (arefresh, state);
 	egg_debug ("setting online %i", arefresh->priv->network_active);
 	if (arefresh->priv->network_active)
@@ -509,8 +557,7 @@ gpk_auto_refresh_client_changed_cb (DkpClient *client, GpkAutoRefresh *arefresh)
 static void
 gpk_auto_refresh_init (GpkAutoRefresh *arefresh)
 {
-	PkNetworkEnum state;
-
+//	PkNetworkEnum state;
 	arefresh->priv = GPK_AUTO_REFRESH_GET_PRIVATE (arefresh);
 	arefresh->priv->on_battery = FALSE;
 	arefresh->priv->network_active = FALSE;
@@ -530,10 +577,10 @@ gpk_auto_refresh_init (GpkAutoRefresh *arefresh)
 
 	/* we need to query the last cache refresh time */
 	arefresh->priv->control = pk_control_new ();
-	g_signal_connect (arefresh->priv->control, "network-state-changed",
-			  G_CALLBACK (gpk_auto_refresh_network_status_changed_cb), arefresh);
-	state = pk_control_get_network_state (arefresh->priv->control, NULL);
-	arefresh->priv->network_active = gpk_auto_refresh_convert_network_state (arefresh, state);
+	g_signal_connect (arefresh->priv->control, "notify::network-state",
+			  G_CALLBACK (gpk_auto_refresh_notify_network_state_cb), arefresh);
+//	state = pk_control_get_network_state (arefresh->priv->control, NULL);
+//	arefresh->priv->network_active = gpk_auto_refresh_convert_network_state (arefresh, state);
 
 	/* use a DkpClient */
 	arefresh->priv->client = dkp_client_new ();
diff --git a/src/gpk-firmware.c b/src/gpk-firmware.c
index efbe515..7bbe711 100644
--- a/src/gpk-firmware.c
+++ b/src/gpk-firmware.c
@@ -67,7 +67,7 @@ struct GpkFirmwarePrivate
 	GConfClient		*gconf_client;
 	GFileMonitor		*monitor;
 	GPtrArray		*array_requested;
-	PkClient		*client_primary;
+	PkClient		*client;
 	GPtrArray		*packages_found;
 	guint			 timeout_id;
 };
@@ -182,9 +182,9 @@ gpk_firmware_install_file (GpkFirmware *firmware)
 	/* install all of the firmware files */
 	package_ids = pk_package_list_to_strv (firmware->priv->packages_found);
 #if PK_CHECK_VERSION(0,5,0)
-	ret = pk_client_install_packages (firmware->priv->client_primary, TRUE, package_ids, &error);
+	ret = pk_client_install_packages (firmware->priv->client, TRUE, package_ids, &error);
 #else
-	ret = pk_client_install_packages (firmware->priv->client_primary, package_ids, &error);
+	ret = pk_client_install_packages (firmware->priv->client, package_ids, &error);
 #endif
 	if (!ret) {
 		egg_warning ("failed to install provide file: %s", error->message);
@@ -342,11 +342,7 @@ gpk_firmware_check_available (GpkFirmware *firmware, const gchar *filename)
 
 	/* search for newest not installed package */
 	filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_INSTALLED, PK_FILTER_ENUM_NEWEST, -1);
-	ret = pk_client_search_file (firmware->priv->client_primary, filter, filename, &error);
-
-	/* unsay bodge */
-	pk_client_set_synchronous (firmware->priv->client_primary, FALSE, NULL);
-
+	ret = pk_client_search_file_sync (firmware->priv->client, filter, filename, &error);
 	if (!ret) {
 		egg_warning ("failed to search file %s: %s", filename, error->message);
 		g_error_free (error);
@@ -354,7 +350,7 @@ gpk_firmware_check_available (GpkFirmware *firmware, const gchar *filename)
 	}
 
 	/* make sure we have one package */
-	list = pk_results_get_package_array (firmware->priv->client_primary);
+	list = pk_results_get_package_array (firmware->priv->client);
 	if (list->len == 0)
 		egg_debug ("no package providing %s found", filename);
 	else if (list->len != 1)
@@ -602,24 +598,6 @@ gpk_firmware_error_code_cb (PkClient *client, PkErrorCodeEnum code, const gchar
 }
 
 /**
- * gpk_firmware_primary_requeue:
- **/
-static gboolean
-gpk_firmware_primary_requeue (GpkFirmware *firmware)
-{
-	gboolean ret;
-	GError *error = NULL;
-
-	/* retry new action */
-	ret = pk_client_requeue (firmware->priv->client_primary, &error);
-	if (!ret) {
-		egg_warning ("Failed to requeue: %s", error->message);
-		g_error_free (error);
-	}
-	return ret;
-}
-
-/**
  * gpk_firmware_require_restart:
  **/
 static void
@@ -725,14 +703,6 @@ gpk_firmware_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime,
 	pk_client_get_role (client, &role, NULL, NULL);
 	egg_debug ("role: %s, exit: %s", pk_role_enum_to_text (role), pk_exit_enum_to_text (exit_enum));
 
-	/* need to handle retry with only_trusted=FALSE */
-	if (exit_enum == PK_EXIT_ENUM_NEED_UNTRUSTED) {
-		egg_debug ("need to handle untrusted");
-		pk_client_set_only_trusted (client, FALSE);
-		gpk_firmware_primary_requeue (firmware);
-		return;
-	}
-
 	/* tell the user we installed okay */
 	if (exit_enum == PK_EXIT_ENUM_SUCCESS && role == PK_ROLE_ENUM_INSTALL_PACKAGES) {
 
@@ -1009,11 +979,11 @@ gpk_firmware_init (GpkFirmware *firmware)
 	firmware->priv->array_requested = g_ptr_array_new ();
 	firmware->priv->gconf_client = gconf_client_get_default ();
 	firmware->priv->consolekit = egg_console_kit_new ();
-	firmware->priv->client_primary = pk_client_new ();
+	firmware->priv->client = pk_client_new ();
 
-	g_signal_connect (firmware->priv->client_primary, "error-code",
+	g_signal_connect (firmware->priv->client, "error-code",
 			  G_CALLBACK (gpk_firmware_error_code_cb), firmware);
-	g_signal_connect (firmware->priv->client_primary, "finished",
+	g_signal_connect (firmware->priv->client, "finished",
 			  G_CALLBACK (gpk_firmware_finished_cb), firmware);
 
 	/* setup watch for new hardware */
@@ -1054,7 +1024,7 @@ gpk_firmware_finalize (GObject *object)
 	g_ptr_array_foreach (firmware->priv->array_requested, (GFunc) gpk_firmware_request_free, NULL);
 	g_ptr_array_free (firmware->priv->array_requested, TRUE);
 	g_object_unref (firmware->priv->packages_found);
-	g_object_unref (firmware->priv->client_primary);
+	g_object_unref (firmware->priv->client);
 	g_object_unref (firmware->priv->gconf_client);
 	g_object_unref (firmware->priv->consolekit);
 	if (firmware->priv->monitor != NULL)
diff --git a/src/gpk-prefs.c b/src/gpk-prefs.c
index 1e70c74..d872850 100644
--- a/src/gpk-prefs.c
+++ b/src/gpk-prefs.c
@@ -361,14 +361,16 @@ gpk_prefs_message_received_cb (UniqueApp *app, UniqueCommand command, UniqueMess
 }
 
 /**
- * gpk_prefs_network_status_changed_cb:
+ * gpk_prefs_notify_network_state_cb:
  **/
 static void
-gpk_prefs_network_status_changed_cb (PkControl *control, PkNetworkEnum state, gpointer data)
+gpk_prefs_notify_network_state_cb (PkControl *control, GParamSpec *pspec, gpointer data)
 {
 	GtkWidget *widget;
+	PkNetworkEnum state;
 
 	/* only show label on mobile broadband */
+	g_object_get (control, "network-state", &state, NULL);
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_mobile_broadband"));
 	if (state == PK_NETWORK_ENUM_MOBILE)
 		gtk_widget_show (widget);
@@ -531,8 +533,8 @@ main (int argc, char *argv[])
 	/* get actions */
 	loop = g_main_loop_new (NULL, FALSE);
 	control = pk_control_new ();
-	g_signal_connect (control, "network-state-changed",
-			  G_CALLBACK (gpk_prefs_network_status_changed_cb), NULL);
+	g_signal_connect (control, "notify::network-state",
+			  G_CALLBACK (gpk_prefs_notify_network_state_cb), NULL);
 
 	/* get UI */
 	builder = gtk_builder_new ();



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