diff options
author | Conor Curran <conor.curran@canonical.com> | 2011-02-02 15:58:22 -0600 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2011-02-02 15:58:22 -0600 |
commit | 81ab9100b3d3e767e32ff4c960abf20c089e0457 (patch) | |
tree | e20bf90a01caa52ed5e98175a7f2bb57327ef1be /src | |
parent | 9e8c509c0f321f322c3b9d0a0a23050cb3b30a3f (diff) | |
parent | 9992cab449e6dbf1d87046fede2ec35bfab51cd6 (diff) | |
download | ayatana-indicator-sound-81ab9100b3d3e767e32ff4c960abf20c089e0457.tar.gz ayatana-indicator-sound-81ab9100b3d3e767e32ff4c960abf20c089e0457.tar.bz2 ayatana-indicator-sound-81ab9100b3d3e767e32ff4c960abf20c089e0457.zip |
Merged TreviƱo's (Marco Trevisan) work
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-sound.c | 12 | ||||
-rw-r--r-- | src/indicator-sound.h | 9 | ||||
-rw-r--r-- | src/sound-state-manager.c | 106 | ||||
-rw-r--r-- | src/sound-state-manager.h | 5 |
4 files changed, 113 insertions, 19 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c index f259dfd..7e5ebc7 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -133,7 +133,7 @@ indicator_sound_init (IndicatorSound *self) GList* t_list = NULL; priv->transport_widgets_list = t_list; priv->state_manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL); - + g_signal_connect ( G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self ); @@ -149,7 +149,6 @@ indicator_sound_dispose (GObject *object) g_object_unref(G_OBJECT(self->service)); self->service = NULL; } - g_list_free ( priv->transport_widgets_list ); G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); @@ -402,7 +401,9 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, newitem, menu_volume_item, parent); - return TRUE; + sound_state_manager_attach_notification_to_volume_widget (priv->state_manager, + volume_widget); + return TRUE; } /*******************************************************************/ @@ -563,7 +564,6 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) return digested; } - static void indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) @@ -589,5 +589,7 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, 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); + + sound_state_manager_show_notification (priv->state_manager, value); } diff --git a/src/indicator-sound.h b/src/indicator-sound.h index ecc38fb..40a3e6f 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 <http://www.gnu.org/licenses/>. */ +#include "config.h" + #include <libindicator/indicator.h> #include <libindicator/indicator-object.h> #include <libindicator/indicator-service-manager.h> @@ -51,11 +53,4 @@ struct _IndicatorSound { // GObject Boiler plate GType indicator_sound_get_type (void); -void prepare_state_machine(); -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); -void tidy_up_hash(); - #endif diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index e8865d8..a592711 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -18,6 +18,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <libindicator/indicator-image-helper.h> +#include <libnotify/notify.h> + +#include "config.h" + #include "sound-state-manager.h" #include "dbus-shared-names.h" @@ -30,6 +34,8 @@ struct _SoundStateManagerPrivate GList* blocked_animation_list; SoundState current_state; GtkImage* speaker_image; + NotifyNotification* notification; + GSettings *settings_manager; }; #define SOUND_STATE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_TYPE_STATE_MANAGER, SoundStateManagerPrivate)) @@ -41,7 +47,11 @@ static gint animation_id; static GList* blocked_iter = NULL; static gboolean can_animate = FALSE; -static void sound_state_manager_prepare_blocked_animation(SoundStateManager* self); +//Notifications +static void sound_state_manager_notification_init (SoundStateManager* self); + +//Animation/State related +static void sound_state_manager_prepare_blocked_animation (SoundStateManager* self); static gboolean sound_state_manager_start_animation (gpointer user_data); static gboolean sound_state_manager_fade_back_to_mute_image (gpointer user_data); static void sound_state_manager_reset_mute_blocking_animation (SoundStateManager* self); @@ -54,6 +64,7 @@ static void sound_state_signal_cb ( GDBusProxy* proxy, gpointer user_data ); static gboolean sound_state_manager_can_proceed_with_blocking_animation (SoundStateManager* self); + static void sound_state_manager_init (SoundStateManager* self) { @@ -63,6 +74,12 @@ sound_state_manager_init (SoundStateManager* self) priv->volume_states = NULL; priv->speaker_image = NULL; priv->blocked_animation_list = NULL; + priv->notification = NULL; + priv->settings_manager = NULL; + + priv->settings_manager = g_settings_new("com.canonical.indicators.sound"); + + sound_state_manager_notification_init (self); sound_state_manager_prepare_state_image_names (self); sound_state_manager_prepare_blocked_animation (self); @@ -89,9 +106,16 @@ sound_state_manager_dispose (GObject *object) g_hash_table_destroy (priv->volume_states); sound_state_manager_free_the_animation_list (self); + + if (priv->notification) { + notify_uninit(); + } + + g_object_unref(priv->settings_manager); + G_OBJECT_CLASS (sound_state_manager_parent_class)->dispose (object); } - + static void sound_state_manager_class_init (SoundStateManagerClass *klass) @@ -106,6 +130,77 @@ sound_state_manager_class_init (SoundStateManagerClass *klass) design_team_size = gtk_icon_size_register("design-team-size", 22, 22); } +static void +sound_state_manager_notification_init (SoundStateManager* self) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + if (!notify_init(PACKAGE_NAME)) + return; + + 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", ""); + } +} + +void +sound_state_manager_attach_notification_to_volume_widget (SoundStateManager *self, + GtkWidget* volume_widget) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + if (priv->notification) + notify_notification_attach_to_widget(priv->notification, volume_widget); +} + + +void +sound_state_manager_show_notification (SoundStateManager *self, + double value) +{ + SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); + + if (priv->notification == NULL || + g_settings_get_boolean (priv->settings_manager, "show-notify-osd-on-scroll") == FALSE){ + return; + } + + char *icon; + const int notify_value = CLAMP((int)value, -1, 101); + SoundState state = sound_state_manager_get_current_state (self); + + if (state == ZERO_LEVEL) { + // Not available for all the themes + icon = "audio-volume-off"; + } else if (state == LOW_LEVEL) { + icon = "audio-volume-low"; + } else if (state == MEDIUM_LEVEL) { + icon = "audio-volume-medium"; + } else if (state == HIGH_LEVEL) { + 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); +} + + /* Prepare states versus images names hash. */ @@ -113,7 +208,8 @@ static void sound_state_manager_prepare_state_image_names (SoundStateManager* self) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); - priv->volume_states = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + priv->volume_states = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(MUTED), g_strdup("audio-volume-muted-panel")); g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(ZERO_LEVEL), g_strdup("audio-volume-low-zero-panel")); g_hash_table_insert (priv->volume_states, GINT_TO_POINTER(LOW_LEVEL), g_strdup("audio-volume-low-panel")); @@ -281,8 +377,7 @@ sound_state_signal_cb ( GDBusProxy* proxy, blocked_id = g_timeout_add_seconds (4, sound_state_manager_start_animation, self); - indicator_image_helper_update (priv->speaker_image, image_name); - + indicator_image_helper_update (priv->speaker_image, image_name); } else{ indicator_image_helper_update (priv->speaker_image, image_name); @@ -291,7 +386,6 @@ sound_state_signal_cb ( GDBusProxy* proxy, else { g_warning ("sorry don't know what signal this is - %s", signal_name); } - } void diff --git a/src/sound-state-manager.h b/src/sound-state-manager.h index d73d5d9..0b919cb 100644 --- a/src/sound-state-manager.h +++ b/src/sound-state-manager.h @@ -58,8 +58,11 @@ void sound_state_manager_deal_with_disconnect (SoundStateManager* self); void sound_state_manager_get_state_cb (GObject *object, GAsyncResult *res, gpointer user_data); +void sound_state_manager_show_notification (SoundStateManager *self, + double value); - +void sound_state_manager_attach_notification_to_volume_widget (SoundStateManager *self, + GtkWidget* volume_widget); G_END_DECLS |