Checking last activity timestamp
Previous topic  First topic  Next topic


In same cases, we need to check the last timestamp of activity of own application.

The best known example of use is the save screen feature.

In a Marinas-GUI application there are two last activity timestamp:

- Last activity timestamp of "ALL" events:

include:
mg_set and mg_do activity will reset "ALL" activity timestamp
ONGOTFOCUS, ONLOSTFOCUS, ONMOVE and ONPAINT windows events will reset "ALL" activity timestamp

exclude:
mg_get activity will not reset "ALL" activity timestamp

- Last activity timestamp of "USER" events:

include:
mg_set and mg_do activity will reset "USER" activity timestamp

exclude:
mg_get activity will not reset "USER" activity timestamp
ONGOTFOCUS, ONLOSTFOCUS, ONMOVE and ONPAINT windows events will not reset "USER" activity timestamp


Note: when you switch between a window and other into your desktop, window events like ONPAINT are fired and reset the "last ALL activity timestamp", but not reset the "last USER activity timestamp"


The activity timestamp is in this format:
YYYYMMDDHHMMSScc

You can check the last timestamp by using the following functions:

cLastAllActivityTimestamp := mg_getLastAllActivityTimestamp()
or
cLastUserActivityTimestamp := mg_getLastUserActivityTimestamp()

You can reset the last timestamp with:

mg_resetLastAllActivityTimestamp()
or
mg_resetLastUserActivityTimestamp()

You can suspend the reset activity timestamp by coding:

mg_setSuspendAllActivityTimestamp( .T. | .F. )
or
mg_setSuspendUserActivityTimestamp( .T. | .F. )

and check those states with:

lSuspend := mg_getSuspendAllActivityTimestamp()
or
lSuspend := mg_getSuspendUserActivityTimestamp()

If you neet to see witch user activity are reseting the last user activity, you can activate the log trace to see activity:

mg_setLogUserActivityTimestamp( .T. | .F. )

and you can check the log state with:

lLogUserActivated := mg_getLogUserActivityTimestamp()

in addition, you can log all activity by using:

mg_setLogAllActivityTimestamp( .T. | .F. )

and check log state with:

lLogAllActivated := mg_getLogAllActivityTimestamp()

Warning: mg_setLogAllActivityTimestamp() and mg_setLogUserActivityTimestamp() will produce a loss of performance because its writes activity in the application LOG file.
Remember, the application log file has the same name that application executable but with ".log" as extension file name


Checking activity


You can check the elapsed time from last activity by using a TIMER control and same functions.

e.g.:


CREATE WINDOW myWin
   MAIN .T.
   ...
   ...
   CREATE TIMER timer_1
      INTERVAL 1000 // 1 second
      ACTION myCheckActivity()
      ENABLED .T. // like "START" method
   END TIMER
   ...
   ...
END WINDOW

   ...

FUNCTION myCheckActivity()
   IF mg_timestampElapsedSec( mg_getLastUserActivityTimestamp() , mg_dateTimeCen() ) > 30 // seconds
      mg_do( "d_window" , "timer_1" , "stop" )
      ...
      ...
      >>> put here your code!!!
      ...
      ...
      mg_resetLastUserActivityTimestamp()
      mg_do( "d_window" , "timer_1" , "start" )
   ENDIF
RETURN NIL


Note: mg_dateTimeCen() returns the current timestamp in this form: YYYYMMDDHHMMSScc
and
mg_timestampElapsedSec( cOldTimestamp , cNewTimestamp ) returns the difference between two timestamp in seconds



Marinas-GUI Version 03.06 and
Marinas-IDE Version 05.06 and
LEX Files Version 02.06


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
last update: March 09
2017
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




A Harbour/QT framework to make multiplatform programs

(©) Copyright 2009-2017 by Fernando Santolin (aka CarozoDeQuilmes)
CarozoDeQuilmes@gmail.com

2009-2017 Beta tester and full English translator: Bruno Luciani
Bruno.Luciani@gmail.com

2014-2015 Final English corrector: David Worboys
DavidWorboys@hotmail.com

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Jump to Donation Topic


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

www.marinas-gui.org


www.marinas-gui.org  

Previous topic  First topic  Next topic