aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon/proxywidget.cpp
blob: 28bd1fcda768195a23ea68b10f6c26ede2399a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "proxywidget.h"
#include "proxythread.h"

#include "gatstotree.h"

#include <QMessageBox>

#include <gats/types.h>
#include <bu/sio.h>

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::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 );
}