~ubuntu-branches/ubuntu/vivid/glib2.0/vivid-proposed

« back to all changes in this revision

Viewing changes to gio/gapplication.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2015-03-03 17:36:38 UTC
  • mfrom: (207.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20150303173638-plazvisc6kzfsve3
Tags: 2.43.91-1
* New upstream release 2.43.91
  - We have now added 'g_autofree' as a libgsystem-style autocleanup macro
    that calls g_free() on the content of a local variable when it leaves
    scope (working only on GCC and clang).
  - GApplication now has an "is-busy" property, allowing one to query the
    effective busy state.
* debian/libglib2.0-0.symbols: Add new symbols for this release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
263
263
  PROP_IS_REGISTERED,
264
264
  PROP_IS_REMOTE,
265
265
  PROP_INACTIVITY_TIMEOUT,
266
 
  PROP_ACTION_GROUP
 
266
  PROP_ACTION_GROUP,
 
267
  PROP_IS_BUSY
267
268
};
268
269
 
269
270
enum
1180
1181
                        g_application_get_inactivity_timeout (application));
1181
1182
      break;
1182
1183
 
 
1184
    case PROP_IS_BUSY:
 
1185
      g_value_set_boolean (value, g_application_get_is_busy (application));
 
1186
      break;
 
1187
 
1183
1188
    default:
1184
1189
      g_assert_not_reached ();
1185
1190
    }
1213
1218
{
1214
1219
  GApplication *application = G_APPLICATION (object);
1215
1220
 
1216
 
  g_slist_free_full (application->priv->option_groups, (GDestroyNotify) g_option_group_free);
 
1221
  g_slist_free_full (application->priv->option_groups, (GDestroyNotify) g_option_group_unref);
1217
1222
  if (application->priv->main_options)
1218
 
    g_option_group_free (application->priv->main_options);
 
1223
    g_option_group_unref (application->priv->main_options);
1219
1224
  if (application->priv->packed_options)
1220
1225
    {
1221
1226
      g_slist_free_full (application->priv->option_strings, g_free);
1344
1349
                         G_PARAM_DEPRECATED | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
1345
1350
 
1346
1351
  /**
 
1352
   * GApplication:is-busy:
 
1353
   *
 
1354
   * Whether the application is currently marked as busy through
 
1355
   * g_application_mark_busy() or g_application_bind_busy_property().
 
1356
   *
 
1357
   * Since: 2.44
 
1358
   */
 
1359
  g_object_class_install_property (object_class, PROP_IS_BUSY,
 
1360
    g_param_spec_boolean ("is-busy",
 
1361
                          P_("Is busy"),
 
1362
                          P_("If this application is currently marked busy"),
 
1363
                          FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
1364
 
 
1365
  /**
1347
1366
   * GApplication::startup:
1348
1367
   * @application: the application
1349
1368
   *
2305
2324
 
2306
2325
  g_settings_sync ();
2307
2326
 
 
2327
  if (!application->priv->must_quit_now)
 
2328
    while (g_main_context_iteration (NULL, FALSE))
 
2329
      ;
 
2330
 
2308
2331
  return status;
2309
2332
}
2310
2333
 
2544
2567
  application->priv->busy_count++;
2545
2568
 
2546
2569
  if (!was_busy)
2547
 
    g_application_impl_set_busy_state (application->priv->impl, TRUE);
 
2570
    {
 
2571
      g_application_impl_set_busy_state (application->priv->impl, TRUE);
 
2572
      g_object_notify (G_OBJECT (application), "is-busy");
 
2573
    }
2548
2574
}
2549
2575
 
2550
2576
/**
2570
2596
  application->priv->busy_count--;
2571
2597
 
2572
2598
  if (application->priv->busy_count == 0)
2573
 
    g_application_impl_set_busy_state (application->priv->impl, FALSE);
 
2599
    {
 
2600
      g_application_impl_set_busy_state (application->priv->impl, FALSE);
 
2601
      g_object_notify (G_OBJECT (application), "is-busy");
 
2602
    }
 
2603
}
 
2604
 
 
2605
/**
 
2606
 * g_application_get_is_busy:
 
2607
 * @application: a #GApplication
 
2608
 *
 
2609
 * Gets the application's current busy state, as set through
 
2610
 * g_application_mark_busy() or g_application_bind_busy_property().
 
2611
 *
 
2612
 * Returns: %TRUE if @application is currenty marked as busy
 
2613
 *
 
2614
 * Since: 2.44
 
2615
 */
 
2616
gboolean
 
2617
g_application_get_is_busy (GApplication *application)
 
2618
{
 
2619
  g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
 
2620
 
 
2621
  return application->priv->busy_count > 0;
2574
2622
}
2575
2623
 
2576
2624
/* Notifications {{{1 */
2710
2758
/**
2711
2759
 * g_application_bind_busy_property:
2712
2760
 * @application: a #GApplication
2713
 
 * @object: a #GObject
2714
 
 * @property: (allow-none): the name of a boolean property of @object
 
2761
 * @object: (type GObject.Object): a #GObject
 
2762
 * @property: the name of a boolean property of @object
2715
2763
 *
2716
2764
 * Marks @application as busy (see g_application_mark_busy()) while
2717
2765
 * @property on @object is %TRUE.
2718
2766
 *
2719
 
 * Multiple such bindings can exist, but only one property can be bound
2720
 
 * per object. Calling this function again for the same object replaces
2721
 
 * a previous binding. If @property is %NULL, the binding is destroyed.
2722
 
 *
2723
2767
 * The binding holds a reference to @application while it is active, but
2724
2768
 * not to @object. Instead, the binding is destroyed when @object is
2725
2769
 * finalized.
2731
2775
                                  gpointer      object,
2732
2776
                                  const gchar  *property)
2733
2777
{
2734
 
  GClosure *closure = NULL;
2735
 
  guint notify_id;
 
2778
  guint notify_id;
 
2779
  GQuark property_quark;
 
2780
  GParamSpec *pspec;
 
2781
  GApplicationBusyBinding *binding;
 
2782
  GClosure *closure;
 
2783
 
 
2784
  g_return_if_fail (G_IS_APPLICATION (application));
 
2785
  g_return_if_fail (G_IS_OBJECT (object));
 
2786
  g_return_if_fail (property != NULL);
 
2787
 
 
2788
  notify_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
 
2789
  property_quark = g_quark_from_string (property);
 
2790
  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
 
2791
 
 
2792
  g_return_if_fail (pspec != NULL && pspec->value_type == G_TYPE_BOOLEAN);
 
2793
 
 
2794
  if (g_signal_handler_find (object, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC,
 
2795
                             notify_id, property_quark, NULL, g_application_notify_busy_binding, NULL) > 0)
 
2796
    {
 
2797
      g_critical ("%s: '%s' is already bound to the busy state of the application", G_STRFUNC, property);
 
2798
      return;
 
2799
    }
 
2800
 
 
2801
  binding = g_slice_new (GApplicationBusyBinding);
 
2802
  binding->app = g_object_ref (application);
 
2803
  binding->is_busy = FALSE;
 
2804
 
 
2805
  closure = g_cclosure_new (G_CALLBACK (g_application_notify_busy_binding), binding,
 
2806
                            g_application_busy_binding_destroy);
 
2807
  g_signal_connect_closure_by_id (object, notify_id, property_quark, closure, FALSE);
 
2808
 
 
2809
  /* fetch the initial value */
 
2810
  g_application_notify_busy_binding (object, pspec, binding);
 
2811
}
 
2812
 
 
2813
/**
 
2814
 * g_application_unbind_busy_property:
 
2815
 * @application: a #GApplication
 
2816
 * @object: (type GObject.Object): a #GObject
 
2817
 * @property: the name of a boolean property of @object
 
2818
 *
 
2819
 * Destroys a binding between @property and the busy state of
 
2820
 * @application that was previously created with
 
2821
 * g_application_bind_busy_property().
 
2822
 *
 
2823
 * Since: 2.44
 
2824
 */
 
2825
void
 
2826
g_application_unbind_busy_property (GApplication *application,
 
2827
                                    gpointer      object,
 
2828
                                    const gchar  *property)
 
2829
{
 
2830
  guint notify_id;
 
2831
  GQuark property_quark;
2736
2832
  gulong handler_id;
2737
2833
 
2738
2834
  g_return_if_fail (G_IS_APPLICATION (application));
2739
2835
  g_return_if_fail (G_IS_OBJECT (object));
 
2836
  g_return_if_fail (property != NULL);
2740
2837
 
2741
2838
  notify_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
 
2839
  property_quark = g_quark_from_string (property);
2742
2840
 
2743
 
  if (property != NULL)
 
2841
  handler_id = g_signal_handler_find (object, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC,
 
2842
                                      notify_id, property_quark, NULL, g_application_notify_busy_binding, NULL);
 
2843
  if (handler_id == 0)
2744
2844
    {
2745
 
      GParamSpec *pspec;
2746
 
      GApplicationBusyBinding *binding;
2747
 
 
2748
 
      pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
2749
 
      g_return_if_fail (pspec != NULL && pspec->value_type == G_TYPE_BOOLEAN);
2750
 
 
2751
 
      binding = g_slice_new (GApplicationBusyBinding);
2752
 
      binding->app = g_object_ref (application);
2753
 
      binding->is_busy = FALSE;
2754
 
 
2755
 
      /* fetch the initial value */
2756
 
      g_application_notify_busy_binding (object, pspec, binding);
2757
 
 
2758
 
      closure = g_cclosure_new (G_CALLBACK (g_application_notify_busy_binding), binding,
2759
 
                                g_application_busy_binding_destroy);
 
2845
      g_critical ("%s: '%s' is not bound to the busy state of the application", G_STRFUNC, property);
 
2846
      return;
2760
2847
    }
2761
2848
 
2762
 
  /* unset a previous binding after fetching the new initial value, so
2763
 
   * that we don't switch to FALSE for a brief moment when both the
2764
 
   * old and the new property are set to TRUE
2765
 
   */
2766
 
  handler_id = g_signal_handler_find (object, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC, notify_id,
2767
 
                                      0, NULL, g_application_notify_busy_binding, NULL);
2768
 
  if (handler_id > 0)
2769
 
    g_signal_handler_disconnect (object, handler_id);
2770
 
 
2771
 
  if (closure)
2772
 
    g_signal_connect_closure_by_id (object, notify_id, g_quark_from_string (property), closure, FALSE);
 
2849
  g_signal_handler_disconnect (object, handler_id);
2773
2850
}
2774
2851
 
2775
2852
/* Epilogue {{{1 */