diff --git a/src/ui_tray_icon.rs b/src/ui_tray_icon.rs index 4e6d56065..dfb495385 100644 --- a/src/ui_tray_icon.rs +++ b/src/ui_tray_icon.rs @@ -12,7 +12,7 @@ use std::cell::RefCell; use libc; use audio::*; use errors::*; -use std::path; +use std::path::*; @@ -63,7 +63,7 @@ struct AudioPix { impl AudioPix { - pub fn new(size: i32) -> Result { + pub fn new_from_theme(size: i32) -> Result { let theme: gtk::IconTheme = gtk::IconTheme::get_default().ok_or("Couldn't get default icon theme")?; let pix = AudioPix { @@ -82,6 +82,19 @@ impl AudioPix { return Ok(pix); } + pub fn new_from_pnmixer() -> Result { + gtk::IconTheme::get_default().ok_or("Couldn't get default icon theme")?; + let pix = AudioPix { + muted: pixbuf_new_from_file("pnmixer-muted.png")?, + low: pixbuf_new_from_file("pnmixer-low.png")?, + medium: pixbuf_new_from_file("pnmixer-medium.png")?, + high: pixbuf_new_from_file("pnmixer-high.png")?, + off: pixbuf_new_from_file("pnmixer-off.png")?, + }; + + return Ok(pix); + } + pub fn select_pix(&self, vol_level: VolLevel) -> &gdk_pixbuf::Pixbuf { match vol_level { VolLevel::Muted => &self.muted, @@ -105,7 +118,7 @@ fn pixbuf_new_from_theme(icon_name: &str, debug!("Loading stock icon {} from {:?}", icon_name, - icon_info.get_filename().unwrap_or(path::PathBuf::new())); + icon_info.get_filename().unwrap_or(PathBuf::new())); // TODO: propagate error let pixbuf = icon_info.load_icon().unwrap(); @@ -114,6 +127,23 @@ fn pixbuf_new_from_theme(icon_name: &str, } +fn pixbuf_new_from_file(filename: &str) -> Result { + ensure!(!filename.is_empty(), "Filename is empty"); + + let s = format!("./data/pixmaps/{}", filename); + let path = Path::new(s.as_str()); + + if path.exists() { + let str_path = path.to_str().ok_or("Path is not valid unicode")?; + + // TODO: propagate error + return Ok(gdk_pixbuf::Pixbuf::new_from_file(str_path).unwrap()); + } else { + bail!("Uh-oh"); + } +} + + fn update_tray_icon(audio_pix: &AudioPix, appstate: &AppS) { let status_icon = &appstate.gui.status_icon; let pixbuf = audio_pix.select_pix(appstate.audio.vol_level()); @@ -122,7 +152,7 @@ fn update_tray_icon(audio_pix: &AudioPix, appstate: &AppS) { pub fn init_tray_icon(appstate: Rc) { - let audio_pix = Rc::new(RefCell::new(try_w!(AudioPix::new(ICON_MIN_SIZE)))); + let audio_pix = Rc::new(RefCell::new(try_w!(AudioPix::new_from_pnmixer()))); update_tray_icon(&audio_pix.borrow(), &appstate); /* connect audio handler */ @@ -240,7 +270,7 @@ fn on_tray_icon_size_changed(appstate: &AppS, { let mut pix = audio_pix.borrow_mut(); - *pix = try_wr!(AudioPix::new(size), false); + *pix = try_wr!(AudioPix::new_from_pnmixer(), false); } update_tray_icon(&audio_pix.borrow(), &appstate);