use crate::CacheType;
#[cfg(any(feature = "v2_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_24")))]
use crate::SessionFeature;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use std::fmt;
#[cfg(any(feature = "v2_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_24")))]
glib::wrapper! {
#[doc(alias = "SoupCache")]
pub struct Cache(Object<ffi::SoupCache, ffi::SoupCacheClass>) @implements SessionFeature;
match fn {
type_ => || ffi::soup_cache_get_type(),
}
}
#[cfg(not(any(feature = "v2_24", feature = "dox")))]
glib::wrapper! {
#[doc(alias = "SoupCache")]
pub struct Cache(Object<ffi::SoupCache, ffi::SoupCacheClass>);
match fn {
type_ => || ffi::soup_cache_get_type(),
}
}
impl Cache {
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_new")]
pub fn new(cache_dir: Option<&str>, cache_type: CacheType) -> Cache {
crate::assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_cache_new(cache_dir.to_glib_none().0, cache_type.into_glib()))
}
}
}
pub const NONE_CACHE: Option<&Cache> = None;
pub trait CacheExt: 'static {
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_clear")]
fn clear(&self);
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_dump")]
fn dump(&self);
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_flush")]
fn flush(&self);
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_get_max_size")]
#[doc(alias = "get_max_size")]
fn max_size(&self) -> u32;
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_load")]
fn load(&self);
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
#[doc(alias = "soup_cache_set_max_size")]
fn set_max_size(&self, max_size: u32);
#[doc(alias = "cache-dir")]
fn cache_dir(&self) -> Option<glib::GString>;
#[doc(alias = "cache-type")]
fn cache_type(&self) -> CacheType;
}
impl<O: IsA<Cache>> CacheExt for O {
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn clear(&self) {
unsafe {
ffi::soup_cache_clear(self.as_ref().to_glib_none().0);
}
}
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn dump(&self) {
unsafe {
ffi::soup_cache_dump(self.as_ref().to_glib_none().0);
}
}
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn flush(&self) {
unsafe {
ffi::soup_cache_flush(self.as_ref().to_glib_none().0);
}
}
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn max_size(&self) -> u32 {
unsafe {
ffi::soup_cache_get_max_size(self.as_ref().to_glib_none().0)
}
}
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn load(&self) {
unsafe {
ffi::soup_cache_load(self.as_ref().to_glib_none().0);
}
}
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
fn set_max_size(&self, max_size: u32) {
unsafe {
ffi::soup_cache_set_max_size(self.as_ref().to_glib_none().0, max_size);
}
}
fn cache_dir(&self) -> Option<glib::GString> {
unsafe {
let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type());
glib::gobject_ffi::g_object_get_property(self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, b"cache-dir\0".as_ptr() as *const _, value.to_glib_none_mut().0);
value.get().expect("Return Value for property `cache-dir` getter")
}
}
fn cache_type(&self) -> CacheType {
unsafe {
let mut value = glib::Value::from_type(<CacheType as StaticType>::static_type());
glib::gobject_ffi::g_object_get_property(self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, b"cache-type\0".as_ptr() as *const _, value.to_glib_none_mut().0);
value.get().expect("Return Value for property `cache-type` getter")
}
}
}
impl fmt::Display for Cache {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Cache")
}
}