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:
parent
c38430e292
commit
fa46c76af4
6 changed files with 27 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1321,6 +1321,7 @@ dependencies = [
|
||||||
"libgweather",
|
"libgweather",
|
||||||
"log",
|
"log",
|
||||||
"strum",
|
"strum",
|
||||||
|
"thiserror",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,6 @@ libc = "0.2.158"
|
||||||
libgweather = "4.4.0"
|
libgweather = "4.4.0"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
strum = { version = "0.26.2", features = ["derive"] }
|
strum = { version = "0.26.2", features = ["derive"] }
|
||||||
|
thiserror = "1.0.64"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
||||||
url = "2.3.1"
|
url = "2.3.1"
|
||||||
|
|
|
||||||
1
news.d/48.alpha/added-get-correct-folder-name-via-portal
Normal file
1
news.d/48.alpha/added-get-correct-folder-name-via-portal
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Show the correct folder name in the properties view inside flatpaks if the file is only accessible via portal.
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
mod file;
|
mod file;
|
||||||
mod gps;
|
mod gps;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub use file::FileInfo;
|
pub use file::FileInfo;
|
||||||
use glycin::{Frame, FrameDetails, ImageInfoDetails, MemoryFormat};
|
use glycin::{Frame, FrameDetails, ImageInfoDetails, MemoryFormat};
|
||||||
pub use gps::GPSLocation;
|
pub use gps::GPSLocation;
|
||||||
|
|
@ -191,6 +194,14 @@ impl Metadata {
|
||||||
self.file_info.as_ref().map(|x| x.display_name.to_string())
|
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> {
|
pub fn file_size(&self) -> Option<String> {
|
||||||
self.file_info
|
self.file_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -17,12 +17,15 @@
|
||||||
|
|
||||||
use crate::deps::*;
|
use crate::deps::*;
|
||||||
|
|
||||||
|
const ATTRIBUTE_HOST_PATH: &str = "xattr::document-portal.host-path";
|
||||||
|
|
||||||
pub struct FileInfo {
|
pub struct FileInfo {
|
||||||
pub(super) display_name: glib::GString,
|
pub(super) display_name: glib::GString,
|
||||||
pub(super) file_size: Option<u64>,
|
pub(super) file_size: Option<u64>,
|
||||||
pub(super) mime_type: Option<glib::GString>,
|
pub(super) mime_type: Option<glib::GString>,
|
||||||
pub(super) created: Option<glib::DateTime>,
|
pub(super) created: Option<glib::DateTime>,
|
||||||
pub(super) modified: Option<glib::DateTime>,
|
pub(super) modified: Option<glib::DateTime>,
|
||||||
|
pub(super) host_path: Option<glib::GString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileInfo {
|
impl FileInfo {
|
||||||
|
|
@ -35,6 +38,7 @@ impl FileInfo {
|
||||||
gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
||||||
gio::FILE_ATTRIBUTE_TIME_CREATED,
|
gio::FILE_ATTRIBUTE_TIME_CREATED,
|
||||||
gio::FILE_ATTRIBUTE_TIME_MODIFIED,
|
gio::FILE_ATTRIBUTE_TIME_MODIFIED,
|
||||||
|
ATTRIBUTE_HOST_PATH,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -50,6 +54,7 @@ impl FileInfo {
|
||||||
.and_then(|x| gio::content_type_get_mime_type(&x)),
|
.and_then(|x| gio::content_type_get_mime_type(&x)),
|
||||||
created: file_info.creation_date_time(),
|
created: file_info.creation_date_time(),
|
||||||
modified: file_info.modification_date_time(),
|
modified: file_info.modification_date_time(),
|
||||||
|
host_path: file_info.attribute_as_string(ATTRIBUTE_HOST_PATH),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,13 @@ mod imp {
|
||||||
let metadata = image.metadata();
|
let metadata = image.metadata();
|
||||||
|
|
||||||
// Folder
|
// 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
|
// The portal only supports opening folders of files that have a path
|
||||||
obj.action_set_enabled("properties.open-folder", file.path().is_some());
|
obj.action_set_enabled("properties.open-folder", file.path().is_some());
|
||||||
// Only show URI if now folder available
|
// 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> {
|
fn format_name(&self) -> Option<String> {
|
||||||
let image = self.image.borrow();
|
let image = self.image.borrow();
|
||||||
let metadata = image.as_ref()?.metadata();
|
let metadata = image.as_ref()?.metadata();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue