1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::process::{Command, Output};

/// Sets a boolean value through dconf
pub fn set_boolean(key: &str, value: bool) -> Option<()> {
	set(key, &format!("{}", value))
}

/// Gets a boolean value through dconf
pub fn get_boolean(key: &str) -> Option<bool> {
	Some(get(key)? == "true")
}

/// Sets a string value through dconf
pub fn set_string(key: &str, value: &str) -> Option<()> {
    set(key, &format!("'{}'", value))
}

/// Gets a string value through dconf
pub fn get_string(key: &str) -> Option<String> {
    get(key)
}

/// Sets an int value through dconf
pub fn set_int(key: &str, value: i32) -> Option<()> {
    set(key, &format!("{}", value))
}

/// Gets an int value through dconf
pub fn get_int(key: &str) -> Option<i32> {
    Some(get(key)?.parse::<i32>().unwrap())
}

/// Sets a uint value through dconf
pub fn set_uint(key: &str, value: u32) -> Option<()> {
    set(key, &format!("{}", value))
}

/// Gets a uint value through dconf
pub fn get_uint(key: &str) -> Option<u32> {
    Some(get(key)?.parse::<u32>().unwrap())
}

/// Sets a double value through dconf
pub fn set_double(key: &str, value: f64) -> Option<()> {
    set(key, &format!("{}", value))
}

/// Gets a double value through dconf
pub fn get_double(key: &str) -> Option<f64> {
    Some(get(key)?.parse::<f64>().unwrap())
}


// Helpers
fn get(key: &str) -> Option<String> {
    let mut cmd = Command::new("dconf");
	cmd.args(&["read", key]);
	Some(get_stdout(cmd.output().unwrap()))
}

fn set(key: &str, value: &str) -> Option<()>{
    let mut cmd = Command::new("dconf");
	cmd.args(&["write", key, value]);
	match cmd.output() {
		Ok(_) => Some(()),
		Err(e) => None,
	}
}

fn get_stdout(output: Output) -> String {
	let vs = output.stdout;
	String::from_utf8(vs).unwrap().replace("\'", "").replace("\n", "")
}