From fdb42cfc0c2154e20b1fb582c2e257d0a129be9c Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 2 Dec 2019 01:08:34 +0200 Subject: [PATCH] ui/status: show tag and search backend info Show tag and search backend info for each account. --- ui/src/components/mail/status.rs | 95 +++++++++++++++++++++++++++++--- ui/src/sqlite3.rs | 15 +++-- 2 files changed, 97 insertions(+), 13 deletions(-) diff --git a/ui/src/components/mail/status.rs b/ui/src/components/mail/status.rs index 48f06cc0..e803462c 100644 --- a/ui/src/components/mail/status.rs +++ b/ui/src/components/mail/status.rs @@ -368,9 +368,87 @@ impl Component for AccountStatus { self.dirty = false; let (width, height) = self.content.size(); let a = &context.accounts[self.account_pos]; - if a.settings.account().format() == "imap" { - let backend_lck = a.backend.read().unwrap(); + let backend_lck = a.backend.read().unwrap(); + let (_x, _y) = write_string_to_grid( + "(Press Esc to return)", + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((1, 0), (width - 1, height - 1)), + None, + ); + let mut line = 2; + let (_x, _y) = write_string_to_grid( + "Tag support: ", + &mut self.content, + Color::Default, + Color::Default, + Attr::Bold, + ((1, line), (width - 1, height - 1)), + None, + ); + write_string_to_grid( + if backend_lck.tags().is_some() { + "yes" + } else { + "no" + }, + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((_x, _y), (width - 1, height - 1)), + None, + ); + line += 1; + let (_x, _y) = write_string_to_grid( + "Cache backend: ", + &mut self.content, + Color::Default, + Color::Default, + Attr::Bold, + ((1, line), (width - 1, height - 1)), + None, + ); + write_string_to_grid( + &if a.settings.account().format() == "imap" + && *a.settings.conf.cache_type() == CacheType::None + { + "server-side search".to_string() + } else if a.settings.account().format() == "notmuch" + && *a.settings.conf.cache_type() == CacheType::None + { + "notmuch database".to_string() + } else { + #[cfg(feature = "sqlite3")] + { + if *a.settings.conf.cache_type() == CacheType::Sqlite3 { + if let Ok(path) = crate::sqlite3::db_path() { + format!("sqlite3 database {}", path.display()) + } else { + "sqlite3 database".to_string() + } + } else { + "none (search will be slow)".to_string() + } + } + #[cfg(not(feature = "sqlite3"))] + { + "none (search will be slow)".to_string() + } + }, + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((_x, _y), (width - 1, height - 1)), + None, + ); + + line += 1; + if a.settings.account().format() == "imap" { let b = (*backend_lck).as_any(); if let Some(imap_backend) = b.downcast_ref::() { write_string_to_grid( @@ -378,8 +456,8 @@ impl Component for AccountStatus { &mut self.content, Color::Default, Color::Default, - Attr::Default, - ((1, 1), (width - 1, height - 1)), + Attr::Bold, + ((1, line), (width - 1, height - 1)), None, ); let mut capabilities = imap_backend.capabilities(); @@ -393,10 +471,11 @@ impl Component for AccountStatus { Color::Default, Color::Default, Attr::Default, - ((max_name_width + 6, 1), (width - 1, height - 1)), + ((max_name_width + 6, line), (width - 1, height - 1)), None, ); capabilities.sort(); + line += 1; for (i, cap) in capabilities.into_iter().enumerate() { let (width, height) = self.content.size(); write_string_to_grid( @@ -405,7 +484,7 @@ impl Component for AccountStatus { Color::Default, Color::Default, Attr::Default, - ((1, 2 + i), (width - 1, height - 1)), + ((1, line + i), (width - 1, height - 1)), None, ); @@ -420,7 +499,7 @@ impl Component for AccountStatus { Color::Green, Color::Default, Attr::Default, - ((max_name_width + 6, 2 + i), (width - 1, height - 1)), + ((max_name_width + 6, line + i), (width - 1, height - 1)), None, ); } else { @@ -430,7 +509,7 @@ impl Component for AccountStatus { Color::Red, Color::Default, Attr::Default, - ((max_name_width + 6, 2 + i), (width - 1, height - 1)), + ((max_name_width + 6, line + i), (width - 1, height - 1)), None, ); } diff --git a/ui/src/sqlite3.rs b/ui/src/sqlite3.rs index ecba3d1c..0f0d7f37 100644 --- a/ui/src/sqlite3.rs +++ b/ui/src/sqlite3.rs @@ -31,6 +31,7 @@ use melib::{ }; use rusqlite::{params, Connection}; use std::borrow::Cow; +use std::path::PathBuf; use std::convert::TryInto; use std::sync::{Arc, RwLock}; @@ -43,6 +44,14 @@ pub fn escape_double_quote(w: &str) -> Cow { } } +pub fn db_path() -> Result { + let data_dir = + xdg::BaseDirectories::with_prefix("meli").map_err(|e| MeliError::new(e.to_string()))?; + Ok(data_dir + .place_data_file("index.db") + .map_err(|e| MeliError::new(e.to_string()))?) +} + //#[inline(always)] //fn fts5_bareword(w: &str) -> Cow { // if w == "AND" || w == "OR" || w == "NOT" { @@ -67,11 +76,7 @@ pub fn escape_double_quote(w: &str) -> Cow { //} // pub fn open_db() -> Result { - let data_dir = - xdg::BaseDirectories::with_prefix("meli").map_err(|e| MeliError::new(e.to_string()))?; - let db_path = data_dir - .place_data_file("index.db") - .map_err(|e| MeliError::new(e.to_string()))?; + let db_path = db_path()?; let mut set_mode = false; if !db_path.exists() { log(