diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ else() set(KF5_MIN_VERSION "5.42.0") set(QT_MIN_VERSION "5.7.0") - set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils) + set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service) set(KF5_OPTIONAL_COMPONENTS DocTools) if(UNIX) set(KF5_OPTIONAL_COMPONENTS ${KF5_OPTIONAL_COMPONENTS} PulseAudioQt Runner) diff --git a/plugins/share/CMakeLists.txt b/plugins/share/CMakeLists.txt --- a/plugins/share/CMakeLists.txt +++ b/plugins/share/CMakeLists.txt @@ -10,6 +10,7 @@ KF5::Notifications KF5::I18n KF5::KIOWidgets + KF5::Service ) ####################################### diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "core/filetransferjob.h" @@ -121,14 +122,19 @@ } } else if (np.has(QStringLiteral("text"))) { QString text = np.get(QStringLiteral("text")); - if (!QStandardPaths::findExecutable(QStringLiteral("kate")).isEmpty()) { + + KService::Ptr service = KMimeTypeTrader::self()->preferredService(QStringLiteral("text/plain")); + const QString defaultApp = service ? service->desktopEntryName() : QString(); + + if (defaultApp == QLatin1String("org.kde.kate") || defaultApp == QLatin1String("org.kde.kwrite")) { QProcess* proc = new QProcess(); connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); - proc->start(QStringLiteral("kate"), QStringList(QStringLiteral("--stdin"))); + proc->start(defaultApp.section('.', 2,2), QStringList(QStringLiteral("--stdin"))); proc->write(text.toUtf8()); proc->closeWriteChannel(); } else { QTemporaryFile tmpFile; + tmpFile.setFileTemplate(QStringLiteral("kdeconnect-XXXXXX.txt")); tmpFile.setAutoRemove(false); tmpFile.open(); tmpFile.write(text.toUtf8());