~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/sound/gvc-mixer-sink.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2008 William Jon McCann
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include <glib.h>
 
28
#include <glib/gi18n-lib.h>
 
29
 
 
30
#include <pulse/pulseaudio.h>
 
31
 
 
32
#include "gvc-mixer-sink.h"
 
33
#include "gvc-mixer-stream-private.h"
 
34
#include "gvc-channel-map-private.h"
 
35
 
 
36
#define GVC_MIXER_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkPrivate))
 
37
 
 
38
struct GvcMixerSinkPrivate
 
39
{
 
40
        gpointer dummy;
 
41
};
 
42
 
 
43
static void     gvc_mixer_sink_class_init (GvcMixerSinkClass *klass);
 
44
static void     gvc_mixer_sink_init       (GvcMixerSink      *mixer_sink);
 
45
static void     gvc_mixer_sink_finalize   (GObject           *object);
 
46
 
 
47
G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM)
 
48
 
 
49
static gboolean
 
50
gvc_mixer_sink_push_volume (GvcMixerStream *stream, gpointer *op)
 
51
{
 
52
        pa_operation        *o;
 
53
        guint                index;
 
54
        const GvcChannelMap *map;
 
55
        pa_context          *context;
 
56
        const pa_cvolume    *cv;
 
57
 
 
58
        index = gvc_mixer_stream_get_index (stream);
 
59
 
 
60
        map = gvc_mixer_stream_get_channel_map (stream);
 
61
 
 
62
        /* set the volume */
 
63
        cv = gvc_channel_map_get_cvolume(map);
 
64
 
 
65
        context = gvc_mixer_stream_get_pa_context (stream);
 
66
 
 
67
        o = pa_context_set_sink_volume_by_index (context,
 
68
                                                 index,
 
69
                                                 cv,
 
70
                                                 NULL,
 
71
                                                 NULL);
 
72
 
 
73
        if (o == NULL) {
 
74
                g_warning ("pa_context_set_sink_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
 
75
                return FALSE;
 
76
        }
 
77
 
 
78
        *op = o;
 
79
 
 
80
        return TRUE;
 
81
}
 
82
 
 
83
static gboolean
 
84
gvc_mixer_sink_change_is_muted (GvcMixerStream *stream,
 
85
                                gboolean        is_muted)
 
86
{
 
87
        pa_operation *o;
 
88
        guint         index;
 
89
        pa_context   *context;
 
90
 
 
91
        index = gvc_mixer_stream_get_index (stream);
 
92
        context = gvc_mixer_stream_get_pa_context (stream);
 
93
 
 
94
        o = pa_context_set_sink_mute_by_index (context,
 
95
                                               index,
 
96
                                               is_muted,
 
97
                                               NULL,
 
98
                                               NULL);
 
99
 
 
100
        if (o == NULL) {
 
101
                g_warning ("pa_context_set_sink_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
 
102
                return FALSE;
 
103
        }
 
104
 
 
105
        pa_operation_unref(o);
 
106
 
 
107
        return TRUE;
 
108
}
 
109
 
 
110
static gboolean
 
111
gvc_mixer_sink_change_port (GvcMixerStream *stream,
 
112
                            const char     *port)
 
113
{
 
114
        pa_operation *o;
 
115
        guint         index;
 
116
        pa_context   *context;
 
117
 
 
118
        index = gvc_mixer_stream_get_index (stream);
 
119
        context = gvc_mixer_stream_get_pa_context (stream);
 
120
 
 
121
        o = pa_context_set_sink_port_by_index (context,
 
122
                                               index,
 
123
                                               port,
 
124
                                               NULL,
 
125
                                               NULL);
 
126
 
 
127
        if (o == NULL) {
 
128
                g_warning ("pa_context_set_sink_port_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
 
129
                return FALSE;
 
130
        }
 
131
 
 
132
        pa_operation_unref(o);
 
133
 
 
134
        return TRUE;
 
135
}
 
136
 
 
137
static void
 
138
gvc_mixer_sink_class_init (GvcMixerSinkClass *klass)
 
139
{
 
140
        GObjectClass        *object_class = G_OBJECT_CLASS (klass);
 
141
        GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
 
142
 
 
143
        object_class->finalize = gvc_mixer_sink_finalize;
 
144
 
 
145
        stream_class->push_volume = gvc_mixer_sink_push_volume;
 
146
        stream_class->change_port = gvc_mixer_sink_change_port;
 
147
        stream_class->change_is_muted = gvc_mixer_sink_change_is_muted;
 
148
 
 
149
        g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate));
 
150
}
 
151
 
 
152
static void
 
153
gvc_mixer_sink_init (GvcMixerSink *sink)
 
154
{
 
155
        sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink);
 
156
}
 
157
 
 
158
static void
 
159
gvc_mixer_sink_finalize (GObject *object)
 
160
{
 
161
        GvcMixerSink *mixer_sink;
 
162
 
 
163
        g_return_if_fail (object != NULL);
 
164
        g_return_if_fail (GVC_IS_MIXER_SINK (object));
 
165
 
 
166
        mixer_sink = GVC_MIXER_SINK (object);
 
167
 
 
168
        g_return_if_fail (mixer_sink->priv != NULL);
 
169
        G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object);
 
170
}
 
171
 
 
172
/**
 
173
 * gvc_mixer_sink_new: (skip)
 
174
 *
 
175
 * @context:
 
176
 * @index:
 
177
 * @channel_map:
 
178
 *
 
179
 * Returns:
 
180
 */
 
181
GvcMixerStream *
 
182
gvc_mixer_sink_new (pa_context    *context,
 
183
                    guint          index,
 
184
                    GvcChannelMap *channel_map)
 
185
 
 
186
{
 
187
        GObject *object;
 
188
 
 
189
        object = g_object_new (GVC_TYPE_MIXER_SINK,
 
190
                               "pa-context", context,
 
191
                               "index", index,
 
192
                               "channel-map", channel_map,
 
193
                               NULL);
 
194
 
 
195
        return GVC_MIXER_STREAM (object);
 
196
}