7#include "translatormenu.h"
8#include "texttranslator_debug.h"
9#include "translator/misc/translatorutil.h"
10#include "translator/translatorengineloader.h"
12#include <KConfigGroup>
13#include <KLocalizedString>
14#include <KSharedConfig>
17using namespace TextTranslator;
18TranslatorMenu::TranslatorMenu(
QObject *parent)
23 mMenu->setTitle(
i18n(
"Translate…"));
24 mMenu->setIcon(
QIcon::fromTheme(QStringLiteral(
"preferences-desktop-locale")));
28TranslatorMenu::~TranslatorMenu()
33bool TranslatorMenu::isEmpty()
const
38void TranslatorMenu::updateMenu()
42 const QString engine = groupTranslate.readEntry(QStringLiteral(
"engine"), QStringLiteral(
"google"));
44 const QString currentPluginName = TextTranslator::TranslatorEngineLoader::self()->currentPluginName(engine);
46 if (!currentPluginName.
isEmpty()) {
47 actionText = QStringLiteral(
"[%1] ").
arg(currentPluginName);
49 const auto fromList = groupTranslate.readEntry(QStringLiteral(
"From"),
QStringList());
50 const auto toList = groupTranslate.readEntry(QStringLiteral(
"To"),
QStringList());
51 for (
const auto &fromLang : fromList) {
52 const QString fromLangI18n = TextTranslator::TranslatorUtil::searchI18nFromLanguage(fromLang);
54 qCWarning(TEXTTRANSLATOR_LOG) <<
"Impossible to find \"from\" language " << fromLangI18n;
56 for (
const auto &toLang : toList) {
57 const QString toLangI18n = TextTranslator::TranslatorUtil::searchI18nFromLanguage(toLang);
59 qCWarning(TEXTTRANSLATOR_LOG) <<
"Impossible to find \"to\" language " << fromLangI18n;
61 if (fromLangI18n != toLangI18n) {
62 auto action =
new QAction(mMenu);
63 action->setText(QStringLiteral(
"%1%2 -> %3").arg(actionText, fromLangI18n, toLangI18n));
65 Q_EMIT translate(fromLang, toLang, mModelIndex);
82 mModelIndex = newModelIndex;
85QMenu *TranslatorMenu::menu()
const
90#include "moc_translatormenu.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...)
void triggered(bool checked)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
QString arg(Args &&... args) const const
bool isEmpty() const const