diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7020d52 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] + +members = [ + "mconnect", + "mconnectctl", + "kdeconnect", + ] \ No newline at end of file diff --git a/kdeconnect/Cargo.toml b/kdeconnect/Cargo.toml new file mode 100644 index 0000000..8ec6125 --- /dev/null +++ b/kdeconnect/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "kdeconnect" +version = "0.1.0" +authors = ["Maciek Borzecki "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/kdeconnect/src/lib.rs b/kdeconnect/src/lib.rs new file mode 100644 index 0000000..a6c14ff --- /dev/null +++ b/kdeconnect/src/lib.rs @@ -0,0 +1,11 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} + +pub fn bang() { + println!("bang!"); +} diff --git a/mconnect/Cargo.toml b/mconnect/Cargo.toml new file mode 100644 index 0000000..8e7b9ef --- /dev/null +++ b/mconnect/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "mconnect" +version = "0.1.0" +authors = ["Maciek Borzecki "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +kdeconnect = { path = "../kdeconnect", version = "" } +log = "0.4" +tempfile = "3.1.0" + +[dependencies.glib] +version = "" +features = ["v2_44"] + +[dependencies.gio] +version = "" +features = ["v2_44"] diff --git a/mconnect/src/app.rs b/mconnect/src/app.rs new file mode 100644 index 0000000..0ebbb67 --- /dev/null +++ b/mconnect/src/app.rs @@ -0,0 +1,33 @@ +use std::path::PathBuf; + +use glib; + +use super::config; + +extern crate kdeconnect; + +fn user_config_path() -> Result { + let user_config_dir = match glib::get_user_config_dir() { + Some(v) => v, + None => return Err(String::from("cannot obtain user config directory")) + }; + + let mut config_path = PathBuf::new(); + + config_path.push(user_config_dir); + config_path.push(config::NAME); + println!("user config dir: {}", config_path.as_path().display()); + Ok(config_path) +} + +pub fn run() -> Result<(), String> { + let config_path = match user_config_path() { + Err(x) => return Err(format!("cannot obtain user config path: {}", x)), + Ok(p) => p + }; + + let c = config::load_from_path(config_path); + + kdeconnect::bang(); + Ok(()) +} diff --git a/mconnect/src/config.rs b/mconnect/src/config.rs new file mode 100644 index 0000000..f3b7a12 --- /dev/null +++ b/mconnect/src/config.rs @@ -0,0 +1,55 @@ +use std::io; +use std::path::Path; + +use glib; + +pub const NAME: &'static str = "mconnect.conf"; + +pub struct Config { + kf: glib::KeyFile, +} + +pub fn load_from_path>(path: T) -> Result { + let kf = glib::KeyFile::new(); + let c = Config { kf: kf }; + + if let Err(err) = c.kf.load_from_file(path, glib::KeyFileFlags::KEEP_COMMENTS) { + match err.kind::() { + Some(glib::FileError::Noent) => { + println!("user config not found, using defaults"); + Ok(c) + } + _ => Err(err.to_string()), + } + } else { + Ok(c) + } +} + +#[cfg(test)] +mod tests { + use std::io::Write; + use tempfile::NamedTempFile; + + #[test] + fn simple_load() { + let mut tmpf = NamedTempFile::new().expect("cannot create a temp file"); + writeln!(tmpf, "").expect("write failed"); + let res = super::load_from_path(tmpf.path()); + assert!(res.is_ok()); + } + + #[test] + fn not_found_not_error() { + let res = super::load_from_path("does-not-exist"); + assert!(res.is_ok()); + } + + #[test] + fn bad_format() { + let mut tmp = NamedTempFile::new().expect("cannot create a temp file"); + writeln!(tmp, "bad-format").expect("write failed"); + let res = super::load_from_path(tmp.path()); + assert!(res.is_err()); + } +} diff --git a/mconnect/src/main.rs b/mconnect/src/main.rs new file mode 100644 index 0000000..5edd5f5 --- /dev/null +++ b/mconnect/src/main.rs @@ -0,0 +1,12 @@ +mod app; +mod config; + +fn main() { + std::process::exit(match app::run() { + Ok(_) => 0, + Err(err) => { + eprintln!("error: {}", err); + 1 + } + }); +} diff --git a/mconnectctl/Cargo.toml b/mconnectctl/Cargo.toml new file mode 100644 index 0000000..32c9c63 --- /dev/null +++ b/mconnectctl/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "mconnectctl" +version = "0.1.0" +authors = ["Maciek Borzecki "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/mconnectctl/src/main.rs b/mconnectctl/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/mconnectctl/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}