[empathy: 19/26] empathy-connectivity: only send the new state in the state-change signal
- From: Jonny Lamb <jonnylamb src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [empathy: 19/26] empathy-connectivity: only send the new state in the state-change signal
- Date: Thu, 20 Aug 2009 13:46:01 +0000 (UTC)
commit c98e85dcf635914dc66755d6a8560e2d370cfffe
Author: Jonny Lamb <jonny lamb collabora co uk>
Date: Wed Aug 19 16:50:14 2009 +0100
empathy-connectivity: only send the new state in the state-change signal
It can be assumed that the old state was always the opposite to the
new state, because the signal is only ever fired if the new state
differs from the old state.
Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>
libempathy-gtk/empathy-presence-chooser.c | 3 +-
libempathy/empathy-connectivity.c | 31 +++++++++++++++++++---------
libempathy/empathy-idle.c | 5 +--
3 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c
index b066819..490ad89 100644
--- a/libempathy-gtk/empathy-presence-chooser.c
+++ b/libempathy-gtk/empathy-presence-chooser.c
@@ -713,7 +713,6 @@ presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser,
static void
presence_chooser_connectivity_state_change (EmpathyConnectivity *connectivity,
- gboolean old_online,
gboolean new_online,
EmpathyPresenceChooser *chooser)
{
@@ -796,7 +795,7 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
g_signal_connect (priv->connectivity, "state-change",
G_CALLBACK (presence_chooser_connectivity_state_change),
chooser);
- presence_chooser_connectivity_state_change (priv->connectivity, FALSE,
+ presence_chooser_connectivity_state_change (priv->connectivity,
empathy_connectivity_is_online (priv->connectivity), chooser);
}
diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c
index 8c38cf2..82ac9c9 100644
--- a/libempathy/empathy-connectivity.c
+++ b/libempathy/empathy-connectivity.c
@@ -58,6 +58,23 @@ static EmpathyConnectivity *connectivity_singleton = NULL;
G_DEFINE_TYPE (EmpathyConnectivity, empathy_connectivity, G_TYPE_OBJECT);
+static void
+connectivity_change_state (EmpathyConnectivity *connectivity,
+ gboolean new_state)
+{
+ EmpathyConnectivityPriv *priv;
+
+ priv = GET_PRIV (connectivity);
+
+ if (priv->connected == new_state)
+ return;
+
+ priv->connected = new_state;
+
+ g_signal_emit (connectivity, signals[STATE_CHANGE], 0,
+ priv->connected);
+}
+
#ifdef HAVE_NM
static void
connectivity_nm_state_change_cb (NMClient *client,
@@ -65,7 +82,6 @@ connectivity_nm_state_change_cb (NMClient *client,
EmpathyConnectivity *connectivity)
{
EmpathyConnectivityPriv *priv;
- gboolean old_nm_connected;
gboolean new_nm_connected;
NMState state;
@@ -75,16 +91,12 @@ connectivity_nm_state_change_cb (NMClient *client,
return;
state = nm_client_get_state (priv->nm_client);
- old_nm_connected = priv->connected;
new_nm_connected = !(state == NM_STATE_CONNECTING
|| state == NM_STATE_DISCONNECTED);
DEBUG ("New NetworkManager network state %d", state);
- priv->connected = new_nm_connected;
-
- g_signal_emit (connectivity, signals[STATE_CHANGE], 0,
- old_nm_connected, new_nm_connected);
+ connectivity_change_state (connectivity, new_nm_connected);
}
#endif
@@ -223,9 +235,9 @@ empathy_connectivity_class_init (EmpathyConnectivityClass *klass)
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__BOOLEAN_BOOLEAN,
+ _empathy_marshal_VOID__BOOLEAN,
G_TYPE_NONE,
- 2, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, NULL);
+ 1, G_TYPE_BOOLEAN, NULL);
g_object_class_install_property (oclass,
PROP_USE_CONN,
@@ -294,8 +306,7 @@ empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity,
}
else
{
- g_signal_emit (connectivity, signals[STATE_CHANGE], 0,
- FALSE, TRUE);
+ connectivity_change_state (connectivity, TRUE);
}
g_object_notify (G_OBJECT (connectivity), "use-conn");
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c
index c3e6b01..f408cf6 100644
--- a/libempathy/empathy-idle.c
+++ b/libempathy/empathy-idle.c
@@ -226,7 +226,6 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy,
static void
idle_state_change_cb (EmpathyConnectivity *connectivity,
- gboolean old_online,
gboolean new_online,
EmpathyIdle *idle)
{
@@ -234,7 +233,7 @@ idle_state_change_cb (EmpathyConnectivity *connectivity,
priv = GET_PRIV (idle);
- if (old_online && !new_online) {
+ if (!new_online) {
/* We are no longer connected */
DEBUG ("Disconnected: Save state %d (%s)",
priv->state, priv->status);
@@ -243,7 +242,7 @@ idle_state_change_cb (EmpathyConnectivity *connectivity,
priv->saved_status = g_strdup (priv->status);
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
}
- else if (!old_online && new_online
+ else if (new_online
&& priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
/* We are now connected */
DEBUG ("Reconnected: Restore state %d (%s)",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]