diff options
Diffstat (limited to 'src/gatscon/proxywidget.cpp')
| -rw-r--r-- | src/gatscon/proxywidget.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/gatscon/proxywidget.cpp b/src/gatscon/proxywidget.cpp new file mode 100644 index 0000000..28bd1fc --- /dev/null +++ b/src/gatscon/proxywidget.cpp | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #include "proxywidget.h" | ||
| 2 | #include "proxythread.h" | ||
| 3 | |||
| 4 | #include "gatstotree.h" | ||
| 5 | |||
| 6 | #include <QMessageBox> | ||
| 7 | |||
| 8 | #include <gats/types.h> | ||
| 9 | #include <bu/sio.h> | ||
| 10 | |||
| 11 | using namespace Bu; | ||
| 12 | |||
| 13 | ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, | ||
| 14 | const QByteArray baHost, int iPortOut ) : | ||
| 15 | QWidget( pParent ), | ||
| 16 | pPrx( NULL ) | ||
| 17 | { | ||
| 18 | setupUi( this ); | ||
| 19 | |||
| 20 | pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); | ||
| 21 | |||
| 22 | connect( pPrx, SIGNAL(gotConnection()), | ||
| 23 | this, SLOT(gotConnection()), Qt::QueuedConnection ); | ||
| 24 | connect( pPrx, SIGNAL(recv( Gats::Object *)), | ||
| 25 | this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); | ||
| 26 | connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), | ||
| 27 | this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); | ||
| 28 | |||
| 29 | pPrx->start(); | ||
| 30 | } | ||
| 31 | |||
| 32 | ProxyWidget::~ProxyWidget() | ||
| 33 | { | ||
| 34 | } | ||
| 35 | |||
| 36 | void ProxyWidget::sendToClient() | ||
| 37 | { | ||
| 38 | try | ||
| 39 | { | ||
| 40 | Gats::Object *pObj = Gats::Object::strToGats( | ||
| 41 | leGats->text().toAscii().constData() | ||
| 42 | ); | ||
| 43 | sio << "Send: " << *pObj << sio.nl; | ||
| 44 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 45 | twHistory->invisibleRootItem() | ||
| 46 | ); | ||
| 47 | pIt->setText( 0, "proxy -> client" ); | ||
| 48 | gatsToTree( pIt, pObj ); | ||
| 49 | pPrx->send( pObj ); | ||
| 50 | delete pObj; | ||
| 51 | |||
| 52 | leGats->setText(""); | ||
| 53 | leGats->setFocus(); | ||
| 54 | } | ||
| 55 | catch( Bu::ExceptionBase &e ) | ||
| 56 | { | ||
| 57 | QMessageBox::critical( this, "GatsCon - Error", e.what() ); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | void ProxyWidget::sendToServer() | ||
| 62 | { | ||
| 63 | try | ||
| 64 | { | ||
| 65 | Gats::Object *pObj = Gats::Object::strToGats( | ||
| 66 | leGats->text().toAscii().constData() | ||
| 67 | ); | ||
| 68 | sio << "Send: " << *pObj << sio.nl; | ||
| 69 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 70 | twHistory->invisibleRootItem() | ||
| 71 | ); | ||
| 72 | pIt->setText( 0, "proxy -> host" ); | ||
| 73 | gatsToTree( pIt, pObj ); | ||
| 74 | pPrx->pHost->send( pObj ); | ||
| 75 | delete pObj; | ||
| 76 | |||
| 77 | leGats->setText(""); | ||
| 78 | leGats->setFocus(); | ||
| 79 | } | ||
| 80 | catch( Bu::ExceptionBase &e ) | ||
| 81 | { | ||
| 82 | QMessageBox::critical( this, "GatsCon - Error", e.what() ); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | void ProxyWidget::clientRecv( Gats::Object *pObj ) | ||
| 87 | { | ||
| 88 | sio << "Recv: " << *pObj << sio.nl; | ||
| 89 | |||
| 90 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 91 | twHistory->invisibleRootItem() | ||
| 92 | ); | ||
| 93 | pIt->setText( 0, "client -> host" ); | ||
| 94 | gatsToTree( pIt, pObj ); | ||
| 95 | delete pObj; | ||
| 96 | } | ||
| 97 | |||
| 98 | void ProxyWidget::hostRecv( Gats::Object *pObj ) | ||
| 99 | { | ||
| 100 | sio << "Recv: " << *pObj << sio.nl; | ||
| 101 | |||
| 102 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 103 | twHistory->invisibleRootItem() | ||
| 104 | ); | ||
| 105 | pIt->setText( 0, "host -> client" ); | ||
| 106 | gatsToTree( pIt, pObj ); | ||
| 107 | delete pObj; | ||
| 108 | } | ||
| 109 | |||
| 110 | void ProxyWidget::gotConnection() | ||
| 111 | { | ||
| 112 | lwConnect->stop(); | ||
| 113 | swRoot->setCurrentIndex( 1 ); | ||
| 114 | } | ||
| 115 | |||
