diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-06-08 14:26:57 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-06-08 14:26:57 +0100 |
commit | 5a9881a144df8a9c36f9d5b96ea53e872c76949b (patch) | |
tree | 3b3ffcf7f6cc8f227540bae401f2ddc5f693923c /src | |
parent | ed0f4a53abcce977b74ca2647fddbb08b4284982 (diff) | |
download | ayatana-indicator-sound-5a9881a144df8a9c36f9d5b96ea53e872c76949b.tar.gz ayatana-indicator-sound-5a9881a144df8a9c36f9d5b96ea53e872c76949b.tar.bz2 ayatana-indicator-sound-5a9881a144df8a9c36f9d5b96ea53e872c76949b.zip |
new transport bar
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/common-defs.h | 1 | ||||
-rwxr-xr-x | src/indicator-sound.c | 197 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 1 | ||||
-rw-r--r-- | src/slider-menu-item.c | 18 | ||||
-rw-r--r-- | src/transport-bar.c | 94 | ||||
-rw-r--r-- | src/transport-bar.h | 49 | ||||
-rw-r--r-- | src/transport-menu-item.vala | 19 |
8 files changed, 277 insertions, 105 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a1ecece..716cab2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,7 +47,8 @@ sound-service-server.h: $(srcdir)/sound-service.xml # libsoundmenu vala ##################### music_bridge_VALASOURCES = \ - music-player-bridge.vala + music-player-bridge.vala \ + transport-menu-item.vala music_bridge_VALAFLAGS = \ --ccode \ diff --git a/src/common-defs.h b/src/common-defs.h index 9be1da5..94c178e 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -27,3 +27,4 @@ with this program. If not, see <http://www.gnu.org/licenses/>. // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" #define DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME "volume" +#define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-transport-bar" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 18f48d8..31f023e 100755 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -91,6 +91,9 @@ static void slider_grabbed(GtkWidget *widget, gpointer user_data); static void slider_released(GtkWidget *widget, gpointer user_data); static void style_changed_cb(GtkWidget *widget, gpointer user_data); +//transport bar related +static gboolean new_transport_bar(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); + // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); @@ -150,9 +153,9 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_label = get_label; io_class->get_image = get_icon; io_class->get_menu = get_menu; - io_class->scroll = scroll; + io_class->scroll = scroll; - design_team_size = gtk_icon_size_register("design-team-size", 22, 22); + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); return; } @@ -217,9 +220,9 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) -{ - gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - g_debug("At start-up attempting to set the image to %s", current_name); +{ + gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + g_debug("At start-up attempting to set the image to %s", current_name); speaker_image = indicator_image_helper(current_name); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; @@ -231,16 +234,15 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); - - g_object_set_data (G_OBJECT (client), - "indicator", io); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); + DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); + g_object_set_data (G_OBJECT (client), "indicator", io); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_bar); - // register Key-press listening on the menu widget as the slider does not allow this. - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); - return GTK_MENU(menu); + // register Key-press listening on the menu widget as the slider does not allow this. + g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); + return GTK_MENU(menu); } static void @@ -307,6 +309,13 @@ new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuC return TRUE; } +static gboolean new_transport_bar(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_debug("indicator-sound: new_transport_bar() called "); + return TRUE; +} + + static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { @@ -337,11 +346,11 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); - // Ensure we are in a coherent state with the service at start up. - // Preserve ordering! - fetch_volume_percent_from_dbus(); - fetch_mute_value_from_dbus(); - fetch_sink_availability_from_dbus(); + // Ensure we are in a coherent state with the service at start up. + // Preserve ordering! + fetch_volume_percent_from_dbus(); + fetch_mute_value_from_dbus(); + fetch_sink_availability_from_dbus(); } } else { @@ -645,7 +654,6 @@ catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_valu /*******************************************************************/ //UI callbacks /******************************************************************/ - /** value_changed_event_cb: This callback will get triggered irregardless of whether its a user change or a programmatic change. @@ -692,94 +700,93 @@ key_press_cb: static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) { - gboolean digested = FALSE; + gboolean digested = FALSE; - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange* range = (GtkRange*)slider; - gdouble current_value = gtk_range_get_value(range); - gdouble new_value = current_value; - const gdouble five_percent = 5; - GtkWidget *menuitem; - - menuitem = GTK_MENU_SHELL (widget)->active_menu_item; - if(IDO_IS_SCALE_MENU_ITEM(menuitem) == TRUE) + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + GtkRange* range = (GtkRange*)slider; + gdouble current_value = gtk_range_get_value(range); + gdouble new_value = current_value; + const gdouble five_percent = 5; + GtkWidget *menuitem; + + menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + if(IDO_IS_SCALE_MENU_ITEM(menuitem) == TRUE) + { + switch(event->keyval) { - switch(event->keyval) - { - case GDK_Right: - digested = TRUE; - if(event->state & GDK_CONTROL_MASK) - { - new_value = 100; - } - else - { - new_value = current_value + five_percent; - } - break; - case GDK_Left: - digested = TRUE; - if(event->state & GDK_CONTROL_MASK) - { - new_value = 0; - } - else - { - new_value = current_value - five_percent; - } - break; - case GDK_plus: - digested = TRUE; - new_value = current_value + five_percent; - break; - case GDK_minus: - digested = TRUE; - new_value = current_value - five_percent; - break; - default: - break; - } - - new_value = CLAMP(new_value, 0, 100); - if(new_value != current_value && current_state != STATE_MUTED) - { - g_debug("Attempting to set the range from the key listener to %f", new_value); - // In order to ensure that the exterior filtering does not catch this, reset the exterior_vol_update - // to ensure these updates. - exterior_vol_update = OUT_OF_RANGE; - gtk_range_set_value(range, new_value); - } + case GDK_Right: + digested = TRUE; + if(event->state & GDK_CONTROL_MASK) + { + new_value = 100; + } + else + { + new_value = current_value + five_percent; + } + break; + case GDK_Left: + digested = TRUE; + if(event->state & GDK_CONTROL_MASK) + { + new_value = 0; + } + else + { + new_value = current_value - five_percent; + } + break; + case GDK_plus: + digested = TRUE; + new_value = current_value + five_percent; + break; + case GDK_minus: + digested = TRUE; + new_value = current_value - five_percent; + break; + default: + break; } - return digested; + + new_value = CLAMP(new_value, 0, 100); + if(new_value != current_value && current_state != STATE_MUTED) + { + g_debug("Attempting to set the range from the key listener to %f", new_value); + // In order to ensure that the exterior filtering does not catch this, reset the exterior_vol_update + // to ensure these updates. + exterior_vol_update = OUT_OF_RANGE; + gtk_range_set_value(range, new_value); + } + } + return digested; } static void style_changed_cb(GtkWidget *widget, gpointer user_data) { - g_debug("Just caught a style change event"); - update_state(current_state); - reset_mute_blocking_animation(); - update_state(current_state); - free_the_animation_list(); - prepare_blocked_animation(); + g_debug("Just caught a style change event"); + update_state(current_state); + reset_mute_blocking_animation(); + update_state(current_state); + free_the_animation_list(); + prepare_blocked_animation(); } static void scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) { - if (device_available == FALSE || current_state == STATE_MUTED) - return; + if (device_available == FALSE || current_state == STATE_MUTED) + return; - IndicatorSound *sound = INDICATOR_SOUND (io); - GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider)); - gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider)); + IndicatorSound *sound = INDICATOR_SOUND (io); + GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider)); + gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider)); - if (direction == INDICATOR_OBJECT_SCROLL_UP){ - value += adj->step_increment; - } - else{ - value -= adj->step_increment; - } - gtk_range_set_value (GTK_RANGE (sound->slider), - value); + if (direction == INDICATOR_OBJECT_SCROLL_UP){ + value += adj->step_increment; + } + else{ + value -= adj->step_increment; + } + gtk_range_set_value (GTK_RANGE (sound->slider), value); } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c2cfc7a..cd5d65d 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -49,6 +49,7 @@ public class MusicPlayerBridge : GLib.Object string client_name = type.split(".")[1]; if (root_menu != null && client_name != null){ Dbusmenu.Menuitem client_item = new Dbusmenu.Menuitem(); + client_item.property_set(MENUITEM_PROP_LABEL, client_name.concat(" is registered")); registered_clients.set(client_name, client_item); root_menu.child_append(client_item); diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index cb72524..8a21fcf 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -53,8 +53,8 @@ static void slider_menu_item_class_init (SliderMenuItemClass *klass) object_class->dispose = slider_menu_item_dispose; object_class->finalize = slider_menu_item_finalize; - DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); - mclass->handle_event = handle_event; + DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); + mclass->handle_event = handle_event; return; } @@ -81,10 +81,10 @@ static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) { g_debug("in the handle event method of slider_menu_item"); - gdouble volume_input = 0; - volume_input = g_value_get_double(value); - if(value != NULL) - set_sink_volume(volume_input); + gdouble volume_input = 0; + volume_input = g_value_get_double(value); + if(value != NULL) + set_sink_volume(volume_input); } @@ -92,9 +92,9 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_volume) { SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL); - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_SLIDER_MENUITEM_TYPE); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_SLIDER_MENUITEM_TYPE); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); return self; } diff --git a/src/transport-bar.c b/src/transport-bar.c new file mode 100644 index 0000000..ef1edb4 --- /dev/null +++ b/src/transport-bar.c @@ -0,0 +1,94 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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/>. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib/gi18n.h> +#include "transport-bar.h" +#include "common-defs.h" + +typedef struct _TransportBarPrivate TransportBarPrivate; + +struct _TransportBarPrivate +{ +}; + +#define TRANSPORT_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRANSPORT_BAR_TYPE, TransportBarPrivate)) + +/* Prototypes */ +static void transport_bar_class_init (TransportBarClass *klass); +static void transport_bar_init (TransportBar *self); +static void transport_bar_dispose (GObject *object); +static void transport_bar_finalize (GObject *object); +//static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); +G_DEFINE_TYPE (TransportBar, transport_bar, DBUSMENU_TYPE_MENUITEM); + +static void +transport_bar_class_init (TransportBarClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (TransportBarPrivate)); + + object_class->dispose = transport_bar_dispose; + object_class->finalize = transport_bar_finalize; + + //DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); + //mclass->handle_event = handle_event; + return; +} + +static void +transport_bar_init (TransportBar *self) +{ + g_debug("Building new Transport Item"); + return; +} + +static void +transport_bar_dispose (GObject *object) +{ + G_OBJECT_CLASS (transport_bar_parent_class)->dispose (object); + return; +} + +static void +transport_bar_finalize (GObject *object) +{ + G_OBJECT_CLASS (transport_bar_parent_class)->finalize (object); +} + + +//static void +//handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) +//{ +// g_debug("TransportBar -> handle event caught!"); +//} + + + +TransportBar* +transport_bar_new() +{ + TransportBar *self = g_object_new(TRANSPORT_BAR_TYPE, NULL); + //dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE); + return self; +} diff --git a/src/transport-bar.h b/src/transport-bar.h new file mode 100644 index 0000000..77a1a97 --- /dev/null +++ b/src/transport-bar.h @@ -0,0 +1,49 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +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/>. +*/ +#ifndef __TRANSPORT_BAR_H__ +#define __TRANSPORT_BAR_H__ + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TRANSPORT_BAR_TYPE (transport_bar_get_type ()) +#define TRANSPORT_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRANSPORT_BAR_TYPE, TransportBar)) +#define TRANSPORT_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRANSPORT_BAR_TYPE, TransportBarClass)) +#define IS_TRANSPORT_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRANSPORT_BAR_TYPE)) +#define IS_TRANSPORT_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRANSPORT_BAR_TYPE)) +#define TRANSPORT_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRANSPORT_BAR_TYPE, TransportBarClass)) + +typedef struct _TransportBar TransportBar; +typedef struct _TransportBarClass TransportBarClass; + +struct _TransportBarClass { +}; + +struct _TransportBar { +}; + +GType transport_item_get_type (void); +TransportBar* transport_item_new(); + +G_END_DECLS + +#endif + diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala new file mode 100644 index 0000000..812ef6a --- /dev/null +++ b/src/transport-menu-item.vala @@ -0,0 +1,19 @@ +using Dbusmenu; +using Gee; + +public class TransportMenuItem : Dbusmenu.Menuitem +{ + /* Not ideal duplicate definition of const - see common-defs/h */ + const string DBUSMENU_TRANSPORT_MENUITEM_TYPE = "x-canonical-transport-bar"; + + public TransportMenuItem() + { + this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE); + } + + public override void handle_event(string name, GLib.Value value, uint timestamp) + { + debug("TransportItem -> handle event caught!"); + } + +}
\ No newline at end of file |