MCPcopy Create free account
hub / github.com/KDE/kdeconnect-kde / copyAuthCodeIfPresent

Method copyAuthCodeIfPresent

plugins/notifications/notificationsplugin.cpp:188–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void 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
212QString NotificationsPlugin::newId()
213{

Callers

nothing calls this directly

Calls 1

setTextMethod · 0.45

Tested by

no test coverage detected