KTextAddons

lingvaengineclient.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 "lingvaengineclient.h"
8#include "lingvaenginedialog.h"
9#include "lingvaengineplugin.h"
10#include "lingvaengineutil.h"
11#include "translator/misc/translatorutil.h"
12#include <KConfigGroup>
13#include <KLocalizedString>
14#include <KSharedConfig>
15#include <QPointer>
16
17LingvaEngineClient::LingvaEngineClient(QObject *parent)
18 : TextTranslator::TranslatorEngineClient{parent}
19{
20}
21
22LingvaEngineClient::~LingvaEngineClient() = default;
23
24QString LingvaEngineClient::name() const
25{
26 return QStringLiteral("lingva");
27}
28
29QString LingvaEngineClient::translatedName() const
30{
31 return i18n("Lingva");
32}
33
34TextTranslator::TranslatorEnginePlugin *LingvaEngineClient::createTranslator()
35{
36 auto enginePlugin = new LingvaEnginePlugin();
37 connect(this, &LingvaEngineClient::configureChanged, enginePlugin, &LingvaEnginePlugin::slotConfigureChanged);
38 return enginePlugin;
39}
40
41QMap<TextTranslator::TranslatorUtil::Language, QString> LingvaEngineClient::supportedFromLanguages()
42{
43 if (mFromLanguages.isEmpty()) {
44 mFromLanguages = fillLanguages();
45 }
46 return mFromLanguages;
47}
48
49QMap<TextTranslator::TranslatorUtil::Language, QString> LingvaEngineClient::supportedToLanguages()
50{
51 return supportedFromLanguages();
52}
53
54bool LingvaEngineClient::hasConfigurationDialog() const
55{
56 return true;
57}
58
59bool LingvaEngineClient::showConfigureDialog(QWidget *parentWidget)
60{
61 bool settingsChanged = false;
62 QPointer<LingvaEngineDialog> dlg = new LingvaEngineDialog(parentWidget);
63 KConfigGroup myGroup(KSharedConfig::openConfig(), LingvaEngineUtil::groupName());
64 QString lingvaUrl = myGroup.readEntry(LingvaEngineUtil::serverUrlKey(), LingvaEngineUtil::defaultServerUrl());
65 if (lingvaUrl.isEmpty()) {
66 lingvaUrl = LingvaEngineUtil::defaultServerUrl();
67 }
68 dlg->setServerUrl(lingvaUrl);
69 if (dlg->exec()) {
70 const QString serverUrl = dlg->serverUrl();
71 myGroup.writeEntry(LingvaEngineUtil::serverUrlKey(), serverUrl);
72 myGroup.sync();
73 Q_EMIT configureChanged();
74 settingsChanged = true;
75 }
76 delete dlg;
77 return settingsChanged;
78}
79
80TextTranslator::TranslatorEngineClient::EngineType LingvaEngineClient::engineType() const
81{
82 return TextTranslator::TranslatorEngineClient::Network;
83}
84
85bool LingvaEngineClient::isSupported(TextTranslator::TranslatorUtil::Language lang) const
86{
87 switch (lang) {
88 case TextTranslator::TranslatorUtil::ka:
89 case TextTranslator::TranslatorUtil::tl:
90 return false;
91 default:
92 break;
93 }
94 return true;
95}
96
97#include "moc_lingvaengineclient.cpp"
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.