diff --git a/app/config/appearancesettings.h b/app/config/appearancesettings.h --- a/app/config/appearancesettings.h +++ b/app/config/appearancesettings.h @@ -78,19 +78,19 @@ void updateSkinSetting(); void installSkin(); - void installSkinArchive(KJob* deleteJob = 0); + void installSkinArchive(); /** * Validates the given skin. * This method checks if the fileList of the skin * contains all required files. * * @param skinId The SkinID of the skin which will be validated. - * @param fileList The filelist of the skin. + * @param kns The skin has been installed from kns. * * @return True if the skin is valid, otherwise false. */ - bool validateSkin(const QString &skinId, const QStringList& fileList); + bool validateSkin(const QString &skinId, bool kns); /** * Extracts the skin IDs from the given fileList. @@ -118,6 +118,7 @@ void populateSkinList(const QString& installationDirectory); void checkForExistingSkin(); + void removeSkin(const QString& skinDir, std::function successCallback = 0); void installSkin(const QUrl& skinUrl); void failInstall(const QString& error); void cleanupAfterInstall(); diff --git a/app/config/appearancesettings.cpp b/app/config/appearancesettings.cpp --- a/app/config/appearancesettings.cpp +++ b/app/config/appearancesettings.cpp @@ -262,43 +262,26 @@ connect(job, &KIO::ListJob::result, [=](KJob *job) { if (!job->error()) - { - m_installSkinId = m_installSkinFileList.at(0); - - if (validateSkin(m_installSkinId, m_installSkinFileList)) - checkForExistingSkin(); - else - failInstall(xi18nc("@info", "Unable to locate required files in the skin archive.The archive appears to be invalid.")); - } + checkForExistingSkin(); else failInstall(xi18nc("@info", "Unable to list the skin archive contents.") + QStringLiteral("\n\n") + job->errorString()); }); } -bool AppearanceSettings::validateSkin(const QString &skinId, const QStringList& fileList) +bool AppearanceSettings::validateSkin(const QString& skinId, bool kns) { - bool titleFileFound = false; - bool tabsFileFound = false; - QString titleFileName = skinId + QStringLiteral("/title.skin"); - QString tabsFileName = skinId + QStringLiteral("/tabs.skin"); + QString dir = kns ? QStringLiteral("kns_skins/") : QStringLiteral("skins/"); - foreach (const QString& fileName, fileList) - { - if (fileName.endsWith(titleFileName)) - { - titleFileFound = true; - } - else if (fileName.endsWith(tabsFileName)) - { - tabsFileFound = true; - } - } + QString titlePath = QStandardPaths::locate(QStandardPaths::DataLocation, dir + skinId + QStringLiteral("/title.skin")); + QString tabsPath = QStandardPaths::locate(QStandardPaths::DataLocation, dir + skinId + QStringLiteral("/tabs.skin")); - return titleFileFound && tabsFileFound; + return !titlePath.isEmpty() && !tabsPath.isEmpty(); } void AppearanceSettings::checkForExistingSkin() { + m_installSkinId = m_installSkinFileList.at(0); + QModelIndexList skins = m_skins->match(m_skins->index(0, 0), SkinId, m_installSkinId, 1, Qt::MatchExactly | Qt::MatchWrap); @@ -329,40 +312,51 @@ KGuiItem(xi18nc("@action:button", "Reinstall Skin"))); if (remove == KMessageBox::Continue) - { - KIO::DeleteJob* job = KIO::del(QUrl::fromLocalFile(skinDir), KIO::HideProgressInfo); - connect(job, SIGNAL(result(KJob*)), this, SLOT(installSkinArchive(KJob*))); - } + removeSkin(skinDir, [=](){ installSkinArchive(); }); else cleanupAfterInstall(); } } else installSkinArchive(); } -void AppearanceSettings::installSkinArchive(KJob* deleteJob) +void AppearanceSettings::removeSkin(const QString& skinDir, std::function successCallback) { - if (deleteJob && deleteJob->error()) - { - KMessageBox::error(parentWidget(), deleteJob->errorString(), xi18nc("@title:Window", "Could Not Delete Skin")); - return; - } + KIO::DeleteJob* job = KIO::del(QUrl::fromLocalFile(skinDir), KIO::HideProgressInfo); + connect(job, &KIO::DeleteJob::result, [=](KJob* deleteJob) { + if (deleteJob->error()) { + KMessageBox::error(parentWidget(), deleteJob->errorString(), xi18nc("@title:Window", "Could Not Delete Skin")); + } else if (successCallback) { + successCallback(); + } + }); +} +void AppearanceSettings::installSkinArchive() +{ KTar skinArchive(m_installSkinFile.fileName()); if (skinArchive.open(QIODevice::ReadOnly)) { const KArchiveDirectory* skinDir = skinArchive.directory(); skinDir->copyTo(m_localSkinsDir); skinArchive.close(); - populateSkinList(); + if (validateSkin(m_installSkinId, false)) + { + populateSkinList(); - if (Settings::skin() == m_installSkinId) - emit settingsChanged(); + if (Settings::skin() == m_installSkinId) + emit settingsChanged(); - cleanupAfterInstall(); + cleanupAfterInstall(); + } + else + { + removeSkin(m_localSkinsDir + m_installSkinId); + failInstall(xi18nc("@info", "Unable to locate required files in the skin archive.The archive appears to be invalid.")); + } } else failInstall(xi18nc("@info", "The skin archive file could not be opened.")); @@ -426,7 +420,6 @@ { if (m_skins->rowCount() <= 1) return; - QString skinId = skinList->currentIndex().data(SkinId).toString(); QString skinDir = skinList->currentIndex().data(SkinDir).toString(); QString skinName = skinList->currentIndex().data(SkinName).toString(); QString skinAuthor = skinList->currentIndex().data(SkinAuthor).toString(); @@ -439,26 +432,19 @@ KStandardGuiItem::del()); if (remove == KMessageBox::Continue) - { - KIO::DeleteJob* job = KIO::del(QUrl::fromLocalFile(skinDir), KIO::HideProgressInfo); - connect(job, &KIO::DeleteJob::result, [=](KJob* deleteJob) { - if (deleteJob->error()) + removeSkin(skinDir, [=](){ + QString skinId = skinList->currentIndex().data(SkinId).toString(); + if (skinId == Settings::skin()) { - KMessageBox::error(parentWidget(), deleteJob->errorString(), xi18nc("@title:Window", "Could Not Delete Skin")); - } else { - if (skinId == Settings::skin()) - { - Settings::setSkin(QStringLiteral("default")); - Settings::setSkinInstalledWithKns(false); - Settings::self()->save(); - emit settingsChanged(); - } - - resetSelection(); - populateSkinList(); + Settings::setSkin(QStringLiteral("default")); + Settings::setSkinInstalledWithKns(false); + Settings::self()->save(); + emit settingsChanged(); } + + resetSelection(); + populateSkinList(); }); - } } QSet AppearanceSettings::extractKnsSkinIds(const QStringList& fileList) @@ -474,7 +460,7 @@ QString relativeName = QString(file).remove(m_knsSkinDir, Qt::CaseInsensitive); // Get everything before the first slash - that should be our skins ID. - QString skinId = relativeName.section(QStringLiteral("/"), 0, QString::SectionSkipEmpty); + QString skinId = relativeName.section(QStringLiteral("/"), 0, 0, QString::SectionSkipEmpty); // Skip all other entries in the file list if we found what we were searching for. if (!skinId.isEmpty()) @@ -519,7 +505,7 @@ foreach (const QString& skinId, skinIdList) { // Validate the current skin. - if (!validateSkin(skinId, entry.installedFiles())) + if (!validateSkin(skinId, true)) { isValid = false; }