mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Use async functions for backend
This commit is contained in:
parent
95f939cb07
commit
711b6d97ff
12 changed files with 346 additions and 420 deletions
|
|
@ -7,6 +7,8 @@ edition = "2018"
|
||||||
anyhow = "1.0.33"
|
anyhow = "1.0.33"
|
||||||
diesel = { version = "1.4.5", features = ["sqlite"] }
|
diesel = { version = "1.4.5", features = ["sqlite"] }
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
|
futures = "0.3.6"
|
||||||
|
futures-channel = "0.3.5"
|
||||||
gio = "0.9.1"
|
gio = "0.9.1"
|
||||||
glib = "0.10.2"
|
glib = "0.10.2"
|
||||||
gtk = { version = "0.9.2", features = ["v3_24"] }
|
gtk = { version = "0.9.2", features = ["v3_24"] }
|
||||||
|
|
|
||||||
347
src/backend.rs
347
src/backend.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use super::database::*;
|
use super::database::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use glib::Sender;
|
use futures_channel::oneshot;
|
||||||
|
use futures_channel::oneshot::Sender;
|
||||||
|
|
||||||
enum BackendAction {
|
enum BackendAction {
|
||||||
UpdatePerson(Person, Sender<Result<()>>),
|
UpdatePerson(Person, Sender<Result<()>>),
|
||||||
|
|
@ -157,265 +158,123 @@ impl Backend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_person<F: Fn(Result<()>) -> () + 'static>(&self, person: Person, callback: F) {
|
pub async fn update_person(&self, person: Person) -> Result<()> {
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(UpdatePerson(person, sender));
|
||||||
receiver.attach(None, move |result| {
|
receiver.await?
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(UpdatePerson(person, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_person<F: Fn(Result<Person>) -> () + 'static>(&self, id: i64, callback: F) {
|
pub async fn get_person(&self, id: i64) -> Result<Person> {
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetPerson(id, sender));
|
||||||
receiver.attach(None, move |result| {
|
receiver.await?
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetPerson(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_person<F: Fn(Result<()>) -> () + 'static>(&self, id: i64, callback: F) {
|
pub async fn delete_person(&self, id: i64) -> Result<()> {
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(DeletePerson(id, sender));
|
||||||
receiver.attach(None, move |result| {
|
receiver.await?
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(DeletePerson(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_persons<F: Fn(Result<Vec<Person>>) -> () + 'static>(&self, callback: F) {
|
pub async fn get_persons(&self) -> Result<Vec<Person>> {
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetPersons(sender));
|
||||||
receiver.attach(None, move |result| {
|
receiver.await?
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetPersons(sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_instrument<F: Fn(Result<()>) -> () + 'static>(
|
pub async fn update_instrument(&self, instrument: Instrument) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender
|
||||||
|
.send(UpdateInstrument(instrument, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_instrument(&self, id: i64) -> Result<Instrument> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetInstrument(id, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_instrument(&self, id: i64) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(DeleteInstrument(id, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_instruments(&self) -> Result<Vec<Instrument>> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetInstruments(sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_work(&self, work_insertion: WorkInsertion) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(UpdateWork(work_insertion, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_work_descriptions(&self, person_id: i64) -> Result<Vec<WorkDescription>> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender
|
||||||
|
.send(GetWorkDescriptions(person_id, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_ensemble(&self, ensemble: Ensemble) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(UpdateEnsemble(ensemble, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_ensemble(&self, id: i64) -> Result<Ensemble> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetEnsemble(id, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_ensemble(&self, id: i64) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(DeleteEnsemble(id, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_ensembles(&self) -> Result<Vec<Ensemble>> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender.send(GetEnsembles(sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_recording(&self, recording_insertion: RecordingInsertion) -> Result<()> {
|
||||||
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
self.action_sender
|
||||||
|
.send(UpdateRecording(recording_insertion, sender));
|
||||||
|
receiver.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_recordings_for_person(
|
||||||
&self,
|
&self,
|
||||||
instrument: Instrument,
|
person_id: i64,
|
||||||
callback: F,
|
) -> Result<Vec<RecordingDescription>> {
|
||||||
) {
|
let (sender, receiver) = oneshot::channel();
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
self.action_sender
|
||||||
.send(UpdateInstrument(instrument, sender))
|
.send(GetRecordingsForPerson(person_id, sender));
|
||||||
.expect("Failed to send action to database thread!");
|
receiver.await?
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_instrument<F: Fn(Result<Instrument>) -> () + 'static>(&self, id: i64, callback: F) {
|
pub async fn get_recordings_for_ensemble(
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetInstrument(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_instrument<F: Fn(Result<()>) -> () + 'static>(&self, id: i64, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(DeleteInstrument(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_instruments<F: Fn(Result<Vec<Instrument>>) -> () + 'static>(&self, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetInstruments(sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_work<F: Fn(Result<()>) -> () + 'static>(&self, work: WorkInsertion, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(UpdateWork(work, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_work_descriptions<F: Fn(Result<Vec<WorkDescription>>) -> () + 'static>(
|
|
||||||
&self,
|
&self,
|
||||||
id: i64,
|
ensemble_id: i64,
|
||||||
callback: F,
|
) -> Result<Vec<RecordingDescription>> {
|
||||||
) {
|
let (sender, receiver) = oneshot::channel();
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
self.action_sender
|
||||||
.send(GetWorkDescriptions(id, sender))
|
.send(GetRecordingsForEnsemble(ensemble_id, sender));
|
||||||
.expect("Failed to send action to database thread!");
|
receiver.await?
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_ensemble<F: Fn(Result<()>) -> () + 'static>(
|
pub async fn get_recordings_for_work(&self, work_id: i64) -> Result<Vec<RecordingDescription>> {
|
||||||
&self,
|
let (sender, receiver) = oneshot::channel();
|
||||||
ensemble: Ensemble,
|
|
||||||
callback: F,
|
|
||||||
) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
self.action_sender
|
||||||
.send(UpdateEnsemble(ensemble, sender))
|
.send(GetRecordingsForWork(work_id, sender));
|
||||||
.expect("Failed to send action to database thread!");
|
receiver.await?
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_ensemble<F: Fn(Result<Ensemble>) -> () + 'static>(&self, id: i64, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetEnsemble(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_ensemble<F: Fn(Result<()>) -> () + 'static>(&self, id: i64, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel::<Result<()>>(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(DeleteEnsemble(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_ensembles<F: Fn(Result<Vec<Ensemble>>) -> () + 'static>(&self, callback: F) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetEnsembles(sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_recording<F: Fn(Result<()>) -> () + 'static>(
|
|
||||||
&self,
|
|
||||||
recording: RecordingInsertion,
|
|
||||||
callback: F,
|
|
||||||
) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(UpdateRecording(recording, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_recordings_for_person<F: Fn(Result<Vec<RecordingDescription>>) -> () + 'static>(
|
|
||||||
&self,
|
|
||||||
id: i64,
|
|
||||||
callback: F,
|
|
||||||
) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetRecordingsForPerson(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_recordings_for_ensemble<F: Fn(Result<Vec<RecordingDescription>>) -> () + 'static>(
|
|
||||||
&self,
|
|
||||||
id: i64,
|
|
||||||
callback: F,
|
|
||||||
) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetRecordingsForEnsemble(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_recordings_for_work<F: Fn(Result<Vec<RecordingDescription>>) -> () + 'static>(
|
|
||||||
&self,
|
|
||||||
id: i64,
|
|
||||||
callback: F,
|
|
||||||
) {
|
|
||||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
|
||||||
|
|
||||||
receiver.attach(None, move |result| {
|
|
||||||
callback(result);
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action_sender
|
|
||||||
.send(GetRecordingsForWork(id, sender))
|
|
||||||
.expect("Failed to send action to database thread!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub struct EnsembleEditor<F>
|
||||||
where
|
where
|
||||||
F: Fn(Ensemble) -> () + 'static,
|
F: Fn(Ensemble) -> () + 'static,
|
||||||
{
|
{
|
||||||
|
backend: Rc<Backend>,
|
||||||
window: gtk::Window,
|
window: gtk::Window,
|
||||||
callback: F,
|
callback: F,
|
||||||
id: i64,
|
id: i64,
|
||||||
|
|
@ -42,6 +43,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = Rc::new(EnsembleEditor {
|
let result = Rc::new(EnsembleEditor {
|
||||||
|
backend: backend,
|
||||||
window: window,
|
window: window,
|
||||||
callback: callback,
|
callback: callback,
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -58,10 +60,13 @@ where
|
||||||
name: result.name_entry.get_text().to_string(),
|
name: result.name_entry.get_text().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
backend.update_ensemble(ensemble.clone(), clone!(@strong result => move |_| {
|
let clone = result.clone();
|
||||||
result.window.close();
|
let c = glib::MainContext::default();
|
||||||
(result.callback)(ensemble.clone());
|
c.spawn_local(async move {
|
||||||
}));
|
clone.backend.update_ensemble(ensemble.clone()).await.unwrap();
|
||||||
|
clone.window.close();
|
||||||
|
(clone.callback)(ensemble.clone());
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
result.window.set_transient_for(Some(parent));
|
result.window.set_transient_for(Some(parent));
|
||||||
|
|
|
||||||
|
|
@ -41,40 +41,40 @@ where
|
||||||
list: list,
|
list: list,
|
||||||
});
|
});
|
||||||
|
|
||||||
result
|
let c = glib::MainContext::default();
|
||||||
.backend
|
let clone = result.clone();
|
||||||
.get_ensembles(clone!(@strong result => move |ensembles| {
|
c.spawn_local(async move {
|
||||||
let ensembles = ensembles.unwrap();
|
let ensembles = clone.backend.get_ensembles().await.unwrap();
|
||||||
|
|
||||||
for (index, ensemble) in ensembles.iter().enumerate() {
|
for (index, ensemble) in ensembles.iter().enumerate() {
|
||||||
let label = gtk::Label::new(Some(&ensemble.name));
|
let label = gtk::Label::new(Some(&ensemble.name));
|
||||||
label.set_halign(gtk::Align::Start);
|
label.set_halign(gtk::Align::Start);
|
||||||
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||||
row.show_all();
|
row.show_all();
|
||||||
result.list.insert(&row, -1);
|
clone.list.insert(&row, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
clone.list.connect_row_activated(
|
||||||
.list
|
clone!(@strong clone, @strong ensembles => move |_, row| {
|
||||||
.connect_row_activated(clone!(@strong result, @strong ensembles => move |_, row| {
|
clone.window.close();
|
||||||
result.window.close();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
(clone.callback)(ensembles[index].clone());
|
||||||
(result.callback)(ensembles[index].clone());
|
}),
|
||||||
}));
|
);
|
||||||
|
|
||||||
result
|
clone
|
||||||
.list
|
.list
|
||||||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
.set_filter_func(Some(Box::new(clone!(@strong clone => move |row| {
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let search = result.search_entry.get_text().to_string().to_lowercase();
|
let search = clone.search_entry.get_text().to_string().to_lowercase();
|
||||||
search.is_empty() || ensembles[index]
|
search.is_empty() || ensembles[index]
|
||||||
.name
|
.name
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.contains(&search)
|
.contains(&search)
|
||||||
}))));
|
}))));
|
||||||
}));
|
});
|
||||||
|
|
||||||
result
|
result
|
||||||
.search_entry
|
.search_entry
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub struct InstrumentEditor<F>
|
||||||
where
|
where
|
||||||
F: Fn(Instrument) -> () + 'static,
|
F: Fn(Instrument) -> () + 'static,
|
||||||
{
|
{
|
||||||
|
backend: Rc<Backend>,
|
||||||
window: gtk::Window,
|
window: gtk::Window,
|
||||||
callback: F,
|
callback: F,
|
||||||
id: i64,
|
id: i64,
|
||||||
|
|
@ -42,6 +43,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = Rc::new(InstrumentEditor {
|
let result = Rc::new(InstrumentEditor {
|
||||||
|
backend: backend,
|
||||||
window: window,
|
window: window,
|
||||||
callback: callback,
|
callback: callback,
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -58,10 +60,13 @@ where
|
||||||
name: result.name_entry.get_text().to_string(),
|
name: result.name_entry.get_text().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
backend.update_instrument(instrument.clone(), clone!(@strong result => move |_| {
|
let c = glib::MainContext::default();
|
||||||
result.window.close();
|
let clone = result.clone();
|
||||||
(result.callback)(instrument.clone());
|
c.spawn_local(async move {
|
||||||
}));
|
clone.backend.update_instrument(instrument.clone()).await.unwrap();
|
||||||
|
clone.window.close();
|
||||||
|
(clone.callback)(instrument.clone());
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
result.window.set_transient_for(Some(parent));
|
result.window.set_transient_for(Some(parent));
|
||||||
|
|
|
||||||
|
|
@ -41,41 +41,41 @@ where
|
||||||
list: list,
|
list: list,
|
||||||
});
|
});
|
||||||
|
|
||||||
result
|
let c = glib::MainContext::default();
|
||||||
.backend
|
let clone = result.clone();
|
||||||
.get_instruments(clone!(@strong result => move |instruments| {
|
c.spawn_local(async move {
|
||||||
let instruments = instruments.unwrap();
|
let instruments = clone.backend.get_instruments().await.unwrap();
|
||||||
|
|
||||||
for (index, instrument) in instruments.iter().enumerate() {
|
for (index, instrument) in instruments.iter().enumerate() {
|
||||||
let label = gtk::Label::new(Some(&instrument.name));
|
let label = gtk::Label::new(Some(&instrument.name));
|
||||||
label.set_halign(gtk::Align::Start);
|
label.set_halign(gtk::Align::Start);
|
||||||
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||||
row.show_all();
|
row.show_all();
|
||||||
result.list.insert(&row, -1);
|
clone.list.insert(&row, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
clone.list.connect_row_activated(
|
||||||
.list
|
clone!(@strong clone, @strong instruments => move |_, row| {
|
||||||
.connect_row_activated(clone!(@strong result, @strong instruments => move |_, row| {
|
clone.window.close();
|
||||||
result.window.close();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
(clone.callback)(instruments[index].clone());
|
||||||
(result.callback)(instruments[index].clone());
|
}),
|
||||||
}));
|
);
|
||||||
|
|
||||||
result
|
clone
|
||||||
.list
|
.list
|
||||||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
.set_filter_func(Some(Box::new(clone!(@strong clone => move |row| {
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let search = result.search_entry.get_text().to_string();
|
let search = clone.search_entry.get_text().to_string();
|
||||||
|
|
||||||
search.is_empty() || instruments[index]
|
search.is_empty() || instruments[index]
|
||||||
.name
|
.name
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.contains(&result.search_entry.get_text().to_string().to_lowercase())
|
.contains(&clone.search_entry.get_text().to_string().to_lowercase())
|
||||||
}))));
|
}))));
|
||||||
}));
|
});
|
||||||
|
|
||||||
result
|
result
|
||||||
.search_entry
|
.search_entry
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub struct PersonEditor<F>
|
||||||
where
|
where
|
||||||
F: Fn(Person) -> () + 'static,
|
F: Fn(Person) -> () + 'static,
|
||||||
{
|
{
|
||||||
|
backend: Rc<Backend>,
|
||||||
window: gtk::Window,
|
window: gtk::Window,
|
||||||
callback: F,
|
callback: F,
|
||||||
id: i64,
|
id: i64,
|
||||||
|
|
@ -44,6 +45,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = Rc::new(PersonEditor {
|
let result = Rc::new(PersonEditor {
|
||||||
|
backend: backend,
|
||||||
window: window,
|
window: window,
|
||||||
callback: callback,
|
callback: callback,
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -62,10 +64,13 @@ where
|
||||||
last_name: result.last_name_entry.get_text().to_string(),
|
last_name: result.last_name_entry.get_text().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
backend.update_person(person.clone(), clone!(@strong result => move |_| {
|
let c = glib::MainContext::default();
|
||||||
result.window.close();
|
let clone = result.clone();
|
||||||
(result.callback)(person.clone());
|
c.spawn_local(async move {
|
||||||
}));
|
clone.backend.update_person(person.clone()).await.unwrap();
|
||||||
|
clone.window.close();
|
||||||
|
(clone.callback)(person.clone());
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
result.window.set_transient_for(Some(parent));
|
result.window.set_transient_for(Some(parent));
|
||||||
|
|
|
||||||
|
|
@ -41,40 +41,40 @@ where
|
||||||
list: list,
|
list: list,
|
||||||
});
|
});
|
||||||
|
|
||||||
result
|
let c = glib::MainContext::default();
|
||||||
.backend
|
let clone = result.clone();
|
||||||
.get_persons(clone!(@strong result => move |persons| {
|
c.spawn_local(async move {
|
||||||
let persons = persons.unwrap();
|
let persons = clone.backend.get_persons().await.unwrap();
|
||||||
|
|
||||||
for (index, person) in persons.iter().enumerate() {
|
for (index, person) in persons.iter().enumerate() {
|
||||||
let label = gtk::Label::new(Some(&person.name_lf()));
|
let label = gtk::Label::new(Some(&person.name_lf()));
|
||||||
label.set_halign(gtk::Align::Start);
|
label.set_halign(gtk::Align::Start);
|
||||||
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||||
row.show_all();
|
row.show_all();
|
||||||
result.list.insert(&row, -1);
|
clone.list.insert(&row, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
clone.list.connect_row_activated(
|
||||||
.list
|
clone!(@strong clone, @strong persons => move |_, row| {
|
||||||
.connect_row_activated(clone!(@strong result, @strong persons => move |_, row| {
|
clone.window.close();
|
||||||
result.window.close();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
(clone.callback)(persons[index].clone());
|
||||||
(result.callback)(persons[index].clone());
|
}),
|
||||||
}));
|
);
|
||||||
|
|
||||||
result
|
clone
|
||||||
.list
|
.list
|
||||||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
.set_filter_func(Some(Box::new(clone!(@strong clone => move |row| {
|
||||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
let index: usize = row.get_index().try_into().unwrap();
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
let search = result.search_entry.get_text().to_string().to_lowercase();
|
let search = clone.search_entry.get_text().to_string().to_lowercase();
|
||||||
search.is_empty() || persons[index]
|
search.is_empty() || persons[index]
|
||||||
.name_lf()
|
.name_lf()
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.contains(&search)
|
.contains(&search)
|
||||||
}))));
|
}))));
|
||||||
}));
|
});
|
||||||
|
|
||||||
result
|
result
|
||||||
.search_entry
|
.search_entry
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,13 @@ where
|
||||||
performances: result.performers.borrow().to_vec(),
|
performances: result.performers.borrow().to_vec(),
|
||||||
};
|
};
|
||||||
|
|
||||||
result.backend.update_recording(recording.clone().into(), clone!(@strong result => move |_| {
|
let c = glib::MainContext::default();
|
||||||
result.window.close();
|
let clone = result.clone();
|
||||||
(result.callback)(recording.clone());
|
c.spawn_local(async move {
|
||||||
}));
|
clone.backend.update_recording(recording.clone().into()).await.unwrap();
|
||||||
|
clone.window.close();
|
||||||
|
(clone.callback)(recording.clone());
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
work_button.connect_clicked(clone!(@strong result => move |_| {
|
work_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
|
|
||||||
|
|
@ -185,10 +185,13 @@ where
|
||||||
sections: sections,
|
sections: sections,
|
||||||
};
|
};
|
||||||
|
|
||||||
result.backend.update_work(work.clone().into(), clone!(@strong result => move |_| {
|
let c = glib::MainContext::default();
|
||||||
result.window.close();
|
let clone = result.clone();
|
||||||
(result.callback)(work.clone());
|
c.spawn_local(async move {
|
||||||
}));
|
clone.backend.update_work(work.clone().into()).await.unwrap();
|
||||||
|
clone.window.close();
|
||||||
|
(clone.callback)(work.clone());
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
composer_button.connect_clicked(clone!(@strong result => move |_| {
|
composer_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,12 @@ where
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
Loading => {
|
Loading => {
|
||||||
self.backend
|
let c = glib::MainContext::default();
|
||||||
.get_persons(clone!(@strong self as self_ => move |persons| {
|
let clone = self.clone();
|
||||||
self_.clone().set_state(Persons(persons.unwrap()));
|
c.spawn_local(async move {
|
||||||
}));
|
let persons = clone.backend.get_persons().await.unwrap();
|
||||||
|
clone.clone().set_state(Persons(persons));
|
||||||
|
});
|
||||||
|
|
||||||
self.sidebar_stack.set_visible_child_name("loading");
|
self.sidebar_stack.set_visible_child_name("loading");
|
||||||
self.stack.set_visible_child_name("empty_screen");
|
self.stack.set_visible_child_name("empty_screen");
|
||||||
|
|
@ -181,12 +183,16 @@ where
|
||||||
PersonLoading(person) => {
|
PersonLoading(person) => {
|
||||||
self.header.set_title(Some(&person.name_fl()));
|
self.header.set_title(Some(&person.name_fl()));
|
||||||
|
|
||||||
self.backend.get_work_descriptions(
|
let c = glib::MainContext::default();
|
||||||
person.id,
|
let clone = self.clone();
|
||||||
clone!(@strong self as self_ => move |works| {
|
c.spawn_local(async move {
|
||||||
self_.clone().set_state(Person(works.unwrap()));
|
let works = clone
|
||||||
}),
|
.backend
|
||||||
);
|
.get_work_descriptions(person.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
clone.clone().set_state(Person(works));
|
||||||
|
});
|
||||||
|
|
||||||
self.content_stack.set_visible_child_name("loading");
|
self.content_stack.set_visible_child_name("loading");
|
||||||
self.stack.set_visible_child_name("person_screen");
|
self.stack.set_visible_child_name("person_screen");
|
||||||
|
|
|
||||||
142
src/window.rs
142
src/window.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use super::backend::Backend;
|
use super::backend::Backend;
|
||||||
use super::database::*;
|
use super::database::*;
|
||||||
use super::dialogs::*;
|
use super::dialogs::*;
|
||||||
|
use futures::prelude::*;
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
@ -196,12 +197,15 @@ impl Window {
|
||||||
"edit-person",
|
"edit-person",
|
||||||
Some(glib::VariantTy::new("x").unwrap()),
|
Some(glib::VariantTy::new("x").unwrap()),
|
||||||
clone!(@strong result => move |_, id| {
|
clone!(@strong result => move |_, id| {
|
||||||
result.backend.get_person(id.unwrap().get().unwrap(), clone!(@strong result => move |person| {
|
let id = id.unwrap().get().unwrap();
|
||||||
let person = person.unwrap();
|
let result = result.clone();
|
||||||
|
let c = glib::MainContext::default();
|
||||||
|
c.spawn_local(async move {
|
||||||
|
let person = result.backend.get_person(id).await.unwrap();
|
||||||
PersonEditor::new(result.backend.clone(), &result.window, Some(person), clone!(@strong result => move |_| {
|
PersonEditor::new(result.backend.clone(), &result.window, Some(person), clone!(@strong result => move |_| {
|
||||||
result.clone().set_state(Loading);
|
result.clone().set_state(Loading);
|
||||||
})).show();
|
})).show();
|
||||||
}));
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -210,9 +214,13 @@ impl Window {
|
||||||
"delete-person",
|
"delete-person",
|
||||||
Some(glib::VariantTy::new("x").unwrap()),
|
Some(glib::VariantTy::new("x").unwrap()),
|
||||||
clone!(@strong result => move |_, id| {
|
clone!(@strong result => move |_, id| {
|
||||||
result.backend.delete_person(id.unwrap().get().unwrap(), clone!(@strong result => move |_| {
|
let id = id.unwrap().get().unwrap();
|
||||||
|
let result = result.clone();
|
||||||
|
let c = glib::MainContext::default();
|
||||||
|
c.spawn_local(async move {
|
||||||
|
result.backend.delete_person(id).await.unwrap();
|
||||||
result.clone().set_state(Loading);
|
result.clone().set_state(Loading);
|
||||||
}));
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -221,12 +229,15 @@ impl Window {
|
||||||
"edit-ensemble",
|
"edit-ensemble",
|
||||||
Some(glib::VariantTy::new("x").unwrap()),
|
Some(glib::VariantTy::new("x").unwrap()),
|
||||||
clone!(@strong result => move |_, id| {
|
clone!(@strong result => move |_, id| {
|
||||||
result.backend.get_ensemble(id.unwrap().get().unwrap(), clone!(@strong result => move |ensemble| {
|
let id = id.unwrap().get().unwrap();
|
||||||
let ensemble = ensemble.unwrap();
|
let result = result.clone();
|
||||||
|
let c = glib::MainContext::default();
|
||||||
|
c.spawn_local(async move {
|
||||||
|
let ensemble = result.backend.get_ensemble(id).await.unwrap();
|
||||||
EnsembleEditor::new(result.backend.clone(), &result.window, Some(ensemble), clone!(@strong result => move |_| {
|
EnsembleEditor::new(result.backend.clone(), &result.window, Some(ensemble), clone!(@strong result => move |_| {
|
||||||
result.clone().set_state(Loading);
|
result.clone().set_state(Loading);
|
||||||
})).show();
|
})).show();
|
||||||
}));
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -235,9 +246,13 @@ impl Window {
|
||||||
"delete-ensemble",
|
"delete-ensemble",
|
||||||
Some(glib::VariantTy::new("x").unwrap()),
|
Some(glib::VariantTy::new("x").unwrap()),
|
||||||
clone!(@strong result => move |_, id| {
|
clone!(@strong result => move |_, id| {
|
||||||
result.backend.delete_ensemble(id.unwrap().get().unwrap(), clone!(@strong result => move |_| {
|
let id = id.unwrap().get().unwrap();
|
||||||
|
let result = result.clone();
|
||||||
|
let c = glib::MainContext::default();
|
||||||
|
c.spawn_local(async move {
|
||||||
|
result.backend.delete_ensemble(id).await.unwrap();
|
||||||
result.clone().set_state(Loading);
|
result.clone().set_state(Loading);
|
||||||
}));
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -298,24 +313,24 @@ impl Window {
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
Loading => {
|
Loading => {
|
||||||
self.backend
|
let self_ = self.clone();
|
||||||
.get_persons(clone!(@strong self as self_ => move |persons| {
|
let c = glib::MainContext::default();
|
||||||
let persons = persons.unwrap();
|
c.spawn_local(async move {
|
||||||
self_.backend.get_ensembles(clone!(@strong self_ => move |ensembles| {
|
let persons = self_.backend.get_persons().await.unwrap();
|
||||||
let ensembles = ensembles.unwrap();
|
let ensembles = self_.backend.get_ensembles().await.unwrap();
|
||||||
let mut poes: Vec<PersonOrEnsemble> = Vec::new();
|
|
||||||
|
|
||||||
for person in &persons {
|
let mut poes: Vec<PersonOrEnsemble> = Vec::new();
|
||||||
poes.push(PersonOrEnsemble::Person(person.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for ensemble in &ensembles {
|
for person in &persons {
|
||||||
poes.push(PersonOrEnsemble::Ensemble(ensemble.clone()));
|
poes.push(PersonOrEnsemble::Person(person.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
self_.clone().set_state(Selection(poes));
|
for ensemble in &ensembles {
|
||||||
}));
|
poes.push(PersonOrEnsemble::Ensemble(ensemble.clone()));
|
||||||
}));
|
}
|
||||||
|
|
||||||
|
self_.clone().set_state(Selection(poes));
|
||||||
|
});
|
||||||
|
|
||||||
self.sidebar_stack.set_visible_child_name("loading");
|
self.sidebar_stack.set_visible_child_name("loading");
|
||||||
self.main_stack.set_visible_child_name("empty_screen");
|
self.main_stack.set_visible_child_name("empty_screen");
|
||||||
|
|
@ -392,19 +407,26 @@ impl Window {
|
||||||
|
|
||||||
self.overview_header_menu_button.set_menu_model(Some(&menu));
|
self.overview_header_menu_button.set_menu_model(Some(&menu));
|
||||||
|
|
||||||
self.backend.get_work_descriptions(
|
let self_ = self.clone();
|
||||||
person.id,
|
let c = glib::MainContext::default();
|
||||||
clone!(@strong self as self_, @strong poe => move |works| {
|
c.spawn_local(async move {
|
||||||
let works = works.unwrap();
|
let works = self_
|
||||||
self_.backend.get_recordings_for_person(
|
.backend
|
||||||
person.id,
|
.get_work_descriptions(person.id)
|
||||||
clone!(@strong self_, @strong poe => move |recordings| {
|
.await
|
||||||
let recordings = recordings.unwrap();
|
.unwrap();
|
||||||
self_.clone().set_state(OverviewScreen(poe.clone(), works.clone(), recordings, String::from("")));
|
let recordings = self_
|
||||||
}),
|
.backend
|
||||||
);
|
.get_recordings_for_person(person.id)
|
||||||
}),
|
.await
|
||||||
);
|
.unwrap();
|
||||||
|
self_.clone().set_state(OverviewScreen(
|
||||||
|
poe.clone(),
|
||||||
|
works.clone(),
|
||||||
|
recordings,
|
||||||
|
String::from(""),
|
||||||
|
));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
PersonOrEnsemble::Ensemble(ensemble) => {
|
PersonOrEnsemble::Ensemble(ensemble) => {
|
||||||
self.overview_header.set_title(Some(&ensemble.name));
|
self.overview_header.set_title(Some(&ensemble.name));
|
||||||
|
|
@ -427,13 +449,21 @@ impl Window {
|
||||||
|
|
||||||
self.overview_header_menu_button.set_menu_model(Some(&menu));
|
self.overview_header_menu_button.set_menu_model(Some(&menu));
|
||||||
|
|
||||||
self.backend.get_recordings_for_ensemble(
|
let self_ = self.clone();
|
||||||
ensemble.id,
|
let c = glib::MainContext::default();
|
||||||
clone!(@strong self as self_ => move |recordings| {
|
c.spawn_local(async move {
|
||||||
let recordings = recordings.unwrap();
|
let recordings = self_
|
||||||
self_.clone().set_state(OverviewScreen(poe.clone(), Vec::new(), recordings, String::from("")));
|
.backend
|
||||||
}),
|
.get_recordings_for_ensemble(ensemble.id)
|
||||||
);
|
.await
|
||||||
|
.unwrap();
|
||||||
|
self_.clone().set_state(OverviewScreen(
|
||||||
|
poe.clone(),
|
||||||
|
Vec::new(),
|
||||||
|
recordings,
|
||||||
|
String::from(""),
|
||||||
|
));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -552,13 +582,21 @@ impl Window {
|
||||||
.set_title(Some(&work.composer.name_fl()));
|
.set_title(Some(&work.composer.name_fl()));
|
||||||
self.work_details_header.set_subtitle(Some(&work.title));
|
self.work_details_header.set_subtitle(Some(&work.title));
|
||||||
|
|
||||||
self.backend.get_recordings_for_work(
|
let c = glib::MainContext::default();
|
||||||
work.id,
|
let self_ = self.clone();
|
||||||
clone!(@strong self as self_ => move |recordings| {
|
c.spawn_local(async move {
|
||||||
let recordings = recordings.unwrap();
|
let recordings = self_
|
||||||
self_.clone().set_state(WorkScreen(poe.clone(), work.clone(), recordings, String::new()));
|
.backend
|
||||||
}),
|
.get_recordings_for_work(work.id)
|
||||||
);
|
.await
|
||||||
|
.unwrap();
|
||||||
|
self_.clone().set_state(WorkScreen(
|
||||||
|
poe.clone(),
|
||||||
|
work.clone(),
|
||||||
|
recordings,
|
||||||
|
String::new(),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
self.work_details_stack.set_visible_child_name("loading");
|
self.work_details_stack.set_visible_child_name("loading");
|
||||||
self.main_stack
|
self.main_stack
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue