From 75daf3857bf43d81ab4821de82c45a4bb3c8c4cd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Apr 2020 21:58:04 +0200 Subject: [PATCH] FileManager: Use GUI::DesktopServices::open() to open files Instead of squirreling away this logic deep in the FileManager app, we now delegate file opening to GUI::DesktopServices. --- Applications/FileManager/DirectoryView.cpp | 55 +++------------------- 1 file changed, 7 insertions(+), 48 deletions(-) diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index be96e6c8a8c..4832baaffa8 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -27,6 +27,8 @@ #include "DirectoryView.h" #include #include +#include +#include #include #include #include @@ -68,55 +70,12 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index) return; } - ASSERT(!S_ISLNK(st.st_mode)); + URL url; + url.set_protocol("file"); + url.set_path(path); - if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) { - if (fork() == 0) { - int rc = execl(path.characters(), path.characters(), nullptr); - if (rc < 0) - perror("exec"); - ASSERT_NOT_REACHED(); - } - return; - } - - if (path.to_lowercase().ends_with(".png")) { - if (fork() == 0) { - int rc = execl("/bin/qs", "/bin/qs", path.characters(), nullptr); - if (rc < 0) - perror("exec"); - ASSERT_NOT_REACHED(); - } - return; - } - - if (path.to_lowercase().ends_with(".html")) { - if (fork() == 0) { - int rc = execl("/bin/Browser", "/bin/Browser", path.characters(), nullptr); - if (rc < 0) - perror("exec"); - ASSERT_NOT_REACHED(); - } - return; - } - - if (path.to_lowercase().ends_with(".wav")) { - if (fork() == 0) { - int rc = execl("/bin/SoundPlayer", "/bin/SoundPlayer", path.characters(), nullptr); - if (rc < 0) - perror("exec"); - ASSERT_NOT_REACHED(); - } - return; - } - - if (fork() == 0) { - int rc = execl("/bin/TextEditor", "/bin/TextEditor", path.characters(), nullptr); - if (rc < 0) - perror("exec"); - ASSERT_NOT_REACHED(); - } -}; + GUI::DesktopServices::open(url); +} DirectoryView::DirectoryView() : m_model(GUI::FileSystemModel::create())