source: src-qt4/pc-soundconfig/snddialog.cpp @ 73f107f

releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 73f107f was 73f107f, checked in by Kris Moore <kris@…>, 8 months ago

Add support for setting the default pulseaudio sink when we change default audio
devices

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include <QProcess>
13#include "snddialog.h"
14#include <pcbsd-utils.h>
15
16
17void sndDialog::programInit()
18{
19  // Connect our pushbuttons
20  connect(pushTest, SIGNAL( clicked() ), this, SLOT( slotDiagnostic() ) );
21  connect(pushClose, SIGNAL( clicked() ), this, SLOT( slotClose() ) );
22  connect(pushApply, SIGNAL( clicked() ), this, SLOT( slotSave() ) );
23  connect(comboSound, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotEnableApply() ) );
24
25  refreshDevices();
26}
27
28void sndDialog::slotEnableApply()
29{
30  pushApply->setEnabled(true);
31}
32
33void sndDialog::refreshDevices()
34{
35  defaultUnit = -1 ;
36  comboSound->clear();
37
38  // List the sound devices
39  QString tmp, snd;
40  QProcess d;
41  d.start(QString("cat"), QStringList() << "/dev/sndstat");
42  while(d.state() == QProcess::Starting || d.state() == QProcess::Running) {
43     d.waitForFinished(200);
44     QCoreApplication::processEvents();
45  }
46   
47  int i = 0;
48  while (d.canReadLine()) {
49    tmp = d.readLine().simplified();
50    if ( tmp.indexOf("pcm") == 0 ) {
51      comboSound->addItem(tmp);
52      if ( tmp.indexOf("default") != -1 ) {
53        defaultUnit=i;
54        comboSound->setCurrentIndex(i);
55      }
56      i++;
57    }
58  } 
59
60  if ( defaultUnit == -1 ) {
61     labelDesc->setText(tr("No sound devices detected!"));
62     pushTest->setEnabled(false);
63     pushApply->setEnabled(false);
64     comboSound->setEnabled(false);
65  }
66     
67  pushApply->setEnabled(false);
68}
69
70// Close the dialog and exit
71void sndDialog::slotClose()
72{
73  close();
74}
75
76void sndDialog::slotSave()
77{
78  QString tmp;
79  tmp.setNum(comboSound->currentIndex());
80  system("sysctl hw.snd.default_unit=" + tmp.toLatin1());
81
82  // Try to set the default pulseaudio sink as well
83  QString username = QString::fromLocal8Bit(getenv("LOGNAME"));
84  system("su " + username.toLatin1() + " -c \"pactl set-default-sink " + tmp.toLatin1() + "\"");
85
86  pcbsd::Utils::setConfFileValue( "/etc/sysctl.conf", "hw.snd.default_unit=", "hw.snd.default_unit=" + tmp );
87  refreshDevices();
88}
89
90// Play some sound for the user to detect this new device
91void sndDialog::slotDiagnostic()
92{
93  QString tmp;
94  tmp.setNum(comboSound->currentIndex());
95
96  // Change the sysctl, and play a sound
97  system("sysctl hw.snd.default_unit=" + tmp.toLatin1());
98  system("mixer vol 100:100");
99  system("mixer pcm 100:100");
100  system("mixer speaker 100:100");
101
102  QProcess d;
103  d.start(QString("mplayer"), QStringList() << "/usr/local/share/sounds/testsound.ogg");
104  while(d.state() == QProcess::Starting || d.state() == QProcess::Running) {
105     d.waitForFinished(200);
106     QCoreApplication::processEvents();
107  }
108
109  tmp.setNum(defaultUnit);
110  system("sysctl hw.snd.default_unit=" + tmp.toLatin1());
111}
Note: See TracBrowser for help on using the repository browser.