diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
commit | 74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch) | |
tree | 843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /c++-libbu++/src/gatscon/clientwidget.cpp | |
parent | d9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff) | |
download | libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2 libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip |
Made the repo less libbu++-centric.
Diffstat (limited to 'c++-libbu++/src/gatscon/clientwidget.cpp')
-rw-r--r-- | c++-libbu++/src/gatscon/clientwidget.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/c++-libbu++/src/gatscon/clientwidget.cpp b/c++-libbu++/src/gatscon/clientwidget.cpp new file mode 100644 index 0000000..941d9fa --- /dev/null +++ b/c++-libbu++/src/gatscon/clientwidget.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | #include "clientwidget.h" | ||
2 | #include "clientthread.h" | ||
3 | |||
4 | #include "gatstotree.h" | ||
5 | #include "treetogats.h" | ||
6 | |||
7 | #include <QMessageBox> | ||
8 | |||
9 | #include <gats/gatsstream.h> | ||
10 | #include <bu/tcpsocket.h> | ||
11 | #include <bu/sio.h> | ||
12 | #include <bu/file.h> | ||
13 | |||
14 | using namespace Bu; | ||
15 | |||
16 | ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, | ||
17 | int iPort ) : | ||
18 | QWidget( pParent ) | ||
19 | { | ||
20 | setupUi( this ); | ||
21 | |||
22 | pCli = new ClientThread( this, baHost, iPort ); | ||
23 | connect( pCli, SIGNAL(recv( Gats::Object *)), | ||
24 | this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); | ||
25 | |||
26 | pCli->start(); | ||
27 | } | ||
28 | |||
29 | ClientWidget::~ClientWidget() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void ClientWidget::saveTo( const QString &sFile ) | ||
34 | { | ||
35 | File fOut( sFile.toAscii().constData(), File::WriteNew ); | ||
36 | Gats::GatsStream gsOut( fOut ); | ||
37 | QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); | ||
38 | for( int j = 0; j < pRoot->childCount(); j++ ) | ||
39 | { | ||
40 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); | ||
41 | gsOut.writeObject( pObj ); | ||
42 | delete pObj; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | void ClientWidget::send() | ||
47 | { | ||
48 | try | ||
49 | { | ||
50 | Gats::Object *pObj = Gats::Object::strToGats( | ||
51 | leGats->text().toAscii().constData() | ||
52 | ); | ||
53 | sio << "Send: " << *pObj << sio.nl; | ||
54 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
55 | twHistory->invisibleRootItem() | ||
56 | ); | ||
57 | pIt->setText( 0, "send" ); | ||
58 | gatsToTree( pIt, pObj ); | ||
59 | pCli->send( pObj ); | ||
60 | delete pObj; | ||
61 | |||
62 | leGats->setText(""); | ||
63 | leGats->setFocus(); | ||
64 | } | ||
65 | catch( Bu::ExceptionBase &e ) | ||
66 | { | ||
67 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | void ClientWidget::recv( Gats::Object *pObj ) | ||
72 | { | ||
73 | sio << "Recv: " << *pObj << sio.nl; | ||
74 | |||
75 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
76 | twHistory->invisibleRootItem() | ||
77 | ); | ||
78 | pIt->setText( 0, "recv" ); | ||
79 | gatsToTree( pIt, pObj ); | ||
80 | delete pObj; | ||
81 | } | ||
82 | |||