Add medium preview screen

This commit is contained in:
Elias Projahn 2021-03-23 18:06:42 +01:00
parent 2f281d7d11
commit 2922c17a86
3 changed files with 158 additions and 1 deletions

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/>
<object class="GtkBox" id="widget">
<property name="orientation">vertical</property>
<child>
<object class="AdwHeaderBar">
<property name="show-start-title-buttons">false</property>
<property name="show-end-title-buttons">false</property>
<property name="title-widget">
<object class="AdwWindowTitle" id="window_title">
<property name="title" translatable="yes">Preview</property>
</object>
</property>
<child>
<object class="GtkButton" id="back_button">
<property name="icon-name">go-previous-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="vexpand">True</property>
<child>
<object class="AdwClamp">
<child>
<object class="GtkBox" id="medium_box">
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-bottom">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="name_label">
<property name="halign">start</property>
<property name="margin-top">12</property>
<property name="margin-bottom">6</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View file

@ -78,7 +78,10 @@ impl ImportScreen {
.build(); .build();
row.connect_activated(clone!(@weak this => move |_| { row.connect_activated(clone!(@weak this => move |_| {
debug!("Medium selected: {}", medium.name); let medium = medium.clone();
spawn!(@clone this, async move {
push!(this.handle, MediumPreview, (this.session.clone(), medium.clone())).await;
});
})); }));
this.matching_list.append(&row); this.matching_list.append(&row);

View file

@ -0,0 +1,103 @@
use super::medium_editor::MediumEditor;
use crate::navigator::{NavigationHandle, Screen};
use crate::widgets::Widget;
use gettextrs::gettext;
use glib::clone;
use gtk::prelude::*;
use gtk_macros::get_widget;
use libadwaita::prelude::*;
use log::debug;
use musicus_backend::db::Medium;
use musicus_backend::import::ImportSession;
use std::rc::Rc;
use std::sync::Arc;
/// A dialog for presenting the selected medium when importing music.
pub struct MediumPreview {
handle: NavigationHandle<()>,
session: Arc<ImportSession>,
widget: gtk::Box,
}
impl Screen<(Arc<ImportSession>, Medium), ()> for MediumPreview {
/// Create a new medium preview screen.
fn new((session, medium): (Arc<ImportSession>, Medium), handle: NavigationHandle<()>) -> Rc<Self> {
// Create UI
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/medium_preview.ui");
get_widget!(builder, gtk::Box, widget);
get_widget!(builder, gtk::Button, back_button);
get_widget!(builder, gtk::Box, medium_box);
get_widget!(builder, gtk::Label, name_label);
let this = Rc::new(Self {
handle,
session,
widget,
});
// Connect signals and callbacks
back_button.connect_clicked(clone!(@weak this => move |_| {
this.handle.pop(None);
}));
// Populate the widget
name_label.set_text(&medium.name);
for track_set in medium.tracks {
let recording = &track_set.recording;
let frame = gtk::FrameBuilder::new()
.margin_bottom(12)
.build();
let list = gtk::ListBoxBuilder::new()
.selection_mode(gtk::SelectionMode::None)
.build();
let header = libadwaita::ActionRowBuilder::new()
.activatable(false)
.title(&recording.work.get_title())
.subtitle(&recording.get_performers())
.build();
list.append(&header);
for track in track_set.tracks {
let mut parts = Vec::<String>::new();
for part in &track.work_parts {
parts.push(track_set.recording.work.parts[*part].title.clone());
}
let title = if parts.is_empty() {
gettext("Unknown")
} else {
parts.join(", ")
};
let row = libadwaita::ActionRowBuilder::new()
.activatable(false)
.title(&title)
.subtitle(&track.path)
.margin_start(12)
.build();
list.append(&row);
}
frame.set_child(Some(&list));
medium_box.append(&frame);
}
this
}
}
impl Widget for MediumPreview {
fn get_widget(&self) -> gtk::Widget {
self.widget.clone().upcast()
}
}