]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Remove QObject inheritance from Account and add event for account removal.
authorJoão Mesquita <jmesquita@freeswitch.org>
Wed, 20 Jan 2010 05:11:40 +0000 (05:11 +0000)
committerJoão Mesquita <jmesquita@freeswitch.org>
Wed, 20 Jan 2010 05:11:40 +0000 (05:11 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16412 d0543943-73ff-0310-b7d9-9358b9ac24b2

fscomm/account.cpp
fscomm/account.h
fscomm/fshost.cpp
fscomm/fshost.h
fscomm/mainwindow.cpp
fscomm/mainwindow.h
fscomm/preferences/prefaccounts.cpp
fscomm/preferences/prefaccounts.h

index 13986f4c4bc2df114e051f891882c977a3c1452e..971181842623afbd553e9183c7f5bd28e30c002c 100644 (file)
@@ -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;
+        }
+    }
 }
index 8ebfa579241e3562827526c4452266388ab27a82..ef66e70bd2ef161d41f2b7c825e645b247fe3a67 100644 (file)
@@ -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 @@ 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
index 736af8ed5e4e2680ea3581d4c0f32676d3a4eb88..2eb926f471e9db014f628a0cfecd9669ff936624 100644 (file)
@@ -326,8 +326,7 @@ void FSHost::generalEventHandler(switch_event_t *event)
                 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 @@ void FSHost::generalEventHandler(switch_event_t *event)
                     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 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res)
     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())
index e67d27d2f24fec12187722552097a8f09359f761..74e215197b41671bcd9da710dfa5db3049523367 100644 (file)
@@ -46,6 +46,7 @@ public:
     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 @@ signals:
     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);
index 289a8ad46305f301a50faa4473d0975f5fcfc14e..c58fbd581978a3a7c6f5b44a54dd63d09a23b042 100644 (file)
@@ -83,6 +83,7 @@ MainWindow::MainWindow(QWidget *parent) :
     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 @@ void MainWindow::accountAdd(QSharedPointer<Account> acc)
     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()));
index 9f305b6e16d194486088577216b09b50db82ca84..a895c0876fdb1fa9a812ce74e5fb54210c43b237 100644 (file)
@@ -76,6 +76,7 @@ private slots:
     void recordCall(bool);
     void setDefaultAccount();
     void accountAdd(QSharedPointer<Account>);
+    void accountDel(QSharedPointer<Account>);
     void accountStateChanged(QSharedPointer<Account>);
 
 private:
index 0fed6d973f5effb3c0440c08b26ba49a38396cb7..929b36baea58a295f58da21298999d9d92ce9b96 100644 (file)
@@ -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<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++;
         }
index 08ec5c18da623067e986886a326a154fdf0e147e..7d98b571d32bda2e32001055f41c9b68c93064de 100644 (file)
@@ -4,6 +4,8 @@
 #include <QObject>
 #include "ui_prefdialog.h"
 
+#define FSCOMM_EVENT_ACC_REMOVED "fscomm::acc_removed"
+
 class QSettings;
 class AccountDialog;