/**/

signal on halt
signal on break_c

call Init
call CreateApp
call HandleApp

/***********************************************************************/
Init: procedure
    l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
    if AddLibrary("rxmui.library")~=0 then exit
    call RxMUIOpt("DebugMode ShowErr")
    return
/***********************************************************************/
HandleApp: procedure expose infos.
    ctrl_c=2**12
    do forever
        call NewHandle("app","h",ctrl_c)
        if and(h.signals,ctrl_c)>0 then exit
        if h.EventFlag then
            select
                when h.event="QUIT" then exit
                otherwise interpret h.event
            end
    end
/***********************************************************************/
CreateApp: procedure expose infos.
    app.Title="FreeDB"
    app.Version="$VER: FreeDB 1.0 (27.10.2001)"
    app.Copyright="Copyrught © 2001 by Alfonso Ranieri"
    app.Author="Alfonso Ranieri"
    app.Description="FreeDB example"
    app.Base="FREEDB"
    app.Menustrip="strip"
     strip.0="mproject"
      mproject.Title="Project"
      mproject.Class="menu"
       mproject.0=Menuitem("mabout","?\About...")
       mproject.1=Menuitem("maboutrxmui","About RxMUI...")
       mproject.2=Menuitem("maboutmui","About MUI...")
       mproject.3=Menuitem("","BAR")
       mproject.4=Menuitem("mhide","H\Hide")
       mproject.5=Menuitem("","BAR")
       mproject.6=Menuitem("mquit","Q\Quit")
     strip.1="mfreedb"
      mfreedb.Title="FreeDB"
      mfreedb.Class="menu"
       mfreedb.0=Menuitem("mget","G\Get")
       mfreedb.1=Menuitem("mgetlocal","L\Get local")
       mfreedb.2=Menuitem("mgetremote","R\Get remote")
     strip.2="meditor"
      meditor.Title="Editor"
      meditor.Class="menu"
       meditor.0=Menuitem("mconfig","C\Config...")
       meditor.1=Menuitem("mmui","M\MUI...")
    app.SubWindow.0="wmain"
     wmain.ID="MAIN"
     wmain.Title="FreeDB Example"
     wmain.Contents="mgroup"
      mgroup.0="disc"
        disc.Class="FreeDBDisc"
        disc.Prg="FreeDB.rexx"
        disc.Ver="1.0"
    app.SubWindow.1="wabout"
     wabout.Class="FreeDBAbout"
     wabout.RefWindow="wmain"
    app.SubWindow.2="wconf"
     wvonf.Class="window"
     wvonf.ID="CONF"
     wconf.Title="FreeDB configuration"
     wconf.Menustrip="wcstrip"
      wcstrip.0="mconfig"
      mconfig.Title="Config"
      mconfig.Class="menu"
       mconfig.0=Menuitem("mlast","L\Last saveds")
       mconfig.1=Menuitem("mrestore","R\Restore")
       mconfig.2=Menuitem("mgetsites","G\Get")
     wconf.Contents="cmgroup"
      cmgroup.0="cg"
        cg.Class="FreeDBConfig"


    if NewObj("APPLICATION","APP")>0 then exit

    call Notify("wmain","CloseRequest",1,"APP","Returnid","QUIT")
    call Notify("wconf","CloseRequest",1,"wconf","set","Open",0)

    call Notify("mabout","menutrigger","everytime","wabout","set","open",1)
    call Notify("maboutrxmui","menutrigger","everytime","app","aboutrxmui","wmain")
    call Notify("maboutmui","menutrigger","everytime","app","aboutmui","wmain")
    call Notify("mhide","menutrigger","everytime","app","set","iconified",1)
    call Notify("mquit","menutrigger","everytime","app","returnid","quit")
    call Notify("mget","menutrigger","everytime","disc","GetDisc")
    call Notify("mgetlocal","menutrigger","everytime","disc","GetDisc","local")
    call Notify("mgetremote","menutrigger","everytime","disc","GetDisc","remote")
    call Notify("mconfig","menutrigger","everytime","wconf","set","open",1)
    call Notify("mmui","menutrigger","everytime","app","OpenConfigWindow")

    call Notify("mlast","menutrigger","everytime","cg","load","env")
    call Notify("mrestore","menutrigger","everytime","cg","load","envarc")
    call Notify("mgetsites","menutrigger","everytime","cg","getsites")

    call Notify("cg","done",1,"wconf","set","Open",0)

    call Notify("disc","doubleclick",1,"APP","RETURN","say double")
    call Notify("disc","activetitle",everytime,"APP","RETURN","say active h.activetitle","triggerattr")
    call Notify("disc","Changed",0,"app","return","call DiscChanged(0)")
    call Notify("disc","Changed",1,"app","return","call DiscChanged(1)")

    call set("wmain","open",1)

    return
/***********************************************************************/
halt:
break_c:
    exit
/**************************************************************************/
DiscChanged: procedure expose infos.
parse arg d
    if ~d then return
    call DoMethod("disc","GetData","infos")

    if infos.TOCFlag then do
        say infos.toc.NumTracks
        do i=0 to infos.toc.NumTracks-1
            say i":" infos.toc.i.min infos.toc.i.sec infos.toc.i.frame
        end
    end


    if infos.DIFlag then do
        say infos.di.Title infos.di.Artist infos.di.NumTracks
        do i=0 to infos.di.NumTracks-1
            say i":" infos.di.titles.i
        end
    end

    return
/**************************************************************************/
