+static void
+g_app_info_monitor_init (GAppInfoMonitor *monitor)
+{
+}
+
+static void
+g_app_info_monitor_class_init (GAppInfoMonitorClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ g_app_info_monitor_changed_signal = g_signal_new ("changed", G_TYPE_APP_INFO_MONITOR, G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ object_class->finalize = g_app_info_monitor_finalize;
+}
+
+/**
+ * g_app_info_monitor_get:
+ *
+ * Gets the #GAppInfoMonitor for the current thread-default main
+ * context.
+ *
+ * The #GAppInfoMonitor will emit a "changed" signal in the
+ * thread-default main context whenever the list of installed
+ * applications (as reported by g_app_info_get_all()) may have changed.
+ *
+ * You must only call g_object_unref() on the return value from under
+ * the same main context as you created it.
+ *
+ * Returns: (transfer full): a reference to a #GAppInfoMonitor
+ *
+ * Since: 2.40
+ **/
+GAppInfoMonitor *
+g_app_info_monitor_get (void)
+{
+ GAppInfoMonitor *monitor;
+ GMainContext *context;
+
+ context = g_main_context_get_thread_default ();
+ if (!context)
+ context = g_main_context_default ();
+
+ g_return_val_if_fail (g_main_context_acquire (context), NULL);
+
+ g_mutex_lock (&g_app_info_monitor_lock);
+ if (!g_app_info_monitors)
+ g_app_info_monitors = g_hash_table_new (NULL, NULL);
+
+ monitor = g_hash_table_lookup (g_app_info_monitors, context);
+ g_mutex_unlock (&g_app_info_monitor_lock);
+
+ if (!monitor)
+ {
+ monitor = g_object_new (G_TYPE_APP_INFO_MONITOR, NULL);
+ monitor->context = g_main_context_ref (context);
+
+ g_mutex_lock (&g_app_info_monitor_lock);
+ g_hash_table_insert (g_app_info_monitors, context, monitor);
+ g_mutex_unlock (&g_app_info_monitor_lock);
+ }
+ else
+ g_object_ref (monitor);
+
+ g_main_context_release (context);
+
+ return monitor;
+}
+
+static gboolean
+g_app_info_monitor_emit (gpointer user_data)
+{
+ GMainContext *context = user_data;
+ GAppInfoMonitor *monitor;
+
+ g_mutex_lock (&g_app_info_monitor_lock);
+ monitor = g_hash_table_lookup (g_app_info_monitors, context);
+ g_mutex_unlock (&g_app_info_monitor_lock);
+
+ /* It is possible that the monitor was already destroyed by the time
+ * we get here, so make sure it's not NULL.
+ */
+ if (monitor != NULL)
+ {
+ /* We don't have to worry about another thread disposing the
+ * monitor but we do have to worry about the possibility that one
+ * of the attached handlers may do so.
+ *
+ * Take a ref so that the monitor doesn't disappear in the middle
+ * of the emission.
+ */
+ g_object_ref (monitor);
+ g_signal_emit (monitor, g_app_info_monitor_changed_signal, 0);
+ g_object_unref (monitor);
+ }
+
+ return FALSE;
+}
+
+void
+g_app_info_monitor_fire (void)
+{
+ GHashTableIter iter;
+ gpointer context;
+
+ g_mutex_lock (&g_app_info_monitor_lock);
+
+ if (g_app_info_monitors)
+ {
+ g_hash_table_iter_init (&iter, g_app_info_monitors);
+ while (g_hash_table_iter_next (&iter, &context, NULL))
+ {
+ GSource *idle;
+
+ idle = g_idle_source_new ();
+ g_source_set_callback (idle, g_app_info_monitor_emit, context, NULL);
+ g_source_set_name (idle, "[gio] g_app_info_monitor_emit");
+ g_source_attach (idle, context);
+ g_source_unref (idle);
+ }
+ }
+
+ g_mutex_unlock (&g_app_info_monitor_lock);
+}