Skip to content

Commit

Permalink
Improve terminal detecting. Improve unquoting. Add findDesktopFile
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Apr 26, 2016
1 parent 2548f43 commit ebe9224
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 88 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ catch (IniLikeException e) { //Parsing error - file is not desktop file or has e

Utility that can parse, execute and rewrites .desktop files.

This will start vlc with the first parameter set to $HOME/Music:
This will open $HOME/.bashrc in geany text editor:

dub run :util -- exec /usr/share/applications/vlc.desktop $HOME/Music
dub run :util -- exec /usr/share/applications/geany.desktop $HOME/.bashrc

This should start command line application in terminal emulator (will be detected automatically):

Expand All @@ -137,7 +137,7 @@ Additional application actions are supported too:

Open link with preferred application:

dub run :util -- link /usr/share/desktop-base/debian-homepage.desktop
dub run :util -- open /usr/share/desktop-base/debian-homepage.desktop

Starts .desktop file defined executable or opens link:

Expand All @@ -150,6 +150,11 @@ Parse and write .desktop file to new location (to testing purposes):
Read basic information about desktop file:

dub run :util -- read /usr/share/applications/kde4/kate.desktop

When passing base name of desktop file instead of path it's treated like desktop file id and desktop file is searched in system applications paths.

dub run :util -- exec python2.7.desktop
dub run :util -- exec kde4-kate.desktop

### [Desktop test](examples/test/source/app.d)

Expand Down
3 changes: 2 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"authors": ["Roman Chistokhodov"],
"dependencies": {
"inilike": "~>0.6.2",
"xdgpaths" : "~>0.2.1"
"xdgpaths" : "~>0.2.1",
"findexecutable" : "~>0.1.0"
},
"targetName" : "desktopfile",
"targetPath" : "lib",
Expand Down
3 changes: 2 additions & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"versions": {
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"xdgpaths": "0.2.1"
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
}
3 changes: 2 additions & 1 deletion examples/shoot/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"versions": {
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"xdgpaths": "0.2.1"
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
}
3 changes: 2 additions & 1 deletion examples/test/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"standardpaths": "0.4.0",
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"xdgpaths": "0.2.1"
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
}
2 changes: 1 addition & 1 deletion examples/test/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main(string[] args)

string[] dataPaths = standardPaths(StandardPath.data);

desktopDirs = applicationsPaths() ~ dataPaths.map!(s => buildPath(s, "desktop-directories")).array ~ dataPaths.map!(s => buildPath(s, "templates")).array ~ dataPaths.map!(s => buildPath(s, "autostart")).array ~ writablePath(StandardPath.desktop);
desktopDirs = applicationsPaths() ~ dataPaths.map!(s => buildPath(s, "desktop-directories")).array ~ dataPaths.map!(s => buildPath(s, "templates")).array ~ standardPaths(StandardPath.startup) ~ writablePath(StandardPath.desktop);
}

version(Windows) {
Expand Down
3 changes: 2 additions & 1 deletion examples/util/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"versions": {
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"xdgpaths": "0.2.1"
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
}
17 changes: 13 additions & 4 deletions examples/util/source/app.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import std.stdio;
import std.getopt;
import std.process;
import std.path;

import desktopfile.file;
import isfreedesktop;
Expand All @@ -18,14 +19,22 @@ import isfreedesktop;
void main(string[] args)
{
if (args.length < 3) {
writefln("Usage: %s <read|exec|link|start|write> <desktop-file> <optional arguments>", args[0]);
writefln("Usage: %s <read|exec|open|start|write> <desktop-file> <optional arguments>", args[0]);
return;
}

string command = args[1];
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;
}
}

if (command == "read") {
auto df = new DesktopFile(inFile);

Expand Down Expand Up @@ -62,14 +71,14 @@ void main(string[] args)
}
} else {
string[] urls = args[3..$];
writeln("Exec:", df.expandExecString(urls, locale));
writefln("Exec: %(%s %)", df.expandExecString(urls, locale));
df.startApplication(urls, locale);
}


} else if (command == "link") {
} else if (command == "open") {
auto df = new DesktopFile(inFile);
writeln("Link:", df.url());
writeln("Link: ", df.url());
df.startLink();
} else if (command == "start") {
auto df = new DesktopFile(inFile);
Expand Down
17 changes: 8 additions & 9 deletions source/desktopfile/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ final class DesktopEntry : IniLikeGroup
@nogc @safe bool terminal() const nothrow pure {
return isTrue(value("Terminal"));
}
/// Sets "Terminal" field to true or false.
///setter
@safe bool terminal(bool t) {
this["Terminal"] = t ? "true" : "false";
this["Terminal"] = boolToString(t);
return t;
}

Expand All @@ -498,7 +498,7 @@ final class DesktopEntry : IniLikeGroup
* Sets the list of values for the "Categories" list.
*/
void categories(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["Categories"] = DesktopFile.joinValues(values);
this["Categories"] = DesktopFile.joinValues(values).escapeIfNeeded();
}

/**
Expand All @@ -521,7 +521,7 @@ final class DesktopEntry : IniLikeGroup
* Sets the list of values for the "Keywords" list.
*/
void keywords(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["Keywords"] = DesktopFile.joinValues(values);
this["Keywords"] = DesktopFile.joinValues(values).escapeIfNeeded();
}

/**
Expand All @@ -536,7 +536,7 @@ final class DesktopEntry : IniLikeGroup
* Sets the list of values for the "MimeType" list.
*/
void mimeTypes(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["MimeType"] = DesktopFile.joinValues(values);
this["MimeType"] = DesktopFile.joinValues(values).escapeIfNeeded();
}

/**
Expand All @@ -553,7 +553,7 @@ final class DesktopEntry : IniLikeGroup
* Sets the list of values for "Actions" list.
*/
void actions(Range)(Range values) if (isInputRange!Range && isSomeString!(ElementType!Range)) {
this["Actions"] = DesktopFile.joinValues(values);
this["Actions"] = DesktopFile.joinValues(values).escapeIfNeeded();
}

/**
Expand All @@ -566,7 +566,7 @@ final class DesktopEntry : IniLikeGroup

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

/**
Expand All @@ -579,7 +579,7 @@ final class DesktopEntry : IniLikeGroup

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

protected:
Expand Down Expand Up @@ -1126,7 +1126,6 @@ private:
unittest
{
import std.file;
//Test DesktopFile
string desktopFileContents =
`[Desktop Entry]
# Comment
Expand Down
4 changes: 2 additions & 2 deletions source/desktopfile/paths.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static if (isFreedesktop)
}

/**
* Path where .desktop files can be stored without requiring of root privileges.
* This function is defined only on freedesktop systems to avoid confusion with other systems that have data paths not compatible with Desktop Entry Spec.
* Path where .desktop files can be stored by user.
* This function is defined only on freedesktop systems.
* Note: it does not check if returned path exists and appears to be directory.
*/
@safe string writableApplicationsPath() nothrow {
Expand Down
Loading

0 comments on commit ebe9224

Please sign in to comment.