How do I add item to Pidgin menu

风流意气都作罢 提交于 2019-12-25 02:56:05

问题


I want to add arbitrary item to Pidgin menu. Let it be Buddies → Show → Groups. I want it to be checkbutton (like Buddies → Show → Empty Groups) with custom function associated. How can I do this?

  • In Pidgin 2.10.9
  • In Pidgin 3.0.0 (development branch)

回答1:


The following example is for Pidgin version 2.10.9. I believe there are not many changes in 3.0.0 (current development branch) so it will be applicable there too with minimal modifications.

First of all, download Pidgin sources. In Ubuntu this is done simply by running

apt-get source pidgin

Which will fetch libpurple, pidgin and finch sources. Then go into pidgin-2.10.9/pidgin/gtkblist.c and find the line

static GtkItemFactoryEntry blist_menu[] =

There you will see Gtk menu in text. Add the following line:

{ N_("/Buddies/Show/_Groups"), NULL, pidgin_blist_show_groups_cb, 1, "<CheckItem>", NULL },

after

{ N_("/Buddies/Show/_Empty Groups"), NULL, pidgin_blist_show_empty_groups_cb, 1, "<CheckItem>", NULL },

You can see that the line added is just the analog of after which it was added. The 3rd array member is the function responsible for updating menu item status.

Next, add the function you just specified, pidgin_blist_show_groups_cb. You can do it finding the pidgin_blist_show_empty_groups_cb and copying it's contents.

static void pidgin_blist_show_groups_cb(gpointer data, guint action, GtkWidget *item)
{
    pidgin_set_cursor(gtkblist->window, GDK_WATCH);

    purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/blist/show_groups",
            gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)));

    pidgin_clear_cursor(gtkblist->window);
}

Also, you need to set item status on startup. Find the function

static void pidgin_blist_show(PurpleBuddyList *list)

and add

gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show/Groups"))),
                                                      purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/show_groups"));

after

gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show/Empty Groups"))),
                                                   purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/show_empty_groups"));

The adding preference "/blist/show_groups" as well as adding callback to it is explained in How do I add custom preference into Pidgin?. To test your changes, compile and install pidgin:

sudo apt-get build-dep pidgin
cd pidgin-2.10.9/
fakeroot debian/rules binary
sudo dpkg -i ../pidgin_2.10.9-0ubuntu3.deb



回答2:


Pidgin-3.0.0

There are some changes in the way which Pidgin generates menu in 3.0.0 version. First, there is new array GtkToggleActionEntry blist_menu_toggle_entries[]. You need to add there

{ "ShowGroups", NULL, N_("_Groups"), NULL, NULL, G_CALLBACK(pidgin_blist_show_groups_cb), FALSE },

after

{ "ShowEmptyGroups", NULL, N_("_Empty Groups"), NULL, NULL, G_CALLBACK(pidgin_blist_show_empty_groups_cb), FALSE },

And, there is static const char *blist_menu. You need to add

"<menuitem action='ShowGroups'/>"

after

"<menuitem action='ShowEmptyGroups'/>"

Then follow the instructions from this answer skipping the very first.



来源:https://stackoverflow.com/questions/23379170/how-do-i-add-item-to-pidgin-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!