general: change wallpaper to background

- Change wallpaper term to background(string and code)
- Remove toast error when cancel background portal
This commit is contained in:
Elton A Rodrigues 2022-08-17 21:31:36 -03:00 • committed by Elton Rodrigues | Solve4ME
parent 2f9c7793c8
commit 8679734a43
4 changed files with 23 additions and 23 deletions

View file

@ -68,8 +68,8 @@
<attribute name="action">win.rotate-image</attribute> <attribute name="action">win.rotate-image</attribute>
</item>--> </item>-->
<item> <item>
<attribute name="label" translatable="yes">_Set as Wallpaper</attribute> <attribute name="label" translatable="yes">_Set as Background…</attribute>
<attribute name="action">win.set-wallpaper</attribute> <attribute name="action">win.set-background</attribute>
</item> </item>
</section> </section>
</menu> </menu>

View file

@ -134,8 +134,8 @@
<attribute name="action">win.rotate-image</attribute> <attribute name="action">win.rotate-image</attribute>
</item>--> </item>-->
<item> <item>
<attribute name="label" translatable="yes">_Set as Wallpaper</attribute> <attribute name="label" translatable="yes">_Set as Background…</attribute>
<attribute name="action">win.set-wallpaper</attribute> <attribute name="action">win.set-background</attribute>
</item> </item>
</section> </section>
<section> <section>

View file

@ -27,6 +27,8 @@ use gtk::CompositeTemplate;
use anyhow::{bail, Context}; use anyhow::{bail, Context};
use ashpd::desktop::wallpaper; use ashpd::desktop::wallpaper;
use ashpd::desktop::ResponseError;
use ashpd::Error;
use ashpd::WindowIdentifier; use ashpd::WindowIdentifier;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -360,33 +362,31 @@ impl LpImageView {
} }
} }
pub fn set_wallpaper(&self) -> anyhow::Result<()> { pub fn set_background(&self) -> anyhow::Result<()> {
let wallpaper = self.uri().context("No URI for current file")?; let background = self.uri().context("No URI for current file")?;
spawn!(clone!(@weak self as view => async move { spawn!(clone!(@weak self as view => async move {
let id = WindowIdentifier::from_native( let id = WindowIdentifier::from_native(
&view.native().expect("View should have a GtkNative"), &view.native().expect("View should have a GtkNative"),
) )
.await; .await;
let status = match wallpaper::set_from_uri( let _ = match wallpaper::set_from_uri(
&id, &id,
&wallpaper, &background,
true, true,
wallpaper::SetOn::Background, wallpaper::SetOn::Background,
) )
.await { .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, // 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. // so we need to use the C int value of the enum.
// `TOAST_PRIORITY_NORMAL = 0`, and `TOAST_PRIORITY_HIGH = 1` // `TOAST_PRIORITY_NORMAL = 0`, and `TOAST_PRIORITY_HIGH = 1`
Some(&(status, 1).to_variant()), Ok(_) => view.activate_action("win.show-toast", Some(&(i18n("Set as background."), 1).to_variant())).unwrap(),
) Err(err) => {
.unwrap(); if !matches!(err, Error::Response(ResponseError::Cancelled)) {
view.activate_action("win.show-toast", Some(&(i18n("Could not set background."), 1).to_variant())).unwrap();
}
},
};
})); }));
Ok(()) Ok(())

View file

@ -102,8 +102,8 @@ mod imp {
win.open_with(); win.open_with();
}); });
klass.install_action("win.set-wallpaper", None, move |win, _, _| { klass.install_action("win.set-background", None, move |win, _, _| {
win.set_wallpaper(); win.set_background();
}); });
klass.install_action("win.print", None, move |win, _, _| { 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(); let imp = self.imp();
if let Err(e) = imp.image_view.set_wallpaper() { if let Err(e) = imp.image_view.set_background() {
log::error!("Failed to set wallpaper: {}", e); log::error!("Failed to set background: {}", e);
} }
} }
@ -329,7 +329,7 @@ impl LpWindow {
pub fn set_actions_enabled(&self, enabled: bool) { pub fn set_actions_enabled(&self, enabled: bool) {
self.action_set_enabled("win.open-with", enabled); 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.toggle-fullscreen", enabled);
self.action_set_enabled("win.print", enabled); self.action_set_enabled("win.print", enabled);
self.action_set_enabled("win.copy", enabled); self.action_set_enabled("win.copy", enabled);