Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report when events already exist in db on importation #7

Merged
merged 3 commits into from Oct 19, 2021

Conversation

dcaliste
Copy link
Contributor

@dcaliste dcaliste commented Sep 29, 2021

Add a "duplicate" role to the import model to be able to flag events that already exist in the database, based on their UID.

Also push two simplification commits:

  • the ExtendedStorage::setDefaultNotebook() should not be called. The purpose of this method is to change the flag of a given notebook saying that this notebook is default. It is not the purpose of an importation routine, as far as I can tell.
  • filtering the events from all incodences and sorting them can be done easily with the KCalendarCore::Calendar::events() routine.

@pvuorela and @chriadam, the root of this MR comes from various discussions in this thread on the forum : https://forum.sailfishos.org/t/bug-4-2-0-21-cannot-import-calendar-entries-via-ics-file/7988/13 The overall goal would be to give a better feedback to the user of what is going on during importation. At the moment, importing twice an event with a UID will result in an importation failed, without explaining to the user what happened. What I'm proposing instead of just a detailed error is to warn the user of possible existing event in the database and let the user overwrite them if they choose to.

This PR requires sailfishos/mkcal#7 since, I'm using the same DEL+ADD pattern as in KCalendarCore.

const KCalendarCore::Incidence::Ptr old =
mStorage->calendar()->incidence(incidence->uid(), incidence->recurrenceId());
if (old) {
// Unconditionnaly overwrite existing incidence with the same UID/RecID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: unconditionally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, thanks for the notice.

@@ -54,6 +55,7 @@ class CalendarImportModel : public QAbstractListModel
EndTimeRole,
AllDayRole,
LocationRole,
DuplicateRole,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put this one after the UidRole

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

if (!mEventList.isEmpty())
mEventList.clear();
mEventList = cal->events(KCalendarCore::EventSortStartDate);
for (const KCalendarCore::Event::Ptr &event : mEventList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really important, but I think this will detach due to ranged-for semantics, because mEventList isn't a const ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need a qAsConst here, but it deosn't exist yet in Qt5.6… I left it like that for simplicity, the size of the list is the number of imported events, so it is small. And the list content are QSharedPointers, so the detach should be cheap : no copy will be done.
I've added a comment for future upgrade though.

@chriadam
Copy link
Contributor

LGTM. I wonder if @blammit or @pvuorela have any comments?

@chriadam
Copy link
Contributor

Can you please add "Contributes to JB#55786" to the commit message also?

@dcaliste
Copy link
Contributor Author

I've added the JB id to the commit message.

We also wondered on IRC what happened before the PR if the added event had a revision strictly higher than the already existing event. After checking in mKCal, I'm sure there is no treatment of the revision. You can add an event sharing the same UID and RecID to a calendar that has not been populated with the DB content, and then when saving, whatever the revision of your event, the operation will fail because of UNIQUE constraint not being valid.

@pvuorela
Copy link
Contributor

Didn't test now but seems good to me.

const KCalendarCore::Event::Ptr old =
mStorage->calendar()->event(event->uid(), event->recurrenceId());
if (old) {
mDuplicates.insert(old->instanceIdentifier());
Copy link
Contributor

@pvuorela pvuorela Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mDuplicates should be emptied somewhere in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll update the MR. Thanks.

@pvuorela
Copy link
Contributor

LGTM

@pvuorela pvuorela merged commit 643120a into sailfishos:master Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants