From cd3a726e26b801527d66abeacf10aa20afa062e4 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 15 Oct 2026 06:20:57 +1300 Subject: [PATCH] Name the .qetz MIME type application/x-qet-project+zip Every other QElectroTech file type is application/x-qet-*; the zipped project was application/x-qelectrotech-project+zip. No release has shipped it yet, so it is renamed now. Files written with the old name still open: the reader accepts both, and the shared-mime-info file keeps the old name as an alias and matches either on content. Review of #1472 (scorpio810, point 2). Co-Authored-By: Claude Opus 5.5 --- misc/org.qelectrotech.qelectrotech.desktop | 2 +- misc/qelectrotech.xml | 4 +++- sources/container/QETZ-FORMAT.md | 2 +- sources/container/qetcontainer.cpp | 6 ++++-- sources/container/qetcontainer.h | 2 ++ tests/qttest/tst_qetzip.cpp | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/misc/org.qelectrotech.qelectrotech.desktop b/misc/org.qelectrotech.qelectrotech.desktop index 86876992c..84b76599e 100644 --- a/misc/org.qelectrotech.qelectrotech.desktop +++ b/misc/org.qelectrotech.qelectrotech.desktop @@ -6,7 +6,7 @@ Exec=qelectrotech %F Icon=qelectrotech Terminal=false Type=Application -MimeType=application/x-qet-project;application/x-qelectrotech-project+zip;application/x-qet-element;application/x-qet-titleblock; +MimeType=application/x-qet-project;application/x-qet-project+zip;application/x-qet-element;application/x-qet-titleblock; Categories=Graphics; Keywords=Graphics;Science;Electricity;Engineering; Comment=Edit electrical diagrams. diff --git a/misc/qelectrotech.xml b/misc/qelectrotech.xml index cefe25eb5..e6137b9c6 100644 --- a/misc/qelectrotech.xml +++ b/misc/qelectrotech.xml @@ -34,11 +34,13 @@ QElectroTech 项目文件 - + + QElectroTech zipped project file + diff --git a/sources/container/QETZ-FORMAT.md b/sources/container/QETZ-FORMAT.md index a88c84d36..42e0838ba 100644 --- a/sources/container/QETZ-FORMAT.md +++ b/sources/container/QETZ-FORMAT.md @@ -46,7 +46,7 @@ The code is `qetcontainer.cpp` (the zip and its files), `qetcontainerdb.cpp` | Entry | Content | |---|---| -| `mimetype` | `application/x-qelectrotech-project+zip`, the first entry, stored uncompressed | +| `mimetype` | `application/x-qet-project+zip`, the first entry, stored uncompressed (files written before October 2026 say `application/x-qelectrotech-project+zip`; both are read) | | `manifest.xml` | `` | | `project.xml` | the project document, each part replaced by `` | | `project.sqlite` | the engineering data (section 4) | diff --git a/sources/container/qetcontainer.cpp b/sources/container/qetcontainer.cpp index f6659ebbc..406e43751 100644 --- a/sources/container/qetcontainer.cpp +++ b/sources/container/qetcontainer.cpp @@ -25,7 +25,8 @@ #include #include -const char QetContainer::MimeType[] = "application/x-qelectrotech-project+zip"; +const char QetContainer::MimeType[] = "application/x-qet-project+zip"; +const char QetContainer::OldMimeType[] = "application/x-qelectrotech-project+zip"; namespace { const QString PartTag = QStringLiteral("qetz-part"); @@ -426,7 +427,8 @@ bool QetContainer::join(const QList &entries, QDomDocument *proje for (const QetZip::Entry &entry : entries) files.insert(entry.name, entry.data); - if (files.value(QStringLiteral("mimetype")) != QByteArray(MimeType)) { + const QByteArray mimetype = files.value(QStringLiteral("mimetype")); + if (mimetype != QByteArray(MimeType) && mimetype != QByteArray(OldMimeType)) { setError(error, QStringLiteral("not a QElectroTech project (.qetz)")); return false; } diff --git a/sources/container/qetcontainer.h b/sources/container/qetcontainer.h index c5a22987a..404aa630b 100644 --- a/sources/container/qetcontainer.h +++ b/sources/container/qetcontainer.h @@ -53,6 +53,8 @@ namespace QetContainer { extern const char MimeType[]; + /// The MIME type .qetz files had before it was renamed; still read + extern const char OldMimeType[]; /// Picture bytes by file name, see join() using Pictures = QHash; /// The format written; files of a later format are refused by join() diff --git a/tests/qttest/tst_qetzip.cpp b/tests/qttest/tst_qetzip.cpp index 156cb8fb6..021483762 100644 --- a/tests/qttest/tst_qetzip.cpp +++ b/tests/qttest/tst_qetzip.cpp @@ -17,7 +17,7 @@ class tst_qetzip : public QObject static QList sample() { QList entries; - entries.append({QStringLiteral("mimetype"), QByteArray("application/x-qelectrotech-project+zip"), false}); + entries.append({QStringLiteral("mimetype"), QByteArray("application/x-qet-project+zip"), false}); QByteArray xml(""); for (int i = 0 ; i < 2000 ; ++i) xml += ""; xml += ""; @@ -65,7 +65,7 @@ private slots: QCOMPARE(out.at(i).compress, in.at(i).compress); } // mimetype first and stored: its bytes appear as is after the header - QCOMPARE(zip.indexOf("application/x-qelectrotech-project+zip"), 30 + int(qstrlen("mimetype"))); + QCOMPARE(zip.indexOf("application/x-qet-project+zip"), 30 + int(qstrlen("mimetype"))); } void sameBytesTwice()