Skip to content

Commit

Permalink
Add showIn. Documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Apr 27, 2016
1 parent 40fbfa5 commit 4879b2d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/util/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"inilike": "0.6.2",
"xdgpaths": "0.2.1"
}
}
}
13 changes: 8 additions & 5 deletions examples/util/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ void main(string[] args)
string inFile = args[2];
string locale = currentLocale();

if (inFile == inFile.baseName && inFile.extension == ".desktop") {
inFile = findDesktopFile(inFile);
if (inFile is null) {
stderr.writeln("Could not find desktop file with such id: ", inFile);
return;
static if (isFreedesktop) {
if (inFile == inFile.baseName && inFile.extension == ".desktop") {
string desktopId = inFile;
inFile = findDesktopFile(desktopId);
if (inFile is null) {
stderr.writeln("Could not find desktop file with such id: ", desktopId);
return;
}
}
}

Expand Down
39 changes: 37 additions & 2 deletions source/desktopfile/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ final class DesktopEntry : IniLikeGroup
}

/**
* Returns: the value associated with "Exec" key.
* Exec command as it's defined in desktop file.
* Returns: the value associated with "Exec" key (in escaped form).
* Note: To get arguments from exec string use expandExecString.
* See_Also: expandExecString, startApplication, tryExecString
*/
Expand Down Expand Up @@ -297,7 +298,7 @@ final class DesktopEntry : IniLikeGroup

/**
* 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 $(B 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).
* Returns: The value associated with "TryExec" key, possibly with quotes removed if path is quoted.
* Returns: The value associated with "TryExec" key.
* See_Also: execString
*/
@nogc @safe string tryExecString() const nothrow pure {
Expand Down Expand Up @@ -425,6 +426,7 @@ final class DesktopEntry : IniLikeGroup
}

/**
* A boolean value specifying if an application uses Startup Notification Protocol.
* Returns: The value associated with "startupNotify" key converted to bool using isTrue.
*/
@nogc @safe bool startupNotify() const nothrow pure {
Expand Down Expand Up @@ -582,6 +584,39 @@ final class DesktopEntry : IniLikeGroup
this["NotShowIn"] = DesktopFile.joinValues(values).escapeIfNeeded();
}

/**
* Check if desktop file should be shown in menu of specific desktop environment.
* Params:
* desktopEnvironment = Name of desktop environment, usually detected by XDG_CURRENT_DESKTOP variable.
* See_Also: $(LINK2 https://specifications.freedesktop.org/menu-spec/latest/apb.html, Registered OnlyShowIn Environments)
*/
@trusted bool showIn(string desktopEnvironment)
{
if (notShowIn().canFind(desktopEnvironment)) {
return false;
}
auto onlyIn = onlyShowIn();
return onlyIn.empty || onlyIn.canFind(desktopEnvironment);
}

///
unittest
{
auto df = new DesktopFile();
df.notShowIn = ["GNOME", "MATE"];
assert(df.showIn("KDE"));
assert(df.showIn("awesome"));
assert(df.showIn(""));
assert(!df.showIn("GNOME"));
df.onlyShowIn = ["LXDE", "XFCE"];
assert(df.showIn("LXDE"));
assert(df.showIn("XFCE"));
assert(!df.showIn(""));
assert(!df.showIn("awesome"));
assert(!df.showIn("KDE"));
assert(!df.showIn("MATE"));
}

protected:
@trusted override void validateKeyValue(string key, string value) const {
validateKeyValueImpl(key, value);
Expand Down

0 comments on commit 4879b2d

Please sign in to comment.