From b05dfcb94690e52c877077c4227977f311dd7960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mesquita?= Date: Wed, 20 Jan 2010 05:11:40 +0000 Subject: [PATCH] Remove QObject inheritance from Account and add event for account removal. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16412 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- fscomm/account.cpp | 16 ++++++++++++++-- fscomm/account.h | 10 +++++----- fscomm/fshost.cpp | 18 ++++++++++++++++-- fscomm/fshost.h | 2 ++ fscomm/mainwindow.cpp | 17 +++++++++++++++++ fscomm/mainwindow.h | 1 + fscomm/preferences/prefaccounts.cpp | 16 ++++++++++++++++ fscomm/preferences/prefaccounts.h | 2 ++ 8 files changed, 73 insertions(+), 9 deletions(-) diff --git a/fscomm/account.cpp b/fscomm/account.cpp index 13986f4c4b..9711818426 100644 --- a/fscomm/account.cpp +++ b/fscomm/account.cpp @@ -1,6 +1,18 @@ +#include #include "account.h" -Account::Account(QObject *parent) : - QObject(parent) +Account::Account(QString name) : + _name(name) { + QSettings settings; + settings.beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways"); + foreach(QString g, settings.childGroups()) + { + settings.beginGroup(g); + if(settings.value("gateway/attrs/name").toString() == name) + { + _uuid = g; + break; + } + } } diff --git a/fscomm/account.h b/fscomm/account.h index 8ebfa57924..ef66e70bd2 100644 --- a/fscomm/account.h +++ b/fscomm/account.h @@ -1,7 +1,7 @@ #ifndef ACCOUNT_H #define ACCOUNT_H -#include +#include #define FSCOMM_GW_STATE_TRYING 0 #define FSCOMM_GW_STATE_REGISTER 1 @@ -26,20 +26,20 @@ static QString fscomm_gw_state_names[] = { QString("Not applicable") }; -class Account : public QObject -{ -Q_OBJECT +class Account { public: - explicit Account(QObject *parent = 0); + explicit Account(QString name); 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]; } + QString getUUID() { return _uuid; } private: QString _name; int _state; + QString _uuid; }; #endif // ACCOUNT_H diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index 736af8ed5e..2eb926f471 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -326,8 +326,7 @@ void FSHost::generalEventHandler(switch_event_t *event) QSharedPointer acc; if (!_accounts.contains(gw)) { - Account * accPtr = new Account(); - accPtr->setName(gw); + Account * accPtr = new Account(gw); acc = QSharedPointer(accPtr); _accounts.insert(gw, acc); emit newAccount(acc); @@ -364,6 +363,11 @@ void FSHost::generalEventHandler(switch_event_t *event) emit accountStateChange(acc); } } + else if (strcmp(event->subclass_name, "fscomm::acc_removed") == 0) + { + QSharedPointer acc = _accounts.take(switch_event_get_header_nil(event, "acc_name")); + emit delAccount(acc); + } else { printEventHeaders(event); @@ -388,6 +392,16 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res) return status; } +QSharedPointer FSHost::getAccountByUUID(QString uuid) +{ + foreach(QSharedPointer acc, _accounts.values()) + { + if (acc.data()->getUUID() == uuid) + return acc; + } + return QSharedPointer(); +} + QSharedPointer FSHost::getCurrentActiveCall() { foreach(QSharedPointer call, _active_calls.values()) diff --git a/fscomm/fshost.h b/fscomm/fshost.h index e67d27d2f2..74e215197b 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -46,6 +46,7 @@ public: QSharedPointer getCallByUUID(QString uuid) { return _active_calls.value(uuid); } QSharedPointer getCurrentActiveCall(); QList > getAccounts() { return _accounts.values(); } + QSharedPointer getAccountByUUID(QString uuid); protected: void run(void); @@ -60,6 +61,7 @@ signals: void hungup(QSharedPointer); void accountStateChange(QSharedPointer); void newAccount(QSharedPointer); + void delAccount(QSharedPointer); private: switch_status_t processBlegEvent(switch_event_t *, QString); diff --git a/fscomm/mainwindow.cpp b/fscomm/mainwindow.cpp index 289a8ad463..c58fbd5819 100644 --- a/fscomm/mainwindow.cpp +++ b/fscomm/mainwindow.cpp @@ -83,6 +83,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer)), this, SLOT(callFailed(QSharedPointer))); connect(&g_FSHost, SIGNAL(accountStateChange(QSharedPointer)), this, SLOT(accountStateChanged(QSharedPointer))); connect(&g_FSHost, SIGNAL(newAccount(QSharedPointer)), this, SLOT(accountAdd(QSharedPointer))); + connect(&g_FSHost, SIGNAL(delAccount(QSharedPointer)), this, SLOT(accountDel(QSharedPointer))); /*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/ connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall())); @@ -153,6 +154,22 @@ void MainWindow::accountAdd(QSharedPointer acc) ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); } +void MainWindow::accountDel(QSharedPointer acc) +{ + foreach (QTableWidgetItem *i, ui->tableAccounts->findItems(acc.data()->getName(), Qt::MatchExactly)) + { + if (i->text() == acc.data()->getName()) + { + ui->tableAccounts->removeRow(i->row()); + ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()-1); + ui->tableAccounts->resizeColumnsToContents(); + ui->tableAccounts->resizeRowsToContents(); + ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); + return; + } + } +} + void MainWindow::accountStateChanged(QSharedPointer acc) { ui->statusBar->showMessage(tr("Account %1 is %2").arg(acc.data()->getName(), acc.data()->getStateName())); diff --git a/fscomm/mainwindow.h b/fscomm/mainwindow.h index 9f305b6e16..a895c0876f 100644 --- a/fscomm/mainwindow.h +++ b/fscomm/mainwindow.h @@ -76,6 +76,7 @@ private slots: void recordCall(bool); void setDefaultAccount(); void accountAdd(QSharedPointer); + void accountDel(QSharedPointer); void accountStateChanged(QSharedPointer); private: diff --git a/fscomm/preferences/prefaccounts.cpp b/fscomm/preferences/prefaccounts.cpp index 0fed6d973f..929b36baea 100644 --- a/fscomm/preferences/prefaccounts.cpp +++ b/fscomm/preferences/prefaccounts.cpp @@ -13,6 +13,11 @@ PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) : connect(_ui->sofiaGwEditBtn, SIGNAL(clicked()), this, SLOT(editAccountBtnClicked())); _ui->accountsTable->horizontalHeader()->setStretchLastSection(true); + + if (switch_event_reserve_subclass(FSCOMM_EVENT_ACC_REMOVED) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n"); + } + } void PrefAccounts::addAccountBtnClicked() @@ -86,6 +91,17 @@ void PrefAccounts::remAccountBtnClicked() _settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways"); _settings->remove(item->data(Qt::UserRole).toString()); _settings->endGroup(); + /* Fire event to remove account */ + switch_event_t *event; + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FSCOMM_EVENT_ACC_REMOVED) == SWITCH_STATUS_SUCCESS) { + QSharedPointer acc = g_FSHost.getAccountByUUID(item->data(Qt::UserRole).toString()); + if (!acc.isNull()) + { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "acc_name", acc.data()->getName().toAscii().data()); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "acc_uuid", acc.data()->getUUID().toAscii().data()); + switch_event_fire(&event); + } + } _ui->accountsTable->removeRow(row-offset); offset++; } diff --git a/fscomm/preferences/prefaccounts.h b/fscomm/preferences/prefaccounts.h index 08ec5c18da..7d98b571d3 100644 --- a/fscomm/preferences/prefaccounts.h +++ b/fscomm/preferences/prefaccounts.h @@ -4,6 +4,8 @@ #include #include "ui_prefdialog.h" +#define FSCOMM_EVENT_ACC_REMOVED "fscomm::acc_removed" + class QSettings; class AccountDialog;