cgtkpidgin

How do I add item to Pidgin menu


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?


Solution

  • 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