aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-05-17 14:56:28 +0000
committerMike Buland <eichlan@xagasoft.com>2011-05-17 14:56:28 +0000
commit6d8bc516acf7a5995736423e838c987d08e69c09 (patch)
tree9db78ee528b26e0d5718b2ac4c987388e1b9c313 /src/gatscon
parentd269a39f27e2dcd57d0e3362ef3a7fd9ad3f3639 (diff)
downloadlibgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.gz
libgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.bz2
libgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.xz
libgats-6d8bc516acf7a5995736423e838c987d08e69c09.zip
Ok, you can now open files, save files, save files from proxies and clients,
and add new root items to files. Later I'll add some actual editing capabilities, should be really easy.
Diffstat (limited to 'src/gatscon')
-rw-r--r--src/gatscon/clientwidget.cpp16
-rw-r--r--src/gatscon/clientwidget.h5
-rw-r--r--src/gatscon/filewidget.cpp33
-rw-r--r--src/gatscon/filewidget.h9
-rw-r--r--src/gatscon/filewidget.ui59
-rw-r--r--src/gatscon/iobase.cpp1
-rw-r--r--src/gatscon/iobase.h10
-rw-r--r--src/gatscon/mainwnd.cpp59
-rw-r--r--src/gatscon/mainwnd.h6
-rw-r--r--src/gatscon/mainwnd.ui67
-rw-r--r--src/gatscon/proxywidget.cpp16
-rw-r--r--src/gatscon/proxywidget.h5
-rw-r--r--src/gatscon/treetogats.cpp52
-rw-r--r--src/gatscon/treetogats.h13
14 files changed, 346 insertions, 5 deletions
diff --git a/src/gatscon/clientwidget.cpp b/src/gatscon/clientwidget.cpp
index 0ea04a3..c9cb4c1 100644
--- a/src/gatscon/clientwidget.cpp
+++ b/src/gatscon/clientwidget.cpp
@@ -2,11 +2,14 @@
2#include "clientthread.h" 2#include "clientthread.h"
3 3
4#include "gatstotree.h" 4#include "gatstotree.h"
5#include "treetogats.h"
5 6
6#include <QMessageBox> 7#include <QMessageBox>
7 8
9#include <gats/gatsstream.h>
8#include <bu/tcpsocket.h> 10#include <bu/tcpsocket.h>
9#include <bu/sio.h> 11#include <bu/sio.h>
12#include <bu/file.h>
10 13
11using namespace Bu; 14using namespace Bu;
12 15
@@ -27,6 +30,19 @@ ClientWidget::~ClientWidget()
27{ 30{
28} 31}
29 32
33void 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
30void ClientWidget::send() 46void ClientWidget::send()
31{ 47{
32 try 48 try
diff --git a/src/gatscon/clientwidget.h b/src/gatscon/clientwidget.h
index 9ce2798..5ff18fb 100644
--- a/src/gatscon/clientwidget.h
+++ b/src/gatscon/clientwidget.h
@@ -2,19 +2,22 @@
2#define CLIENT_WIDGET_H 2#define CLIENT_WIDGET_H
3 3
4#include "ui_clientwidget.h" 4#include "ui_clientwidget.h"
5#include "iobase.h"
5 6
6namespace Gats 7namespace Gats
7{ 8{
8 class Object; 9 class Object;
9}; 10};
10 11
11class ClientWidget : public QWidget, protected Ui::ClientWidget 12class ClientWidget : public QWidget, protected Ui::ClientWidget, public IoBase
12{ 13{
13 Q_OBJECT; 14 Q_OBJECT;
14public: 15public:
15 ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); 16 ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort );
16 virtual ~ClientWidget(); 17 virtual ~ClientWidget();
17 18
19 virtual void saveTo( const QString &sFile );
20
18public slots: 21public slots:
19 void send(); 22 void send();
20 void recv( Gats::Object *pObj ); 23 void recv( Gats::Object *pObj );
diff --git a/src/gatscon/filewidget.cpp b/src/gatscon/filewidget.cpp
index b2dd09e..70f7b03 100644
--- a/src/gatscon/filewidget.cpp
+++ b/src/gatscon/filewidget.cpp
@@ -1,11 +1,14 @@
1#include "filewidget.h" 1#include "filewidget.h"
2 2
3#include "gatstotree.h" 3#include "gatstotree.h"
4#include "treetogats.h"
4 5
5#include <gats/types.h> 6#include <gats/types.h>
6#include <gats/gatsstream.h> 7#include <gats/gatsstream.h>
7#include <bu/file.h> 8#include <bu/file.h>
8 9
10#include <QInputDialog>
11
9using namespace Bu; 12using namespace Bu;
10 13
11FileWidget::FileWidget( QWidget *pParent ) : 14FileWidget::FileWidget( QWidget *pParent ) :
@@ -37,3 +40,33 @@ FileWidget::~FileWidget()
37{ 40{
38} 41}
39 42
43void FileWidget::saveTo( const QString &sFile )
44{
45 File fOut( sFile.toAscii().constData(), File::WriteNew );
46 Gats::GatsStream gsOut( fOut );
47 QTreeWidgetItem *pRoot = twGats->invisibleRootItem();
48 for( int j = 0; j < pRoot->childCount(); j++ )
49 {
50 Gats::Object *pObj = treeToGats( pRoot->child( j ) );
51 gsOut.writeObject( pObj );
52 delete pObj;
53 }
54}
55
56void FileWidget::addRootItem()
57{
58 QString sText = QInputDialog::getText( this, "GatsCon - Add Root Item",
59 "Gats:");
60 Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() );
61 QTreeWidgetItem *pNew = new QTreeWidgetItem(
62 twGats->invisibleRootItem()
63 );
64 pNew->setText( 0, "<root>" );
65 gatsToTree( pNew, pObj );
66 delete pObj;
67}
68
69void FileWidget::delRootItem()
70{
71}
72
diff --git a/src/gatscon/filewidget.h b/src/gatscon/filewidget.h
index ac46685..9993bfe 100644
--- a/src/gatscon/filewidget.h
+++ b/src/gatscon/filewidget.h
@@ -2,13 +2,14 @@
2#define FILE_WIDGET_H 2#define FILE_WIDGET_H
3 3
4#include "ui_filewidget.h" 4#include "ui_filewidget.h"
5#include "iobase.h"
5 6
6namespace Gats 7namespace Gats
7{ 8{
8 class Object; 9 class Object;
9}; 10};
10 11
11class FileWidget : public QWidget, protected Ui::FileWidget 12class FileWidget : public QWidget, protected Ui::FileWidget, public IoBase
12{ 13{
13 Q_OBJECT; 14 Q_OBJECT;
14public: 15public:
@@ -16,6 +17,12 @@ public:
16 FileWidget( QWidget *pParent, QString sFile ); 17 FileWidget( QWidget *pParent, QString sFile );
17 virtual ~FileWidget(); 18 virtual ~FileWidget();
18 19
20 virtual void saveTo( const QString &sFile );
21
22public slots:
23 void addRootItem();
24 void delRootItem();
25
19private: 26private:
20}; 27};
21 28
diff --git a/src/gatscon/filewidget.ui b/src/gatscon/filewidget.ui
index 6557035..d0e6ec3 100644
--- a/src/gatscon/filewidget.ui
+++ b/src/gatscon/filewidget.ui
@@ -6,7 +6,7 @@
6 <rect> 6 <rect>
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>400</width> 9 <width>316</width>
10 <height>300</height> 10 <height>300</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
@@ -33,8 +33,63 @@
33 </column> 33 </column>
34 </widget> 34 </widget>
35 </item> 35 </item>
36 <item>
37 <layout class="QHBoxLayout" name="horizontalLayout_2">
38 <item>
39 <widget class="QPushButton" name="pushButton_2">
40 <property name="text">
41 <string>Add Root Item</string>
42 </property>
43 </widget>
44 </item>
45 <item>
46 <widget class="QPushButton" name="pushButton">
47 <property name="text">
48 <string>Del Root Item</string>
49 </property>
50 </widget>
51 </item>
52 </layout>
53 </item>
36 </layout> 54 </layout>
37 </widget> 55 </widget>
38 <resources/> 56 <resources/>
39 <connections/> 57 <connections>
58 <connection>
59 <sender>pushButton_2</sender>
60 <signal>clicked()</signal>
61 <receiver>FileWidget</receiver>
62 <slot>addRootItem()</slot>
63 <hints>
64 <hint type="sourcelabel">
65 <x>60</x>
66 <y>283</y>
67 </hint>
68 <hint type="destinationlabel">
69 <x>10</x>
70 <y>343</y>
71 </hint>
72 </hints>
73 </connection>
74 <connection>
75 <sender>pushButton</sender>
76 <signal>clicked()</signal>
77 <receiver>FileWidget</receiver>
78 <slot>delRootItem()</slot>
79 <hints>
80 <hint type="sourcelabel">
81 <x>252</x>
82 <y>283</y>
83 </hint>
84 <hint type="destinationlabel">
85 <x>258</x>
86 <y>324</y>
87 </hint>
88 </hints>
89 </connection>
90 </connections>
91 <slots>
92 <slot>addRootItem()</slot>
93 <slot>delRootItem()</slot>
94 </slots>
40</ui> 95</ui>
diff --git a/src/gatscon/iobase.cpp b/src/gatscon/iobase.cpp
new file mode 100644
index 0000000..309444c
--- /dev/null
+++ b/src/gatscon/iobase.cpp
@@ -0,0 +1 @@
#include "iobase.h"
diff --git a/src/gatscon/iobase.h b/src/gatscon/iobase.h
new file mode 100644
index 0000000..5bd3843
--- /dev/null
+++ b/src/gatscon/iobase.h
@@ -0,0 +1,10 @@
1#ifndef IO_BASE_H
2#define IO_BASE_H
3
4class IoBase
5{
6public:
7 virtual void saveTo( const class QString &sFile )=0;
8};
9
10#endif
diff --git a/src/gatscon/mainwnd.cpp b/src/gatscon/mainwnd.cpp
index 628988e..bddaf08 100644
--- a/src/gatscon/mainwnd.cpp
+++ b/src/gatscon/mainwnd.cpp
@@ -7,11 +7,15 @@
7#include "connectdlg.h" 7#include "connectdlg.h"
8#include "setupproxydlg.h" 8#include "setupproxydlg.h"
9 9
10#include <QLabel>
10#include <QFileDialog> 11#include <QFileDialog>
11 12
12MainWnd::MainWnd() 13MainWnd::MainWnd()
13{ 14{
14 setupUi( this ); 15 setupUi( this );
16
17 pMode = new QLabel( "Idle", this );
18 statusBar()->addPermanentWidget( pMode );
15} 19}
16 20
17MainWnd::~MainWnd() 21MainWnd::~MainWnd()
@@ -23,11 +27,16 @@ void MainWnd::connect()
23 ConnectDlg dlg( this ); 27 ConnectDlg dlg( this );
24 if( dlg.exec() == QDialog::Accepted ) 28 if( dlg.exec() == QDialog::Accepted )
25 { 29 {
30 sCurFile.clear();
26 setCentralWidget( 31 setCentralWidget(
27 new ClientWidget( 32 new ClientWidget(
28 this, dlg.getHostname(), dlg.getPort() 33 this, dlg.getHostname(), dlg.getPort()
29 ) 34 )
30 ); 35 );
36 pMode->setText(
37 QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ).
38 arg( dlg.getPort() )
39 );
31 } 40 }
32} 41}
33 42
@@ -37,11 +46,17 @@ void MainWnd::proxy()
37 46
38 if( dlg.exec() == QDialog::Accepted ) 47 if( dlg.exec() == QDialog::Accepted )
39 { 48 {
49 sCurFile.clear();
40 setCentralWidget( 50 setCentralWidget(
41 new ProxyWidget( 51 new ProxyWidget(
42 this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() 52 this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut()
43 ) 53 )
44 ); 54 );
55 pMode->setText(
56 QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ).
57 arg( QString(dlg.getHostOut()) ).
58 arg( dlg.getPortOut() )
59 );
45 } 60 }
46} 61}
47 62
@@ -53,8 +68,52 @@ void MainWnd::open()
53 if( sFile.isEmpty() ) 68 if( sFile.isEmpty() )
54 return; 69 return;
55 70
71 sCurFile = sFile;
56 setCentralWidget( 72 setCentralWidget(
57 new FileWidget( this, sFile ) 73 new FileWidget( this, sFile )
58 ); 74 );
75 pMode->setText( QString("File mode: %1").arg( sCurFile ) );
76}
77
78void MainWnd::newFile()
79{
80 sCurFile.clear();
81 setCentralWidget(
82 new FileWidget( this )
83 );
84 pMode->setText( QString("File mode: <untitled>") );
85}
86
87void MainWnd::save()
88{
89 if( sCurFile.isEmpty() )
90 {
91 saveAs();
92 }
93 else
94 {
95 IoBase *pIo = dynamic_cast<IoBase *>(centralWidget());
96 if( !pIo )
97 return;
98
99 pIo->saveTo( sCurFile );
100 }
101}
102
103void MainWnd::saveAs()
104{
105 IoBase *pIo = dynamic_cast<IoBase *>(centralWidget());
106 if( !pIo )
107 return;
108
109 QString sFile = QFileDialog::getSaveFileName(
110 this, "GatsCon - save gats file"
111 );
112 if( sFile.isEmpty() )
113 return;
114
115 pIo->saveTo( sFile );
116
117 sCurFile = sFile;
59} 118}
60 119
diff --git a/src/gatscon/mainwnd.h b/src/gatscon/mainwnd.h
index 8f638d8..d1ae080 100644
--- a/src/gatscon/mainwnd.h
+++ b/src/gatscon/mainwnd.h
@@ -14,7 +14,13 @@ public slots:
14 void connect(); 14 void connect();
15 void proxy(); 15 void proxy();
16 void open(); 16 void open();
17 void newFile();
18 void save();
19 void saveAs();
17 20
21private:
22 QString sCurFile;
23 class QLabel *pMode;
18}; 24};
19 25
20#endif 26#endif
diff --git a/src/gatscon/mainwnd.ui b/src/gatscon/mainwnd.ui
index dbf5e11..397860e 100644
--- a/src/gatscon/mainwnd.ui
+++ b/src/gatscon/mainwnd.ui
@@ -131,10 +131,77 @@
131 </hint> 131 </hint>
132 </hints> 132 </hints>
133 </connection> 133 </connection>
134 <connection>
135 <sender>actionE_xit</sender>
136 <signal>triggered()</signal>
137 <receiver>MainWnd</receiver>
138 <slot>close()</slot>
139 <hints>
140 <hint type="sourcelabel">
141 <x>-1</x>
142 <y>-1</y>
143 </hint>
144 <hint type="destinationlabel">
145 <x>215</x>
146 <y>159</y>
147 </hint>
148 </hints>
149 </connection>
150 <connection>
151 <sender>action_New_Gats_File</sender>
152 <signal>triggered()</signal>
153 <receiver>MainWnd</receiver>
154 <slot>newFile()</slot>
155 <hints>
156 <hint type="sourcelabel">
157 <x>-1</x>
158 <y>-1</y>
159 </hint>
160 <hint type="destinationlabel">
161 <x>215</x>
162 <y>159</y>
163 </hint>
164 </hints>
165 </connection>
166 <connection>
167 <sender>action_Save</sender>
168 <signal>triggered()</signal>
169 <receiver>MainWnd</receiver>
170 <slot>save()</slot>
171 <hints>
172 <hint type="sourcelabel">
173 <x>-1</x>
174 <y>-1</y>
175 </hint>
176 <hint type="destinationlabel">
177 <x>215</x>
178 <y>159</y>
179 </hint>
180 </hints>
181 </connection>
182 <connection>
183 <sender>action_Save_As</sender>
184 <signal>triggered()</signal>
185 <receiver>MainWnd</receiver>
186 <slot>saveAs()</slot>
187 <hints>
188 <hint type="sourcelabel">
189 <x>-1</x>
190 <y>-1</y>
191 </hint>
192 <hint type="destinationlabel">
193 <x>215</x>
194 <y>159</y>
195 </hint>
196 </hints>
197 </connection>
134 </connections> 198 </connections>
135 <slots> 199 <slots>
136 <slot>connect()</slot> 200 <slot>connect()</slot>
137 <slot>proxy()</slot> 201 <slot>proxy()</slot>
138 <slot>open()</slot> 202 <slot>open()</slot>
203 <slot>save()</slot>
204 <slot>saveAs()</slot>
205 <slot>newFile()</slot>
139 </slots> 206 </slots>
140</ui> 207</ui>
diff --git a/src/gatscon/proxywidget.cpp b/src/gatscon/proxywidget.cpp
index 28bd1fc..3792e31 100644
--- a/src/gatscon/proxywidget.cpp
+++ b/src/gatscon/proxywidget.cpp
@@ -2,11 +2,14 @@
2#include "proxythread.h" 2#include "proxythread.h"
3 3
4#include "gatstotree.h" 4#include "gatstotree.h"
5#include "treetogats.h"
5 6
6#include <QMessageBox> 7#include <QMessageBox>
7 8
9#include <gats/gatsstream.h>
8#include <gats/types.h> 10#include <gats/types.h>
9#include <bu/sio.h> 11#include <bu/sio.h>
12#include <bu/file.h>
10 13
11using namespace Bu; 14using namespace Bu;
12 15
@@ -33,6 +36,19 @@ ProxyWidget::~ProxyWidget()
33{ 36{
34} 37}
35 38
39void ProxyWidget::saveTo( const QString &sFile )
40{
41 File fOut( sFile.toAscii().constData(), File::WriteNew );
42 Gats::GatsStream gsOut( fOut );
43 QTreeWidgetItem *pRoot = twHistory->invisibleRootItem();
44 for( int j = 0; j < pRoot->childCount(); j++ )
45 {
46 Gats::Object *pObj = treeToGats( pRoot->child( j ) );
47 gsOut.writeObject( pObj );
48 delete pObj;
49 }
50}
51
36void ProxyWidget::sendToClient() 52void ProxyWidget::sendToClient()
37{ 53{
38 try 54 try
diff --git a/src/gatscon/proxywidget.h b/src/gatscon/proxywidget.h
index 0ef1fd4..d6ebf4d 100644
--- a/src/gatscon/proxywidget.h
+++ b/src/gatscon/proxywidget.h
@@ -2,13 +2,14 @@
2#define PROXY_WIDGET_H 2#define PROXY_WIDGET_H
3 3
4#include "ui_proxywidget.h" 4#include "ui_proxywidget.h"
5#include "iobase.h"
5 6
6namespace Gats 7namespace Gats
7{ 8{
8 class Object; 9 class Object;
9}; 10};
10 11
11class ProxyWidget : public QWidget, protected Ui::ProxyWidget 12class ProxyWidget : public QWidget, protected Ui::ProxyWidget, public IoBase
12{ 13{
13 Q_OBJECT; 14 Q_OBJECT;
14public: 15public:
@@ -16,6 +17,8 @@ public:
16 int iPortOut ); 17 int iPortOut );
17 virtual ~ProxyWidget(); 18 virtual ~ProxyWidget();
18 19
20 virtual void saveTo( const QString &sFile );
21
19public slots: 22public slots:
20 void sendToClient(); 23 void sendToClient();
21 void sendToServer(); 24 void sendToServer();
diff --git a/src/gatscon/treetogats.cpp b/src/gatscon/treetogats.cpp
new file mode 100644
index 0000000..a1571d1
--- /dev/null
+++ b/src/gatscon/treetogats.cpp
@@ -0,0 +1,52 @@
1#include "treetogats.h"
2
3#include <QTreeWidgetItem>
4
5#include <gats/types.h>
6
7Gats::Object *treeToGats( QTreeWidgetItem *pRoot )
8{
9 QString sType = pRoot->text( 1 );
10 QByteArray baDat = pRoot->text( 2 ).toAscii();
11 if( sType == "int" )
12 {
13 return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) );
14 }
15 else if( sType == "str" )
16 {
17 return new Gats::String( baDat.constData(), baDat.size() );
18 }
19 else if( sType == "float" )
20 {
21 return new Gats::Float( strtod( baDat.constData(), NULL ) );
22 }
23 else if( sType == "bool" )
24 {
25 return new Gats::Boolean( baDat == "true" );
26 }
27 else if( sType == "list" )
28 {
29 Gats::List *pRet = new Gats::List();
30 for( int j = 0; j < pRoot->childCount(); j++ )
31 {
32 pRet->append( treeToGats( pRoot->child( j ) ) );
33 }
34 return pRet;
35 }
36 else if( sType == "dict" )
37 {
38 Gats::Dictionary *pRet = new Gats::Dictionary();
39 for( int j = 0; j < pRoot->childCount(); j++ )
40 {
41 QTreeWidgetItem *pChild = pRoot->child( j );
42 pRet->insert(
43 pChild->text( 0 ).toAscii().constData(),
44 treeToGats( pChild )
45 );
46 }
47 return pRet;
48 }
49
50 throw Bu::ExceptionBase("Unhandled type found.");
51}
52
diff --git a/src/gatscon/treetogats.h b/src/gatscon/treetogats.h
new file mode 100644
index 0000000..931623d
--- /dev/null
+++ b/src/gatscon/treetogats.h
@@ -0,0 +1,13 @@
1#ifndef TREE_TO_GATS_H
2#define TREE_TO_GATS_H
3
4class QTreeWidgetItem;
5
6namespace Gats
7{
8 class Object;
9};
10
11Gats::Object *treeToGats( QTreeWidgetItem *pRoot );
12
13#endif