aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-02-18 13:05:58 +0000
committerConor Curran <conor.curran@canonical.com>2011-02-18 13:05:58 +0000
commitd8cc480485f8f46142298341ef5336a0572be5b4 (patch)
tree80f848454f6bc39384d9eb58e9b4f5c03ce337ba
parent8263f9aed8c1c66cfe7a7749a4d78c096165acd3 (diff)
downloadayatana-indicator-sound-d8cc480485f8f46142298341ef5336a0572be5b4.tar.gz
ayatana-indicator-sound-d8cc480485f8f46142298341ef5336a0572be5b4.tar.bz2
ayatana-indicator-sound-d8cc480485f8f46142298341ef5336a0572be5b4.zip
all working nicely, custom mute behaviour needed
-rw-r--r--src/active-sink.c25
-rw-r--r--src/active-sink.h31
-rw-r--r--src/mute-menu-item.c1
-rw-r--r--src/pulseaudio-mgr.c12
-rw-r--r--src/voip-input-menu-item.c67
-rw-r--r--src/voip-input-menu-item.h10
-rw-r--r--src/voip-input-widget.c4
7 files changed, 117 insertions, 33 deletions
diff --git a/src/active-sink.c b/src/active-sink.c
index d97419b..2e212e7 100644
--- a/src/active-sink.c
+++ b/src/active-sink.c
@@ -53,7 +53,6 @@ static pa_cvolume active_sink_construct_mono_volume (const pa_cvolume* vol);
static void active_sink_volume_update (ActiveSink* self, gdouble percent);
static void active_sink_mute_update (ActiveSink* self, gboolean muted);
-
G_DEFINE_TYPE (ActiveSink, active_sink, G_TYPE_OBJECT);
static void
@@ -88,17 +87,28 @@ active_sink_init (ActiveSink *self)
}
void
-active_sink_activate_voip_item (ActiveSink* self)
+active_sink_activate_voip_item (ActiveSink* self, gint sink_input_index, gint client_index)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- voip_input_menu_item_enable (priv->voip_input_menu_item, TRUE);
+ if (voip_input_menu_item_is_interested (priv->voip_input_menu_item,
+ sink_input_index,
+ client_index)){
+ voip_input_menu_item_enable (priv->voip_input_menu_item, TRUE);
+ }
}
void
active_sink_deactivate_voip_source (ActiveSink* self)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- voip_input_menu_item_enable (priv->voip_input_menu_item, FALSE);
+ voip_input_menu_item_deactivate_source (priv->voip_input_menu_item);
+}
+
+void
+active_sink_deactivate_voip_client (ActiveSink* self)
+{
+ ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
+ voip_input_menu_item_deactivate_voip_client (priv->voip_input_menu_item);
}
@@ -186,6 +196,13 @@ active_sink_update_volume (ActiveSink* self, gdouble percent)
}
+gint
+active_sink_get_current_sink_input_index (ActiveSink* sink)
+{
+ ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);
+ return voip_input_menu_item_get_sink_input_index (priv->voip_input_menu_item);
+}
+
static void
active_sink_mute_update (ActiveSink* self, gboolean muted)
{
diff --git a/src/active-sink.h b/src/active-sink.h
index 5c6b31a..52f0e47 100644
--- a/src/active-sink.h
+++ b/src/active-sink.h
@@ -50,27 +50,34 @@ struct _ActiveSinkClass {
GType active_sink_get_type (void) G_GNUC_CONST;
+/**
+ * TODO
+ * Refactor this to become a device manager obj basically acting as wrapper for
+ * the communication between pulseaudio-mgr and the individual items.
+ * First steps collapse slider/volume related stuff into slider-menu-item.
+ */
+
+// Sink related
void active_sink_populate (ActiveSink* sink, const pa_sink_info* update);
void active_sink_update (ActiveSink* sink, const pa_sink_info* update);
-void active_sink_update_voip_input_source (ActiveSink* sink, const pa_source_info* update);
-void active_sink_activate_voip_item (ActiveSink* sink);
-
-gboolean active_sink_is_voip_source_populated (ActiveSink* sink);
gboolean active_sink_is_populated (ActiveSink* sink);
-
-void active_sink_determine_blocking_state (ActiveSink* self);
-
gint active_sink_get_index (ActiveSink* self);
-gint active_sink_get_source_index (ActiveSink* self);
-
-SoundState active_sink_get_state (ActiveSink* self);
-
void active_sink_deactivate (ActiveSink* self);
-void active_sink_deactivate_voip_source (ActiveSink* self);
void active_sink_update_mute (ActiveSink* self, gboolean mute_update);
void active_sink_update_volume (ActiveSink* self, gdouble percent);
void active_sink_ensure_sink_is_unmuted (ActiveSink* self);
+// source and sinkinput/client related for VOIP functionality
+void active_sink_update_voip_input_source (ActiveSink* sink, const pa_source_info* update);
+void active_sink_activate_voip_item (ActiveSink* sink, gint sink_input_index, gint client_index);
+gint active_sink_get_current_sink_input_index (ActiveSink* sink);
+gboolean active_sink_is_voip_source_populated (ActiveSink* sink);
+gint active_sink_get_source_index (ActiveSink* self);
+void active_sink_determine_blocking_state (ActiveSink* self);
+void active_sink_deactivate_voip_source (ActiveSink* self);
+void active_sink_deactivate_voip_client (ActiveSink* self);
+SoundState active_sink_get_state (ActiveSink* self);
+
ActiveSink* active_sink_new (SoundServiceDbus* service);
G_END_DECLS
diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c
index 8409b9f..2876be3 100644
--- a/src/mute-menu-item.c
+++ b/src/mute-menu-item.c
@@ -61,6 +61,7 @@ mute_menu_item_init (MuteMenuItem *self)
{
g_debug("Building new Mute Menu Item");
MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self);
+ priv->button = NULL;
priv->button = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set_bool (priv->button,
DBUSMENU_MENUITEM_PROP_VISIBLE,
diff --git a/src/pulseaudio-mgr.c b/src/pulseaudio-mgr.c
index 1cfe7af..8f7a290 100644
--- a/src/pulseaudio-mgr.c
+++ b/src/pulseaudio-mgr.c
@@ -229,7 +229,13 @@ pm_subscribed_events_callback (pa_context *c,
// We don't care about sink input removals.
g_debug ("sink input event");
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
- g_debug ("Just saw a sink input removal event - index = %i", index);
+ gint cached_index = active_sink_get_current_sink_input_index (sink);
+
+ g_debug ("Just saw a sink input removal event - index = %i and cached index = %i", index, cached_index);
+
+ if (index == cached_index){
+ active_sink_deactivate_voip_client (sink);
+ }
}
else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
g_debug ("some new sink input event ? - index = %i", index);
@@ -440,8 +446,8 @@ pm_sink_input_info_callback (pa_context *c,
const char* value = pa_proplist_gets (info->proplist, PA_PROP_MEDIA_ROLE);
g_debug ("prop role = %s", value);
if (g_strcmp0 (value, "phone") == 0) {
- g_debug ("And yes its a VOIP app ...");
- active_sink_activate_voip_item (a_sink);
+ g_debug ("And yes its a VOIP app ... sink input index = %i", info->index);
+ active_sink_activate_voip_item (a_sink, (gint)info->index, (gint)info->client);
// TODO to start with we will assume our source is the same as what this 'client'
// is pointing at. This should probably be more intelligent :
// query for the list of source output info's and going on the name of the client
diff --git a/src/voip-input-menu-item.c b/src/voip-input-menu-item.c
index 54e12e6..498fb77 100644
--- a/src/voip-input-menu-item.c
+++ b/src/voip-input-menu-item.c
@@ -34,8 +34,9 @@ struct _VoipInputMenuItemPrivate {
guint32 volume_steps;
pa_channel_map channel_map;
pa_volume_t base_volume;
- gint index;
+ gint source_index;
gint sink_input_index;
+ gint client_index;
};
#define VOIP_INPUT_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VOIP_INPUT_MENU_ITEM_TYPE, VoipInputMenuItemPrivate))
@@ -80,7 +81,9 @@ voip_input_menu_item_init (VoipInputMenuItem *self)
DBUSMENU_MENUITEM_PROP_VISIBLE,
FALSE );
- priv->index = DEVICE_NOT_ACTIVE;
+ priv->source_index = DEVICE_NOT_ACTIVE;
+ priv->sink_input_index = DEVICE_NOT_ACTIVE;
+ priv->client_index = DEVICE_NOT_ACTIVE;
}
static void
@@ -108,7 +111,7 @@ handle_event (DbusmenuMenuitem * mi,
input = g_variant_get_variant(value);
}
- gboolean percent = g_variant_get_double(input);
+ gdouble percent = g_variant_get_double(input);
if (value != NULL){
if (IS_VOIP_INPUT_MENU_ITEM (mi)) {
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (VOIP_INPUT_MENU_ITEM (mi));
@@ -119,7 +122,7 @@ handle_event (DbusmenuMenuitem * mi,
pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
pa_cvolume_set(&new_volume, 1, new_volume_value);
- pm_update_mic_gain (priv->index, new_volume);
+ pm_update_mic_gain (priv->source_index, new_volume);
//active_sink_update_volume (priv->a_sink, volume_input);
//active_sink_ensure_sink_is_unmuted (priv->a_sink);
}
@@ -143,11 +146,11 @@ voip_input_menu_item_update (VoipInputMenuItem* item,
{
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
// only overwrite the constants of each source if the device has changed
- if (priv->index == DEVICE_NOT_ACTIVE){
+ if (priv->source_index == DEVICE_NOT_ACTIVE){
priv->base_volume = source->base_volume;
priv->volume_steps = source->n_volume_steps;
priv->channel_map = source->channel_map;
- priv->index = source->index;
+ priv->source_index = source->index;
}
priv->volume = voip_input_menu_item_construct_mono_volume (&source->volume);
priv->mute = source->mute;
@@ -162,33 +165,75 @@ voip_input_menu_item_update (VoipInputMenuItem* item,
}
gboolean
+voip_input_menu_item_is_interested (VoipInputMenuItem* item,
+ gint sink_input_index,
+ gint client_index)
+{
+ VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
+ // Check to make sure we are not handling another voip beforehand and that we
+ // have an active sink (might need to match up at start up)
+ if (priv->sink_input_index != DEVICE_NOT_ACTIVE &&
+ priv->source_index != DEVICE_NOT_ACTIVE){
+ return FALSE;
+ }
+
+ priv->sink_input_index = sink_input_index;
+
+ g_debug ("vimi - siindex = %i", sink_input_index);
+ g_debug ("vimi - siindex stored = %i", priv->sink_input_index);
+
+ priv->client_index = client_index;
+
+ return TRUE;
+}
+
+
+gboolean
voip_input_menu_item_is_populated (VoipInputMenuItem* item)
{
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
- return priv->index != -1;
+ return priv->source_index != DEVICE_NOT_ACTIVE;
}
gint
voip_input_menu_item_get_index (VoipInputMenuItem* item)
{
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
- return priv->index;
+ return priv->source_index;
+}
+
+gint
+voip_input_menu_item_get_sink_input_index (VoipInputMenuItem* item)
+{
+ VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
+
+ return priv->sink_input_index;
+}
+
+void
+voip_input_menu_item_deactivate_source (VoipInputMenuItem* item)
+{
+ VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
+ priv->source_index = DEVICE_NOT_ACTIVE;
+ voip_input_menu_item_enable (item, FALSE);
}
void
-voip_input_menu_item_deactivate (VoipInputMenuItem* item)
+voip_input_menu_item_deactivate_voip_client (VoipInputMenuItem* item)
{
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
- priv->index = -1;
+ priv->client_index = DEVICE_NOT_ACTIVE;
+ priv->sink_input_index = DEVICE_NOT_ACTIVE;
voip_input_menu_item_enable (item, FALSE);
}
+
void
voip_input_menu_item_enable (VoipInputMenuItem* item,
gboolean active)
{
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
- if (priv->index == -1 && active == TRUE) {
+ if (priv->source_index == DEVICE_NOT_ACTIVE && active == TRUE) {
g_warning ("Tried to enable the VOIP menuitem but we don't have an active source ??");
active = FALSE;
}
diff --git a/src/voip-input-menu-item.h b/src/voip-input-menu-item.h
index 70dc9fa..5a62393 100644
--- a/src/voip-input-menu-item.h
+++ b/src/voip-input-menu-item.h
@@ -49,9 +49,17 @@ GType voip_input_menu_item_get_type (void);
void voip_input_menu_item_update (VoipInputMenuItem* item,
const pa_source_info* source);
void voip_input_menu_item_enable (VoipInputMenuItem* item, gboolean active);
+gboolean voip_input_menu_item_is_interested (VoipInputMenuItem* item,
+ gint sink_input_index,
+ gint client_index);
gboolean voip_input_menu_item_is_populated (VoipInputMenuItem* item);
+// TODO rename get source index
gint voip_input_menu_item_get_index (VoipInputMenuItem* item);
-void voip_input_menu_item_deactivate (VoipInputMenuItem* item);
+
+gint voip_input_menu_item_get_sink_input_index (VoipInputMenuItem* item);
+
+void voip_input_menu_item_deactivate_source (VoipInputMenuItem* item);
+void voip_input_menu_item_deactivate_voip_client (VoipInputMenuItem* item);
VoipInputMenuItem* voip_input_menu_item_new (ActiveSink* sink);
diff --git a/src/voip-input-widget.c b/src/voip-input-widget.c
index fa58d21..de06c7c 100644
--- a/src/voip-input-widget.c
+++ b/src/voip-input-widget.c
@@ -96,12 +96,12 @@ voip_input_widget_init (VoipInputWidget *self)
g_signal_connect(priv->ido_voip_input_slider, "slider-released", G_CALLBACK(voip_input_widget_slider_released), self);
GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)priv->ido_voip_input_slider);
- GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks("audio-volume-low-zero-panel");
+ GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks("audio-input-microphone");
gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU);
g_object_unref(primary_gicon);
GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)priv->ido_voip_input_slider);
- GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks("audio-input-microphone");
+ GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks("audio-input-microphone-high");
gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU);
g_object_unref(secondary_gicon);