Mercurial > pidgin.yaz
comparison console/gntblist.c @ 14883:c8cd118653fc
[gaim-migrate @ 17652]
Add a 'Plugins' item in the buddylist menu (ctrl-o).
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 02 Nov 2006 00:18:34 +0000 |
parents | 2405b9e6f05f |
children | ea920bd4a00b |
comparison
equal
deleted
inserted
replaced
14882:62e16ed961cc | 14883:c8cd118653fc |
---|---|
67 | 67 |
68 /* XXX: I am KISSing */ | 68 /* XXX: I am KISSing */ |
69 GntWidget *status; /* Dropdown with the statuses */ | 69 GntWidget *status; /* Dropdown with the statuses */ |
70 GntWidget *statustext; /* Status message */ | 70 GntWidget *statustext; /* Status message */ |
71 int typing; | 71 int typing; |
72 | |
73 GntWidget *menu; | |
74 /* These are the menuitems that get regenerated */ | |
75 GntMenuItem *accounts; | |
76 GntMenuItem *plugins; | |
72 } GGBlist; | 77 } GGBlist; |
73 | 78 |
74 typedef enum | 79 typedef enum |
75 { | 80 { |
76 STATUS_PRIMITIVE = 0, | 81 STATUS_PRIMITIVE = 0, |
1764 GaimPluginAction *action = data; | 1769 GaimPluginAction *action = data; |
1765 if (action && action->callback) | 1770 if (action && action->callback) |
1766 action->callback(action); | 1771 action->callback(action); |
1767 } | 1772 } |
1768 | 1773 |
1769 static GntMenuItem *reconstruct_accounts_menu() | 1774 static void |
1775 build_plugin_actions(GntMenuItem *item, GaimPlugin *plugin, gpointer context) | |
1776 { | |
1777 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); | |
1778 GList *actions; | |
1779 GntMenuItem *menuitem; | |
1780 | |
1781 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
1782 for (actions = GAIM_PLUGIN_ACTIONS(plugin, context); actions; | |
1783 actions = g_list_delete_link(actions, actions)) { | |
1784 if (actions->data) { | |
1785 GaimPluginAction *action = actions->data; | |
1786 action->plugin = plugin; | |
1787 action->context = context; | |
1788 menuitem = gnt_menuitem_new(action->label); | |
1789 gnt_menu_add_item(GNT_MENU(sub), menuitem); | |
1790 | |
1791 gnt_menuitem_set_callback(menuitem, plugin_action, action); | |
1792 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action", | |
1793 action, (GDestroyNotify)gaim_plugin_action_free); | |
1794 } | |
1795 } | |
1796 } | |
1797 | |
1798 static void | |
1799 reconstruct_plugins_menu() | |
1800 { | |
1801 GntWidget *sub; | |
1802 GntMenuItem *plg; | |
1803 GList *iter; | |
1804 | |
1805 if (!ggblist) | |
1806 return; | |
1807 | |
1808 if (ggblist->plugins == NULL) | |
1809 ggblist->plugins = gnt_menuitem_new(_("Plugins")); | |
1810 | |
1811 plg = ggblist->plugins; | |
1812 sub = gnt_menu_new(GNT_MENU_POPUP); | |
1813 gnt_menuitem_set_submenu(plg, GNT_MENU(sub)); | |
1814 | |
1815 for (iter = gaim_plugins_get_loaded(); iter; iter = iter->next) { | |
1816 GaimPlugin *plugin = iter->data; | |
1817 GntMenuItem *item; | |
1818 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) | |
1819 continue; | |
1820 | |
1821 if (!GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
1822 continue; | |
1823 | |
1824 item = gnt_menuitem_new(_(plugin->info->name)); | |
1825 gnt_menu_add_item(GNT_MENU(sub), item); | |
1826 build_plugin_actions(item, plugin, NULL); | |
1827 } | |
1828 } | |
1829 | |
1830 static void | |
1831 reconstruct_accounts_menu() | |
1770 { | 1832 { |
1771 GntWidget *sub; | 1833 GntWidget *sub; |
1772 GntMenuItem *acc, *item; | 1834 GntMenuItem *acc, *item; |
1773 GList *iter; | 1835 GList *iter; |
1774 | 1836 |
1775 if (!ggblist) | 1837 if (!ggblist) |
1776 return NULL; | 1838 return; |
1777 | 1839 |
1778 acc = gnt_menuitem_new(_("Accounts")); | 1840 if (ggblist->accounts == NULL) |
1779 | 1841 ggblist->accounts = gnt_menuitem_new(_("Accounts")); |
1842 | |
1843 acc = ggblist->accounts; | |
1780 sub = gnt_menu_new(GNT_MENU_POPUP); | 1844 sub = gnt_menu_new(GNT_MENU_POPUP); |
1781 gnt_menuitem_set_submenu(acc, GNT_MENU(sub)); | 1845 gnt_menuitem_set_submenu(acc, GNT_MENU(sub)); |
1782 | 1846 |
1783 for (iter = gaim_accounts_get_all_active(); iter; | 1847 for (iter = gaim_accounts_get_all_active(); iter; |
1784 iter = g_list_delete_link(iter, iter)) { | 1848 iter = g_list_delete_link(iter, iter)) { |
1789 if (!gc || !GAIM_CONNECTION_IS_CONNECTED(gc)) | 1853 if (!gc || !GAIM_CONNECTION_IS_CONNECTED(gc)) |
1790 continue; | 1854 continue; |
1791 prpl = gc->prpl; | 1855 prpl = gc->prpl; |
1792 | 1856 |
1793 if (GAIM_PLUGIN_HAS_ACTIONS(prpl)) { | 1857 if (GAIM_PLUGIN_HAS_ACTIONS(prpl)) { |
1794 GList *acts; | |
1795 GntWidget *s; | |
1796 | |
1797 item = gnt_menuitem_new(gaim_account_get_username(account)); | 1858 item = gnt_menuitem_new(gaim_account_get_username(account)); |
1798 s = gnt_menu_new(GNT_MENU_POPUP); | |
1799 gnt_menuitem_set_submenu(item, GNT_MENU(s)); | |
1800 gnt_menu_add_item(GNT_MENU(sub), item); | 1859 gnt_menu_add_item(GNT_MENU(sub), item); |
1801 | 1860 build_plugin_actions(item, prpl, gc); |
1802 for (acts = GAIM_PLUGIN_ACTIONS(prpl, gc); acts; | |
1803 acts = g_list_delete_link(acts, acts)) { | |
1804 GaimPluginAction *action = acts->data; | |
1805 if (!action) | |
1806 continue; | |
1807 | |
1808 action->plugin = prpl; | |
1809 action->context = gc; | |
1810 | |
1811 item = gnt_menuitem_new(action->label); | |
1812 gnt_menuitem_set_callback(item, plugin_action, action); | |
1813 /* This is to make sure the action is freed when the menu is destroyed */ | |
1814 g_object_set_data_full(G_OBJECT(item), "plugin_action", action, | |
1815 (GDestroyNotify)gaim_plugin_action_free); | |
1816 gnt_menu_add_item(GNT_MENU(s), item); | |
1817 } | |
1818 } | 1861 } |
1819 } | 1862 } |
1820 return acc; | |
1821 } | 1863 } |
1822 | 1864 |
1823 static void show_offline_cb(GntMenuItem *item, gpointer n) | 1865 static void show_offline_cb(GntMenuItem *item, gpointer n) |
1824 { | 1866 { |
1825 gaim_prefs_set_bool(PREF_ROOT "/showoffline", | 1867 gaim_prefs_set_bool(PREF_ROOT "/showoffline", |
1840 | 1882 |
1841 if (!ggblist) | 1883 if (!ggblist) |
1842 return; | 1884 return; |
1843 | 1885 |
1844 window = GNT_WINDOW(ggblist->window); | 1886 window = GNT_WINDOW(ggblist->window); |
1845 menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | 1887 ggblist->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); |
1846 gnt_window_set_menu(window, GNT_MENU(menu)); | 1888 gnt_window_set_menu(window, GNT_MENU(menu)); |
1847 | 1889 |
1848 item = gnt_menuitem_new(_("Options")); | 1890 item = gnt_menuitem_new(_("Options")); |
1849 gnt_menu_add_item(GNT_MENU(menu), item); | 1891 gnt_menu_add_item(GNT_MENU(menu), item); |
1850 | 1892 |
1865 | 1907 |
1866 item = gnt_menuitem_new(_("Sort by log size")); | 1908 item = gnt_menuitem_new(_("Sort by log size")); |
1867 gnt_menu_add_item(GNT_MENU(sub), item); | 1909 gnt_menu_add_item(GNT_MENU(sub), item); |
1868 gnt_menuitem_set_callback(GNT_MENUITEM(item), sort_blist_change_cb, "log"); | 1910 gnt_menuitem_set_callback(GNT_MENUITEM(item), sort_blist_change_cb, "log"); |
1869 | 1911 |
1870 item = reconstruct_accounts_menu(); | 1912 reconstruct_accounts_menu(); |
1871 gnt_menu_add_item(GNT_MENU(menu), item); | 1913 gnt_menu_add_item(GNT_MENU(menu), ggblist->accounts); |
1914 | |
1915 reconstruct_plugins_menu(); | |
1916 gnt_menu_add_item(GNT_MENU(menu), ggblist->plugins); | |
1872 } | 1917 } |
1873 | 1918 |
1874 void gg_blist_show() | 1919 void gg_blist_show() |
1875 { | 1920 { |
1876 blist_show(gaim_get_blist()); | 1921 blist_show(gaim_get_blist()); |
1909 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->statustext); | 1954 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->statustext); |
1910 | 1955 |
1911 gnt_widget_show(ggblist->window); | 1956 gnt_widget_show(ggblist->window); |
1912 | 1957 |
1913 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", gg_blist_get_handle(), | 1958 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", gg_blist_get_handle(), |
1914 GAIM_CALLBACK(create_menu), NULL); | 1959 GAIM_CALLBACK(reconstruct_accounts_menu), NULL); |
1915 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", gg_blist_get_handle(), | 1960 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", gg_blist_get_handle(), |
1916 GAIM_CALLBACK(create_menu), NULL); | 1961 GAIM_CALLBACK(reconstruct_accounts_menu), NULL); |
1917 gaim_signal_connect(gaim_blist_get_handle(), "buddy-status-changed", gg_blist_get_handle(), | 1962 gaim_signal_connect(gaim_blist_get_handle(), "buddy-status-changed", gg_blist_get_handle(), |
1918 GAIM_CALLBACK(buddy_status_changed), ggblist); | 1963 GAIM_CALLBACK(buddy_status_changed), ggblist); |
1919 gaim_signal_connect(gaim_blist_get_handle(), "buddy-idle-changed", gg_blist_get_handle(), | 1964 gaim_signal_connect(gaim_blist_get_handle(), "buddy-idle-changed", gg_blist_get_handle(), |
1920 GAIM_CALLBACK(buddy_idle_changed), ggblist); | 1965 GAIM_CALLBACK(buddy_idle_changed), ggblist); |
1966 | |
1967 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", gg_blist_get_handle(), | |
1968 GAIM_CALLBACK(reconstruct_plugins_menu), NULL); | |
1969 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", gg_blist_get_handle(), | |
1970 GAIM_CALLBACK(reconstruct_plugins_menu), NULL); | |
1921 | 1971 |
1922 #if 0 | 1972 #if 0 |
1923 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gg_blist_get_handle(), | 1973 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gg_blist_get_handle(), |
1924 GAIM_CALLBACK(buddy_signed_on), ggblist); | 1974 GAIM_CALLBACK(buddy_signed_on), ggblist); |
1925 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gg_blist_get_handle(), | 1975 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gg_blist_get_handle(), |