7#include "extractlanguagejob.h"
8#include "bergamotengineutils.h"
9#include "libbergamot_debug.h"
10#include <KLocalizedString>
14ExtractLanguageJob::ExtractLanguageJob(
QObject *parent)
19ExtractLanguageJob::~ExtractLanguageJob() =
default;
21bool ExtractLanguageJob::canStart()
const
23 return !mSource.isEmpty();
26void ExtractLanguageJob::start()
29 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to start ExtractLanguageJob";
30 Q_EMIT errorText(
i18n(
"Impossible to extract language"));
35 auto tar =
new KTar(mSource);
37 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to open temporary file" << mSource;
42 if (!QDir().
mkpath(BergamotEngineUtils::storageLanguagePath())) {
43 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to create path" << BergamotEngineUtils::storageLanguagePath();
48 const KArchiveDirectory *zipDir = tar->directory();
49 const QStringList lst = zipDir->
entries();
51 for (
const QString &name : lst) {
52 const QString storeDirectory{BergamotEngineUtils::storageLanguagePath() + QLatin1Char(
'/') +
name};
53 if (!QDir().
mkpath(storeDirectory)) {
54 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to create :" << storeDirectory;
57 const KArchiveEntry *configPathEntry = zipDir->
entry(name);
58 if (configPathEntry && configPathEntry->
isDirectory()) {
59 const auto configDirectory =
static_cast<const KArchiveDirectory *
>(configPathEntry);
60 const QStringList entries = configDirectory->entries();
62 for (
const QString &file : entries) {
63 const KArchiveEntry *filePathEntry = zipDir->
entry(name + QStringLiteral(
"/%1").arg(file));
64 if (filePathEntry && filePathEntry->
isFile()) {
65 const auto filePath =
static_cast<const KArchiveFile *
>(filePathEntry);
66 if (!filePath->copyTo(storeDirectory)) {
67 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to copy to " << storeDirectory;
70 qCWarning(TRANSLATOR_LIBBERGAMOT_LOG) <<
"Impossible to import file " << file;
80QString ExtractLanguageJob::source()
const
85void ExtractLanguageJob::setSource(
const QString &newSource)
90#include "moc_extractlanguagejob.cpp"
QStringList entries() const
const KArchiveEntry * entry(const QString &name) const
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 name(StandardAction id)