837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
|
# File 'lib/rwd/rwd.rb', line 837
def render(res, path, post, download, downloadfile, pda, sessionid)
@rwd_time = Time.now
vars = Hash.new if vars.nil?
@rwd_switches = Hash.new if @rwd_switches.nil?
done = false
help = false
back = false
tab = ""
@rwd_progress_thread = nil
@rwd_msgtype = nil if @rwd_progress_thread.nil?
@rwd_download = nil
@rwd_download_file = nil
@rwd_switches.each do |key, value|
vars[key] = "off"
end
@rwd_switches = Hash.new
post.sort.each do |key, value|
puts "Post: #{key} -> #{value.from_html.inspect}" if $rwd_debug
$rwdtinkerlog.info "Post: #{key} -> #{value.from_html.inspect}\n"
vars[key] = value.from_html
$rwdtinkerlog.info "rwd: #{value.from_html}\n"
end
@rwd_action = vars["rwd_action"] if vars.include?("rwd_action")
@rwd_action, @rwd_args = @rwd_action.split(/\//, 2) unless @rwd_action.nil?
@rwd_action, rest = @rwd_action.split(/\?/) unless @rwd_action.nil?
@rwd_refresh_action = (@rwd_action or @rwd_refresh_action or "main")
unless rest.nil?
rest.each do |s|
k, v = s.split(/=/, 2)
vars[k] = v
end
end
if @rwd_action == "rwd_cancel"
@rwd_progress_thread.kill unless @rwd_progress_thread.nil?
@rwd_progress_thread = nil
@rwd_action = "rwd_back"
end
@rwd_history = [["main", [], "main", ""]] if @rwd_history.empty?
if @rwd_action =~ /^rwd_tab_/
@rwd_tab = @rwd_action.sub(/^rwd_tab_/, "")
@rwd_history[-1][3] = @rwd_tab
else
case @rwd_action
when "rwd_back"
@rwd_history.pop
@rwd_action = (@rwd_history[-1] or [nil, nil, nil])[0]
@rwd_args = (@rwd_history[-1] or [nil, nil, nil])[1]
@rwd_window = (@rwd_history[-1] or [nil, nil, nil])[2]
@rwd_tab = (@rwd_history[-1] or [nil, nil, nil])[3]
back = true
when "rwd_help"
help = true
when "rwd_main"
@rwd_action = nil
@rwd_window = nil
@rwd_tab = nil
@rwd_history = []
when "rwd_quit"
done = true
else
end
@rwd_history = @rwd_history[-100..-1] if @rwd_history.length >= 100
@rwd_action = "main" if @rwd_action.nil?
@rwd_action = "main" if @rwd_action.empty?
@rwd_window = "main" if @rwd_window.nil?
@rwd_window = "main" if @rwd_window.empty?
@rwd_tab = "" if @rwd_tab.nil?
@rwd_args = [] if @rwd_args.nil?
@rwd_args = [] if @rwd_action == "main"
vars["rwd_action"] = @rwd_action
vars["rwd_window"] = @rwd_window
vars["rwd_tab"] = @rwd_tab
vars.each do |k, v|
$rwdtinkerlog.info "rwd: Post: #{k} -> #{v}\n"
if ((not k.empty?) and k.scan(/^rwd_/).empty? and not @rwd_ignore_vars.include?("@#{k}"))
instance_eval "@#{k} = ''"
instance_variable_set("@#{k}", vars.fetch("#{k}"))
$rwdtinkerlog.info "rwd: Post: #{k} -> #{v}\n"
end
end
if (not back) or @rwd_call_after_back.include?(@rwd_action)
unless @rwd_action =~ /^rwd_/
$rwdtinkerlog.debug "Method: #{@rwd_action}(#{@rwd_args})"
if methods.include?(@rwd_action)
method(@rwd_action).call(*@rwd_args)
else
puts "Method '%s' is not defined." % @rwd_action
end
end
@rwd_history = [["main", [], "main", ""]] if @rwd_action == "main"
@rwd_history = [["main", [], "main", ""]] if @rwd_history.empty?
a = [@rwd_action, @rwd_args, @rwd_window, @rwd_tab]
@rwd_history.push a if (@rwd_history[-1] != a or not @rwd_msgtype.nil?)
if @rwd_window == "rwd_back"
@rwd_history.pop
@rwd_history.pop
@rwd_action = (@rwd_history[-1] or [nil, nil, nil])[0]
@rwd_args = (@rwd_history[-1] or [nil, nil, nil])[1]
@rwd_window = (@rwd_history[-1] or [nil, nil, nil])[2]
@rwd_tab = (@rwd_history[-1] or [nil, nil, nil])[3]
end
end
end
instance_variables.each do |k|
k.sub!(/^@/, "")
instance_eval "vars['#{k}'] = @#{k}.to_s" if (k.scan(/^rwd_/).empty? and not @rwd_ignore_vars.include?("@#{k}"))
end
vars.sort.each do |key, value|
puts "Pre: #{key} -> #{value.inspect}" if $rwd_debug
end
if done
res << RWDDone.new(@rwd_exitbrowser).render(pda)
else
if not @rwd_download.nil?
puts "Download: #{@rwd_window}" if $rwd_debug
download << @rwd_download
downloadfile << @rwd_download_file
else
if not @rwd_progress_thread.nil?
res << RWDProgressBar.new(@rwd_progress_refresh, @rwd_progress_progress).render(pda, @rwd_refresh_action)
else
if not @rwd_msgtype.nil?
res << RWDMessage.new(@rwd_msg).render(pda) if @rwd_msgtype == "message"
res << RWDError.new(@rwd_msg).render(pda) if @rwd_msgtype == "error"
res << @rwd_msg if @rwd_msgtype == "text"
else
puts "Window: #{@rwd_window}" if $rwd_debug
puts "Tab: #{@rwd_tab}" if $rwd_debug
begin if @rwd_window.empty?
@rwd_window = "main"
end
res << RWDWindow.new($rwd_gui_tinker, @rwd_window).render(pda, @rwd_refresh_action, vars, @rwd_switches, help, @rwd_tab)
rescue
$rwdtinkerlog.error "rwd: error in render"
end
end
end
end
end
return done
end
|