diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 4dcaa70d..a255bae4 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -291,6 +291,7 @@ theme = Theme match-desktop = Match desktop dark = Dark light = Light +enable-thumbnails = Enable thumbnails ### Type to Search type-to-search = Type to Search diff --git a/src/app.rs b/src/app.rs index 8e1420f0..f7033258 100644 --- a/src/app.rs +++ b/src/app.rs @@ -69,7 +69,7 @@ use wayland_client::{Proxy, protocol::wl_output::WlOutput}; use crate::{ clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste}, config::{ - AppTheme, Config, DesktopConfig, Favorite, IconSizes, TIME_CONFIG_ID, TabConfig, + AppTheme, Config, DesktopConfig, Favorite, IconSizes, TIME_CONFIG_ID, TabConfig, ThumbCfg, TimeConfig, TypeToSearch, }, dialog::{Dialog, DialogKind, DialogMessage, DialogResult}, @@ -387,6 +387,7 @@ pub enum Message { TabPrev, TabClose(Option), TabConfig(TabConfig), + ThumbConfig(ThumbCfg), TabMessage(Option, tab::Message), TabNew, TabRescan( @@ -1904,6 +1905,18 @@ impl App { }, )) }) + .add({ + let thumb_cfg = self.config.thumb_cfg; + widget::settings::item::builder(fl!("enable-thumbnails")).toggler( + thumb_cfg.enabled, + move |enabled| { + Message::ThumbConfig(ThumbCfg { + enabled, + ..thumb_cfg + }) + }, + ) + }) .into(), widget::settings::section() .title(fl!("type-to-search")) @@ -3799,6 +3812,12 @@ impl Application for App { return self.update_config(); } } + Message::ThumbConfig(config) => { + if config != self.config.thumb_cfg { + config_set!(thumb_cfg, config); + return self.update_config(); + } + } Message::ToggleFoldersFirst => { let mut config = self.config.tab; config.folders_first = !config.folders_first; diff --git a/src/config.rs b/src/config.rs index d66abe82..6ce2317b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -298,6 +298,7 @@ pub struct ThumbCfg { pub jobs: NonZeroU16, pub max_mem_mb: NonZeroU16, pub max_size_mb: NonZeroU16, + pub enabled: bool, } impl Default for ThumbCfg { @@ -306,6 +307,7 @@ impl Default for ThumbCfg { jobs: 4.try_into().unwrap(), max_mem_mb: 2000.try_into().unwrap(), max_size_mb: 64.try_into().unwrap(), + enabled: true, } } } diff --git a/src/tab.rs b/src/tab.rs index 8e2a0edb..3c9ac431 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -2060,7 +2060,7 @@ impl Item { widget::image(handle.clone()).into() } ItemThumbnail::Svg(handle) => widget::svg(handle.clone()).into(), - ItemThumbnail::Text(content) => widget::text_editor(&content) + ItemThumbnail::Text(content) => widget::text_editor(content) .class(cosmic::theme::iced::TextEditor::Custom(Box::new( text_editor_class, ))) @@ -5604,7 +5604,7 @@ impl Tab { pub fn subscription(&self, preview: bool) -> Subscription { //TODO: how many thumbnail loads should be in flight at once? - let jobs = self.thumb_config.jobs.get().clone() as usize; + let jobs = self.thumb_config.jobs.get() as usize; let mut subscriptions = Vec::with_capacity(jobs + 3); if let Some(items) = &self.items_opt { @@ -5619,7 +5619,7 @@ impl Tab { }; for item in items.iter() { - if item.thumbnail_opt.is_some() { + if item.thumbnail_opt.is_some() || !self.thumb_config.enabled { // Skip items that already have a mime type and thumbnail continue; } @@ -5650,9 +5650,9 @@ impl Tab { }; if can_thumbnail { let mime = item.mime.clone(); - let max_jobs = jobs.clone(); - let max_mb = self.thumb_config.max_mem_mb.get().clone() as u64; - let max_size = self.thumb_config.max_size_mb.get().clone() as u64; + let max_jobs = jobs; + let max_mb = self.thumb_config.max_mem_mb.get() as u64; + let max_size = self.thumb_config.max_size_mb.get() as u64; subscriptions.push(Subscription::run_with_id( ("thumbnail", path.clone()), stream::channel(1, move |mut output| async move {