Search for matching mediums online or locally

This commit is contained in:
Elias Projahn 2021-03-23 17:16:20 +01:00
parent 606ee563e9
commit 2f281d7d11
2 changed files with 32 additions and 7 deletions

View file

@ -32,16 +32,27 @@
<property name="margin-bottom">6</property> <property name="margin-bottom">6</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkBox">
<property name="halign">start</property>
<property name="margin-top">12</property> <property name="margin-top">12</property>
<property name="margin-bottom">6</property> <property name="margin-bottom">6</property>
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Matching metadata</property> <property name="label" translatable="yes">Matching metadata</property>
<attributes> <attributes>
<attribute name="weight" value="bold"/> <attribute name="weight" value="bold"/>
</attributes> </attributes>
</object> </object>
</child> </child>
<child>
<object class="GtkCheckButton" id="server_check_button">
<property name="label" translatable="yes">Use the Musicus server</property>
<property name="active">True</property>
</object>
</child>
</object>
</child>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
<child> <child>

View file

@ -7,6 +7,7 @@ use gtk::prelude::*;
use gtk_macros::get_widget; use gtk_macros::get_widget;
use libadwaita::prelude::*; use libadwaita::prelude::*;
use log::debug; use log::debug;
use musicus_backend::Error;
use musicus_backend::db::Medium; use musicus_backend::db::Medium;
use musicus_backend::import::ImportSession; use musicus_backend::import::ImportSession;
use std::rc::Rc; use std::rc::Rc;
@ -17,6 +18,7 @@ pub struct ImportScreen {
handle: NavigationHandle<()>, handle: NavigationHandle<()>,
session: Arc<ImportSession>, session: Arc<ImportSession>,
widget: gtk::Box, widget: gtk::Box,
server_check_button: gtk::CheckButton,
matching_stack: gtk::Stack, matching_stack: gtk::Stack,
error_row: libadwaita::ActionRow, error_row: libadwaita::ActionRow,
matching_list: gtk::ListBox, matching_list: gtk::ListBox,
@ -29,7 +31,13 @@ impl ImportScreen {
let this = self; let this = self;
spawn!(@clone this, async move { spawn!(@clone this, async move {
match this.handle.backend.db().get_mediums_by_source_id(this.session.source_id()).await { let mediums: Result<Vec<Medium>, Error> = if this.server_check_button.get_active() {
this.handle.backend.cl().get_mediums_by_discid(this.session.source_id()).await.map_err(|err| err.into())
} else {
this.handle.backend.db().get_mediums_by_source_id(this.session.source_id()).await.map_err(|err| err.into())
};
match mediums {
Ok(mediums) => { Ok(mediums) => {
if !mediums.is_empty() { if !mediums.is_empty() {
this.show_matches(mediums); this.show_matches(mediums);
@ -99,6 +107,7 @@ impl Screen<Arc<ImportSession>, ()> for ImportScreen {
get_widget!(builder, gtk::Stack, matching_stack); get_widget!(builder, gtk::Stack, matching_stack);
get_widget!(builder, gtk::Button, try_again_button); get_widget!(builder, gtk::Button, try_again_button);
get_widget!(builder, libadwaita::ActionRow, error_row); get_widget!(builder, libadwaita::ActionRow, error_row);
get_widget!(builder, gtk::CheckButton, server_check_button);
get_widget!(builder, gtk::ListBox, matching_list); get_widget!(builder, gtk::ListBox, matching_list);
get_widget!(builder, gtk::Button, select_button); get_widget!(builder, gtk::Button, select_button);
get_widget!(builder, gtk::Button, add_button); get_widget!(builder, gtk::Button, add_button);
@ -107,6 +116,7 @@ impl Screen<Arc<ImportSession>, ()> for ImportScreen {
handle, handle,
session, session,
widget, widget,
server_check_button,
matching_stack, matching_stack,
error_row, error_row,
matching_list, matching_list,
@ -118,6 +128,10 @@ impl Screen<Arc<ImportSession>, ()> for ImportScreen {
this.handle.pop(None); this.handle.pop(None);
})); }));
this.server_check_button.connect_toggled(clone!(@weak this => move |_| {
this.load_matches();
}));
try_again_button.connect_clicked(clone!(@weak this => move |_| { try_again_button.connect_clicked(clone!(@weak this => move |_| {
this.load_matches(); this.load_matches();
})); }));