diff --git a/CMakeLists.txt b/CMakeLists.txt index ac30d8b01..5f18715df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ if (SAILFISHOS) 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 index 794f22f4d..bb47e9878 100644 --- a/plugins/share/CMakeLists.txt +++ b/plugins/share/CMakeLists.txt @@ -10,6 +10,7 @@ target_link_libraries(kdeconnect_share KF5::Notifications KF5::I18n KF5::KIOWidgets + KF5::Service ) ####################################### diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 2e4fe3079..764980e4a 100644 --- 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 @@ bool SharePlugin::receivePacket(const NetworkPacket& np) } } 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());