Skip to main content

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    ///  - [`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    ///  signal in the
77    /// thread-default main context whenever the list of installed
78    /// applications (as reported by g_app_info_get_all()) may have changed.
79    ///
80    /// The #GAppInfoMonitor::changed signal will only be emitted once until
81    /// g_app_info_get_all() (or another `g_app_info_*()` function) is called. Doing
82    /// so will re-arm the signal ready to notify about the next change.
83    ///
84    /// You must only call g_object_unref() on the return value from under
85    /// the same main context as you created it.
86    ///
87    /// # Returns
88    ///
89    /// a reference to a #GAppInfoMonitor
90    #[doc(alias = "g_app_info_monitor_get")]
91    pub fn get() -> AppInfoMonitor {
92        unsafe { from_glib_full(ffi::g_app_info_monitor_get()) }
93    }
94
95    /// Signal emitted when the app info database changes, when applications are
96    /// installed or removed.
97    #[doc(alias = "changed")]
98    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
99        unsafe extern "C" fn changed_trampoline<F: Fn(&AppInfoMonitor) + 'static>(
100            this: *mut ffi::GAppInfoMonitor,
101            f: glib::ffi::gpointer,
102        ) {
103            unsafe {
104                let f: &F = &*(f as *const F);
105                f(&from_glib_borrow(this))
106            }
107        }
108        unsafe {
109            let f: Box_<F> = Box_::new(f);
110            connect_raw(
111                self.as_ptr() as *mut _,
112                c"changed".as_ptr(),
113                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
114                    changed_trampoline::<F> as *const (),
115                )),
116                Box_::into_raw(f),
117            )
118        }
119    }
120}