Commit 2e08338e authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Provide translate-shell functionality information and check

This change adds an installation status information page as well as an
interactive test to the settings menu for checking if the translat-shell
integration works. Once more translate engines (like Wiktionary) are
supported, this dialog should be extended for selecting the main eninge.
parent 2e065bf1
......@@ -84,6 +84,7 @@ set(parley_LIB_SRCS
settings/generaloptions.cpp
settings/parleyprefs.cpp
settings/viewoptions.cpp
settings/translationshelloptions.cpp
settings/documentproperties.cpp
settings/languageproperties.cpp
settings/languagepropertiespage.cpp
......@@ -130,6 +131,7 @@ ki18n_wrap_ui(parley_LIB_SRCS
settings/languagepropertiespage.ui
settings/documentproperties.ui
settings/kgametheme/kgamethemeselector.ui
settings/translationshellpage.ui
statistics/statisticsmainwindow.ui
dashboard/dashboard.ui
)
......
......@@ -6,9 +6,9 @@
*/
#include "parleyprefs.h"
#include "generaloptions.h"
#include "kgametheme/kgamethemeselector.h"
#include "translationshelloptions.h"
#include "viewoptions.h"
#include <KConfigSkeleton>
#include <KLocalizedString>
......@@ -23,11 +23,15 @@ ParleyPrefs::ParleyPrefs(KEduVocDocument *doc, QWidget *parent, const QString &n
addPage(new KGameThemeSelector(this, config), i18n("Theme"), QStringLiteral("games-config-theme"));
m_generalOptions = new GeneralOptions(0);
addPage(m_generalOptions, i18nc("title:window general settings", "General"), QStringLiteral("parley"), i18n("General Settings"), true);
m_generalOptions = new GeneralOptions(this);
addPage(m_generalOptions, i18nc("title:window general settings", "General"), QStringLiteral("parley"), i18n("General Settings"));
m_viewOptions = new ViewOptions(this);
addPage(m_viewOptions, i18n("View"), QStringLiteral("view-choose"), i18n("View Settings"));
m_translationShellOptions = new TranslationShellOptions(this);
addPage(m_translationShellOptions, i18n("Online Translations"), QStringLiteral("internet-services"), i18n("Online Translation Services"));
m_viewOptions = new ViewOptions(0);
addPage(m_viewOptions, i18n("View"), QStringLiteral("view-choose"), i18n("View Settings"), true);
setHelp(QString(), QStringLiteral("parley"));
}
......
......@@ -15,12 +15,9 @@
class GeneralOptions;
class ViewOptions;
class PasteOptions;
class PluginOptions;
class TranslationShellOptions;
class KEduVocDocument;
class KComboBox;
class KConfigSkeleton;
class ParleyPrefs : public KConfigDialog
......@@ -61,8 +58,7 @@ protected:
private:
GeneralOptions *m_generalOptions{nullptr};
ViewOptions *m_viewOptions{nullptr};
PasteOptions *m_pasteOptions{nullptr};
PluginOptions *m_pluginOptions{nullptr};
TranslationShellOptions *m_translationShellOptions{nullptr};
KConfigSkeleton *m_config{nullptr};
KEduVocDocument *m_doc{nullptr};
......
/*
SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "translationshelloptions.h"
#include "translateshelladapter.h"
#include <KLed>
#include <KLocalizedString>
TranslationShellOptions::TranslationShellOptions(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
KLed *installStatusLed = new KLed(this);
installStatusLed->setLook(KLed::Look::Flat);
QLabel *installStatusText = new QLabel(this);
if (mTranslationShellAdapter.isTranslateShellAvailable()) {
installStatusLed->setState(KLed::State::On);
installStatusText->setText(i18n("translate-shell is available."));
} else {
installStatusLed->setState(KLed::State::Off);
installStatusText->setText(i18n("translate-shell executable could not be found."));
buttonRunTest->setEnabled(false);
}
formLayoutInstalledState->insertRow(0, installStatusLed, installStatusText);
connect(buttonRunTest, &QToolButton::clicked, this, &TranslationShellOptions::runTranslateShellTest);
labelResultArea->setText("...");
}
void TranslationShellOptions::runTranslateShellTest()
{
auto translationResult = mTranslationShellAdapter.translate("parley", "en", "de");
if (translationResult.m_suggestions.count() > 0) {
labelResultArea->setText(translationResult.m_suggestions.first());
} else {
labelResultArea->setText(i18n("Error"));
}
}
/*
SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef TRANSLATIONSHELLOPTIONS_H
#define TRANSLATIONSHELLOPTIONS_H
#include "translateshelladapter.h"
#include "ui_translationshellpage.h"
class TranslationShellOptions : public QWidget, public Ui::TranslationShellPage
{
Q_OBJECT
public:
explicit TranslationShellOptions(QWidget *parent = nullptr);
private slots:
void runTranslateShellTest();
private:
TranslateShellAdapter mTranslationShellAdapter;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Peter Hedlund</author>
<class>TranslationShellPage</class>
<widget class="QWidget" name="TranslationShellPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<height>246</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBoxInstalledStatus">
<property name="title">
<string>Translation Shell Integration</string>
</property>
<layout class="QVBoxLayout" name="groupBoxLayoutInstalledStatus">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string notr="true">Parley provides access to translation webservices via utilizing the &quot;translate-shell&quot; tool.</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayoutInstalledState"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Run Interactive Functionality Test</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>The interaction test request translation of English word &quot;parley&quot; into German.</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QToolButton" name="buttonRunTest">
<property name="text">
<string>Start online test</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Result:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelResultArea">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment