source: src-qt4/pc-soundconfig/snddialog.cpp @ 0cfe72f

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 0cfe72f was 0cfe72f, checked in by Kris Moore <kris@…>, 16 months ago

Add all the changes for related using of split pcbsd-utils libs

  • Property mode set to 100644
File size: 3.0 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  pcbsd::Utils::setConfFileValue( "/etc/sysctl.conf", "hw.snd.default_unit=", "hw.snd.default_unit=" + tmp );
82  refreshDevices();
83}
84
85// Play some sound for the user to detect this new device
86void sndDialog::slotDiagnostic()
87{
88  QString tmp;
89  tmp.setNum(comboSound->currentIndex());
90
91  // Change the sysctl, and play a sound
92  system("sysctl hw.snd.default_unit=" + tmp.toLatin1());
93  system("mixer vol 100:100");
94  system("mixer pcm 100:100");
95  system("mixer speaker 100:100");
96
97  QProcess d;
98  d.start(QString("mplayer"), QStringList() << "/usr/local/share/sounds/testsound.ogg");
99  while(d.state() == QProcess::Starting || d.state() == QProcess::Running) {
100     d.waitForFinished(200);
101     QCoreApplication::processEvents();
102  }
103
104  tmp.setNum(defaultUnit);
105  system("sysctl hw.snd.default_unit=" + tmp.toLatin1());
106}
Note: See TracBrowser for help on using the repository browser.