提交 fb79c1bf authored 作者: João Mesquita's avatar João Mesquita

Add all the new stuff to persist accounts and sofia configs. Still not working,…

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
上级 72d143d0
......@@ -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 \
......
......@@ -9,6 +9,8 @@
</global_settings>
<profiles>
<profile name="softphone">
<gateways>
</gateways>
<settings>
<param name="user-agent-string" value="${user-agent-string)"/>
<param name="debug" value="${debug}"/>
......
......@@ -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");
......
......@@ -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<QString, Call*> _active_calls;
QHash<QString, QString> _bleg_uuids;
......
......@@ -33,6 +33,8 @@
#include <QString>
#include <QtGui>
#include <QDir>
#include <QDomDocument>
#include <QDomNodeList>
#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)
{
......
......@@ -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;
};
......
#include <QSettings>
#include <QtGui>
#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<QTableWidgetSelectionRange> 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();
......
......@@ -17,6 +17,8 @@ public:
private slots:
void writeConfig();
void addExtraParam();
void remExtraParam();
protected:
void changeEvent(QEvent *e);
......
#include <QtGui>
#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();
}
#ifndef PREFACCOUNTS_H
#define PREFACCOUNTS_H
#include <QObject>
#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
......@@ -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();*/
}
......@@ -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;*/
};
......
......@@ -72,6 +72,9 @@
<iconset resource="../resources.qrc">
<normaloff>:/images/pref_accounts.jpg</normaloff>:/images/pref_accounts.jpg</iconset>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsUserCheckable</set>
</property>
</item>
<item>
<property name="text">
......@@ -81,6 +84,9 @@
<iconset resource="../resources.qrc">
<normaloff>:/images/pref_sip.png</normaloff>:/images/pref_sip.png</iconset>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsUserCheckable</set>
</property>
</item>
<item>
<property name="text">
......@@ -134,15 +140,10 @@
<widget class="QWidget" name="accountsPage">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QTableWidget" name="sofiaGwListWidget">
<widget class="QTableWidget" name="accountsTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<column>
<property name="text">
<string>Enabled</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论