2
0

prefdialog.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <QtGui>
  2. #include "prefdialog.h"
  3. #include "ui_prefdialog.h"
  4. #include "prefportaudio.h"
  5. #include "prefsofia.h"
  6. #include "prefaccounts.h"
  7. PrefDialog::PrefDialog(QWidget *parent) :
  8. QDialog(parent),
  9. ui(new Ui::PrefDialog)
  10. {
  11. ui->setupUi(this);
  12. connect(this, SIGNAL(accepted()), this, SLOT(writeConfig()));
  13. connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
  14. _pref_accounts = new PrefAccounts(ui);
  15. _mod_portaudio = new PrefPortaudio(ui, this);
  16. connect(_mod_portaudio, SIGNAL(preprocessorsApplied(QStringList)), this, SIGNAL(preprocessorsApplied(QStringList)));
  17. _mod_sofia = new PrefSofia(ui, this);
  18. readConfig();
  19. }
  20. PrefDialog::~PrefDialog()
  21. {
  22. delete ui;
  23. }
  24. void PrefDialog::clicked(QAbstractButton *b) {
  25. if (ui->buttonBox->buttonRole(b) == QDialogButtonBox::ApplyRole) {
  26. writeConfig();
  27. readConfig();
  28. }
  29. if ( ui->buttonBox->buttonRole(b) == QDialogButtonBox::RejectRole) {
  30. /* This doesn't really work because we need to reset the DOM as well to discard changes... */
  31. readConfig();
  32. }
  33. }
  34. void PrefDialog::writeConfig()
  35. {
  36. /* Ask modules to write their configs. */
  37. _mod_portaudio->writeConfig();
  38. _mod_sofia->writeConfig();
  39. _pref_accounts->writeConfig();
  40. /* Write it to file */
  41. ISettings settings(this);
  42. settings.saveToFile();
  43. /* Re-read the configuration to memory */
  44. const char *err;
  45. switch_xml_t xml_root;
  46. if ((xml_root = switch_xml_open_root(1, &err))) {
  47. switch_xml_free(xml_root);
  48. } else {
  49. QMessageBox::critical(0, tr("Unable to save settings"),
  50. tr("There was an error saving your settings.\nPlease report this bug.\n%1").arg(err),
  51. QMessageBox::Ok);
  52. return;
  53. }
  54. /* Tell modules new config is in memory so they get a chance */
  55. _mod_portaudio->postWriteConfig();
  56. _pref_accounts->postWriteConfig();
  57. }
  58. void PrefDialog::changeEvent(QEvent *e)
  59. {
  60. QDialog::changeEvent(e);
  61. switch (e->type()) {
  62. case QEvent::LanguageChange:
  63. ui->retranslateUi(this);
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. void PrefDialog::readConfig()
  70. {
  71. _pref_accounts->readConfig();
  72. _mod_portaudio->readConfig();
  73. _mod_sofia->readConfig();
  74. }