Support for opening and displaying desktop files

This commit is contained in:
kateleet 2021-12-05 15:50:42 +08:00
parent 6ace2da599
commit 94ecc56617
2 changed files with 12 additions and 4 deletions

View file

@ -246,8 +246,10 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
case UrlRole: case UrlRole:
return item.url(); return item.url();
case DisplayNameRole: { case DisplayNameRole: {
if (item.isDesktopFile()) if (item.isDesktopFile()) {
return ""; KDesktopFile dfile(item.localPath());
return dfile.readName();
}
return item.url().fileName(); return item.url().fileName();
} }
@ -938,6 +940,12 @@ void FolderModel::openSelected()
KFileItem item(url); KFileItem item(url);
QString mimeType = item.mimetype(); QString mimeType = item.mimetype();
// Desktop file.
if (mimeType == "application/x-desktop") {
FileLauncher::self()->launchApp(url.toLocalFile(), "");
continue;
}
// runnable // runnable
if (mimeType == "application/x-executable" || if (mimeType == "application/x-executable" ||
mimeType == "application/x-sharedlib" || mimeType == "application/x-sharedlib" ||

View file

@ -39,7 +39,7 @@ Item {
property bool hovered: GridView.view.hoveredItem === control property bool hovered: GridView.view.hoveredItem === control
property bool selected: model.selected property bool selected: model.selected
property bool blank: model.blank property bool blank: model.blank
property var fileName: model.fileName property var fileName: model.displayName
// For desktop // For desktop
visible: GridView.view.isDesktopView ? !blank : true visible: GridView.view.isDesktopView ? !blank : true
@ -207,7 +207,7 @@ Item {
textFormat: Text.PlainText textFormat: Text.PlainText
elide: Qt.ElideRight elide: Qt.ElideRight
wrapMode: Text.Wrap wrapMode: Text.Wrap
text: model.fileName text: control.fileName
color: control.GridView.view.isDesktopView ? "white" color: control.GridView.view.isDesktopView ? "white"
: selected ? FishUI.Theme.highlightedTextColor : selected ? FishUI.Theme.highlightedTextColor
: FishUI.Theme.textColor : FishUI.Theme.textColor