/* Annuaire client - dec 98 - by magical Fred */ /****************************************************************************/ /* */ /* data structures */ /* */ /****************************************************************************/ struct Card = [ authorCARD : S, /* author of the site */ sitenameCARD : S, /* name of the site */ emailCARD : S, /* email */ messageCARD : S, /* info message about the site */ ipCARD : S, /* last ip know. 0/nil if down */ bitmapCARD : S, /* filename of the bitmap */ lastCARD : I, /* date of the last succeful check */ idnumCARD : I, /* unique number - key in the database */ flagCARD : I, /* actif / proxy, etc */ rankCARD : I /* rang dans la fenetre */ ] mkCARD ;; /****************************************************************************/ /* */ /* Communications client -> server */ /* */ /****************************************************************************/ defcom Cregister=register;; defcom CaskCount= askCount ;; defcom CgetKey = getKey I I ;; defcom CaskCard = askCard I ;; defcom CaskBitmap = askBitmap I S I ;; defcom Copen=open S;; defcom CaskIpSite = askIpSite S S S ;; defcom CnewFavorite = newFavorite ;; /****************************************************************************/ /* */ /* Variables */ /* */ /****************************************************************************/ typeof listCard = [ Card r1 ] ;; typeof focus=DMI;; typeof reply=S;; typeof cardwin = ObjWin ;; typeof listwin = ObjListTab ;; typeof myFont = ObjFont ;; typeof safefond = ObjBitmap ;; typeof fond = ObjBitmap ;; var nbcount = 0 ;; var getcount = 0 ;; var cardListed = 0 ;; typeof bitmap = ObjBitmap ;; typeof AskedSitenameS = S ;; var listS = "dir.scol-technologies.org:3102" ;; fun genldbitmap(name)= let _LDbitmap _channel _checkpack name -> u in if u != nil then u else _LDjpeg _channel _checkpack name ;; /****************************************************************************/ /* */ /* fun sortCard(list,card) */ /* */ /* sort the card list by sitename */ /* */ /****************************************************************************/ fun sortCard(list,card)=if list == nil then [ card nil ] else let list -> [ c n ] in if (strcmp c.sitenameCARD card.sitenameCARD)>0 then [ card list ] else [ c sortCard n card ] ;; fun sortListCard(list,todo)= if todo == nil then list else let todo -> [ c n ] in sortListCard sortCard list c n ;; fun displayCard(l)=if l == nil then 0 else let l -> [ c n ] in let _GETlistTabCount listwin -> tcount in ( _ADDlistTabItem listwin tcount tcount c.sitenameCARD ; _SETlistTabItem listwin tcount 1 if (c.flagCARD&2)==2 then "Active" else "Inactive" ; set c.rankCARD = tcount ; displayCard n ) ;; fun remakeList()= set listCard = sortListCard nil listCard ; _RSTlistTab listwin ; displayCard listCard ; 0 ;; /****************************************************************************/ /* */ /* fun findCardByNum ( list [ Card r1 ] , id I ) -> Card */ /* */ /* find a card in a card list with its idnum */ /* */ /****************************************************************************/ fun findCardByNum(l,id)=if l == nil then nil else let l ->[ c n ] in if c.idnumCARD == id then c else findCardByNum n id ;; fun findCardByRank(l,r)=if l == nil then nil else let l -> [ c n ] in if c.rankCARD == r then c else findCardByRank n r ;; /****************************************************************************/ /* */ /* fun gotCard (l [ [ S r1 ] r1 ]-> u0 */ /* */ /* parse informations about a list of site */ /* */ /****************************************************************************/ fun gotCard(l)=if l == nil then 0 else let l -> [line next ] in let line -> [ id [ author [ site [ email [ flag _]]]]] in ( set listCard = [ mkCARD [ author site email nil nil nil nil atoi id atoi flag 0 ] listCard ] ; set getcount = getcount + 1 ; gotCard next ) ;; /****************************************************************************/ /* */ /* fun selectCard(CARD u ) -> CARD */ /* */ /* print information of a card into the cardwin window */ /* */ /****************************************************************************/ fun selectCard(u)= _CPbitmap16 fond 0 0 safefond 0 0 406 525 nil ; _DRAWtext fond myFont 177 247 TD_TOP 0xFFFFFF u.sitenameCARD ; _DRAWtext fond myFont 194 278 TD_TOP 0xFFFFFF u.authorCARD ; _DRAWtext fond myFont 121 308 TD_TOP 0xFFFFFF u.emailCARD ; set cardListed = u.idnumCARD ; if u.messageCARD == nil then ( _DMSsend this CaskCard [ u.idnumCARD ] ; 0 ) else ( _DRAWrectangleText fond myFont 30 358 192 470 0xFFFFFF TD_LEFT|TD_TOP u.messageCARD ; if (_checkpack u.bitmapCARD) != nil then ( if bitmap == nil then _DSbitmap bitmap else 0 ; set bitmap = genldbitmap u.bitmapCARD ; 0 ) else ( set bitmap = _CRbitmap _channel 128 128 ; _FILLbitmap bitmap 0 ; _DRAWtext bitmap myFont 64 20 TD_CENTER 0x77FF00 "Download" ; _DRAWtext bitmap myFont 64 50 TD_CENTER 0x77FF00 "0%" ; _DMSsend this CaskBitmap [ u.idnumCARD u.bitmapCARD 0 ] ; 0 ) ; _PAINTwindow cardwin ; 0 ) ;; /****************************************************************************/ /* */ /* selection of a site into the list */ /* */ /****************************************************************************/ fun selectSite(ol,bla,rank)= let findCardByRank listCard rank -> u in selectCard u ;; /****************************************************************************/ /* */ /* handling DMS action */ /* */ /****************************************************************************/ fun activate(from,action,param,rep)= if !strcmp action "getMotion" then (set focus=from; set reply=rep;0) else nil;; fun paintcard(w,a)= _BLTbitmap cardwin fond 0 0 ; if bitmap != nil then _BLTbitmap cardwin bitmap 251 358 else nil ;; fun previouscard(a,b)= let findCardByNum listCard cardListed -> c in let if c.rankCARD == 0 then nbcount-1 else c.rankCARD - 1 -> id in ( selectCard findCardByRank listCard id ; 0 ) ;; fun nextcard(a,b)= let findCardByNum listCard cardListed -> c in let if c.rankCARD == (nbcount-1) then 0 else c.rankCARD +1 -> id in ( selectCard findCardByRank listCard id ; 0 ) ;; fun gocard(a,b)= let findCardByNum listCard cardListed -> c in if c != nil then ( _on _masterchannel Copen [strcatn "scol://"::c.ipCARD::":"::c.sitenameCARD::nil ]; 0 ) else 0 ;; fun _end(a)=_DMSdelete this;; fun _resize(x,s)= let x->[wn x y w h] in _SIZEwindow cardwin w h x y; 0;; /****************************************************************************/ /* */ /* Add a favorite site */ /* */ /****************************************************************************/ defcom CaddBookmark = addbookmark S ;; fun addFavorite(a,b)= let findCardByNum listCard cardListed -> c in if c == nil then (_fooS "Card not found in addFavorite";0) else let strbuild (c.sitenameCARD:: (strcatn "scol://"::listS::"/name+"::c.sitenameCARD:: "/author+"::c.authorCARD::"/email+"::c.emailCARD::nil)::nil)::nil -> booknote in let substr booknote 0 (strlen booknote) -1 -> booknote2 in ( /* write the new favorites */ _fooS booknote2 ; _on _masterchannel CaddBookmark [ booknote2 ] ; 0 ) ;; /* function init of the client */ fun IniDMI(param)= let [ _getress "name" _getress "author" _getress "email" ] -> [ n r e ] in if (e != nil) && (r!=nil) && (n!=nil) then ( set AskedSitenameS = n ; _DMSregisterDMI this @activate nil; _DMSsend this CaskIpSite [ n r e ] ; 0 ) else ( set myFont = _CRfont _channel 14 0 FF_WEIGHT "Arial" ; set safefond = _LDjpeg _channel _checkpack "Dms/commtools/cardregister/screen.jpg" ; set fond = _CRbitmap _channel 406 525 ; _CPbitmap16 fond 0 0 safefond 0 0 406 525 nil ; _DMSregisterDMI this @activate nil; let _DMSgetZone this "Card" @_end @_resize @_end ->[wn x y w h] in ( _showconsole ; if wn == nil then set cardwin = _CRwindow _channel DMSwin 30 30 406 525 WN_MENU|WN_MINBOX "Directory" else set cardwin = wn ; _CBwinPaint cardwin @paintcard 0 ; set listwin = _CRlistTab _channel cardwin 5 40 396 190 LV_DOWN ; _CBlistTabSelect listwin @selectSite 0 ; _ADDlistTabColumn listwin 0 280 0 "Site" ; _ADDlistTabColumn listwin 1 100 0 "State" ; let _LDbitmap _channel _checkpack "Dms/Commtools/CardRegister/previous.bmp" -> bmp in _CBbutton _CRbuttonBitmap _channel cardwin bmp 25 497 54 20 0 @previouscard 0 ; let _LDbitmap _channel _checkpack "Dms/Commtools/CardRegister/go.bmp" -> bmp in let _GETbitmapSize bmp -> [x y ] in _CBbutton _CRbuttonBitmap _channel cardwin bmp 257 497 x y 0 @gocard 0 ; let _LDbitmap _channel _checkpack "Dms/Commtools/CardRegister/add.favor.bmp" -> bmp in _CBbutton _CRbuttonBitmap _channel cardwin bmp 108 497 120 20 0 @addFavorite 0 ; let _LDbitmap _channel _checkpack "Dms/Commtools/CardRegister/next.bmp" -> bmp in _CBbutton _CRbuttonBitmap _channel cardwin bmp 334 497 50 20 0 @nextcard 0 ; 0 ) ; _DMSsend this CaskCount [] ; _DMSsend this Cregister []; 0 ) ;; /****************************************************************************/ /* */ /* fun __sendCount ( I i ) -> u0 */ /* */ /* get from the server the number of cards. */ /* */ /****************************************************************************/ fun __sendCount(i)= set nbcount = i ; set getcount = 0 ; set listCard = nil ; _RSTlistTab listwin ; _DMSsend this CgetKey [ 1 min nbcount 10 ] ;; /****************************************************************************/ /* */ /* __sendCard [ S s ] -> u0 */ /* */ /* get from server informations about a short list of site */ /* */ /****************************************************************************/ fun __sendCard(s)= gotCard strextr s ; remakeList ; if getcount < nbcount then _DMSsend this CgetKey [ getcount+1 min getcount +10 nbcount ] else nil ;; /****************************************************************************/ /* */ /* fun _sendBitmap ( I id, S cont, I clen , I len ) -> u0 */ /* I id : card identifiant */ /* S cont : bitmap file part */ /* I clen : seek position of the bmp part */ /* I len : total size of the file */ /* */ /* receive a part of the bitmap file from the server */ /* */ /****************************************************************************/ fun __sendBitmap(id,cont,clen,len)= if cont==nil then ( _FILLbitmap bitmap 0 ; _DRAWtext bitmap myFont 64 20 TD_CENTER 0x77FF00 "No bitmap" ; _PAINTwindow cardwin ; 0 ) else if id == cardListed then ( let findCardByNum listCard id -> c in ( _appendpack cont _getmodifypack c.bitmapCARD ; if clen < len then ( _DMSsend this CaskBitmap [id c.bitmapCARD clen] ; _FILLbitmap bitmap 0 ; _DRAWtext bitmap myFont 64 20 TD_CENTER 0x77FF00 "Download" ; _DRAWtext bitmap myFont 64 50 TD_CENTER 0x77FF00 strcat itoa clen*100/len "%" ; 0 ) else ( if bitmap != nil then _DSbitmap bitmap else 0 ; set bitmap = genldbitmap c.bitmapCARD ; 0 ) ; _PAINTwindow cardwin ; 0 ) ) else 0 ;; /****************************************************************************/ /* */ /* reception from the server of informations on a card */ /* */ /****************************************************************************/ fun __sendInfoCard(id,msg,ip,last,filename,sign,flag)= let findCardByNum listCard id -> c in ( set c.messageCARD = msg ; set c.ipCARD = ip ; set c.lastCARD = last ; set c.bitmapCARD = filename ; set c.flagCARD = flag ; _SETlistTabItem listwin c.rankCARD 1 if (flag&2)==2 then "Active" else "Inactive" ; let _getlongname _getpack _checkpack filename filename "#" -> signature in if !strcmp signature sign then ( if bitmap == nil then _DSbitmap bitmap else 0 ; set bitmap = genldbitmap filename ; 0 ) else if cardListed == id then ( set bitmap = _CRbitmap _channel 128 128 ; _FILLbitmap bitmap 0 ; _DRAWtext bitmap myFont 64 20 TD_CENTER 0x77FF00 "Download" ; _DRAWtext bitmap myFont 64 50 TD_CENTER 0x77FF00 "0%" ; _DMSsend this CaskBitmap [ id filename 0 ] ; 0 ) else 0 ; if cardListed == id then ( _DRAWrectangleText fond myFont 30 358 200 470 0xFFFFFF TD_LEFT|TD_TOP msg ; 0 ) else 0 ; _PAINTwindow cardwin ; 0 ) ;; /****************************************************************************/ /* */ /* fun __refreshState (I idnum, I state ) -> I */ /* */ /* server send a change of state ( actif/inactif ) */ /* */ /****************************************************************************/ fun __refreshState (idnum,state)= let findCardByNum listCard idnum -> c in ( set c.flagCARD = state ; _SETlistTabItem listwin c.rankCARD 1 if (state&2)==2 then "Active" else "Inactive" ) ;; /****************************************************************************/ /* */ /* fun __ipSite ( S ip ) */ /* */ /* the annuaire server return the address of the asked site */ /* */ /****************************************************************************/ fun endMachine(a,b,c)= _closemachine ;; fun __ipSite (ip)=if ip == nil then ( _DLGrflmessage _DLGMessageBox _channel DMSwin "Site not available" "The site is down or unknow" 0 @endMachine 0 ; 0 ) else ( _on _masterchannel Copen [strcatn "scol://"::ip::":"::AskedSitenameS::nil ] ; _closemachine ) ;;