Fix some TODOs

This commit is contained in:
Julian Ospald 2017-07-12 16:26:41 +02:00
parent 4c09eabfd2
commit b4ad4bf93e
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
6 changed files with 40 additions and 30 deletions

View File

@ -92,9 +92,6 @@ impl AlsaCard {
cb: cb,
});
/* TODO: callback is registered here, which must be unregistered
* when the card is destroyed!!
* poll descriptors must be unwatched too */
let watch_ids = AlsaCard::watch_poll_descriptors(vec_pollfd,
acard.as_ref());
acard.watch_ids.set(watch_ids);
@ -199,7 +196,6 @@ impl AlsaCard {
}
// TODO: test that this is actually triggered when switching cards
impl Drop for AlsaCard {
// call Box::new(x), transmute the Box into a raw pointer, and then
// std::mem::forget
@ -258,7 +254,6 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
debug!("G_IO_STATUS_AGAIN");
continue;
}
// TODO: handle these failure cases
glib_sys::G_IO_STATUS_NORMAL => {
error!("Alsa failed to clear the channel");
cb(AlsaEvent::AlsaCardError);

View File

@ -181,6 +181,21 @@ impl Audio {
*rc = glib::get_monotonic_time();
}
let alsa_vol = percent_to_vol(new_vol,
self.acard.borrow().get_volume_range(),
dir)?;
/* only invoke handlers etc. if volume did actually change */
{
let old_alsa_vol = percent_to_vol(self.vol()?,
self.acard.borrow().get_volume_range(),
dir)?;
if old_alsa_vol == alsa_vol {
return Ok(());
}
}
/* auto-unmute */
if self.has_mute() && self.get_mute()? {
self.set_mute(false, user)?;
@ -198,14 +213,10 @@ impl Audio {
new_vol,
user);
let alsa_vol = percent_to_vol(new_vol,
self.acard.borrow().get_volume_range(),
dir)?;
self.acard
.borrow()
.set_vol(alsa_vol)?;
// TODO: only invoke handlers if volume did not change
invoke_handlers(&self.handlers.borrow(),
AudioSignal::ValuesChanged,
user);
@ -313,7 +324,6 @@ fn on_alsa_event(last_action_timestamp: &mut i64,
/* external change */
match alsa_event {
// TODO: invoke handlers with AudioUserUnknown
AlsaEvent::AlsaCardError => {
invoke_handlers(handlers,
self::AudioSignal::CardError,

View File

@ -101,17 +101,17 @@ impl Default for ViewPrefs {
#[derive(Deserialize, Debug, Serialize)]
#[serde(default)]
pub struct VolColor {
pub red: u8,
pub green: u8,
pub blue: u8,
pub red: f64,
pub green: f64,
pub blue: f64,
}
impl Default for VolColor {
fn default() -> VolColor {
return VolColor {
red: 245,
green: 180,
blue: 0,
red: 0.960784313725,
green: 0.705882352941,
blue: 0.0,
};
}
}

View File

@ -3,6 +3,7 @@ use errors::*;
use prefs::*;
#[derive(Clone, Copy, Debug)]
pub enum VolDir {
Up,
Down,

View File

@ -111,11 +111,10 @@ impl PrefsDialog {
self.vol_meter_pos_spin.set_value(prefs.view_prefs.vol_meter_offset as
f64);
// TODO don't convert like that
let rgba = gdk::RGBA {
red: prefs.view_prefs.vol_meter_color.red as f64 / 255.0,
green: prefs.view_prefs.vol_meter_color.green as f64 / 255.0,
blue: prefs.view_prefs.vol_meter_color.blue as f64 / 255.0,
red: prefs.view_prefs.vol_meter_color.red,
green: prefs.view_prefs.vol_meter_color.green,
blue: prefs.view_prefs.vol_meter_color.blue,
alpha: 1.0,
};
self.vol_meter_color_button.set_rgba(&rgba);
@ -162,22 +161,27 @@ impl PrefsDialog {
fn to_prefs(&self) -> Prefs {
// TODO: remove duplication with default instance
let card = self.card_combo.get_active_text();
let channel = self.chan_combo.get_active_text();
if card.is_none() || channel.is_none() {
return Prefs::default();
}
let device_prefs =
DevicePrefs {
card: self.card_combo
.get_active_text()
.unwrap_or(String::from("(default)")),
.unwrap(),
channel: self.chan_combo
.get_active_text()
.unwrap_or(String::from("Master")),
.unwrap(),
};
// TODO save raw values?
let vol_meter_color = VolColor {
red: (self.vol_meter_color_button.get_rgba().red * 255.0) as u8,
green: (self.vol_meter_color_button.get_rgba().green * 255.0) as u8,
blue: (self.vol_meter_color_button.get_rgba().blue * 255.0) as u8,
red: (self.vol_meter_color_button.get_rgba().red),
green: (self.vol_meter_color_button.get_rgba().green),
blue: (self.vol_meter_color_button.get_rgba().blue),
};
let view_prefs = ViewPrefs {

View File

@ -159,9 +159,9 @@ pub struct VolMeter {
impl VolMeter {
fn new(prefs: &Prefs) -> VolMeter {
return VolMeter {
red: prefs.view_prefs.vol_meter_color.red,
green: prefs.view_prefs.vol_meter_color.green,
blue: prefs.view_prefs.vol_meter_color.blue,
red: (prefs.view_prefs.vol_meter_color.red * 255.0) as u8,
green: (prefs.view_prefs.vol_meter_color.green * 255.0) as u8,
blue: (prefs.view_prefs.vol_meter_color.blue * 255.0) as u8,
x_offset_pct: prefs.view_prefs.vol_meter_offset as i64,
y_offset_pct: 10,
/* dynamic */