Difference between revisions of "Development/Tutorials/Desktop File"

(Mark for updating)
(Replaced content with "This tutorial was updated and moved to https://develop.kde.org/docs/desktop-file/ Category:MovedDevelop")
Tag: Replaced
 
Line 1: Line 1:
 +
This tutorial was updated and moved to https://develop.kde.org/docs/desktop-file/
  
 
+
[[Category:MovedDevelop]]
{{TutorialBrowser|
 
 
 
series=Basics|
 
 
 
name=Desktop File|
 
 
 
pre=|
 
 
 
next=|
 
 
 
reading=[http://standards.freedesktop.org/desktop-entry-spec/latest/ the .desktop Free Desktop Spec];
 
}}
 
 
 
{{Review|Port to KF5}}
 
 
 
== Desktop File ==
 
 
 
In order for your application to show up in menus and/or to be automatically associated with mime types in file browsers, you need to provide a .desktop file like follows:
 
 
 
<syntaxhighlight lang="ini">
 
[Desktop Entry]
 
Type=Application
 
Exec=your-app %u
 
MimeType=application/x-your-mime-type;
 
Icon=some-icon
 
X-DocPath=yourapp/index.html
 
Terminal=false
 
Name=Your App
 
GenericName=Some Generic Name
 
Comment=Short Description Of Your App
 
Categories=Qt;KDE;
 
</syntaxhighlight>
 
 
 
Take a look at [http://standards.freedesktop.org/desktop-entry-spec/latest/ the .desktop Free Desktop Spec] to find our more about the key/value pairs above. It's important to pick a good set of Categories, see the spec for a list of valid values.
 
 
 
== Your project ==
 
You want your project to show up in the K Menu like this:
 
 
 
[[File:Snapshot-k-menu.png]]
 
 
 
In this example, the application is called quickpen and it shows up in the category "Graphics". To accomplish that in your project you need to take care the .desktop file is distributed to the appropriate place.
 
 
 
=== qmake based projects ===
 
In case you are working on a qmake based project, add the following to your .pro file:
 
'''target.path = /usr/local/bin'''
 
desktop.path = /usr/share/applications
 
desktop.files += your-app.desktop
 
 
 
'''INSTALLS += target''' desktop
 
 
 
Note that the bold strings above should be in your project anyway.
 
 
 
An example .pro file can be found [https://github.com/tstaerk/quickpen/blob/dc7a5560b0cbac159d1c443572c676ee7d8fbb23/quickpen.pro here]. The related .desktop file can be found [https://github.com/tstaerk/quickpen/blob/e3b03c5949085e87a659303ae7866378f6539542/quickpen.desktop here].
 
 
 
=== cmake based projects ===
 
In case you are working on a cmake based project, add an install directive to your CMakeLists.txt file like this:
 
install( PROGRAMS your-app.desktop DESTINATION ${[[Development/CMake/Addons_for_KDE#The_locations_of_install_directories|XDG_APPS_INSTALL_DIR]]} )
 
 
 
An example CMakeLists.txt file can be found [http://quickgit.kde.org/?p=kdepim.git&a=blob&hb=18742d763bc8a2d2c2c7ef433cc66c39b6a95036&f=ktimetracker/support/CMakeLists.txt here]. The corresponding .desktop file is [http://quickgit.kde.org/?p=kdepim.git&a=blob&hb=63798b547ecb595d166cdbe2e0a04d985fcc8980&f=ktimetracker/support/ktimetracker.desktop here].
 
 
 
= Menus =
 
You can also use a .desktop file to describe KDE's context menus. Context menus are the menus that appear when you right-click onto your desktop or onto a file or folder. Let's write a context menu for konqueror that counts the lines in a file.
 
 
 
To do this, change directory to your Service Menu directory:
 
$ kde4-config --path services
 
/home/knoppix/.kde/share/kde4/services/:/usr/share/kde4/services/
 
$ cd /usr/share/kde4/services/ServiceMenus/
 
 
 
Create a desktop file with any name, e.g. count.desktop with the following content:
 
 
 
[Desktop Entry]
 
Type=Service
 
ServiceTypes=KonqPopupMenu/Plugin
 
MimeType=all/all;
 
Actions=countlines;
 
X-KDE-Submenu=Count
 
X-KDE-StartupNotify=false
 
X-KDE-Priority=TopLevel
 
 
[Desktop Action countlines]
 
Name=Count lines
 
Exec=kdialog --msgbox "$(wc -l %F)"
 
 
 
It will look like this:
 
 
 
[[File:Snapshot-file-context-menu-kde-2.png]]
 
 
 
Some remarks:
 
* it is possible to translate the strings the user sees. For a German translation you could add below X-KDE-Submenu=Count:
 
X-KDE-Submenu[de]=Zaehlen
 
* this context menu entry will not only appear in Konqueror, but also e.g. in Dolphin.
 
* if you want this to work as a menu item, not as a submenu, just delete the line
 
X-KDE-Submenu=Count
 
 
 
= See also =
 
* [http://standards.freedesktop.org/desktop-entry-spec/latest/ FreeDeskTop's specification about Desktop entries]
 
 
 
[[Category:Programming]]
 
[[Category:Tutorial]]
 
[[Category:FAQs]]
 

Latest revision as of 09:35, 4 October 2020

This tutorial was updated and moved to https://develop.kde.org/docs/desktop-file/


This page was last edited on 4 October 2020, at 09:35. Content is available under Creative Commons License SA 4.0 unless otherwise noted.