presentation/FolderIconCatalog.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "FolderIconCatalog.h" | ||
| 2 | |||
| 3 | #include <QFile> | ||
| 4 | #include <QLoggingCategory> | ||
| 5 | #include <QTextStream> | ||
| 6 | |||
| 7 |
4/7✓ Branch 2 → 3 taken 21 times.
✓ Branch 2 → 8 taken 750 times.
✓ Branch 4 → 5 taken 21 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 21 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
771 | Q_LOGGING_CATEGORY(lcFolderIcons, "mailjd.foldericons") |
| 8 | |||
| 9 | 2383 | bool FolderIconCatalog::load(const QString &csvPath) { | |
| 10 |
2/2✓ Branch 3 → 4 taken 1617 times.
✓ Branch 3 → 5 taken 766 times.
|
2383 | if (loaded()) return true; |
| 11 |
1/1✓ Branch 5 → 6 taken 766 times.
|
766 | QFile file(csvPath); |
| 12 |
2/3✓ Branch 7 → 8 taken 766 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 24 taken 766 times.
|
766 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 13 | ✗ | qCWarning(lcFolderIcons) << "Icon codemap unavailable:" << csvPath << file.errorString(); | |
| 14 | ✗ | return false; | |
| 15 | } | ||
| 16 |
1/1✓ Branch 24 → 25 taken 766 times.
|
766 | QTextStream stream(&file); |
| 17 |
1/1✓ Branch 25 → 26 taken 766 times.
|
766 | stream.readLine(); // header: name,codepoint |
| 18 |
3/3✓ Branch 54 → 55 taken 5705934 times.
✓ Branch 55 → 28 taken 5705168 times.
✓ Branch 55 → 56 taken 766 times.
|
5705934 | while (!stream.atEnd()) { |
| 19 |
2/2✓ Branch 28 → 29 taken 5705168 times.
✓ Branch 29 → 30 taken 5705168 times.
|
5705168 | const QString line = stream.readLine().trimmed(); |
| 20 | 5705168 | const int comma = line.indexOf(QLatin1Char(',')); | |
| 21 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 5705168 times.
|
5705168 | if (comma <= 0) continue; |
| 22 | 5705168 | bool ok = false; | |
| 23 |
2/2✓ Branch 36 → 37 taken 5705168 times.
✓ Branch 37 → 38 taken 5705168 times.
|
5705168 | const int codePoint = line.mid(comma + 1).toInt(&ok, 16); |
| 24 |
2/4✓ Branch 39 → 40 taken 5705168 times.
✗ Branch 39 → 41 not taken.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 5705168 times.
|
5705168 | if (!ok || codePoint <= 0) continue; |
| 25 |
1/1✓ Branch 42 → 43 taken 5705168 times.
|
5705168 | const QString name = line.left(comma); |
| 26 | 5705168 | m_entries.append({name, codePoint}); | |
| 27 |
1/1✓ Branch 46 → 47 taken 5705168 times.
|
5705168 | m_codePoints.insert(name, codePoint); |
| 28 | 5705168 | } | |
| 29 |
7/7✓ Branch 56 → 57 taken 766 times.
✓ Branch 60 → 61 taken 766 times.
✓ Branch 61 → 62 taken 766 times.
✓ Branch 63 → 64 taken 766 times.
✓ Branch 64 → 65 taken 766 times.
✓ Branch 68 → 58 taken 766 times.
✓ Branch 68 → 69 taken 766 times.
|
1532 | qCInfo(lcFolderIcons) << "Icon codemap loaded:" << m_entries.size() << "icons"; |
| 30 | 766 | return loaded(); | |
| 31 | 5705934 | } | |
| 32 | |||
| 33 | 2350 | QString FolderIconCatalog::defaultIconName(const FolderInfo &folder) { | |
| 34 |
2/2✓ Branch 8 → 9 taken 624 times.
✓ Branch 8 → 14 taken 1726 times.
|
2974 | if (folder.path == QStringLiteral("INBOX")) return QStringLiteral("inbox"); |
| 35 |
3/3✓ Branch 14 → 15 taken 1726 times.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 21 taken 1721 times.
|
1731 | if (folder.isSent()) return QStringLiteral("send"); |
| 36 |
3/3✓ Branch 21 → 22 taken 1721 times.
✓ Branch 22 → 23 taken 4 times.
✓ Branch 22 → 28 taken 1717 times.
|
1725 | if (folder.isDrafts()) return QStringLiteral("file-edit-outline"); |
| 37 |
3/3✓ Branch 28 → 29 taken 1717 times.
✓ Branch 29 → 30 taken 17 times.
✓ Branch 29 → 35 taken 1700 times.
|
1734 | if (folder.isTrash()) return QStringLiteral("trash-can-outline"); |
| 38 |
3/3✓ Branch 35 → 36 taken 1700 times.
✓ Branch 36 → 37 taken 4 times.
✓ Branch 36 → 42 taken 1696 times.
|
1704 | if (folder.isArchive()) return QStringLiteral("archive-outline"); |
| 39 |
3/3✓ Branch 42 → 43 taken 1696 times.
✓ Branch 43 → 44 taken 17 times.
✓ Branch 43 → 49 taken 1679 times.
|
1713 | if (folder.isJunk()) return QStringLiteral("alert-octagon-outline"); |
| 40 | // Leaf-name heuristics carried over from the Widgets folder tree (T-125). | ||
| 41 | static const QHash<QString, QString> byName = { | ||
| 42 | {"notifications", "bell-outline"}, {"benachrichtigungen", "bell-outline"}, | ||
| 43 | {"newsletter", "newspaper-variant-outline"}, {"newsletters", "newspaper-variant-outline"}, | ||
| 44 | {"work", "briefcase-outline"}, {"arbeit", "briefcase-outline"}, | ||
| 45 | {"important", "star-outline"}, {"wichtig", "star-outline"}, | ||
| 46 | {"lists", "format-list-bulleted"}, {"mailinglisten", "format-list-bulleted"}, | ||
| 47 | {"mailing-listen", "format-list-bulleted"}, | ||
| 48 | {"receipts", "receipt-text-outline"}, {"rechnungen", "receipt-text-outline"}, | ||
| 49 | {"invoices", "receipt-text-outline"}, | ||
| 50 | {"travel", "airplane"}, {"reisen", "airplane"}, | ||
| 51 | {"server", "server"}, {"monitoring", "monitor-eye"}, | ||
| 52 | {"backup", "cloud-upload-outline"}, {"git", "source-branch"}, | ||
| 53 | {"pipelines", "pipe"}, {"geld", "currency-eur"}, | ||
| 54 | {"money", "currency-eur"}, {"steuern", "calculator"}, | ||
| 55 | {"bitcoin", "bitcoin"}, {"versicherungen", "shield-check-outline"}, | ||
| 56 | {"privat", "account-outline"}, {"personal", "account-outline"}, | ||
| 57 | {"bestellungen", "cart-outline"}, {"orders", "cart-outline"}, | ||
| 58 | {"uni", "school-outline"}, {"university", "school-outline"}, | ||
| 59 | {"schule", "school-outline"}, {"games", "gamepad-variant-outline"}, | ||
| 60 | {"tracking", "map-marker-path"}, {"startups", "rocket-launch-outline"}, | ||
| 61 | {"onlinekurse", "book-open-page-variant-outline"}, | ||
| 62 | {"spam", "alert-octagon-outline"}, {"spam2", "alert-octagon-outline"}, | ||
| 63 | {"junk", "alert-octagon-outline"}, {"sent", "send"}, | ||
| 64 | {"gesendet", "send"}, {"drafts", "file-edit-outline"}, | ||
| 65 | {"entw\u00fcrfe", "file-edit-outline"}, {"trash", "trash-can-outline"}, | ||
| 66 | {"papierkorb", "trash-can-outline"}, {"archive", "archive-outline"}, | ||
| 67 | {"archiv", "archive-outline"}, | ||
| 68 |
5/10✓ Branch 49 → 50 taken 11 times.
✓ Branch 49 → 107 taken 1668 times.
✓ Branch 51 → 52 taken 11 times.
✗ Branch 51 → 107 not taken.
✓ Branch 104 → 105 taken 528 times.
✓ Branch 104 → 106 taken 11 times.
✗ Branch 124 → 125 not taken.
✗ Branch 124 → 126 not taken.
✗ Branch 133 → 134 not taken.
✗ Branch 133 → 135 not taken.
|
2218 | }; |
| 69 |
2/2✓ Branch 108 → 109 taken 1256 times.
✓ Branch 108 → 110 taken 423 times.
|
1679 | const QString leaf = folder.delimiter.isEmpty() ? folder.path |
| 70 |
1/1✓ Branch 111 → 112 taken 423 times.
|
1679 | : folder.path.section(folder.delimiter, -1); |
| 71 |
1/1✓ Branch 115 → 116 taken 1679 times.
|
1679 | return byName.value(leaf.toLower(), QStringLiteral("folder-outline")); |
| 72 | 1690 | } | |
| 73 | |||
| 74 | 766 | FolderIconListModel::FolderIconListModel(const FolderIconCatalog *catalog, QObject *parent) | |
| 75 | 766 | : QAbstractListModel(parent), m_catalog(catalog) { | |
| 76 |
1/1✓ Branch 5 → 6 taken 766 times.
|
766 | rebuild(); |
| 77 | 766 | } | |
| 78 | |||
| 79 | 79807 | int FolderIconListModel::rowCount(const QModelIndex &parent) const { | |
| 80 |
2/2✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 5 taken 79803 times.
|
79807 | return parent.isValid() ? 0 : m_rows.size(); |
| 81 | } | ||
| 82 | |||
| 83 | 2263 | QVariant FolderIconListModel::data(const QModelIndex &index, int role) const { | |
| 84 |
3/6✓ Branch 3 → 4 taken 2263 times.
✗ Branch 3 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 2263 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 2263 times.
|
2263 | if (!index.isValid() || index.row() >= m_rows.size()) return {}; |
| 85 | 2263 | const auto &entry = m_catalog->entries().at(m_rows.at(index.row())); | |
| 86 |
4/4✓ Branch 15 → 16 taken 1145 times.
✓ Branch 15 → 17 taken 1118 times.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 1143 times.
|
2263 | if (role == NameRole || role == Qt::DisplayRole) return entry.name; |
| 87 |
2/2✓ Branch 18 → 19 taken 1119 times.
✓ Branch 18 → 20 taken 24 times.
|
1143 | if (role == GlyphRole) return entry.codePoint; |
| 88 | 24 | return {}; | |
| 89 | } | ||
| 90 | |||
| 91 | 767 | QHash<int, QByteArray> FolderIconListModel::roleNames() const { | |
| 92 |
2/4✓ Branch 6 → 7 taken 1534 times.
✓ Branch 6 → 8 taken 767 times.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
|
2301 | return {{NameRole, "iconName"}, {GlyphRole, "glyph"}}; |
| 93 | 767 | } | |
| 94 | |||
| 95 | 2 | void FolderIconListModel::setFilter(const QString &filter) { | |
| 96 |
1/1✓ Branch 2 → 3 taken 2 times.
|
2 | const QString trimmed = filter.trimmed(); |
| 97 |
2/2✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 1 time.
|
2 | if (trimmed == m_filter) return; |
| 98 | 1 | m_filter = trimmed; | |
| 99 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | rebuild(); |
| 100 |
1/1✓ Branch 8 → 9 taken 1 time.
|
1 | emit filterChanged(); |
| 101 | 2 | } | |
| 102 | |||
| 103 | 2 | int FolderIconListModel::rowOf(const QString &name) const { | |
| 104 |
2/2✓ Branch 11 → 3 taken 2 times.
✓ Branch 11 → 12 taken 1 time.
|
3 | for (int row = 0; row < m_rows.size(); ++row) |
| 105 |
2/2✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 1 time.
|
2 | if (m_catalog->entries().at(m_rows.at(row)).name == name) return row; |
| 106 | 1 | return -1; | |
| 107 | } | ||
| 108 | |||
| 109 | 767 | void FolderIconListModel::rebuild() { | |
| 110 | 767 | beginResetModel(); | |
| 111 | 767 | m_rows.clear(); | |
| 112 |
1/2✓ Branch 4 → 5 taken 767 times.
✗ Branch 4 → 19 not taken.
|
767 | if (m_catalog) { |
| 113 | 767 | const auto &entries = m_catalog->entries(); | |
| 114 |
2/2✓ Branch 18 → 7 taken 5712616 times.
✓ Branch 18 → 19 taken 767 times.
|
5713383 | for (int i = 0; i < entries.size(); ++i) |
| 115 |
6/6✓ Branch 8 → 9 taken 7448 times.
✓ Branch 8 → 12 taken 5705168 times.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 7447 times.
✓ Branch 14 → 15 taken 5705169 times.
✓ Branch 14 → 16 taken 7447 times.
|
5712616 | if (m_filter.isEmpty() || entries.at(i).name.contains(m_filter, Qt::CaseInsensitive)) |
| 116 | 5705169 | m_rows.append(i); | |
| 117 | } | ||
| 118 | 767 | endResetModel(); | |
| 119 | 767 | } | |
| 120 |