mimick/library/
asset_object.rs1use glib::prelude::*;
8use glib::subclass::prelude::*;
9use std::cell::{Cell, RefCell};
10
11mod imp {
12 use super::*;
13 use glib::Properties;
14
15 #[derive(Properties, Default)]
16 #[properties(wrapper_type = super::AssetObject)]
17 pub struct AssetObject {
18 #[property(get, set)]
20 id: RefCell<String>,
21
22 #[property(get, set)]
24 filename: RefCell<String>,
25
26 #[property(get, set)]
28 mime_type: RefCell<String>,
29
30 #[property(get, set)]
32 created_at: RefCell<String>,
33
34 #[property(get, set)]
36 asset_type: RefCell<String>,
37
38 #[property(get, set)]
40 sync_state: Cell<u32>,
41
42 #[property(get, set)]
44 thumbhash: RefCell<Option<String>>,
45
46 #[property(get, set)]
49 local_path: RefCell<String>,
50
51 #[property(get, set)]
54 remote_id: RefCell<String>,
55
56 #[property(get, set)]
59 width: Cell<u32>,
60
61 #[property(get, set)]
63 height: Cell<u32>,
64 }
65
66 #[glib::object_subclass]
67 impl ObjectSubclass for AssetObject {
68 const NAME: &'static str = "MimickAssetObject";
69 type Type = super::AssetObject;
70 }
71
72 #[glib::derived_properties]
73 impl ObjectImpl for AssetObject {}
74}
75
76glib::wrapper! {
77 pub struct AssetObject(ObjectSubclass<imp::AssetObject>);
79}
80
81pub struct AssetInit<'a> {
84 pub id: &'a str,
85 pub filename: &'a str,
86 pub mime_type: &'a str,
87 pub created_at: &'a str,
88 pub asset_type: &'a str,
89 pub sync_state: u32,
90 pub thumbhash: Option<&'a str>,
91 pub width: u32,
92 pub height: u32,
93}
94
95impl AssetObject {
96 pub fn new(init: AssetInit<'_>) -> Self {
97 glib::Object::builder()
98 .property("id", init.id)
99 .property("filename", init.filename)
100 .property("mime-type", init.mime_type)
101 .property("created-at", init.created_at)
102 .property("asset-type", init.asset_type)
103 .property("sync-state", init.sync_state)
104 .property("thumbhash", init.thumbhash)
105 .property("local-path", "")
106 .property("remote-id", init.id)
107 .property("width", init.width)
108 .property("height", init.height)
109 .build()
110 }
111
112 pub fn new_local(
116 id: &str,
117 filename: &str,
118 mime_type: &str,
119 created_at: &str,
120 asset_type: &str,
121 local_path: &str,
122 ) -> Self {
123 glib::Object::builder()
124 .property("id", id)
125 .property("filename", filename)
126 .property("mime-type", mime_type)
127 .property("created-at", created_at)
128 .property("asset-type", asset_type)
129 .property("sync-state", 1u32)
130 .property("thumbhash", None::<String>)
131 .property("local-path", local_path)
132 .property("remote-id", "")
133 .property("width", 0u32)
134 .property("height", 0u32)
135 .build()
136 }
137}