anchor.diff:  conf_fill(_Key,#conf{widget=Widget, val=Val},_) ->
     g('Gtk_entry_set_text',[Widget,to_str(Val)]).
   
  -conf_get_val(Key,LD) -> (fetch(Key,LD#ld.conf))#conf.val.
  -
  -get_gui_val(Key,LD) -> 
  -  C = fetch(Key,LD#ld.conf),
  -  get_gui_val(C#conf.widget,C#conf.type,C#conf.val).
  +conf_val(Key,LD) when is_record(LD,ld) -> 
  +  conf_val(Key,LD#ld.conf);
  +conf_val(Key,Confs) ->
  +  (fetch(Key,Confs))#conf.val.
   
   get_gui_val(Widget,Type,Val) -> 
     X = g('Gtk_entry_get_text',[Widget]),
  
positive.code: -export([loop/1]).				%internal export
  
  -import(lists,[foreach/2,flatten/1,keysearch/3,nth/2,reverse/1,seq/2,sort/1]).
  -import(orddict,[fold/3,update/3,map/2,fetch/2,from_list/1]).
  
  -include("log.hrl").
  
  -define(LP(X), ?MODULE:loop(X)).
  -define(MARG,10).
  -define(XSIZE,2000).
  -define(YSIZE,100).
  -define(WXSIZE,200).
  -define(WYSIZE,?YSIZE).
  
negative.code: 	     {mem,   #conf{widget=conf_mem,   val=1024,type=integer}},
  	     {net,   #conf{widget=conf_net,   val=1024,type=integer}}]).
  
  %% sets and allpies conf values
  %% TagVals and Confs are dicts
  -spec conf(#ld{},tag_vals()) -> #ld{}.
  conf(LD,TagVals) ->
    Confs = fold(fun conf_upd/3,LD#ld.conf,TagVals),
    conf_apply(TagVals,Confs),
    LD#ld{conf=Confs}.
  
  -spec conf_upd(atom(),any(),confs()) -> confs().
  conf_upd(Key,Val,Confs) ->
    update(Key, fun(Conf) -> Conf#conf{val=Val} end, Confs).
  
  %% check if any conf values have changed, i.e. if the GUI and the conf
  %% struct differ. if so, take the value from the GUI
  %% TagVals and Confs are dicts
  -spec conf(#ld{}) -> #ld{}.
  conf(LD) -> 
    {TagVals,Confs} = fold(fun conf_chk/3, {new(),LD#ld.conf}, LD#ld.conf),
    conf_apply(TagVals,Confs),
    LD#ld{conf=Confs}.
  
  -type tag_vals_confs() :: {tag_vals(),confs()}.
  -spec conf_chk(atom(), #conf{}, tag_vals_confs()) -> tag_vals_confs().
  conf_chk(Tag,Conf,{TagVals,Confs}) ->
    Val = get_gui_val(Conf#conf.widget,Conf#conf.type,Conf#conf.val),
    case Val == Conf#conf.val of
      true -> {TagVals,Confs};
      false-> {store(Tag,Val,TagVals), store(Tag,Conf#conf{val=Val},Confs)}
    end.
  
  %% TagVals are the items that has changed
  %% apply them. this is a side effect.
  -spec conf_apply(tag_vals(),confs())->any().
  conf_apply(TagVals,Confs) ->
    at_least_one_of([anode,aproxy],TagVals,fun restart/1,Confs),
    if_there([cpu,net,mem,cookie],TagVals,fun do_conf/2,Confs).
  
  if_there(Tags,TagVals,Fun,Confs) ->
    _ = [Fun(Tag,Confs) || Tag<-Tags,is_key(Tag,TagVals)].
  
  do_conf(cpu,Confs)   -> conf_send(cpu,conf_val(cpu,Confs));
  do_conf(net,Confs)   -> conf_send(net,conf_val(net,Confs));
  do_conf(mem,Confs)   -> conf_send(mem,conf_val(mem,Confs));
  do_conf(cookie,Confs)-> setcookie(conf_val(anode,Confs),conf_val(cookie,Confs)).
  
  conf_send(Key, Val) -> prf:config(gperf_prf,consumer,{Key,Val}).
  
  