KTextAddons

autocorrectionsettings.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "autocorrectionsettings.h"
8#include "export/exportlibreofficeautocorrection.h"
9#include "import/importlibreofficeautocorrection.h"
10
11#include "settings/textautocorrectionsettings.h"
12#include "textautocorrection_debug.h"
13
14#include <QRegularExpression>
15#include <QStandardPaths>
16
17using namespace TextAutoCorrectionCore;
18using namespace Qt::Literals::StringLiterals;
19namespace TextAutoCorrectionCore
20{
21class AutoCorrectionSettingsPrivate
22{
23public:
24 AutoCorrectionUtils::TypographicQuotes mTypographicSingleQuotes;
25 AutoCorrectionUtils::TypographicQuotes mTypographicDoubleQuotes;
26 AutoCorrectionUtils::TypographicQuotes mDoubleFrenchQuotes;
27
28 QHash<QString, QString> mAutocorrectEntries;
29 QHash<QString, QString> mSuperScriptEntries;
30
31 QSet<QString> mUpperCaseExceptions;
32 QSet<QString> mTwoUpperLetterExceptions;
33
34 QString mCustomWritablePath;
35 QString mCustomSystemPath;
36
37 QString mAutoCorrectLang;
38
39 QChar mNonBreakingSpace;
40
41 int mMaxFindStringLength = 0;
42 int mMinFindStringLength = 0;
43
44 bool mSingleSpaces = true; // suppress double spaces.
45 bool mUppercaseFirstCharOfSentence = false; // convert first letter of a sentence automatically to uppercase
46 bool mFixTwoUppercaseChars = false; // convert two uppercase characters to one upper and one lowercase.
47 bool mAutoFractions = true; // replace 1/2 with ½
48 bool mCapitalizeWeekDays = false;
49 bool mAdvancedAutocorrect = false; // autocorrection from a list of entries
50
51 bool mReplaceDoubleQuotes = false; // replace double quotes with typographical quotes
52 bool mReplaceSingleQuotes = false; // replace single quotes with typographical quotes
53
54 bool mAutoFormatUrl = false;
55 bool mAutoBoldUnderline = false;
56 bool mEnabled = false;
57 bool mSuperScriptAppendix = false;
58
59 bool mAddNonBreakingSpace = false;
60 bool mReplaceDoubleQuotesByFrenchQuotes = false;
61};
62}
63
64AutoCorrectionSettings::AutoCorrectionSettings()
65 : d(new TextAutoCorrectionCore::AutoCorrectionSettingsPrivate)
66{
67 // default double quote open 0x201c
68 // default double quote close 0x201d
69 // default single quote open 0x2018
70 // default single quote close 0x2019
71 d->mTypographicSingleQuotes = AutoCorrectionUtils::typographicDefaultSingleQuotes();
72 d->mTypographicDoubleQuotes = AutoCorrectionUtils::typographicDefaultDoubleQuotes();
73 d->mDoubleFrenchQuotes = AutoCorrectionUtils::typographicDefaultFrenchQuotes();
74 d->mNonBreakingSpace = QChar(QChar::Nbsp);
75 readConfig();
76}
77
78AutoCorrectionSettings::~AutoCorrectionSettings() = default;
79
80void AutoCorrectionSettings::setCapitalizeWeekDays(bool b)
81{
82 d->mCapitalizeWeekDays = b;
83}
84
85void AutoCorrectionSettings::setReplaceDoubleQuotes(bool b)
86{
87 d->mReplaceDoubleQuotes = b;
88}
89
90void AutoCorrectionSettings::setReplaceSingleQuotes(bool b)
91{
92 d->mReplaceSingleQuotes = b;
93}
94
95void AutoCorrectionSettings::setAdvancedAutocorrect(bool b)
96{
97 d->mAdvancedAutocorrect = b;
98}
99
100void AutoCorrectionSettings::setAutoFormatUrl(bool b)
101{
102 d->mAutoFormatUrl = b;
103}
104
105void AutoCorrectionSettings::setAutoBoldUnderline(bool b)
106{
107 d->mAutoBoldUnderline = b;
108}
109
110void AutoCorrectionSettings::setSuperScript(bool b)
111{
112 d->mSuperScriptAppendix = b;
113}
114
115void AutoCorrectionSettings::setAddNonBreakingSpace(bool b)
116{
117 d->mAddNonBreakingSpace = b;
118}
119
120bool AutoCorrectionSettings::isEnabledAutoCorrection() const
121{
122 return d->mEnabled;
123}
124
125bool AutoCorrectionSettings::isUppercaseFirstCharOfSentence() const
126{
127 return d->mUppercaseFirstCharOfSentence;
128}
129
130bool AutoCorrectionSettings::isFixTwoUppercaseChars() const
131{
132 return d->mFixTwoUppercaseChars;
133}
134
135bool AutoCorrectionSettings::isSingleSpaces() const
136{
137 return d->mSingleSpaces;
138}
139
140bool AutoCorrectionSettings::isAutoFractions() const
141{
142 return d->mAutoFractions;
143}
144
145bool AutoCorrectionSettings::isCapitalizeWeekDays() const
146{
147 return d->mCapitalizeWeekDays;
148}
149
150bool AutoCorrectionSettings::isReplaceDoubleQuotes() const
151{
152 return d->mReplaceDoubleQuotes;
153}
154
155bool AutoCorrectionSettings::isReplaceSingleQuotes() const
156{
157 return d->mReplaceSingleQuotes;
158}
159
160bool AutoCorrectionSettings::isAdvancedAutocorrect() const
161{
162 return d->mAdvancedAutocorrect;
163}
164
165bool AutoCorrectionSettings::isAutoFormatUrl() const
166{
167 return d->mAutoFormatUrl;
168}
169
170bool AutoCorrectionSettings::isAutoBoldUnderline() const
171{
172 return d->mAutoBoldUnderline;
173}
174
175bool AutoCorrectionSettings::isSuperScript() const
176{
177 return d->mSuperScriptAppendix;
178}
179
180bool AutoCorrectionSettings::isAddNonBreakingSpace() const
181{
182 return d->mAddNonBreakingSpace;
183}
184
185bool AutoCorrectionSettings::isReplaceDoubleQuotesByFrenchQuotes() const
186{
187 return d->mReplaceDoubleQuotesByFrenchQuotes;
188}
189
190void AutoCorrectionSettings::setEnabledAutoCorrection(bool b)
191{
192 d->mEnabled = b;
193}
194
195void AutoCorrectionSettings::setReplaceDoubleQuotesByFrenchQuotes(bool b)
196{
197 d->mReplaceDoubleQuotesByFrenchQuotes = b;
198}
199
200TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes AutoCorrectionSettings::typographicSingleQuotes() const
201{
202 return d->mTypographicSingleQuotes;
203}
204
205TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes AutoCorrectionSettings::typographicDoubleQuotes() const
206{
207 return d->mTypographicDoubleQuotes;
208}
209
210void AutoCorrectionSettings::setTypographicSingleQuotes(TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes singleQuote)
211{
212 d->mTypographicSingleQuotes = singleQuote;
213}
214
215void AutoCorrectionSettings::setTypographicDoubleQuotes(AutoCorrectionUtils::TypographicQuotes doubleQuote)
216{
217 d->mTypographicDoubleQuotes = doubleQuote;
218}
219
220void AutoCorrectionSettings::readConfig()
221{
222 d->mAutoBoldUnderline = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->autoBoldUnderline();
223 d->mAutoFormatUrl = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->autoFormatUrl();
224 d->mUppercaseFirstCharOfSentence = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->uppercaseFirstCharOfSentence();
225 d->mFixTwoUppercaseChars = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->fixTwoUppercaseChars();
226 d->mSingleSpaces = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->singleSpaces();
227 d->mAutoFractions = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->autoFractions();
228 d->mCapitalizeWeekDays = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->capitalizeWeekDays();
229 d->mAdvancedAutocorrect = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->advancedAutocorrect();
230 d->mReplaceDoubleQuotes = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->replaceDoubleQuotes();
231 d->mReplaceSingleQuotes = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->replaceSingleQuotes();
232 d->mEnabled = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->enabled();
233 d->mSuperScriptAppendix = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->superScript();
234 d->mAddNonBreakingSpace = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->addNonBreakingSpaceInFrench();
235 d->mReplaceDoubleQuotesByFrenchQuotes = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->replaceDoubleQuotesByFrenchQuotes();
236 d->mCustomSystemPath = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->customSystemPath();
237 d->mCustomWritablePath = TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->customWritablePath();
238
239 d->mTypographicSingleQuotes =
240 AutoCorrectionUtils::TypographicQuotes::fromString(TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->typographicSingleQuotes());
241 if (d->mTypographicSingleQuotes.isEmpty()) {
242 d->mTypographicSingleQuotes = AutoCorrectionUtils::typographicDefaultSingleQuotes();
243 }
244 d->mTypographicDoubleQuotes =
245 AutoCorrectionUtils::TypographicQuotes::fromString(TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->typographicDoubleQuotes());
246 if (d->mTypographicDoubleQuotes.isEmpty()) {
247 d->mTypographicDoubleQuotes = AutoCorrectionUtils::typographicDefaultDoubleQuotes();
248 }
249 readAutoCorrectionFile();
250}
251
252void AutoCorrectionSettings::writeConfig()
253{
254 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setAutoBoldUnderline(d->mAutoBoldUnderline);
255 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setAutoFormatUrl(d->mAutoFormatUrl);
256 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setUppercaseFirstCharOfSentence(d->mUppercaseFirstCharOfSentence);
257 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setFixTwoUppercaseChars(d->mFixTwoUppercaseChars);
258 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setSingleSpaces(d->mSingleSpaces);
259 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setAutoFractions(d->mAutoFractions);
260 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setCapitalizeWeekDays(d->mCapitalizeWeekDays);
261 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setAdvancedAutocorrect(d->mAdvancedAutocorrect);
262 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setReplaceDoubleQuotes(d->mReplaceDoubleQuotes);
263 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setReplaceSingleQuotes(d->mReplaceSingleQuotes);
264 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setEnabled(d->mEnabled);
265 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setSuperScript(d->mSuperScriptAppendix);
266 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setAddNonBreakingSpaceInFrench(d->mAddNonBreakingSpace);
267 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setTypographicSingleQuotes(d->mTypographicSingleQuotes.toString());
268 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setTypographicDoubleQuotes(d->mTypographicDoubleQuotes.toString());
269 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setReplaceDoubleQuotesByFrenchQuotes(d->mReplaceDoubleQuotesByFrenchQuotes);
270 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setCustomWritablePath(d->mCustomWritablePath);
271 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->setCustomSystemPath(d->mCustomSystemPath);
272 TextAutoCorrectionCore::TextAutoCorrectionSettings::self()->requestSync();
273 writeAutoCorrectionFile();
274}
275
276void AutoCorrectionSettings::setAutoFractions(bool newAutoFractions)
277{
278 d->mAutoFractions = newAutoFractions;
279}
280
281void AutoCorrectionSettings::setSingleSpaces(bool newSingleSpaces)
282{
283 d->mSingleSpaces = newSingleSpaces;
284}
285
286void AutoCorrectionSettings::setFixTwoUppercaseChars(bool newFixTwoUppercaseChars)
287{
288 d->mFixTwoUppercaseChars = newFixTwoUppercaseChars;
289}
290
291void AutoCorrectionSettings::setUppercaseFirstCharOfSentence(bool newUppercaseFirstCharOfSentence)
292{
293 d->mUppercaseFirstCharOfSentence = newUppercaseFirstCharOfSentence;
294}
295
296void AutoCorrectionSettings::setUpperCaseExceptions(const QSet<QString> &exceptions)
297{
298 d->mUpperCaseExceptions = exceptions;
299}
300
301void AutoCorrectionSettings::setTwoUpperLetterExceptions(const QSet<QString> &exceptions)
302{
303 d->mTwoUpperLetterExceptions = exceptions;
304}
305
306QSet<QString> AutoCorrectionSettings::upperCaseExceptions() const
307{
308 return d->mUpperCaseExceptions;
309}
310
311QSet<QString> AutoCorrectionSettings::twoUpperLetterExceptions() const
312{
313 return d->mTwoUpperLetterExceptions;
314}
315
316QString AutoCorrectionSettings::language() const
317{
318 return d->mAutoCorrectLang;
319}
320
321void AutoCorrectionSettings::setLanguage(const QString &lang, bool forceGlobal)
322{
323 if (d->mAutoCorrectLang != lang || forceGlobal) {
324 d->mAutoCorrectLang = lang;
325 // Re-read xml file
326 readAutoCorrectionFile(forceGlobal);
327 }
328}
329
330bool AutoCorrectionSettings::isFrenchLanguage() const
331{
332 return d->mAutoCorrectLang == "FR_fr"_L1 || d->mAutoCorrectLang == "fr"_L1;
333}
334
335bool AutoCorrectionSettings::addAutoCorrect(const QString &currentWord, const QString &replaceWord)
336{
337 if (!d->mAutocorrectEntries.contains(currentWord)) {
338 d->mAutocorrectEntries.insert(currentWord, replaceWord);
339 writeAutoCorrectionFile();
340 return true;
341 } else {
342 return false;
343 }
344}
345
346QChar AutoCorrectionSettings::nonBreakingSpace() const
347{
348 return d->mNonBreakingSpace;
349}
350
351void AutoCorrectionSettings::setNonBreakingSpace(const QChar &newNonBreakingSpace)
352{
353 d->mNonBreakingSpace = newNonBreakingSpace;
354}
355
356QHash<QString, QString> AutoCorrectionSettings::superScriptEntries() const
357{
358 return d->mSuperScriptEntries;
359}
360
361void AutoCorrectionSettings::setSuperScriptEntries(const QHash<QString, QString> &newSuperScriptEntries)
362{
363 d->mSuperScriptEntries = newSuperScriptEntries;
364}
365
366void AutoCorrectionSettings::setAutocorrectEntries(const QHash<QString, QString> &entries)
367{
368 d->mMaxFindStringLength = 0;
369 d->mMinFindStringLength = 0;
371 while (i.hasNext()) {
372 i.next();
373 const int findStringLenght(i.key().length());
374 d->mMaxFindStringLength = qMax(d->mMaxFindStringLength, findStringLenght);
375 d->mMinFindStringLength = qMin(d->mMinFindStringLength, findStringLenght);
376 }
377 d->mAutocorrectEntries = entries;
378}
379
380QHash<QString, QString> AutoCorrectionSettings::autocorrectEntries() const
381{
382 return d->mAutocorrectEntries;
383}
384
385void AutoCorrectionSettings::writeAutoCorrectionFile(const QString &filename)
386{
387 ExportLibreOfficeAutocorrection correct;
388 correct.setAutocorrectEntries(d->mAutocorrectEntries);
389 correct.setUpperCaseExceptions(d->mUpperCaseExceptions);
390 correct.setTwoUpperLetterExceptions(d->mTwoUpperLetterExceptions);
391 QString message;
392 if (!correct.exportData(d->mAutoCorrectLang, filename, message, d->mCustomWritablePath)) {
393 qCDebug(TEXTAUTOCORRECTION_LOG) << "We can't save in file :" << filename;
394 }
395}
396
397int AutoCorrectionSettings::maxFindStringLength() const
398{
399 return d->mMaxFindStringLength;
400}
401
402int AutoCorrectionSettings::minFindStringLength() const
403{
404 return d->mMinFindStringLength;
405}
406
407void AutoCorrectionSettings::loadLocalFileName(const QString &localFileName, const QString &fname)
408{
409 ImportLibreOfficeAutocorrection import;
410 QString messageError;
411 if (import.import(localFileName, messageError, ImportAbstractAutocorrection::All)) {
412 d->mUpperCaseExceptions = import.upperCaseExceptions();
413 d->mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
414 d->mAutocorrectEntries = import.autocorrectEntries();
415 // Don't import it in local
416 // mSuperScriptEntries = import.superScriptEntries();
417 }
418 if (!fname.isEmpty() && import.import(fname, messageError, ImportAbstractAutocorrection::SuperScript)) {
419 d->mSuperScriptEntries = import.superScriptEntries();
420 }
421 d->mMaxFindStringLength = import.maxFindStringLenght();
422 d->mMinFindStringLength = import.minFindStringLenght();
423}
424
425void AutoCorrectionSettings::loadGlobalFileName(const QString &fname)
426{
427 if (fname.isEmpty()) {
428 const QString fileName = containsAutoCorrectionFile(d->mAutoCorrectLang);
429 if (!fileName.isEmpty()) {
431 ImportLibreOfficeAutocorrection import;
432 if (import.import(fileName, errorMessage)) {
433 d->mUpperCaseExceptions = import.upperCaseExceptions();
434 d->mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
435 d->mAutocorrectEntries = import.autocorrectEntries();
436 d->mSuperScriptEntries = import.superScriptEntries();
437 d->mMaxFindStringLength = import.maxFindStringLenght();
438 d->mMinFindStringLength = import.minFindStringLenght();
439 }
440 }
441 } else {
442 qDebug() << " import libreoffice file " << fname;
443 ImportLibreOfficeAutocorrection import;
444 QString messageError;
445 if (import.import(fname, messageError, ImportAbstractAutocorrection::All)) {
446 d->mUpperCaseExceptions = import.upperCaseExceptions();
447 d->mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
448 d->mAutocorrectEntries = import.autocorrectEntries();
449 d->mSuperScriptEntries = import.superScriptEntries();
450 d->mMaxFindStringLength = import.maxFindStringLenght();
451 d->mMinFindStringLength = import.minFindStringLenght();
452 }
453 }
454}
455
456void AutoCorrectionSettings::migrateKMailXmlFile()
457{
458#if 0
459 // TODO
460 QString kdelang = QStringLiteral("en_US");
462 if (!lst.isEmpty()) {
463 kdelang = lst.at(0);
464 if (kdelang == QLatin1Char('C')) {
465 kdelang = QStringLiteral("en_US");
466 }
467 }
468 static QRegularExpression reg(QStringLiteral("@.*"));
469 kdelang.remove(reg);
470
471 QString localFileName;
472 static QRegularExpression regpath(QRegularExpression(QStringLiteral("_.*")));
473 // Look at local file:
474 if (!forceGlobal) {
475 if (!mAutoCorrectLang.isEmpty()) {
476 localFileName =
477 QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/custom-"_L1 + mAutoCorrectLang + ".xml"_L1);
478 } else {
479 if (!kdelang.isEmpty()) {
480 localFileName =
481 QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/custom-"_L1 + kdelang + ".xml"_L1);
482 }
483 if (localFileName.isEmpty() && kdelang.contains(QLatin1Char('_'))) {
484 kdelang.remove(regpath);
485 localFileName =
486 QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/custom-"_L1 + kdelang + ".xml"_L1);
487 }
488 }
489 }
490 QString fname;
491 // Load Global directly
492 if (!mAutoCorrectLang.isEmpty()) {
493 if (mAutoCorrectLang == "en_US"_L1) {
494 fname = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("autocorrect/autocorrect.xml"));
495 } else {
496 fname = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/"_L1 + mAutoCorrectLang + ".xml"_L1);
497 }
498 } else {
499 if (fname.isEmpty() && !kdelang.isEmpty()) {
500 fname = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/"_L1 + kdelang + ".xml"_L1);
501 }
502 if (fname.isEmpty() && kdelang.contains(QLatin1Char('_'))) {
503 kdelang.remove(regpath);
504 fname = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "autocorrect/"_L1 + kdelang + ".xml"_L1);
505 }
506 }
507 if (fname.isEmpty()) {
508 fname = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("autocorrect/autocorrect.xml"));
509 }
510
511 if (mAutoCorrectLang.isEmpty()) {
512 mAutoCorrectLang = kdelang;
513 }
514#endif
515}
516
517void AutoCorrectionSettings::readAutoCorrectionFile(bool forceGlobal)
518{
519 d->mUpperCaseExceptions.clear();
520 d->mAutocorrectEntries.clear();
521 d->mTwoUpperLetterExceptions.clear();
522 d->mSuperScriptEntries.clear();
523
524 QString kdelang = QStringLiteral("en-US");
526 if (!lst.isEmpty()) {
527 kdelang = lst.at(0);
528 if (kdelang == QLatin1Char('C')) {
529 kdelang = QStringLiteral("en-US");
530 }
531 }
532 static QRegularExpression reg(QStringLiteral("@.*"));
533 kdelang.remove(reg);
534
535 QString localFileName;
536 static QRegularExpression regpath(QRegularExpression(QStringLiteral("_.*")));
537 // Look at local file:
538 if (!forceGlobal) {
539 if (d->mAutoCorrectLang.isEmpty()) {
540 if (!kdelang.isEmpty()) {
541 localFileName = containsAutoCorrectionFile(kdelang);
542 }
543 if (localFileName.isEmpty() && kdelang.contains(QLatin1Char('_'))) {
544 kdelang.remove(regpath);
545 localFileName = containsAutoCorrectionFile(kdelang);
546 }
547 }
548 }
549 QString fname;
550 // Load Global directly
551 if (!d->mAutoCorrectLang.isEmpty()) {
552 localFileName = containsAutoCorrectionFile(d->mAutoCorrectLang);
553 } else {
554 if (fname.isEmpty() && !kdelang.isEmpty()) {
555 fname = containsAutoCorrectionFile(kdelang);
556 }
557 if (fname.isEmpty() && kdelang.contains(QLatin1Char('_'))) {
558 kdelang.remove(regpath);
559 fname = containsAutoCorrectionFile(kdelang);
560 }
561 }
562
563 if (d->mAutoCorrectLang.isEmpty()) {
564 d->mAutoCorrectLang = kdelang;
565 }
566 // qDebug() << " fname :" << fname;
567 // qDebug() << " localFileName:" << localFileName;
568
569 if (localFileName.isEmpty()) {
570 loadGlobalFileName(fname);
571 } else {
572 loadLocalFileName(localFileName, fname);
573 }
574}
575
576QString AutoCorrectionSettings::containsAutoCorrectionFile(const QString &fileName)
577{
578 return AutoCorrectionUtils::containsAutoCorrectionFile(fileName, d->mCustomSystemPath, d->mCustomWritablePath);
579}
580
581AutoCorrectionUtils::TypographicQuotes AutoCorrectionSettings::doubleFrenchQuotes() const
582{
583 return d->mDoubleFrenchQuotes;
584}
585
586void AutoCorrectionSettings::setDoubleFrenchQuotes(const AutoCorrectionUtils::TypographicQuotes &newDoubleFrenchQuotes)
587{
588 d->mDoubleFrenchQuotes = newDoubleFrenchQuotes;
589}
590
591QString AutoCorrectionSettings::customWritablePath() const
592{
593 return d->mCustomWritablePath;
594}
595
596void AutoCorrectionSettings::setCustomWritablePath(const QString &path)
597{
598 d->mCustomWritablePath = path;
599}
600
601QString AutoCorrectionSettings::customSystemPath() const
602{
603 return d->mCustomSystemPath;
604}
605
606void AutoCorrectionSettings::setCustomSystemPath(const QString &path)
607{
608 d->mCustomSystemPath = path;
609}
610
611QDebug operator<<(QDebug d, const TextAutoCorrectionCore::AutoCorrectionSettings &t)
612{
613 d << "mAddNonBreakingSpace " << t.nonBreakingSpace();
614 d << "mSuperScriptAppendix " << t.isSuperScript();
615 d << "mEnabled " << t.isEnabledAutoCorrection();
616 d << "mAutoBoldUnderline " << t.isAutoBoldUnderline();
617 d << "mAutoFormatUrl " << t.isAutoFormatUrl();
618 d << "mReplaceSingleQuotes " << t.isReplaceSingleQuotes();
619 d << "mReplaceDoubleQuotes " << t.isReplaceDoubleQuotes();
620 d << "mAdvancedAutocorrect " << t.isAdvancedAutocorrect();
621 d << "mCapitalizeWeekDays " << t.isCapitalizeWeekDays();
622 d << "mAutoFractions " << t.isAutoFractions();
623 d << "mFixTwoUppercaseChars " << t.isFixTwoUppercaseChars();
624 d << "mUppercaseFirstCharOfSentence " << t.isUppercaseFirstCharOfSentence();
625 d << "mSingleSpaces " << t.isSingleSpaces();
626 d << "mMaxFindStringLength " << t.maxFindStringLength();
627 d << "mMinFindStringLength " << t.minFindStringLength();
628 d << "mNonBreakingSpace " << t.nonBreakingSpace();
629 d << "mAutoCorrectLang " << t.language();
630 d << "mTwoUpperLetterExceptions " << t.twoUpperLetterExceptions();
631 d << "mUpperCaseExceptions " << t.upperCaseExceptions();
632 d << "mSuperScriptEntries " << t.superScriptEntries();
633 d << "mAutocorrectEntries " << t.autocorrectEntries();
634 d << "mTypographicDoubleQuotes " << t.typographicDoubleQuotes();
635 d << "mTypographicSingleQuotes " << t.typographicSingleQuotes();
636 d << "mReplaceDoubleQuotesByFrenchQuotes " << t.isReplaceDoubleQuotesByFrenchQuotes();
637 return d;
638}
void requestSync()
Call this slot instead of directly KConfig::sync() to minimize the overall config writes.
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
QString path(const QString &relativePath)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
const_reference at(qsizetype i) const const
bool isEmpty() const const
QLocale system()
QStringList uiLanguages() const const
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.