Commit 4484df3d authored by Igor Poboiko's avatar Igor Poboiko
Browse files

[resources/ews] Adjust name of root collection to the name of the resource

The name of root collection inside the Akonadi DB (and thus, i.e. inside KMail)
is always `akonadi_ews_resource#`, even if the resource itself was renamed.
Even though we call `mRootCollection->setName(name())`, the name get's
overriden after we fetch it from DB.
The settings UI changes the name of the resource, but not root collection.

This patch runs `CollectionModifyJob` to rename the root collection in both
scenarios: either when we fetch root collection or change the resource name.

BUG: 413078
BUG: 416663

Test Plan:
1) Open KMail -> Settings -> Accounts -> Receiving -> EWS account
2) Change "Account Name", save
3) The change gets applied to Mailbox View inside KMail UI immediately

Reviewers: dvratil, nowicki

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision:
parent 5b19d1ad
......@@ -145,6 +145,7 @@ EwsResource::EwsResource(const QString &id)
QMetaObject::invokeMethod(this, &EwsResource::delayedInit, Qt::QueuedConnection);
connect(this, &AgentBase::reloadConfiguration, this, &EwsResource::reloadConfig);
connect(this, &ResourceBase::nameChanged, this, &EwsResource::adjustRootCollectionName);
......@@ -302,6 +303,7 @@ void EwsResource::rootCollectionFetched(KJob *job)
CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob *>(job);
if (fetchJob && !fetchJob->collections().isEmpty()) {
mRootCollection = fetchJob->collections().first();
qCDebugNC(EWSRES_LOG) << QStringLiteral("Root collection fetched: ") << mRootCollection;
......@@ -1408,4 +1410,15 @@ void EwsResource::emitReadyStatus()
Q_EMIT percent(0);
void EwsResource::adjustRootCollectionName(const QString &newName)
if (mRootCollection.isValid()) {
auto *attr = mRootCollection.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing);
if (attr->displayName() != newName) {
new CollectionModifyJob(mRootCollection);
......@@ -126,6 +126,7 @@ private Q_SLOTS:
void authFailed(const QString &error);
void requestAuthFailed();
void emitReadyStatus();
void adjustRootCollectionName(const QString &newName);
public Q_SLOTS:
Q_SCRIPTABLE void sendMessage(const QString &id, const QByteArray &content);
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