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::{SignalHandlerId, connect_raw},
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 ///
35 /// The following functions will re-arm the [`changed`][struct@crate::AppInfoMonitor#changed]
36 /// signal if using [`GDesktopAppInfo`](../gio-unix/class.DesktopAppInfo.html)
37 /// from `gio-unix-2.0.pc` (GIR namespace `GioUnix-2.0`):
38 /// - [`AppInfoExt::launch_uris()`][crate::prelude::AppInfoExt::launch_uris()]
39 /// - [`AppInfoExtManual::launch_uris_async()`][crate::prelude::AppInfoExtManual::launch_uris_async()]
40 /// - [`g_desktop_app_info_launch_uris_as_manager_with_fds()`](../gio-unix/type_func.DesktopAppInfo.g_desktop_app_info_launch_uris_as_manager_with_fds.html)
41 /// - [`g_desktop_app_info_get_for_intent()`](../gio-unix/type_func.DesktopAppInfo.get_for_intent.html)
42 /// - [`g_desktop_app_info_get_default_for_intent()`](../gio-unix/type_func.DesktopAppInfo.get_default_for_intent.html)
43 ///
44 /// - [`g_desktop_app_info_new()`](../gio-unix/ctor.DesktopAppInfo.new.html)
45 /// - [`g_desktop_app_info_new_from_filename()`](../gio-unix/ctor.DesktopAppInfo.new_from_filename.html)
46 /// - [`g_desktop_app_info_new_from_keyfile()`](../gio-unix/ctor.DesktopAppInfo.new_from_keyfile.html)
47 /// - [`g_desktop_app_info_search()`](../gio-unix/type_func.DesktopAppInfo.search.html)
48 ///
49 /// In the usual case, applications should try to make note of the change
50 /// (doing things like invalidating caches) but not act on it. In
51 /// particular, applications should avoid making calls to `GAppInfo` APIs
52 /// in response to the change signal, deferring these until the time that
53 /// the updated data is actually required. The exception to this case is when
54 /// application information is actually being displayed on the screen
55 /// (for example, during a search or when the list of all applications is shown).
56 /// The reason for this is that changes to the list of installed applications
57 /// often come in groups (like during system updates) and rescanning the list
58 /// on every change is pointless and expensive.
59 ///
60 /// ## Signals
61 ///
62 ///
63 /// #### `changed`
64 /// Signal emitted when the app info database changes, when applications are
65 /// installed or removed.
66 ///
67 ///
68 ///
69 /// # Implements
70 ///
71 /// [`trait@glib::ObjectExt`]
72 #[doc(alias = "GAppInfoMonitor")]
73 pub struct AppInfoMonitor(Object<ffi::GAppInfoMonitor>);
74
75 match fn {
76 type_ => || ffi::g_app_info_monitor_get_type(),
77 }
78}
79
80impl AppInfoMonitor {
81 /// Gets the #GAppInfoMonitor for the current thread-default main
82 /// context.
83 ///
84 /// The #GAppInfoMonitor will emit a “changed” signal in the
85 /// thread-default main context whenever the list of installed
86 /// applications (as reported by g_app_info_get_all()) may have changed.
87 ///
88 /// The #GAppInfoMonitor::changed signal will only be emitted once until
89 /// g_app_info_get_all() (or another `g_app_info_*()` function) is called. Doing
90 /// so will re-arm the signal ready to notify about the next change.
91 ///
92 /// You must only call g_object_unref() on the return value from under
93 /// the same main context as you created it.
94 ///
95 /// # Returns
96 ///
97 /// a reference to a #GAppInfoMonitor
98 #[doc(alias = "g_app_info_monitor_get")]
99 pub fn get() -> AppInfoMonitor {
100 unsafe { from_glib_full(ffi::g_app_info_monitor_get()) }
101 }
102
103 /// Signal emitted when the app info database changes, when applications are
104 /// installed or removed.
105 #[doc(alias = "changed")]
106 pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
107 unsafe extern "C" fn changed_trampoline<F: Fn(&AppInfoMonitor) + 'static>(
108 this: *mut ffi::GAppInfoMonitor,
109 f: glib::ffi::gpointer,
110 ) {
111 unsafe {
112 let f: &F = &*(f as *const F);
113 f(&from_glib_borrow(this))
114 }
115 }
116 unsafe {
117 let f: Box_<F> = Box_::new(f);
118 connect_raw(
119 self.as_ptr() as *mut _,
120 c"changed".as_ptr(),
121 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122 changed_trampoline::<F> as *const (),
123 )),
124 Box_::into_raw(f),
125 )
126 }
127 }
128}