| 186 | } |
| 187 | |
| 188 | void NotificationsPlugin::copyAuthCodeIfPresent(const QString &action) |
| 189 | { |
| 190 | // The auth code we receive has invisible characters in it for some reason. |
| 191 | // (U+2063 INVISIBLE SEPARATOR between each digit). |
| 192 | // Remove them if present before continuing. |
| 193 | QString sanitizedAction = action; |
| 194 | sanitizedAction.remove(QChar(0x2063)); |
| 195 | |
| 196 | // Match blocks of digits, 4-10 digits long. This should match auth codes |
| 197 | // in any language without relying on the action text having a specific |
| 198 | // keyword in it such as "Copy" in English. |
| 199 | QRegularExpression authCodeRegex(QStringLiteral("\\b(\\d{4,10})\\b")); |
| 200 | QRegularExpressionMatch match = authCodeRegex.match(sanitizedAction); |
| 201 | |
| 202 | if (!match.hasMatch()) { |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | QString text = match.captured(1); |
| 207 | auto mimeData = new QMimeData; |
| 208 | mimeData->setText(text); |
| 209 | KSystemClipboard::instance()->setMimeData(mimeData, QClipboard::Clipboard); |
| 210 | } |
| 211 | |
| 212 | QString NotificationsPlugin::newId() |
| 213 | { |