[nautilus-actions] Add missing files to git repository



commit 9f7091d2dff8f92d2bf8d039a3a20368e7eb3591
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Jan 26 01:33:21 2011 +0100

    Add missing files to git repository
    
    + src/api/na-timeout.h
    + src/core/na-timeout.c

 src/api/na-timeout.h  |   91 +++++++++++++++++++++++++++++++++++++++++++++
 src/core/na-timeout.c |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+), 0 deletions(-)
---
diff --git a/src/api/na-timeout.h b/src/api/na-timeout.h
new file mode 100644
index 0000000..cdb0c4d
--- /dev/null
+++ b/src/api/na-timeout.h
@@ -0,0 +1,91 @@
+/*
+ * Nautilus-Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifndef __NAUTILUS_ACTIONS_API_NA_TIMEOUT_H__
+#define __NAUTILUS_ACTIONS_API_NA_TIMEOUT_H__
+
+/**
+ * SECTION: timeout
+ * @title: NATimeout
+ * @short_description: The NATimeout Structure
+ * @include: nautilus-actions/na-timeout.h
+ *
+ * The NATimeout structure is a convenience structure to manage timeout
+ * functions.
+ *
+ * Since: 3.1.0
+ */
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef void ( *NATimeoutFunc )( void *user_data );
+
+/**
+ * NATimeout:
+ * @timeout:   (i) timeout configurable parameter (ms)
+ * @handler:   (i) handler function
+ * @user_data: (i) user data
+ * @private:   private data
+ *
+ * This structure let the user (i.e. the code which uses it) manage functions
+ * which should only be called after some time of inactivity, which is typically
+ * the case of 'item-change' handlers.
+ *
+ * The structure is supposed to be initialized at construction time with
+ * @timeout in milliseconds, @handler and @user_data input parameters.
+ * The @private pointer identifier must be set to %NULL.
+ *
+ * Such a structure must be allocated for each managed event.
+ *
+ * When an event is detected, the na_timeout_event() function must be called
+ * with this structure. The function makes sure that the @handler callback
+ * will be triggered as soon as no event will be recorded after @timeout
+ * milliseconds of inactivity.
+ *
+ * Since: 3.1.0
+ */
+typedef struct {
+	/*< public >*/
+	guint         timeout;
+	NATimeoutFunc handler;
+	gpointer      user_data;
+	/*< private >*/
+	GTimeVal      last_time;
+	guint         source_id;
+}
+	NATimeout;
+
+void na_timeout_event( NATimeout *timeout );
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_ACTIONS_API_NA_TIMEOUT_H__ */
diff --git a/src/core/na-timeout.c b/src/core/na-timeout.c
new file mode 100644
index 0000000..f3b99f9
--- /dev/null
+++ b/src/core/na-timeout.c
@@ -0,0 +1,98 @@
+/*
+ * Nautilus-Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <api/na-timeout.h>
+
+static gboolean on_timeout_event_timeout( NATimeout *timeout );
+static gulong   time_val_diff( const GTimeVal *recent, const GTimeVal *old );
+
+/**
+ * na_timeout_event:
+ * @timeout: the #NATimeout structure which will handle this event.
+ */
+void
+na_timeout_event( NATimeout *event )
+{
+	g_return_if_fail( event != NULL );
+
+	g_get_current_time( &event->last_time );
+
+	if( !event->source_id ){
+		event->source_id = g_timeout_add( event->timeout, ( GSourceFunc ) on_timeout_event_timeout, event );
+	}
+}
+
+/*
+ * this timer is set when we receive the first event of a serie
+ * we continue to loop until last event is older that our burst timeout
+ */
+static gboolean
+on_timeout_event_timeout( NATimeout *timeout )
+{
+	GTimeVal now;
+	gulong diff;
+	gulong timeout_usec;
+
+	g_get_current_time( &now );
+	diff = time_val_diff( &now, &timeout->last_time );
+	timeout_usec = 1000*timeout->timeout;
+
+	if( diff < timeout_usec ){
+		/* do not stop */
+		return( TRUE );
+	}
+
+	/* last individual notification is older that the 'timeout' parameter
+	 * we may so suppose that the burst is terminated
+	 * and feel authorized to trigger the defined callback
+	 */
+	( *timeout->handler )( timeout->user_data );
+
+	/* at the end of the callback execution, reset the event source id.
+	 * and stop the execution of this one
+	 */
+	timeout->source_id = 0;
+	return( FALSE );
+}
+
+/*
+ * returns the difference in microseconds.
+ */
+static gulong
+time_val_diff( const GTimeVal *recent, const GTimeVal *old )
+{
+	gulong microsec = 1000000 * ( recent->tv_sec - old->tv_sec );
+	microsec += recent->tv_usec  - old->tv_usec;
+	return( microsec );
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]