Blubb
This commit is contained in:
parent
00ffe55ecd
commit
973e6a0257
@ -22,6 +22,7 @@ toml = "^0.4.2"
|
||||
serde_derive = "^1.0.9"
|
||||
serde = "^1.0.9"
|
||||
xdg = "*"
|
||||
which = "*"
|
||||
|
||||
[dependencies.gtk]
|
||||
git = "https://github.com/gtk-rs/gtk.git"
|
||||
|
@ -26,6 +26,7 @@ extern crate gobject_sys;
|
||||
extern crate gtk;
|
||||
extern crate gtk_sys;
|
||||
extern crate libc;
|
||||
extern crate which;
|
||||
extern crate xdg;
|
||||
|
||||
use std::rc::Rc;
|
||||
@ -65,10 +66,10 @@ fn main() {
|
||||
let apps = Rc::new(AppS::new());
|
||||
|
||||
let mut prefs = prefs::Prefs::new().unwrap();
|
||||
println!("Channel: {:?}", prefs.to_str());
|
||||
println!("Channel: {}", prefs.to_str());
|
||||
prefs.store_config();
|
||||
|
||||
// println!("Channel: {:?}", prefs.to_str());
|
||||
println!("Control_cmd: {:?}", prefs.get_avail_vol_control_cmd());
|
||||
|
||||
ui_entry::init(apps);
|
||||
|
||||
|
58
src/prefs.rs
58
src/prefs.rs
@ -1,8 +1,12 @@
|
||||
use errors::*;
|
||||
use toml;
|
||||
use xdg;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std;
|
||||
use toml;
|
||||
use which;
|
||||
use xdg;
|
||||
|
||||
|
||||
|
||||
@ -28,17 +32,6 @@ impl Default for MiddleClickAction {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Prefs {
|
||||
pub device_prefs: DevicePrefs,
|
||||
pub view_prefs: ViewPrefs,
|
||||
pub behavior_prefs: BehaviorPrefs,
|
||||
pub notify_prefs: NotifyPrefs,
|
||||
// TODO: HotKeys?
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct DevicePrefs {
|
||||
@ -101,7 +94,7 @@ impl Default for VolColor {
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct BehaviorPrefs {
|
||||
vol_control_cmd: Option<String>,
|
||||
pub vol_control_cmd: Option<String>,
|
||||
pub vol_scroll_step: f64,
|
||||
pub middle_click_action: MiddleClickAction,
|
||||
// TODO: fine scroll step?
|
||||
@ -142,8 +135,15 @@ impl Default for NotifyPrefs {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Prefs {
|
||||
pub device_prefs: DevicePrefs,
|
||||
pub view_prefs: ViewPrefs,
|
||||
pub behavior_prefs: BehaviorPrefs,
|
||||
pub notify_prefs: NotifyPrefs,
|
||||
// TODO: HotKeys?
|
||||
}
|
||||
|
||||
impl Prefs {
|
||||
pub fn new() -> Result<Prefs> {
|
||||
@ -201,12 +201,32 @@ impl Prefs {
|
||||
}
|
||||
|
||||
|
||||
// TODO: implement
|
||||
pub fn vol_control_cmd() -> String {
|
||||
return String::from("");
|
||||
pub fn get_avail_vol_control_cmd(&self) -> Option<String> {
|
||||
match self.behavior_prefs.vol_control_cmd {
|
||||
Some(ref c) => return Some(c.clone()),
|
||||
None => {
|
||||
for command in VOL_CONTROL_COMMANDS.iter() {
|
||||
if which::which(command).is_ok() {
|
||||
return Some(String::from(*command));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Prefs {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> std::result::Result<(), std::fmt::Error> {
|
||||
let s = self.to_str();
|
||||
return write!(f, "{}", s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn get_xdg_dirs() -> xdg::BaseDirectories {
|
||||
return xdg::BaseDirectories::with_prefix("pnmixer-rs").unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user