mod imp; use std::str::FromStr; use adw::subclass::prelude::*; use f_uuid::Uuid; use glib::Object; use gtk::glib; glib::wrapper! { pub struct AppObject(ObjectSubclass); } impl AppObject { pub fn new(name: &str, path: &str) -> Self { let id = Uuid::new_random(); AppObject::from_fields(id, name, path) } pub fn from_fields(id: Uuid, name: &str, path: &str) -> Self { Object::builder() .property("id", id.to_string()) .property("name", name) .property("path", path) .build() } pub fn to_app_data(&self) -> AppData { let id_str = &self.imp().id.borrow(); let id = Uuid::from_str(id_str).unwrap(); let name = self.imp().name.borrow().clone(); let path = self.imp().path.borrow().clone(); AppData { id, name, path } } pub fn from_app_data(app_data: &AppData) -> Self { Self::from_fields(app_data.id, &app_data.name, &app_data.path) } } #[derive(Default, Clone)] pub struct AppData { pub id: Uuid, pub name: String, pub path: String }