diff --git a/src/mpris.rs b/src/mpris.rs index 3b3453c7..a7c32e2d 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -103,31 +103,27 @@ impl MprisControls { } } -fn dict_lookup(dict: &glib::VariantDict, key: &str) -> Option { - dict.lookup_value(key, None)?.get() -} - -fn property(proxy: &gio::DBusProxy, prop: &str) -> Option { - proxy.cached_property(prop)?.get() -} - struct Metadata(glib::VariantDict); impl Metadata { + fn lookup(&self, key: &str) -> Option { + self.0.lookup_value(key, None)?.get() + } + fn title(&self) -> Option { - dict_lookup(&self.0, "xesam:title") + self.lookup("xesam:title") } fn album(&self) -> Option { - dict_lookup(&self.0, "xesam:album") + self.lookup("xesam:album") } fn artist(&self) -> Option> { - dict_lookup(&self.0, "xesam:artist") + self.lookup("xesam:artist") } fn arturl(&self) -> Option { - dict_lookup(&self.0, "mpris:artUrl") + self.lookup("mpris:artUrl") } } @@ -147,6 +143,10 @@ impl Player { Ok(Self(proxy)) } + fn property(&self, prop: &str) -> Option { + self.0.cached_property(prop)?.get() + } + fn connect_properties_changed(&self, f: F) { self.0 .connect_local("g-properties-changed", false, move |_| { @@ -157,11 +157,11 @@ impl Player { } fn playback_status(&self) -> Option { - property(&self.0, "PlayBackStatus") + self.property("PlayBackStatus") } fn metadata(&self) -> Option { - Some(Metadata(property(&self.0, "Metadata")?)) + Some(Metadata(self.property("Metadata")?)) } }