File indexing completed on 2024-12-22 04:28:09
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 #include "autocorrectionutils.h" 0009 #include "textautocorrectioncore_export.h" 0010 #include <QDebug> 0011 #include <QSet> 0012 namespace TextAutoCorrectionCore 0013 { 0014 class AutoCorrectionSettingsPrivate; 0015 class TEXTAUTOCORRECTIONCORE_EXPORT AutoCorrectionSettings 0016 { 0017 public: 0018 AutoCorrectionSettings(); 0019 ~AutoCorrectionSettings(); 0020 0021 [[nodiscard]] bool isEnabledAutoCorrection() const; 0022 [[nodiscard]] bool isUppercaseFirstCharOfSentence() const; 0023 [[nodiscard]] bool isFixTwoUppercaseChars() const; 0024 [[nodiscard]] bool isSingleSpaces() const; 0025 [[nodiscard]] bool isAutoFractions() const; 0026 [[nodiscard]] bool isCapitalizeWeekDays() const; 0027 [[nodiscard]] bool isReplaceDoubleQuotes() const; 0028 [[nodiscard]] bool isReplaceSingleQuotes() const; 0029 [[nodiscard]] bool isAdvancedAutocorrect() const; 0030 [[nodiscard]] bool isAutoFormatUrl() const; 0031 [[nodiscard]] bool isAutoBoldUnderline() const; 0032 [[nodiscard]] bool isSuperScript() const; 0033 0034 [[nodiscard]] bool isAddNonBreakingSpace() const; 0035 [[nodiscard]] bool isReplaceDoubleQuotesByFrenchQuotes() const; 0036 0037 [[nodiscard]] TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes typographicSingleQuotes() const; 0038 [[nodiscard]] TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes typographicDoubleQuotes() const; 0039 void setTypographicSingleQuotes(TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes singleQuote); 0040 void setTypographicDoubleQuotes(TextAutoCorrectionCore::AutoCorrectionUtils::TypographicQuotes doubleQuote); 0041 0042 void setAutoFormatUrl(bool b); 0043 void setAutoBoldUnderline(bool b); 0044 void setSuperScript(bool b); 0045 void setAddNonBreakingSpace(bool b); 0046 void setCapitalizeWeekDays(bool b); 0047 void setReplaceDoubleQuotes(bool b); 0048 void setReplaceSingleQuotes(bool b); 0049 void setAdvancedAutocorrect(bool b); 0050 void setEnabledAutoCorrection(bool b); 0051 void setReplaceDoubleQuotesByFrenchQuotes(bool b); 0052 0053 void readConfig(); 0054 0055 void writeConfig(); 0056 0057 void setAutoFractions(bool newAutoFractions); 0058 0059 void setSingleSpaces(bool newSingleSpaces); 0060 0061 void setFixTwoUppercaseChars(bool newFixTwoUppercaseChars); 0062 0063 void setUppercaseFirstCharOfSentence(bool newUppercaseFirstCharOfSentence); 0064 0065 void setUpperCaseExceptions(const QSet<QString> &exceptions); 0066 void setTwoUpperLetterExceptions(const QSet<QString> &exceptions); 0067 [[nodiscard]] QSet<QString> upperCaseExceptions() const; 0068 [[nodiscard]] QSet<QString> twoUpperLetterExceptions() const; 0069 0070 void setLanguage(const QString &lang, bool forceGlobal = false); 0071 [[nodiscard]] QString language() const; 0072 0073 [[nodiscard]] bool isFrenchLanguage() const; 0074 void setAutocorrectEntries(const QHash<QString, QString> &entries); 0075 0076 [[nodiscard]] QHash<QString, QString> autocorrectEntries() const; 0077 [[nodiscard]] bool addAutoCorrect(const QString ¤tWord, const QString &replaceWord); 0078 0079 [[nodiscard]] QChar nonBreakingSpace() const; 0080 void setNonBreakingSpace(const QChar &newNonBreakingSpace); 0081 0082 [[nodiscard]] QHash<QString, QString> superScriptEntries() const; 0083 void setSuperScriptEntries(const QHash<QString, QString> &newSuperScriptEntries); 0084 0085 void writeAutoCorrectionFile(const QString &filename = QString()); 0086 [[nodiscard]] int maxFindStringLength() const; 0087 0088 [[nodiscard]] int minFindStringLength() const; 0089 0090 void loadLocalFileName(const QString &localFileName, const QString &fname); 0091 void loadGlobalFileName(const QString &fname); 0092 0093 [[nodiscard]] AutoCorrectionUtils::TypographicQuotes doubleFrenchQuotes() const; 0094 void setDoubleFrenchQuotes(const AutoCorrectionUtils::TypographicQuotes &newDoubleFrenchQuotes); 0095 0096 [[nodiscard]] QString customWritablePath() const; 0097 void setCustomWritablePath(const QString &path); 0098 0099 [[nodiscard]] QString customSystemPath() const; 0100 void setCustomSystemPath(const QString &path); 0101 0102 private: 0103 TEXTAUTOCORRECTIONCORE_NO_EXPORT void migrateKMailXmlFile(); 0104 TEXTAUTOCORRECTIONCORE_NO_EXPORT void readAutoCorrectionFile(bool forceGlobal = false); 0105 [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT QString containsAutoCorrectionFile(const QString &fileName); 0106 0107 friend class AutoCorrectionSettingsPrivate; 0108 std::unique_ptr<AutoCorrectionSettingsPrivate> const d; 0109 }; 0110 } 0111 TEXTAUTOCORRECTIONCORE_EXPORT QDebug operator<<(QDebug d, const TextAutoCorrectionCore::AutoCorrectionSettings &t);