[network-manager-applet] applet: really fix animation stuttering



commit 83a378aebca53de5bf626681c243138aeae997ca
Author: Dan Williams <dcbw redhat com>
Date:   Wed Nov 4 10:47:12 2009 -0800

    applet: really fix animation stuttering
    
    While d45a2d05745379d13271d03330eb8d3213c0e51d fixed some of the root
    cause of stuttering (by fixing other device state changes interfering
    with the activating device's animation), becuase D-Bus is asynchronous,
    when the device state changed the ActiveConnections property update
    may not have been processed yet, causing applet_common_device_state_changed()
    to fail to retrieve the NMActiveConnection for this device.
    
    Fix that all for real (and the race between VPN activation turning the
    icon on/off and the device activating turning the icon on/off) by
    checking whether anything is activating (either a device or a VPN)
    before starting or stopping the animation.

 src/applet.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 72 insertions(+), 11 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 7ab578c..a944970 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -714,6 +714,48 @@ clear_animation_timeout (NMApplet *applet)
 	}
 }
 
+static gboolean
+applet_is_any_device_activating (NMApplet *applet)
+{
+	const GPtrArray *devices;
+	int i;
+
+	/* Check for activating devices */
+	devices = nm_client_get_devices (applet->nm_client);
+	for (i = 0; devices && (i < devices->len); i++) {
+		NMDevice *candidate = NM_DEVICE (g_ptr_array_index (devices, i));
+		NMDeviceState state;
+
+		state = nm_device_get_state (candidate);
+		if (state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_ACTIVATED)
+			return TRUE;
+	}
+	return FALSE;
+}
+
+static gboolean
+applet_is_any_vpn_activating (NMApplet *applet)
+{
+	const GPtrArray *connections;
+	int i;
+
+	connections = nm_client_get_active_connections (applet->nm_client);
+	for (i = 0; connections && (i < connections->len); i++) {
+		NMActiveConnection *candidate = NM_ACTIVE_CONNECTION (g_ptr_array_index (connections, i));
+		NMVPNConnectionState vpn_state;
+
+		if (NM_IS_VPN_CONNECTION (candidate)) {
+			vpn_state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (candidate));
+			if (   vpn_state == NM_VPN_CONNECTION_STATE_PREPARE
+			    || vpn_state == NM_VPN_CONNECTION_STATE_NEED_AUTH
+			    || vpn_state == NM_VPN_CONNECTION_STATE_CONNECT
+			    || vpn_state == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET) {
+				return TRUE;
+			}
+		}
+	}
+	return FALSE;
+}
 static void
 save_timestamp_cb (NMSettingsConnectionInterface *connection,
                    GError *error,
@@ -885,15 +927,20 @@ vpn_connection_state_changed (NMVPNConnection *vpn,
 	NMConnection *connection;
 	const char *banner;
 	char *title = NULL, *msg = NULL;
-	gboolean clear_timeout = TRUE;
+	gboolean device_activating, vpn_activating;
+
+	device_activating = applet_is_any_device_activating (applet);
+	vpn_activating = applet_is_any_vpn_activating (applet);
 
 	switch (state) {
 	case NM_VPN_CONNECTION_STATE_PREPARE:
 	case NM_VPN_CONNECTION_STATE_NEED_AUTH:
 	case NM_VPN_CONNECTION_STATE_CONNECT:
 	case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
-		start_animation_timeout (applet);
-		clear_timeout = FALSE;
+		/* Be sure to turn animation timeout on here since the dbus signals
+		 * for new active connections might not have come through yet.
+		 */
+		vpn_activating = TRUE;
 		break;
 	case NM_VPN_CONNECTION_STATE_ACTIVATED:
 		banner = nm_vpn_connection_get_banner (vpn);
@@ -929,8 +976,11 @@ vpn_connection_state_changed (NMVPNConnection *vpn,
 		break;
 	}
 
-	if (clear_timeout)
+	if (device_activating || vpn_activating)
+		start_animation_timeout (applet);
+	else
 		clear_animation_timeout (applet);
+
 	applet_schedule_update_icon (applet);
 }
 
@@ -1935,31 +1985,42 @@ applet_common_device_state_changed (NMDevice *device,
                                     NMDeviceStateReason reason,
                                     NMApplet *applet)
 {
+	gboolean device_activating = FALSE, vpn_activating = FALSE;
 	NMConnection *connection;
 	NMActiveConnection *active = NULL;
 
-	connection = applet_find_active_connection_for_device (device, applet, &active);
-	if (!connection)
-		return;
+	device_activating = applet_is_any_device_activating (applet);
+	vpn_activating = applet_is_any_vpn_activating (applet);
 
 	switch (new_state) {
 	case NM_DEVICE_STATE_PREPARE:
 	case NM_DEVICE_STATE_CONFIG:
 	case NM_DEVICE_STATE_NEED_AUTH:
 	case NM_DEVICE_STATE_IP_CONFIG:
-		start_animation_timeout (applet);
+		/* Be sure to turn animation timeout on here since the dbus signals
+		 * for new active connections or devices might not have come through yet.
+		 */
+		device_activating = TRUE;
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
 		/* If the device activation was successful, update the corresponding
 		 * connection object with a current timestamp.
 		 */
-		if (active)
+		connection = applet_find_active_connection_for_device (device, applet, &active);
+		if (connection && (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_USER))
 			update_connection_timestamp (active, connection, applet);
-		/* Fall through */
+		break;
 	default:
-		clear_animation_timeout (applet);
 		break;
 	}
+
+	/* If there's an activating device but we're not animating, start animation.
+	 * If we're animating, but there's no activating device or VPN, stop animating.
+	 */
+	if (device_activating || vpn_activating)
+		start_animation_timeout (applet);
+	else
+		clear_animation_timeout (applet);
 }
 
 static void



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