pidgin: c4db69fe: Improve our NetworkManager support in a ...

rlaager at pidgin.im rlaager at pidgin.im
Sat Oct 25 20:40:49 EDT 2008


-----------------------------------------------------------------
Revision: c4db69fe62c1650d1fb404a8bbb12bf47852f70c
Ancestor: baabfd850dd02c15606049de180747cc916f6fa6
Author: rlaager at pidgin.im
Date: 2008-10-26T00:29:27
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c4db69fe62c1650d1fb404a8bbb12bf47852f70c

Modified files:
        libpurple/network.c libpurple/prpl.c pidgin/gtkconn.c

ChangeLog: 

Improve our NetworkManager support in a couple of ways:
 * We no longer show error minidialogs when the network is not available.
 * We no longer ask NetworkManager (over DBus) for the network state with
   every call to purple_network_is_available().  We now cache the result.
 * Be a little more robust when we're not sure of the connection status.
Fixes #7323

-------------- next part --------------
============================================================
--- libpurple/network.c	8d2a2ab174e53917f6c8d2c3beed44667a7edb4f
+++ libpurple/network.c	6245faabb1ac507e35cb1cc1aa07598fb20ac181
@@ -66,6 +66,8 @@ static DBusGProxy *dbus_proxy = NULL;
 static DBusGConnection *nm_conn = NULL;
 static DBusGProxy *nm_proxy = NULL;
 static DBusGProxy *dbus_proxy = NULL;
+static NMState nm_state = NM_STATE_UNKNOWN;
+static gboolean have_nm_state = FALSE;
 
 #elif defined _WIN32
 static int current_network_count;
@@ -596,13 +598,15 @@ purple_network_is_available(void)
 purple_network_is_available(void)
 {
 #ifdef HAVE_NETWORKMANAGER
-	NMState state = nm_get_network_state();
-	if (state == NM_STATE_UNKNOWN)
+	if (!have_nm_state)
 	{
-		purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n");
-		return TRUE;
+		have_nm_state = TRUE;
+		nm_state = nm_get_network_state();
+		if (nm_state == NM_STATE_UNKNOWN)
+			purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n");
 	}
-	else if (state == NM_STATE_CONNECTED)
+
+	if (nm_state == NM_STATE_UNKNOWN || nm_state == NM_STATE_CONNECTED)
 		return TRUE;
 
 	return FALSE;
@@ -618,9 +622,12 @@ nm_update_state(NMState state)
 static void
 nm_update_state(NMState state)
 {
-	static NMState prev = NM_STATE_UNKNOWN;
+	NMState prev = nm_state;
 	PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
 
+	have_nm_state = TRUE;
+	nm_state = state;
+
 	purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
 
 	switch(state)
@@ -630,16 +637,14 @@ nm_update_state(NMState state)
 			res_init();
 			if (ui_ops != NULL && ui_ops->network_connected != NULL)
 				ui_ops->network_connected();
-			prev = state;
 			break;
 		case NM_STATE_ASLEEP:
 		case NM_STATE_CONNECTING:
 		case NM_STATE_DISCONNECTED:
-			if (prev != NM_STATE_CONNECTED)
+			if (prev != NM_STATE_CONNECTED && prev != NM_STATE_UNKNOWN)
 				break;
 			if (ui_ops != NULL && ui_ops->network_disconnected != NULL)
 				ui_ops->network_disconnected();
-			prev = state;
 			break;
 		case NM_STATE_UNKNOWN:
 		default:
@@ -664,7 +669,6 @@ nm_get_network_state(void)
 		return NM_STATE_UNKNOWN;
 
 	if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) {
-		/* XXX: Print an error? */
 		g_error_free(err);
 		return NM_STATE_UNKNOWN;
 	}
============================================================
--- libpurple/prpl.c	a2f9ed66262e0720f017a353b705a132e4e7825e
+++ libpurple/prpl.c	1e2df97bcf949adfc848ee4e0770cfdd0c6233b0
@@ -23,6 +23,7 @@
 #include "internal.h"
 #include "conversation.h"
 #include "debug.h"
+#include "network.h"
 #include "notify.h"
 #include "prpl.h"
 #include "request.h"
@@ -317,7 +318,8 @@ do_prpl_change_account_status(PurpleAcco
 	PurplePluginProtocolInfo *prpl_info;
 
 	if (purple_status_is_online(new_status) &&
-		purple_account_is_disconnected(account))
+		purple_account_is_disconnected(account) &&
+		purple_network_is_available())
 	{
 		purple_account_connect(account);
 		return;
============================================================
--- pidgin/gtkconn.c	fc183bf7b4daa12f5f46e00cbc4954eda59671a7
+++ pidgin/gtkconn.c	8f434427ffc3242a2dbd492689d80a9dfcbe1cee
@@ -208,9 +208,7 @@ static void pidgin_connection_network_di
 	while (l) {
 		PurpleAccount *a = (PurpleAccount*)l->data;
 		if (!purple_account_is_disconnected(a)) {
-			purple_connection_error_reason(purple_account_get_connection(a),
-			                               PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-			                               _("Network disconnected"));
+			purple_account_disconnect(a);
 		}
 		l = l->next;
 	}


More information about the Commits mailing list