mirror of https://github.com/procxx/kepka.git
mime types hack added for webp
This commit is contained in:
parent
9dab1f1fe2
commit
5d54d48f70
|
@ -651,7 +651,7 @@ void DocumentOpenLink::onClick(Qt::MouseButton button) const {
|
|||
if (data->status != FileReady) return;
|
||||
|
||||
QString name = data->name, filter;
|
||||
QMimeType mimeType = QMimeDatabase().mimeTypeForName(data->mime);
|
||||
MimeType mimeType = mimeTypeForName(data->mime);
|
||||
QStringList p = mimeType.globPatterns();
|
||||
QString pattern = p.isEmpty() ? QString() : p.front();
|
||||
if (name.isEmpty()) {
|
||||
|
@ -682,7 +682,7 @@ void DocumentSaveLink::doSave(bool forceSavingAs) const {
|
|||
} else {
|
||||
QDir alreadyDir(already.isEmpty() ? QDir() : QFileInfo(already).dir());
|
||||
QString name = already.isEmpty() ? data->name : already, filter;
|
||||
QMimeType mimeType = QMimeDatabase().mimeTypeForName(data->mime);
|
||||
MimeType mimeType = mimeTypeForName(data->mime);
|
||||
QStringList p = mimeType.globPatterns();
|
||||
QString pattern = p.isEmpty() ? QString() : p.front();
|
||||
if (name.isEmpty()) {
|
||||
|
|
|
@ -76,7 +76,7 @@ void LocalImageLoaderPrivate::prepareImages() {
|
|||
img = App::readImage(file, 0, true, &animated);
|
||||
}
|
||||
if (type == ToPrepareDocument) {
|
||||
mime = QMimeDatabase().mimeTypeForFile(info).name();
|
||||
mime = mimeTypeForFile(info).name();
|
||||
}
|
||||
filename = info.fileName();
|
||||
filesize = info.size();
|
||||
|
@ -91,7 +91,7 @@ void LocalImageLoaderPrivate::prepareImages() {
|
|||
img = QImage();
|
||||
}
|
||||
}
|
||||
QMimeType mimeType = QMimeDatabase().mimeTypeForData(data);
|
||||
MimeType mimeType = mimeTypeForData(data);
|
||||
if (type == ToPrepareDocument) {
|
||||
mime = mimeType.name();
|
||||
}
|
||||
|
@ -105,8 +105,7 @@ void LocalImageLoaderPrivate::prepareImages() {
|
|||
} else {
|
||||
if (type == ToPrepareDocument) {
|
||||
filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true);
|
||||
QMimeType mimeType = QMimeDatabase().mimeTypeForName("image/png");
|
||||
mime = mimeType.name();
|
||||
mime = mimeTypeForName("image/png").name();
|
||||
data = QByteArray();
|
||||
{
|
||||
QBuffer b(&data);
|
||||
|
|
|
@ -21233,6 +21233,11 @@
|
|||
<comment xml:lang="vi">Ảnh WebP</comment>
|
||||
<comment xml:lang="zh_CN">WebP 图像</comment>
|
||||
<comment xml:lang="zh_TW">WebP 影像</comment>
|
||||
<magic priority="50">
|
||||
<match value="RIFF" type="string" offset="0">
|
||||
<match value="WEBP" type="string" offset="8"/>
|
||||
</match>
|
||||
</magic>
|
||||
<glob pattern="*.webp"/>
|
||||
</mime-type>
|
||||
<mime-type type="image/x-dds">
|
||||
|
|
|
@ -922,3 +922,57 @@ QString rusKeyboardLayoutSwitch(const QString &from) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList MimeType::globPatterns() const {
|
||||
switch (_type) {
|
||||
case WebP: return QStringList(qsl("*.webp"));
|
||||
default: break;
|
||||
}
|
||||
return _typeStruct.globPatterns();
|
||||
}
|
||||
QString MimeType::filterString() const {
|
||||
switch (_type) {
|
||||
case WebP: return qsl("WebP image (*.webp)");
|
||||
default: break;
|
||||
}
|
||||
return _typeStruct.filterString();
|
||||
}
|
||||
QString MimeType::name() const {
|
||||
switch (_type) {
|
||||
case WebP: return qsl("image/webp");
|
||||
default: break;
|
||||
}
|
||||
return _typeStruct.name();
|
||||
}
|
||||
|
||||
MimeType mimeTypeForName(const QString &mime) {
|
||||
if (mime == qsl("image/webp")) return MimeType(MimeType::WebP);
|
||||
return MimeType(QMimeDatabase().mimeTypeForName(mime));
|
||||
}
|
||||
|
||||
MimeType mimeTypeForFile(const QFileInfo &file) {
|
||||
QString path = file.absoluteFilePath();
|
||||
if (path.endsWith(qsl(".webp"), Qt::CaseInsensitive)) return MimeType(MimeType::WebP);
|
||||
{
|
||||
QFile f(path);
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QByteArray magic = f.read(12);
|
||||
if (magic.size() >= 12) {
|
||||
if (!memcmp(magic.constData(), "RIFF", 4) && !memcmp(magic.constData() + 8, "WEBP", 4)) {
|
||||
return MimeType(MimeType::WebP);
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
return MimeType(QMimeDatabase().mimeTypeForFile(file));
|
||||
}
|
||||
|
||||
MimeType mimeTypeForData(const QByteArray &data) {
|
||||
if (data.size() >= 12) {
|
||||
if (!memcmp(data.constData(), "RIFF", 4) && !memcmp(data.constData() + 8, "WEBP", 4)) {
|
||||
return MimeType(MimeType::WebP);
|
||||
}
|
||||
}
|
||||
return MimeType(QMimeDatabase().mimeTypeForData(data));
|
||||
}
|
||||
|
|
|
@ -353,3 +353,30 @@ inline QString strMakeFromLetters(const uint32 *letters, int32 len) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class MimeType {
|
||||
public:
|
||||
|
||||
enum TypeEnum {
|
||||
Unknown,
|
||||
WebP,
|
||||
};
|
||||
|
||||
MimeType(const QMimeType &type) : _type(Unknown), _typeStruct(type) {
|
||||
}
|
||||
MimeType(TypeEnum type) : _type(type) {
|
||||
}
|
||||
QStringList globPatterns() const;
|
||||
QString filterString() const;
|
||||
QString name() const;
|
||||
|
||||
private:
|
||||
|
||||
QMimeType _typeStruct;
|
||||
TypeEnum _type;
|
||||
|
||||
};
|
||||
|
||||
MimeType mimeTypeForName(const QString &mime);
|
||||
MimeType mimeTypeForFile(const QFileInfo &file);
|
||||
MimeType mimeTypeForData(const QByteArray &data);
|
||||
|
|
Loading…
Reference in New Issue