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