mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Apply clippy suggestions
This commit is contained in:
parent
7d7343ea8c
commit
c92eece842
19 changed files with 46 additions and 53 deletions
|
|
@ -97,7 +97,7 @@ impl Screen<Option<Performance>, Performance> for PerformanceEditor {
|
|||
spawn!(@clone this, async move {
|
||||
if let Some(person) = push!(this.handle, PersonSelector).await {
|
||||
this.show_person(Some(&person));
|
||||
this.person.replace(Some(person.clone()));
|
||||
this.person.replace(Some(person));
|
||||
this.show_ensemble(None);
|
||||
this.ensemble.replace(None);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ impl RecordingEditor {
|
|||
self.handle
|
||||
.backend
|
||||
.db()
|
||||
.update_recording(recording.clone().into())
|
||||
.update_recording(recording.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use gtk_macros::get_widget;
|
|||
use libadwaita::prelude::*;
|
||||
use musicus_backend::db::{generate_id, Instrument, Person, Work, WorkPart, WorkSection};
|
||||
use std::cell::RefCell;
|
||||
use std::convert::TryInto;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Either a work part or a work section.
|
||||
|
|
@ -86,10 +85,7 @@ impl Screen<Option<Work>, Work> for WorkEditor {
|
|||
}
|
||||
|
||||
for section in work.sections {
|
||||
structure.insert(
|
||||
section.before_index.try_into().unwrap(),
|
||||
PartOrSection::Section(section),
|
||||
);
|
||||
structure.insert(section.before_index, PartOrSection::Section(section));
|
||||
}
|
||||
|
||||
(work.id, Some(work.composer), work.instruments, structure)
|
||||
|
|
@ -141,7 +137,7 @@ impl Screen<Option<Work>, Work> for WorkEditor {
|
|||
spawn!(@clone this, async move {
|
||||
if let Some(person) = push!(this.handle, PersonSelector).await {
|
||||
this.show_composer(&person);
|
||||
this.composer.replace(Some(person.to_owned()));
|
||||
this.composer.replace(Some(person));
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
|
@ -179,7 +175,7 @@ impl Screen<Option<Work>, Work> for WorkEditor {
|
|||
if let Some(instrument) = push!(this.handle, InstrumentSelector).await {
|
||||
let length = {
|
||||
let mut instruments = this.instruments.borrow_mut();
|
||||
instruments.push(instrument.clone());
|
||||
instruments.push(instrument);
|
||||
instruments.len()
|
||||
};
|
||||
|
||||
|
|
@ -344,8 +340,8 @@ impl WorkEditor {
|
|||
.clone()
|
||||
.expect("Tried to create work without composer!"),
|
||||
instruments: self.instruments.borrow().clone(),
|
||||
parts: parts,
|
||||
sections: sections,
|
||||
parts,
|
||||
sections,
|
||||
};
|
||||
|
||||
let upload = self.upload_switch.state();
|
||||
|
|
@ -356,7 +352,7 @@ impl WorkEditor {
|
|||
self.handle
|
||||
.backend
|
||||
.db()
|
||||
.update_work(work.clone().into())
|
||||
.update_work(work.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ impl MediumEditor {
|
|||
id: generate_id(),
|
||||
name: self.name_entry.text().to_string(),
|
||||
discid: Some(self.session.source_id().to_owned()),
|
||||
tracks: tracks,
|
||||
tracks,
|
||||
};
|
||||
|
||||
let upload = self.publish_switch.state();
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ impl MediumPreview {
|
|||
/// Copy the tracks to the music library and add the medium to the database.
|
||||
async fn import(&self) -> Result<()> {
|
||||
let medium = self.medium.borrow();
|
||||
let medium = medium.as_ref().ok_or(anyhow!("No medium set!"))?;
|
||||
let medium = medium.as_ref().ok_or_else(|| anyhow!("No medium set!"))?;
|
||||
|
||||
// Create a new directory in the music library path for the imported medium.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use glib::clone;
|
|||
use gtk::prelude::*;
|
||||
use gtk_macros::get_widget;
|
||||
use musicus_backend::import::ImportSession;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A dialog for starting to import music.
|
||||
|
|
@ -63,7 +62,7 @@ impl Screen<(), ()> for SourceSelector {
|
|||
this.widget.set_visible_child_name("loading");
|
||||
|
||||
spawn!(@clone this, async move {
|
||||
match ImportSession::folder(PathBuf::from(path)).await {
|
||||
match ImportSession::folder(path).await {
|
||||
Ok(session) => {
|
||||
let result = push!(this.handle, ImportScreen, session).await;
|
||||
this.handle.pop(result);
|
||||
|
|
|
|||
|
|
@ -61,10 +61,8 @@ impl Screen<(Recording, Vec<usize>), Vec<usize>> for TrackEditor {
|
|||
let mut selection = this.selection.borrow_mut();
|
||||
if check.is_active() {
|
||||
selection.push(index);
|
||||
} else {
|
||||
if let Some(pos) = selection.iter().position(|part| *part == index) {
|
||||
selection.remove(pos);
|
||||
}
|
||||
} else if let Some(pos) = selection.iter().position(|part| *part == index) {
|
||||
selection.remove(pos);
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -65,10 +65,8 @@ impl Screen<Arc<ImportSession>, Vec<usize>> for TrackSelector {
|
|||
let mut selection = this.selection.borrow_mut();
|
||||
if check.is_active() {
|
||||
selection.push(index);
|
||||
} else {
|
||||
if let Some(pos) = selection.iter().position(|part| *part == index) {
|
||||
selection.remove(pos);
|
||||
}
|
||||
} else if let Some(pos) = selection.iter().position(|part| *part == index) {
|
||||
selection.remove(pos);
|
||||
}
|
||||
|
||||
if selection.is_empty() {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl Screen<(), LoginData> for RegisterDialog {
|
|||
let captcha_id = this.captcha_id.borrow().clone().unwrap();
|
||||
let answer = this.captcha_entry.text().to_string();
|
||||
|
||||
let email = if email.len() == 0 {
|
||||
let email = if email.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(email)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub struct ServerDialog {
|
|||
backend: Rc<Backend>,
|
||||
window: libadwaita::Window,
|
||||
url_entry: gtk::Entry,
|
||||
selected_cb: RefCell<Option<Box<dyn Fn(String) -> ()>>>,
|
||||
selected_cb: RefCell<Option<Box<dyn Fn(String)>>>,
|
||||
}
|
||||
|
||||
impl ServerDialog {
|
||||
|
|
@ -54,7 +54,7 @@ impl ServerDialog {
|
|||
}
|
||||
|
||||
/// The closure to call when the server was set.
|
||||
pub fn set_selected_cb<F: Fn(String) -> () + 'static>(&self, cb: F) {
|
||||
pub fn set_selected_cb<F: Fn(String) + 'static>(&self, cb: F) {
|
||||
self.selected_cb.replace(Some(Box::new(cb)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ impl Screen<(), Ensemble> for EnsembleSelector {
|
|||
|
||||
this.selector
|
||||
.set_load_online(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { Ok(clone.handle.backend.cl().get_ensembles().await?) }
|
||||
}));
|
||||
|
||||
this.selector
|
||||
.set_load_local(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { clone.handle.backend.db().get_ensembles().await.unwrap() }
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ impl Screen<(), Instrument> for InstrumentSelector {
|
|||
|
||||
this.selector
|
||||
.set_load_online(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { Ok(clone.handle.backend.cl().get_instruments().await?) }
|
||||
}));
|
||||
|
||||
this.selector
|
||||
.set_load_local(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { clone.handle.backend.db().get_instruments().await.unwrap() }
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ impl Screen<(), Person> for PersonSelector {
|
|||
|
||||
this.selector
|
||||
.set_load_online(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { Ok(clone.handle.backend.cl().get_persons().await?) }
|
||||
}));
|
||||
|
||||
this.selector
|
||||
.set_load_local(clone!(@weak this => @default-panic, move || {
|
||||
let clone = this.clone();
|
||||
let clone = this;
|
||||
async move { clone.handle.backend.db().get_persons().await.unwrap() }
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ pub struct Selector<T: 'static> {
|
|||
stack: gtk::Stack,
|
||||
list: Rc<List>,
|
||||
items: RefCell<Vec<T>>,
|
||||
back_cb: RefCell<Option<Box<dyn Fn() -> ()>>>,
|
||||
add_cb: RefCell<Option<Box<dyn Fn() -> ()>>>,
|
||||
back_cb: RefCell<Option<Box<dyn Fn()>>>,
|
||||
add_cb: RefCell<Option<Box<dyn Fn()>>>,
|
||||
make_widget: RefCell<Option<Box<dyn Fn(&T) -> gtk::Widget>>>,
|
||||
load_online: RefCell<Option<Box<dyn Fn() -> Box<dyn Future<Output = Result<Vec<T>>>>>>>,
|
||||
load_local: RefCell<Option<Box<dyn Fn() -> Box<dyn Future<Output = Vec<T>>>>>>,
|
||||
|
|
@ -147,12 +147,12 @@ impl<T> Selector<T> {
|
|||
}
|
||||
|
||||
/// Set the closure to be called when the user wants to go back.
|
||||
pub fn set_back_cb<F: Fn() -> () + 'static>(&self, cb: F) {
|
||||
pub fn set_back_cb<F: Fn() + 'static>(&self, cb: F) {
|
||||
self.back_cb.replace(Some(Box::new(cb)));
|
||||
}
|
||||
|
||||
/// Set the closure to be called when the user wants to add an item.
|
||||
pub fn set_add_cb<F: Fn() -> () + 'static>(&self, cb: F) {
|
||||
pub fn set_add_cb<F: Fn() + 'static>(&self, cb: F) {
|
||||
self.add_cb.replace(Some(Box::new(cb)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,16 +5,11 @@ use std::cell::Cell;
|
|||
|
||||
glib::wrapper! {
|
||||
/// A thin list model managing only indices to an external data source.
|
||||
pub struct IndexedListModel(ObjectSubclass<indexed_list_model::IndexedListModel>)
|
||||
pub struct IndexedListModel(ObjectSubclass<indexed_list_model_imp::IndexedListModel>)
|
||||
@implements gio::ListModel;
|
||||
}
|
||||
|
||||
impl IndexedListModel {
|
||||
/// Create a new indexed list model, which will be empty initially.
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).unwrap()
|
||||
}
|
||||
|
||||
/// Set the length of the list model.
|
||||
pub fn set_length(&self, length: u32) {
|
||||
let old_length = self.property("length").unwrap().get::<u32>().unwrap();
|
||||
|
|
@ -23,7 +18,13 @@ impl IndexedListModel {
|
|||
}
|
||||
}
|
||||
|
||||
mod indexed_list_model {
|
||||
impl Default for IndexedListModel {
|
||||
fn default() -> Self {
|
||||
glib::Object::new(&[]).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
mod indexed_list_model_imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
@ -97,7 +98,7 @@ mod indexed_list_model {
|
|||
|
||||
glib::wrapper! {
|
||||
/// A simple GObject holding just one integer.
|
||||
pub struct ItemIndex(ObjectSubclass<item_index::ItemIndex>);
|
||||
pub struct ItemIndex(ObjectSubclass<item_index_imp::ItemIndex>);
|
||||
}
|
||||
|
||||
impl ItemIndex {
|
||||
|
|
@ -112,7 +113,7 @@ impl ItemIndex {
|
|||
}
|
||||
}
|
||||
|
||||
mod item_index {
|
||||
mod item_index_imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct List {
|
|||
impl List {
|
||||
/// Create a new list. The list will be empty initially.
|
||||
pub fn new() -> Rc<Self> {
|
||||
let model = IndexedListModel::new();
|
||||
let model = IndexedListModel::default();
|
||||
let filter = gtk::CustomFilter::new(|_| true);
|
||||
let filter_model = gtk::FilterListModel::new(Some(&model), Some(&filter));
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct PlayerBar {
|
|||
play_image: gtk::Image,
|
||||
pause_image: gtk::Image,
|
||||
player: Rc<RefCell<Option<Rc<Player>>>>,
|
||||
playlist_cb: Rc<RefCell<Option<Box<dyn Fn() -> ()>>>>,
|
||||
playlist_cb: Rc<RefCell<Option<Box<dyn Fn()>>>>,
|
||||
}
|
||||
|
||||
impl PlayerBar {
|
||||
|
|
@ -37,7 +37,7 @@ impl PlayerBar {
|
|||
get_widget!(builder, gtk::Image, pause_image);
|
||||
|
||||
let player = Rc::new(RefCell::new(None::<Rc<Player>>));
|
||||
let playlist_cb = Rc::new(RefCell::new(None::<Box<dyn Fn() -> ()>>));
|
||||
let playlist_cb = Rc::new(RefCell::new(None::<Box<dyn Fn()>>));
|
||||
|
||||
previous_button.connect_clicked(clone!(@strong player => move |_| {
|
||||
if let Some(player) = &*player.borrow() {
|
||||
|
|
@ -74,8 +74,8 @@ impl PlayerBar {
|
|||
duration_label,
|
||||
play_image,
|
||||
pause_image,
|
||||
player: player,
|
||||
playlist_cb: playlist_cb,
|
||||
player,
|
||||
playlist_cb,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ impl PlayerBar {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_playlist_cb<F: Fn() -> () + 'static>(&self, cb: F) {
|
||||
pub fn set_playlist_cb<F: Fn() + 'static>(&self, cb: F) {
|
||||
self.playlist_cb.replace(Some(Box::new(cb)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl UploadSection {
|
|||
let section = Section::new(&gettext("Upload"), &list);
|
||||
|
||||
let this = Rc::new(Self {
|
||||
widget: section.widget.clone(),
|
||||
widget: section.widget,
|
||||
backend,
|
||||
switch,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue