rwdmpd 0.06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/Readme.txt +475 -0
  2. data/bin/rwdmpd +19 -0
  3. data/code/01rwdcore/01rwdcore.rb +29 -0
  4. data/code/01rwdcore/02helptexthashbegin.rb +4 -0
  5. data/code/01rwdcore/03helptexthash.rb +23 -0
  6. data/code/01rwdcore/04helptextend.rb +6 -0
  7. data/code/01rwdcore/jumplinkcommand.rb +26 -0
  8. data/code/01rwdcore/openhelpwindow.rb +31 -0
  9. data/code/01rwdcore/returntomain.rb +10 -0
  10. data/code/01rwdcore/rundocuments.rb +10 -0
  11. data/code/01rwdcore/runeditconfiguration.rb +10 -0
  12. data/code/01rwdcore/runhelpabout.rb +10 -0
  13. data/code/01rwdcore/runopentinkerdocument.rb +7 -0
  14. data/code/01rwdcore/rwdtinkerversion.rb +22 -0
  15. data/code/01rwdcore/rwdwindowreturn.rb +9 -0
  16. data/code/01rwdcore/selectiontab.rb +9 -0
  17. data/code/01rwdcore/setuphelpaboutoptions.rb +13 -0
  18. data/code/01rwdcore/setuptinkerdocuments.rb +6 -0
  19. data/code/01rwdcore/test_cases.rb +109 -0
  20. data/code/01rwdcore/test_harness.rb +13 -0
  21. data/code/01rwdcore/uploadreturns.rb +62 -0
  22. data/code/dd0viewphoto/dd0viewphoto.rb +3 -0
  23. data/code/superant.com.rwdmp3/0uninstallapplet.rb +11 -0
  24. data/code/superant.com.rwdmp3/clearscreendisplay.rb +7 -0
  25. data/code/superant.com.rwdmp3/controlmpd.rb +139 -0
  26. data/code/superant.com.rwdmp3/helptexthashrwdmp3.rb +41 -0
  27. data/code/superant.com.rwdmp3/listplaylistfiles.rb +12 -0
  28. data/code/superant.com.rwdmp3/loadconfigurationrecord.rb +22 -0
  29. data/code/superant.com.rwdmp3/loadconfigurationvariables.rb +13 -0
  30. data/code/superant.com.rwdmp3/loadplaylistrecord.rb +19 -0
  31. data/code/superant.com.rwdmp3/mpd_client.rb +41 -0
  32. data/code/superant.com.rwdmp3/mpd_seek.rb +23 -0
  33. data/code/superant.com.rwdmp3/openhelpwindowrwdmp3.rb +25 -0
  34. data/code/superant.com.rwdmp3/runrwdmpdwindow.rb +10 -0
  35. data/code/superant.com.rwdmp3/rwdtinkerversion.rb +10 -0
  36. data/code/superant.com.rwdmp3/saveconfigurationrecord.rb +19 -0
  37. data/code/superant.com.rwdmp3/saveplaylistrecord.rb +18 -0
  38. data/code/superant.com.rwdmp3/startmp3server.rb +16 -0
  39. data/code/superant.com.rwdtinkerbackwindow/diagnostictab.rb +19 -0
  40. data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +61 -0
  41. data/code/superant.com.rwdtinkerbackwindow/initiateapplets.rb +240 -0
  42. data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +34 -0
  43. data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +20 -0
  44. data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
  45. data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +53 -0
  46. data/code/superant.com.rwdtinkerbackwindow/listinstalledfiles.rb +12 -0
  47. data/code/superant.com.rwdtinkerbackwindow/listzips.rb +33 -0
  48. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationrecord.rb +22 -0
  49. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationvariables.rb +14 -0
  50. data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
  51. data/code/superant.com.rwdtinkerbackwindow/openappletname.rb +19 -0
  52. data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +38 -0
  53. data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
  54. data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +46 -0
  55. data/code/superant.com.rwdtinkerbackwindow/removeappletvariables.rb +52 -0
  56. data/code/superant.com.rwdtinkerbackwindow/runremoteinstall.rb +11 -0
  57. data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +15 -0
  58. data/code/superant.com.rwdtinkerbackwindow/rwdtinkerwin2version.rb +13 -0
  59. data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +19 -0
  60. data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +22 -0
  61. data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +24 -0
  62. data/code/zz0applicationend/zz0end.rb +4 -0
  63. data/configuration/language.dist +8 -0
  64. data/configuration/rwdapplicationidentity.dist +3 -0
  65. data/configuration/rwdtinker.dist +15 -0
  66. data/configuration/rwdwmpd-0.06.dist +14 -0
  67. data/configuration/tinkerwin2variables.dist +18 -0
  68. data/gui/00coreguibegin/applicationguitop.rwd +4 -0
  69. data/gui/frontwindow0/cc0openphoto.rwd +22 -0
  70. data/gui/frontwindowselections/00selectiontabbegin.rwd +11 -0
  71. data/gui/frontwindowselections/jumplinkcommands.rwd +15 -0
  72. data/gui/frontwindowselections/wwselectionend.rwd +3 -0
  73. data/gui/frontwindowtdocuments/00documentbegin.rwd +6 -0
  74. data/gui/frontwindowtdocuments/tinkerdocuments.rwd +14 -0
  75. data/gui/frontwindowtdocuments/zzdocumentend.rwd +8 -0
  76. data/gui/helpaboutbegin/zzzrwdlasttab.rwd +6 -0
  77. data/gui/helpaboutbegin/zzzzhelpscreenstart.rwd +3 -0
  78. data/gui/helpaboutbegin/zzzzzzhelpabouttab.rwd +15 -0
  79. data/gui/helpaboutzend/helpscreenend.rwd +3 -0
  80. data/gui/helpaboutzend/zhelpscreenstart2.rwd +3 -0
  81. data/gui/helpaboutzend/zzzzhelpabout2.rwd +15 -0
  82. data/gui/helpaboutzend/zzzzhelpscreen2end.rwd +3 -0
  83. data/gui/tinkerbackwindows/superant.com.rwdmp3/10appletbegin.rwd +4 -0
  84. data/gui/tinkerbackwindows/superant.com.rwdmp3/20rwdmpd.rwd +37 -0
  85. data/gui/tinkerbackwindows/superant.com.rwdmp3/25rwdseek.rwd +23 -0
  86. data/gui/tinkerbackwindows/superant.com.rwdmp3/30editplaylist.rwd +27 -0
  87. data/gui/tinkerbackwindows/superant.com.rwdmp3/88viewconfiguration.rwd +32 -0
  88. data/gui/tinkerbackwindows/superant.com.rwdmp3/89rwddiagnostics.rwd +26 -0
  89. data/gui/tinkerbackwindows/superant.com.rwdmp3/90jumplinkcommands.rwd +17 -0
  90. data/gui/tinkerbackwindows/superant.com.rwdmp3/9end.rwd +6 -0
  91. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/1appname.rwd +5 -0
  92. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +41 -0
  93. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
  94. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +44 -0
  95. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +30 -0
  96. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/70rwddiagnostics.rwd +29 -0
  97. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/81jumplinkcommands.rwd +17 -0
  98. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/9backend.rwd +6 -0
  99. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +31 -0
  100. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/9end.rwd +4 -0
  101. data/gui/tinkerbackwindows/superant.com.versionwindow/1appname.rwd +19 -0
  102. data/gui/tinkerbackwindows/superant.com.versionwindow/helpaboutwindow.rwd +17 -0
  103. data/gui/zzcoreguiend/yy9rwdend.rwd +4 -0
  104. data/init.rb +277 -0
  105. data/installed/mpdmusicdata2.inf +2 -0
  106. data/installed/rwdwmpd-0.06.inf +10 -0
  107. data/installed/temp.rb +1 -0
  108. data/lang/en/rwdcore/languagefile.rb +58 -0
  109. data/lang/es/rwdcore/languagefile-es.rb +62 -0
  110. data/lang/fr/rwdcore/languagefile.rb +64 -0
  111. data/lang/jp/rwdcore/languagefile.rb +72 -0
  112. data/lang/nl/rwdcore/languagefile.rb +75 -0
  113. data/lib/librmpd.rb +1152 -0
  114. data/lib/mpdserver.rb +1204 -0
  115. data/lib/rconftool.rb +387 -0
  116. data/lib/rwd/browser.rb +123 -0
  117. data/lib/rwd/ftools.rb +174 -0
  118. data/lib/rwd/mime.rb +328 -0
  119. data/lib/rwd/net.rb +876 -0
  120. data/lib/rwd/ruby.rb +889 -0
  121. data/lib/rwd/rwd.rb +1422 -0
  122. data/lib/rwd/sgml.rb +236 -0
  123. data/lib/rwd/thread.rb +63 -0
  124. data/lib/rwd/tree.rb +371 -0
  125. data/lib/rwd/xml.rb +101 -0
  126. data/lib/rwdthemes/default.rwd +317 -0
  127. data/lib/rwdthemes/pda.rwd +72 -0
  128. data/lib/rwdthemes/windowslike.rwd +171 -0
  129. data/lib/zip/ioextras.rb +114 -0
  130. data/lib/zip/stdrubyext.rb +111 -0
  131. data/lib/zip/tempfile_bugfixed.rb +195 -0
  132. data/lib/zip/zip.rb +1378 -0
  133. data/lib/zip/zipfilesystem.rb +558 -0
  134. data/lib/zip/ziprequire.rb +61 -0
  135. data/music/classicalmues.mp3 +0 -0
  136. data/rwd_files/HowTo_Mpd.txt +136 -0
  137. data/rwd_files/HowTo_Tinker.txt +482 -0
  138. data/rwd_files/HowTo_TinkerWin2.txt +202 -0
  139. data/rwd_files/Readme.txt +57 -0
  140. data/rwd_files/RubyWebDialogs.html +6 -0
  141. data/rwd_files/favicon.ico +0 -0
  142. data/rwd_files/rdoc-style.css +175 -0
  143. data/rwd_files/rwdapplications.html +54 -0
  144. data/rwd_files/tinker.png +0 -0
  145. data/rwdconfig.dist +22 -0
  146. data/rwdmpd.rb +1 -0
  147. data/tests/RubyGauge.rb +179 -0
  148. data/tests/checkdepends.sh +4 -0
  149. data/tests/cleancnf.sh +6 -0
  150. data/tests/makedist-rwdwmpd.rb +58 -0
  151. data/tests/makedist.rb +66 -0
  152. data/tests/rdep.rb +354 -0
  153. data/tests/totranslate.lang +93 -0
  154. data/zips/rwdwaddresses-1.06.zip +0 -0
  155. data/zips/rwdwcalc-0.62.zip +0 -0
  156. data/zips/rwdwfoldeditor-0.04.zip +0 -0
  157. data/zips/rwdwgutenberg-0.09.zip +0 -0
  158. data/zips/rwdwmpd-0.06.zip +0 -0
  159. data/zips/rwdwruby-1.07.zip +0 -0
  160. data/zips/temp.rb +1 -0
  161. data/zips/tinkerbellw-0.02.zip +0 -0
  162. data/zips/wrubyslippers-1.06.zip +0 -0
  163. metadata +220 -0
@@ -0,0 +1,1422 @@
1
+ require "lib/rwd/ruby"
2
+ require "lib/rwd/xml"
3
+ require "lib/rwd/net"
4
+ require "lib/rwd/browser"
5
+ require "lib/rwd/thread"
6
+ require "md5"
7
+ require "rbconfig"
8
+
9
+
10
+
11
+ begin
12
+ require "win32ole"
13
+ require "win32/registry"
14
+ rescue LoadError
15
+ $".push "win32ole.so"
16
+ $".push "win32/registry.rb"
17
+ end
18
+
19
+ $rwd_exit = ARGV.include?("--rwd-exit") # Hack ???
20
+ $rwd_exit = true if defined?(REQUIRE2LIB)
21
+ $rwd_debug = ($rwd_debug or $DEBUG or false)
22
+ $rwd_border = ($rwd_border or 0)
23
+ $rwd_dir = Dir.pwd
24
+ $rwd_files = File.expand_path("rwd_files", Dir.pwd)
25
+ $rwd_html = {}
26
+
27
+ ARGV.delete_if do |arg|
28
+ arg =~ /^--rwd-/
29
+ end
30
+
31
+ RWDEmptyline = "..."
32
+
33
+ #module RWD
34
+
35
+ rcfile = nil
36
+ s = ENV["HOME"] ; s = File.expand_path(".rwdrc", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s))
37
+ s = ENV["USERPROFILE"] ; s = File.expand_path("rwd.cfg", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s))
38
+ s = ENV["windir"] ; s = File.expand_path("rwd.cfg", s) unless s.nil? ; rcfile = s if (not s.nil? and rcfile.nil? and File.file?(s))
39
+
40
+ AL = "align='left'"
41
+ AC = "align='center'"
42
+ AR = "align='right'"
43
+ VA = "valign='middle'"
44
+
45
+ Format = "\n<!-- %-10s %-10s -->\t"
46
+
47
+ unless rcfile.nil?
48
+ puts "Reading #{rcfile} ..."
49
+
50
+ Hash.file(rcfile).each do |k, v|
51
+ ENV[k] = v unless ENV.include?(k)
52
+ end
53
+ end
54
+
55
+ if ENV["RWDTHEME"]
56
+ if ENV["RWDTHEME"] = "PDA"
57
+ load 'lib/rwdthemes/default.rwd'
58
+ end
59
+ if ENV["RWDTHEME"] = "DEFAULT"
60
+ $stderr.puts "loading theme DEFAULT"
61
+ load 'lib/rwdthemes/default.rwd'
62
+ end
63
+ if ENV["RWDTHEME"] = "WINDOWSLOOKALIKE"
64
+ load 'lib/rwdthemes/windowslike.rwd'
65
+ end
66
+ else
67
+ load 'lib/rwdthemes/default.rwd'
68
+ end
69
+
70
+ ENV["RWDBROWSER"] = (ENV["RWDBROWSER"] or defaultbrowser) or puts "No browser found."
71
+ ENV["RWDPORTS"] = (ENV["RWDPORTS"] or "7701-7709")
72
+ ENV["RWDTHEME"] = (ENV["RWDTHEME"] or "DEFAULT")
73
+
74
+ #trap("INT") {puts "Terminating..." ; exit}
75
+
76
+ $SAFE = 0
77
+
78
+ class IE
79
+ def initialize(url)
80
+ @ie = WIN32OLE.new("InternetExplorer.Application")
81
+ @ev = WIN32OLE_EVENT.new(@ie, "DWebBrowserEvents2")
82
+
83
+ @ie.navigate(url)
84
+
85
+ @ie.menubar = false
86
+ @ie.toolbar = false
87
+ @ie.addressbar = false
88
+ @ie.statusbar = false
89
+
90
+ @ie.visible = true
91
+
92
+ at_exit do
93
+ @ie.visible = false
94
+ end
95
+
96
+ @ev.on_event("OnQuit") do
97
+ Thread.main.exit
98
+ end
99
+
100
+ Thread.new do
101
+ loop do
102
+ WIN32OLE_EVENT.message_loop
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ class Array
109
+ def rwd_options(emptyline=nil)
110
+ if emptyline.nil?
111
+ a = self
112
+ else
113
+ a = [emptyline].concat(self)
114
+ end
115
+
116
+ a.numsort.collect{|s| "<option>#{s.to_s.to_html}</option>" }.join("\n")
117
+ end
118
+
119
+ def rwd_method(method)
120
+ res = ""
121
+
122
+ self.each do |s|
123
+ s = s.join("/") if s.kind_of?(Array)
124
+ s2 = s.dup
125
+ s2[0..0] = s2[0..0].upcase
126
+ res = res + "<p align='left'><a action='#{method}/#{s.to_html}'>#{s2.to_html}</a></p>"
127
+ end
128
+
129
+ return res
130
+ end
131
+
132
+ def rwd_row(key=nil, value=nil, bold=false)
133
+ res = ""
134
+
135
+ res = res + "<row valign='top'>"
136
+ res = res + "<radio name='#{key.to_html}' value='#{value.to_html}'/>" unless key.nil?
137
+ res = res + self.collect{|s| "<p align='#{(s.kind_of?(Numeric) or s =~ /^\d+\.\d+$/) ? "right" : "left"}'>#{"<b>" if bold}#{s.to_s.to_html}#{"</b>" if bold}</p>"}.join("")
138
+ res = res + "</row>"
139
+
140
+ return res
141
+ end
142
+
143
+ def rwd_table(headers=nil, highlightrows=[])
144
+ res = ""
145
+
146
+ highlightrows = [highlightrows].flatten
147
+
148
+ n = -1
149
+
150
+ res = res + "<table>"
151
+ res = res + headers.rwd_row(nil, nil, true) unless headers.nil?
152
+ res = res + self.collect{|a| a.rwd_row(nil, nil, highlightrows.include?(n+=1))}.join("")
153
+ res = res + "</table>"
154
+
155
+ return res
156
+ end
157
+
158
+ def rwd_headers(emptyfield=false)
159
+ res = ""
160
+
161
+ res = res + "<row>"
162
+ res = res + "<p/>" if emptyfield
163
+ res = res + self.collect{|s| "<p align='left'><b>#{s.to_html}</b></p>" }.join("")
164
+ res = res + "</row>"
165
+
166
+ return res
167
+ end
168
+
169
+ def rwd_form(prefix, values=[], twoparts=0, options={})
170
+ res = []
171
+
172
+ res << "<table>"
173
+ self.each_index do |n|
174
+ name = "#{prefix.to_html}#{self[n].downcase.to_html}"
175
+
176
+ res << "<row>"
177
+ res << "<p align='right'>"
178
+ res << "#{self[n].to_html}:"
179
+ res << "</p>"
180
+
181
+ if options.keys.include?(self[n])
182
+ res << "<select name='#{name}'>"
183
+ res << options[self[n]].rwd_options(RWDEmptyline)
184
+ res << "</select>"
185
+ else
186
+ s = ""
187
+
188
+ s << "<text name='#{name}'"
189
+ s << " value='#{values[n].to_s.to_html}'" if n < values.length
190
+ s << "/>"
191
+
192
+ res << s
193
+ end
194
+
195
+ res << "</row>"
196
+
197
+ if twoparts > 0 and n == twoparts-1
198
+ res << "<row><empty/></row>"
199
+ end
200
+ end
201
+ res << "</table>"
202
+
203
+ return res.join("\n")
204
+ end
205
+ end
206
+
207
+ class Hash
208
+ def rwd_table(field=nil, joinwith=nil, headers=nil)
209
+ res = []
210
+
211
+ res << "<table>"
212
+ res << headers.rwd_headers((not field.nil?)) if not headers.nil?
213
+ self.keys.numsort.each do |key|
214
+ key2 = key
215
+ value2 = self[key]
216
+
217
+ key2 = key2.join(joinwith) if key2.kind_of?(Array)
218
+ value2 = [value2] if value2.kind_of?(String)
219
+
220
+ res << value2.rwd_row(field, key2)
221
+ end
222
+ res << "</table>"
223
+
224
+ res.join("\n")
225
+ end
226
+ end
227
+
228
+ class EVTable
229
+ def rwd_table(field=nil, joinwith=@sep)
230
+ super(field, joinwith, @headers)
231
+ end
232
+
233
+ def rwd_form(prefix="", key=nil, twoparts=false)
234
+ values = self[key] if not key.nil?
235
+ values = [] if values.nil?
236
+ options = {}
237
+
238
+ if File.file?(oldlocation("constraints.tsv"))
239
+ table = File.basename(@file).gsub(/\.tsv$/, "")
240
+
241
+ TSVFile.new(oldlocation("constraints.tsv")).subset(["Table", "Constraint"], [table, "key"], ["Column", "Value"]).values.each do |column, table2|
242
+ options[column] = TSVFile.new(oldlocation("#{table2}.tsv")).keys.collect{|a| a.join("\t")}
243
+ end
244
+ end
245
+
246
+ @headers.rwd_form(prefix, values, twoparts ? @key : 0, options)
247
+ end
248
+
249
+ def rwd_metadata
250
+ res = []
251
+
252
+ res << "<table>"
253
+ res << "<row>"
254
+ res << " <empty/>"
255
+ res << " <text name='header_new' value=''/>"
256
+ res << "</row>"
257
+ @headers.each_index do |n|
258
+ res << "<row>"
259
+ res << " <text name='header_#{n}_old' value='#{@headers[n]}'/>"
260
+ res << " <text name='header_#{n}_new' value=''/>"
261
+ res << "</row>"
262
+ end
263
+ res << "</table>"
264
+
265
+ return res.join("\n")
266
+ end
267
+ end
268
+
269
+ class OpenTag
270
+ def prechildren(res, before, after, varshtml, varsstring, switches, help, oneormorefields, firstaction, tabs, tab, pda)
271
+ bef = before[-1]
272
+ res << Format % ["Before", @subtype] if ($rwd_debug and not bef.nil?)
273
+ res << bef if not bef.nil?
274
+
275
+ res << Format % ["Pre", @subtype] if $rwd_debug
276
+
277
+ align = AC
278
+ align = "align='#{@args["align"]}'" if @args.include?("align")
279
+
280
+ valign = VA
281
+ valign = "valign='#{@args["valign"]}'" if @args.include?("valign")
282
+
283
+ value1 = ""
284
+ value1 = varshtml[@args["name"]] if varshtml.include?(@args["name"])
285
+ value1 = @args["value"] if @args.include?("value")
286
+
287
+ value2 = ""
288
+ value2 = varsstring[@args["name"]] if varsstring.include?(@args["name"])
289
+ value2 = @args["value"] if @args.include?("value")
290
+
291
+ cellspacing = 3
292
+ cellspacing = 0 if pda
293
+
294
+ case @subtype
295
+ when "application"
296
+ when "window", "helpwindow"
297
+ args = @args.deep_dup
298
+
299
+ args["nohelpbutton"] = (not help)
300
+
301
+ template = $rwd_html_1
302
+ template = $rwd_html_PDA_1 if pda
303
+
304
+ res << (template(template, args))
305
+ when "p" then res << "<p #{align}>"
306
+ when "pre" then res << "<pre #{align}>"
307
+ when "big" then res << "<p #{align}><big>"
308
+ when "small" then res << "<p #{align}><small>"
309
+ when "list" then res << "<ul #{align}>"
310
+ when "item" then res << "<li #{align}>"
311
+ when "empty" then res << "<p><br>"
312
+ when "image"
313
+ width = "width='#{@args["width"]}" if @args.include?("width")
314
+ height = "height='#{@args["height"]}'" if @args.include?("height")
315
+
316
+ res << "<img src='#{@args["src"]}' alt='#{@args["alt"]}' #{width} #{height}>"
317
+ when "progressbar"
318
+ width = 200
319
+
320
+ res << "<table>"
321
+ res << " <tr>"
322
+ res << " <td colspan='2'><img src='rwd_pixel.gif' height='1' width='#{width+5}'></td>"
323
+ res << " </tr>"
324
+ res << " <tr>"
325
+ res << " <td bgcolor='#DDDDDD'><img src='rwd_pixel.gif' height='10' width='#{(width*@args["value"].to_f).to_i}'></td>"
326
+ res << " <td bgcolor='#EEEEEE'><img src='rwd_pixel.gif' height='10' width='#{(width*(1.0-@args["value"].to_f)).to_i}'></td>"
327
+ res << " </tr>"
328
+ res << "</table>"
329
+ when "br" then res << "<br>"
330
+ when "hr" then res << "<hr>"
331
+ when "b" then res << "<b>"
332
+ when "i" then res << "<i>"
333
+ when "a"
334
+ if @args.include?("href")
335
+ res << "<a href='#{@args["href"]}' target='#{@args["target"] or "_blank"}'>"
336
+ else
337
+ res << "<a href='javascript:document.bodyform.rwd_action.value=\"#{@args["action"]}\";document.bodyform.submit();'>"
338
+ end
339
+ when "vertical" then res << "<table #{AC} border='#{$rwd_border}' cellspacing='#{cellspacing}' cellpadding='0'>"
340
+ when "horizontal" then res << "<table #{AC} border='#{$rwd_border}' cellspacing='#{cellspacing}' cellpadding='0'><tr #{align} #{valign}>"
341
+ when "table" then res << "<table #{AC} border='#{$rwd_border}' cellspacing='#{cellspacing}' cellpadding='0'>"
342
+ when "row" then res << "<tr #{align} #{valign}>"
343
+ when "hidden" then res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='hidden'>"
344
+ when "text"
345
+ maxlength = ""
346
+ maxlength = "maxlength='%s'" % @args["maxlength"] if @args.include?("maxlength")
347
+ size = ""
348
+ size = "size='%s'" % @args["size"] if @args.include?("size")
349
+ size = "size='%s'" % 10 if pda
350
+ res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='text' #{maxlength} #{size}>"
351
+ oneormorefields << "true"
352
+ when "textarea"
353
+ res << "<p #{align}><textarea name='#{@args["name"]}' rows='25' cols='80'>#{value2.crlf}</textarea>"
354
+ oneormorefields << "true"
355
+ when "password"
356
+ maxlength = ""
357
+ maxlength = "maxlength='%s'" % @args["maxlength"] if @args.include?("maxlength")
358
+ size = ""
359
+ size = "size='%s'" % 10 if pda
360
+ res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='password' #{maxlength} #{size}>"
361
+ oneormorefields << "true"
362
+ when "checkbox"
363
+ if varshtml[@args["name"]] == "on"
364
+ switches[@args["name"]] = true
365
+ res << "<p #{align}><input name='#{@args["name"]}' checked='on' type='checkbox'>"
366
+ else
367
+ switches[@args["name"]] = false
368
+ res << "<p #{align}><input name='#{@args["name"]}' type='checkbox'>"
369
+ end
370
+ oneormorefields << "true"
371
+ when "radio"
372
+ if varshtml[@args["name"]] == value1 # ??? 1 or 2?
373
+ res << "<p #{align}><input name='#{@args["name"]}' checked='on' value='#{value1}' type='radio'>"
374
+ else
375
+ res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='radio'>"
376
+ end
377
+ oneormorefields << "true"
378
+ when "select"
379
+ res << "<select #{align} name='#{@args["name"]}' width='#{@args["width"]} size='#{@args["size"]}'>" # ??? Misschien nog iets met 'multiple'?
380
+ name = @args["name"]
381
+ $select = varshtml[name]
382
+ oneormorefields << "true"
383
+ when "option"
384
+ if $select == @children[0].text
385
+ res << "<option selected='true'>"
386
+ else
387
+ res << "<option>"
388
+ end
389
+ when "button"
390
+ res << "<input type='submit' value='#{@args["caption"]}' onclick='document.bodyform.rwd_action.value=\"#{@args["action"]}\";'>"
391
+ firstaction << @args["action"] if (firstaction.empty? and @args.include?("action"))
392
+ oneormorefields << "true"
393
+ when "back"
394
+ res << "<input type='submit' value='Back' onclick='document.bodyform.rwd_action.value=\"rwd_back\";'>"
395
+ firstaction << "rwd_back" if firstaction.empty?
396
+ oneormorefields << "true"
397
+ when "cancel"
398
+ res << "<input type='submit' value='Cancel' onclick='document.bodyform.rwd_action.value=\"rwd_cancel\";'>"
399
+ firstaction << "rwd_cancel" if firstaction.empty?
400
+ oneormorefields << "true"
401
+ when "help"
402
+ res << "<input type='submit' value='Help' onclick='document.bodyform.rwd_action.value=\"rwd_help\";'>"
403
+ firstaction << "rwd_help" if firstaction.empty?
404
+ oneormorefields << "true"
405
+ when "quit"
406
+ res << "<input type='submit' value='Quit' onclick='document.bodyform.rwd_action.value=\"rwd_quit\";'>"
407
+ firstaction << "rwd_quit" if firstaction.empty?
408
+ oneormorefields << "true"
409
+ when "close"
410
+ res << "<input type='submit' value='Close' onclick='window.close();'>"
411
+ firstaction << "rwd_quit" if firstaction.empty?
412
+ oneormorefields << "true"
413
+ when "main"
414
+ res << "<input type='submit' value='Main' onclick='document.bodyform.rwd_action.value=\"rwd_main\";'>"
415
+ firstaction << "rwd_main" if firstaction.empty?
416
+ oneormorefields << "true"
417
+ when "reset"
418
+ res << "<input type='reset' value='Reset'>"
419
+ firstaction << "rwd_quit" if firstaction.empty? # ???
420
+ oneormorefields << "true"
421
+ when "closewindow"
422
+ #res << "<script type='text/javascript'>\n" # ???
423
+ #res << "<!--\n"
424
+ #res << " window.close();\n"
425
+ #res << "//-->\n"
426
+ #res << "</script>"
427
+ when "tabs"
428
+ res << "<table #{AC} border='#{$rwd_border}' cellspacing='0' cellpadding='0'>"
429
+ res << " <tr #{AL}>"
430
+ res << " <td #{AL} class='tabs'>"
431
+ res << " <table #{AL} border='#{$rwd_border}' cellspacing='0' cellpadding='0'>"
432
+ res << " <tr #{AL}>"
433
+ #res << " <td class='notab'>&nbsp;</td>"
434
+ tabs.each do |obj|
435
+ name = obj.args["name"]
436
+ caption = obj.args["caption"]
437
+
438
+ res << "<td #{AL} class='notab'>&nbsp;</td>" unless obj == tabs[0]
439
+
440
+ if name == tab
441
+ res << "<td #{AC} class='activetab'><tt>&nbsp;#{caption}&nbsp;</tt></td>"
442
+ else
443
+ res << "<td #{AC} class='passivetab'><a href='javascript:document.bodyform.rwd_action.value=\"rwd_tab_#{name}\";document.bodyform.submit();'><tt>&nbsp;#{caption}&nbsp;</tt></a></td>"
444
+ end
445
+ end
446
+ res << " <td class='notab' width='100%'>&nbsp;</td>"
447
+ res << " </tr>"
448
+ res << " </table>"
449
+ res << " </td>"
450
+ res << " </tr>"
451
+ res << " <tr #{align}>"
452
+ res << " <td #{align} class='tabblad'>"
453
+ when "tab"
454
+ res << "<table #{AC} border='#{$rwd_border}' cellspacing='3' cellpadding='0'>"
455
+ when "panel"
456
+ level = (@args["level"] or "normal")
457
+ res << "<table #{AC} border='#{$rwd_border}' cellspacing='0' cellpadding='0'>"
458
+ res << " <tr #{align}>"
459
+ res << " <td #{align} class='panel1'>" if level == "normal"
460
+ res << " <td #{align} class='panel1high'>" if level == "high"
461
+ res << " <td #{align} class='panel1low'>" if level == "low"
462
+ res << " <table #{AC} border='#{$rwd_border}' cellspacing='0' cellpadding='0'>"
463
+ res << " <tr #{align}>"
464
+ res << " <td #{align} class='panel2'>" if level == "normal"
465
+ res << " <td #{align} class='panel2high'>" if level == "high"
466
+ res << " <td #{align} class='panel2low'>" if level == "low"
467
+ res << " <table #{AC} border='#{$rwd_border}' cellspacing='3' cellpadding='0'>"
468
+ else
469
+ puts "<#{@subtype}>"
470
+ res << "&lt;#{@subtype}&gt;"
471
+ end
472
+
473
+ bef = nil
474
+ aft = nil
475
+
476
+ case @subtype
477
+ when "vertical", "window", "helpwindow", "tab", "panel"
478
+ res << Format % ["AftPre", @subtype] if $rwd_debug
479
+ if @args.include?("spacing")
480
+ s = "<tr><td>&nbsp;</td></tr>" * (@args["spacing"].to_i)
481
+ else
482
+ s = ""
483
+ end
484
+ bef = "#{s}<tr #{align} #{valign}><td #{align}>"
485
+ aft = "</td></tr>"
486
+ when "horizontal", "row"
487
+ res << Format % ["AftPre", @subtype] if $rwd_debug
488
+ bef = "<td #{align}>"
489
+ aft = "</td>"
490
+ end
491
+
492
+ before.push(bef)
493
+ after.push(aft)
494
+ end
495
+
496
+ def postchildren(res, before, after, varshtml, varsstring, switches, help, oneormorefields, firstaction, tabs, tab, pda)
497
+ case @subtype
498
+ when "vertical", "window", "helpwindow", "tab", "panel"
499
+ res << Format % ["BefPost", @subtype] if $rwd_debug
500
+ if @args.include?("spacing")
501
+ res << "<tr><td>&nbsp;</td></tr>" * (@args["spacing"].to_i)
502
+ end
503
+ when "horizontal", "row"
504
+ res << Format % ["BefPost", @subtype] if $rwd_debug
505
+ end
506
+
507
+ res << Format % ["Post", @subtype] if $rwd_debug
508
+
509
+ case @subtype
510
+ when "application"
511
+ when "window", "helpwindow"
512
+ args = @args.deep_dup
513
+
514
+ args["nohelpbutton"] = (not help)
515
+
516
+ template = $rwd_html_2
517
+ template = $rwd_html_PDA_2 if pda
518
+
519
+ res << (template(template, args))
520
+ when "p" then res << "</p>"
521
+ when "pre" then res << "</pre>"
522
+ when "big" then res << "</big></p>"
523
+ when "small" then res << "</small></p>"
524
+ when "list" then res << "</ul>"
525
+ when "item" then res << "</li>"
526
+ when "empty" then res << "</p>"
527
+ when "image" then res << ""
528
+ when "progressbar" then res << ""
529
+ when "br" then res << ""
530
+ when "hr" then res << ""
531
+ when "b" then res << "</b>"
532
+ when "i" then res << "</i>"
533
+ when "a" then res << "</a>"
534
+ when "vertical" then res << "</table>"
535
+ when "horizontal" then res << "</tr></table>"
536
+ when "table" then res << "</table>"
537
+ when "row" then res << "</tr>"
538
+ when "hidden" then res << "</p>"
539
+ when "text" then res << "</p>"
540
+ when "textarea" then res << "</p>"
541
+ when "password" then res << "</p>"
542
+ when "checkbox" then res << "</p>"
543
+ when "radio" then res << "</p>"
544
+ when "select"
545
+ res << "</select>"
546
+ $select = nil
547
+ when "option" then res << "</option>"
548
+ when "button" then res << ""
549
+ when "back" then res << ""
550
+ when "cancel" then res << ""
551
+ when "help" then res << ""
552
+ when "quit" then res << ""
553
+ when "close" then res << ""
554
+ when "main" then res << ""
555
+ when "reset" then res << ""
556
+ when "closewindow" then res << ""
557
+ when "tabs"
558
+ res << " </td>"
559
+ res << " </tr>"
560
+ res << "</table>"
561
+ when "tab"
562
+ res << "</table>"
563
+ when "panel"
564
+ res << " </table>"
565
+ res << " </td>"
566
+ res << " </tr>"
567
+ res << " </table>"
568
+ res << " </td>"
569
+ res << " </tr>"
570
+ res << "</table>"
571
+ else
572
+ puts "</#{@subtype}>"
573
+ res << "&lt;/#{@subtype}&gt;"
574
+ end
575
+
576
+ before.pop
577
+ after.pop
578
+
579
+ aft = after[-1]
580
+ res << Format % ["After", @subtype] if ($rwd_debug and not aft.nil?)
581
+ res << aft if not aft.nil?
582
+ end
583
+
584
+ def template(html, vars)
585
+ res = []
586
+
587
+ a = {}
588
+
589
+ vars.each do |k, v|
590
+ a[k.upcase] = v
591
+ end
592
+
593
+ logo = nil
594
+ logo = File.expand_path(vars["logo"], $rwd_files) if vars.include?("logo")
595
+ logo = nil unless logo.nil? or File.file?(logo)
596
+
597
+ watermark = nil
598
+ watermark = File.expand_path(vars["watermark"], $rwd_files) if vars.include?("watermark")
599
+ watermark = nil unless watermark.nil? or File.file?(watermark)
600
+
601
+ a["LOGO"] = "" unless not logo.nil?
602
+ a["WATERMARK"] = "" unless not watermark.nil?
603
+
604
+ a["HELPBUTTON"] = (not (vars["nohelpbutton"]))
605
+ a["BACKBUTTONS"] = (not (vars["nobackbuttons"]))
606
+ a["BACKBUTTONS"] = (not (vars["nobackbuttons"]))
607
+ a["CLOSEBUTTON"] = (not (vars["noclosebutton"]))
608
+
609
+ if a.include?("WIDTH")
610
+ a["WIDTH1"] = "width='#{a["WIDTH"]}'"
611
+ a["WIDTH2"] = a["WIDTH"]
612
+ else
613
+ a["WIDTH1"] = " "
614
+ a["WIDTH2"] = "1"
615
+ end
616
+
617
+ html.split(/\r*\n/).each do |line|
618
+ if line =~ /%[A-Z0-9]+%/
619
+ a.each do |k, v|
620
+ v = false if (v.kind_of?(String) and v.empty?)
621
+
622
+ if line.include?("%#{k}%")
623
+ line.gsub!("%#{k}%", "#{v}") if v
624
+ end
625
+ end
626
+
627
+ line = "<!-- #{line.scan(/%[A-Z0-9]+%/).join(" ")} -->" if line =~ /%[A-Z0-9]+%/
628
+ end
629
+
630
+ res << line
631
+ end
632
+
633
+ res.join("\n")
634
+ end
635
+ end
636
+
637
+ class Text
638
+ def prechildren(res, before, after, varshtml, varsstring, switches, help, oneormorefields, firstaction, tabs, tab, pda)
639
+ if not @text.scan(/[^ \t\r\n]/).empty?
640
+ res << Format % ["Text", ""] if $rwd_debug
641
+ res << "#{@text}"
642
+ end
643
+ end
644
+ end
645
+
646
+ class RWDTree < XML
647
+ end
648
+
649
+ class RWDWindow
650
+ @@windows = {} # Kind of caching.
651
+ @@helpwindows = {} # Kind of caching.
652
+
653
+ def initialize(rwd, window=nil)
654
+ rwd = rwd.join("\n") if rwd.kind_of?(Array)
655
+
656
+ if @@windows[rwd].nil?
657
+ @@windows[rwd] = {}
658
+ @@helpwindows[rwd] = {}
659
+
660
+ tree = XML.new(rwd)
661
+
662
+ tree.parse(OpenTag, "window") do |type, obj|
663
+ $rwd_appvars.each{|k, v| obj.args[k] = v}
664
+ @@windows[rwd][obj.args["name"]] = obj.to_h
665
+ end
666
+
667
+ tree.parse(OpenTag, "helpwindow") do |type, obj|
668
+ $rwd_appvars.each{|k, v| obj.args[k] = v}
669
+ @@helpwindows[rwd][obj.args["name"]] = obj.to_h
670
+ end
671
+ end
672
+
673
+ @rwd = (@@windows[rwd][window] or "").dup
674
+ @helprwd = (@@helpwindows[rwd][window] or "").dup
675
+ end
676
+
677
+ def render(pda, action=nil, vars=Hash.new, switches=Hash.new, help=false, tab="")
678
+ varshtml = Hash.new
679
+ varsstring = Hash.new
680
+ oneormorefields = ""
681
+ firstaction = ""
682
+ html = []
683
+
684
+ vars = vars.deep_dup
685
+
686
+ begin # error wrap
687
+
688
+ vars.each do |key, value|
689
+ if not key.empty?
690
+ if value.respond_to? "to_s"
691
+ @rwd.gsub!(/%%#{key}%%/, value.to_s)
692
+ @rwd.gsub!(/%#{key}%/, value.to_s.to_html)
693
+
694
+ @helprwd.gsub!(/%%#{key}%%/, value.to_s)
695
+ @helprwd.gsub!(/%#{key}%/, value.to_s.to_html)
696
+
697
+ varshtml[key] = value.to_s.to_html
698
+ varsstring[key] = value.to_s
699
+ end
700
+ end
701
+ end
702
+
703
+ windowobject = RWDTree.new(@rwd).children.dup.delete_if{|obj| obj.subtype != "window"}[0]
704
+ helpobject = RWDTree.new(@helprwd).children.dup.delete_if{|obj| obj.subtype != "helpwindow"}[0]
705
+
706
+ tabsobj = windowobject.children.dup.delete_if{|obj| obj.subtype != "tabs"}[0]
707
+
708
+ if not tabsobj.nil?
709
+ tabs = tabsobj.children.dup.delete_if{|obj| (not obj.kind_of?(OpenTag)) or (obj.subtype != "tab")}
710
+
711
+ if tab.empty?
712
+ tab = tabs[0].args["name"]
713
+ end
714
+
715
+ tabsobj.children.delete_if{|obj| (obj.kind_of?(OpenTag)) and (obj.subtype == "tab") and obj.args["name"] != tab}
716
+ end
717
+
718
+ if help
719
+ helpobject.parsetree("prechildren", "postchildren", html, [""], [""], varshtml, varsstring, switches, false, oneormorefields, firstaction, tabs, tab, pda)
720
+ else
721
+ windowobject.parsetree("prechildren", "postchildren", html, [""], [""], varshtml, varsstring, switches, (not @helprwd.empty?), oneormorefields, firstaction, tabs, tab, pda)
722
+ end
723
+
724
+ html = html.join("") # ???
725
+
726
+ html.gsub!(/%%*[[:alnum:]_\-]+%%*/, "") if not $rwd_debug
727
+ html.gsub!(/%%/, "%")
728
+ html.gsub!(/\n\n*/, "\n")
729
+
730
+ if oneormorefields.empty?
731
+ focus = ""
732
+ else
733
+ focus = "document.bodyform.elements[0].focus();"
734
+ end
735
+
736
+ firstaction = action if windowobject.args.keys.include?("refresh") unless action.nil?
737
+
738
+ html.gsub!(/\$RWD_FIRSTACTION\$/ , firstaction)
739
+ html.gsub!(/\$RWD_FOCUS\$/ , focus)
740
+
741
+ html
742
+ end
743
+
744
+ rescue
745
+
746
+ $stderr.puts "error in RWDWindow - render method"
747
+ end
748
+ end
749
+
750
+
751
+ class RWDMessage < RWDWindow
752
+ def initialize(msg)
753
+ super("<window title='RWD Message' nobackbuttons noclosebutton><p>#{msg}</p><back/></window>")
754
+ end
755
+ end
756
+
757
+ class RWDError < RWDWindow
758
+ def initialize(msg)
759
+ super("<window title='RWD Error' nobackbuttons noclosebutton><p><b>Error:</b> #{msg}</p><back/></window>")
760
+ end
761
+ end
762
+
763
+ class RWDProgressBar < RWDWindow
764
+ def initialize(refresh, progress)
765
+ s = ""
766
+ s << "<window title='RWD Progress' nobackbuttons noclosebutton refresh='#{refresh}'>"
767
+ if progress.length == 1
768
+ progress.each do |caption, value|
769
+ s << "<p>#{caption}</p><progressbar value='#{value}'/><p>#{(100*value).to_i}%%</p>"
770
+ end
771
+ else
772
+ s << "<table>"
773
+ progress.each do |caption, value|
774
+ s << "<row><p align='left'>#{caption}</p><progressbar value='#{value}'/><p align='right'>#{(100*value).to_i}%%</p></row>"
775
+ end
776
+ s << "</table>"
777
+ end
778
+ s << "<cancel/>"
779
+ s << "</window>"
780
+ super(s)
781
+ end
782
+ end
783
+
784
+ class RWDDone < RWDWindow
785
+ def initialize(exitbrowser)
786
+ super("<window title='RWD Message' nobackbuttons noclosebutton><p>Done.</p><i>(Some browsers don't close,<br>because of security reasons.)</i><horizontal><close/>#{exitbrowser ? "" : "<button caption='Again'/>"}</horizontal>#{exitbrowser ? "<closewindow/>" : ""}</window>")
787
+ end
788
+ end
789
+
790
+ class RWDialog
791
+
792
+ def initialize(xml)
793
+ @rwd_xml = $rwd_gui_tinker
794
+ # change from default ev - was xml
795
+ @rwd_exitbrowser = false
796
+ @rwd_history = []
797
+ @rwd_ignore_vars = []
798
+ @rwd_call_after_back = []
799
+ @rwd_time = Time.now
800
+
801
+ $rwd_appvars = {} if $rwd_appvars.nil?
802
+ XML.new(xml).parse(OpenTag, "application") do |type, obj|
803
+ obj.args.deep_dup.each do |k, v|
804
+ $rwd_appvars[k] = v
805
+ end
806
+ end
807
+ end
808
+
809
+ def self.file(rwdfile, *args)
810
+ new(File.new(rwdfile).readlines, *args)
811
+ end
812
+
813
+ def serve(port=nil, auth=nil, realm=self.class.to_s)
814
+ exit if $rwd_exit
815
+
816
+ raise "RWD is not initialized." if @rwd_xml.nil?
817
+
818
+ low, high = ENV["RWDPORTS"].split(/[^\d+]/)
819
+ high = low if high.nil?
820
+ low, high = low.to_i, high.to_i
821
+
822
+ io = nil
823
+
824
+ port, io = TCPServer.freeport(low, high, (not auth.nil?)) if port.nil?
825
+ raise "No free TCP port." if port.nil?
826
+
827
+ port = port.to_i
828
+
829
+ @rwd_server = RWDServer.new(self, port, io, auth, realm)
830
+
831
+ self
832
+ end
833
+
834
+
835
+
836
+ def render(res, path, post, download, downloadfile, pda, sessionid)
837
+ # Avoid a timeout.
838
+
839
+ @rwd_time = Time.now
840
+
841
+ # Initialize some vars.
842
+
843
+ vars = Hash.new if vars.nil?
844
+ @rwd_switches = Hash.new if @rwd_switches.nil?
845
+
846
+ done = false
847
+ help = false
848
+ back = false
849
+ tab = ""
850
+ @rwd_progress_thread = nil
851
+ @rwd_msgtype = nil if @rwd_progress_thread.nil?
852
+ @rwd_download = nil
853
+ @rwd_download_file = nil
854
+
855
+ # Switches are used for checkboxes.
856
+
857
+ @rwd_switches.each do |key, value|
858
+ vars[key] = "off"
859
+ end
860
+
861
+ @rwd_switches = Hash.new
862
+
863
+ # Copy the vars from the window to vars. vars wil later on be copied to instance variables.
864
+
865
+ post.sort.each do |key, value|
866
+ puts "Post: #{key} -> #{value.from_html.inspect}" if $rwd_debug
867
+ if $DEBUG
868
+ $stderr.puts "Post: #{key} -> #{value.from_html.inspect}\n"
869
+ end
870
+ vars[key] = value.from_html
871
+ if $DEBUG
872
+ $stderr.puts " #{value.from_html}\n"
873
+ end
874
+ end
875
+
876
+ # Stack handling for rwd_action, rwd_window and rwd_tab.
877
+
878
+ @rwd_action = vars["rwd_action"] if vars.include?("rwd_action")
879
+ @rwd_action, @rwd_args = @rwd_action.split(/\//, 2) unless @rwd_action.nil?
880
+ @rwd_action, rest = @rwd_action.split(/\?/) unless @rwd_action.nil?
881
+
882
+ @rwd_refresh_action = (@rwd_action or @rwd_refresh_action or "main")
883
+
884
+ unless rest.nil?
885
+ rest.each do |s|
886
+ k, v = s.split(/=/, 2)
887
+ vars[k] = v
888
+ end
889
+ end
890
+
891
+ if @rwd_action == "rwd_cancel"
892
+ @rwd_progress_thread.kill unless @rwd_progress_thread.nil?
893
+ @rwd_progress_thread = nil
894
+ @rwd_action = "rwd_back"
895
+ end
896
+
897
+ @rwd_history = [["main", [], "main", ""]] if @rwd_history.empty?
898
+
899
+ if @rwd_action =~ /^rwd_tab_/
900
+ @rwd_tab = @rwd_action.sub(/^rwd_tab_/, "")
901
+ @rwd_history[-1][3] = @rwd_tab
902
+ else
903
+ case @rwd_action
904
+ when "rwd_back"
905
+ @rwd_history.pop
906
+ @rwd_action = (@rwd_history[-1] or [nil, nil, nil])[0]
907
+ @rwd_args = (@rwd_history[-1] or [nil, nil, nil])[1]
908
+ @rwd_window = (@rwd_history[-1] or [nil, nil, nil])[2]
909
+ @rwd_tab = (@rwd_history[-1] or [nil, nil, nil])[3]
910
+ back = true
911
+ when "rwd_help"
912
+ help = true
913
+ when "rwd_main"
914
+ @rwd_action = nil
915
+ @rwd_window = nil
916
+ @rwd_tab = nil
917
+ @rwd_history = []
918
+ when "rwd_quit"
919
+ done = true
920
+ else
921
+ end
922
+
923
+ # History stuff
924
+
925
+ @rwd_history = @rwd_history[-100..-1] if @rwd_history.length >= 100
926
+ @rwd_action = "main" if @rwd_action.nil?
927
+ @rwd_action = "main" if @rwd_action.empty?
928
+ @rwd_window = "main" if @rwd_window.nil?
929
+ @rwd_window = "main" if @rwd_window.empty?
930
+ @rwd_tab = "" if @rwd_tab.nil?
931
+ @rwd_args = [] if @rwd_args.nil?
932
+ @rwd_args = [] if @rwd_action == "main"
933
+
934
+ vars["rwd_action"] = @rwd_action
935
+ vars["rwd_window"] = @rwd_window
936
+ vars["rwd_tab"] = @rwd_tab
937
+
938
+ # Copy vars from window to instance.
939
+
940
+ vars.each do |k, v|
941
+ if $DEBUG
942
+ $stderr.puts "Post: #{k} -> #{v}\n"
943
+ end
944
+ if ((not k.empty?) and k.scan(/^rwd_/).empty? and not @rwd_ignore_vars.include?("@#{k}"))
945
+
946
+ instance_eval "@#{k} = ''"
947
+ instance_variable_set("@#{k}", vars.fetch("#{k}"))
948
+ if $DEBUG
949
+ $stderr.puts "Post: #{k} -> #{v}\n"
950
+ end
951
+ end
952
+ end
953
+
954
+ # Callback.
955
+
956
+ if (not back) or @rwd_call_after_back.include?(@rwd_action)
957
+ unless @rwd_action =~ /^rwd_/
958
+ puts "Method: #{@rwd_action}(#{@rwd_args.join(", ")})" if $rwd_debug
959
+ if methods.include?(@rwd_action)
960
+ method(@rwd_action).call(*@rwd_args)
961
+ else
962
+ puts "Method '%s' is not defined." % @rwd_action
963
+ end
964
+ end
965
+
966
+ # History stuff
967
+
968
+ @rwd_history = [["main", [], "main", ""]] if @rwd_action == "main"
969
+ @rwd_history = [["main", [], "main", ""]] if @rwd_history.empty?
970
+
971
+ a = [@rwd_action, @rwd_args, @rwd_window, @rwd_tab]
972
+
973
+ @rwd_history.push a if (@rwd_history[-1] != a or not @rwd_msgtype.nil?)
974
+
975
+ if @rwd_window == "rwd_back"
976
+ @rwd_history.pop
977
+ @rwd_history.pop
978
+ @rwd_action = (@rwd_history[-1] or [nil, nil, nil])[0]
979
+ @rwd_args = (@rwd_history[-1] or [nil, nil, nil])[1]
980
+ @rwd_window = (@rwd_history[-1] or [nil, nil, nil])[2]
981
+ @rwd_tab = (@rwd_history[-1] or [nil, nil, nil])[3]
982
+ end
983
+ end
984
+ end
985
+
986
+ # Copy vars from instance to window.
987
+
988
+ instance_variables.each do |k|
989
+ k.sub!(/^@/, "")
990
+ instance_eval "vars['#{k}'] = @#{k}.to_s" if (k.scan(/^rwd_/).empty? and not @rwd_ignore_vars.include?("@#{k}"))
991
+ end
992
+
993
+ # just ignore.
994
+
995
+ vars.sort.each do |key, value|
996
+ puts "Pre: #{key} -> #{value.inspect}" if $rwd_debug
997
+ end
998
+
999
+
1000
+ # Answer to browser.
1001
+
1002
+ if done
1003
+ res << RWDDone.new(@rwd_exitbrowser).render(pda)
1004
+ else
1005
+ if not @rwd_download.nil?
1006
+ puts "Download: #{@rwd_window}" if $rwd_debug
1007
+
1008
+ download << @rwd_download
1009
+ downloadfile << @rwd_download_file
1010
+ else
1011
+ if not @rwd_progress_thread.nil?
1012
+ res << RWDProgressBar.new(@rwd_progress_refresh, @rwd_progress_progress).render(pda, @rwd_refresh_action)
1013
+ else
1014
+ if not @rwd_msgtype.nil?
1015
+ res << RWDMessage.new(@rwd_msg).render(pda) if @rwd_msgtype == "message"
1016
+ res << RWDError.new(@rwd_msg).render(pda) if @rwd_msgtype == "error"
1017
+ res << @rwd_msg if @rwd_msgtype == "text"
1018
+ else
1019
+ puts "Window: #{@rwd_window}" if $rwd_debug
1020
+ puts "Tab: #{@rwd_tab}" if $rwd_debug
1021
+
1022
+ begin # error block
1023
+ if @rwd_window.empty?
1024
+ @rwd_window = "main"
1025
+ end
1026
+ res << RWDWindow.new($rwd_gui_tinker, @rwd_window).render(pda, @rwd_refresh_action, vars, @rwd_switches, help, @rwd_tab)
1027
+ rescue
1028
+ if $DEBUG
1029
+ $stderr.puts "error in render"
1030
+ end
1031
+ end
1032
+ end
1033
+ end
1034
+ end
1035
+ end
1036
+
1037
+ return done
1038
+ end
1039
+
1040
+ def samewindow?
1041
+ @rwd_history[-1][2] == @rwd_window
1042
+ end
1043
+
1044
+ def message(msg, &block)
1045
+ @rwd_msg = msg
1046
+ @rwd_msgtype = "message"
1047
+ end
1048
+
1049
+ def error(msg, &block)
1050
+ @rwd_msg = msg
1051
+ @rwd_msgtype = "error"
1052
+ end
1053
+
1054
+ def text(msg)
1055
+ @rwd_msg = "<html><body><pre>#{msg}</pre></body></html>"
1056
+ @rwd_msgtype = "text"
1057
+ end
1058
+
1059
+ def progressbar(refresh, *progress)
1060
+ @rwd_progress_refresh = (refresh or 1)
1061
+ @rwd_progress_progress = []
1062
+
1063
+ while not progress.empty?
1064
+ s = (progress.shift or "")
1065
+ if s.kind_of?(Array)
1066
+ caption, value = s
1067
+ value = (value or 0.0).to_f
1068
+ else
1069
+ caption = s
1070
+ value = (progress.shift or 0.0).to_f
1071
+ end
1072
+
1073
+ @rwd_progress_progress << [caption, value]
1074
+ end
1075
+
1076
+ if @rwd_progress_thread.nil?
1077
+ @rwd_progress_progress.each do |a|
1078
+ a[1] = 0.0
1079
+ end
1080
+
1081
+ @rwd_progress_thread =
1082
+ Thread.new do
1083
+ yield
1084
+ end
1085
+ Thread.pass
1086
+ end
1087
+
1088
+ @rwd_progress_thread = nil unless @rwd_progress_thread.alive?
1089
+ end
1090
+
1091
+ def download(data, filename="")
1092
+ @rwd_download = data
1093
+ @rwd_download_file = filename
1094
+ end
1095
+
1096
+ def exitbrowser
1097
+ @rwd_exitbrowser = true
1098
+ end
1099
+
1100
+ def timeout(timeout, interval=1)
1101
+ @rwd_timeout = timeout
1102
+
1103
+ unless @rwd_timeout_thread
1104
+ @rwd_timeout_thread =
1105
+ Thread.new do
1106
+ loop do
1107
+ if Time.now - @rwd_time > @rwd_timeout
1108
+ $stderr.puts "Exiting due to timeout (#{@rwd_timeout} seconds)."
1109
+ exit 1
1110
+ end
1111
+ sleep interval
1112
+ end
1113
+ end
1114
+ end
1115
+ end
1116
+ end
1117
+
1118
+ class RWDLogin < RWDialog
1119
+ def initialize(realm)
1120
+ super("<window name='main' title='RWD Login for #{realm}' nobackbuttons noclosebutton><table><row><p align='right'>Username:</p><text name='rwd_a'/></row><row><p align='right'>Password:</p><password name='rwd_b'/></row></table><button caption='Login'/></window>")
1121
+ end
1122
+ end
1123
+
1124
+ class RWDTimeOut < RWDialog
1125
+ def initialize
1126
+ super("<window name='main' title='RWD Error' nobackbuttons noclosebutton><p><b>Error:</b> Session has expired.</p><button caption='New session'/></window>")
1127
+ end
1128
+ end
1129
+
1130
+ class SessionCleanup
1131
+ def initialize(sessions, interval, timeout)
1132
+ every(interval) do
1133
+ sessions.delete_if do |id, session|
1134
+ time = Time.now.to_i - session.lastaccess.to_i
1135
+
1136
+ puts "Session %s deleted" % id if time > timeout
1137
+
1138
+ time > timeout
1139
+ end
1140
+ end
1141
+ end
1142
+ end
1143
+
1144
+ class Sessions
1145
+ def initialize(rack, cleanup)
1146
+ @rack = rack.to_s
1147
+ @cleanup = SessionCleanup.new(self, 3600, 24*3600) if cleanup
1148
+ @sessions = {}
1149
+ end
1150
+
1151
+ def [](sessionid)
1152
+ @sessions[sessionid]
1153
+ end
1154
+
1155
+ def []=(sessionid, value)
1156
+ @sessions[sessionid] = value
1157
+ end
1158
+
1159
+ def delete(sessionid)
1160
+ @sessions.delete(sessionid)
1161
+ end
1162
+
1163
+ def delete_if(&block)
1164
+ @sessions.delete_if{|k, v| block.call(k, v)}
1165
+ end
1166
+
1167
+ def include?(sessionid)
1168
+ @sessions.include?(sessionid)
1169
+ end
1170
+ end
1171
+
1172
+ class RWDSession < Hash
1173
+ attr_reader :sessionid
1174
+ attr_reader :lastaccess
1175
+ attr_reader :authenticated
1176
+ attr_writer :authenticated
1177
+
1178
+ def initialize(sessionid=nil)
1179
+ @sessionid = sessionid
1180
+ @lastaccess = Time.now
1181
+ @authenticated = false
1182
+ end
1183
+
1184
+ def touch
1185
+ @lastaccess = Time.now
1186
+ end
1187
+
1188
+ def render(res, path, post, download, downloadfile, pda)
1189
+ done = self["object"].render(res, path, post, download, downloadfile, pda, @sessionid)
1190
+
1191
+ res.gsub!(/\$RWD_SESSION\$/, done ? "" : "#{@sessionid}")
1192
+
1193
+ return done
1194
+ end
1195
+ end
1196
+
1197
+ class RWDServer
1198
+ def initialize(obj, port, io, auth, realm)
1199
+ @object = obj
1200
+ @localbrowsing = false
1201
+ @browserstarted = false
1202
+ @sessions = Sessions.new(obj.class, (not auth.nil?))
1203
+
1204
+ if auth.nil?
1205
+ @localbrowsing = true
1206
+
1207
+ if ENV.include?("RWDBROWSER") and not ENV["RWDBROWSER"].nil? and not ENV["RWDBROWSER"].empty?
1208
+ @browserstarted = true
1209
+ @object.exitbrowser
1210
+
1211
+ # Start browser.
1212
+
1213
+ @browserthread =
1214
+ Thread.new do
1215
+ puts "Starting the browser..."
1216
+
1217
+ #if ENV["RWDBROWSER"].downcase =~ /iexplore/ # ???
1218
+ #@ie = IE.new("http://localhost:#{port}/")
1219
+ #else
1220
+ browser = ENV["RWDBROWSER"].dup
1221
+ url = "http://localhost:%s/" % [port]
1222
+
1223
+ re = /[$%]1\b/
1224
+ command = "%s \"%s\"" % [browser, url]
1225
+ command = browser.gsub(re, url) if browser =~ re
1226
+
1227
+ command.gsub!(/%port%/, port.to_s)
1228
+
1229
+ system(command) or $stderr.puts "Starting of the browser failed, or the browser terminated abnormally.\nCommand => #{command}"
1230
+ #end
1231
+
1232
+ puts "The browser has terminated."
1233
+ end
1234
+ end
1235
+ end
1236
+
1237
+ # Start server.
1238
+
1239
+ portio = port
1240
+ portio = [port, io] unless io.nil?
1241
+ threadlimiter = ThreadLimiter.new(1)
1242
+
1243
+ HTTPServer.serve(portio, (not auth.nil?)) do |req, resp|
1244
+ threadlimiter.wait do
1245
+ vars = {}
1246
+ req.vars.each do |k, v|
1247
+ vars[k] = v.join("\t")
1248
+ end
1249
+ pad = (req.request.path or "/")
1250
+
1251
+ if auth.kind_of? String
1252
+ file = "#{home}/#{auth}"
1253
+ auths = {}
1254
+ auths = Hash.file(file) if File.file?(file)
1255
+ else
1256
+ auths = auth
1257
+ end
1258
+
1259
+ #oldsessionid = vars["rwd_session"]
1260
+ oldsessionid = req.cookies["sessionid"]
1261
+
1262
+ # Retrieve session.
1263
+
1264
+ session = @sessions[oldsessionid]
1265
+
1266
+ # Eventually create new session.
1267
+
1268
+ if session.nil?
1269
+ sessionid = MD5.new(req.peeraddr[3].to_s + @object.inspect.to_s + ("%1.6f" % Time.now.to_f)).to_s while (sessionid == nil or @sessions.include?(sessionid))
1270
+ session = RWDSession.new(sessionid)
1271
+
1272
+ if auth.nil?
1273
+ session["object"] = @object
1274
+ else
1275
+ session["object"] = @object.clone
1276
+ end
1277
+
1278
+ if oldsessionid.nil? or oldsessionid.empty?
1279
+ if not auth.nil? and not auth.empty? and not session.authenticated and pad !~ /^\/rwd_/
1280
+
1281
+ # Check authentication
1282
+
1283
+ us = vars["rwd_a"]
1284
+ pa = vars["rwd_b"]
1285
+
1286
+ if us.nil? or pa.nil? or auths[us] != pa
1287
+ session = RWDSession.new
1288
+ session["object"] = RWDLogin.new(realm)
1289
+ pad = "/"
1290
+ else
1291
+ session.authenticated = true
1292
+ @sessions[session.sessionid] = session
1293
+ end
1294
+ else
1295
+ session.authenticated = true
1296
+ @sessions[session.sessionid] = session
1297
+ end
1298
+ else
1299
+ session = RWDSession.new
1300
+ session["object"] = RWDTimeOut.new
1301
+ end
1302
+
1303
+ vars = {}
1304
+ end
1305
+
1306
+ # Avoid timeout.
1307
+
1308
+ session.touch
1309
+
1310
+ if pad == "/"
1311
+
1312
+ # Serve methods/callbacks.
1313
+
1314
+ # Build new page.
1315
+
1316
+ download = ""
1317
+ downloadfile = ""
1318
+ res = ""
1319
+
1320
+ done = session.render(res, pad, vars, download, downloadfile, req.pda?)
1321
+
1322
+ begin
1323
+ if download.empty?
1324
+ resp["Content-Type"] = "text/html"
1325
+ if done
1326
+ resp.cookies["sessionid"] = ""
1327
+ else
1328
+ resp.cookies["sessionid"] = session.sessionid
1329
+ end
1330
+
1331
+ resp << res
1332
+ else
1333
+ resp["Content-Type"] = "application/octet-stream"
1334
+ resp["Content-Disposition"] = "attachment;"
1335
+ resp["Content-Disposition"] = "attachment; filename=%s" % downloadfile unless downloadfile.empty?
1336
+
1337
+ resp << download
1338
+ end
1339
+ rescue
1340
+ puts "Sending response to browser failed."
1341
+
1342
+ @sessions.delete(session.sessionid)
1343
+ end
1344
+
1345
+ # Eventually delete this session.
1346
+
1347
+ if done
1348
+ @sessions.delete(session.sessionid)
1349
+
1350
+ if @localbrowsing
1351
+ resp.stop
1352
+
1353
+ if @browserstarted and not @browserthread.nil? and @browserthread.alive?
1354
+ resp.stop do
1355
+ puts "Waiting for the browser to terminate..."
1356
+
1357
+ @browserthread.join
1358
+ end
1359
+ end
1360
+ end
1361
+ end
1362
+
1363
+ else
1364
+
1365
+ # Serve files.
1366
+
1367
+ if pad == "/rwd_pixel.gif"
1368
+ resp["Cache-Control"] = "max-age=86400"
1369
+ resp["Content-Type"] = "image/gif"
1370
+ resp << $rwd_pixel
1371
+ else
1372
+ if session.authenticated
1373
+ pwd = Dir.pwd
1374
+ file = File.expand_path(pad.gsub(/^\/*/, ""), $rwd_files)
1375
+
1376
+ if not file.index(pwd) == 0
1377
+ resp["Content-Type"] = "text/html"
1378
+ resp.response = "HTTP/1.0 400 BAD REQUEST"
1379
+ resp << "<html><body><p><b>Bad Request.</b> (<tt>#{pad}</tt>)</p></body></html>"
1380
+ elsif File.file?(file)
1381
+ resp << File.new(file, "rb").read rescue nil
1382
+ else
1383
+ resp["Content-Type"] = "text/html"
1384
+ resp.response = "HTTP/1.0 404 NOT FOUND"
1385
+ resp << "<html><body><p><b>Not found.</b> (<tt>#{pad}</tt>)</p></body></html>"
1386
+ end
1387
+ else
1388
+ resp["Content-Type"] = "text/html"
1389
+ resp.response = "HTTP/1.0 ??? NOT AUTHORIZED"
1390
+ resp << "<html><body><p><b>Not Authorized.</b></p></body></html>"
1391
+ end
1392
+ end
1393
+
1394
+ end
1395
+
1396
+ end
1397
+ end
1398
+ end
1399
+ end
1400
+
1401
+
1402
+
1403
+ $rwd_pixel = "
1404
+ R0lGODlhAQABAMIAAAAAAP///+7u7kREiP///////////////yH5BAEKAAMA
1405
+ LAAAAAABAAEAAAMCOAkAOw==
1406
+ ".unpack("m").shift
1407
+
1408
+ $rwd_logo = "
1409
+ R0lGODlhEAAQAMIAAAAAAP///+7u7kREiP///////////////yH5BAEKAAQA
1410
+ LAAAAAAQABAAAANCSErQ/k21QKulrIrNu8heuAGUcJ0BuQVD676DasK0zNKv
1411
+ jefB+oo6l6AxBAx7M2HRePQph5xga0RsJqfELPI2DSUAADs=
1412
+ ".unpack("m").shift
1413
+
1414
+
1415
+ $rwd_html_1, $rwd_html_2 = $rwd_html[ENV["RWDTHEME"]].split(/^\s*%BODY%\s*\r*$/)
1416
+ #if ENV["RWDTHEME"] == "PDA"
1417
+ #$rwd_html_PDA_1, $rwd_html_PDA_2 = $rwd_html["PDA"].split(/^\s*%BODY%\s*\r*$/)
1418
+ #end
1419
+ #end
1420
+ #
1421
+ #class RWDialog < RWD::RWDialog
1422
+ #end