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

Get tags directly from the Akonadi::Item

Using a fetch job to get the incidence's tags adds complexity, and the
fetch handler sets the "dirty" flag after loading finishes, which
causes unnecessary "Do you really want to cancel?" dialogs whenever a
user opens a tagged incidence for editing and then cancels the edit
without changing anything.
parent 5c741bbf
Pipeline #68767 failed with stage
in 4 minutes and 42 seconds
......@@ -12,6 +12,8 @@
#include "incidenceeditor_debug.h"
#include "ui_dialogdesktop.h"
#include <CalendarSupport/Utils>
#include <TagAttribute>
#include <TagCreateJob>
#include <TagFetchJob>
......@@ -36,15 +38,30 @@ void IncidenceCategories::onSelectionChanged(const Akonadi::Tag::List &list)
void IncidenceCategories::load(const KCalendarCore::Incidence::Ptr &incidence)
{
mLoadedIncidence = incidence;
Q_UNUSED(incidence)
}
void IncidenceCategories::load(const Akonadi::Item &item)
{
mLoadedIncidence = CalendarSupport::incidence(item);
mDirty = false;
mWasDirty = false;
mMissingCategories.clear();
Q_ASSERT(mLoadedIncidence);
if (mLoadedIncidence) {
auto fetchJob = new Akonadi::TagFetchJob(this);
fetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>();
connect(fetchJob, &Akonadi::TagFetchJob::result, this, &IncidenceCategories::onTagsFetched);
mMissingCategories = mLoadedIncidence->categories();
const auto tags = item.tags();
Akonadi::Tag::List selectedTags;
selectedTags.reserve(mMissingCategories.count());
for (const auto &tag : tags) {
if (mMissingCategories.removeAll(tag.name()) > 0) {
selectedTags << tag;
}
}
createMissingCategories();
mUi->mTagWidget->blockSignals(true);
mUi->mTagWidget->setSelection(selectedTags);
mUi->mTagWidget->blockSignals(false);
}
}
......@@ -97,30 +114,6 @@ void IncidenceCategories::printDebugInfo() const
qCDebug(INCIDENCEEDITOR_LOG) << "mLoadedIncidence->categories() = " << mLoadedIncidence->categories();
}
void IncidenceCategories::onTagsFetched(KJob *job)
{
if (job->error()) {
qCWarning(INCIDENCEEDITOR_LOG) << "Failed to load tags " << job->errorString();
return;
}
auto fetchJob = static_cast<Akonadi::TagFetchJob *>(job);
const Akonadi::Tag::List jobTags = fetchJob->tags();
Q_ASSERT(mLoadedIncidence);
mMissingCategories = mLoadedIncidence->categories();
Akonadi::Tag::List selectedTags;
selectedTags.reserve(mMissingCategories.count());
for (const auto &tag : jobTags) {
if (mMissingCategories.removeAll(tag.name()) > 0) {
selectedTags << tag;
}
}
createMissingCategories();
mUi->mTagWidget->setSelection(selectedTags);
}
void IncidenceCategories::onMissingTagCreated(KJob *job)
{
if (job->error()) {
......
......@@ -23,6 +23,7 @@ public:
explicit IncidenceCategories(Ui::EventOrTodoDesktop *ui);
void load(const KCalendarCore::Incidence::Ptr &incidence) override;
void load(const Akonadi::Item &item) override;
void save(const KCalendarCore::Incidence::Ptr &incidence) override;
void save(Akonadi::Item &item) override;
......@@ -38,7 +39,6 @@ private:
void createMissingCategories();
void onSelectionChanged(const Akonadi::Tag::List &);
void onTagsFetched(KJob *);
void onMissingTagCreated(KJob *);
Ui::EventOrTodoDesktop *mUi = nullptr;
......
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