1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
/***
This file is part of pavucontrol.
Copyright 2006-2008 Lennart Poettering
Copyright 2008 Sjoerd Simons <sjoerd@luon.net>
pavucontrol is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
pavucontrol is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with pavucontrol. If not, see <https://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define PACKAGE_VERSION "0.1"
#include <pulse/pulseaudio.h>
#include <pulse/glib-mainloop.h>
#include <pulse/ext-stream-restore.h>
#include <pulse/ext-device-manager.h>
// #include <canberra-gtk.h>
#include "pavucontrol.h"
#include "minimalstreamwidget.h"
#include "channel.h"
#include "streamwidget.h"
#include "cardwidget.h"
#include "sinkwidget.h"
#include "sourcewidget.h"
#include "sinkinputwidget.h"
#include "sourceoutputwidget.h"
#include "rolewidget.h"
#include "mainwindow.h"
#include <QMessageBox>
#include <QApplication>
#include <QLocale>
#include <QLibraryInfo>
#include <QTranslator>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QString>
static pa_context* context = nullptr;
static pa_mainloop_api* api = nullptr;
static int n_outstanding = 0;
static int default_tab = 0;
static bool retry = false;
static int reconnect_timeout = 1;
void show_error(const char *txt) {
char buf[256];
snprintf(buf, sizeof(buf), "%s: %s", txt, pa_strerror(pa_context_errno(context)));
QMessageBox::critical(nullptr, QObject::tr("Error"), QString::fromUtf8(buf));
qApp->quit();
}
static void dec_outstanding(MainWindow *w) {
if (n_outstanding <= 0)
return;
if (--n_outstanding <= 0) {
// w->get_window()->set_cursor();
w->setConnectionState(true);
}
}
void card_cb(pa_context *, const pa_card_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Card callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
w->updateCard(*i);
}
#if HAVE_EXT_DEVICE_RESTORE_API
static void ext_device_restore_subscribe_cb(pa_context *c, pa_device_type_t type, uint32_t idx, void *userdata);
#endif
void sink_cb(pa_context *c, const pa_sink_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Sink callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
#if HAVE_EXT_DEVICE_RESTORE_API
if (w->updateSink(*i))
ext_device_restore_subscribe_cb(c, PA_DEVICE_TYPE_SINK, i->index, w);
#else
w->updateSink(*i);
#endif
}
void source_cb(pa_context *, const pa_source_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Source callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
w->updateSource(*i);
}
void sink_input_cb(pa_context *, const pa_sink_input_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Sink input callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
w->updateSinkInput(*i);
}
void source_output_cb(pa_context *, const pa_source_output_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Source output callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
if (n_outstanding > 0) {
/* At this point all notebook pages have been populated, so
* let's open one that isn't empty */
if (default_tab != -1) {
if (default_tab < 1 || default_tab > w->notebook->count()) {
if (!w->sinkInputWidgets.empty())
w->notebook->setCurrentIndex(0);
else if (!w->sourceOutputWidgets.empty())
w->notebook->setCurrentIndex(1);
else if (!w->sourceWidgets.empty() && w->sinkWidgets.empty())
w->notebook->setCurrentIndex(3);
else
w->notebook->setCurrentIndex(2);
} else {
w->notebook->setCurrentIndex(default_tab - 1);
}
default_tab = -1;
}
}
dec_outstanding(w);
return;
}
w->updateSourceOutput(*i);
}
void client_cb(pa_context *, const pa_client_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Client callback failure").toUtf8().constData());
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
w->updateClient(*i);
}
void server_info_cb(pa_context *, const pa_server_info *i, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (!i) {
show_error(QObject::tr("Server info callback failure").toUtf8().constData());
return;
}
w->updateServer(*i);
dec_outstanding(w);
}
void ext_stream_restore_read_cb(
pa_context *,
const pa_ext_stream_restore_info *i,
int eol,
void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
dec_outstanding(w);
g_debug(QObject::tr("Failed to initialize stream_restore extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
w->deleteEventRoleWidget();
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
w->updateRole(*i);
}
static void ext_stream_restore_subscribe_cb(pa_context *c, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
pa_operation *o;
if (!(o = pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, w))) {
show_error(QObject::tr("pa_ext_stream_restore_read() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
#if HAVE_EXT_DEVICE_RESTORE_API
void ext_device_restore_read_cb(
pa_context *,
const pa_ext_device_restore_info *i,
int eol,
void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
dec_outstanding(w);
g_debug(QObject::tr("Failed to initialize device restore extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
return;
}
if (eol > 0) {
dec_outstanding(w);
return;
}
/* Do something with a widget when this part is written */
w->updateDeviceInfo(*i);
}
static void ext_device_restore_subscribe_cb(pa_context *c, pa_device_type_t type, uint32_t idx, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
pa_operation *o;
if (type != PA_DEVICE_TYPE_SINK)
return;
if (!(o = pa_ext_device_restore_read_formats(c, type, idx, ext_device_restore_read_cb, w))) {
show_error(QObject::tr("pa_ext_device_restore_read_sink_formats() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
#endif
void ext_device_manager_read_cb(
pa_context *,
const pa_ext_device_manager_info *,
int eol,
void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) {
dec_outstanding(w);
g_debug(QObject::tr("Failed to initialize device manager extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
return;
}
w->canRenameDevices = true;
if (eol > 0) {
dec_outstanding(w);
return;
}
/* Do something with a widget when this part is written */
}
static void ext_device_manager_subscribe_cb(pa_context *c, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
pa_operation *o;
if (!(o = pa_ext_device_manager_read(c, ext_device_manager_read_cb, w))) {
show_error(QObject::tr("pa_ext_device_manager_read() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeSink(index);
else {
pa_operation *o;
if (!(o = pa_context_get_sink_info_by_index(c, index, sink_cb, w))) {
show_error(QObject::tr("pa_context_get_sink_info_by_index() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_SOURCE:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeSource(index);
else {
pa_operation *o;
if (!(o = pa_context_get_source_info_by_index(c, index, source_cb, w))) {
show_error(QObject::tr("pa_context_get_source_info_by_index() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeSinkInput(index);
else {
pa_operation *o;
if (!(o = pa_context_get_sink_input_info(c, index, sink_input_cb, w))) {
show_error(QObject::tr("pa_context_get_sink_input_info() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeSourceOutput(index);
else {
pa_operation *o;
if (!(o = pa_context_get_source_output_info(c, index, source_output_cb, w))) {
show_error(QObject::tr("pa_context_get_sink_input_info() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_CLIENT:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeClient(index);
else {
pa_operation *o;
if (!(o = pa_context_get_client_info(c, index, client_cb, w))) {
show_error(QObject::tr("pa_context_get_client_info() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_SERVER: {
pa_operation *o;
if (!(o = pa_context_get_server_info(c, server_info_cb, w))) {
show_error(QObject::tr("pa_context_get_server_info() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
case PA_SUBSCRIPTION_EVENT_CARD:
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
w->removeCard(index);
else {
pa_operation *o;
if (!(o = pa_context_get_card_info_by_index(c, index, card_cb, w))) {
show_error(QObject::tr("pa_context_get_card_info_by_index() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
}
break;
}
}
/* Forward Declaration */
gboolean connect_to_pulse(gpointer userdata);
void context_state_callback(pa_context *c, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
g_assert(c);
switch (pa_context_get_state(c)) {
case PA_CONTEXT_UNCONNECTED:
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME:
break;
case PA_CONTEXT_READY: {
pa_operation *o;
reconnect_timeout = 1;
/* Create event widget immediately so it's first in the list */
w->createEventRoleWidget();
pa_context_set_subscribe_callback(c, subscribe_cb, w);
if (!(o = pa_context_subscribe(c, (pa_subscription_mask_t)
(PA_SUBSCRIPTION_MASK_SINK|
PA_SUBSCRIPTION_MASK_SOURCE|
PA_SUBSCRIPTION_MASK_SINK_INPUT|
PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
PA_SUBSCRIPTION_MASK_CLIENT|
PA_SUBSCRIPTION_MASK_SERVER|
PA_SUBSCRIPTION_MASK_CARD), nullptr, nullptr))) {
show_error(QObject::tr("pa_context_subscribe() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
/* Keep track of the outstanding callbacks for UI tweaks */
n_outstanding = 0;
if (!(o = pa_context_get_server_info(c, server_info_cb, w))) {
show_error(QObject::tr("pa_context_get_server_info() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_client_info_list(c, client_cb, w))) {
show_error(QObject::tr("pa_context_client_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_card_info_list(c, card_cb, w))) {
show_error(QObject::tr("pa_context_get_card_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_sink_info_list(c, sink_cb, w))) {
show_error(QObject::tr("pa_context_get_sink_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_source_info_list(c, source_cb, w))) {
show_error(QObject::tr("pa_context_get_source_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_sink_input_info_list(c, sink_input_cb, w))) {
show_error(QObject::tr("pa_context_get_sink_input_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
if (!(o = pa_context_get_source_output_info_list(c, source_output_cb, w))) {
show_error(QObject::tr("pa_context_get_source_output_info_list() failed").toUtf8().constData());
return;
}
pa_operation_unref(o);
n_outstanding++;
/* These calls are not always supported */
if ((o = pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, w))) {
pa_operation_unref(o);
n_outstanding++;
pa_ext_stream_restore_set_subscribe_cb(c, ext_stream_restore_subscribe_cb, w);
if ((o = pa_ext_stream_restore_subscribe(c, 1, nullptr, nullptr)))
pa_operation_unref(o);
} else
g_debug(QObject::tr("Failed to initialize stream_restore extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
#if HAVE_EXT_DEVICE_RESTORE_API
/* TODO Change this to just the test function */
if ((o = pa_ext_device_restore_read_formats_all(c, ext_device_restore_read_cb, w))) {
pa_operation_unref(o);
n_outstanding++;
pa_ext_device_restore_set_subscribe_cb(c, ext_device_restore_subscribe_cb, w);
if ((o = pa_ext_device_restore_subscribe(c, 1, nullptr, nullptr)))
pa_operation_unref(o);
} else
g_debug(QObject::tr("Failed to initialize device restore extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
#endif
if ((o = pa_ext_device_manager_read(c, ext_device_manager_read_cb, w))) {
pa_operation_unref(o);
n_outstanding++;
pa_ext_device_manager_set_subscribe_cb(c, ext_device_manager_subscribe_cb, w);
if ((o = pa_ext_device_manager_subscribe(c, 1, nullptr, nullptr)))
pa_operation_unref(o);
} else
g_debug(QObject::tr("Failed to initialize device manager extension: %s").toUtf8().constData(), pa_strerror(pa_context_errno(context)));
break;
}
case PA_CONTEXT_FAILED:
w->setConnectionState(false);
w->removeAllWidgets();
w->updateDeviceVisibility();
pa_context_unref(context);
context = nullptr;
if (reconnect_timeout > 0) {
g_debug("%s", QObject::tr("Connection failed, attempting reconnect").toUtf8().constData());
g_timeout_add_seconds(reconnect_timeout, connect_to_pulse, w);
}
return;
case PA_CONTEXT_TERMINATED:
default:
qApp->quit();
return;
}
}
pa_context* get_context(void) {
return context;
}
gboolean connect_to_pulse(gpointer userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata);
if (context)
return false;
pa_proplist *proplist = pa_proplist_new();
pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, QObject::tr("PulseAudio Volume Control").toUtf8().constData());
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "org.PulseAudio.pavucontrol");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "audio-card");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION);
context = pa_context_new_with_proplist(api, nullptr, proplist);
g_assert(context);
pa_proplist_free(proplist);
pa_context_set_state_callback(context, context_state_callback, w);
w->setConnectingMessage();
if (pa_context_connect(context, nullptr, PA_CONTEXT_NOFAIL, nullptr) < 0) {
if (pa_context_errno(context) == PA_ERR_INVALID) {
w->setConnectingMessage(QObject::tr("Connection to PulseAudio failed. Automatic retry in 5s\n\n"
"In this case this is likely because PULSE_SERVER in the Environment/X11 Root Window Properties\n"
"or default-server in client.conf is misconfigured.\n"
"This situation can also arrise when PulseAudio crashed and left stale details in the X11 Root Window.\n"
"If this is the case, then PulseAudio should autospawn again, or if this is not configured you should\n"
"run start-pulseaudio-x11 manually.").toUtf8().constData());
reconnect_timeout = 5;
}
else {
if(!retry) {
reconnect_timeout = -1;
qApp->quit();
} else {
g_debug("%s", QObject::tr("Connection failed, attempting reconnect").toUtf8().constData());
reconnect_timeout = 5;
g_timeout_add_seconds(reconnect_timeout, connect_to_pulse, userdata);
}
}
}
return false;
}
int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
QApplication app(argc, argv);
app.setOrganizationName(QStringLiteral("pavucontrol-qt"));
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
QString locale = QLocale::system().name();
QTranslator qtTranslator;
if(qtTranslator.load(QStringLiteral("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
qApp->installTranslator(&qtTranslator);
QTranslator appTranslator;
if(appTranslator.load(QStringLiteral("pavucontrol-qt_") + locale, QStringLiteral(PAVUCONTROL_QT_DATA_DIR) + QStringLiteral("/translations")))
qApp->installTranslator(&appTranslator);
QCommandLineParser parser;
parser.setApplicationDescription(QObject::tr("PulseAudio Volume Control"));
parser.addHelpOption();
const QString VERINFO = QStringLiteral(PAVUCONTROLQT_VERSION
"\nQt " QT_VERSION_STR);
app.setApplicationVersion(VERINFO);
parser.addVersionOption();
QCommandLineOption tabOption(QStringList() << QStringLiteral("tab") << QStringLiteral("t"), QObject::tr("Select a specific tab on load."), QStringLiteral("tab"));
parser.addOption(tabOption);
QCommandLineOption retryOption(QStringList() << QStringLiteral("retry") << QStringLiteral("r"), QObject::tr("Retry forever if pa quits (every 5 seconds)."));
parser.addOption(retryOption);
QCommandLineOption maximizeOption(QStringList() << QStringLiteral("maximize") << QStringLiteral("m"), QObject::tr("Maximize the window."));
parser.addOption(maximizeOption);
parser.process(app);
default_tab = parser.value(tabOption).toInt();
retry = parser.isSet(retryOption);
// ca_context_set_driver(ca_gtk_context_get(), "pulse");
MainWindow* mainWindow = new MainWindow();
if(parser.isSet(maximizeOption))
mainWindow->showMaximized();
pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default());
g_assert(m);
api = pa_glib_mainloop_get_api(m);
g_assert(api);
connect_to_pulse(mainWindow);
if (reconnect_timeout >= 0) {
mainWindow->show();
app.exec();
}
if (reconnect_timeout < 0)
show_error(QObject::tr("Fatal Error: Unable to connect to PulseAudio").toUtf8().constData());
delete mainWindow;
if (context)
pa_context_unref(context);
pa_glib_mainloop_free(m);
return 0;
}
|