aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/indicator-sound.c72
-rw-r--r--src/pulse-manager.h2
-rw-r--r--src/sound-service.c2
3 files changed, 69 insertions, 7 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){
diff --git a/src/pulse-manager.h b/src/pulse-manager.h
index 5271628..8fa32b3 100644
--- a/src/pulse-manager.h
+++ b/src/pulse-manager.h
@@ -21,6 +21,6 @@ pa_context* get_context(void);
void establish_pulse_activities(SoundServiceDbus *service);
void set_sink_volume(gdouble percent);
void toggle_global_mute(gboolean mute_value);
-
+void close_pulse_activites();
diff --git a/src/sound-service.c b/src/sound-service.c
index 7cf065c..101cd18 100644
--- a/src/sound-service.c
+++ b/src/sound-service.c
@@ -76,7 +76,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service
dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _(b_all_muted == FALSE ? "Mute All" : "Unmute"));
g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute), NULL);
//TODO: If no valid sinks are found grey out the item(s)
- dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, b_sink_available);
+ dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available);
// Slider
volume_slider_menuitem = slider_menu_item_new(b_sink_available, volume_percent);