Changeset View
Changeset View
Standalone View
Standalone View
krArc/krarcbasemanager.cpp
Context not available. | |||||
32 | }; | 32 | }; | ||
---|---|---|---|---|---|
33 | 33 | | |||
34 | int KrArcBaseManager::autoDetectElems = sizeof(autoDetectParams) / sizeof(AutoDetectParams); | 34 | int KrArcBaseManager::autoDetectElems = sizeof(autoDetectParams) / sizeof(AutoDetectParams); | ||
35 | const int KrArcBaseManager::maxLenType = 5; | ||||
35 | 36 | | |||
36 | QString KrArcBaseManager::detectArchive(bool &encrypted, QString fileName, bool checkEncrypted, bool fast) | 37 | QString KrArcBaseManager::detectArchive(bool &encrypted, QString fileName, bool checkEncrypted, bool fast) | ||
37 | { | 38 | { | ||
Context not available. | |||||
173 | 174 | | |||
174 | return QString(); | 175 | return QString(); | ||
175 | } | 176 | } | ||
177 | | ||||
178 | //! Returns a short identifier of the type of a file, obtained from the mime type of the file | ||||
179 | /*! | ||||
180 | \param mime The mime type of the file. | ||||
181 | \return A short QString which contains an identifier of the type of the file. | ||||
182 | */ | ||||
183 | QString KrArcBaseManager::getShortTypeFromMime(const QString &mime) | ||||
184 | { | ||||
185 | // 7zip files are a not a normal case because their mimetype does not | ||||
186 | // follow the norm of other types: zip, tar, lha, ace, arj, etc. | ||||
187 | if (mime == "application/x-7z-compressed") | ||||
188 | return "7z"; | ||||
189 | | ||||
190 | // If it's a rar file but its mimetype isn't "application/x-rar" | ||||
191 | if (mime == "application/x-rar-compressed") | ||||
192 | return "rar"; | ||||
193 | | ||||
194 | // The short type that will be returned | ||||
195 | QString sType = mime; | ||||
196 | | ||||
197 | int lastHyphen = sType.lastIndexOf('-'); | ||||
198 | if (lastHyphen != -1) | ||||
199 | sType = sType.mid(lastHyphen + 1); | ||||
200 | else { | ||||
201 | int lastSlash = sType.lastIndexOf('/'); | ||||
202 | if (lastSlash != -1) | ||||
203 | sType = sType.mid(lastSlash + 1); | ||||
204 | } | ||||
205 | // The identifier kept short | ||||
206 | if (sType.length() > maxLenType) | ||||
207 | sType = sType.right(maxLenType); | ||||
208 | | ||||
209 | return sType; | ||||
210 | } | ||||
Context not available. |