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 #pragma once 0007 #include "libbergamot_export.h" 0008 #include "translator.h" 0009 #include <QObject> 0010 0011 class LIBBERGAMOT_EXPORT ManagerModelTranslator : public QObject 0012 { 0013 Q_OBJECT 0014 public: 0015 struct ProgressInfo { 0016 QString languageName; 0017 qint64 bytesReceived = -1; 0018 qint64 bytesTotal = -1; 0019 }; 0020 explicit ManagerModelTranslator(QObject *parent = nullptr); 0021 ~ManagerModelTranslator() override; 0022 0023 static ManagerModelTranslator *self(); 0024 0025 void downloadListModels(); 0026 0027 [[nodiscard]] QVector<Translator> translators() const; 0028 void setTranslators(const QVector<Translator> &newTranslators); 0029 0030 void loadModelList(const QString &fileName); 0031 0032 void downloadLanguage(const QString &url, const QString &checkSum); 0033 [[nodiscard]] bool needDownloadModelList() const; 0034 Q_SIGNALS: 0035 void errorText(const QString &str); 0036 void progress(const ManagerModelTranslator::ProgressInfo &info); 0037 void extractDone(); 0038 void downLoadModelListDone(); 0039 0040 private: 0041 LIBBERGAMOT_NO_EXPORT void parseListModel(const QJsonObject &obj); 0042 QVector<Translator> mTranslators; 0043 }; 0044 Q_DECLARE_TYPEINFO(ManagerModelTranslator::ProgressInfo, Q_MOVABLE_TYPE);