2
Copyright 2011 Canonical Ltd.
5
Conor Curran <conor.curran@canonical.com>
7
This program is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License version 3, as published
9
by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranties of
13
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
PURPOSE. See the GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License along
17
with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <glib/gi18n.h>
24
#include "voip-input-menu-item.h"
25
#include "common-defs.h"
26
#include "pulseaudio-mgr.h"
28
typedef struct _VoipInputMenuItemPrivate VoipInputMenuItemPrivate;
30
struct _VoipInputMenuItemPrivate {
35
pa_channel_map channel_map;
36
pa_volume_t base_volume;
38
gint source_output_index;
42
#define VOIP_INPUT_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VOIP_INPUT_MENU_ITEM_TYPE, VoipInputMenuItemPrivate))
45
static void voip_input_menu_item_class_init (VoipInputMenuItemClass *klass);
46
static void voip_input_menu_item_init (VoipInputMenuItem *self);
47
static void voip_input_menu_item_dispose (GObject *object);
48
static void voip_input_menu_item_finalize (GObject *object);
49
static void handle_event (DbusmenuMenuitem * mi, const gchar * name,
50
GVariant * value, guint timestamp);
52
// This method should really be shared between this and the volume slider obj
53
// perfectly static - wait until the device mgr wrapper is properly sorted and
55
static pa_cvolume voip_input_menu_item_construct_mono_volume (const pa_cvolume* vol);
57
G_DEFINE_TYPE (VoipInputMenuItem, voip_input_menu_item, DBUSMENU_TYPE_MENUITEM);
60
voip_input_menu_item_class_init (VoipInputMenuItemClass *klass)
62
GObjectClass *object_class = G_OBJECT_CLASS (klass);
64
g_type_class_add_private (klass, sizeof (VoipInputMenuItemPrivate));
66
object_class->dispose = voip_input_menu_item_dispose;
67
object_class->finalize = voip_input_menu_item_finalize;
69
DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass);
70
mclass->handle_event = handle_event;
74
voip_input_menu_item_init (VoipInputMenuItem *self)
76
dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self),
77
DBUSMENU_MENUITEM_PROP_TYPE,
78
DBUSMENU_VOIP_INPUT_MENUITEM_TYPE );
79
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (self);
80
dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(self),
81
DBUSMENU_MENUITEM_PROP_VISIBLE,
84
priv->source_index = NOT_ACTIVE;
85
priv->source_output_index = NOT_ACTIVE;
86
priv->client_index = NOT_ACTIVE;
87
priv->mute = NOT_ACTIVE;
91
voip_input_menu_item_dispose (GObject *object)
93
G_OBJECT_CLASS (voip_input_menu_item_parent_class)->dispose (object);
98
voip_input_menu_item_finalize (GObject *object)
100
G_OBJECT_CLASS (voip_input_menu_item_parent_class)->finalize (object);
104
handle_event (DbusmenuMenuitem * mi,
109
GVariant* input = NULL;
111
if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT) == TRUE) {
112
input = g_variant_get_variant(value);
115
gdouble percent = g_variant_get_double(input);
117
if (IS_VOIP_INPUT_MENU_ITEM (mi)) {
118
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (VOIP_INPUT_MENU_ITEM (mi));
120
g_debug ("Handle event in the voip input level backend instance - %f", percent);
122
pa_cvolume new_volume;
123
pa_cvolume_init(&new_volume);
124
new_volume.channels = 1;
125
pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
126
pa_cvolume_set(&new_volume, 1, new_volume_value);
128
pm_update_mic_gain (priv->source_index, new_volume);
129
// finally unmute if needed
130
if (priv->mute == 1) {
131
pm_update_mic_mute (priv->source_index, 0);
138
voip_input_menu_item_construct_mono_volume (const pa_cvolume* vol)
140
pa_cvolume new_volume;
141
pa_cvolume_init(&new_volume);
142
new_volume.channels = 1;
143
pa_volume_t max_vol = pa_cvolume_max(vol);
144
pa_cvolume_set(&new_volume, 1, max_vol);
149
voip_input_menu_item_update (VoipInputMenuItem* item,
150
const pa_source_info* source)
152
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
153
// only overwrite the constants of each source if the device has changed
154
if (priv->source_index == NOT_ACTIVE){
155
priv->base_volume = source->base_volume;
156
priv->volume_steps = source->n_volume_steps;
157
priv->channel_map = source->channel_map;
158
priv->source_index = source->index;
160
priv->volume = voip_input_menu_item_construct_mono_volume (&source->volume);
161
pa_volume_t vol = pa_cvolume_max (&source->volume);
162
gdouble update = ((gdouble) vol * 100) / PA_VOLUME_NORM;
164
GVariant* new_volume = g_variant_new_double(update);
165
dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(item),
166
DBUSMENU_VOIP_INPUT_MENUITEM_LEVEL,
168
// Only send over the mute updates if the state has changed.
169
// in this order - volume first mute last!!
170
if (priv->mute != source->mute){
172
g_debug ("voip menu item - update - mute = %i", priv->mute);
174
GVariant* new_mute_update = g_variant_new_int32 (source->mute);
175
dbusmenu_menuitem_property_set_variant (DBUSMENU_MENUITEM(item),
176
DBUSMENU_VOIP_INPUT_MENUITEM_MUTE,
180
priv->mute = source->mute;
185
voip_input_menu_item_is_interested (VoipInputMenuItem* item,
186
gint source_output_index,
189
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
190
// Check to make sure we are not handling another voip beforehand and that we
191
// have an active sink (might need to match up at start up)
192
if (priv->source_output_index != NOT_ACTIVE &&
193
priv->source_index != NOT_ACTIVE){
197
priv->source_output_index = source_output_index;
198
priv->client_index = client_index;
204
voip_input_menu_item_is_active (VoipInputMenuItem* item)
206
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
207
return (priv->source_output_index != NOT_ACTIVE && priv->client_index != NOT_ACTIVE);
212
voip_input_menu_item_is_populated (VoipInputMenuItem* item)
214
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
215
return priv->source_index != NOT_ACTIVE;
219
voip_input_menu_item_get_index (VoipInputMenuItem* item)
221
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
222
return priv->source_index;
226
voip_input_menu_item_get_source_output_index (VoipInputMenuItem* item)
228
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
230
return priv->source_output_index;
234
* If the pulse server informs of a default source change
235
* or the source in question is removed.
239
voip_input_menu_item_deactivate_source (VoipInputMenuItem* item, gboolean visible)
241
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
242
priv->source_index = NOT_ACTIVE;
243
dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item),
244
DBUSMENU_MENUITEM_PROP_VISIBLE,
249
voip_input_menu_item_deactivate_voip_client (VoipInputMenuItem* item)
251
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
252
priv->client_index = NOT_ACTIVE;
253
priv->source_output_index = NOT_ACTIVE;
254
voip_input_menu_item_enable (item, FALSE);
258
voip_input_menu_item_enable (VoipInputMenuItem* item,
261
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (item);
262
if (priv->source_index == NOT_ACTIVE && active == TRUE) {
263
g_warning ("Tried to enable the VOIP menuitem but we don't have an active source ??");
266
dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item),
267
DBUSMENU_MENUITEM_PROP_VISIBLE,
272
voip_input_menu_item_new (Device* sink)
274
VoipInputMenuItem *self = g_object_new(VOIP_INPUT_MENU_ITEM_TYPE, NULL);
275
VoipInputMenuItemPrivate* priv = VOIP_INPUT_MENU_ITEM_GET_PRIVATE (self);
b'\\ No newline at end of file'