Bug 446665 - Cannot set Addressee birthday from QML (e.g., from plasma-phonebook)
Summary: Cannot set Addressee birthday from QML (e.g., from plasma-phonebook)
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kcontacts
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: git
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL: https://invent.kde.org/plasma-mobile/...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-08 04:55 UTC by Kevin Kofler
Modified: 2022-03-30 23:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Kofler 2021-12-08 04:55:37 UTC
As can be seen in:
https://invent.kde.org/frameworks/kcontacts/-/blob/c0bd98e873075d57eed2555f9f4126ba660dc59a/src/addressee.h#L85
the birthday property in Addressee is not writable, and neither is there a scriptable explicit setter.

This is the root cause of this plasma-phonebook regression:
https://invent.kde.org/plasma-mobile/plasma-phonebook/-/issues/6#note_307938

As the comment in addressee.h says, the issue that makes this not straightforward is the withTime argument. I think the best that can be done is something like:

Q_PROPERTY(QDateTime birthday READ birthday WRITE setBirthdayProperty)

void setBirthdayProperty(const QDateTime &birthday) {
  setBirthday(birthday, birthday.time().msecsSinceStartOfDay() != 0);
}

(which will treat an explicit time of midnight the same as no time, but at least it should do the right thing in the context of the Phonebook application where we do not allow setting a time to begin with, and even with a time, it will do the right thing in most cases).
Comment 1 Kevin Kofler 2021-12-21 03:41:09 UTC
Ping? Would a solution like the one I suggested be acceptable? If so, I can probably send a merge request, but I will not spend my time on it if it is going to be rejected anyway. So I need your feedback!
Comment 2 Kevin Kofler 2022-01-10 05:18:42 UTC
Volker, you are the one who added the Q_PROPERTY lines for Addressee including the one at issue here, could you please chime in? (I am willing to send a merge request if the general approach sounds reasonable to you, but I do not want to waste my time coding a merge request if it will be met with the same silence as this bug report.)
Comment 3 Volker Krause 2022-01-10 16:46:31 UTC
Making the birthday property writable in some form, using the approach you outlined or e.g. by marking the existing setter Q_INVOKABLE, seems like a good idea to me. But of course I can't make any promises about this being accepted, I'm not the maintainer of KContacts.
Comment 4 Bug Janitor Service 2022-03-20 21:47:34 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kcontacts/-/merge_requests/37
Comment 5 Kevin Kofler 2022-03-30 23:06:03 UTC
Git commit 8b4ba9c0ed465ded679e626071feebe8aabe481c by Kevin Kofler.
Committed on 30/03/2022 at 23:03.
Pushed by kkofler into branch 'master'.

Addressee: make birthday writable from QML

Add a private Addressee::setBirthdayProperty(const QDateTime &) wrapper
method that guesses the extra withTime argument and use that as the
WRITE method for the Q_PROPERTY birthday.

A non-midnight time spec will lead to the birthday being recorded with
the time, a time spec exactly at midnight to a date-only birthday (the
common case). This is the best we can do for a property setter.

This should make setting the birthday in Plasma Phonebook work again.
(It last worked when Plasma Phonebook had its own QML wrapper for the
Addressee class, which has been dropped since.)

See also:
https://invent.kde.org/plasma-mobile/plasma-phonebook/-/issues/6#note_307938

M  +5    -0    src/addressee.cpp
M  +2    -1    src/addressee.h

https://invent.kde.org/frameworks/kcontacts/commit/8b4ba9c0ed465ded679e626071feebe8aabe481c