From f0bf9cfda194e552c4727a4ba345f88dd904403c Mon Sep 17 00:00:00 2001 From: Pau Rodriguez-Estivill Date: Thu, 24 Sep 2020 15:53:42 +0200 Subject: [PATCH] drive: add xdg office icons to xdg desktop files --- backend/drive/drive.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index a9fb01672..eab0c3bba 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -73,6 +73,7 @@ const ( partialFields = "id,name,size,md5Checksum,trashed,explicitlyTrashed,modifiedTime,createdTime,mimeType,parents,webViewLink,shortcutDetails,exportLinks" listRGrouping = 50 // number of IDs to search at once when using ListR listRInputBuffer = 1000 // size of input buffer when using ListR + defaultXDGIcon = "text-html" ) // Globals @@ -128,6 +129,12 @@ var ( _mimeTypeCustomTransform = map[string]string{ "application/vnd.google-apps.script+json": "application/json", } + _mimeTypeToXDGLinkIcons = map[string]string{ + "application/vnd.google-apps.document": "x-office-document", + "application/vnd.google-apps.drawing": "x-office-drawing", + "application/vnd.google-apps.presentation": "x-office-presentation", + "application/vnd.google-apps.spreadsheet": "x-office-spreadsheet", + } fetchFormatsOnce sync.Once // make sure we fetch the export/import formats only once _exportFormats map[string][]string // allowed export MIME type conversions _importFormats map[string][]string // allowed import MIME type conversions @@ -1294,11 +1301,15 @@ func (f *Fs) newLinkObject(remote string, info *drive.File, extension, exportMim if t == nil { return nil, errors.Errorf("unsupported link type %s", exportMimeType) } + xdgIcon := _mimeTypeToXDGLinkIcons[info.MimeType] + if xdgIcon == "" { + xdgIcon = defaultXDGIcon + } var buf bytes.Buffer err := t.Execute(&buf, struct { - URL, Title string + URL, Title, XDGIcon string }{ - info.WebViewLink, info.Name, + info.WebViewLink, info.Name, xdgIcon, }) if err != nil { return nil, errors.Wrap(err, "executing template failed") @@ -3750,7 +3761,7 @@ URL={{ .URL }}{{"\r"}} Encoding=UTF-8 Name={{ .Title }} URL={{ .URL }} -Icon=text-html +Icon={{ .XDGIcon }} Type=Link ` htmlTemplate = `