EmpathyConnectivity *connectivity;
gulong state_change_signal_id;
+ gboolean ready;
+
TpConnectionPresenceType state;
gchar *status;
- TpConnectionPresenceType flash_state;
gboolean auto_away;
TpConnectionPresenceType away_saved_state;
guint ext_away_timeout;
TpAccountManager *manager;
+ gulong idle_presence_changed_id;
/* pointer to a TpAccount --> glong of time of connection */
GHashTable *connect_times;
PROP_0,
PROP_STATE,
PROP_STATUS,
- PROP_FLASH_STATE,
PROP_AUTO_AWAY
};
priv->away_saved_state, new_state);
empathy_idle_set_state (idle, new_state);
} else if (!is_idle && priv->is_idle) {
- const gchar *new_status;
/* We are no more idle, restore state */
idle_ext_away_stop (idle);
- if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
- priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
- priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
- new_status = NULL;
- } else {
- new_status = priv->status;
- }
-
/* Only try and set the presence if the away saved state is not
* unset. This is an odd case because it means that the session
* didn't notify us of the state change to idle, and as a
* result, we couldn't save the current state at that time.
*/
if (priv->away_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
- DEBUG ("Restoring state to %d, reset status to %s",
- priv->away_saved_state, new_status);
+ DEBUG ("Restoring state to %d",
+ priv->away_saved_state);
- empathy_idle_set_presence (idle,
- priv->away_saved_state,
- new_status);
+ empathy_idle_set_state (idle,priv->away_saved_state);
} else {
DEBUG ("Away saved state is unset. This means that we "
"weren't told when the session went idle. "
priv->state_change_signal_id);
priv->state_change_signal_id = 0;
+ if (priv->manager != NULL) {
+ g_signal_handler_disconnect (priv->manager,
+ priv->idle_presence_changed_id);
+ g_object_unref (priv->manager);
+ }
+
g_object_unref (priv->connectivity);
g_hash_table_destroy (priv->connect_times);
return retval;
}
+static const gchar *
+empathy_idle_get_status (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ if (G_UNLIKELY (!priv->ready))
+ g_critical (G_STRLOC ": %s called before AccountManager ready",
+ G_STRFUNC);
+
+ if (!priv->status) {
+ return empathy_presence_get_default_message (priv->state);
+ }
+
+ return priv->status;
+}
+
static void
idle_get_property (GObject *object,
guint param_id,
case PROP_STATUS:
g_value_set_string (value, empathy_idle_get_status (idle));
break;
- case PROP_FLASH_STATE:
- g_value_set_enum (value, empathy_idle_get_flash_state (idle));
- break;
case PROP_AUTO_AWAY:
g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
break;
case PROP_STATUS:
empathy_idle_set_status (idle, g_value_get_string (value));
break;
- case PROP_FLASH_STATE:
- empathy_idle_set_flash_state (idle, g_value_get_enum (value));
- break;
case PROP_AUTO_AWAY:
empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
break;
"status",
NULL,
G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_FLASH_STATE,
- g_param_spec_uint ("flash-state",
- "flash-state",
- "flash-state",
- 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
- TP_CONNECTION_PRESENCE_TYPE_UNSET,
- G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_AUTO_AWAY,
GAsyncResult *result,
gpointer user_data)
{
- EmpathyIdle *idle = EMPATHY_IDLE (user_data);
+ EmpathyIdle *idle = user_data;
TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
- EmpathyIdlePriv *priv = GET_PRIV (idle);
+ EmpathyIdlePriv *priv;
TpConnectionPresenceType state;
gchar *status, *status_message;
GList *accounts, *l;
GError *error = NULL;
+ /* In case we've been finalized before reading this callback */
+ if (idle_singleton == NULL)
+ return;
+
+ priv = GET_PRIV (idle);
+ priv->ready = TRUE;
+
if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
DEBUG ("Failed to prepare account manager: %s", error->message);
g_error_free (error);
accounts = tp_account_manager_get_valid_accounts (priv->manager);
for (l = accounts; l != NULL; l = l->next) {
- empathy_signal_connect_weak (l->data, "status-changed",
+ tp_g_signal_connect_object (l->data, "status-changed",
G_CALLBACK (account_status_changed_cb),
- G_OBJECT (idle));
+ idle, 0);
}
g_list_free (accounts);
{
EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
+ TpDBusDaemon *dbus;
idle->priv = priv;
priv->is_idle = FALSE;
tp_account_manager_prepare_async (priv->manager, NULL,
account_manager_ready_cb, idle);
- g_signal_connect (priv->manager, "most-available-presence-changed",
+ priv->idle_presence_changed_id = g_signal_connect (priv->manager,
+ "most-available-presence-changed",
G_CALLBACK (idle_presence_changed_cb), idle);
- priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
+ dbus = tp_dbus_daemon_dup (NULL);
+
+ priv->gs_proxy = dbus_g_proxy_new_for_name (
+ tp_proxy_get_dbus_connection (dbus),
"org.gnome.SessionManager",
"/org/gnome/SessionManager/Presence",
"org.gnome.SessionManager.Presence");
DEBUG ("Failed to get gs proxy");
}
+ g_object_unref (dbus);
+
priv->connectivity = empathy_connectivity_dup_singleton ();
priv->state_change_signal_id = g_signal_connect (priv->connectivity,
"state-change", G_CALLBACK (idle_state_change_cb), idle);
priv = GET_PRIV (idle);
+ if (G_UNLIKELY (!priv->ready))
+ g_critical (G_STRLOC ": %s called before AccountManager ready",
+ G_STRFUNC);
+
return priv->state;
}
empathy_idle_set_presence (idle, state, priv->status);
}
-const gchar *
-empathy_idle_get_status (EmpathyIdle *idle)
-{
- EmpathyIdlePriv *priv;
-
- priv = GET_PRIV (idle);
-
- if (!priv->status) {
- return empathy_presence_get_default_message (priv->state);
- }
-
- return priv->status;
-}
-
void
empathy_idle_set_status (EmpathyIdle *idle,
const gchar *status)
empathy_idle_set_presence (idle, priv->state, status);
}
-TpConnectionPresenceType
-empathy_idle_get_flash_state (EmpathyIdle *idle)
-{
- EmpathyIdlePriv *priv;
-
- priv = GET_PRIV (idle);
-
- return priv->flash_state;
-}
-
-void
-empathy_idle_set_flash_state (EmpathyIdle *idle,
- TpConnectionPresenceType state)
-{
- EmpathyIdlePriv *priv;
-
- priv = GET_PRIV (idle);
-
- priv->flash_state = state;
-
- if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
- }
-
- g_object_notify (G_OBJECT (idle), "flash-state");
-}
-
static void
empathy_idle_do_set_presence (EmpathyIdle *idle,
TpConnectionPresenceType status_type,