grammalecteconfigwidget.cpp 3.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
   Copyright (C) 2019 Montel Laurent <montel@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "grammalecteconfigwidget.h"
Laurent Montel's avatar
Laurent Montel committed
21

Laurent Montel's avatar
Laurent Montel committed
22

23
#include <QVBoxLayout>
24
#include <QTabWidget>
25
#include <KLocalizedString>
26 27
#include <KConfigGroup>
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
28
#include <QCheckBox>
29 30 31 32

GrammalecteConfigWidget::GrammalecteConfigWidget(QWidget *parent)
    : QWidget(parent)
{
33 34
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(QStringLiteral("mainlayout"));
Laurent Montel's avatar
Laurent Montel committed
35
    mainLayout->setMargin(0);
36 37 38 39 40

    QTabWidget *mTab = new QTabWidget(this);
    mTab->setObjectName(QStringLiteral("mTab"));
    mainLayout->addWidget(mTab);
    mTab->addTab(addGeneralTab(), i18n("General"));
Laurent Montel's avatar
Laurent Montel committed
41 42 43
    mGrammarTabWidget = addGrammarTab();
    mTab->addTab(mGrammarTabWidget, i18n("Grammar Settings"));
    loadSettings(); //First
Laurent Montel's avatar
Laurent Montel committed
44
    loadGrammarSettings();
45 46 47 48 49 50
}

GrammalecteConfigWidget::~GrammalecteConfigWidget()
{

}
51

Laurent Montel's avatar
Laurent Montel committed
52 53
void GrammalecteConfigWidget::loadGrammarSettings()
{
Laurent Montel's avatar
Laurent Montel committed
54
    //Remove hardcoded path
Laurent Montel's avatar
Laurent Montel committed
55
    GrammalecteGenerateConfigOptionJob *job = new GrammalecteGenerateConfigOptionJob(this);
Laurent Montel's avatar
Laurent Montel committed
56 57 58 59 60 61 62 63
    job->setPythonPath(QStringLiteral("/usr/bin/python3"));
    job->setGrammarlecteCliPath(QStringLiteral("/compile/kde5/framework/kde/pim/grammalecte/grammalecte-cli.py"));
    connect(job, &GrammalecteGenerateConfigOptionJob::finished, this, &GrammalecteConfigWidget::slotGetSettingsFinished);
    job->start();
}

void GrammalecteConfigWidget::slotGetSettingsFinished(const QVector<GrammalecteGenerateConfigOptionJob::Option> &result)
{
Laurent Montel's avatar
Laurent Montel committed
64
    mListOptions.reserve(result.count());
Laurent Montel's avatar
Laurent Montel committed
65
    for (const GrammalecteGenerateConfigOptionJob::Option &opt : result) {
Laurent Montel's avatar
Laurent Montel committed
66 67
        QCheckBox *box = new QCheckBox(opt.description, this);
        box->setProperty("optionname", opt.optionName);
Laurent Montel's avatar
Laurent Montel committed
68
        box->setChecked(opt.defaultValue);
Laurent Montel's avatar
Laurent Montel committed
69 70
        mGrammarTabWidget->layout()->addWidget(box);
        mListOptions.append(box);
Laurent Montel's avatar
Laurent Montel committed
71
    }
Laurent Montel's avatar
Laurent Montel committed
72 73
}

74 75
QWidget *GrammalecteConfigWidget::addGrammarTab()
{
Laurent Montel's avatar
Laurent Montel committed
76 77 78 79 80 81
    QWidget *grammarTabWidget = new QWidget(this);
    grammarTabWidget->setObjectName(QStringLiteral("grammar"));
    QVBoxLayout *layout = new QVBoxLayout(grammarTabWidget);
    layout->setObjectName(QStringLiteral("grammartablayout"));
    layout->setMargin(0);
    return grammarTabWidget;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
}

QWidget *GrammalecteConfigWidget::addGeneralTab()
{
    QWidget *w = new QWidget(this);
    w->setObjectName(QStringLiteral("general"));
    return w;
}

void GrammalecteConfigWidget::loadSettings()
{
    KConfigGroup grp(KSharedConfig::openConfig(), "Grammalecte");
    //TODO
}

void GrammalecteConfigWidget::saveSettings()
{
    KConfigGroup grp(KSharedConfig::openConfig(), "Grammalecte");
    //TODO
}