File indexing completed on 2024-05-12 16:16:11

0001 /*
0002   SPDX-FileCopyrightText: 2022-2023 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "texttranslator_export.h"
0010 #include <QNetworkReply>
0011 #include <QObject>
0012 #include <QString>
0013 #include <TextTranslator/TranslatorUtil>
0014 #include <memory>
0015 
0016 namespace TextTranslator
0017 {
0018 class TranslatorEnginePluginPrivate;
0019 class TEXTTRANSLATOR_EXPORT TranslatorEnginePlugin : public QObject
0020 {
0021     Q_OBJECT
0022 public:
0023     explicit TranslatorEnginePlugin(QObject *parent = nullptr);
0024     ~TranslatorEnginePlugin() override;
0025 
0026     virtual void translate() = 0;
0027 
0028     Q_REQUIRED_RESULT QString resultTranslate() const;
0029     void setInputText(const QString &text);
0030     void setFrom(const QString &language);
0031     void setTo(const QString &language);
0032     void setResult(const QString &result);
0033     void setJsonDebug(const QString &debug);
0034 
0035     Q_REQUIRED_RESULT QString inputText() const;
0036     Q_REQUIRED_RESULT QString from() const;
0037     Q_REQUIRED_RESULT QString to() const;
0038     Q_REQUIRED_RESULT QString result() const;
0039     Q_REQUIRED_RESULT QString jsonDebug() const;
0040 
0041     void clear();
0042 
0043 Q_SIGNALS:
0044     void translateDone();
0045     void translateFailed(const QString &errorMessage);
0046     void languagesChanged();
0047 
0048 protected:
0049     void appendResult(const QString &result);
0050     void slotError(QNetworkReply::NetworkError error);
0051     Q_REQUIRED_RESULT bool verifyFromAndToLanguage();
0052     Q_REQUIRED_RESULT bool hasDebug() const;
0053 
0054     Q_REQUIRED_RESULT virtual QString languageCode(const QString &langStr);
0055 
0056 private:
0057     std::unique_ptr<TranslatorEnginePluginPrivate> const d;
0058 };
0059 }