7#include "deeplengineclient.h"
8#include "deeplengineconfiguredialog.h"
9#include "deeplengineplugin.h"
10#include "deeplengineutil.h"
11#include "deepltranslator_debug.h"
12#include "translator/misc/translatorutil.h"
13#include <KConfigGroup>
14#include <KLocalizedString>
15#include <KSharedConfig>
17#include <qt6keychain/keychain.h>
19DeeplEngineClient::DeeplEngineClient(
QObject *parent)
20 : TextTranslator::TranslatorEngineClient{parent}
24DeeplEngineClient::~DeeplEngineClient() =
default;
26QString DeeplEngineClient::name()
const
28 return QStringLiteral(
"deepl");
31QString DeeplEngineClient::translatedName()
const
36TextTranslator::TranslatorEnginePlugin *DeeplEngineClient::createTranslator()
38 auto enginePlugin =
new DeeplEnginePlugin();
39 connect(
this, &DeeplEngineClient::configureChanged, enginePlugin, &DeeplEnginePlugin::slotConfigureChanged);
46 mFromLanguages = fillLanguages();
48 return mFromLanguages;
53 return supportedFromLanguages();
56bool DeeplEngineClient::isSupported(TextTranslator::TranslatorUtil::Language lang)
const
59 case TextTranslator::TranslatorUtil::automatic:
60 case TextTranslator::TranslatorUtil::bg:
61 case TextTranslator::TranslatorUtil::cs:
62 case TextTranslator::TranslatorUtil::da:
63 case TextTranslator::TranslatorUtil::de:
64 case TextTranslator::TranslatorUtil::en:
65 case TextTranslator::TranslatorUtil::el:
66 case TextTranslator::TranslatorUtil::es:
67 case TextTranslator::TranslatorUtil::et:
68 case TextTranslator::TranslatorUtil::fi:
69 case TextTranslator::TranslatorUtil::fr:
70 case TextTranslator::TranslatorUtil::hu:
71 case TextTranslator::TranslatorUtil::id:
72 case TextTranslator::TranslatorUtil::it:
73 case TextTranslator::TranslatorUtil::ja:
74 case TextTranslator::TranslatorUtil::lt:
75 case TextTranslator::TranslatorUtil::lv:
76 case TextTranslator::TranslatorUtil::nl:
77 case TextTranslator::TranslatorUtil::pl:
78 case TextTranslator::TranslatorUtil::pt:
79 case TextTranslator::TranslatorUtil::ro:
80 case TextTranslator::TranslatorUtil::ru:
81 case TextTranslator::TranslatorUtil::sk:
82 case TextTranslator::TranslatorUtil::sl:
83 case TextTranslator::TranslatorUtil::sv:
84 case TextTranslator::TranslatorUtil::tr:
85 case TextTranslator::TranslatorUtil::uk:
86 case TextTranslator::TranslatorUtil::zh:
94bool DeeplEngineClient::hasConfigurationDialog()
const
99bool DeeplEngineClient::showConfigureDialog(
QWidget *parentWidget)
101 bool settingsChanged =
false;
104 dlg->setUseFreeLicenceKey(myGroup.readEntry(DeeplEngineUtil::freeLicenseKey(),
false));
106 auto readJob =
new QKeychain::ReadPasswordJob(DeeplEngineUtil::translatorGroupName(),
this);
107 connect(readJob, &QKeychain::Job::finished,
this, [dlg](QKeychain::Job *baseJob) {
111 qCWarning(TRANSLATOR_DEEPL_LOG) <<
"We have an error during reading password " << job->errorString();
113 dlg->setApiKey(job->textData());
116 readJob->setKey(DeeplEngineUtil::apiGroupName());
119 myGroup.writeEntry(DeeplEngineUtil::freeLicenseKey(), dlg->useFreeLicenceKey());
122 auto writeJob =
new QKeychain::WritePasswordJob(DeeplEngineUtil::translatorGroupName(),
this);
123 connect(writeJob, &QKeychain::Job::finished,
this, &DeeplEngineClient::slotPasswordWritten);
124 writeJob->setKey(DeeplEngineUtil::apiGroupName());
125 writeJob->setTextData(dlg->apiKey());
127 Q_EMIT configureChanged();
128 settingsChanged =
true;
131 return settingsChanged;
134TextTranslator::TranslatorEngineClient::EngineType DeeplEngineClient::engineType()
const
136 return TextTranslator::TranslatorEngineClient::Network;
139void DeeplEngineClient::slotPasswordWritten(QKeychain::Job *baseJob)
141 if (baseJob->error()) {
142 qCWarning(TRANSLATOR_DEEPL_LOG) <<
"Error writing password using QKeychain:" << baseJob->errorString();
146#include "moc_deeplengineclient.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
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)