
------------------------------------------------------------------------
--# Password generator, requires <b>apg</b>
------------------------------------------------------------------------

include GtkEngine.e

constant docs = `<u><b>Password Generator</b></u>
Generates 6 random passwords with pronunciation.
Hit the Generate <small><sup>(alt-G)</sup> </small> button to generate a new list.`

constant win = create(GtkWindow,{
    {"default size",300,100},
    {"border width",10},
    {"position",GTK_WIN_POS_CENTER},
    {"icon","thumbnails/passred.png"},
    {"connect","destroy","Quit"}})
    
constant panel = create(GtkBox,1)
    add(win,panel)

constant lbl = create(GtkLabel)
    set(lbl,"markup",docs)
    add(panel,lbl)

constant bkgnd = create(GtkEventBox,{
    {"border width",10},
    {"background",0}})
    add(panel,bkgnd)

constant list = create(GtkLabel)
    set(list,"foreground","#18F424")
    add(bkgnd,list)

constant 
    btn1 = create(GtkButton,"gtk-quit","Quit"),
    btn2 = create(GtkButton,"stock_repeat#_Generate","GeneratePW"),
    box = create(GtkButtonBox)
    pack(panel,-box)
    add(box,{btn1,btn2}) 

show_all(win)

    if system_exec("which apg",0) != 0 then
        Warn(win,"Error","Cannot find apg program","Please install one!")
        abort(1)
    else
        GeneratePW()
    end if
    
main()

------------------------------
global function GeneratePW() -- call apg, format and display results;
------------------------------
system("apg > pw.list -a 0 -M Ncl -t",0)
object results = read_lines("pw.list")
object words = "<span color='green'>  <b><u>Password</u></b> </span><span color='red3'> <b><u> Pronunciation</u></b> \n\n</span>"
    for i = 1 to length(results) do
        words &= format("  <b>[1]</b>   <span color='red'>[2]</span>  \n",split(results[i],' '))
    end for
    set(list,"markup",words)
    set(list,"selectable",TRUE)
    delete_file("pw.list")
return 1
end function
  

