mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 13:39:29 +01:00
prefer content based guessing to get MIME from file path
This commit is contained in:
parent
46a59968af
commit
52ef04d4ed
2 changed files with 175 additions and 16 deletions
|
@ -53,26 +53,14 @@ fn mime_to_option(mime: Mime) -> Option<Mime> {
|
|||
impl TryFrom<&Path> for MimeType {
|
||||
type Error = Error;
|
||||
fn try_from(path: &Path) -> Result<Self> {
|
||||
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(())
|
||||
}
|
||||
|
|
167
tests/SettingsWidgetFdoSecrets.ui
Normal file
167
tests/SettingsWidgetFdoSecrets.ui
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsWidgetFdoSecrets</class>
|
||||
<widget class="QWidget" name="SettingsWidgetFdoSecrets">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>525</width>
|
||||
<height>457</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="MessageWidget" name="warningMsg" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableFdoSecretService">
|
||||
<property name="text">
|
||||
<string>Enable KeepassXC Freedesktop.org Secret Service integration</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="noConfirmDeleteItem">
|
||||
<property name="toolTip">
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Skip confirmation when entries are deleted by clients</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="showNotification">
|
||||
<property name="text">
|
||||
<string>Show notification when passwords are retrieved by clients</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="confirmAccessItem">
|
||||
<property name="toolTip">
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Confirm when passwords are retrieved by clients</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Exposed database groups:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableDatabases">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Authorization</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>These applications are currently connected:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableClients">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MessageWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/MessageWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in a new issue