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
@@ -22,99 +22,115 @@ NetworkSettingsData::NetworkSettingsData( void ) {
22 // load settings 22 // load settings
23 Force = 0; 23 Force = 0;
24 IsModified = 0; 24 IsModified = 0;
25 loadSettings(); 25 loadSettings();
26} 26}
27 27
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
42 do { 41 do {
43 42
44 if( ! F.open(IO_ReadOnly) ) 43 if( ! F.open(IO_ReadOnly) )
45 break; 44 break;
46 45
47 /* load the file -> 46 /* load the file ->
48 47
49 FORMAT : 48 FORMAT :
50 49
51 [NETNODETYPE] 50 [NETNODETYPE]
52 Entries ... 51 Entries ...
53 <EMPTYLINE> 52 <EMPTYLINE>
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
67 if( ! NSResources ) { 66 if( ! NSResources ) {
68 continue; 67 continue;
69 } 68 }
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="";
96 Attr = S; 101 Attr = S;
97 } 102 }
98 103
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 }
115 } 131 }
116 } 132 }
117 133
118 } while( 0 ); 134 } while( 0 );
119 135
120} 136}
@@ -129,24 +145,43 @@ QString NetworkSettingsData::saveSettings( void ) {
129 QFile F( CfgFile + ".bup" ); 145 QFile F( CfgFile + ".bup" );
130 146
131 printf( "Saving settings to %s\n", CfgFile.latin1() ); 147 printf( "Saving settings to %s\n", CfgFile.latin1() );
132 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { 148 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
133 ErrS = qApp->translate( "NetworkSettings", 149 ErrS = qApp->translate( "NetworkSettings",
134 "<p>Could not save setup to \"%1\" !</p>" ). 150 "<p>Could not save setup to \"%1\" !</p>" ).
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();
147 ++it ) { 182 ++it ) {
148 // all nodes in those connections 183 // all nodes in those connections
149 for( QListIterator<ANetNodeInstance> nit(*(it.current())); 184 for( QListIterator<ANetNodeInstance> nit(*(it.current()));
150 nit.current(); 185 nit.current();
151 ++nit ) { 186 ++nit ) {
152 // header 187 // header