KTextAddons

libretranslateengineconfigurewidget.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 "libretranslateengineconfigurewidget.h"
8#include <KLineEditEventHandler>
9#include <KLocalizedString>
10#include <QCheckBox>
11#include <QCompleter>
12#include <QFormLayout>
13#include <QLineEdit>
14
15LibreTranslateEngineConfigureWidget::LibreTranslateEngineConfigureWidget(QWidget *parent)
16 : QWidget{parent}
17 , mServerUrl(new QLineEdit(this))
18 , mApiKey(new QLineEdit(this))
19 , mRequiredApiKey(new QCheckBox(i18nc("@option:check", "Server required Api Key"), this))
20{
21 auto mainLayout = new QFormLayout(this);
22 mainLayout->setContentsMargins({});
23 mainLayout->setObjectName(QStringLiteral("mainLayout"));
24
25 mServerUrl->setObjectName(QStringLiteral("mServerUrl"));
26 mServerUrl->setClearButtonEnabled(true);
27 mainLayout->addRow(i18n("Server Url:"), mServerUrl);
28
29 mRequiredApiKey->setObjectName(QStringLiteral("mRequiredApiKey"));
30 mainLayout->addWidget(mRequiredApiKey);
31
32 mApiKey->setObjectName(QStringLiteral("mApiKey"));
33 mApiKey->setClearButtonEnabled(true);
34 mainLayout->addRow(i18n("Api Key:"), mApiKey);
35 connect(mRequiredApiKey, &QCheckBox::clicked, this, &LibreTranslateEngineConfigureWidget::updateApiKeyState);
36
37 const QStringList listServer{
38 QStringLiteral("https://libretranslate.com"),
39 QStringLiteral("https://libretranslate.de"),
40 QStringLiteral("https://translate.argosopentech.com"),
41 QStringLiteral("https://translate.api.skitzen.com"),
42 QStringLiteral("https://translate.fortytwo-it.com"),
43 QStringLiteral("https://translate.terraprint.co"),
44 QStringLiteral("https://lt.vern.cc"),
45 };
46
49
50 auto completer = new QCompleter(listServer, this);
51 completer->setCaseSensitivity(Qt::CaseInsensitive);
52 mServerUrl->setCompleter(completer);
53}
54
55LibreTranslateEngineConfigureWidget::~LibreTranslateEngineConfigureWidget() = default;
56
57void LibreTranslateEngineConfigureWidget::updateApiKeyState(bool state)
58{
59 mApiKey->setEnabled(state);
60}
61
62QString LibreTranslateEngineConfigureWidget::serverUrl() const
63{
64 return mServerUrl->text();
65}
66
67void LibreTranslateEngineConfigureWidget::setServerUrl(const QString &serverUrl)
68{
69 mServerUrl->setText(serverUrl);
70}
71
72QString LibreTranslateEngineConfigureWidget::apiKey() const
73{
74 return mApiKey->text();
75}
76
77void LibreTranslateEngineConfigureWidget::setApiKey(const QString &key)
78{
79 mApiKey->setText(key);
80}
81
82bool LibreTranslateEngineConfigureWidget::serverRequiredApiKey() const
83{
84 return mRequiredApiKey->isChecked();
85}
86
87void LibreTranslateEngineConfigureWidget::setServerRequiredApiKey(bool state)
88{
89 mRequiredApiKey->setChecked(state);
90 updateApiKeyState(state);
91}
92
93#include "moc_libretranslateengineconfigurewidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
bool isChecked() const const
void clicked(bool checked)
CaseInsensitive
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.