propertiesView: Retrive host path via portal

This way we should always be able to get the correct folder name if
xdg-desktop-portal > 0.19.
This commit is contained in:
Sophie Herold 2024-10-08 20:53:10 +02:00
parent c38430e292
commit fa46c76af4
6 changed files with 27 additions and 8 deletions

1
Cargo.lock generated
View file

@ -1321,6 +1321,7 @@ dependencies = [
"libgweather",
"log",
"strum",
"thiserror",
"tracing-subscriber",
"url",
]

View file

@ -36,5 +36,6 @@ libc = "0.2.158"
libgweather = "4.4.0"
log = "0.4.17"
strum = { version = "0.26.2", features = ["derive"] }
thiserror = "1.0.64"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
url = "2.3.1"

View file

@ -0,0 +1 @@
Show the correct folder name in the properties view inside flatpaks if the file is only accessible via portal.

View file

@ -24,6 +24,9 @@
mod file;
mod gps;
use std::path::PathBuf;
use std::str::FromStr;
pub use file::FileInfo;
use glycin::{Frame, FrameDetails, ImageInfoDetails, MemoryFormat};
pub use gps::GPSLocation;
@ -191,6 +194,14 @@ impl Metadata {
self.file_info.as_ref().map(|x| x.display_name.to_string())
}
/// Original host path inside flatpaks obtained via xattr
pub fn host_path(&self) -> Option<PathBuf> {
self.file_info
.as_ref()
.and_then(|x| x.host_path.as_ref())
.and_then(|x| PathBuf::from_str(x.as_str()).ok())
}
pub fn file_size(&self) -> Option<String> {
self.file_info
.as_ref()

View file

@ -1,4 +1,4 @@
// Copyright (c) 2023 Sophie Herold
// Copyright (c) 2023-2024 Sophie Herold
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -17,12 +17,15 @@
use crate::deps::*;
const ATTRIBUTE_HOST_PATH: &str = "xattr::document-portal.host-path";
pub struct FileInfo {
pub(super) display_name: glib::GString,
pub(super) file_size: Option<u64>,
pub(super) mime_type: Option<glib::GString>,
pub(super) created: Option<glib::DateTime>,
pub(super) modified: Option<glib::DateTime>,
pub(super) host_path: Option<glib::GString>,
}
impl FileInfo {
@ -35,6 +38,7 @@ impl FileInfo {
gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
gio::FILE_ATTRIBUTE_TIME_CREATED,
gio::FILE_ATTRIBUTE_TIME_MODIFIED,
ATTRIBUTE_HOST_PATH,
],
)
.await?;
@ -50,6 +54,7 @@ impl FileInfo {
.and_then(|x| gio::content_type_get_mime_type(&x)),
created: file_info.creation_date_time(),
modified: file_info.modification_date_time(),
host_path: file_info.attribute_as_string(ATTRIBUTE_HOST_PATH),
})
}
}

View file

@ -190,7 +190,13 @@ mod imp {
let metadata = image.metadata();
// Folder
let has_folder = Self::update_row(&self.folder, self.folder_name());
let parent = metadata
.host_path()
.or_else(|| file.path())
.as_ref()
.and_then(|x| x.parent())
.and_then(|p| util::get_file_display_name(&gio::File::for_path(p)));
let has_folder = Self::update_row(&self.folder, parent);
// The portal only supports opening folders of files that have a path
obj.action_set_enabled("properties.open-folder", file.path().is_some());
// Only show URI if now folder available
@ -242,12 +248,6 @@ mod imp {
}
}
fn folder_name(&self) -> Option<String> {
self.file()
.and_then(|f| f.parent())
.and_then(|p| util::get_file_display_name(&p))
}
fn format_name(&self) -> Option<String> {
let image = self.image.borrow();
let metadata = image.as_ref()?.metadata();