aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-sound.c
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-02-04 18:01:13 -0800
committerConor Curran <conor.curran@canonical.com>2010-02-04 18:01:13 -0800
commit279ebae33dd7790293516ad8e4c4a179b83d5186 (patch)
treeee2500758726d3af08fe2df57aec9c94f81f4633 /src/indicator-sound.c
parentf63890bd42b350f80c7a8d13adda9ffc58e18eb1 (diff)
downloadayatana-indicator-sound-279ebae33dd7790293516ad8e4c4a179b83d5186.tar.gz
ayatana-indicator-sound-279ebae33dd7790293516ad8e4c4a179b83d5186.tar.bz2
ayatana-indicator-sound-279ebae33dd7790293516ad8e4c4a179b83d5186.zip
updates for libdbus changes and new state machine pattern for the icon indicator
Diffstat (limited to 'src/indicator-sound.c')
-rw-r--r--src/indicator-sound.c72
1 files changed, 67 insertions, 5 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index 5ca4df7..89b64dd 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -79,17 +79,30 @@ 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 GtkImage *speaker_image = NULL;
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, double value, gpointer user_data);
static void change_speaker_image(gdouble volume_percent);
+static void prepare_state_machine();
// DBUS communication
static DBusGProxy *sound_dbus_proxy = NULL;
static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata);
-static void catch_signal(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata);
+static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata);
+
+/****Volume States 'members' ***/
+static const gint STATE_MUTED = 0;
+static const gint STATE_ZERO = 1;
+static const gint STATE_LOW = 2;
+static const gint STATE_MEDIUM = 3;
+static const gint STATE_HIGH = 4;
+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 = STATE_MUTED;
+static gint previous_state = STATE_MUTED;
static void
indicator_sound_class_init (IndicatorSoundClass *klass)
@@ -119,9 +132,43 @@ 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();
+
return;
}
+
+static void test_images_hash()
+{
+ gchar* name;
+ name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0));
+ g_debug("image name = %s", 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), "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)
{
@@ -143,7 +190,7 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u
}
g_debug("about to connect to the signals");
dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal), NULL, NULL);
+ dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL);
}
} else {
@@ -153,7 +200,6 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u
return;
}
-
static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata)
{
//gtk_image_set_from_icon_name(speaker_image, "audio-volume-muted-blocking-symbolic", GTK_ICON_SIZE_MENU);
@@ -169,6 +215,7 @@ indicator_sound_dispose (GObject *object)
g_object_unref(G_OBJECT(self->service));
self->service = NULL;
}
+ g_hash_table_destroy(volume_states);
G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object);
return;
}
@@ -189,11 +236,26 @@ get_label (IndicatorObject * io)
static GtkImage *
get_icon (IndicatorObject * io)
{
- speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name("audio-volume-high", GTK_ICON_SIZE_MENU));
+ gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
+ g_debug("At start-up attempting to set the image to %s", image_name);
+ speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(image_name, GTK_ICON_SIZE_MENU));
gtk_widget_show(GTK_WIDGET(speaker_image));
return speaker_image;
}
+static void update_state(const gint state)
+{
+ previous_state = current_state;
+ current_state = state;
+ gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
+ gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU);
+}
+
+static void determine_state(gdouble volume_percent)
+{
+
+}
+
static void change_speaker_image(gdouble volume_percent)
{
if (volume_percent < 30.0 && volume_percent > 0){