examples/multimedia/audiodevices/audiodevices.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/examples/multimedia/audiodevices/audiodevices.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/examples/multimedia/audiodevices/audiodevices.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -40,45 +40,33 @@
 ****************************************************************************/
 
 
-#include <QDebug>
 #include <QAudioDeviceInfo>
 
 #include "audiodevices.h"
 
-AudioDevicesBase::AudioDevicesBase( QMainWindow *parent, Qt::WFlags f )
+AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f)
+    : QMainWindow(parent, f)
 {
-    Q_UNUSED(parent)
-    Q_UNUSED(f)
-    setupUi( this );
+    setupUi(this);
 }
 
 AudioDevicesBase::~AudioDevicesBase() {}
 
 
-AudioTest::AudioTest( QMainWindow *parent, Qt::WFlags f )
-    : AudioDevicesBase( parent, f )
+AudioTest::AudioTest(QWidget *parent, Qt::WFlags f)
+    : AudioDevicesBase(parent, f)
 {
-    nearestFreq->setDisabled(true);
-    nearestChannel->setDisabled(true);
-    nearestCodec->setDisabled(true);
-    nearestSampleSize->setDisabled(true);
-    nearestSampleType->setDisabled(true);
-    nearestEndian->setDisabled(true);
-    logOutput->setDisabled(true);
-
     mode = QAudio::AudioOutput;
-    modeBox->addItem("Input");
-    modeBox->addItem("Output");
 
-    connect(testButton,SIGNAL(clicked()),SLOT(test()));
-    connect(modeBox,SIGNAL(activated(int)),SLOT(modeChanged(int)));
-    connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
-    connect(frequencyBox,SIGNAL(activated(int)),SLOT(freqChanged(int)));
-    connect(channelsBox,SIGNAL(activated(int)),SLOT(channelChanged(int)));
-    connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
-    connect(sampleSizesBox,SIGNAL(activated(int)),SLOT(sampleSizeChanged(int)));
-    connect(sampleTypesBox,SIGNAL(activated(int)),SLOT(sampleTypeChanged(int)));
-    connect(endianBox,SIGNAL(activated(int)),SLOT(endianChanged(int)));
+    connect(testButton, SIGNAL(clicked()), SLOT(test()));
+    connect(modeBox, SIGNAL(activated(int)), SLOT(modeChanged(int)));
+    connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
+    connect(frequencyBox, SIGNAL(activated(int)), SLOT(freqChanged(int)));
+    connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int)));
+    connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int)));
+    connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int)));
+    connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int)));
+    connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int)));
 
     modeBox->setCurrentIndex(0);
     modeChanged(0);
@@ -98,7 +86,7 @@
 
     if (!deviceInfo.isNull()) {
         if (deviceInfo.isFormatSupported(settings)) {
-            logOutput->append("Success");
+            logOutput->append(tr("Success"));
             nearestFreq->setText("");
             nearestChannel->setText("");
             nearestCodec->setText("");
@@ -136,19 +124,19 @@
         }
     }
     else
-        logOutput->append("No Device");
+        logOutput->append(tr("No Device"));
 }
 
 void AudioTest::modeChanged(int idx)
 {
     // mode has changed
-    if(idx == 0)
-        mode=QAudio::AudioInput;
+    if (idx == 0)
+        mode = QAudio::AudioInput;
     else
-        mode=QAudio::AudioOutput;
+        mode = QAudio::AudioOutput;
 
     deviceBox->clear();
-    foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(mode))
+    foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode))
         deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo));
 }
 
@@ -162,37 +150,37 @@
 
     frequencyBox->clear();
     QList<int> freqz = deviceInfo.supportedFrequencies();
-    for(int i = 0; i < freqz.size(); ++i)
+    for (int i = 0; i < freqz.size(); ++i)
         frequencyBox->addItem(QString("%1").arg(freqz.at(i)));
-    if(freqz.size())
+    if (freqz.size())
         settings.setFrequency(freqz.at(0));
 
     channelsBox->clear();
     QList<int> chz = deviceInfo.supportedChannels();
-    for(int i = 0; i < chz.size(); ++i)
+    for (int i = 0; i < chz.size(); ++i)
         channelsBox->addItem(QString("%1").arg(chz.at(i)));
-    if(chz.size())
+    if (chz.size())
         settings.setChannels(chz.at(0));
 
     codecsBox->clear();
     QStringList codecz = deviceInfo.supportedCodecs();
-    for(int i = 0; i < codecz.size(); ++i)
+    for (int i = 0; i < codecz.size(); ++i)
         codecsBox->addItem(QString("%1").arg(codecz.at(i)));
-    if(codecz.size())
+    if (codecz.size())
         settings.setCodec(codecz.at(0));
     // Add false to create failed condition!
     codecsBox->addItem("audio/test");
 
     sampleSizesBox->clear();
     QList<int> sampleSizez = deviceInfo.supportedSampleSizes();
-    for(int i = 0; i < sampleSizez.size(); ++i)
+    for (int i = 0; i < sampleSizez.size(); ++i)
         sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i)));
-    if(sampleSizez.size())
+    if (sampleSizez.size())
         settings.setSampleSize(sampleSizez.at(0));
 
     sampleTypesBox->clear();
     QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes();
-    for(int i = 0; i < sampleTypez.size(); ++i) {
+    for (int i = 0; i < sampleTypez.size(); ++i) {
         switch(sampleTypez.at(i)) {
             case QAudioFormat::SignedInt:
                 sampleTypesBox->addItem("SignedInt");
@@ -206,14 +194,14 @@
             case QAudioFormat::Unknown:
                 sampleTypesBox->addItem("Unknown");
         }
-	if(sampleTypez.size())
+	if (sampleTypez.size())
             settings.setSampleType(sampleTypez.at(0));
     }
 
     endianBox->clear();
     QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders();
-    for(int i = 0; i < endianz.size(); ++i) {
-        switch(endianz.at(i)) {
+    for (int i = 0; i < endianz.size(); ++i) {
+        switch (endianz.at(i)) {
             case QAudioFormat::LittleEndian:
                 endianBox->addItem("Little Endian");
                 break;
@@ -222,7 +210,7 @@
                 break;
         }
     }
-    if(endianz.size())
+    if (endianz.size())
         settings.setByteOrder(endianz.at(0));
 }
 
@@ -249,7 +237,7 @@
 
 void AudioTest::sampleTypeChanged(int idx)
 {
-    switch(sampleTypesBox->itemText(idx).toInt()) {
+    switch (sampleTypesBox->itemText(idx).toInt()) {
         case QAudioFormat::SignedInt:
             settings.setSampleType(QAudioFormat::SignedInt);
             break;
@@ -263,7 +251,7 @@
 
 void AudioTest::endianChanged(int idx)
 {
-    switch(endianBox->itemText(idx).toInt()) {
+    switch (endianBox->itemText(idx).toInt()) {
         case QAudioFormat::LittleEndian:
             settings.setByteOrder(QAudioFormat::LittleEndian);
             break;
@@ -271,4 +259,3 @@
             settings.setByteOrder(QAudioFormat::BigEndian);
     }
 }
-