Add example for 'change-state' signal
authorRyan Lortie <desrt@desrt.ca>
Wed, 29 Jun 2011 13:53:24 +0000 (14:53 +0100)
committerJavier Jardon <jjardon@gnome.org>
Wed, 29 Jun 2011 15:20:52 +0000 (16:20 +0100)
Pulled from the testcase.

gio/gsimpleaction.c

index 0f26c0f74a6065cf6d29f30df462f24b0540c71b..bf8dd7373db65543c5e0dc5eb1647429859de4c7 100644 (file)
@@ -351,6 +351,28 @@ g_simple_action_class_init (GSimpleActionClass *class)
    * default action is taken.  If the state should change then you must
    * call g_simple_action_set_state() from the handler.
    *
+   * <example>
+   * <title>Example 'change-state' handler</title>
+   * <programlisting>
+   * static void
+   * change_volume_state (GSimpleAction *action,
+   *                      GVariant      *value,
+   *                      gpointer       user_data)
+   * {
+   *   gint requested;
+   *
+   *   requested = g_variant_get_int32 (value);
+   *
+   *   // Volume only goes from 0 to 10
+   *   if (0 <= requested && requested <= 10)
+   *     g_simple_action_set_state (action, value);
+   * }
+   * </programlisting>
+   * </example>
+   *
+   * The handler need not set the state to the requested value.  It
+   * could set it to any value at all, or take some other action.
+   *
    * Since: 2.30
    */
   g_simple_action_signals[SIGNAL_CHANGE_STATE] =