glibmm r750 - in trunk: . glib/glibmm



Author: jjongsma
Date: Fri Dec 12 01:09:55 2008
New Revision: 750
URL: http://svn.gnome.org/viewvc/glibmm?rev=750&view=rev

Log:
Add convenience functions for one-shot timer/idle handlers

	* glib/glibmm/main.h:
	* glib/glibmm/main.cc: Added SignalIdle::connect_once,
	SignalTimeout::connect_once, and SignalTimeout::connect_seconds_once.

Modified:
   trunk/ChangeLog
   trunk/glib/glibmm/main.cc
   trunk/glib/glibmm/main.h

Modified: trunk/glib/glibmm/main.cc
==============================================================================
--- trunk/glib/glibmm/main.cc	(original)
+++ trunk/glib/glibmm/main.cc	Fri Dec 12 01:09:55 2008
@@ -310,6 +310,12 @@
   return connection;
 }
 
+void SignalTimeout::connect_once(const sigc::slot<void>& slot, 
+                                 unsigned int interval, int priority)
+{
+    connect(sigc::bind_return(slot, false), interval, priority);
+}
+
 /* Note that this is our equivalent of g_timeout_add_seconds(). */
 sigc::connection SignalTimeout::connect_seconds(const sigc::slot<bool>& slot,
                                         unsigned int interval, int priority)
@@ -333,6 +339,12 @@
   return connection;
 }
 
+void SignalTimeout::connect_seconds_once(const sigc::slot<void>& slot, 
+                                         unsigned int interval, int priority)
+{
+    connect_seconds(sigc::bind_return(slot, false), interval, priority);
+}
+
 SignalTimeout signal_timeout()
 {
   return SignalTimeout(0); // 0 means default context
@@ -368,6 +380,11 @@
   return connection;
 }
 
+void SignalIdle::connect_once(const sigc::slot<void>& slot, int priority)
+{
+    connect(sigc::bind_return(slot, false), priority);
+}
+
 SignalIdle signal_idle()
 {
   return SignalIdle(0); // 0 means default context

Modified: trunk/glib/glibmm/main.h
==============================================================================
--- trunk/glib/glibmm/main.h	(original)
+++ trunk/glib/glibmm/main.h	Fri Dec 12 01:09:55 2008
@@ -160,6 +160,20 @@
   sigc::connection connect(const sigc::slot<bool>& slot, unsigned int interval,
                            int priority = PRIORITY_DEFAULT);
 
+ /** Connects an timeout handler that runs only once.
+  * This method takes a function pointer to a function with a void return
+  * and no parameters. After running once it is not called again.
+  *
+  * @see connect
+  * @param slot A slot to call when @a interval has elapsed. For example:
+  * @code
+  * void on_timeout_once()
+  * @endcode
+  * @param interval The timeout in milliseconds.
+  * @param priority The priority of the new event source. 
+  */
+  void connect_once(const sigc::slot<void>& slot, unsigned int interval,
+                    int priority = PRIORITY_DEFAULT);
 
   /** Connects a timeout handler with whole second granularity.
    *
@@ -191,6 +205,23 @@
   sigc::connection connect_seconds(const sigc::slot<bool>& slot, unsigned int interval,
                            int priority = PRIORITY_DEFAULT);
 
+ /** Connects an timeout handler that runs only once with whole second
+  *  granularity.
+  *
+  * This method takes a function pointer to a function with a void return
+  * and no parameters. After running once it is not called again.
+  *
+  * @see connect_seconds
+  * @param slot A slot to call when @a interval has elapsed. For example:
+  * @code
+  * void on_timeout_once()
+  * @endcode
+  * @param interval The timeout in milliseconds.
+  * @param priority The priority of the new event source. 
+  */
+  void connect_seconds_once(const sigc::slot<void>& slot, unsigned int interval,
+                            int priority = PRIORITY_DEFAULT);
+
 private:
   GMainContext* context_;
 
@@ -222,6 +253,12 @@
    */
   sigc::connection connect(const sigc::slot<bool>& slot, int priority = PRIORITY_DEFAULT_IDLE);
 
+ /** Connects an idle handler that runs only once.
+  * This method takes a function pointer to a function with a void return
+  * and no parameters. After running once it is not called again.
+  */
+  void connect_once(const sigc::slot<void>& slot, int priority = PRIORITY_DEFAULT_IDLE);
+
 private:
   GMainContext* context_;
 



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