Commit b29b5daa authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use resourceconverterimpl.h

parent 251188e9
......@@ -20,6 +20,7 @@
#include "abstractimportexportjob.h"
#include "archivestorage.h"
#include "importexportprogressindicatorbase.h"
#include "resourceconverterimpl.h"
#include "synchronizeresourcejob.h"
#include <MailCommon/MailUtil>
......@@ -341,7 +342,8 @@ void AbstractImportExportJob::backupResourceFile(const Akonadi::AgentInstance &a
const QString identifier = agent.identifier();
const QString archivePath = defaultPath + identifier + QLatin1Char('/');
QString url = Utils::resourcePath(identifier);
ResourceConverterImpl converter;
QString url = converter.resourcePath(identifier);
if (!url.isEmpty()) {
QFileInfo fi(url);
QString filename = fi.fileName();
......@@ -397,11 +399,12 @@ QStringList AbstractImportExportJob::restoreResourceFile(const QString &resource
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
ResourceConverterImpl converter;
QString newUrl;
if (overwriteResources) {
newUrl = Utils::resourcePath(resourceConfig);
newUrl = converter.resourcePath(resourceConfig);
} else {
newUrl = Utils::adaptResourcePath(resourceConfig, storePath);
newUrl = converter.adaptResourcePath(resourceConfig, storePath);
}
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
......
......@@ -30,6 +30,7 @@
#include <QDir>
#include <QStandardPaths>
#include <QTimer>
#include <resourceconverterimpl.h>
ExportAddressbookJob::ExportAddressbookJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -93,7 +94,8 @@ void ExportAddressbookJob::slotWriteNextArchiveResource()
if (identifier.contains(QLatin1String("akonadi_vcarddir_resource_")) || identifier.contains(QLatin1String("akonadi_contacts_resource_"))) {
const QString archivePath = Utils::addressbookPath() + identifier + QLatin1Char('/');
const QString url = Utils::resourcePath(identifier, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts/"));
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts/"));
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
......@@ -144,20 +146,22 @@ void ExportAddressbookJob::backupConfig()
if (kaddressBookConfig->hasGroup(collectionViewCheckStateStr)) {
KConfigGroup group = kaddressBookConfig->group(collectionViewCheckStateStr);
const QString selectionKey(QStringLiteral("Selection"));
Utils::convertCollectionListToRealPath(group, selectionKey);
ResourceConverterImpl converter;
converter.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);
ResourceConverterImpl converter;
converter.convertCollectionToRealPath(group, currentKey);
currentKey = QStringLiteral("Expansion");
Utils::convertCollectionToRealPath(group, currentKey);
converter.convertCollectionToRealPath(group, currentKey);
currentKey = QStringLiteral("Selection");
Utils::convertCollectionToRealPath(group, currentKey);
converter.convertCollectionToRealPath(group, currentKey);
}
kaddressBookConfig->sync();
backupFile(tmp.fileName(), Utils::configsPath(), kaddressbookStr);
......
......@@ -31,6 +31,7 @@
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include <resourceconverterimpl.h>
namespace {
inline const QString storeAddressbook()
......@@ -105,7 +106,8 @@ void ImportAddressbookJob::restoreResources()
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
//TODO fix default path
const QString newUrl = Utils::adaptResourcePath(resourceConfig, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts"));
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/contacts"));
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
......
......@@ -31,6 +31,7 @@
#include <QDir>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include <resourceconverterimpl.h>
ExportAlarmJob::ExportAlarmJob(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
......@@ -94,7 +95,8 @@ void ExportAlarmJob::slotWriteNextArchiveResource()
if (identifier.contains(QLatin1String("akonadi_kalarm_dir_resource_"))) {
const QString archivePath = Utils::alarmPath() + identifier + QLatin1Char('/');
const QString url = Utils::resourcePath(identifier);
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
......@@ -145,7 +147,8 @@ void ExportAlarmJob::backupConfig()
if (kalarmConfig->hasGroup(collectionsStr)) {
KConfigGroup group = kalarmConfig->group(collectionsStr);
const QString selectionKey(QStringLiteral("FavoriteCollectionIds"));
Utils::convertCollectionIdsToRealPath(group, selectionKey);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(group, selectionKey);
}
kalarmConfig->sync();
......
......@@ -32,6 +32,7 @@
#include <QFile>
#include <QStandardPaths>
#include <QTimer>
#include <resourceconverterimpl.h>
namespace {
inline const QString storeAlarm()
......@@ -108,7 +109,8 @@ void ImportAlarmJob::restoreResources()
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
const QString newUrl = Utils::adaptResourcePath(resourceConfig, storeAlarm());
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, storeAlarm());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
......
......@@ -30,6 +30,7 @@
#include <QFile>
#include <QDir>
#include <QColor>
#include <resourceconverterimpl.h>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
......@@ -96,7 +97,8 @@ void ExportCalendarJob::slotWriteNextArchiveResource()
if (identifier.contains(QLatin1String("akonadi_icaldir_resource_"))) {
const QString archivePath = Utils::calendarPath() + identifier + QLatin1Char('/');
const QString url = Utils::resourcePath(identifier);
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
......@@ -147,14 +149,16 @@ void ExportCalendarJob::backupConfig()
if (korganizerConfig->hasGroup(globalCollectionsStr)) {
KConfigGroup group = korganizerConfig->group(globalCollectionsStr);
const QString selectionKey(QStringLiteral("Selection"));
Utils::convertCollectionListToRealPath(group, selectionKey);
ResourceConverterImpl converter;
converter.convertCollectionListToRealPath(group, selectionKey);
}
const QString collectionTreeViewStr(QStringLiteral("CollectionTreeView"));
if (korganizerConfig->hasGroup(collectionTreeViewStr)) {
KConfigGroup group = korganizerConfig->group(collectionTreeViewStr);
const QString selectionKey(QStringLiteral("Expansion"));
Utils::convertCollectionListToRealPath(group, selectionKey);
ResourceConverterImpl converter;
converter.convertCollectionListToRealPath(group, selectionKey);
}
korganizerConfig->sync();
......
......@@ -36,6 +36,7 @@
#include <QStandardPaths>
#include <QTimer>
#include <QColor>
#include <resourceconverterimpl.h>
namespace {
inline const QString storeCalendar()
......@@ -113,7 +114,8 @@ void ImportCalendarJob::restoreResources()
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
const QString newUrl = Utils::adaptResourcePath(resourceConfig, storeCalendar());
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, storeCalendar());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
......
......@@ -42,6 +42,7 @@
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include <QRegularExpression>
#include <resourceconverterimpl.h>
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>
......@@ -154,8 +155,8 @@ void ExportMailJob::slotWriteNextArchiveResource()
if (identifier.contains(QLatin1String("akonadi_maildir_resource_"))
|| identifier.contains(QLatin1String("akonadi_mixedmaildir_resource_"))) {
const QString archivePath = Utils::mailsPath() + identifier + QLatin1Char('/');
const QString url = Utils::resourcePath(identifier);
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
......@@ -516,10 +517,11 @@ void ExportMailJob::backupConfig()
KConfigGroup favoriteGroup = kmailConfig->group(collectionFolderViewStr);
const QString currentKey(QStringLiteral("Current"));
Utils::convertCollectionToRealPath(favoriteGroup, currentKey);
ResourceConverterImpl converter;
converter.convertCollectionToRealPath(favoriteGroup, currentKey);
const QString expensionKey(QStringLiteral("Expansion"));
Utils::convertCollectionListToRealPath(favoriteGroup, expensionKey);
converter.convertCollectionListToRealPath(favoriteGroup, expensionKey);
}
const QString favoriteCollectionStr(QStringLiteral("FavoriteCollections"));
......@@ -527,7 +529,8 @@ void ExportMailJob::backupConfig()
KConfigGroup favoriteGroup = kmailConfig->group(favoriteCollectionStr);
const QString favoriteCollectionIdsStr(QStringLiteral("FavoriteCollectionIds"));
Utils::convertCollectionIdsToRealPath(favoriteGroup, favoriteCollectionIdsStr);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(favoriteGroup, favoriteCollectionIdsStr);
}
const QString favoriteCollectionOrderStr(QStringLiteral("FavoriteCollectionsOrder"));
......@@ -536,7 +539,8 @@ void ExportMailJob::backupConfig()
//For favorite id for root collection == 0 and we store only folder => c
const QString favoriteCollectionIdsStr(QStringLiteral("0"));
const QString prefixCollection(QStringLiteral("c"));
Utils::convertCollectionIdsToRealPath(favoriteGroup, favoriteCollectionIdsStr, prefixCollection);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(favoriteGroup, favoriteCollectionIdsStr, prefixCollection);
}
//Event collection
......@@ -544,7 +548,8 @@ void ExportMailJob::backupConfig()
if (kmailConfig->hasGroup(eventCollectionStr)) {
KConfigGroup eventGroup = kmailConfig->group(eventCollectionStr);
const QString eventLastEventSelectedFolder(QStringLiteral("LastEventSelectedFolder"));
Utils::convertCollectionIdsToRealPath(eventGroup, eventLastEventSelectedFolder);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(eventGroup, eventLastEventSelectedFolder);
}
//Todo collection
......@@ -552,14 +557,16 @@ void ExportMailJob::backupConfig()
if (kmailConfig->hasGroup(todoCollectionStr)) {
KConfigGroup todoGroup = kmailConfig->group(todoCollectionStr);
const QString todoLastEventSelectedFolder(QStringLiteral("LastSelectedFolder"));
Utils::convertCollectionIdsToRealPath(todoGroup, todoLastEventSelectedFolder);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(todoGroup, todoLastEventSelectedFolder);
}
//FolderSelectionDialog collection
const QString folderSelectionCollectionStr(QStringLiteral("FolderSelectionDialog"));
if (kmailConfig->hasGroup(folderSelectionCollectionStr)) {
KConfigGroup folderSelectionGroup = kmailConfig->group(folderSelectionCollectionStr);
const QString folderSelectionSelectedFolder(QStringLiteral("LastSelectedFolder"));
Utils::convertCollectionIdsToRealPath(folderSelectionGroup, folderSelectionSelectedFolder);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(folderSelectionGroup, folderSelectionSelectedFolder);
}
//Note collection
......@@ -567,7 +574,8 @@ void ExportMailJob::backupConfig()
if (kmailConfig->hasGroup(noteCollectionStr)) {
KConfigGroup noteGroup = kmailConfig->group(noteCollectionStr);
const QString noteLastEventSelectedFolder(QStringLiteral("LastNoteSelectedFolder"));
Utils::convertCollectionIdsToRealPath(noteGroup, noteLastEventSelectedFolder);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(noteGroup, noteLastEventSelectedFolder);
}
//Convert MessageListTab collection id
......@@ -578,7 +586,8 @@ void ExportMailJob::backupConfig()
for (int i = 0; i < numberOfTab; ++i) {
KConfigGroup messageListPaneTabGroup = kmailConfig->group(QStringLiteral("MessageListTab%1").arg(i));
const QString messageListPaneTabFolderStr(QStringLiteral("collectionId"));
Utils::convertCollectionIdsToRealPath(messageListPaneTabGroup, messageListPaneTabFolderStr);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(messageListPaneTabGroup, messageListPaneTabFolderStr);
}
}
......@@ -591,7 +600,8 @@ void ExportMailJob::backupConfig()
if (kmailConfig->hasGroup(groupId)) {
KConfigGroup identityGroup = kmailConfig->group(groupId);
const QString automaticAddContactStr(QStringLiteral("Collection"));
Utils::convertCollectionIdsToRealPath(identityGroup, automaticAddContactStr);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(identityGroup, automaticAddContactStr);
}
}
......
......@@ -46,6 +46,7 @@
#include <QStandardPaths>
#include <QTimer>
#include <QRegularExpression>
#include <resourceconverterimpl.h>
using namespace Akonadi;
namespace {
......@@ -305,10 +306,11 @@ void ImportMailJob::restoreResources()
QDir dir(mTempDirName);
dir.mkdir(Utils::resourcesPath());
ResourceConverterImpl converter;
for (const QString &filename : qAsConst(mFileList)) {
//We need to find akonadi_* and agent_config_akonadi_*
if (filename.startsWith(Utils::resourcesPath() + QStringLiteral("akonadi_"))) {
const QString agentFileConfigName = Utils::agentFileName(filename);
const QString agentFileConfigName = converter.agentFileName(filename);
QString resourceName;
if (mFileList.contains(agentFileConfigName)) {
//Parse config file => get name
......@@ -549,7 +551,8 @@ void ImportMailJob::restoreMails()
//qCDebug(PIMDATAEXPORTERCORE_LOG)<<" filename "<<filename<<" resourceName"<<resourceName;
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
const QString newUrl = Utils::adaptResourcePath(resourceConfig, storeMails());
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, storeMails());
const QString agentConfigFile = value.akonadiAgentConfigFile;
if (!agentConfigFile.isEmpty()) {
......@@ -1288,7 +1291,8 @@ void ImportMailJob::importKmailConfig(const KArchiveFile *kmailsnippet, const QS
KConfigGroup newGroup(kmailConfig, QStringLiteral("Automatic Add Contacts %1").arg(i.value()));
identityGroup.copyTo(&newGroup);
const QString automaticAddContactStr(QStringLiteral("Collection"));
Utils::convertCollectionIdsToRealPath(newGroup, automaticAddContactStr);
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(newGroup, automaticAddContactStr);
identityGroup.deleteGroup();
}
++i;
......
......@@ -61,7 +61,8 @@ void ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource()
if (identifier.contains(QLatin1String("akonadi_akonotes_resource_"))) {
const QString archivePath = Utils::notePath() + identifier + QLatin1Char('/');
QString url = Utils::resourcePath(identifier);
ResourceConverterImpl converter;
QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url) && QDir(url).exists()) {
mAgentPaths << url;
if (!url.isEmpty()) {
......
......@@ -32,6 +32,7 @@
#include <QStandardPaths>
#include <QDir>
#include <QTimer>
#include <resourceconverterimpl.h>
namespace {
inline const QString backupnote()
......@@ -157,7 +158,8 @@ void ImportNotesJob::restoreResources()
KSharedConfig::Ptr resourceConfig = KSharedConfig::openConfig(copyToDirName + QLatin1Char('/') + resourceName);
const QString newUrl = Utils::adaptResourcePath(resourceConfig, backupnote());
ResourceConverterImpl converter;
const QString newUrl = converter.adaptResourcePath(resourceConfig, backupnote());
QFileInfo newUrlInfo(newUrl);
const QString dataFile = value.akonadiResources;
const KArchiveEntry *dataResouceEntry = mArchiveDirectory->entry(dataFile);
......
......@@ -109,34 +109,6 @@ QString Utils::infoPath()
return QStringLiteral("information/");
}
QString Utils::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData)
{
QString newUrl = Utils::resourcePath(resourceConfig);
if (!newUrl.contains(QDir::homePath())) {
QFileInfo fileInfo(newUrl);
fileInfo.fileName();
//qCDebug(PIMDATAEXPORTERCORE_LOG)<<" url "<<url.path();
QString currentPath = QDir::homePath() + QLatin1Char('/') + storedData;
newUrl = (currentPath + QLatin1Char('/') + fileInfo.fileName());
if (!QDir(currentPath).exists()) {
QDir().mkdir(currentPath);
}
}
if (QFileInfo::exists(newUrl)) {
QString newFileName = newUrl;
QFileInfo fileInfo(newFileName);
for (int i = 0;; ++i) {
const QString currentPath = fileInfo.path() + QLatin1Char('/') + QString::number(i) + QLatin1Char('/');
newFileName = currentPath + fileInfo.fileName();
if (!QFileInfo::exists(newFileName)) {
QDir().mkdir(currentPath);
break;
}
}
newUrl = newFileName;
}
return newUrl;
}
QString Utils::resourcePath(const KSharedConfigPtr &resourceConfig, const QString &defaultPath)
{
......@@ -148,81 +120,6 @@ QString Utils::resourcePath(const KSharedConfigPtr &resourceConfig, const QStrin
return url;
}
//Merge two methods I think
void Utils::convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection)
{
if (group.hasKey(currentKey)) {
const QStringList value = group.readEntry(currentKey, QStringList());
QStringList newValue;
for (QString str : value) {
bool found = false;
if (!prefixCollection.isEmpty() && str.startsWith(prefixCollection)) {
str.remove(0, prefixCollection.length());
}
const qlonglong collectionId = str.toLongLong(&found);
if (found) {
const QString realPath = MailCommon::Util::fullCollectionPath(Akonadi::Collection(collectionId));
if (!realPath.isEmpty()) {
newValue << realPath;
}
}
}
if (newValue.isEmpty()) {
group.deleteEntry(currentKey);
} else {
group.writeEntry(currentKey, newValue);
}
}
}
void Utils::convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey)
{
if (group.hasKey(currentKey)) {
const QStringList listExpension = group.readEntry(currentKey, QStringList());
if (listExpension.isEmpty()) {
group.deleteEntry(currentKey);
} else {
QStringList result;
for (QString collection : listExpension) {
collection.remove(QLatin1Char('c'));
bool found = false;
const qlonglong collectionValue = collection.toLongLong(&found);
if (found && collectionValue != -1) {
const QString realPath = MailCommon::Util::fullCollectionPath(Akonadi::Collection(collectionValue));
if (!realPath.isEmpty()) {
result << realPath;
}
}
}
if (result.isEmpty()) {
group.deleteEntry(currentKey);
} else {
group.writeEntry(currentKey, result);
}
}
}
}
void Utils::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
{
if (group.hasKey(currentKey)) {
QString collectionId = group.readEntry(currentKey);
if (collectionId.isEmpty()) {
group.deleteEntry(currentKey);
} else {
collectionId.remove(QLatin1Char('c'));
bool found = false;
const qlonglong collectionValue = collectionId.toLongLong(&found);
if (found && collectionValue != -1) {
const QString realPath = MailCommon::Util::fullCollectionPath(Akonadi::Collection(collectionValue));
group.writeEntry(currentKey, realPath);
} else {
group.deleteEntry(currentKey);
}
}
}
}
QString Utils::resourcePath(const QString &agentIdentifier, const QString &defaultPath)
{
const QString agentFileName = agentIdentifier + QStringLiteral("rc");
......
......@@ -96,12 +96,7 @@ Q_REQUIRED_RESULT QString akonadiAgentName(const QString &configPath);
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString agentFileName(const QString &filename);
void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey);
void convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey);
void convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection = QString());
Q_REQUIRED_RESULT QString resourcePath(const QString &agentIdentifier, const QString &defaultPath = QString());
Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData);
Q_REQUIRED_RESULT QString storeResources(KZip *archive, const QString &identifier, const QString &path);
KZip *openZip(const QString &filename, QString &errorMsg);
PIMDATAEXPORTER_EXPORT void storeDataExportInfo(const QString &filename, KZip *archive);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment