File indexing completed on 2024-12-22 04:28:23

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 "libvoskspeechtotext_export.h"
0009 #include "voskengineutils.h"
0010 
0011 #include "voskspeechtotextinfo.h"
0012 #include <QAbstractListModel>
0013 
0014 class LIBVOSKSPEECHTOTEXT_EXPORT VoskSpeechToTextModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 public:
0018     enum VoskRoles {
0019         Identifier,
0020         LangText,
0021         Size,
0022         SizeByte,
0023         CheckSum,
0024         Installed,
0025         AvailableVersion,
0026         InstalledVersion,
0027         NeedToUpdateLanguage,
0028         Name,
0029         Url,
0030         LastColumn = Url,
0031     };
0032 
0033     Q_ENUM(VoskRoles)
0034 
0035     explicit VoskSpeechToTextModel(QObject *parent = nullptr);
0036     ~VoskSpeechToTextModel() override;
0037 
0038     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0039     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0040 
0041     void clear();
0042 
0043     [[nodiscard]] QVector<VoskSpeechToTextInfo> speechToTextInfos() const;
0044     void setSpeechToTextInfos(const QVector<VoskSpeechToTextInfo> &newSpeechToTextInfo);
0045 
0046     void updateInstalledLanguage();
0047 
0048     void removeLanguage(const QString &name);
0049 
0050 protected:
0051     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0052     int columnCount(const QModelIndex &parent) const override;
0053 
0054 private:
0055     [[nodiscard]] bool isInstalled(const QString &shortName) const;
0056     [[nodiscard]] QString versionInstalled(const QString &shortName) const;
0057     [[nodiscard]] bool needToUpdateLanguageModel(const VoskSpeechToTextInfo &language) const;
0058     QVector<VoskSpeechToTextInfo> mSpeechToTextInfos;
0059     QVector<VoskEngineUtils::LanguageInstalled> mLanguageInstalled;
0060 };