Mercurial > pidgin
comparison src/protocols/jabber/jabber.c @ 4745:01cae9259e2f
[gaim-migrate @ 5060]
fixes a bug where if all your accounts got logged off, thus making the
buddy list disappear, you could never get it back. That makes for a bad
time when your internet connection goes out (like mine did last night)
also makes some of the prpl tooltips spiffier, and re-does some of the
handling of away messages in jabber, thus making it cooler.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 13 Mar 2003 17:52:21 +0000 |
parents | a0746ffce599 |
children | 92ae181271e9 |
comparison
equal
deleted
inserted
replaced
4744:a0746ffce599 | 4745:01cae9259e2f |
---|---|
1134 */ | 1134 */ |
1135 static char *jabber_lookup_away(gjconn gjc, char *name) | 1135 static char *jabber_lookup_away(gjconn gjc, char *name) |
1136 { | 1136 { |
1137 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | 1137 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); |
1138 | 1138 |
1139 if(!jri || !jri->away_msg) | 1139 if(!jri) |
1140 return _("Unknown"); | 1140 return _("Unknown"); |
1141 | 1141 |
1142 return jri->away_msg; | 1142 return jri->away_msg; |
1143 } | 1143 } |
1144 static const char *jabber_get_state_string(int s) { | |
1145 switch(s) { | |
1146 case UC_AWAY: | |
1147 return _("Away"); | |
1148 case UC_CHAT: | |
1149 return _("Chatty"); | |
1150 case UC_XA: | |
1151 return _("Extended Away"); | |
1152 case UC_DND: | |
1153 return _("Do Not Disturb"); | |
1154 default: | |
1155 return _("Available"); | |
1156 } | |
1157 } | |
1144 | 1158 |
1145 static void jabber_track_away(gjconn gjc, jpacket p, char *type) | 1159 static void jabber_track_away(gjconn gjc, jpacket p, char *type) |
1146 { | 1160 { |
1147 char *show; | |
1148 char *vshow = NULL; | |
1149 char *status = NULL; | |
1150 char *msg = NULL; | |
1151 jab_res_info jri = NULL; | 1161 jab_res_info jri = NULL; |
1152 | 1162 |
1153 if(!p || !p->from || !p->from->user) | 1163 if(!p || !p->from || !p->from->user) |
1154 return; | 1164 return; |
1155 | 1165 |
1156 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); | 1166 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); |
1157 | 1167 |
1158 if(!jri) | 1168 if(!jri) |
1159 return; | 1169 return; |
1160 | 1170 |
1161 if (type && (strcasecmp(type, "unavailable") == 0)) { | |
1162 vshow = _("Unavailable"); | |
1163 } else { | |
1164 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) { | |
1165 if (!strcasecmp(show, "away")) { | |
1166 vshow = _("Away"); | |
1167 } else if (!strcasecmp(show, "chat")) { | |
1168 vshow = _("Online"); | |
1169 } else if (!strcasecmp(show, "xa")) { | |
1170 vshow = _("Extended Away"); | |
1171 } else if (!strcasecmp(show, "dnd")) { | |
1172 vshow = _("Do Not Disturb"); | |
1173 } | |
1174 } | |
1175 } | |
1176 | |
1177 status = g_strdup(xmlnode_get_tag_data(p->x, "status")); | |
1178 | |
1179 if(vshow != NULL || status != NULL ) { | |
1180 /* kinda hokey, but it works :-) */ | |
1181 msg = g_strdup_printf("%s%s%s", | |
1182 (vshow == NULL? "" : vshow), | |
1183 (vshow == NULL || status == NULL? "" : ": "), | |
1184 (status == NULL? "" : status)); | |
1185 } else { | |
1186 msg = g_strdup(_("Online")); | |
1187 } | |
1188 | |
1189 g_free(status); | |
1190 | |
1191 if(jri->away_msg) | 1171 if(jri->away_msg) |
1192 g_free(jri->away_msg); | 1172 g_free(jri->away_msg); |
1193 | 1173 |
1194 jri->away_msg = msg; | 1174 jri->away_msg = g_strdup(xmlnode_get_tag_data(p->x, "status")); |
1195 } | 1175 } |
1196 | 1176 |
1197 static void jabber_convo_closed(struct gaim_connection *gc, char *name) | 1177 static void jabber_convo_closed(struct gaim_connection *gc, char *name) |
1198 { | 1178 { |
1199 jab_res_info jri = jabber_find_resource(gc, name); | 1179 jab_res_info jri = jabber_find_resource(gc, name); |
3153 jab_res_info jri = resources->data; | 3133 jab_res_info jri = resources->data; |
3154 char *status; | 3134 char *status; |
3155 realwho = g_strdup_printf("%s/%s", buddy, jri->name); | 3135 realwho = g_strdup_printf("%s/%s", buddy, jri->name); |
3156 status = strdup_withhtml(jabber_lookup_away(gjc, realwho)); | 3136 status = strdup_withhtml(jabber_lookup_away(gjc, realwho)); |
3157 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | 3137 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); |
3158 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status); | 3138 *ap++ = g_strdup_printf("<B>Status:</B> %s%s%s<BR>\n", jabber_get_state_string(jri->state), status ? ": " : "", status ? status : ""); |
3159 g_free(status); | 3139 g_free(status); |
3160 g_free(realwho); | 3140 g_free(realwho); |
3161 resources = resources->next; | 3141 resources = resources->next; |
3162 } | 3142 } |
3163 | 3143 |
3202 | 3182 |
3203 } | 3183 } |
3204 | 3184 |
3205 static char *jabber_tooltip_text(struct buddy *b) | 3185 static char *jabber_tooltip_text(struct buddy *b) |
3206 { | 3186 { |
3207 struct jabber_data *jd = b->account->gc->proto_data; | 3187 jab_res_info jri = jabber_find_resource(b->account->gc, b->name); |
3208 char *text = jabber_lookup_away(jd->gjc, b->name); | 3188 if(jri) { |
3209 if (text) | 3189 char *text = strip_html(jabber_lookup_away(GC_GJ(b->account->gc), |
3210 return strip_html(text); | 3190 b->name)); |
3191 char *ret = g_strdup_printf(_("<b>Status:</b> %s%s%s"), | |
3192 jabber_get_state_string(jri->state), text ? ": " : "", | |
3193 text ? text : ""); | |
3194 | |
3195 if(text) | |
3196 g_free(text); | |
3197 return ret; | |
3198 } | |
3211 return NULL; | 3199 return NULL; |
3212 } | 3200 } |
3213 | 3201 |
3214 static char *jabber_status_text(struct buddy *b) | 3202 static char *jabber_status_text(struct buddy *b) |
3215 { | 3203 { |
3216 struct jabber_data *jd = b->account->gc->proto_data; | |
3217 if (b->uc & UC_UNAVAILABLE) { | 3204 if (b->uc & UC_UNAVAILABLE) { |
3218 return strip_html(jabber_lookup_away(jd->gjc, b->name)); | 3205 char *ret = strip_html(jabber_lookup_away(GC_GJ(b->account->gc), |
3206 b->name)); | |
3207 if(!ret) { | |
3208 jab_res_info jri = jabber_find_resource(b->account->gc, b->name); | |
3209 if(jri) | |
3210 ret = g_strdup(jabber_get_state_string(jri->state)); | |
3211 } | |
3212 return ret; | |
3219 } | 3213 } |
3220 return NULL; | 3214 return NULL; |
3221 } | 3215 } |
3222 | 3216 |
3223 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { | 3217 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { |
3539 gchar **str_arr = (gchar **) g_new(gpointer, | 3533 gchar **str_arr = (gchar **) g_new(gpointer, |
3540 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3); | 3534 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3); |
3541 gchar **ap = str_arr; | 3535 gchar **ap = str_arr; |
3542 gchar *buddy, *final; | 3536 gchar *buddy, *final; |
3543 | 3537 |
3538 jab_res_info jri; | |
3539 | |
3544 if((buddy = get_realwho(gjc, from, TRUE, NULL)) == NULL) { | 3540 if((buddy = get_realwho(gjc, from, TRUE, NULL)) == NULL) { |
3545 g_strfreev(str_arr); | 3541 g_strfreev(str_arr); |
3546 return; | 3542 return; |
3547 } | 3543 } |
3544 | |
3545 jri = jabber_find_resource(GJ_GC(gjc), buddy); | |
3548 | 3546 |
3549 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy); | 3547 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy); |
3550 | 3548 |
3551 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | 3549 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { |
3552 if(strcmp(vc_tp->tag, "DESC") == 0) | 3550 if(strcmp(vc_tp->tag, "DESC") == 0) |
3567 g_free(fmt); | 3565 g_free(fmt); |
3568 } | 3566 } |
3569 } | 3567 } |
3570 } | 3568 } |
3571 | 3569 |
3570 | |
3572 status = strdup_withhtml(jabber_lookup_away(gjc, buddy)); | 3571 status = strdup_withhtml(jabber_lookup_away(gjc, buddy)); |
3573 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status); | 3572 *ap++ = g_strdup_printf("<B>Status:</B> %s%s%s<BR>\n", |
3573 jri ? jabber_get_state_string(jri->state) : "", | |
3574 jri && status ? ": " : "", status ? status : ""); | |
3574 g_free(status); | 3575 g_free(status); |
3575 | 3576 |
3576 /* | 3577 /* |
3577 * "Description" handled as a special case: get a copy of the | 3578 * "Description" handled as a special case: get a copy of the |
3578 * string and HTML-ize. | 3579 * string and HTML-ize. |