#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; }