Browse Source

initial version

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
bboozzoo/maybe-rust
Maciek Borzecki 5 years ago
parent
commit
d2e75a1f69
9 changed files with 159 additions and 0 deletions
  1. +7
    -0
      Cargo.toml
  2. +9
    -0
      kdeconnect/Cargo.toml
  3. +11
    -0
      kdeconnect/src/lib.rs
  4. +20
    -0
      mconnect/Cargo.toml
  5. +33
    -0
      mconnect/src/app.rs
  6. +55
    -0
      mconnect/src/config.rs
  7. +12
    -0
      mconnect/src/main.rs
  8. +9
    -0
      mconnectctl/Cargo.toml
  9. +3
    -0
      mconnectctl/src/main.rs

+ 7
- 0
Cargo.toml View File

@ -0,0 +1,7 @@
[workspace]
members = [
"mconnect",
"mconnectctl",
"kdeconnect",
]

+ 9
- 0
kdeconnect/Cargo.toml View File

@ -0,0 +1,9 @@
[package]
name = "kdeconnect"
version = "0.1.0"
authors = ["Maciek Borzecki <maciek.borzecki@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

+ 11
- 0
kdeconnect/src/lib.rs View File

@ -0,0 +1,11 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub fn bang() {
println!("bang!");
}

+ 20
- 0
mconnect/Cargo.toml View File

@ -0,0 +1,20 @@
[package]
name = "mconnect"
version = "0.1.0"
authors = ["Maciek Borzecki <maciek.borzecki@gmail.com>"]
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"]

+ 33
- 0
mconnect/src/app.rs View File

@ -0,0 +1,33 @@
use std::path::PathBuf;
use glib;
use super::config;
extern crate kdeconnect;
fn user_config_path() -> Result<PathBuf, String> {
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(())
}

+ 55
- 0
mconnect/src/config.rs View File

@ -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<T: AsRef<Path>>(path: T) -> Result<Config, String> {
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::<glib::FileError>() {
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());
}
}

+ 12
- 0
mconnect/src/main.rs View File

@ -0,0 +1,12 @@
mod app;
mod config;
fn main() {
std::process::exit(match app::run() {
Ok(_) => 0,
Err(err) => {
eprintln!("error: {}", err);
1
}
});
}

+ 9
- 0
mconnectctl/Cargo.toml View File

@ -0,0 +1,9 @@
[package]
name = "mconnectctl"
version = "0.1.0"
authors = ["Maciek Borzecki <maciek.borzecki@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

+ 3
- 0
mconnectctl/src/main.rs View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

Loading…
Cancel
Save