soup/auto/
cookie_jar.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, Cookie, CookieJarAcceptPolicy, SessionFeature};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "SoupCookieJar")]
17    pub struct CookieJar(Object<ffi::SoupCookieJar, ffi::SoupCookieJarClass>) @implements SessionFeature;
18
19    match fn {
20        type_ => || ffi::soup_cookie_jar_get_type(),
21    }
22}
23
24impl CookieJar {
25    pub const NONE: Option<&'static CookieJar> = None;
26
27    #[doc(alias = "soup_cookie_jar_new")]
28    pub fn new() -> CookieJar {
29        assert_initialized_main_thread!();
30        unsafe { from_glib_full(ffi::soup_cookie_jar_new()) }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`CookieJar`] objects.
35    ///
36    /// This method returns an instance of [`CookieJarBuilder`](crate::builders::CookieJarBuilder) which can be used to create [`CookieJar`] objects.
37    pub fn builder() -> CookieJarBuilder {
38        CookieJarBuilder::new()
39    }
40}
41
42impl Default for CookieJar {
43    fn default() -> Self {
44        Self::new()
45    }
46}
47
48// rustdoc-stripper-ignore-next
49/// A [builder-pattern] type to construct [`CookieJar`] objects.
50///
51/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
52#[must_use = "The builder must be built to be used"]
53pub struct CookieJarBuilder {
54    builder: glib::object::ObjectBuilder<'static, CookieJar>,
55}
56
57impl CookieJarBuilder {
58    fn new() -> Self {
59        Self {
60            builder: glib::object::Object::builder(),
61        }
62    }
63
64    pub fn accept_policy(self, accept_policy: CookieJarAcceptPolicy) -> Self {
65        Self {
66            builder: self.builder.property("accept-policy", accept_policy),
67        }
68    }
69
70    pub fn read_only(self, read_only: bool) -> Self {
71        Self {
72            builder: self.builder.property("read-only", read_only),
73        }
74    }
75
76    // rustdoc-stripper-ignore-next
77    /// Build the [`CookieJar`].
78    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
79    pub fn build(self) -> CookieJar {
80        assert_initialized_main_thread!();
81        self.builder.build()
82    }
83}
84
85pub trait CookieJarExt: IsA<CookieJar> + 'static {
86    #[doc(alias = "soup_cookie_jar_all_cookies")]
87    fn all_cookies(&self) -> Vec<Cookie> {
88        unsafe {
89            FromGlibPtrContainer::from_glib_full(ffi::soup_cookie_jar_all_cookies(
90                self.as_ref().to_glib_none().0,
91            ))
92        }
93    }
94
95    #[doc(alias = "soup_cookie_jar_get_accept_policy")]
96    #[doc(alias = "get_accept_policy")]
97    #[doc(alias = "accept-policy")]
98    fn accept_policy(&self) -> CookieJarAcceptPolicy {
99        unsafe {
100            from_glib(ffi::soup_cookie_jar_get_accept_policy(
101                self.as_ref().to_glib_none().0,
102            ))
103        }
104    }
105
106    #[doc(alias = "soup_cookie_jar_get_cookie_list")]
107    #[doc(alias = "get_cookie_list")]
108    fn cookie_list(&self, uri: &glib::Uri, for_http: bool) -> Vec<Cookie> {
109        unsafe {
110            FromGlibPtrContainer::from_glib_full(ffi::soup_cookie_jar_get_cookie_list(
111                self.as_ref().to_glib_none().0,
112                uri.to_glib_none().0,
113                for_http.into_glib(),
114            ))
115        }
116    }
117
118    #[doc(alias = "soup_cookie_jar_get_cookie_list_with_same_site_info")]
119    #[doc(alias = "get_cookie_list_with_same_site_info")]
120    fn cookie_list_with_same_site_info(
121        &self,
122        uri: &glib::Uri,
123        top_level: Option<&glib::Uri>,
124        site_for_cookies: Option<&glib::Uri>,
125        for_http: bool,
126        is_safe_method: bool,
127        is_top_level_navigation: bool,
128    ) -> Vec<Cookie> {
129        unsafe {
130            FromGlibPtrContainer::from_glib_full(
131                ffi::soup_cookie_jar_get_cookie_list_with_same_site_info(
132                    self.as_ref().to_glib_none().0,
133                    uri.to_glib_none().0,
134                    top_level.to_glib_none().0,
135                    site_for_cookies.to_glib_none().0,
136                    for_http.into_glib(),
137                    is_safe_method.into_glib(),
138                    is_top_level_navigation.into_glib(),
139                ),
140            )
141        }
142    }
143
144    #[doc(alias = "soup_cookie_jar_get_cookies")]
145    #[doc(alias = "get_cookies")]
146    fn cookies(&self, uri: &glib::Uri, for_http: bool) -> Option<glib::GString> {
147        unsafe {
148            from_glib_full(ffi::soup_cookie_jar_get_cookies(
149                self.as_ref().to_glib_none().0,
150                uri.to_glib_none().0,
151                for_http.into_glib(),
152            ))
153        }
154    }
155
156    #[doc(alias = "soup_cookie_jar_is_persistent")]
157    fn is_persistent(&self) -> bool {
158        unsafe {
159            from_glib(ffi::soup_cookie_jar_is_persistent(
160                self.as_ref().to_glib_none().0,
161            ))
162        }
163    }
164
165    #[doc(alias = "soup_cookie_jar_set_accept_policy")]
166    #[doc(alias = "accept-policy")]
167    fn set_accept_policy(&self, policy: CookieJarAcceptPolicy) {
168        unsafe {
169            ffi::soup_cookie_jar_set_accept_policy(
170                self.as_ref().to_glib_none().0,
171                policy.into_glib(),
172            );
173        }
174    }
175
176    #[doc(alias = "soup_cookie_jar_set_cookie")]
177    fn set_cookie(&self, uri: &glib::Uri, cookie: &str) {
178        unsafe {
179            ffi::soup_cookie_jar_set_cookie(
180                self.as_ref().to_glib_none().0,
181                uri.to_glib_none().0,
182                cookie.to_glib_none().0,
183            );
184        }
185    }
186
187    #[doc(alias = "soup_cookie_jar_set_cookie_with_first_party")]
188    fn set_cookie_with_first_party(&self, uri: &glib::Uri, first_party: &glib::Uri, cookie: &str) {
189        unsafe {
190            ffi::soup_cookie_jar_set_cookie_with_first_party(
191                self.as_ref().to_glib_none().0,
192                uri.to_glib_none().0,
193                first_party.to_glib_none().0,
194                cookie.to_glib_none().0,
195            );
196        }
197    }
198
199    #[doc(alias = "read-only")]
200    fn is_read_only(&self) -> bool {
201        ObjectExt::property(self.as_ref(), "read-only")
202    }
203
204    #[doc(alias = "changed")]
205    fn connect_changed<F: Fn(&Self, Option<&Cookie>, Option<&Cookie>) + 'static>(
206        &self,
207        f: F,
208    ) -> SignalHandlerId {
209        unsafe extern "C" fn changed_trampoline<
210            P: IsA<CookieJar>,
211            F: Fn(&P, Option<&Cookie>, Option<&Cookie>) + 'static,
212        >(
213            this: *mut ffi::SoupCookieJar,
214            old_cookie: *mut ffi::SoupCookie,
215            new_cookie: *mut ffi::SoupCookie,
216            f: glib::ffi::gpointer,
217        ) {
218            let f: &F = &*(f as *const F);
219            f(
220                CookieJar::from_glib_borrow(this).unsafe_cast_ref(),
221                Option::<Cookie>::from_glib_borrow(old_cookie)
222                    .as_ref()
223                    .as_ref(),
224                Option::<Cookie>::from_glib_borrow(new_cookie)
225                    .as_ref()
226                    .as_ref(),
227            )
228        }
229        unsafe {
230            let f: Box_<F> = Box_::new(f);
231            connect_raw(
232                self.as_ptr() as *mut _,
233                c"changed".as_ptr() as *const _,
234                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235                    changed_trampoline::<Self, F> as *const (),
236                )),
237                Box_::into_raw(f),
238            )
239        }
240    }
241
242    #[doc(alias = "accept-policy")]
243    fn connect_accept_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244        unsafe extern "C" fn notify_accept_policy_trampoline<
245            P: IsA<CookieJar>,
246            F: Fn(&P) + 'static,
247        >(
248            this: *mut ffi::SoupCookieJar,
249            _param_spec: glib::ffi::gpointer,
250            f: glib::ffi::gpointer,
251        ) {
252            let f: &F = &*(f as *const F);
253            f(CookieJar::from_glib_borrow(this).unsafe_cast_ref())
254        }
255        unsafe {
256            let f: Box_<F> = Box_::new(f);
257            connect_raw(
258                self.as_ptr() as *mut _,
259                c"notify::accept-policy".as_ptr() as *const _,
260                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261                    notify_accept_policy_trampoline::<Self, F> as *const (),
262                )),
263                Box_::into_raw(f),
264            )
265        }
266    }
267}
268
269impl<O: IsA<CookieJar>> CookieJarExt for O {}