diff --git a/kmail/job/fetchrecursivecollectionsjob.cpp b/kmail/job/fetchrecursivecollectionsjob.cpp index 406a896198..2e70cfdc8d 100644 --- a/kmail/job/fetchrecursivecollectionsjob.cpp +++ b/kmail/job/fetchrecursivecollectionsjob.cpp @@ -1,66 +1,66 @@ /* Copyright (c) 2015 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "fetchrecursivecollectionsjob.h" #include "kmail_debug.h" #include FetchRecursiveCollectionsJob::FetchRecursiveCollectionsJob(QObject *parent) : QObject(parent) { } FetchRecursiveCollectionsJob::~FetchRecursiveCollectionsJob() { } void FetchRecursiveCollectionsJob::start() { if (!mTopCollection.isValid()) { qCWarning(KMAIL_LOG) << "Any collection is defined"; Q_EMIT fetchCollectionFailed(); deleteLater(); return; } Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(mTopCollection, Akonadi::CollectionFetchJob::Recursive); connect(job, &Akonadi::CollectionFetchJob::result, this, &FetchRecursiveCollectionsJob::slotInitialCollectionFetchingDone); } void FetchRecursiveCollectionsJob::setTopCollection(const Akonadi::Collection &col) { - mTopCollection = col; + mTopCollection = col; } void FetchRecursiveCollectionsJob::slotInitialCollectionFetchingDone(KJob *job) { if (job->error()) { qCWarning(KMAIL_LOG) << job->errorString(); Q_EMIT fetchCollectionFailed(); deleteLater(); return; } Akonadi::CollectionFetchJob *fetchJob = qobject_cast(job); Q_EMIT fetchCollectionFinished(fetchJob->collections() << mTopCollection); deleteLater(); } diff --git a/kmail/job/markallmessagesasreadinfolderandsubfolderjob.cpp b/kmail/job/markallmessagesasreadinfolderandsubfolderjob.cpp index 5bb928d299..511885f31e 100644 --- a/kmail/job/markallmessagesasreadinfolderandsubfolderjob.cpp +++ b/kmail/job/markallmessagesasreadinfolderandsubfolderjob.cpp @@ -1,87 +1,87 @@ /* Copyright (c) 2015 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "markallmessagesasreadinfolderandsubfolderjob.h" #include "fetchrecursivecollectionsjob.h" #include "kmail_debug.h" MarkAllMessagesAsReadInFolderAndSubFolderJob::MarkAllMessagesAsReadInFolderAndSubFolderJob(QObject *parent) : QObject(parent) { } MarkAllMessagesAsReadInFolderAndSubFolderJob::~MarkAllMessagesAsReadInFolderAndSubFolderJob() { } void MarkAllMessagesAsReadInFolderAndSubFolderJob::setTopLevelCollection(const Akonadi::Collection &topLevelCollection) { mTopLevelCollection = topLevelCollection; } void MarkAllMessagesAsReadInFolderAndSubFolderJob::start() { if (!mTopLevelCollection.isValid()) { qCDebug(KMAIL_LOG()) << "Invalid toplevel collection"; deleteLater(); return; } FetchRecursiveCollectionsJob *fetchJob = new FetchRecursiveCollectionsJob(this); fetchJob->setTopCollection(mTopLevelCollection); connect(fetchJob, &FetchRecursiveCollectionsJob::fetchCollectionFailed, this, &MarkAllMessagesAsReadInFolderAndSubFolderJob::slotFetchCollectionFailed); connect(fetchJob, &FetchRecursiveCollectionsJob::fetchCollectionFinished, this, &MarkAllMessagesAsReadInFolderAndSubFolderJob::slotFetchCollectionDone); fetchJob->start(); } void MarkAllMessagesAsReadInFolderAndSubFolderJob::slotFetchCollectionFailed() { qCDebug(KMAIL_LOG()) << "Fetch toplevel collection failed"; deleteLater(); } void MarkAllMessagesAsReadInFolderAndSubFolderJob::slotFetchCollectionDone(const Akonadi::Collection::List &list) { Akonadi::MessageStatus messageStatus; messageStatus.setRead(true); Akonadi::MarkAsCommand *markAsReadAllJob = new Akonadi::MarkAsCommand(messageStatus, list); connect(markAsReadAllJob, &Akonadi::MarkAsCommand::result, this, &MarkAllMessagesAsReadInFolderAndSubFolderJob::slotMarkAsResult); markAsReadAllJob->execute(); } void MarkAllMessagesAsReadInFolderAndSubFolderJob::slotMarkAsResult(Akonadi::MarkAsCommand::Result result) { - switch(result) { + switch (result) { case Akonadi::MarkAsCommand::Undefined: qCDebug(KMAIL_LOG()) << "MarkAllMessagesAsReadInFolderAndSubFolderJob undefined result"; break; case Akonadi::MarkAsCommand::OK: qCDebug(KMAIL_LOG()) << "MarkAllMessagesAsReadInFolderAndSubFoldeJob Done"; break; case Akonadi::MarkAsCommand::Canceled: qCDebug(KMAIL_LOG()) << "MarkAllMessagesAsReadInFolderAndSubFoldeJob was canceled"; break; case Akonadi::MarkAsCommand::Failed: qCDebug(KMAIL_LOG()) << "MarkAllMessagesAsReadInFolderAndSubFoldeJob was failed"; break; } deleteLater(); } diff --git a/pimsettingexporter/core/abstractimportexportjob.cpp b/pimsettingexporter/core/abstractimportexportjob.cpp index 3b16ae4185..d6cfefc2de 100644 --- a/pimsettingexporter/core/abstractimportexportjob.cpp +++ b/pimsettingexporter/core/abstractimportexportjob.cpp @@ -1,620 +1,619 @@ /* Copyright (c) 2012-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "abstractimportexportjob.h" #include "archivestorage.h" #include "importexportprogressindicatorbase.h" #include "synchronizeresourcejob.h" #include "MailCommon/MailUtil" #include "PimCommon/CreateResource" #include #include #include #include #include #include #include #include #include int AbstractImportExportJob::sArchiveVersion = -1; AbstractImportExportJob::AbstractImportExportJob(QObject *parent, ArchiveStorage *archiveStorage, Utils::StoredTypes typeSelected, int numberOfStep) : QObject(parent), mTypeSelected(typeSelected), mArchiveStorage(archiveStorage), mIdentityManager(new KIdentityManagement::IdentityManager(false, this, "mIdentityManager")), mTempDir(Q_NULLPTR), mArchiveDirectory(Q_NULLPTR), mNumberOfStep(numberOfStep), mCreateResource(Q_NULLPTR), mIndex(-1), mImportExportProgressIndicator(new ImportExportProgressIndicatorBase(this)) { mImportExportProgressIndicator->setNumberOfStep(numberOfStep); connect(mImportExportProgressIndicator, &ImportExportProgressIndicatorBase::info, this, &AbstractImportExportJob::info); } AbstractImportExportJob::~AbstractImportExportJob() { delete mCreateResource; delete mIdentityManager; delete mTempDir; } void AbstractImportExportJob::createProgressDialog(const QString &title) { mImportExportProgressIndicator->createProgressDialog(title); connect(mImportExportProgressIndicator, &ImportExportProgressIndicatorBase::canceled, this, &AbstractImportExportJob::slotTaskCanceled); } void AbstractImportExportJob::slotTaskCanceled() { Q_EMIT error(i18n("Task Canceled")); Q_EMIT jobFinished(); } bool AbstractImportExportJob::wasCanceled() const { return mImportExportProgressIndicator->wasCanceled(); } void AbstractImportExportJob::increaseProgressDialog() { mImportExportProgressIndicator->increaseProgressDialog(); } void AbstractImportExportJob::setProgressDialogLabel(const QString &text) { mImportExportProgressIndicator->setProgressDialogLabel(text); } ImportExportProgressIndicatorBase *AbstractImportExportJob::importExportProgressIndicator() const { return mImportExportProgressIndicator; } void AbstractImportExportJob::setImportExportProgressIndicator(ImportExportProgressIndicatorBase *importExportProgressIndicator) { delete mImportExportProgressIndicator; mImportExportProgressIndicator = importExportProgressIndicator; mImportExportProgressIndicator->setNumberOfStep(mNumberOfStep); } KZip *AbstractImportExportJob::archive() const { return mArchiveStorage->archive(); } void AbstractImportExportJob::backupUiRcFile(const QString &configFileName, const QString &application) { const QString configrcStr(configFileName); const QString configrc = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kxmlgui5/") + application + QLatin1Char('/') + configrcStr; qDebug() << " configrc" << configrc << " configFileName " << configFileName; if (QFile(configrc).exists()) { backupFile(configrc, Utils::configsPath(), configrcStr); } } void AbstractImportExportJob::backupConfigFile(const QString &configFileName) { const QString configrcStr(configFileName); const QString configrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + configrcStr; if (QFile(configrc).exists()) { backupFile(configrc, Utils::configsPath(), configrcStr); } } void AbstractImportExportJob::backupFile(const QString &filename, const QString &path, const QString &storedName) { if (QFile(filename).exists()) { const bool fileAdded = archive()->addLocalFile(filename, path + storedName); if (fileAdded) { Q_EMIT info(i18n("\"%1\" backup done.", storedName)); } else { Q_EMIT error(i18n("\"%1\" cannot be exported.", storedName)); } } else { Q_EMIT error(i18n("\"%1\" does not exist.", filename)); } } int AbstractImportExportJob::mergeConfigMessageBox(const QString &configName) const { return mImportExportProgressIndicator->mergeConfigMessageBox(configName); } bool AbstractImportExportJob::overwriteConfigMessageBox(const QString &configName) const { return mImportExportProgressIndicator->overwriteConfigMessageBox(configName); } void AbstractImportExportJob::overwriteDirectory(const QString &path, const KArchiveEntry *entry) { if (QDir(path).exists()) { if (overwriteDirectoryMessageBox(path)) { const KArchiveDirectory *dirEntry = static_cast(entry); if (!dirEntry->copyTo(path)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "directory cannot overwrite to " << path; } } } else { const KArchiveDirectory *dirEntry = static_cast(entry); if (dirEntry->copyTo(path)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "directory cannot overwrite to " << path; } } } void AbstractImportExportJob::searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName) { Q_FOREACH (const QString &entryName, dir->entries()) { const KArchiveEntry *entry = dir->entry(entryName); if (entry && entry->isDirectory()) { const QString newPrefix = (prefix.isEmpty() ? prefix : prefix + QLatin1Char('/')) + entryName; if (entryName == searchEntryName) { storeArchiveInfoResources(static_cast(entry), entryName); } else { searchAllFiles(static_cast(entry), newPrefix, searchEntryName); } } } } void AbstractImportExportJob::storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix) { Q_FOREACH (const QString &entryName, dir->entries()) { const KArchiveEntry *entry = dir->entry(entryName); if (entry && entry->isDirectory()) { const KArchiveDirectory *resourceDir = static_cast(entry); const QStringList lst = resourceDir->entries(); if (lst.count() >= 2) { const QString archPath(prefix + QLatin1Char('/') + entryName + QLatin1Char('/')); resourceFiles files; Q_FOREACH (const QString &name, lst) { if (isAConfigFile(name)) { files.akonadiConfigFile = archPath + name; } else if (name.startsWith(Utils::prefixAkonadiConfigFile())) { files.akonadiAgentConfigFile = archPath + name; } else { files.akonadiResources = archPath + name; } } files.debug(); mListResourceFile.append(files); } else { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " Problem in archive. number of file " << lst.count(); } } } } bool AbstractImportExportJob::isAConfigFile(const QString &name) const { //Redefine in subclass return true; } bool AbstractImportExportJob::overwriteDirectoryMessageBox(const QString &directory) const { return mImportExportProgressIndicator->overwriteDirectoryMessageBox(directory); } void AbstractImportExportJob::convertRealPathToCollection(KConfigGroup &group, const QString ¤tKey, bool addCollectionPrefix) { if (group.hasKey(currentKey)) { const QString path = group.readEntry(currentKey); if (!path.isEmpty()) { const Akonadi::Collection::Id id = convertPathToId(path); if (id != -1) { if (addCollectionPrefix) { group.writeEntry(currentKey, QStringLiteral("c%1").arg(id)); } else { group.writeEntry(currentKey, id); } } else { group.deleteEntry(currentKey); } } } } void AbstractImportExportJob::convertRealPathToCollectionList(KConfigGroup &group, const QString ¤tKey, bool addCollectionPrefix) { if (group.hasKey(currentKey)) { const QStringList listExpension = group.readEntry(currentKey, QStringList()); QStringList result; if (!listExpension.isEmpty()) { Q_FOREACH (const QString &collection, listExpension) { const Akonadi::Collection::Id id = convertPathToId(collection); if (id != -1) { if (addCollectionPrefix) { result << QStringLiteral("c%1").arg(id); } else { result << QStringLiteral("%1").arg(id); } } } if (result.isEmpty()) { group.deleteEntry(currentKey); } else { group.writeEntry(currentKey, result); } } } } Akonadi::Collection::Id AbstractImportExportJob::convertPathToId(const QString &path) { if (mHashConvertPathCollectionId.contains(path)) { return mHashConvertPathCollectionId.value(path); } const Akonadi::Collection::Id id = MailCommon::Util::convertFolderPathToCollectionId(path); if (id != -1) { mHashConvertPathCollectionId.insert(path, id); } return id; } void AbstractImportExportJob::initializeImportJob() { if (mTempDir) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " initializeImportJob already called"; } else { mTempDir = new QTemporaryDir(); mTempDirName = mTempDir->path(); mCreateResource = new PimCommon::CreateResource(); connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractImportExportJob::info); connect(mCreateResource, &PimCommon::CreateResource::createResourceError, this, &AbstractImportExportJob::error); } } void AbstractImportExportJob::copyToDirectory(const KArchiveEntry *entry, const QString &dest) { const KArchiveDirectory *subfolderDir = static_cast(entry); if (!subfolderDir->copyTo(dest)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "directory cannot copy to " << dest; } Q_EMIT info(i18n("\"%1\" was copied.", dest)); } void AbstractImportExportJob::copyToFile(const KArchiveFile *archivefile, const QString &dest, const QString &filename, const QString &prefix) { QDir dir(mTempDirName); const QString copyToDirName(mTempDirName + QLatin1Char('/') + prefix); const bool created = dir.mkpath(copyToDirName); if (!created) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " directory :" << prefix << " not created"; } if (!archivefile->copyTo(copyToDirName)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "file " << filename << " can not copy to " << dest; } QFile file; file.setFileName(copyToDirName + QLatin1Char('/') + filename); //QFile doesn't overwrite => remove old file before //qCDebug(PIMSETTINGEXPORTERCORE_LOG)<<" dest "<showErrorMessage(i18n("File \"%1\" cannot be copied to \"%2\".", filename, dest), i18n("Copy file")); } else { Q_EMIT info(i18n("\"%1\" was restored.", filename)); } } void AbstractImportExportJob::backupResourceFile(const Akonadi::AgentInstance &agent, const QString &defaultPath) { const QString identifier = agent.identifier(); const QString archivePath = defaultPath + identifier + QDir::separator(); QString url = Utils::resourcePath(agent); if (!url.isEmpty()) { QFileInfo fi(url); QString filename = fi.fileName(); const bool fileAdded = archive()->addLocalFile(url, archivePath + filename); if (fileAdded) { const QString errorStr = Utils::storeResources(archive(), identifier, archivePath); if (!errorStr.isEmpty()) { Q_EMIT error(errorStr); } Q_EMIT info(i18n("\"%1\" was backed up.", filename)); url = Utils::akonadiAgentConfigPath(identifier); if (!url.isEmpty()) { fi = QFileInfo(url); filename = fi.fileName(); const bool fileAdded = archive()->addLocalFile(url, archivePath + filename); if (fileAdded) { Q_EMIT info(i18n("\"%1\" was backed up.", filename)); } else { Q_EMIT error(i18n("\"%1\" file cannot be added to backup file.", filename)); } } } else { Q_EMIT error(i18n("\"%1\" file cannot be added to backup file.", filename)); } } } QStringList AbstractImportExportJob::restoreResourceFile(const QString &resourceBaseName, const QString &defaultPath, const QString &storePath, bool overwriteResources) { QStringList resourceToSync; //TODO fix sync config after created a resource if (!mListResourceFile.isEmpty()) { QDir dir(mTempDirName); dir.mkdir(defaultPath); const QString copyToDirName(mTempDirName + QLatin1Char('/') + defaultPath); for (int i = 0; i < mListResourceFile.size(); ++i) { resourceFiles value = mListResourceFile.at(i); QMap settings; if (value.akonadiConfigFile.contains(resourceBaseName + QLatin1Char('_'))) { const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile); if (fileResouceEntry && fileResouceEntry->isFile()) { const KArchiveFile *file = static_cast(fileResouceEntry); file->copyTo(copyToDirName); QString resourceName(file->name()); QString filename(file->name()); //TODO adapt filename otherwise it will use all the time the same filename. qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " filename :" << filename; KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName); QString newUrl; if (overwriteResources) { newUrl = Utils::resourcePath(resourceConfig); } else { newUrl = Utils::adaptResourcePath(resourceConfig, storePath); } const QString dataFile = value.akonadiResources; const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile); if (dataResouceEntry->isFile()) { const KArchiveFile *file = static_cast(dataResouceEntry); file->copyTo(newUrl); } settings.insert(QStringLiteral("Path"), newUrl); const QString agentConfigFile = value.akonadiAgentConfigFile; if (!agentConfigFile.isEmpty()) { const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile); if (akonadiAgentConfigEntry->isFile()) { const KArchiveFile *file = static_cast(akonadiAgentConfigEntry); file->copyTo(copyToDirName); resourceName = file->name(); const QString configPath = copyToDirName + QLatin1Char('/') + resourceName; filename = Utils::akonadiAgentName(configPath); } } addSpecificResourceSettings(resourceConfig, resourceBaseName, settings); const QString newResource = mCreateResource->createResource(resourceBaseName, filename, settings); infoAboutNewResource(newResource); resourceToSync << newResource; qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " newResource" << newResource; } } } Q_EMIT info(i18n("Resources restored.")); } else { Q_EMIT error(i18n("No resources files found.")); } return resourceToSync; } void AbstractImportExportJob::addSpecificResourceSettings(KSharedConfig::Ptr /*resourceConfig*/, const QString &/*resourceName*/, QMap &/*settings*/) { //Redefine it in subclass } void AbstractImportExportJob::extractZipFile(const KArchiveFile *file, const QString &source, const QString &destination, bool isStoredAsZippedArchive) { file->copyTo(source); QDir dest(destination); if (!dest.exists()) { dest.mkpath(destination); } if (isStoredAsZippedArchive) { QString errorMsg; KZip *zip = Utils::openZip(source + QLatin1Char('/') + file->name(), errorMsg); if (zip) { const KArchiveDirectory *zipDir = zip->directory(); Q_FOREACH (const QString &entryName, zipDir->entries()) { const KArchiveEntry *entry = zipDir->entry(entryName); if (entry) { if (entry->isDirectory()) { const KArchiveDirectory *dir = static_cast(entry); dir->copyTo(destination + QDir::separator() + dir->name(), true); } else if (entry->isFile()) { const KArchiveFile *dir = static_cast(entry); dir->copyTo(destination); } } qApp->processEvents(); } delete zip; } else { Q_EMIT error(errorMsg); } } else { QFile achiveFile(source + QLatin1Char('/') + file->name()); if (!achiveFile.copy(destination + QLatin1Char('/') + file->name())) { Q_EMIT error(i18n("Unable to copy file", file->name())); } } } void AbstractImportExportJob::restoreUiRcFile(const QString &configNameStr, const QString &applicationName) { const KArchiveEntry *configNameentry = mArchiveDirectory->entry(Utils::configsPath() + configNameStr); if (configNameentry && configNameentry->isFile()) { const KArchiveFile *configNameconfiguration = static_cast(configNameentry); const QString configNamerc = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kxmlgui5/") + applicationName + QLatin1Char('/') + configNameStr; if (QFile(configNamerc).exists()) { if (overwriteConfigMessageBox(configNameStr)) { copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath()); } } else { copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath()); } } } void AbstractImportExportJob::restoreConfigFile(const QString &configNameStr) { const KArchiveEntry *configNameentry = mArchiveDirectory->entry(Utils::configsPath() + configNameStr); if (configNameentry && configNameentry->isFile()) { const KArchiveFile *configNameconfiguration = static_cast(configNameentry); const QString configNamerc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + configNameStr; if (QFile(configNamerc).exists()) { //TODO 4.12 allow to merge config. if (overwriteConfigMessageBox(configNameStr)) { copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath()); } } else { copyToFile(configNameconfiguration, configNamerc, configNameStr, Utils::configsPath()); } } } void AbstractImportExportJob::infoAboutNewResource(const QString &resourceName) { Q_EMIT info(i18n("Resource \'%1\' created.", resourceName)); } int AbstractImportExportJob::archiveVersion() { return sArchiveVersion; } void AbstractImportExportJob::setArchiveVersion(int version) { sArchiveVersion = version; } void AbstractImportExportJob::slotSynchronizeInstanceFailed(const QString &instance) { Q_EMIT error(i18n("Failed to synchronize %1.", instance)); } void AbstractImportExportJob::slotSynchronizeInstanceDone(const QString &name, const QString &identifier) { Q_EMIT info(i18n("Resource %1 synchronized.", name)); Q_EMIT needSynchronizeResource(name, identifier); } void AbstractImportExportJob::slotAllResourceSynchronized() { Q_EMIT info(i18n("All resources synchronized.")); slotNextStep(); } void AbstractImportExportJob::slotNextStep() { //Implement in sub class. } void AbstractImportExportJob::startSynchronizeResources(const QStringList &listResourceToSync) { Q_EMIT info(i18n("Start synchronizing...")); SynchronizeResourceJob *job = new SynchronizeResourceJob(this); job->setListResources(listResourceToSync); connect(job, &SynchronizeResourceJob::synchronizationFinished, this, &AbstractImportExportJob::slotAllResourceSynchronized); connect(job, &SynchronizeResourceJob::synchronizationInstanceDone, this, &AbstractImportExportJob::slotSynchronizeInstanceDone); connect(job, &SynchronizeResourceJob::synchronizationInstanceFailed, this, &AbstractImportExportJob::slotSynchronizeInstanceFailed); job->start(); } void AbstractImportExportJob::initializeListStep() { if (mTypeSelected & Utils::MailTransport) { mListStep << Utils::MailTransport; } if (mTypeSelected & Utils::Mails) { mListStep << Utils::Mails; } if (mTypeSelected & Utils::Resources) { mListStep << Utils::Resources; } if (mTypeSelected & Utils::Identity) { mListStep << Utils::Identity; } if (mTypeSelected & Utils::Config) { mListStep << Utils::Config; } if (mTypeSelected & Utils::AkonadiDb) { mListStep << Utils::AkonadiDb; } if (mTypeSelected & Utils::Data) { mListStep << Utils::Data; } } void AbstractImportExportJob::storeDirectory(const QString &subDirectory) { const QDir directoryToStore(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + subDirectory); if (directoryToStore.exists()) { const bool templateDirAdded = archive()->addLocalDirectory(directoryToStore.path(), Utils::dataPath() + subDirectory); if (templateDirAdded) { Q_EMIT info(i18n("Directory \"%1\" added to backup file.", directoryToStore.path())); } else { Q_EMIT error(i18n("Directory \"%1\" cannot be added to backup file.", directoryToStore.path())); } } } void AbstractImportExportJob::importDataSubdirectory(const QString &subdirectoryRelativePath) { const KArchiveEntry *themeEntry = mArchiveDirectory->entry(Utils::dataPath() + subdirectoryRelativePath); if (themeEntry && themeEntry->isDirectory()) { const KArchiveDirectory *themeDir = static_cast(themeEntry); Q_FOREACH (const QString &entryName, themeDir->entries()) { const KArchiveEntry *entry = themeDir->entry(entryName); if (entry && entry->isDirectory()) { QString subFolderName = entryName; QDir themeDirectory(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(entryName)); int i = 1; while (themeDirectory.exists()) { subFolderName = entryName + QStringLiteral("_%1").arg(i); themeDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName)); ++i; } copyToDirectory(entry, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + subdirectoryRelativePath + QStringLiteral("/%1").arg(subFolderName)); } } } } - diff --git a/pimsettingexporter/core/abstractimportexportjob.h b/pimsettingexporter/core/abstractimportexportjob.h index 6ed5cd7e28..162b99efeb 100644 --- a/pimsettingexporter/core/abstractimportexportjob.h +++ b/pimsettingexporter/core/abstractimportexportjob.h @@ -1,140 +1,139 @@ /* Copyright (c) 2012-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef ABSTRACTIMPORTEXPORTJOB_H #define ABSTRACTIMPORTEXPORTJOB_H #include #include "utils.h" #include #include "pimsettingexporter_export.h" #include #include class ArchiveStorage; class KArchiveDirectory; class QTemporaryDir; class KZip; class KArchiveFile; class KArchiveEntry; namespace KIdentityManagement { class Identity; class IdentityManager; } namespace PimCommon { class CreateResource; } class ImportExportProgressIndicatorBase; class PIMSETTINGEXPORTER_EXPORT AbstractImportExportJob : public QObject { Q_OBJECT public: explicit AbstractImportExportJob(QObject *parent, ArchiveStorage *archiveStorage, Utils::StoredTypes typeSelected, int numberOfStep); ~AbstractImportExportJob(); virtual void start() = 0; bool wasCanceled() const; static int archiveVersion(); static void setArchiveVersion(int version); void setImportExportProgressIndicator(ImportExportProgressIndicatorBase *importExportProgressIndicator); ImportExportProgressIndicatorBase *importExportProgressIndicator() const; Q_SIGNALS: void info(const QString &); void error(const QString &); void title(const QString &); void endLine(); void needSynchronizeResource(const QString &name, const QString &identifier); void jobFinished(); private Q_SLOTS: void slotAllResourceSynchronized(); void slotSynchronizeInstanceDone(const QString &, const QString &identifier); void slotSynchronizeInstanceFailed(const QString &instance); void slotTaskCanceled(); protected: virtual void slotNextStep(); protected: void initializeListStep(); void startSynchronizeResources(const QStringList &listResourceToSync); void infoAboutNewResource(const QString &resourceName); void copyToDirectory(const KArchiveEntry *entry, const QString &dest); void extractZipFile(const KArchiveFile *file, const QString &source, const QString &destination, bool isStoredAsZippedArchive = true); void convertRealPathToCollection(KConfigGroup &group, const QString ¤tKey, bool addCollectionPrefix = false); void convertRealPathToCollectionList(KConfigGroup &group, const QString ¤tKey, bool addCollectionPrefix = true); void copyToFile(const KArchiveFile *archivefile, const QString &dest, const QString &filename, const QString &prefix); void initializeImportJob(); void backupFile(const QString &filename, const QString &path, const QString &storedName); void backupConfigFile(const QString &configFileName); void backupUiRcFile(const QString &configFileName, const QString &applicationName); void restoreUiRcFile(const QString &configNameStr, const QString &applicationName); int mergeConfigMessageBox(const QString &configName) const; bool overwriteConfigMessageBox(const QString &configName) const; Akonadi::Collection::Id convertPathToId(const QString &path); void backupResourceFile(const Akonadi::AgentInstance &agent, const QString &defaultPath); QStringList restoreResourceFile(const QString &resourceName, const QString &defaultPath, const QString &storePath, bool overwriteResources = false); virtual void addSpecificResourceSettings(KSharedConfig::Ptr resourceConfig, const QString &resourceName, QMap &settings); void restoreConfigFile(const QString &configNameStr); bool overwriteDirectoryMessageBox(const QString &directory) const; void overwriteDirectory(const QString &path, const KArchiveEntry *entry); virtual bool isAConfigFile(const QString &name) const; void searchAllFiles(const KArchiveDirectory *dir, const QString &prefix, const QString &searchEntryName); void storeArchiveInfoResources(const KArchiveDirectory *dir, const QString &prefix); KZip *archive() const; void increaseProgressDialog(); void createProgressDialog(const QString &title = QString()); void setProgressDialogLabel(const QString &text); void storeDirectory(const QString &subDirectory); void importDataSubdirectory(const QString &subdirectoryRelativePath); - QHash mHashConvertPathCollectionId; QVector mListResourceFile; QString mTempDirName; Utils::StoredTypes mTypeSelected; ArchiveStorage *mArchiveStorage; KIdentityManagement::IdentityManager *mIdentityManager; QTemporaryDir *mTempDir; const KArchiveDirectory *mArchiveDirectory; int mNumberOfStep; PimCommon::CreateResource *mCreateResource; QStringList mAgentPaths; QList mListStep; int mIndex; static int sArchiveVersion; private: ImportExportProgressIndicatorBase *mImportExportProgressIndicator; }; #endif // ABSTRACTIMPORTEXPORTJOB_H diff --git a/pimsettingexporter/core/addressbook/exportaddressbookjob.cpp b/pimsettingexporter/core/addressbook/exportaddressbookjob.cpp index 2d279c684e..9461e99bdc 100644 --- a/pimsettingexporter/core/addressbook/exportaddressbookjob.cpp +++ b/pimsettingexporter/core/addressbook/exportaddressbookjob.cpp @@ -1,172 +1,171 @@ /* Copyright (c) 2012-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "exportaddressbookjob.h" #include "exportresourcearchivejob.h" #include #include #include #include #include #include #include #include ExportAddressbookJob::ExportAddressbookJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep), mIndexIdentifier(0) { } ExportAddressbookJob::~ExportAddressbookJob() { } void ExportAddressbookJob::start() { Q_EMIT title(i18n("Start export KAddressBook settings...")); createProgressDialog(i18n("Export KAddressBook settings")); if (mTypeSelected & Utils::Resources) { QTimer::singleShot(0, this, SLOT(slotCheckBackupResource())); } else if (mTypeSelected & Utils::Config) { QTimer::singleShot(0, this, SLOT(slotCheckBackupConfig())); } else { Q_EMIT jobFinished(); } } void ExportAddressbookJob::slotCheckBackupResource() { setProgressDialogLabel(i18n("Backing up resources...")); increaseProgressDialog(); QTimer::singleShot(0, this, SLOT(slotWriteNextArchiveResource())); } void ExportAddressbookJob::slotCheckBackupConfig() { if (mTypeSelected & Utils::Config) { backupConfig(); increaseProgressDialog(); if (wasCanceled()) { Q_EMIT jobFinished(); return; } } Q_EMIT jobFinished(); } void ExportAddressbookJob::slotAddressbookJobTerminated() { if (wasCanceled()) { Q_EMIT jobFinished(); return; } mIndexIdentifier++; QTimer::singleShot(0, this, SLOT(slotWriteNextArchiveResource())); } void ExportAddressbookJob::slotWriteNextArchiveResource() { Akonadi::AgentManager *manager = Akonadi::AgentManager::self(); const Akonadi::AgentInstance::List list = manager->instances(); if (mIndexIdentifier < list.count()) { Akonadi::AgentInstance agent = list.at(mIndexIdentifier); const QString identifier = agent.identifier(); if (identifier.contains(QStringLiteral("akonadi_vcarddir_resource_")) || identifier.contains(QStringLiteral("akonadi_contacts_resource_"))) { const QString archivePath = Utils::addressbookPath() + identifier + QDir::separator(); QString url = Utils::resourcePath(agent, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/share/contacts/")); if (!mAgentPaths.contains(url)) { mAgentPaths << url; if (!url.isEmpty()) { ExportResourceArchiveJob *resourceJob = new ExportResourceArchiveJob(this); resourceJob->setArchivePath(archivePath); resourceJob->setUrl(url); resourceJob->setIdentifier(identifier); resourceJob->setArchive(archive()); resourceJob->setArchiveName(QStringLiteral("addressbook.zip")); connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportAddressbookJob::error); connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportAddressbookJob::info); connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportAddressbookJob::slotAddressbookJobTerminated); resourceJob->start(); } } else { QTimer::singleShot(0, this, SLOT(slotAddressbookJobTerminated())); } } else if (identifier.contains(QStringLiteral("akonadi_vcard_resource_"))) { backupResourceFile(agent, Utils::addressbookPath()); QTimer::singleShot(0, this, SLOT(slotAddressbookJobTerminated())); } else { QTimer::singleShot(0, this, SLOT(slotAddressbookJobTerminated())); } } else { Q_EMIT info(i18n("Resources backup done.")); QTimer::singleShot(0, this, SLOT(slotCheckBackupConfig())); } } void ExportAddressbookJob::backupConfig() { setProgressDialogLabel(i18n("Backing up config...")); const QString kaddressbookStr(QStringLiteral("kaddressbookrc")); const QString kaddressbookrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kaddressbookStr; if (QFile(kaddressbookrc).exists()) { KSharedConfigPtr kaddressbook = KSharedConfig::openConfig(kaddressbookrc); QTemporaryFile tmp; tmp.open(); KConfig *kaddressBookConfig = kaddressbook->copyTo(tmp.fileName()); const QString collectionViewCheckStateStr(QStringLiteral("CollectionViewCheckState")); if (kaddressBookConfig->hasGroup(collectionViewCheckStateStr)) { KConfigGroup group = kaddressBookConfig->group(collectionViewCheckStateStr); const QString selectionKey(QStringLiteral("Selection")); Utils::convertCollectionListToRealPath(group, selectionKey); } const QString collectionViewStateStr(QStringLiteral("CollectionViewState")); if (kaddressBookConfig->hasGroup(collectionViewStateStr)) { KConfigGroup group = kaddressBookConfig->group(collectionViewStateStr); QString currentKey(QStringLiteral("Current")); Utils::convertCollectionToRealPath(group, currentKey); currentKey = QStringLiteral("Expansion"); Utils::convertCollectionToRealPath(group, currentKey); currentKey = QStringLiteral("Selection"); Utils::convertCollectionToRealPath(group, currentKey); } kaddressBookConfig->sync(); backupFile(tmp.fileName(), Utils::configsPath(), kaddressbookStr); delete kaddressBookConfig; } backupUiRcFile(QStringLiteral("kaddressbookui.rc"), QStringLiteral("kaddressbook")); storeDirectory(QStringLiteral("/kaddressbook/csv-templates/")); storeDirectory(QStringLiteral("/kaddressbook/viewertemplates/")); storeDirectory(QStringLiteral("/kaddressbook/printing/")); Q_EMIT info(i18n("Config backup done.")); } - diff --git a/pimsettingexporter/core/addressbook/importaddressbookjob.cpp b/pimsettingexporter/core/addressbook/importaddressbookjob.cpp index fe929b750f..ee73a9c200 100644 --- a/pimsettingexporter/core/addressbook/importaddressbookjob.cpp +++ b/pimsettingexporter/core/addressbook/importaddressbookjob.cpp @@ -1,245 +1,244 @@ /* Copyright (c) 2013-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "importaddressbookjob.h" #include "archivestorage.h" #include "PimCommon/CreateResource" #include #include #include #include #include #include #include #include namespace { inline const QString storeAddressbook() { return QStringLiteral("backupaddressbook/"); } } ImportAddressbookJob::ImportAddressbookJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep) { initializeImportJob(); } ImportAddressbookJob::~ImportAddressbookJob() { } void ImportAddressbookJob::start() { Q_EMIT title(i18n("Start import KAddressBook settings...")); mArchiveDirectory = archive()->directory(); createProgressDialog(i18n("Import KAddressBook settings")); searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("addressbook")); initializeListStep(); QTimer::singleShot(0, this, SLOT(slotNextStep())); } void ImportAddressbookJob::slotNextStep() { ++mIndex; if (mIndex < mListStep.count()) { const Utils::StoredType type = mListStep.at(mIndex); if (type == Utils::Resources) { restoreResources(); } else if (type == Utils::Config) { restoreConfig(); } } else { Q_EMIT jobFinished(); } } void ImportAddressbookJob::restoreResources() { Q_EMIT info(i18n("Restore resources...")); setProgressDialogLabel(i18n("Restore resources...")); increaseProgressDialog(); QStringList listResource; listResource << restoreResourceFile(QStringLiteral("akonadi_vcard_resource"), Utils::addressbookPath(), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/share/kaddressbook/")); if (!mListResourceFile.isEmpty()) { QDir dir(mTempDirName); dir.mkdir(Utils::addressbookPath()); const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::addressbookPath()); const int numberOfResourceFile = mListResourceFile.size(); for (int i = 0; i < numberOfResourceFile; ++i) { resourceFiles value = mListResourceFile.at(i); QMap settings; if (value.akonadiConfigFile.contains(QStringLiteral("akonadi_vcarddir_resource_")) || value.akonadiConfigFile.contains(QStringLiteral("akonadi_contacts_resource_"))) { const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile); if (fileResouceEntry && fileResouceEntry->isFile()) { const KArchiveFile *file = static_cast(fileResouceEntry); file->copyTo(copyToDirName); QString resourceName(file->name()); QString filename(file->name()); //TODO adapt filename otherwise it will use all the time the same filename. KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName); //TODO fix default path const QString newUrl = Utils::adaptResourcePath(resourceConfig, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/share/contacts")); QFileInfo newUrlInfo(newUrl); const QString dataFile = value.akonadiResources; const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile); if (dataResouceEntry->isFile()) { const KArchiveFile *file = static_cast(dataResouceEntry); //TODO adapt directory name too extractZipFile(file, copyToDirName, newUrlInfo.path(), value.akonadiConfigFile.contains(QStringLiteral("akonadi_contacts_resource_"))); } settings.insert(QStringLiteral("Path"), newUrl); const QString agentConfigFile = value.akonadiAgentConfigFile; if (!agentConfigFile.isEmpty()) { const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile); if (akonadiAgentConfigEntry->isFile()) { const KArchiveFile *file = static_cast(akonadiAgentConfigEntry); file->copyTo(copyToDirName); resourceName = file->name(); filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName); } } QString instanceType; if (value.akonadiConfigFile.contains(QStringLiteral("akonadi_vcarddir_resource_"))) { instanceType = QStringLiteral("akonadi_vcarddir_resource"); } else if (value.akonadiConfigFile.contains(QStringLiteral("akonadi_contacts_resource_"))) { instanceType = QStringLiteral("akonadi_contacts_resource"); } else { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " not supported" << value.akonadiConfigFile; } const QString newResource = mCreateResource->createResource(instanceType, filename, settings, true); infoAboutNewResource(newResource); qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " newResource" << newResource; listResource << newResource; } } } } Q_EMIT info(i18n("Resources restored.")); //It's maildir support. Need to add support startSynchronizeResources(listResource); } void ImportAddressbookJob::addSpecificResourceSettings(KSharedConfig::Ptr resourceConfig, const QString &resourceName, QMap &settings) { if (resourceName == QLatin1String("akonadi_vcard_resource")) { KConfigGroup general = resourceConfig->group(QStringLiteral("General")); if (general.hasKey(QStringLiteral("DisplayName"))) { settings.insert(QStringLiteral("DisplayName"), general.readEntry(QStringLiteral("DisplayName"))); } if (general.hasKey(QStringLiteral("ReadOnly"))) { settings.insert(QStringLiteral("ReadOnly"), general.readEntry(QStringLiteral("ReadOnly"), false)); } if (general.hasKey(QStringLiteral("MonitorFile"))) { settings.insert(QStringLiteral("MonitorFile"), general.readEntry(QStringLiteral("MonitorFile"), true)); } } } bool ImportAddressbookJob::isAConfigFile(const QString &name) const { return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_vcarddir_resource_")) || - name.contains(QStringLiteral("akonadi_vcard_resource_")) || - name.contains(QStringLiteral("akonadi_contacts_resource_"))); + name.contains(QStringLiteral("akonadi_vcard_resource_")) || + name.contains(QStringLiteral("akonadi_contacts_resource_"))); } void ImportAddressbookJob::restoreConfig() { increaseProgressDialog(); setProgressDialogLabel(i18n("Restore configs...")); const QString kaddressbookStr(QStringLiteral("kaddressbookrc")); const KArchiveEntry *kaddressbookrcentry = mArchiveDirectory->entry(Utils::configsPath() + kaddressbookStr); if (kaddressbookrcentry && kaddressbookrcentry->isFile()) { const KArchiveFile *kaddressbookrcFile = static_cast(kaddressbookrcentry); const QString kaddressbookrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kaddressbookStr; if (QFile(kaddressbookrc).exists()) { if (overwriteConfigMessageBox(kaddressbookStr)) { importkaddressBookConfig(kaddressbookrcFile, kaddressbookrc, kaddressbookStr, Utils::configsPath()); } } else { importkaddressBookConfig(kaddressbookrcFile, kaddressbookrc, kaddressbookStr, Utils::configsPath()); } } restoreUiRcFile(QStringLiteral("kaddressbookui.rc"), QStringLiteral("kaddressbook")); Q_EMIT info(i18n("Config restored.")); QTimer::singleShot(0, this, &ImportAddressbookJob::slotNextStep); } void ImportAddressbookJob::importkaddressBookConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix) { copyToFile(file, config, filename, prefix); KSharedConfig::Ptr kaddressBookConfig = KSharedConfig::openConfig(config); const QString collectionViewCheckStateStr(QStringLiteral("CollectionViewCheckState")); if (kaddressBookConfig->hasGroup(collectionViewCheckStateStr)) { KConfigGroup group = kaddressBookConfig->group(collectionViewCheckStateStr); const QString selectionKey(QStringLiteral("Selection")); convertRealPathToCollectionList(group, selectionKey, true); } const QString collectionViewStateStr(QStringLiteral("CollectionViewState")); if (kaddressBookConfig->hasGroup(collectionViewStateStr)) { KConfigGroup group = kaddressBookConfig->group(collectionViewStateStr); QString currentKey(QStringLiteral("Current")); convertRealPathToCollection(group, currentKey, true); currentKey = QStringLiteral("Expansion"); convertRealPathToCollection(group, currentKey, true); currentKey = QStringLiteral("Selection"); convertRealPathToCollection(group, currentKey, true); } const QString cvsTemplateDirName = QStringLiteral("/kaddressbook/csv-templates/"); const KArchiveEntry *csvtemplateEntry = mArchiveDirectory->entry(Utils::dataPath() + cvsTemplateDirName); if (csvtemplateEntry && csvtemplateEntry->isDirectory()) { const KArchiveDirectory *csvTemplateDir = static_cast(csvtemplateEntry); Q_FOREACH (const QString &entryName, csvTemplateDir->entries()) { const KArchiveEntry *entry = csvTemplateDir->entry(entryName); if (entry && entry->isFile()) { const KArchiveFile *csvTemplateFile = static_cast(entry); const QString name = csvTemplateFile->name(); QString autocorrectionPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + cvsTemplateDirName; if (QFile(autocorrectionPath).exists()) { if (overwriteConfigMessageBox(name)) { copyToFile(csvTemplateFile, autocorrectionPath + QLatin1Char('/') + name, name, Utils::dataPath() + cvsTemplateDirName); } } else { autocorrectionPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + cvsTemplateDirName; copyToFile(csvTemplateFile, autocorrectionPath + QLatin1Char('/') + name, name, Utils::dataPath() + cvsTemplateDirName); } } } } - importDataSubdirectory(QStringLiteral("/kaddressbook/viewertemplates/")); importDataSubdirectory(QStringLiteral("/kaddressbook/printing/")); kaddressBookConfig->sync(); } diff --git a/pimsettingexporter/core/alarm/importalarmjob.cpp b/pimsettingexporter/core/alarm/importalarmjob.cpp index f9e43a190f..71cf62622e 100644 --- a/pimsettingexporter/core/alarm/importalarmjob.cpp +++ b/pimsettingexporter/core/alarm/importalarmjob.cpp @@ -1,188 +1,188 @@ /* Copyright (c) 2012-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "importalarmjob.h" #include "archivestorage.h" #include "PimCommon/CreateResource" #include #include #include #include #include #include #include #include #include namespace { inline const QString storeAlarm() { return QStringLiteral("backupalarm/"); } } ImportAlarmJob::ImportAlarmJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep) { initializeImportJob(); } ImportAlarmJob::~ImportAlarmJob() { } void ImportAlarmJob::start() { Q_EMIT title(i18n("Start import KAlarm settings...")); createProgressDialog(i18n("Import KAlarm settings")); mArchiveDirectory = archive()->directory(); searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("alarm")); initializeListStep(); QTimer::singleShot(0, this, &ImportAlarmJob::slotNextStep); } void ImportAlarmJob::slotNextStep() { ++mIndex; if (mIndex < mListStep.count()) { const Utils::StoredType type = mListStep.at(mIndex); if (type == Utils::Resources) { restoreResources(); } else if (type == Utils::Config) { restoreConfig(); } else { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << Q_FUNC_INFO << " not supported type " << type; slotNextStep(); } } else { Q_EMIT jobFinished(); } } void ImportAlarmJob::restoreResources() { Q_EMIT info(i18n("Restore resources...")); setProgressDialogLabel(i18n("Restore resources...")); increaseProgressDialog(); QStringList listResource; listResource << restoreResourceFile(QStringLiteral("akonadi_kalarm_resource"), Utils::alarmPath(), storeAlarm(), false); if (!mListResourceFile.isEmpty()) { QDir dir(mTempDirName); dir.mkdir(Utils::alarmPath()); const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::alarmPath()); const int numberOfResourceFile = mListResourceFile.size(); for (int i = 0; i < numberOfResourceFile; ++i) { resourceFiles value = mListResourceFile.at(i); QMap settings; if (value.akonadiConfigFile.contains(QStringLiteral("akonadi_kalarm_dir_resource_")) || value.akonadiConfigFile.contains(QStringLiteral("akonadi_kalarm_resource_"))) { const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile); if (fileResouceEntry && fileResouceEntry->isFile()) { const KArchiveFile *file = static_cast(fileResouceEntry); file->copyTo(copyToDirName); QString resourceName(file->name()); QString filename(file->name()); //TODO adapt filename otherwise it will use all the time the same filename. qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " filename :" << filename; KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName); const QString newUrl = Utils::adaptResourcePath(resourceConfig, storeAlarm()); QFileInfo newUrlInfo(newUrl); const QString dataFile = value.akonadiResources; const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile); bool isDirResource = value.akonadiConfigFile.contains(QStringLiteral("akonadi_kalarm_dir_resource_")); if (dataResouceEntry->isFile()) { const KArchiveFile *file = static_cast(dataResouceEntry); //TODO adapt directory name too extractZipFile(file, copyToDirName, newUrlInfo.path(), isDirResource); } settings.insert(QStringLiteral("Path"), newUrl); const QString agentConfigFile = value.akonadiAgentConfigFile; if (!agentConfigFile.isEmpty()) { const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile); if (akonadiAgentConfigEntry->isFile()) { const KArchiveFile *file = static_cast(akonadiAgentConfigEntry); file->copyTo(copyToDirName); resourceName = file->name(); filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName); } } const QString archiveNameType = isDirResource ? QStringLiteral("akonadi_kalarm_dir_resource") : QStringLiteral("akonadi_kalarm_resource"); const QString newResource = mCreateResource->createResource(QStringLiteral("akonadi_kalarm_dir_resource"), filename, settings, true); infoAboutNewResource(newResource); listResource << newResource; qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " newResource" << newResource; } } } } //It's maildir support. Need to add support startSynchronizeResources(listResource); } bool ImportAlarmJob::isAConfigFile(const QString &name) const { return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_kalarm_resource_")) - || name.contains(QStringLiteral("akonadi_kalarm_dir_resource_"))); + || name.contains(QStringLiteral("akonadi_kalarm_dir_resource_"))); } void ImportAlarmJob::restoreConfig() { increaseProgressDialog(); setProgressDialogLabel(i18n("Restore configs...")); const QString kalarmStr(QStringLiteral("kalarmrc")); const KArchiveEntry *kalarmrcentry = mArchiveDirectory->entry(Utils::configsPath() + kalarmStr); if (kalarmrcentry && kalarmrcentry->isFile()) { const KArchiveFile *kalarmrcFile = static_cast(kalarmrcentry); const QString kalarmrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + kalarmStr; if (QFile(kalarmrc).exists()) { if (overwriteConfigMessageBox(kalarmStr)) { importkalarmConfig(kalarmrcFile, kalarmrc, kalarmStr, Utils::configsPath()); } } else { importkalarmConfig(kalarmrcFile, kalarmrc, kalarmStr, Utils::configsPath()); } } restoreUiRcFile(QStringLiteral("kalarmui.rc"), QStringLiteral("kalarm")); Q_EMIT info(i18n("Config restored.")); QTimer::singleShot(0, this, &ImportAlarmJob::slotNextStep); } void ImportAlarmJob::importkalarmConfig(const KArchiveFile *kalarmFile, const QString &kalarmrc, const QString &filename, const QString &prefix) { copyToFile(kalarmFile, kalarmrc, filename, prefix); KSharedConfig::Ptr kalarmConfig = KSharedConfig::openConfig(kalarmrc); const QString collectionsStr(QStringLiteral("Collections")); if (kalarmConfig->hasGroup(collectionsStr)) { KConfigGroup group = kalarmConfig->group(collectionsStr); const QString selectionKey(QStringLiteral("FavoriteCollectionIds")); convertRealPathToCollectionList(group, selectionKey, false); } kalarmConfig->sync(); } diff --git a/pimsettingexporter/core/calendar/importcalendarjob.cpp b/pimsettingexporter/core/calendar/importcalendarjob.cpp index e2545f2e6b..ad1c5a4fc7 100644 --- a/pimsettingexporter/core/calendar/importcalendarjob.cpp +++ b/pimsettingexporter/core/calendar/importcalendarjob.cpp @@ -1,291 +1,289 @@ /* Copyright (c) 2012-2015 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "importcalendarjob.h" #include "archivestorage.h" #include "PimCommon/CreateResource" #include #include #include #include #include #include #include "pimsettingexportcore_debug.h" #include #include #include #include namespace { inline const QString storeCalendar() { return QStringLiteral("backupcalendar/"); } } ImportCalendarJob::ImportCalendarJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep) { initializeImportJob(); } ImportCalendarJob::~ImportCalendarJob() { } void ImportCalendarJob::start() { Q_EMIT title(i18n("Start import KOrganizer settings...")); mArchiveDirectory = archive()->directory(); createProgressDialog(i18n("Import KOrganizer settings")); searchAllFiles(mArchiveDirectory, QString(), QStringLiteral("calendar")); initializeListStep(); QTimer::singleShot(0, this, &ImportCalendarJob::slotNextStep); } void ImportCalendarJob::slotNextStep() { ++mIndex; if (mIndex < mListStep.count()) { Utils::StoredType type = mListStep.at(mIndex); if (type == Utils::Resources) { restoreResources(); } else if (type == Utils::Config) { restoreConfig(); } else { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << Q_FUNC_INFO << " not supported type " << type; slotNextStep(); } } else { Q_EMIT jobFinished(); } } void ImportCalendarJob::restoreResources() { Q_EMIT info(i18n("Restore resources...")); setProgressDialogLabel(i18n("Restore resources...")); increaseProgressDialog(); QStringList listResource; listResource << restoreResourceFile(QStringLiteral("akonadi_ical_resource"), Utils::calendarPath(), storeCalendar()); if (!mListResourceFile.isEmpty()) { QDir dir(mTempDirName); dir.mkdir(Utils::addressbookPath()); const QString copyToDirName(mTempDirName + QLatin1Char('/') + Utils::calendarPath()); const int numberOfResourceFile = mListResourceFile.size(); for (int i = 0; i < numberOfResourceFile; ++i) { resourceFiles value = mListResourceFile.at(i); QMap settings; if (value.akonadiConfigFile.contains(QStringLiteral("akonadi_icaldir_resource_")) || value.akonadiConfigFile.contains(QStringLiteral("akonadi_ical_resource_"))) { const KArchiveEntry *fileResouceEntry = mArchiveDirectory->entry(value.akonadiConfigFile); if (fileResouceEntry && fileResouceEntry->isFile()) { const KArchiveFile *file = static_cast(fileResouceEntry); if (!file->copyTo(copyToDirName)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "file can not copy to " << copyToDirName; } QString resourceName(file->name()); QString filename(file->name()); //TODO adapt filename otherwise it will use all the time the same filename. qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " filename :" << filename; KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName); const QString newUrl = Utils::adaptResourcePath(resourceConfig, storeCalendar()); QFileInfo newUrlInfo(newUrl); const QString dataFile = value.akonadiResources; const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile); bool isDirResource = value.akonadiConfigFile.contains(QStringLiteral("akonadi_icaldir_resource_")); if (dataResouceEntry->isFile()) { const KArchiveFile *file = static_cast(dataResouceEntry); //TODO adapt directory name too extractZipFile(file, copyToDirName, newUrlInfo.path(), value.akonadiConfigFile.contains(QStringLiteral("akonadi_icaldir_resource_"))); } settings.insert(QStringLiteral("Path"), newUrl); const QString agentConfigFile = value.akonadiAgentConfigFile; if (!agentConfigFile.isEmpty()) { const KArchiveEntry *akonadiAgentConfigEntry = mArchiveDirectory->entry(agentConfigFile); if (akonadiAgentConfigEntry->isFile()) { const KArchiveFile *file = static_cast(akonadiAgentConfigEntry); file->copyTo(copyToDirName); resourceName = file->name(); filename = Utils::akonadiAgentName(copyToDirName + QLatin1Char('/') + resourceName); } } const QString resourceTypeName = isDirResource ? QStringLiteral("akonadi_icaldir_resource") : QStringLiteral("akonadi_ical_resource"); const QString newResource = mCreateResource->createResource(resourceTypeName, filename, settings, true); infoAboutNewResource(newResource); listResource << newResource; qCDebug(PIMSETTINGEXPORTERCORE_LOG) << " newResource" << newResource; } } } } //It's maildir support. Need to add support startSynchronizeResources(listResource); } void ImportCalendarJob::addSpecificResourceSettings(KSharedConfig::Ptr resourceConfig, const QString &resourceName, QMap &settings) { if (resourceName == QLatin1String("akonadi_ical_resource")) { KConfigGroup general = resourceConfig->group(QStringLiteral("General")); if (general.hasKey(QStringLiteral("DisplayName"))) { settings.insert(QStringLiteral("DisplayName"), general.readEntry(QStringLiteral("DisplayName"))); } if (general.hasKey(QStringLiteral("ReadOnly"))) { settings.insert(QStringLiteral("ReadOnly"), general.readEntry(QStringLiteral("ReadOnly"), false)); } if (general.hasKey(QStringLiteral("MonitorFile"))) { settings.insert(QStringLiteral("MonitorFile"), general.readEntry(QStringLiteral("MonitorFile"), true)); } } } bool ImportCalendarJob::isAConfigFile(const QString &name) const { return name.endsWith(QLatin1String("rc")) && (name.contains(QStringLiteral("akonadi_ical_resource_")) - || name.contains(QStringLiteral("akonadi_icaldir_resource_"))); + || name.contains(QStringLiteral("akonadi_icaldir_resource_"))); } void ImportCalendarJob::restoreConfig() { increaseProgressDialog(); setProgressDialogLabel(i18n("Restore configs...")); const QString korganizerPrinterrcStr(QStringLiteral("calendar_printing.rc")); const QString oldKorganizerPrintrrcStr(QStringLiteral("korganizer_printing.rc")); const KArchiveEntry *oldKorganizerPrinterEntry = mArchiveDirectory->entry(Utils::configsPath() + oldKorganizerPrintrrcStr); if (oldKorganizerPrinterEntry && oldKorganizerPrinterEntry->isFile()) { const KArchiveFile *korganizerFile = static_cast(oldKorganizerPrinterEntry); const QString oldKorganizerPrintrrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerPrinterrcStr; if (QFile(oldKorganizerPrintrrc).exists()) { if (overwriteConfigMessageBox(oldKorganizerPrintrrc)) { copyToFile(korganizerFile, oldKorganizerPrintrrc, oldKorganizerPrintrrcStr, Utils::configsPath()); } } else { copyToFile(korganizerFile, oldKorganizerPrintrrc, oldKorganizerPrintrrcStr, Utils::configsPath()); } } else { const KArchiveEntry *korganizerPrinterEntry = mArchiveDirectory->entry(Utils::configsPath() + korganizerPrinterrcStr); if (korganizerPrinterEntry && korganizerPrinterEntry->isFile()) { const KArchiveFile *korganizerFile = static_cast(korganizerPrinterEntry); const QString korganizerPrinterrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerPrinterrcStr; if (QFile(korganizerPrinterrc).exists()) { if (overwriteConfigMessageBox(korganizerPrinterrcStr)) { copyToFile(korganizerFile, korganizerPrinterrc, korganizerPrinterrcStr, Utils::configsPath()); } } else { copyToFile(korganizerFile, korganizerPrinterrc, korganizerPrinterrcStr, Utils::configsPath()); } } } const QString korganizerStr(QStringLiteral("korganizerrc")); const KArchiveEntry *korganizerrcentry = mArchiveDirectory->entry(Utils::configsPath() + korganizerStr); if (korganizerrcentry && korganizerrcentry->isFile()) { const KArchiveFile *korganizerrcFile = static_cast(korganizerrcentry); const QString korganizerrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korganizerStr; if (QFile(korganizerrc).exists()) { if (overwriteConfigMessageBox(korganizerStr)) { importkorganizerConfig(korganizerrcFile, korganizerrc, korganizerStr, Utils::configsPath()); } } else { importkorganizerConfig(korganizerrcFile, korganizerrc, korganizerStr, Utils::configsPath()); } } const QString korgacStr(QStringLiteral("korgacrc")); const KArchiveEntry *korgacrcentry = mArchiveDirectory->entry(Utils::configsPath() + korgacStr); if (korgacrcentry && korgacrcentry->isFile()) { const KArchiveFile *korgacrcFile = static_cast(korgacrcentry); const QString korgacrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + korgacStr; if (QFile(korgacrc).exists()) { if (overwriteConfigMessageBox(korgacStr)) { copyToFile(korgacrcFile, korgacrc, korgacStr, Utils::configsPath()); } } else { copyToFile(korgacrcFile, korgacrc, korgacStr, Utils::configsPath()); } } const QString freebusyStr(QStringLiteral("freebusyurls")); const KArchiveEntry *freebusyentry = mArchiveDirectory->entry(Utils::dataPath() + QLatin1String("korganizer/") + freebusyStr); if (freebusyentry && freebusyentry->isFile()) { const KArchiveFile *freebusyrcFile = static_cast(freebusyentry); const QString freebusypath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/korganizer/") + freebusyStr; if (QFile(freebusypath).exists()) { //TODO 4.12 merge it. if (overwriteConfigMessageBox(freebusyStr)) { copyToFile(freebusyrcFile, freebusypath, freebusyStr, Utils::dataPath()); } } else { copyToFile(freebusyrcFile, freebusypath, freebusyStr, Utils::dataPath()); } } const KArchiveEntry *templateEntry = mArchiveDirectory->entry(Utils::dataPath() + QLatin1String("korganizer/templates/")); if (templateEntry && templateEntry->isDirectory()) { //TODO 4.12 verify if template already exists. const QString templatePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QLatin1String("korganizer/templates/"); const KArchiveDirectory *templateDir = static_cast(templateEntry); if (!templateDir->copyTo(templatePath)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "template cannot copy to " << templatePath; } } const KArchiveEntry *designerEntry = mArchiveDirectory->entry(Utils::dataPath() + QLatin1String("korganizer/designer/")); if (designerEntry && designerEntry->isDirectory()) { const QString templatePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QLatin1String("korganizer/designer/"); const KArchiveDirectory *templateDir = static_cast(designerEntry); if (!templateDir->copyTo(templatePath)) { qCDebug(PIMSETTINGEXPORTERCORE_LOG) << "template cannot copy to " << templatePath; } } - - restoreUiRcFile(QStringLiteral("korganizerui.rc"), QStringLiteral("korganizer")); restoreUiRcFile(QStringLiteral("korganizer_part.rc"), QStringLiteral("korganizer")); Q_EMIT info(i18n("Config restored.")); QTimer::singleShot(0, this, &ImportCalendarJob::slotNextStep); } void ImportCalendarJob::importkorganizerConfig(const KArchiveFile *file, const QString &config, const QString &filename, const QString &prefix) { copyToFile(file, config, filename, prefix); KSharedConfig::Ptr korganizerConfig = KSharedConfig::openConfig(config); const QString collectionsStr(QStringLiteral("GlobalCollectionSelection")); if (korganizerConfig->hasGroup(collectionsStr)) { KConfigGroup group = korganizerConfig->group(collectionsStr); const QString selectionKey(QStringLiteral("Selection")); convertRealPathToCollectionList(group, selectionKey, true); } korganizerConfig->sync(); }