From: Richard Kettlewell Date: Sun, 21 Oct 2007 15:04:55 +0000 (+0100) Subject: random play menu item X-Git-Tag: 5.0.3~524 X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/commitdiff_plain/2d504956e1c3612ed62f16a05fd504b5998e6759?ds=sidebyside;hp=ac6bf2bad50653d84388269a6629d121b8c37b8f random play menu item --- diff --git a/disobedience/control.c b/disobedience/control.c index 6542f82..d3c4e18 100644 --- a/disobedience/control.c +++ b/disobedience/control.c @@ -46,6 +46,7 @@ static void update_rtp(const struct icon *); static void update_nortp(const struct icon *); static void clicked_icon(GtkButton *, gpointer); static void clicked_menu(GtkMenuItem *, gpointer userdata); +static void toggled_menu(GtkCheckMenuItem *, gpointer userdata); static int enable_rtp(disorder_eclient *c, disorder_eclient_no_response *completed, @@ -91,6 +92,9 @@ struct icon { disorder_eclient_no_response *completed, void *v); + /** @brief Flag */ + unsigned flags; + /** @brief Pointer to button */ GtkWidget *button; @@ -98,35 +102,104 @@ struct icon { GtkWidget *item; }; +/** @brief This is the active half of a pair */ +#define ICON_ACTIVE 0x0001 + +/** @brief This is the inactive half of a pair */ +#define ICON_INACTIVE 0x0002 + /** @brief Table of all icons */ static struct icon icons[] = { - { "pause.png", "Pause playing track", 0, - update_pause, - disorder_eclient_pause, 0, 0 }, - { "play.png", "Resume playing track", 0, - update_play, - disorder_eclient_resume, 0, 0 }, - { "cross.png", "Cancel playing track", "/Control/Scratch", - update_scratch, - disorder_eclient_scratch_playing, 0, 0 }, - { "random.png", "Enable random play", 0, - update_random_enable, - disorder_eclient_random_enable, 0, 0 }, - { "randomcross.png", "Disable random play", 0, - update_random_disable, - disorder_eclient_random_disable, 0, 0 }, - { "notes.png", "Enable play", 0, - update_enable, - disorder_eclient_enable, 0, 0 }, - { "notescross.png", "Disable play", 0, - update_disable, - disorder_eclient_disable, 0, 0 }, - { "speaker.png", "Play network stream", 0, - update_rtp, - enable_rtp, 0, 0 }, - { "speakercross.png", "Stop playing network stream", 0, - update_nortp, - disable_rtp, 0, 0 }, + { + "pause.png", /* icon */ + "Pause playing track", /* tip */ + 0, /* menuitem */ + update_pause, /* update */ + disorder_eclient_pause, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "play.png", /* icon */ + "Resume playing track", /* tip */ + 0, /* menuitem */ + update_play, /* update */ + disorder_eclient_resume, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "cross.png", /* icon */ + "Cancel playing track", /* tip */ + "/Control/Scratch", /* menuitem */ + update_scratch, /* update */ + disorder_eclient_scratch_playing, /* action */ + 0, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "random.png", /* icon */ + "Enable random play", /* tip */ + "/Control/Random play", /* menuitem */ + update_random_enable, /* update */ + disorder_eclient_random_enable, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "randomcross.png", /* icon */ + "Disable random play", /* tip */ + "/Control/Random play", /* menuitem */ + update_random_disable, /* update */ + disorder_eclient_random_disable, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "notes.png", /* icon */ + "Enable play", /* tip */ + 0, /* menuitem */ + update_enable, /* update */ + disorder_eclient_enable, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "notescross.png", /* icon */ + "Disable play", /* tip */ + 0, /* menuitem */ + update_disable, /* update */ + disorder_eclient_disable, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "speaker.png", /* icon */ + "Play network stream", /* tip */ + 0, /* menuitem */ + update_rtp, /* update */ + enable_rtp, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "speakercross.png", /* icon */ + "Stop playing network stream", /* tip */ + 0, /* menuitem */ + update_nortp, /* update */ + disable_rtp, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, }; /** @brief Count of icons */ @@ -178,8 +251,19 @@ GtkWidget *control_widget(void) { if(icons[n].menuitem) { icons[n].item = gtk_item_factory_get_widget(mainmenufactory, icons[n].menuitem); - g_signal_connect(G_OBJECT(icons[n].item), "activate", - G_CALLBACK(clicked_menu), &icons[n]); + switch(icons[n].flags & (ICON_ACTIVE|ICON_INACTIVE)) { + case ICON_ACTIVE: + g_signal_connect(G_OBJECT(icons[n].item), "toggled", + G_CALLBACK(toggled_menu), &icons[n]); + break; + case ICON_INACTIVE: + /* Don't connect two instances of the signal! */ + break; + default: + g_signal_connect(G_OBJECT(icons[n].item), "activate", + G_CALLBACK(clicked_menu), &icons[n]); + break; + } } } /* create the adjustments for the volume control */ @@ -255,10 +339,13 @@ static void update_icon(const struct icon *icon, if(visible) gtk_widget_set_sensitive(icon->button, usable); if(icon->item) { - /* There's an associated menu item */ - (visible ? gtk_widget_show : gtk_widget_hide)(icon->item); - if(visible) - gtk_widget_set_sensitive(icon->item, usable); + /* There's an associated menu item. These are always visible, but may not + * be usable. */ + if((icon->flags & (ICON_ACTIVE|ICON_INACTIVE)) == ICON_ACTIVE) { + /* The active half of a pair */ + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(icon->item), visible); + } + gtk_widget_set_sensitive(icon->item, usable); } } @@ -330,6 +417,22 @@ static void clicked_menu(GtkMenuItem attribute((unused)) *menuitem, icon->action(client, 0, 0); } +static void toggled_menu(GtkCheckMenuItem *menuitem, + gpointer userdata) { + const struct icon *icon = userdata; + size_t n; + + /* This is a bit fiddlier than the others, we need to find the action for the + * new state. If the new state is active then we want the ICON_INACTIVE + * version and vica versa. */ + for(n = 0; n < NICONS; ++n) + if(icons[n].item == icon->item + && !!(icons[n].flags & ICON_INACTIVE) == !!menuitem->active) + break; + if(n < NICONS) + icons[n].action(client, 0, 0); +} + /** @brief Called when the volume has been adjusted */ static void volume_adjusted(GtkAdjustment attribute((unused)) *a, gpointer attribute((unused)) user_data) { diff --git a/disobedience/menu.c b/disobedience/menu.c index 5085be2..fcf9e9f 100644 --- a/disobedience/menu.c +++ b/disobedience/menu.c @@ -139,24 +139,97 @@ static void about_popup_got_version(void attribute((unused)) *v, /** @brief Create the menu bar widget */ GtkWidget *menubar(GtkWidget *w) { static const GtkItemFactoryEntry entries[] = { - { (char *)"/File", 0, 0, 0, (char *)"", 0 }, - { (char *)"/File/Login", (char *)"L", login, 0, - 0, 0 }, - { (char *)"/File/Quit Disobedience", (char *)"Q", quit_program, 0, - (char *)"", GTK_STOCK_QUIT }, - - { (char *)"/Edit", 0, 0, 0, (char *)"", 0 }, - { (char *)"/Edit/Select all tracks", (char *)"A", select_all, 0, - 0, 0 }, - { (char *)"/Edit/Track properties", 0, properties_item, 0, - 0, 0 }, - - { (char *)"/Control", 0, 0, 0, (char *)"", 0 }, - { (char *)"/Control/Scratch", (char *)"S", 0, 0, 0, 0 }, + { + (char *)"/File", /* path */ + 0, /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/File/Login", /* path */ + (char *)"L", /* accelerator */ + login, /* callback */ + 0, /* callback_action */ + 0, /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/File/Quit Disobedience", /* path */ + (char *)"Q", /* accelerator */ + quit_program, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + GTK_STOCK_QUIT /* extra_data */ + }, - { (char *)"/Help", 0, 0, 0, (char *)"", 0 }, - { (char *)"/Help/About DisOrder", 0, about_popup, 0, - (char *)"", GTK_STOCK_ABOUT }, + { + (char *)"/Edit", /* path */ + 0, /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/Edit/Select all tracks", /* path */ + (char *)"A", /* accelerator */ + select_all, /* callback */ + 0, /* callback_action */ + 0, /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/Edit/Track properties", /* path */ + 0, /* accelerator */ + properties_item, /* callback */ + 0, /* callback_action */ + 0, /* item_type */ + 0 /* extra_data */ + }, + + { + (char *)"/Control", /* path */ + 0, /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/Control/Scratch", /* path */ + (char *)"S", /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + 0, /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/Control/Random play", /* path */ + (char *)"R", /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + 0 /* extra_data */ + }, + + { + (char *)"/Help", /* path */ + 0, /* accelerator */ + 0, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + 0 /* extra_data */ + }, + { + (char *)"/Help/About DisOrder", /* path */ + 0, /* accelerator */ + about_popup, /* callback */ + 0, /* callback_action */ + (char *)"", /* item_type */ + GTK_STOCK_ABOUT /* extra_data */ + }, }; GtkAccelGroup *accel = gtk_accel_group_new();