Revision
14582
Author
jmesquita
Date
2009-08-21 00:41:14 -0500 (Fri, 21 Aug 2009)

Log Message

Change the model used on the console listview. Make loglevel changeable.

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.cpp (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.cpp	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.cpp	2009-08-21 05:41:14 UTC (rev 14582)
@@ -279,7 +279,6 @@
     if (esl_connect(handle, _host->toAscii(), _port->toInt(), _pass->toAscii()) == ESL_SUCCESS)
     {
         events("plain", "all");
-        send("log 7");
         emit connected();
     }
 

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.h (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.h	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/eslconnection.h	2009-08-21 05:41:14 UTC (rev 14582)
@@ -75,7 +75,6 @@
     //int sendEvent(ESLevent *send_me);
     ESLevent *recvEvent();
     ESLevent *recvEventTimed(int ms);
-    bool setConsoleLogLevel(int);
     /*void api(QString cmd);*/
     ESLevent* bgapi(QString cmd);
     void send(QString cmd);
@@ -94,6 +93,7 @@
     int setEventLock(const char *val);
     int disconnect(void);
     QString getName();
+    bool setConsoleLogLevel(int);
 signals:
     void connected(void);
     void disconnected(void);

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.cpp (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.cpp	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/monitorstatemachine.cpp	2009-08-21 05:41:14 UTC (rev 14582)
@@ -165,9 +165,15 @@
         Event *event = new Event(e._headers);
         Channel * chan = _channels.value(event_uuid, NULL);
         if (!chan)
+        {
             chan = _inactive_channels.value(event_uuid, NULL);
+            return;
+        }
         if (!chan)
+        {
             qDebug() << QString("Event %1 has no uuid.").arg(e.getType());
+            return;
+        }
         chan->addEvent(event);
         emit newEvent(chan, event);
     }

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp	2009-08-21 05:41:14 UTC (rev 14582)
@@ -12,12 +12,17 @@
     findNext(false)
 {
     m_ui->setupUi(this);
-    sourceModel = new QStandardItemModel(this);
+    sourceModel = new ConsoleModel(this);
     model = new SortFilterProxyModel(this);
     model->setSourceModel(sourceModel);
     model->setFilterKeyColumn(0);
     m_ui->consoleListView->setModel(model);
 
+    QObject::connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
+                     this, SLOT(setConditionalScroll()));
+    QObject::connect(sourceModel, SIGNAL(layoutChanged()),
+                     this, SLOT(conditionalScroll()));
+
     QObject::connect(m_ui->btnSend, SIGNAL(clicked()),
                      this, SLOT(cmdSendClicked()));
     QObject::connect(m_ui->lineCmd, SIGNAL(textChanged(QString)),
@@ -36,6 +41,8 @@
                      this, SLOT(checkInfo(bool)));
     QObject::connect(m_ui->checkDebug, SIGNAL(clicked(bool)),
                      this, SLOT(checkDebug(bool)));
+    QObject::connect(m_ui->comboLogLevel, SIGNAL(currentIndexChanged(int)),
+                     this, SLOT(changeLogLevel(int)));
 
     QObject::connect(m_ui->btnFilterClear, SIGNAL(clicked()),
                      this, SLOT(filterClear()));
@@ -61,17 +68,25 @@
     msm = new MonitorStateMachine();
     msm->addESLconnection(esl);
 
-    scrollTimer = new QBasicTimer;
-    scrollTimer->start(0, this);
-    /* Number of items to be inserted */
-    batch = 40;
 }
 
 ConsoleTabWidget::~ConsoleTabWidget()
 {
+    writeSettings();
     delete m_ui;
 }
 
+void ConsoleTabWidget::setConditionalScroll()
+{
+    autoScroll = (m_ui->consoleListView->verticalScrollBar()->maximum() == m_ui->consoleListView->verticalScrollBar()->value());
+}
+
+void ConsoleTabWidget::conditionalScroll()
+{
+    if (autoScroll)
+        m_ui->consoleListView->scrollToBottom();
+}
+
 void ConsoleTabWidget::clearConsoleContents()
 {
     sourceModel->clear();
@@ -89,25 +104,6 @@
     }
 }
 
-void ConsoleTabWidget::timerEvent(QTimerEvent *e)
-{
-    bool scroll = false;
-    if (e->timerId() == scrollTimer->timerId())
-    {
-        if (m_ui->consoleListView->verticalScrollBar()->value() == m_ui->consoleListView->verticalScrollBar()->maximum())
-            scroll = true;
-
-        int inserted_items = 0;
-        while( !_list_items.isEmpty() && inserted_items < batch)
-        {
-            sourceModel->appendRow(_list_items.takeFirst());
-            inserted_items++;
-        }
-        if (scroll)
-            m_ui->consoleListView->scrollToBottom();
-    }
-}
-
 void ConsoleTabWidget::filterClear()
 {
     m_ui->lineFilter->clear();
@@ -131,15 +127,18 @@
 {
     m_ui->btnSend->setEnabled(true);
     m_ui->lineCmd->setEnabled(true);
+    m_ui->comboLogLevel->setEnabled(true);
     QStandardItem *item = new QStandardItem(tr("Connected!"));
     item->setData(ESL_LOG_LEVEL_EMERG, Qt::UserRole);
     addNewConsoleItem(item);
+    readSettings();
 }
 
 void ConsoleTabWidget::disconnected()
 {
     m_ui->btnSend->setEnabled(false);
     m_ui->lineCmd->setEnabled(false);
+    m_ui->comboLogLevel->setEnabled(false);
     QStandardItem *item = new QStandardItem(tr("Disconnected!"));
     item->setData(ESL_LOG_LEVEL_EMERG, Qt::UserRole);
     addNewConsoleItem(item);
@@ -149,6 +148,7 @@
 {
     m_ui->btnSend->setEnabled(false);
     m_ui->lineCmd->setEnabled(false);
+    m_ui->comboLogLevel->setEnabled(false);
     QStandardItem *item = new QStandardItem(tr("Connection Failed! Reason: %1").arg(reason));
     item->setData(ESL_LOG_LEVEL_EMERG, Qt::UserRole);
     addNewConsoleItem(item);
@@ -175,7 +175,6 @@
             addNewConsoleItem(item);
         }
     }
-    //delete event;
 }
 
 void ConsoleTabWidget::addNewConsoleItem(QStandardItem *item)
@@ -185,8 +184,7 @@
     QPalette palette = settings.value(QString("log-level-%1-palette").arg(item->data(Qt::UserRole).toInt())).value<QPalette>();
     item->setBackground(palette.base());
     item->setForeground(palette.text());
-    //sourceModel->appendRow(item);
-    _list_items.append(item);
+    sourceModel->appendRow(item);
 }
 
 void ConsoleTabWidget::cmdSendClicked()
@@ -249,3 +247,53 @@
 {
     model->setLogLevelFilter(ESL_LOG_LEVEL_DEBUG, state);
 }
+
+void ConsoleTabWidget::changeLogLevel(int level)
+{
+    if (esl->setConsoleLogLevel(level))
+    {
+        currentLogLevel = level;
+        QStandardItem *item = new QStandardItem(QString("Changed loglevel to %1").arg(level));
+        item->setData(ESL_LOG_LEVEL_EMERG, Qt::UserRole);
+        addNewConsoleItem(item);
+        if (level > 4)
+        {
+            m_ui->lblWarningMsg->show();
+            m_ui->lblWarningMsg->setText("High loglevels connected to high load servers can cause network consgestion!");
+            m_ui->lblWarningMsg->setAutoFillBackground(true);
+            m_ui->lblWarningMsg->setPalette(QPalette(Qt::yellow));
+            QTimer::singleShot(5000, m_ui->lblWarningMsg, SLOT(hide()));
+        }
+    }
+    else
+    {
+        currentLogLevel = level;
+        QStandardItem *item = new QStandardItem(QString("Could not change loglevel to %1").arg(level));
+        item->setData(ESL_LOG_LEVEL_ALERT, Qt::UserRole);
+        m_ui->comboLogLevel->blockSignals(true);
+        m_ui->comboLogLevel->setCurrentIndex(currentLogLevel);
+        m_ui->comboLogLevel->blockSignals(false);
+    }
+}
+
+void ConsoleTabWidget::readSettings()
+{
+    QSettings settings;
+    settings.beginGroup("Console");
+    settings.beginGroup(esl->getName());
+    /* Set the saved loglevel */
+    m_ui->comboLogLevel->setCurrentIndex(settings.value("Loglevel", 0).toInt());
+    settings.endGroup();
+    settings.endGroup();
+}
+
+void ConsoleTabWidget::writeSettings()
+{
+    QSettings settings;
+    settings.beginGroup("Console");
+    settings.beginGroup(esl->getName());
+    /* Save the current loglevel */
+    settings.setValue("Loglevel", currentLogLevel);
+    settings.endGroup();
+    settings.endGroup();
+}

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h	2009-08-21 05:41:14 UTC (rev 14582)
@@ -28,9 +28,9 @@
 
 protected:
     void changeEvent(QEvent *e);
-    void timerEvent(QTimerEvent *);
 
 private slots:
+    void setConditionalScroll();
     void conditionalScroll();
     void filterClear();
     void filterStringChanged();
@@ -48,20 +48,22 @@
     void checkNotice(bool);
     void checkInfo(bool);
     void checkDebug(bool);
+    void changeLogLevel(int);
 
 private:
     Ui::ConsoleTabWidget *m_ui;
-    QStandardItemModel *sourceModel;
+    ConsoleModel *sourceModel;
     QModelIndexList foundItems;
     SortFilterProxyModel *model;
-    QBasicTimer *scrollTimer;
     ESLconnection *esl;
     MonitorStateMachine *msm;
     RealtimeStatisticsDialog *_rtStatsDlg;
     bool findNext;
-    QList<QStandardItem *> _list_items;
-    int batch;
+    bool autoScroll;
+    int currentLogLevel;
 
+    void readSettings();
+    void writeSettings();
 };
 
 #endif // CONSOLETABWIDGET_H

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.ui (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.ui	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.ui	2009-08-21 05:41:14 UTC (rev 14582)
@@ -6,16 +6,22 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>859</width>
-    <height>557</height>
+    <width>657</width>
+    <height>525</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_6">
+  <layout class="QVBoxLayout" name="verticalLayout_5">
    <item>
     <widget class="QGroupBox" name="groupBox_2">
+     <property name="maximumSize">
+      <size>
+       <width>16777215</width>
+       <height>97</height>
+      </size>
+     </property>
      <property name="title">
       <string>Filter</string>
      </property>
@@ -78,6 +84,13 @@
          </widget>
         </item>
         <item>
+         <widget class="QLabel" name="lblWarningMsg">
+          <property name="text">
+           <string/>
+          </property>
+         </widget>
+        </item>
+        <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
@@ -96,24 +109,150 @@
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <widget class="QListView" name="consoleListView">
-       <property name="editTriggers">
-        <set>QAbstractItemView::NoEditTriggers</set>
+    <widget class="QSplitter" name="splitter">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <widget class="QListView" name="consoleListView">
+      <property name="editTriggers">
+       <set>QAbstractItemView::NoEditTriggers</set>
+      </property>
+      <property name="selectionMode">
+       <enum>QAbstractItemView::ExtendedSelection</enum>
+      </property>
+      <property name="layoutMode">
+       <enum>QListView::SinglePass</enum>
+      </property>
+     </widget>
+     <widget class="QWidget" name="layoutWidget">
+      <layout class="QVBoxLayout" name="verticalLayout_4">
+       <property name="sizeConstraint">
+        <enum>QLayout::SetMaximumSize</enum>
        </property>
-       <property name="selectionMode">
-        <enum>QAbstractItemView::ExtendedSelection</enum>
-       </property>
-       <property name="layoutMode">
-        <enum>QListView::SinglePass</enum>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_3">
        <item>
-        <widget class="QGroupBox" name="groupBox">
+        <layout class="QVBoxLayout" name="verticalLayout_3">
+         <property name="sizeConstraint">
+          <enum>QLayout::SetMaximumSize</enum>
+         </property>
+         <item>
+          <widget class="QGroupBox" name="groupBox">
+           <property name="maximumSize">
+            <size>
+             <width>120</width>
+             <height>16777215</height>
+            </size>
+           </property>
+           <property name="title">
+            <string>Log Level Filter</string>
+           </property>
+           <layout class="QVBoxLayout" name="verticalLayout">
+            <item>
+             <widget class="QCheckBox" name="checkEmerg">
+              <property name="text">
+               <string>Console</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkAlert">
+              <property name="text">
+               <string>Alert</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkCrit">
+              <property name="text">
+               <string>Critical</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkError">
+              <property name="text">
+               <string>Error</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkWarn">
+              <property name="text">
+               <string>Warning</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkNotice">
+              <property name="text">
+               <string>Notice</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkInfo">
+              <property name="text">
+               <string>Info</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="checkDebug">
+              <property name="text">
+               <string>Debug</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <spacer name="verticalSpacer">
+              <property name="orientation">
+               <enum>Qt::Vertical</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>20</width>
+                <height>18</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </widget>
+         </item>
+         <item>
+          <widget class="Line" name="line">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="groupBox_3">
          <property name="maximumSize">
           <size>
            <width>120</width>
@@ -121,115 +260,71 @@
           </size>
          </property>
          <property name="title">
-          <string>Log Level</string>
+          <string>Loglevel</string>
          </property>
-         <layout class="QVBoxLayout" name="verticalLayout">
-          <item>
-           <widget class="QCheckBox" name="checkEmerg">
-            <property name="text">
-             <string>Console</string>
+         <layout class="QFormLayout" name="formLayout">
+          <item row="0" column="0">
+           <widget class="QComboBox" name="comboLogLevel">
+            <property name="enabled">
+             <bool>false</bool>
             </property>
-            <property name="checked">
-             <bool>true</bool>
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
             </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkAlert">
-            <property name="text">
-             <string>Alert</string>
+            <property name="layoutDirection">
+             <enum>Qt::LeftToRight</enum>
             </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
+            <item>
+             <property name="text">
+              <string>Console</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Alert</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Critical</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Error</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Warning</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Notice</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Info</string>
+             </property>
+            </item>
+            <item>
+             <property name="text">
+              <string>Debug</string>
+             </property>
+            </item>
            </widget>
           </item>
-          <item>
-           <widget class="QCheckBox" name="checkCrit">
-            <property name="text">
-             <string>Critical</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkError">
-            <property name="text">
-             <string>Error</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkWarn">
-            <property name="text">
-             <string>Warning</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkNotice">
-            <property name="text">
-             <string>Notice</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkInfo">
-            <property name="text">
-             <string>Info</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QCheckBox" name="checkDebug">
-            <property name="text">
-             <string>Debug</string>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <spacer name="verticalSpacer">
-            <property name="orientation">
-             <enum>Qt::Vertical</enum>
-            </property>
-            <property name="sizeHint" stdset="0">
-             <size>
-              <width>20</width>
-              <height>18</height>
-             </size>
-            </property>
-           </spacer>
-          </item>
          </layout>
         </widget>
        </item>
-       <item>
-        <widget class="Line" name="line">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-        </widget>
-       </item>
       </layout>
-     </item>
-    </layout>
+     </widget>
+    </widget>
    </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">

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


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.cpp	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/realtimestatisticsdialog.cpp	2009-08-21 05:41:14 UTC (rev 14582)
@@ -24,8 +24,6 @@
             this, SLOT(channelCreate(Channel*)));
     connect(sm, SIGNAL(channelDestroyed(Channel*)),
             this, SLOT(channelDestroy(Channel*)));
-    connect(sm, SIGNAL(channelStateChanged(Channel*)),
-            this, SLOT(channelStateChanged(Channel*)));
     connect(m_ui->listActiveChannels, SIGNAL(clicked(QModelIndex)),
             this, SLOT(activeChannelSelected(QModelIndex)));
     connect(m_ui->listInactiveChannels, SIGNAL(clicked(QModelIndex)),
@@ -113,31 +111,6 @@
     }
 }
 
-void RealtimeStatisticsDialog::channelStateChanged(Channel * ch)
-{
-    /* Sanity checking */
-    if (!ch)
-        return;
-
-    foreach (QStandardItem *item, _channel_model->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive))
-    {
-        if (item->data(Qt::UserRole) == ch->getUUID())
-            if (_channel_model->itemFromIndex(m_ui->listActiveChannels->currentIndex()) == item)
-            {
-                activeChannelSelected(_channel_model->indexFromItem(item));
-            }
-    }
-
-    foreach (QStandardItem *item, _inactive_channel_model->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive))
-    {
-        if (item->data(Qt::UserRole) == ch->getUUID())
-            if (_inactive_channel_model->itemFromIndex(m_ui->listInactiveChannels->currentIndex()) == item)
-            {
-                inactiveChannelSelected(_inactive_channel_model->indexFromItem(item));
-            }
-    }
-}
-
 void RealtimeStatisticsDialog::activeChannelSelected(QModelIndex index)
 {
 

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.cpp (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.cpp	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.cpp	2009-08-21 05:41:14 UTC (rev 14582)
@@ -1,6 +1,66 @@
 #include <QtGui>
 #include "sortfilterproxymodel.h"
 
+ConsoleModel::ConsoleModel (QObject *parent)
+        : QAbstractListModel(parent)
+{
+    QSettings settings;
+    batchSize = settings.value("Console/batchSize", 200).toInt();
+    insertionTimer = new QBasicTimer;
+    insertionTimer->start(0, this);
+}
+
+int ConsoleModel::rowCount ( const QModelIndex & /*parent*/ ) const
+{
+    return _listDisplayModel.count();
+}
+
+QVariant ConsoleModel::data ( const QModelIndex & index, int role ) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    return _listDisplayModel.at(index.row())->data(role);
+}
+
+void ConsoleModel::clear()
+{
+    _listDisplayModel.clear();
+}
+
+void ConsoleModel::appendRow ( QStandardItem* item )
+{
+    _listInsertModel.append(item);
+}
+
+void ConsoleModel::timerEvent(QTimerEvent *e)
+{
+
+    if (e->timerId() == insertionTimer->timerId())
+    {
+        if (!_listInsertModel.isEmpty())
+        {
+            int inserted_items = 0;
+            int toBeInserted = 0;
+            if (_listInsertModel.size() < batchSize)
+            {
+                toBeInserted = _listInsertModel.size() - 1;
+            } else {
+                 toBeInserted = batchSize - 1;
+            }
+            beginInsertRows( QModelIndex(), _listDisplayModel.size(), _listDisplayModel.size() + toBeInserted );
+            emit layoutAboutToBeChanged();
+            while( !_listInsertModel.isEmpty() && inserted_items < batchSize)
+            {
+                _listDisplayModel.append(_listInsertModel.takeFirst());
+                inserted_items++;
+            }
+            endInsertRows();
+            emit layoutChanged();
+        }
+    }
+}
+
 SortFilterProxyModel::SortFilterProxyModel(QObject *parent)
         : QSortFilterProxyModel(parent)
 {

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.h (14581 => 14582)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.h	2009-08-21 00:59:09 UTC (rev 14581)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/sortfilterproxymodel.h	2009-08-21 05:41:14 UTC (rev 14582)
@@ -2,8 +2,32 @@
 #define SORTFILTERPROXYMODEL_H
 
 #include <QSortFilterProxyModel>
+#include <QAbstractListModel>
 #include <QVector>
+#include <QList>
 
+class QBasicTimer;
+class QStandardItem;
+class QScrollBar;
+
+class ConsoleModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    ConsoleModel (QObject *parent = 0);
+    int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
+    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
+    void appendRow ( QStandardItem* item );
+    void clear();
+protected:
+    void timerEvent(QTimerEvent *);
+private:
+    QList<QStandardItem *> _listDisplayModel;
+    QList<QStandardItem *> _listInsertModel;
+    int batchSize;
+    QBasicTimer *insertionTimer;
+};
+
 class SortFilterProxyModel : public QSortFilterProxyModel
 {
     Q_OBJECT