Merge lp:~cjcurran/indicator-sound/unify-device-handling-patterns into lp:~indicator-applet-developers/indicator-sound/trunk_3

Proposed by Conor Curran
Status: Merged
Approved by: Ted Gould
Approved revision: 224
Merged at revision: 222
Proposed branch: lp:~cjcurran/indicator-sound/unify-device-handling-patterns
Merge into: lp:~indicator-applet-developers/indicator-sound/trunk_3
Diff against target: 1108 lines (+288/-255)
10 files modified
src/Makefile.am (+2/-2)
src/device.c (+80/-139)
src/device.h (+32/-33)
src/pulseaudio-mgr.c (+43/-43)
src/pulseaudio-mgr.h (+2/-2)
src/slider-menu-item.c (+110/-21)
src/slider-menu-item.h (+10/-4)
src/sound-service-dbus.c (+5/-5)
src/voip-input-menu-item.c (+2/-4)
src/voip-input-menu-item.h (+2/-2)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/unify-device-handling-patterns
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+53315@code.launchpad.net

Description of the change

This is essentially a renaming refactor that was needed on the service side. Every since the voip item was introduced the existing pattern within the pulsemanager of assuming its userdata object was some sort of sink representative became untrue. The userdata mgr is simply just now a wrapper for which the pulsemanager uses to communicate with to menu. It is now called simply 'Device'
Furthermore all state should be stored in the respective widgets. Therefore there is no need for Device to calculate volumes etc.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-02-17 16:07:28 +0000
+++ src/Makefile.am 2011-03-14 20:12:00 +0000
@@ -92,8 +92,8 @@
92 sound-service.c \92 sound-service.c \
93 pulseaudio-mgr.h \93 pulseaudio-mgr.h \
94 pulseaudio-mgr.c \94 pulseaudio-mgr.c \
95 active-sink.c \95 device.c \
96 active-sink.h \96 device.h \
97 sound-service-dbus.h \97 sound-service-dbus.h \
98 sound-service-dbus.c \98 sound-service-dbus.c \
99 slider-menu-item.h \99 slider-menu-item.h \
100100
=== renamed file 'src/active-sink.c' => 'src/device.c'
--- src/active-sink.c 2011-02-18 17:11:08 +0000
+++ src/device.c 2011-03-14 20:12:00 +0000
@@ -18,64 +18,55 @@
18*/18*/
19#include <libdbusmenu-glib/menuitem.h>19#include <libdbusmenu-glib/menuitem.h>
2020
21#include "active-sink.h"21#include "device.h"
22#include "slider-menu-item.h"22#include "slider-menu-item.h"
23#include "mute-menu-item.h"23#include "mute-menu-item.h"
24#include "voip-input-menu-item.h"24#include "voip-input-menu-item.h"
25#include "pulseaudio-mgr.h"25#include "pulseaudio-mgr.h"
2626
27typedef struct _ActiveSinkPrivate ActiveSinkPrivate;27typedef struct _DevicePrivate DevicePrivate;
2828
29struct _ActiveSinkPrivate29struct _DevicePrivate
30{30{
31 SliderMenuItem* volume_slider_menuitem;31 SliderMenuItem* volume_slider_menuitem;
32 MuteMenuItem* mute_menuitem;32 MuteMenuItem* mute_menuitem;
33 VoipInputMenuItem* voip_input_menu_item;33 VoipInputMenuItem* voip_input_menu_item;
34 SoundState current_sound_state;34 SoundState current_sound_state;
35 SoundServiceDbus* service;35 SoundServiceDbus* service;
36 gint index;
37 gchar* name;
38 pa_cvolume volume;
39 pa_channel_map channel_map;
40 pa_volume_t base_volume;
41};36};
4237
43#define ACTIVE_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ACTIVE_SINK_TYPE, ActiveSinkPrivate))38#define DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEVICE_TYPE, DevicePrivate))
4439
45/* Prototypes */40/* Prototypes */
46static void active_sink_class_init (ActiveSinkClass *klass);41static void device_class_init (DeviceClass *klass);
47static void active_sink_init (ActiveSink *self);42static void device_init (Device *self);
48static void active_sink_dispose (GObject *object);43static void device_dispose (GObject *object);
49static void active_sink_finalize (GObject *object);44static void device_finalize (GObject *object);
5045
51static SoundState active_sink_get_state_from_volume (ActiveSink* self);46static SoundState device_get_state_from_volume (Device* self);
52static pa_cvolume active_sink_construct_mono_volume (const pa_cvolume* vol);47static void device_mute_update (Device* self, gboolean muted);
53static void active_sink_volume_update (ActiveSink* self, gdouble percent);48
54static void active_sink_mute_update (ActiveSink* self, gboolean muted);49G_DEFINE_TYPE (Device, device, G_TYPE_OBJECT);
55
56G_DEFINE_TYPE (ActiveSink, active_sink, G_TYPE_OBJECT);
5750
58static void51static void
59active_sink_class_init (ActiveSinkClass *klass)52device_class_init (DeviceClass *klass)
60{53{
61 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);54 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
6255
63 g_type_class_add_private (klass, sizeof (ActiveSinkPrivate));56 g_type_class_add_private (klass, sizeof (DevicePrivate));
6457
65 gobject_class->dispose = active_sink_dispose;58 gobject_class->dispose = device_dispose;
66 gobject_class->finalize = active_sink_finalize; 59 gobject_class->finalize = device_finalize;
67}60}
6861
69static void62static void
70active_sink_init (ActiveSink *self)63device_init (Device *self)
71{64{
72 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);65 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
73 priv->mute_menuitem = NULL;66 priv->mute_menuitem = NULL;
74 priv->volume_slider_menuitem = NULL;67 priv->volume_slider_menuitem = NULL;
75 priv->voip_input_menu_item = NULL;68 priv->voip_input_menu_item = NULL;
76 priv->current_sound_state = UNAVAILABLE;69 priv->current_sound_state = UNAVAILABLE;
77 priv->index = -1;
78 priv->name = NULL;
79 priv->service = NULL;70 priv->service = NULL;
8071
81 // Init our menu items.72 // Init our menu items.
@@ -87,45 +78,38 @@
87}78}
8879
89static void80static void
90active_sink_dispose (GObject *object)81device_dispose (GObject *object)
91{ 82{
92 G_OBJECT_CLASS (active_sink_parent_class)->dispose (object);83 G_OBJECT_CLASS (device_parent_class)->dispose (object);
93}84}
9485
95static void86static void
96active_sink_finalize (GObject *object)87device_finalize (GObject *object)
97{88{
98 G_OBJECT_CLASS (active_sink_parent_class)->finalize (object); 89 G_OBJECT_CLASS (device_parent_class)->finalize (object);
99}90}
10091
101void92void
102active_sink_populate (ActiveSink* sink,93device_populate (Device* self,
103 const pa_sink_info* update)94 const pa_sink_info* update)
104{95{
105 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE(sink);96 DevicePrivate* priv = DEVICE_GET_PRIVATE(self);
10697 device_mute_update (self, update->mute);
107 priv->name = g_strdup (update->name);
108 priv->index = update->index;
109 active_sink_mute_update (sink, update->mute);
110 priv->volume = active_sink_construct_mono_volume (&update->volume);
111 priv->base_volume = update->base_volume;
112 priv->channel_map = update->channel_map;
113
114 pa_volume_t vol = pa_cvolume_max (&update->volume);
115 gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
116
117 active_sink_volume_update (sink, volume_percent);
118 active_sink_mute_update (sink, update->mute);
119 mute_menu_item_enable (priv->mute_menuitem, TRUE);98 mute_menu_item_enable (priv->mute_menuitem, TRUE);
120 slider_menu_item_enable (priv->volume_slider_menuitem, TRUE);99 slider_menu_item_populate (priv->volume_slider_menuitem, update);
100 SoundState state = device_get_state_from_volume (self);
101 if (priv->current_sound_state != state){
102 priv->current_sound_state = state;
103 sound_service_dbus_update_sound_state (priv->service,
104 priv->current_sound_state);
105 }
121106
122 g_debug ("Active sink has been populated - volume %f", volume_percent);
123}107}
124108
125void109void
126active_sink_activate_voip_item (ActiveSink* self, gint sink_input_index, gint client_index)110device_activate_voip_item (Device* self, gint sink_input_index, gint client_index)
127{111{
128 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);112 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
129 if (voip_input_menu_item_is_interested (priv->voip_input_menu_item,113 if (voip_input_menu_item_is_interested (priv->voip_input_menu_item,
130 sink_input_index,114 sink_input_index,
131 client_index)){115 client_index)){
@@ -134,85 +118,55 @@
134}118}
135119
136void120void
137active_sink_deactivate_voip_source (ActiveSink* self, gboolean visible)121device_deactivate_voip_source (Device* self, gboolean visible)
138{122{
139 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);123 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
140 visible &= voip_input_menu_item_is_active (priv->voip_input_menu_item);124 visible &= voip_input_menu_item_is_active (priv->voip_input_menu_item);
141 voip_input_menu_item_deactivate_source (priv->voip_input_menu_item, visible);125 voip_input_menu_item_deactivate_source (priv->voip_input_menu_item, visible);
142}126}
143127
144void128void
145active_sink_deactivate_voip_client (ActiveSink* self)129device_deactivate_voip_client (Device* self)
146{130{
147 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);131 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
148 voip_input_menu_item_deactivate_voip_client (priv->voip_input_menu_item);132 voip_input_menu_item_deactivate_voip_client (priv->voip_input_menu_item);
149}133}
150134
151void135void
152active_sink_update (ActiveSink* sink,136device_update (Device* self,
153 const pa_sink_info* update)137 const pa_sink_info* update)
154{138{
155 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);139 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
156 active_sink_mute_update (sink, update->mute);140 slider_menu_item_update (priv->volume_slider_menuitem, update);
157 priv->volume = active_sink_construct_mono_volume (&update->volume);141
158 priv->base_volume = update->base_volume;142 SoundState state = device_get_state_from_volume (self);
159 priv->channel_map = update->channel_map;
160
161 pa_volume_t vol = pa_cvolume_max (&update->volume);
162 gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
163
164 active_sink_volume_update (sink, volume_percent);
165 active_sink_mute_update (sink, update->mute);
166}
167
168// To the UI
169static void
170active_sink_volume_update (ActiveSink* self, gdouble percent)
171{
172 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
173 slider_menu_item_update (priv->volume_slider_menuitem, percent);
174 SoundState state = active_sink_get_state_from_volume (self);
175 if (priv->current_sound_state != state){143 if (priv->current_sound_state != state){
176 priv->current_sound_state = state;144 priv->current_sound_state = state;
177 sound_service_dbus_update_sound_state (priv->service,145 sound_service_dbus_update_sound_state (priv->service,
178 priv->current_sound_state);146 priv->current_sound_state);
179 }147 }
180}148
181149 device_mute_update (self, update->mute);
182// From the UI150}
183void
184active_sink_update_volume (ActiveSink* self, gdouble percent)
185{
186 pa_cvolume new_volume;
187 pa_cvolume_init(&new_volume);
188 new_volume.channels = 1;
189 pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
190 pa_cvolume_set(&new_volume, 1, new_volume_value);
191
192 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
193
194 pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value);
195 pm_update_volume (priv->index, new_volume);
196}
197
198151
199gint152gint
200active_sink_get_current_sink_input_index (ActiveSink* sink)153device_get_current_sink_input_index (Device* self)
201{154{
202 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);155 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
203 return voip_input_menu_item_get_sink_input_index (priv->voip_input_menu_item);156 return voip_input_menu_item_get_sink_input_index (priv->voip_input_menu_item);
204}157}
205158
206static void 159static void
207active_sink_mute_update (ActiveSink* self, gboolean muted)160device_mute_update (Device* self, gboolean muted)
208{161{
209 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);162 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
210 mute_menu_item_update (priv->mute_menuitem, muted);163 mute_menu_item_update (priv->mute_menuitem, muted);
211 SoundState state = active_sink_get_state_from_volume (self);164 SoundState state = device_get_state_from_volume (self);
212 165
213 if (muted == TRUE){166 if (muted == TRUE){
214 state = MUTED;167 state = MUTED;
215 }168 }
169 // Only send signals if something has changed
216 if (priv->current_sound_state != state){170 if (priv->current_sound_state != state){
217 priv->current_sound_state = state;171 priv->current_sound_state = state;
218 sound_service_dbus_update_sound_state (priv->service, state);172 sound_service_dbus_update_sound_state (priv->service, state);
@@ -220,9 +174,9 @@
220}174}
221175
222void176void
223active_sink_ensure_sink_is_unmuted (ActiveSink* self)177device_ensure_sink_is_unmuted (Device* self)
224{178{
225 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);179 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
226 if (mute_menu_item_is_muted (priv->mute_menuitem)){180 if (mute_menu_item_is_muted (priv->mute_menuitem)){
227 pm_update_mute (FALSE); 181 pm_update_mute (FALSE);
228 }182 }
@@ -230,9 +184,9 @@
230184
231185
232static SoundState186static SoundState
233active_sink_get_state_from_volume (ActiveSink* self)187device_get_state_from_volume (Device* self)
234{188{
235 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);189 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
236 GVariant* v = dbusmenu_menuitem_property_get_variant (DBUSMENU_MENUITEM(priv->volume_slider_menuitem),190 GVariant* v = dbusmenu_menuitem_property_get_variant (DBUSMENU_MENUITEM(priv->volume_slider_menuitem),
237 DBUSMENU_VOLUME_MENUITEM_LEVEL);191 DBUSMENU_VOLUME_MENUITEM_LEVEL);
238 gdouble volume_percent = g_variant_get_double (v);192 gdouble volume_percent = g_variant_get_double (v);
@@ -254,21 +208,10 @@
254 return state;208 return state;
255}209}
256210
257pa_cvolume
258active_sink_construct_mono_volume (const pa_cvolume* vol)
259{
260 pa_cvolume new_volume;
261 pa_cvolume_init(&new_volume);
262 new_volume.channels = 1;
263 pa_volume_t max_vol = pa_cvolume_max(vol);
264 pa_cvolume_set(&new_volume, 1, max_vol);
265 return new_volume;
266}
267
268void211void
269active_sink_determine_blocking_state (ActiveSink* self)212device_determine_blocking_state (Device* self)
270{213{
271 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);214 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
272 if (mute_menu_item_is_muted (priv->mute_menuitem)){215 if (mute_menu_item_is_muted (priv->mute_menuitem)){
273 /**216 /**
274 We don't want to set the current state to blocking217 We don't want to set the current state to blocking
@@ -280,65 +223,63 @@
280}223}
281224
282gint225gint
283active_sink_get_index (ActiveSink* self)226device_get_index (Device* self)
284{227{
285 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);228 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
286 return priv->index;229 return slider_menu_item_get_sink_index (priv->volume_slider_menuitem);
287}230}
288231
289gboolean232gboolean
290active_sink_is_populated (ActiveSink* sink)233device_is_populated (Device* self)
291{234{
292 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);235 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
293 return (priv->index != -1);236 return dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM (priv->volume_slider_menuitem),
237 DBUSMENU_MENUITEM_PROP_ENABLED);
294}238}
295239
296void 240void
297active_sink_deactivate (ActiveSink* self)241device_deactivate (Device* self)
298{242{
299 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);243 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
300 priv->current_sound_state = UNAVAILABLE;244 priv->current_sound_state = UNAVAILABLE;
301 sound_service_dbus_update_sound_state (priv->service,245 sound_service_dbus_update_sound_state (priv->service,
302 priv->current_sound_state); 246 priv->current_sound_state);
303 mute_menu_item_enable (priv->mute_menuitem, FALSE);247 mute_menu_item_enable (priv->mute_menuitem, FALSE);
304 slider_menu_item_enable (priv->volume_slider_menuitem, FALSE);248 slider_menu_item_enable (priv->volume_slider_menuitem, FALSE);
305 priv->index = -1;
306 g_free(priv->name);
307 priv->name = NULL;
308}249}
309250
310SoundState251SoundState
311active_sink_get_state (ActiveSink* self)252device_get_state (Device* self)
312{253{
313 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);254 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
314 return priv->current_sound_state;255 return priv->current_sound_state;
315}256}
316257
317void258void
318active_sink_update_voip_input_source (ActiveSink* self, const pa_source_info* update)259device_update_voip_input_source (Device* self, const pa_source_info* update)
319{260{
320 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);261 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
321 voip_input_menu_item_update (priv->voip_input_menu_item, update);262 voip_input_menu_item_update (priv->voip_input_menu_item, update);
322}263}
323264
324gboolean265gboolean
325active_sink_is_voip_source_populated (ActiveSink* self)266device_is_voip_source_populated (Device* self)
326{267{
327 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);268 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
328 return voip_input_menu_item_is_populated (priv->voip_input_menu_item);269 return voip_input_menu_item_is_populated (priv->voip_input_menu_item);
329}270}
330271
331gint active_sink_get_source_index (ActiveSink* self)272gint device_get_source_index (Device* self)
332{273{
333 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);274 DevicePrivate* priv = DEVICE_GET_PRIVATE (self);
334 return voip_input_menu_item_get_index (priv->voip_input_menu_item);275 return voip_input_menu_item_get_index (priv->voip_input_menu_item);
335}276}
336277
337ActiveSink*278Device*
338active_sink_new (SoundServiceDbus* service)279device_new (SoundServiceDbus* service)
339{280{
340 ActiveSink* sink = g_object_new (ACTIVE_SINK_TYPE, NULL);281 Device* sink = g_object_new (DEVICE_TYPE, NULL);
341 ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink);282 DevicePrivate* priv = DEVICE_GET_PRIVATE (sink);
342 priv->service = service;283 priv->service = service;
343 sound_service_dbus_build_sound_menu (service,284 sound_service_dbus_build_sound_menu (service,
344 mute_menu_item_get_button (priv->mute_menuitem),285 mute_menu_item_get_button (priv->mute_menuitem),
345286
=== renamed file 'src/active-sink.h' => 'src/device.h'
--- src/active-sink.h 2011-02-18 16:56:17 +0000
+++ src/device.h 2011-03-14 20:12:00 +0000
@@ -17,8 +17,8 @@
17 * with this program. If not, see <http://www.gnu.org/licenses/>.17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#ifndef __ACTIVE_SINK_H__20#ifndef __DEVICE_H__
21#define __ACTIVE_SINK_H__21#define __DEVICE_H__
2222
23#include <glib.h>23#include <glib.h>
24#include <glib-object.h>24#include <glib-object.h>
@@ -30,25 +30,25 @@
3030
31G_BEGIN_DECLS31G_BEGIN_DECLS
3232
33#define ACTIVE_SINK_TYPE (active_sink_get_type ())33#define DEVICE_TYPE (device_get_type ())
34#define ACTIVE_SINK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ACTIVE_SINK_TYPE, ActiveSink))34#define DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DEVICE_TYPE, Device))
35#define ACTIVE_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), ACTIVE_SINK_TYPE, ActiveSinkClass))35#define DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), DEVICE_TYPE, DeviceClass))
36#define IS_ACTIVE_SINK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ACTIVE_SINK_TYPE))36#define IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DEVICE_TYPE))
37#define IS_ACTIVE_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ACTIVE_SINK_TYPE))37#define IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DEVICE_TYPE))
38#define ACTIVE_SINK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ACTIVE_SINK_TYPE, ActiveSinkClass))38#define DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEVICE_TYPE, DeviceClass))
3939
40typedef struct _ActiveSink ActiveSink;40typedef struct _Device Device;
41typedef struct _ActiveSinkClass ActiveSinkClass;41typedef struct _DeviceClass DeviceClass;
4242
43struct _ActiveSink {43struct _Device {
44 GObject parent;44 GObject parent;
45};45};
4646
47struct _ActiveSinkClass {47struct _DeviceClass {
48 GObjectClass parent_class;48 GObjectClass parent_class;
49};49};
5050
51GType active_sink_get_type (void) G_GNUC_CONST;51GType device_get_type (void) G_GNUC_CONST;
5252
53/**53/**
54 * TODO54 * TODO
@@ -58,27 +58,26 @@
58 */58 */
5959
60// Sink related60// Sink related
61void active_sink_populate (ActiveSink* sink, const pa_sink_info* update); 61void device_populate (Device* sink, const pa_sink_info* update);
62void active_sink_update (ActiveSink* sink, const pa_sink_info* update); 62void device_update (Device* sink, const pa_sink_info* update);
63gboolean active_sink_is_populated (ActiveSink* sink);63gboolean device_is_populated (Device* sink);
64gint active_sink_get_index (ActiveSink* self);64gint device_get_index (Device* self);
65void active_sink_deactivate (ActiveSink* self);65void device_deactivate (Device* self);
66void active_sink_update_mute (ActiveSink* self, gboolean mute_update);66void device_update_mute (Device* self, gboolean mute_update);
67void active_sink_update_volume (ActiveSink* self, gdouble percent);67void device_ensure_sink_is_unmuted (Device* self);
68void active_sink_ensure_sink_is_unmuted (ActiveSink* self);
6968
70// source and sinkinput/client related for VOIP functionality69// source and sinkinput/client related for VOIP functionality
71void active_sink_update_voip_input_source (ActiveSink* sink, const pa_source_info* update);70void device_update_voip_input_source (Device* sink, const pa_source_info* update);
72void active_sink_activate_voip_item (ActiveSink* sink, gint sink_input_index, gint client_index);71void device_activate_voip_item (Device* sink, gint sink_input_index, gint client_index);
73gint active_sink_get_current_sink_input_index (ActiveSink* sink);72gint device_get_current_sink_input_index (Device* sink);
74gboolean active_sink_is_voip_source_populated (ActiveSink* sink);73gboolean device_is_voip_source_populated (Device* sink);
75gint active_sink_get_source_index (ActiveSink* self);74gint device_get_source_index (Device* self);
76void active_sink_determine_blocking_state (ActiveSink* self);75void device_determine_blocking_state (Device* self);
77void active_sink_deactivate_voip_source (ActiveSink* self, gboolean visible);76void device_deactivate_voip_source (Device* self, gboolean visible);
78void active_sink_deactivate_voip_client (ActiveSink* self);77void device_deactivate_voip_client (Device* self);
79SoundState active_sink_get_state (ActiveSink* self);78SoundState device_get_state (Device* self);
8079
81ActiveSink* active_sink_new (SoundServiceDbus* service);80Device* device_new (SoundServiceDbus* service);
8281
83G_END_DECLS82G_END_DECLS
8483
8584
=== modified file 'src/pulseaudio-mgr.c'
--- src/pulseaudio-mgr.c 2011-03-01 20:36:26 +0000
+++ src/pulseaudio-mgr.c 2011-03-14 20:12:00 +0000
@@ -68,7 +68,7 @@
68 const pa_sink_input_info *info,68 const pa_sink_input_info *info,
69 int eol,69 int eol,
70 void *userdata);70 void *userdata);
71static void pm_update_active_sink (pa_context *c,71static void pm_update_device (pa_context *c,
72 const pa_sink_info *info,72 const pa_sink_info *info,
73 int eol,73 int eol,
74 void *userdata);74 void *userdata);
@@ -89,11 +89,11 @@
89 Entry Point89 Entry Point
90 **/90 **/
91void 91void
92pm_establish_pulse_connection (ActiveSink* active_sink)92pm_establish_pulse_connection (Device* device)
93{93{
94 pa_main_loop = pa_glib_mainloop_new (g_main_context_default ());94 pa_main_loop = pa_glib_mainloop_new (g_main_context_default ());
95 g_assert (pa_main_loop);95 g_assert (pa_main_loop);
96 reconnect_to_pulse ((gpointer)active_sink); 96 reconnect_to_pulse ((gpointer)device);
97}97}
9898
99/**99/**
@@ -119,7 +119,7 @@
119{119{
120 g_debug("Attempt a pulse connection");120 g_debug("Attempt a pulse connection");
121 // reset121 // reset
122 g_return_val_if_fail (IS_ACTIVE_SINK (user_data), FALSE);122 g_return_val_if_fail (IS_DEVICE (user_data), FALSE);
123123
124 connection_attempts += 1;124 connection_attempts += 1;
125 if (pulse_context != NULL) {125 if (pulse_context != NULL) {
@@ -216,38 +216,38 @@
216 uint32_t index,216 uint32_t index,
217 void* userdata)217 void* userdata)
218{218{
219 if (IS_ACTIVE_SINK (userdata) == FALSE){219 if (IS_DEVICE (userdata) == FALSE){
220 g_critical ("subscribed events callback - our userdata is not what we think it should be");220 g_critical ("subscribed events callback - our userdata is not what we think it should be");
221 return;221 return;
222 }222 }
223 ActiveSink* sink = ACTIVE_SINK (userdata);223 Device* sink = DEVICE (userdata);
224224
225 switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {225 switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
226 case PA_SUBSCRIPTION_EVENT_SINK:226 case PA_SUBSCRIPTION_EVENT_SINK:
227 227
228 // We don't care about any other sink other than the active one.228 // We don't care about any other sink other than the active one.
229 if (index != active_sink_get_index (sink))229 if (index != device_get_index (sink))
230 return;230 return;
231 231
232 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {232 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
233 active_sink_deactivate (sink);233 device_deactivate (sink);
234 234
235 }235 }
236 else{236 else{
237 pa_operation_unref (pa_context_get_sink_info_by_index (c,237 pa_operation_unref (pa_context_get_sink_info_by_index (c,
238 index,238 index,
239 pm_update_active_sink,239 pm_update_device,
240 userdata) );240 userdata) );
241 }241 }
242 break;242 break;
243 case PA_SUBSCRIPTION_EVENT_SOURCE:243 case PA_SUBSCRIPTION_EVENT_SOURCE:
244 g_debug ("Looks like source event of some description - index = %i", index);244 g_debug ("Looks like source event of some description - index = %i", index);
245 // We don't care about any other sink other than the active one.245 // We don't care about any other sink other than the active one.
246 if (index != active_sink_get_source_index (sink))246 if (index != device_get_source_index (sink))
247 return;247 return;
248 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {248 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
249 g_debug ("Source removal event - index = %i", index);249 g_debug ("Source removal event - index = %i", index);
250 active_sink_deactivate_voip_source (sink, FALSE);250 device_deactivate_voip_source (sink, FALSE);
251 }251 }
252 else{252 else{
253 pa_operation_unref (pa_context_get_source_info_by_index (c,253 pa_operation_unref (pa_context_get_source_info_by_index (c,
@@ -260,12 +260,12 @@
260 // We don't care about sink input removals.260 // We don't care about sink input removals.
261 g_debug ("sink input event");261 g_debug ("sink input event");
262 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {262 if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
263 gint cached_index = active_sink_get_current_sink_input_index (sink);263 gint cached_index = device_get_current_sink_input_index (sink);
264264
265 g_debug ("Just saw a sink input removal event - index = %i and cached index = %i", index, cached_index);265 g_debug ("Just saw a sink input removal event - index = %i and cached index = %i", index, cached_index);
266266
267 if (index == cached_index){267 if (index == cached_index){
268 active_sink_deactivate_voip_client (sink);268 device_deactivate_voip_client (sink);
269 }269 }
270 }270 }
271 else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {271 else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
@@ -308,7 +308,7 @@
308 break;308 break;
309 case PA_CONTEXT_FAILED:309 case PA_CONTEXT_FAILED:
310 g_warning("PA_CONTEXT_FAILED - Is PulseAudio Daemon running ?");310 g_warning("PA_CONTEXT_FAILED - Is PulseAudio Daemon running ?");
311 active_sink_deactivate (ACTIVE_SINK (userdata));311 device_deactivate (DEVICE (userdata));
312 if (reconnect_idle_id == 0){312 if (reconnect_idle_id == 0){
313 reconnect_idle_id = g_timeout_add_seconds (RECONNECT_DELAY,313 reconnect_idle_id = g_timeout_add_seconds (RECONNECT_DELAY,
314 reconnect_to_pulse,314 reconnect_to_pulse,
@@ -362,7 +362,7 @@
362362
363 if (info == NULL) {363 if (info == NULL) {
364 g_warning("No PA server - get the hell out of here");364 g_warning("No PA server - get the hell out of here");
365 active_sink_deactivate (ACTIVE_SINK (userdata));365 device_deactivate (DEVICE (userdata));
366 return;366 return;
367 }367 }
368 // Go for the default sink368 // Go for the default sink
@@ -373,7 +373,7 @@
373 pm_default_sink_info_callback,373 pm_default_sink_info_callback,
374 userdata) )) {374 userdata) )) {
375 g_warning("pa_context_get_sink_info_by_namet() failed");375 g_warning("pa_context_get_sink_info_by_namet() failed");
376 active_sink_deactivate (ACTIVE_SINK (userdata));376 device_deactivate (DEVICE (userdata));
377 pa_operation_unref(operation);377 pa_operation_unref(operation);
378 return;378 return;
379 }379 }
@@ -382,7 +382,7 @@
382 pm_sink_info_callback,382 pm_sink_info_callback,
383 userdata))) {383 userdata))) {
384 g_warning("pa_context_get_sink_info_list() failed");384 g_warning("pa_context_get_sink_info_list() failed");
385 active_sink_deactivate (ACTIVE_SINK (userdata));385 device_deactivate (DEVICE (userdata));
386 pa_operation_unref(operation);386 pa_operation_unref(operation);
387 return;387 return;
388 }388 }
@@ -421,14 +421,14 @@
421 return;421 return;
422 }422 }
423 else {423 else {
424 if (IS_ACTIVE_SINK (userdata) == FALSE || sink == NULL){424 if (IS_DEVICE (userdata) == FALSE || sink == NULL){
425 g_warning ("sink info callback - our user data is not what we think it should be or the sink parameter is null");425 g_warning ("sink info callback - our user data is not what we think it should be or the sink parameter is null");
426 return;426 return;
427 }427 }
428 ActiveSink* a_sink = ACTIVE_SINK (userdata);428 Device* a_sink = DEVICE (userdata);
429 if (active_sink_is_populated (a_sink) == FALSE &&429 if (device_is_populated (a_sink) == FALSE &&
430 g_ascii_strncasecmp("auto_null", sink->name, 9) != 0){430 g_ascii_strncasecmp("auto_null", sink->name, 9) != 0){
431 active_sink_populate (a_sink, sink);431 device_populate (a_sink, sink);
432 }432 }
433 }433 }
434}434}
@@ -443,16 +443,16 @@
443 return;443 return;
444 } 444 }
445 else {445 else {
446 if (IS_ACTIVE_SINK (userdata) == FALSE || info == NULL){446 if (IS_DEVICE (userdata) == FALSE || info == NULL){
447 g_warning ("Default sink info callback - our user data is not what we think it should be or the info parameter is null");447 g_warning ("Default sink info callback - our user data is not what we think it should be or the info parameter is null");
448 return;448 return;
449 }449 }
450 // Only repopulate if there is a change with regards the index450 // Only repopulate if there is a change with regards the index
451 if (active_sink_get_index (ACTIVE_SINK (userdata)) == info->index)451 if (device_get_index (DEVICE (userdata)) == info->index)
452 return;452 return;
453 453
454 g_debug ("Pulse Server has handed us a new default sink");454 g_debug ("Pulse Server has handed us a new default sink");
455 active_sink_populate (ACTIVE_SINK (userdata), info);455 device_populate (DEVICE (userdata), info);
456 }456 }
457}457}
458458
@@ -466,18 +466,18 @@
466 return;466 return;
467 }467 }
468 else {468 else {
469 if (info == NULL || IS_ACTIVE_SINK (userdata) == FALSE) {469 if (info == NULL || IS_DEVICE (userdata) == FALSE) {
470 g_warning("Sink input info callback : SINK INPUT INFO IS NULL or our user_data is not what we think it should be");470 g_warning("Sink input info callback : SINK INPUT INFO IS NULL or our user_data is not what we think it should be");
471 return;471 return;
472 }472 }
473473
474 if (IS_ACTIVE_SINK (userdata) == FALSE){474 if (IS_DEVICE (userdata) == FALSE){
475 g_warning ("sink input info callback - our user data is not what we think it should be");475 g_warning ("sink input info callback - our user data is not what we think it should be");
476 return;476 return;
477 }477 }
478 // Check if this is Voip sink input478 // Check if this is Voip sink input
479 gint result = pa_proplist_contains (info->proplist, PA_PROP_MEDIA_ROLE);479 gint result = pa_proplist_contains (info->proplist, PA_PROP_MEDIA_ROLE);
480 ActiveSink* a_sink = ACTIVE_SINK (userdata);480 Device* a_sink = DEVICE (userdata);
481481
482 if (result == 1){482 if (result == 1){
483 g_debug ("Sink input info has media role property");483 g_debug ("Sink input info has media role property");
@@ -485,7 +485,7 @@
485 g_debug ("prop role = %s", value);485 g_debug ("prop role = %s", value);
486 if (g_strcmp0 (value, "phone") == 0) {486 if (g_strcmp0 (value, "phone") == 0) {
487 g_debug ("And yes its a VOIP app ... sink input index = %i", info->index);487 g_debug ("And yes its a VOIP app ... sink input index = %i", info->index);
488 active_sink_activate_voip_item (a_sink, (gint)info->index, (gint)info->client);488 device_activate_voip_item (a_sink, (gint)info->index, (gint)info->client);
489 // TODO to start with we will assume our source is the same as what this 'client'489 // TODO to start with we will assume our source is the same as what this 'client'
490 // is pointing at. This should probably be more intelligent :490 // is pointing at. This should probably be more intelligent :
491 // query for the list of source output info's and going on the name of the client491 // query for the list of source output info's and going on the name of the client
@@ -494,14 +494,14 @@
494 }494 }
495495
496 // And finally check for the mute blocking state496 // And finally check for the mute blocking state
497 if (active_sink_get_index (a_sink) == info->sink){497 if (device_get_index (a_sink) == info->sink){
498 active_sink_determine_blocking_state (a_sink);498 device_determine_blocking_state (a_sink);
499 }499 }
500 }500 }
501}501}
502502
503static void 503static void
504pm_update_active_sink (pa_context *c,504pm_update_device (pa_context *c,
505 const pa_sink_info *info,505 const pa_sink_info *info,
506 int eol,506 int eol,
507 void *userdata)507 void *userdata)
@@ -510,11 +510,11 @@
510 return;510 return;
511 }511 }
512 else{512 else{
513 if (IS_ACTIVE_SINK (userdata) == FALSE || info == NULL){513 if (IS_DEVICE (userdata) == FALSE || info == NULL){
514 g_warning ("update_active_sink - our user data is not what we think it should be or the info parameter is null");514 g_warning ("update_device - our user data is not what we think it should be or the info parameter is null");
515 return;515 return;
516 }516 }
517 active_sink_update (ACTIVE_SINK(userdata), info);517 device_update (DEVICE(userdata), info);
518 }518 }
519}519}
520520
@@ -551,16 +551,16 @@
551 return;551 return;
552 }552 }
553 else {553 else {
554 if (IS_ACTIVE_SINK (userdata) == FALSE || info == NULL){554 if (IS_DEVICE (userdata) == FALSE || info == NULL){
555 g_warning ("Default source info callback - our user data is not what we think it should be or the source info parameter is null");555 g_warning ("Default source info callback - our user data is not what we think it should be or the source info parameter is null");
556 return;556 return;
557 }557 }
558 // If there is an index change we need to change our cached source558 // If there is an index change we need to change our cached source
559 if (active_sink_get_source_index (ACTIVE_SINK (userdata)) == info->index)559 if (device_get_source_index (DEVICE (userdata)) == info->index)
560 return;560 return;
561 g_debug ("Pulse Server has handed us a new default source");561 g_debug ("Pulse Server has handed us a new default source");
562 active_sink_deactivate_voip_source (ACTIVE_SINK (userdata), TRUE);562 device_deactivate_voip_source (DEVICE (userdata), TRUE);
563 active_sink_update_voip_input_source (ACTIVE_SINK (userdata), info);563 device_update_voip_input_source (DEVICE (userdata), info);
564 }564 }
565}565}
566566
@@ -574,13 +574,13 @@
574 return;574 return;
575 }575 }
576 else {576 else {
577 if (IS_ACTIVE_SINK (userdata) == FALSE || info == NULL){577 if (IS_DEVICE (userdata) == FALSE || info == NULL){
578 g_warning ("source info callback - our user data is not what we think it should be or the source info parameter is null");578 g_warning ("source info callback - our user data is not what we think it should be or the source info parameter is null");
579 return;579 return;
580 }580 }
581 // For now we will take the first available581 // For now we will take the first available
582 if (active_sink_is_voip_source_populated (ACTIVE_SINK (userdata)) == FALSE){582 if (device_is_voip_source_populated (DEVICE (userdata)) == FALSE){
583 active_sink_update_voip_input_source (ACTIVE_SINK (userdata), info);583 device_update_voip_input_source (DEVICE (userdata), info);
584 }584 }
585 }585 }
586}586}
@@ -595,11 +595,11 @@
595 return;595 return;
596 }596 }
597 else {597 else {
598 if (IS_ACTIVE_SINK (userdata) == FALSE || info == NULL ){598 if (IS_DEVICE (userdata) == FALSE || info == NULL ){
599 g_warning ("source info update callback - our user data is not what we think it should be or the source info paramter is null");599 g_warning ("source info update callback - our user data is not what we think it should be or the source info paramter is null");
600 return;600 return;
601 }601 }
602 g_debug ("Got a source update for %s , index %i", info->name, info->index);602 g_debug ("Got a source update for %s , index %i", info->name, info->index);
603 active_sink_update_voip_input_source (ACTIVE_SINK (userdata), info);603 device_update_voip_input_source (DEVICE (userdata), info);
604 }604 }
605}605}
606606
=== modified file 'src/pulseaudio-mgr.h'
--- src/pulseaudio-mgr.h 2011-02-18 16:22:58 +0000
+++ src/pulseaudio-mgr.h 2011-03-14 20:12:00 +0000
@@ -17,9 +17,9 @@
17with this program. If not, see <http://www.gnu.org/licenses/>.17with this program. If not, see <http://www.gnu.org/licenses/>.
18*/18*/
1919
20#include "active-sink.h"20#include "device.h"
2121
22void pm_establish_pulse_connection (ActiveSink* active_sink);22void pm_establish_pulse_connection (Device* device);
23void close_pulse_activites();23void close_pulse_activites();
24void pm_update_volume (gint sink_index, pa_cvolume new_volume);24void pm_update_volume (gint sink_index, pa_cvolume new_volume);
25void pm_update_mic_gain (gint source_index, pa_cvolume new_gain);25void pm_update_mic_gain (gint source_index, pa_cvolume new_gain);
2626
=== modified file 'src/slider-menu-item.c'
--- src/slider-menu-item.c 2011-03-10 19:48:26 +0000
+++ src/slider-menu-item.c 2011-03-14 20:12:00 +0000
@@ -23,11 +23,17 @@
23#include <glib/gi18n.h>23#include <glib/gi18n.h>
24#include "slider-menu-item.h"24#include "slider-menu-item.h"
25#include "common-defs.h"25#include "common-defs.h"
26#include "pulseaudio-mgr.h"
2627
27typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate;28typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate;
2829
29struct _SliderMenuItemPrivate {30struct _SliderMenuItemPrivate {
30 ActiveSink* a_sink;31 Device* a_sink;
32 gint index;
33 gchar* name;
34 pa_cvolume volume;
35 pa_channel_map channel_map;
36 pa_volume_t base_volume;
31};37};
3238
33#define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate))39#define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate))
@@ -39,6 +45,8 @@
39static void slider_menu_item_finalize (GObject *object);45static void slider_menu_item_finalize (GObject *object);
40static void handle_event (DbusmenuMenuitem * mi, const gchar * name, 46static void handle_event (DbusmenuMenuitem * mi, const gchar * name,
41 GVariant * value, guint timestamp);47 GVariant * value, guint timestamp);
48static pa_cvolume slider_menu_item_construct_mono_volume (const pa_cvolume* vol);
49static void slider_menu_item_update_volume (SliderMenuItem* self, gdouble percent);
4250
43G_DEFINE_TYPE (SliderMenuItem, slider_menu_item, DBUSMENU_TYPE_MENUITEM);51G_DEFINE_TYPE (SliderMenuItem, slider_menu_item, DBUSMENU_TYPE_MENUITEM);
4452
@@ -63,7 +71,13 @@
63 g_debug("Building new Slider Menu Item");71 g_debug("Building new Slider Menu Item");
64 dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self),72 dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self),
65 DBUSMENU_MENUITEM_PROP_TYPE,73 DBUSMENU_MENUITEM_PROP_TYPE,
66 DBUSMENU_VOLUME_MENUITEM_TYPE ); 74 DBUSMENU_VOLUME_MENUITEM_TYPE );
75
76 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
77
78 priv->index = -1;
79 priv->name = NULL;
80
67 return;81 return;
68}82}
6983
@@ -97,33 +111,108 @@
97 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (SLIDER_MENU_ITEM (mi));111 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (SLIDER_MENU_ITEM (mi));
98 gdouble volume_input = g_variant_get_double(input);112 gdouble volume_input = g_variant_get_double(input);
99 //g_debug ("slider menu item about to update volume %f", volume_input);113 //g_debug ("slider menu item about to update volume %f", volume_input);
100 active_sink_update_volume (priv->a_sink, volume_input);114 slider_menu_item_update_volume (SLIDER_MENU_ITEM (mi), volume_input);
101 active_sink_ensure_sink_is_unmuted (priv->a_sink); 115 device_ensure_sink_is_unmuted (priv->a_sink);
102 } 116 }
103 }117 }
104}118}
105119
106void120
107slider_menu_item_update (SliderMenuItem* item,121void
108 gdouble update)122slider_menu_item_populate (SliderMenuItem* self, const pa_sink_info* update)
109{123{
110 GVariant* new_volume = g_variant_new_double(update);124 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
111 dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(item),125 priv->name = g_strdup (update->name);
112 DBUSMENU_VOLUME_MENUITEM_LEVEL,126 priv->index = update->index;
113 new_volume);127 priv->volume = slider_menu_item_construct_mono_volume (&update->volume);
114}128 priv->base_volume = update->base_volume;
115129 priv->channel_map = update->channel_map;
116void130
117slider_menu_item_enable (SliderMenuItem* item,131 pa_volume_t vol = pa_cvolume_max (&update->volume);
118 gboolean active)132 gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
119{133 GVariant* new_volume = g_variant_new_double (volume_percent);
120 dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item),134 dbusmenu_menuitem_property_set_variant (DBUSMENU_MENUITEM(self),
135 DBUSMENU_VOLUME_MENUITEM_LEVEL,
136 new_volume);
137 slider_menu_item_enable (self, TRUE);
138}
139
140// From the UI
141static void
142slider_menu_item_update_volume (SliderMenuItem* self, gdouble percent)
143{
144 pa_cvolume new_volume;
145 pa_cvolume_init(&new_volume);
146 new_volume.channels = 1;
147 pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
148 pa_cvolume_set(&new_volume, 1, new_volume_value);
149
150 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
151
152 pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value);
153 pm_update_volume (priv->index, new_volume);
154}
155
156// To the UI
157void
158slider_menu_item_update (SliderMenuItem* self, const pa_sink_info* update)
159{
160 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
161
162 priv->volume = slider_menu_item_construct_mono_volume (&update->volume);
163 priv->base_volume = update->base_volume;
164 priv->channel_map = update->channel_map;
165
166 pa_volume_t vol = pa_cvolume_max (&update->volume);
167 gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
168
169 GVariant* new_volume = g_variant_new_double (volume_percent);
170 dbusmenu_menuitem_property_set_variant (DBUSMENU_MENUITEM(self),
171 DBUSMENU_VOLUME_MENUITEM_LEVEL,
172 new_volume);
173}
174
175/*
176 * Enable/Disabled can be considered the equivalent of whether we have an active
177 * sink or not, let the widget have inherent state.
178 */
179void
180slider_menu_item_enable (SliderMenuItem* self, gboolean active)
181{
182 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
183
184 dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(self),
121 DBUSMENU_MENUITEM_PROP_ENABLED,185 DBUSMENU_MENUITEM_PROP_ENABLED,
122 active );186 active);
187 if(active == FALSE){
188 priv->index = -1;
189 if(priv->name != NULL){
190 g_free(priv->name);
191 priv->name = NULL;
192 }
193 }
194}
195
196gint
197slider_menu_item_get_sink_index (SliderMenuItem* self)
198{
199 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
200 return priv->index;
201}
202
203static pa_cvolume
204slider_menu_item_construct_mono_volume (const pa_cvolume* vol)
205{
206 pa_cvolume new_volume;
207 pa_cvolume_init(&new_volume);
208 new_volume.channels = 1;
209 pa_volume_t max_vol = pa_cvolume_max(vol);
210 pa_cvolume_set(&new_volume, 1, max_vol);
211 return new_volume;
123}212}
124213
125SliderMenuItem*214SliderMenuItem*
126slider_menu_item_new (ActiveSink* sink)215slider_menu_item_new (Device* sink)
127{ 216{
128 SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL);217 SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL);
129 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);218 SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
130219
=== modified file 'src/slider-menu-item.h'
--- src/slider-menu-item.h 2011-02-04 19:55:20 +0000
+++ src/slider-menu-item.h 2011-03-14 20:12:00 +0000
@@ -23,7 +23,7 @@
23#include <glib-object.h>23#include <glib-object.h>
2424
25#include <libdbusmenu-glib/menuitem.h>25#include <libdbusmenu-glib/menuitem.h>
26#include "active-sink.h"26#include "device.h"
2727
28G_BEGIN_DECLS28G_BEGIN_DECLS
2929
@@ -47,10 +47,16 @@
4747
48GType slider_menu_item_get_type (void);48GType slider_menu_item_get_type (void);
4949
50void slider_menu_item_update(SliderMenuItem* item, gdouble update);50void slider_menu_item_update(SliderMenuItem* item, const pa_sink_info* update);
51void slider_menu_item_enable(SliderMenuItem* item, gboolean active);51void slider_menu_item_enable(SliderMenuItem* item, gboolean active);
5252void slider_menu_item_populate (SliderMenuItem* self, const pa_sink_info* update);
53SliderMenuItem* slider_menu_item_new (ActiveSink* sink);53//void
54//active_sink_update (ActiveSink* sink,
55// const pa_sink_info* update)
56
57gint slider_menu_item_get_sink_index (SliderMenuItem* self);
58
59SliderMenuItem* slider_menu_item_new (Device* sink);
5460
55G_END_DECLS61G_END_DECLS
5662
5763
=== modified file 'src/sound-service-dbus.c'
--- src/sound-service-dbus.c 2011-03-11 15:24:11 +0000
+++ src/sound-service-dbus.c 2011-03-14 20:12:00 +0000
@@ -29,7 +29,7 @@
29#include <libdbusmenu-glib/client.h>29#include <libdbusmenu-glib/client.h>
3030
31#include "sound-service-dbus.h"31#include "sound-service-dbus.h"
32#include "active-sink.h"32#include "device.h"
33#include "gen-sound-service.xml.h"33#include "gen-sound-service.xml.h"
34#include "dbus-shared-names.h"34#include "dbus-shared-names.h"
3535
@@ -55,7 +55,7 @@
55struct _SoundServiceDbusPrivate {55struct _SoundServiceDbusPrivate {
56 GDBusConnection* connection;56 GDBusConnection* connection;
57 DbusmenuMenuitem* root_menuitem;57 DbusmenuMenuitem* root_menuitem;
58 ActiveSink* active_sink;58 Device* device;
59};59};
6060
61static GDBusNodeInfo * node_info = NULL;61static GDBusNodeInfo * node_info = NULL;
@@ -155,7 +155,7 @@
155 paths);155 paths);
156 dbusmenu_server_set_root (server, priv->root_menuitem);156 dbusmenu_server_set_root (server, priv->root_menuitem);
157 g_object_unref (priv->root_menuitem);157 g_object_unref (priv->root_menuitem);
158 priv->active_sink = active_sink_new (self);158 priv->device = device_new (self);
159 return priv->root_menuitem;159 return priv->root_menuitem;
160}160}
161161
@@ -272,8 +272,8 @@
272 SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service);272 SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (service);
273273
274 if (g_strcmp0(method, "GetSoundState") == 0) {274 if (g_strcmp0(method, "GetSoundState") == 0) {
275 g_debug("Get state - %i", active_sink_get_state (priv->active_sink));275 g_debug("Get state - %i", device_get_state (priv->device));
276 retval = g_variant_new ( "(i)", active_sink_get_state (priv->active_sink)); 276 retval = g_variant_new ( "(i)", device_get_state (priv->device));
277 } 277 }
278 else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) { 278 else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) {
279 gboolean blacklist;279 gboolean blacklist;
280280
=== modified file 'src/voip-input-menu-item.c'
--- src/voip-input-menu-item.c 2011-02-18 17:11:08 +0000
+++ src/voip-input-menu-item.c 2011-03-14 20:12:00 +0000
@@ -28,7 +28,7 @@
28typedef struct _VoipInputMenuItemPrivate VoipInputMenuItemPrivate;28typedef struct _VoipInputMenuItemPrivate VoipInputMenuItemPrivate;
2929
30struct _VoipInputMenuItemPrivate {30struct _VoipInputMenuItemPrivate {
31 ActiveSink* a_sink;31 Device* a_sink;
32 pa_cvolume volume;32 pa_cvolume volume;
33 gint mute;33 gint mute;
34 guint32 volume_steps;34 guint32 volume_steps;
@@ -129,8 +129,6 @@
129 if (priv->mute == 1) {129 if (priv->mute == 1) {
130 pm_update_mic_mute (priv->source_index, 0);130 pm_update_mic_mute (priv->source_index, 0);
131 }131 }
132 //active_sink_update_volume (priv->a_sink, volume_input);
133 //active_sink_ensure_sink_is_unmuted (priv->a_sink);
134 }132 }
135 }133 }
136}134}
@@ -268,7 +266,7 @@
268}266}
269267
270VoipInputMenuItem*268VoipInputMenuItem*
271voip_input_menu_item_new (ActiveSink* sink)269voip_input_menu_item_new (Device* sink)
272{270{
273 VoipInputMenuItem *self = g_object_new(VOIP_INPUT_MENU_ITEM_TYPE, NULL);271 VoipInputMenuItem *self = g_object_new(VOIP_INPUT_MENU_ITEM_TYPE, NULL);
274 VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (self);272 VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (self);
275273
=== modified file 'src/voip-input-menu-item.h'
--- src/voip-input-menu-item.h 2011-02-18 17:11:08 +0000
+++ src/voip-input-menu-item.h 2011-03-14 20:12:00 +0000
@@ -22,7 +22,7 @@
22#include <glib.h>22#include <glib.h>
23#include <pulse/pulseaudio.h>23#include <pulse/pulseaudio.h>
24#include <libdbusmenu-glib/menuitem.h>24#include <libdbusmenu-glib/menuitem.h>
25#include "active-sink.h"25#include "device.h"
2626
27G_BEGIN_DECLS27G_BEGIN_DECLS
2828
@@ -62,7 +62,7 @@
62void voip_input_menu_item_deactivate_source (VoipInputMenuItem* item, gboolean visible);62void voip_input_menu_item_deactivate_source (VoipInputMenuItem* item, gboolean visible);
63void voip_input_menu_item_deactivate_voip_client (VoipInputMenuItem* item);63void voip_input_menu_item_deactivate_voip_client (VoipInputMenuItem* item);
6464
65VoipInputMenuItem* voip_input_menu_item_new (ActiveSink* sink);65VoipInputMenuItem* voip_input_menu_item_new (Device* sink);
6666
67G_END_DECLS67G_END_DECLS
6868

Subscribers

People subscribed via source and target branches