presentation/QuickTaskActions.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include "data/CalendarModels.h" | ||
| 3 | #include "data/MailRequest.h" | ||
| 4 | #include <QHash> | ||
| 5 | #include <QObject> | ||
| 6 | #include <QVariantMap> | ||
| 7 | #include <QVariantList> | ||
| 8 | #include <QSet> | ||
| 9 | #include <functional> | ||
| 10 | #include <optional> | ||
| 11 | |||
| 12 | class MailSessionCore; | ||
| 13 | class WorkspaceState; | ||
| 14 | class QuickTaskModel; | ||
| 15 | |||
| 16 | // Identity-scoped task edits, batching and inverse outbox writes. GUI thread. | ||
| 17 | class QuickTaskActions final : public QObject { | ||
| 18 | 87 | Q_OBJECT | |
| 19 | Q_PROPERTY(QString undoText READ undoText NOTIFY undoChanged) | ||
| 20 | Q_PROPERTY(int defaultReminder READ defaultReminder WRITE setDefaultReminder NOTIFY stateChanged) | ||
| 21 | Q_PROPERTY(QString lastList READ lastList WRITE setLastList NOTIFY stateChanged) | ||
| 22 | public: | ||
| 23 | struct Deps { | ||
| 24 | std::function<bool(const MailId &)> acceptsIdentity; | ||
| 25 | std::function<QString()> accountName; | ||
| 26 | std::function<void(const QString &)> setStatus; | ||
| 27 | }; | ||
| 28 | QuickTaskActions(MailSessionCore &, WorkspaceState &, QuickTaskModel &, Deps, QObject *parent = nullptr); | ||
| 29 | QVariantMap taskRecord(const QString &uid, const QString &accountId, const QString &calendarPath) const; | ||
| 30 | QVariantMap taskAt(int row) const; | ||
| 31 | QVariantMap createTaskFromInput(const QString &input); | ||
| 32 | QVariantMap saveTask(const QVariantMap &fields); | ||
| 33 | QVariantMap currentMailReference() const; | ||
| 34 | QVariantMap taskMailReference(const QString &messageId) const; | ||
| 35 | bool openTaskMail(const QString &messageId); | ||
| 36 | bool toggleTaskAt(int row); | ||
| 37 | bool toggleTask(const QString &uid, const QString &accountId, const QString &calendarPath); | ||
| 38 | bool removeTaskAt(int row); | ||
| 39 | bool removeTask(const QString &uid, const QString &accountId, const QString &calendarPath); | ||
| 40 | Q_INVOKABLE QVariantMap apply(const QVariantList &identities, const QString &action, const QVariantMap &fields = {}); | ||
| 41 | Q_INVOKABLE QVariantMap previewInput(const QString &input) const; | ||
| 42 | static const CalendarInfo *matchTaskList(const QList<CalendarInfo> &calendars, const QString &hint); | ||
| 43 | Q_INVOKABLE QVariantList subtasks(const QVariantMap &identity) const; | ||
| 44 | // S94.5.5: tasks linked to a mail (reader strip) and the canonical | ||
| 45 | // Message-IDs of all open linked tasks (mail list glyph). | ||
| 46 | QVariantList tasksForMessage(const QString &messageId) const; | ||
| 47 | QSet<QString> openTaskMessageIds() const; | ||
| 48 | // S94.5.8: open tasks of the "Today" smart list (overdue, due or starting | ||
| 49 | // today), ordered by due date, for the mail agenda panel. | ||
| 50 | QVariantList dueToday() const; | ||
| 51 | QVariantList openTasksFor(const QString &view, const QString &filter = {}, const QString &sort = QStringLiteral("due")) const; | ||
| 52 | Q_INVOKABLE QVariantMap createSubtask(const QVariantMap &identity, const QString &title); | ||
| 53 | // S94.4.6: place `identity` before or after `target` (same list) in the | ||
| 54 | // manual order; one undo entry for every task whose sort order changes. | ||
| 55 | Q_INVOKABLE QVariantMap reorder(const QVariantMap &identity, const QVariantMap &target, bool after); | ||
| 56 | // S94.4.6: a task chip dragged in the calendar ({uid, accountId, | ||
| 57 | // calendarPath, start}) moves its due date by whole days (undoable). | ||
| 58 | Q_INVOKABLE QVariantMap moveDue(const QVariantMap &occurrence, int deltaMinutes); | ||
| 59 | Q_INVOKABLE bool undo(); | ||
| 60 | Q_INVOKABLE bool open(const QVariantMap &identity); | ||
| 61 | Q_INVOKABLE bool resolveConflict(const QVariantMap &identity, const QString &choice); | ||
| 62 | // F108-12: a write the server refuses — try again now, or take the | ||
| 63 | // server's version (the local change goes into the conflict history). | ||
| 64 | Q_INVOKABLE bool retryWrite(const QVariantMap &identity); | ||
| 65 | Q_INVOKABLE bool discardChange(const QVariantMap &identity); | ||
| 66 | Q_INVOKABLE QVariantMap convertChecklist(const QVariantMap &identity, const QString &description, int line); | ||
| 67 | 122 | QString undoText() const { return m_undoText; } | |
| 68 | 353 | int defaultReminder() const { return m_defaultReminder; } | |
| 69 | void setDefaultReminder(int value); | ||
| 70 | 323 | QString lastList() const { return m_lastList; } | |
| 71 | void setLastList(const QString &key); | ||
| 72 | // Test seam (F-40): how many tasksForCalendar reads subtree collection | ||
| 73 | // performed since the last reset — one per list per bulk action. | ||
| 74 | 2 | int listReadsForTests() const { return m_listReads; } | |
| 75 | 2 | void resetListReadsForTests() { m_listReads = 0; } | |
| 76 | signals: | ||
| 77 | void undoChanged(); | ||
| 78 | void stateChanged(); | ||
| 79 | void openRequested(const QVariantMap &task); | ||
| 80 | private: | ||
| 81 | struct Snapshot { CalendarTask task; bool existed = true; }; | ||
| 82 | void addDefaultReminder(CalendarTask *task) const; | ||
| 83 | void remember(const QString &text, const QList<Snapshot> &snapshots); | ||
| 84 | QList<CalendarTask> subtree(const CalendarTask &task) const; | ||
| 85 | // F-40 (SPRINT-104): the parent→children index of one task list, built | ||
| 86 | // from a single tasksForCalendar read; subtreeOf walks it. | ||
| 87 | QHash<QString, QList<CalendarTask>> childrenOf(const QString &accountId, const QString &calendarPath) const; | ||
| 88 | static QList<CalendarTask> subtreeOf(const CalendarTask &task, | ||
| 89 | const QHash<QString, QList<CalendarTask>> &children); | ||
| 90 | bool validParent(const CalendarTask &task, const QString &parentUid) const; | ||
| 91 | MailSessionCore &m_session; | ||
| 92 | WorkspaceState &m_workspace; | ||
| 93 | QuickTaskModel &m_tasks; | ||
| 94 | Deps m_deps; | ||
| 95 | QList<Snapshot> m_undo; | ||
| 96 | QString m_undoText, m_lastList; | ||
| 97 | const CalendarInfo *defaultTarget(const QList<CalendarInfo> &calendars) const; | ||
| 98 | quint64 m_undoGeneration = 0; | ||
| 99 | int m_defaultReminder = 0; | ||
| 100 | mutable int m_listReads = 0; | ||
| 101 | }; | ||
| 102 |