presentation/QuickNextUp.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QDateTime> | ||
| 4 | #include <QObject> | ||
| 5 | #include <QTimer> | ||
| 6 | #include <QVariantMap> | ||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <optional> | ||
| 10 | |||
| 11 | class CalendarStore; | ||
| 12 | struct CalendarOccurrence; | ||
| 13 | |||
| 14 | // Sprint 93 S93.3.10 (journey J1): the next appointment of today for the | ||
| 15 | // mail workspace's status bar — "14:00 Dentist · in 25 min", during an | ||
| 16 | // appointment "Now: Design review until 10:30" — with its calendar color, | ||
| 17 | // the occurrence (for the details popover) and a meeting link ("Join"). | ||
| 18 | // Hidden when nothing timed is left today or when switched off | ||
| 19 | // (QSettings "calendar/nextUpInStatusBar", default on). Reads today's | ||
| 20 | // occurrences from its own store connection on refresh(): the calendar's | ||
| 21 | // storeChanged, visibility changes and a 30 s tick. | ||
| 22 | class QuickNextUp final : public QObject { | ||
| 23 | 789 | Q_OBJECT | |
| 24 | Q_PROPERTY(bool available READ available NOTIFY changed) | ||
| 25 | Q_PROPERTY(bool ongoing READ ongoing NOTIFY changed) | ||
| 26 | Q_PROPERTY(QString text READ text NOTIFY changed) | ||
| 27 | Q_PROPERTY(QString color READ color NOTIFY changed) | ||
| 28 | Q_PROPERTY(QVariantMap occurrence READ occurrence NOTIFY changed) | ||
| 29 | Q_PROPERTY(QString meetingUrl READ meetingUrl NOTIFY changed) | ||
| 30 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY changed) | ||
| 31 | // F100-17: at most two appointments after the shown one, revealed when | ||
| 32 | // the status-bar chip is hovered — timed ones first (next 7 days), then | ||
| 33 | // all-day ones (today's running ones first): [{text, color, occurrence}]. | ||
| 34 | Q_PROPERTY(QVariantList following READ following NOTIFY changed) | ||
| 35 | // F100-17: how many more of today's appointments are not shown (the | ||
| 36 | // small "+N" behind them) and that day ("YYYY-MM-DD") for its link. | ||
| 37 | Q_PROPERTY(int moreToday READ moreToday NOTIFY changed) | ||
| 38 | Q_PROPERTY(QString today READ todayIso NOTIFY changed) | ||
| 39 | public: | ||
| 40 | using Clock = std::function<QDateTime()>; | ||
| 41 | using HiddenCalendars = std::function<QStringList()>; | ||
| 42 | QuickNextUp(QString databasePath, HiddenCalendars hiddenCalendars, QObject *parent = nullptr); | ||
| 43 | ~QuickNextUp() override; | ||
| 44 | |||
| 45 |
4/4✓ Branch 3 → 4 taken 1521 times.
✓ Branch 3 → 7 taken 5 times.
✓ Branch 5 → 6 taken 208 times.
✓ Branch 5 → 7 taken 1313 times.
|
1526 | bool available() const { return enabled() && !m_occurrence.isEmpty(); } |
| 46 | 1522 | bool ongoing() const { return m_ongoing; } | |
| 47 | 1523 | QString text() const { return m_text; } | |
| 48 |
2/2✓ Branch 6 → 7 taken 1907 times.
✓ Branch 7 → 8 taken 1907 times.
|
3814 | QString color() const { return m_occurrence.value(QStringLiteral("color")).toString(); } |
| 49 | 5 | QVariantMap occurrence() const { return m_occurrence; } | |
| 50 | 3039 | QString meetingUrl() const { return m_meetingUrl; } | |
| 51 | 3071 | QVariantList following() const { return m_following; } | |
| 52 | 4558 | int moreToday() const { return m_moreToday; } | |
| 53 |
3/3✓ Branch 2 → 3 taken 938 times.
✓ Branch 3 → 4 taken 938 times.
✓ Branch 4 → 5 taken 938 times.
|
938 | QString todayIso() const { return now().date().toString(Qt::ISODate); } |
| 54 | bool enabled() const; | ||
| 55 | void setEnabled(bool enabled); | ||
| 56 | |||
| 57 | Q_INVOKABLE void refresh(); | ||
| 58 | 2 | void setClock(Clock clock) { m_clock = std::move(clock); } | |
| 59 | |||
| 60 | signals: | ||
| 61 | void changed(); | ||
| 62 | |||
| 63 | private: | ||
| 64 | QDateTime now() const; | ||
| 65 | QVariantList followingAfter(const CalendarOccurrence &shown, const QDateTime ¤t, int *moreToday); | ||
| 66 | std::optional<CalendarOccurrence> nextLater(const QDateTime ¤t); | ||
| 67 | |||
| 68 | QString m_databasePath; | ||
| 69 | HiddenCalendars m_hiddenCalendars; | ||
| 70 | Clock m_clock; | ||
| 71 | std::unique_ptr<CalendarStore> m_store; | ||
| 72 | QTimer m_tick; | ||
| 73 | QVariantMap m_occurrence; | ||
| 74 | QString m_text; | ||
| 75 | QString m_meetingUrl; | ||
| 76 | QVariantList m_following; | ||
| 77 | int m_moreToday = 0; | ||
| 78 | bool m_ongoing = false; | ||
| 79 | QString m_today; // the day of the last emitted state | ||
| 80 | }; | ||
| 81 |