From a2b894c649ba47e9929216d500e59fedeeeacbd6 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Thu, 29 Dec 2011 16:34:47 +0300 Subject: [PATCH] Adds tooltips for fader, mute, lock, & record buttons. Bug 6637 --- xfce4-mixer/xfce-mixer-track.c | 86 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 86 insertions(+), 0 deletions(-) diff --git a/xfce4-mixer/xfce-mixer-track.c b/xfce4-mixer/xfce-mixer-track.c index 82b412b..bcca191 100644 --- a/xfce4-mixer/xfce-mixer-track.c +++ b/xfce4-mixer/xfce-mixer-track.c @@ -173,7 +173,79 @@ xfce_mixer_track_new (GstElement *card, return GTK_WIDGET (track); } +static void +xfce_mixer_update_fader_tooltip(GtkWidget *fader, gint channel, gint num_channels, gdouble volume, gdouble max_volume) +{ + gchar *tooltip; + + g_return_if_fail (fader != NULL); + + if(num_channels > 1) + { + /* This is for the tooltip popup when hovering over the volume slider for a stereo channel. + * It's intended to show something like left channel, volume 50% + */ + tooltip = g_strdup_printf(_("%s channel, volume: %1.0f%%"), channel == 0 ? _("Left") : _("Right"), (volume / max_volume) * 100.0f); + } + else + { + /* This is for the tooltip popup when hovering over the volume slider for a mono channel. + * It's just displays the current volume, i.e.: volume 50% + */ + tooltip = g_strdup_printf(_("volume: %1.0f%%"), (volume / max_volume) * 100.0f); + } + gtk_widget_set_tooltip_text(fader, tooltip); + g_free(tooltip); +} + +static void +xfce_mixer_update_mute_tooltip(GtkWidget *mute, gboolean muted) +{ + gchar *tooltip; + + g_return_if_fail (mute != NULL); + + /* This is for the tooltip popup when hovering over the mute button below a track. + * It's intended to show whether the track is muted or not. + */ + tooltip = g_strdup_printf("%s", muted ? _("Muted") : _("Not muted")); + gtk_widget_set_tooltip_text(mute, tooltip); + g_free(tooltip); +} +static void +xfce_mixer_update_locked_tooltip(GtkWidget *lock, gboolean locked) +{ + gchar *tooltip; + + g_return_if_fail (lock != NULL); + + /* This is for the tooltip popup when hovering over the chained/lock button below a track. + * It's intended to show whether the user can set the channel volume independently or not. + */ + tooltip = g_strdup_printf("%s", locked ? _("All channels have the same volume") : _("Each channel has an independent volume")); + gtk_widget_set_tooltip_text(lock, tooltip); + g_free(tooltip); +} + +static void +xfce_mixer_update_record_tooltip(GtkWidget *record, gboolean recording) +{ + gchar *tooltip; + + g_return_if_fail (record != NULL); + + tooltip = g_malloc(1024); + if(tooltip) + { + /* This is for the tooltip popup when hovering over the recording button below a track. + * It's intended to show whether the track is currently recording or not. + */ + g_snprintf(tooltip, 1024, "%s", recording ? _("Recording") : _("Not recording")); + gtk_widget_set_tooltip_text(record, tooltip); + g_free(tooltip); + } +} static void xfce_mixer_track_create_contents (XfceMixerTrack *track) @@ -221,6 +293,8 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) gtk_widget_show (fader); track->channel_faders = g_list_append (track->channel_faders, fader); + + xfce_mixer_update_fader_tooltip (fader, channel, track->gst_track->num_channels, (gdouble)volumes[channel], (gdouble)track->gst_track->max_volume); } /* Create a horizontal for the control buttons */ @@ -237,6 +311,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->mute_button, "toggled", G_CALLBACK (xfce_mixer_track_mute_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->mute_button, FALSE, FALSE, 0); gtk_widget_show (track->mute_button); + xfce_mixer_update_mute_tooltip (track->mute_button, FALSE); } if (G_LIKELY (track->gst_track->num_channels >= 2)) @@ -248,6 +323,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->lock_button, "toggled", G_CALLBACK (xfce_mixer_track_lock_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->lock_button, FALSE, FALSE, 0); gtk_widget_show (track->lock_button); + xfce_mixer_update_locked_tooltip (track->lock_button, TRUE); } /* Create record button for capture tracks */ @@ -259,6 +335,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->record_button, "toggled", G_CALLBACK (xfce_mixer_track_record_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->record_button, FALSE, FALSE, 0); gtk_widget_show (track->record_button); + xfce_mixer_update_record_tooltip (track->record_button, FALSE); } /* Some of the mixer controls need to be updated before they can be used */ @@ -305,6 +382,8 @@ xfce_mixer_track_fader_changed (GtkRange *range, gtk_range_set_value (GTK_RANGE (iter->data), gtk_range_get_value (range)); volumes[channel] = (gint) gtk_range_get_value (GTK_RANGE (iter->data)); + + xfce_mixer_update_fader_tooltip (iter->data, channel, track->gst_track->num_channels, volumes[channel], track->gst_track->max_volume); } /* Deliver the volume update to GStreamer */ @@ -330,11 +409,13 @@ xfce_mixer_track_mute_toggled (GtkToggleButton *button, { stock = "xfce4-mixer-muted"; gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_mute_tooltip ((GtkWidget *)button, TRUE); } else { stock = "xfce4-mixer-no-muted"; gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, FALSE); + xfce_mixer_update_mute_tooltip ((GtkWidget *)button, FALSE); } image = gtk_image_new_from_icon_name (stock, XFCE_MIXER_ICON_SIZE); @@ -358,11 +439,13 @@ xfce_mixer_track_lock_toggled (GtkToggleButton *button, { image = gtk_image_new_from_file (DATADIR "/pixmaps/xfce4-mixer/chain-broken.png"); gtk_button_set_image (GTK_BUTTON (track->lock_button), image); + xfce_mixer_update_locked_tooltip ((GtkWidget *)button, FALSE); return; } image = gtk_image_new_from_file (DATADIR "/pixmaps/xfce4-mixer/chain.png"); gtk_button_set_image (GTK_BUTTON (track->lock_button), image); + xfce_mixer_update_locked_tooltip ((GtkWidget *)button, TRUE); /* Allocate array for volumes of all channels */ volumes = g_new (gint, track->gst_track->num_channels); @@ -402,11 +485,13 @@ xfce_mixer_track_record_toggled (GtkToggleButton *button, { stock = "xfce4-mixer-record"; gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_record_tooltip ((GtkWidget *)button, TRUE); } else { stock = "xfce4-mixer-no-record"; gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, FALSE); + xfce_mixer_update_record_tooltip ((GtkWidget *)button, TRUE); } image = gtk_image_new_from_icon_name (stock, XFCE_MIXER_ICON_SIZE); @@ -442,6 +527,7 @@ xfce_mixer_track_update_record (XfceMixerTrack *track) { record = GST_MIXER_TRACK_HAS_FLAG (track->gst_track, GST_MIXER_TRACK_RECORD); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (track->record_button), record); + xfce_mixer_update_record_tooltip (track->record_button, record); } } -- 1.7.5.4