[Freeswitch-svn] [commit] r11497 - freeswitch/trunk/scripts/contrib/jmesquita/fsgui
FreeSWITCH SVN
jmesquita at freeswitch.org
Mon Jan 26 16:48:49 PST 2009
Author: jmesquita
Date: Mon Jan 26 18:48:49 2009
New Revision: 11497
Log:
Initial commit of FSGui. It works only for send_recv events and not multithreaded.
Added:
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.cpp
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.h
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.cpp
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.h
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.pro
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.ui
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/main.cpp
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.cpp
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.h
freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.ui
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.cpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.cpp Mon Jan 26 18:48:49 2009
@@ -0,0 +1,88 @@
+#include "conn_event_handler.h"
+
+
+conn_event_handler::conn_event_handler()
+{
+ memset(&handle, 0, sizeof(esl_handle_t));
+}
+
+conn_event_handler::~conn_event_handler(void){
+ getDisconnected();
+ delete &handle;
+}
+
+void conn_event_handler::getDisconnected(){
+ esl_disconnect(&handle);
+}
+
+void conn_event_handler::getConnected(QString hostname, int port, QString password){
+ QByteArray h = hostname.toAscii();
+ QByteArray p = password.toAscii();
+ const char * Hostname = h.data();
+ const char * Password = p.data();
+ esl_status_t status = esl_connect(&handle, Hostname, port, Password);
+ if ( status != ESL_SUCCESS)
+ {
+ QString errDesc = handle.err;
+ emit connectionError(errDesc);
+ }
+ else
+ {
+ emit gotConnected();
+ }
+}
+
+void conn_event_handler::handleError(){
+ return;
+}
+
+void conn_event_handler::readClient()
+{
+ return;
+}
+
+void conn_event_handler::sendMessage(QString message)
+{
+ if (isConnected())
+ {
+ esl_status_t status = esl_send_recv(&handle, message.toAscii());
+ QString reply;
+ if (status != ESL_FAIL)
+ {
+ if (message.contains("nolog") ||
+ message.contains("event") ||
+ message.contains("noevent") ||
+ message.contains("nixevent") ||
+ message.contains("log") ||
+ message.contains("nolog") ||
+ message.contains("filter")
+ )
+ {
+ reply = handle.last_sr_reply;
+ reply+="\n";
+ }
+ else if (message.contains("exit"))
+ {
+ emit connectionError("Disconnected!");
+ handle.connected = ESL_FALSE;
+ reply = "See you!\n";
+ }
+ else
+ {
+ reply = handle.last_sr_event->body;
+ }
+ }
+ emit messageSignal(reply);
+ }
+ return;
+}
+
+void conn_event_handler::handleRecvMessage(QString msg)
+{
+ return;
+}
+
+bool conn_event_handler::isConnected()
+{
+ return handle.connected;
+}
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/conn_event_handler.h Mon Jan 26 18:48:49 2009
@@ -0,0 +1,39 @@
+#ifndef CONN_EVENT_HANDLER_H
+#define CONN_EVENT_HANDLER_H
+
+#include <QtGui>
+
+extern "C" {
+ #include "esl.h"
+ #include "esl_event.h"
+ #include "esl_threadmutex.h"
+ #include "esl_config.h"
+}
+
+
+class conn_event_handler : public QObject
+{
+
+ Q_OBJECT
+
+public:
+ conn_event_handler();
+ ~conn_event_handler();
+ void getConnected(QString, int, QString);
+ void getDisconnected(void);
+ bool isConnected(void);
+private slots:
+ void handleError();
+ void readClient(void);
+public slots:
+ void sendMessage(QString);
+private:
+ void handleRecvMessage(QString);
+ esl_handle_t handle;
+signals:
+ void connectionError(QString);
+ void gotConnected(void);
+ void messageSignal(QString);
+};
+
+#endif // CONN_EVENT_HANDLER_H
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.cpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.cpp Mon Jan 26 18:48:49 2009
@@ -0,0 +1,80 @@
+#include "fsgui.h"
+#include "ui_fsgui.h"
+#include "serverlogin.h"
+
+FSGui::FSGui(QWidget *parent)
+ : QMainWindow(parent), ui(new Ui::FSGuiClass)
+{
+ ui->setupUi(this);
+ serverLogin = new ServerLogin(this);
+ serverLogin->show();
+
+ connect( serverLogin , SIGNAL(acceptedSignal(QString, QString, QString)),
+ this, SLOT(connectSlot(QString, QString, QString)) );
+
+ connect(ui->btnSend, SIGNAL(clicked()), this, SLOT(btnSendClickedSlot()));
+ connect(ui->lineCmd, SIGNAL(textChanged(QString)), this, SLOT(lineCmdEditedSlot(QString)));
+ connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
+ connect(ui->actionConnect, SIGNAL(triggered()), serverLogin, SLOT(show()));
+
+}
+
+FSGui::~FSGui()
+{
+ delete socket;
+ delete ui;
+}
+
+void FSGui::error(QString msg){
+ ui->statusBar->showMessage(msg);
+}
+
+void FSGui::connectSlot(QString hostname, QString port, QString password){
+ socket = new conn_event_handler();
+ connect( socket , SIGNAL( connectionError(QString) ),
+ this, SLOT( error(QString) ) );
+ connect(socket , SIGNAL( gotConnected() ),
+ this, SLOT(connectionSuccessful()));
+ connect(socket , SIGNAL( messageSignal(QString) ),
+ this, SLOT( messageSlot(QString) ));
+ connect(this, SIGNAL(btnSendClickedSignal(QString)),
+ socket, SLOT(sendMessage(QString)));
+ socket->getConnected(hostname, port.toInt(), password);
+ ui->btnSend->setEnabled(true);
+}
+
+void FSGui::connectionSuccessful(void){
+ ui->statusBar->showMessage(tr("Connected!"));
+}
+
+void FSGui::btnSendClickedSlot()
+{
+ emit btnSendClickedSignal(ui->lineCmd->text());
+ ui->lineCmd->clear();
+}
+
+void FSGui::lineCmdEditedSlot(QString text)
+{
+ if (socket->isConnected() && !text.isEmpty())
+ {
+ ui->btnSend->setEnabled(true);
+ }
+ else
+ {
+ ui->btnSend->setEnabled(false);
+ }
+}
+
+void FSGui::messageSlot(QString msg)
+{
+ if (!msg.isEmpty())
+ {
+ QTime timestamp = QTime::currentTime();
+ QStringList msgList = msg.split("\n", QString::SkipEmptyParts);
+ for (int i = 0 ; i < msgList.size() ; ++i)
+ {
+ QString message = timestamp.toString("hh:mm:ss.zzz") + " : " + msgList[i] + "\n";
+ ui->textConsole->insertPlainText(message);
+ }
+ }
+}
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.h Mon Jan 26 18:48:49 2009
@@ -0,0 +1,40 @@
+#ifndef FSGUI_H
+#define FSGUI_H
+
+#include <QtGui/QMainWindow>
+#include "conn_event_handler.h"
+
+
+namespace Ui
+{
+ class FSGuiClass;
+}
+
+class FSGui : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ FSGui(QWidget *parent = 0);
+ ~FSGui();
+
+private:
+ Ui::FSGuiClass *ui;
+ conn_event_handler* socket;
+ QDialog * serverLogin;
+ QLabel * statusBarLabel;
+
+private slots:
+ void error(QString);
+ void connectionSuccessful(void);
+ void connectSlot(QString, QString, QString);
+ void btnSendClickedSlot();
+ void lineCmdEditedSlot(QString);
+ void messageSlot(QString);
+
+signals:
+ void btnSendClickedSignal(QString);
+
+};
+
+#endif // FSGUI_H
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.pro
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.pro Mon Jan 26 18:48:49 2009
@@ -0,0 +1,24 @@
+# -------------------------------------------------
+# Project created by QtCreator 2009-01-18T13:57:52
+# -------------------------------------------------
+TARGET = fs_gui
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ fsgui.cpp \
+ conn_event_handler.cpp \
+ serverlogin.cpp
+
+INCLUDEPATH = ./../../../libs/esl/src/include
+
+HEADERS += fsgui.h \
+ conn_event_handler.h \
+ serverlogin.h \
+ esl.h \
+ esl_threadmutex.h \
+ esl_config.h
+
+FORMS += fsgui.ui \
+ serverlogin.ui
+
+LIBS += -L.. -lesl
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.ui
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/fsgui.ui Mon Jan 26 18:48:49 2009
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FSGuiClass</class>
+ <widget class="QMainWindow" name="FSGuiClass">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>FSGui - The console for humans</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QTextEdit" name="textConsole">
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLineEdit" name="lineCmd"/>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="btnSend">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Send</string>
+ </property>
+ <property name="shortcut">
+ <string>Return</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ <property name="default">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>&File</string>
+ </property>
+ <addaction name="actionConnect"/>
+ <addaction name="separator"/>
+ <addaction name="actionQuit"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>&Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionQuit">
+ <property name="text">
+ <string>&Quit</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>&About</string>
+ </property>
+ </action>
+ <action name="actionConnect">
+ <property name="text">
+ <string>&Connect</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+C</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <tabstops>
+ <tabstop>lineCmd</tabstop>
+ <tabstop>textConsole</tabstop>
+ <tabstop>btnSend</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/main.cpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/main.cpp Mon Jan 26 18:48:49 2009
@@ -0,0 +1,10 @@
+#include <QtGui/QApplication>
+#include "fsgui.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ FSGui w;
+ w.show();
+ return a.exec();
+}
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.cpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.cpp Mon Jan 26 18:48:49 2009
@@ -0,0 +1,33 @@
+#include "serverlogin.h"
+#include "ui_serverlogin.h"
+
+ServerLogin::ServerLogin(QWidget *parent) :
+ QDialog(parent),
+ m_ui(new Ui::ServerLogin)
+{
+ m_ui->setupUi(this);
+ this->setModal(true);
+
+ connect (this, SIGNAL(accepted()), this, SLOT(acceptedSlot()));
+}
+
+ServerLogin::~ServerLogin()
+{
+ delete m_ui;
+}
+
+void ServerLogin::changeEvent(QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ m_ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+void ServerLogin::acceptedSlot()
+{
+ emit acceptedSignal(m_ui->editHostname->text(), m_ui->editPort->text(), m_ui->editPassword->text());
+}
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.h Mon Jan 26 18:48:49 2009
@@ -0,0 +1,30 @@
+#ifndef SERVERLOGIN_H
+#define SERVERLOGIN_H
+
+#include <QtGui/QDialog>
+
+namespace Ui {
+ class ServerLogin;
+}
+
+class ServerLogin : public QDialog {
+ Q_OBJECT
+ Q_DISABLE_COPY(ServerLogin)
+public:
+ explicit ServerLogin(QWidget *parent = 0);
+ virtual ~ServerLogin();
+
+protected:
+ virtual void changeEvent(QEvent *e);
+
+private:
+ Ui::ServerLogin *m_ui;
+
+private slots:
+ void acceptedSlot();
+
+signals:
+ void acceptedSignal(QString, QString, QString);
+};
+
+#endif // SERVERLOGIN_H
Added: freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.ui
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/fsgui/serverlogin.ui Mon Jan 26 18:48:49 2009
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ServerLogin</class>
+ <widget class="QDialog" name="ServerLogin">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>218</width>
+ <height>148</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Server Login</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Hostname:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="editHostname">
+ <property name="maxLength">
+ <number>32767</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="editPort">
+ <property name="inputMask">
+ <string>999999; </string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="editPassword"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ <property name="centerButtons">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ServerLogin</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ServerLogin</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
More information about the Freeswitch-svn
mailing list