14
14
#include < qfile.h>
15
15
#include < qdir.h>
16
16
#include < qmessagebox.h>
17
+ #include < qcheckbox.h>
18
+ #include < qcombobox.h>
19
+ #include < qlineedit.h>
20
+ #include < qdom.h>
17
21
18
22
#include " qf_box.h"
19
23
#include " qf_settings.h"
@@ -22,7 +26,7 @@ struct tQucsSettings QucsSettings;
22
26
23
27
// #########################################################################
24
28
// Loads the settings file and stores the settings.
25
- bool loadSettings ( )
29
+ bool loadSettings ( void )
26
30
{
27
31
bool result = true ;
28
32
@@ -34,6 +38,11 @@ bool loadSettings()
34
38
QString Line, Setting;
35
39
while (!stream.atEnd ()) {
36
40
Line = stream.readLine ();
41
+ if (Line.left (9 ) == " <!DOCTYPE" ) {
42
+ file.close ();
43
+ result = loadXmlSettings ();
44
+ break ;
45
+ }
37
46
Setting = Line.section (' =' ,0 ,0 );
38
47
Line = Line.section (' =' ,1 ,1 );
39
48
if (Setting == " FilterWindow" ) {
@@ -43,7 +52,7 @@ bool loadSettings()
43
52
}
44
53
}
45
54
file.close ();
46
- }
55
+ }
47
56
48
57
file.setName (QDir::homeDirPath ()+QDir::convertSeparators (" /.qucs/qucsrc" ));
49
58
if (!file.open (IO_ReadOnly))
@@ -67,7 +76,7 @@ bool loadSettings()
67
76
68
77
// #########################################################################
69
78
// Saves the settings in the settings file.
70
- bool saveApplSettings (qf_box *qucs)
79
+ bool saveSettings (qf_box *qucs)
71
80
{
72
81
if (qucs->x () == QucsSettings.x )
73
82
if (qucs->y () == QucsSettings.y )
@@ -90,3 +99,170 @@ bool saveApplSettings(qf_box *qucs)
90
99
file.close ();
91
100
return true ;
92
101
}
102
+
103
+ // #########################################################################
104
+ // Saves the application settings in the XML settings file.
105
+ bool saveXmlSettings (qf_box * qucs)
106
+ {
107
+ QDomDocument doc (" QucsFilter" );
108
+ QDomElement el, gr, rt;
109
+
110
+ rt = doc.createElement (" Settings" );
111
+ doc.appendChild (rt);
112
+
113
+ el = doc.createElement (" Version" );
114
+ el.setAttribute (" value" , PACKAGE_VERSION);
115
+ rt.appendChild (el);
116
+
117
+ el = doc.createElement (" Window" );
118
+ el.setAttribute (" x" , qucs->x ());
119
+ el.setAttribute (" y" , qucs->y ());
120
+ rt.appendChild (el);
121
+
122
+ gr = doc.createElement (" LC" );
123
+ el = doc.createElement (" Type" );
124
+ el.setAttribute (" Type" , qucs->FilterName ->currentItem ());
125
+ el.setAttribute (" Class" , qucs->TformName ->currentItem ());
126
+ el.setAttribute (" SpecifyOrder" , qucs->OrderBox ->isChecked ());
127
+ el.setAttribute (" Order" , qucs->OrderCombo ->currentItem ());
128
+ el.setAttribute (" SubOrder" , qucs->SubOrderCombo ->currentItem ());
129
+ gr.appendChild (el);
130
+ el = doc.createElement (" Cutoff" );
131
+ el.setAttribute (" Value" , qucs->EnterCutoff ->text ());
132
+ el.setAttribute (" Unit" , qucs->CutoffCombo ->currentItem ());
133
+ gr.appendChild (el);
134
+ el = doc.createElement (" Bandwidth" );
135
+ el.setAttribute (" Value" , qucs->EnterBandwidth ->text ());
136
+ el.setAttribute (" Unit" , qucs->BandwidthCombo ->currentItem ());
137
+ gr.appendChild (el);
138
+ el = doc.createElement (" Stopband" );
139
+ el.setAttribute (" Value" , qucs->EnterStopband ->text ());
140
+ el.setAttribute (" Unit" , qucs->StopbandCombo ->currentItem ());
141
+ gr.appendChild (el);
142
+ el = doc.createElement (" Ripple" );
143
+ el.setAttribute (" Value" , qucs->EnterRipple ->text ());
144
+ gr.appendChild (el);
145
+ el = doc.createElement (" Angle" );
146
+ el.setAttribute (" Value" , qucs->EnterAngle ->text ());
147
+ gr.appendChild (el);
148
+ el = doc.createElement (" Attenuation" );
149
+ el.setAttribute (" Value" , qucs->EnterAttenuation ->text ());
150
+ gr.appendChild (el);
151
+ el = doc.createElement (" Impedance" );
152
+ el.setAttribute (" Zin" , qucs->EnterZin ->text ());
153
+ el.setAttribute (" Zout" , qucs->EnterZout ->text ());
154
+ gr.appendChild (el);
155
+ rt.appendChild (gr);
156
+
157
+ QFile file (QDir::homeDirPath ()+QDir::convertSeparators (" /.qucs/filterrc" ));
158
+ if (!file.open (IO_WriteOnly)) {
159
+ QMessageBox::warning (0 ,
160
+ QObject::tr (" Warning" ),
161
+ QObject::tr (" Cannot save settings file !" ));
162
+ return false ;
163
+ }
164
+
165
+ QTextStream str (&file);
166
+ str << doc.toString ();
167
+ file.close ();
168
+ return true ;
169
+ }
170
+
171
+ // #########################################################################
172
+ // Helper function to find XML nodes and attributes
173
+ static QString getXml (QDomDocument * doc, const QString type,
174
+ const QString attr, const QString group = " " )
175
+ {
176
+ QDomElement docElem = doc->documentElement ();
177
+
178
+ QDomNode n = docElem.firstChild ();
179
+ while (!n.isNull ()) {
180
+ QDomElement e = n.toElement ();
181
+ if (!e.isNull ()) {
182
+ if (group.isEmpty ()) {
183
+ if (e.tagName () == type) {
184
+ return e.attribute (attr, " " );
185
+ }
186
+ }
187
+ else {
188
+ if (e.tagName () == group) {
189
+ QDomNode ng = e.firstChild ();
190
+ while (!ng.isNull ()) {
191
+ QDomElement eg = ng.toElement ();
192
+ if (!eg.isNull ()) {
193
+ if (eg.tagName () == type) {
194
+ return eg.attribute (attr, " " );
195
+ }
196
+ }
197
+ ng = ng.nextSibling ();
198
+ }
199
+ }
200
+ }
201
+ }
202
+ n = n.nextSibling ();
203
+ }
204
+ return " " ;
205
+ }
206
+
207
+ static int getInteger (QDomDocument * doc, const QString type,
208
+ const QString attr, const QString group = " " )
209
+ {
210
+ return getXml (doc, type, attr, group).toInt ();
211
+ }
212
+
213
+ static double getDouble (QDomDocument * doc, const QString type,
214
+ const QString attr, const QString group = " " )
215
+ {
216
+ return getXml (doc, type, attr, group).toDouble ();
217
+ }
218
+
219
+ static QString getString (QDomDocument * doc, const QString type,
220
+ const QString attr, const QString group = " " )
221
+ {
222
+ return getXml (doc, type, attr, group);
223
+ }
224
+
225
+ // #########################################################################
226
+ // Loads the XML settings file and stores the settings.
227
+ bool loadXmlSettings (void )
228
+ {
229
+ bool result = true ;
230
+
231
+ QFile file (QDir::homeDirPath ()+QDir::convertSeparators (" /.qucs/filterrc" ));
232
+ if (!file.open (IO_ReadOnly))
233
+ result = false ; // settings file doesn't exist
234
+ else {
235
+ QDomDocument doc;
236
+ QString errmsg;
237
+ int line, col;
238
+ if (!doc.setContent (&file, true , &errmsg, &line, &col)) {
239
+ cerr << file.name () << " :" << line << " :" << col
240
+ << " : " << errmsg << endl;
241
+ cerr << doc.toCString ();
242
+ file.close ();
243
+ return false ;
244
+ }
245
+
246
+ QucsSettings.x = getInteger (&doc, " Window" , " x" );
247
+ QucsSettings.y = getInteger (&doc, " Window" , " y" );
248
+
249
+ QucsSettings.type = getInteger (&doc, " Type" , " Type" , " LC" );
250
+ QucsSettings.form = getInteger (&doc, " Type" , " Class" , " LC" );
251
+ QucsSettings.specify = getInteger (&doc, " Type" , " SpecifyOrder" , " LC" );
252
+ QucsSettings.ord = getInteger (&doc, " Type" , " Order" , " LC" );
253
+ QucsSettings.subord = getInteger (&doc, " Type" , " SubOrder" , " LC" );
254
+
255
+ QucsSettings.cutoff = getDouble (&doc, " Cutoff" , " Value" , " LC" );
256
+ QucsSettings.cutoff_unit = getInteger (&doc, " Cutoff" , " Unit" , " LC" );
257
+ QucsSettings.zin = getDouble (&doc, " Impedance" , " Zin" , " LC" );
258
+ QucsSettings.zout = getDouble (&doc, " Impedance" , " Zout" , " LC" );
259
+ QucsSettings.bw = getDouble (&doc, " Bandwidth" , " Value" , " LC" );
260
+ QucsSettings.bw_unit = getInteger (&doc, " Bandwidth" , " Unit" , " LC" );
261
+ QucsSettings.sb = getDouble (&doc, " Stopband" , " Value" , " LC" );
262
+ QucsSettings.sb_unit = getInteger (&doc, " Stopband" , " Unit" , " LC" );
263
+ QucsSettings.ripple = getDouble (&doc, " Ripple" , " Value" , " LC" );
264
+ QucsSettings.angle = getDouble (&doc, " Angle" , " Value" , " LC" );
265
+ QucsSettings.atten = getDouble (&doc, " Attenuation" , " Value" , " LC" );
266
+ }
267
+ return result;
268
+ }
0 commit comments