Add a config dialog tab for decoder options
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blob53e2ffea7a73c6395ba64a764358eb88ef4547f7
2 #include "config.h"
4 #include <cmath>
6 #include <QFileDialog>
7 #include <QMessageBox>
8 #include <QCloseEvent>
9 #include <QSettings>
10 #include <QtGlobal>
11 #include "mainwindow.h"
12 #include "ui_mainwindow.h"
14 namespace {
16 static const struct {
17 char backend_name[16];
18 char full_string[32];
19 } backendList[] = {
20 #ifdef HAVE_JACK
21 { "jack", "JACK" },
22 #endif
23 #ifdef HAVE_PULSEAUDIO
24 { "pulse", "PulseAudio" },
25 #endif
26 #ifdef HAVE_ALSA
27 { "alsa", "ALSA" },
28 #endif
29 #ifdef HAVE_COREAUDIO
30 { "core", "CoreAudio" },
31 #endif
32 #ifdef HAVE_OSS
33 { "oss", "OSS" },
34 #endif
35 #ifdef HAVE_SOLARIS
36 { "solaris", "Solaris" },
37 #endif
38 #ifdef HAVE_SNDIO
39 { "sndio", "SoundIO" },
40 #endif
41 #ifdef HAVE_QSA
42 { "qsa", "QSA" },
43 #endif
44 #ifdef HAVE_MMDEVAPI
45 { "mmdevapi", "MMDevAPI" },
46 #endif
47 #ifdef HAVE_DSOUND
48 { "dsound", "DirectSound" },
49 #endif
50 #ifdef HAVE_WINMM
51 { "winmm", "Windows Multimedia" },
52 #endif
53 #ifdef HAVE_PORTAUDIO
54 { "port", "PortAudio" },
55 #endif
56 #ifdef HAVE_OPENSL
57 { "opensl", "OpenSL" },
58 #endif
60 { "null", "Null Output" },
61 #ifdef HAVE_WAVE
62 { "wave", "Wave Writer" },
63 #endif
64 { "", "" }
67 static const struct NameValuePair {
68 const char name[64];
69 const char value[16];
70 } speakerModeList[] = {
71 { "Autodetect", "" },
72 { "Mono", "mono" },
73 { "Stereo", "stereo" },
74 { "Quadrophonic", "quad" },
75 { "5.1 Surround (Side)", "surround51" },
76 { "5.1 Surround (Rear)", "surround51rear" },
77 { "6.1 Surround", "surround61" },
78 { "7.1 Surround", "surround71" },
80 { "", "" }
81 }, sampleTypeList[] = {
82 { "Autodetect", "" },
83 { "8-bit int", "int8" },
84 { "8-bit uint", "uint8" },
85 { "16-bit int", "int16" },
86 { "16-bit uint", "uint16" },
87 { "32-bit int", "int32" },
88 { "32-bit uint", "uint32" },
89 { "32-bit float", "float32" },
91 { "", "" }
92 }, resamplerList[] = {
93 { "Point", "point" },
94 { "Linear", "linear" },
95 { "Default (Linear)", "" },
96 { "4-Point Sinc", "sinc4" },
97 { "8-Point Sinc", "sinc8" },
98 { "Band-limited Sinc", "bsinc" },
100 { "", "" }
101 }, stereoModeList[] = {
102 { "Autodetect", "" },
103 { "Speakers", "speakers" },
104 { "Headphones", "headphones" },
106 { "", "" }
107 }, stereoPanList[] = {
108 { "Default", "" },
109 { "UHJ", "uhj" },
110 { "Pair-Wise", "paired" },
112 { "", "" }
115 static QString getDefaultConfigName()
117 #ifdef Q_OS_WIN32
118 static const char fname[] = "alsoft.ini";
119 QByteArray base = qgetenv("AppData");
120 #else
121 static const char fname[] = "alsoft.conf";
122 QByteArray base = qgetenv("XDG_CONFIG_HOME");
123 if(base.isEmpty())
125 base = qgetenv("HOME");
126 if(base.isEmpty() == false)
127 base += "/.config";
129 #endif
130 if(base.isEmpty() == false)
131 return base +'/'+ fname;
132 return fname;
135 static QString getBaseDataPath()
137 #ifdef Q_OS_WIN32
138 QByteArray base = qgetenv("AppData");
139 #else
140 QByteArray base = qgetenv("XDG_DATA_HOME");
141 if(base.isEmpty())
143 base = qgetenv("HOME");
144 if(!base.isEmpty())
145 base += "/.local/share";
147 #endif
148 return base;
151 static QStringList getAllDataPaths(QString append=QString())
153 QStringList list;
154 list.append(getBaseDataPath());
155 #ifdef Q_OS_WIN32
156 // TODO: Common AppData path
157 #else
158 QString paths = qgetenv("XDG_DATA_DIRS");
159 if(paths.isEmpty())
160 paths = "/usr/local/share/:/usr/share/";
161 list += paths.split(QChar(':'), QString::SkipEmptyParts);
162 #endif
163 QStringList::iterator iter = list.begin();
164 while(iter != list.end())
166 if(iter->isEmpty())
167 iter = list.erase(iter);
168 else
170 iter->append(append);
171 iter++;
174 return list;
177 template<size_t N>
178 static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
180 for(size_t i = 0;i < N-1;i++)
182 if(str == list[i].name)
183 return list[i].value;
185 return QString();
188 template<size_t N>
189 static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
191 for(size_t i = 0;i < N-1;i++)
193 if(str == list[i].value)
194 return list[i].name;
196 return QString();
201 MainWindow::MainWindow(QWidget *parent) :
202 QMainWindow(parent),
203 ui(new Ui::MainWindow),
204 mPeriodSizeValidator(NULL),
205 mPeriodCountValidator(NULL),
206 mSourceCountValidator(NULL),
207 mEffectSlotValidator(NULL),
208 mSourceSendValidator(NULL),
209 mSampleRateValidator(NULL),
210 mJackBufferValidator(NULL),
211 mNeedsSave(false)
213 ui->setupUi(this);
215 for(int i = 0;speakerModeList[i].name[0];i++)
216 ui->channelConfigCombo->addItem(speakerModeList[i].name);
217 ui->channelConfigCombo->adjustSize();
218 for(int i = 0;sampleTypeList[i].name[0];i++)
219 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
220 ui->sampleFormatCombo->adjustSize();
221 for(int i = 0;stereoModeList[i].name[0];i++)
222 ui->stereoModeCombo->addItem(stereoModeList[i].name);
223 ui->stereoModeCombo->adjustSize();
224 for(int i = 0;stereoPanList[i].name[0];i++)
225 ui->stereoPanningComboBox->addItem(stereoPanList[i].name);
226 ui->stereoPanningComboBox->adjustSize();
228 int count;
229 for(count = 0;resamplerList[count].name[0];count++) {
231 ui->resamplerSlider->setRange(0, count-1);
233 ui->hrtfStateComboBox->adjustSize();
235 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
236 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
237 #else
238 ui->cpuExtDisabledLabel->setVisible(false);
239 #endif
241 #ifndef HAVE_NEON
243 #ifndef HAVE_SSE4_1
244 #ifndef HAVE_SSE3
245 #ifndef HAVE_SSE2
246 #ifndef HAVE_SSE
247 ui->enableSSECheckBox->setVisible(false);
248 #endif /* !SSE */
249 ui->enableSSE2CheckBox->setVisible(false);
250 #endif /* !SSE2 */
251 ui->enableSSE3CheckBox->setVisible(false);
252 #endif /* !SSE3 */
253 ui->enableSSE41CheckBox->setVisible(false);
254 #endif /* !SSE4.1 */
255 ui->enableNeonCheckBox->setVisible(false);
257 #else /* !Neon */
259 #ifndef HAVE_SSE4_1
260 #ifndef HAVE_SSE3
261 #ifndef HAVE_SSE2
262 #ifndef HAVE_SSE
263 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
264 ui->enableSSECheckBox->setVisible(false);
265 #endif /* !SSE */
266 ui->enableSSE2CheckBox->setVisible(false);
267 #endif /* !SSE2 */
268 ui->enableSSE3CheckBox->setVisible(false);
269 #endif /* !SSE3 */
270 ui->enableSSE41CheckBox->setVisible(false);
271 #endif /* !SSE4.1 */
273 #endif
275 mPeriodSizeValidator = new QIntValidator(64, 8192, this);
276 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
277 mPeriodCountValidator = new QIntValidator(2, 16, this);
278 ui->periodCountEdit->setValidator(mPeriodCountValidator);
280 mSourceCountValidator = new QIntValidator(0, 256, this);
281 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
282 mEffectSlotValidator = new QIntValidator(0, 16, this);
283 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
284 mSourceSendValidator = new QIntValidator(0, 4, this);
285 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
286 mSampleRateValidator = new QIntValidator(8000, 192000, this);
287 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
289 mJackBufferValidator = new QIntValidator(0, 8192, this);
290 ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
292 connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
293 connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
295 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutPage()));
297 connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction()));
298 connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
300 connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
301 connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
302 connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
303 connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
304 connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton()));
306 connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int)));
308 connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
309 connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
310 connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
311 connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
313 connect(ui->stereoPanningComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
315 connect(ui->decoderHQModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(toggleHqState(int)));
316 connect(ui->decoderDistCompCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
317 connect(ui->decoderQuadLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
318 connect(ui->decoderQuadButton, SIGNAL(clicked()), this, SLOT(selectQuadDecoderFile()));
319 connect(ui->decoder51LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
320 connect(ui->decoder51Button, SIGNAL(clicked()), this, SLOT(select51DecoderFile()));
321 connect(ui->decoder51RearLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
322 connect(ui->decoder51RearButton, SIGNAL(clicked()), this, SLOT(select51RearDecoderFile()));
323 connect(ui->decoder61LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
324 connect(ui->decoder61Button, SIGNAL(clicked()), this, SLOT(select71DecoderFile()));
325 connect(ui->decoder71LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
326 connect(ui->decoder71Button, SIGNAL(clicked()), this, SLOT(select61DecoderFile()));
328 connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
329 connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
330 connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
331 connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
332 connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
333 connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
335 connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
336 connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
337 connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
339 connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
340 connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
341 connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
342 connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
343 connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
345 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
346 connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
348 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
349 connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
350 connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
352 connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
353 connect(ui->emulateEaxCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
354 connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
355 connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
356 connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
357 connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
358 connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
359 connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
360 connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
361 connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
362 connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
363 connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
365 connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
366 connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
367 connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
369 connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
370 connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int)));
371 connect(ui->jackBufferSizeLine, SIGNAL(editingFinished()), this, SLOT(updateJackBufferSizeSlider()));
373 connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
374 connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
375 connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
376 connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
378 connect(ui->ossDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
379 connect(ui->ossPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSPlayback()));
380 connect(ui->ossDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
381 connect(ui->ossCapturePushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSCapture()));
383 connect(ui->solarisDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
384 connect(ui->solarisPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectSolarisPlayback()));
386 connect(ui->waveOutputLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
387 connect(ui->waveOutputButton, SIGNAL(clicked(bool)), this, SLOT(selectWaveOutput()));
388 connect(ui->waveBFormatCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
390 ui->backendListWidget->setCurrentRow(0);
391 ui->tabWidget->setCurrentIndex(0);
393 for(int i = 1;i < ui->backendListWidget->count();i++)
394 ui->backendListWidget->setRowHidden(i, true);
395 for(int i = 0;backendList[i].backend_name[0];i++)
397 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
398 backendList[i].full_string, Qt::MatchFixedString
400 foreach(const QListWidgetItem *item, items)
401 ui->backendListWidget->setItemHidden(item, false);
404 loadConfig(getDefaultConfigName());
407 MainWindow::~MainWindow()
409 delete ui;
410 delete mPeriodSizeValidator;
411 delete mPeriodCountValidator;
412 delete mSourceCountValidator;
413 delete mEffectSlotValidator;
414 delete mSourceSendValidator;
415 delete mSampleRateValidator;
416 delete mJackBufferValidator;
419 void MainWindow::closeEvent(QCloseEvent *event)
421 if(!mNeedsSave)
422 event->accept();
423 else
425 QMessageBox::StandardButton btn = QMessageBox::warning(this,
426 tr("Apply changes?"), tr("Save changes before quitting?"),
427 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel
429 if(btn == QMessageBox::Save)
430 saveCurrentConfig();
431 if(btn == QMessageBox::Cancel)
432 event->ignore();
433 else
434 event->accept();
438 void MainWindow::cancelCloseAction()
440 mNeedsSave = false;
441 close();
445 void MainWindow::showAboutPage()
447 QMessageBox::information(this, tr("About"),
448 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+(ALSOFT_VERSION ".")
453 QStringList MainWindow::collectHrtfs()
455 QStringList ret;
457 for(int i = 0;i < ui->hrtfFileList->count();i++)
459 QDir dir(ui->hrtfFileList->item(i)->text());
460 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
461 foreach(const QString &fname, fnames)
463 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
464 continue;
466 QString name = fname.left(fname.length()-4);
467 if(!ret.contains(name))
468 ret.push_back(name);
469 else
471 size_t i = 1;
472 do {
473 QString s = name+" #"+QString::number(i);
474 if(!ret.contains(s))
476 ret.push_back(s);
477 break;
479 ++i;
480 } while(1);
485 if(ui->defaultHrtfPathsCheckBox->isChecked())
487 QStringList paths = getAllDataPaths("/openal/hrtf");
488 foreach(const QString &name, paths)
490 QDir dir(name);
491 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
492 foreach(const QString &fname, fnames)
494 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
495 continue;
497 QString name = fname.left(fname.length()-4);
498 if(!ret.contains(name))
499 ret.push_back(name);
500 else
502 size_t i = 1;
503 do {
504 QString s = name+" #"+QString::number(i);
505 if(!ret.contains(s))
507 ret.push_back(s);
508 break;
510 ++i;
511 } while(1);
516 return ret;
520 void MainWindow::loadConfigFromFile()
522 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
523 if(fname.isEmpty() == false)
524 loadConfig(fname);
527 void MainWindow::loadConfig(const QString &fname)
529 QSettings settings(fname, QSettings::IniFormat);
531 QString sampletype = settings.value("sample-type").toString();
532 ui->sampleFormatCombo->setCurrentIndex(0);
533 if(sampletype.isEmpty() == false)
535 QString str = getNameFromValue(sampleTypeList, sampletype);
536 if(!str.isEmpty())
538 int j = ui->sampleFormatCombo->findText(str);
539 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
543 QString channelconfig = settings.value("channels").toString();
544 ui->channelConfigCombo->setCurrentIndex(0);
545 if(channelconfig.isEmpty() == false)
547 QString str = getNameFromValue(speakerModeList, channelconfig);
548 if(!str.isEmpty())
550 int j = ui->channelConfigCombo->findText(str);
551 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
555 QString srate = settings.value("frequency").toString();
556 if(srate.isEmpty())
557 ui->sampleRateCombo->setCurrentIndex(0);
558 else
560 ui->sampleRateCombo->lineEdit()->clear();
561 ui->sampleRateCombo->lineEdit()->insert(srate);
564 ui->srcCountLineEdit->clear();
565 ui->srcCountLineEdit->insert(settings.value("sources").toString());
566 ui->effectSlotLineEdit->clear();
567 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
568 ui->srcSendLineEdit->clear();
569 ui->srcSendLineEdit->insert(settings.value("sends").toString());
571 QString resampler = settings.value("resampler").toString().trimmed();
572 ui->resamplerSlider->setValue(0);
573 /* The "cubic" resampler is no longer supported. It's been replaced by
574 * "sinc4". */
575 if(resampler == "cubic")
576 resampler = "sinc4";
577 for(int i = 0;resamplerList[i].name[0];i++)
579 if(resampler == resamplerList[i].value)
581 ui->resamplerSlider->setValue(i);
582 break;
586 QString stereomode = settings.value("stereo-mode").toString().trimmed();
587 ui->stereoModeCombo->setCurrentIndex(0);
588 if(stereomode.isEmpty() == false)
590 QString str = getNameFromValue(stereoModeList, stereomode);
591 if(!str.isEmpty())
593 int j = ui->stereoModeCombo->findText(str);
594 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
598 int periodsize = settings.value("period_size").toInt();
599 ui->periodSizeEdit->clear();
600 if(periodsize >= 64)
602 ui->periodSizeEdit->insert(QString::number(periodsize));
603 updatePeriodSizeSlider();
606 int periodcount = settings.value("periods").toInt();
607 ui->periodCountEdit->clear();
608 if(periodcount >= 2)
610 ui->periodCountEdit->insert(QString::number(periodcount));
611 updatePeriodCountSlider();
614 QString stereopan = settings.value("stereo-panning").toString();
615 ui->stereoPanningComboBox->setCurrentIndex(0);
616 if(stereopan.isEmpty() == false)
618 QString str = getNameFromValue(stereoPanList, stereopan);
619 if(!str.isEmpty())
621 int j = ui->stereoPanningComboBox->findText(str);
622 if(j > 0) ui->stereoPanningComboBox->setCurrentIndex(j);
626 bool hqmode = settings.value("decoder/hq-mode", false).toBool();
627 ui->decoderHQModeCheckBox->setChecked(hqmode);
628 bool distcomp = settings.value("decoder/distance-comp", true).toBool();
629 ui->decoderDistCompCheckBox->setChecked(distcomp);
630 ui->decoderDistCompCheckBox->setEnabled(hqmode);
632 ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
633 ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
634 ui->decoder51RearLineEdit->setText(settings.value("decoder/surround51rear").toString());
635 ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
636 ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
638 QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
639 if(disabledCpuExts.size() == 1)
640 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
641 std::transform(disabledCpuExts.begin(), disabledCpuExts.end(),
642 disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed));
643 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
644 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
645 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
646 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
647 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
649 QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
650 if(hrtf_paths.size() == 1)
651 hrtf_paths = hrtf_paths[0].split(QChar(','));
652 std::transform(hrtf_paths.begin(), hrtf_paths.end(),
653 hrtf_paths.begin(), std::mem_fun_ref(&QString::trimmed));
654 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
655 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
656 else
658 hrtf_paths.removeAll(QString());
659 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
661 hrtf_paths.removeDuplicates();
662 ui->hrtfFileList->clear();
663 ui->hrtfFileList->addItems(hrtf_paths);
664 updateHrtfRemoveButton();
666 QString hrtfstate = settings.value("hrtf").toString().toLower();
667 if(hrtfstate == "true")
668 ui->hrtfStateComboBox->setCurrentIndex(1);
669 else if(hrtfstate == "false")
670 ui->hrtfStateComboBox->setCurrentIndex(2);
671 else
672 ui->hrtfStateComboBox->setCurrentIndex(0);
674 ui->preferredHrtfComboBox->clear();
675 ui->preferredHrtfComboBox->addItem("- Any -");
676 if(ui->defaultHrtfPathsCheckBox->isChecked())
678 QStringList hrtfs = collectHrtfs();
679 foreach(const QString &name, hrtfs)
680 ui->preferredHrtfComboBox->addItem(name);
683 QString defaulthrtf = settings.value("default-hrtf").toString();
684 ui->preferredHrtfComboBox->setCurrentIndex(0);
685 if(defaulthrtf.isEmpty() == false)
687 int i = ui->preferredHrtfComboBox->findText(defaulthrtf);
688 if(i > 0)
689 ui->preferredHrtfComboBox->setCurrentIndex(i);
690 else
692 i = ui->preferredHrtfComboBox->count();
693 ui->preferredHrtfComboBox->addItem(defaulthrtf);
694 ui->preferredHrtfComboBox->setCurrentIndex(i);
697 ui->preferredHrtfComboBox->adjustSize();
699 ui->enabledBackendList->clear();
700 ui->disabledBackendList->clear();
701 QStringList drivers = settings.value("drivers").toStringList();
702 if(drivers.size() == 0)
703 ui->backendCheckBox->setChecked(true);
704 else
706 if(drivers.size() == 1)
707 drivers = drivers[0].split(QChar(','));
708 std::transform(drivers.begin(), drivers.end(),
709 drivers.begin(), std::mem_fun_ref(&QString::trimmed));
711 bool lastWasEmpty = false;
712 foreach(const QString &backend, drivers)
714 lastWasEmpty = backend.isEmpty();
715 if(lastWasEmpty) continue;
717 if(!backend.startsWith(QChar('-')))
718 for(int j = 0;backendList[j].backend_name[0];j++)
720 if(backend == backendList[j].backend_name)
722 ui->enabledBackendList->addItem(backendList[j].full_string);
723 break;
726 else if(backend.size() > 1)
728 QStringRef backendref = backend.rightRef(backend.size()-1);
729 for(int j = 0;backendList[j].backend_name[0];j++)
731 if(backendref == backendList[j].backend_name)
733 ui->disabledBackendList->addItem(backendList[j].full_string);
734 break;
739 ui->backendCheckBox->setChecked(lastWasEmpty);
742 QString defaultreverb = settings.value("default-reverb").toString().toLower();
743 ui->defaultReverbComboBox->setCurrentIndex(0);
744 if(defaultreverb.isEmpty() == false)
746 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
748 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
750 ui->defaultReverbComboBox->setCurrentIndex(i);
751 break;
756 ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
758 QStringList excludefx = settings.value("excludefx").toStringList();
759 if(excludefx.size() == 1)
760 excludefx = excludefx[0].split(QChar(','));
761 std::transform(excludefx.begin(), excludefx.end(),
762 excludefx.begin(), std::mem_fun_ref(&QString::trimmed));
763 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
764 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
765 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
766 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
767 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
768 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
769 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
770 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
771 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
772 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
774 ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool());
775 ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool());
776 ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool());
778 ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool());
779 ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
780 updateJackBufferSizeSlider();
782 ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
783 ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
784 ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool());
785 ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool());
787 ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
788 ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
790 ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
792 ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
793 ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
795 ui->applyButton->setEnabled(false);
796 ui->closeCancelButton->setText(tr("Close"));
797 mNeedsSave = false;
800 void MainWindow::saveCurrentConfig()
802 saveConfig(getDefaultConfigName());
803 ui->applyButton->setEnabled(false);
804 ui->closeCancelButton->setText(tr("Close"));
805 mNeedsSave = false;
806 QMessageBox::information(this, tr("Information"),
807 tr("Applications using OpenAL need to be restarted for changes to take effect."));
810 void MainWindow::saveConfigAsFile()
812 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
813 if(fname.isEmpty() == false)
815 saveConfig(fname);
816 ui->applyButton->setEnabled(false);
817 mNeedsSave = false;
821 void MainWindow::saveConfig(const QString &fname) const
823 QSettings settings(fname, QSettings::IniFormat);
825 /* HACK: Compound any stringlist values into a comma-separated string. */
826 QStringList allkeys = settings.allKeys();
827 foreach(const QString &key, allkeys)
829 QStringList vals = settings.value(key).toStringList();
830 if(vals.size() > 1)
831 settings.setValue(key, vals.join(QChar(',')));
834 settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
835 settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
837 uint rate = ui->sampleRateCombo->currentText().toUInt();
838 if(!(rate > 0))
839 settings.setValue("frequency", QString());
840 else
841 settings.setValue("frequency", rate);
843 settings.setValue("period_size", ui->periodSizeEdit->text());
844 settings.setValue("periods", ui->periodCountEdit->text());
846 settings.setValue("sources", ui->srcCountLineEdit->text());
847 settings.setValue("slots", ui->effectSlotLineEdit->text());
849 settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
851 settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
852 settings.setValue("stereo-panning", getValueFromName(stereoPanList, ui->stereoPanningComboBox->currentText()));
854 settings.setValue("decoder/hq-mode",
855 ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
857 settings.setValue("decoder/distance-comp",
858 ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
861 settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
862 settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
863 settings.setValue("decoder/surround51rear", ui->decoder51RearLineEdit->text());
864 settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
865 settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
867 QStringList strlist;
868 if(!ui->enableSSECheckBox->isChecked())
869 strlist.append("sse");
870 if(!ui->enableSSE2CheckBox->isChecked())
871 strlist.append("sse2");
872 if(!ui->enableSSE3CheckBox->isChecked())
873 strlist.append("sse3");
874 if(!ui->enableSSE41CheckBox->isChecked())
875 strlist.append("sse4.1");
876 if(!ui->enableNeonCheckBox->isChecked())
877 strlist.append("neon");
878 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
880 if(ui->hrtfStateComboBox->currentIndex() == 1)
881 settings.setValue("hrtf", "true");
882 else if(ui->hrtfStateComboBox->currentIndex() == 2)
883 settings.setValue("hrtf", "false");
884 else
885 settings.setValue("hrtf", QString());
887 if(ui->preferredHrtfComboBox->currentIndex() == 0)
888 settings.setValue("default-hrtf", QString());
889 else
891 QString str = ui->preferredHrtfComboBox->currentText();
892 settings.setValue("default-hrtf", str);
895 strlist.clear();
896 for(int i = 0;i < ui->hrtfFileList->count();i++)
897 strlist.append(ui->hrtfFileList->item(i)->text());
898 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
899 strlist.append(QString());
900 settings.setValue("hrtf-paths", strlist.join(QChar(',')));
902 strlist.clear();
903 for(int i = 0;i < ui->enabledBackendList->count();i++)
905 QString label = ui->enabledBackendList->item(i)->text();
906 for(int j = 0;backendList[j].backend_name[0];j++)
908 if(label == backendList[j].full_string)
910 strlist.append(backendList[j].backend_name);
911 break;
915 for(int i = 0;i < ui->disabledBackendList->count();i++)
917 QString label = ui->disabledBackendList->item(i)->text();
918 for(int j = 0;backendList[j].backend_name[0];j++)
920 if(label == backendList[j].full_string)
922 strlist.append(QChar('-')+QString(backendList[j].backend_name));
923 break;
927 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
928 strlist.append("-all");
929 else if(ui->backendCheckBox->isChecked())
930 strlist.append(QString());
931 settings.setValue("drivers", strlist.join(QChar(',')));
933 // TODO: Remove check when we can properly match global values.
934 if(ui->defaultReverbComboBox->currentIndex() == 0)
935 settings.setValue("default-reverb", QString());
936 else
938 QString str = ui->defaultReverbComboBox->currentText().toLower();
939 settings.setValue("default-reverb", str);
942 if(ui->emulateEaxCheckBox->isChecked())
943 settings.setValue("reverb/emulate-eax", "true");
944 else
945 settings.remove("reverb/emulate-eax"/*, "false"*/);
947 strlist.clear();
948 if(!ui->enableEaxReverbCheck->isChecked())
949 strlist.append("eaxreverb");
950 if(!ui->enableStdReverbCheck->isChecked())
951 strlist.append("reverb");
952 if(!ui->enableChorusCheck->isChecked())
953 strlist.append("chorus");
954 if(!ui->enableDistortionCheck->isChecked())
955 strlist.append("distortion");
956 if(!ui->enableCompressorCheck->isChecked())
957 strlist.append("compressor");
958 if(!ui->enableEchoCheck->isChecked())
959 strlist.append("echo");
960 if(!ui->enableEqualizerCheck->isChecked())
961 strlist.append("equalizer");
962 if(!ui->enableFlangerCheck->isChecked())
963 strlist.append("flanger");
964 if(!ui->enableModulatorCheck->isChecked())
965 strlist.append("modulator");
966 if(!ui->enableDedicatedCheck->isChecked())
967 strlist.append("dedicated");
968 settings.setValue("excludefx", strlist.join(QChar(',')));
970 settings.setValue("pulse/spawn-server",
971 ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
973 settings.setValue("pulse/allow-moves",
974 ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
976 settings.setValue("pulse/fix-rate",
977 ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
980 settings.setValue("jack/spawn-server",
981 ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
983 settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
985 settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
986 settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
987 settings.setValue("alsa/allow-resampler",
988 ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
990 settings.setValue("alsa/mmap",
991 ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
994 settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
995 settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
997 settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
999 settings.setValue("wave/file", ui->waveOutputLine->text());
1000 settings.setValue("wave/bformat",
1001 ui->waveBFormatCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1004 /* Remove empty keys
1005 * FIXME: Should only remove keys whose value matches the globally-specified value.
1007 allkeys = settings.allKeys();
1008 foreach(const QString &key, allkeys)
1010 QString str = settings.value(key).toString();
1011 if(str == QString())
1012 settings.remove(key);
1017 void MainWindow::enableApplyButton()
1019 if(!mNeedsSave)
1020 ui->applyButton->setEnabled(true);
1021 mNeedsSave = true;
1022 ui->closeCancelButton->setText(tr("Cancel"));
1026 void MainWindow::updateResamplerLabel(int num)
1028 ui->resamplerLabel->setText(resamplerList[num].name);
1029 enableApplyButton();
1033 void MainWindow::updatePeriodSizeEdit(int size)
1035 ui->periodSizeEdit->clear();
1036 if(size >= 64)
1038 size = (size+32)&~0x3f;
1039 ui->periodSizeEdit->insert(QString::number(size));
1041 enableApplyButton();
1044 void MainWindow::updatePeriodSizeSlider()
1046 int pos = ui->periodSizeEdit->text().toInt();
1047 if(pos >= 64)
1049 if(pos > 8192)
1050 pos = 8192;
1051 ui->periodSizeSlider->setSliderPosition(pos);
1053 enableApplyButton();
1056 void MainWindow::updatePeriodCountEdit(int count)
1058 ui->periodCountEdit->clear();
1059 if(count >= 2)
1060 ui->periodCountEdit->insert(QString::number(count));
1061 enableApplyButton();
1064 void MainWindow::updatePeriodCountSlider()
1066 int pos = ui->periodCountEdit->text().toInt();
1067 if(pos < 2)
1068 pos = 0;
1069 else if(pos > 16)
1070 pos = 16;
1071 ui->periodCountSlider->setSliderPosition(pos);
1072 enableApplyButton();
1076 void MainWindow::toggleHqState(int state)
1078 ui->decoderDistCompCheckBox->setEnabled(state);
1079 enableApplyButton();
1082 void MainWindow::selectQuadDecoderFile()
1083 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadrophonic Decoder");}
1084 void MainWindow::select51DecoderFile()
1085 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround (Side) Decoder");}
1086 void MainWindow::select51RearDecoderFile()
1087 { selectDecoderFile(ui->decoder51RearLineEdit, "Select 5.1 Surround (Rear) Decoder");}
1088 void MainWindow::select61DecoderFile()
1089 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1090 void MainWindow::select71DecoderFile()
1091 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1092 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1094 QString fname = QFileDialog::getOpenFileName(this, tr(caption),
1095 line->text(), tr("AmbDec Files (*.ambdec);;All Files (*.*)")
1097 if(!fname.isEmpty())
1099 line->setText(fname);
1100 enableApplyButton();
1105 void MainWindow::updateJackBufferSizeEdit(int size)
1107 ui->jackBufferSizeLine->clear();
1108 if(size > 0)
1109 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1110 enableApplyButton();
1113 void MainWindow::updateJackBufferSizeSlider()
1115 int value = ui->jackBufferSizeLine->text().toInt();
1116 int pos = (int)floor(log2(value) + 0.5);
1117 ui->jackBufferSizeSlider->setSliderPosition(pos);
1118 enableApplyButton();
1122 void MainWindow::addHrtfFile()
1124 QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
1125 if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
1127 ui->hrtfFileList->addItem(path);
1128 enableApplyButton();
1132 void MainWindow::removeHrtfFile()
1134 QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
1135 if(!selected.isEmpty())
1137 foreach(QListWidgetItem *item, selected)
1138 delete item;
1139 enableApplyButton();
1143 void MainWindow::updateHrtfRemoveButton()
1145 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
1148 void MainWindow::showEnabledBackendMenu(QPoint pt)
1150 QMap<QAction*,QString> actionMap;
1152 pt = ui->enabledBackendList->mapToGlobal(pt);
1154 QMenu ctxmenu;
1155 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1156 if(ui->enabledBackendList->selectedItems().size() == 0)
1157 removeAction->setEnabled(false);
1158 ctxmenu.addSeparator();
1159 for(size_t i = 0;backendList[i].backend_name[0];i++)
1161 QString backend = backendList[i].full_string;
1162 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1163 actionMap[action] = backend;
1164 if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1165 ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1166 action->setEnabled(false);
1169 QAction *gotAction = ctxmenu.exec(pt);
1170 if(gotAction == removeAction)
1172 QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
1173 foreach(QListWidgetItem *item, selected)
1174 delete item;
1175 enableApplyButton();
1177 else if(gotAction != NULL)
1179 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1180 if(iter != actionMap.end())
1181 ui->enabledBackendList->addItem(iter.value());
1182 enableApplyButton();
1186 void MainWindow::showDisabledBackendMenu(QPoint pt)
1188 QMap<QAction*,QString> actionMap;
1190 pt = ui->disabledBackendList->mapToGlobal(pt);
1192 QMenu ctxmenu;
1193 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1194 if(ui->disabledBackendList->selectedItems().size() == 0)
1195 removeAction->setEnabled(false);
1196 ctxmenu.addSeparator();
1197 for(size_t i = 0;backendList[i].backend_name[0];i++)
1199 QString backend = backendList[i].full_string;
1200 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1201 actionMap[action] = backend;
1202 if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1203 ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1204 action->setEnabled(false);
1207 QAction *gotAction = ctxmenu.exec(pt);
1208 if(gotAction == removeAction)
1210 QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
1211 foreach(QListWidgetItem *item, selected)
1212 delete item;
1213 enableApplyButton();
1215 else if(gotAction != NULL)
1217 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1218 if(iter != actionMap.end())
1219 ui->disabledBackendList->addItem(iter.value());
1220 enableApplyButton();
1224 void MainWindow::selectOSSPlayback()
1226 QString current = ui->ossDefaultDeviceLine->text();
1227 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1228 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1229 if(!fname.isEmpty())
1231 ui->ossDefaultDeviceLine->setText(fname);
1232 enableApplyButton();
1236 void MainWindow::selectOSSCapture()
1238 QString current = ui->ossDefaultCaptureLine->text();
1239 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1240 QString fname = QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current);
1241 if(!fname.isEmpty())
1243 ui->ossDefaultCaptureLine->setText(fname);
1244 enableApplyButton();
1248 void MainWindow::selectSolarisPlayback()
1250 QString current = ui->solarisDefaultDeviceLine->text();
1251 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1252 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1253 if(!fname.isEmpty())
1255 ui->solarisDefaultDeviceLine->setText(fname);
1256 enableApplyButton();
1260 void MainWindow::selectWaveOutput()
1262 QString fname = QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1263 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)")
1265 if(!fname.isEmpty())
1267 ui->waveOutputLine->setText(fname);
1268 enableApplyButton();