aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon/clientwidget.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-05-17 01:24:51 +0000
committerMike Buland <eichlan@xagasoft.com>2011-05-17 01:24:51 +0000
commitefcbdb7a0347b4399cbabacf3cbea432eeafb17b (patch)
treed468a9d8e129cba0cef68a09421c0e21c720ede6 /src/gatscon/clientwidget.cpp
parent02c60c6720f41bcfc367d02ae4c655b651642991 (diff)
downloadlibgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.gz
libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.bz2
libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.xz
libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.zip
Gats::Object now has a strToGats function, it's pretty slick, it takes a string
and produces a fully formed gats tree. Also, gatscon now can interact with a server directly.
Diffstat (limited to 'src/gatscon/clientwidget.cpp')
-rw-r--r--src/gatscon/clientwidget.cpp67
1 files changed, 58 insertions, 9 deletions
diff --git a/src/gatscon/clientwidget.cpp b/src/gatscon/clientwidget.cpp
index 4872d9d..6039035 100644
--- a/src/gatscon/clientwidget.cpp
+++ b/src/gatscon/clientwidget.cpp
@@ -1,24 +1,73 @@
1#include "clientwidget.h" 1#include "clientwidget.h"
2#include "connectdlg.h" 2#include "connectdlg.h"
3#include "clientthread.h"
4
5#include "gatstotree.h"
6
7#include <QMessageBox>
8
9#include <bu/tcpsocket.h>
10#include <bu/sio.h>
11
12using namespace Bu;
3 13
4ClientWidget::ClientWidget( QWidget *pParent ) : 14ClientWidget::ClientWidget( QWidget *pParent ) :
5 QWidget( pParent ), 15 QWidget( pParent )
6 gsCli( ssCli )
7{ 16{
8 setupUi( this ); 17 setupUi( this );
9 18
10 ConnectDlg dlg( this ); 19 {
11 dlg.exec(); 20 ConnectDlg dlg( this );
21 dlg.exec();
12 22
13 ssCli.setStream( 23 sio << "Connect: " << dlg.getHostname().constData() << ":"
14 new Bu::TcpSocket( dlg.getHost().constData(), dlg.getPort() ) 24 << dlg.getPort() << sio.nl;
15 );
16 25
17 Gats::Object *pObj = gsCli.readObject(); 26 pCli = new ClientThread( this, dlg.getHostname(), dlg.getPort() );
18 gatsToTree( twHistory, pObj ); 27 }
28 pCli->start();
29 connect( pCli, SIGNAL(recv( Gats::Object *)),
30 this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection );
19} 31}
20 32
21ClientWidget::~ClientWidget() 33ClientWidget::~ClientWidget()
22{ 34{
23} 35}
24 36
37void ClientWidget::send()
38{
39 try
40 {
41 Gats::Object *pObj = Gats::Object::strToGats(
42 leGats->text().toAscii().constData()
43 );
44 sio << "Send: " << *pObj << sio.nl;
45 QTreeWidgetItem *pIt = new QTreeWidgetItem(
46 twHistory->invisibleRootItem()
47 );
48 pIt->setText( 0, "send" );
49 gatsToTree( pIt, pObj );
50 pCli->send( pObj );
51 delete pObj;
52
53 leGats->setText("");
54 leGats->setFocus();
55 }
56 catch( Bu::ExceptionBase &e )
57 {
58 QMessageBox::critical( this, "GatsCon - Error", e.what() );
59 }
60}
61
62void ClientWidget::recv( Gats::Object *pObj )
63{
64 sio << "Recv: " << *pObj << sio.nl;
65
66 QTreeWidgetItem *pIt = new QTreeWidgetItem(
67 twHistory->invisibleRootItem()
68 );
69 pIt->setText( 0, "recv" );
70 gatsToTree( pIt, pObj );
71 delete pObj;
72}
73