Revision
16412
Author
jmesquita
Date
2010-01-19 23:11:40 -0600 (Tue, 19 Jan 2010)

Log Message

Remove QObject inheritance from Account and add event for account removal.

Modified Paths

Diff

Modified: freeswitch/trunk/fscomm/account.cpp (16411 => 16412)


--- freeswitch/trunk/fscomm/account.cpp	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/account.cpp	2010-01-20 05:11:40 UTC (rev 16412)
@@ -1,6 +1,18 @@
+#include <QtGui>
 #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;
+        }
+    }
 }

Modified: freeswitch/trunk/fscomm/account.h (16411 => 16412)


--- freeswitch/trunk/fscomm/account.h	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/account.h	2010-01-20 05:11:40 UTC (rev 16412)
@@ -1,7 +1,7 @@
 #ifndef ACCOUNT_H
 #define ACCOUNT_H
 
-#include <QObject>
+#include <QString>
 
 #define FSCOMM_GW_STATE_TRYING 0
 #define FSCOMM_GW_STATE_REGISTER 1
@@ -26,20 +26,20 @@
     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

Modified: freeswitch/trunk/fscomm/fshost.cpp (16411 => 16412)


--- freeswitch/trunk/fscomm/fshost.cpp	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/fshost.cpp	2010-01-20 05:11:40 UTC (rev 16412)
@@ -326,8 +326,7 @@
                 QSharedPointer<Account> acc;
                 if (!_accounts.contains(gw))
                 {
-                    Account * accPtr = new Account();
-                    accPtr->setName(gw);
+                    Account * accPtr = new Account(gw);
                     acc = QSharedPointer<Account>(accPtr);
                     _accounts.insert(gw, acc);
                     emit newAccount(acc);
@@ -364,6 +363,11 @@
                     emit accountStateChange(acc);
                 }
             }
+            else if (strcmp(event->subclass_name, "fscomm::acc_removed") == 0)
+            {
+                QSharedPointer<Account> acc = _accounts.take(switch_event_get_header_nil(event, "acc_name"));
+                emit delAccount(acc);
+            }
             else
             {
                 printEventHeaders(event);
@@ -388,6 +392,16 @@
     return status;
 }
 
+QSharedPointer<Account> FSHost::getAccountByUUID(QString uuid)
+{
+    foreach(QSharedPointer<Account> acc, _accounts.values())
+    {
+        if (acc.data()->getUUID() == uuid)
+            return acc;
+    }
+    return QSharedPointer<Account>();
+}
+
 QSharedPointer<Call> FSHost::getCurrentActiveCall()
 {
     foreach(QSharedPointer<Call> call, _active_calls.values())

Modified: freeswitch/trunk/fscomm/fshost.h (16411 => 16412)


--- freeswitch/trunk/fscomm/fshost.h	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/fshost.h	2010-01-20 05:11:40 UTC (rev 16412)
@@ -46,6 +46,7 @@
     QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
     QSharedPointer<Call> getCurrentActiveCall();
     QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
+    QSharedPointer<Account> getAccountByUUID(QString uuid);
 
 protected:
     void run(void);
@@ -60,6 +61,7 @@
     void hungup(QSharedPointer<Call>);
     void accountStateChange(QSharedPointer<Account>);
     void newAccount(QSharedPointer<Account>);
+    void delAccount(QSharedPointer<Account>);
 
 private:
     switch_status_t processBlegEvent(switch_event_t *, QString);

Modified: freeswitch/trunk/fscomm/mainwindow.cpp (16411 => 16412)


--- freeswitch/trunk/fscomm/mainwindow.cpp	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/mainwindow.cpp	2010-01-20 05:11:40 UTC (rev 16412)
@@ -83,6 +83,7 @@
     connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>)));
     connect(&g_FSHost, SIGNAL(accountStateChange(QSharedPointer<Account>)), this, SLOT(accountStateChanged(QSharedPointer<Account>)));
     connect(&g_FSHost, SIGNAL(newAccount(QSharedPointer<Account>)), this, SLOT(accountAdd(QSharedPointer<Account>)));
+    connect(&g_FSHost, SIGNAL(delAccount(QSharedPointer<Account>)), this, SLOT(accountDel(QSharedPointer<Account>)));
     /*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/
 
     connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
@@ -153,6 +154,22 @@
     ui->tableAccounts->horizontalHeader()->setStretchLastSection(true);
 }
 
+void MainWindow::accountDel(QSharedPointer<Account> 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<Account> acc)
 {
     ui->statusBar->showMessage(tr("Account %1 is %2").arg(acc.data()->getName(), acc.data()->getStateName()));

Modified: freeswitch/trunk/fscomm/mainwindow.h (16411 => 16412)


--- freeswitch/trunk/fscomm/mainwindow.h	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/mainwindow.h	2010-01-20 05:11:40 UTC (rev 16412)
@@ -76,6 +76,7 @@
     void recordCall(bool);
     void setDefaultAccount();
     void accountAdd(QSharedPointer<Account>);
+    void accountDel(QSharedPointer<Account>);
     void accountStateChanged(QSharedPointer<Account>);
 
 private:

Modified: freeswitch/trunk/fscomm/preferences/prefaccounts.cpp (16411 => 16412)


--- freeswitch/trunk/fscomm/preferences/prefaccounts.cpp	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/preferences/prefaccounts.cpp	2010-01-20 05:11:40 UTC (rev 16412)
@@ -13,6 +13,11 @@
     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 @@
             _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<Account> 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++;
         }

Modified: freeswitch/trunk/fscomm/preferences/prefaccounts.h (16411 => 16412)


--- freeswitch/trunk/fscomm/preferences/prefaccounts.h	2010-01-19 23:54:32 UTC (rev 16411)
+++ freeswitch/trunk/fscomm/preferences/prefaccounts.h	2010-01-20 05:11:40 UTC (rev 16412)
@@ -4,6 +4,8 @@
 #include <QObject>
 #include "ui_prefdialog.h"
 
+#define FSCOMM_EVENT_ACC_REMOVED "fscomm::acc_removed"
+
 class QSettings;
 class AccountDialog;