/** * Updates all status icons for the different volume states like * muted, low, medium, high as well as the volume meter. This * is triggered either by apply_prefs() in the preferences subsystem, * do_alsa_reinit() or tray_icon_resized(). */ void update_status_icons() { int i,icon_width; GdkPixbuf* old_icons[4]; int size = tray_icon_size(); for(i=0;i<4;i++) old_icons[i] = status_icons[i]; if (g_key_file_has_key(keyFile,"PNMixer","IconTheme",NULL)) { status_icons[0] = get_stock_pixbuf("audio-volume-muted",size); status_icons[1] = get_stock_pixbuf("audio-volume-low",size); status_icons[2] = get_stock_pixbuf("audio-volume-medium",size); status_icons[3] = get_stock_pixbuf("audio-volume-high",size); } else { status_icons[0] = create_pixbuf("pnmixer-muted.png"); status_icons[1] = create_pixbuf("pnmixer-low.png"); status_icons[2] = create_pixbuf("pnmixer-medium.png"); status_icons[3] = create_pixbuf("pnmixer-high.png"); } icon_width = gdk_pixbuf_get_height(status_icons[0]); vol_div_factor = ((gdk_pixbuf_get_height(status_icons[0])-10)/100.0); vol_meter_width = 1.25*icon_width; if (vol_meter_width%4 != 0) vol_meter_width -= (vol_meter_width%4); if (!vol_meter_row && g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) { int lim = vol_meter_width/4; vol_meter_row = g_malloc(vol_meter_width*sizeof(guchar)); for(i=0;i<lim;i++) { vol_meter_row[i*4] = vol_meter_red; vol_meter_row[i*4+1] = vol_meter_green; vol_meter_row[i*4+2] = vol_meter_blue; vol_meter_row[i*4+3] = 255; } } else if (vol_meter_row && !g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) { free(vol_meter_row); vol_meter_row = NULL; if (icon_copy) g_object_unref(icon_copy); icon_copy = NULL; } draw_offset = g_key_file_get_integer(keyFile,"PNMixer","VolMeterPos",NULL); if (tray_icon) get_mute_state(TRUE); for(i = 0;i < 4;i++) if(old_icons[i]) g_object_unref(old_icons[i]); }
GtkWidget* create_prefs_window (void) { GtkBuilder *builder; GError *error = NULL; GdkColor vol_meter_color_button_color; gint *vol_meter_clrs; gchar *vol_cmd,*uifile,*custcmd; PrefsData *prefs_data; uifile = get_ui_file("prefs.xml"); if (!uifile) { report_error(_("Can't find preferences user interface file. Please insure PNMixer is installed correctly.\n")); return NULL; } builder = gtk_builder_new(); if (!gtk_builder_add_from_file( builder, uifile, &error)) { g_warning("%s",error->message); report_error(error->message); g_error_free(error); g_free(uifile); g_object_unref (G_OBJECT (builder)); return NULL; } g_free(uifile); prefs_data = g_slice_new(PrefsData); #define GO(name) prefs_data->name = GTK_WIDGET(gtk_builder_get_object(builder,#name)) GO(prefs_window); GO(card_combo); GO(chan_combo); GO(vol_pos_label); GO(vol_pos_combo); GO(vol_meter_pos_label); GO(vol_meter_pos_spin); GO(vol_meter_color_label); GO(vol_meter_color_button); GO(custom_label); GO(custom_entry); GO(vol_text_check); GO(draw_vol_check); GO(icon_theme_combo); GO(vol_control_entry); GO(scroll_step_spin); GO(middle_click_combo); GO(enable_hotkeys_check); GO(hotkey_spin); GO(hotkey_dialog); GO(hotkey_key_label); GO(mute_hotkey_label); GO(up_hotkey_label); GO(down_hotkey_label); #ifdef HAVE_LIBN GO(enable_noti_check); GO(hotkey_noti_check); GO(mouse_noti_check); GO(popup_noti_check); GO(external_noti_check); #endif #undef GO // vol text display gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(prefs_data->vol_text_check), g_key_file_get_boolean_with_default(keyFile,"PNMixer","DisplayTextVolume",FALSE)); gtk_combo_box_set_active (GTK_COMBO_BOX (prefs_data->vol_pos_combo), g_key_file_get_integer_with_default(keyFile,"PNMixer","TextVolumePosition",0)); // volume meter gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(prefs_data->draw_vol_check), g_key_file_get_boolean_with_default(keyFile,"PNMixer","DrawVolMeter",FALSE)); gtk_adjustment_set_upper (GTK_ADJUSTMENT(gtk_builder_get_object(builder,"vol_meter_pos_adjustment")), tray_icon_size()-10); gtk_spin_button_set_value (GTK_SPIN_BUTTON(prefs_data->vol_meter_pos_spin), g_key_file_get_integer_with_default(keyFile,"PNMixer","VolMeterPos",0)); // load available icon themes into icon theme combo box. also sets active load_icon_themes(prefs_data->icon_theme_combo, GTK_LIST_STORE(gtk_builder_get_object(builder,"icon_theme_liststore"))); // set color button color vol_meter_clrs = get_vol_meter_colors(); vol_meter_color_button_color.red = vol_meter_clrs[0]; vol_meter_color_button_color.green = vol_meter_clrs[1]; vol_meter_color_button_color.blue = vol_meter_clrs[2]; gtk_color_button_set_color(GTK_COLOR_BUTTON(prefs_data->vol_meter_color_button), &vol_meter_color_button_color); g_free(vol_meter_clrs); // fill in card/channel combo boxes fill_card_combo(prefs_data->card_combo,prefs_data->chan_combo); // volume command vol_cmd = get_vol_command(); if (vol_cmd) { gtk_entry_set_text(GTK_ENTRY(prefs_data->vol_control_entry), vol_cmd); g_free(vol_cmd); } // mouse scroll step gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_data->scroll_step_spin), g_key_file_get_integer_with_default(keyFile,"PNMixer","MouseScrollStep",1)); // middle click gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_data->middle_click_combo), g_key_file_get_integer_with_default(keyFile,"PNMixer","MiddleClickAction",0)); // custom command gtk_entry_set_invisible_char(GTK_ENTRY(prefs_data->custom_entry), 8226); custcmd = g_key_file_get_string(keyFile,"PNMixer","CustomCommand",NULL); if (custcmd) { gtk_entry_set_text(GTK_ENTRY(prefs_data->custom_entry),custcmd); g_free(custcmd); } on_vol_text_toggle(GTK_TOGGLE_BUTTON(prefs_data->vol_text_check), prefs_data); on_draw_vol_toggle(GTK_TOGGLE_BUTTON(prefs_data->draw_vol_check), prefs_data); on_middle_changed(GTK_COMBO_BOX(prefs_data->middle_click_combo), prefs_data); // hotkeys gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(prefs_data->enable_hotkeys_check), g_key_file_get_boolean_with_default(keyFile,"PNMixer","EnableHotKeys",FALSE)); // hotkey step gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_data->hotkey_spin), g_key_file_get_integer_with_default(keyFile,"PNMixer","HotkeyVolumeStep",1)); if (g_key_file_has_key(keyFile,"PNMixer","VolMuteKey",NULL)) set_label_for_keycode(prefs_data->mute_hotkey_label, g_key_file_get_integer(keyFile,"PNMixer", "VolMuteKey", NULL), g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolMuteMods", 0)); if (g_key_file_has_key(keyFile,"PNMixer","VolUpKey",NULL)) set_label_for_keycode(prefs_data->up_hotkey_label, g_key_file_get_integer(keyFile,"PNMixer", "VolUpKey", NULL), g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolUpMods", 0)); if (g_key_file_has_key(keyFile,"PNMixer","VolDownKey",NULL)) set_label_for_keycode(prefs_data->down_hotkey_label, g_key_file_get_integer(keyFile,"PNMixer", "VolDownKey", NULL), g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolDownMods", 0)); gtk_notebook_append_page(GTK_NOTEBOOK(gtk_builder_get_object(builder,"notebook1")), #ifdef HAVE_LIBN GTK_WIDGET(gtk_builder_get_object(builder,"notification_vbox")), #else GTK_WIDGET(gtk_builder_get_object(builder,"no_notification_label")), #endif gtk_label_new("Notifications")); #ifdef HAVE_LIBN // notification checkboxes set_notifications_booleans(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_data->enable_noti_check),enable_noti); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_data->hotkey_noti_check),hotkey_noti); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_data->mouse_noti_check),mouse_noti); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_data->popup_noti_check),popup_noti); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_data->external_noti_check),external_noti); on_notification_toggle(GTK_TOGGLE_BUTTON(prefs_data->enable_noti_check),prefs_data); #endif gtk_builder_connect_signals(builder, prefs_data); g_object_unref (G_OBJECT (builder)); return prefs_data->prefs_window; }
/** * Updates all status icons for the different volume states like * muted, low, medium, high as well as the volume meter. This * is triggered either by apply_prefs() in the preferences subsystem, * do_alsa_reinit() or tray_icon_resized(). */ void update_status_icons(void) { int i, icon_width; GdkPixbuf *old_icons[N_VOLUME_ICONS]; int size = tray_icon_size(); for (i = 0; i < N_VOLUME_ICONS; i++) old_icons[i] = status_icons[i]; /* Handle icons depending on the theme */ if (prefs_get_boolean("SystemTheme", FALSE)) { status_icons[VOLUME_MUTED] = get_stock_pixbuf("audio-volume-muted", size); status_icons[VOLUME_OFF] = get_stock_pixbuf("audio-volume-off", size); status_icons[VOLUME_LOW] = get_stock_pixbuf("audio-volume-low", size); status_icons[VOLUME_MEDIUM] = get_stock_pixbuf("audio-volume-medium", size); status_icons[VOLUME_HIGH] = get_stock_pixbuf("audio-volume-high", size); /* 'audio-volume-off' is not available in every icon set. More info at: * http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html */ if (status_icons[VOLUME_OFF] == NULL) status_icons[VOLUME_OFF] = get_stock_pixbuf("audio-volume-low", size); } else { status_icons[VOLUME_MUTED] = create_pixbuf("pnmixer-muted.png"); status_icons[VOLUME_OFF] = create_pixbuf("pnmixer-off.png"); status_icons[VOLUME_LOW] = create_pixbuf("pnmixer-low.png"); status_icons[VOLUME_MEDIUM] = create_pixbuf("pnmixer-medium.png"); status_icons[VOLUME_HIGH] = create_pixbuf("pnmixer-high.png"); } /* Handle volume meter */ icon_width = gdk_pixbuf_get_height(status_icons[0]); vol_div_factor = ((gdk_pixbuf_get_height(status_icons[0]) - 10) / 100.0); vol_meter_width = 1.25 * icon_width; if (vol_meter_width % 4 != 0) vol_meter_width -= (vol_meter_width % 4); if (prefs_get_boolean("DrawVolMeter", FALSE)) { int lim; if (vol_meter_row) g_free(vol_meter_row); vol_meter_row = g_malloc(vol_meter_width * sizeof(guchar)); lim = vol_meter_width / 4; for (i = 0; i < lim; i++) { vol_meter_row[i * 4] = vol_meter_red; vol_meter_row[i * 4 + 1] = vol_meter_green; vol_meter_row[i * 4 + 2] = vol_meter_blue; vol_meter_row[i * 4 + 3] = 255; } } else { if (vol_meter_row) g_free(vol_meter_row); vol_meter_row = NULL; if (icon_copy) g_object_unref(icon_copy); icon_copy = NULL; } draw_offset = prefs_get_integer("VolMeterPos", 0); if (tray_icon) on_volume_has_changed(); for (i = 0; i < N_VOLUME_ICONS; i++) if (old_icons[i]) g_object_unref(old_icons[i]); }