use std::path::PathBuf;
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
use gravityfile_analyze::{AgeReport, DuplicateReport};
use gravityfile_core::FileTree;
use gravityfile_scan::ScanProgress;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AppMode {
#[default]
Normal,
Scanning,
Help,
ConfirmDelete,
Deleting,
Command,
Quit,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Display, EnumIter, FromRepr)]
pub enum View {
#[default]
Explorer,
Duplicates,
Age,
Errors,
}
impl View {
pub fn next(self) -> Self {
let current = self as usize;
let next = (current + 1) % Self::iter().count();
Self::from_repr(next).unwrap_or_default()
}
pub fn prev(self) -> Self {
let current = self as usize;
let count = Self::iter().count();
let prev = (current + count - 1) % count;
Self::from_repr(prev).unwrap_or_default()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ScanView {
#[default]
Progress,
Errors,
}
impl ScanView {
pub fn next(self) -> Self {
match self {
ScanView::Progress => ScanView::Errors,
ScanView::Errors => ScanView::Progress,
}
}
pub fn prev(self) -> Self {
self.next() }
}
#[derive(Debug, Clone)]
pub struct DeletionProgress {
pub total: usize,
pub deleted: usize,
pub failed: usize,
pub bytes_freed: u64,
pub current: Option<PathBuf>,
}
impl DeletionProgress {
pub fn new(total: usize) -> Self {
Self {
total,
deleted: 0,
failed: 0,
bytes_freed: 0,
current: None,
}
}
pub fn percentage(&self) -> u16 {
if self.total > 0 {
((self.deleted + self.failed) as f64 / self.total as f64 * 100.0) as u16
} else {
0
}
}
}
pub enum ScanResult {
Progress(ScanProgress),
#[allow(dead_code)] Warning(gravityfile_core::ScanWarning),
ScanComplete(Result<FileTree, gravityfile_scan::ScanError>),
AnalysisComplete {
duplicates: DuplicateReport,
age_report: AgeReport,
},
DeletionProgress(DeletionProgress),
DeletionComplete {
deleted: usize,
failed: usize,
bytes_freed: u64,
},
}
#[derive(Debug, Clone)]
pub struct SelectedInfo {
pub name: String,
pub path: PathBuf,
pub size: u64,
pub file_count: u64,
pub dir_count: u64,
pub modified: std::time::SystemTime,
pub is_dir: bool,
}