FGCom: add dialog for FGCom
[fg:toms-fgdata.git] / gui / dialogs / fgcom.xml
1 <?xml version="1.0"?>
2
3 <PropertyList>
4   <name>fgcom</name>
5   <layout>vbox</layout>
6   <resizable>false</resizable>
7
8   <nasal>
9         <open><![CDATA[
10             var autofill = func {
11                 if ((getprop("/sim/fgcom/selected-server") == nil) or 
12                     (getprop("/sim/fgcom/selected-server") == "" )   ){
13                     var tx = getprop("/sim/fgcom/server");
14                     var dlg = cmdarg();
15                     #var servers = cmdarg().getChildren("group")[5].getChildren("combo")[0].getChildren("value");
16                     var servers = props.globals.getNode("/sim/gui/dialogs/multiplay/fgcom-servers", 1);
17                     foreach (var s; servers.getChildren("value")) {
18                         var server = s.getValue();
19                         var host = split(" ", server)[0];
20                         if (host == tx) {
21                             setprop("/sim/fgcom/selected-server", server);
22                         }
23                     }
24                 }
25             }
26             
27             var servers = props.globals.getNode("/sim/gui/dialogs/multiplay/fgcom-servers", 1);
28             var updateServers = func {
29                 servers.removeChildren("value");                
30                 # get the results list from the server
31                 var serverlist = props.globals.getNode("/sim/multiplay/server-list", 1);
32             
33                 var i=0;
34                 foreach (var s; serverlist.getChildren("fgcom")) {
35                     
36                     if (!s.getNode("online").getBoolValue()) {
37                       continue; # skip offline servers
38                     }
39                   
40                 # label is name and location, for the moment
41                 # should we include the number of users? or wait until we
42                 # have a better UI toolkit?
43                     var nm = s.getNode("hostname").getValue() ~ " - " ~ s.getNode("location").getValue();
44                     servers.getNode("value[" ~ i ~ "]", 1).setValue(nm);
45                     i += 1;
46                 }
47
48                 autofill();
49                 gui.dialog_update("fgcom", "server");
50             }
51             
52             var static_serverList = [
53                     ['fgcom.flightgear.org', 'Avignon, France'],
54                     ['delta384.server4you.de', 'Unknown']
55                 ];
56                 
57             var updateServersFailed = func {
58                 debug.dump("Failed to retrieve server list!");
59     
60                 servers.removeChildren("value"); 
61                 var i=0;
62                 foreach (var s; static_serverList) {
63                 # create the node the PUI combo
64                     var nm = s[0] ~ " - " ~ s[1];
65                     servers.getNode("value[" ~ i ~ "]", 1).setValue(nm);
66                     i += 1;
67                 }
68                 
69                 autofill();
70                 gui.dialog_update("fgcom", "server");
71             }
72             
73             # listen for results arriving  
74             setlistener("/sim/multiplay/got-servers", updateServers);
75             setlistener("/sim/multiplay/get-servers-failure", updateServersFailed);
76             
77             fgcommand("xmlhttprequest",  props.Node.new({
78               "url" : "http://liveries.flightgear.org/mpstatus/mpservers.xml",
79               "targetnode" : "/sim/multiplay/server-list",
80               "complete" : "/sim/multiplay/got-servers",
81               "failure" : "/sim/multiplay/get-servers-failure"
82             }));
83             ]]>
84         </open>
85     <close>
86     </close>
87   </nasal>
88
89   <!-- titlebar -->
90   <group>
91     <layout>hbox</layout>
92     <empty>
93       <stretch>1</stretch>
94     </empty>
95
96     <text>
97       <label>FGCom Settings</label>
98     </text>
99
100     <empty>
101       <stretch>1</stretch>
102     </empty>
103
104     <button>
105       <pref-width>16</pref-width>
106       <pref-height>16</pref-height>
107       <legend></legend>
108       <keynum>27</keynum>
109       <border>2</border>
110       <binding>
111         <command>dialog-close</command>
112       </binding>
113     </button>
114   </group>
115   <hrule/>
116
117   <!-- main dialog area -->
118   <group>
119     <layout>table</layout>
120     <halign>left</halign>
121
122     <text>
123       <row>0</row>
124       <col>0</col>
125       <label>Enabled:</label>
126       <halign>right</halign>
127     </text>
128     <checkbox>
129       <row>0</row>
130       <col>1</col>
131       <colspan>2</colspan>
132       <halign>left</halign>
133       <name>enabled</name>
134       <label></label>
135       <property>/sim/fgcom/enabled</property>
136       <binding>
137         <command>dialog-apply</command>
138         <object-name>enabled</object-name>
139       </binding>
140     </checkbox>
141
142     <text>
143       <row>2</row>
144       <col>0</col>
145       <label>Mic Volume:</label>
146       <halign>right</halign>
147     </text>
148     <slider>
149       <row>2</row>
150       <col>1</col>
151       <colspan>2</colspan>
152       <halign>left</halign>
153       <name>mic-vol</name>
154       <label></label>
155       <min>0</min>
156       <max>1.0</max>
157       <step>0.1</step>
158       <property>/sim/fgcom/mic-level</property>
159       <binding>
160         <command>dialog-apply</command>
161         <object-name>mic-vol</object-name>
162       </binding>
163     </slider>
164
165     <text>
166       <row>3</row>
167       <col>0</col>
168       <label>Speaker Volume:</label>
169       <halign>right</halign>
170     </text>
171     <slider>
172       <row>3</row>
173       <col>1</col>
174       <colspan>2</colspan>
175       <halign>left</halign>
176       <name>speaker-vol</name>
177       <label></label>
178       <min>0</min>
179       <max>1.0</max>
180       <step>0.1</step>
181       <property>/sim/fgcom/speaker-level</property>
182       <binding>
183         <command>dialog-apply</command>
184         <object-name>speaker-vol</object-name>
185       </binding>
186     </slider>
187   </group>
188
189   <hrule/>
190
191   <!-- registration -->
192   <group>
193     <layout>hbox</layout>
194     <empty>
195       <stretch>1</stretch>
196     </empty>
197
198     <text>
199       <label>Registration</label>
200     </text>
201
202     <empty>
203       <stretch>1</stretch>
204     </empty>
205   </group>
206
207   <group>
208     <layout>table</layout>
209     <halign>left</halign>
210
211     <text>
212       <row>0</row>
213       <col>0</col>
214       <halign>right</halign>
215       <label>Enabled:</label>
216       <enable>
217         <equals>
218           <property>/sim/fgcom/enabled</property>
219           <value>0</value>
220         </equals>
221       </enable>
222     </text>
223     <checkbox>
224       <row>0</row>
225       <col>1</col>
226       <colspan>2</colspan>
227       <halign>left</halign>
228       <name>reg-enabled</name>
229       <label></label>
230       <property>/sim/fgcom/register/enabled</property>
231       <enable>
232         <equals>
233           <property>/sim/fgcom/enabled</property>
234           <value>0</value>
235         </equals>
236       </enable>
237       <binding>
238         <command>dialog-apply</command>
239         <object-name>reg-enabled</object-name>
240       </binding>
241     </checkbox>
242
243     <text>
244       <row>1</row>
245       <col>0</col>
246       <halign>right</halign>
247       <label>Username:</label>
248       <enable>
249         <equals>
250           <property>/sim/fgcom/enabled</property>
251           <value>0</value>
252         </equals>
253       </enable>
254     </text>
255     <input>
256       <name>username</name>
257       <row>1</row>
258       <col>1</col>
259       <colspan>2</colspan>
260       <halign>left</halign>
261       <pref-width>125</pref-width>
262       <editable>true</editable>
263       <property>/sim/fgcom/register/username</property>
264       <enable>
265         <equals>
266           <property>/sim/fgcom/enabled</property>
267           <value>0</value>
268         </equals>
269       </enable>
270       <binding>
271         <command>dialog-apply</command>
272         <object-name>username</object-name>
273       </binding>
274     </input>
275
276     <text>
277       <row>2</row>
278       <col>0</col>
279       <halign>right</halign>
280       <label>Password:</label>
281       <enable>
282         <equals>
283           <property>/sim/fgcom/enabled</property>
284           <value>0</value>
285         </equals>
286       </enable>
287     </text>
288     <input>
289       <name>password</name>
290       <row>2</row>
291       <col>1</col>
292       <colspan>2</colspan>
293       <halign>left</halign>
294       <pref-width>125</pref-width>
295       <editable>true</editable>
296       <property>/sim/fgcom/register/password</property>
297       <enable>
298         <equals>
299           <property>/sim/fgcom/enabled</property>
300           <value>0</value>
301         </equals>
302       </enable>
303       <binding>
304         <command>dialog-apply</command>
305         <object-name>password</object-name>
306       </binding>
307     </input>
308   </group>
309
310   <hrule/>
311
312   <!-- server -->
313   <group>
314     <layout>hbox</layout>
315     <empty>
316       <stretch>1</stretch>
317     </empty>
318
319     <text>
320       <label>Server</label>
321     </text>
322
323     <empty>
324       <stretch>1</stretch>
325     </empty>
326   </group>
327
328   <group>
329     <layout>table</layout>
330     <halign>left</halign>
331
332     <text>
333       <row>0</row>
334       <col>0</col>
335       <label>Test:</label>
336       <halign>right</halign>
337     </text>
338     <checkbox>
339       <row>0</row>
340       <col>1</col>
341       <colspan>2</colspan>
342       <halign>left</halign>
343       <name>test</name>
344       <label></label>
345       <property>/sim/fgcom/test</property>
346       <binding>
347         <command>dialog-apply</command>
348         <object-name>test</object-name>
349       </binding>
350     </checkbox>
351
352     <combo>
353       <name>server</name>
354       <row>1</row>
355       <col>0</col>
356       <colspan>6</colspan>
357       <pref-width>275</pref-width>
358       <editable>false</editable>
359       <property>/sim/fgcom/selected-server</property>
360       <properties>/sim/gui/dialogs/multiplay/fgcom-servers</properties>
361       <binding>
362         <command>dialog-apply</command>
363         <object-name>server</object-name>
364       </binding>
365       <binding>
366         <command>nasal</command>
367         <script>
368           <![CDATA[
369                  setprop("/sim/fgcom/enabled", 0);
370
371                  var server = getprop("/sim/fgcom/selected-server");
372                  server = split(" ", server)[0];
373                  setprop("/sim/fgcom/server", server);
374
375                  setprop("/sim/fgcom/enabled", 1);
376              ]]>
377         </script>
378       </binding>
379       <binding>
380         <command>dialog-apply</command>
381         <object-name>test</object-name>
382       </binding>
383     </combo>
384
385   </group>
386
387   <!-- button area -->
388
389   <hrule/>
390   <group>
391     <layout>hbox</layout>
392     <default-padding>10</default-padding>
393     <empty>
394       <stretch>true</stretch>
395     </empty>
396
397     <button>
398       <legend>Close</legend>
399       <default>true</default>
400       <equal>true</equal>
401       <binding>
402         <command>dialog-close</command>
403       </binding>
404     </button>
405
406     <empty>
407       <stretch>true</stretch>
408     </empty>
409   </group>
410
411 </PropertyList>
412