1use chrono::NaiveDateTime;
2use uuid::Uuid;
3
4use crate::db::{Color, CustomData};
5
6#[derive(Debug, Default, Eq, PartialEq, Clone)]
8#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
9pub struct Meta {
10 pub generator: Option<String>,
12
13 pub database_name: Option<String>,
15
16 pub database_name_changed: Option<NaiveDateTime>,
18
19 pub database_description: Option<String>,
21
22 pub database_description_changed: Option<NaiveDateTime>,
24
25 pub default_username: Option<String>,
27
28 pub default_username_changed: Option<NaiveDateTime>,
30
31 pub maintenance_history_days: Option<usize>,
33
34 pub color: Option<Color>,
36
37 pub master_key_changed: Option<NaiveDateTime>,
39
40 pub master_key_change_rec: Option<isize>,
41
42 pub master_key_change_force: Option<isize>,
43
44 pub memory_protection: Option<MemoryProtection>,
46
47 pub custom_icons: CustomIcons,
49
50 pub(crate) recyclebin_enabled: Option<bool>,
52
53 pub(crate) recyclebin_uuid: Option<Uuid>,
55
56 pub(crate) recyclebin_changed: Option<NaiveDateTime>,
58
59 pub entry_templates_group: Option<Uuid>,
61
62 pub entry_templates_group_changed: Option<NaiveDateTime>,
64
65 pub last_selected_group: Option<Uuid>,
67
68 pub last_top_visible_group: Option<Uuid>,
70
71 pub history_max_items: Option<usize>,
73
74 pub history_max_size: Option<usize>,
76
77 pub settings_changed: Option<NaiveDateTime>,
79
80 pub binaries: BinaryAttachments,
82
83 pub custom_data: CustomData,
85}
86
87impl Meta {
88 pub fn new() -> Self {
90 Self {
91 recyclebin_enabled: Some(true),
92 ..Meta::default()
93 }
94 }
95
96 pub fn set_recycle_bin_enabled(&mut self, enabled: bool) {
98 self.recyclebin_enabled = Some(enabled);
99 self.set_recycle_bin_changed();
100 }
101
102 pub fn recycle_bin_enabled(&self) -> bool {
103 self.recyclebin_enabled.unwrap_or(false)
104 }
105
106 pub fn recycle_bin_changed(&self) -> Option<NaiveDateTime> {
107 self.recyclebin_changed
108 }
109
110 pub fn set_recycle_bin_changed(&mut self) {
112 let time = chrono::Local::now().naive_local();
113 self.recyclebin_changed = Some(time);
114 }
115}
116
117#[derive(Debug, PartialEq, Eq, Clone)]
119#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
120pub struct MemoryProtection {
121 pub protect_title: bool,
123
124 pub protect_username: bool,
126
127 pub protect_password: bool,
129
130 pub protect_url: bool,
132
133 pub protect_notes: bool,
135}
136
137impl Default for MemoryProtection {
138 fn default() -> Self {
139 Self {
140 protect_title: false,
141 protect_username: false,
142 protect_password: true,
143 protect_url: false,
144 protect_notes: false,
145 }
146 }
147}
148
149#[derive(Debug, Default, PartialEq, Eq, Clone)]
151#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
152pub struct CustomIcons {
153 pub icons: Vec<Icon>,
154}
155
156#[derive(Debug, Default, PartialEq, Eq, Clone)]
158#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
159pub struct Icon {
160 pub uuid: Uuid,
162
163 pub data: Vec<u8>,
165}
166
167#[derive(Debug, Default, PartialEq, Eq, Clone)]
169#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
170pub struct BinaryAttachments {
171 pub binaries: Vec<BinaryAttachment>,
172}
173
174#[derive(Debug, Default, PartialEq, Eq, Clone)]
176#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
177pub struct BinaryAttachment {
178 pub identifier: Option<String>,
179 pub compressed: bool,
180 pub content: Vec<u8>,
181}