From 411333bed0e020e1725e3dd48afdc57e41fd1b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 14:10:10 +0100 Subject: use update_state_from_volume instead of determine_state_from_volume And make determine_state_from_volume return the state for the selected value --- src/indicator-sound.c | 23 ++++++++++++++++------- src/indicator-sound.h | 2 +- src/volume-widget.c | 6 +++--- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3867f27..d1bcc33 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -115,6 +115,7 @@ static void get_sink_availability_cb ( GObject *object, /****Volume States 'members' ***/ static void update_state(const gint state); +static const gint STATE_INVALID = -1; static const gint STATE_MUTED = 0; static const gint STATE_ZERO = 1; static const gint STATE_LOW = 2; @@ -452,7 +453,7 @@ static void fetch_state (IndicatorSound* self) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); if(priv->volume_widget != NULL){ - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); + update_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); } g_dbus_proxy_call ( priv->dbus_proxy, @@ -631,12 +632,11 @@ update_state(const gint state) indicator_image_helper_update(speaker_image, image_name); } - -void +static gint determine_state_from_volume(gdouble volume_percent) { if (device_available == FALSE) - return; + return STATE_INVALID; gint state = previous_state; if (volume_percent < 30.0 && volume_percent > 0) { state = STATE_LOW; @@ -647,9 +647,18 @@ determine_state_from_volume(gdouble volume_percent) } else if (volume_percent == 0.0) { state = STATE_ZERO; } - update_state(state); + return state; } +void +update_state_from_volume(gdouble volume_percent) +{ + gint state = determine_state_from_volume(volume_percent); + if (state == STATE_INVALID) + return; + + update_state(state); +} static gboolean start_animation() @@ -753,7 +762,7 @@ react_to_signal_sink_mute_update(gboolean mute_value, IndicatorSound* self) GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); gtk_widget_set_sensitive(slider_widget, !mute_value); if(mute_value == FALSE){ - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); + update_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); } } @@ -768,7 +777,7 @@ react_to_signal_sink_availability_update(gboolean available_value, IndicatorSoun } IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); + update_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); //g_debug("signal caught - sink availability update with value: %i", available_value); } diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 9f829bb..7bf69b6 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -53,7 +53,7 @@ struct _IndicatorSound { GType indicator_sound_get_type (void); void prepare_state_machine(); -extern void determine_state_from_volume(gdouble volume_percent); +extern void update_state_from_volume(gdouble volume_percent); gint get_state(); gchar* get_state_image_name(gint state); void prepare_for_tests(IndicatorObject * io); diff --git a/src/volume-widget.c b/src/volume-widget.c index 38dc9bb..9fa1395 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -137,7 +137,7 @@ volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, gdouble update = g_variant_get_double (value); //g_debug("volume-widget - update level with value %f", update); gtk_range_set_value(range, update); - determine_state_from_volume(update); + update_state_from_volume(update); } } } @@ -157,7 +157,7 @@ volume_widget_set_twin_item(VolumeWidget* self, GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; gtk_range_set_value(range, initial_level); - determine_state_from_volume(initial_level); + update_state_from_volume(initial_level); } static gboolean @@ -169,7 +169,7 @@ volume_widget_change_value_cb (GtkRange *range, g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); volume_widget_update(mitem, new_value); - determine_state_from_volume(new_value); + update_state_from_volume(new_value); return FALSE; } -- cgit v1.2.3 From 463c714aac4835bcdfda3c523122c13fac1586f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 17:01:01 +0100 Subject: Show a value notify-osd notification (if supported) when scrolling To improve the indicator usability, show a notify-osd bubble with the volume value when changing the value level using the scrolling-wheel over the indicator icon. --- src/indicator-sound.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/indicator-sound.h | 2 ++ 2 files changed, 81 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index d1bcc33..aa7c43e 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -30,6 +30,8 @@ with this program. If not, see . #include +#include + #include "indicator-sound.h" #include "transport-widget.h" #include "metadata-widget.h" @@ -47,7 +49,8 @@ struct _IndicatorSoundPrivate { GtkWidget* volume_widget; GList* transport_widgets_list; - GDBusProxy *dbus_proxy; + GDBusProxy *dbus_proxy; + NotifyNotification* notification; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -69,6 +72,10 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static void indicator_sound_scroll (IndicatorObject* io, gint delta, IndicatorScrollDirection direction); +//Notification +static void indicator_sound_notification_init (IndicatorSound *self); +static void indicator_sound_notification_show (IndicatorSound *self, double value); + //Slider related static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); @@ -183,6 +190,10 @@ indicator_sound_init (IndicatorSound *self) priv->dbus_proxy = NULL; GList* t_list = NULL; priv->transport_widgets_list = t_list; + priv->notification = NULL; + + priv->notification = NULL; + indicator_sound_notification_init (self); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, @@ -206,6 +217,10 @@ indicator_sound_dispose (GObject *object) g_list_free ( priv->transport_widgets_list ); + if (priv->notification) { + notify_uninit(); + } + G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); return; } @@ -349,6 +364,9 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); priv->volume_widget = volume_widget; + if (priv->notification) + notify_notification_attach_to_widget(priv->notification, volume_widget); + GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); g_signal_connect(ido_slider_widget, "style-set", G_CALLBACK(style_changed_cb), NULL); @@ -366,6 +384,28 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, return TRUE; } +static void indicator_sound_notification_init (IndicatorSound *self) +{ + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + + if (notify_init(PACKAGE_NAME)) { + GList* caps = notify_get_server_caps(); + gboolean has_notify_osd = FALSE; + + if (caps) { + if (g_list_find_custom(caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0)) { + has_notify_osd = TRUE; + } + g_list_foreach(caps, (GFunc) g_free, NULL); + g_list_free(caps); + } + + if (has_notify_osd) { + priv->notification = notify_notification_new(PACKAGE_NAME, NULL, NULL, NULL); + notify_notification_set_hint_string(priv->notification, "x-canonical-private-synchronous", ""); + } + } +} static void connection_changed (IndicatorServiceManager * sm, @@ -950,6 +990,41 @@ style_changed_cb(GtkWidget *widget, gpointer user_data) prepare_blocked_animation(); } +static void +indicator_sound_notification_show(IndicatorSound *self, double value) +{ + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + + if (priv->notification == NULL) + return; + + char *icon; + const int notify_value = CLAMP((int)value, -1, 101); + gint state = determine_state_from_volume (CLAMP(value, 0, 100)); + + if (state == STATE_ZERO) { + GtkIconTheme *theme = gtk_icon_theme_get_default(); + if (gtk_icon_theme_has_icon(theme, "audio-volume-off")) { + // Not available in all the themes + icon = "audio-volume-off"; + } else { + icon = "audio-volume-muted"; + } + } else if (state == STATE_LOW) { + icon = "audio-volume-low"; + } else if (state == STATE_MEDIUM) { + icon = "audio-volume-medium"; + } else if (state == STATE_HIGH) { + icon = "audio-volume-high"; + } else { + icon = "audio-volume-muted"; + } + + notify_notification_update(priv->notification, PACKAGE_NAME, NULL, icon); + notify_notification_set_hint_int32(priv->notification, "value", notify_value); + notify_notification_show(priv->notification, NULL); +} + static void indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) { @@ -973,5 +1048,7 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirectio value -= adj->step_increment; } //g_debug("indicator-sound-scroll - update slider with value %f", value); - volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); + volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); + + indicator_sound_notification_show(INDICATOR_SOUND (io), value); } diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 7bf69b6..276136d 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -23,6 +23,8 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config.h" + #include #include #include -- cgit v1.2.3 From 9c765ddc17fefb9d0839b75c66551ed72e187bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 17:18:52 +0100 Subject: indentation fixes --- src/indicator-sound.c | 81 ++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index aa7c43e..15c8cb0 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -388,23 +388,26 @@ static void indicator_sound_notification_init (IndicatorSound *self) { IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - if (notify_init(PACKAGE_NAME)) { - GList* caps = notify_get_server_caps(); - gboolean has_notify_osd = FALSE; + if (!notify_init(PACKAGE_NAME)) + return; - if (caps) { - if (g_list_find_custom(caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0)) { - has_notify_osd = TRUE; - } - g_list_foreach(caps, (GFunc) g_free, NULL); - g_list_free(caps); - } + GList* caps = notify_get_server_caps(); + gboolean has_notify_osd = FALSE; - if (has_notify_osd) { - priv->notification = notify_notification_new(PACKAGE_NAME, NULL, NULL, NULL); - notify_notification_set_hint_string(priv->notification, "x-canonical-private-synchronous", ""); + if (caps) { + if (g_list_find_custom(caps, "x-canonical-private-synchronous", + (GCompareFunc) g_strcmp0)) { + has_notify_osd = TRUE; } - } + g_list_foreach(caps, (GFunc) g_free, NULL); + g_list_free(caps); + } + + if (has_notify_osd) { + priv->notification = notify_notification_new(PACKAGE_NAME, NULL, NULL, NULL); + notify_notification_set_hint_string(priv->notification, + "x-canonical-private-synchronous", ""); + } } static void @@ -998,31 +1001,31 @@ indicator_sound_notification_show(IndicatorSound *self, double value) if (priv->notification == NULL) return; - char *icon; - const int notify_value = CLAMP((int)value, -1, 101); - gint state = determine_state_from_volume (CLAMP(value, 0, 100)); - - if (state == STATE_ZERO) { - GtkIconTheme *theme = gtk_icon_theme_get_default(); - if (gtk_icon_theme_has_icon(theme, "audio-volume-off")) { - // Not available in all the themes - icon = "audio-volume-off"; - } else { - icon = "audio-volume-muted"; - } - } else if (state == STATE_LOW) { - icon = "audio-volume-low"; - } else if (state == STATE_MEDIUM) { - icon = "audio-volume-medium"; - } else if (state == STATE_HIGH) { - icon = "audio-volume-high"; - } else { - icon = "audio-volume-muted"; - } - - notify_notification_update(priv->notification, PACKAGE_NAME, NULL, icon); - notify_notification_set_hint_int32(priv->notification, "value", notify_value); - notify_notification_show(priv->notification, NULL); + char *icon; + const int notify_value = CLAMP((int)value, -1, 101); + gint state = determine_state_from_volume (CLAMP(value, 0, 100)); + + if (state == STATE_ZERO) { + GtkIconTheme *theme = gtk_icon_theme_get_default(); + if (gtk_icon_theme_has_icon(theme, "audio-volume-off")) { + // Not available in all the themes + icon = "audio-volume-off"; + } else { + icon = "audio-volume-muted"; + } + } else if (state == STATE_LOW) { + icon = "audio-volume-low"; + } else if (state == STATE_MEDIUM) { + icon = "audio-volume-medium"; + } else if (state == STATE_HIGH) { + icon = "audio-volume-high"; + } else { + icon = "audio-volume-muted"; + } + + notify_notification_update(priv->notification, PACKAGE_NAME, NULL, icon); + notify_notification_set_hint_int32(priv->notification, "value", notify_value); + notify_notification_show(priv->notification, NULL); } static void -- cgit v1.2.3 From 826144b11815fb1f475dcdab0fd235e4f34df9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 17:22:55 +0100 Subject: Ops, indentation: one space left! :P --- src/indicator-sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 15c8cb0..4022422 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -1014,7 +1014,7 @@ indicator_sound_notification_show(IndicatorSound *self, double value) icon = "audio-volume-muted"; } } else if (state == STATE_LOW) { - icon = "audio-volume-low"; + icon = "audio-volume-low"; } else if (state == STATE_MEDIUM) { icon = "audio-volume-medium"; } else if (state == STATE_HIGH) { -- cgit v1.2.3 From 41fb49c27538a2c6044a7170e855baea0f11b2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 17:23:58 +0100 Subject: gtk_icon_theme_has_icon() doesn't seem to work here... When no "audio-volume-off" icon is provided by any theme, the notification is not shown, so notify-osd-icons package is reccomanded here. --- src/indicator-sound.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 4022422..e94526b 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -1006,13 +1006,8 @@ indicator_sound_notification_show(IndicatorSound *self, double value) gint state = determine_state_from_volume (CLAMP(value, 0, 100)); if (state == STATE_ZERO) { - GtkIconTheme *theme = gtk_icon_theme_get_default(); - if (gtk_icon_theme_has_icon(theme, "audio-volume-off")) { - // Not available in all the themes - icon = "audio-volume-off"; - } else { - icon = "audio-volume-muted"; - } + // Not available for all the themes + icon = "audio-volume-off"; } else if (state == STATE_LOW) { icon = "audio-volume-low"; } else if (state == STATE_MEDIUM) { -- cgit v1.2.3 From b0babf1fab9b3e74f32de4635dd9eed78cccfc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 18:37:25 +0100 Subject: more indentation fixes... --- src/indicator-sound.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index e94526b..8e86f8b 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -698,9 +698,9 @@ update_state_from_volume(gdouble volume_percent) { gint state = determine_state_from_volume(volume_percent); if (state == STATE_INVALID) - return; + return; - update_state(state); + update_state(state); } static gboolean -- cgit v1.2.3 From 21cf01130cd686a9e4c1d4e90dbd3e01f8d0b7b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 27 Jan 2011 16:49:23 +0100 Subject: merge: reset indicator-sound.h values --- src/indicator-sound.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-sound.h b/src/indicator-sound.h index a7468fb..c52a62a 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -54,7 +54,7 @@ struct _IndicatorSound { GType indicator_sound_get_type (void); void prepare_state_machine(); -extern void update_state_from_volume(gdouble volume_percent); +extern void determine_state_from_volume(gdouble volume_percent); gint get_state(); gchar* get_state_image_name(gint state); void prepare_for_tests(IndicatorObject * io); -- cgit v1.2.3 From d834013cb980c93b88d2f09aec69bce9d5f95148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 27 Jan 2011 18:25:15 +0100 Subject: Added show-notify-osd-on-scroll gsettings parameter This parameter (ON, by default) allows to enable/disable the notify-osd bubble on volume-change by mouse scroll. --- src/indicator-sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 29a9f91..9867e04 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -49,6 +49,7 @@ struct _IndicatorSoundPrivate GList* transport_widgets_list; GDBusProxy *dbus_proxy; SoundStateManager* state_manager; + GSettings *settings_manager; NotifyNotification* notification; }; @@ -140,6 +141,7 @@ indicator_sound_init (IndicatorSound *self) priv->state_manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); priv->notification = NULL; + priv->settings_manager = g_settings_new("com.canonical.indicators.sound"); indicator_sound_notification_init (self); g_signal_connect ( G_OBJECT(self->service), @@ -651,5 +653,6 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, //g_debug("indicator-sound-scroll - update slider with value %f", value); volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); - indicator_sound_notification_show(INDICATOR_SOUND (io), current_state, value); + if (g_settings_get_boolean(priv->settings_manager, "show-notify-osd-on-scroll")) + indicator_sound_notification_show(INDICATOR_SOUND (io), current_state, value); } -- cgit v1.2.3 From 439e6943aa4b50684ea7ebafc663d1ed21947961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 27 Jan 2011 18:33:30 +0100 Subject: Unref the GSettings object... --- src/indicator-sound.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 9867e04..88ef27d 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -162,6 +162,8 @@ indicator_sound_dispose (GObject *object) g_list_free ( priv->transport_widgets_list ); + g_object_unref(priv->settings_manager); + if (priv->notification) { notify_uninit(); } -- cgit v1.2.3