Check if the user is gone away

Post Reply
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Check if the user is gone away

Post by Marco Turco »

Hi,
I have a lot of customers that leave my FWH app active and go away. I need a solution to understand if the user is still working otherwise I want to automatically terminate the app.

I think something like a 15 min timer could runs but I need to reset the timer each time the user move the mouse or press a keyboard key.
Any ideas or alternatives ?

Thanks in advance
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
zekasan
Posts: 7
Joined: Fri Feb 22, 2008 12:11 pm

Re: Check if the user is gone away

Post by zekasan »

Code: Select all

*************
FUNCTION Main()
*************
 
   nTempo_espera := 10         //Tempo a ser esperado ate chamar a funcao
 
   cNome_funcao := "LOGOFF()"  //nome da funcao a ser chamada quando
                               //chegar no tempo de espera
 
   lTimercontinua := .f.       //se apos executar a funcao , continua monitorando
                               //a inatividade do mouse e teclado.
 
   define window oWnd title "Teste de teclado e mouse"
 
   activate window oWnd ;
            on init tinativo():new( nTempo_espera,cNome_funcao, lTimerContinua )
 
return NIL
 

function logoff()
 
   msgalert("AQUI ENTRA SUA FUNCAO DE LOGOFF !","AVISO")
 
return nil
 
// Classe: tinativo.prg
 
#include "fivewin.ch"
 
CLASS TINATIVO
 
  DATA nTimeInpAntes
  DATA nTimeInpDepois
  DATA cTimeAtu 
  DATA nTempo
  DATA oTimerTime
  DATA cFunc
  DATA lContinuar
 
  METHOD NEW( nTime, cFuncao, lContinua )  CONSTRUCTOR
 
  METHOD ver_tempo()
 
ENDCLASS
 
**********************
METHOD new(ntime,cFuncao,lContinua) CLASS TINATIVO
**********************
 
   ::cfunc:=cfuncao
   ::ntempo:=ntime
   ::lContinuar:=lContinua
   ::oTimerTime := TTimer():New( 1000, { || ::VER_TEMPO() } )
   ::oTimerTime:Activate()
   ::cTimeAtu := time()
   ::nTimeInpAntes := getInputState()    // 0 = erro
 
return self
 
*************************
METHOD VER_TEMPO CLASS TINATIVO
*************************
 
   ::nTimeInpDepois := getInputState()
 
   if ( ::nTimeInpDepois - ::nTimeInpAntes ) > 0
 
      ::nTimeInpAntes := getInputState()
 
      ::cTimeAtu := time()
 
   endif
 
   if ( CONVTIME(time()) - CONVTIME(::cTimeAtu) ) > ::ntempo
 
      ::oTimerTime:DeActivate()
 
      aux := ::cfunc
   
      * aqui executa a funcao
 
      &aux
 
      if ::lContinuar
 
         ::oTimerTime:Activate()
 
         ::cTimeAtu := time()
 
      endif
 
   endif
 
return NIL
five 12.07/xharbour/xdevstudio
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Check if the user is gone away

Post by ukoenig »

Wanted to test it, but there are two missing functions :

::nTimeInpAntes := getInputState()

IF ( CONVTIME(time() )

possible to include them :?:

Instead of using CONVTIME, I could use my function

Code: Select all


FUNCTION ELAPSED(dStart, dEnd, cTimeStart, cTimeEnd)
LOCAL nTotalSec, nCtr, nConstant, nTemp, aRetVal[4,2]
 
IF ! ( VALTYPE(dStart) $ 'DC' )
    dStart := DATE()
ELSEIF VALTYPE(dStart) == 'C'
    cTimeStart := dStart
    dStart := DATE()
ENDIF
 
IF ! ( VALTYPE(dEnd) $ 'DC' )
    dEnd := DATE()
ELSEIF VALTYPE(dEnd) == 'C'
    cTimeEnd := dEnd
    dEnd := DATE()
ENDIF
 
IF( VALTYPE(cTimeStart) != 'C', cTimeStart := '00:00:00', )
IF( VALTYPE(cTimeEnd)   != 'C', cTimeEnd   := '00:00:00', )
 
nTotalSec  := (dEnd - dStart) * 86400                              + ;
                VAL(cTimeEnd)   *  3600                              + ;
                VAL(SUBSTR(cTimeEnd,AT(':', cTimeEnd)+1,2)) * 60     + ;
                IF(RAT(':', cTimeEnd) == AT(':', cTimeEnd), 0,         ;
                VAL(SUBSTR(cTimeEnd,RAT(':', cTimeEnd)+1)))          - ;
                VAL(cTimeStart) * 3600                               - ;
                VAL(SUBSTR(cTimeStart,AT(':', cTimeStart)+1,2)) * 60 - ;
                IF(RAT(':', cTimeStart) == AT(':', cTimeStart), 0,     ;
                VAL(SUBSTR(cTimeStart,RAT(':', cTimeStart)+1)))
 
nTemp := nTotalSec
 
FOR nCtr = 1 to 4
    nConstant := IF(nCtr == 1, 86400, IF(nCtr == 2, 3600, IF( nCtr == 3, 60, 1)))
    aRetVal[nCtr,1] := INT(nTemp/nConstant)
    aRetval[nCtr,2] := nTotalSec / nConstant
    nTemp -= aRetVal[nCtr,1] * nConstant
NEXT
 
RETURN aRetVal
 
best regards
Uwe :?:
Last edited by ukoenig on Tue Feb 16, 2016 1:48 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Check if the user is gone away

Post by karinha »

João Santos - São Paulo - Brasil
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Check if the user is gone away

Post by ukoenig »

Thank You very much

Tested and works fine !

Maybe my usage gives You a idea to include it inside Your own app ?

I added this solution to my METRO-app section ALARMCLOCK / DateTime -function to define the parameters.
The main-function : a sound is played at a defined date and time. 3 different date/times are possible.
NEW : a defined workingtime < 0 > means the function is disabled.
You can define : closing the app or showing a new LOGIN.


Image

My MAIN-window :
aVal[51] is the time defined inside my alarmclock-function
SHOW_TD(oWnd) opens the alarmclock

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT ( SHOW_TD(oWnd), IIF( aVal[51] > 0, TINATIVO():New( 3, "LOGOFF()", .F. ), NIL ) ) ;
ON CLICK IIF( nRow > ScreenHeight() - 100 .and. nCol > ScreenWidth() - 100, ;
oWnd:End(), ( nBenutzer := USERLOGIN(oWnd), ;
IIF( nBenutzer > 0, ( LOAD_SYS1(nBenutzer), BUILDMETRO(oWnd) ), oWnd:End() ) ) ) ;
ON PAINT ( ABPaint( hDC, ( ScreenWidth() / 2 ) - ( oImgTouch:nWidth / 2 ), ;
( ScreenHeight() / 2 ) - ( oImgTouch:nHeight / 2 ), oImgTouch:hBitmap, 255 ),; // DrawTransparent( hDC, oImgTouch:hBitmap, 250, 500 ),;
ABPaint( hDC, ScreenWidth() - 100, ScreenHeight() - 40,;
oImgEnd:hBitmap, 255 ), ;
oImgEnd:End() )

New LOGIN selected from alarmclock-section after a defined elapsed time :

Image

Code: Select all

FUNCTION LOGOFF()

IF  aVal[52] = 2 // Quit selected
      oWnd:End()
ELSE                // new login selected
   IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
         DBSELECTAREA("SYSTEM")
         LOAD_SYS1(nBenutzer)
         nBenutzer := USERLOGIN(oWnd) // valid = nBenutzer > 0
         IF nBenutzer = 0
              oWnd:End()
         ELSE
              BUILDMETRO(oWnd) 
         ENDIF
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D
Last edited by ukoenig on Wed Feb 17, 2016 11:28 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Check if the user is gone away

Post by ukoenig »

I added a third option to carry on working from
the point, the program has been locked.

Code: Select all

FUNCTION LOGOFF()
LOCAL nOldselect 

IF  aVal[52] = 1
    CLOSE DATABASE
    oWnd:End()
ELSEIF  aVal[52] = 2
    CLOSE DATABASE
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN1(oWnd) 
        IF nBenutzer = 0
            oWnd:End()
        ELSE
            BUILDMETRO(oWnd) 
        ENDIF
    ENDIF
ELSEIF  aVal[52] = 3   // carry on working 
    nOldselect := SELECT()
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN2(oWnd) // small extra login
        DBSELECTAREA( nOldselect )
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D
Last edited by ukoenig on Wed Feb 17, 2016 4:53 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Check if the user is gone away

Post by ukoenig »

I added a third option to carry on working from
the point, the program has been locked.

Image

Code: Select all

FUNCTION LOGOFF()
LOCAL nOldselect 

IF  aVal[52] = 1 // CLOSE
    CLOSE DATABASE
    oWnd:End()
ELSEIF  aVal[52] = 2 // NORMAL LOGIN
    CLOSE DATABASE
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN1(oWnd) 
        IF nBenutzer = 0
            oWnd:End()
        ELSE
            BUILDMETRO(oWnd) 
        ENDIF
    ENDIF
ELSEIF  aVal[52] = 3   // CARRY ON WORKING 
    nOldselect := SELECT()
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN2(oWnd) // small extra login
        DBSELECTAREA( nOldselect )
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Check if the user is gone away

Post by Marco Turco »

Solved, thank you all for the tricks.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Check if the user is gone away

Post by ukoenig »

Marco,
there is a useful solution from Daniel.
Closes the program and starts again for login.

http://forums.fivetechsupport.com/viewt ... ch#p108676

best regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
Post Reply