home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / rxmui / examples / applications / EmCheck.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2001-01-29  |  7.7 KB  |  301 lines

  1. /* EMCheck 1.1 (11.11.2000) */
  2.  
  3. signal on halt
  4. signal on break_c
  5.  
  6. call init()
  7.  
  8. call CreateApp()
  9.  
  10. call handleApp()
  11.  
  12. /* never reached */
  13.  
  14. init:procedure expose global.
  15.     l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  16.     if AddLibrary("rxmui.library")~=0 then exit
  17.     call RxMUIOpt("DebugMode ShowErr")
  18.  
  19.     global.this=x2d(pragma("ID"))
  20.     global.fun=""
  21.     global.closing=0
  22.     return
  23.  
  24.  
  25. HandleApp: procedure expose global.
  26.     do forever
  27.         call HandleAppOnce()
  28.     end
  29.     /* never reached */
  30.  
  31. HandleAppOnce: procedure expose global.
  32.     ctrl_c=2**12
  33.     sig = or(ctrl_c,global.aps)
  34.     call NewHandle("APP","H",sig)
  35.     if and(h.signals,ctrl_c)>0 then call SafeQuit(1)
  36.     if and(h.signals,global.aps)>0 then call HandleArexxPort()
  37.     if h.EventFlag then
  38.         select
  39.             when h.event="QUIT" then call SafeQuit(1)
  40.             otherwise interpret h.event
  41.         end
  42.     return
  43.  
  44. CreateApp: procedure expose global.
  45.  
  46.     mstrip.0="MProject"
  47.      MProject.class="menu"
  48.      MProject.title="Project"
  49.       MProject.0=MenuItem("MAbout","About...","?")
  50.       MProject.1=MenuItem("MAboutRxMUI","About RxMUI...")
  51.       MProject.2=MenuItem("MAboutMUI","About MUI...")
  52.       MProject.3=MenuItem("","BAR")
  53.       MProject.4=MenuItem("MHide","Hide","H")
  54.       MProject.5=MenuItem("","BAR")
  55.       MProject.6=MenuItem("MQuit","Quit","Q")
  56.     mstrip.1="MSettings"
  57.      MSettings.class="menu"
  58.      MSettings.title="Preferences"
  59.       MSettings.0=MenuItem("MUse","Use","U")
  60.       MSettings.1=MenuItem("MSave","Save","S")
  61.       MSettings.2=MenuItem("MRestore","Last saved","R")
  62.       MSettings.3=MenuItem("","BAR")
  63.       MSettings.4=MenuItem("MMUI","MUI...")
  64.     res=NewObj("menustrip","mstrip")
  65.     if res>0 then exit
  66.  
  67.     app.title="EMCheck"
  68.     app.version="$VER: EMCheck 1.1 (11.11.2000)"
  69.     app.copyright="Under GNU public licence"
  70.     app.author="Alfonso [alfie] Ranieri"
  71.     app.description="Checks a pop3 email account."
  72.     app.base="EMCHECK"
  73.     app.DiskObject="emcheck"
  74.     app.OwnArexx=1
  75.     app.MenuStrip="mstrip"
  76.     app.SubWindow="mwin"
  77.  
  78.      mwin.ID="MAIN"
  79.      mwin.Title="EMCheck 1.1"
  80.      mwin.Contents="mgroup"
  81.  
  82.       mgroup.0="g0"
  83.        g0.Class="group"
  84.        g0.Frame="group"
  85.        g0.Columns=2
  86.         g0.0=label("_Host")
  87.         g0.1="hg"
  88.          hg.Class="group"
  89.          hg.Horiz=1
  90.          hg.spacing=1
  91.            host.CycleChain=1
  92.            host.ObjectID=1
  93.           hg.0=string("host","h")
  94.            HostPort.Weight=30
  95.            HostPort.CycleChain=1
  96.            HostPort.ObjectID=2
  97.            HostPort.IsNumeric=1
  98.            HostPort.MinVal=1
  99.            HostPort.MaxVal=65535
  100.            HostPort.Format="right"
  101.           hg.1=string("HostPort",,110)
  102.         g0.2=label("_User")
  103.          user.CycleChain=1
  104.          user.ObjectID=3
  105.         g0.3=string("user","u")
  106.         g0.4=label("_Pass")
  107.          pass.CycleChain=1
  108.          pass.ObjectID=4
  109.          pass.Secret=1
  110.         g0.5=string("pass","p")
  111.  
  112.       mgroup.1=text("info","Welcome to EMCheck!")
  113.  
  114.       mgroup.2="g1"
  115.        g1.Class="group"
  116.        g1.PageMode=1
  117.          start.CycleChain=1
  118.         g1.0=button("start","_Start")
  119.          stop.CycleChain=1
  120.         g1.1=button("stop","_Stop")
  121.  
  122.     res=NewObj("application","app")
  123.     if res>0 then exit
  124.  
  125.     call notify("mwin","CloseRequest",1,"app","ReturnID","QUIT")
  126.  
  127.     call notify("MAbout","MenuTrigger","EveryTime","app","About","mwin")
  128.     call notify("MAboutRxMUI","MenuTrigger","EveryTime","app","AboutRxMUI","mwin")
  129.     call notify("MAboutMUI","MenuTrigger","EveryTime","app","AboutMUI","mwin")
  130.     call notify("MHide","MenuTrigger","EveryTime","app","set","iconified",1)
  131.     call notify("MQuit","MenuTrigger","EveryTime","app","returnid","quit")
  132.     call notify("MUse","MenuTrigger","EveryTime","app","save","env")
  133.     call notify("MSave","MenuTrigger","EveryTime","app","save","envarc")
  134.     call notify("MSave","MenuTrigger","EveryTime","app","save","env")
  135.     call notify("MRestore","MenuTrigger","EveryTime","app","load","envarc")
  136.     call notify("MMUI","MenuTrigger","EveryTime","app","OpenConfigWindow")
  137.  
  138.     call notify("start","pressed",0,"app","return","call SafeStart")
  139.     call notify("stop","pressed",0,"app","return","call SafeQuit(0)")
  140.  
  141.     call notify("g1","ActivePage","EveryTime","g0","set","disabled","TriggerValue")
  142.     call notify("g1","ActivePage",0,"mwin","set","DefaultObject","start")
  143.     call notify("g1","ActivePage",1,"mwin","set","DefaultObject","stop")
  144.     call notify("g1","ActivePage",0,"mwin","set","ActiveObject","start")
  145.     call notify("g1","ActivePage",1,"mwin","set","ActiveObject","stop")
  146.  
  147.     call DoMethod("app","load","env")
  148.  
  149.     call getattr("app","base","GLOBAL.REXXPORT")
  150.     global.aps=PortSignal(global.RexxPort)
  151.  
  152.     call set("mwin","open",1)
  153.     call getattr("mwin","open","o")
  154.     if o=0 then exit
  155.  
  156.     call set("g1","ActivePage",0)
  157.  
  158.     return
  159.  
  160. halt:
  161. break_c:
  162.     call SafeQuit(1)
  163.  
  164. HandleArexxPort: procedure expose global.
  165.  
  166.     do while pkt~=null()
  167.         pkt=GetPkt(global.RexxPort)
  168.         if pkt~=null() then call HandleARexxMsg(pkt)
  169.         call DoMethod("app","InputBuffered")
  170.     end
  171.     return
  172.  
  173. HandleARexxMsg: procedure expose global.
  174. parse arg pkt
  175.  
  176.     msg=GetArg(pkt)
  177.     parse var msg cmd args
  178.     ret1=0
  179.     ret2=0
  180.  
  181.     select
  182.  
  183.         when cmd="QUIT" then call SafeQuit(1)
  184.         when cmd="HIDE" then call set("app","iconified",1)
  185.         when cmd="SHOW" then call set("app","iconified",0)
  186.  
  187.         when cmd="MACRO" then do
  188.             parse var args id macro
  189.             if id=global.this then do
  190.                 global.fun=macro
  191.                 call set("app","sleep",0)
  192.             end
  193.             else ret1=20
  194.         end
  195.  
  196.         when cmd="ERR" | cmd="EOM" then do
  197.             parse var args id msg
  198.             if id=global.this then do
  199.                 global.fun=""
  200.                 if cmd="ERR" then call info(msg)
  201.                 call set("g1","ActivePage",0)
  202.             end
  203.             else ret1=20
  204.         end
  205.  
  206.         when cmd="INFO" then do
  207.             parse var args id msg
  208.             if id=global.this then call info(msg)
  209.             else ret1=20
  210.         end
  211.  
  212.         otherwise ret1=20
  213.  
  214.     end
  215.  
  216.     call reply(pkt,ret1,ret2)
  217.  
  218.     return
  219.  
  220.  
  221. SafeStart: procedure expose global.
  222.  
  223.     if ~IsLibOn("SOCKET") then do
  224.         call info("No TCP/IP stack running !!!")
  225.         return
  226.     end
  227.  
  228.     if ~exists("EMCheckFun.rexx") then do
  229.         call info("EMCheckFun.rexx not found !!!")
  230.         return
  231.     end
  232.  
  233.     call getattr("host","contents","H")
  234.     if h="" then do
  235.         call info("Host not suppleid.")
  236.         return
  237.     end
  238.  
  239.     call getattr("HostPort","contents","HP")
  240.     if hp="" then do
  241.         call info("Host porta not supplied.")
  242.         return
  243.     end
  244.     if hp=0 | hp>65535 then do
  245.         call info("Host port not valid '"hp"'.")
  246.         return
  247.     end
  248.  
  249.     call getattr("user","contents","U")
  250.     if user="" then do
  251.         call info("User not supplied.")
  252.         return
  253.     end
  254.  
  255.     call getattr("pass","contents","P")
  256.     if p="" then do
  257.         call info("Password not supplied.")
  258.         return
  259.     end
  260.  
  261.     call set("app","sleep",1)
  262.     call set("g1","ActivePage",1)
  263.     call info("Launching child macro...")
  264.  
  265.     /*ID/A,HOST/A,HOSTPORT/A/N,USER/A,PASS/A*/
  266.     cmd="EMCheckFun.rexx" global.this '"'h'"' '"'hp'"' '"'u'"' '"'p'"'
  267.     call RxsCall(cmd,,,global.RexxPort)
  268.  
  269.     return
  270.  
  271. SafeQuit: procedure expose global.
  272. parse arg e
  273.  
  274.     if global.closing then return
  275.  
  276.     call set("app","sleep",1)
  277.     global.closing=1
  278.  
  279.     if global.fun~="" then do
  280.         call info("Waiting for child macro...")
  281.         call Signal(global.fun,2**12)
  282.         do while global.fun~=""
  283.             call HandleAppOnce()
  284.         end
  285.     end
  286.  
  287.     if e then exit
  288.  
  289.     call set("g1","ActivePage",0)
  290.     call set("app","sleep",0)
  291.     global.closing=0
  292.     return
  293.  
  294.  
  295.  
  296. info: procedure expose global.
  297. parse arg msg
  298.     call set("info","contents",msg)
  299.     return
  300.  
  301.