Skip to content

Commit 1d31f8a

Browse files
Option to disable thumbnailing
Closes: #1216
1 parent c7d6a11 commit 1d31f8a

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

i18n/en/cosmic_files.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ theme = Theme
291291
match-desktop = Match desktop
292292
dark = Dark
293293
light = Light
294+
enable-thumbnails = Enable thumbnails
294295
295296
### Type to Search
296297
type-to-search = Type to Search

src/app.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use wayland_client::{Proxy, protocol::wl_output::WlOutput};
6969
use crate::{
7070
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
7171
config::{
72-
AppTheme, Config, DesktopConfig, Favorite, IconSizes, TIME_CONFIG_ID, TabConfig,
72+
AppTheme, Config, DesktopConfig, Favorite, IconSizes, TIME_CONFIG_ID, TabConfig, ThumbCfg,
7373
TimeConfig, TypeToSearch,
7474
},
7575
dialog::{Dialog, DialogKind, DialogMessage, DialogResult},
@@ -387,6 +387,7 @@ pub enum Message {
387387
TabPrev,
388388
TabClose(Option<Entity>),
389389
TabConfig(TabConfig),
390+
ThumbConfig(ThumbCfg),
390391
TabMessage(Option<Entity>, tab::Message),
391392
TabNew,
392393
TabRescan(
@@ -1904,6 +1905,18 @@ impl App {
19041905
},
19051906
))
19061907
})
1908+
.add({
1909+
let thumb_cfg = self.config.thumb_cfg;
1910+
widget::settings::item::builder(fl!("enable-thumbnails")).toggler(
1911+
thumb_cfg.enabled,
1912+
move |enabled| {
1913+
Message::ThumbConfig(ThumbCfg {
1914+
enabled,
1915+
..thumb_cfg
1916+
})
1917+
},
1918+
)
1919+
})
19071920
.into(),
19081921
widget::settings::section()
19091922
.title(fl!("type-to-search"))
@@ -3799,6 +3812,12 @@ impl Application for App {
37993812
return self.update_config();
38003813
}
38013814
}
3815+
Message::ThumbConfig(config) => {
3816+
if config != self.config.thumb_cfg {
3817+
config_set!(thumb_cfg, config);
3818+
return self.update_config();
3819+
}
3820+
}
38023821
Message::ToggleFoldersFirst => {
38033822
let mut config = self.config.tab;
38043823
config.folders_first = !config.folders_first;

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub struct ThumbCfg {
298298
pub jobs: NonZeroU16,
299299
pub max_mem_mb: NonZeroU16,
300300
pub max_size_mb: NonZeroU16,
301+
pub enabled: bool,
301302
}
302303

303304
impl Default for ThumbCfg {
@@ -306,6 +307,7 @@ impl Default for ThumbCfg {
306307
jobs: 4.try_into().unwrap(),
307308
max_mem_mb: 2000.try_into().unwrap(),
308309
max_size_mb: 64.try_into().unwrap(),
310+
enabled: true,
309311
}
310312
}
311313
}

src/tab.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ impl Item {
20602060
widget::image(handle.clone()).into()
20612061
}
20622062
ItemThumbnail::Svg(handle) => widget::svg(handle.clone()).into(),
2063-
ItemThumbnail::Text(content) => widget::text_editor(&content)
2063+
ItemThumbnail::Text(content) => widget::text_editor(content)
20642064
.class(cosmic::theme::iced::TextEditor::Custom(Box::new(
20652065
text_editor_class,
20662066
)))
@@ -5604,7 +5604,7 @@ impl Tab {
56045604

56055605
pub fn subscription(&self, preview: bool) -> Subscription<Message> {
56065606
//TODO: how many thumbnail loads should be in flight at once?
5607-
let jobs = self.thumb_config.jobs.get().clone() as usize;
5607+
let jobs = self.thumb_config.jobs.get() as usize;
56085608
let mut subscriptions = Vec::with_capacity(jobs + 3);
56095609

56105610
if let Some(items) = &self.items_opt {
@@ -5619,7 +5619,7 @@ impl Tab {
56195619
};
56205620

56215621
for item in items.iter() {
5622-
if item.thumbnail_opt.is_some() {
5622+
if item.thumbnail_opt.is_some() || !self.thumb_config.enabled {
56235623
// Skip items that already have a mime type and thumbnail
56245624
continue;
56255625
}
@@ -5650,9 +5650,9 @@ impl Tab {
56505650
};
56515651
if can_thumbnail {
56525652
let mime = item.mime.clone();
5653-
let max_jobs = jobs.clone();
5654-
let max_mb = self.thumb_config.max_mem_mb.get().clone() as u64;
5655-
let max_size = self.thumb_config.max_size_mb.get().clone() as u64;
5653+
let max_jobs = jobs;
5654+
let max_mb = self.thumb_config.max_mem_mb.get() as u64;
5655+
let max_size = self.thumb_config.max_size_mb.get() as u64;
56565656
subscriptions.push(Subscription::run_with_id(
56575657
("thumbnail", path.clone()),
56585658
stream::channel(1, move |mut output| async move {

0 commit comments

Comments
 (0)