7#include "voskextractlanguagejob.h"
8#include "libvoskspeechtotext_debug.h"
9#include "voskengineutils.h"
10#include <KLocalizedString>
14VoskExtractLanguageJob::VoskExtractLanguageJob(
QObject *parent)
19VoskExtractLanguageJob::~VoskExtractLanguageJob() =
default;
21bool VoskExtractLanguageJob::canStart()
const
23 return !mSource.isEmpty();
29 const QStringList lst =
dir->entries();
31 for (
const QString &it : lst) {
32 const KArchiveEntry *entry =
dir->entry(it);
35 extractRecursive(
static_cast<const KArchiveDirectory *
>(entry), path + it + QLatin1Char(
'/'));
36 }
else if (entry->
isFile()) {
37 const KArchiveEntry *filePathEntry =
dir->entry(it);
38 const auto filePath =
static_cast<const KArchiveFile *
>(filePathEntry);
39 const QString storeDirectory{VoskEngineUtils::storageLanguagePath() + QLatin1Char(
'/') +
path};
41 if (!QDir().
mkpath(storeDirectory)) {
42 qCWarning(LIBVOSKSPEECHTOTEXT_LOG) <<
"Impossible to create :" << storeDirectory;
45 if (!filePath->copyTo(storeDirectory)) {
46 qCWarning(LIBVOSKSPEECHTOTEXT_LOG) <<
"Impossible to copy to " << storeDirectory;
52void VoskExtractLanguageJob::start()
55 qCWarning(LIBVOSKSPEECHTOTEXT_LOG) <<
"Impossible to start ExtractLanguageJob";
56 Q_EMIT errorText(
i18n(
"Impossible to extract language"));
61 auto zip =
new KZip(mSource);
63 qCWarning(LIBVOSKSPEECHTOTEXT_LOG) <<
"Impossible to open temporary file" << mSource;
68 if (!QDir().
mkpath(VoskEngineUtils::storageLanguagePath())) {
69 qCWarning(LIBVOSKSPEECHTOTEXT_LOG) <<
"Impossible to create path" << VoskEngineUtils::storageLanguagePath();
74 const KArchiveDirectory *zipDir = zip->directory();
75 extractRecursive(zipDir, QString());
81QString VoskExtractLanguageJob::source()
const
86void VoskExtractLanguageJob::setSource(
const QString &newSource)
91#include "moc_voskextractlanguagejob.cpp"
virtual bool isDirectory() const
virtual bool isFile() const
QString i18n(const char *text, const TYPE &arg...)
KIOCORE_EXPORT MkpathJob * mkpath(const QUrl &url, const QUrl &baseUrl=QUrl(), JobFlags flags=DefaultFlags)
QString path(const QString &relativePath)
KIOCORE_EXPORT QString dir(const QString &fileClass)