Skip to content

Commit 9c23311

Browse files
improvements
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent b4c1c12 commit 9c23311

2 files changed

Lines changed: 55 additions & 52 deletions

File tree

Sources/NextcloudKit/TypeIdentifiers/NKFilePropertyResolver.swift

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,50 @@ public final class NKFilePropertyResolver {
5454
fileProperty.ext = fileExtension.takeRetainedValue() as String
5555
}
5656

57+
// Collabora Nextcloud Text Office
58+
if capabilities.richDocumentsMimetypes.contains(typeIdentifier) {
59+
fileProperty.classFile = .document
60+
fileProperty.iconName = .document
61+
fileProperty.name = "document"
62+
63+
return fileProperty
64+
}
65+
66+
// Special-case identifiers
67+
switch typeIdentifier {
68+
case "text/plain", "text/html", "net.daringfireball.markdown", "text/x-markdown":
69+
fileProperty.classFile = .document
70+
fileProperty.iconName = .document
71+
fileProperty.name = "markdown"
72+
return fileProperty
73+
case "com.microsoft.word.doc":
74+
fileProperty.classFile = .document
75+
fileProperty.iconName = .document
76+
fileProperty.name = "document"
77+
return fileProperty
78+
case "com.apple.iwork.keynote.key":
79+
fileProperty.classFile = .document
80+
fileProperty.iconName = .ppt
81+
fileProperty.name = "keynote"
82+
return fileProperty
83+
case "com.microsoft.excel.xls":
84+
fileProperty.classFile = .document
85+
fileProperty.iconName = .xls
86+
fileProperty.name = "sheet"
87+
return fileProperty
88+
case "com.apple.iwork.numbers.numbers":
89+
fileProperty.classFile = .document
90+
fileProperty.iconName = .xls
91+
fileProperty.name = "numbers"
92+
return fileProperty
93+
case "com.microsoft.powerpoint.ppt":
94+
fileProperty.classFile = .document
95+
fileProperty.iconName = .ppt
96+
fileProperty.name = "presentation"
97+
default:
98+
break
99+
}
100+
57101
// Well-known UTI type classifications
58102
if UTTypeConformsTo(inUTI, kUTTypeImage) {
59103
fileProperty.classFile = .image
@@ -89,53 +133,14 @@ public final class NKFilePropertyResolver {
89133
fileProperty.iconName = .txt
90134
fileProperty.name = "text"
91135
} else {
92-
// Special-case identifiers
93-
switch typeIdentifier {
94-
case "text/plain", "text/html", "net.daringfireball.markdown", "text/x-markdown":
95-
fileProperty.classFile = .document
96-
fileProperty.iconName = .document
97-
fileProperty.name = "markdown"
98-
99-
case "com.microsoft.word.doc":
136+
if UTTypeConformsTo(inUTI, kUTTypeContent) {
100137
fileProperty.classFile = .document
101138
fileProperty.iconName = .document
102139
fileProperty.name = "document"
103-
104-
case "com.apple.iwork.keynote.key":
105-
fileProperty.classFile = .document
106-
fileProperty.iconName = .ppt
107-
fileProperty.name = "keynote"
108-
109-
case "com.microsoft.excel.xls":
110-
fileProperty.classFile = .document
111-
fileProperty.iconName = .xls
112-
fileProperty.name = "sheet"
113-
114-
case "com.apple.iwork.numbers.numbers":
115-
fileProperty.classFile = .document
116-
fileProperty.iconName = .xls
117-
fileProperty.name = "numbers"
118-
119-
case "com.microsoft.powerpoint.ppt":
120-
fileProperty.classFile = .document
121-
fileProperty.iconName = .ppt
122-
fileProperty.name = "presentation"
123-
124-
default:
125-
// Check against Collabora mimetypes
126-
if capabilities.richDocumentsMimetypes.contains(typeIdentifier) {
127-
fileProperty.classFile = .document
128-
fileProperty.iconName = .document
129-
fileProperty.name = "document"
130-
} else if UTTypeConformsTo(inUTI, kUTTypeContent) {
131-
fileProperty.classFile = .document
132-
fileProperty.iconName = .document
133-
fileProperty.name = "document"
134-
} else {
135-
fileProperty.classFile = .unknow
136-
fileProperty.iconName = .unknow
137-
fileProperty.name = "file"
138-
}
140+
} else {
141+
fileProperty.classFile = .unknow
142+
fileProperty.iconName = .unknow
143+
fileProperty.name = "file"
139144
}
140145
}
141146

Sources/NextcloudKit/TypeIdentifiers/NKTypeIdentifiers.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ public final class NKTypeIdentifiersHelper {
9595
typeIdentifier: String,
9696
fileNameWithoutExt: String,
9797
ext: String) {
98-
var result: (
99-
mimeType: String,
100-
classFile: String,
101-
iconName: String,
102-
typeIdentifier: String,
103-
fileNameWithoutExt: String,
104-
ext: String
105-
)!
98+
var result: (mimeType: String,
99+
classFile: String,
100+
iconName: String,
101+
typeIdentifier: String,
102+
fileNameWithoutExt: String,
103+
ext: String)!
106104

107105
let semaphore = DispatchSemaphore(value: 0)
108106

0 commit comments

Comments
 (0)