Skip to content

Commit

Permalink
Add missing setters for DesktopEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Mar 24, 2016
1 parent cc1fdf5 commit ac68dab
Showing 1 changed file with 103 additions and 14 deletions.
117 changes: 103 additions & 14 deletions source/desktopfile/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ final class DesktopEntry : IniLikeGroup
@nogc @safe string displayName() const nothrow {
return value("Name");
}

///setter
@safe string displayName(string name) {
this["Name"] = name;
return name;
}

/**
* Returns: Localized name.
* See_Also: name
Expand All @@ -193,6 +200,12 @@ final class DesktopEntry : IniLikeGroup
@nogc @safe string genericName() const nothrow {
return value("GenericName");
}

///setter
@safe string genericName(string name) {
this["GenericName"] = name;
return name;
}
/**
* Returns: Localized generic name
* See_Also: genericName
Expand All @@ -209,6 +222,13 @@ final class DesktopEntry : IniLikeGroup
@nogc @safe string comment() const nothrow {
return value("Comment");
}

///setter
@safe string comment(string commentary) {
this["Comment"] = commentary;
return commentary;
}

/**
* Returns: Localized comment
* See_Also: comment
Expand All @@ -226,6 +246,12 @@ final class DesktopEntry : IniLikeGroup
return value("Exec");
}

///setter
@safe string execString(string exec) {
this["Exec"] = exec;
return exec;
}

/**
* URL to access.
* Returns: The value associated with "URL" key.
Expand All @@ -234,6 +260,12 @@ final class DesktopEntry : IniLikeGroup
return value("URL");
}

///setter
@safe string url(string link) {
this["URL"] = link;
return link;
}

///
unittest
{
Expand All @@ -247,22 +279,18 @@ final class DesktopEntry : IniLikeGroup
* See_Also: execString
*/
@nogc @safe string tryExecString() const nothrow {
string orig = value("TryExec");
if (orig.length) {
if (orig[0] == '"' || orig[0] == '\'' && orig.length > 1 && orig[$-1] == orig[0]) {
return orig[1..$-1];
}
}
return orig;
return value("TryExec");
}

///
unittest
{
auto df = new DesktopFile(iniLikeStringReader("[Desktop Entry]\nTryExec=whoami"));
assert(df.tryExecString() == "whoami");
df = new DesktopFile(iniLikeStringReader("[Desktop Entry]\nTryExec='/path to/whoami'"));
assert(df.tryExecString() == "/path to/whoami");
/**
* Set TryExec value.
* Throws:
* Exception if tryExec is not abolute path nor base name.
*/
@safe string tryExecString(string tryExec) {
enforce(tryExec.isAbsolute || tryExec.baseName == tryExec, "TryExec must be absolute path or base name");
this["TryExec"] = tryExec;
return tryExec;
}

/**
Expand All @@ -276,6 +304,17 @@ final class DesktopEntry : IniLikeGroup
return value("Icon");
}

/**
* Set Icon value.
* Throws:
* Exception if icon is not abolute path nor base name.
*/
@safe string iconName(string icon) {
enforce(icon.isAbsolute || icon.baseName == icon, "Icon must be absolute path or base name");
this["Icon"] = icon;
return icon;
}

/**
* Returns: Localized icon name
* See_Also: iconName
Expand All @@ -284,6 +323,10 @@ final class DesktopEntry : IniLikeGroup
return localizedValue("Icon", locale);
}

private @nogc @safe static string boolToString(bool b) nothrow pure {
return b ? "true" : "false";
}

/**
* NoDisplay means "this application exists, but don't display it in the menus".
* Returns: The value associated with "NoDisplay" key converted to bool using isTrue.
Expand All @@ -292,6 +335,12 @@ final class DesktopEntry : IniLikeGroup
return isTrue(value("NoDisplay"));
}

///setter
@safe bool noDisplay(bool notDisplay) {
this["NoDisplay"] = boolToString(notDisplay);
return notDisplay;
}

/**
* 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.
Expand All @@ -301,6 +350,12 @@ final class DesktopEntry : IniLikeGroup
return isTrue(value("Hidden"));
}

///setter
@safe bool hidden(bool hide) {
this["Hidden"] = boolToString(hide);
return hide;
}

/**
* A boolean value specifying if D-Bus activation is supported for this application.
* Returns: The value associated with "dbusActivable" key converted to bool using isTrue.
Expand All @@ -309,13 +364,25 @@ final class DesktopEntry : IniLikeGroup
return isTrue(value("DBusActivatable"));
}

///setter
@safe bool dbusActivable(bool activable) {
this["DBusActivatable"] = boolToString(activable);
return activable;
}

/**
* Returns: The value associated with "startupNotify" key converted to bool using isTrue.
*/
@nogc @safe bool startupNotify() const nothrow {
return isTrue(value("StartupNotify"));
}

///setter
@safe bool startupNotify(bool notify) {
this["StartupNotify"] = boolToString(notify);
return notify;
}

/**
* The working directory to run the program in.
* Returns: The value associated with "Path" key.
Expand All @@ -324,6 +391,17 @@ final class DesktopEntry : IniLikeGroup
return value("Path");
}

/**
* Set Path value.
* Throws:
* Exception if path is not valid path.
*/
@safe string workingDirectory(string path) {
enforce(path.isValidPath, "Working directory must be valid path");
this["Path"] = path;
return path;
}

/**
* Whether the program runs in a terminal window.
* Returns: The value associated with "Terminal" key converted to bool using isTrue.
Expand Down Expand Up @@ -415,13 +493,24 @@ final class DesktopEntry : IniLikeGroup
return DesktopFile.splitValues(value("OnlyShowIn"));
}

///setter
@safe void onlyShowIn(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["OnlyShowIn"] = DesktopFile.joinValues(values);
}

/**
* A list of strings identifying the desktop environments that should not display a given desktop entry.
* Returns: The range of multiple values associated with "NotShowIn" key.
*/
@safe auto notShowIn() const {
return DesktopFile.splitValues(value("NotShowIn"));
}

///setter
@safe void notShowIn(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["NotShowIn"] = DesktopFile.joinValues(values);
}

protected:
@trusted override void validateKeyValue(string key, string value) const {
enforce(isValidKey(key), "key is invalid");
Expand Down

0 comments on commit ac68dab

Please sign in to comment.