Commit 5bf2e967 authored by Glen Ditchfield's avatar Glen Ditchfield 🐛 Committed by Glen Ditchfield
Browse files

Do not create duplicate tags

If an event with categories is cut & pasted, the pasted event has the
same categories as the original but does not have the same tag-item
relationships in Akonadi.  (This is not the only way that categories
and tags go out of sync.)

When the incidence editor opens the pasted event, it creates new GENERIC
tags for the categories, duplicating the existing tag.  Then it inserts
the tag in the editor, thus making it dirty and causing unnecessary
"Do you really want to cancel?" dialogs.

This patch creates PLAIN tags, merges them with existing tags, and
does not dirty the editor.

BUG: 441846
parent a8d733e8
Pipeline #86452 skipped
......@@ -98,8 +98,11 @@ QStringList IncidenceCategories::categories() const
void IncidenceCategories::createMissingCategories()
for (const QString &category : std::as_const(mMissingCategories)) {
Akonadi::Tag missingTag = Akonadi::Tag::genericTag(category);
// Either the tag doesn't exist, or Akonadi doesn't have a tag <-> item
// relation for this category and instance. Try to create a PLAIN tag.
Akonadi::Tag missingTag = Akonadi::Tag(category);
auto createJob = new Akonadi::TagCreateJob(missingTag, this);
connect(createJob, &Akonadi::TagCreateJob::result, this, &IncidenceCategories::onMissingTagCreated);
......@@ -124,10 +127,13 @@ void IncidenceCategories::onMissingTagCreated(KJob *job)
auto createJob = static_cast<Akonadi::TagCreateJob *>(job);
int count = mMissingCategories.removeAll(createJob->tag().name());
Q_ASSERT(count > 0);
QVector<Akonadi::Tag> selectedTags;
selectedTags.reserve(mUi->mTagWidget->selection().count() + 1);
selectedTags << mUi->mTagWidget->selection() << createJob->tag();
auto selectedTags {mUi->mTagWidget->selection()};
selectedTags += createJob->tag();
// If the created tag was one of the instance's missing categories,
// adding it to the widget doesn't make it dirty.
mUi->mTagWidget->blockSignals(count > 0);
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