/* Global Download Client - DMS - February 2003 - by Bob Le Gob */ /******************************************************************************* Variables *******************************************************************************/ typeof winZone = ObjWin;; /* Window for the module zone */ typeof bmpZone = ObjBitmap;; /* Background chosen bitmap */ typeof bmpBlit = ObjBitmap;; /* Real zone bitmap */ struct MyStruct = [myW:I, myH:I] mkMyStruct;; typeof mrZone = MyStruct;; typeof mrBmp = MyStruct;; var iDisplay = 0;; /* 0-Bitmap background, 1-Colored background */ var iStatus = 0;; /* 0-Still, 1-Download in progress */ var iBgCol = 0;; /* Background color */ var iPgCol = 0;; /* Progress bar color */ var iCrCol = 0;; /* Activity cursor color */ var iTotalBytes = 0;; /* Bytes to download */ var iDwnldBytes = 0;; /* Bytes downloaded */ var iTotalKB = 0;; /* KBytes to download */ var iDwnldKB = 0;; /* KBytes downloaded */ typeof tmrCursor = Timer;; /* Activity cursor timer */ var iPercentX = 0;; /* Activity cursor value (%) */ var iCursorX = 0;; /* Activity cursor value (x) */ /******************************************************************************* Protos *******************************************************************************/ proto cbPaint = fun [ObjWin I] I;; /******************************************************************************* Functions *******************************************************************************/ /******************************************************************************* Functions: Secondary functions *******************************************************************************/ /******************************************************************************* cbTick() - Activity cursor timer Tick callback tmr -> Timer : Activity cursor timer p -> u0 : Not used <- I : Not used *******************************************************************************/ fun cbTick(tmr, p) = if (iPercentX >= 99) then set iPercentX = 0 else set iPercentX = iPercentX + 1; set iCursorX = (iPercentX * mrZone.myW) / 100; _PAINTwindow winZone; 0;; /******************************************************************************* FreeResources() - Freeing resources of the module <- I : Not used *******************************************************************************/ fun FreeResources() = if (tmrCursor != nil) then (_deltimer tmrCursor; set tmrCursor = nil; 0;) else 0; if (bmpBlit != nil) then (_DSbitmap bmpBlit; set bmpBlit = nil; 0;) else 0; if (bmpZone != nil) then (_DSbitmap bmpZone; set bmpZone = nil; 0;) else 0; if (winZone != nil) then (_DSwindow winZone; set winZone = nil; 0;) else 0; 0;; /******************************************************************************* GetFileExtension() - Getting extension of file name str -> S : File name, or sub part of file name <- S : File extension *******************************************************************************/ fun GetFileExtension(str) = let strfind "." str 0 -> dotFound in if (dotFound == nil) then strlowercase str else GetFileExtension substr str (dotFound + 1) ((strlen str) - dotFound - 1);; /******************************************************************************* Functions: Zone handling *******************************************************************************/ /******************************************************************************* cbZoneEnd() - Destroying module zone zone -> S : Zone name <- I : Not used *******************************************************************************/ fun cbZoneEnd(zone) = FreeResources; _DMSdelete this; 0;; /******************************************************************************* cbZoneResize() - Resizing module zone coord -> [ObjWin I I I I] : New coordinates [window x y w h] zone -> S : Zone name <- I : Not used *******************************************************************************/ fun cbZoneResize(coord, zone) = let coord -> [_ x y w h] in ( _SIZEwindow winZone w h x y; set mrZone.myW = w + 1; set mrZone.myH = h + 1; if (bmpBlit != nil) then (_DSbitmap bmpBlit; set bmpBlit = _CRbitmap _channel (w + 1) (h + 1); 0;) else 0; _PAINTwindow winZone; 0; );; /******************************************************************************* Functions: Module main callbacks *******************************************************************************/ /******************************************************************************* cbBeforeClose() - Callback called before ending of server <- I : Not used *******************************************************************************/ fun cbBeforeClose() = _DMSreleaseZone this "GlobalDownload"; FreeResources; 0;; /******************************************************************************* cbRegisterDownload() - New download beginning from -> DMI : Not used action -> S : Not used param -> S : Total size of new download others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbRegisterDownload(from, action, param, others, tag) = if (iStatus == 0) then ( set iPercentX = 0; set iCursorX = 0; set tmrCursor = _starttimer _channel 100; _rfltimer tmrCursor @cbTick nil; 0; ) else 0; set iStatus = 1; set iTotalBytes = iTotalBytes + (atoi param); set iTotalKB = iTotalBytes / 1024; if (iTotalKB == 0) then set iTotalKB = 1 else 0; _PAINTwindow winZone; 0;; /******************************************************************************* cbRegisterFile() - New file downloaded from -> DMI : Not used action -> S : Not used param -> S : Size of downloaded file others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbRegisterFile(from, action, param, others, tag) = set iDwnldBytes = iDwnldBytes + (atoi param); set iDwnldKB = iDwnldBytes / 1024; _PAINTwindow winZone; if (iDwnldBytes >= iTotalBytes) then ( _deltimer tmrCursor; set iStatus = 0; set iDwnldBytes = 0; set iTotalBytes = 0; set iDwnldKB = 0; set iTotalKB = 0; set tmrCursor = nil; set iPercentX = 0; set iCursorX = 0; _PAINTwindow winZone; 0; ) else 0; 0;; /******************************************************************************* cbPaint() - Window Paint callback win -> ObjWin : Window p -> I : Not used <- I : Not used *******************************************************************************/ fun cbPaint(win, p) = _FILLbitmap bmpBlit iBgCol; if (iDisplay == 0) then ( _SCPbitmap bmpBlit 0 0 mrZone.myW mrZone.myH bmpZone 0 0 mrBmp.myW mrBmp.myH nil; 0; ) else 0; if (iStatus == 1) then ( _DRAWrectangle bmpBlit 0 0 ((mrZone.myW * iDwnldKB) / iTotalKB) mrZone.myH DRAW_INVISIBLE nil nil DRAW_SOLID iPgCol; _DRAWline bmpBlit iCursorX 0 iCursorX (mrZone.myH - 1) DRAW_SOLID 4 iCrCol; 0; ) else 0; _STBLTbitmap winZone 0 0 mrZone.myW mrZone.myH bmpBlit 0 0 mrZone.myW mrZone.myH; 0;; /******************************************************************************* Functions: Module instanciation *******************************************************************************/ /******************************************************************************* Standard IniDMI param -> S : Parameter from server - List of files to download - strbuild format <- I : Not used *******************************************************************************/ fun IniDMI(param)= set winZone = nil; set bmpZone = nil; set bmpBlit = nil; set tmrCursor = nil; let _DMSgetZone this "GlobalDownload" @cbZoneEnd @cbZoneResize @cbZoneEnd -> [win x y w h] in if (win == nil) then nil else let strextr param -> l in let getInfo l "bgBmp" -> sBgBmp in let getInfo l "bgCol" -> sBgCol in let getInfo l "pgCol" -> sPgCol in let getInfo l "crCol" -> sCrCol in ( set winZone = _CRwindow _channel win x y w h WN_CHILD|WN_NOBORDER "GlobalDownload"; set mrZone = mkMyStruct [(w + 1) (h + 1)]; if !strcmp sBgBmp nil then ( set iDisplay = 1; set iBgCol = atoi sBgCol; 0; ) else ( set iDisplay = 0; if !strcmp GetFileExtension sBgBmp "bmp" then set bmpZone = _LDbitmap _channel _checkpack sBgBmp else set bmpZone = _LDjpeg _channel _checkpack sBgBmp; let _GETbitmapSize bmpZone -> [wb hb] in set mrBmp = mkMyStruct [(wb + 1) (hb + 1)]; 0; ); set iPgCol = atoi sPgCol; set iCrCol = atoi sCrCol; set bmpBlit = _CRbitmap _channel (w + 1) (h + 1); _DMSregister this @cbBeforeClose; _DMSdefineActions this (["register_download" @cbRegisterDownload]):: (["register_file" @cbRegisterFile]):: nil; _CBwinPaint winZone @cbPaint nil; ); 0;;