libcosmic/examples/app_library/app_group/mod.rs

47 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-02 17:25:33 -05:00
mod imp;
2021-12-06 10:56:45 -05:00
use glib::Object;
2021-12-02 17:25:33 -05:00
use glib::ObjectExt;
use glib::ToVariant;
use gtk4::glib;
2021-12-06 10:56:45 -05:00
use gtk4::subclass::prelude::*;
2021-12-02 17:25:33 -05:00
use serde::{Deserialize, Serialize};
glib::wrapper! {
pub struct AppGroup(ObjectSubclass<imp::AppGroup>);
}
impl AppGroup {
pub fn new(data: AppGroupData) -> Self {
let self_: Self = Object::new(&[
("id", &data.id),
("name", &data.name),
("mutable", &data.mutable),
("icon", &data.icon),
("category", &data.category),
])
.expect("Failed to create `ApplicationObject`.");
if let Err(e) = self_.set_property("appnames", data.app_names.to_variant()) {
println!("failed to set category icon property");
dbg!(e);
};
self_
}
2021-12-06 10:56:45 -05:00
pub fn group_data(&self) -> AppGroupData {
let imp = imp::AppGroup::from_instance(self);
imp.data.borrow().clone()
}
2021-12-02 17:25:33 -05:00
}
// Object holding the state
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct AppGroupData {
pub id: u32,
pub name: String,
pub icon: String,
pub mutable: bool,
pub app_names: Vec<String>,
pub category: String,
}