mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Listen for state changes in medium preview
This commit is contained in:
parent
79c86cbb57
commit
bd2d7baee0
1 changed files with 33 additions and 1 deletions
|
|
@ -5,7 +5,7 @@ use glib::clone;
|
|||
use gtk::prelude::*;
|
||||
use gtk_macros::get_widget;
|
||||
use musicus_backend::db::Medium;
|
||||
use musicus_backend::import::ImportSession;
|
||||
use musicus_backend::import::{ImportSession, State};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -14,6 +14,8 @@ pub struct MediumPreview {
|
|||
handle: NavigationHandle<()>,
|
||||
session: Arc<ImportSession>,
|
||||
widget: gtk::Box,
|
||||
import_button: gtk::Button,
|
||||
done_stack: gtk::Stack,
|
||||
}
|
||||
|
||||
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
||||
|
|
@ -34,6 +36,8 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
|||
handle,
|
||||
session,
|
||||
widget,
|
||||
import_button,
|
||||
done_stack,
|
||||
});
|
||||
|
||||
// Connect signals and callbacks
|
||||
|
|
@ -111,10 +115,38 @@ impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
|
|||
medium_box.append(&frame);
|
||||
}
|
||||
|
||||
this.handle_state(&this.session.state());
|
||||
spawn!(@clone this, async move {
|
||||
loop {
|
||||
let state = this.session.state_change().await;
|
||||
this.handle_state(&state);
|
||||
|
||||
match state {
|
||||
State::Ready | State::Error => break,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl MediumPreview {
|
||||
/// Handle a state change of the import process.
|
||||
fn handle_state(&self, state: &State) {
|
||||
match state {
|
||||
State::Waiting => todo!("This shouldn't happen."),
|
||||
State::Copying => self.done_stack.set_visible_child_name("loading"),
|
||||
State::Ready => {
|
||||
self.done_stack.set_visible_child_name("ready");
|
||||
self.import_button.set_sensitive(true);
|
||||
}
|
||||
State::Error => todo!("Import error!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for MediumPreview {
|
||||
fn get_widget(&self) -> gtk::Widget {
|
||||
self.widget.clone().upcast()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue