7#include "bergamotengineclient.h"
8#include "begamotenginedialog.h"
9#include "bergamotengineplugin.h"
10#include "translator/misc/translatorutil.h"
11#include <KConfigGroup>
12#include <KLocalizedString>
13#include <KSharedConfig>
16BergamotEngineClient::BergamotEngineClient(
QObject *parent)
17 : TextTranslator::TranslatorEngineClient{parent}
19 updateInstalledLanguage();
22BergamotEngineClient::~BergamotEngineClient() =
default;
24QString BergamotEngineClient::name()
const
26 return QStringLiteral(
"bergamot");
29QString BergamotEngineClient::translatedName()
const
31 return i18n(
"Bergamot");
34TextTranslator::TranslatorEnginePlugin *BergamotEngineClient::createTranslator()
36 auto enginePlugin =
new BergamotEnginePlugin();
37 connect(
this, &BergamotEngineClient::configureChanged, enginePlugin, &BergamotEnginePlugin::slotConfigureChanged);
43 return mFromLanguages;
51bool BergamotEngineClient::hasConfigurationDialog()
const
56bool BergamotEngineClient::showConfigureDialog(
QWidget *parentWidget)
58 bool settingsChanged =
false;
61 BergamotEngineUtils::SettingsInfo info;
62 info.loadSettingsInfo();
63 dlg->setSettingsInfo(info);
65 info = dlg->settingsInfo();
66 info.saveSettingsInfo();
67 updateInstalledLanguage();
69 settingsChanged =
true;
72 return settingsChanged;
75void BergamotEngineClient::updateInstalledLanguage()
77 mLanguageInstalled = BergamotEngineUtils::languageLocallyStored();
78 updateFromLanguageList();
79 updateToLanguageList();
82void BergamotEngineClient::updateFromLanguageList()
84 mFromLanguages.
clear();
85 for (
const auto &lang : std::as_const(mLanguageInstalled)) {
86 const TextTranslator::TranslatorUtil::Language langUtil = TextTranslator::TranslatorUtil::stringToLanguage(lang.from);
87 mFromLanguages.
insert(langUtil, TextTranslator::TranslatorUtil::translatedLanguage(langUtil));
92void BergamotEngineClient::updateToLanguageList()
95 for (
const auto &lang : std::as_const(mLanguageInstalled)) {
97 if (lang.to == mLanguageCode || mLanguageCode.
isEmpty()) {
98 const TextTranslator::TranslatorUtil::Language langUtil = TextTranslator::TranslatorUtil::stringToLanguage(lang.to);
100 mToLanguages.
insert(langUtil, TextTranslator::TranslatorUtil::translatedLanguage(langUtil));
105bool BergamotEngineClient::hasInvertSupport()
const
110void BergamotEngineClient::generateToListFromCurrentToLanguage(
const QString &languageCode)
112 mLanguageCode = languageCode;
113 updateToLanguageList();
116TextTranslator::TranslatorEngineClient::EngineType BergamotEngineClient::engineType()
const
118 return TextTranslator::TranslatorEngineClient::Locale;
121bool BergamotEngineClient::isSupported(TextTranslator::TranslatorUtil::Language lang)
const
127void BergamotEngineClient::updateListLanguages()
129 updateInstalledLanguage();
132#include "moc_bergamotengineclient.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...)
iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const