7#include "importkmailautocorrection.h"
11#include <QXmlStreamReader>
12using namespace TextAutoCorrectionCore;
14ImportKMailAutocorrection::ImportKMailAutocorrection() =
default;
16ImportKMailAutocorrection::~ImportKMailAutocorrection() =
default;
18bool ImportKMailAutocorrection::import(
const QString &fileName,
QString &errorMessage, LoadAttribute loadAttribute)
20 Q_UNUSED(errorMessage);
21 QFile xmlFile(fileName);
26 mMaxFindStringLength = 0;
27 mMinFindStringLength = 0;
28 if (xml.readNextStartElement()) {
29 while (xml.readNextStartElement()) {
31 if (xmlName ==
"UpperCaseExceptions"_L1) {
32 if (loadAttribute == All) {
33 while (xml.readNextStartElement()) {
35 if (tagname ==
"word"_L1) {
36 if (xml.attributes().hasAttribute(QStringLiteral(
"exception"))) {
37 const QString exception = xml.attributes().value(QStringLiteral(
"exception")).toString();
38 mUpperCaseExceptions += exception;
39 xml.skipCurrentElement();
44 xml.skipCurrentElement();
46 }
else if (xmlName ==
"TwoUpperLetterExceptions"_L1) {
47 if (loadAttribute == All) {
48 while (xml.readNextStartElement()) {
50 if (tagname ==
"word"_L1) {
51 if (xml.attributes().hasAttribute(QStringLiteral(
"exception"))) {
52 const QString exception = xml.attributes().value(QStringLiteral(
"exception")).toString();
53 mTwoUpperLetterExceptions += exception;
54 xml.skipCurrentElement();
57 xml.skipCurrentElement();
61 xml.skipCurrentElement();
63 }
else if (xmlName ==
"DoubleQuote"_L1) {
64 if (loadAttribute == All) {
65 if (xml.readNextStartElement()) {
67 if (tagname ==
"doublequote"_L1) {
68 mTypographicDoubleQuotes.begin = xml.attributes().value(QStringLiteral(
"begin")).toString().at(0);
69 mTypographicDoubleQuotes.end = xml.attributes().value(QStringLiteral(
"end")).toString().at(0);
70 xml.skipCurrentElement();
72 xml.skipCurrentElement();
74 xml.skipCurrentElement();
77 xml.skipCurrentElement();
79 }
else if (xmlName ==
"SimpleQuote"_L1) {
80 if (loadAttribute == All) {
81 if (xml.readNextStartElement()) {
83 if (tagname ==
"simplequote"_L1) {
84 const QString simpleQuoteBegin = xml.attributes().value(QStringLiteral(
"begin")).toString();
85 if (!simpleQuoteBegin.
isEmpty()) {
86 mTypographicSingleQuotes.begin = simpleQuoteBegin.
at(0);
88 const QString simpleQuoteEnd = xml.attributes().value(QStringLiteral(
"end")).toString();
89 if (!simpleQuoteEnd.
isEmpty()) {
90 mTypographicSingleQuotes.end = simpleQuoteEnd.
at(0);
92 xml.skipCurrentElement();
94 xml.skipCurrentElement();
96 xml.skipCurrentElement();
99 xml.skipCurrentElement();
101 }
else if (xmlName ==
"SuperScript"_L1) {
102 if (loadAttribute == All || loadAttribute == SuperScript) {
103 while (xml.readNextStartElement()) {
105 if (tagname ==
"item"_L1) {
106 const QString find = xml.attributes().value(QStringLiteral(
"find")).toString();
107 const QString super = xml.attributes().value(QStringLiteral(
"super")).toString();
108 mSuperScriptEntries.
insert(find, super);
109 xml.skipCurrentElement();
111 xml.skipCurrentElement();
115 xml.skipCurrentElement();
117 }
else if (xmlName ==
"items"_L1) {
118 if (loadAttribute == All) {
119 while (xml.readNextStartElement()) {
121 if (tagname ==
"item"_L1) {
122 const QString find = xml.attributes().value(QStringLiteral(
"find")).toString();
123 const QString replace = xml.attributes().value(QStringLiteral(
"replace")).toString();
124 const int findLenght(
find.length());
125 mMaxFindStringLength = qMax(findLenght, mMaxFindStringLength);
126 mMinFindStringLength = qMin(findLenght, mMinFindStringLength);
127 mAutocorrectEntries.
insert(find, replace);
128 xml.skipCurrentElement();
130 xml.skipCurrentElement();
134 xml.skipCurrentElement();
138 xml.skipCurrentElement();
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
iterator insert(const Key &key, const T &value)
const QChar at(qsizetype position) const const
bool isEmpty() const const