From 74dd68ad611d15abf16a65c36a7cfd3f4492930a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 9 Nov 2012 16:25:22 +0000 Subject: Made the repo less libbu++-centric. --- c++-libbu++/src/gatscon/clientwidget.cpp | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 c++-libbu++/src/gatscon/clientwidget.cpp (limited to 'c++-libbu++/src/gatscon/clientwidget.cpp') 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 @@ +#include "clientwidget.h" +#include "clientthread.h" + +#include "gatstotree.h" +#include "treetogats.h" + +#include + +#include +#include +#include +#include + +using namespace Bu; + +ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, + int iPort ) : + QWidget( pParent ) +{ + setupUi( this ); + + pCli = new ClientThread( this, baHost, iPort ); + connect( pCli, SIGNAL(recv( Gats::Object *)), + this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); + + pCli->start(); +} + +ClientWidget::~ClientWidget() +{ +} + +void ClientWidget::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 ClientWidget::send() +{ + 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, "send" ); + gatsToTree( pIt, pObj ); + pCli->send( pObj ); + delete pObj; + + leGats->setText(""); + leGats->setFocus(); + } + catch( Bu::ExceptionBase &e ) + { + QMessageBox::critical( this, "Gats Console - Error", e.what() ); + } +} + +void ClientWidget::recv( Gats::Object *pObj ) +{ + sio << "Recv: " << *pObj << sio.nl; + + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "recv" ); + gatsToTree( pIt, pObj ); + delete pObj; +} + -- cgit v1.2.3