#include "proxywidget.h" #include "proxythread.h" #include "gatstotree.h" #include "treetogats.h" #include #include #include #include #include using namespace Bu; ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, int iPortOut ) : QWidget( pParent ), pPrx( NULL ) { setupUi( this ); pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); connect( pPrx, SIGNAL(gotConnection()), this, SLOT(gotConnection()), Qt::QueuedConnection ); connect( pPrx, SIGNAL(recv( Gats::Object *)), this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); pPrx->start(); } ProxyWidget::~ProxyWidget() { } void ProxyWidget::saveTo( const QString &sFile ) { File fOut( sFile.toAscii().constData(), File::WriteNew ); Gats::GatsStream gsOut( fOut ); QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); for( int j = 0; j < pRoot->childCount(); j++ ) { Gats::Object *pObj = treeToGats( pRoot->child( j ) ); gsOut.writeObject( pObj ); delete pObj; } } void ProxyWidget::sendToClient() { try { Gats::Object *pObj = Gats::Object::strToGats( leGats->text().toAscii().constData() ); sio << "Send: " << *pObj << sio.nl; QTreeWidgetItem *pIt = new QTreeWidgetItem( twHistory->invisibleRootItem() ); pIt->setText( 0, "proxy -> client" ); gatsToTree( pIt, pObj ); pPrx->send( pObj ); delete pObj; leGats->setText(""); leGats->setFocus(); } catch( Bu::ExceptionBase &e ) { QMessageBox::critical( this, "GatsCon - Error", e.what() ); } } void ProxyWidget::sendToServer() { try { Gats::Object *pObj = Gats::Object::strToGats( leGats->text().toAscii().constData() ); sio << "Send: " << *pObj << sio.nl; QTreeWidgetItem *pIt = new QTreeWidgetItem( twHistory->invisibleRootItem() ); pIt->setText( 0, "proxy -> host" ); gatsToTree( pIt, pObj ); pPrx->pHost->send( pObj ); delete pObj; leGats->setText(""); leGats->setFocus(); } catch( Bu::ExceptionBase &e ) { QMessageBox::critical( this, "GatsCon - Error", e.what() ); } } void ProxyWidget::clientRecv( Gats::Object *pObj ) { sio << "Recv: " << *pObj << sio.nl; QTreeWidgetItem *pIt = new QTreeWidgetItem( twHistory->invisibleRootItem() ); pIt->setText( 0, "client -> host" ); gatsToTree( pIt, pObj ); delete pObj; } void ProxyWidget::hostRecv( Gats::Object *pObj ) { sio << "Recv: " << *pObj << sio.nl; QTreeWidgetItem *pIt = new QTreeWidgetItem( twHistory->invisibleRootItem() ); pIt->setText( 0, "host -> client" ); gatsToTree( pIt, pObj ); delete pObj; } void ProxyWidget::gotConnection() { lwConnect->stop(); swRoot->setCurrentIndex( 1 ); }