webkit2gtk/auto/
uri_request.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.git)
3// DO NOT EDIT
4
5use glib::object::Cast;
6use glib::object::IsA;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib::StaticType;
11use glib::ToValue;
12use std::boxed::Box as Box_;
13use std::fmt;
14use std::mem::transmute;
15
16glib::wrapper! {
17    #[doc(alias = "WebKitURIRequest")]
18    pub struct URIRequest(Object<ffi::WebKitURIRequest, ffi::WebKitURIRequestClass>);
19
20    match fn {
21        type_ => || ffi::webkit_uri_request_get_type(),
22    }
23}
24
25impl URIRequest {
26    #[doc(alias = "webkit_uri_request_new")]
27    pub fn new(uri: &str) -> URIRequest {
28        assert_initialized_main_thread!();
29        unsafe {
30            from_glib_full(ffi::webkit_uri_request_new(uri.to_glib_none().0))
31        }
32    }
33
34            // rustdoc-stripper-ignore-next
35            /// Creates a new builder-pattern struct instance to construct [`URIRequest`] objects.
36            ///
37            /// This method returns an instance of [`URIRequestBuilder`] which can be used to create [`URIRequest`] objects.
38            pub fn builder() -> URIRequestBuilder {
39                URIRequestBuilder::default()
40            }
41        
42}
43
44#[derive(Clone, Default)]
45// rustdoc-stripper-ignore-next
46        /// A [builder-pattern] type to construct [`URIRequest`] objects.
47        ///
48        /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
49pub struct URIRequestBuilder {
50    uri: Option<String>,
51}
52
53impl URIRequestBuilder {
54    // rustdoc-stripper-ignore-next
55    /// Create a new [`URIRequestBuilder`].
56    pub fn new() -> Self {
57        Self::default()
58    }
59
60
61    // rustdoc-stripper-ignore-next
62    /// Build the [`URIRequest`].
63    pub fn build(self) -> URIRequest {
64        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
65if let Some(ref uri) = self.uri {
66                properties.push(("uri", uri));
67            }
68        glib::Object::new::<URIRequest>(&properties)
69                .expect("Failed to create an instance of URIRequest")
70
71    }
72
73    pub fn uri(mut self, uri: &str) -> Self {
74        self.uri = Some(uri.to_string());
75        self
76    }
77}
78
79pub const NONE_URI_REQUEST: Option<&URIRequest> = None;
80
81pub trait URIRequestExt: 'static {
82    #[doc(alias = "webkit_uri_request_get_http_headers")]
83    #[doc(alias = "get_http_headers")]
84    fn http_headers(&self) -> Option<soup::MessageHeaders>;
85
86    #[cfg(any(feature = "v2_12", feature = "dox"))]
87    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_12")))]
88    #[doc(alias = "webkit_uri_request_get_http_method")]
89    #[doc(alias = "get_http_method")]
90    fn http_method(&self) -> Option<glib::GString>;
91
92    #[doc(alias = "webkit_uri_request_get_uri")]
93    #[doc(alias = "get_uri")]
94    fn uri(&self) -> Option<glib::GString>;
95
96    #[doc(alias = "webkit_uri_request_set_uri")]
97    fn set_uri(&self, uri: &str);
98
99    #[doc(alias = "uri")]
100    fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
101}
102
103impl<O: IsA<URIRequest>> URIRequestExt for O {
104    fn http_headers(&self) -> Option<soup::MessageHeaders> {
105        unsafe {
106            from_glib_none(ffi::webkit_uri_request_get_http_headers(self.as_ref().to_glib_none().0))
107        }
108    }
109
110    #[cfg(any(feature = "v2_12", feature = "dox"))]
111    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_12")))]
112    fn http_method(&self) -> Option<glib::GString> {
113        unsafe {
114            from_glib_none(ffi::webkit_uri_request_get_http_method(self.as_ref().to_glib_none().0))
115        }
116    }
117
118    fn uri(&self) -> Option<glib::GString> {
119        unsafe {
120            from_glib_none(ffi::webkit_uri_request_get_uri(self.as_ref().to_glib_none().0))
121        }
122    }
123
124    fn set_uri(&self, uri: &str) {
125        unsafe {
126            ffi::webkit_uri_request_set_uri(self.as_ref().to_glib_none().0, uri.to_glib_none().0);
127        }
128    }
129
130    fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131        unsafe extern "C" fn notify_uri_trampoline<P: IsA<URIRequest>, F: Fn(&P) + 'static>(this: *mut ffi::WebKitURIRequest, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
132            let f: &F = &*(f as *const F);
133            f(URIRequest::from_glib_borrow(this).unsafe_cast_ref())
134        }
135        unsafe {
136            let f: Box_<F> = Box_::new(f);
137            connect_raw(self.as_ptr() as *mut _, b"notify::uri\0".as_ptr() as *const _,
138                Some(transmute::<_, unsafe extern "C" fn()>(notify_uri_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
139        }
140    }
141}
142
143impl fmt::Display for URIRequest {
144    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
145        f.write_str("URIRequest")
146    }
147}