comparison src/conversation.c @ 14035:8bda65b88e49

[gaim-migrate @ 16638] A bunch of small changes. Mostly remove "if not null" checks before calling g_free, g_list_free, g_slist_free and g_strdup. Also use g_list_foreach() to call g_free to free strings in an array. And some whitespace changes here and there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 05 Aug 2006 08:27:39 +0000
parents 1c411ca5590c
children
comparison
equal deleted inserted replaced
14034:0839a7b71325 14035:8bda65b88e49
333 { 333 {
334 GaimPluginProtocolInfo *prpl_info = NULL; 334 GaimPluginProtocolInfo *prpl_info = NULL;
335 GaimConversationUiOps *ops; 335 GaimConversationUiOps *ops;
336 GaimConnection *gc; 336 GaimConnection *gc;
337 const char *name; 337 const char *name;
338 GList *node;
339 338
340 g_return_if_fail(conv != NULL); 339 g_return_if_fail(conv != NULL);
341 340
342 ops = gaim_conversation_get_ui_ops(conv); 341 ops = gaim_conversation_get_ui_ops(conv);
343 gc = gaim_conversation_get_gc(conv); 342 gc = gaim_conversation_get_gc(conv);
431 g_free(conv->u.im); 430 g_free(conv->u.im);
432 conv->u.im = NULL; 431 conv->u.im = NULL;
433 } 432 }
434 else if (conv->type == GAIM_CONV_TYPE_CHAT) { 433 else if (conv->type == GAIM_CONV_TYPE_CHAT) {
435 434
436 for (node = conv->u.chat->in_room; node != NULL; node = node->next) { 435 g_list_foreach(conv->u.chat->in_room, (GFunc)gaim_conv_chat_cb_destroy, NULL);
437 if (node->data != NULL)
438 gaim_conv_chat_cb_destroy((GaimConvChatBuddy *)node->data);
439 node->data = NULL;
440 }
441
442 for (node = conv->u.chat->ignored; node != NULL; node = node->next) {
443 if (node->data != NULL)
444 g_free(node->data);
445 node->data = NULL;
446 }
447
448 g_list_free(conv->u.chat->in_room); 436 g_list_free(conv->u.chat->in_room);
437
438 g_list_foreach(conv->u.chat->ignored, (GFunc)g_free, NULL);
449 g_list_free(conv->u.chat->ignored); 439 g_list_free(conv->u.chat->ignored);
450 440
451 conv->u.chat->in_room = NULL; 441 conv->u.chat->in_room = NULL;
452 conv->u.chat->ignored = NULL; 442 conv->u.chat->ignored = NULL;
453 443
454 if (conv->u.chat->who != NULL) 444 g_free(conv->u.chat->who);
455 g_free(conv->u.chat->who);
456 conv->u.chat->who = NULL; 445 conv->u.chat->who = NULL;
457 446
458 if (conv->u.chat->topic != NULL) 447 g_free(conv->u.chat->topic);
459 g_free(conv->u.chat->topic);
460 conv->u.chat->topic = NULL; 448 conv->u.chat->topic = NULL;
461 449
462 if(conv->u.chat->nick) 450 g_free(conv->u.chat->nick);
463 g_free(conv->u.chat->nick);
464 451
465 GAIM_DBUS_UNREGISTER_POINTER(conv->u.chat); 452 GAIM_DBUS_UNREGISTER_POINTER(conv->u.chat);
466 g_free(conv->u.chat); 453 g_free(conv->u.chat);
467 conv->u.chat = NULL; 454 conv->u.chat = NULL;
468 } 455 }
585 gaim_conversation_set_title(GaimConversation *conv, const char *title) 572 gaim_conversation_set_title(GaimConversation *conv, const char *title)
586 { 573 {
587 g_return_if_fail(conv != NULL); 574 g_return_if_fail(conv != NULL);
588 g_return_if_fail(title != NULL); 575 g_return_if_fail(title != NULL);
589 576
590 if (conv->title != NULL) 577 g_free(conv->title);
591 g_free(conv->title);
592
593 conv->title = g_strdup(title); 578 conv->title = g_strdup(title);
594 579
595 gaim_conversation_update(conv, GAIM_CONV_UPDATE_TITLE); 580 gaim_conversation_update(conv, GAIM_CONV_UPDATE_TITLE);
596 } 581 }
597 582
649 void 634 void
650 gaim_conversation_set_name(GaimConversation *conv, const char *name) 635 gaim_conversation_set_name(GaimConversation *conv, const char *name)
651 { 636 {
652 g_return_if_fail(conv != NULL); 637 g_return_if_fail(conv != NULL);
653 638
654 if (conv->name != NULL) 639 g_free(conv->name);
655 g_free(conv->name); 640 conv->name = g_strdup(name);
656
657 conv->name = (name == NULL ? NULL : g_strdup(name));
658 641
659 gaim_conversation_autoset_title(conv); 642 gaim_conversation_autoset_title(conv);
660 } 643 }
661 644
662 const char * 645 const char *
1324 void 1307 void
1325 gaim_conv_chat_set_topic(GaimConvChat *chat, const char *who, const char *topic) 1308 gaim_conv_chat_set_topic(GaimConvChat *chat, const char *who, const char *topic)
1326 { 1309 {
1327 g_return_if_fail(chat != NULL); 1310 g_return_if_fail(chat != NULL);
1328 1311
1329 if (chat->who != NULL) g_free(chat->who); 1312 g_free(chat->who);
1330 if (chat->topic != NULL) g_free(chat->topic); 1313 g_free(chat->topic);
1331 1314
1332 chat->who = (who == NULL ? NULL : g_strdup(who)); 1315 chat->who = g_strdup(who);
1333 chat->topic = (topic == NULL ? NULL : g_strdup(topic)); 1316 chat->topic = g_strdup(topic);
1334 1317
1335 gaim_conversation_update(gaim_conv_chat_get_conversation(chat), 1318 gaim_conversation_update(gaim_conv_chat_get_conversation(chat),
1336 GAIM_CONV_UPDATE_TOPIC); 1319 GAIM_CONV_UPDATE_TOPIC);
1337 1320
1338 gaim_signal_emit(gaim_conversations_get_handle(), "chat-topic-changed", 1321 gaim_signal_emit(gaim_conversations_get_handle(), "chat-topic-changed",
1445 { 1428 {
1446 GaimConvChatBuddyFlags f1 = 0, f2 = 0; 1429 GaimConvChatBuddyFlags f1 = 0, f2 = 0;
1447 char *user1 = NULL, *user2 = NULL; 1430 char *user1 = NULL, *user2 = NULL;
1448 gint ret = 0; 1431 gint ret = 0;
1449 1432
1450
1451 if (a) { 1433 if (a) {
1452 f1 = a->flags; 1434 f1 = a->flags;
1453 if (a->alias_key) 1435 if (a->alias_key)
1454 user1 = a->alias_key; 1436 user1 = a->alias_key;
1455 else if (a->name) 1437 else if (a->name)
1456 user1 = a->name; 1438 user1 = a->name;
1457 } 1439 }
1458 1440
1459 if (b) { 1441 if (b) {
1460 f2 = b->flags; 1442 f2 = b->flags;
1461 if (b->alias_key) 1443 if (b->alias_key)
1462 user2 = b->alias_key; 1444 user2 = b->alias_key;
1463 else if (b->name) 1445 else if (b->name)
1468 if (!(user1 == NULL && user2 == NULL)) 1450 if (!(user1 == NULL && user2 == NULL))
1469 ret = (user1 == NULL) ? -1: 1; 1451 ret = (user1 == NULL) ? -1: 1;
1470 } else if (f1 != f2) { 1452 } else if (f1 != f2) {
1471 /* sort more important users first */ 1453 /* sort more important users first */
1472 ret = (f1 > f2) ? -1 : 1; 1454 ret = (f1 > f2) ? -1 : 1;
1473 } else if (a->buddy != b->buddy) { 1455 } else if (a->buddy != b->buddy) {
1474 ret = a->buddy ? -1 : 1; 1456 ret = a->buddy ? -1 : 1;
1475 } else { 1457 } else {
1476 ret = strcasecmp(user1, user2); 1458 ret = strcasecmp(user1, user2);
1477 } 1459 }
1478 1460
1563 if (extra_msgs != NULL) 1545 if (extra_msgs != NULL)
1564 extra_msgs = extra_msgs->next; 1546 extra_msgs = extra_msgs->next;
1565 } 1547 }
1566 1548
1567 cbuddies = g_list_sort(cbuddies, (GCompareFunc)gaim_conv_chat_cb_compare); 1549 cbuddies = g_list_sort(cbuddies, (GCompareFunc)gaim_conv_chat_cb_compare);
1568 1550
1569 if (ops != NULL && ops->chat_add_users != NULL) 1551 if (ops != NULL && ops->chat_add_users != NULL)
1570 ops->chat_add_users(conv, cbuddies, new_arrivals); 1552 ops->chat_add_users(conv, cbuddies, new_arrivals);
1571 1553
1572 g_list_free(cbuddies); 1554 g_list_free(cbuddies);
1573 } 1555 }
1726 g_list_remove(gaim_conv_chat_get_users(chat), cb)); 1708 g_list_remove(gaim_conv_chat_get_users(chat), cb));
1727 gaim_conv_chat_cb_destroy(cb); 1709 gaim_conv_chat_cb_destroy(cb);
1728 } 1710 }
1729 1711
1730 /* NOTE: Don't remove them from ignored in case they re-enter. */ 1712 /* NOTE: Don't remove them from ignored in case they re-enter. */
1731 1713
1732 if (!quiet) { 1714 if (!quiet) {
1733 const char *alias = user; 1715 const char *alias = user;
1734 char *escaped; 1716 char *escaped;
1735 char *tmp; 1717 char *tmp;
1736 1718
1864 } 1846 }
1865 1847
1866 void gaim_conv_chat_set_nick(GaimConvChat *chat, const char *nick) { 1848 void gaim_conv_chat_set_nick(GaimConvChat *chat, const char *nick) {
1867 g_return_if_fail(chat != NULL); 1849 g_return_if_fail(chat != NULL);
1868 1850
1869 if(chat->nick) 1851 g_free(chat->nick);
1870 g_free(chat->nick);
1871 chat->nick = g_strdup(gaim_normalize(chat->conv->account, nick)); 1852 chat->nick = g_strdup(gaim_normalize(chat->conv->account, nick));
1872 } 1853 }
1873 1854
1874 const char *gaim_conv_chat_get_nick(GaimConvChat *chat) { 1855 const char *gaim_conv_chat_get_nick(GaimConvChat *chat) {
1875 g_return_val_if_fail(chat != NULL, NULL); 1856 g_return_val_if_fail(chat != NULL, NULL);
1918 g_return_val_if_fail(name != NULL, NULL); 1899 g_return_val_if_fail(name != NULL, NULL);
1919 1900
1920 cb = g_new0(GaimConvChatBuddy, 1); 1901 cb = g_new0(GaimConvChatBuddy, 1);
1921 cb->name = g_strdup(name); 1902 cb->name = g_strdup(name);
1922 cb->flags = flags; 1903 cb->flags = flags;
1923 if (alias) 1904 cb->alias = g_strdup(alias);
1924 cb->alias = g_strdup(alias);
1925 else
1926 cb->alias = NULL;
1927 1905
1928 GAIM_DBUS_REGISTER_POINTER(cb, GaimConvChatBuddy); 1906 GAIM_DBUS_REGISTER_POINTER(cb, GaimConvChatBuddy);
1929 return cb; 1907 return cb;
1930 } 1908 }
1931 1909
1948 } 1926 }
1949 1927
1950 void 1928 void
1951 gaim_conv_chat_cb_destroy(GaimConvChatBuddy *cb) 1929 gaim_conv_chat_cb_destroy(GaimConvChatBuddy *cb)
1952 { 1930 {
1953 g_return_if_fail(cb != NULL); 1931 if (cb == NULL)
1932 return;
1954 1933
1955 g_free(cb->alias); 1934 g_free(cb->alias);
1956 g_free(cb->alias_key); 1935 g_free(cb->alias_key);
1957 g_free(cb->name); 1936 g_free(cb->name);
1958 cb->name = NULL;
1959 cb->alias = NULL;
1960 cb->alias_key = NULL;
1961 cb->flags = 0;
1962 1937
1963 GAIM_DBUS_UNREGISTER_POINTER(cb); 1938 GAIM_DBUS_UNREGISTER_POINTER(cb);
1964 g_free(cb); 1939 g_free(cb);
1965 } 1940 }
1966 1941