2022-01-14 01:09:25 +00:00
|
|
|
use crate::{entities::app::App, impl_def_and_def_mut};
|
2021-10-15 07:52:08 +00:00
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
2022-01-15 15:58:36 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-10-28 05:42:39 +00:00
|
|
|
use std::fmt::Formatter;
|
2021-10-15 07:52:08 +00:00
|
|
|
|
2022-01-16 05:44:14 +00:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone, Serialize, Deserialize)]
|
2022-01-15 15:58:36 +00:00
|
|
|
pub struct Trash {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub modified_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub create_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub ty: TrashType,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct RepeatedTrash {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<Trash>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_def_and_def_mut!(RepeatedTrash, Trash);
|
|
|
|
|
|
|
|
impl std::convert::From<App> for Trash {
|
|
|
|
fn from(app: App) -> Self {
|
|
|
|
Trash {
|
|
|
|
id: app.id,
|
|
|
|
name: app.name,
|
|
|
|
modified_time: app.modified_time,
|
|
|
|
create_time: app.create_time,
|
2022-02-08 06:36:59 +00:00
|
|
|
ty: TrashType::TrashApp,
|
2022-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:44:14 +00:00
|
|
|
#[derive(Eq, PartialEq, Debug, ProtoBuf_Enum, Clone, Serialize, Deserialize)]
|
2021-10-15 07:52:08 +00:00
|
|
|
pub enum TrashType {
|
|
|
|
Unknown = 0,
|
2022-02-08 06:36:59 +00:00
|
|
|
TrashView = 1,
|
|
|
|
TrashApp = 2,
|
2021-10-15 07:52:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 09:09:50 +00:00
|
|
|
impl std::convert::TryFrom<i32> for TrashType {
|
|
|
|
type Error = String;
|
|
|
|
|
|
|
|
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
|
|
|
match value {
|
|
|
|
0 => Ok(TrashType::Unknown),
|
2022-02-08 06:36:59 +00:00
|
|
|
1 => Ok(TrashType::TrashView),
|
|
|
|
2 => Ok(TrashType::TrashApp),
|
2021-10-15 09:09:50 +00:00
|
|
|
_ => Err(format!("Invalid trash type: {}", value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 07:52:08 +00:00
|
|
|
impl std::default::Default for TrashType {
|
2022-01-23 04:14:00 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
TrashType::Unknown
|
|
|
|
}
|
2021-10-15 07:52:08 +00:00
|
|
|
}
|
2021-10-12 14:31:38 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
2021-12-31 02:32:25 +00:00
|
|
|
pub struct RepeatedTrashId {
|
2021-10-17 14:44:51 +00:00
|
|
|
#[pb(index = 1)]
|
2021-12-31 02:32:25 +00:00
|
|
|
pub items: Vec<TrashId>,
|
2021-10-18 10:40:15 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub delete_all: bool,
|
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl std::fmt::Display for RepeatedTrashId {
|
2021-10-28 05:42:39 +00:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_str(&format!(
|
|
|
|
"{:?}",
|
2021-11-04 04:47:41 +00:00
|
|
|
&self.items.iter().map(|item| format!("{}", item)).collect::<Vec<_>>()
|
2021-10-28 05:42:39 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl RepeatedTrashId {
|
|
|
|
pub fn all() -> RepeatedTrashId {
|
|
|
|
RepeatedTrashId {
|
2021-10-18 10:40:15 +00:00
|
|
|
items: vec![],
|
|
|
|
delete_all: true,
|
|
|
|
}
|
|
|
|
}
|
2021-10-17 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl std::convert::From<Vec<TrashId>> for RepeatedTrashId {
|
|
|
|
fn from(items: Vec<TrashId>) -> Self {
|
|
|
|
RepeatedTrashId {
|
2021-10-18 10:40:15 +00:00
|
|
|
items,
|
|
|
|
delete_all: false,
|
|
|
|
}
|
|
|
|
}
|
2021-10-17 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl std::convert::From<Vec<Trash>> for RepeatedTrashId {
|
2021-10-17 14:44:51 +00:00
|
|
|
fn from(trash: Vec<Trash>) -> Self {
|
|
|
|
let items = trash
|
|
|
|
.into_iter()
|
2021-12-31 02:32:25 +00:00
|
|
|
.map(|t| TrashId { id: t.id, ty: t.ty })
|
2021-10-17 14:44:51 +00:00
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
RepeatedTrashId {
|
2021-10-18 10:40:15 +00:00
|
|
|
items,
|
|
|
|
delete_all: false,
|
|
|
|
}
|
2021-10-17 14:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
2021-12-31 02:32:25 +00:00
|
|
|
pub struct TrashId {
|
2021-10-12 14:31:38 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2021-10-15 07:52:08 +00:00
|
|
|
pub ty: TrashType,
|
2021-10-12 14:31:38 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl std::convert::From<&Trash> for TrashId {
|
2021-10-18 08:30:20 +00:00
|
|
|
fn from(trash: &Trash) -> Self {
|
2021-12-31 02:32:25 +00:00
|
|
|
TrashId {
|
2021-10-18 08:30:20 +00:00
|
|
|
id: trash.id.clone(),
|
|
|
|
ty: trash.ty.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 02:32:25 +00:00
|
|
|
impl std::fmt::Display for TrashId {
|
2022-01-23 04:14:00 +00:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_str(&format!("{:?}:{}", self.ty, self.id))
|
|
|
|
}
|
2021-11-04 04:47:41 +00:00
|
|
|
}
|