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

  1. /* SendMsg.rexx 1.1 (11.11.2000) */
  2.  
  3. signal on halt
  4. signal on break_c
  5. call init()
  6. call CreateApp()
  7. call HandleApp()
  8. /* never reached */
  9. /***********************************************************************/
  10. init: procedure expose global.
  11.     l="rmh.library";if ~show("L",l) then;if ~addLib(l,0,-30) then exit
  12.     if addLibrary("rexxsupport.library","rxsocket.library","rxmui.library")~=0 then exit
  13.  
  14.     call RxMUIOpt("DebugMode ShowErr")
  15.  
  16.     global.this=x2d(pragma("ID"))
  17.     global.fun=""
  18.     global.closing=0
  19.  
  20.     parm.1.value=""
  21.     parm.2.value=""
  22.     parm.3.value=""
  23.     if ~ReadArgs("NEW/S,TO/K,SUBJECT/K,MSG/K/F") then do
  24.         call PrintFault()
  25.         exit
  26.     end
  27.     global.MsgType=parm.0.flag
  28.     if global.MsgType then do
  29.         global.to=""
  30.         global.group=parm.1.value
  31.     end
  32.     else do
  33.         global.to=parm.1.value
  34.         global.group=""
  35.     end
  36.     global.esubject=parm.2.value
  37.     global.nsubject=parm.2.value
  38.     global.msg=parm.3.value
  39.  
  40.     global.CM=exists("MUI:Libs/MUI/CManager.mcc")
  41.  
  42.     return
  43. /***********************************************************************/
  44. CreateApp: procedure expose global.
  45.  
  46.     strip.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.     strip.1="MSettings"
  57.      MSettings.Title="Settings"
  58.      MSettings.Class="menu"
  59.       MShowP.ObjectID=1
  60.      MSettings.0=MenuItem("MShowP","Show Prefs","P","CHEKIT TOGGLE")
  61.      MSettings.1=MenuItem("MMUI","MUI...")
  62.     res=NewObj("Menustrip","strip")
  63.     if res~=0 then call err(res)
  64.  
  65.     to.CycleChain=1
  66.     if string("to","n")="" then call err(57)
  67.  
  68.     if global.cm then do
  69.         ToObj.object="cmg"
  70.          cmg.Class="group"
  71.          cmg.Frame="InputList"
  72.           cmg.0="cm"
  73.            cm.Class="cm"
  74.            cm.AutoLoad=1
  75.            cm.HideUsers=0
  76.            cm.HideWWW=1
  77.            cm.HideFtp=1
  78.            cm.HideChat=1
  79.            cm.HideTelnet=1
  80.            cm.NoMenu=1
  81.            cm.DoubleClick="GLOBAL.CMENTRY"
  82.         ToObj.String="to"
  83.         ToObj.Button=MakeObj("","ImageButton","Popup")
  84.         ToObj.Toggle=1
  85.  
  86.         res=NewObj("popobject","ToObj")
  87.         if res~=0 then call err(res)
  88.     end
  89.     else NameObj="to"
  90.  
  91.     app.Title="SendMsg"
  92.     app.Version="$VER: SendMsg 1.0 (20.7.2000)"
  93.     app.Copyright="Copyright 2000 by alfie"
  94.     app.Author="alfie"
  95.     app.Description="Send e-messages"
  96.     app.Base="SENDMSG"
  97.     app.OwnARexx=1
  98.     app.MenuStrip="strip"
  99.     app.SubWindow="mwin"
  100.  
  101.      mwin.ID="MAIN"
  102.      mwin.Title="SendMsg"
  103.      mwin.Contents="mgroup"
  104.  
  105.       call child("mgroup","mg","group")
  106.  
  107.        call child("mg","swg","group")
  108.         swg.Horiz=1
  109.         swg.0=label("Send _what")
  110.         swg.1=MakeObj("MsgType","Cycle","EMail|New","w",global.MsgType)
  111.  
  112.        call child("mg","eg","group")
  113.         eg.Frame="group"
  114.         eg.FrameTitle="Message data"
  115.         eg.Background="groupback"
  116.          call child("eg","sg","group")
  117.           sg.PageMode=1
  118.           sg.ActivePage=global.MsgType
  119.            call child("sg","sge","group")
  120.             sge.Columns=2
  121.              call child("sge",label("_To"))
  122.              call child("sge","ToObj")
  123.              call child("sge",label("S_ubject"))
  124.              esubject.CycleChain=1; call child("sge",string("ESUBJECT","u",global.esubject))
  125.            call child("sg","sgn","group")
  126.             sgn.Columns=2
  127.              call child("sgn",label("_Group"))
  128.              group.CycleChain=1; call child("sgn",string("group","g",global.group))
  129.              call child("sgn",label("S_ubject"))
  130.              nsubject.CycleChain=1; call child("sgn",string("NSUBJECT","u",global.nsubject))
  131.          call child("eg","text","TextInputScroll")
  132.           text.Frame="string"
  133.           text.CycleChain=1
  134.           text.MaxLen=1024
  135.           text.Styles="EMAIL"
  136.           text.ScrollVertScrollerOnly=1
  137.           text.MaxLines=256
  138.           text.Multiline=1
  139.           text.Contents=global.msg
  140.  
  141.       call child("mgroup","g0","group")
  142.        g0.Weight=0
  143.        g0.Frame="group"
  144.        g0.FrameTitle="Preferences"
  145.        g0.BAckground="groupback"
  146.        g0.Columns=2
  147.         call child("g0",label("Real _name"))
  148.         name.CycleChain=1; name.ObjectID=2; call child("g0",string("NAME","n"))
  149.         call child("g0",label("_EMail"))
  150.         email.CycleChain=1; email.ObjectID=3; call child("g0",string("EMAIL","e"))
  151.         call child("g0",label("_Host"))
  152.         call child("g0","hg","group")
  153.          hg.PageMode=1
  154.          hg.ActivePage=global.MsgType
  155.           ehost.CycleChain=1; ehost.ObjectID=4; call child("hg",string("EHOST","h"))
  156.           nhost.CycleChain=1; nhost.ObjectID=5; call child("hg",string("NHOST","h"))
  157.  
  158.        info.Weight=20;
  159.       call child("mgroup",text("info","Welcome to SendMsg!"))
  160.  
  161.       call child("mgroup","abg","group")
  162.        abg.Weight=20
  163.        abg.Horiz=1
  164.        abg.PageMode=1
  165.         call child("abg","abg0","group")
  166.         abg0.Horiz=1
  167.          send.CycleChain=1; call child("abg0",button("SEND","_Send"))
  168.           call child("abg0",hspace())
  169.           call child("abg0",button("QUIT","_Quit"))
  170.         call child("abg",button("STOP","_Stop"))
  171.  
  172.     res=NewObj("application","app")
  173.     if res~=0 then call err(res)
  174.  
  175.     call notify("mwin","CloseRequest",1,"app","return","call SafeQuit(1)")
  176.  
  177.     call notify("MAbout","MenuTrigger","everytime","app","about","win")
  178.     call notify("MAboutRxMUI","MenuTrigger","everytime","app","aboutrxmui","win")
  179.     call notify("MAboutMUI","MenuTrigger","everytime","app","aboutmui","win")
  180.     call notify("MHide","MenuTrigger","everytime","app","Set","iconified",1)
  181.     call notify("MQuit","MenuTrigger","everytime","app","return","call SafeQuit(1)")
  182.     call notify("MShowP",""Checked"","everytime","g0","Set","ShowMe","triggervalue")
  183.     call notify("mmui","MenuTrigger","everytime","app","openconfigwindow","win")
  184.  
  185.     call notify("MsgType","active","everytime","hg","Set","ActivePage","triggervalue")
  186.     call notify("MsgType","active","everytime","sg","Set","ActivePage","triggervalue")
  187.  
  188.     call notify("send","pressed",0,"app","return","call SafeStart()")
  189.     call notify("stop","pressed",0,"app","return","call SafeQuit(0)")
  190.     call notify("quit","pressed",0,"app","return","call SafeQuit(1)")
  191.  
  192.     call notify("abg","ActivePage","everytime","mg","Set","disabled","triggervalue")
  193.  
  194.     if global.CM then do
  195.         call Notify("cm","doubleclick","everytime","ToObj","close",1)
  196.         call Notify("ToObj","success",1,"app","return","call set('to','contents',global.cmentry.email)")
  197.     end
  198.  
  199.     call DoMethod("app","load","envarc")
  200.     call GetAttr("MShowP",""Checked"","S")
  201.     call set("g0","ShowMe",s)
  202.     call set("mwin","defaultobject","send")
  203.  
  204.     call set("mwin","open",1)
  205.     call GetAttr("mwin","open","o")
  206.     if o=0 then do
  207.         say "can't open window"
  208.         call SafeQuit(1)
  209.     end
  210.  
  211.     call GetAttr("app","base","GLOBAL.REXXPORT")
  212.     global.aps = portSignal(global.rexxPort)
  213.  
  214.     return
  215. /**************************************************************************/
  216. HandleApp: procedure expose global.
  217.     do forever
  218.         call HandleAppOnce()
  219.     end
  220. /**************************************************************************/
  221. HandleAppOnce: procedure expose global.
  222.     ctrl_c=2**12
  223.     sig = or(ctrl_c,global.aps)
  224.     call NewHandle("APP","H",sig)
  225.     if and(h.signals,ctrl_c)>0 then call SafeQuit(1)
  226.     if and(h.signals,global.aps)>0 then call HandleArexxPort()
  227.     if h.EventFlag then
  228.         select
  229.             when h.event="QUIT" then call SafeQuit(1)
  230.             otherwise interpret h.event
  231.         end
  232.     return
  233. /**************************************************************************/
  234. HandleARexxPort: procedure expose global.
  235.  
  236.     do while pkt~=null()
  237.         pkt=GetPkt(global.RexxPort)
  238.         if pkt~=null() then call HandleARexxMsg(pkt)
  239.         call DoMethod("app","InputBuffered")
  240.     end
  241.     return
  242. /**************************************************************************/
  243. HandleARexxMsg: procedure expose global.
  244. parse arg pkt
  245.  
  246.     msg=GetArg(pkt)
  247.     parse var msg cmd args
  248.     ret1=0
  249.     ret2=0
  250.  
  251.     select
  252.  
  253.         when cmd="QUIT" then call SafeQuit(1)
  254.         when cmd="HIDE" then call set("app","iconified",1)
  255.         when cmd="SHOW" then call set("app","iconified",0)
  256.  
  257.  
  258.         when cmd="MACRO" then do
  259.             parse var args id macro
  260.             if id=global.this then do
  261.                 global.fun=macro
  262.                 call set("app","sleep",0)
  263.             end
  264.             else ret1=20
  265.         end
  266.  
  267.         when cmd="ERR" | cmd="EOM" then do
  268.             parse var args id msg
  269.             if id=global.this then do
  270.                 global.fun=""
  271.                 if cmd="ERR" then call info(msg)
  272.                 call set("abg","ActivePage",0)
  273.             end
  274.             else ret1=20
  275.         end
  276.  
  277.         when cmd="INFO" then do
  278.             parse var args id msg
  279.             if id=global.this then call info(msg)
  280.             else ret1=20
  281.         end
  282.  
  283.         otherwise ret1=20
  284.  
  285.     end
  286.  
  287.     call reply(pkt,ret1,ret2)
  288.  
  289.     return
  290. /**************************************************************************/
  291. SafeStart: procedure expose global.
  292.  
  293.     if ~IsLibOn("SOCKET") then do
  294.         call info("No TCP/IP stack running!!!")
  295.         return
  296.     end
  297.  
  298.     if ~exists("sendmsgfun.rexx") then do
  299.         call info "Macro 'sendmsgfun.rexx' not found"
  300.         call set("app","sleep",0)
  301.         return
  302.     end
  303.  
  304.     call GetAttr("MsgType","active","T")
  305.     if t then do
  306.         call GetAttr("nhost","contents","H")
  307.         call GetAttr("name","contents","N")
  308.         call GetAttr("email","contents","E")
  309.         call GetAttr("group","contents","TO")
  310.         call GetAttr("nsubject","contents","S")
  311.         call GetAttr("text","contents","TE")
  312.     end
  313.     else do
  314.         call GetAttr("ehost","contents","H")
  315.         call GetAttr("name","contents","N")
  316.         call GetAttr("email","contents","E")
  317.         call GetAttr("to","contents","TO")
  318.         call GetAttr("esubject","contents","S")
  319.         call GetAttr("text","contents","TE")
  320.     end
  321.  
  322.     if h="" then do
  323.         if t then call info("You must supply a valid News host name")
  324.         else call info("You must supply a valid SMTP host name")
  325.         call set("app","sleep",0)
  326.         return
  327.     end
  328.  
  329.     if n="" then do
  330.         call info("No Real name supplied")
  331.         call set("app","sleep",0)
  332.         return
  333.     end
  334.  
  335.     if e="" then do
  336.         call info("No EMail address supplied")
  337.         call set("app","sleep",0)
  338.         return
  339.     end
  340.  
  341.     if to="" then do
  342.         if t then call info("You must supply a newsgroup name")
  343.         else call info("You must supply a dest EMail address")
  344.         call set("app","sleep",0)
  345.         return
  346.     end
  347.  
  348.     if s="" then do
  349.         call info("No subject supplied")
  350.         call set("app","sleep",0)
  351.         return
  352.     end
  353.  
  354.     if te="" then do
  355.         call info("Can't send an empty message")
  356.         call set("app","sleep",0)
  357.         return
  358.     end
  359.  
  360.     call set("app","sleep",1)
  361.     call set("abg","ActivePage",1)
  362.     call info("Launching child...")
  363.  
  364.     if t then hp=119
  365.     else hp=25
  366.  
  367.  
  368.     /* ID/A,TYPE/A/N,HOST/A,HOSTPORT/A,REALNAME/A,EMAIL/A,TO/A,SUBJECT/A,TEXT/A/K/F */
  369.     cmd="SendMsgFun.rexx" global.this t h hp '"'n'"' '"'e'"' '"'to'"' '"'s'"' "TEXT" te
  370.     call RxsCall(cmd,,,global.RexxPort)
  371.  
  372.     return
  373. /**************************************************************************/
  374. SafeQuit: procedure expose global.
  375. parse arg e
  376.  
  377.     if global.closing then return
  378.  
  379.     call set("app","sleep",1)
  380.     global.closing=1
  381.  
  382.     if global.fun~="" then do
  383.         call info("Breaking child task...")
  384.  
  385.         call Signal(global.fun,2**12)
  386.         do while global.fun~=""
  387.             call HandleAppOnce()
  388.         end
  389.     end
  390.  
  391.     if e then do
  392.         call DoMethod("app","save","envarc")
  393.         exit
  394.     end
  395.  
  396.     call set("abg","ActivePage",0)
  397.     call set("app","sleep",0)
  398.     global.closing=0
  399.     return
  400. /**************************************************************************/
  401. info: procedure expose global.
  402. parse arg txt
  403.     call set("info","contents",txt)
  404.     return
  405. /**************************************************************************/
  406. halt:
  407. break_c:
  408.     call SafeQuit(1)
  409. /**************************************************************************/
  410.