presentation/ComposeSessionStore.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ComposeSessionStore.h" | ||
| 2 | #include "ComposeLog.h" | ||
| 3 | |||
| 4 | #include <QQmlEngine> | ||
| 5 | #include <QTimer> | ||
| 6 | |||
| 7 | #include "ComposeDraftFiles.h" | ||
| 8 | |||
| 9 | #include <QLoggingCategory> | ||
| 10 | #include <QUuid> | ||
| 11 | |||
| 12 | |||
| 13 | 798 | ComposeSessionStore::ComposeSessionStore(QObject *parent) : QAbstractListModel(parent) {} | |
| 14 | |||
| 15 | 798 | ComposeSessionStore::~ComposeSessionStore() = default; | |
| 16 | |||
| 17 | 2152 | int ComposeSessionStore::rowCount(const QModelIndex &parent) const { | |
| 18 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 2151 times.
|
2152 | return parent.isValid() ? 0 : int(m_sessions.size()); |
| 19 | } | ||
| 20 | |||
| 21 | 7 | QVariant ComposeSessionStore::data(const QModelIndex &index, int role) const { | |
| 22 |
5/6✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 7 taken 1 time.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 6 times.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 11 taken 6 times.
|
7 | if (!index.isValid() || index.row() >= int(m_sessions.size())) return {}; |
| 23 | 6 | ComposeSession *session = m_sessions.at(index.row()).get(); | |
| 24 |
6/7✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 17 taken 1 time.
✓ Branch 14 → 21 taken 1 time.
✓ Branch 14 → 25 taken 1 time.
✓ Branch 14 → 29 taken 1 time.
✓ Branch 14 → 33 taken 1 time.
✗ Branch 14 → 35 not taken.
|
6 | switch (role) { |
| 25 | 1 | case SessionRole: return QVariant::fromValue(static_cast<QObject *>(session)); | |
| 26 | 1 | case SessionIdRole: return session->sessionId(); | |
| 27 | 1 | case Qt::DisplayRole: | |
| 28 |
1/1✓ Branch 21 → 22 taken 1 time.
|
1 | case TitleRole: return session->title(); |
| 29 | 1 | case PlaceRole: return session->place(); | |
| 30 | 1 | case KindRole: return session->kind(); | |
| 31 | 1 | case DirtyRole: return session->dirty(); | |
| 32 | ✗ | default: return {}; | |
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | 1 | QHash<int, QByteArray> ComposeSessionStore::roleNames() const { | |
| 37 | ✗ | return {{SessionRole, "session"}, {SessionIdRole, "sessionId"}, {TitleRole, "title"}, | |
| 38 |
2/4✓ Branch 10 → 11 taken 6 times.
✓ Branch 10 → 12 taken 1 time.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
|
7 | {PlaceRole, "place"}, {KindRole, "kind"}, {DirtyRole, "dirty"}}; |
| 39 | 1 | } | |
| 40 | |||
| 41 | 2 | int ComposeSessionStore::openDrafts() const { | |
| 42 | 2 | int count = 0; | |
| 43 |
2/2✓ Branch 25 → 4 taken 4 times.
✓ Branch 25 → 26 taken 2 times.
|
6 | for (const auto &session : m_sessions) |
| 44 |
7/10✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 16 not taken.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 16 taken 1 time.
✓ Branch 17 → 18 taken 4 times.
✗ Branch 17 → 19 not taken.
✓ Branch 19 → 20 taken 4 times.
✗ Branch 19 → 21 not taken.
✓ Branch 21 → 22 taken 3 times.
✓ Branch 21 → 23 taken 1 time.
|
4 | if (session->place() != QLatin1String("outbox") && session->place() != QLatin1String("discarded")) ++count; |
| 45 | 2 | return count; | |
| 46 | } | ||
| 47 | |||
| 48 | 1549 | int ComposeSessionStore::indexOf(const QString &sessionId) const { | |
| 49 |
2/2✓ Branch 12 → 3 taken 1758 times.
✓ Branch 12 → 13 taken 58 times.
|
1816 | for (int i = 0; i < int(m_sessions.size()); ++i) |
| 50 |
3/3✓ Branch 3 → 4 taken 1758 times.
✓ Branch 8 → 9 taken 1491 times.
✓ Branch 8 → 10 taken 267 times.
|
1758 | if (m_sessions.at(i)->sessionId() == sessionId) return i; |
| 51 | 58 | return -1; | |
| 52 | } | ||
| 53 | |||
| 54 | 159 | void ComposeSessionStore::adopt(std::unique_ptr<ComposeSession> session) { | |
| 55 | 159 | ComposeSession *raw = session.get(); | |
| 56 | // Sessions reach QML through invokables; without this the JavaScript | ||
| 57 | // garbage collector would own (and delete) the parentless objects. | ||
| 58 |
1/1✓ Branch 3 → 4 taken 159 times.
|
159 | QQmlEngine::setObjectOwnership(raw, QQmlEngine::CppOwnership); |
| 59 | 159 | const QString id = raw->sessionId(); | |
| 60 |
1/1✓ Branch 6 → 7 taken 159 times.
|
159 | connect(raw, &ComposeSession::finished, this, [this, id](const QString &reason) { |
| 61 | // Sent sessions wait in the outbox (parkForOutbox); the others end here. | ||
| 62 |
6/6✓ Branch 4 → 5 taken 50 times.
✓ Branch 4 → 8 taken 19 times.
✓ Branch 7 → 8 taken 8 times.
✓ Branch 7 → 9 taken 42 times.
✓ Branch 10 → 11 taken 27 times.
✓ Branch 10 → 12 taken 42 times.
|
69 | if (reason == QLatin1String("sent") || reason == QLatin1String("scheduled")) return; |
| 63 |
1/1✓ Branch 14 → 15 taken 42 times.
|
42 | removeSession(id, reason == QLatin1String("discarded")); |
| 64 | 42 | emit sessionClosed(id, reason); | |
| 65 | }); | ||
| 66 | 991 | auto refresh = [this, raw] { | |
| 67 |
1/1✓ Branch 3 → 4 taken 991 times.
|
991 | const int row = indexOf(raw->sessionId()); |
| 68 |
4/5✓ Branch 5 → 6 taken 991 times.
✗ Branch 5 → 14 not taken.
✓ Branch 8 → 9 taken 991 times.
✓ Branch 10 → 11 taken 991 times.
✓ Branch 11 → 12 taken 991 times.
|
991 | if (row >= 0) emit dataChanged(index(row), index(row)); |
| 69 | 991 | }; | |
| 70 |
1/1✓ Branch 9 → 10 taken 159 times.
|
159 | connect(raw, &ComposeSession::subjectChanged, this, refresh); |
| 71 |
1/1✓ Branch 11 → 12 taken 159 times.
|
159 | connect(raw, &ComposeSession::placeChanged, this, refresh); |
| 72 |
1/1✓ Branch 13 → 14 taken 159 times.
|
159 | connect(raw, &ComposeSession::saveStateChanged, this, refresh); |
| 73 |
1/1✓ Branch 18 → 19 taken 159 times.
|
159 | beginInsertRows({}, int(m_sessions.size()), int(m_sessions.size())); |
| 74 |
1/1✓ Branch 20 → 21 taken 159 times.
|
159 | m_sessions.push_back(std::move(session)); |
| 75 |
1/1✓ Branch 21 → 22 taken 159 times.
|
159 | endInsertRows(); |
| 76 |
1/1✓ Branch 22 → 23 taken 159 times.
|
159 | emit changed(); |
| 77 |
1/1✓ Branch 23 → 24 taken 159 times.
|
159 | emit sessionOpened(raw); |
| 78 | 159 | } | |
| 79 | |||
| 80 | 154 | ComposeSession *ComposeSessionStore::create(const QString &kind, const QVariantMap &prefill, const QString &place, | |
| 81 | const QVariantMap &mailReference, const ComposeSession::Quote "e) { | ||
| 82 |
2/2✓ Branch 2 → 3 taken 154 times.
✓ Branch 3 → 4 taken 154 times.
|
154 | const QString id = QUuid::createUuid().toString(QUuid::WithoutBraces); |
| 83 |
1/1✓ Branch 4 → 5 taken 154 times.
|
154 | auto session = std::make_unique<ComposeSession>(id, kind, m_deps); |
| 84 |
1/1✓ Branch 6 → 7 taken 154 times.
|
154 | session->setPlace(place, mailReference); |
| 85 |
1/1✓ Branch 8 → 9 taken 154 times.
|
154 | session->prefill(prefill, quote); |
| 86 | 154 | ComposeSession *raw = session.get(); | |
| 87 |
7/7✓ Branch 10 → 11 taken 154 times.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 21 → 12 taken 1 time.
✓ Branch 21 → 22 taken 154 times.
|
155 | qCInfo(lcCompose) << "session opened" << kind << place; |
| 88 |
1/1✓ Branch 24 → 25 taken 154 times.
|
154 | adopt(std::move(session)); |
| 89 | 154 | return raw; | |
| 90 | 154 | } | |
| 91 | |||
| 92 | ✗ | QObject *ComposeSessionStore::createSession(const QString &kind, const QVariantMap &prefill, const QString &place) { | |
| 93 | ✗ | return create(kind, prefill, place); | |
| 94 | } | ||
| 95 | |||
| 96 | 493 | QObject *ComposeSessionStore::session(const QString &sessionId) const { | |
| 97 | 493 | const int row = indexOf(sessionId); | |
| 98 |
2/2✓ Branch 3 → 4 taken 441 times.
✓ Branch 3 → 6 taken 52 times.
|
493 | return row < 0 ? nullptr : m_sessions.at(row).get(); |
| 99 | } | ||
| 100 | |||
| 101 | 10132 | QObject *ComposeSessionStore::sessionForMail(const QString &accountId, qint64 folderId, qint64 uid) const { | |
| 102 |
2/2✓ Branch 81 → 4 taken 389 times.
✓ Branch 81 → 82 taken 10072 times.
|
10461 | for (const auto &session : m_sessions) { |
| 103 | 389 | const QVariantMap reference = session->mailReference(); | |
| 104 |
8/22✓ Branch 11 → 12 taken 389 times.
✓ Branch 12 → 13 taken 389 times.
✓ Branch 63 → 64 taken 389 times.
✗ Branch 63 → 65 not taken.
✓ Branch 65 → 66 taken 389 times.
✗ Branch 65 → 67 not taken.
✓ Branch 67 → 68 taken 389 times.
✗ Branch 67 → 69 not taken.
✓ Branch 69 → 70 taken 389 times.
✗ Branch 69 → 71 not taken.
✓ Branch 71 → 72 taken 60 times.
✓ Branch 71 → 74 taken 329 times.
✗ Branch 126 → 127 not taken.
✗ Branch 126 → 128 not taken.
✗ Branch 130 → 131 not taken.
✗ Branch 130 → 132 not taken.
✗ Branch 134 → 135 not taken.
✗ Branch 134 → 136 not taken.
✗ Branch 138 → 139 not taken.
✗ Branch 138 → 140 not taken.
✗ Branch 142 → 143 not taken.
✗ Branch 142 → 144 not taken.
|
1167 | if (reference.value(QStringLiteral("accountId")).toString() == accountId && |
| 105 |
10/20✓ Branch 19 → 20 taken 129 times.
✓ Branch 20 → 21 taken 129 times.
✓ Branch 21 → 22 taken 129 times.
✗ Branch 21 → 40 not taken.
✓ Branch 55 → 56 taken 129 times.
✓ Branch 55 → 57 taken 260 times.
✓ Branch 57 → 58 taken 129 times.
✓ Branch 57 → 59 taken 260 times.
✓ Branch 59 → 60 taken 129 times.
✓ Branch 59 → 61 taken 260 times.
✓ Branch 61 → 62 taken 389 times.
✗ Branch 61 → 63 not taken.
✗ Branch 110 → 111 not taken.
✗ Branch 110 → 112 not taken.
✗ Branch 114 → 115 not taken.
✗ Branch 114 → 116 not taken.
✗ Branch 118 → 119 not taken.
✗ Branch 118 → 120 not taken.
✗ Branch 122 → 123 not taken.
✗ Branch 122 → 124 not taken.
|
647 | reference.value(QStringLiteral("folderId")).toLongLong() == folderId && |
| 106 |
18/28✓ Branch 14 → 15 taken 129 times.
✓ Branch 14 → 40 taken 260 times.
✓ Branch 26 → 27 taken 129 times.
✓ Branch 27 → 28 taken 129 times.
✓ Branch 28 → 29 taken 65 times.
✓ Branch 28 → 40 taken 64 times.
✓ Branch 33 → 34 taken 61 times.
✓ Branch 33 → 40 taken 4 times.
✓ Branch 45 → 46 taken 129 times.
✓ Branch 45 → 47 taken 260 times.
✓ Branch 47 → 48 taken 129 times.
✓ Branch 47 → 49 taken 260 times.
✓ Branch 49 → 50 taken 129 times.
✓ Branch 49 → 51 taken 260 times.
✓ Branch 51 → 52 taken 129 times.
✓ Branch 51 → 53 taken 260 times.
✓ Branch 53 → 54 taken 129 times.
✓ Branch 53 → 55 taken 260 times.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 91 not taken.
✗ Branch 94 → 95 not taken.
✗ Branch 94 → 96 not taken.
✗ Branch 98 → 99 not taken.
✗ Branch 98 → 100 not taken.
✗ Branch 102 → 103 not taken.
✗ Branch 102 → 104 not taken.
✗ Branch 106 → 107 not taken.
✗ Branch 106 → 108 not taken.
|
1486 | reference.value(QStringLiteral("uid")).toLongLong() == uid && session->place() != QLatin1String("outbox") && |
| 107 |
6/8✓ Branch 38 → 39 taken 60 times.
✓ Branch 38 → 40 taken 1 time.
✓ Branch 41 → 42 taken 61 times.
✓ Branch 41 → 43 taken 328 times.
✓ Branch 43 → 44 taken 65 times.
✓ Branch 43 → 45 taken 324 times.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
|
450 | session->place() != QLatin1String("discarded")) |
| 108 | 60 | return session.get(); | |
| 109 | 389 | } | |
| 110 | 10072 | return nullptr; | |
| 111 | } | ||
| 112 | |||
| 113 | 10128 | QObject *ComposeSessionStore::sessionForReference(const QVariantMap &reference) const { | |
| 114 | 10128 | bool folderOk = false, uidOk = false; | |
| 115 |
3/3✓ Branch 6 → 7 taken 10128 times.
✓ Branch 7 → 8 taken 10128 times.
✓ Branch 8 → 9 taken 10128 times.
|
20256 | const qint64 folderId = reference.value(QStringLiteral("folderId")).toString().toLongLong(&folderOk); |
| 116 |
3/3✓ Branch 18 → 19 taken 10128 times.
✓ Branch 19 → 20 taken 10128 times.
✓ Branch 20 → 21 taken 10128 times.
|
20256 | const qint64 uid = reference.value(QStringLiteral("uid")).toString().toLongLong(&uidOk); |
| 117 |
3/4✓ Branch 26 → 27 taken 10127 times.
✓ Branch 26 → 28 taken 1 time.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 10127 times.
|
10128 | if (!folderOk || !uidOk) return nullptr; |
| 118 |
3/3✓ Branch 33 → 34 taken 10127 times.
✓ Branch 34 → 35 taken 10127 times.
✓ Branch 35 → 36 taken 10127 times.
|
20254 | return sessionForMail(reference.value(QStringLiteral("accountId")).toString(), folderId, uid); |
| 119 | } | ||
| 120 | |||
| 121 | 3 | void ComposeSessionStore::setPlace(const QString &sessionId, const QString &place) { | |
| 122 | 3 | const int row = indexOf(sessionId); | |
| 123 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3 times.
|
3 | if (row < 0) return; |
| 124 |
4/4✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 13 taken 2 times.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 14 → 15 taken 3 times.
|
3 | m_sessions.at(row)->setPlace(place, place == QLatin1String("inline") ? m_sessions.at(row)->mailReference() : QVariantMap()); |
| 125 | 3 | emit changed(); | |
| 126 | } | ||
| 127 | |||
| 128 | 1301 | QList<ComposeSession *> ComposeSessionStore::sessions() const { | |
| 129 | 1301 | QList<ComposeSession *> out; | |
| 130 |
3/3✓ Branch 6 → 7 taken 427 times.
✓ Branch 9 → 4 taken 427 times.
✓ Branch 9 → 10 taken 1301 times.
|
1728 | for (const auto &session : m_sessions) out.append(session.get()); |
| 131 | 1301 | return out; | |
| 132 | ✗ | } | |
| 133 | |||
| 134 | 794 | int ComposeSessionStore::restoreOpenSessions() { | |
| 135 | 794 | int restored = 0; | |
| 136 |
5/5✓ Branch 2 → 3 taken 794 times.
✓ Branch 3 → 4 taken 794 times.
✓ Branch 4 → 5 taken 794 times.
✓ Branch 57 → 6 taken 5 times.
✓ Branch 57 → 58 taken 794 times.
|
799 | for (const QString &id : ComposeDraftFiles::sessions(m_deps.profileDirectory)) { |
| 137 |
2/3✓ Branch 7 → 8 taken 5 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 5 times.
|
5 | if (indexOf(id) >= 0) continue; |
| 138 |
1/1✓ Branch 10 → 11 taken 5 times.
|
5 | const auto draft = ComposeDraftFiles::load(m_deps.profileDirectory, id); |
| 139 |
8/20✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 20 not taken.
✓ Branch 17 → 18 taken 5 times.
✓ Branch 18 → 19 taken 5 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 5 times.
✓ Branch 22 → 23 taken 5 times.
✗ Branch 22 → 24 not taken.
✓ Branch 24 → 25 taken 5 times.
✗ Branch 24 → 26 not taken.
✓ Branch 26 → 27 taken 5 times.
✗ Branch 26 → 28 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 5 times.
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
|
10 | if (!draft || draft->value(QStringLiteral("closed")).toBool()) continue; |
| 140 |
3/3✓ Branch 34 → 35 taken 5 times.
✓ Branch 35 → 36 taken 5 times.
✓ Branch 36 → 37 taken 5 times.
|
10 | auto session = std::make_unique<ComposeSession>(id, draft->value(QStringLiteral("kind")).toString(), m_deps); |
| 141 |
1/1✓ Branch 43 → 44 taken 5 times.
|
5 | session->restore(*draft); |
| 142 |
1/1✓ Branch 46 → 47 taken 5 times.
|
5 | adopt(std::move(session)); |
| 143 | 5 | ++restored; | |
| 144 | 799 | } | |
| 145 | 794 | return restored; | |
| 146 | } | ||
| 147 | |||
| 148 | 2 | void ComposeSessionStore::mailLeft(const QString &accountId, qint64 folderId, qint64 uid) { | |
| 149 | 2 | auto *session = qobject_cast<ComposeSession *>(sessionForMail(accountId, folderId, uid)); | |
| 150 |
7/8✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 9 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 1 time.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 1 time.
|
2 | if (!session || session->place() != QLatin1String("inline")) return; |
| 151 |
1/1✓ Branch 19 → 20 taken 1 time.
|
2 | session->setPlace(QStringLiteral("window")); |
| 152 | 1 | emit changed(); | |
| 153 | } | ||
| 154 | |||
| 155 | 27 | void ComposeSessionStore::parkForOutbox(ComposeSession *session, qint64 outboxId) { | |
| 156 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 27 times.
|
27 | if (!session) return; |
| 157 |
1/1✓ Branch 5 → 6 taken 27 times.
|
27 | m_outboxSessions.insert(outboxId, session->sessionId()); |
| 158 |
1/1✓ Branch 11 → 12 taken 27 times.
|
54 | session->setPlace(QStringLiteral("outbox"), session->mailReference()); |
| 159 | 27 | emit changed(); | |
| 160 | } | ||
| 161 | |||
| 162 | 4 | ComposeSession *ComposeSessionStore::reopenFromOutbox(qint64 outboxId) { | |
| 163 |
1/1✓ Branch 2 → 3 taken 4 times.
|
4 | const QString id = m_outboxSessions.take(outboxId); |
| 164 |
1/1✓ Branch 3 → 4 taken 4 times.
|
4 | const int row = indexOf(id); |
| 165 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 4 times.
|
4 | if (row < 0) return nullptr; |
| 166 |
1/1✓ Branch 6 → 7 taken 4 times.
|
4 | ComposeSession *session = m_sessions.at(row).get(); |
| 167 |
1/1✓ Branch 8 → 9 taken 4 times.
|
4 | session->reopenAfterUndo(); |
| 168 |
5/12✓ Branch 11 → 12 taken 4 times.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 16 not taken.
✓ Branch 19 → 20 taken 4 times.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 4 times.
✓ Branch 23 → 24 taken 4 times.
✗ Branch 23 → 25 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
|
8 | session->setPlace(session->mailReference().isEmpty() ? QStringLiteral("tab") : QStringLiteral("inline"), |
| 169 | 8 | session->mailReference()); | |
| 170 |
1/1✓ Branch 27 → 28 taken 4 times.
|
4 | emit changed(); |
| 171 |
1/1✓ Branch 28 → 29 taken 4 times.
|
4 | emit sessionReopened(session); |
| 172 | 4 | return session; | |
| 173 | 4 | } | |
| 174 | |||
| 175 | 1 | bool ComposeSessionStore::discardFromOutbox(qint64 outboxId) { | |
| 176 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 3 → 4 taken 1 time.
|
1 | const int row = indexOf(m_outboxSessions.take(outboxId)); |
| 177 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1 time.
|
1 | if (row < 0) return false; |
| 178 | 1 | m_sessions.at(row)->discard(); // finished("discarded") removes it with its files | |
| 179 | 1 | return true; | |
| 180 | } | ||
| 181 | |||
| 182 | ✗ | void ComposeSessionStore::outboxFinished(qint64 outboxId) { | |
| 183 | ✗ | const QString id = m_outboxSessions.take(outboxId); | |
| 184 | ✗ | if (id.isEmpty()) return; | |
| 185 | ✗ | removeSession(id, true); | |
| 186 | ✗ | emit sessionClosed(id, QStringLiteral("sent")); | |
| 187 | ✗ | } | |
| 188 | |||
| 189 | 805 | bool ComposeSessionStore::saveAll() { | |
| 190 | 805 | bool ok = true; | |
| 191 |
2/2✓ Branch 29 → 4 taken 123 times.
✓ Branch 29 → 30 taken 805 times.
|
928 | for (const auto &session : m_sessions) { |
| 192 | 123 | const QString place = session->place(); | |
| 193 |
5/6✓ Branch 9 → 10 taken 101 times.
✓ Branch 9 → 13 taken 22 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 101 times.
✓ Branch 15 → 16 taken 22 times.
✓ Branch 15 → 17 taken 101 times.
|
123 | if (place == QLatin1String("outbox") || place == QLatin1String("discarded")) continue; |
| 194 |
3/3✓ Branch 18 → 19 taken 101 times.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 21 taken 100 times.
|
101 | if (!session->save()) ok = false; |
| 195 | 123 | } | |
| 196 | 805 | return ok; | |
| 197 | } | ||
| 198 | |||
| 199 | 222 | QString ComposeSessionStore::sessionIdAt(int row) const { | |
| 200 |
3/4✓ Branch 2 → 3 taken 222 times.
✗ Branch 2 → 8 not taken.
✓ Branch 4 → 5 taken 221 times.
✓ Branch 4 → 8 taken 1 time.
|
222 | return row >= 0 && row < int(m_sessions.size()) ? m_sessions.at(row)->sessionId() : QString(); |
| 201 | } | ||
| 202 | |||
| 203 | 3 | void ComposeSessionStore::discardWithUndo(const QString &sessionId, int undoMilliseconds) { | |
| 204 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3 times.
|
3 | if (indexOf(sessionId) < 0) return; |
| 205 | // One undo step: the older discard becomes final. That removes its | ||
| 206 | // session, so the row is looked up afterwards (the row taken before | ||
| 207 | // pointed past the end and threw std::out_of_range). | ||
| 208 |
5/6✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 10 taken 2 times.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 2 times.
|
3 | if (!m_discardedId.isEmpty() && m_discardedId != sessionId) finishDiscard(); |
| 209 | 3 | const int row = indexOf(sessionId); | |
| 210 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 3 times.
|
3 | if (row < 0) return; |
| 211 | 3 | ComposeSession *session = m_sessions.at(row).get(); | |
| 212 | 3 | m_discardedId = sessionId; | |
| 213 | 3 | m_discardedPlace = session->place(); | |
| 214 | 3 | m_discardedReference = session->mailReference(); | |
| 215 |
1/1✓ Branch 28 → 29 taken 3 times.
|
6 | session->setPlace(QStringLiteral("discarded"), m_discardedReference); |
| 216 | 3 | emit changed(); // sessionClosed("discarded") follows when the undo window ends | |
| 217 |
2/9✓ Branch 32 → 33 taken 3 times.
✗ Branch 36 → 37 not taken.
✗ Branch 37 → 38 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 45 → 34 not taken.
✓ Branch 45 → 46 taken 3 times.
|
3 | qCInfo(lcCompose) << "session" << sessionId << "discarded, undo for" << undoMilliseconds << "ms"; |
| 218 |
1/1✓ Branch 47 → 48 taken 3 times.
|
3 | QTimer::singleShot(undoMilliseconds, this, [this, sessionId] { |
| 219 |
1/2✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 5 not taken.
|
1 | if (m_discardedId == sessionId) finishDiscard(); |
| 220 | 1 | }); | |
| 221 | } | ||
| 222 | |||
| 223 | 2 | QObject *ComposeSessionStore::undoDiscard() { | |
| 224 | 2 | const int row = indexOf(m_discardedId); | |
| 225 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 1 time.
|
2 | if (row < 0) return nullptr; |
| 226 | 1 | ComposeSession *session = m_sessions.at(row).get(); | |
| 227 | 1 | session->setPlace(m_discardedPlace, m_discardedReference); | |
| 228 |
2/7✓ Branch 8 → 9 taken 1 time.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 19 → 10 not taken.
✓ Branch 19 → 20 taken 1 time.
|
1 | qCInfo(lcCompose) << "session" << m_discardedId << "discard undone"; |
| 229 | 1 | m_discardedId.clear(); | |
| 230 | 1 | emit changed(); | |
| 231 | 1 | emit sessionReopened(session); | |
| 232 | 1 | return session; | |
| 233 | } | ||
| 234 | |||
| 235 | 2 | void ComposeSessionStore::finishDiscard() { | |
| 236 | 2 | const int row = indexOf(m_discardedId); | |
| 237 | 2 | m_discardedId.clear(); | |
| 238 |
1/2✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 8 not taken.
|
2 | if (row >= 0) m_sessions.at(row)->discard(); // finished("discarded") removes it with its files |
| 239 | 2 | } | |
| 240 | |||
| 241 | 42 | void ComposeSessionStore::removeSession(const QString &sessionId, bool deleteDraft) { | |
| 242 |
1/1✓ Branch 2 → 3 taken 42 times.
|
42 | const int row = indexOf(sessionId); |
| 243 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 42 times.
|
42 | if (row < 0) return; |
| 244 |
1/1✓ Branch 6 → 7 taken 42 times.
|
42 | beginRemoveRows({}, row, row); |
| 245 |
1/1✓ Branch 7 → 8 taken 42 times.
|
42 | std::unique_ptr<ComposeSession> session = std::move(m_sessions.at(row)); |
| 246 |
1/1✓ Branch 13 → 14 taken 42 times.
|
42 | m_sessions.erase(m_sessions.begin() + row); |
| 247 |
1/1✓ Branch 14 → 15 taken 42 times.
|
42 | endRemoveRows(); |
| 248 |
2/2✓ Branch 15 → 16 taken 23 times.
✓ Branch 15 → 20 taken 19 times.
|
42 | if (deleteDraft) { |
| 249 |
1/1✓ Branch 18 → 19 taken 23 times.
|
23 | session->attachments().removeAll(); |
| 250 |
1/1✓ Branch 19 → 20 taken 23 times.
|
23 | ComposeDraftFiles::remove(m_deps.profileDirectory, sessionId); |
| 251 | } | ||
| 252 |
1/1✓ Branch 21 → 22 taken 42 times.
|
42 | session.release()->deleteLater(); |
| 253 |
1/1✓ Branch 22 → 23 taken 42 times.
|
42 | emit changed(); |
| 254 | 42 | } | |
| 255 |