From fb79c1bfe4aaeff594c1c31274bc385a55885657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mesquita?= Date: Mon, 11 Jan 2010 04:40:39 +0000 Subject: [PATCH] Add all the new stuff to persist accounts and sofia configs. Still not working, but a lot work as been done and panes not working are disabled. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16235 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- fscomm/FSComm.pro | 3 +- fscomm/conf/sofia.conf.xml | 2 + fscomm/fshost.cpp | 23 +- fscomm/fshost.h | 2 + fscomm/mod_qsettings/mod_qsettings.cpp | 75 +++++ fscomm/mod_qsettings/mod_qsettings.h | 1 + fscomm/preferences/accountdialog.cpp | 55 +++- fscomm/preferences/accountdialog.h | 2 + fscomm/preferences/accountdialog.ui | 404 ++++++++++++------------- fscomm/preferences/prefaccounts.cpp | 30 ++ fscomm/preferences/prefaccounts.h | 21 ++ fscomm/preferences/prefdialog.cpp | 5 +- fscomm/preferences/prefdialog.h | 4 +- fscomm/preferences/prefdialog.ui | 13 +- 14 files changed, 405 insertions(+), 235 deletions(-) create mode 100644 fscomm/preferences/prefaccounts.cpp create mode 100644 fscomm/preferences/prefaccounts.h diff --git a/fscomm/FSComm.pro b/fscomm/FSComm.pro index 47a3629ecd..b5aa792ed8 100644 --- a/fscomm/FSComm.pro +++ b/fscomm/FSComm.pro @@ -29,7 +29,8 @@ SOURCES += main.cpp \ preferences/prefdialog.cpp \ preferences/prefportaudio.cpp \ preferences/prefsofia.cpp \ - preferences/accountdialog.cpp + preferences/accountdialog.cpp \ + preferences/prefaccounts.cpp HEADERS += mainwindow.h \ fshost.h \ call.h \ diff --git a/fscomm/conf/sofia.conf.xml b/fscomm/conf/sofia.conf.xml index 67f7f5d958..2dde03dacf 100644 --- a/fscomm/conf/sofia.conf.xml +++ b/fscomm/conf/sofia.conf.xml @@ -9,6 +9,8 @@ + + diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index 6ddca28547..5d58dae278 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -47,15 +47,10 @@ FSHost::FSHost(QObject *parent) : } -void FSHost::run(void) +void FSHost::createFolders() { - switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; - const char *err = NULL; - switch_bool_t console = SWITCH_FALSE; - switch_status_t destroy_status; - /* Create directory structure for softphone with default configs */ - QDir conf_dir = QDir(QDir::home()); + QDir conf_dir = QDir::home(); if (!conf_dir.exists(".fscomm")) { conf_dir.mkpath(".fscomm/conf/accounts"); @@ -66,8 +61,8 @@ void FSHost::run(void) QString dest = QString("%1/.fscomm/conf/freeswitch.xml").arg(conf_dir.absolutePath()); rootXML.copy(dest); - QFile defaultAccount(":/confs/example.xml"); - dest = QString("%1/.fscomm/conf/accounts/example.xml").arg(conf_dir.absolutePath()); + QFile defaultAccount(":/confs/template.xml"); + dest = QString("%1/.fscomm/conf/accounts/template.xml").arg(conf_dir.absolutePath()); defaultAccount.copy(dest); } @@ -110,6 +105,16 @@ void FSHost::run(void) } strcpy(SWITCH_GLOBAL_dirs.htdocs_dir, QString("%1/htdocs").arg(conf_dir.absolutePath()).toAscii().constData()); } +} + +void FSHost::run(void) +{ + switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; + const char *err = NULL; + switch_bool_t console = SWITCH_FALSE; + switch_status_t destroy_status; + + createFolders(); /* If you need to override configuration directories, you need to change them in the SWITCH_GLOBAL_dirs global structure */ printf("Initializing core...\n"); diff --git a/fscomm/fshost.h b/fscomm/fshost.h index 46336bb8b0..dff60e33ce 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -45,6 +45,7 @@ class Call; #define FSCOMM_GW_STATE_EXPIRED 7 #define FSCOMM_GW_STATE_NOREG 8 + static const char *fscomm_gw_state_names[] = { "TRYING", "REGISTER", @@ -83,6 +84,7 @@ signals: private: switch_status_t processBlegEvent(switch_event_t *, QString); switch_status_t processAlegEvent(switch_event_t *, QString); + void createFolders(); void printEventHeaders(switch_event_t *event); QHash _active_calls; QHash _bleg_uuids; diff --git a/fscomm/mod_qsettings/mod_qsettings.cpp b/fscomm/mod_qsettings/mod_qsettings.cpp index cef4720b45..30e3fa5d17 100644 --- a/fscomm/mod_qsettings/mod_qsettings.cpp +++ b/fscomm/mod_qsettings/mod_qsettings.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "mod_qsettings/mod_qsettings.h" switch_xml_t XMLBinding::getConfigXML(QString tmpl) @@ -79,9 +81,82 @@ switch_xml_t XMLBinding::getConfigXML(QString tmpl) char *res = switch_event_expand_headers(e, tmplContents.data()); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Template %s as follows:\n%s", tmpl.toAscii().constData(), res); switch_safe_free(e); + if (tmpl == "sofia.conf") + { + return proccessAccounts(tmpl, res); + } return switch_xml_parse_str(res, strlen(res)); } +switch_xml_t XMLBinding::proccessAccounts(QString tmpl, QByteArray xml) +{ + char *res = NULL; + + QDomDocument xmlDom; + + /* Process sofia accounts */ + if (tmpl == "sofia.conf") + { + int errorLine, errorColumn; + QString errorMsg; + + if (!xmlDom.setContent(xml, &errorMsg, &errorLine, &errorColumn)) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse the xml template from sofia.conf.xml to add the accounts!\n"); + } + QDomNodeList gatewaysNodeList = xmlDom.elementsByTagName("gateways"); + if (gatewaysNodeList.isEmpty() || gatewaysNodeList.count() > 1) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Where is my gateways tag? Or do we have more then one match?\n"); + } + + QDomNode gatewaysNode = gatewaysNodeList.at(0); + + _settings->beginGroup("FreeSWITCH/conf/accounts"); + foreach (QString account, _settings->childGroups()) + { + switch_event_t *e; + switch_event_create_plain(&e, SWITCH_EVENT_REQUEST_PARAMS); + switch_assert(e); + + _settings->beginGroup(account); + switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, "name", account.toAscii().data()); + foreach (QString k, _settings->childKeys()) + { + switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, k.toAscii().constData(), _settings->value(k).toByteArray().constData()); + } + _settings->endGroup(); + + /* Open template file and expand all strings based on QSettings */ + QFile tmplFile(QString("%1/.fscomm/templates/account.conf.xml").arg(QDir::homePath())); + if (!tmplFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Template for accounts could not be read!\n"); + return NULL; + } + + QByteArray tmplContents(tmplFile.readAll()); + tmplFile.close(); + + res = switch_event_expand_headers(e, tmplContents.data()); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Template of account %s as follows:\n%s", account.toAscii().data(), res); + + QDomDocument gatewayXML; + if (!gatewayXML.setContent(QByteArray(res), &errorMsg, &errorLine, &errorColumn)) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "We could not parse the XML for the account!\n"); + } + + gatewaysNode.appendChild(gatewayXML); + switch_safe_free(e); + } + _settings->endGroup(); + } + + return switch_xml_parse_str(xmlDom.toByteArray().data(), strlen(xmlDom.toByteArray().data())); +} + static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data) { diff --git a/fscomm/mod_qsettings/mod_qsettings.h b/fscomm/mod_qsettings/mod_qsettings.h index 91e1b401e2..e6947ac242 100644 --- a/fscomm/mod_qsettings/mod_qsettings.h +++ b/fscomm/mod_qsettings/mod_qsettings.h @@ -43,6 +43,7 @@ public: QString getBinding(void) { return _binding; } switch_xml_t getConfigXML(QString); private: + switch_xml_t proccessAccounts(QString, QByteArray); QString _binding; QSettings* _settings; }; diff --git a/fscomm/preferences/accountdialog.cpp b/fscomm/preferences/accountdialog.cpp index 75e6d1df35..a4095f7deb 100644 --- a/fscomm/preferences/accountdialog.cpp +++ b/fscomm/preferences/accountdialog.cpp @@ -1,4 +1,5 @@ #include +#include #include "accountdialog.h" #include "ui_accountdialog.h" @@ -9,6 +10,8 @@ AccountDialog::AccountDialog(QWidget *parent) : ui->setupUi(this); _settings = new QSettings; connect(this, SIGNAL(accepted()), this, SLOT(writeConfig())); + connect(ui->sofiaExtraParamAddBtn, SIGNAL(clicked()), this, SLOT(addExtraParam())); + connect(ui->sofiaExtraParamRemBtn, SIGNAL(clicked()), this, SLOT(remExtraParam())); } AccountDialog::~AccountDialog() @@ -16,6 +19,42 @@ AccountDialog::~AccountDialog() delete ui; } +void AccountDialog::remExtraParam() +{ + QList sel = ui->sofiaExtraParamTable->selectedRanges(); + + foreach(QTableWidgetSelectionRange range, sel) + { + int offset =0; + for(int row = range.topRow(); row<=range.bottomRow(); row++) + { + ui->sofiaExtraParamTable->removeRow(row-offset); + offset++; + } + } +} + +void AccountDialog::addExtraParam() +{ + bool ok; + QString paramName = QInputDialog::getText(this, tr("Add parameter."), + tr("New parameter name:"), QLineEdit::Normal, + NULL, &ok); + if (!ok) + return; + QString paramVal = QInputDialog::getText(this, tr("Add parameter."), + tr("New parameter value:"), QLineEdit::Normal, + NULL, &ok); + if (!ok) + return; + + QTableWidgetItem* paramNameItem = new QTableWidgetItem(paramName); + QTableWidgetItem* paramValItem = new QTableWidgetItem(paramVal); + ui->sofiaExtraParamTable->setRowCount(ui->sofiaExtraParamTable->rowCount()+1); + ui->sofiaExtraParamTable->setItem(ui->sofiaExtraParamTable->rowCount()-1,0,paramNameItem); + ui->sofiaExtraParamTable->setItem(ui->sofiaExtraParamTable->rowCount()-1,1,paramValItem); +} + void AccountDialog::writeConfig() { _settings->beginGroup("FreeSWITCH/conf/accounts"); @@ -23,19 +62,21 @@ void AccountDialog::writeConfig() _settings->beginGroup(ui->sofiaGwNameEdit->text()); _settings->setValue("username", ui->sofiaGwUsernameEdit->text()); _settings->setValue("realm", ui->sofiaGwRealmEdit->text()); - _settings->setValue("from-user", ui->sofiaGwFromUserEdit->text()); - _settings->setValue("from-domain", ui->sofiaGwFromDomainEdit->text()); _settings->setValue("password", ui->sofiaGwPasswordEdit->text()); _settings->setValue("extension", ui->sofiaGwExtensionEdit->text()); - _settings->setValue("proxy", ui->sofiaGwProxyEdit->text()); - _settings->setValue("register-proxy", ui->sofiaGwRegisterProxyEdit->text()); _settings->setValue("expire-seconds", ui->sofiaGwExpireSecondsSpin->value()); _settings->setValue("register", ui->sofiaGwRegisterCombo->currentText()); _settings->setValue("register-transport", ui->sofiaGwRegisterTransportCombo->currentText()); _settings->setValue("retry-seconds", ui->sofiaGwRetrySecondsSpin->value()); - _settings->setValue("caller-id-in-from", ui->sofiaGwCallerIdInFromCombo->currentText()); - _settings->setValue("contact-params", ui->sofiaGwContactParamsEdit->text()); - _settings->setValue("ping", ui->sofiaGwPingSpin->value()); + + _settings->beginGroup("customParams"); + for (int i = 0; i< ui->sofiaExtraParamTable->rowCount(); i++) + { + _settings->setValue(ui->sofiaExtraParamTable->item(i, 0)->text(), + ui->sofiaExtraParamTable->item(i, 1)->text()); + } + _settings->endGroup(); + _settings->endGroup(); _settings->endGroup(); diff --git a/fscomm/preferences/accountdialog.h b/fscomm/preferences/accountdialog.h index b7e408d7e1..f229a4459a 100644 --- a/fscomm/preferences/accountdialog.h +++ b/fscomm/preferences/accountdialog.h @@ -17,6 +17,8 @@ public: private slots: void writeConfig(); + void addExtraParam(); + void remExtraParam(); protected: void changeEvent(QEvent *e); diff --git a/fscomm/preferences/accountdialog.ui b/fscomm/preferences/accountdialog.ui index acddb9eb05..bf29856d94 100644 --- a/fscomm/preferences/accountdialog.ui +++ b/fscomm/preferences/accountdialog.ui @@ -9,206 +9,204 @@ 0 0 - 495 - 573 + 389 + 394 Account - - - - - name + + + + + 1 + + + Basic + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + name + + + + + + + + + + username + + + + + + + + + + realm + + + + + + + + + + password + + + + + + + + + + extension + + + + + + + + + + expire-seconds + + + + + + + 60 + + + + + + + register + + + + + + + + true + + + + + false + + + + + + + + register-transport + + + + + + + + udp + + + + + tcp + + + + + + + + retry-seconds + + + + + + + 30 + + + + + + + + Advanced + + + + + + + Param Name + + + + + Param Value + + + + + + + + + + + + + + + + + + - + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + - - - - - - - username - - - - - - - - - - realm - - - - - - - - - - from-user - - - - - - - - - - from-domain - - - - - - - - - - password - - - - - - - - - - extension - - - - - - - - - - proxy - - - - - - - - - - register-proxy - - - - - - - - - - expire-seconds - - - - - - - 60 - - - - - - - register - - - - - - - - true - - - - - false - - - - - - - - register-transport - - - - - - - - udp - - - - - tcp - - - - - - - - retry-seconds - - - - - - - 30 - - - - - - - contact-params - - - - - - - - - - caller-id-in-from - - - - - - - ping - - - - - - - 25 - - - - + Qt::Horizontal @@ -218,20 +216,6 @@ - - - - - false - - - - - true - - - - @@ -243,8 +227,8 @@ accept() - 248 - 254 + 257 + 563 157 @@ -259,8 +243,8 @@ reject() - 316 - 260 + 325 + 563 286 diff --git a/fscomm/preferences/prefaccounts.cpp b/fscomm/preferences/prefaccounts.cpp new file mode 100644 index 0000000000..d4695f0788 --- /dev/null +++ b/fscomm/preferences/prefaccounts.cpp @@ -0,0 +1,30 @@ +#include +#include "prefaccounts.h" + +PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) : + _ui(ui) +{ + _settings = new QSettings(); +} + +void PrefAccounts::writeConfig() +{ + return; +} + +void PrefAccounts::readConfig() +{ + _settings->beginGroup("FreeSWITCH/conf/accounts"); + foreach(QString accountName, _settings->childGroups()) + { + _settings->beginGroup(accountName); + QTableWidgetItem *item0 = new QTableWidgetItem(accountName); + QTableWidgetItem *item1 = new QTableWidgetItem(_settings->value("username").toString()); + _settings->endGroup(); + _ui->accountsTable->setRowCount(_ui->accountsTable->rowCount()+1); + _ui->accountsTable->setItem(_ui->accountsTable->rowCount()-1, 0, item0); + _ui->accountsTable->setItem(_ui->accountsTable->rowCount()-1, 1, item1); + } + + _settings->endGroup(); +} diff --git a/fscomm/preferences/prefaccounts.h b/fscomm/preferences/prefaccounts.h new file mode 100644 index 0000000000..aa4206ca06 --- /dev/null +++ b/fscomm/preferences/prefaccounts.h @@ -0,0 +1,21 @@ +#ifndef PREFACCOUNTS_H +#define PREFACCOUNTS_H + +#include +#include "ui_prefdialog.h" + +class QSettings; + +class PrefAccounts +{ +public: + explicit PrefAccounts(Ui::PrefDialog *ui); + void readConfig(); + void writeConfig(); + +private: + Ui::PrefDialog *_ui; + QSettings *_settings; +}; + +#endif // PREFACCOUNTS_H diff --git a/fscomm/preferences/prefdialog.cpp b/fscomm/preferences/prefdialog.cpp index 05242f3f1f..483377462b 100644 --- a/fscomm/preferences/prefdialog.cpp +++ b/fscomm/preferences/prefdialog.cpp @@ -4,6 +4,7 @@ #include "prefportaudio.h" #include "prefsofia.h" #include "accountdialog.h" +#include "prefaccounts.h" PrefDialog::PrefDialog(QWidget *parent) : QDialog(parent), @@ -15,8 +16,9 @@ PrefDialog::PrefDialog(QWidget *parent) : connect(ui->sofiaGwAddBtn, SIGNAL(clicked()), this, SLOT(addAccountBtnClicked())); _accDlg = NULL; + /*_pref_accounts = new PrefAccounts(ui);*/ _mod_portaudio = new PrefPortaudio(ui, this); - _mod_sofia = new PrefSofia(ui, this); + /*_mod_sofia = new PrefSofia(ui, this);*/ readConfig(); } @@ -55,6 +57,7 @@ void PrefDialog::changeEvent(QEvent *e) void PrefDialog::readConfig() { + /*_pref_accounts->readConfig();*/ _mod_portaudio->readConfig(); /*_mod_sofia->readConfig();*/ } diff --git a/fscomm/preferences/prefdialog.h b/fscomm/preferences/prefdialog.h index 1c1ee66b04..794131bb89 100644 --- a/fscomm/preferences/prefdialog.h +++ b/fscomm/preferences/prefdialog.h @@ -8,6 +8,7 @@ class PrefPortaudio; class PrefSofia; +class PrefAccounts; class AccountDialog; namespace Ui { @@ -31,9 +32,10 @@ private: void readConfig(); QSettings *_settings; AccountDialog *_accDlg; +/* PrefAccounts *_pref_accounts;*/ Ui::PrefDialog *ui; PrefPortaudio *_mod_portaudio; - PrefSofia *_mod_sofia; +/* PrefSofia *_mod_sofia;*/ }; diff --git a/fscomm/preferences/prefdialog.ui b/fscomm/preferences/prefdialog.ui index 2d8c7c7a26..8ac862430a 100644 --- a/fscomm/preferences/prefdialog.ui +++ b/fscomm/preferences/prefdialog.ui @@ -72,6 +72,9 @@ :/images/pref_accounts.jpg:/images/pref_accounts.jpg + + ItemIsSelectable|ItemIsDragEnabled|ItemIsUserCheckable + @@ -81,6 +84,9 @@ :/images/pref_sip.png:/images/pref_sip.png + + ItemIsSelectable|ItemIsDragEnabled|ItemIsUserCheckable + @@ -134,15 +140,10 @@ - + QAbstractItemView::NoEditTriggers - - - Enabled - - Name