int main (int argc, char **argv) { g_assert (tp_connection_presence_type_cmp_availability ( TP_CONNECTION_PRESENCE_TYPE_AWAY, TP_CONNECTION_PRESENCE_TYPE_UNSET) == 1); g_assert (tp_connection_presence_type_cmp_availability ( TP_CONNECTION_PRESENCE_TYPE_BUSY, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE) == -1); g_assert (tp_connection_presence_type_cmp_availability ( TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, 100) == 0); return 0; }
static void main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor, EmpathyContact *contact, TpConnectionPresenceType current, TpConnectionPresenceType previous, EmpathyMainWindow *window) { TpAccount *account; gboolean should_play = FALSE; EmpathyIdle *idle; account = empathy_contact_get_account (contact); idle = empathy_idle_dup_singleton (); should_play = !empathy_idle_account_is_just_connected (idle, account); if (!should_play) goto out; if (tp_connection_presence_type_cmp_availability (previous, TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) { /* contact was online */ if (tp_connection_presence_type_cmp_availability (current, TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) /* someone is logging off */ empathy_sound_play (GTK_WIDGET (window->window), EMPATHY_SOUND_CONTACT_DISCONNECTED); } else { /* contact was offline */ if (tp_connection_presence_type_cmp_availability (current, TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) /* someone is logging in */ empathy_sound_play (GTK_WIDGET (window->window), EMPATHY_SOUND_CONTACT_CONNECTED); } out: g_object_unref (idle); }
static void account_manager_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); GError *error = NULL; EmpathyIdle *idle; EmpathyConnectivity *connectivity; gboolean autoconnect = TRUE; if (!tp_account_manager_prepare_finish (manager, result, &error)) { DEBUG ("Failed to prepare account manager: %s", error->message); g_error_free (error); return; } /* Autoconnect */ idle = empathy_idle_dup_singleton (); connectivity = empathy_connectivity_dup_singleton (); empathy_conf_get_bool (empathy_conf_get (), EMPATHY_PREFS_AUTOCONNECT, &autoconnect); if (autoconnect && !no_connect && tp_connection_presence_type_cmp_availability (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) /* if current state is Offline, then put it online */ empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); if (should_create_salut_account (manager) || !empathy_import_mc4_has_imported ()) { EmpathyConnectionManagers *managers; managers = empathy_connection_managers_dup_singleton (); if (!check_connection_managers_ready (managers)) { g_signal_connect (managers, "notify::ready", G_CALLBACK (connection_managers_ready_cb), NULL); } } else if (!start_hidden) { maybe_show_account_assistant (); } g_object_unref (idle); g_object_unref (connectivity); }
static gint state_sort_func (GtkTreeModel *model, GtkTreeIter *iter_a, GtkTreeIter *iter_b, gpointer user_data) { gint ret_val; gchar *name_a, *name_b; FolksPersona *persona_a, *persona_b; gtk_tree_model_get (model, iter_a, EMPATHY_PERSONA_STORE_COL_NAME, &name_a, EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_a, -1); gtk_tree_model_get (model, iter_b, EMPATHY_PERSONA_STORE_COL_NAME, &name_b, EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_b, -1); if (persona_a == NULL || persona_b == NULL) { ret_val = 0; goto free_and_out; } /* If we managed to get this far, we can start looking at * the presences. */ ret_val = -tp_connection_presence_type_cmp_availability ( folks_presence_get_presence_type (FOLKS_PRESENCE (persona_a)), folks_presence_get_presence_type (FOLKS_PRESENCE (persona_b))); if (ret_val == 0) { /* Fallback: compare by name et al. */ ret_val = sort_personas (persona_a, persona_b); } free_and_out: g_free (name_a); g_free (name_b); tp_clear_object (&persona_a); tp_clear_object (&persona_b); return ret_val; }
static gint contact_list_store_state_sort_func (GtkTreeModel *model, GtkTreeIter *iter_a, GtkTreeIter *iter_b, gpointer user_data) { gint ret_val = 0; gchar *name_a, *name_b; gboolean is_separator_a, is_separator_b; EmpathyContact *contact_a, *contact_b; gtk_tree_model_get (model, iter_a, EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a, -1); gtk_tree_model_get (model, iter_b, EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b, -1); /* Separator or group? */ if (is_separator_a || is_separator_b) { if (is_separator_a) { ret_val = -1; } else if (is_separator_b) { ret_val = 1; } } else if (!contact_a && contact_b) { ret_val = 1; } else if (contact_a && !contact_b) { ret_val = -1; } else if (!contact_a && !contact_b) { /* Handle groups */ ret_val = g_utf8_collate (name_a, name_b); } if (ret_val) { goto free_and_out; } /* If we managed to get this far, we can start looking at * the presences. */ ret_val = -tp_connection_presence_type_cmp_availability ( empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)), empathy_contact_get_presence (EMPATHY_CONTACT (contact_b))); if (ret_val == 0) { /* Fallback: compare by name */ ret_val = g_utf8_collate (name_a, name_b); } free_and_out: g_free (name_a); g_free (name_b); if (contact_a) { g_object_unref (contact_a); } if (contact_b) { g_object_unref (contact_b); } return ret_val; }