From d534a56d95bca7bdd812be024d9eacba4734e2b7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 9 Nov 2012 17:20:11 +0000 Subject: Many changes: tabconv'd the C++ code, added a license, BSD, and docs. --- c++-libbu++/src/gatscon/clientthread.cpp | 43 ++++---- c++-libbu++/src/gatscon/clientthread.h | 29 +++-- c++-libbu++/src/gatscon/clientwidget.cpp | 95 +++++++++-------- c++-libbu++/src/gatscon/clientwidget.h | 23 ++-- c++-libbu++/src/gatscon/connectdlg.cpp | 15 ++- c++-libbu++/src/gatscon/connectdlg.h | 17 ++- c++-libbu++/src/gatscon/filewidget.cpp | 75 +++++++------ c++-libbu++/src/gatscon/filewidget.h | 23 ++-- c++-libbu++/src/gatscon/gatstotree.cpp | 115 ++++++++++---------- c++-libbu++/src/gatscon/gatstotree.h | 21 ++-- c++-libbu++/src/gatscon/iobase.cpp | 7 ++ c++-libbu++/src/gatscon/iobase.h | 9 +- c++-libbu++/src/gatscon/main.cpp | 15 ++- c++-libbu++/src/gatscon/mainwnd.cpp | 149 +++++++++++++------------- c++-libbu++/src/gatscon/mainwnd.h | 31 +++--- c++-libbu++/src/gatscon/proxythread.cpp | 113 ++++++++++---------- c++-libbu++/src/gatscon/proxythread.h | 55 +++++----- c++-libbu++/src/gatscon/proxywidget.cpp | 169 ++++++++++++++++-------------- c++-libbu++/src/gatscon/proxywidget.h | 31 +++--- c++-libbu++/src/gatscon/setupproxydlg.cpp | 17 ++- c++-libbu++/src/gatscon/setupproxydlg.h | 19 ++-- c++-libbu++/src/gatscon/treetogats.cpp | 89 ++++++++-------- c++-libbu++/src/gatscon/treetogats.h | 9 +- 23 files changed, 665 insertions(+), 504 deletions(-) (limited to 'c++-libbu++/src/gatscon') diff --git a/c++-libbu++/src/gatscon/clientthread.cpp b/c++-libbu++/src/gatscon/clientthread.cpp index 4c7b72a..4032a50 100644 --- a/c++-libbu++/src/gatscon/clientthread.cpp +++ b/c++-libbu++/src/gatscon/clientthread.cpp @@ -1,13 +1,20 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "clientthread.h" #include ClientThread::ClientThread( QObject *pParent, const QByteArray &baHost, - int iPort ) : - QThread( pParent ), - baHost( baHost ), - iPort( iPort ), - gsCli( ssCli ) + int iPort ) : + QThread( pParent ), + baHost( baHost ), + iPort( iPort ), + gsCli( ssCli ) { } @@ -17,22 +24,22 @@ ClientThread::~ClientThread() void ClientThread::send( Gats::Object *pObj ) { - gsCli.writeObject( pObj ); + gsCli.writeObject( pObj ); } void ClientThread::run() { - ssCli.setStream( - new Bu::TcpSocket( baHost.constData(), iPort ) - ); - - while( !ssCli.isEos() ) - { - Gats::Object *pObj = gsCli.readObject(); - if( pObj == NULL ) - continue; - - emit recv( pObj ); - } + ssCli.setStream( + new Bu::TcpSocket( baHost.constData(), iPort ) + ); + + while( !ssCli.isEos() ) + { + Gats::Object *pObj = gsCli.readObject(); + if( pObj == NULL ) + continue; + + emit recv( pObj ); + } } diff --git a/c++-libbu++/src/gatscon/clientthread.h b/c++-libbu++/src/gatscon/clientthread.h index 3182d37..a4343ee 100644 --- a/c++-libbu++/src/gatscon/clientthread.h +++ b/c++-libbu++/src/gatscon/clientthread.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef CLIENT_THREAD_H #define CLIENT_THREAD_H @@ -9,29 +16,29 @@ namespace Gats { - class Object; + class Object; }; class ClientThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); - virtual ~ClientThread(); + ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); + virtual ~ClientThread(); - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); signals: - void recv( Gats::Object *pObj ); + void recv( Gats::Object *pObj ); protected: - virtual void run(); + virtual void run(); private: - QByteArray baHost; - int iPort; - Bu::StreamStack ssCli; - Gats::GatsStream gsCli; + QByteArray baHost; + int iPort; + Bu::StreamStack ssCli; + Gats::GatsStream gsCli; }; #endif diff --git a/c++-libbu++/src/gatscon/clientwidget.cpp b/c++-libbu++/src/gatscon/clientwidget.cpp index 941d9fa..f13e736 100644 --- a/c++-libbu++/src/gatscon/clientwidget.cpp +++ b/c++-libbu++/src/gatscon/clientwidget.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "clientwidget.h" #include "clientthread.h" @@ -14,16 +21,16 @@ using namespace Bu; ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, - int iPort ) : - QWidget( pParent ) + int iPort ) : + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); - pCli = new ClientThread( this, baHost, iPort ); - connect( pCli, SIGNAL(recv( Gats::Object *)), - this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); - - pCli->start(); + pCli = new ClientThread( this, baHost, iPort ); + connect( pCli, SIGNAL(recv( Gats::Object *)), + this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); + + pCli->start(); } ClientWidget::~ClientWidget() @@ -32,51 +39,51 @@ 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; - } + 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; + 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() ); - } + 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; + sio << "Recv: " << *pObj << sio.nl; - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "recv" ); - gatsToTree( pIt, pObj ); - delete pObj; + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "recv" ); + gatsToTree( pIt, pObj ); + delete pObj; } diff --git a/c++-libbu++/src/gatscon/clientwidget.h b/c++-libbu++/src/gatscon/clientwidget.h index 06c154d..b40adf4 100644 --- a/c++-libbu++/src/gatscon/clientwidget.h +++ b/c++-libbu++/src/gatscon/clientwidget.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef CLIENT_WIDGET_H #define CLIENT_WIDGET_H @@ -7,24 +14,24 @@ namespace Gats { - class Object; + class Object; }; class ClientWidget : public QWidget, protected Ui::ClientWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); - virtual ~ClientWidget(); + ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); + virtual ~ClientWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void send(); - void recv( Gats::Object *pObj ); + void send(); + void recv( Gats::Object *pObj ); private: - class ClientThread *pCli; + class ClientThread *pCli; }; #endif diff --git a/c++-libbu++/src/gatscon/connectdlg.cpp b/c++-libbu++/src/gatscon/connectdlg.cpp index 589ae97..0bb159b 100644 --- a/c++-libbu++/src/gatscon/connectdlg.cpp +++ b/c++-libbu++/src/gatscon/connectdlg.cpp @@ -1,9 +1,16 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "connectdlg.h" ConnectDlg::ConnectDlg( QWidget *pParent ) : - QDialog( pParent ) + QDialog( pParent ) { - setupUi( this ); + setupUi( this ); } ConnectDlg::~ConnectDlg() @@ -12,11 +19,11 @@ ConnectDlg::~ConnectDlg() QByteArray ConnectDlg::getHostname() const { - return leHost->text().toAscii(); + return leHost->text().toAscii(); } int ConnectDlg::getPort() const { - return sbPort->value(); + return sbPort->value(); } diff --git a/c++-libbu++/src/gatscon/connectdlg.h b/c++-libbu++/src/gatscon/connectdlg.h index 57ea6cd..7396ef6 100644 --- a/c++-libbu++/src/gatscon/connectdlg.h +++ b/c++-libbu++/src/gatscon/connectdlg.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef CONNECT_DLG_H #define CONNECT_DLG_H @@ -5,13 +12,13 @@ class ConnectDlg : public QDialog, protected Ui::ConnectDlg { - Q_OBJECT; + Q_OBJECT; public: - ConnectDlg( QWidget *pParent ); - virtual ~ConnectDlg(); + ConnectDlg( QWidget *pParent ); + virtual ~ConnectDlg(); - QByteArray getHostname() const; - int getPort() const; + QByteArray getHostname() const; + int getPort() const; }; #endif diff --git a/c++-libbu++/src/gatscon/filewidget.cpp b/c++-libbu++/src/gatscon/filewidget.cpp index dbd70fd..23f6839 100644 --- a/c++-libbu++/src/gatscon/filewidget.cpp +++ b/c++-libbu++/src/gatscon/filewidget.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "filewidget.h" #include "gatstotree.h" @@ -12,28 +19,28 @@ using namespace Bu; FileWidget::FileWidget( QWidget *pParent ) : - QWidget( pParent ) + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); } FileWidget::FileWidget( QWidget *pParent, QString sFile ) : - QWidget( pParent ) + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); - File fIn( sFile.toAscii().constData(), File::Read ); - Gats::GatsStream gsIn( fIn ); - Gats::Object *pObj; - while( (pObj = gsIn.readObject()) ) - { - QTreeWidgetItem *pNew = new QTreeWidgetItem( - twGats->invisibleRootItem() - ); - pNew->setText( 0, "" ); - gatsToTree( pNew, pObj ); - delete pObj; - } + File fIn( sFile.toAscii().constData(), File::Read ); + Gats::GatsStream gsIn( fIn ); + Gats::Object *pObj; + while( (pObj = gsIn.readObject()) ) + { + QTreeWidgetItem *pNew = new QTreeWidgetItem( + twGats->invisibleRootItem() + ); + pNew->setText( 0, "" ); + gatsToTree( pNew, pObj ); + delete pObj; + } } FileWidget::~FileWidget() @@ -42,28 +49,28 @@ FileWidget::~FileWidget() void FileWidget::saveTo( const QString &sFile ) { - File fOut( sFile.toAscii().constData(), File::WriteNew ); - Gats::GatsStream gsOut( fOut ); - QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - Gats::Object *pObj = treeToGats( pRoot->child( j ) ); - gsOut.writeObject( pObj ); - delete pObj; - } + File fOut( sFile.toAscii().constData(), File::WriteNew ); + Gats::GatsStream gsOut( fOut ); + QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + Gats::Object *pObj = treeToGats( pRoot->child( j ) ); + gsOut.writeObject( pObj ); + delete pObj; + } } void FileWidget::addRootItem() { - QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", - "Gats:"); - Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); - QTreeWidgetItem *pNew = new QTreeWidgetItem( - twGats->invisibleRootItem() - ); - pNew->setText( 0, "" ); - gatsToTree( pNew, pObj ); - delete pObj; + QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", + "Gats:"); + Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); + QTreeWidgetItem *pNew = new QTreeWidgetItem( + twGats->invisibleRootItem() + ); + pNew->setText( 0, "" ); + gatsToTree( pNew, pObj ); + delete pObj; } void FileWidget::delRootItem() diff --git a/c++-libbu++/src/gatscon/filewidget.h b/c++-libbu++/src/gatscon/filewidget.h index 9993bfe..1426eae 100644 --- a/c++-libbu++/src/gatscon/filewidget.h +++ b/c++-libbu++/src/gatscon/filewidget.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef FILE_WIDGET_H #define FILE_WIDGET_H @@ -6,22 +13,22 @@ namespace Gats { - class Object; + class Object; }; class FileWidget : public QWidget, protected Ui::FileWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - FileWidget( QWidget *pParent=NULL ); - FileWidget( QWidget *pParent, QString sFile ); - virtual ~FileWidget(); + FileWidget( QWidget *pParent=NULL ); + FileWidget( QWidget *pParent, QString sFile ); + virtual ~FileWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void addRootItem(); - void delRootItem(); + void addRootItem(); + void delRootItem(); private: }; diff --git a/c++-libbu++/src/gatscon/gatstotree.cpp b/c++-libbu++/src/gatscon/gatstotree.cpp index e388d5e..192b395 100644 --- a/c++-libbu++/src/gatscon/gatstotree.cpp +++ b/c++-libbu++/src/gatscon/gatstotree.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "gatstotree.h" #include @@ -6,86 +13,86 @@ void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) { - switch( pObj->getType() ) - { - case Gats::typeInteger: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeString: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeFloat: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeBoolean: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeList: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeDictionary: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeNull: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - } + switch( pObj->getType() ) + { + case Gats::typeInteger: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeString: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeFloat: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeBoolean: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeList: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeDictionary: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeNull: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + } } void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ) { - p->setText( 1, "int"); - p->setText( 2, QString("%1").arg( pObj->getValue() ) ); + p->setText( 1, "int"); + p->setText( 2, QString("%1").arg( pObj->getValue() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ) { - p->setText( 1, "str"); - p->setText( 2, QString("%1").arg( pObj->getStr() ) ); + p->setText( 1, "str"); + p->setText( 2, QString("%1").arg( pObj->getStr() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ) { - p->setText( 1, "float"); - p->setText( 2, QString("%1").arg( pObj->getValue() ) ); + p->setText( 1, "float"); + p->setText( 2, QString("%1").arg( pObj->getValue() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ) { - p->setText( 1, "bool"); - p->setText( 2, pObj->getValue()?"true":"false" ); + p->setText( 1, "bool"); + p->setText( 2, pObj->getValue()?"true":"false" ); } void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ) { - p->setText( 1, "list"); - int j = 0; - for( Gats::List::iterator i = pObj->begin(); i; i++ ) - { - QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); - pIt->setText( 0, QString("%1").arg( j++ ) ); - gatsToTree( pIt, *i ); - } + p->setText( 1, "list"); + int j = 0; + for( Gats::List::iterator i = pObj->begin(); i; i++ ) + { + QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); + pIt->setText( 0, QString("%1").arg( j++ ) ); + gatsToTree( pIt, *i ); + } } void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ) { - p->setText( 1, "dict"); - for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) - { - QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); - pIt->setText( 0, QString( i.getKey().getStr() ) ); - gatsToTree( pIt, *i ); - } + p->setText( 1, "dict"); + for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) + { + QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); + pIt->setText( 0, QString( i.getKey().getStr() ) ); + gatsToTree( pIt, *i ); + } } void gatsToTree( QTreeWidgetItem *p, Gats::Null *pObj ) { - p->setText( 1, "null"); + p->setText( 1, "null"); } diff --git a/c++-libbu++/src/gatscon/gatstotree.h b/c++-libbu++/src/gatscon/gatstotree.h index a803017..dc8f451 100644 --- a/c++-libbu++/src/gatscon/gatstotree.h +++ b/c++-libbu++/src/gatscon/gatstotree.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef GATS_TO_TREE_H #define GATS_TO_TREE_H @@ -5,13 +12,13 @@ class QTreeWidgetItem; namespace Gats { - class Integer; - class String; - class Float; - class Boolean; - class List; - class Dictionary; - class Object; + class Integer; + class String; + class Float; + class Boolean; + class List; + class Dictionary; + class Object; }; #include diff --git a/c++-libbu++/src/gatscon/iobase.cpp b/c++-libbu++/src/gatscon/iobase.cpp index 309444c..40af455 100644 --- a/c++-libbu++/src/gatscon/iobase.cpp +++ b/c++-libbu++/src/gatscon/iobase.cpp @@ -1 +1,8 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "iobase.h" diff --git a/c++-libbu++/src/gatscon/iobase.h b/c++-libbu++/src/gatscon/iobase.h index 5bd3843..4475551 100644 --- a/c++-libbu++/src/gatscon/iobase.h +++ b/c++-libbu++/src/gatscon/iobase.h @@ -1,10 +1,17 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef IO_BASE_H #define IO_BASE_H class IoBase { public: - virtual void saveTo( const class QString &sFile )=0; + virtual void saveTo( const class QString &sFile )=0; }; #endif diff --git a/c++-libbu++/src/gatscon/main.cpp b/c++-libbu++/src/gatscon/main.cpp index b9b2327..11b6d4a 100644 --- a/c++-libbu++/src/gatscon/main.cpp +++ b/c++-libbu++/src/gatscon/main.cpp @@ -1,13 +1,20 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "mainwnd.h" #include int main( int argc, char *argv[] ) { - QApplication app( argc, argv ); + QApplication app( argc, argv ); - MainWnd wnd; - wnd.show(); + MainWnd wnd; + wnd.show(); - return app.exec(); + return app.exec(); } diff --git a/c++-libbu++/src/gatscon/mainwnd.cpp b/c++-libbu++/src/gatscon/mainwnd.cpp index 5d31019..7cce116 100644 --- a/c++-libbu++/src/gatscon/mainwnd.cpp +++ b/c++-libbu++/src/gatscon/mainwnd.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "mainwnd.h" #include "clientwidget.h" @@ -12,10 +19,10 @@ MainWnd::MainWnd() { - setupUi( this ); + setupUi( this ); - pMode = new QLabel( "Idle", this ); - statusBar()->addPermanentWidget( pMode ); + pMode = new QLabel( "Idle", this ); + statusBar()->addPermanentWidget( pMode ); } MainWnd::~MainWnd() @@ -24,96 +31,96 @@ MainWnd::~MainWnd() void MainWnd::connect() { - ConnectDlg dlg( this ); - if( dlg.exec() == QDialog::Accepted ) - { - sCurFile.clear(); - setCentralWidget( - new ClientWidget( - this, dlg.getHostname(), dlg.getPort() - ) - ); - pMode->setText( - QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). - arg( dlg.getPort() ) - ); - } + ConnectDlg dlg( this ); + if( dlg.exec() == QDialog::Accepted ) + { + sCurFile.clear(); + setCentralWidget( + new ClientWidget( + this, dlg.getHostname(), dlg.getPort() + ) + ); + pMode->setText( + QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). + arg( dlg.getPort() ) + ); + } } void MainWnd::proxy() { - SetupProxyDlg dlg( this ); - - if( dlg.exec() == QDialog::Accepted ) - { - sCurFile.clear(); - setCentralWidget( - new ProxyWidget( - this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() - ) - ); - pMode->setText( - QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). - arg( QString(dlg.getHostOut()) ). - arg( dlg.getPortOut() ) - ); - } + SetupProxyDlg dlg( this ); + + if( dlg.exec() == QDialog::Accepted ) + { + sCurFile.clear(); + setCentralWidget( + new ProxyWidget( + this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() + ) + ); + pMode->setText( + QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). + arg( QString(dlg.getHostOut()) ). + arg( dlg.getPortOut() ) + ); + } } void MainWnd::open() { - QString sFile = QFileDialog::getOpenFileName( - this, "Gats Console - open gats file" - ); - if( sFile.isEmpty() ) - return; - - sCurFile = sFile; - setCentralWidget( - new FileWidget( this, sFile ) - ); - pMode->setText( QString("File mode: %1").arg( sCurFile ) ); + QString sFile = QFileDialog::getOpenFileName( + this, "Gats Console - open gats file" + ); + if( sFile.isEmpty() ) + return; + + sCurFile = sFile; + setCentralWidget( + new FileWidget( this, sFile ) + ); + pMode->setText( QString("File mode: %1").arg( sCurFile ) ); } void MainWnd::newFile() { - sCurFile.clear(); - setCentralWidget( - new FileWidget( this ) - ); - pMode->setText( QString("File mode: ") ); + sCurFile.clear(); + setCentralWidget( + new FileWidget( this ) + ); + pMode->setText( QString("File mode: ") ); } void MainWnd::save() { - if( sCurFile.isEmpty() ) - { - saveAs(); - } - else - { - IoBase *pIo = dynamic_cast(centralWidget()); - if( !pIo ) - return; - - pIo->saveTo( sCurFile ); - } + if( sCurFile.isEmpty() ) + { + saveAs(); + } + else + { + IoBase *pIo = dynamic_cast(centralWidget()); + if( !pIo ) + return; + + pIo->saveTo( sCurFile ); + } } void MainWnd::saveAs() { - IoBase *pIo = dynamic_cast(centralWidget()); - if( !pIo ) - return; + IoBase *pIo = dynamic_cast(centralWidget()); + if( !pIo ) + return; - QString sFile = QFileDialog::getSaveFileName( - this, "Gats Console - save gats file" - ); - if( sFile.isEmpty() ) - return; + QString sFile = QFileDialog::getSaveFileName( + this, "Gats Console - save gats file" + ); + if( sFile.isEmpty() ) + return; - pIo->saveTo( sFile ); + pIo->saveTo( sFile ); - sCurFile = sFile; + sCurFile = sFile; } diff --git a/c++-libbu++/src/gatscon/mainwnd.h b/c++-libbu++/src/gatscon/mainwnd.h index d1ae080..2a5c3fa 100644 --- a/c++-libbu++/src/gatscon/mainwnd.h +++ b/c++-libbu++/src/gatscon/mainwnd.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef MAIN_WND_H #define MAIN_WND_H @@ -5,22 +12,22 @@ class MainWnd : public QMainWindow, protected Ui::MainWnd { - Q_OBJECT; + Q_OBJECT; public: - MainWnd(); - virtual ~MainWnd(); - + MainWnd(); + virtual ~MainWnd(); + public slots: - void connect(); - void proxy(); - void open(); - void newFile(); - void save(); - void saveAs(); + void connect(); + void proxy(); + void open(); + void newFile(); + void save(); + void saveAs(); private: - QString sCurFile; - class QLabel *pMode; + QString sCurFile; + class QLabel *pMode; }; #endif diff --git a/c++-libbu++/src/gatscon/proxythread.cpp b/c++-libbu++/src/gatscon/proxythread.cpp index 574b56b..733af7f 100644 --- a/c++-libbu++/src/gatscon/proxythread.cpp +++ b/c++-libbu++/src/gatscon/proxythread.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "proxythread.h" #include @@ -10,15 +17,15 @@ using namespace Bu; ProxyThread::ProxyThread( QObject *pParent, int iPortIn, - const QByteArray &baHostOut, int iPortOut ) : - QThread( pParent ), - pHost( NULL ), - iPortIn( iPortIn ), - baHostOut( baHostOut ), - iPortOut( iPortOut ), - gsCli( ssCli ) + const QByteArray &baHostOut, int iPortOut ) : + QThread( pParent ), + pHost( NULL ), + iPortIn( iPortIn ), + baHostOut( baHostOut ), + iPortOut( iPortOut ), + gsCli( ssCli ) { - pHost = new ProxyHostThread( pParent, this ); + pHost = new ProxyHostThread( pParent, this ); } ProxyThread::~ProxyThread() @@ -27,52 +34,52 @@ ProxyThread::~ProxyThread() void ProxyThread::send( Gats::Object *pObj ) { - MemBuf bg; - Gats::GatsStream gs( bg ); - gs.writeObject( pObj ); - ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); + MemBuf bg; + Gats::GatsStream gs( bg ); + gs.writeObject( pObj ); + ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); } void ProxyThread::run() { - int iSockIn; + int iSockIn; - { - TcpServerSocket tsIn( iPortIn ); - do - { - iSockIn = tsIn.accept( 5 ); - } while( iSockIn < 0 ); - } + { + TcpServerSocket tsIn( iPortIn ); + do + { + iSockIn = tsIn.accept( 5 ); + } while( iSockIn < 0 ); + } - emit gotConnection(); + emit gotConnection(); - ssCli.setStream( new TcpSocket( iSockIn ) ); - ssCli.setBlocking( true ); + ssCli.setStream( new TcpSocket( iSockIn ) ); + ssCli.setBlocking( true ); - pHost->setStream( - new TcpSocket( baHostOut.constData(), iPortOut ) - ); + pHost->setStream( + new TcpSocket( baHostOut.constData(), iPortOut ) + ); - pHost->start(); + pHost->start(); - while( !ssCli.isEos() ) - { - Gats::Object *pObj = gsCli.readObject(); - if( pObj == NULL ) - continue; + while( !ssCli.isEos() ) + { + Gats::Object *pObj = gsCli.readObject(); + if( pObj == NULL ) + continue; - pHost->send( pObj ); - emit recv( pObj ); - } + pHost->send( pObj ); + emit recv( pObj ); + } } ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) : - QThread( pParent ), - pClient( pClient ), - ssHst(), - gsHst( ssHst ) + QThread( pParent ), + pClient( pClient ), + ssHst(), + gsHst( ssHst ) { } @@ -82,27 +89,27 @@ ProxyHostThread::~ProxyHostThread() void ProxyHostThread::send( Gats::Object *pObj ) { - MemBuf bg; - Gats::GatsStream gs( bg ); - gs.writeObject( pObj ); - ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); + MemBuf bg; + Gats::GatsStream gs( bg ); + gs.writeObject( pObj ); + ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); } void ProxyHostThread::setStream( Bu::Stream *pStr ) { - ssHst.setStream( pStr ); + ssHst.setStream( pStr ); } void ProxyHostThread::run() { - while( !ssHst.isEos() ) - { - Gats::Object *pObj = gsHst.readObject(); - if( pObj == NULL ) - continue; - - pClient->send( pObj ); - emit recv( pObj ); - } + while( !ssHst.isEos() ) + { + Gats::Object *pObj = gsHst.readObject(); + if( pObj == NULL ) + continue; + + pClient->send( pObj ); + emit recv( pObj ); + } } diff --git a/c++-libbu++/src/gatscon/proxythread.h b/c++-libbu++/src/gatscon/proxythread.h index df75046..e53ca2c 100644 --- a/c++-libbu++/src/gatscon/proxythread.h +++ b/c++-libbu++/src/gatscon/proxythread.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef PROXY_THREAD_H #define PROXY_THREAD_H @@ -8,53 +15,53 @@ class ProxyThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, - int iPortOut ); - virtual ~ProxyThread(); + ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, + int iPortOut ); + virtual ~ProxyThread(); - class ProxyHostThread *pHost; + class ProxyHostThread *pHost; - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); signals: - void recv( Gats::Object *pObj ); - void gotConnection(); + void recv( Gats::Object *pObj ); + void gotConnection(); protected: - virtual void run(); + virtual void run(); private: - int iPortIn; - QByteArray baHostOut; - int iPortOut; + int iPortIn; + QByteArray baHostOut; + int iPortOut; - Bu::StreamStack ssCli; - Gats::GatsStream gsCli; + Bu::StreamStack ssCli; + Gats::GatsStream gsCli; }; class ProxyHostThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ProxyHostThread( QObject *pParent, ProxyThread *pClient ); - virtual ~ProxyHostThread(); + ProxyHostThread( QObject *pParent, ProxyThread *pClient ); + virtual ~ProxyHostThread(); - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); - void setStream( Bu::Stream *pStr ); + void setStream( Bu::Stream *pStr ); signals: - void recv( Gats::Object *pObj ); + void recv( Gats::Object *pObj ); protected: - virtual void run(); + virtual void run(); private: - ProxyThread *pClient; - Bu::StreamStack ssHst; - Gats::GatsStream gsHst; + ProxyThread *pClient; + Bu::StreamStack ssHst; + Gats::GatsStream gsHst; }; #endif diff --git a/c++-libbu++/src/gatscon/proxywidget.cpp b/c++-libbu++/src/gatscon/proxywidget.cpp index 215f95f..c95e39a 100644 --- a/c++-libbu++/src/gatscon/proxywidget.cpp +++ b/c++-libbu++/src/gatscon/proxywidget.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "proxywidget.h" #include "proxythread.h" @@ -14,22 +21,22 @@ using namespace Bu; ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, - const QByteArray baHost, int iPortOut ) : - QWidget( pParent ), - pPrx( NULL ) + const QByteArray baHost, int iPortOut ) : + QWidget( pParent ), + pPrx( NULL ) { - setupUi( this ); + setupUi( this ); - pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); + 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 ); + 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(); + pPrx->start(); } ProxyWidget::~ProxyWidget() @@ -38,94 +45,94 @@ ProxyWidget::~ProxyWidget() void ProxyWidget::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; - } + 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 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, "Gats Console - Error", e.what() ); - } + 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, "Gats Console - 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, "Gats Console - Error", e.what() ); - } + 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, "Gats Console - 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; + 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; + 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 ); + lwConnect->stop(); + swRoot->setCurrentIndex( 1 ); } diff --git a/c++-libbu++/src/gatscon/proxywidget.h b/c++-libbu++/src/gatscon/proxywidget.h index d6ebf4d..1674a34 100644 --- a/c++-libbu++/src/gatscon/proxywidget.h +++ b/c++-libbu++/src/gatscon/proxywidget.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef PROXY_WIDGET_H #define PROXY_WIDGET_H @@ -6,28 +13,28 @@ namespace Gats { - class Object; + class Object; }; class ProxyWidget : public QWidget, protected Ui::ProxyWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, - int iPortOut ); - virtual ~ProxyWidget(); + ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, + int iPortOut ); + virtual ~ProxyWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void sendToClient(); - void sendToServer(); - void clientRecv( Gats::Object *pObj ); - void hostRecv( Gats::Object *pObj ); - void gotConnection(); + void sendToClient(); + void sendToServer(); + void clientRecv( Gats::Object *pObj ); + void hostRecv( Gats::Object *pObj ); + void gotConnection(); private: - class ProxyThread *pPrx; + class ProxyThread *pPrx; }; #endif diff --git a/c++-libbu++/src/gatscon/setupproxydlg.cpp b/c++-libbu++/src/gatscon/setupproxydlg.cpp index 7c7a873..6d80683 100644 --- a/c++-libbu++/src/gatscon/setupproxydlg.cpp +++ b/c++-libbu++/src/gatscon/setupproxydlg.cpp @@ -1,9 +1,16 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "setupproxydlg.h" SetupProxyDlg::SetupProxyDlg( QWidget *pParent ) : - QDialog( pParent ) + QDialog( pParent ) { - setupUi( this ); + setupUi( this ); } SetupProxyDlg::~SetupProxyDlg() @@ -12,16 +19,16 @@ SetupProxyDlg::~SetupProxyDlg() int SetupProxyDlg::getPortIn() const { - return sbPortIn->value(); + return sbPortIn->value(); } QByteArray SetupProxyDlg::getHostOut() const { - return leHostOut->text().toAscii(); + return leHostOut->text().toAscii(); } int SetupProxyDlg::getPortOut() const { - return sbPortOut->value(); + return sbPortOut->value(); } diff --git a/c++-libbu++/src/gatscon/setupproxydlg.h b/c++-libbu++/src/gatscon/setupproxydlg.h index 6cc31bd..685e893 100644 --- a/c++-libbu++/src/gatscon/setupproxydlg.h +++ b/c++-libbu++/src/gatscon/setupproxydlg.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef SETUP_PROXY_DLG_H #define SETUP_PROXY_DLG_H @@ -5,14 +12,14 @@ class SetupProxyDlg : public QDialog, protected Ui::SetupProxyDlg { - Q_OBJECT; + Q_OBJECT; public: - SetupProxyDlg( QWidget *pParent=NULL ); - virtual ~SetupProxyDlg(); + SetupProxyDlg( QWidget *pParent=NULL ); + virtual ~SetupProxyDlg(); - int getPortIn() const; - QByteArray getHostOut() const; - int getPortOut() const; + int getPortIn() const; + QByteArray getHostOut() const; + int getPortOut() const; }; #endif diff --git a/c++-libbu++/src/gatscon/treetogats.cpp b/c++-libbu++/src/gatscon/treetogats.cpp index a1571d1..f12a319 100644 --- a/c++-libbu++/src/gatscon/treetogats.cpp +++ b/c++-libbu++/src/gatscon/treetogats.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "treetogats.h" #include @@ -6,47 +13,47 @@ Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) { - QString sType = pRoot->text( 1 ); - QByteArray baDat = pRoot->text( 2 ).toAscii(); - if( sType == "int" ) - { - return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); - } - else if( sType == "str" ) - { - return new Gats::String( baDat.constData(), baDat.size() ); - } - else if( sType == "float" ) - { - return new Gats::Float( strtod( baDat.constData(), NULL ) ); - } - else if( sType == "bool" ) - { - return new Gats::Boolean( baDat == "true" ); - } - else if( sType == "list" ) - { - Gats::List *pRet = new Gats::List(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - pRet->append( treeToGats( pRoot->child( j ) ) ); - } - return pRet; - } - else if( sType == "dict" ) - { - Gats::Dictionary *pRet = new Gats::Dictionary(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - QTreeWidgetItem *pChild = pRoot->child( j ); - pRet->insert( - pChild->text( 0 ).toAscii().constData(), - treeToGats( pChild ) - ); - } - return pRet; - } + QString sType = pRoot->text( 1 ); + QByteArray baDat = pRoot->text( 2 ).toAscii(); + if( sType == "int" ) + { + return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); + } + else if( sType == "str" ) + { + return new Gats::String( baDat.constData(), baDat.size() ); + } + else if( sType == "float" ) + { + return new Gats::Float( strtod( baDat.constData(), NULL ) ); + } + else if( sType == "bool" ) + { + return new Gats::Boolean( baDat == "true" ); + } + else if( sType == "list" ) + { + Gats::List *pRet = new Gats::List(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + pRet->append( treeToGats( pRoot->child( j ) ) ); + } + return pRet; + } + else if( sType == "dict" ) + { + Gats::Dictionary *pRet = new Gats::Dictionary(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + QTreeWidgetItem *pChild = pRoot->child( j ); + pRet->insert( + pChild->text( 0 ).toAscii().constData(), + treeToGats( pChild ) + ); + } + return pRet; + } - throw Bu::ExceptionBase("Unhandled type found."); + throw Bu::ExceptionBase("Unhandled type found."); } diff --git a/c++-libbu++/src/gatscon/treetogats.h b/c++-libbu++/src/gatscon/treetogats.h index 931623d..29f7d6c 100644 --- a/c++-libbu++/src/gatscon/treetogats.h +++ b/c++-libbu++/src/gatscon/treetogats.h @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #ifndef TREE_TO_GATS_H #define TREE_TO_GATS_H @@ -5,7 +12,7 @@ class QTreeWidgetItem; namespace Gats { - class Object; + class Object; }; Gats::Object *treeToGats( QTreeWidgetItem *pRoot ); -- cgit v1.2.3