use crate::{ffi, Position};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "PanelSessionItem")]
pub struct SessionItem(Object<ffi::PanelSessionItem, ffi::PanelSessionItemClass>);
match fn {
type_ => || ffi::panel_session_item_get_type(),
}
}
impl SessionItem {
#[doc(alias = "panel_session_item_new")]
pub fn new() -> SessionItem {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::panel_session_item_new()) }
}
pub fn builder() -> SessionItemBuilder {
SessionItemBuilder::new()
}
#[doc(alias = "panel_session_item_get_id")]
#[doc(alias = "get_id")]
pub fn id(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::panel_session_item_get_id(self.to_glib_none().0)) }
}
#[doc(alias = "panel_session_item_get_metadata_value")]
#[doc(alias = "get_metadata_value")]
pub fn metadata_value(
&self,
key: &str,
expected_type: Option<&glib::VariantTy>,
) -> Option<glib::Variant> {
unsafe {
from_glib_full(ffi::panel_session_item_get_metadata_value(
self.to_glib_none().0,
key.to_glib_none().0,
expected_type.to_glib_none().0,
))
}
}
#[doc(alias = "panel_session_item_get_module_name")]
#[doc(alias = "get_module_name")]
#[doc(alias = "module-name")]
pub fn module_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::panel_session_item_get_module_name(
self.to_glib_none().0,
))
}
}
#[doc(alias = "panel_session_item_get_position")]
#[doc(alias = "get_position")]
pub fn position(&self) -> Option<Position> {
unsafe { from_glib_none(ffi::panel_session_item_get_position(self.to_glib_none().0)) }
}
#[doc(alias = "panel_session_item_get_type_hint")]
#[doc(alias = "get_type_hint")]
#[doc(alias = "type-hint")]
pub fn type_hint(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::panel_session_item_get_type_hint(self.to_glib_none().0)) }
}
#[doc(alias = "panel_session_item_get_workspace")]
#[doc(alias = "get_workspace")]
pub fn workspace(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::panel_session_item_get_workspace(self.to_glib_none().0)) }
}
#[doc(alias = "panel_session_item_has_metadata_with_type")]
pub fn has_metadata_with_type(&self, key: &str, expected_type: &glib::VariantTy) -> bool {
unsafe {
from_glib(ffi::panel_session_item_has_metadata_with_type(
self.to_glib_none().0,
key.to_glib_none().0,
expected_type.to_glib_none().0,
))
}
}
#[doc(alias = "panel_session_item_set_id")]
#[doc(alias = "id")]
pub fn set_id(&self, id: Option<&str>) {
unsafe {
ffi::panel_session_item_set_id(self.to_glib_none().0, id.to_glib_none().0);
}
}
#[doc(alias = "panel_session_item_set_metadata_value")]
pub fn set_metadata_value(&self, key: &str, value: Option<&glib::Variant>) {
unsafe {
ffi::panel_session_item_set_metadata_value(
self.to_glib_none().0,
key.to_glib_none().0,
value.to_glib_none().0,
);
}
}
#[doc(alias = "panel_session_item_set_module_name")]
#[doc(alias = "module-name")]
pub fn set_module_name(&self, module_name: Option<&str>) {
unsafe {
ffi::panel_session_item_set_module_name(
self.to_glib_none().0,
module_name.to_glib_none().0,
);
}
}
#[doc(alias = "panel_session_item_set_position")]
#[doc(alias = "position")]
pub fn set_position(&self, position: Option<&Position>) {
unsafe {
ffi::panel_session_item_set_position(self.to_glib_none().0, position.to_glib_none().0);
}
}
#[doc(alias = "panel_session_item_set_type_hint")]
#[doc(alias = "type-hint")]
pub fn set_type_hint(&self, type_hint: Option<&str>) {
unsafe {
ffi::panel_session_item_set_type_hint(
self.to_glib_none().0,
type_hint.to_glib_none().0,
);
}
}
#[doc(alias = "panel_session_item_set_workspace")]
#[doc(alias = "workspace")]
pub fn set_workspace(&self, workspace: Option<&str>) {
unsafe {
ffi::panel_session_item_set_workspace(
self.to_glib_none().0,
workspace.to_glib_none().0,
);
}
}
#[doc(alias = "id")]
pub fn connect_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_id_trampoline<F: Fn(&SessionItem) + 'static>(
this: *mut ffi::PanelSessionItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::id\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_id_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "module-name")]
pub fn connect_module_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_module_name_trampoline<F: Fn(&SessionItem) + 'static>(
this: *mut ffi::PanelSessionItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::module-name\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_module_name_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "position")]
pub fn connect_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_position_trampoline<F: Fn(&SessionItem) + 'static>(
this: *mut ffi::PanelSessionItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::position\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_position_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "type-hint")]
pub fn connect_type_hint_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_type_hint_trampoline<F: Fn(&SessionItem) + 'static>(
this: *mut ffi::PanelSessionItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::type-hint\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_type_hint_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "workspace")]
pub fn connect_workspace_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_workspace_trampoline<F: Fn(&SessionItem) + 'static>(
this: *mut ffi::PanelSessionItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::workspace\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_workspace_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for SessionItem {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct SessionItemBuilder {
builder: glib::object::ObjectBuilder<'static, SessionItem>,
}
impl SessionItemBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn id(self, id: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("id", id.into()),
}
}
pub fn module_name(self, module_name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("module-name", module_name.into()),
}
}
pub fn position(self, position: &Position) -> Self {
Self {
builder: self.builder.property("position", position.clone()),
}
}
pub fn type_hint(self, type_hint: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("type-hint", type_hint.into()),
}
}
pub fn workspace(self, workspace: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("workspace", workspace.into()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> SessionItem {
self.builder.build()
}
}