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

Add addNewIdentity virtual method

parent 5aa634ad
......@@ -116,3 +116,9 @@ void ImportMailJobInterfaceTest::importMail()
delete impl;
delete file;
}
void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid)
{
qDebug() << " void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) not implemented yet";
}
......@@ -42,6 +42,7 @@ protected:
Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override;
Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override;
void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) override;
};
class ImportMailJobInterfaceTest : public QObject
......
......@@ -1004,19 +1004,7 @@ void ImportMailJobInterface::restoreIdentity()
}
const QString name = group.readEntry(QStringLiteral("Name"));
KIdentityManagement::Identity *identity = &mIdentityManager->newFromScratch(uniqueIdentityName(name));
group.writeEntry(QStringLiteral("Name"), name);
group.sync();
identity->readConfig(group);
if (oldUid != -1) {
mHashIdentity.insert(oldUid, identity->uoid());
if (oldUid == defaultIdentity) {
mIdentityManager->setAsDefault(identity->uoid());
}
}
mIdentityManager->commit();
addNewIdentity(name, group, defaultIdentity, oldUid);
}
Q_EMIT info(i18n("Identities restored."));
} else {
......
......@@ -58,6 +58,11 @@ protected:
virtual void synchronizeResource(const QStringList &lst) = 0;
virtual void importFilters(const QVector<MailCommon::MailFilter *> &filters) = 0;
virtual Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) = 0;
virtual void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) = 0;
Q_REQUIRED_RESULT QString uniqueIdentityName(const QString &name);
QHash<int, uint> mHashIdentity;
private:
void restoreTransports();
......@@ -81,9 +86,7 @@ private:
void mergeSieveTemplate(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void importSimpleFilesInDirectory(const QString &relativePath);
void addMailTransport(MailTransport::Transport *mt, int defaultTransport, int transportId);
Q_REQUIRED_RESULT QString uniqueIdentityName(const QString &name);
QHash<int, uint> mHashIdentity;
QHash<int, int> mHashTransport;
QHash<QString, QString> mHashResources;
QStringList mFileList;
......
......@@ -23,6 +23,8 @@
#include <AkonadiCore/CollectionFetchJob>
#include <PimCommonAkonadi/CreateResource>
#include <MailCommon/FilterManager>
#include <KIdentityManagement/Identity>
#include <KIdentityManagement/IdentityManager>
using namespace Akonadi;
ImportMailJobInterfaceImpl::ImportMailJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
......@@ -79,3 +81,20 @@ QString ImportMailJobInterfaceImpl::adaptNewResourceUrl(bool overwriteResources,
ResourceConverterImpl converter;
return converter.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath);
}
void ImportMailJobInterfaceImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentity, int oldUid)
{
KIdentityManagement::Identity *identity = &mIdentityManager->newFromScratch(uniqueIdentityName(name));
group.writeEntry(QStringLiteral("Name"), name);
group.sync();
identity->readConfig(group);
if (oldUid != -1) {
mHashIdentity.insert(oldUid, identity->uoid());
if (oldUid == defaultIdentity) {
mIdentityManager->setAsDefault(identity->uoid());
}
}
mIdentityManager->commit();
}
......@@ -47,6 +47,7 @@ protected:
void importFilters(const QVector<MailCommon::MailFilter *> &filters) override;
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override;
void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) override;
};
#endif // ImportMailJob_H
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