File indexing completed on 2024-05-12 16:16:01
0001 /* 0002 SPDX-FileCopyrightText: 2019-2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "grammalectemanager.h" 0008 #include <KConfigGroup> 0009 #include <KSharedConfig> 0010 #include <QStandardPaths> 0011 namespace 0012 { 0013 static const char myConfigGroupName[] = "Grammalecte"; 0014 } 0015 using namespace TextGrammarCheck; 0016 GrammalecteManager::GrammalecteManager(QObject *parent) 0017 : QObject(parent) 0018 { 0019 loadSettings(); 0020 } 0021 0022 GrammalecteManager::~GrammalecteManager() = default; 0023 0024 GrammalecteManager *GrammalecteManager::self() 0025 { 0026 static GrammalecteManager s_self; 0027 return &s_self; 0028 } 0029 0030 void GrammalecteManager::saveSettings() 0031 { 0032 KConfigGroup grp(KSharedConfig::openConfig(), QLatin1String(myConfigGroupName)); 0033 grp.writeEntry(QStringLiteral("pythonpath"), mPythonPath); 0034 grp.writeEntry(QStringLiteral("grammalectepath"), mGrammalectePath); 0035 grp.writeEntry(QStringLiteral("options"), mOptions); 0036 } 0037 0038 QStringList GrammalecteManager::options() const 0039 { 0040 return mOptions; 0041 } 0042 0043 void GrammalecteManager::setOptions(const QStringList &saveOptions) 0044 { 0045 mOptions = saveOptions; 0046 } 0047 0048 void GrammalecteManager::loadSettings() 0049 { 0050 KConfigGroup grp(KSharedConfig::openConfig(), QLatin1String(myConfigGroupName)); 0051 mPythonPath = grp.readEntry(QStringLiteral("pythonpath")); 0052 if (mPythonPath.isEmpty()) { 0053 mPythonPath = QStandardPaths::findExecutable(QStringLiteral("python3")); 0054 } 0055 mGrammalectePath = grp.readEntry(QStringLiteral("grammalectepath")); 0056 mOptions = grp.readEntry(QStringLiteral("options"), QStringList()); 0057 } 0058 0059 QString GrammalecteManager::pythonPath() const 0060 { 0061 return mPythonPath; 0062 } 0063 0064 QString GrammalecteManager::grammalectePath() const 0065 { 0066 return mGrammalectePath; 0067 } 0068 0069 void GrammalecteManager::setPythonPath(const QString &pythonPath) 0070 { 0071 mPythonPath = pythonPath; 0072 } 0073 0074 void GrammalecteManager::setGrammalectePath(const QString &grammalectePath) 0075 { 0076 mGrammalectePath = grammalectePath; 0077 } 0078 0079 #include "moc_grammalectemanager.cpp"