void jabber_change_status(GGaduStatusPrototype *sp, gboolean keep_desc) { enum states status; LmMessage *m = NULL; gchar *show = NULL; gchar *show_away = "away"; gchar *show_xa = "xa"; gchar *show_dnd = "dnd"; gchar *show_chat = "chat"; print_debug("jabber_change_status start"); if (!sp) return; status = sp->status; /* Just a simple esthetic functionality */ if((jabber_data.status == JABBER_STATUS_UNAVAILABLE) && sp->status == JABBER_STATUS_UNAVAILABLE) { GGaduStatusPrototype *sp_temp = ggadu_find_status_prototype(p, jabber_data.status); sp_temp->status = JABBER_STATUS_UNAVAILABLE; if(sp_temp->status_description) { g_free(sp_temp->status_description); sp_temp->status_description = NULL; } signal_emit("jabber", "gui status changed", sp_temp, "main-gui"); GGaduStatusPrototype_free(sp_temp); return; } if (status == JABBER_STATUS_UNAVAILABLE) { lm_connection_close(jabber_data.connection, NULL); return; } /* connect if switched to any other than unavailable */ if ((jabber_data.status == JABBER_STATUS_UNAVAILABLE) && (status != JABBER_STATUS_UNAVAILABLE) && (!jabber_data.connection || !lm_connection_is_open(jabber_data.connection) || !lm_connection_is_authenticated(jabber_data.connection))) { g_thread_create(jabber_login_connect, (gpointer) status, FALSE, NULL); return; } if (jabber_data.connection && !lm_connection_is_authenticated(jabber_data.connection)) { print_debug("You are not yet authenticated!"); return; } m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, (status == JABBER_STATUS_UNAVAILABLE) ? LM_MESSAGE_SUB_TYPE_UNAVAILABLE : LM_MESSAGE_SUB_TYPE_AVAILABLE); /* switch (status == JABBER_STATUS_DESCR ? jabber_data.status : status) */ switch (status) { case JABBER_STATUS_AWAY: show = show_away; break; case JABBER_STATUS_XA: show = show_xa; break; case JABBER_STATUS_DND: show = show_dnd; break; case JABBER_STATUS_CHAT: show = show_chat; break; case JABBER_STATUS_AVAILABLE: show = NULL; break; default: break; } if (show) lm_message_node_add_child(m->node, "show", show); if(keep_desc) { if(sp->status_description) g_free(sp->status_description); sp->status_description = g_strdup(jabber_data.description); } if(jabber_data.description) { g_free(jabber_data.description); jabber_data.description = NULL; } if (sp->status_description) { print_debug("jabber: status description %s %s",sp->status_description,show); lm_message_node_add_child(m->node, "status", sp->status_description); jabber_data.description = g_strdup(sp->status_description); } print_debug(lm_message_node_to_string(m->node)); if (!lm_connection_send(jabber_data.connection, m, NULL)) { print_debug("jabber: Couldn't change status!\n"); } else { jabber_data.status = status; signal_emit("jabber", "gui status changed", sp, "main-gui"); } lm_message_unref(m); print_debug("jabber_change_status end"); }
//doc Loudmouth isConnected IoObject *IoLoudmouth_isConnected(IoLoudmouth *self, IoObject *locals, IoMessage *m) { return IOBOOL(self, lm_connection_is_authenticated(LMCONN(self))); }