move config stuff to `ui`

embed
Manos Pitsidianakis 2018-08-19 13:30:43 +03:00
parent 9d5b2a4628
commit 681ac4b849
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 29 additions and 11 deletions

View File

@ -19,7 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct AccountSettings {
pub name: String,
pub root_folder: String,

View File

@ -29,7 +29,7 @@ use pager::PagerSettings;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Default, Deserialize)]
pub struct FileAccount {
root_folder: String,
format: String,
@ -44,15 +44,30 @@ impl FileAccount {
}
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Default, Deserialize)]
struct FileSettings {
accounts: HashMap<String, FileAccount>,
pager: PagerSettings,
}
#[derive(Debug, Clone, Default)]
pub struct AccountConfiguration {
account: AccountSettings,
conf: FileAccount,
}
impl AccountConfiguration {
pub fn account(&self) -> &AccountSettings {
&self.account
}
pub fn conf(&self) -> &FileAccount {
&self.conf
}
}
#[derive(Debug, Clone, Default)]
pub struct Settings {
pub accounts: HashMap<String, AccountSettings>,
pub accounts: HashMap<String, AccountConfiguration>,
pub pager: PagerSettings,
}
@ -67,8 +82,8 @@ impl FileSettings {
let mut s = Config::new();
let s = s.merge(File::new(config_path.to_str().unwrap(), FileFormat::Toml));
// No point in returning without a config file.
// TODO: Error and exit instead of panic.
/* No point in returning without a config file.
TODO: Error and exit instead of panic. */
s.unwrap().deserialize().unwrap()
}
}
@ -76,13 +91,13 @@ impl FileSettings {
impl Settings {
pub fn new() -> Settings {
let fs = FileSettings::new();
let mut s: HashMap<String, AccountSettings> = HashMap::new();
let mut s: HashMap<String, AccountConfiguration> = HashMap::new();
for (id, x) in fs.accounts {
let format = x.format.to_lowercase();
let sent_folder = x.sent_folder;
let sent_folder = x.sent_folder.clone();
let threaded = x.threaded;
let root_folder = x.root_folder;
let root_folder = x.root_folder.clone();
let acc = AccountSettings {
name: id.clone(),
@ -92,7 +107,10 @@ impl Settings {
threaded,
};
s.insert(id, acc);
s.insert(id, AccountConfiguration {
account: acc,
conf: x
});
}
Settings {

View File

@ -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.clone(), &backends))
.map(|(n, a_s)| Account::new(n.to_string(), a_s.account().clone(), &backends))
.collect();
accounts.sort_by(|a, b| a.name().cmp(&b.name()));
let (startup_tx, startup_rx) = chan::async();