use chrono::NaiveDateTime;
use uuid::Uuid;
use crate::db::{Color, CustomData};
#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct Meta {
pub generator: Option<String>,
pub database_name: Option<String>,
pub database_name_changed: Option<NaiveDateTime>,
pub database_description: Option<String>,
pub database_description_changed: Option<NaiveDateTime>,
pub default_username: Option<String>,
pub default_username_changed: Option<NaiveDateTime>,
pub maintenance_history_days: Option<usize>,
pub color: Option<Color>,
pub master_key_changed: Option<NaiveDateTime>,
pub master_key_change_rec: Option<isize>,
pub master_key_change_force: Option<isize>,
pub memory_protection: Option<MemoryProtection>,
pub custom_icons: CustomIcons,
pub(crate) recyclebin_enabled: Option<bool>,
pub(crate) recyclebin_uuid: Option<Uuid>,
pub(crate) recyclebin_changed: Option<NaiveDateTime>,
pub entry_templates_group: Option<Uuid>,
pub entry_templates_group_changed: Option<NaiveDateTime>,
pub last_selected_group: Option<Uuid>,
pub last_top_visible_group: Option<Uuid>,
pub history_max_items: Option<usize>,
pub history_max_size: Option<usize>,
pub settings_changed: Option<NaiveDateTime>,
pub binaries: BinaryAttachments,
pub custom_data: CustomData,
}
impl Meta {
pub fn new() -> Self {
Self {
recyclebin_enabled: Some(true),
..Meta::default()
}
}
pub fn set_recycle_bin_enabled(&mut self, enabled: bool) {
self.recyclebin_enabled = Some(enabled);
self.set_recycle_bin_changed();
}
pub fn recycle_bin_enabled(&self) -> bool {
self.recyclebin_enabled.unwrap_or(false)
}
pub fn recycle_bin_changed(&self) -> Option<NaiveDateTime> {
self.recyclebin_changed
}
pub fn set_recycle_bin_changed(&mut self) {
let time = chrono::Local::now().naive_local();
self.recyclebin_changed = Some(time);
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct MemoryProtection {
pub protect_title: bool,
pub protect_username: bool,
pub protect_password: bool,
pub protect_url: bool,
pub protect_notes: bool,
}
impl Default for MemoryProtection {
fn default() -> Self {
Self {
protect_title: false,
protect_username: false,
protect_password: true,
protect_url: false,
protect_notes: false,
}
}
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct CustomIcons {
pub icons: Vec<Icon>,
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct Icon {
pub uuid: Uuid,
pub data: Vec<u8>,
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct BinaryAttachments {
pub binaries: Vec<BinaryAttachment>,
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct BinaryAttachment {
pub identifier: Option<String>,
pub compressed: bool,
pub content: Vec<u8>,
}