mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
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.
This commit is contained in:
parent
3f08dd5ddc
commit
75daf3857b
1 changed files with 7 additions and 48 deletions
|
@ -27,6 +27,8 @@
|
|||
#include "DirectoryView.h"
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibGUI/DesktopServices.h>
|
||||
#include <LibGUI/SortingProxyModel.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue