Update
This commit is contained in:
parent
d12d43f404
commit
a6201df328
@ -12,7 +12,7 @@ use std::cell::RefCell;
|
|||||||
use libc;
|
use libc;
|
||||||
use audio::*;
|
use audio::*;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use std::path;
|
use std::path::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ struct AudioPix {
|
|||||||
|
|
||||||
|
|
||||||
impl AudioPix {
|
impl AudioPix {
|
||||||
pub fn new(size: i32) -> Result<AudioPix> {
|
pub fn new_from_theme(size: i32) -> Result<AudioPix> {
|
||||||
let theme: gtk::IconTheme =
|
let theme: gtk::IconTheme =
|
||||||
gtk::IconTheme::get_default().ok_or("Couldn't get default icon theme")?;
|
gtk::IconTheme::get_default().ok_or("Couldn't get default icon theme")?;
|
||||||
let pix = AudioPix {
|
let pix = AudioPix {
|
||||||
@ -82,6 +82,19 @@ impl AudioPix {
|
|||||||
return Ok(pix);
|
return Ok(pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_from_pnmixer() -> Result<AudioPix> {
|
||||||
|
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 {
|
pub fn select_pix(&self, vol_level: VolLevel) -> &gdk_pixbuf::Pixbuf {
|
||||||
match vol_level {
|
match vol_level {
|
||||||
VolLevel::Muted => &self.muted,
|
VolLevel::Muted => &self.muted,
|
||||||
@ -105,7 +118,7 @@ fn pixbuf_new_from_theme(icon_name: &str,
|
|||||||
|
|
||||||
debug!("Loading stock icon {} from {:?}",
|
debug!("Loading stock icon {} from {:?}",
|
||||||
icon_name,
|
icon_name,
|
||||||
icon_info.get_filename().unwrap_or(path::PathBuf::new()));
|
icon_info.get_filename().unwrap_or(PathBuf::new()));
|
||||||
|
|
||||||
// TODO: propagate error
|
// TODO: propagate error
|
||||||
let pixbuf = icon_info.load_icon().unwrap();
|
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<gdk_pixbuf::Pixbuf> {
|
||||||
|
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) {
|
fn update_tray_icon(audio_pix: &AudioPix, appstate: &AppS) {
|
||||||
let status_icon = &appstate.gui.status_icon;
|
let status_icon = &appstate.gui.status_icon;
|
||||||
let pixbuf = audio_pix.select_pix(appstate.audio.vol_level());
|
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<AppS>) {
|
pub fn init_tray_icon(appstate: Rc<AppS>) {
|
||||||
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);
|
update_tray_icon(&audio_pix.borrow(), &appstate);
|
||||||
|
|
||||||
/* connect audio handler */
|
/* connect audio handler */
|
||||||
@ -240,7 +270,7 @@ fn on_tray_icon_size_changed(appstate: &AppS,
|
|||||||
|
|
||||||
{
|
{
|
||||||
let mut pix = audio_pix.borrow_mut();
|
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);
|
update_tray_icon(&audio_pix.borrow(), &appstate);
|
||||||
|
Loading…
Reference in New Issue
Block a user