move config stuff to `ui`
parent
47dd2ed93e
commit
9d5b2a4628
|
@ -8,7 +8,6 @@ workspace = ".."
|
|||
bitflags = "1.0"
|
||||
chan = "0.1.21"
|
||||
chrono = "0.4"
|
||||
config = "0.6"
|
||||
crossbeam = "^0.3.0"
|
||||
data-encoding = "2.1.1"
|
||||
encoding = "0.2.33"
|
||||
|
|
|
@ -19,40 +19,11 @@
|
|||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate config;
|
||||
extern crate serde;
|
||||
extern crate xdg;
|
||||
pub mod pager;
|
||||
|
||||
use pager::PagerSettings;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct FileAccount {
|
||||
root_folder: String,
|
||||
format: String,
|
||||
sent_folder: String,
|
||||
threaded: bool,
|
||||
}
|
||||
|
||||
impl FileAccount {
|
||||
pub fn folder(&self) -> &str {
|
||||
&self.root_folder
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct FileSettings {
|
||||
accounts: HashMap<String, FileAccount>,
|
||||
pager: PagerSettings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AccountSettings {
|
||||
name: String,
|
||||
root_folder: String,
|
||||
format: String,
|
||||
pub name: String,
|
||||
pub root_folder: String,
|
||||
pub format: String,
|
||||
pub sent_folder: String,
|
||||
pub threaded: bool,
|
||||
}
|
||||
|
@ -68,55 +39,3 @@ impl AccountSettings {
|
|||
&self.root_folder
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Settings {
|
||||
pub accounts: HashMap<String, AccountSettings>,
|
||||
pub pager: PagerSettings,
|
||||
}
|
||||
|
||||
use self::config::{Config, File, FileFormat};
|
||||
impl FileSettings {
|
||||
pub fn new() -> FileSettings {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix("meli").unwrap();
|
||||
let config_path = xdg_dirs
|
||||
.place_config_file("config")
|
||||
.expect("cannot create configuration directory");
|
||||
//let setts = Config::default().merge(File::new(config_path.to_str().unwrap_or_default(), config::FileFormat::Toml)).unwrap();
|
||||
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.
|
||||
s.unwrap().deserialize().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new() -> Settings {
|
||||
let fs = FileSettings::new();
|
||||
let mut s: HashMap<String, AccountSettings> = HashMap::new();
|
||||
|
||||
for (id, x) in fs.accounts {
|
||||
let format = x.format.to_lowercase();
|
||||
let sent_folder = x.sent_folder;
|
||||
let threaded = x.threaded;
|
||||
let root_folder = x.root_folder;
|
||||
|
||||
let acc = AccountSettings {
|
||||
name: id.clone(),
|
||||
root_folder,
|
||||
format,
|
||||
sent_folder,
|
||||
threaded,
|
||||
};
|
||||
|
||||
s.insert(id, acc);
|
||||
}
|
||||
|
||||
Settings {
|
||||
accounts: s,
|
||||
pager: fs.pager,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,10 @@ authors = []
|
|||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
xdg = "2.1.0"
|
||||
serde = "1.0.71"
|
||||
serde_derive = "1.0.71"
|
||||
config = "0.6"
|
||||
chan = "0.1.21"
|
||||
chan-signal = "0.3.1"
|
||||
fnv = "1.0.3"
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* meli - configuration module.
|
||||
*
|
||||
* Copyright 2017 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate config;
|
||||
extern crate serde;
|
||||
extern crate xdg;
|
||||
pub mod pager;
|
||||
|
||||
use melib::conf::AccountSettings;
|
||||
use pager::PagerSettings;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct FileAccount {
|
||||
root_folder: String,
|
||||
format: String,
|
||||
sent_folder: String,
|
||||
threaded: bool,
|
||||
folders: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl FileAccount {
|
||||
pub fn folder(&self) -> &str {
|
||||
&self.root_folder
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct FileSettings {
|
||||
accounts: HashMap<String, FileAccount>,
|
||||
pager: PagerSettings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Settings {
|
||||
pub accounts: HashMap<String, AccountSettings>,
|
||||
pub pager: PagerSettings,
|
||||
}
|
||||
|
||||
use self::config::{Config, File, FileFormat};
|
||||
impl FileSettings {
|
||||
pub fn new() -> FileSettings {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix("meli").unwrap();
|
||||
let config_path = xdg_dirs
|
||||
.place_config_file("config")
|
||||
.expect("cannot create configuration directory");
|
||||
//let setts = Config::default().merge(File::new(config_path.to_str().unwrap_or_default(), config::FileFormat::Toml)).unwrap();
|
||||
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.
|
||||
s.unwrap().deserialize().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new() -> Settings {
|
||||
let fs = FileSettings::new();
|
||||
let mut s: HashMap<String, AccountSettings> = HashMap::new();
|
||||
|
||||
for (id, x) in fs.accounts {
|
||||
let format = x.format.to_lowercase();
|
||||
let sent_folder = x.sent_folder;
|
||||
let threaded = x.threaded;
|
||||
let root_folder = x.root_folder;
|
||||
|
||||
let acc = AccountSettings {
|
||||
name: id.clone(),
|
||||
root_folder,
|
||||
format,
|
||||
sent_folder,
|
||||
threaded,
|
||||
};
|
||||
|
||||
s.insert(id, acc);
|
||||
}
|
||||
|
||||
Settings {
|
||||
accounts: s,
|
||||
pager: fs.pager,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ extern crate melib;
|
|||
extern crate mime_apps;
|
||||
extern crate notify_rust;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate chan;
|
||||
extern crate chan_signal;
|
||||
extern crate linkify;
|
||||
|
@ -54,3 +56,6 @@ pub use state::*;
|
|||
|
||||
pub mod components;
|
||||
pub use components::*;
|
||||
|
||||
pub mod conf;
|
||||
pub use conf::*;
|
||||
|
|
Loading…
Reference in New Issue