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

Import export kaddressbook data

parent 0cd3dc71
......@@ -161,6 +161,29 @@ void ExportAddressbookJob::backupConfig()
delete kaddressBookConfig;
}
backupUiRcFile(QStringLiteral("kaddressbookui.rc"), QStringLiteral("kaddressbook"));
QString subDirectory = QStringLiteral("/kaddressbook/csv-templates/");
const QDir templateDirectory(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + subDirectory);
if (templateDirectory.exists()) {
const bool templateDirAdded = archive()->addLocalDirectory(templateDirectory.path(), Utils::dataPath() + subDirectory);
if (templateDirAdded) {
Q_EMIT info(i18n("Template directory \"%1\" added to backup file.", templateDirectory.path()));
} else {
Q_EMIT error(i18n("Template directory \"%1\" cannot be added to backup file.", templateDirectory.path()));
}
}
subDirectory = QStringLiteral("/kaddressbook/viewertemplates/");
const QDir viewertemplateDirectory(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + subDirectory);
if (viewertemplateDirectory.exists()) {
const bool templateDirAdded = archive()->addLocalDirectory(templateDirectory.path(), Utils::dataPath() + subDirectory);
if (templateDirAdded) {
Q_EMIT info(i18n("Template directory \"%1\" added to backup file.", templateDirectory.path()));
} else {
Q_EMIT error(i18n("Template directory \"%1\" cannot be added to backup file.", templateDirectory.path()));
}
}
Q_EMIT info(i18n("Config backup done."));
}
......@@ -255,6 +255,49 @@ void ImportAddressbookJob::importkaddressBookConfig(const KArchiveFile *file, co
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<const KArchiveDirectory *>(csvtemplateEntry);
Q_FOREACH (const QString &entryName, csvTemplateDir->entries()) {
const KArchiveEntry *entry = csvTemplateDir->entry(entryName);
if (entry && entry->isFile()) {
const KArchiveFile *csvTemplateFile = static_cast<const KArchiveFile *>(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);
}
}
}
}
const QString viewerTemplateName = QStringLiteral("/kaddressbook/viewertemplates/");
const KArchiveEntry *themeEntry = mArchiveDirectory->entry(Utils::dataPath() + viewerTemplateName);
if (themeEntry && themeEntry->isDirectory()) {
const KArchiveDirectory *themeDir = static_cast<const KArchiveDirectory *>(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('/') + viewerTemplateName + QStringLiteral("/%1").arg(entryName));
int i = 1;
while (themeDirectory.exists()) {
subFolderName = entryName + QStringLiteral("_%1").arg(i);
themeDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + viewerTemplateName + QStringLiteral("/%1").arg(subFolderName));
++i;
}
copyToDirectory(entry, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + viewerTemplateName + QStringLiteral("/%1").arg(subFolderName));
}
}
}
kaddressBookConfig->sync();
}
......
......@@ -109,3 +109,5 @@ Root
| |---------knotes/print/*
| |---------akregator/*
| |---------blogilo/blogilo.db
| |---------kaddressbook/viewertemplates/
| |---------kaddressbook/csv-templates/
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