Skip to content

Commit

Permalink
One big update
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed May 17, 2016
1 parent de11545 commit 557892d
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 272 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ matrix:
- d: gdc-4.8.2
- d: ldc-0.14.0
include:
- d: dmd-2.069.2
env: USE_DOVERALLS=true
- d: dmd-2.067.1
- d: gdc-4.9.2
- d: ldc-0.15.1
- d: gdc-4.8.2
- d: ldc-0.14.0

install:
- chmod +x download_doveralls.sh
- ./download_doveralls.sh

script:
- dub test -b unittest-cov --compiler=${DC}
- chmod +x start_doveralls.sh
- ./start_doveralls.sh
- chmod +x travis-script.sh
- ./travis-script.sh
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ The library is crossplatform for the most part, though there's little sense to u
**desktopfile** provides basic features like reading and executing desktop files, and more:

* [Exec](http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html) value unquoting and unescaping. Expanding field codes.
* Starting several instances of application if it supports only %f or %u and not %F or %U.
* Can rewrite desktop files preserving all comments and the original order of groups [as required by spec](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html).
* Retrieving [Desktop file ID](http://standards.freedesktop.org/desktop-entry-spec/latest/ape.html).
* Support for [Additional application actions](http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s10.html).
* Determining default terminal command to run applications with Terminal=true. Note that default terminal detector may not work properly on particular system (e.g. Fedora which does not have xterm installed by default) since there's no standard way to find default terminal emulator that would work on every distribution and desktop environment. If you strive for better terminal emulator detection you may look at [xdg-terminal.sh](https://src.chromium.org/svn/trunk/deps/third_party/xdg-utils/scripts/xdg-terminal).
* Determining default terminal command to run applications with Terminal=true. Note that default terminal detector may not work properly on particular system since there's no standard way to find default terminal emulator that would work on every distribution and desktop environment. If you strive for better terminal emulator detection you may look at [xdg-terminal.sh](https://src.chromium.org/svn/trunk/deps/third_party/xdg-utils/scripts/xdg-terminal).

### Missing features

Features that currently should be handled by user, but may be implemented in the future versions of library.

* [D-Bus Activation](http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s07.html).
* Startup Notification Protocol.
* Copying files to local file system when %f field code is used.
* Starting several instances of application if it supports only %f or %u and not %F or %U.
* Copying files to local file system when %f or %F field code is used.
* Ayatana Desktop Shortcuts used in Unity. This is not part of Desktop Entry and actually violates the specification.

## Generating documentation

Expand Down Expand Up @@ -84,13 +85,13 @@ try {
string[] keywords = df.keywords().array; //Keywords can be used to improve searching of the application.
foreach(action; df.byAction()) { //Supported actions.
string actionName = action.name();
string actionName = action.localizedDisplayName(locale);
action.start(locale);
}
if (df.type() == DesktopFile.Type.Application) {
//This is application
string commandLine = df.execString(); //Command line pattern used to start the application.
string commandLine = df.execValue(); //Command line pattern used to start the application.
try {
df.startApplication(urls, locale); //Start application using given arguments and specified locale. It will be automatically started in terminal emulator if required.
}
Expand Down Expand Up @@ -125,7 +126,7 @@ Utility that can parse, execute and rewrites .desktop files.

This will open $HOME/.bashrc in geany text editor:

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

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

Expand All @@ -135,6 +136,10 @@ Additional application actions are supported too:

dub run :util -- exec /usr/share/applications/steam.desktop --action=Settings

Running of multiple application instances if it does not support handling multiple urls:

dub run :util -- exec /usr/share/applications/leafpad.desktop dub.json README.md

Open link with preferred application:

dub run :util -- open /usr/share/desktop-base/debian-homepage.desktop
Expand All @@ -161,6 +166,11 @@ On non-freedesktop systems appPath should be passed and PATH variable prepared.
set PATH=C:\ProgramData\KDE\bin
dub run :util -- --appPath=C:\ProgramData\KDE\share\applications exec kde4-gwenview.desktop

Executing .desktop files with complicated Exec lines:

dub run :util -- exec "$HOME/.local/share/applications/wine/Programs/True Remembrance/True Remembrance.desktop" # launcher that was generated by wine
dub run :util -- exec $HOME/TorBrowser/tor-browser_en-US/start-tor-browser.desktop # Tor browser launcher

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

Parses all .desktop files in system's applications paths (usually /usr/local/share/applicatons and /usr/share/applications) and on the user's Desktop.
Expand All @@ -186,9 +196,14 @@ Example using cmd on Windows (KDE installed):

Uses the alternative way of starting desktop file. Instead of constructing DesktopFile object it just starts the application or opens link after read enough information from file.

dub run :shoot -- $HOME/Desktop/vlc.desktop
dub run :shoot -- /usr/share/applications/python2.7.desktop
dub run :shoot -- vlc.desktop
dub run :shoot -- python2.7.desktop
dub run :shoot -- geany.desktop dub.json

Running of multiple application instances if it does not support handling multiple urls:

dub run :shoot -- leafpad.desktop dub.json README.md

On Windows (KDE installed):

dub run :shoot -- C:\ProgramData\KDE\share\applications\kde4\gwenview.desktop
dub run :shoot -- C:\ProgramData\KDE\share\applications\kde4\gwenview.desktop
6 changes: 0 additions & 6 deletions download_doveralls.sh

This file was deleted.

2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"fileVersion": 1,
"versions": {
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"inilike": "0.7.0",
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/shoot/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"fileVersion": 1,
"versions": {
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"inilike": "0.7.0",
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
Expand Down
39 changes: 35 additions & 4 deletions examples/shoot/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,54 @@ int main(string[] args)
{
bool onlyExec;
bool notFollow;
string[] appPaths;

getopt(
args,
"onlyExec", "Only start applications, don't open links", &onlyExec,
"notFollow", "Don't follow desktop files", &notFollow);
"notFollow", "Don't follow desktop files", &notFollow,
"appPath", "Path of applications directory", &appPaths);


string fileName;
string inFile;
if (args.length > 1) {
fileName = args[1];
inFile = args[1];
} else {
stderr.writeln("Must provide path to desktop file");
return 1;
}

if (appPaths.length == 0) {
static if (isFreedesktop) {
import desktopfile.paths;
appPaths = applicationsPaths();
}
version(Windows) {
try {
auto root = environment.get("SYSTEMDRIVE", "C:");
auto kdeAppDir = root ~ `\ProgramData\KDE\share\applications`;
if (kdeAppDir.isDir) {
appPaths = [kdeAppDir];
}
} catch(Exception e) {

}
}
}

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

ShootOptions options;

options.urls = args[2..$];

if (onlyExec) {
options.flags = options.flags & ~ShootOptions.Link;
}
Expand All @@ -33,7 +64,7 @@ int main(string[] args)
}

try {
shootDesktopFile(fileName, options);
shootDesktopFile(inFile, options);
}
catch(Exception e) {
stderr.writeln(e.msg);
Expand Down
2 changes: 1 addition & 1 deletion examples/test/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"authors": ["freeslave"],
"dependencies": {
"desktopfile" : "*",
"standardpaths": "~>0.4.0"
"standardpaths": "~>0.5.0"
},
"targetPath" : "bin",
"targetType" : "executable"
Expand Down
4 changes: 2 additions & 2 deletions examples/test/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"fileVersion": 1,
"versions": {
"standardpaths": "0.4.0",
"standardpaths": "0.5.0",
"isfreedesktop": "0.1.0",
"inilike": "0.6.2",
"inilike": "0.7.0",
"xdgpaths": "0.2.1",
"findexecutable": "0.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions examples/test/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ void main(string[] args)
}
try {
auto df = new DesktopFile(entry, DesktopFile.ReadOptions.noOptions);
if (!df.execString().empty) {
auto execArgs = df.expandExecString();
if (!df.execValue().empty) {
auto execArgs = df.expandExecValue();
}
}
catch(IniLikeException e) {
catch(IniLikeReadException e) {
stderr.writefln("Error reading %s: at %s: %s", entry, e.lineNumber, e.msg);
}
catch(DesktopExecException e) {
Expand Down
2 changes: 1 addition & 1 deletion examples/util/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"versions": {
"isfreedesktop": "0.1.0",
"findexecutable": "0.1.0",
"inilike": "0.6.2",
"inilike": "0.7.0",
"xdgpaths": "0.2.1"
}
}
4 changes: 2 additions & 2 deletions examples/util/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void main(string[] args)
writefln("MimeTypes: %(%s %)", df.mimeTypes());

if (df.type() == DesktopFile.Type.Application) {
writeln("Exec: ", df.execString());
writeln("Exec: ", df.execValue());
writeln("In terminal: ", df.terminal());
writeln("Trusted: ", isTrusted(df.fileName));
}
Expand All @@ -96,7 +96,7 @@ void main(string[] args)
}
} else {
string[] urls = args[3..$];
string[] appArgs = df.expandExecString(urls, locale);
string[] appArgs = df.expandExecValue(urls, locale);
writefln("Exec: %(%s %)", appArgs);
df.startApplication(urls, locale);
}
Expand Down
Loading

0 comments on commit 557892d

Please sign in to comment.