summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index b4d9aaa..13979ce 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -28,14 +28,13 @@ NetworkSettingsData::NetworkSettingsData( void ) {
28// saving is done by caller 28// saving is done by caller
29NetworkSettingsData::~NetworkSettingsData( void ) { 29NetworkSettingsData::~NetworkSettingsData( void ) {
30 delete NSResources; 30 delete NSResources;
31} 31}
32 32
33void NetworkSettingsData::loadSettings( void ) { 33void NetworkSettingsData::loadSettings( void ) {
34 QString S; 34 QString Line, S;
35 ANetNodeInstance* NNI;
36 QString Attr, Value; 35 QString Attr, Value;
37 long idx; 36 long idx;
38 37
39 QFile F( CfgFile ); 38 QFile F( CfgFile );
40 QTextStream TS( &F ); 39 QTextStream TS( &F );
41 40
@@ -54,13 +53,13 @@ void NetworkSettingsData::loadSettings( void ) {
54 [connection] 53 [connection]
55 Name=Name 54 Name=Name
56 Node=Name 55 Node=Name
57 <EMPTYLINE> 56 <EMPTYLINE>
58 */ 57 */
59 while( ! TS.atEnd() ) { 58 while( ! TS.atEnd() ) {
60 S = TS.readLine(); 59 S = Line = TS.readLine();
61 60
62 if ( S.isEmpty() || S[0] != '[' ) 61 if ( S.isEmpty() || S[0] != '[' )
63 continue; 62 continue;
64 63
65 S = S.mid( 1, S.length()-2 ); 64 S = S.mid( 1, S.length()-2 );
66 65
@@ -70,26 +69,32 @@ void NetworkSettingsData::loadSettings( void ) {
70 69
71 if( S == "connection" ) { 70 if( S == "connection" ) {
72 // load connections -> collections of nodes 71 // load connections -> collections of nodes
73 NodeCollection * NC = new NodeCollection( TS ); 72 NodeCollection * NC = new NodeCollection( TS );
74 NSResources->addConnection( NC ); 73 NSResources->addConnection( NC );
75 } else { 74 } else {
76 // load nodes 75 ANetNode * NN = 0;
76 ANetNodeInstance* NNI = 0;
77 if( S.startsWith( "nodetype " ) ) {
78 S = S.mid( 9, S.length()-9-1 );
79 fprintf( stderr, "Node %s\n", S.latin1() );
80 // try to find netnode
81 NN = NSResources->findNetNode( S );
82 } else {
83 // try to find instance
77 NNI = NSResources->createNodeInstance( S ); 84 NNI = NSResources->createNodeInstance( S );
78 if( ! NNI ) {
79 printf( "SKIPPING %s\n", S.latin1() );
80 } 85 }
81 86
82 do { 87 do {
83 S = TS.readLine(); 88 S = TS.readLine();
89
90 if( NN || NNI ) {
84 if( S.isEmpty() ) { 91 if( S.isEmpty() ) {
85 // empty line 92 // empty line
86 break; 93 break;
87 } 94 }
88 // node found ?
89 if( NNI ) {
90 idx = S.find( '=' ); 95 idx = S.find( '=' );
91 if( idx > 0 ) { 96 if( idx > 0 ) {
92 Attr = S.left( idx ); 97 Attr = S.left( idx );
93 Value = S.mid( idx+1, S.length() ); 98 Value = S.mid( idx+1, S.length() );
94 } else { 99 } else {
95 Value=""; 100 Value="";
@@ -99,16 +104,27 @@ void NetworkSettingsData::loadSettings( void ) {
99 Value.stripWhiteSpace(); 104 Value.stripWhiteSpace();
100 Attr.stripWhiteSpace(); 105 Attr.stripWhiteSpace();
101 Attr.lower(); 106 Attr.lower();
102 // dequote Attr 107 // dequote Attr
103 Value = deQuote(Value); 108 Value = deQuote(Value);
104 109
110 if( NN ) {
111 // set the attribute
112 NNI->setAttribute( Attr, Value );
113 } else {
105 // set the attribute 114 // set the attribute
106 NNI->setAttribute( Attr, Value ); 115 NNI->setAttribute( Attr, Value );
107 } 116 }
108 117 } else {
118 LeftOvers.append( Line );
119 // add empty line too as delimiter
120 if( S.isEmpty() ) {
121 // empty line
122 break;
123 }
124 }
109 } while( 1 ); 125 } while( 1 );
110 if( NNI ) { 126 if( NNI ) {
111 // loading from file -> exists 127 // loading from file -> exists
112 NNI->setNew( FALSE ); 128 NNI->setNew( FALSE );
113 NSResources->addNodeInstance( NNI ); 129 NSResources->addNodeInstance( NNI );
114 } 130 }
@@ -135,12 +151,31 @@ QString NetworkSettingsData::saveSettings( void ) {
135 arg(CfgFile); 151 arg(CfgFile);
136 // problem 152 // problem
137 return ErrS; 153 return ErrS;
138 } 154 }
139 155
140 QTextStream TS( &F ); 156 QTextStream TS( &F );
157
158 // save leftovers
159 for ( QStringList::Iterator it = LeftOvers.begin();
160 it != LeftOvers.end(); ++it ) {
161 TS << (*it) << endl;
162 }
163
164 // save global configs
165 for( QDictIterator<NetNode_t> it( NSResources->netNodes() );
166 it.current();
167 ++it ) {
168 TS << "[nodetype "
169 << it.current()->NetNode->name()
170 << "]"
171 << endl;
172
173 it.current()->NetNode->saveAttributes( TS );
174 }
175
141 { Name2Connection_t & M = NSResources->connections(); 176 { Name2Connection_t & M = NSResources->connections();
142 ANetNodeInstance * NNI; 177 ANetNodeInstance * NNI;
143 178
144 // for all connections 179 // for all connections
145 for( QDictIterator<NodeCollection> it(M); 180 for( QDictIterator<NodeCollection> it(M);
146 it.current(); 181 it.current();