Mercurial > pidgin
comparison src/gtkconv.c @ 13505:7a6763bbf82b
[gaim-migrate @ 15881]
On Mon, 2006-03-13 at 15:10 -0500, Adil wrote:
> Would it be `better' to not print an error message for the event
> (because it is possible to have a chat-window for a disconnected
> account), and popup a menu with disabled entries instead?
This commit implements that. I've also removed some code duplication by having create_chat_menu() look up the prpl_info from the gc.
Also, I think we should grey out the Send File menu item when a particular user doesn't have the ability to receive files, rather than not show it. It's more consistent with what we do elsewhere. I've made that change as well.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Tue, 14 Mar 2006 06:15:31 +0000 |
| parents | 2d2a52b0bfa5 |
| children | cd21f1738063 |
comparison
equal
deleted
inserted
replaced
| 13504:2d2a52b0bfa5 | 13505:7a6763bbf82b |
|---|---|
| 1533 else | 1533 else |
| 1534 g_return_if_reached(); | 1534 g_return_if_reached(); |
| 1535 } | 1535 } |
| 1536 | 1536 |
| 1537 static GtkWidget * | 1537 static GtkWidget * |
| 1538 create_chat_menu(GaimConversation *conv, const char *who, | 1538 create_chat_menu(GaimConversation *conv, const char *who, GaimConnection *gc) |
| 1539 GaimPluginProtocolInfo *prpl_info, GaimConnection *gc) | |
| 1540 { | 1539 { |
| 1541 static GtkWidget *menu = NULL; | 1540 static GtkWidget *menu = NULL; |
| 1541 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 1542 GaimConvChat *chat = GAIM_CONV_CHAT(conv); | 1542 GaimConvChat *chat = GAIM_CONV_CHAT(conv); |
| 1543 gboolean is_me = FALSE; | 1543 gboolean is_me = FALSE; |
| 1544 GtkWidget *button; | 1544 GtkWidget *button; |
| 1545 | |
| 1546 if (gc != NULL) | |
| 1547 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1545 | 1548 |
| 1546 /* | 1549 /* |
| 1547 * If a menu already exists, destroy it before creating a new one, | 1550 * If a menu already exists, destroy it before creating a new one, |
| 1548 * thus freeing-up the memory it occupied. | 1551 * thus freeing-up the memory it occupied. |
| 1549 */ | 1552 */ |
| 1556 menu = gtk_menu_new(); | 1559 menu = gtk_menu_new(); |
| 1557 | 1560 |
| 1558 if (!is_me) { | 1561 if (!is_me) { |
| 1559 button = gaim_new_item_from_stock(menu, _("IM"), GAIM_STOCK_IM, | 1562 button = gaim_new_item_from_stock(menu, _("IM"), GAIM_STOCK_IM, |
| 1560 G_CALLBACK(menu_chat_im_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1563 G_CALLBACK(menu_chat_im_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1564 | |
| 1565 if (gc == NULL) | |
| 1566 gtk_widget_set_sensitive(button, FALSE); | |
| 1567 | |
| 1561 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1568 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1562 | 1569 |
| 1563 if (prpl_info && prpl_info->send_file | 1570 |
| 1564 && (!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, who))) { | 1571 if (prpl_info && prpl_info->send_file) |
| 1572 { | |
| 1565 button = gaim_new_item_from_stock(menu, _("Send File"), | 1573 button = gaim_new_item_from_stock(menu, _("Send File"), |
| 1566 GAIM_STOCK_FILE_TRANSFER, G_CALLBACK(menu_chat_send_file_cb), | 1574 GAIM_STOCK_FILE_TRANSFER, G_CALLBACK(menu_chat_send_file_cb), |
| 1567 GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1575 GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1576 | |
| 1577 if (gc == NULL || prpl_info == NULL || | |
| 1578 !(!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, who))) | |
| 1579 { | |
| 1580 gtk_widget_set_sensitive(button, FALSE); | |
| 1581 } | |
| 1582 | |
| 1568 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1583 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1569 } | 1584 } |
| 1585 | |
| 1570 | 1586 |
| 1571 if (gaim_conv_chat_is_user_ignored(GAIM_CONV_CHAT(conv), who)) | 1587 if (gaim_conv_chat_is_user_ignored(GAIM_CONV_CHAT(conv), who)) |
| 1572 button = gaim_new_item_from_stock(menu, _("Un-Ignore"), GAIM_STOCK_IGNORE, | 1588 button = gaim_new_item_from_stock(menu, _("Un-Ignore"), GAIM_STOCK_IGNORE, |
| 1573 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1589 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1574 else | 1590 else |
| 1575 button = gaim_new_item_from_stock(menu, _("Ignore"), GAIM_STOCK_IGNORE, | 1591 button = gaim_new_item_from_stock(menu, _("Ignore"), GAIM_STOCK_IGNORE, |
| 1576 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1592 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1593 | |
| 1594 if (gc == NULL) | |
| 1595 gtk_widget_set_sensitive(button, FALSE); | |
| 1596 | |
| 1577 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1597 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1578 } | 1598 } |
| 1579 | 1599 |
| 1580 if (prpl_info && (prpl_info->get_info || prpl_info->get_cb_info)) { | 1600 if (prpl_info && (prpl_info->get_info || prpl_info->get_cb_info)) { |
| 1581 button = gaim_new_item_from_stock(menu, _("Info"), GAIM_STOCK_INFO, | 1601 button = gaim_new_item_from_stock(menu, _("Info"), GAIM_STOCK_INFO, |
| 1582 G_CALLBACK(menu_chat_info_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1602 G_CALLBACK(menu_chat_info_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1603 | |
| 1604 if (gc == NULL) | |
| 1605 gtk_widget_set_sensitive(button, FALSE); | |
| 1606 | |
| 1583 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1607 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1584 } | 1608 } |
| 1585 | 1609 |
| 1586 if (prpl_info && prpl_info->get_cb_away) { | 1610 if (prpl_info && prpl_info->get_cb_away) { |
| 1587 button = gaim_new_item_from_stock(menu, _("Get Away Message"), GAIM_STOCK_AWAY, | 1611 button = gaim_new_item_from_stock(menu, _("Get Away Message"), GAIM_STOCK_AWAY, |
| 1588 G_CALLBACK(menu_chat_get_away_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1612 G_CALLBACK(menu_chat_get_away_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1613 | |
| 1614 if (gc == NULL) | |
| 1615 gtk_widget_set_sensitive(button, FALSE); | |
| 1616 | |
| 1589 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1617 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1590 } | 1618 } |
| 1591 | 1619 |
| 1592 if (!is_me && prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { | 1620 if (!is_me && prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { |
| 1593 if (gaim_find_buddy(gc->account, who)) | 1621 if (gaim_find_buddy(conv->account, who)) |
| 1594 button = gaim_new_item_from_stock(menu, _("Remove"), GTK_STOCK_REMOVE, | 1622 button = gaim_new_item_from_stock(menu, _("Remove"), GTK_STOCK_REMOVE, |
| 1595 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1623 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1596 else | 1624 else |
| 1597 button = gaim_new_item_from_stock(menu, _("Add"), GTK_STOCK_ADD, | 1625 button = gaim_new_item_from_stock(menu, _("Add"), GTK_STOCK_ADD, |
| 1598 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1626 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1627 | |
| 1628 if (gc == NULL) | |
| 1629 gtk_widget_set_sensitive(button, FALSE); | |
| 1630 | |
| 1599 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | 1631 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); |
| 1600 } | 1632 } |
| 1601 | 1633 |
| 1602 button = gaim_new_item_from_stock(menu, _("Last said"), GTK_STOCK_INDEX, | 1634 button = gaim_new_item_from_stock(menu, _("Last said"), GTK_STOCK_INDEX, |
| 1603 G_CALLBACK(menu_last_said_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | 1635 G_CALLBACK(menu_last_said_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); |
| 1611 | 1643 |
| 1612 static gint | 1644 static gint |
| 1613 gtkconv_chat_popup_menu_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | 1645 gtkconv_chat_popup_menu_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) |
| 1614 { | 1646 { |
| 1615 GaimConversation *conv = gtkconv->active_conv; | 1647 GaimConversation *conv = gtkconv->active_conv; |
| 1616 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 1617 GaimGtkChatPane *gtkchat; | 1648 GaimGtkChatPane *gtkchat; |
| 1618 GaimConnection *gc; | 1649 GaimConnection *gc; |
| 1619 GaimAccount *account; | 1650 GaimAccount *account; |
| 1620 GtkTreeSelection *sel; | 1651 GtkTreeSelection *sel; |
| 1621 GtkTreeIter iter; | 1652 GtkTreeIter iter; |
| 1626 gtkconv = GAIM_GTK_CONVERSATION(conv); | 1657 gtkconv = GAIM_GTK_CONVERSATION(conv); |
| 1627 gtkchat = gtkconv->u.chat; | 1658 gtkchat = gtkconv->u.chat; |
| 1628 account = gaim_conversation_get_account(conv); | 1659 account = gaim_conversation_get_account(conv); |
| 1629 gc = account->gc; | 1660 gc = account->gc; |
| 1630 | 1661 |
| 1631 g_return_val_if_fail(gc != NULL, FALSE); | |
| 1632 | |
| 1633 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | 1662 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); |
| 1634 | |
| 1635 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1636 | 1663 |
| 1637 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | 1664 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); |
| 1638 if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) | 1665 if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) |
| 1639 return FALSE; | 1666 return FALSE; |
| 1640 | 1667 |
| 1641 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); | 1668 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); |
| 1642 menu = create_chat_menu (conv, who, prpl_info, gc); | 1669 menu = create_chat_menu (conv, who, gc); |
| 1643 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | 1670 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, |
| 1644 gaim_gtk_treeview_popup_menu_position_func, widget, | 1671 gaim_gtk_treeview_popup_menu_position_func, widget, |
| 1645 0, GDK_CURRENT_TIME); | 1672 0, GDK_CURRENT_TIME); |
| 1646 g_free(who); | 1673 g_free(who); |
| 1647 | 1674 |
| 1652 static gint | 1679 static gint |
| 1653 right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, | 1680 right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, |
| 1654 GaimGtkConversation *gtkconv) | 1681 GaimGtkConversation *gtkconv) |
| 1655 { | 1682 { |
| 1656 GaimConversation *conv = gtkconv->active_conv; | 1683 GaimConversation *conv = gtkconv->active_conv; |
| 1657 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 1658 GaimGtkChatPane *gtkchat; | 1684 GaimGtkChatPane *gtkchat; |
| 1659 GaimConnection *gc; | 1685 GaimConnection *gc; |
| 1660 GaimAccount *account; | 1686 GaimAccount *account; |
| 1661 GtkTreePath *path; | 1687 GtkTreePath *path; |
| 1662 GtkTreeIter iter; | 1688 GtkTreeIter iter; |
| 1675 event->x, event->y, &path, &column, &x, &y); | 1701 event->x, event->y, &path, &column, &x, &y); |
| 1676 | 1702 |
| 1677 if (path == NULL) | 1703 if (path == NULL) |
| 1678 return FALSE; | 1704 return FALSE; |
| 1679 | 1705 |
| 1680 if (gc != NULL) | |
| 1681 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1682 | |
| 1683 gtk_tree_selection_select_path(GTK_TREE_SELECTION( | 1706 gtk_tree_selection_select_path(GTK_TREE_SELECTION( |
| 1684 gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list))), path); | 1707 gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list))), path); |
| 1685 | 1708 |
| 1686 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); | 1709 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); |
| 1687 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); | 1710 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); |
| 1693 GtkTextMark *mark = get_mark_for_user(gtkconv, who); | 1716 GtkTextMark *mark = get_mark_for_user(gtkconv, who); |
| 1694 | 1717 |
| 1695 if(mark != NULL) | 1718 if(mark != NULL) |
| 1696 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(gtkconv->imhtml), mark, 0.1, FALSE, 0, 0); | 1719 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(gtkconv->imhtml), mark, 0.1, FALSE, 0, 0); |
| 1697 } else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { | 1720 } else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { |
| 1698 GtkWidget *menu = create_chat_menu (conv, who, prpl_info, gc); | 1721 GtkWidget *menu = create_chat_menu (conv, who, gc); |
| 1699 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | 1722 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 1700 event->button, event->time); | 1723 event->button, event->time); |
| 1701 } | 1724 } |
| 1702 | 1725 |
| 1703 g_free(who); | 1726 g_free(who); |
| 4506 /* we shouldn't display the popup | 4529 /* we shouldn't display the popup |
| 4507 * if the user has selected something: */ | 4530 * if the user has selected something: */ |
| 4508 if (!gtk_text_buffer_get_selection_bounds( | 4531 if (!gtk_text_buffer_get_selection_bounds( |
| 4509 gtk_text_iter_get_buffer(arg2), | 4532 gtk_text_iter_get_buffer(arg2), |
| 4510 &start, &end)) { | 4533 &start, &end)) { |
| 4511 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 4512 GtkWidget *menu = NULL; | 4534 GtkWidget *menu = NULL; |
| 4513 GaimConnection *gc = | 4535 GaimConnection *gc = |
| 4514 gaim_conversation_get_gc(conv); | 4536 gaim_conversation_get_gc(conv); |
| 4515 | 4537 |
| 4516 | 4538 |
| 4517 if (gc != NULL) | 4539 menu = create_chat_menu(conv, buddyname, gc); |
| 4518 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO( | |
| 4519 gc->prpl); | |
| 4520 | |
| 4521 menu = create_chat_menu(conv, buddyname, | |
| 4522 prpl_info, gc); | |
| 4523 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | 4540 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, |
| 4524 NULL, GTK_WIDGET(imhtml), | 4541 NULL, GTK_WIDGET(imhtml), |
| 4525 btn_event->button, | 4542 btn_event->button, |
| 4526 btn_event->time); | 4543 btn_event->time); |
| 4527 | 4544 |
