use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::fmt;
glib::wrapper! {
#[doc(alias = "WebKitUserMessage")]
pub struct UserMessage(Object<ffi::WebKitUserMessage, ffi::WebKitUserMessageClass>);
match fn {
type_ => || ffi::webkit_user_message_get_type(),
}
}
impl UserMessage {
pub const NONE: Option<&'static UserMessage> = None;
#[doc(alias = "webkit_user_message_new")]
pub fn new(name: &str, parameters: Option<&glib::Variant>) -> UserMessage {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::webkit_user_message_new(
name.to_glib_none().0,
parameters.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_user_message_new_with_fd_list")]
#[doc(alias = "new_with_fd_list")]
pub fn with_fd_list(
name: &str,
parameters: Option<&glib::Variant>,
fd_list: Option<&impl IsA<gio::UnixFDList>>,
) -> UserMessage {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::webkit_user_message_new_with_fd_list(
name.to_glib_none().0,
parameters.to_glib_none().0,
fd_list.map(|p| p.as_ref()).to_glib_none().0,
))
}
}
pub fn builder() -> UserMessageBuilder {
UserMessageBuilder::default()
}
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
impl Default for UserMessage {
fn default() -> Self {
glib::object::Object::new::<Self>(&[])
}
}
#[derive(Clone, Default)]
#[must_use = "The builder must be built to be used"]
pub struct UserMessageBuilder {
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
fd_list: Option<gio::UnixFDList>,
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
name: Option<String>,
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
parameters: Option<glib::Variant>,
}
impl UserMessageBuilder {
pub fn new() -> Self {
Self::default()
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> UserMessage {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
#[cfg(any(feature = "v2_28", feature = "dox"))]
if let Some(ref fd_list) = self.fd_list {
properties.push(("fd-list", fd_list));
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
if let Some(ref name) = self.name {
properties.push(("name", name));
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
if let Some(ref parameters) = self.parameters {
properties.push(("parameters", parameters));
}
glib::Object::new::<UserMessage>(&properties)
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
pub fn fd_list(mut self, fd_list: &impl IsA<gio::UnixFDList>) -> Self {
self.fd_list = Some(fd_list.clone().upcast());
self
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
#[cfg(any(feature = "v2_28", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_28")))]
pub fn parameters(mut self, parameters: &glib::Variant) -> Self {
self.parameters = Some(parameters.clone());
self
}
}
pub trait UserMessageExt: 'static {
#[doc(alias = "webkit_user_message_get_fd_list")]
#[doc(alias = "get_fd_list")]
fn fd_list(&self) -> Option<gio::UnixFDList>;
#[doc(alias = "webkit_user_message_get_name")]
#[doc(alias = "get_name")]
fn name(&self) -> Option<glib::GString>;
#[doc(alias = "webkit_user_message_get_parameters")]
#[doc(alias = "get_parameters")]
fn parameters(&self) -> Option<glib::Variant>;
#[doc(alias = "webkit_user_message_send_reply")]
fn send_reply(&self, reply: &impl IsA<UserMessage>);
}
impl<O: IsA<UserMessage>> UserMessageExt for O {
fn fd_list(&self) -> Option<gio::UnixFDList> {
unsafe {
from_glib_none(ffi::webkit_user_message_get_fd_list(
self.as_ref().to_glib_none().0,
))
}
}
fn name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::webkit_user_message_get_name(
self.as_ref().to_glib_none().0,
))
}
}
fn parameters(&self) -> Option<glib::Variant> {
unsafe {
from_glib_none(ffi::webkit_user_message_get_parameters(
self.as_ref().to_glib_none().0,
))
}
}
fn send_reply(&self, reply: &impl IsA<UserMessage>) {
unsafe {
ffi::webkit_user_message_send_reply(
self.as_ref().to_glib_none().0,
reply.as_ref().to_glib_none().0,
);
}
}
}
impl fmt::Display for UserMessage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("UserMessage")
}
}