diff --git a/fscomm/FSComm.pro b/fscomm/FSComm.pro index 52291ee8dc..4bb59b669a 100644 --- a/fscomm/FSComm.pro +++ b/fscomm/FSComm.pro @@ -30,7 +30,8 @@ SOURCES += main.cpp \ preferences/prefportaudio.cpp \ preferences/prefsofia.cpp \ preferences/accountdialog.cpp \ - preferences/prefaccounts.cpp + preferences/prefaccounts.cpp \ + account.cpp HEADERS += mainwindow.h \ fshost.h \ call.h \ @@ -39,7 +40,8 @@ HEADERS += mainwindow.h \ preferences/prefportaudio.h \ preferences/prefsofia.h \ preferences/accountdialog.h \ - preferences/prefaccounts.h + preferences/prefaccounts.h \ + account.h FORMS += mainwindow.ui \ preferences/prefdialog.ui \ preferences/accountdialog.ui diff --git a/fscomm/account.cpp b/fscomm/account.cpp new file mode 100644 index 0000000000..13986f4c4b --- /dev/null +++ b/fscomm/account.cpp @@ -0,0 +1,6 @@ +#include "account.h" + +Account::Account(QObject *parent) : + QObject(parent) +{ +} diff --git a/fscomm/account.h b/fscomm/account.h new file mode 100644 index 0000000000..8ebfa57924 --- /dev/null +++ b/fscomm/account.h @@ -0,0 +1,45 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include + +#define FSCOMM_GW_STATE_TRYING 0 +#define FSCOMM_GW_STATE_REGISTER 1 +#define FSCOMM_GW_STATE_REGED 2 +#define FSCOMM_GW_STATE_UNREGED 3 +#define FSCOMM_GW_STATE_UNREGISTER 4 +#define FSCOMM_GW_STATE_FAILED 5 +#define FSCOMM_GW_STATE_FAIL_WAIT 6 +#define FSCOMM_GW_STATE_EXPIRED 7 +#define FSCOMM_GW_STATE_NOREG 8 + + +static QString fscomm_gw_state_names[] = { + QString("Trying"), + QString("Registering"), + QString("Registered"), + QString("Un-Registered"), + QString("Un-Registering"), + QString("Failed"), + QString("Failed"), + QString("Expired"), + QString("Not applicable") +}; + +class Account : public QObject +{ +Q_OBJECT +public: + explicit Account(QObject *parent = 0); + void setName(QString name) { _name = name; } + QString getName() { return _name; } + void setState(int state) { _state = state; } + int getState() { return _state; } + QString getStateName() { return fscomm_gw_state_names[_state]; } + +private: + QString _name; + int _state; +}; + +#endif // ACCOUNT_H diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index eb8b9fd652..39b1b72afd 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -43,6 +43,7 @@ FSHost::FSHost(QObject *parent) : switch_core_set_globals(); qRegisterMetaType >("QSharedPointer"); + qRegisterMetaType >("QSharedPointer"); } @@ -322,24 +323,46 @@ void FSHost::generalEventHandler(switch_event_t *event) { QString state = switch_event_get_header_nil(event, "State"); QString gw = switch_event_get_header_nil(event, "Gateway"); - if (state == "TRYING") - emit gwStateChange(gw, FSCOMM_GW_STATE_TRYING); - else if (state == "REGISTER") - emit gwStateChange(gw, FSCOMM_GW_STATE_REGISTER); - else if (state == "REGED") - emit gwStateChange(gw, FSCOMM_GW_STATE_REGED); - else if (state == "UNREGED") - emit gwStateChange(gw, FSCOMM_GW_STATE_UNREGED); - else if (state == "UNREGISTER") - emit gwStateChange(gw, FSCOMM_GW_STATE_UNREGISTER); - else if (state =="FAILED") - emit gwStateChange(gw, FSCOMM_GW_STATE_FAILED); - else if (state == "FAIL_WAIT") - emit gwStateChange(gw, FSCOMM_GW_STATE_FAIL_WAIT); - else if (state == "EXPIRED") - emit gwStateChange(gw, FSCOMM_GW_STATE_EXPIRED); - else if (state == "NOREG") - emit gwStateChange(gw, FSCOMM_GW_STATE_NOREG); + QSharedPointer acc; + if (!_accounts.contains(gw)) + { + Account * accPtr = new Account(); + accPtr->setName(gw); + acc = QSharedPointer(accPtr); + _accounts.insert(gw, acc); + emit newAccount(acc); + } + else + acc = _accounts.value(gw); + + if (state == "TRYING") { + acc.data()->setState(FSCOMM_GW_STATE_TRYING); + emit accountStateChange(acc); + } else if (state == "REGISTER") { + acc.data()->setState(FSCOMM_GW_STATE_REGISTER); + emit accountStateChange(acc); + } else if (state == "REGED") { + acc.data()->setState(FSCOMM_GW_STATE_REGED); + emit accountStateChange(acc); + } else if (state == "UNREGED") { + acc.data()->setState(FSCOMM_GW_STATE_UNREGED); + emit accountStateChange(acc); + } else if (state == "UNREGISTER") { + acc.data()->setState(FSCOMM_GW_STATE_UNREGISTER); + emit accountStateChange(acc); + } else if (state =="FAILED") { + acc.data()->setState(FSCOMM_GW_STATE_FAILED); + emit accountStateChange(acc); + } else if (state == "FAIL_WAIT") { + acc.data()->setState(FSCOMM_GW_STATE_FAIL_WAIT); + emit accountStateChange(acc); + } else if (state == "EXPIRED") { + acc.data()->setState(FSCOMM_GW_STATE_EXPIRED); + emit accountStateChange(acc); + } else if (state == "NOREG") { + acc.data()->setState(FSCOMM_GW_STATE_NOREG); + emit accountStateChange(acc); + } } else { diff --git a/fscomm/fshost.h b/fscomm/fshost.h index cb172f324d..e67d27d2f2 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -34,29 +34,7 @@ #include #include #include "call.h" - -#define FSCOMM_GW_STATE_TRYING 0 -#define FSCOMM_GW_STATE_REGISTER 1 -#define FSCOMM_GW_STATE_REGED 2 -#define FSCOMM_GW_STATE_UNREGED 3 -#define FSCOMM_GW_STATE_UNREGISTER 4 -#define FSCOMM_GW_STATE_FAILED 5 -#define FSCOMM_GW_STATE_FAIL_WAIT 6 -#define FSCOMM_GW_STATE_EXPIRED 7 -#define FSCOMM_GW_STATE_NOREG 8 - - -static const char *fscomm_gw_state_names[] = { - "TRYING", - "REGISTER", - "REGED", - "UNREGED", - "UNREGISTER", - "FAILED", - "FAIL_WAIT", - "EXPIRED", - "NOREG" -}; +#include "account.h" class FSHost : public QThread { @@ -67,7 +45,7 @@ public: void generalEventHandler(switch_event_t *event); QSharedPointer getCallByUUID(QString uuid) { return _active_calls.value(uuid); } QSharedPointer getCurrentActiveCall(); - QString getGwStateName(int id) { return fscomm_gw_state_names[id]; } + QList > getAccounts() { return _accounts.values(); } protected: void run(void); @@ -80,7 +58,8 @@ signals: void newOutgoingCall(QSharedPointer); void callFailed(QSharedPointer); void hungup(QSharedPointer); - void gwStateChange(QString, int); + void accountStateChange(QSharedPointer); + void newAccount(QSharedPointer); private: switch_status_t processBlegEvent(switch_event_t *, QString); @@ -88,6 +67,7 @@ private: void createFolders(); void printEventHeaders(switch_event_t *event); QHash > _active_calls; + QHash > _accounts; QHash _bleg_uuids; }; diff --git a/fscomm/main.cpp b/fscomm/main.cpp index 9f8c461c7e..b86dc11217 100644 --- a/fscomm/main.cpp +++ b/fscomm/main.cpp @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) QObject::connect(&g_FSHost, SIGNAL(ready()), splash, SLOT(close())); MainWindow w; QObject::connect(&g_FSHost, SIGNAL(ready()), &w, SLOT(show())); + QObject::connect(&g_FSHost, SIGNAL(ready()), &w, SLOT(print())); g_FSHost.start(); return a.exec(); } diff --git a/fscomm/mainwindow.cpp b/fscomm/mainwindow.cpp index e3113a9870..c7060b20c3 100644 --- a/fscomm/mainwindow.cpp +++ b/fscomm/mainwindow.cpp @@ -81,7 +81,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(&g_FSHost, SIGNAL(hungup(QSharedPointer)), this, SLOT(hungup(QSharedPointer))); connect(&g_FSHost, SIGNAL(newOutgoingCall(QSharedPointer)), this, SLOT(newOutgoingCall(QSharedPointer))); connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer)), this, SLOT(callFailed(QSharedPointer))); - connect(&g_FSHost, SIGNAL(gwStateChange(QString,int)), this, SLOT(gwStateChanged(QString,int))); + connect(&g_FSHost, SIGNAL(accountStateChange(QSharedPointer)), this, SLOT(accountStateChanged(QSharedPointer))); + connect(&g_FSHost, SIGNAL(newAccount(QSharedPointer)), this, SLOT(accountAdd(QSharedPointer))); /*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/ connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall())); @@ -92,6 +93,11 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered())); connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); + connect(ui->actionSetDefaultAccount, SIGNAL(triggered(bool)), this, SLOT(setDefaultAccount())); + + /* Set the context menus */ + ui->tableAccounts->addAction(ui->actionSetDefaultAccount); + } MainWindow::~MainWindow() @@ -102,6 +108,20 @@ MainWindow::~MainWindow() g_FSHost.wait(); } +void MainWindow::setDefaultAccount() +{ + QString accName = ui->tableAccounts->item(ui->tableAccounts->selectedRanges()[0].topRow(), 0)->text(); + + if (accName.isEmpty()) + return; + + QSettings settings; + settings.beginGroup("FreeSWITCH/conf/globals"); + switch_core_set_variable("default_gateway", accName.toAscii().data()); + settings.setValue("default_gateway", accName); + settings.endGroup(); +} + void MainWindow::prefTriggered() { if (!preferences) @@ -118,29 +138,32 @@ void MainWindow::coreLoadingError(QString err) QApplication::exit(255); } -void MainWindow::gwStateChanged(QString gw, int state) +void MainWindow::accountAdd(QSharedPointer acc) { - ui->statusBar->showMessage(tr("Account %1 is %2").arg(gw, g_FSHost.getGwStateName(state))); - - /* TODO: This should be placed somewhere else when the config handler is here... */ - QList match = ui->tableAccounts->findItems(gw, Qt::MatchExactly); - if (match.isEmpty()) - { - /* Create the damn thing */ - ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()+1); - QTableWidgetItem *gwField = new QTableWidgetItem(gw); - QTableWidgetItem *stField = new QTableWidgetItem(g_FSHost.getGwStateName(state)); - ui->tableAccounts->setItem(0,0,gwField); - ui->tableAccounts->setItem(0,1,stField); - ui->tableAccounts->resizeColumnsToContents(); - return; - } - - QTableWidgetItem *gwField = match.at(0); - QTableWidgetItem *stField = ui->tableAccounts->item(gwField->row(),1); - stField->setText(g_FSHost.getGwStateName(state)); + ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()+1); + QTableWidgetItem *gwField = new QTableWidgetItem(acc.data()->getName()); + QTableWidgetItem *stField = new QTableWidgetItem(acc.data()->getStateName()); + ui->tableAccounts->setItem(ui->tableAccounts->rowCount()-1,0,gwField); + ui->tableAccounts->setItem(ui->tableAccounts->rowCount()-1,1,stField); ui->tableAccounts->resizeColumnsToContents(); + ui->tableAccounts->resizeRowsToContents(); + ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); +} +void MainWindow::accountStateChanged(QSharedPointer acc) +{ + ui->statusBar->showMessage(tr("Account %1 is %2").arg(acc.data()->getName(), acc.data()->getStateName())); + foreach (QTableWidgetItem *i, ui->tableAccounts->findItems(acc.data()->getName(), Qt::MatchExactly)) + { + if (i->text() == acc.data()->getName()) + { + ui->tableAccounts->item(i->row(), 1)->setText(acc.data()->getStateName()); + ui->tableAccounts->resizeColumnsToContents(); + ui->tableAccounts->resizeRowsToContents(); + ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); + return; + } + } } void MainWindow::dialDTMF(QString dtmf) diff --git a/fscomm/mainwindow.h b/fscomm/mainwindow.h index 0e9dbd69a0..9f305b6e16 100644 --- a/fscomm/mainwindow.h +++ b/fscomm/mainwindow.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "preferences/prefdialog.h" namespace Ui { @@ -60,7 +61,6 @@ private slots: void showAbout(); void prefTriggered(); void coreLoadingError(QString); - void gwStateChanged(QString, int); void dialDTMF(QString); void callListDoubleClick(QListWidgetItem *); void makeCall(); @@ -74,6 +74,9 @@ private slots: void hungup(QSharedPointer); void callFailed(QSharedPointer); void recordCall(bool); + void setDefaultAccount(); + void accountAdd(QSharedPointer); + void accountStateChanged(QSharedPointer); private: Ui::MainWindow *ui; diff --git a/fscomm/mainwindow.ui b/fscomm/mainwindow.ui index 594f272192..819430b586 100644 --- a/fscomm/mainwindow.ui +++ b/fscomm/mainwindow.ui @@ -269,6 +269,9 @@ + + Qt::ActionsContextMenu + QAbstractItemView::NoEditTriggers @@ -371,6 +374,14 @@ About + + + Set Default Account + + + Set the default account for dialing out. + +