diff --git a/src/common/mime_types.rs b/src/common/mime_types.rs index 0be95a0..d041c66 100644 --- a/src/common/mime_types.rs +++ b/src/common/mime_types.rs @@ -53,26 +53,14 @@ fn mime_to_option(mime: Mime) -> Option { impl TryFrom<&Path> for MimeType { type Error = Error; fn try_from(path: &Path) -> Result { - use mime::APPLICATION_OCTET_STREAM as UNKNOWN; let db = xdg_mime::SharedMimeInfo::new(); - let name_guess = mime_to_option(match path.file_name() { - Some(f) => db.get_mime_types_from_file_name(&f.to_string_lossy()) - [0] - .clone(), - None => UNKNOWN, - }); + let guess = db.guess_mime_type().path(&path).guess(); - let content_guess = mime_to_option({ - let guess = db.guess_mime_type().path(&path).guess(); - guess.mime_type().clone() - }); + let mime = mime_to_option(guess.mime_type().clone()) + .ok_or_else(|| Error::Ambiguous(path.to_owned()))?; - Ok(Self( - name_guess - .or(content_guess) - .ok_or_else(|| Error::Ambiguous(path.to_owned()))?, - )) + Ok(Self(mime)) } } @@ -122,6 +110,10 @@ mod tests { MimeType::try_from("./tests/cat")?.0, "application/x-shellscript" ); + assert_eq!( + MimeType::try_from("./tests/SettingsWidgetFdoSecrets.ui")?.0, + "application/x-designer" + ); Ok(()) } diff --git a/tests/SettingsWidgetFdoSecrets.ui b/tests/SettingsWidgetFdoSecrets.ui new file mode 100644 index 0000000..af4a8ef --- /dev/null +++ b/tests/SettingsWidgetFdoSecrets.ui @@ -0,0 +1,167 @@ + + + SettingsWidgetFdoSecrets + + + + 0 + 0 + 525 + 457 + + + + Options + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Enable KeepassXC Freedesktop.org Secret Service integration + + + + + + + 0 + + + + General + + + + + + <html><head/><body><p>If enabled, clients can delete exposed entries without confirmation. Otherwise, attempts to delete an entry may need to be confirmed interactively (subject to global Security/Convenience settings).</p></body></html> + + + Skip confirmation when entries are deleted by clients + + + + + + + Show notification when passwords are retrieved by clients + + + + + + + <html><head/><body><p>If enabled, any attempt to read a password must be confirmed. Otherwise, clients can read passwords without confirmation when the database is unlocked.</p><p>This option only covers the access to the password of an entry. Clients can always enumerate the items of exposed databases and query their attributes.</p></body></html> + + + Confirm when passwords are retrieved by clients + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 40 + + + + + + + + Exposed database groups: + + + + + + + Qt::NoFocus + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + Authorization + + + + + + These applications are currently connected: + + + + + + + Qt::NoFocus + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + + + + + MessageWidget + QWidget +
gui/MessageWidget.h
+ 1 +
+
+ + +