/* Control Client - DMS - Apr 98 - by Sylvain HUET */ /* rev April 00 - by Sebastien DENEUX */ defcom Cregister=Register;; defcom Ccommand=command I S S;; defcom Srelay = relay S S S;; /* used to relay actions */ typeof ll=[[I S I S S] r1];; typeof currentSelection = S;; typeof win=ObjWin;; typeof peopleT=ObjText;; typeof peopleL=ObjList;; typeof messageT=ObjText;; typeof messageE=ObjText;; typeof buttons=[ObjButton r1];; fun llById(a,b)=let a-> [id _ _ _ _] in id==b;; fun _who(x,b,i,sel)= let nth_list ll i -> a in if a==nil then nil else let a->[n ip tim name localisation] in _DLGMessageBox _channel win (_loc this "CTRL_TITLE" nil) (if !strcmp ip "XXX" then strcatn name::" ["::(itoa n)::"] "::(itoa time-tim)::" sec "::localisation::nil else strcatn name::" ["::(itoa n)::"]-("::ip::") "::(itoa time-tim)::" sec "::localisation::nil) 0;; /*----------------*/ fun _click(x,b,i,sel)= let nth_list ll i -> a in if a==nil then nil else let a->[n ip tim name localisation] in set currentSelection = name; 0 ;; fun extrlist(l)= if l==nil then nil else let l->[x n] in [(atoi hd x) (hd tl x) (atoi hd tl tl x) (hd tl tl tl x) (hd tl tl tl tl x)]::extrlist n;; fun _destroyE(a,b)= _DMSdelete this;; fun _end(b)= _DMSdelete this;; fun _resize(x,s)= let x->[wn x y w h] in _SIZEwindow win w h x y; 0;; fun resizebuttons(l,w,y)= if l==nil then 0 else let l->[b n] in (_SIZEbutton b 55+30 20 w-60-30 y; resizebuttons n w y+20);; fun _resizeE(a,b,w,h)= if (h<100)||(w<20) then nil else (_SIZEtext peopleT w-10 20 5 5; _SIZElist peopleL w-70-30 h-85 5 30; _SIZEtext messageT w-10 20 5 h-50; _SIZEtext messageE w-10 20 5 h-25; resizebuttons buttons w 30);; fun _sendcom(a,b)= let _GETlist peopleL ->[i _] in let nth_list ll i -> [n _ _ _ _] in _DMSsend this Ccommand [n b _GETtext messageE];; fun addbuttons(l, w, y, lname) = if l==nil then nil else let l->[s n] in let lname -> [t q] in (_CBbutton _CRbutton _channel win w-60-30 y 55+30 20 0 t @_sendcom s)::addbuttons n w y+20 q ;; fun iniWin(wn, x, y, w, h, l) = set win=_CRwindow _channel wn x y w h if wn==nil then WN_MENU+WN_MINBOX+WN_SIZEBOX else WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER strcat strcat (_loc this "CTRL_TITLE" nil) " : " _DMSgetName this; _CBwinDestroy win @_destroyE 0; _CBwinSize win @_resizeE 0; set peopleT=_CRtext _channel win 5 5 w-10 20 ET_BORDER|ET_ALIGN_CENTER strcat "0" (_loc this "CTRL_PEOPLE" nil); _CBwinDestroy win @_destroyE 0; set peopleL=_CRlist _channel win 5 30 w-70-30 h-85 LB_DOWN+LB_VSCROLL; set messageT=_CRtext _channel win 5 h-50 w-10 20 ET_BORDER|ET_ALIGN_CENTER (_loc this "CTRL_MESS" nil); set messageE=_CReditLine _channel win 5 h-25 w-10 20 ET_DOWN|ET_AHSCROLL ""; _CBlistDclick peopleL @_who 0; _CBlistClick peopleL @_click 0; set buttons=addbuttons "del"::"private"::"broadcast"::l w 30 (_loc this "CTRL_DEL" nil)::(_loc this "CTRL_PRIV" nil)::(_loc this "CTRL_BROAD" nil)::l; 0 ;; /******************************************************************************* relay action *******************************************************************************/ fun cbRelay (from, action, param, others, tag,i) = if currentSelection == nil then nil else _DMSsend this Srelay [currentSelection param i] ;; /******************************************************************************* define others actions *******************************************************************************/ fun DefOthers(n) = if n == nil || n <= 0 then 0 else ( _DMSdefineActions this [strcat "relay." itoa n mkfun6 @cbRelay itoa n]::nil; DefOthers n-1 ) ;; /*--------*/ fun IniDMI(param)= let lineextr param -> [nbEventRelay[b _]] in ( /* define relay actions */ DefOthers atoi nbEventRelay; _DMSsend this Cregister []; let _DMSgetZone this "Control" @_end @_resize @_end ->[wn x y w h] in if wn!=nil then iniWin wn x y w h hd strextr b else iniWin nil nil nil 350 350 hd strextr b; 0 ) ;; /*--------*/ fun updatel2(x,b)= let b->[l pos] in let x->[_ ip _ n location] in if !strcmp ip "XXX" then _ADDlist l pos strcatn n::" "::location::nil else _ADDlist l pos strcatn n::" ("::ip::") "::location::nil;; /*--------*/ fun llsort(a,b)= let a -> [_ _ _ login1 _] in let b -> [_ _ _ login2 _] in if (strcmpi login1 login2)>=0 then -1 else 1;; /*--------*/ /*init list first time*/ fun __setlist(s)= set ll=rquicksort @llsort (extrlist strextr s); _SETtext peopleT strcat (itoa sizelist ll) strcat " " (_loc this "CTRL_PEOPLE" nil); _RSTlist peopleL; apply_on_list ll @updatel2 [peopleL 10000];; /*--------*/ /*a new user is being registered*/ fun __addUser(s)= let hd strextr s -> x in let atoi hd x -> id in let [id (hd tl x) (atoi hd tl tl x) (hd tl tl tl x) (hd tl tl tl tl x)] -> newUser in ( set ll = rquicksort @llsort newUser::ll; _SETtext peopleT strcat (itoa sizelist ll) strcat " " (_loc this "CTRL_PEOPLE" nil); let posf_in_list ll @llById id -> pos in updatel2 newUser [peopleL pos] );; /*--------*/ /*update user login*/ fun __updateUser(s)= let hd strextr s -> x in let atoi hd x -> id in let search_in_list ll @llById id -> e in let posf_in_list ll @llById id -> pos in ( _DELlist peopleL pos; mutate e <- [_ (hd tl x) (atoi hd tl tl x) (hd tl tl tl x) (hd tl tl tl tl x)]; set ll = rquicksort @llsort ll; let posf_in_list ll @llById id -> pos in updatel2 e [peopleL pos]; 0 );; /*--------*/ /*delete a user*/ fun __delUser(id,login)= if !strcmp login currentSelection then set currentSelection = nil else nil; let posf_in_list ll @llById id -> pos in ( _DELlist peopleL pos; set ll=removef_from_list ll @llById id; _SETtext peopleT strcat (itoa sizelist ll) strcat " " (_loc this "CTRL_PEOPLE" nil); 0 );;