Exemple #1
0
Data IMInvoker::statusToData(PurpleStatus *status) {
	Data data;
	const char* statusName = purple_status_get_name(status);
	if (statusName) data.compound["name"] = Data(statusName, Data::VERBATIM);

	PurpleStatusType* statusType = PURPLE_STATUS_GET_TYPE(status);

	GList *statusAttrElem;
	PURPLE_STATUS_ATTR* statusAttr;
	GList *statusAttrList = purple_status_type_get_attrs(statusType);

	for(statusAttrElem = statusAttrList; statusAttrElem; statusAttrElem = statusAttrElem->next) {
		statusAttr = (PURPLE_STATUS_ATTR*)statusAttrElem->data;
		const char* statusAttrId = PURPLE_STATUS_ATTR_GET_ID(statusAttr);
		PURPLE_VALUE* statusValue = purple_status_get_attr_value(status, statusAttrId);
		if (statusValue) {
			data.compound[statusAttrId] = purpleValueToData(statusValue);
		}
	}

	data.compound["active"] = Data((bool)purple_status_is_active(status));
	data.compound["available"] = Data((bool)purple_status_is_available(status));
	data.compound["exclusive"] = Data((bool)purple_status_is_exclusive(status));
	data.compound["active"] = Data((bool)purple_status_is_active(status));
	data.compound["independent"] = Data((bool)purple_status_is_independent(status));
	data.compound["online"] = Data((bool)purple_status_is_online(status));

	return data;
}
Exemple #2
0
void purple_prpl_got_user_status_deactive(PurpleAccount *account, const char *name,
					const char *status_id)
{
	GSList *list, *l;
	PurpleBuddy *buddy;
	PurplePresence *presence;
	PurpleStatus *status;

	g_return_if_fail(account   != NULL);
	g_return_if_fail(name      != NULL);
	g_return_if_fail(status_id != NULL);
	g_return_if_fail(purple_account_is_connected(account) || purple_account_is_connecting(account));

	if((list = purple_find_buddies(account, name)) == NULL)
		return;

	for(l = list; l != NULL; l = l->next) {
		buddy = l->data;

		presence = purple_buddy_get_presence(buddy);
		status   = purple_presence_get_status(presence, status_id);

		if(NULL == status)
			continue;

		if (purple_status_is_active(status)) {
			purple_status_set_active(status, FALSE);
			purple_blist_update_buddy_status(buddy, status);
		}
	}

	g_slist_free(list);
}
Exemple #3
0
void jabber_set_status(PurpleAccount *account, PurpleStatus *status)
{
	PurpleConnection *gc;
	JabberStream *js;

	if (!purple_account_is_connected(account))
		return;

	if (purple_status_is_exclusive(status) && !purple_status_is_active(status)) {
		/* An exclusive status can't be deactivated. You should just
		 * activate some other exclusive status. */
		return;
	}

	gc = purple_account_get_connection(account);
	js = purple_connection_get_protocol_data(gc);

	/* it's a mood update */
	if (purple_status_type_get_primitive(purple_status_get_type(status)) == PURPLE_STATUS_MOOD) {
		const char *mood =
			purple_status_get_attr_string(status, PURPLE_MOOD_NAME);
		const char *mood_text =
			purple_status_get_attr_string(status, PURPLE_MOOD_COMMENT);
		jabber_mood_set(js, mood, mood_text);
		return;
	}

	jabber_presence_send(js, FALSE);
}
Exemple #4
0
static char *
create_media_string(PurplePresence *presence)
{
	const char *title, *game, *office;
	char *ret;
	PurpleStatus *status = purple_presence_get_status(presence, "tune");
	if (!status || !purple_status_is_active(status))
		return NULL;

	title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
	game = purple_status_get_attr_string(status, "game");
	office = purple_status_get_attr_string(status, "office");

	if (title && *title) {
		const char *artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
		const char *album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM);
		ret = g_strdup_printf("WMP\\0Music\\01\\0{0}%s%s\\0%s\\0%s\\0%s\\0",
		                      artist ? " - {1}" : "",
		                      album ? " ({2})" : "",
		                      title,
		                      artist ? artist : "",
		                      album ? album : "");
	}
	else if (game && *game)
		ret = g_strdup_printf("\\0Games\\01\\0Playing {0}\\0%s\\0", game);
	else if (office && *office)
		ret = g_strdup_printf("\\0Office\\01\\0Editing {0}\\0%s\\0", office);
	else
		ret = NULL;

	return ret;
}
Exemple #5
0
static void ga_plugin_set_status(PurpleAccount *account, PurpleStatus *status)
{
	PurpleConnection *gc = purple_account_get_connection(account);
	//const char *status_id = purple_status_get_id(status);

	g_return_if_fail(gc != NULL);

	if (!purple_status_is_active(status))
		return;

}
Exemple #6
0
gboolean
pn_timeout_tune_status (gpointer data)
{
    MsnSession *session;
    PurpleAccount *account;
    PurplePresence *presence;
    PurpleStatus *status;

    session = data;

    if (!session)
        return FALSE;

    account = msn_session_get_user_data (session);
    presence = purple_account_get_presence (account);
    status = purple_presence_get_status (presence, "tune");

    if (status)
    {
        if (session->autoupdate_tune.enabled)
        {
            pn_update_personal_message (session);

            if (!status || !purple_status_is_active (status))
                session->autoupdate_tune.enabled = FALSE;
        }
        else
        {
            if (status && purple_status_is_active (status))
            {
                session->autoupdate_tune.enabled = TRUE;
                pn_update_personal_message (session);
            }
        }
    }

    session->autoupdate_tune.timer = g_timeout_add_seconds (10, pn_timeout_tune_status, session);

    return FALSE;
}
Exemple #7
0
void flist_purple_set_status(PurpleAccount *account, PurpleStatus *status) {
    PurpleConnection *pc = purple_account_get_connection(account);
    FListAccount *fla = pc->proto_data;
    PurpleStatusType *statusType = purple_status_get_type(status);
    GList *statusTypes = flist_status_types(account);
    GList *cur = statusTypes;
    FListStatus fStatus = FLIST_STATUS_UNKNOWN;
    
    // The status isn't active! bail!
    if (!purple_status_is_active(status))
        return;
    
    // First, get the presence. If it's idle, we default to idle.
    PurplePresence *presence = purple_status_get_presence(status);
    if(purple_presence_is_idle(presence)) {
        flist_set_status(fla, FLIST_STATUS_IDLE, purple_status_get_attr_string(status, FLIST_STATUS_MESSAGE_KEY));
    }
    
    // Alright, not idle. Next, compare StatusType IDs. If it's a match, use that.
    while(cur) {
        PurpleStatusType *type = cur->data;
        if(strcmp(purple_status_type_get_id(type), purple_status_type_get_id(statusType)) == 0){
            fStatus = flist_parse_status(purple_status_type_get_id(statusType));
            break;
        } else {
            cur = g_list_next(cur);
        }
    }
    // Found a matching F-list Status. Use it!
    if(fStatus != FLIST_STATUS_UNKNOWN) {
        flist_set_status(fla, fStatus, 	purple_status_get_attr_string(status, FLIST_STATUS_MESSAGE_KEY));
    } else {
        // Alright, seems the status we chose isn't an F-list one. Let's convert to the next best primitive.
        switch (purple_status_type_get_primitive(statusType)) {
            case PURPLE_STATUS_AWAY:
            case PURPLE_STATUS_EXTENDED_AWAY:
                flist_set_status(fla, FLIST_STATUS_AWAY, purple_status_get_attr_string(status, FLIST_STATUS_MESSAGE_KEY));
                break;
            case PURPLE_STATUS_UNAVAILABLE:
                flist_set_status(fla, FLIST_STATUS_DND, purple_status_get_attr_string(status, FLIST_STATUS_MESSAGE_KEY));
                break;
                
                // Assume AVAILABLE by default if it's not an AWAY/DND status
            default:
                flist_set_status(fla, FLIST_STATUS_AVAILABLE, purple_status_get_attr_string(status, FLIST_STATUS_MESSAGE_KEY));
        }
    }
    g_list_free(statusTypes);
    flist_update_server_status(fla);
}
void sipe_purple_set_status(PurpleAccount *account,
			    PurpleStatus *status)
{
	SIPE_DEBUG_INFO("sipe_purple_set_status[CB]: status=%s",
			purple_status_get_id(status));

	if (!purple_status_is_active(status))
		return;

	if (account->gc) {
		const gchar *status_id = purple_status_get_id(status);
		const gchar *note      = purple_status_get_attr_string(status,
								       SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE);
		sipe_core_status_set(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
				     sipe_purple_token_to_activity(status_id),
				     note);
	}
}
Exemple #9
0
static void irc_set_status(PurpleAccount *account, PurpleStatus *status)
{
	PurpleConnection *gc = purple_account_get_connection(account);
	struct irc_conn *irc;
	const char *args[1];
	const char *status_id = purple_status_get_id(status);

	g_return_if_fail(gc != NULL);
	irc = gc->proto_data;

	if (!purple_status_is_active(status))
		return;

	args[0] = NULL;

	if (!strcmp(status_id, "away")) {
		args[0] = purple_status_get_attr_string(status, "message");
		if ((args[0] == NULL) || (*args[0] == '\0'))
			args[0] = _("Away");
		irc_cmd_away(irc, "away", NULL, args);
	} else if (!strcmp(status_id, "available")) {
		irc_cmd_away(irc, "back", NULL, args);
	}
}
Exemple #10
0
void jabber_presence_send(JabberStream *js, gboolean force)
{
	PurpleAccount *account;
	xmlnode *presence, *x, *photo;
	char *stripped = NULL;
	JabberBuddyState state;
	int priority;
	const char *artist = NULL, *title = NULL, *source = NULL, *uri = NULL, *track = NULL;
	int length = -1;
	gboolean allowBuzz;
	PurplePresence *p;
	PurpleStatus *status, *tune;

	account = purple_connection_get_account(js->gc);
	p = purple_account_get_presence(account);
	status = purple_presence_get_active_status(p);

	/* we don't want to send presence before we've gotten our roster */
	if (js->state != JABBER_STREAM_CONNECTED) {
		purple_debug_misc("jabber", "attempt to send presence before roster retrieved\n");
		return;
	}

	purple_status_to_jabber(status, &state, &stripped, &priority);

	/* check for buzz support */
	allowBuzz = purple_status_get_attr_boolean(status,"buzz");
	/* changing the buzz state has to trigger a re-broadcasting of the presence for caps */

	tune = purple_presence_get_status(p, "tune");
	if (js->googletalk && !stripped && purple_status_is_active(tune)) {
		stripped = jabber_google_presence_outgoing(tune);
	}

#define CHANGED(a,b) ((!a && b) || (a && a[0] == '\0' && b && b[0] != '\0') || \
					  (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b)))
	/* check if there are any differences to the <presence> and send them in that case */
	if (force || allowBuzz != js->allowBuzz || js->old_state != state ||
		CHANGED(js->old_msg, stripped) || js->old_priority != priority ||
		CHANGED(js->old_avatarhash, js->avatar_hash) || js->old_idle != js->idle) {
		/* Need to update allowBuzz before creating the presence (with caps) */
		js->allowBuzz = allowBuzz;

		presence = jabber_presence_create_js(js, state, stripped, priority);

		/* Per XEP-0153 4.1, we must always send the <x> */
		x = xmlnode_new_child(presence, "x");
		xmlnode_set_namespace(x, "vcard-temp:x:update");
		/*
		 * FIXME: Per XEP-0153 4.3.2 bullet 2, we must not publish our
		 * image hash if another resource has logged in and updated the
		 * vcard avatar. Requires changes in jabber_presence_parse.
		 */
		if (js->vcard_fetched) {
			/* Always publish a <photo>; it's empty if we have no image. */
			photo = xmlnode_new_child(x, "photo");
			if (js->avatar_hash)
				xmlnode_insert_data(photo, js->avatar_hash, -1);
		}

		jabber_send(js, presence);

		g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence);
		xmlnode_free(presence);

		/* update old values */

		if(js->old_msg)
			g_free(js->old_msg);
		if(js->old_avatarhash)
			g_free(js->old_avatarhash);
		js->old_msg = g_strdup(stripped);
		js->old_avatarhash = g_strdup(js->avatar_hash);
		js->old_state = state;
		js->old_priority = priority;
		js->old_idle = js->idle;
	}
	g_free(stripped);

	/* next, check if there are any changes to the tune values */
	if (purple_status_is_active(tune)) {
		artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
		title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
		source = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
		uri = purple_status_get_attr_string(tune, PURPLE_TUNE_URL);
		track = purple_status_get_attr_string(tune, PURPLE_TUNE_TRACK);
		length = (!purple_status_get_attr_value(tune, PURPLE_TUNE_TIME)) ? -1 :
				purple_status_get_attr_int(tune, PURPLE_TUNE_TIME);
	}

	if(CHANGED(artist, js->old_artist) || CHANGED(title, js->old_title) || CHANGED(source, js->old_source) ||
	   CHANGED(uri, js->old_uri) || CHANGED(track, js->old_track) || (length != js->old_length)) {
		PurpleJabberTuneInfo tuneinfo = {
			(char*)artist,
			(char*)title,
			(char*)source,
			(char*)track,
			length,
			(char*)uri
		};
		jabber_tune_set(js->gc, &tuneinfo);

		/* update old values */
		g_free(js->old_artist);
		g_free(js->old_title);
		g_free(js->old_source);
		g_free(js->old_uri);
		g_free(js->old_track);
		js->old_artist = g_strdup(artist);
		js->old_title = g_strdup(title);
		js->old_source = g_strdup(source);
		js->old_uri = g_strdup(uri);
		js->old_length = length;
		js->old_track = g_strdup(track);
	}

#undef CHANGED

	jabber_presence_fake_to_self(js, status);
}