Mercurial > pidgin.yaz
changeset 10196:760e690a5f30
[gaim-migrate @ 11313]
A few steps closer to being able to set an oscar away message.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 16 Nov 2004 23:29:53 +0000 |
parents | fa4973f356a1 |
children | 7369bf2bf593 |
files | src/account.c src/protocols/oscar/oscar.c src/status.c |
diffstat | 3 files changed, 101 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/src/account.c Tue Nov 16 03:56:09 2004 +0000 +++ b/src/account.c Tue Nov 16 23:29:53 2004 +0000 @@ -553,6 +553,11 @@ gboolean active, ...) { GaimStatus *status; + gboolean changed = FALSE; + va_list args; + const char *id, *string_data; + int int_data; + gboolean boolean_data; g_return_if_fail(account != NULL); g_return_if_fail(status_id != NULL); @@ -575,7 +580,52 @@ return; } - if (gaim_status_is_active(status) == active) + if (gaim_status_is_active(status) != active) + changed = TRUE; + + /* Set any attributes */ + va_start(args, active); + while ((id = va_arg(args, const char *)) != NULL) + { + GaimValue *value; + value = gaim_status_get_attr_value(status, id); + if (value->type == GAIM_TYPE_STRING) + { + string_data = va_arg(args, const char *); + if (((string_data == NULL) && (value->data.string_data == NULL)) || + ((string_data != NULL) && (value->data.string_data != NULL) && + !strcmp(string_data, value->data.string_data))) + { + continue; + } + gaim_status_set_attr_string(status, id, string_data); + changed = TRUE; + } + else if (value->type == GAIM_TYPE_INT) + { + int_data = va_arg(args, int); + if (int_data == value->data.int_data) + continue; + gaim_status_set_attr_int(status, id, int_data); + changed = TRUE; + } + else if (value->type == GAIM_TYPE_BOOLEAN) + { + boolean_data = va_arg(args, gboolean); + if (boolean_data == value->data.boolean_data) + continue; + gaim_status_set_attr_int(status, id, boolean_data); + changed = TRUE; + } + else + { + /* We don't know what the data is--skip over it */ + va_arg(args, void *); + } + } + va_end(args); + + if (!changed) return; gaim_status_set_active(status, active);
--- a/src/protocols/oscar/oscar.c Tue Nov 16 03:56:09 2004 +0000 +++ b/src/protocols/oscar/oscar.c Tue Nov 16 23:29:53 2004 +0000 @@ -5549,7 +5549,7 @@ GaimPresence *presence; const gchar *status_id; int charset = 0; - gchar *text_html = NULL; + const gchar *text_html = NULL; char *msg = NULL; gsize msglen = 0; @@ -5558,14 +5558,13 @@ status_id = gaim_status_get_id(status); presence = gaim_account_get_presence(account); + gaim_debug_info("oscar", "Setting status to %s\n", status_id); + if (primitive == GAIM_STATUS_HIDDEN) aim_setextstatus(od->sess, AIM_ICQ_STATE_INVISIBLE); else aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL); - - aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL); - if (od->rights.maxawaymsglen == 0) gaim_notify_warning(gc, NULL, _("Unable to set AIM away message."), _("You have probably requested to set your " @@ -5578,56 +5577,49 @@ aim_locate_setprofile(od->sess, NULL, NULL, 0, NULL, "", 0); #if 0 /* Set an available message */ - aim_locate_setprofile(od->sess, NULL, NULL, 0, NULL, "", 0); aim_srv_setavailmsg(od->sess, text); #endif - return; - } - - /* - * XXX - Using status_id below is definitely wrong. We want to get - * the away message that the Gaim user just set. We probably want - * to get a certain attribute from status->attr_values, but I don't - * think any of that is implemented yet. - * - * Something like - * text_html = gaim_status_get_attr_string(status, "message"); - */ - status_id = gaim_status_get_name(status); - text_html = gaim_strdup_withhtml(status_id); - - charset = oscar_charset_check(text_html); - if (charset == AIM_CHARSET_UNICODE) { - msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); - aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg, - (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); - g_free(msg); - } else if (charset == AIM_CHARSET_CUSTOM) { - msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); - aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg, - (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); - g_free(msg); + + } else if (primitive == GAIM_STATUS_AWAY) { + text_html = gaim_status_get_attr_string(status, "message"); + + if (text_html == NULL) { + text_html = _("Away"); + } + + charset = oscar_charset_check(text_html); + if (charset == AIM_CHARSET_UNICODE) { + msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); + aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg, + (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); + g_free(msg); + } else if (charset == AIM_CHARSET_CUSTOM) { + msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); + aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg, + (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); + g_free(msg); + } else { + msglen = strlen(text_html); + aim_locate_setprofile(od->sess, NULL, NULL, 0, "us-ascii", text_html, + (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); + } + + if (msglen > od->rights.maxawaymsglen) { + gchar *errstr; + + errstr = g_strdup_printf(ngettext("The maximum away message length of %d byte " + "has been exceeded. Gaim has truncated it for you.", + "The maximum away message length of %d bytes " + "has been exceeded. Gaim has truncated it for you.", + od->rights.maxawaymsglen), od->rights.maxawaymsglen); + gaim_notify_warning(gc, NULL, _("Away message too long."), errstr); + g_free(errstr); + } + } else { - msglen = strlen(text_html); - aim_locate_setprofile(od->sess, NULL, NULL, 0, "us-ascii", text_html, - (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); - } - - if (msglen > od->rights.maxawaymsglen) { - gchar *errstr; - - errstr = g_strdup_printf(ngettext("The maximum away message length of %d byte " - "has been exceeded. Gaim has truncated it for you.", - "The maximum away message length of %d bytes " - "has been exceeded. Gaim has truncated it for you.", - od->rights.maxawaymsglen), od->rights.maxawaymsglen); - gaim_notify_warning(gc, NULL, _("Away message too long."), errstr); - g_free(errstr); - } - - g_free(text_html); - - return; + gaim_debug_info("oscar", "Don't know what to do for this status\n"); + + } } static void
--- a/src/status.c Tue Nov 16 03:56:09 2004 +0000 +++ b/src/status.c Tue Nov 16 23:29:53 2004 +0000 @@ -750,7 +750,7 @@ attr = gaim_status_type_get_attr(status_type, id); g_return_if_fail(attr != NULL); - attr_value = gaim_status_attr_get_value_type(attr); + attr_value = gaim_status_get_attr_value(status, id); g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING); gaim_value_set_string(attr_value, value); @@ -833,6 +833,12 @@ primitive != GAIM_STATUS_OFFLINE); } +/* + * What's the difference between + * gaim_status_get_attr_value(GaimStatus *status, const char *id) + * gaim_status_attr_get_value_type(GaimStatusAttr *attr) + * and I think there was another similar one... + */ GaimValue * gaim_status_get_attr_value(const GaimStatus *status, const char *id) {