From 4c352ed86a063549b9a6d9d43617d1c5fef25a08 Mon Sep 17 00:00:00 2001 From: Matteo Nardi Date: Fri, 24 Nov 2023 17:33:18 +0100 Subject: [PATCH 1/3] Add .fenv to .gitignore [Fenv](https://gitlab.gnome.org/ZanderBrown/fenv/) makes it easier to build and run flatpak applications from command line. Its artifacts are put in a .fenv folder, which should be ignored. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b658585e..f38be52d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ _build/ .vscode target .flatpak-builder +.fenv -- GitLab From 5e32cfa1dfac5dc5418ca012ec0c1d65eac7d005 Mon Sep 17 00:00:00 2001 From: Matteo Nardi Date: Tue, 5 Dec 2023 17:24:53 +0100 Subject: [PATCH 2/3] window: remember image property visibility state Added GSettings support to Loupe. Inspiration was taken from Fractal: LpApplication will contain `gio::Settings` and all code needing them will reach them as a singleton by calling `g_application_get_default`. This design makes the settings dependency less explicit than dependency injection, but allows for shorter code when new settings will be added across different parts of the application. A `show-properties` setting is added for remembaring the image property sidebar state. It's read by LpWindow when the current page changes, and saved when toggling the sidebar. When no image is being shown, the sidebar is always hidden, while the setting remains unchanged. The sidebar state will be restored when a picture is opened. Closes #147 --- .gitlab-ci.yml | 4 ++-- data/meson.build | 20 ++++++++++++++++++++ data/org.gnome.Loupe.gschema.xml.in | 9 +++++++++ meson.build | 3 +++ po/POTFILES.in | 1 + src/application.rs | 27 +++++++++++++++++++++++++-- src/window.rs | 25 +++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 data/org.gnome.Loupe.gschema.xml.in diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a1dfc960..b5a74758 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -121,7 +121,7 @@ other-checks: image: alpine script: - apk add --no-cache git - - git ls-files 'src/*.rs' 'src/*.ui' 'data/*.ui' 'data/*.desktop.in*' '*.metainfo.xml.in*' > po/POTFILES.in + - git ls-files 'src/*.rs' 'src/*.ui' 'data/*.ui' 'data/*.desktop.in*' '*.gschema.xml.in' '*.metainfo.xml.in*' > po/POTFILES.in - git diff --exit-code pages: @@ -147,4 +147,4 @@ nightly@aarch64: extends: ".publish_nightly" stage: deploy dependencies: - - flatpak@aarch64 \ No newline at end of file + - flatpak@aarch64 diff --git a/data/meson.build b/data/meson.build index ef6b855d..fced285c 100644 --- a/data/meson.build +++ b/data/meson.build @@ -90,6 +90,26 @@ appstream_file = i18n.merge_file( subdir('icons') +# GSchema +gschema_conf = configuration_data() +gschema_conf.set('app-id', app_id) +gschema_conf.set('gettext-package', meson.project_name()) +configure_file( + input: '@0@.gschema.xml.in'.format(base_id), + output: '@0@.gschema.xml'.format(app_id), + configuration: gschema_conf, + install: true, + install_dir: iv_datadir / 'glib-2.0' / 'schemas' +) + +# Validate GSchema +test( + 'validate-gschema', glib_compile_schemas, + args: [ + '--strict', '--dry-run', meson.current_source_dir() + ] +) + # Post install gnome.post_install() diff --git a/data/org.gnome.Loupe.gschema.xml.in b/data/org.gnome.Loupe.gschema.xml.in new file mode 100644 index 00000000..13ac2ead --- /dev/null +++ b/data/org.gnome.Loupe.gschema.xml.in @@ -0,0 +1,9 @@ + + + + + false + Show the image properties sidebar + + + diff --git a/meson.build b/meson.build index b3c5b6ae..a1f0fd14 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ dependency('gweather4', version: '>=4.0.0') dependency('lcms2', version: '>=2.12.0') cargo = find_program('cargo', required: true) +glib_compile_schemas = find_program('glib-compile-schemas', required: true) iv_prefix = get_option('prefix') iv_bindir = iv_prefix / get_option('bindir') @@ -35,6 +36,7 @@ if get_option('profile') != 'release' endif endif +base_id = 'org.gnome.Loupe' app_id = 'org.gnome.Loupe@0@'.format(profile) iv_version = meson.project_version() + version_suffix @@ -66,6 +68,7 @@ endif gnome.post_install( gtk_update_icon_cache: true, update_desktop_database: true, + glib_compile_schemas: true, ) meson.add_dist_script( diff --git a/po/POTFILES.in b/po/POTFILES.in index 7d5f3615..b94f5464 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,5 @@ data/org.gnome.Loupe.desktop.in.in +data/org.gnome.Loupe.gschema.xml.in data/org.gnome.Loupe.metainfo.xml.in.in data/resources/gtk/help-overlay.ui src/about.rs diff --git a/src/application.rs b/src/application.rs index 6f40d63a..586f167a 100644 --- a/src/application.rs +++ b/src/application.rs @@ -33,8 +33,18 @@ mod imp { // The basic struct that holds our // state and widgets - #[derive(Default, Debug)] - pub struct LpApplication {} + #[derive(Debug)] + pub struct LpApplication { + pub settings: gio::Settings, + } + + impl Default for LpApplication { + fn default() -> Self { + Self { + settings: gio::Settings::new(config::APP_ID), + } + } + } // Sets up the basics for the GObject // The `#[glib::object_subclass] macro implements @@ -209,4 +219,17 @@ impl LpApplication { } }); } + + pub fn settings(&self) -> gio::Settings { + self.imp().settings.clone() + } +} + +impl Default for LpApplication { + fn default() -> Self { + gio::Application::default() + .unwrap() + .downcast::() + .unwrap() + } } diff --git a/src/window.rs b/src/window.rs index 10d1690f..94639f0a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -35,6 +35,7 @@ use gtk::CompositeTemplate; use std::cell::{Cell, OnceCell, RefCell}; use std::path::{Path, PathBuf}; +use crate::application::LpApplication; use crate::config; use crate::util::{Direction, Position}; use crate::widgets::{LpDragOverlay, LpImage, LpImageView, LpPropertiesView}; @@ -275,6 +276,10 @@ mod imp { .connect_pressed(clone!(@weak obj => move |_,_,_,_| { obj.image_view().navigate(Direction::Back); })); + self.properties_button + .connect_toggled(clone!(@weak obj => move |_| { + obj.on_properties_button_toggled(); + })); if config::PROFILE == ".Devel" { obj.add_css_class("devel"); @@ -764,10 +769,14 @@ impl LpWindow { ); if has_image { + let settings = LpApplication::default().settings(); + imp.properties_button + .set_active(settings.boolean("show-properties")); imp.stack.set_visible_child(&*imp.image_view); imp.image_view.grab_focus(); self.schedule_hide_controls(); } else { + imp.properties_button.set_active(false); imp.stack.set_visible_child(&*imp.status_page); imp.status_page.grab_focus(); // Leave fullscreen since status page has no controls to leave it @@ -775,6 +784,22 @@ impl LpWindow { } } + /// When the image-properties sidebar is displayed or hidden, we should update the + /// "show-properties" setting. + fn on_properties_button_toggled(&self) { + let imp = self.imp(); + // When no image is shown, we skip this update as the sidebar should always be hidden. + // This can happen when deleting a picture. + if imp.image_view.current_page().is_none() { + return; + } + let settings = LpApplication::default().settings(); + let result = settings.set_boolean("show-properties", imp.properties_button.is_active()); + if let Err(err) = result { + log::warn!("Failed to save show-properties state, {}", err); + } + } + pub fn update_title(&self) { let title = self .imp() -- GitLab From 81c90302885590a0886fed7c1beaa5db8cdc15a4 Mon Sep 17 00:00:00 2001 From: Matteo Nardi Date: Thu, 7 Dec 2023 15:20:13 +0100 Subject: [PATCH 3/3] window: fix show-properties setting bug Fix issue in previous commit when having multiple windows. Steps to reproduce: - enable properties in window A and window B doesn't have them enabled - switch an image in window B - the properties would be shown Co-authored-by: Sophie Herold --- src/window.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/window.rs b/src/window.rs index 94639f0a..db69af6c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -759,7 +759,6 @@ impl LpWindow { let has_image = current_page.is_some(); - imp.properties_button.set_sensitive(has_image); self.set_actions_enabled(has_image); self.action_set_enabled( "win.trash", @@ -769,9 +768,13 @@ impl LpWindow { ); if has_image { - let settings = LpApplication::default().settings(); - imp.properties_button - .set_active(settings.boolean("show-properties")); + // Properties buttons was not enabled before. Pickup config state for enabling + // it again. + if !imp.properties_button.is_sensitive() { + let settings = LpApplication::default().settings(); + imp.properties_button + .set_active(settings.boolean("show-properties")); + } imp.stack.set_visible_child(&*imp.image_view); imp.image_view.grab_focus(); self.schedule_hide_controls(); @@ -782,6 +785,8 @@ impl LpWindow { // Leave fullscreen since status page has no controls to leave it self.set_fullscreened(false); } + + imp.properties_button.set_sensitive(has_image); } /// When the image-properties sidebar is displayed or hidden, we should update the -- GitLab