File indexing completed on 2024-11-24 04:16:55

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006   Based on translatelocally code
0007 */
0008 
0009 #pragma once
0010 #include "bergamotengineutils.h"
0011 #include "libbergamot_export.h"
0012 #include "translation.h"
0013 #include <QList>
0014 #include <QObject>
0015 #include <QString>
0016 #include <condition_variable>
0017 #include <memory>
0018 #include <mutex>
0019 #include <thread>
0020 struct ModelDescription;
0021 struct TranslationInput;
0022 
0023 class LIBBERGAMOT_EXPORT BergamotMarianInterface : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit BergamotMarianInterface(QObject *parent = nullptr);
0028     ~BergamotMarianInterface() override;
0029 
0030     void translate(const QString &str);
0031     [[nodiscard]] QString model() const;
0032 
0033     void setModel(const QString &pathModelDir, const BergamotEngineUtils::SettingsInfo &settings);
0034 
0035 Q_SIGNALS:
0036     void translationReady(Translation translation);
0037     void pendingChanged(bool isBusy); // Disables issuing another translation while we are busy.
0038     void errorText(const QString &message);
0039 
0040 private:
0041     std::unique_ptr<TranslationInput> mPendingInput;
0042     std::unique_ptr<ModelDescription> mPendingModel;
0043 
0044     std::mutex mMutex;
0045     std::condition_variable mConditionVariable;
0046 
0047     std::thread mWorke;
0048     QString mModelString;
0049     bool mPendingShutdown = false;
0050 };