Update to newest gtk-rs crates

Some things were adapted accordingly and some warnings from clippy were
fixed along the way.
This commit is contained in:
Elias Projahn 2021-06-30 20:28:29 +02:00
parent 863c9d19c3
commit 7c9c01d3ea
9 changed files with 359 additions and 406 deletions

View file

@ -5,10 +5,10 @@ edition = "2018"
[dependencies]
fragile = "1.0.0"
gio = "0.9.1"
glib = "0.10.3"
gstreamer = "0.16.4"
gstreamer-player = "0.16.3"
gio = "0.14.0"
glib = "0.14.0"
gstreamer = "0.17.0"
gstreamer-player = "0.17.0"
log = { version = "0.4.14", features = ["std"] }
musicus_client = { version = "0.1.0", path = "../client" }
musicus_database = { version = "0.1.0", path = "../database" }

View file

@ -102,10 +102,9 @@ impl Backend {
pub async fn init(&self) -> Result<()> {
self.init_library().await?;
if let Some(url) = self.settings.get_string("server-url") {
if !url.is_empty() {
self.client.set_server_url(&url);
}
let url = self.settings.string("server-url");
if !url.is_empty() {
self.client.set_server_url(&url);
}
#[cfg(all(feature = "dbus"))]

View file

@ -8,11 +8,10 @@ use std::rc::Rc;
impl Backend {
/// Initialize the music library if it is set in the settings.
pub(super) async fn init_library(&self) -> Result<()> {
if let Some(path) = self.settings.get_string("music-library-path") {
if !path.is_empty() {
self.set_music_library_path_priv(PathBuf::from(path.to_string()))
.await?;
}
let path = self.settings.string("music-library-path");
if !path.is_empty() {
self.set_music_library_path_priv(PathBuf::from(path.to_string()))
.await?;
}
Ok(())

View file

@ -31,7 +31,7 @@ impl Player {
pub fn new(music_library_path: PathBuf) -> Rc<Self> {
let dispatcher = gstreamer_player::PlayerGMainContextSignalDispatcher::new(None);
let player = gstreamer_player::Player::new(None, Some(&dispatcher.upcast()));
let mut config = player.get_config();
let mut config = player.config();
config.set_position_update_interval(250);
player.set_config(config).unwrap();
player.set_video_track_enabled(false);
@ -88,14 +88,14 @@ impl Player {
let clone = fragile::Fragile::new(result.clone());
player.connect_position_updated(move |_, position| {
for cb in &*clone.get().position_cbs.borrow() {
cb(position.mseconds().unwrap());
cb(position.unwrap().mseconds());
}
});
let clone = fragile::Fragile::new(result.clone());
player.connect_duration_changed(move |_, duration| {
for cb in &*clone.get().duration_cbs.borrow() {
cb(duration.mseconds().unwrap());
cb(duration.unwrap().mseconds());
}
});
@ -172,8 +172,8 @@ impl Player {
self.current_track.get()
}
pub fn get_duration(&self) -> gstreamer::ClockTime {
self.player.get_duration()
pub fn get_duration(&self) -> Option<gstreamer::ClockTime> {
self.player.duration()
}
pub fn is_playing(&self) -> bool {
@ -250,9 +250,11 @@ impl Player {
}
pub fn previous(&self) -> Result<()> {
let mut current_track = self.current_track.get().ok_or(Error::Other(String::from(
"Player tried to access non existant current track.",
)))?;
let mut current_track = self.current_track.get().ok_or_else(|| {
Error::Other(String::from(
"Player tried to access non existant current track.",
))
})?;
if current_track > 0 {
current_track -= 1;
@ -273,9 +275,11 @@ impl Player {
}
pub fn next(&self) -> Result<()> {
let mut current_track = self.current_track.get().ok_or(Error::Other(String::from(
"Player tried to access non existant current track.",
)))?;
let mut current_track = self.current_track.get().ok_or_else(|| {
Error::Other(String::from(
"Player tried to access non existant current track.",
))
})?;
let playlist = self.playlist.borrow();
@ -298,10 +302,8 @@ impl Player {
.into_string()
.unwrap();
let uri = glib::filename_to_uri(&path, None).or(Err(Error::Other(format!(
"Failed to create URI from path: {}",
path
))))?;
let uri = glib::filename_to_uri(&path, None)
.map_err(|_| Error::Other(format!("Failed to create URI from path: {}", path)))?;
self.player.set_uri(&uri);
@ -351,7 +353,7 @@ impl Player {
}
for cb in &*self.duration_cbs.borrow() {
cb(self.player.get_duration().mseconds().unwrap());
cb(self.player.duration().unwrap().mseconds());
}
for cb in &*self.playing_cbs.borrow() {