aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-02-04 16:17:31 +0000
committerConor Curran <conor.curran@canonical.com>2011-02-04 16:17:31 +0000
commit025fb0a3df226ab127ee435c341882addfafcbba (patch)
treee7da7aca3e7428e37acf7183ddee3f837d8874d8
parent7ba3797b9006f0a7e048787ee6de91fd05e60d2b (diff)
downloadayatana-indicator-sound-025fb0a3df226ab127ee435c341882addfafcbba.tar.gz
ayatana-indicator-sound-025fb0a3df226ab127ee435c341882addfafcbba.tar.bz2
ayatana-indicator-sound-025fb0a3df226ab127ee435c341882addfafcbba.zip
almost in place
-rw-r--r--src/Makefile.am9
-rw-r--r--src/active-sink.c60
-rw-r--r--src/active-sink.h11
-rw-r--r--src/pulseaudio-mgr.c27
-rw-r--r--src/pulseaudio-mgr.h21
-rw-r--r--src/sound-service-dbus.c31
-rw-r--r--src/sound-service-dbus.h10
7 files changed, 94 insertions, 75 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ed64aeb..63d6d5a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,7 +72,6 @@ music_bridge_VALAFLAGS = \
--pkg gdk-pixbuf-2.0 \
--pkg libxml-2.0
-
$(MAINTAINER_VALAFLAGS)
music_bridge_APIFILES = \
@@ -89,8 +88,10 @@ indicator_sound_service_SOURCES = \
common-defs.h \
sound-service.h \
sound-service.c \
- pulse-manager.h \
- pulse-manager.c \
+ pulseaudio-mgr.h \
+ pulseaudio-mgr.c \
+ active-sink.c \
+ active-sink.h \
sound-service-dbus.h \
sound-service-dbus.c \
slider-menu-item.h \
@@ -108,7 +109,7 @@ indicator_sound_service_LDADD = $(PULSEAUDIO_LIBS) $(SOUNDSERVICE_LIBS) $(GCONF_
# Service xml compilation
#########################
DBUS_SPECS = \
- sound-service.xml
+ sound-service.xml
gen-%.xml.h: %.xml
@echo "Building $@ from $<"
diff --git a/src/active-sink.c b/src/active-sink.c
index b41d6d3..b84e03f 100644
--- a/src/active-sink.c
+++ b/src/active-sink.c
@@ -16,25 +16,27 @@ 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/>.
*/
-
#include <libdbusmenu-glib/menuitem.h>
#include "active-sink.h"
#include "slider-menu-item.h"
#include "mute-menu-item.h"
-
+#include "pulseaudio-mgr.h"
typedef struct _ActiveSinkPrivate ActiveSinkPrivate;
struct _ActiveSinkPrivate
{
- gboolean is_active;
SliderMenuItem* volume_slider_menuitem;
MuteMenuItem* mute_menuitem;
SoundState current_sound_state;
- gint index;
SoundServiceDbus* service;
+ gint index;
+ gchar* name;
+ pa_cvolume volume;
+ pa_channel_map channel_map;
+ pa_volume_t base_volume;
};
#define ACTIVE_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ACTIVE_SINK_TYPE, ActiveSinkPrivate))
@@ -46,6 +48,8 @@ static void active_sink_dispose (GObject *object);
static void active_sink_finalize (GObject *object);
static SoundState active_sink_get_state_from_volume (ActiveSink* self);
+static pa_cvolume active_sink_construct_mono_volume (const pa_cvolume* vol);
+
G_DEFINE_TYPE (ActiveSink, active_sink, G_TYPE_OBJECT);
@@ -64,12 +68,12 @@ static void
active_sink_init(ActiveSink *self)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- priv->details = NULL;
priv->mute_menuitem = NULL;
priv->volume_slider_menuitem = NULL;
priv->current_sound_state = UNAVAILABLE;
- priv->is_active = TRUE;
priv->index = -1;
+ priv->name = NULL;
+ priv->service = NULL;
// Init our menu items.
priv->mute_menuitem = g_object_new (MUTE_MENU_ITEM_TYPE, NULL);
@@ -82,10 +86,10 @@ active_sink_dispose (GObject *object)
ActiveSink * self = ACTIVE_SINK(object);
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- if (priv->details != NULL) {
+ /*if (priv->details != NULL) {
g_free (priv->details->name);
g_free (priv->details);
- }
+ }*/
G_OBJECT_CLASS (active_sink_parent_class)->dispose (object);
}
@@ -96,25 +100,30 @@ active_sink_finalize (GObject *object)
G_OBJECT_CLASS (active_sink_parent_class)->finalize (object);
}
-// This needs to populate the appropriate values on the menu items
void
active_sink_populate (ActiveSink* sink,
- gdouble volume,
- gboolean mute,
- gint device_index)
+ const pa_sink_info* update)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE(sink);
- active_sink_update_volume (sink, volume);
- active_sink_update_mute (sink, mute);
- priv->index = device_index;
- priv->is_active = TRUE;
+
+ priv->name = g_strdup (update->name);
+ priv->index = update->index;
+ // Why the double negative !?
+ active_sink_update_mute (sink, !!update->mute);
+ priv->volume = active_sink_construct_mono_volume (&update->volume);
+ priv->base_volume = update->base_volume;
+ priv->channel_map = update->channel_map;
+
+ pa_volume_t vol = pa_cvolume_max (&update->volume);
+ gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
+ active_sink_update_volume (sink, volume_percent);
}
gboolean
active_sink_is_populated (ActiveSink* sink)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);
- return priv->is_active;
+ return (priv->index != -1);
}
gboolean
@@ -186,13 +195,26 @@ active_sink_get_state_from_volume (ActiveSink* self)
return state;
}
+static pa_cvolume
+active_sink_construct_mono_volume (const pa_cvolume* vol)
+{
+ pa_cvolume new_volume;
+ pa_cvolume_init(&new_volume);
+ new_volume.channels = 1;
+ pa_volume_t max_vol = pa_cvolume_max(vol);
+ pa_cvolume_set(&new_volume, 1, max_vol);
+ return new_volume;
+}
+
+
ActiveSink* active_sink_new (SoundServiceDbus* service)
{
ActiveSink* sink = g_object_new (ACTIVE_SINK_TYPE, NULL);
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);
priv->service = service;
sound_service_dbus_build_sound_menu (service,
- priv->mute_menuitem,
- priv->voluem_slider_menuitem);
+ mute_menu_item_get_button (priv->mute_menuitem),
+ DBUSMENU_MENUITEM (priv->volume_slider_menuitem));
+ pm_establish_pulse_connection (sink);
return sink;
}
diff --git a/src/active-sink.h b/src/active-sink.h
index 827b8a7..3b21d94 100644
--- a/src/active-sink.h
+++ b/src/active-sink.h
@@ -22,8 +22,10 @@
#include <glib.h>
#include <glib-object.h>
-#include <libdbusmenu-glib/menuitem.h>
+
#include "common-defs.h"
+#include "sound-service-dbus.h"
+
#include <pulse/pulseaudio.h>
G_BEGIN_DECLS
@@ -46,7 +48,7 @@ struct _ActiveSinkClass {
GObjectClass parent_class;
};
-typedef struct {
+/*typedef struct {
gchar* name;
gint index;
pa_cvolume volume;
@@ -54,17 +56,20 @@ typedef struct {
gboolean mute;
pa_volume_t base_volume;
} sink_details;
+*/
GType active_sink_get_type (void) G_GNUC_CONST;
-void active_sink_update_details (ActiveSink* sink, sink_details* details);
+void active_sink_populate (ActiveSink* sink, const pa_sink_info* update);
gboolean active_sink_is_populated (ActiveSink* sink);
gboolean active_sink_is_muted (ActiveSink* self);
gint active_sink_get_index (ActiveSink* self);
SoundState active_sink_get_state (ActiveSink* self);
+
void active_sink_update_volume (ActiveSink* self, gdouble vol_percent);
void active_sink_update_mute (ActiveSink* self, gboolean muted);
+ActiveSink* active_sink_new (SoundServiceDbus* service);
G_END_DECLS
diff --git a/src/pulseaudio-mgr.c b/src/pulseaudio-mgr.c
index 28340b7..9fd449d 100644
--- a/src/pulseaudio-mgr.c
+++ b/src/pulseaudio-mgr.c
@@ -62,7 +62,7 @@ static void pm_update_active_sink (pa_context *c,
void *userdata);
-static void pm_populate_active_sink (const pa_sink_info *info, ActiveSink* sink);
+//static void pm_populate_active_sink (const pa_sink_info *info, ActiveSink* sink);
static gboolean reconnect_to_pulse (gpointer user_data);
static pa_cvolume construct_mono_volume(const pa_cvolume* vol);
@@ -74,7 +74,7 @@ static pa_glib_mainloop *pa_main_loop = NULL;
// Entry Point
void
-establish_pulse_activities (ActiveSink* active_sink)
+pm_establish_pulse_connection (ActiveSink* active_sink)
{
pa_main_loop = pa_glib_mainloop_new (g_main_context_default ());
g_assert (pa_main_loop);
@@ -142,7 +142,7 @@ reconnect_to_pulse (gpointer user_data)
}
}
-static void
+/*static void
pm_populate_active_sink (const pa_sink_info *info, ActiveSink* sink)
{
details->index = info->index;
@@ -153,18 +153,9 @@ pm_populate_active_sink (const pa_sink_info *info, ActiveSink* sink)
details->channel_map = info->channel_map;
active_sink_update_details (sink, details);
g_debug ("active sink populated with sink %s", details->name);
-}
+
+}*/
-static pa_cvolume
-construct_mono_volume(const pa_cvolume* vol)
-{
- pa_cvolume new_volume;
- pa_cvolume_init(&new_volume);
- new_volume.channels = 1;
- pa_volume_t max_vol = pa_cvolume_max(vol);
- pa_cvolume_set(&new_volume, 1, max_vol);
- return new_volume;
-}
/**********************************************************************************************************************/
// Pulse-Audio asychronous call-backs
@@ -325,9 +316,10 @@ pm_sink_info_callback (pa_context *c,
return;
}
ActiveSink* a_sink = ACTIVE_SINK (userdata);
- if (active_sink_is_populated (a_sink) &&
+ if (active_sink_is_populated (a_sink) == FALSE &&
g_ascii_strncasecmp("auto_null", sink->name, 9) != 0){
- populate_active_sink (sink, a_sink);
+ active_sink_populate (a_sink, sink);
+ //populate_active_sink (sink, a_sink);
}
}
}
@@ -349,7 +341,8 @@ pm_default_sink_info_callback (pa_context *c,
}
g_debug ("server has handed us a default sink");
- pm_populate_active_sink (info, ACTIVE_SINK (userdata));
+ active_sink_populate (ACTIVE_SINK (userdata), info);
+ //pm_populate_active_sink (info, ACTIVE_SINK (userdata));
}
}
diff --git a/src/pulseaudio-mgr.h b/src/pulseaudio-mgr.h
index 692a55a..af4f29c 100644
--- a/src/pulseaudio-mgr.h
+++ b/src/pulseaudio-mgr.h
@@ -1,6 +1,25 @@
+/*
+Copyright 2011 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/>.
+*/
+
#include "active-sink.h"
-void establish_pulse_activities (ActiveSink* active_sink);
+void pm_establish_pulse_connection (ActiveSink* active_sink);
void close_pulse_activites();
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index 9009869..1617a47 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -29,7 +29,7 @@
#include <libdbusmenu-glib/client.h>
#include "sound-service-dbus.h"
-
+#include "active-sink.h"
#include "gen-sound-service.xml.h"
#include "dbus-shared-names.h"
@@ -60,7 +60,6 @@ struct _SoundServiceDbusPrivate {
static GDBusNodeInfo * node_info = NULL;
static GDBusInterfaceInfo * interface_info = NULL;
-static gboolean b_startup = TRUE;
#define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate))
@@ -69,17 +68,8 @@ static void sound_service_dbus_init (SoundServiceDbus *self);
static void sound_service_dbus_dispose (GObject *object);
static void sound_service_dbus_finalize (GObject *object);
-static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* root,
- gboolean mute_update,
- gboolean availability,
- gdouble volume );
static void show_sound_settings_dialog (DbusmenuMenuitem *mi,
gpointer user_data);
-static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self);
-static void sound_service_dbus_determine_state (SoundServiceDbus* self,
- gboolean availability,
- gboolean mute,
- gdouble volume);
static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self,
gchar* player_name,
gboolean blacklist);
@@ -173,8 +163,8 @@ sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
// Mute button
- dbusmenu_menuitem_child_append (priv->root_menuitem, mute_item));
- dbusmenu_menuitem_child_append (priv->root_menuitem, slider_item ));
+ dbusmenu_menuitem_child_append (priv->root_menuitem, mute_item);
+ dbusmenu_menuitem_child_append (priv->root_menuitem, slider_item);
// Separator
DbusmenuMenuitem* separator = dbusmenu_menuitem_new();
@@ -239,21 +229,12 @@ sound_service_dbus_update_sound_state (SoundServiceDbus* self,
SoundState new_state)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
- SoundState update = new_state;
- // Ensure that after it has become available update the state with the current volume level
- if (new_state == AVAILABLE &&
- mute_menu_item_is_muted (priv->mute_menuitem) == FALSE){
- update = sound_service_dbus_get_state_from_volume (self);
- }
- if (update != BLOCKED){
- priv->current_sound_state = update;
- }
- GVariant* v_output = g_variant_new("(i)", (int)update);
+ GVariant* v_output = g_variant_new("(i)", (int)new_state);
GError * error = NULL;
- g_debug ("emitting signal with value %i", (int)update);
+ g_debug ("emitting state signal with value %i", (int)new_state);
g_dbus_connection_emit_signal( priv->connection,
NULL,
INDICATOR_SOUND_SERVICE_DBUS_OBJECT_PATH,
@@ -286,7 +267,7 @@ bus_method_call (GDBusConnection * connection,
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service);
if (g_strcmp0(method, "GetSoundState") == 0) {
- g_debug("Get state - %i", active_sink_get_state (priv->active_sink);
+ g_debug("Get state - %i", active_sink_get_state (priv->active_sink));
retval = g_variant_new ( "(i)", active_sink_get_state (priv->active_sink));
}
else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) {
diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h
index fab3549..cdc4608 100644
--- a/src/sound-service-dbus.h
+++ b/src/sound-service-dbus.h
@@ -55,12 +55,10 @@ GType sound_service_dbus_get_type (void) G_GNUC_CONST;
DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self);
void sound_service_dbus_update_sound_state (SoundServiceDbus* self, SoundState new_state);
-void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, gboolean sink_mute);
-void sound_service_dbus_update_volume(SoundServiceDbus* self, gdouble volume);
-void sound_service_dbus_update_pa_state ( SoundServiceDbus* root,
- gboolean availability,
- gboolean mute_update,
- gdouble volume );
+void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
+ DbusmenuMenuitem* mute_item,
+ DbusmenuMenuitem* slider_item);
+
G_END_DECLS