Clean up KCalendarCore::Calendar
Open, Needs TriagePublic

Description

calendar.h starts with this comment:

TODO: KDE5:

This API needs serious cleaning up:
- Most (all) methods aren't async ( deleteIncidence(), addIncidence(), load(), save(), ... )
  so it's not very easy to make a derived class that loads from akonadi.

- It has too many methods. Why do we need fooEvent()/fooJournal()/fooTodo() when fooIncidence()
  should be enough.

Related: Use hierarchical dptrs in KCalendarCore::Incidence classes

Many calendar component properties are interrelated, and an API that provides individual setters for them is likely to allow invalid combinations, or to have subtle behaviors depending on the order of calls. See KCalendarCore MR 45 which handles some interactions between "completed" status, completion dates, and completion percentages. An interface that sets several properties at once could be less error-prone, but I don't know how that interacts with Q_PROPERTY().

  • IncidenceBase
    • d should be a unique_ptr.
  • Incidence
    • GEO
      • Latitude and longitude should both be valid, or both should be undefined.
      • setHasGeo(true) is a weird thing to do.
      • Suggestions:
        • Remove setHasGeo(), setGeoLatitude(), setGeoLongitude().
        • Add
          • void setGeo(float, float); or
          • void setGeo(std::pair<float,float>); or
          • void setGeo(QVector<float>); (must have 2 elements) or
          • void setGeo(QGeoCoordinate) or
          • class Geo; void setGeo(Geo);, where Geo encapsulates the float pair and the constructor performs range checks.
        • hasGeo() is true if and only if both floats are in range.
        • geo() returns a std::pair, QVector, or Geo, to match setGeo().
    • PRIORITY
      • Defined by RFC 5545 as 0 (undefined), 1 (highest), 2, 3, ... 9 (lowest). Importance is mostly the reverse of the numerical order.
        • In a UI that can sort by priority, is highest > lowest? In KF5, no. I think KF6 should change that.
        • Is undefined < lowest? In KF5, yes. I think KF6 should keep that.
    • RELATED-TO: this should allow more than one GUID per relationship type.
      • QMultiMap<RelType,Guid> relatedTo(); or
      • QList<Guid> relatedTo(RelType);
    • Revision: rename to RFC5545 terminology SEQUENCE.
    • SEQUENCE: should this be unsigned instead of int?
    • STATUS
      • Not all status values are valid for all components.
      • Setting a status can have side-effects: changing the status of a completed should clear any completed date.
      • Suggestions:
        • Remove Incidence::setStatus() and add setStatus() to the descendant classes, or
        • Make Incidence::setStatus() virtual.
ognarb added a subscriber: ognarb.Mar 22 2021, 4:42 PM

In https://invent.kde.org/carlschwan/kalendar I tried to use the Calendar API to build a QML based monthview. It was possible but I wish there was an easy way to be able to know how many events collides.

alex added a subscriber: alex.Sep 24 2021, 2:42 PM

@gjditchfield Are you planning on working on this?

"Hoping" would be a better word than "planning".

I do have some scattered notes that I should move here.

gjditchfield updated the task description. (Show Details)Sep 25 2021, 9:17 PM
gjditchfield added a project: Heaptrack.
alex added a comment.Sep 26 2021, 11:11 AM

PRIORITY: should this be unsigned instead of int?

The general trend is to not use the unsigned types unless one really needs to. Would there be reasons why one would want to have an unsigned int?

In T14217#263949, @alex wrote:

Would there be reasons why one would want to have an unsigned int?

PRIORITY must be in 0..9, so with an unsigned type the compiler can help me avoid the simple dumb mistake of using a negative priority value. (Of course, that's only half of the possible mistakes.)

alex added a comment.Sep 26 2021, 6:39 PM

I don't think a unit helps there, what if the value comes as an int from the UI? This is always ugly IMHO. I think there is validation needed instead.

gjditchfield updated the task description. (Show Details)Sep 27 2021, 7:32 PM