diff --git a/src/core/kinds.rs b/src/core/kinds.rs index 6dafbd6..df3a6de 100644 --- a/src/core/kinds.rs +++ b/src/core/kinds.rs @@ -18,6 +18,20 @@ pub enum ServiceItemKind { Content(Slide), } +impl ServiceItemKind { + pub fn title(&self) -> String { + match self { + ServiceItemKind::Song(song) => song.title.to_string(), + ServiceItemKind::Video(video) => video.title.to_string(), + ServiceItemKind::Image(image) => image.title.to_string(), + ServiceItemKind::Presentation(presentation) => { + presentation.title.to_string() + } + ServiceItemKind::Content(slide) => todo!(), + } + } +} + impl std::fmt::Display for ServiceItemKind { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let s = match self { diff --git a/src/main.rs b/src/main.rs index 8cdb977..80d49c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use cosmic::iced_core::text::Wrapping; use cosmic::iced_futures::Subscription; use cosmic::iced_widget::{column, row, stack}; use cosmic::theme; +use cosmic::widget::button::Catalog; use cosmic::widget::dnd_destination::dnd_destination; use cosmic::widget::menu::key_bind::Modifier; use cosmic::widget::menu::{ItemWidth, KeyBind}; @@ -735,7 +736,7 @@ impl cosmic::Application for App { ] .spacing(cosmic::theme::active().cosmic().space_s()), ) - .padding(cosmic::theme::active().cosmic().space_xxxl()) + .padding(cosmic::theme::active().cosmic().space_xl()) .style(nav_bar_style); let modal = Container::new(modal) .padding([ @@ -745,8 +746,18 @@ impl cosmic::Application for App { .center_x(Length::Fill) .align_top(Length::Fill); let mouse_stack = stack!( - mouse_area(Space::new(Length::Fill, Length::Fill)) - .on_press(Message::CloseSearch), + mouse_area( + container(Space::new(Length::Fill, Length::Fill)) + .style(|_| { + container::background( + cosmic::iced::Background::Color( + Color::BLACK, + ) + .scale_alpha(0.3), + ) + }) + ) + .on_press(Message::CloseSearch), modal ); Some(mouse_stack.into()) @@ -1167,7 +1178,7 @@ impl cosmic::Application for App { .iter() .enumerate() .find(|(id, _)| index == *id) - && let Some(slide) = item.slides.first() + && let Some(_slide) = item.slides.first() { self.current_item = (index, 0); self.presenter.update( diff --git a/src/ui/library.rs b/src/ui/library.rs index a43196e..d546945 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -4,7 +4,8 @@ use cosmic::{ dialog::file_chooser::open::Dialog, iced::{ alignment::Vertical, clipboard::dnd::DndAction, - keyboard::Modifiers, Background, Border, Color, Length, + keyboard::Modifiers, wgpu::core::command::DynComputePass, + Background, Border, Color, Length, }, iced_core::widget::tree::State, iced_widget::{column, row as rowm, text as textm}, @@ -26,12 +27,13 @@ use tracing::{debug, error, warn}; use crate::core::{ content::Content, images::{self, update_image_in_db, Image}, + kinds::ServiceItemKind, model::{KindWrapper, LibraryKind, Model}, presentations::{ self, add_presentation_to_db, update_presentation_in_db, Presentation, }, - service_items::ServiceItem, + service_items::{ServiceItem, ServiceTrait}, songs::{self, update_song_in_db, Song}, videos::{self, update_video_in_db, Video}, }; @@ -920,56 +922,52 @@ impl<'a> Library { pub async fn search_items( &self, query: String, - ) -> Vec { + ) -> Vec { let query = query.to_lowercase(); - let mut items: Vec = self + let mut items: Vec = self .song_library .items - .iter() + .clone() + .into_iter() .filter(|song| song.title.to_lowercase().contains(&query)) - .map( - super::super::core::content::Content::to_service_item, - ) + .map(|song| ServiceItemKind::Song(song)) .collect(); - let videos: Vec = self + let videos: Vec = self .video_library .items - .iter() + .clone() + .into_iter() .filter(|vid| vid.title.to_lowercase().contains(&query)) - .map( - super::super::core::content::Content::to_service_item, - ) + .map(|video| ServiceItemKind::Video(video)) .collect(); - let images: Vec = self + let images: Vec = self .image_library .items - .iter() + .clone() + .into_iter() .filter(|image| { image.title.to_lowercase().contains(&query) }) - .map( - super::super::core::content::Content::to_service_item, - ) + .map(|image| ServiceItemKind::Image(image)) .collect(); - let presentations: Vec = self + let presentations: Vec = self .presentation_library .items - .iter() + .clone() + .into_iter() .filter(|pres| pres.title.to_lowercase().contains(&query)) - .map( - super::super::core::content::Content::to_service_item, - ) + .map(|pres| ServiceItemKind::Presentation(pres)) .collect(); items.extend(videos); items.extend(images); items.extend(presentations); - let mut items: Vec<(usize, ServiceItem)> = items + let mut items: Vec<(usize, ServiceItemKind)> = items .into_iter() .map(|item| { ( levenshtein::distance( query.bytes(), - item.title.bytes(), + item.title().bytes(), ), item, )