From b5b188b830aed08c98d9cf76b7e4dc1a22c064f1 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Thu, 28 Jul 2022 02:21:49 +0530 Subject: [PATCH] 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. --- plugins/share/shareplugin.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 8495cc93a..bf14f69b0 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -145,6 +145,17 @@ bool SharePlugin::receivePacket(const NetworkPacket& np) } else if (np.has(QStringLiteral("text"))) { QString text = np.get(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();