comparison src/protocols/jabber/jabber.c @ 4359:5fb47ec9bfe4

[gaim-migrate @ 4625] Wow, okay, where to begin with this one ;) I rewrote the whole conversation backend. It is now core/UI split. Here's how it works.. Every conversation is represented by a gaim_conversation structure. This branches out into gaim_im and gaim_chat structures. Every conversation lives in (well, normally, but it doesn't have to) a gaim_window structure. This is a _CORE_ representation of a window. There can be multiple gaim_window structures around. The gaim_window and gaim_conversation structures have UI-specific operation structures associated with them. At the moment, the only UI is GTK+, and this will be for some time. Don't start thinking you can write a QT UI now. It's just not going to happen. Everything that is done on a conversation is done through the core API. This API does core processing and then calls the UI operations for the rendering and anything else. Now, what does this give the user? - Multiple windows. - Multiple tabs per window. - Draggable tabs. - Send As menu is moved to the menubar. - Menubar for chats. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. For developers: - Fully documented API - Core/UI split - Variable checking and mostly sane handling of incorrect variables. - Logical structure to conversations, both core and UI. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. - Oh yeah, and the beginning of a stock icon system. Now, there are things that aren't there yet. You will see tabs even if you have them turned off. This will be fixed in time. Also, the preferences will change to work with the new structure. I'm starting school in 2 days, so it may not be done immediately, but hopefully in the next week. Enjoy! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 20 Jan 2003 09:10:23 +0000
parents 367fc70fe4f7
children 7ba9b56a8796
comparison
equal deleted inserted replaced
4358:2b8abf7f9cc1 4359:5fb47ec9bfe4
217 * pending and existing chats lists. 217 * pending and existing chats lists.
218 */ 218 */
219 struct jabber_chat { 219 struct jabber_chat {
220 gaim_jid gjid; 220 gaim_jid gjid;
221 struct gaim_connection *gc; 221 struct gaim_connection *gc;
222 struct conversation *b; 222 struct gaim_conversation *b;
223 int id; 223 int id;
224 int state; 224 int state;
225 }; 225 };
226 226
227 /* 227 /*
819 } 819 }
820 820
821 /* 821 /*
822 * Find chat by chat group name 822 * Find chat by chat group name
823 */ 823 */
824 static struct conversation *find_chat(struct gaim_connection *gc, char *name) 824 static struct gaim_conversation *find_chat(struct gaim_connection *gc, char *name)
825 { 825 {
826 GSList *bcs = gc->buddy_chats; 826 GSList *bcs = gc->buddy_chats;
827 struct conversation *b = NULL; 827 struct gaim_conversation *b = NULL;
828 char *chat = g_strdup(normalize(name)); 828 char *chat = g_strdup(normalize(name));
829 829
830 while (bcs) { 830 while (bcs) {
831 b = bcs->data; 831 b = bcs->data;
832 if (!strcasecmp(normalize(b->name), chat)) 832 if (!strcasecmp(normalize(b->name), chat))
852 * was, so that's the way I'm leaving it--for now. 852 * was, so that's the way I'm leaving it--for now.
853 */ 853 */
854 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc) 854 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc)
855 { 855 {
856 GSList *bcs = gc->buddy_chats; 856 GSList *bcs = gc->buddy_chats;
857 struct conversation *b = NULL; 857 struct gaim_conversation *b = NULL;
858 struct jabber_data *jd = gc->proto_data; 858 struct jabber_data *jd = gc->proto_data;
859 859
860 *jc = NULL; 860 *jc = NULL;
861 861
862 while(bcs != NULL) { 862 while(bcs != NULL) {
863 b = bcs->data; 863 b = bcs->data;
864 if (id == b->id) 864 if (id == gaim_chat_get_id(GAIM_CHAT(b)))
865 break; 865 break;
866 bcs = bcs->next; 866 bcs = bcs->next;
867 } 867 }
868 868
869 if (bcs != NULL) { 869 if (bcs != NULL) {
935 } 935 }
936 936
937 return jc; 937 return jc;
938 } 938 }
939 939
940 static gboolean find_chat_buddy(struct conversation *b, char *name) 940 static gboolean find_chat_buddy(struct gaim_conversation *b, char *name)
941 { 941 {
942 GList *m = b->in_room; 942 GList *m = gaim_chat_get_users(GAIM_CHAT(b));
943 943
944 while (m) { 944 while (m) {
945 if (!strcmp(m->data, name)) 945 if (!strcmp(m->data, name))
946 return TRUE; 946 return TRUE;
947 m = m->next; 947 m = m->next;
1322 serv_got_chat_invite(GJ_GC(gjc), conference_room, from, msg, m); 1322 serv_got_chat_invite(GJ_GC(gjc), conference_room, from, msg, m);
1323 } else if (msg) { /* whisper */ 1323 } else if (msg) { /* whisper */
1324 struct jabber_chat *jc; 1324 struct jabber_chat *jc;
1325 g_snprintf(m, sizeof(m), "%s", msg); 1325 g_snprintf(m, sizeof(m), "%s", msg);
1326 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) 1326 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b)
1327 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, 1327 serv_got_chat_in(GJ_GC(gjc),
1328 time_sent); 1328 gaim_chat_get_id(GAIM_CHAT(jc->b)),
1329 p->from->resource, 1, m, time_sent);
1329 else { 1330 else {
1330 int flags = 0; 1331 int flags = 0;
1331 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from); 1332 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from);
1332 if(jri && typing) 1333 if(jri && typing)
1333 jri->has_composing = TRUE; 1334 jri->has_composing = TRUE;
1334 if (xmlnode_get_tag(p->x, "gaim")) 1335 if (xmlnode_get_tag(p->x, "gaim"))
1335 flags = IM_FLAG_GAIMUSER; 1336 flags = IM_FLAG_GAIMUSER;
1336 jabber_track_convo_thread(gjc, from, thread_id); 1337 jabber_track_convo_thread(gjc, from, thread_id);
1337 if (find_conversation(from)) 1338 if (gaim_find_conversation(from))
1338 serv_got_im(GJ_GC(gjc), from, m, flags, 1339 serv_got_im(GJ_GC(gjc), from, m, flags,
1339 time_sent, -1); 1340 time_sent, -1);
1340 else { 1341 else {
1341 if(p->from->user) { 1342 if(p->from->user) {
1342 from = g_strdup_printf("%s@%s", p->from->user, 1343 from = g_strdup_printf("%s@%s", p->from->user,
1391 if (!jc) { 1392 if (!jc) {
1392 /* we're not in this chat. are we supposed to be? */ 1393 /* we're not in this chat. are we supposed to be? */
1393 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { 1394 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) {
1394 /* yes, we're supposed to be. so now we are. */ 1395 /* yes, we're supposed to be. so now we are. */
1395 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user); 1396 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user);
1396 jc->id = jc->b->id; 1397 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b));
1397 jc->state = JCS_ACTIVE; 1398 jc->state = JCS_ACTIVE;
1398 } else { 1399 } else {
1399 /* no, we're not supposed to be. */ 1400 /* no, we're not supposed to be. */
1400 g_free(msg); 1401 g_free(msg);
1401 return; 1402 return;
1402 } 1403 }
1403 } 1404 }
1404 if (p->from->resource) { 1405 if (p->from->resource) {
1405 if (!y) { 1406 if (!y) {
1406 if (!find_chat_buddy(jc->b, p->from->resource)) { 1407 if (!find_chat_buddy(jc->b, p->from->resource)) {
1407 add_chat_buddy(jc->b, p->from->resource, NULL); 1408 gaim_chat_add_user(GAIM_CHAT(jc->b),
1409 p->from->resource, NULL);
1408 } else if ((y = xmlnode_get_tag(p->x, "status"))) { 1410 } else if ((y = xmlnode_get_tag(p->x, "status"))) {
1409 jabber_track_away(gjc, p, NULL); 1411 jabber_track_away(gjc, p, NULL);
1410 } 1412 }
1411 } else if (jc->b && msg) { 1413 } else if (jc->b && msg) {
1412 char buf[8192]; 1414 char buf[8192];
1413 1415
1414 if (topic) { 1416 if (topic) {
1415 char tbuf[8192]; 1417 char tbuf[8192];
1416 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); 1418 g_snprintf(tbuf, sizeof(tbuf), "%s", topic);
1417 chat_set_topic(jc->b, p->from->resource, tbuf); 1419 gaim_chat_set_topic(GAIM_CHAT(jc->b),
1420 p->from->resource, tbuf);
1418 } 1421 }
1419 1422
1420 g_snprintf(buf, sizeof(buf), "%s", msg); 1423 g_snprintf(buf, sizeof(buf), "%s", msg);
1421 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, 1424 serv_got_chat_in(GJ_GC(gjc),
1422 time_sent); 1425 gaim_chat_get_id(GAIM_CHAT(jc->b)),
1426 p->from->resource, 0, buf, time_sent);
1423 } 1427 }
1424 } else { /* message from the server */ 1428 } else { /* message from the server */
1425 if(jc->b && topic) { 1429 if(jc->b && topic) {
1426 char tbuf[8192]; 1430 char tbuf[8192];
1427 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); 1431 g_snprintf(tbuf, sizeof(tbuf), "%s", topic);
1428 chat_set_topic(jc->b, "", tbuf); 1432 gaim_chat_set_topic(GAIM_CHAT(jc->b), "", tbuf);
1429 } 1433 }
1430 } 1434 }
1431 1435
1432 } else { 1436 } else {
1433 debug_printf("unhandled message %s\n", type); 1437 debug_printf("unhandled message %s\n", type);
1441 gaim_jid gjid; 1445 gaim_jid gjid;
1442 char *buddy; 1446 char *buddy;
1443 xmlnode y; 1447 xmlnode y;
1444 char *show; 1448 char *show;
1445 int state = 0; 1449 int state = 0;
1446 struct conversation *cnv = NULL; 1450 struct gaim_conversation *cnv = NULL;
1447 struct jabber_chat *jc = NULL; 1451 struct jabber_chat *jc = NULL;
1448 int priority = 0; 1452 int priority = 0;
1449 struct jabber_buddy_data *jbd; 1453 struct jabber_buddy_data *jbd;
1450 1454
1451 to = xmlnode_get_attrib(p->x, "to"); 1455 to = xmlnode_get_attrib(p->x, "to");
1504 * buddy on our list, simply bail out. */ 1508 * buddy on our list, simply bail out. */
1505 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) { 1509 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) {
1506 static int i = 0x70; 1510 static int i = 0x70;
1507 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) { 1511 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) {
1508 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user); 1512 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user);
1509 jc->id = jc->b->id; 1513 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b));
1510 jc->state = JCS_ACTIVE; 1514 jc->state = JCS_ACTIVE;
1511 } else if ((b = find_buddy(GJ_GC(gjc)->user, buddy)) == NULL) { 1515 } else if ((b = find_buddy(GJ_GC(gjc)->user, buddy)) == NULL) {
1512 g_free(buddy); 1516 g_free(buddy);
1513 gaim_jid_free(gjid); 1517 gaim_jid_free(gjid);
1514 return; 1518 return;
1543 return; 1547 return;
1544 } 1548 }
1545 jd = jc->gc->proto_data; 1549 jd = jc->gc->proto_data;
1546 /* if it's not ourselves...*/ 1550 /* if it's not ourselves...*/
1547 if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) { 1551 if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) {
1548 remove_chat_buddy(jc->b, gjid->resource, NULL); 1552 gaim_chat_remove_user(GAIM_CHAT(jc->b), gjid->resource,
1553 NULL);
1549 g_free(buddy); 1554 g_free(buddy);
1550 gaim_jid_free(gjid); 1555 gaim_jid_free(gjid);
1551 return; 1556 return;
1552 } 1557 }
1553 1558
1563 g_free(buddy); 1568 g_free(buddy);
1564 gaim_jid_free(gjid); 1569 gaim_jid_free(gjid);
1565 return; 1570 return;
1566 } 1571 }
1567 if (!find_chat_buddy(jc->b, gjid->resource)) { 1572 if (!find_chat_buddy(jc->b, gjid->resource)) {
1568 add_chat_buddy(jc->b, gjid->resource, NULL); 1573 gaim_chat_add_user(GAIM_CHAT(jc->b), gjid->resource, NULL);
1569 } 1574 }
1570 } 1575 }
1571 } 1576 }
1572 } 1577 }
1573 1578