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 
0007 #pragma once
0008 #include "bergamotengineutils.h"
0009 #include "libbergamot_private_export.h"
0010 #include "translator.h"
0011 #include <QAbstractListModel>
0012 
0013 class LIBBERGAMOT_TESTS_EXPORT TranslatorModel : public QAbstractListModel
0014 {
0015     Q_OBJECT
0016 public:
0017     enum TranslatorRoles {
0018         Source,
0019         Target,
0020         TypeTranslator,
0021         Repository,
0022         InstalledVersion,
0023         AvailableVersion,
0024         Installed,
0025         CheckSum,
0026         Identifier,
0027         NeedToUpdateLanguage,
0028         Url,
0029         LastColumn = Url,
0030     };
0031 
0032     Q_ENUM(TranslatorRoles)
0033 
0034     explicit TranslatorModel(QObject *parent = nullptr);
0035     ~TranslatorModel() override;
0036 
0037     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0038     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0039 
0040     void clear();
0041 
0042     void insertTranslators(const QVector<Translator> &translators);
0043 
0044     [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0045     [[nodiscard]] int columnCount(const QModelIndex &parent) const override;
0046 
0047     void removeLanguage(const QString &identifier);
0048 
0049     void updateInstalledLanguage();
0050 
0051 private:
0052     [[nodiscard]] bool isInstalled(const QString &shortName) const;
0053     [[nodiscard]] int versionInstalled(const QString &shortName) const;
0054     [[nodiscard]] bool needToUpdateLanguageModel(const Translator &translator) const;
0055     QVector<Translator> mTranslators;
0056     QVector<BergamotEngineUtils::LanguageInstalled> mLanguageInstalled;
0057 };