gio/auto/app_info_monitor.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// `GAppInfoMonitor` monitors application information for changes.
16 ///
17 /// `GAppInfoMonitor` is a very simple object used for monitoring the app
18 /// info database for changes (newly installed or removed applications).
19 ///
20 /// Call [`get()`][Self::get()] to get a `GAppInfoMonitor` and connect
21 /// to the [`changed`][struct@crate::AppInfoMonitor#changed] signal. The signal will be emitted once when
22 /// the app info database changes, and will not be emitted again until after the
23 /// next call to [`AppInfo::all()`][crate::AppInfo::all()] or another `g_app_info_*()` function.
24 /// This is because monitoring the app info database for changes is expensive.
25 ///
26 /// The following functions will re-arm the [`changed`][struct@crate::AppInfoMonitor#changed]
27 /// signal so it can be emitted again:
28 ///
29 /// - [`AppInfo::all()`][crate::AppInfo::all()]
30 /// - [`AppInfo::all_for_type()`][crate::AppInfo::all_for_type()]
31 /// - [`AppInfo::default_for_type()`][crate::AppInfo::default_for_type()]
32 /// - [`AppInfo::fallback_for_type()`][crate::AppInfo::fallback_for_type()]
33 /// - [`AppInfo::recommended_for_type()`][crate::AppInfo::recommended_for_type()]
34 /// - [`g_desktop_app_info_get_implementations()`](../gio-unix/type_func.DesktopAppInfo.get_implementation.html)
35 /// - [`g_desktop_app_info_new()`](../gio-unix/ctor.DesktopAppInfo.new.html)
36 /// - [`g_desktop_app_info_new_from_filename()`](../gio-unix/ctor.DesktopAppInfo.new_from_filename.html)
37 /// - [`g_desktop_app_info_new_from_keyfile()`](../gio-unix/ctor.DesktopAppInfo.new_from_keyfile.html)
38 /// - [`g_desktop_app_info_search()`](../gio-unix/type_func.DesktopAppInfo.search.html)
39 ///
40 /// The latter functions are available if using
41 /// [`GDesktopAppInfo`](../gio-unix/class.DesktopAppInfo.html) from
42 /// `gio-unix-2.0.pc` (GIR namespace `GioUnix-2.0`).
43 ///
44 /// In the usual case, applications should try to make note of the change
45 /// (doing things like invalidating caches) but not act on it. In
46 /// particular, applications should avoid making calls to `GAppInfo` APIs
47 /// in response to the change signal, deferring these until the time that
48 /// the updated data is actually required. The exception to this case is when
49 /// application information is actually being displayed on the screen
50 /// (for example, during a search or when the list of all applications is shown).
51 /// The reason for this is that changes to the list of installed applications
52 /// often come in groups (like during system updates) and rescanning the list
53 /// on every change is pointless and expensive.
54 ///
55 /// ## Signals
56 ///
57 ///
58 /// #### `changed`
59 /// Signal emitted when the app info database changes, when applications are
60 /// installed or removed.
61 ///
62 ///
63 ///
64 /// # Implements
65 ///
66 /// [`trait@glib::ObjectExt`]
67 #[doc(alias = "GAppInfoMonitor")]
68 pub struct AppInfoMonitor(Object<ffi::GAppInfoMonitor>);
69
70 match fn {
71 type_ => || ffi::g_app_info_monitor_get_type(),
72 }
73}
74
75impl AppInfoMonitor {
76 /// Gets the #GAppInfoMonitor for the current thread-default main
77 /// context.
78 ///
79 /// The #GAppInfoMonitor will emit a “changed” signal in the
80 /// thread-default main context whenever the list of installed
81 /// applications (as reported by g_app_info_get_all()) may have changed.
82 ///
83 /// The #GAppInfoMonitor::changed signal will only be emitted once until
84 /// g_app_info_get_all() (or another `g_app_info_*()` function) is called. Doing
85 /// so will re-arm the signal ready to notify about the next change.
86 ///
87 /// You must only call g_object_unref() on the return value from under
88 /// the same main context as you created it.
89 ///
90 /// # Returns
91 ///
92 /// a reference to a #GAppInfoMonitor
93 #[doc(alias = "g_app_info_monitor_get")]
94 pub fn get() -> AppInfoMonitor {
95 unsafe { from_glib_full(ffi::g_app_info_monitor_get()) }
96 }
97
98 /// Signal emitted when the app info database changes, when applications are
99 /// installed or removed.
100 #[doc(alias = "changed")]
101 pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102 unsafe extern "C" fn changed_trampoline<F: Fn(&AppInfoMonitor) + 'static>(
103 this: *mut ffi::GAppInfoMonitor,
104 f: glib::ffi::gpointer,
105 ) {
106 let f: &F = &*(f as *const F);
107 f(&from_glib_borrow(this))
108 }
109 unsafe {
110 let f: Box_<F> = Box_::new(f);
111 connect_raw(
112 self.as_ptr() as *mut _,
113 b"changed\0".as_ptr() as *const _,
114 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
115 changed_trampoline::<F> as *const (),
116 )),
117 Box_::into_raw(f),
118 )
119 }
120 }
121}