diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2010-12-16 15:03:14 -0500 |
---|---|---|
committer | Ken VanDine <ken.vandine@canonical.com> | 2010-12-16 15:03:14 -0500 |
commit | 2565fc2f86a1c81780ca8bcdb1f568b56031fa5a (patch) | |
tree | 4c2288c30b6cdf187747166c3f9f914b8d454f20 /src/volume-widget.c | |
parent | 13bc64e0a3c144740c30e2469fdb5f605d58ee39 (diff) | |
parent | 7ea64f857b5f76cd06e01bfe49eda27c2d2da335 (diff) | |
download | ayatana-indicator-sound-2565fc2f86a1c81780ca8bcdb1f568b56031fa5a.tar.gz ayatana-indicator-sound-2565fc2f86a1c81780ca8bcdb1f568b56031fa5a.tar.bz2 ayatana-indicator-sound-2565fc2f86a1c81780ca8bcdb1f568b56031fa5a.zip |
Import upstream version 0.5.3
Diffstat (limited to 'src/volume-widget.c')
-rw-r--r-- | src/volume-widget.c | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/src/volume-widget.c b/src/volume-widget.c index 6964741..c37f9c7 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -33,9 +33,9 @@ typedef struct _VolumeWidgetPrivate VolumeWidgetPrivate; struct _VolumeWidgetPrivate { - DbusmenuMenuitem* twin_item; - GtkWidget* ido_volume_slider; - gboolean grabbed; + DbusmenuMenuitem* twin_item; + GtkWidget* ido_volume_slider; + gboolean grabbed; }; #define VOLUME_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VOLUME_WIDGET_TYPE, VolumeWidgetPrivate)) @@ -46,14 +46,14 @@ static void volume_widget_init (VolumeWidget *self); static void volume_widget_dispose (GObject *object); static void volume_widget_finalize (GObject *object); static void volume_widget_set_twin_item( VolumeWidget* self, - DbusmenuMenuitem* twin_item); + DbusmenuMenuitem* twin_item); static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata); + GValue* value, gpointer userdata); static gboolean volume_widget_change_value_cb (GtkRange *range, - GtkScrollType scroll, - gdouble value, - gpointer user_data); + GtkScrollType scroll, + gdouble value, + gpointer user_data); static gboolean volume_widget_value_changed_cb(GtkRange *range, gpointer user_data); static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data); @@ -65,33 +65,33 @@ G_DEFINE_TYPE (VolumeWidget, volume_widget, G_TYPE_OBJECT); static void volume_widget_class_init (VolumeWidgetClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (VolumeWidgetPrivate)); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (VolumeWidgetPrivate)); - gobject_class->dispose = volume_widget_dispose; - gobject_class->finalize = volume_widget_finalize; + gobject_class->dispose = volume_widget_dispose; + gobject_class->finalize = volume_widget_finalize; } static void volume_widget_init (VolumeWidget *self) { - //g_debug("VolumeWidget::volume_widget_init"); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + //g_debug("VolumeWidget::volume_widget_init"); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); priv->ido_volume_slider = ido_scale_menu_item_new_with_range ("VOLUME", IDO_RANGE_STYLE_DEFAULT, 0, 0, 100, 1); - g_object_ref (priv->ido_volume_slider); - ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); + g_object_ref (priv->ido_volume_slider); + ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); g_object_set(priv->ido_volume_slider, "reverse-scroll-events", TRUE, NULL); g_signal_connect (priv->ido_volume_slider, "notify::parent", G_CALLBACK (volume_widget_parent_changed), NULL); - - GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - - g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); - g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self); + + GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + + g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); + g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self); g_signal_connect(priv->ido_volume_slider, "slider-grabbed", G_CALLBACK(volume_widget_slider_grabbed), self); g_signal_connect(priv->ido_volume_slider, "slider-released", G_CALLBACK(volume_widget_slider_released), self); @@ -112,64 +112,64 @@ volume_widget_init (VolumeWidget *self) static void volume_widget_dispose (GObject *object) { - G_OBJECT_CLASS (volume_widget_parent_class)->dispose (object); + G_OBJECT_CLASS (volume_widget_parent_class)->dispose (object); } static void volume_widget_finalize (GObject *object) { - G_OBJECT_CLASS (volume_widget_parent_class)->finalize (object); + G_OBJECT_CLASS (volume_widget_parent_class)->finalize (object); } static void volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) -{ - g_return_if_fail (IS_VOLUME_WIDGET (userdata)); - VolumeWidget* mitem = VOLUME_WIDGET(userdata); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - //g_debug("scrub-widget::property_update for prop %s", property); - if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){ - if(priv->grabbed == FALSE){ - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - GtkRange *range = (GtkRange*)slider; - gdouble update = g_value_get_double (value); - //g_debug("volume-widget - update level with value %f", update); - gtk_range_set_value(range, update); - determine_state_from_volume(update); - } - } +{ + g_return_if_fail (IS_VOLUME_WIDGET (userdata)); + VolumeWidget* mitem = VOLUME_WIDGET(userdata); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + //g_debug("scrub-widget::property_update for prop %s", property); + if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){ + if(priv->grabbed == FALSE){ + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + GtkRange *range = (GtkRange*)slider; + gdouble update = g_value_get_double (value); + //g_debug("volume-widget - update level with value %f", update); + gtk_range_set_value(range, update); + determine_state_from_volume(update); + } + } } static void volume_widget_set_twin_item(VolumeWidget* self, DbusmenuMenuitem* twin_item) { - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - priv->twin_item = twin_item; - g_object_ref(priv->twin_item); - g_signal_connect(G_OBJECT(twin_item), "property-changed", - G_CALLBACK(volume_widget_property_update), self); - gdouble initial_level = g_value_get_double (dbusmenu_menuitem_property_get_value(twin_item, - DBUSMENU_VOLUME_MENUITEM_LEVEL)); - //g_debug("volume_widget_set_twin_item initial level = %f", initial_level); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + priv->twin_item = twin_item; + g_object_ref(priv->twin_item); + g_signal_connect(G_OBJECT(twin_item), "property-changed", + G_CALLBACK(volume_widget_property_update), self); + gdouble initial_level = g_value_get_double (dbusmenu_menuitem_property_get_value(twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); + //g_debug("volume_widget_set_twin_item initial level = %f", initial_level); 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); + gtk_range_set_value(range, initial_level); + determine_state_from_volume(initial_level); } static gboolean volume_widget_change_value_cb (GtkRange *range, - GtkScrollType scroll, - gdouble new_value, - gpointer user_data) + GtkScrollType scroll, + gdouble new_value, + gpointer user_data) { - g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); - VolumeWidget* mitem = VOLUME_WIDGET(user_data); - volume_widget_update(mitem, new_value); + 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); - return FALSE; + return FALSE; } /* @@ -179,25 +179,25 @@ volume_widget_change_value_cb (GtkRange *range, static gboolean volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) { - g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); - VolumeWidget* mitem = VOLUME_WIDGET(user_data); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(slider)), 0, 100); - - if(current_value == 0 || current_value == 100){ - volume_widget_update(mitem, current_value); - } + + if(current_value == 0 || current_value == 100){ + volume_widget_update(mitem, current_value); + } return FALSE; } void volume_widget_update(VolumeWidget* self, gdouble update) { - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - GValue value = {0}; + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); - gdouble clamped = CLAMP(update, 0, 100); + gdouble clamped = CLAMP(update, 0, 100); g_value_set_double(&value, clamped); dbusmenu_menuitem_handle_event (priv->twin_item, "update", &value, 0); } @@ -205,13 +205,13 @@ volume_widget_update(VolumeWidget* self, gdouble update) GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self) { - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - return priv->ido_volume_slider; + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + return priv->ido_volume_slider; } static void volume_widget_parent_changed (GtkWidget *widget, - gpointer user_data) + gpointer user_data) { gtk_widget_set_size_request (widget, 200, -1); //g_debug("volume_widget_parent_changed"); @@ -220,24 +220,24 @@ volume_widget_parent_changed (GtkWidget *widget, static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data) { - VolumeWidget* mitem = VOLUME_WIDGET(user_data); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - priv->grabbed = TRUE; + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + priv->grabbed = TRUE; } static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data) { - VolumeWidget* mitem = VOLUME_WIDGET(user_data); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - priv->grabbed = FALSE; + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + priv->grabbed = FALSE; } void volume_widget_tidy_up (GtkWidget *widget) { VolumeWidget* mitem = VOLUME_WIDGET(widget); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); gtk_widget_destroy (priv->ido_volume_slider); } @@ -245,9 +245,9 @@ gdouble volume_widget_get_current_volume ( GtkWidget *widget ) { VolumeWidget* mitem = VOLUME_WIDGET(widget); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); gdouble vol = g_value_get_double ( dbusmenu_menuitem_property_get_value( priv->twin_item, - DBUSMENU_VOLUME_MENUITEM_LEVEL)); + DBUSMENU_VOLUME_MENUITEM_LEVEL)); return vol; } @@ -258,9 +258,9 @@ volume_widget_get_current_volume ( GtkWidget *widget ) GtkWidget* volume_widget_new(DbusmenuMenuitem *item) { - GtkWidget* widget = g_object_new(VOLUME_WIDGET_TYPE, NULL); - volume_widget_set_twin_item((VolumeWidget*)widget, item); - return widget; + GtkWidget* widget = g_object_new(VOLUME_WIDGET_TYPE, NULL); + volume_widget_set_twin_item((VolumeWidget*)widget, item); + return widget; } |