| 84 | } |
| 85 | |
| 86 | QVariant SyncthingRecentChangesModel::data(const QModelIndex &index, int role) const |
| 87 | { |
| 88 | if (!index.isValid() || index.parent().isValid() || static_cast<size_t>(index.row()) >= m_changes.size()) { |
| 89 | return QVariant(); |
| 90 | } |
| 91 | |
| 92 | const SyncthingRecentChange &change = m_changes[static_cast<size_t>(index.row())]; |
| 93 | switch (role) { |
| 94 | case Qt::DisplayRole: |
| 95 | case Qt::EditRole: |
| 96 | switch (index.column()) { |
| 97 | case 0: |
| 98 | return change.fileChange.action; |
| 99 | case 1: |
| 100 | return change.deviceName.isEmpty() ? change.fileChange.modifiedBy : change.deviceName; |
| 101 | case 2: |
| 102 | return change.directoryName.isEmpty() ? change.directoryId : change.directoryName; |
| 103 | case 3: |
| 104 | return change.fileChange.path; |
| 105 | } |
| 106 | break; |
| 107 | case Qt::DecorationRole: |
| 108 | case ActionIcon: |
| 109 | switch (index.column()) { |
| 110 | case 0: |
| 111 | return change.fileChange.local ? commonForkAwesomeIcons().home : commonForkAwesomeIcons().globe; |
| 112 | } |
| 113 | break; |
| 114 | case Qt::ToolTipRole: |
| 115 | switch (index.column()) { |
| 116 | case 0: |
| 117 | return QString((change.fileChange.local ? tr("Locally") : tr("Remotely")) % QChar(' ') % change.fileChange.action % QStringLiteral(", ") |
| 118 | % QString::fromStdString(change.fileChange.eventTime.toString(DateTimeOutputFormat::DateAndTime, true))); |
| 119 | case 1: |
| 120 | return change.deviceId.isEmpty() ? change.fileChange.modifiedBy : change.deviceId; |
| 121 | case 2: |
| 122 | return change.directoryId; |
| 123 | case 3: |
| 124 | return change.fileChange.path; // usually too long so add a tooltip |
| 125 | } |
| 126 | break; |
| 127 | case Action: |
| 128 | return change.fileChange.action; |
| 129 | case ModifiedBy: |
| 130 | return change.deviceName.isEmpty() ? change.fileChange.modifiedBy : change.deviceName; |
| 131 | case DirectoryId: |
| 132 | return change.directoryId; |
| 133 | case DirectoryName: |
| 134 | return change.directoryName; |
| 135 | case Path: |
| 136 | return change.fileChange.path; |
| 137 | case EventTime: |
| 138 | return QString::fromStdString(change.fileChange.eventTime.toString(DateTimeOutputFormat::DateAndTime, true)); |
| 139 | case ExtendedAction: { |
| 140 | auto extendedAction = change.fileChange.action; |
| 141 | extendedAction[0] = extendedAction[0].toUpper(); |
| 142 | return QVariant(std::move(extendedAction)); |
| 143 | } |