Revision
14549
Author
jmesquita
Date
2009-08-18 00:19:23 -0500 (Tue, 18 Aug 2009)

Log Message

Realtime Statistics is now know to be working. Bugs should be reporting. Now we are able to filter channels by making selection to calls.

Modified Paths

Added Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.h (14548 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.h	2009-08-17 23:03:49 UTC (rev 14548)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.h	2009-08-18 05:19:23 UTC (rev 14549)
@@ -56,6 +56,9 @@
     int channelCount() { return _channels.count(); }
     QList<Channel *> getChannels() { return _channels.values(); }
     Channel * getChannel(QString uuid) { return _channels.value(uuid, NULL); }
+    Channel * getInactiveChannel(QString uuid) { return _inactive_channels.value(uuid, NULL); }
+    Call * getCall(QString uuid) { return _calls.value(uuid, NULL); }
+    Call * getInactiveCall(QString uuid) { return _inactive_calls.value(uuid, NULL); }
 private slots:
     void processEvent(ESLevent);
 signals:

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro (14548 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro	2009-08-17 23:03:49 UTC (rev 14548)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro	2009-08-18 05:19:23 UTC (rev 14549)
@@ -29,11 +29,13 @@
 HEADERS = consoleplugin.h \
     sortfilterproxymodel.h \
     consoletabwidget.h \
-    realtimestatisticsdialog.h
+    realtimestatisticsdialog.h \
+    realtimemodels.h
 SOURCES = consoleplugin.cpp \
     sortfilterproxymodel.cpp \
     consoletabwidget.cpp \
-    realtimestatisticsdialog.cpp
+    realtimestatisticsdialog.cpp \
+    realtimemodels.cpp
 FORMS += centralWidget.ui \
     console_settings.ui \
     consoletabwidget.ui \

Added: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.cpp (0 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.cpp	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.cpp	2009-08-18 05:19:23 UTC (rev 14549)
@@ -0,0 +1,22 @@
+#include <QtGui>
+#include "realtimemodels.h"
+
+ChannelSortModel::ChannelSortModel(QObject *parent) :
+        QSortFilterProxyModel(parent)
+{}
+
+void ChannelSortModel::setUUIDFilter(QList<QString> uuid_list)
+{
+    _uuid_list = uuid_list;
+    invalidateFilter();
+}
+
+bool ChannelSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+    QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
+
+    if (_uuid_list.isEmpty())
+        return true;
+
+    return (_uuid_list.contains(sourceModel()->data(index0, Qt::UserRole).toString()));
+}

Added: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.h (0 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.h	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimemodels.h	2009-08-18 05:19:23 UTC (rev 14549)
@@ -0,0 +1,19 @@
+#ifndef REALTIMEMODELS_H
+#define REALTIMEMODELS_H
+
+#include <QSortFilterProxyModel>
+
+class ChannelSortModel : public QSortFilterProxyModel {
+
+    Q_OBJECT
+
+public:
+    ChannelSortModel(QObject *parent = 0);
+    void setUUIDFilter(QList<QString> uuid);
+
+protected:
+     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+    QList<QString> _uuid_list;
+};
+
+#endif // REALTIMEMODELS_H

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.cpp (14548 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.cpp	2009-08-17 23:03:49 UTC (rev 14548)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.cpp	2009-08-18 05:19:23 UTC (rev 14549)
@@ -2,6 +2,7 @@
 #include "realtimestatisticsdialog.h"
 #include "ui_realtimestatisticsdialog.h"
 #include "monitorstatemachine.h"
+#include "realtimemodels.h"
 
 RealtimeStatisticsDialog::RealtimeStatisticsDialog(QWidget *parent, MonitorStateMachine *sm) :
     QDialog(parent),
@@ -17,16 +18,31 @@
             this, SLOT(channelDestroy(Channel*)));
     connect(sm, SIGNAL(channelStateChanged(Channel*)),
             this, SLOT(channelStateChanged(Channel*)));
-    connect(m_ui->listActiveChannels, SIGNAL(itemClicked(QListWidgetItem*)),
-            this, SLOT(channelSelected(QListWidgetItem*)));
+    connect(m_ui->listActiveChannels, SIGNAL(clicked(QModelIndex)),
+            this, SLOT(activeChannelSelected(QModelIndex)));
+    connect(m_ui->listInactiveChannels, SIGNAL(clicked(QModelIndex)),
+            this, SLOT(inactiveChannelSelected(QModelIndex)));
 
     /* Connect call stuff */
     connect(sm, SIGNAL(callCreated(Call*)),
             this, SLOT(callCreate(Call*)));
     connect(sm, SIGNAL(callDestroyed(Call*)),
             this, SLOT(callDestroy(Call*)));
+    connect(m_ui->listActiveCalls, SIGNAL(itemSelectionChanged()),
+            this, SLOT(activeCallSelectionChanged()));
+    connect(m_ui->listInactiveCalls, SIGNAL(itemSelectionChanged()),
+            this, SLOT(inactiveCallSelectionChanged()));
 
-    delete m_ui->tab_2;
+    _channel_model = new QStandardItemModel(this);
+    _channel_sort_model = new ChannelSortModel(this);
+    _channel_sort_model->setSourceModel(_channel_model);
+    m_ui->listActiveChannels->setModel(_channel_sort_model);
+
+    _inactive_channel_model = new QStandardItemModel(this);
+    _inactive_channel_sort_model = new ChannelSortModel(this);
+    _inactive_channel_sort_model->setSourceModel(_inactive_channel_model);
+    m_ui->listInactiveChannels->setModel(_inactive_channel_sort_model);
+
 }
 
 RealtimeStatisticsDialog::~RealtimeStatisticsDialog()
@@ -52,9 +68,9 @@
     if (!ch)
         return;
 
-    QListWidgetItem *item = new QListWidgetItem(QString("%1 - %2").arg(ch->getUUID(), ch->getHeader("Channel-State")),
-                                                m_ui->listActiveChannels);
-    item->setData(Qt::UserRole, ch->getUUID());
+    QStandardItem *item = new QStandardItem(QString("%1 - %2").arg(ch->getUUID(), ch->getHeader("Channel-State")));
+    item->setData(ch->getUUID(), Qt::UserRole);
+    _channel_model->insertRow(0, item);
 }
 
 void RealtimeStatisticsDialog::channelDestroy(Channel *ch)
@@ -63,14 +79,17 @@
     if (!ch)
         return;
 
-    for (int i = 0; i < m_ui->listActiveChannels->count(); i++)
+    QModelIndex selectedIndex = m_ui->listActiveChannels->currentIndex();
+
+    foreach (QStandardItem *item, _channel_model->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive))
     {
-        if (m_ui->listActiveChannels->item(i)->data(Qt::UserRole) == ch->getUUID())
+        if (item->data(Qt::UserRole) == ch->getUUID())
         {
-            if (m_ui->listActiveChannels->currentItem() == m_ui->listActiveChannels->item(i))
+            if (selectedIndex.isValid() && selectedIndex.data(Qt::UserRole) == ch->getUUID())
                 m_ui->listActiveVariables->clear();
 
-            delete m_ui->listActiveChannels->item(i);
+            _channel_model->takeRow(item->index().row());
+            _inactive_channel_model->insertRow(0, item);
         }
     }
 }
@@ -81,22 +100,22 @@
     if (!ch)
         return;
 
-    for (int i = 0; i < m_ui->listActiveChannels->count(); i++)
+    foreach (QStandardItem *item, _channel_model->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive))
     {
-        if (m_ui->listActiveChannels->item(i)->data(Qt::UserRole).toString() == ch->getUUID())
-            if (m_ui->listActiveChannels->currentItem() == m_ui->listActiveChannels->item(i))
+        if (item->data(Qt::UserRole) == ch->getUUID())
+            if (_channel_model->itemFromIndex(m_ui->listActiveChannels->currentIndex()) == item)
             {
-                channelSelected(m_ui->listActiveChannels->item(i));
+                activeChannelSelected(_channel_model->indexFromItem(item));
             }
-        m_ui->listActiveChannels->item(i)->setText(QString("%1 - %2").arg(ch->getUUID(), ch->getHeader("Channel-State")));
+        item->setText(QString("%1 - %2").arg(ch->getUUID(), ch->getHeader("Channel-State")));
     }
 }
 
-void RealtimeStatisticsDialog::channelSelected(QListWidgetItem *item)
+void RealtimeStatisticsDialog::activeChannelSelected(QModelIndex index)
 {
     m_ui->listActiveVariables->clear();
 
-    Channel * ch = _sm->getChannel(item->data(Qt::UserRole).toString());
+    Channel * ch = _sm->getChannel(index.data(Qt::UserRole).toString());
     if (!ch)
         return;
 
@@ -106,6 +125,54 @@
     }
 }
 
+void RealtimeStatisticsDialog::inactiveChannelSelected(QModelIndex index)
+{
+    m_ui->listInactiveVariables->clear();
+
+    Channel * ch = _sm->getInactiveChannel(index.data(Qt::UserRole).toString());
+    if (!ch)
+        return;
+
+    foreach (QString key, ch->getVariables().keys())
+    {
+        m_ui->listInactiveVariables->addItem(QString("%1 = %2").arg(key, ch->getVariables().value(key)));
+    }
+}
+
+void RealtimeStatisticsDialog::activeCallSelectionChanged()
+{
+    QList<QListWidgetItem *> selection = m_ui->listActiveCalls->selectedItems();
+    QList<QString> uuids;
+
+    foreach(QListWidgetItem *item, selection)
+    {
+        Call * call = _sm->getCall(item->data(Qt::UserRole).toString());
+        if (call)
+        {
+            uuids.append(call->getCallerUUID());
+            uuids.append(call->getOriginateeUUID());
+        }
+    }
+    _channel_sort_model->setUUIDFilter(uuids);
+}
+
+void RealtimeStatisticsDialog::inactiveCallSelectionChanged()
+{
+    QList<QListWidgetItem *> selection = m_ui->listInactiveCalls->selectedItems();
+    QList<QString> uuids;
+
+    foreach(QListWidgetItem *item, selection)
+    {
+        Call * call = _sm->getInactiveCall(item->data(Qt::UserRole).toString());
+        if (call)
+        {
+            uuids.append(call->getCallerUUID());
+            uuids.append(call->getOriginateeUUID());
+        }
+    }
+    _inactive_channel_sort_model->setUUIDFilter(uuids);
+}
+
 void RealtimeStatisticsDialog::callCreate(Call *c)
 {
     /* Sanity checking */
@@ -114,9 +181,9 @@
     QString caller_cidnum = c->getCallerChannel()->getHeader("Caller-Caller-ID-Number");
     QString caller_cidname = c->getCallerChannel()->getHeader("variable_effective_caller_id_name");
     QString orig_cidnum = c->getCallerChannel()->getHeader("Caller-Destination-Number");
-    QListWidgetItem *item = new QListWidgetItem(QString("%1(%2) <-> %3").arg(caller_cidnum,
-                                                                             caller_cidname,
-                                                                             orig_cidnum), m_ui->listActiveCalls);
+    QString caller_uuid = c->getCallerUUID();
+    QString callTitle = QString("%1(%2) <-> %3 (Caller UUID: %4)").arg(caller_cidnum, caller_cidname, orig_cidnum, caller_uuid);
+    QListWidgetItem *item = new QListWidgetItem(callTitle, m_ui->listActiveCalls);
     item->setData(Qt::UserRole, c->getCallerUUID());
 }
 
@@ -129,6 +196,9 @@
     for (int i = 0; i < m_ui->listActiveCalls->count(); i++)
     {
         if (m_ui->listActiveCalls->item(i)->data(Qt::UserRole) == c->getCallerUUID())
-            delete m_ui->listActiveCalls->item(i);
+        {
+            QListWidgetItem *item = m_ui->listActiveCalls->takeItem(i);
+            m_ui->listInactiveCalls->addItem(item);
+        }
     }
 }

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.h (14548 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.h	2009-08-17 23:03:49 UTC (rev 14548)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.h	2009-08-18 05:19:23 UTC (rev 14549)
@@ -1,17 +1,18 @@
 #ifndef REALTIMESTATISTICSDIALOG_H
 #define REALTIMESTATISTICSDIALOG_H
 
-#include <QtGui/QDialog>
+#include <QtGui>
 
 namespace Ui {
     class RealtimeStatisticsDialog;
 }
 
-class QListWidgetItem;
 class MonitorStateMachine;
 class Channel;
 class Call;
+class ChannelSortModel;
 
+
 class RealtimeStatisticsDialog : public QDialog {
     Q_OBJECT
 public:
@@ -26,13 +27,20 @@
     void channelCreate(Channel *);
     void channelDestroy(Channel *);
     void channelStateChanged(Channel *);
-    void channelSelected(QListWidgetItem *);
+    void activeChannelSelected(QModelIndex);
+    void inactiveChannelSelected(QModelIndex);
+    void activeCallSelectionChanged();
+    void inactiveCallSelectionChanged();
     void callCreate(Call *);
     void callDestroy(Call *);
 
 private:
     Ui::RealtimeStatisticsDialog *m_ui;
     MonitorStateMachine *_sm;
+    QStandardItemModel *_channel_model;
+    ChannelSortModel *_channel_sort_model;
+    QStandardItemModel *_inactive_channel_model;
+    ChannelSortModel *_inactive_channel_sort_model;
 };
 
 #endif // REALTIMESTATISTICSDIALOG_H

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.ui (14548 => 14549)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.ui	2009-08-17 23:03:49 UTC (rev 14548)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.ui	2009-08-18 05:19:23 UTC (rev 14549)
@@ -36,7 +36,7 @@
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout">
             <item>
-             <widget class="QListWidget" name="listActiveChannels">
+             <widget class="QListView" name="listActiveChannels">
               <property name="editTriggers">
                <set>QAbstractItemView::NoEditTriggers</set>
               </property>
@@ -62,6 +62,9 @@
               <property name="alternatingRowColors">
                <bool>true</bool>
               </property>
+              <property name="selectionMode">
+               <enum>QAbstractItemView::ExtendedSelection</enum>
+              </property>
              </widget>
             </item>
            </layout>
@@ -107,7 +110,7 @@
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout_9">
             <item>
-             <widget class="QListWidget" name="listInactiveChannels">
+             <widget class="QListView" name="listInactiveChannels">
               <property name="editTriggers">
                <set>QAbstractItemView::NoEditTriggers</set>
               </property>
@@ -133,6 +136,9 @@
               <property name="alternatingRowColors">
                <bool>true</bool>
               </property>
+              <property name="selectionMode">
+               <enum>QAbstractItemView::ExtendedSelection</enum>
+              </property>
              </widget>
             </item>
            </layout>