Преглед на файлове

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().
Max Wipfli преди 4 години
родител
ревизия
628c7f094f
променени са 4 файла, в които са добавени 12 реда и са изтрити 9 реда
  1. 2 6
      Userland/Libraries/LibGUI/FileSystemModel.cpp
  2. 3 1
      Userland/Shell/Shell.cpp
  3. 4 1
      Userland/Utilities/bt.cpp
  4. 3 1
      Userland/Utilities/ls.cpp

+ 2 - 6
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 {};
     }
 

+ 3 - 1
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

+ 4 - 1
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);

+ 3 - 1
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());
         }
     }