aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-02-09 18:13:58 +0000
committerConor Curran <conor.curran@canonical.com>2010-02-09 18:13:58 +0000
commit8046b1e98594e5be7a0c3392a0348577a18dce54 (patch)
tree136f0013863e20ed47a6f4ba68889906c49de6a1 /src
parent1ae774f7367f91f40f94a845c525ddedf1ddbba5 (diff)
downloadayatana-indicator-sound-8046b1e98594e5be7a0c3392a0348577a18dce54.tar.gz
ayatana-indicator-sound-8046b1e98594e5be7a0c3392a0348577a18dce54.tar.bz2
ayatana-indicator-sound-8046b1e98594e5be7a0c3392a0348577a18dce54.zip
slider init'd with the correct value - geesh
Diffstat (limited to 'src')
-rw-r--r--src/indicator-sound.c102
-rw-r--r--src/pulse-manager.c4
-rw-r--r--src/sound-service-dbus.c121
-rw-r--r--src/sound-service-dbus.h4
-rw-r--r--src/sound-service.c16
-rw-r--r--src/sound-service.xml7
6 files changed, 120 insertions, 134 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index 588b2d6..3103aac 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -78,13 +78,12 @@ static GtkLabel * get_label (IndicatorObject * io);
static GtkImage * get_icon (IndicatorObject * io);
static GtkMenu * get_menu (IndicatorObject * io);
static GtkWidget *volume_slider = NULL;
-static gdouble input_value_from_across_the_dbus = 0.0;
static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget);
static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data);
/*static void change_speaker_image(gdouble volume_percent);*/
-/*static void prepare_state_machine();*/
+static void prepare_state_machine();
// DBUS communication
static DBusGProxy *sound_dbus_proxy = NULL;
@@ -102,8 +101,9 @@ static const gint STATE_MUTED_WHILE_INPUT = 5;
static const gint STATE_SINKS_NONE = 5;
static GHashTable *volume_states = NULL;
static GtkImage *speaker_image = NULL;
-/*static gint current_state = 0;*/
-//static gint previous_state = 0;
+static gint current_state = 0;
+static gint previous_state = 0;
+static gdouble initial_volume_percent = 0;
static void
indicator_sound_class_init (IndicatorSoundClass *klass)
@@ -133,43 +133,36 @@ static void indicator_sound_init (IndicatorSound *self)
/* Now let's fire these guys up. */
self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION);
g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self);
- //prepare_state_machine();
-
+ prepare_state_machine();
return;
}
-/*static void test_images_hash()*/
-/*{*/
-/* gchar* name;*/
-/* g_debug("about to test the images hash"); */
-/* name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0));*/
-/* g_debug("image name = %s", name); */
-/*}*/
+static void test_images_hash()
+{
+ g_debug("about to test the images hash");
+ gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
+ g_debug("start up current image name = %s", current_name);
+ gchar* previous_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(previous_state));
+ g_debug("start up previous image name = %s", previous_name);
+}
+
+/*
+Prepare states Array.
+*/
+static void prepare_state_machine()
+{
+ volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none"));
+ test_images_hash();
+}
-/*/***/
-/*Prepare states Array.*/
-/***/
-/*static void prepare_state_machine()*/
-/*{*/
-/* volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none");*/
-/* test_images_hash();*/
-/*}*/
-/*static void destroy_volume_image_info(void *value)*/
-/*{*/
-/* gchar* name = (gchar*)value;*/
-/* g_free(name);*/
-/* g_free(sink->description); */
-/* g_free(sink->icon_name); */
-/* g_free(sink); */
-/*}*/
static void
connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata)
@@ -195,8 +188,17 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u
dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL);
dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL);
-/* dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID);*/
-/* dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL);*/
+ gdouble *volume_percent_input;
+ volume_percent_input = g_new0(gdouble, 1);
+ org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error);
+ if (error != NULL) {
+ g_warning("Unable to fetch volume at indicator start up: %s", error->message);
+ g_error_free(error);
+ g_free(volume_percent_input);
+ return;
+ }
+ initial_volume_percent = *volume_percent_input * 100;
+ g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent);
}
} else {
@@ -219,14 +221,6 @@ static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_p
gtk_range_set_value(range, volume_percent);
}
-/*static void catch_signal_sink_mute_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata)*/
-/*{*/
-/* g_debug("signal caught - update sink volume with value : %f", volume_percent);*/
-/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/
-/* GtkRange* range = (GtkRange*)slider; */
-/* gtk_range_set_value(range, volume_percent); */
-/*}*/
-
static void
indicator_sound_dispose (GObject *object)
@@ -320,6 +314,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
g_signal_connect(slider, "change-value", G_CALLBACK(slider_value_changed_event_cb), newitem);
+ GtkRange* range = (GtkRange*)slider;
+ gtk_range_set_value(range, initial_volume_percent);
+
gtk_widget_show_all(volume_slider);
return TRUE;
}
@@ -328,27 +325,20 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
we need to be responsive to that. */
static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget)
{
- g_debug("slider_prop_change_cb ");
+ g_debug("slider_prop_change_cb - dodgy updater ");
g_debug("about to set the slider to %f", g_value_get_double(value));
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
- GtkRange* range = (GtkRange*)slider;
- gdouble level;
- level = gtk_range_get_fill_level(range);
- input_value_from_across_the_dbus = level;
- g_debug("the current level is %f", level);
-
+ GtkRange* range = (GtkRange*)slider;
gtk_range_set_value(range, g_value_get_double(value));
return;
}
static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data)
{
-/* #if(slider_value != input_value_from_across_the_dbus)*/
-/* #{ */
DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data;
gdouble clamped_input = CLAMP(input_value, 0, 100);
GValue value = {0};
- g_debug("User input Event listener for the range - input received = %f", clamped_input);
+ g_debug("User input on SLIDER - = %f", clamped_input);
g_value_init(&value, G_TYPE_DOUBLE);
g_value_set_double(&value, clamped_input);
dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0);
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index 169c0df..e7570c6 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -187,14 +187,14 @@ For now this callback it assumes it only used at startup. It may be necessary to
static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, int eol, void *userdata)
{
if (eol > 0) {
- gboolean device_available;
- device_available = sink_available();
+ gboolean device_available = sink_available();
if(device_available == TRUE)
{
// Hopefully the PA server has set the default device if not default to 0
DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? 0 : DEFAULT_SINK_INDEX;
test_hash();
update_pa_state(TRUE, device_available, default_sink_is_muted(), get_default_sink_volume());
+ sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume());
g_debug("default sink index : %d", DEFAULT_SINK_INDEX);
}
else{
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index bcc21f6..ac92a06 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -25,18 +25,23 @@
#include <dbus/dbus-glib.h>
#include "dbus-shared-names.h"
#include "sound-service-dbus.h"
-#include "sound-service-server.h"
#include "common-defs.h"
#include "sound-service-marshal.h"
#include "pulse-manager.h"
+// DBUS methods -
+// TODO - other should be static and moved from the header to here
+static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror);
+
+#include "sound-service-server.h"
+
typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate;
struct _SoundServiceDbusPrivate
{
DBusGConnection *system_bus;
DBusGConnection *connection;
- GHashTable *sinks_hash;
+ gdouble volume_percent;
};
@@ -44,7 +49,6 @@ struct _SoundServiceDbusPrivate
enum {
SINK_INPUT_WHILE_MUTED,
SINK_VOLUME_UPDATE,
- SINK_MUTE_UPDATE,
LAST_SIGNAL
};
@@ -53,12 +57,12 @@ static guint signals[LAST_SIGNAL] = { 0 };
#define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate))
-
static void sound_service_dbus_class_init (SoundServiceDbusClass *klass);
static void sound_service_dbus_init (SoundServiceDbus *self);
static void sound_service_dbus_dispose (GObject *object);
static void sound_service_dbus_finalize (GObject *object);
+
/* GObject Boilerplate */
G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT);
@@ -92,15 +96,51 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass)
g_cclosure_marshal_VOID__DOUBLE,
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
-/* signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update",*/
-/* G_TYPE_FROM_CLASS (klass),*/
-/* G_SIGNAL_RUN_LAST,*/
-/* 0,*/
-/* NULL, NULL,*/
-/* g_cclosure_marshal_VOID__BOOLEAN,*/
-/* G_TYPE_NONE, 1, G_TYPE_BOOLEAN);*/
}
+static void
+sound_service_dbus_init (SoundServiceDbus *self)
+{
+ GError *error = NULL;
+ SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
+
+ priv->system_bus = NULL;
+ priv->connection = NULL;
+ priv->volume_percent = 0;
+
+ /* Get the system bus */
+ priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ /* Put the object on DBus */
+ priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+
+ if (error != NULL) {
+ g_error("Unable to connect to the session bus when creating application indicator: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ dbus_g_connection_register_g_object(priv->connection,
+ "/org/ayatana/indicator/sound/service",
+ G_OBJECT(self));
+
+ return;
+}
+
+
+static void
+sound_service_dbus_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (sound_service_dbus_parent_class)->dispose (object);
+ return;
+}
+
+static void
+sound_service_dbus_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (sound_service_dbus_parent_class)->finalize (object);
+ return;
+}
+
+
/**
DBUS Method Callbacks
**/
@@ -110,13 +150,12 @@ void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint v
set_sink_volume(volume_percent);
}
-//TODO needed ?
-GList *
-sound_service_dbus_get_sink_list (SoundServiceDbus *self)
+static gboolean sound_service_dbus_get_sink_volume (SoundServiceDbus *self, gdouble *volume_percent_input, GError** gerror)
{
- SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
-
- return g_hash_table_get_keys (priv->sinks_hash);
+ SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
+ g_debug("Get sink volume method in the sound service dbus!, about to send over volume percent of %f", priv->volume_percent);
+ *volume_percent_input = priv->volume_percent;
+ return TRUE;
}
@@ -137,6 +176,9 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_
void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume)
{
+ SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj);
+ priv->volume_percent = sink_volume;
+
g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", sink_volume);
g_signal_emit(obj,
signals[SINK_VOLUME_UPDATE],
@@ -153,50 +195,5 @@ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_v
/* sink_mute);*/
/*}*/
-// TODO needed?
-void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks)
-{
- SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
- priv->sinks_hash = sinks;
-}
-static void
-sound_service_dbus_init (SoundServiceDbus *self)
-{
- GError *error = NULL;
- SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
-
- priv->system_bus = NULL;
- priv->connection = NULL;
-
- /* Get the system bus */
- priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- /* Put the object on DBus */
- priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
-
- if (error != NULL) {
- g_error("Unable to connect to the session bus when creating application indicator: %s", error->message);
- g_error_free(error);
- return;
- }
- dbus_g_connection_register_g_object(priv->connection,
- "/org/ayatana/indicator/sound/service",
- G_OBJECT(self));
-
- return;
-}
-
-static void
-sound_service_dbus_dispose (GObject *object)
-{
- G_OBJECT_CLASS (sound_service_dbus_parent_class)->dispose (object);
- return;
-}
-
-static void
-sound_service_dbus_finalize (GObject *object)
-{
- G_OBJECT_CLASS (sound_service_dbus_parent_class)->finalize (object);
- return;
-}
diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h
index dc52861..08d4bbd 100644
--- a/src/sound-service-dbus.h
+++ b/src/sound-service-dbus.h
@@ -53,18 +53,14 @@ struct _SoundServiceDbusClass {
void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data);
void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data);
};
-
GType sound_service_dbus_get_type (void) G_GNUC_CONST;
// Utility methods to get the messages across into the sound-service-dbus
void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value);
void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume);
-void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks);
// DBUS METHODS
void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror);
-GList *sound_service_dbus_get_sink_list(SoundServiceDbus* service);
-
G_END_DECLS
diff --git a/src/sound-service.c b/src/sound-service.c
index cc39e38..503dc5a 100644
--- a/src/sound-service.c
+++ b/src/sound-service.c
@@ -107,8 +107,9 @@ static void set_global_mute_from_ui()
/* GValue value = {0};*/
/* g_value_init(&value, G_TYPE_DOUBLE);*/
-/* g_value_set_double(&value, 100.0);*/
+/* g_value_set_double(&value, 99.0);*/
/* // Testing*/
+/* g_debug("BUGGY volume update");*/
/* dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value);*/
}
@@ -121,7 +122,6 @@ service_shutdown (IndicatorService *service, gpointer user_data)
{
if (mainloop != NULL) {
-
g_debug("Service shutdown - but commented out for right now");
// TODO: uncomment for release
/* close_pulse_activites()*/
@@ -138,11 +138,6 @@ void update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_m
volume_percent = percent;
g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent);
rebuild_sound_menu(root_menuitem, dbus_interface);
- GValue value = {0};
- g_value_init(&value, G_TYPE_DOUBLE);
- g_value_set_double(&value, volume_percent * 100);
- g_debug("About to send over the volume slider initial value %f", (volume_percent * 100));
- dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value);
}
@@ -174,6 +169,13 @@ main (int argc, char ** argv)
dbusmenu_server_set_root(server, root_menuitem);
establish_pulse_activities(dbus_interface);
+/* // THIS DOES NOT WORK FROM HERE*/
+/* GValue value = {0};*/
+/* g_value_init(&value, G_TYPE_DOUBLE);*/
+/* g_value_set_double(&value, volume_percent * 100);*/
+/* g_debug("About to send over the volume slider initial value %f", (volume_percent * 100));*/
+/* dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value);*/
+
// Run the loop
mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);
diff --git a/src/sound-service.xml b/src/sound-service.xml
index 8583fbc..4a88aab 100644
--- a/src/sound-service.xml
+++ b/src/sound-service.xml
@@ -5,6 +5,10 @@
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_set_sink_volume"/>
<arg type='u' name='volume_percent' direction="in"/>
</method>
+ <method name = "GetSinkVolume">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_volume"/>
+ <arg type='d' name='volume_percent_input' direction="out"/>
+ </method>
<!-- Will need to hook up another signal which monitors for volume change
Our respective UI element should listen to this and therefore will be updated with accurate setting-->
@@ -17,9 +21,6 @@ Our respective UI element should listen to this and therefore will be updated wi
<signal name="SinkVolumeUpdate">
<arg name="volume_percent" type="u" direction="out"/>
</signal>
-<!-- <signal name="SinkMuteUpdate">-->
-<!-- <arg name="current_mute_value" type="b" direction="out"/>-->
-<!-- </signal>-->
</interface>
</node>