Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en/cosmic_files.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -387,6 +387,7 @@ pub enum Message {
TabPrev,
TabClose(Option<Entity>),
TabConfig(TabConfig),
ThumbConfig(ThumbCfg),
TabMessage(Option<Entity>, tab::Message),
TabNew,
TabRescan(
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)))
Expand Down Expand Up @@ -5604,7 +5604,7 @@ impl Tab {

pub fn subscription(&self, preview: bool) -> Subscription<Message> {
//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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading