| 32 | ClientNetworkReplyModel::~ClientNetworkReplyModel() = default; |
| 33 | |
| 34 | QVariant ClientNetworkReplyModel::data(const QModelIndex &index, int role) const |
| 35 | { |
| 36 | if (role == Qt::DisplayRole && index.column() == NetworkReplyModelColumn::OpColumn) { |
| 37 | const auto op = QIdentityProxyModel::data(index, role).toInt(); |
| 38 | switch (op) { |
| 39 | case QNetworkAccessManager::HeadOperation: |
| 40 | return QStringLiteral("HEAD"); |
| 41 | case QNetworkAccessManager::GetOperation: |
| 42 | return QStringLiteral("GET"); |
| 43 | case QNetworkAccessManager::PutOperation: |
| 44 | return QStringLiteral("PUT"); |
| 45 | case QNetworkAccessManager::PostOperation: |
| 46 | return QStringLiteral("POST"); |
| 47 | case QNetworkAccessManager::DeleteOperation: |
| 48 | return QStringLiteral("DELETE"); |
| 49 | case QNetworkAccessManager::CustomOperation: |
| 50 | return tr("Custom"); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (role == Qt::ForegroundRole) { |
| 55 | const auto state = QIdentityProxyModel::data(index.sibling(index.row(), NetworkReplyModelColumn::ObjectColumn), NetworkReplyModelRole::ReplyStateRole).toInt(); |
| 56 | if (state & NetworkReply::Deleted) { |
| 57 | return QGuiApplication::palette().color(QPalette::Disabled, QPalette::Text); |
| 58 | } |
| 59 | if (state & NetworkReply::Error) { |
| 60 | return QColor(Qt::red); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (role == Qt::DecorationRole && index.parent().isValid()) { |
| 65 | const auto state = QIdentityProxyModel::data(index.sibling(index.row(), NetworkReplyModelColumn::ObjectColumn), NetworkReplyModelRole::ReplyStateRole).toInt(); |
| 66 | switch (index.column()) { |
| 67 | case NetworkReplyModelColumn::ObjectColumn: |
| 68 | if (state & NetworkReply::Error) { |
| 69 | return QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton); |
| 70 | } else if (state & NetworkReply::Finished) { |
| 71 | return QApplication::style()->standardIcon(QStyle::SP_DialogOkButton); |
| 72 | } |
| 73 | return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); |
| 74 | case NetworkReplyModelColumn::UrlColumn: { |
| 75 | const auto url = QIdentityProxyModel::data(index, Qt::DisplayRole).toString(); |
| 76 | if ((state & NetworkReply::Encrypted) || ((state & NetworkReply::Unencrypted) == 0 && url.startsWith(QLatin1String("https")))) { |
| 77 | return UIResources::themedIcon(QLatin1String("lock.png")); |
| 78 | } |
| 79 | return UIResources::themedIcon(QLatin1String("lock-open.png")); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (role == Qt::ToolTipRole) { |
| 85 | if (index.column() == NetworkReplyModelColumn::UrlColumn) { |
| 86 | return index.data(Qt::DisplayRole); |
| 87 | } |
| 88 | |
| 89 | const auto errMsgs = QIdentityProxyModel::data(index.sibling(index.row(), NetworkReplyModelColumn::ObjectColumn), NetworkReplyModelRole::ReplyErrorRole).toStringList(); |
| 90 | if (errMsgs.isEmpty()) { |
| 91 | return {}; |