~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to gnome/src/config/audioconf.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
14
14
 *
15
15
 *  You should have received a copy of the GNU General Public License
16
16
 *  along with this program; if not, write to the Free Software
17
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
18
18
 *
19
19
 *  Additional permission under GNU GPL version 3 section 7:
20
20
 *
28
28
 *  as that of the covered work.
29
29
 */
30
30
 
 
31
#include <glib/gstdio.h>
31
32
#include <glib/gi18n.h>
32
 
#include "gtk2_wrappers.h"
33
33
#include "str_utils.h"
 
34
#include "codeclist.h"
 
35
#include "sflphone_const.h"
34
36
#include "audioconf.h"
35
37
#include "utils.h"
36
 
#include "logger.h"
37
 
#include "eel-gconf-extensions.h"
38
38
#include "dbus/dbus.h"
39
39
#include "uimanager.h"
40
40
#include "mainwindow.h"
41
 
#include "unused.h"
42
41
 
43
42
/* FIXME: these should be in a struct rather than at file scope */
44
 
static GtkListStore *pluginlist;
45
 
static GtkListStore *outputlist;
46
 
static GtkListStore *inputlist;
47
 
static GtkListStore *ringtonelist;
48
 
 
49
 
static GtkWidget *output;
50
 
static GtkWidget *input;
51
 
static GtkWidget *ringtone;
52
 
static GtkWidget *plugin;
53
43
static GtkWidget *codecMoveUpButton;
54
44
static GtkWidget *codecMoveDownButton;
55
 
static GtkWidget *codecTreeView;                // View used instead of store to get access to selection
56
 
static GtkWidget *pulse;
 
45
static GtkWidget *codecTreeView; // View used instead of store to get access to selection
 
46
static GtkWidget *pulsebox;
 
47
static GtkWidget *pulse_conf;
57
48
static GtkWidget *alsabox;
58
49
static GtkWidget *alsa_conf;
 
50
static GtkWidget *alsa_output;
 
51
static GtkWidget *alsa_input;
 
52
static GtkWidget *alsa_ringtone;
59
53
 
60
54
// Codec properties ID
61
55
enum {
66
60
    CODEC_COLUMN_COUNT
67
61
};
68
62
 
69
 
static void active_is_always_recording(void);
 
63
#define KBPS "kbps"
 
64
#define KHZ "kHz"
70
65
 
71
66
/**
72
67
 * Fills the tree list with supported codecs
73
68
 */
74
69
static void
75
 
preferences_dialog_fill_codec_list(const account_t *account)
 
70
fill_codec_list(const account_t *account)
76
71
{
77
72
    // Get model of view and clear it
78
73
    GtkListStore *codecStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(codecTreeView)));
79
74
    gtk_list_store_clear(codecStore);
80
75
 
81
 
    GQueue *current = account ? account->codecs : get_system_codec_list();
82
 
 
83
 
    if (!account) DEBUG("Using system codec list");
 
76
    GQueue *list;
 
77
    if (!account) {
 
78
        g_debug("Account is NULL, using global codec list");
 
79
        list = get_audio_codecs_list();
 
80
    } else {
 
81
        list = account->acodecs;
 
82
    }
84
83
 
85
84
    // Insert codecs
86
 
    for (guint i = 0; i < g_queue_get_length(current); i++) {
87
 
        codec_t *c = codec_list_get_nth(i, current);
 
85
    for (size_t i = 0; i < list->length; ++i) {
 
86
        codec_t *c = g_queue_peek_nth(list, i);
88
87
 
89
88
        if (c) {
90
 
            DEBUG("%s", c->name);
 
89
            g_debug("%s is %sactive", c->name, c->is_active ? "" : "not ");
91
90
            GtkTreeIter iter;
92
91
            gtk_list_store_append(codecStore, &iter);
 
92
            gchar *samplerate = g_strdup_printf("%d " KHZ, (gint) (c->sample_rate * 0.001));
 
93
            gchar *bitrate = g_strdup_printf("%s " KBPS, c->bitrate);
 
94
 
93
95
            gtk_list_store_set(codecStore, &iter,
94
96
                               COLUMN_CODEC_ACTIVE, c->is_active,
95
97
                               COLUMN_CODEC_NAME, c->name,
96
 
                               COLUMN_CODEC_FREQUENCY, g_strdup_printf("%d kHz", (gint)(c->sample_rate * 0.001)),
97
 
                               COLUMN_CODEC_BITRATE, g_strdup_printf("%.1f kbps", c->_bitrate),
 
98
                               COLUMN_CODEC_FREQUENCY, samplerate,
 
99
                               COLUMN_CODEC_BITRATE, bitrate,
98
100
                               -1);
 
101
            g_free(samplerate);
 
102
            g_free(bitrate);
99
103
        }
100
104
    }
101
105
}
102
106
 
 
107
static GtkListStore *
 
108
create_device_list_store(gchar **list)
 
109
{
 
110
    GtkListStore *list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
 
111
 
 
112
    for (gchar **tmp = list; tmp && *tmp; ++tmp) {
 
113
        gint device_index = dbus_get_audio_device_index(*tmp);
 
114
        GtkTreeIter iter;
 
115
        gtk_list_store_append(list_store, &iter);
 
116
        gtk_list_store_set(list_store, &iter, 0, *tmp, 1, device_index, -1);
 
117
    }
 
118
    g_strfreev(list);
 
119
    return list_store;
 
120
}
 
121
 
103
122
/**
104
123
 * Fill store with output audio plugins
105
124
 */
106
 
void
107
 
preferences_dialog_fill_audio_plugin_list()
 
125
static GtkListStore*
 
126
create_alsa_plugin_list_store()
108
127
{
109
 
    gtk_list_store_clear(pluginlist);
 
128
    GtkListStore *list_store = gtk_list_store_new(1, G_TYPE_STRING);
110
129
 
111
130
    // Call dbus to retreive list
112
131
    gchar **list = dbus_get_audio_plugin_list();
113
132
 
114
 
    // For each API name included in list
115
 
    if (list != NULL) {
116
 
        int c = 0;
117
 
 
118
 
        for (gchar *managerName = list[c]; managerName != NULL; managerName = list[c]) {
119
 
            c++;
120
 
            GtkTreeIter iter;
121
 
            gtk_list_store_append(pluginlist, &iter);
122
 
            gtk_list_store_set(pluginlist, &iter, 0, managerName, -1);
123
 
        }
124
 
    }
125
 
}
126
 
 
127
 
void
128
 
preferences_dialog_fill_output_audio_device_list()
129
 
{
130
 
    gtk_list_store_clear(outputlist);
131
 
 
132
 
    // Call dbus to retrieve list
133
 
    for (gchar **list = dbus_get_audio_output_device_list(); *list ; list++) {
134
 
        int device_index = dbus_get_audio_device_index(*list);
135
 
        GtkTreeIter iter;
136
 
        gtk_list_store_append(outputlist, &iter);
137
 
        gtk_list_store_set(outputlist, &iter, 0, *list, 1, device_index, -1);
138
 
    }
139
 
}
140
 
 
141
 
void
142
 
preferences_dialog_fill_ringtone_audio_device_list()
143
 
{
144
 
    gtk_list_store_clear(ringtonelist);
145
 
 
146
 
    // Call dbus to retreive output device
147
 
    for (gchar **list = dbus_get_audio_output_device_list(); *list; list++) {
148
 
        int device_index = dbus_get_audio_device_index(*list);
149
 
        GtkTreeIter iter;
150
 
        gtk_list_store_append(ringtonelist, &iter);
151
 
        gtk_list_store_set(ringtonelist, &iter, 0, *list, 1, device_index, -1);
152
 
    }
153
 
}
154
 
 
155
 
void
156
 
select_active_output_audio_device()
157
 
{
158
 
    gboolean show_alsa = must_show_alsa_conf();
159
 
 
160
 
    if(!show_alsa)
161
 
        return;
162
 
 
 
133
    // For each plugin name included in list
 
134
    for (gchar **tmp = list; tmp && *tmp; ++tmp) {
 
135
        GtkTreeIter iter;
 
136
        gtk_list_store_append(list_store, &iter);
 
137
        gtk_list_store_set(list_store, &iter, 0, *tmp, -1);
 
138
    }
 
139
    g_strfreev(list);
 
140
    return list_store;
 
141
}
 
142
 
 
143
static void
 
144
select_active_output_audio_device(GtkWidget *output)
 
145
{
163
146
    // Select active output device on server
164
147
    gchar **devices = dbus_get_current_audio_devices_index();
165
 
 
166
 
 
167
 
    int currentDeviceIndex = atoi(devices[0]);
168
 
    DEBUG("audio device index for output = %d", currentDeviceIndex);
169
 
    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(output));
170
 
 
171
 
    // Find the currently set output device
172
 
    GtkTreeIter iter;
173
 
    gtk_tree_model_get_iter_first(model, &iter);
174
 
 
175
 
    do {
176
 
        int deviceIndex;
177
 
        gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
178
 
 
179
 
        if (deviceIndex == currentDeviceIndex) {
180
 
            // Set current iteration the active one
181
 
            gtk_combo_box_set_active_iter(GTK_COMBO_BOX(output), &iter);
182
 
            return;
183
 
        }
184
 
    } while (gtk_tree_model_iter_next(model, &iter));
 
148
    if (devices && devices[0]) {
 
149
 
 
150
        int currentDeviceIndex = atoi(devices[0]);
 
151
        g_strfreev(devices);
 
152
        g_debug("audio device index for output = %d", currentDeviceIndex);
 
153
        GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(output));
 
154
 
 
155
        // Find the currently set output device
 
156
        GtkTreeIter iter;
 
157
        gtk_tree_model_get_iter_first(model, &iter);
 
158
 
 
159
        do {
 
160
            int deviceIndex;
 
161
            gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
 
162
 
 
163
            if (deviceIndex == currentDeviceIndex) {
 
164
                // Set current iteration the active one
 
165
                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(output), &iter);
 
166
                return;
 
167
            }
 
168
        } while (gtk_tree_model_iter_next(model, &iter));
 
169
    }
185
170
 
186
171
    // No index was found, select first one
187
 
    WARN("No active output device found");
 
172
    g_warning("No active output device found");
188
173
    gtk_combo_box_set_active(GTK_COMBO_BOX(output), 0);
189
174
}
190
175
 
192
177
/**
193
178
 * Select active output audio device
194
179
 */
195
 
void
196
 
select_active_ringtone_audio_device()
 
180
static void
 
181
select_active_ringtone_audio_device(GtkWidget *ringtone)
197
182
{
198
 
    if (must_show_alsa_conf()) {
199
 
        // Select active ringtone device on server
200
 
        gchar **devices = dbus_get_current_audio_devices_index();
201
 
        int currentDeviceIndex = atoi(devices[2]);
202
 
        DEBUG("audio device index for ringtone = %d", currentDeviceIndex);
 
183
    // Select active ringtone device on server
 
184
    gchar **devices = dbus_get_current_audio_devices_index();
 
185
    if (devices && devices[2]) {
 
186
        const gint currentDeviceIndex = atoi(devices[2]);
 
187
        g_strfreev(devices);
 
188
        g_debug("audio device index for ringtone = %d", currentDeviceIndex);
203
189
        GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(ringtone));
204
190
 
205
191
        // Find the currently set ringtone device
216
202
                return;
217
203
            }
218
204
        } while (gtk_tree_model_iter_next(model, &iter));
219
 
 
220
 
        // No index was found, select first one
221
 
        WARN("Warning : No active ringtone device found");
222
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(ringtone), 0);
223
205
    }
224
 
}
225
 
 
226
 
void
227
 
preferences_dialog_fill_input_audio_device_list()
228
 
{
229
 
    gtk_list_store_clear(inputlist);
230
 
 
231
 
    // Call dbus to retreive list
 
206
 
 
207
    // No index was found, select first one
 
208
    g_warning("No active ringtone device found");
 
209
    gtk_combo_box_set_active(GTK_COMBO_BOX(ringtone), 0);
 
210
}
 
211
 
 
212
static GtkListStore*
 
213
create_output_list_store()
 
214
{
 
215
    gchar **list = dbus_get_audio_output_device_list();
 
216
    return create_device_list_store(list);
 
217
}
 
218
 
 
219
static GtkListStore*
 
220
create_input_list_store()
 
221
{
232
222
    gchar **list = dbus_get_audio_input_device_list();
233
 
 
234
 
    // For each device name included in list
235
 
    for (; *list; list++) {
236
 
        int device_index = dbus_get_audio_device_index(*list);
237
 
        GtkTreeIter iter;
238
 
        gtk_list_store_append(inputlist, &iter);
239
 
        gtk_list_store_set(inputlist, &iter, 0, *list, 1, device_index, -1);
240
 
    }
241
 
 
 
223
    return create_device_list_store(list);
242
224
}
243
225
 
244
 
void
245
 
select_active_input_audio_device()
 
226
static void
 
227
select_active_input_audio_device(GtkWidget *input)
246
228
{
247
 
    if (must_show_alsa_conf()) {
248
 
        // Select active input device on server
249
 
        gchar **devices = dbus_get_current_audio_devices_index();
 
229
    // Select active input device on server
 
230
    gchar **devices = dbus_get_current_audio_devices_index();
 
231
    if (devices && devices[1]) {
250
232
        int currentDeviceIndex = atoi(devices[1]);
 
233
        g_strfreev(devices);
251
234
        GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(input));
252
235
 
253
236
        // Find the currently set input device
264
247
                return;
265
248
            }
266
249
        } while (gtk_tree_model_iter_next(model, &iter));
267
 
 
268
 
        // No index was found, select first one
269
 
        WARN("Warning : No active input device found");
270
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(input), 0);
271
 
    }
272
 
}
273
 
 
274
 
void
275
 
update_device_widget(gchar *pluginName)
276
 
{
277
 
    if (utf8_case_equal(pluginName, "default")) {
278
 
        gtk_widget_set_sensitive(output, FALSE);
279
 
        gtk_widget_set_sensitive(input, FALSE);
280
 
        gtk_widget_set_sensitive(ringtone, FALSE);
281
 
    } else {
282
 
        gtk_widget_set_sensitive(output, TRUE);
283
 
        gtk_widget_set_sensitive(input, TRUE);
284
 
        gtk_widget_set_sensitive(ringtone, TRUE);
285
 
    }
286
 
}
287
 
 
288
 
static void
289
 
select_output_audio_plugin(GtkComboBox* widget, gpointer data UNUSED)
290
 
{
291
 
    int comboBoxIndex = gtk_combo_box_get_active(widget);
 
250
    }
 
251
 
 
252
    // No index was found, select first one
 
253
    g_warning("No active input device found");
 
254
    gtk_combo_box_set_active(GTK_COMBO_BOX(input), 0);
 
255
}
 
256
 
 
257
static void
 
258
update_device_widget(const gchar *pluginName, GtkWidget *output, GtkWidget *input, GtkWidget *ringtone)
 
259
{
 
260
    const gboolean is_default = utf8_case_equal(pluginName, "default");
 
261
    gtk_widget_set_sensitive(output, !is_default);
 
262
    gtk_widget_set_sensitive(input, !is_default);
 
263
    gtk_widget_set_sensitive(ringtone, !is_default);
 
264
}
 
265
 
 
266
static void
 
267
select_output_alsa_plugin(GtkComboBox* widget, G_GNUC_UNUSED gpointer data)
 
268
{
 
269
    if (!must_show_alsa_conf())
 
270
        return;
 
271
    const gint comboBoxIndex = gtk_combo_box_get_active(widget);
292
272
 
293
273
    if (comboBoxIndex >= 0) {
294
274
        GtkTreeModel *model = gtk_combo_box_get_model(widget);
297
277
        gchar* pluginName;
298
278
        gtk_tree_model_get(model, &iter, 0, &pluginName, -1);
299
279
        dbus_set_audio_plugin(pluginName);
300
 
        update_device_widget(pluginName);
 
280
        update_device_widget(pluginName, alsa_output, alsa_input, alsa_ringtone);
301
281
    }
302
282
}
303
283
 
304
 
void
305
 
select_active_output_audio_plugin()
 
284
static void
 
285
select_active_output_alsa_plugin(GtkWidget *alsa_plugin)
306
286
{
 
287
    if (!must_show_alsa_conf())
 
288
        return;
307
289
    // Select active output device on server
308
 
    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(plugin));
 
290
    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(alsa_plugin));
309
291
 
310
292
    // Find the current alsa plugin
311
293
    GtkTreeIter iter;
312
294
    gtk_tree_model_get_iter_first(model, &iter);
313
295
 
314
 
    gchar *pluginname = dbus_get_current_audio_output_plugin();
315
 
    gchar *tmp = pluginname;
 
296
    gchar *alsa_pluginname = dbus_get_current_audio_output_plugin();
 
297
    gchar *tmp = alsa_pluginname;
316
298
 
317
299
    do {
318
 
        gtk_tree_model_get(model, &iter, 0, &pluginname, -1);
 
300
        gtk_tree_model_get(model, &iter, 0, &alsa_pluginname, -1);
319
301
 
320
 
        if (utf8_case_equal(tmp, pluginname)) {
 
302
        if (utf8_case_equal(tmp, alsa_pluginname)) {
 
303
            g_free(alsa_pluginname);
321
304
            // Set current iteration the active one
322
 
            gtk_combo_box_set_active_iter(GTK_COMBO_BOX(plugin), &iter);
 
305
            gtk_combo_box_set_active_iter(GTK_COMBO_BOX(alsa_plugin), &iter);
323
306
            return;
324
307
        }
325
308
    } while (gtk_tree_model_iter_next(model, &iter));
 
309
    g_free(alsa_pluginname);
326
310
 
327
311
    // No index was found, select first one
328
 
    WARN("Warning : No active output device found");
329
 
    gtk_combo_box_set_active(GTK_COMBO_BOX(plugin), 0);
330
 
}
331
 
 
332
 
 
333
 
static void
334
 
select_audio_output_device(GtkComboBox* comboBox, gpointer data UNUSED)
335
 
{
336
 
    int comboBoxIndex = gtk_combo_box_get_active(comboBox);
337
 
 
338
 
    if (comboBoxIndex >= 0) {
339
 
        GtkTreeModel *model = gtk_combo_box_get_model(comboBox);
340
 
        GtkTreeIter iter;
341
 
        gtk_combo_box_get_active_iter(comboBox, &iter);
342
 
        int deviceIndex;
343
 
        gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
344
 
        dbus_set_audio_output_device(deviceIndex);
345
 
    }
346
 
}
347
 
 
348
 
static void
349
 
select_audio_input_device(GtkComboBox* comboBox, gpointer data UNUSED)
350
 
{
351
 
    if (gtk_combo_box_get_active(comboBox) >= 0) {
352
 
        GtkTreeModel* model = gtk_combo_box_get_model(comboBox);
353
 
        GtkTreeIter iter;
354
 
        gtk_combo_box_get_active_iter(comboBox, &iter);
355
 
        int deviceIndex;
356
 
        gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
357
 
        dbus_set_audio_input_device(deviceIndex);
358
 
    }
359
 
}
360
 
 
361
 
 
362
 
static void
363
 
select_audio_ringtone_device(GtkComboBox *comboBox, gpointer data UNUSED)
364
 
{
365
 
    if (gtk_combo_box_get_active(comboBox) >= 0) {
366
 
        GtkTreeModel *model = gtk_combo_box_get_model(comboBox);
367
 
        GtkTreeIter iter;
368
 
        gtk_combo_box_get_active_iter(comboBox, &iter);
369
 
        int deviceIndex;
370
 
        gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
371
 
        dbus_set_audio_ringtone_device(deviceIndex);
372
 
    }
373
 
}
374
 
 
 
312
    g_warning("No active output device found");
 
313
    gtk_combo_box_set_active(GTK_COMBO_BOX(alsa_plugin), 0);
 
314
}
 
315
 
 
316
static gint
 
317
get_device_index_from_combobox(GtkComboBox* comboBox)
 
318
{
 
319
    GtkTreeModel* model = gtk_combo_box_get_model(comboBox);
 
320
    GtkTreeIter iter;
 
321
    gtk_combo_box_get_active_iter(comboBox, &iter);
 
322
    gint deviceIndex;
 
323
    gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
 
324
    return deviceIndex;
 
325
}
 
326
 
 
327
static void
 
328
select_audio_output_device(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
 
329
{
 
330
    if (gtk_combo_box_get_active(comboBox) >= 0)
 
331
        dbus_set_audio_output_device(get_device_index_from_combobox(comboBox));
 
332
}
 
333
 
 
334
static void
 
335
select_audio_input_device(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
 
336
{
 
337
    if (gtk_combo_box_get_active(comboBox) >= 0)
 
338
       dbus_set_audio_input_device(get_device_index_from_combobox(comboBox));
 
339
}
 
340
 
 
341
static void
 
342
select_audio_ringtone_device(GtkComboBox *comboBox, G_GNUC_UNUSED gpointer data)
 
343
{
 
344
    if (gtk_combo_box_get_active(comboBox) >= 0)
 
345
        dbus_set_audio_ringtone_device(get_device_index_from_combobox(comboBox));
 
346
}
375
347
 
376
348
/**
377
349
 * Toggle move buttons on if a codec is selected, off elsewise
395
367
 * and in configuration files
396
368
 */
397
369
static void
398
 
codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, gpointer data)
 
370
codec_active_toggled(G_GNUC_UNUSED GtkCellRendererToggle *renderer, gchar *path, gpointer data)
399
371
{
400
372
    // Get path of clicked codec active toggle box
401
373
    GtkTreePath *treePath = gtk_tree_path_new_from_string(path);
407
379
    account_t *acc = (account_t*) data;
408
380
 
409
381
    if (!acc) {
410
 
        ERROR("no account selected");
 
382
        g_warning("no account selected");
411
383
        return;
412
384
    }
413
385
 
414
386
    // Get active value and name at iteration
415
387
    gboolean active;
416
388
    gchar* name;
417
 
    gchar* srate;
 
389
    gchar* samplerate;
418
390
    gtk_tree_model_get(model, &iter, COLUMN_CODEC_ACTIVE, &active,
419
391
                       COLUMN_CODEC_NAME, &name, COLUMN_CODEC_FREQUENCY,
420
 
                       &srate, -1);
421
 
 
422
 
    DEBUG("Selected Codec: %s, %s", name, srate);
423
 
 
424
 
    codec_t* codec;
425
 
 
426
 
    if (utf8_case_equal(name,"speex") && utf8_case_equal(srate,"8 kHz"))
427
 
        codec = codec_list_get_by_payload((gconstpointer) 110, acc->codecs);
428
 
    else if (utf8_case_equal(name,"speex") && utf8_case_equal(srate,"16 kHz"))
429
 
        codec = codec_list_get_by_payload((gconstpointer) 111, acc->codecs);
430
 
    else if (utf8_case_equal(name,"speex") && utf8_case_equal(srate, "32 kHz"))
431
 
        codec = codec_list_get_by_payload((gconstpointer) 112, acc->codecs);
432
 
    else
433
 
        codec = codec_list_get_by_name((gconstpointer) name, acc->codecs);
 
392
                       &samplerate, -1);
 
393
 
 
394
    g_debug("Selected Codec: %s, %s", name, samplerate);
 
395
 
 
396
    codec_t* codec = NULL;
 
397
 
 
398
    const gboolean is_speex = utf8_case_equal(name, "speex");
 
399
    if (is_speex) {
 
400
        if (utf8_case_equal(samplerate, "8 " KHZ))
 
401
            codec = codec_list_get_by_payload(110, acc->acodecs);
 
402
        else if (utf8_case_equal(samplerate, "16 " KHZ))
 
403
            codec = codec_list_get_by_payload(111, acc->acodecs);
 
404
        else if (utf8_case_equal(samplerate, "32 " KHZ))
 
405
            codec = codec_list_get_by_payload(112, acc->acodecs);
 
406
        else
 
407
            codec = codec_list_get_by_name((gconstpointer) name, acc->acodecs);
 
408
    } else {
 
409
        codec = codec_list_get_by_name((gconstpointer) name, acc->acodecs);
 
410
    }
434
411
 
435
412
    // Toggle active value
436
413
    active = !active;
494
471
    if (acc) {
495
472
        // propagate changes in codec queue
496
473
        if (moveUp)
497
 
            codec_list_move_codec_up(indice, &acc->codecs);
 
474
            codec_list_move_codec_up(indice, &acc->acodecs);
498
475
        else
499
 
            codec_list_move_codec_down(indice, &acc->codecs);
 
476
            codec_list_move_codec_down(indice, &acc->acodecs);
500
477
    }
501
478
}
502
479
 
503
480
/**
504
481
 * Called from move up codec button signal
505
482
 */
506
 
static void codec_move_up(GtkButton *button UNUSED, gpointer data)
 
483
static void codec_move_up(G_GNUC_UNUSED GtkButton *button, gpointer data)
507
484
{
508
485
    // Change tree view ordering and get indice changed
509
486
    codec_move(TRUE, data);
512
489
/**
513
490
 * Called from move down codec button signal
514
491
 */
515
 
static void codec_move_down(GtkButton *button UNUSED, gpointer data)
 
492
static void codec_move_down(G_GNUC_UNUSED GtkButton *button, gpointer data)
516
493
{
517
494
    // Change tree view ordering and get indice changed
518
495
    codec_move(FALSE, data);
519
496
}
520
497
 
521
 
GtkWidget* audiocodecs_box(const account_t *account)
 
498
GtkWidget*
 
499
audiocodecs_box(const account_t *account)
522
500
{
523
501
    GtkWidget *audiocodecs_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
524
502
    gtk_container_set_border_width(GTK_CONTAINER(audiocodecs_hbox), 10);
529
507
 
530
508
    gtk_box_pack_start(GTK_BOX(audiocodecs_hbox), scrolledWindow, TRUE, TRUE, 0);
531
509
    GtkListStore *codecStore = gtk_list_store_new(CODEC_COLUMN_COUNT,
532
 
                               G_TYPE_BOOLEAN, /* Active */
533
 
                               G_TYPE_STRING,  /* Name */
534
 
                               G_TYPE_STRING,  /* Frequency */
535
 
                               G_TYPE_STRING,  /* Bit rate */
536
 
                               G_TYPE_STRING   /* Bandwidth */
537
 
                               );
 
510
            G_TYPE_BOOLEAN, /* Active */
 
511
            G_TYPE_STRING, /* Name */
 
512
            G_TYPE_STRING, /* Frequency */
 
513
            G_TYPE_STRING, /* Bitrate */
 
514
            G_TYPE_STRING  /* Bandwidth */);
538
515
 
539
516
    // Create codec tree view with list store
540
517
    codecTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(codecStore));
541
518
 
 
519
    /* The list store model will be destroyed automatically with the view */
 
520
    g_object_unref(G_OBJECT(codecStore));
 
521
 
542
522
    // Get tree selection manager
543
523
    GtkTreeSelection *treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(codecTreeView));
544
524
    g_signal_connect(G_OBJECT(treeSelection), "changed",
568
548
    treeViewColumn = gtk_tree_view_column_new_with_attributes(_("Bitrate"), renderer, "text", COLUMN_CODEC_BITRATE, NULL);
569
549
    gtk_tree_view_append_column(GTK_TREE_VIEW(codecTreeView), treeViewColumn);
570
550
 
571
 
    g_object_unref(G_OBJECT(codecStore));
572
551
    gtk_container_add(GTK_CONTAINER(scrolledWindow), codecTreeView);
573
552
 
574
553
    // Create button box
588
567
    g_signal_connect(G_OBJECT(codecMoveDownButton), "clicked",
589
568
                     G_CALLBACK(codec_move_down), (gpointer) account);
590
569
 
591
 
    preferences_dialog_fill_codec_list(account);
 
570
    fill_codec_list(account);
592
571
 
593
572
    return audiocodecs_hbox;
594
573
}
595
574
 
596
 
void
597
 
select_audio_manager(void)
598
 
{
599
 
    if (!must_show_alsa_conf() && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pulse))) {
 
575
static GtkWidget* alsa_box()
 
576
{
 
577
    GtkWidget *alsa_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
 
578
    gtk_widget_show(alsa_hbox);
 
579
 
 
580
    GtkWidget *grid = gtk_grid_new();
 
581
    gtk_grid_set_column_spacing(GTK_GRID(grid), 40);
 
582
    gtk_box_pack_start(GTK_BOX(alsa_hbox), grid, TRUE, TRUE, 1);
 
583
    gtk_widget_show(grid);
 
584
 
 
585
    gchar *message = "<small><i>default</i> plugin always uses internal sound card. Select <i>dmix/dsnoop</i> to use an alternate soundcard.</small>";
 
586
    GtkWidget *info_bar = gnome_info_bar(message, GTK_MESSAGE_INFO);
 
587
    /* Info bar gets a width of 2 cells */
 
588
    gtk_grid_attach(GTK_GRID(grid), info_bar, 1, 1, 2, 1);
 
589
 
 
590
    g_debug("Configuration plugin");
 
591
    GtkWidget *label = gtk_label_new(_("ALSA plugin"));
 
592
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
593
    gtk_grid_attach(GTK_GRID(grid), label, 1, 2, 1, 1);
 
594
    gtk_widget_show(label);
 
595
    // Set choices of audio managers
 
596
    GtkListStore *alsa_pluginlist = create_alsa_plugin_list_store();
 
597
    GtkWidget *alsa_plugin = gtk_combo_box_new_with_model(GTK_TREE_MODEL(alsa_pluginlist));
 
598
    select_active_output_alsa_plugin(alsa_plugin);
 
599
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), alsa_plugin);
 
600
    g_signal_connect(G_OBJECT(alsa_plugin), "changed", G_CALLBACK(select_output_alsa_plugin), NULL);
 
601
 
 
602
    // Set rendering
 
603
    GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
 
604
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(alsa_plugin), renderer, TRUE);
 
605
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(alsa_plugin), renderer, "text", 0, NULL);
 
606
    gtk_grid_attach(GTK_GRID(grid), alsa_plugin, 2, 2, 1, 1);
 
607
    gtk_widget_show(alsa_plugin);
 
608
 
 
609
    // Device : Output device
 
610
    // Create title label
 
611
    g_debug("Configuration output");
 
612
    label = gtk_label_new(_("Output"));
 
613
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
614
    gtk_grid_attach(GTK_GRID(grid), label, 1, 3, 1, 1);
 
615
    gtk_widget_show(label);
 
616
    // Set choices of output devices
 
617
    GtkListStore *outputlist = create_output_list_store();
 
618
    alsa_output = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputlist));
 
619
    select_active_output_audio_device(alsa_output);
 
620
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), alsa_output);
 
621
    g_signal_connect(G_OBJECT(alsa_output), "changed", G_CALLBACK(select_audio_output_device), NULL);
 
622
 
 
623
    // Set rendering
 
624
    renderer = gtk_cell_renderer_text_new();
 
625
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(alsa_output), renderer, TRUE);
 
626
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(alsa_output), renderer, "text", 0, NULL);
 
627
    gtk_grid_attach(GTK_GRID(grid), alsa_output, 2, 3, 1, 1);
 
628
    gtk_widget_show(alsa_output);
 
629
 
 
630
    // Device : Input device
 
631
    // Create title label
 
632
    g_debug("Configuration input");
 
633
    label = gtk_label_new(_("Input"));
 
634
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
635
    gtk_grid_attach(GTK_GRID(grid), label, 1, 4, 1, 1);
 
636
    gtk_widget_show(label);
 
637
 
 
638
    // Set choices of input devices
 
639
    GtkListStore *inputlist = create_input_list_store();
 
640
    alsa_input = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputlist));
 
641
    select_active_input_audio_device(alsa_input);
 
642
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), alsa_input);
 
643
    g_signal_connect(G_OBJECT(alsa_input), "changed", G_CALLBACK(select_audio_input_device), NULL);
 
644
 
 
645
    // Set rendering
 
646
    renderer = gtk_cell_renderer_text_new();
 
647
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(alsa_input), renderer, TRUE);
 
648
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(alsa_input), renderer, "text", 0, NULL);
 
649
    gtk_grid_attach(GTK_GRID(grid), alsa_input, 2, 4, 1, 1);
 
650
    gtk_widget_show(alsa_input);
 
651
 
 
652
    g_debug("Configuration rintgtone");
 
653
    label = gtk_label_new(_("Ringtone"));
 
654
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
655
    gtk_grid_attach(GTK_GRID(grid), label, 1, 5, 1, 1);
 
656
    gtk_widget_show(label);
 
657
    // set choices of ringtone devices
 
658
    GtkListStore *ringtonelist = create_output_list_store();
 
659
    alsa_ringtone = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ringtonelist));
 
660
    select_active_ringtone_audio_device(alsa_ringtone);
 
661
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), alsa_output);
 
662
    g_signal_connect(G_OBJECT(alsa_ringtone), "changed", G_CALLBACK(select_audio_ringtone_device), NULL);
 
663
 
 
664
    // Set rendering
 
665
    renderer = gtk_cell_renderer_text_new();
 
666
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(alsa_ringtone), renderer, TRUE);
 
667
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(alsa_ringtone), renderer, "text", 0, NULL);
 
668
    gtk_grid_attach(GTK_GRID(grid), alsa_ringtone, 2, 5, 1, 1);
 
669
    gtk_widget_show(alsa_ringtone);
 
670
 
 
671
    gtk_widget_show_all(alsa_hbox);
 
672
 
 
673
    // Update the combo box
 
674
    gchar *alsa_pluginname = dbus_get_current_audio_output_plugin();
 
675
    update_device_widget(alsa_pluginname, alsa_output, alsa_input, alsa_ringtone);
 
676
    g_free(alsa_pluginname);
 
677
    return alsa_hbox;
 
678
}
 
679
 
 
680
static GtkWidget* pulse_box()
 
681
{
 
682
    GtkWidget *pulse_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
 
683
    gtk_widget_show(pulse_hbox);
 
684
 
 
685
    GtkWidget *grid = gtk_grid_new();
 
686
    gtk_grid_set_column_spacing(GTK_GRID(grid), 40);
 
687
    gtk_box_pack_start(GTK_BOX(pulse_hbox), grid, TRUE, TRUE, 1);
 
688
    gtk_widget_show(grid);
 
689
 
 
690
    // Device : Output device
 
691
    // Create title label
 
692
    g_debug("Configuration output");
 
693
    GtkWidget *label = gtk_label_new(_("Output"));
 
694
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
695
    gtk_grid_attach(GTK_GRID(grid), label, 1, 3, 1, 1);
 
696
    gtk_widget_show(label);
 
697
 
 
698
    // Set choices of output devices
 
699
    GtkListStore *outputlist = create_output_list_store();
 
700
    GtkWidget *pulse_output = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputlist));
 
701
    select_active_output_audio_device(pulse_output);
 
702
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), pulse_output);
 
703
    g_signal_connect(G_OBJECT(pulse_output), "changed", G_CALLBACK(select_audio_output_device), NULL);
 
704
 
 
705
    // Set rendering
 
706
    GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
 
707
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(pulse_output), renderer, TRUE);
 
708
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(pulse_output), renderer, "text", 0, NULL);
 
709
    gtk_grid_attach(GTK_GRID(grid), pulse_output, 2, 3, 1, 1);
 
710
    gtk_widget_show(pulse_output);
 
711
 
 
712
    // Device : Input device
 
713
    // Create title label
 
714
    g_debug("Configuration input");
 
715
    label = gtk_label_new(_("Input"));
 
716
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
717
    gtk_grid_attach(GTK_GRID(grid), label, 1, 4, 1, 1);
 
718
    gtk_widget_show(label);
 
719
 
 
720
    // Set choices of output devices
 
721
    GtkListStore *inputlist = create_input_list_store();
 
722
    GtkWidget *pulse_input = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputlist));
 
723
    select_active_input_audio_device(pulse_input);
 
724
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), pulse_input);
 
725
    g_signal_connect(G_OBJECT(pulse_input), "changed", G_CALLBACK(select_audio_input_device), NULL);
 
726
 
 
727
    // Set rendering
 
728
    renderer = gtk_cell_renderer_text_new();
 
729
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(pulse_input), renderer, TRUE);
 
730
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(pulse_input), renderer, "text", 0, NULL);
 
731
    gtk_grid_attach(GTK_GRID(grid), pulse_input, 2, 4, 1, 1);
 
732
    gtk_widget_show(pulse_input);
 
733
 
 
734
    g_debug("Configuration rintgtone");
 
735
    label = gtk_label_new(_("Ringtone"));
 
736
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
737
    gtk_grid_attach(GTK_GRID(grid), label, 1, 5, 1, 1);
 
738
    gtk_widget_show(label);
 
739
    // set choices of ringtone devices
 
740
    GtkListStore *ringtonelist = create_output_list_store();
 
741
    GtkWidget *ringtone = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ringtonelist));
 
742
    select_active_ringtone_audio_device(ringtone);
 
743
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), pulse_output);
 
744
    g_signal_connect(G_OBJECT(ringtone), "changed", G_CALLBACK(select_audio_ringtone_device), NULL);
 
745
 
 
746
    // Set rendering
 
747
    renderer = gtk_cell_renderer_text_new();
 
748
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(ringtone), renderer, TRUE);
 
749
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(ringtone), renderer, "text", 0, NULL);
 
750
    gtk_grid_attach(GTK_GRID(grid), ringtone, 2, 5, 1, 1);
 
751
    gtk_widget_show(ringtone);
 
752
 
 
753
    gtk_widget_show_all(pulse_hbox);
 
754
 
 
755
    return pulse_hbox;
 
756
}
 
757
 
 
758
 
 
759
static void
 
760
select_audio_manager(GtkWidget *alsa_button, SFLPhoneClient *client)
 
761
{
 
762
    if (!must_show_alsa_conf() && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(alsa_button))) {
600
763
        dbus_set_audio_manager(ALSA_API_STR);
 
764
        gtk_container_remove(GTK_CONTAINER(pulse_conf), pulsebox);
 
765
        gtk_widget_hide(pulse_conf);
 
766
 
601
767
        alsabox = alsa_box();
602
768
        gtk_container_add(GTK_CONTAINER(alsa_conf), alsabox);
603
769
        gtk_widget_show(alsa_conf);
604
770
        gtk_widget_set_sensitive(alsa_conf, TRUE);
605
771
        gtk_action_set_sensitive(volumeToggle_, TRUE);
606
 
    } else if (must_show_alsa_conf() && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pulse))) {
 
772
    } else if (must_show_alsa_conf() && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(alsa_button))) {
607
773
        dbus_set_audio_manager(PULSEAUDIO_API_STR);
608
 
        gtk_container_remove(GTK_CONTAINER(alsa_conf) , alsabox);
 
774
        gtk_container_remove(GTK_CONTAINER(alsa_conf), alsabox);
609
775
        gtk_widget_hide(alsa_conf);
610
776
 
 
777
        pulsebox = pulse_box();
 
778
        gtk_container_add(GTK_CONTAINER(pulse_conf), pulsebox);
 
779
        gtk_widget_show(pulse_conf);
 
780
        gtk_widget_set_sensitive(pulse_conf, TRUE);
 
781
        gtk_action_set_sensitive(volumeToggle_, TRUE);
 
782
 
611
783
        if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(volumeToggle_))) {
612
784
            main_window_volume_controls(FALSE);
613
 
            eel_gconf_set_integer(SHOW_VOLUME_CONTROLS, FALSE);
 
785
            g_settings_set_boolean(client->settings, "show-volume-controls", FALSE);
614
786
            gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(volumeToggle_), FALSE);
615
787
        }
616
788
 
617
789
        gtk_action_set_sensitive(volumeToggle_, FALSE);
618
 
    }
619
 
 
620
 
}
621
 
 
622
 
void
 
790
    } else
 
791
        g_warning("Unexpected audio API state");
 
792
}
 
793
 
 
794
static const gchar *reverse_state(const gchar *state)
 
795
{
 
796
    if (g_strcmp0(state, "enabled") == 0)
 
797
        return "disabled";
 
798
    else
 
799
        return "enabled";
 
800
}
 
801
 
 
802
static void
623
803
active_noise_suppress(void)
624
804
{
625
805
    gchar *state = dbus_get_noise_suppress_state();
626
 
 
627
 
    if (g_strcmp0(state, "enabled") == 0)
628
 
        dbus_set_noise_suppress_state("disabled");
629
 
    else
630
 
        dbus_set_noise_suppress_state("enabled");
631
 
 
 
806
    dbus_set_noise_suppress_state(reverse_state(state));
632
807
    g_free(state);
633
808
}
634
809
 
635
 
void
 
810
static void
636
811
active_echo_cancel(void)
637
812
{
638
813
    gchar *state = dbus_get_echo_cancel_state();
639
 
 
640
 
    if (g_strcmp0(state, "enabled") == 0)
641
 
        dbus_set_echo_cancel_state("disabled");
642
 
    else
643
 
        dbus_set_echo_cancel_state("enabled");
644
 
 
 
814
    dbus_set_echo_cancel_state(reverse_state(state));
645
815
    g_free(state);
646
816
}
647
817
 
648
 
void
649
 
echo_tail_length_changed(GtkRange *range, gpointer user_data UNUSED)
650
 
{
651
 
    dbus_set_echo_cancel_tail_length(gtk_range_get_value(range));
652
 
}
653
 
 
654
 
void
655
 
echo_delay_changed(GtkRange *range, gpointer user_data UNUSED)
656
 
{
657
 
    dbus_set_echo_cancel_delay(gtk_range_get_value(range));
658
 
}
659
 
 
660
 
void
 
818
static void
661
819
active_is_always_recording(void)
662
820
{
663
821
    dbus_set_is_always_recording(!dbus_get_is_always_recording());
664
822
}
665
823
 
666
 
GtkWidget* alsa_box()
667
 
{
668
 
    GtkWidget *alsa_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
669
 
    gtk_widget_show(alsa_hbox);
670
 
 
671
 
    GtkWidget *table = gtk_table_new(6, 3, FALSE);
672
 
    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 40);
673
 
    gtk_box_pack_start(GTK_BOX(alsa_hbox) , table , TRUE , TRUE , 1);
674
 
    gtk_widget_show(table);
675
 
 
676
 
    gchar *message = "<small><i>default</i> plugin always uses internal sound card. Select <i>dmix/dsnoop</i> to use an alternate soundcard.</small>";
677
 
    GtkWidget *info_bar = gnome_info_bar(message, GTK_MESSAGE_INFO);
678
 
    gtk_table_attach(GTK_TABLE(table), info_bar, 1, 3, 1, 2, GTK_FILL, GTK_SHRINK, 10, 10);
679
 
 
680
 
    DEBUG("Configuration plugin");
681
 
    GtkWidget *label = gtk_label_new(_("ALSA plugin"));
682
 
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
683
 
    gtk_table_attach(GTK_TABLE(table), label, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
684
 
    gtk_widget_show(label);
685
 
    // Set choices of audio managers
686
 
    pluginlist = gtk_list_store_new(1, G_TYPE_STRING);
687
 
    preferences_dialog_fill_audio_plugin_list();
688
 
    plugin = gtk_combo_box_new_with_model(GTK_TREE_MODEL(pluginlist));
689
 
    select_active_output_audio_plugin();
690
 
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), plugin);
691
 
    g_signal_connect(G_OBJECT(plugin), "changed", G_CALLBACK(select_output_audio_plugin), plugin);
692
 
 
693
 
    // Set rendering
694
 
    GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
695
 
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(plugin), renderer, TRUE);
696
 
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(plugin), renderer, "text", 0, NULL);
697
 
    gtk_table_attach(GTK_TABLE(table), plugin, 2, 3, 2, 3, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
698
 
    gtk_widget_show(plugin);
699
 
 
700
 
    // Device : Output device
701
 
    // Create title label
702
 
    DEBUG("Configuration output");
703
 
    label = gtk_label_new(_("Output"));
704
 
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
705
 
    gtk_table_attach(GTK_TABLE(table), label, 1, 2, 3, 4, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
706
 
    gtk_widget_show(label);
707
 
    // Set choices of output devices
708
 
    outputlist = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
709
 
    preferences_dialog_fill_output_audio_device_list();
710
 
    output = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputlist));
711
 
    select_active_output_audio_device();
712
 
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), output);
713
 
    g_signal_connect(G_OBJECT(output), "changed", G_CALLBACK(select_audio_output_device), output);
714
 
 
715
 
    // Set rendering
716
 
    renderer = gtk_cell_renderer_text_new();
717
 
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(output), renderer, TRUE);
718
 
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(output), renderer, "text", 0, NULL);
719
 
    gtk_table_attach(GTK_TABLE(table), output, 2, 3, 3, 4, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
720
 
    gtk_widget_show(output);
721
 
 
722
 
    // Device : Input device
723
 
    // Create title label
724
 
    DEBUG("Configuration input");
725
 
    label = gtk_label_new(_("Input"));
726
 
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
727
 
    gtk_table_attach(GTK_TABLE(table), label, 1, 2, 4, 5, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
728
 
    gtk_widget_show(label);
729
 
 
730
 
    // Set choices of output devices
731
 
    inputlist = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
732
 
    preferences_dialog_fill_input_audio_device_list();
733
 
    input = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputlist));
734
 
    select_active_input_audio_device();
735
 
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), input);
736
 
    g_signal_connect(G_OBJECT(input), "changed", G_CALLBACK(select_audio_input_device), input);
737
 
 
738
 
    // Set rendering
739
 
    renderer = gtk_cell_renderer_text_new();
740
 
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(input), renderer, TRUE);
741
 
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(input), renderer, "text", 0, NULL);
742
 
    gtk_table_attach(GTK_TABLE(table), input, 2, 3, 4, 5, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
743
 
    gtk_widget_show(input);
744
 
 
745
 
    DEBUG("Configuration rintgtone");
746
 
    label = gtk_label_new(_("Ringtone"));
747
 
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
748
 
    gtk_table_attach(GTK_TABLE(table), label, 1, 2, 5, 6, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
749
 
    gtk_widget_show(label);
750
 
    // set choices of ringtone devices
751
 
    ringtonelist = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
752
 
    preferences_dialog_fill_ringtone_audio_device_list();
753
 
    ringtone = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ringtonelist));
754
 
    select_active_ringtone_audio_device();
755
 
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), output);
756
 
    g_signal_connect(G_OBJECT(ringtone), "changed", G_CALLBACK(select_audio_ringtone_device), output);
757
 
 
758
 
    // Set rendering
759
 
    renderer = gtk_cell_renderer_text_new();
760
 
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(ringtone), renderer, TRUE);
761
 
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(ringtone), renderer, "text", 0, NULL);
762
 
    gtk_table_attach(GTK_TABLE(table), ringtone, 2, 3, 5, 6, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
763
 
    gtk_widget_show(ringtone);
764
 
 
765
 
    gtk_widget_show_all(alsa_hbox);
766
 
 
767
 
    // Update the combo box
768
 
    update_device_widget(dbus_get_current_audio_output_plugin());
769
 
    return alsa_hbox;
770
 
}
771
 
 
772
 
static void record_path_changed(GtkFileChooser *chooser , GtkLabel *label UNUSED)
773
 
{
774
 
    gchar* path;
775
 
    path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
776
 
    dbus_set_record_path(path);
777
 
}
778
 
 
779
 
GtkWidget* create_audio_configuration()
 
824
static void restore_recording_path(GtkFileChooser *chooser)
 
825
{
 
826
    gchar *recording_path = dbus_get_record_path();
 
827
    if (recording_path && strlen(recording_path) > 0)
 
828
        gtk_file_chooser_set_current_folder(chooser, recording_path);
 
829
    g_free(recording_path);
 
830
}
 
831
 
 
832
static void record_path_changed(GtkFileChooser *chooser, G_GNUC_UNUSED gpointer data)
 
833
{
 
834
    gchar* path = gtk_file_chooser_get_filename(chooser);
 
835
    if (!g_access(path, W_OK)) {
 
836
        dbus_set_record_path(path);
 
837
    } else {
 
838
        g_warning("Directory %s is not writable", path);
 
839
        restore_recording_path(chooser);
 
840
    }
 
841
    g_free(path);
 
842
}
 
843
 
 
844
GtkWidget* create_audio_configuration(SFLPhoneClient *client)
780
845
{
781
846
    /* Main widget */
782
847
    GtkWidget *audio_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
783
848
    gtk_container_set_border_width(GTK_CONTAINER(audio_vbox), 10);
784
849
 
785
850
    GtkWidget *frame;
786
 
    GtkWidget *table;
787
 
    gnome_main_section_new_with_table(_("Sound Manager"), &frame, &table, 1, 4);
 
851
    GtkWidget *grid;
 
852
    gnome_main_section_new_with_grid(_("Sound Manager"), &frame, &grid);
788
853
    gtk_box_pack_start(GTK_BOX(audio_vbox), frame, FALSE, FALSE, 0);
789
854
 
790
855
    gchar *audio_manager = dbus_get_audio_manager();
791
 
    gboolean pulse_audio = FALSE;
792
 
 
793
 
    if (g_strcmp0(audio_manager, PULSEAUDIO_API_STR) == 0)
794
 
        pulse_audio = TRUE;
795
 
 
 
856
    const gboolean using_pulse = g_strcmp0(audio_manager, PULSEAUDIO_API_STR) == 0;
796
857
    g_free(audio_manager);
797
858
 
798
 
    pulse = gtk_radio_button_new_with_mnemonic(NULL , _("_Pulseaudio"));
799
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pulse), pulse_audio);
800
 
    gtk_table_attach(GTK_TABLE(table), pulse, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
801
 
 
802
 
    GtkWidget *alsa = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(pulse), _("_ALSA"));
803
 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(alsa), !pulse_audio);
804
 
    g_signal_connect(G_OBJECT(alsa), "clicked", G_CALLBACK(select_audio_manager), NULL);
805
 
    gtk_table_attach(GTK_TABLE(table), alsa, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
859
    GtkWidget *pulse_button = gtk_radio_button_new_with_mnemonic(NULL , _("_Pulseaudio"));
 
860
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pulse_button), using_pulse);
 
861
    gtk_grid_attach(GTK_GRID(grid), pulse_button, 0, 0, 1, 1);
 
862
 
 
863
    // Box for the Pulse configuration
 
864
    pulse_conf = gnome_main_section_new(_("Pulseaudio settings"));
 
865
    gtk_box_pack_start(GTK_BOX(audio_vbox), pulse_conf, FALSE, FALSE, 0);
 
866
    gtk_widget_show(pulse_conf);
 
867
 
 
868
    GtkWidget *alsa_button = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(pulse_button), _("_ALSA"));
 
869
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(alsa_button), !using_pulse);
 
870
    g_signal_connect(G_OBJECT(alsa_button), "clicked", G_CALLBACK(select_audio_manager), client);
 
871
    gtk_grid_attach(GTK_GRID(grid), alsa_button, 1, 0, 1, 1);
806
872
 
807
873
    // Box for the ALSA configuration
808
874
    alsa_conf = gnome_main_section_new(_("ALSA settings"));
812
878
    if (must_show_alsa_conf()) {
813
879
        // Box for the ALSA configuration
814
880
        alsabox = alsa_box();
815
 
        gtk_container_add(GTK_CONTAINER(alsa_conf) , alsabox);
 
881
        gtk_container_add(GTK_CONTAINER(alsa_conf), alsabox);
816
882
        gtk_widget_hide(alsa_conf);
 
883
    } else {
 
884
        pulsebox = pulse_box();
 
885
        gtk_container_add(GTK_CONTAINER(pulse_conf), pulsebox);
 
886
        gtk_widget_hide(pulse_conf);
817
887
    }
818
888
 
819
 
    gnome_main_section_new_with_table(_("Recordings"), &frame, &table, 2, 3);
 
889
    gnome_main_section_new_with_grid(_("Recordings"), &frame, &grid);
820
890
    gtk_box_pack_start(GTK_BOX(audio_vbox), frame, FALSE, FALSE, 0);
821
891
 
822
892
    // label
823
893
    GtkWidget *label = gtk_label_new(_("Destination folder"));
824
 
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
 
894
    gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
825
895
 
826
896
    // folder chooser button
827
 
    GtkWidget *folderChooser = gtk_file_chooser_button_new(_("Select a folder"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
 
897
    GtkWidget *folderChooser = gtk_file_chooser_button_new(_("Select a folder"),
 
898
                                                           GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
828
899
    /* Get the path where to save audio files */
829
 
    gchar *recordingPath = dbus_get_record_path();
830
 
    DEBUG("Load recording path %s", recordingPath);
831
 
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(folderChooser), recordingPath);
832
 
    g_free(recordingPath);
 
900
    restore_recording_path(GTK_FILE_CHOOSER(folderChooser));
833
901
 
834
 
    g_signal_connect(G_OBJECT(folderChooser) , "selection_changed" , G_CALLBACK(record_path_changed) , NULL);
835
 
    gtk_table_attach(GTK_TABLE(table), folderChooser, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
 
902
    g_signal_connect(G_OBJECT(folderChooser) , "selection-changed", G_CALLBACK(record_path_changed),
 
903
                     NULL);
 
904
    gtk_grid_attach(GTK_GRID(grid), folderChooser, 1, 0, 1, 1);
836
905
 
837
906
    // isAlwaysRecording functionality checkbox
838
907
    gboolean isAlwaysRecording = dbus_get_is_always_recording();
839
908
    GtkWidget *enableIsAlwaysRecording = gtk_check_button_new_with_mnemonic(_("_Always recording"));
840
909
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enableIsAlwaysRecording), isAlwaysRecording);
841
910
    g_signal_connect(G_OBJECT(enableIsAlwaysRecording), "clicked", active_is_always_recording, NULL);
842
 
    gtk_table_attach(GTK_TABLE(table), enableIsAlwaysRecording, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5);
 
911
    gtk_grid_attach(GTK_GRID(grid), enableIsAlwaysRecording, 0, 1, 1, 1);
843
912
    gtk_widget_show(GTK_WIDGET(enableIsAlwaysRecording));
844
913
 
845
914
    // Box for the voice enhancement configuration
846
 
    gnome_main_section_new_with_table(_("Voice enhancement settings"), &frame, &table, 2, 1);
 
915
    gnome_main_section_new_with_grid(_("Voice enhancement settings"), &frame, &grid);
847
916
    gtk_box_pack_start(GTK_BOX(audio_vbox), frame, FALSE, FALSE, 0);
848
917
 
849
918
    GtkWidget *enableNoiseReduction = gtk_check_button_new_with_mnemonic(_("_Noise Reduction"));
858
927
    state = NULL;
859
928
 
860
929
    g_signal_connect(G_OBJECT(enableNoiseReduction), "clicked", active_noise_suppress, NULL);
861
 
    gtk_table_attach(GTK_TABLE(table), enableNoiseReduction, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
930
    gtk_grid_attach(GTK_GRID(grid), enableNoiseReduction, 0, 1, 1, 1);
862
931
 
863
932
    GtkWidget *enableEchoCancel = gtk_check_button_new_with_mnemonic(_("_Echo Cancellation"));
864
933
    state = dbus_get_echo_cancel_state();
871
940
    g_free(state);
872
941
 
873
942
    g_signal_connect(G_OBJECT(enableEchoCancel), "clicked", active_echo_cancel, NULL);
874
 
    gtk_table_attach(GTK_TABLE(table), enableEchoCancel, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
943
    gtk_grid_attach(GTK_GRID(grid), enableEchoCancel, 0, 2, 1, 1);
875
944
 
876
945
    gtk_widget_show_all(audio_vbox);
877
946
 
878
 
    if (!pulse_audio)
 
947
    if (!using_pulse)
879
948
        gtk_widget_show(alsa_conf);
880
949
    else
881
950
        gtk_widget_hide(alsa_conf);
891
960
    g_free(api);
892
961
    return ret == 0;
893
962
}
 
963
 
 
964
gboolean
 
965
must_show_volume(SFLPhoneClient *client)
 
966
{
 
967
    return g_settings_get_boolean(client->settings, "show-volume-controls") && must_show_alsa_conf();
 
968
}