Handle link sharing behavior of some apps properly

Some apps (Google News, some RSS readers, probably others), when
you share a link from them, they send it in the form of "title \n url".

Handle that case by opening the URL in a browser instead of the whole message in a text editor.
This commit is contained in:
Bharadwaj Raju 2022-07-28 02:21:49 +05:30
parent c658c8eefd
commit b5b188b830

View file

@ -145,6 +145,17 @@ bool SharePlugin::receivePacket(const NetworkPacket& np)
} else if (np.has(QStringLiteral("text"))) {
QString text = np.get<QString>(QStringLiteral("text"));
/* Handle apps which share links as 'Title\nurl' */
QStringList lines = text.split(QStringLiteral("\n"), Qt::SkipEmptyParts);
if (lines.count() == 2) {
QUrl url (lines[1]);
if (url.isValid() && !url.scheme().isEmpty()) {
QDesktopServices::openUrl(url);
Q_EMIT shareReceived(url.toString());
return true;
}
}
KService::Ptr service = KApplicationTrader::preferredService(QStringLiteral("text/plain"));
const QString defaultApp = service ? service->desktopEntryName() : QString();