DesktopFile

Represents .desktop file.

Constructors

this
this(string fileName, ReadOptions options)

Reads desktop file from file.

this
this(Range byLine, ReadOptions options, string fileName)

Reads desktop file from range of IniLikeLines.

this
this()

Constructs DesktopFile with "Desktop Entry" group and Version set to 1.0

Alias This

desktopEntry

This alias allows to call functions related to "Desktop Entry" group without need to call desktopEntry explicitly.

Members

Aliases

ReadOptions
alias ReadOptions = IniLikeFile.ReadOptions
Undocumented in source.

Enums

Type
enum Type

Desktop entry type

Functions

action
const(DesktopAction) action(string actionName)

Get additional application action by name.

actions
auto actions()

Actions supported by application.

actions
void actions(Range values)

Sets the list of values for "Actions" list.

addGroup
IniLikeGroup addGroup(string groupName)
Undocumented in source. Be warned that the author may not have intended to support it.
byAction
auto byAction()

Iterating over existing actions.

categories
auto categories()

Categories this program belongs to.

categories
void categories(Range values)

Sets the list of values for the "Categories" list.

comment
string comment()

Tooltip for the entry, for example "View sites on the Internet".

dbusActivable
bool dbusActivable()

A boolean value specifying if D-Bus activation is supported for this application.

desktopEntry
inout(IniLikeGroup) desktopEntry()
execString
string execString()
expandExecString
string[] expandExecString(string[] urls, string locale)

Expand "Exec" value into the array of command line arguments to use to start the program. It applies unquoting and unescaping.

genericName
string genericName()

Generic name of the application, for example "Web Browser".

hidden
bool hidden()

Hidden means the user deleted (at his level) something that was present (at an upper level, e.g. in the system dirs). It's strictly equivalent to the .desktop file not existing at all, as far as that user is concerned.

iconName
string iconName()

Icon to display in file manager, menus, etc.

id
string id()

See Desktop File ID

id
string id(Range appPaths)

See Desktop File ID

keywords
auto keywords()

A list of strings which may be used in addition to other metadata to describe this entry.

keywords
void keywords(Range values)

Sets the list of values for the "Keywords" list.

localizedComment
string localizedComment(string locale)
localizedGenericName
string localizedGenericName(string locale)
localizedIconName
string localizedIconName(string locale)
localizedName
string localizedName(string locale)
mimeTypes
auto mimeTypes()

The MIME type(s) supported by this application.

mimeTypes
void mimeTypes(Range values)

Sets the list of values for the "MimeType" list.

name
string name()

Specific name of the application, for example "Mozilla".

noDisplay
bool noDisplay()

NoDisplay means "this application exists, but don't display it in the menus".

notShowIn
auto notShowIn()

A list of strings identifying the desktop environments that should not display a given desktop entry.

onlyShowIn
auto onlyShowIn()

A list of strings identifying the desktop environments that should display a given desktop entry.

removeGroup
void removeGroup(string groupName)

Removes group by name. You can't remove "Desktop Entry" group with this function.

start
Pid start()

Starts application or open link depending on desktop entry type.

startApplication
Pid startApplication(string url, string locale, const(string)[] terminalCommand)

ditto, but uses the only url.

startApplication
Pid startApplication(string[] urls, string locale, const(string)[] terminalCommand)

Starts the application associated with this .desktop file using urls as command line params. If the program should be run in terminal it tries to find system defined terminal emulator to run in.

startLink
Pid startLink()

Opens url defined in .desktop file using xdg-open. Note: This function does not check if the type of desktop file is Link. It relies only on "URL" value.

startupNotify
bool startupNotify()
terminal
bool terminal()

Whether the program runs in a terminal window.

terminal
bool terminal(bool t)

Sets "Terminal" field to true or false.

tryExecString
string tryExecString()

Value used to determine if the program is actually installed. If the path is not an absolute path, the file should be looked up in the PATH environment variable. If the file is not present or if it is not executable, the entry may be ignored (not be used in menus, for example).

type
Type type()

Type of desktop entry.

type
Type type(Type t)

Sets "Type" field to type Note: Setting the Unknown type removes type field.

url
string url()

URL to access.

workingDirectory
string workingDirectory()

The working directory to run the program in.

Static functions

joinValues
string joinValues(Range values)

Join range of multiple values into a string using semicolon as separator. Adds trailing semicolon.

splitValues
auto splitValues(string values)

Some keys can have multiple values, separated by semicolon. This function helps to parse such kind of strings into the range.

Examples

1     import std.file;
2     //Test DesktopFile
3     string desktopFileContents = 
4 `[Desktop Entry]
5 # Comment
6 Name=Double Commander
7 Name[ru]=Двухпанельный коммандер
8 GenericName=File manager
9 GenericName[ru]=Файловый менеджер
10 Comment=Double Commander is a cross platform open source file manager with two panels side by side.
11 Comment[ru]=Double Commander - кроссплатформенный файловый менеджер.
12 Terminal=false
13 Icon=doublecmd
14 Icon[ru]=doublecmd_ru
15 Exec=doublecmd %f
16 TryExec=doublecmd
17 Type=Application
18 Categories=Application;Utility;FileManager;
19 Keywords=folder;manager;disk;filesystem;operations;
20 Actions=OpenDirectory;NotPresented;Settings;NoName;
21 MimeType=inode/directory;application/x-directory;
22 NoDisplay=false
23 Hidden=false
24 StartupNotify=true
25 DBusActivatable=true
26 Path=/opt/doublecmd
27 OnlyShowIn=GNOME;XFCE;LXDE;
28 NotShowIn=KDE;
29 
30 [Desktop Action OpenDirectory]
31 Name=Open directory
32 Name[ru]=Открыть папку
33 Icon=open
34 Exec=doublecmd %u
35 
36 [NoName]
37 Icon=folder
38 
39 [Desktop Action Settings]
40 Name=Settings
41 Name[ru]=Настройки
42 Icon=edit
43 Exec=doublecmd settings
44 
45 [Desktop Action Notspecified]
46 Name=Notspecified Action`;
47     
48     auto df = new DesktopFile(iniLikeStringReader(desktopFileContents), DesktopFile.ReadOptions.preserveComments);
49     assert(df.name() == "Double Commander");
50     assert(df.localizedName("ru_RU") == "Двухпанельный коммандер");
51     assert(df.genericName() == "File manager");
52     assert(df.localizedGenericName("ru_RU") == "Файловый менеджер");
53     assert(df.comment() == "Double Commander is a cross platform open source file manager with two panels side by side.");
54     assert(df.localizedComment("ru_RU") == "Double Commander - кроссплатформенный файловый менеджер.");
55     assert(df.iconName() == "doublecmd");
56     assert(df.localizedIconName("ru_RU") == "doublecmd_ru");
57     assert(df.tryExecString() == "doublecmd");
58     assert(!df.terminal());
59     assert(!df.noDisplay());
60     assert(!df.hidden());
61     assert(df.startupNotify());
62     assert(df.dbusActivable());
63     assert(df.workingDirectory() == "/opt/doublecmd");
64     assert(df.type() == DesktopFile.Type.Application);
65     assert(equal(df.keywords(), ["folder", "manager", "disk", "filesystem", "operations"]));
66     assert(equal(df.categories(), ["Application", "Utility", "FileManager"]));
67     assert(equal(df.actions(), ["OpenDirectory", "NotPresented", "Settings", "NoName"]));
68     assert(equal(df.mimeTypes(), ["inode/directory", "application/x-directory"]));
69     assert(equal(df.onlyShowIn(), ["GNOME", "XFCE", "LXDE"]));
70     assert(equal(df.notShowIn(), ["KDE"]));
71     
72     assert(equal(df.byAction().map!(desktopAction => 
73     tuple(desktopAction.name(), desktopAction.localizedName("ru"), desktopAction.iconName(), desktopAction.execString())), 
74                  [tuple("Open directory", "Открыть папку", "open", "doublecmd %u"), tuple("Settings", "Настройки", "edit", "doublecmd settings")]));
75     
76     assert(df.action("NotPresented").group() is null);
77     assert(df.action("Notspecified").group() is null);
78     assert(df.action("NoName").group() is null);
79     assert(df.action("Settings").group() !is null);
80     
81     assert(df.saveToString() == desktopFileContents);
82     
83     assert(df.contains("Icon"));
84     df.removeEntry("Icon");
85     assert(!df.contains("Icon"));
86     df["Icon"] = "files";
87     assert(df.contains("Icon"));
88     
89     df = new DesktopFile();
90     df.terminal = true;
91     df.type = DesktopFile.Type.Application;
92     df.categories = ["Development", "Compilers"];
93     
94     assert(df.terminal() == true);
95     assert(df.type() == DesktopFile.Type.Application);
96     assert(equal(df.categories(), ["Development", "Compilers"]));
97     
98     string contents = 
99 `[Not desktop entry]
100 Key=Value`;
101     assertThrown(new DesktopFile(iniLikeStringReader(contents)));

Meta