Move accounts to `ui`
parent
681ac4b849
commit
84bf2d43be
|
@ -25,7 +25,6 @@ pub struct AccountSettings {
|
|||
pub root_folder: String,
|
||||
pub format: String,
|
||||
pub sent_folder: String,
|
||||
pub threaded: bool,
|
||||
}
|
||||
|
||||
impl AccountSettings {
|
||||
|
|
|
@ -31,8 +31,6 @@ pub use self::email::*;
|
|||
pub mod backends;
|
||||
use error::Result;
|
||||
use mailbox::backends::{folder_default, Folder, MailBackend};
|
||||
pub mod accounts;
|
||||
pub use mailbox::accounts::Account;
|
||||
pub mod thread;
|
||||
pub use mailbox::thread::{build_threads, Container, Threads, SortOrder, SortField};
|
||||
|
||||
|
|
|
@ -416,9 +416,8 @@ impl Component for CompactListing {
|
|||
Action::MailListing(MailListingAction::ToggleThreaded) => {
|
||||
context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded = !context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf_mut()
|
||||
.toggle_threaded();
|
||||
self.refresh_mailbox(context);
|
||||
self.dirty = true;
|
||||
return;
|
||||
|
|
|
@ -96,7 +96,8 @@ impl MailListing {
|
|||
|
||||
let threaded = context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf()
|
||||
.threaded();
|
||||
// Inform State that we changed the current folder view.
|
||||
context.replies.push_back(UIEvent {
|
||||
id: 0,
|
||||
|
@ -293,7 +294,8 @@ impl MailListing {
|
|||
fn highlight_line_self(&mut self, idx: usize, context: &Context) {
|
||||
let threaded = context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf()
|
||||
.threaded();
|
||||
let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
@ -327,7 +329,8 @@ impl MailListing {
|
|||
fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) {
|
||||
let threaded = context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf()
|
||||
.threaded();
|
||||
let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
@ -515,7 +518,8 @@ impl Component for MailListing {
|
|||
} else {
|
||||
let threaded = context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf()
|
||||
.threaded();
|
||||
let account = &mut context.accounts[self.cursor_pos.0];
|
||||
let (hash, is_seen) = {
|
||||
let mailbox = &mut account[self.cursor_pos.1]
|
||||
|
@ -737,9 +741,8 @@ impl Component for MailListing {
|
|||
Action::MailListing(MailListingAction::ToggleThreaded) => {
|
||||
context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded = !context.accounts[self.cursor_pos.0]
|
||||
.runtime_settings
|
||||
.threaded;
|
||||
.conf_mut()
|
||||
.toggle_threaded();
|
||||
self.refresh_mailbox(context);
|
||||
self.dirty = true;
|
||||
return;
|
||||
|
|
|
@ -209,7 +209,7 @@ impl Component for MailView {
|
|||
|
||||
let (envelope_idx, y): (usize, usize) = {
|
||||
let accounts = &mut context.accounts;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.threaded;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded();
|
||||
let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1]
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
@ -372,7 +372,7 @@ impl Component for MailView {
|
|||
|
||||
{
|
||||
let accounts = &context.accounts;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.threaded;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded();
|
||||
let mailbox = &accounts[self.coordinates.0][self.coordinates.1]
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
@ -462,7 +462,7 @@ impl Component for MailView {
|
|||
self.cmd_buf.clear();
|
||||
let url = {
|
||||
let accounts = &context.accounts;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.threaded;
|
||||
let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded();
|
||||
let mailbox = &accounts[self.coordinates.0][self.coordinates.1]
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
|
|
|
@ -42,6 +42,12 @@ impl FileAccount {
|
|||
pub fn folder(&self) -> &str {
|
||||
&self.root_folder
|
||||
}
|
||||
pub fn threaded(&self) -> bool {
|
||||
self.threaded
|
||||
}
|
||||
pub fn toggle_threaded(&mut self) {
|
||||
self.threaded = !self.threaded;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
|
@ -51,23 +57,26 @@ struct FileSettings {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct AccountConfiguration {
|
||||
pub struct AccountConf {
|
||||
account: AccountSettings,
|
||||
conf: FileAccount,
|
||||
}
|
||||
|
||||
impl AccountConfiguration {
|
||||
impl AccountConf {
|
||||
pub fn account(&self) -> &AccountSettings {
|
||||
&self.account
|
||||
}
|
||||
pub fn conf(&self) -> &FileAccount {
|
||||
&self.conf
|
||||
}
|
||||
pub fn conf_mut(&mut self) -> &mut FileAccount {
|
||||
&mut self.conf
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Settings {
|
||||
pub accounts: HashMap<String, AccountConfiguration>,
|
||||
pub accounts: HashMap<String, AccountConf>,
|
||||
pub pager: PagerSettings,
|
||||
}
|
||||
|
||||
|
@ -91,12 +100,11 @@ impl FileSettings {
|
|||
impl Settings {
|
||||
pub fn new() -> Settings {
|
||||
let fs = FileSettings::new();
|
||||
let mut s: HashMap<String, AccountConfiguration> = HashMap::new();
|
||||
let mut s: HashMap<String, AccountConf> = HashMap::new();
|
||||
|
||||
for (id, x) in fs.accounts {
|
||||
let format = x.format.to_lowercase();
|
||||
let sent_folder = x.sent_folder.clone();
|
||||
let threaded = x.threaded;
|
||||
let root_folder = x.root_folder.clone();
|
||||
|
||||
let acc = AccountSettings {
|
||||
|
@ -104,10 +112,9 @@ impl Settings {
|
|||
root_folder,
|
||||
format,
|
||||
sent_folder,
|
||||
threaded,
|
||||
};
|
||||
|
||||
s.insert(id, AccountConfiguration {
|
||||
s.insert(id, AccountConf {
|
||||
account: acc,
|
||||
conf: x
|
||||
});
|
||||
|
|
|
@ -179,7 +179,7 @@ impl State<std::io::Stdout> {
|
|||
let mut accounts: Vec<Account> = settings
|
||||
.accounts
|
||||
.iter()
|
||||
.map(|(n, a_s)| Account::new(n.to_string(), a_s.account().clone(), &backends))
|
||||
.map(|(n, a_s)| Account::new(n.to_string(), a_s.clone(), &backends))
|
||||
.collect();
|
||||
accounts.sort_by(|a, b| a.name().cmp(&b.name()));
|
||||
let (startup_tx, startup_rx) = chan::async();
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
*/
|
||||
|
||||
use async::*;
|
||||
use conf::AccountSettings;
|
||||
use mailbox::backends::{Backends, RefreshEventConsumer};
|
||||
use conf::AccountConf;
|
||||
use melib::error::Result;
|
||||
use mailbox::backends::{MailBackend, Folder, Backends, RefreshEventConsumer};
|
||||
use mailbox::*;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::result;
|
||||
|
@ -47,20 +48,20 @@ pub struct Account {
|
|||
|
||||
sent_folder: Option<usize>,
|
||||
|
||||
pub settings: AccountSettings,
|
||||
pub runtime_settings: AccountSettings,
|
||||
pub settings: AccountConf,
|
||||
pub runtime_settings: AccountConf,
|
||||
pub backend: Box<MailBackend>,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
pub fn new(name: String, settings: AccountSettings, map: &Backends) -> Self {
|
||||
let mut backend = map.get(settings.format())(&settings);
|
||||
pub fn new(name: String, settings: AccountConf, map: &Backends) -> Self {
|
||||
let mut backend = map.get(settings.account().format())(settings.account());
|
||||
let ref_folders: Vec<Folder> = backend.folders();
|
||||
let mut folders: Vec<Option<Result<Mailbox>>> = Vec::with_capacity(ref_folders.len());
|
||||
let mut workers: Vec<Worker> = Vec::new();
|
||||
let sent_folder = ref_folders
|
||||
.iter()
|
||||
.position(|x: &Folder| x.name() == settings.sent_folder);
|
||||
.position(|x: &Folder| x.name() == settings.account().sent_folder);
|
||||
for f in ref_folders {
|
||||
folders.push(None);
|
||||
let handle = backend.get(&f);
|
|
@ -19,6 +19,8 @@
|
|||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pub mod accounts;
|
||||
pub use self::accounts::Account;
|
||||
#[macro_use]
|
||||
mod position;
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in New Issue