Define new 'pivot-prop-loadable' property
[nautilus-actions.git] / src / core / na-timeout.c
blobf3b99f96c6c465ea936a883020d5aa658e4b5093
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <api/na-timeout.h>
37 static gboolean on_timeout_event_timeout( NATimeout *timeout );
38 static gulong time_val_diff( const GTimeVal *recent, const GTimeVal *old );
40 /**
41 * na_timeout_event:
42 * @timeout: the #NATimeout structure which will handle this event.
44 void
45 na_timeout_event( NATimeout *event )
47 g_return_if_fail( event != NULL );
49 g_get_current_time( &event->last_time );
51 if( !event->source_id ){
52 event->source_id = g_timeout_add( event->timeout, ( GSourceFunc ) on_timeout_event_timeout, event );
57 * this timer is set when we receive the first event of a serie
58 * we continue to loop until last event is older that our burst timeout
60 static gboolean
61 on_timeout_event_timeout( NATimeout *timeout )
63 GTimeVal now;
64 gulong diff;
65 gulong timeout_usec;
67 g_get_current_time( &now );
68 diff = time_val_diff( &now, &timeout->last_time );
69 timeout_usec = 1000*timeout->timeout;
71 if( diff < timeout_usec ){
72 /* do not stop */
73 return( TRUE );
76 /* last individual notification is older that the 'timeout' parameter
77 * we may so suppose that the burst is terminated
78 * and feel authorized to trigger the defined callback
80 ( *timeout->handler )( timeout->user_data );
82 /* at the end of the callback execution, reset the event source id.
83 * and stop the execution of this one
85 timeout->source_id = 0;
86 return( FALSE );
90 * returns the difference in microseconds.
92 static gulong
93 time_val_diff( const GTimeVal *recent, const GTimeVal *old )
95 gulong microsec = 1000000 * ( recent->tv_sec - old->tv_sec );
96 microsec += recent->tv_usec - old->tv_usec;
97 return( microsec );