From 2f9c7793c84ef3c73e56c831b86f7e0d3ac76e9c Mon Sep 17 00:00:00 2001 From: Elton A Rodrigues Date: Wed, 17 Aug 2022 21:20:02 -0300 Subject: [PATCH 1/2] window: Add "open..." to menu add an option in menu to open new image --- data/gtk/window.ui | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/gtk/window.ui b/data/gtk/window.ui index a1eeb1cf..58726bb5 100644 --- a/data/gtk/window.ui +++ b/data/gtk/window.ui @@ -111,6 +111,10 @@ _New Window app.new-window + + _Open… + win.open +
-- GitLab From 8679734a4384bf6c26c248075b10fe3134f5122c Mon Sep 17 00:00:00 2001 From: Elton A Rodrigues Date: Wed, 17 Aug 2022 21:31:36 -0300 Subject: [PATCH 2/2] general: change wallpaper to background - Change wallpaper term to background(string and code) - Remove toast error when cancel background portal --- data/gtk/image_page.ui | 4 ++-- data/gtk/window.ui | 4 ++-- src/widgets/image_view.rs | 26 +++++++++++++------------- src/window.rs | 12 ++++++------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/data/gtk/image_page.ui b/data/gtk/image_page.ui index 815b2494..7053eaa4 100644 --- a/data/gtk/image_page.ui +++ b/data/gtk/image_page.ui @@ -68,8 +68,8 @@ win.rotate-image --> - _Set as Wallpaper - win.set-wallpaper + _Set as Background… + win.set-background
diff --git a/data/gtk/window.ui b/data/gtk/window.ui index 58726bb5..f1aa0436 100644 --- a/data/gtk/window.ui +++ b/data/gtk/window.ui @@ -134,8 +134,8 @@ win.rotate-image --> - _Set as Wallpaper - win.set-wallpaper + _Set as Background… + win.set-background
diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index 49da4dc8..8fb4d6ed 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -27,6 +27,8 @@ use gtk::CompositeTemplate; use anyhow::{bail, Context}; use ashpd::desktop::wallpaper; +use ashpd::desktop::ResponseError; +use ashpd::Error; use ashpd::WindowIdentifier; use once_cell::sync::Lazy; use std::cell::{Cell, RefCell}; @@ -360,33 +362,31 @@ impl LpImageView { } } - pub fn set_wallpaper(&self) -> anyhow::Result<()> { - let wallpaper = self.uri().context("No URI for current file")?; + pub fn set_background(&self) -> anyhow::Result<()> { + let background = self.uri().context("No URI for current file")?; spawn!(clone!(@weak self as view => async move { let id = WindowIdentifier::from_native( &view.native().expect("View should have a GtkNative"), ) .await; - let status = match wallpaper::set_from_uri( + let _ = match wallpaper::set_from_uri( &id, - &wallpaper, + &background, true, wallpaper::SetOn::Background, ) .await { - Ok(_) => i18n("Set as wallpaper."), - Err(_) => i18n("Could not set wallpaper."), - }; - - view.activate_action( - "win.show-toast", // We use `1` here because we can't pass enums directly as GVariants, // so we need to use the C int value of the enum. // `TOAST_PRIORITY_NORMAL = 0`, and `TOAST_PRIORITY_HIGH = 1` - Some(&(status, 1).to_variant()), - ) - .unwrap(); + Ok(_) => view.activate_action("win.show-toast", Some(&(i18n("Set as background."), 1).to_variant())).unwrap(), + Err(err) => { + if !matches!(err, Error::Response(ResponseError::Cancelled)) { + view.activate_action("win.show-toast", Some(&(i18n("Could not set background."), 1).to_variant())).unwrap(); + } + }, + }; })); Ok(()) diff --git a/src/window.rs b/src/window.rs index 18e7e20f..25602a04 100644 --- a/src/window.rs +++ b/src/window.rs @@ -102,8 +102,8 @@ mod imp { win.open_with(); }); - klass.install_action("win.set-wallpaper", None, move |win, _, _| { - win.set_wallpaper(); + klass.install_action("win.set-background", None, move |win, _, _| { + win.set_background(); }); klass.install_action("win.print", None, move |win, _, _| { @@ -274,11 +274,11 @@ impl LpWindow { } } - fn set_wallpaper(&self) { + fn set_background(&self) { let imp = self.imp(); - if let Err(e) = imp.image_view.set_wallpaper() { - log::error!("Failed to set wallpaper: {}", e); + if let Err(e) = imp.image_view.set_background() { + log::error!("Failed to set background: {}", e); } } @@ -329,7 +329,7 @@ impl LpWindow { pub fn set_actions_enabled(&self, enabled: bool) { self.action_set_enabled("win.open-with", enabled); - self.action_set_enabled("win.set-wallpaper", enabled); + self.action_set_enabled("win.set-background", enabled); self.action_set_enabled("win.toggle-fullscreen", enabled); self.action_set_enabled("win.print", enabled); self.action_set_enabled("win.copy", enabled); -- GitLab