Revision
14273
Author
jmesquita
Date
2009-07-16 11:33:59 -0500 (Thu, 16 Jul 2009)

Log Message

Inherit ESLevent to emit different signals for different types of command. Colors have been disabled till we do the preferences window

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/resources/server_manager.ui (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/resources/server_manager.ui	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/resources/server_manager.ui	2009-07-16 16:33:59 UTC (rev 14273)
@@ -56,7 +56,7 @@
          <item row="0" column="1">
           <widget class="QLineEdit" name="host">
            <property name="text">
-            <string>localhost</string>
+            <string/>
            </property>
           </widget>
          </item>
@@ -70,7 +70,7 @@
          <item row="1" column="1">
           <widget class="QLineEdit" name="pass">
            <property name="text">
-            <string>ClueCon</string>
+            <string/>
            </property>
           </widget>
          </item>
@@ -84,7 +84,7 @@
          <item row="2" column="1">
           <widget class="QLineEdit" name="port">
            <property name="text">
-            <string>8021</string>
+            <string/>
            </property>
           </widget>
          </item>

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp	2009-07-16 16:33:59 UTC (rev 14273)
@@ -91,6 +91,8 @@
             this, SLOT(connectionFailedSlot(QString)));
     connect(eslConnection, SIGNAL(gotEvent(ESLevent*)),
             this, SLOT(gotEventSlot(ESLevent*)));
+    connect(eslConnection, SIGNAL(gotConsoleEvent(ESLeventLog*)),
+            this, SLOT(gotConsoleEventSlot(ESLeventLog*)));
 
     eslConnection->doConnect();
 }
@@ -127,7 +129,7 @@
         if (i != cmdList.size()-1)
             args += " ";
     }
-    ESLevent *e = new ESLevent(eslConnection->api(cmdList[0].toAscii(), args.toAscii()));
+    ESLevent *e = new ESLevent(eslConnection->bgapi(cmdList[0].toAscii(), args.toAscii()));
     gotEventSlot(e);
     m_ui->lineCmd->clear();
 }
@@ -138,6 +140,7 @@
     m_ui->comboLogLevel->setEnabled(eslConnection->connected());
     m_ui->lineCmd->setFocus();
     readSettings();
+    eslConnection->sendRecv("event plain BACKGROUND_JOB");
 }
 void consolePage::gotDisconnectedSlot()
 {
@@ -153,50 +156,23 @@
 }
 void consolePage::gotEventSlot(ESLevent * event)
 {
-    QString type (event->getHeader("Content-Type"));
-    if (QString::compare("log/data", type, Qt::CaseInsensitive) == 0)
+    m_ui->textConsole->setTextColor(Qt::black);
+    if (event->getBody())
     {
-        switch (atoi(event->getHeader("log-level")))
-        {
-        case ESL_LOG_LEVEL_NOTICE:
-            {
-                m_ui->textConsole->setTextColor(Qt::cyan);
-                break;
-            }
-        case ESL_LOG_LEVEL_WARNING:
-            {
-                m_ui->textConsole->setTextColor(Qt::yellow);
-                break;
-            }
-        case ESL_LOG_LEVEL_ERROR:
-        case ESL_LOG_LEVEL_CRIT:
-            {
-                m_ui->textConsole->setTextColor(Qt::red);
-                break;
-            }
-        case ESL_LOG_LEVEL_ALERT:
-        case ESL_LOG_LEVEL_EMERG:
-        case ESL_LOG_LEVEL_INFO:
-            {
-                m_ui->textConsole->setTextColor(Qt::green);
-                break;
-            }
-        case ESL_LOG_LEVEL_DEBUG:
-            {
-                m_ui->textConsole->setTextColor(Qt::magenta);
-                break;
-            }
-        default:
-            {
-                m_ui->textConsole->setTextColor(Qt::black);
-            }
-        }
-    }
-    else
-    {
-        m_ui->textConsole->setTextColor(Qt::black);
-    }
+        QString text = event->getBody();
 
+        if (text.endsWith("\r\n"))
+            text.chop(2);
+        if (text.endsWith("\n"))
+            text.chop(1);
+
+        appendConsoleText(text);
+    }
+    delete event;
+}
+void consolePage::gotConsoleEventSlot(ESLeventLog * event)
+{
+    m_ui->textConsole->setTextColor(event->getConsoleColor());
     if (event->getBody())
     {
         QString text = event->getBody();

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/esl_connection.cpp (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/esl_connection.cpp	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/esl_connection.cpp	2009-07-16 16:33:59 UTC (rev 14273)
@@ -39,6 +39,7 @@
 #include <QtGui>
 #include <esl.h>
 #include <esl_connection.h>
+#include "global_defines.h"
 
 #define connection_construct_common() memset(&handle, 0, sizeof(handle)); last_event_obj = NULL
 #define event_construct_common() event = NULL; serialized_string = NULL; mine = 0; hp = NULL
@@ -284,8 +285,18 @@
         ESLevent * event = recvEventTimed(10);
         if (event)
         {
-            ESLevent * e = new ESLevent(event);
-            emit gotEvent(e);
+            QString type (event->getHeader("Content-Type"));
+            if (QString::compare("log/data", type, Qt::CaseInsensitive) == 0)
+            {
+                ESLeventLog *e = new ESLeventLog(event);
+                e->readSettings();
+                emit gotConsoleEvent(e);
+            }
+            else
+            {
+                ESLevent * e = new ESLevent(event);
+                emit gotEvent(e);
+            }
         }
     }
     if (!QString(handle.err).isEmpty())
@@ -487,3 +498,17 @@
 
     return (char *) "invalid";
 }
+
+/* ESLeventLog */
+/***********************************************************************************************/
+ESLeventLog::ESLeventLog(ESLevent *e) : ESLevent(e){}
+ESLeventLog::~ESLeventLog(){}
+void ESLeventLog::readSettings()
+{
+    QSettings settings(SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
+    QColor consoleColor = settings.value(QString("Log-Level-%1-Color").arg(ESLevent::getHeader("Log-Level")), QColor(Qt::black)).value<QColor>();
+}
+QColor ESLeventLog::getConsoleColor()
+{
+    return consoleColor;
+}

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h	2009-07-16 16:33:59 UTC (rev 14273)
@@ -9,6 +9,7 @@
 
 /* Forward declarations */
 class ESLevent;
+class ESLeventLog;
 class ESLconnection;
 
 class consolePage : public QWidget {
@@ -28,6 +29,7 @@
     void gotDisconnectedSlot();
     void connectionFailedSlot(QString);
     void gotEventSlot(ESLevent *);
+    void gotConsoleEventSlot(ESLeventLog *);
     void getDisconnectedSlot();
     void typedCommand();
     void sendCommand();

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/include/esl_connection.h (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/include/esl_connection.h	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/include/esl_connection.h	2009-07-16 16:33:59 UTC (rev 14273)
@@ -39,6 +39,7 @@
 #ifndef _ESL_CONNECTION_H_
 #define _ESL_CONNECTION_H_
 #include <QThread>
+#include <QtGui>
 #include <esl.h>
 
 /*#ifdef __cplusplus
@@ -73,6 +74,16 @@
 	const char *nextHeader(void);
 };
 
+class ESLeventLog : public ESLevent {
+public:
+    ESLeventLog(ESLevent *e);
+    virtual ~ESLeventLog();
+    QColor getConsoleColor();
+    void readSettings();
+private:
+    QColor consoleColor;
+};
+
 class ESLconnection : public QThread
 {
     Q_OBJECT
@@ -107,6 +118,7 @@
     void gotDisconnected(void);
     void connectionFailed(QString);
     void gotEvent(ESLevent*);
+    void gotConsoleEvent(ESLeventLog*);
 protected:
     void run();
 };

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/server_manager.cpp (14272 => 14273)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/server_manager.cpp	2009-07-16 15:43:54 UTC (rev 14272)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/server_manager.cpp	2009-07-16 16:33:59 UTC (rev 14273)
@@ -47,6 +47,7 @@
     m_ui->setupUi(this);
 
     readSettings();
+
     connect(m_ui->btnSave, SIGNAL(clicked()),
             this, SLOT(addNewServer()));
     connect(m_ui->btnDelete, SIGNAL(clicked()),