void menu_info_item_update(menu_info_t* mi, uint32_t index, const char* name, const char* desc, const pa_cvolume* vol, int mute, char* tooltip, const char* icon, const char* address, uint32_t target) { menu_info_item_t* item; if(mi->type == MENU_SERVER) item = menu_info_item_get_by_name(mi, name); else item = menu_info_item_get(mi, index); if(item == NULL) { menu_info_item_add(mi, index, name, desc, vol, mute, tooltip, icon, address, target); return; } g_debug("[menu_info] updating %s %u %s (target: %d)", menu_info_type_name(item->menu_info->type), index, desc, (int)target); g_free(item->name); item->name = g_strdup(name); g_free(item->desc); item->desc = g_strdup(desc); g_free(item->volume); item->volume = g_memdup(vol, sizeof(pa_cvolume)); item->mute = mute; item->target = target; g_free(item->address); item->address = g_strdup(address); menu_type_t submenu_type = menu_info_submenu_type(mi->type); menu_info_t* submenu = &mi->menu_infos->menu_info[submenu_type]; gtk_menu_item_set_label(GTK_MENU_ITEM(item->widget), desc); systray_set_tooltip(GTK_WIDGET(item->widget), tooltip); switch(mi->type) { case MENU_SERVER: case MENU_MODULE: g_debug("[menu_info] *** unhandled %s update! (index: %u, desc: %s)", menu_info_type_name(mi->type), index, desc); break; case MENU_SINK: case MENU_SOURCE: systray_update_item_in_all_submenus(item, submenu); break; case MENU_INPUT: case MENU_OUTPUT: systray_update_all_items_in_submenu(submenu, item); break; } /* if this is the default sink, update status icon acording to volume */ if(mi->type == MENU_SINK && item == menu_info_item_get_by_name(mi, mi->default_name)) ui_update_systray_icon(item); }
GtkWidget* systray_add_menu_item(GtkMenuShell* menu, const char* desc, const char* tooltip, const char* icon) { GtkWidget* item = gtk_image_menu_item_new_with_mnemonic(desc); gtk_menu_shell_append(menu, item); if(tooltip) systray_set_tooltip(item, tooltip); if(icon) gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_MENU)); gtk_widget_show(item); return item; }
GtkWidget* systray_add_radio_item(menu_info_item_t* mii, const char* tooltip) { menu_info_t* mi = mii->menu_info; gchar* label = menu_info_item_label(mii); GtkWidget* item = gtk_radio_menu_item_new_with_label(mi->group, label); g_free(label); if(tooltip) systray_set_tooltip(item, tooltip); mi->group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); systray_remove_placeholder(mi); gtk_menu_shell_append(mi->menu, item); gtk_widget_show(item); return item; }
GtkWidget* systray_add_radio_item(menu_info_t* mi, const char* desc, const char* tooltip) { GtkWidget* item = gtk_radio_menu_item_new_with_label(mi->group, desc); if(tooltip) systray_set_tooltip(item, tooltip); mi->group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); /* if this is the first item, remove the "none" placeholder label */ if(g_hash_table_size(mi->items) == 0) { GList* children = gtk_container_get_children(GTK_CONTAINER(mi->menu)); if(children) gtk_container_remove(GTK_CONTAINER(mi->menu), GTK_WIDGET(children->data)); } gtk_menu_shell_append(mi->menu, item); gtk_widget_show(item); return item; }
GtkWidget* systray_add_item(GtkMenuShell* menu, const char* desc, const char* tooltip, const char* icon) { GtkWidget* item = gtk_menu_item_new(); #if GTK_VERSION_MAJOR == 2 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); #else GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_container_add(GTK_CONTAINER(item), hbox); if(icon) { GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_MENU); #if GTK_VERSION_MAJOR == 2 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); #else gtk_container_add(GTK_CONTAINER(hbox), image); #endif } GtkWidget* label = gtk_label_new(NULL); gtk_label_set_text_with_mnemonic(GTK_LABEL(label), desc); #if GTK_VERSION_MAJOR == 2 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 15); #else gtk_container_add(GTK_CONTAINER(hbox), label); #endif if(tooltip) systray_set_tooltip(item, tooltip); gtk_menu_shell_append(menu, item); gtk_widget_show_all(item); return item; }
void menu_info_item_update(menu_info_t* mi, uint32_t index, const char* name, const char* desc, const pa_cvolume* vol, int mute, char* tooltip, const char* icon, const char* address) { menu_info_item_t* mii; if(mi->type == MENU_SERVER) mii = menu_info_item_get_by_name(mi, name); else mii = menu_info_item_get(mi, index); if(mii == NULL) return menu_info_item_add(mi, index, name, desc, vol, mute, tooltip, icon, address); #ifdef DEBUG g_message("[menu_info] updating %s %u %s", menu_info_type_name(mii->menu_info->type), index, desc); #endif g_free(mii->name); mii->name = g_strdup(name); g_free(mii->desc); mii->desc = g_strdup(desc); g_free(mii->volume); mii->volume = g_memdup(vol, sizeof(pa_cvolume)); mii->mute = mute; g_free(mii->address); mii->address = g_strdup(address); switch(mi->type) { case MENU_SERVER: case MENU_SINK: case MENU_SOURCE: gtk_menu_item_set_label(GTK_MENU_ITEM(mii->widget), desc); systray_set_tooltip(GTK_WIDGET(mii->widget), tooltip); // submenu to update (if any) menu_info_t* submenu = NULL; switch(mi->type) { case MENU_SINK: submenu = &mi->menu_infos->menu_info[MENU_INPUT]; break; case MENU_SOURCE: submenu = &mi->menu_infos->menu_info[MENU_OUTPUT]; break; default: break; } // change labels in stream submenus if(submenu) { GHashTableIter iter; gpointer key; menu_info_item_t* item; menu_info_item_t* subitem; g_hash_table_iter_init(&iter, submenu->items); while(g_hash_table_iter_next(&iter, &key, (gpointer*)&item)) if((subitem = g_hash_table_lookup(item->submenu->items, GUINT_TO_POINTER(mii->index)))) if(!g_str_equal(subitem->desc, desc)) gtk_menu_item_set_label( GTK_MENU_ITEM(subitem->widget), desc); } break; case MENU_INPUT: case MENU_OUTPUT: gtk_menu_item_set_label(GTK_MENU_ITEM(mii->widget), desc); systray_set_tooltip(GTK_WIDGET(mii->widget), tooltip); break; } /* if this is the default sink, update status icon acording to volume */ if(mi->type == MENU_SINK && mii == menu_info_item_get_by_name(mi, mi->default_name)) ui_update_statusicon(mii); }