Bug 399174 - shared text gets opened with vim in an xterm
Summary: shared text gets opened with vim in an xterm
Status: RESOLVED FIXED
Alias: None
Product: kdeconnect
Classification: Applications
Component: common (show other bugs)
Version: unspecified
Platform: Debian unstable Linux
: NOR minor
Target Milestone: ---
Assignee: Albert Vaca Cintora
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-28 09:05 UTC by Marcel Partap
Modified: 2019-02-13 17:43 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel Partap 2018-09-28 09:05:04 UTC
Sending text selections from android to debian's kdeconnect-1.3.1-1 on an xfce desktop opens an xterm with vim.
I see that plugins/share/shareplugin.cpp invokes QDesktopServices::openUrl() on a temp file when kate is not available. How would I tell that to use another app?
Comment 1 Kai Uwe Broulik 2018-09-28 12:01:56 UTC
When plain text is sent (which isn't a file), it uses kate (to which you can pass data via stdin). When Kate isn't installed (which I assume is the case for your xfce setup) then it will download it into a temp filder.

The file will be something like /tmp/kdeconnectd.something, but lack a ".txt" suffix and as such there's no guarantee a "text editor" will open it since it tries to guess from the contents. This can probably be fixed by doing tmpFile.setFileTemplate(QStringLiteral("kdeconnect-XXXXXX.txt")); in the plugin
Comment 2 Nicolas Fella 2018-09-28 13:10:23 UTC
As Kai mentioned, when Kate isn't found then the default program associated with text/plain is opened (which probably is vim on your system). I've posted https://phabricator.kde.org/D15813 which 1) Uses the default editor even if Kate is available and 2) may improve the MIME type detection with a .txt extension
Comment 3 Marcel Partap 2018-09-28 14:17:51 UTC
Hey thanks for the swift reaction! Even without .txt extension, mime type seems to be correctly identified, but it might be a good idea nevertheless.
by ways of looking at `sh -xv /usr/bin/xdg-open sample.txt` I figured out it invokes exo-open on xfce, which does have a `exo-preferred-applications` settings dialog but that can only configure WebBrowser, MailReader, FileManager & TerminalEmulator.
So I found https://wiki.archlinux.org/index.php/XDG_MIME_Applications#mimeapps.list and from that, solved my issue by creating a `/etc/xdg/mimeapps.list` with

[Removed Associations]
text/plain=vim.desktop;diffuse.desktop;gvim.desktop;libreoffice-writer.desktop;okularApplication_txt.desktop

Text sent to kdeconnect now indeed does open with the appropriate mousepad xfce text editor.. which actually makes me `apt install kate` ; )
Comment 4 Nicolas Fella 2019-02-08 23:00:43 UTC
Git commit 47749792f32f4500a9efd3e3644309830723db2a by Nicolas Fella.
Committed on 08/02/2019 at 23:00.
Pushed by nicolasfella into branch 'master'.

Respect users prefered text editor for shared text

Summary:
A user may have Kate installed but another editor set as default for text/plain. Respect that.

Also add .txt extension to the temp file name to make mime-type detection easier.

Test Plan:
Set default text editor to Kate -> Text opens in Kate
Set default text editor to Atom -> Text opens in Atom

Reviewers: #kde_connect, broulik, apol

Reviewed By: #kde_connect, broulik, apol

Subscribers: kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D15813

M  +1    -1    CMakeLists.txt
M  +1    -0    plugins/share/CMakeLists.txt
M  +8    -2    plugins/share/shareplugin.cpp

https://invent.kde.org/kde/kdeconnect-kde/commit/47749792f32f4500a9efd3e3644309830723db2a
Comment 5 Nicolas Fella 2019-02-13 17:43:58 UTC
Git commit 62e2c4c1ea8d51b7c4da6d469677ebe6595c803f by Nicolas Fella.
Committed on 13/02/2019 at 17:43.
Pushed by nicolasfella into branch 'qmlsettings'.

Respect users prefered text editor for shared text

Summary:
A user may have Kate installed but another editor set as default for text/plain. Respect that.

Also add .txt extension to the temp file name to make mime-type detection easier.

Test Plan:
Set default text editor to Kate -> Text opens in Kate
Set default text editor to Atom -> Text opens in Atom

Reviewers: #kde_connect, broulik, apol

Reviewed By: #kde_connect, broulik, apol

Subscribers: kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D15813

M  +1    -1    CMakeLists.txt
M  +1    -0    plugins/share/CMakeLists.txt
M  +8    -2    plugins/share/shareplugin.cpp

https://invent.kde.org/kde/kdeconnect-kde/commit/62e2c4c1ea8d51b7c4da6d469677ebe6595c803f