| 347 | } |
| 348 | |
| 349 | QString TemplatesModel::loadTemplateFile(const QString& fileName) |
| 350 | { |
| 351 | Q_D(TemplatesModel); |
| 352 | |
| 353 | QString saveLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + |
| 354 | d->resourceFilter(TemplatesModelPrivate::Template); |
| 355 | |
| 356 | QDir dir(saveLocation); |
| 357 | if (!dir.exists()) |
| 358 | dir.mkpath(QStringLiteral(".")); |
| 359 | |
| 360 | QFileInfo info(fileName); |
| 361 | QString destination = saveLocation + info.baseName(); |
| 362 | |
| 363 | QMimeType mimeType = QMimeDatabase().mimeTypeForFile(fileName); |
| 364 | qCDebug(LANGUAGE) << "Loaded file" << fileName << "with type" << mimeType.name(); |
| 365 | |
| 366 | if (mimeType.name() == QLatin1String("application/x-desktop")) { |
| 367 | qCDebug(LANGUAGE) << "Loaded desktop file" << info.absoluteFilePath() << ", compressing"; |
| 368 | #ifdef Q_WS_WIN |
| 369 | destination += ".zip"; |
| 370 | KZip archive(destination); |
| 371 | #else |
| 372 | destination += QLatin1String(".tar.bz2"); |
| 373 | KTar archive(destination, QStringLiteral("application/x-bzip")); |
| 374 | #endif //Q_WS_WIN |
| 375 | |
| 376 | archive.open(QIODevice::WriteOnly); |
| 377 | |
| 378 | QDir dir(info.absoluteDir()); |
| 379 | const auto dirEntryInfos = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); |
| 380 | for (const QFileInfo& entry : dirEntryInfos) { |
| 381 | if (entry.isFile()) { |
| 382 | archive.addLocalFile(entry.absoluteFilePath(), entry.fileName()); |
| 383 | } else if (entry.isDir()) { |
| 384 | archive.addLocalDirectory(entry.absoluteFilePath(), entry.fileName()); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | archive.close(); |
| 389 | } else |
| 390 | { |
| 391 | qCDebug(LANGUAGE) << "Copying" << fileName << "to" << saveLocation; |
| 392 | QFile::copy(fileName, saveLocation + info.fileName()); |
| 393 | } |
| 394 | |
| 395 | refresh(); |
| 396 | |
| 397 | return destination; |
| 398 | } |
| 399 | |
| 400 | #include "moc_templatesmodel.cpp" |
no test coverage detected