Skip to main content

gtk4/auto/
app_chooser_dialog.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#![allow(deprecated)]
5
6#[cfg(feature = "v4_10")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
8use crate::Accessible;
9use crate::{
10    AppChooser, Buildable, ConstraintTarget, Dialog, DialogFlags, Native, Root, ShortcutManager,
11    Widget, Window, ffi,
12};
13use glib::{
14    prelude::*,
15    signal::{SignalHandlerId, connect_raw},
16    translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23    #[doc(alias = "GtkAppChooserDialog")]
24    pub struct AppChooserDialog(Object<ffi::GtkAppChooserDialog>) @extends Dialog, Window, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager, AppChooser;
25
26    match fn {
27        type_ => || ffi::gtk_app_chooser_dialog_get_type(),
28    }
29}
30
31#[cfg(not(feature = "v4_10"))]
32glib::wrapper! {
33    #[doc(alias = "GtkAppChooserDialog")]
34    pub struct AppChooserDialog(Object<ffi::GtkAppChooserDialog>) @extends Dialog, Window, Widget, @implements Buildable, ConstraintTarget, Native, Root, ShortcutManager, AppChooser;
35
36    match fn {
37        type_ => || ffi::gtk_app_chooser_dialog_get_type(),
38    }
39}
40
41impl AppChooserDialog {
42    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
43    #[allow(deprecated)]
44    #[doc(alias = "gtk_app_chooser_dialog_new")]
45    pub fn new(
46        parent: Option<&impl IsA<Window>>,
47        flags: DialogFlags,
48        file: &impl IsA<gio::File>,
49    ) -> AppChooserDialog {
50        assert_initialized_main_thread!();
51        unsafe {
52            Widget::from_glib_none(ffi::gtk_app_chooser_dialog_new(
53                parent.map(|p| p.as_ref()).to_glib_none().0,
54                flags.into_glib(),
55                file.as_ref().to_glib_none().0,
56            ))
57            .unsafe_cast()
58        }
59    }
60
61    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
62    #[allow(deprecated)]
63    #[doc(alias = "gtk_app_chooser_dialog_new_for_content_type")]
64    #[doc(alias = "new_for_content_type")]
65    pub fn for_content_type(
66        parent: Option<&impl IsA<Window>>,
67        flags: DialogFlags,
68        content_type: &str,
69    ) -> AppChooserDialog {
70        assert_initialized_main_thread!();
71        unsafe {
72            Widget::from_glib_none(ffi::gtk_app_chooser_dialog_new_for_content_type(
73                parent.map(|p| p.as_ref()).to_glib_none().0,
74                flags.into_glib(),
75                content_type.to_glib_none().0,
76            ))
77            .unsafe_cast()
78        }
79    }
80
81    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
82    #[allow(deprecated)]
83    #[doc(alias = "gtk_app_chooser_dialog_get_heading")]
84    #[doc(alias = "get_heading")]
85    pub fn heading(&self) -> Option<glib::GString> {
86        unsafe {
87            from_glib_none(ffi::gtk_app_chooser_dialog_get_heading(
88                self.to_glib_none().0,
89            ))
90        }
91    }
92
93    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
94    #[allow(deprecated)]
95    #[doc(alias = "gtk_app_chooser_dialog_get_widget")]
96    #[doc(alias = "get_widget")]
97    pub fn widget(&self) -> Widget {
98        unsafe {
99            from_glib_none(ffi::gtk_app_chooser_dialog_get_widget(
100                self.to_glib_none().0,
101            ))
102        }
103    }
104
105    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
106    #[allow(deprecated)]
107    #[doc(alias = "gtk_app_chooser_dialog_set_heading")]
108    #[doc(alias = "heading")]
109    pub fn set_heading(&self, heading: &str) {
110        unsafe {
111            ffi::gtk_app_chooser_dialog_set_heading(
112                self.to_glib_none().0,
113                heading.to_glib_none().0,
114            );
115        }
116    }
117
118    pub fn gfile(&self) -> Option<gio::File> {
119        ObjectExt::property(self, "gfile")
120    }
121
122    #[doc(alias = "heading")]
123    pub fn connect_heading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
124        unsafe extern "C" fn notify_heading_trampoline<F: Fn(&AppChooserDialog) + 'static>(
125            this: *mut ffi::GtkAppChooserDialog,
126            _param_spec: glib::ffi::gpointer,
127            f: glib::ffi::gpointer,
128        ) {
129            unsafe {
130                let f: &F = &*(f as *const F);
131                f(&from_glib_borrow(this))
132            }
133        }
134        unsafe {
135            let f: Box_<F> = Box_::new(f);
136            connect_raw(
137                self.as_ptr() as *mut _,
138                c"notify::heading".as_ptr(),
139                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
140                    notify_heading_trampoline::<F> as *const (),
141                )),
142                Box_::into_raw(f),
143            )
144        }
145    }
146}