Check if the user is gone away

Check if the user is gone away

Postby Marco Turco » Tue Feb 16, 2016 11:22 am

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
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Check if the user is gone away

Postby zekasan » Tue Feb 16, 2016 12:45 pm

Code: Select all  Expand view

*************
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
zekasan
 
Posts: 7
Joined: Fri Feb 22, 2008 12:11 pm

Re: Check if the user is gone away

Postby ukoenig » Tue Feb 16, 2016 1:40 pm

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  Expand view


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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Check if the user is gone away

Postby karinha » Tue Feb 16, 2016 1:46 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Check if the user is gone away

Postby ukoenig » Tue Feb 16, 2016 2:31 pm

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  Expand view

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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Check if the user is gone away

Postby ukoenig » Wed Feb 17, 2016 11:27 am

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


Code: Select all  Expand view

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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Check if the user is gone away

Postby ukoenig » Wed Feb 17, 2016 11:28 am

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

Image

Code: Select all  Expand view

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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Check if the user is gone away

Postby Marco Turco » Wed Feb 17, 2016 4:32 pm

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

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Check if the user is gone away

Postby ukoenig » Wed Feb 17, 2016 7:20 pm

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

viewtopic.php?f=3&t=20477&p=108676&hilit=relaunch#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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 65 guests