presentation/QuickCalendarIcs.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "data/IcsFile.h" | ||
| 4 | #include "data/MailRequest.h" | ||
| 5 | |||
| 6 | #include <QObject> | ||
| 7 | #include <QUrl> | ||
| 8 | #include <QVariantList> | ||
| 9 | #include <QVariantMap> | ||
| 10 | #include <functional> | ||
| 11 | |||
| 12 | class MailSessionCore; | ||
| 13 | |||
| 14 | // Sprint 93 S93.5.3 (CAL-ICS): import and export of calendar files. QML | ||
| 15 | // reaches it as `backend.ics`. | ||
| 16 | // | ||
| 17 | // Import: openFile() (file dialog, drop on the calendar), openAttachment() | ||
| 18 | // (".ics" attachment of the displayed mail) or openText() read a file into | ||
| 19 | // `items` ({uid, summary, whenText, recurring, existsIn [calendar keys], | ||
| 20 | // checked}); IcsImportDialog.qml shows them with the target calendar, and | ||
| 21 | // importChecked() stores the checked series through the coordinator | ||
| 22 | // (outbox, offline-safe). An appointment whose UID already exists in the | ||
| 23 | // target calendar is updated or skipped (duplicate detection by UID). | ||
| 24 | // Export: one appointment series or a whole calendar as a file in the | ||
| 25 | // download folder, or a file for "Send by mail" (attached to a new | ||
| 26 | // message by the caller). | ||
| 27 | // S94.5.9: tasks travel the same way. A file's VTODOs appear in `items` | ||
| 28 | // after its appointments ({kind: "task"}); they are imported into the chosen | ||
| 29 | // calendar when it holds tasks, else into the last used task list. | ||
| 30 | // exportTask()/exportTaskList() write stored task resources unchanged. | ||
| 31 | class QuickCalendarIcs final : public QObject { | ||
| 32 | 21 | Q_OBJECT | |
| 33 | Q_PROPERTY(bool active READ active NOTIFY changed) | ||
| 34 | Q_PROPERTY(QString sourceName READ sourceName NOTIFY changed) | ||
| 35 | Q_PROPERTY(QVariantList items READ items NOTIFY changed) | ||
| 36 | Q_PROPERTY(int checkedCount READ checkedCount NOTIFY changed) | ||
| 37 | Q_PROPERTY(QVariantList calendars READ calendars NOTIFY changed) | ||
| 38 | Q_PROPERTY(QString defaultCalendar READ defaultCalendar NOTIFY changed) | ||
| 39 | public: | ||
| 40 | struct Deps { | ||
| 41 | std::function<QVariantList()> calendarChoices; // QuickPimBackend::calendarChoices | ||
| 42 | std::function<QString()> lastCalendar; // "accountId\npath" | ||
| 43 | std::function<MailId()> currentMail; | ||
| 44 | std::function<void(const QString &)> setStatus; | ||
| 45 | QString exportDirectory; // files for "Send by mail" | ||
| 46 | QString downloadDirectory; // "" = the platform download folder | ||
| 47 | std::function<QString()> lastTaskList; // calendar selection key of the last used task list ("" = none) | ||
| 48 | }; | ||
| 49 | QuickCalendarIcs(MailSessionCore &session, Deps deps, QObject *parent = nullptr); | ||
| 50 | |||
| 51 |
3/4✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 6 taken 2 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 6 times.
|
8 | bool active() const { return !m_entries.isEmpty() || !m_todos.isEmpty(); } |
| 52 | 768 | QString sourceName() const { return m_sourceName; } | |
| 53 | QVariantList items() const; | ||
| 54 | int checkedCount() const; | ||
| 55 | QVariantList calendars() const; | ||
| 56 | QString defaultCalendar() const; | ||
| 57 | |||
| 58 | Q_INVOKABLE bool openFile(const QUrl &url); | ||
| 59 | Q_INVOKABLE bool openAttachment(qint64 attachmentId, const QString &name); | ||
| 60 | bool openText(const QString &text, const QString &name); | ||
| 61 | Q_INVOKABLE void setChecked(int index, bool checked); | ||
| 62 | Q_INVOKABLE void setAllChecked(bool checked); | ||
| 63 | // Returns {ok, imported, updated, skipped, text}. | ||
| 64 | Q_INVOKABLE QVariantMap importChecked(const QString &calendarKey, bool updateExisting); | ||
| 65 | Q_INVOKABLE void close(); | ||
| 66 | |||
| 67 | // The series of an occurrence map ({uid, accountId, calendarPath}). | ||
| 68 | Q_INVOKABLE bool exportOccurrence(const QVariantMap &occurrence); | ||
| 69 | Q_INVOKABLE bool exportCalendar(const QString &accountId, const QString &calendarPath); | ||
| 70 | // Path of a file with the series, for attaching it to a message ("" on failure). | ||
| 71 | Q_INVOKABLE QString occurrenceFile(const QVariantMap &occurrence); | ||
| 72 | // S94.5.9: a task ({uid, accountId, calendarPath}) or a whole task list. | ||
| 73 | Q_INVOKABLE bool exportTask(const QVariantMap &task); | ||
| 74 | Q_INVOKABLE bool exportTaskList(const QString &accountId, const QString &calendarPath); | ||
| 75 | |||
| 76 | signals: | ||
| 77 | void changed(); | ||
| 78 | |||
| 79 | private: | ||
| 80 | QList<QList<CalendarEvent>> seriesOf(const QVariantMap &occurrence) const; | ||
| 81 | QString writeFile(const QString &directory, const QString &name, const QByteArray &bytes, bool unique); | ||
| 82 | bool resolveCalendar(const QString &key, QString *accountId, QString *path) const; | ||
| 83 | // The writable task list for imported tasks: `key` when it holds tasks, | ||
| 84 | // else the last used task list, else the first writable task list. | ||
| 85 | bool resolveTaskList(const QString &key, QString *accountId, QString *path) const; | ||
| 86 | QString saveExport(const QString &title, const QByteArray &bytes); | ||
| 87 | int importTodos(const QString &calendarKey, bool updateExisting, int *updated, int *skipped, int *failed); | ||
| 88 | |||
| 89 | MailSessionCore &m_session; | ||
| 90 | Deps m_deps; | ||
| 91 | QString m_sourceName; | ||
| 92 | QList<IcsFile::Entry> m_entries; | ||
| 93 | QList<bool> m_checked; | ||
| 94 | QList<IcsFile::TodoEntry> m_todos; | ||
| 95 | QList<bool> m_todoChecked; | ||
| 96 | quint64 m_readGeneration = 0; | ||
| 97 | }; | ||
| 98 |