2010-01-04 15:49:22 -05:00
|
|
|
#include <QtGui>
|
|
|
|
#include "prefdialog.h"
|
|
|
|
#include "ui_prefdialog.h"
|
2010-01-05 21:08:25 -05:00
|
|
|
#include "prefportaudio.h"
|
2010-01-07 01:43:51 -05:00
|
|
|
#include "prefsofia.h"
|
2010-01-10 23:40:39 -05:00
|
|
|
#include "prefaccounts.h"
|
2010-01-04 15:49:22 -05:00
|
|
|
|
|
|
|
PrefDialog::PrefDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::PrefDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2010-01-05 21:08:25 -05:00
|
|
|
connect(this, SIGNAL(accepted()), this, SLOT(writeConfig()));
|
2010-07-03 12:37:32 -04:00
|
|
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
|
2010-01-05 21:08:25 -05:00
|
|
|
|
2010-01-13 21:32:20 -05:00
|
|
|
_pref_accounts = new PrefAccounts(ui);
|
2010-01-05 21:08:25 -05:00
|
|
|
_mod_portaudio = new PrefPortaudio(ui, this);
|
2010-04-08 22:15:29 -04:00
|
|
|
connect(_mod_portaudio, SIGNAL(preprocessorsApplied(QStringList)), this, SIGNAL(preprocessorsApplied(QStringList)));
|
2010-01-13 21:32:20 -05:00
|
|
|
_mod_sofia = new PrefSofia(ui, this);
|
2010-01-05 21:08:25 -05:00
|
|
|
readConfig();
|
2010-01-04 15:49:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PrefDialog::~PrefDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
void PrefDialog::clicked(QAbstractButton *b) {
|
|
|
|
if (ui->buttonBox->buttonRole(b) == QDialogButtonBox::ApplyRole) {
|
|
|
|
writeConfig();
|
|
|
|
readConfig();
|
|
|
|
}
|
|
|
|
if ( ui->buttonBox->buttonRole(b) == QDialogButtonBox::RejectRole) {
|
|
|
|
/* This doesn't really work because we need to reset the DOM as well to discard changes... */
|
|
|
|
readConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 21:08:25 -05:00
|
|
|
void PrefDialog::writeConfig()
|
|
|
|
{
|
2010-07-03 12:37:32 -04:00
|
|
|
/* Ask modules to write their configs. */
|
2010-01-05 21:08:25 -05:00
|
|
|
_mod_portaudio->writeConfig();
|
2010-01-13 21:32:20 -05:00
|
|
|
_mod_sofia->writeConfig();
|
2010-07-03 12:37:32 -04:00
|
|
|
_pref_accounts->writeConfig();
|
|
|
|
|
|
|
|
/* Write it to file */
|
|
|
|
ISettings settings(this);
|
|
|
|
settings.saveToFile();
|
|
|
|
|
|
|
|
/* Re-read the configuration to memory */
|
|
|
|
const char *err;
|
|
|
|
switch_xml_t xml_root;
|
|
|
|
|
|
|
|
if ((xml_root = switch_xml_open_root(1, &err))) {
|
|
|
|
switch_xml_free(xml_root);
|
|
|
|
} else {
|
|
|
|
QMessageBox::critical(0, tr("Unable to save settings"),
|
|
|
|
tr("There was an error saving your settings.\nPlease report this bug.\n%1").arg(err),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-17 18:10:57 -05:00
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
/* Tell modules new config is in memory so they get a chance */
|
|
|
|
_mod_portaudio->postWriteConfig();
|
|
|
|
_pref_accounts->postWriteConfig();
|
2010-01-04 15:49:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrefDialog::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QDialog::changeEvent(e);
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::LanguageChange:
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-05 21:08:25 -05:00
|
|
|
|
|
|
|
void PrefDialog::readConfig()
|
|
|
|
{
|
2010-01-13 21:32:20 -05:00
|
|
|
_pref_accounts->readConfig();
|
2010-01-05 21:08:25 -05:00
|
|
|
_mod_portaudio->readConfig();
|
2010-01-13 21:32:20 -05:00
|
|
|
_mod_sofia->readConfig();
|
2010-01-05 21:08:25 -05:00
|
|
|
}
|