use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
pub struct Format {
pub name: String,
pub extensions: Vec<String>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct SpecialPages {
pub home: Option<String>,
pub search: Option<String>,
pub wiki: Option<String>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Handlers {
pub browser: Option<String>,
#[serde(rename = "file-manager")]
pub file_manager: Option<String>,
pub command: Option<String>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct DomainCode {
pub code: char,
pub value: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Settings {
#[serde(rename = "default-category")]
pub default_category: Option<String>,
#[serde(rename = "create-missing-category")]
pub create_missing_category: Option<bool>,
pub autoselect: Option<bool>,
#[serde(rename = "save-with-shortcuts")]
pub save_with_shortcuts: Option<bool>,
#[serde(rename = "script-dir")]
pub script_dir: Option<String>,
#[serde(rename = "special-pages")]
pub special_pages: Option<SpecialPages>,
pub handlers: Option<Handlers>,
pub formats: Option<Vec<Format>>,
#[serde(rename = "domain-codes")]
pub domain_codes: Option<Vec<DomainCode>>,
}
pub enum DataProvider {
Configuration,
Bookmarks,
HelpFile,
}
impl DataProvider {
pub fn new(filename: &str) -> Self {
match filename {
"help" => Self::HelpFile,
"bookmarks" => Self::Bookmarks,
"config" => Self::Configuration,
_ => {
eprintln!("Unknown data requested");
std::process::exit(3);
}
}
}
fn config_data(&self) -> Vec<u8> {
br#"default-category = "default"
create-missing-category = false
autoselect = true
save-with-shortcuts = true
script-dir = "scripts"
[special-pages]
home = "hi"
search = "google"
wiki = "arch-wiki"
[protocols]
browser = "firefox"
file-manager = "caja"
command = "bash"
[[domain-codes]]
code = "b"
value = "blog"
[[domain-codes]]
code = "w"
value = "wiki"
[[formats]]
name = "vim"
extensions = ["txt","c","conf"]
[[formats]]
name = "libreoffice"
extensions = ["odf","odt","docx","doc","xls","xlsx","ppt","pptx"]
[[formats]]
name = "emacs"
extensions = ["rs","md","asciidoc","adoc","xml"]
[[formats]]
name = "vlc"
extensions = ["m3u","mp4","mpg","m4a","mkv","opus"]
[[formats]]
name = "mpv"
extensions = ["mp3","ogg"]
[[formats]]
name = "firefox"
extensions = ["html"]
[[formats]]
name = "chromium"
extensions = ["mhtml"]
"#
.to_vec()
}
fn help_data(&self) -> Vec<u8> {
br#"Help file to be placed here"#.to_vec()
}
fn bookmark_data(&self) -> Vec<u8> {
br#"#!<@access-computing.com>
hi: <@hlg{*default}>
blog <@b*>
debian: <@debian.org>
arch: <@archlinux.org>
# A distro that focuses on accessibility
slint: <@=slint.fr/>
watch <@distrowatch.com>
_accessibility <@w{/debian}/accessibility>
_news: <@9to5linux.com/>
linux <@{*wikipedia}/Linux>
itsfoss(s): <@itsfoss.com/>
technix(x): <@ostechnix.com/>
tecmint(m) <@=tecmint.com/>
docs: <~/Documents>
music: <~/Music>
# The Common Unix Printing Server [cups]
printing <@#631>
# Google search [search find googling]
google? <@google.com>
ddg? <@duckduckgo.com>
bing? <@bing.com>
# The largest source of info on Linux on the web [archie linux-info]
arch-wiki+ <@w{arch}/title>
debian-wiki+ <@w{debian}>
# Free English encyclopedia [reference dictionary wikipedia wiki]
wikipedia+ <@en.wikipedia.org/wiki>
# Tell the time [clock date daytime now]
time: <:!echo "Its `date +%H:%M`"> :bash(-c)
"#
.to_vec()
}
pub fn data(&self) -> Vec<u8> {
match self {
Self::Bookmarks => self.bookmark_data(),
Self::Configuration => self.config_data(),
Self::HelpFile => self.help_data(),
}
}
}