1/*
2 * SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6#ifndef SONNET_SETTINGS_H
7#define SONNET_SETTINGS_H
8
9#include <QAbstractListModel>
10#include <QObject>
11#include <QString>
12#include <QStringList>
13
14#include "sonnetcore_export.h"
15
16#include <memory>
17
18namespace Sonnet
19{
20class Loader;
21class SettingsPrivate;
22
23class SONNETCORE_EXPORT Settings : public QObject
24{
25 Q_OBJECT
26 /// This property holds whether Sonnet should skip checkign words starting with an uppercase letter.
27 Q_PROPERTY(bool skipUppercase READ skipUppercase WRITE setSkipUppercase NOTIFY skipUppercaseChanged)
28 /// This property holds whether Sonnet should autodetect language.
29 Q_PROPERTY(bool autodetectLanguage READ autodetectLanguage WRITE setAutodetectLanguage NOTIFY autodetectLanguageChanged)
30 /// This property holds whether Sonnet should run spellchecking checks in the background.
31 Q_PROPERTY(bool backgroundCheckerEnabled READ backgroundCheckerEnabled WRITE setBackgroundCheckerEnabled NOTIFY backgroundCheckerEnabledChanged)
32 /// This property holds whether Sonnet should be enabled by default.
33 Q_PROPERTY(bool checkerEnabledByDefault READ checkerEnabledByDefault WRITE setCheckerEnabledByDefault NOTIFY checkerEnabledByDefaultChanged)
34 /// This property holds whether Sonnet should skip checking compounds words.
35 Q_PROPERTY(bool skipRunTogether READ skipRunTogether WRITE setSkipRunTogether NOTIFY skipRunTogetherChanged)
36 /// This property holds the list of ignored words.
37 Q_PROPERTY(QStringList currentIgnoreList READ currentIgnoreList WRITE setCurrentIgnoreList NOTIFY currentIgnoreListChanged)
38 /// This property holds the list of preferred languages.
39 Q_PROPERTY(QStringList preferredLanguages READ preferredLanguages WRITE setPreferredLanguages NOTIFY preferredLanguagesChanged)
40 /// This property holds the default language for spell checking.
41 Q_PROPERTY(QString defaultLanguage READ defaultLanguage WRITE setDefaultLanguage NOTIFY defaultLanguageChanged)
42
43 /// This property holds a Qt Model containing all the preferred dictionaries
44 /// with language description and theirs codes. This model makes the
45 /// Qt::DisplayRole as well as the roles defined in \ref DictionaryRoles
46 /// available.
47 /// \since 5.88
48 Q_PROPERTY(QAbstractListModel *dictionaryModel READ dictionaryModel CONSTANT)
49
50 Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged)
51
52public:
53 /// Roles for \ref dictionaryModel
54 enum DictionaryRoles {
55 LanguageCodeRole = Qt::UserRole + 1, //< Language code of the language. This uses "languageCode" as roleNames.
56 PreferredRole, //< This role holds whether the language is one of the preferred languages. This uses "isPreferred" as roleNames.
57 DefaultRole //< This role holds whether the language is the default language. This uses "isDefault" as roleNames.
58 };
59
60 explicit Settings(QObject *parent = nullptr);
61 ~Settings() override;
62
63 void setDefaultLanguage(const QString &lang);
64 QString defaultLanguage() const;
65
66 void setPreferredLanguages(const QStringList &lang);
67 QStringList preferredLanguages() const;
68
69 void setDefaultClient(const QString &client);
70 QString defaultClient() const;
71
72 void setSkipUppercase(bool);
73 bool skipUppercase() const;
74
75 void setAutodetectLanguage(bool);
76 bool autodetectLanguage() const;
77
78 void setSkipRunTogether(bool);
79 bool skipRunTogether() const;
80
81 void setBackgroundCheckerEnabled(bool);
82 bool backgroundCheckerEnabled() const;
83
84 void setCheckerEnabledByDefault(bool);
85 bool checkerEnabledByDefault() const;
86
87 void setCurrentIgnoreList(const QStringList &ignores);
88 QStringList currentIgnoreList() const;
89
90 QStringList clients() const;
91 bool modified() const;
92
93 QAbstractListModel *dictionaryModel();
94
95 Q_INVOKABLE void save();
96
97 static QStringList defaultIgnoreList();
98 static bool defaultSkipUppercase();
99 static bool defaultAutodetectLanguage();
100 static bool defaultBackgroundCheckerEnabled();
101 static bool defaultCheckerEnabledByDefault();
102 static bool defauktSkipRunTogether();
103 static QString defaultDefaultLanguage();
104 static QStringList defaultPreferredLanguages();
105
106Q_SIGNALS:
107 void skipUppercaseChanged();
108 void autodetectLanguageChanged();
109 void backgroundCheckerEnabledChanged();
110 void defaultClientChanged();
111 void defaultLanguageChanged();
112 void preferredLanguagesChanged();
113 void skipRunTogetherChanged();
114 void checkerEnabledByDefaultChanged();
115 void currentIgnoreListChanged();
116 void modifiedChanged();
117
118private:
119 friend class Loader;
120 std::unique_ptr<SettingsPrivate> const d;
121};
122}
123
124#endif // SONNET_SETTINGS_H
125

source code of sonnet/src/core/settings.h