Fix getting of gtk bookmarks

This commit is contained in:
FreeSlave 2016-04-11 10:53:56 -04:00
parent f2d2df59a5
commit 27ff72c90a
1 changed files with 16 additions and 3 deletions

View File

@ -379,6 +379,7 @@ RootEntry[] getBookmarkPaths() nothrow
import std.string : startsWith; import std.string : startsWith;
import std.stdio : File; import std.stdio : File;
import std.exception : collectException; import std.exception : collectException;
import std.uri : decode;
try { try {
enum fileProtocol = "file://"; enum fileProtocol = "file://";
auto configPath = environment.get("XDG_CONFIG_HOME"); auto configPath = environment.get("XDG_CONFIG_HOME");
@ -388,14 +389,26 @@ RootEntry[] getBookmarkPaths() nothrow
auto bookmarksFile = buildPath(configPath, "gtk-3.0/bookmarks"); auto bookmarksFile = buildPath(configPath, "gtk-3.0/bookmarks");
foreach(line; File(bookmarksFile, "r").byLineCopy()) { foreach(line; File(bookmarksFile, "r").byLineCopy()) {
if (line.startsWith(fileProtocol)) { if (line.startsWith(fileProtocol)) {
auto path = line[fileProtocol.length..$]; auto splitted = line.findSplit(" ");
string path;
if (splitted[1].length) {
path = splitted[0][fileProtocol.length..$];
} else {
path = line[fileProtocol.length..$];
}
path = decode(path);
if (path.isAbsolute) { if (path.isAbsolute) {
// Note: GTK supports regular files in bookmarks too, but we allow directories only. // Note: GTK supports regular files in bookmarks too, but we allow directories only.
bool dirExists; bool dirExists;
collectException(path.isDir, dirExists); collectException(path.isDir, dirExists);
if (dirExists) { if (dirExists) {
res ~= RootEntry(RootEntryType.BOOKMARK, path, path.baseName.toUTF32); dstring label;
if (splitted[1].length) {
label = splitted[2].toUTF32;
} else {
label = path.baseName.toUTF32;
}
res ~= RootEntry(RootEntryType.BOOKMARK, path, label);
} }
} }
} }