diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-05-29 23:15:54 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-01 09:28:05 +0200 |
commit | 628c7f094f78d06d28c9fe0f14968e00e82e5be3 (patch) | |
tree | 37f2426b6716282c13f02ee6fa05839d9e30d707 /Userland | |
parent | 5caaa52bee16b4016cfee5ae0a78292c5c0987d5 (diff) | |
download | serenity-628c7f094f78d06d28c9fe0f14968e00e82e5be3.zip |
LibGUI+Shell+bt+ls: Use proper APIs for creating file URLs
This patch replaces ad-hoc generation of file URL strings with using
URL::create_with_file_scheme().
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/FileSystemModel.cpp | 8 | ||||
-rw-r--r-- | Userland/Shell/Shell.cpp | 4 | ||||
-rw-r--r-- | Userland/Utilities/bt.cpp | 5 | ||||
-rw-r--r-- | Userland/Utilities/ls.cpp | 4 |
4 files changed, 12 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 39580681ce..696f1ddd03 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -439,12 +439,8 @@ Variant FileSystemModel::data(const ModelIndex& index, ModelRole role) const } if (role == ModelRole::MimeData) { - if (index.column() == Column::Name) { - StringBuilder builder; - builder.append("file://"); - builder.append(node.full_path()); - return builder.to_string(); - } + if (index.column() == Column::Name) + return URL::create_with_file_scheme(node.full_path()).serialize(); return {}; } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index f64d4c33d8..94c7efcc66 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -15,6 +15,7 @@ #include <AK/ScopedValueRollback.h> #include <AK/StringBuilder.h> #include <AK/TemporaryChange.h> +#include <AK/URL.h> #include <LibCore/ArgsParser.h> #include <LibCore/DirIterator.h> #include <LibCore/Event.h> @@ -66,7 +67,8 @@ void Shell::print_path(const String& path) printf("%s", path.characters()); return; } - printf("\033]8;;file://%s%s\033\\%s\033]8;;\033\\", hostname, path.characters(), path.characters()); + auto url = URL::create_with_file_scheme(path, {}, hostname); + out("\033]8;;{}\033\\{}\033]8;;\033\\", url.serialize(), path); } String Shell::prompt() const diff --git a/Userland/Utilities/bt.cpp b/Userland/Utilities/bt.cpp index 993d79d7e0..f901ed0ada 100644 --- a/Userland/Utilities/bt.cpp +++ b/Userland/Utilities/bt.cpp @@ -5,6 +5,7 @@ */ #include <AK/LexicalPath.h> +#include <AK/URL.h> #include <LibCore/ArgsParser.h> #include <LibCore/DirIterator.h> #include <LibCore/EventLoop.h> @@ -57,7 +58,9 @@ int main(int argc, char** argv) auto full_path = LexicalPath::canonicalized_path(String::formatted("/usr/src/serenity/dummy/dummy/{}", symbol.filename)); if (access(full_path.characters(), F_OK) == 0) { linked = true; - out("\033]8;;file://{}{}?line_number={}\033\\", hostname, full_path, symbol.line_number); + auto url = URL::create_with_file_scheme(full_path, {}, hostname); + url.set_query(String::formatted("line_number={}", symbol.line_number)); + out("\033]8;;{}\033\\", url.serialize()); } out("\033[34;1m{}:{}\033[0m", LexicalPath(symbol.filename).basename(), symbol.line_number); diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp index 4eff6ccb74..d57630c58c 100644 --- a/Userland/Utilities/ls.cpp +++ b/Userland/Utilities/ls.cpp @@ -10,6 +10,7 @@ #include <AK/QuickSort.h> #include <AK/String.h> #include <AK/StringBuilder.h> +#include <AK/URL.h> #include <AK/Utf8View.h> #include <AK/Vector.h> #include <LibCore/ArgsParser.h> @@ -196,7 +197,8 @@ static size_t print_name(const struct stat& st, const String& name, const char* if (!flag_disable_hyperlinks) { auto full_path = Core::File::real_path_for(path_for_hyperlink); if (!full_path.is_null()) { - out("\033]8;;file://{}{}\033\\", hostname(), full_path); + auto url = URL::create_with_file_scheme(full_path, {}, hostname()); + out("\033]8;;{}\033\\", url.serialize()); } } |