Skip to content

Commit

Permalink
Add actions support
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Aug 23, 2015
1 parent fdca71d commit 6a3e6de
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ __dummy.html
bin/
lib/
docs/
*.lst
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ This will start vlc with the first parameter set to $HOME/Music:

dub run desktopfile:desktoputil -- exec /usr/share/applications/vlc.desktop $HOME/Music

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

dub run desktopfile:desktoputil -- exec /usr/share/applications/python2.7.desktop

Run in specific terminal emulator:

dub run desktopfile:desktoputil -- exec /usr/share/applications/python2.7.desktop --term=xterm

Open link with preferred application:

dub run desktopfile:desktoputil -- link /usr/share/desktop-base/debian-homepage.desktop
Expand All @@ -48,7 +52,7 @@ Starts .desktop file defined executable or opens link:

dub run desktopfile:desktoputil -- start /path/to/file.desktop

Parse and write .desktop file to new location:
Parse and write .desktop file to new location (to testing purposes):

dub run desktopfile:desktoputil -- write /usr/share/applications/vlc.desktop $HOME/Desktop/vlc.desktop

Expand Down
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"copyright": "Copyright © 2015, Roman Chistokhodov",
"authors": ["Roman Chistokhodov"],
"dependencies": {
"inilike": "~>0.2.0",
"inilike": "~>0.2.1",
"standardpaths": "~>0.2.0"
},
"targetName" : "desktopfile",
Expand Down
2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"fileVersion": 1,
"versions": {
"standardpaths": "0.2.0",
"inilike": "0.2.0"
"inilike": "0.2.1"
}
}
2 changes: 1 addition & 1 deletion examples/desktoptest/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"fileVersion": 1,
"versions": {
"standardpaths": "0.2.0",
"inilike": "0.2.0"
"inilike": "0.2.1"
}
}
2 changes: 1 addition & 1 deletion examples/desktoputil/dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"fileVersion": 1,
"versions": {
"standardpaths": "0.2.0",
"inilike": "0.2.0"
"inilike": "0.2.1"
}
}
41 changes: 32 additions & 9 deletions examples/desktoputil/source/app.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import std.stdio;
import desktopfile;
import std.getopt;

void main(string[] args)
{
Expand All @@ -10,17 +11,20 @@ void main(string[] args)

string command = args[1];
string inFile = args[2];

string locale = currentLocale();

if (command == "read") {
auto df = new DesktopFile(inFile, DesktopFile.ReadOptions.preserveComments | DesktopFile.ReadOptions.firstGroupOnly);

writeln("Name: ", df.name());
writeln("GenericName: ", df.genericName());
writeln("Comment: ", df.comment());
writefln("Name: %s. Localized: %s", df.name(), df.localizedName(locale));
writefln("GenericName: %s. Localized: %s", df.genericName(), df.localizedGenericName(locale));
writefln("Comment: %s. Localized: %s", df.comment(), df.localizedComment(locale));
writeln("Type: ", df.value("Type"));
writeln("Icon: ", df.iconName());
writeln("Desktop ID: ", df.id());
writefln("Actions: %(%s %)", df.actions());
writefln("Categories: %(%s %)", df.categories());
writefln("MimeTypes: %(%s %)", df.mimeTypes());

if (df.type() == DesktopFile.Type.Application) {
writeln("Exec: ", df.execString());
Expand All @@ -30,10 +34,29 @@ void main(string[] args)
writeln("URL: ", df.url());
}
} else if (command == "exec") {
auto df = new DesktopFile(inFile, DesktopFile.ReadOptions.firstGroupOnly);
string[] urls = args[3..$];
writeln("Exec:", df.expandExecString(urls));
df.startApplication(urls);
auto df = new DesktopFile(inFile);
string action;
string term;
getopt(args, "action", "Action to run", &action,
"term", "Preferred terminal emulator to run console applications", &term);
if (action.length) {
auto desktopAction = df.action(action);
if (desktopAction.group() is null) {
stderr.writefln("No such action %s", action);
} else {
desktopAction.start();
}
} else {
string[] urls = args[3..$];
writeln("Exec:", df.expandExecString(urls));
if (term.length) {
df.startApplication(urls, locale, term);
} else {
df.startApplication(urls, locale);
}
}


} else if (command == "link") {
auto df = new DesktopFile(inFile, DesktopFile.ReadOptions.firstGroupOnly);
writeln("Link:", df.url());
Expand All @@ -50,6 +73,6 @@ void main(string[] args)
writeln(df.saveToString());
}
} else {
writefln("unknown command '%s'", command);
stderr.writefln("unknown command '%s'", command);
}
}
Loading

0 comments on commit 6a3e6de

Please sign in to comment.