mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
FileManager: Add file properties tab for ZIP archives
This commit is contained in:
parent
8d53442187
commit
a333d9959c
4 changed files with 120 additions and 1 deletions
|
@ -7,6 +7,7 @@ serenity_component(
|
||||||
|
|
||||||
compile_gml(FileManagerWindow.gml FileManagerWindowGML.h file_manager_window_gml)
|
compile_gml(FileManagerWindow.gml FileManagerWindowGML.h file_manager_window_gml)
|
||||||
compile_gml(FileOperationProgress.gml FileOperationProgressGML.h file_operation_progress_gml)
|
compile_gml(FileOperationProgress.gml FileOperationProgressGML.h file_operation_progress_gml)
|
||||||
|
compile_gml(PropertiesWindowArchiveTab.gml PropertiesWindowArchiveTabGML.h properties_window_archive_tab_gml)
|
||||||
compile_gml(PropertiesWindowAudioTab.gml PropertiesWindowAudioTabGML.h properties_window_audio_tab_gml)
|
compile_gml(PropertiesWindowAudioTab.gml PropertiesWindowAudioTabGML.h properties_window_audio_tab_gml)
|
||||||
compile_gml(PropertiesWindowFontTab.gml PropertiesWindowFontTabGML.h properties_window_font_tab_gml)
|
compile_gml(PropertiesWindowFontTab.gml PropertiesWindowFontTabGML.h properties_window_font_tab_gml)
|
||||||
compile_gml(PropertiesWindowGeneralTab.gml PropertiesWindowGeneralTabGML.h properties_window_general_tab_gml)
|
compile_gml(PropertiesWindowGeneralTab.gml PropertiesWindowGeneralTabGML.h properties_window_general_tab_gml)
|
||||||
|
@ -24,6 +25,7 @@ set(SOURCES
|
||||||
set(GENERATED_SOURCES
|
set(GENERATED_SOURCES
|
||||||
FileManagerWindowGML.h
|
FileManagerWindowGML.h
|
||||||
FileOperationProgressGML.h
|
FileOperationProgressGML.h
|
||||||
|
PropertiesWindowArchiveTabGML.h
|
||||||
PropertiesWindowAudioTabGML.h
|
PropertiesWindowAudioTabGML.h
|
||||||
PropertiesWindowFontTabGML.h
|
PropertiesWindowFontTabGML.h
|
||||||
PropertiesWindowGeneralTabGML.h
|
PropertiesWindowGeneralTabGML.h
|
||||||
|
@ -31,4 +33,4 @@ set(GENERATED_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(FileManager ICON app-file-manager)
|
serenity_app(FileManager ICON app-file-manager)
|
||||||
target_link_libraries(FileManager PRIVATE LibAudio LibCore LibFileSystem LibGfx LibGUI LibDesktop LibConfig LibMain LibThreading)
|
target_link_libraries(FileManager PRIVATE LibArchive LibAudio LibCore LibFileSystem LibGfx LibGUI LibDesktop LibConfig LibMain LibThreading)
|
||||||
|
|
|
@ -7,13 +7,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PropertiesWindow.h"
|
#include "PropertiesWindow.h"
|
||||||
|
#include <AK/GenericShorthands.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/NumberFormat.h>
|
#include <AK/NumberFormat.h>
|
||||||
#include <Applications/FileManager/DirectoryView.h>
|
#include <Applications/FileManager/DirectoryView.h>
|
||||||
|
#include <Applications/FileManager/PropertiesWindowArchiveTabGML.h>
|
||||||
#include <Applications/FileManager/PropertiesWindowAudioTabGML.h>
|
#include <Applications/FileManager/PropertiesWindowAudioTabGML.h>
|
||||||
#include <Applications/FileManager/PropertiesWindowFontTabGML.h>
|
#include <Applications/FileManager/PropertiesWindowFontTabGML.h>
|
||||||
#include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
|
#include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
|
||||||
#include <Applications/FileManager/PropertiesWindowImageTabGML.h>
|
#include <Applications/FileManager/PropertiesWindowImageTabGML.h>
|
||||||
|
#include <LibArchive/Zip.h>
|
||||||
#include <LibAudio/Loader.h>
|
#include <LibAudio/Loader.h>
|
||||||
#include <LibCore/Directory.h>
|
#include <LibCore/Directory.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
|
@ -222,6 +225,10 @@ ErrorOr<void> PropertiesWindow::create_file_type_specific_tabs(GUI::TabWidget& t
|
||||||
auto file_name_guess = Core::guess_mime_type_based_on_filename(m_path);
|
auto file_name_guess = Core::guess_mime_type_based_on_filename(m_path);
|
||||||
auto mime_type = Core::guess_mime_type_based_on_sniffed_bytes(mapped_file->bytes()).value_or(file_name_guess);
|
auto mime_type = Core::guess_mime_type_based_on_sniffed_bytes(mapped_file->bytes()).value_or(file_name_guess);
|
||||||
|
|
||||||
|
// FIXME: Support other archive types
|
||||||
|
if (mime_type == "application/zip"sv)
|
||||||
|
return create_archive_tab(tab_widget, move(mapped_file));
|
||||||
|
|
||||||
if (mime_type.starts_with("audio/"sv))
|
if (mime_type.starts_with("audio/"sv))
|
||||||
return create_audio_tab(tab_widget, move(mapped_file));
|
return create_audio_tab(tab_widget, move(mapped_file));
|
||||||
|
|
||||||
|
@ -234,6 +241,28 @@ ErrorOr<void> PropertiesWindow::create_file_type_specific_tabs(GUI::TabWidget& t
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> PropertiesWindow::create_archive_tab(GUI::TabWidget& tab_widget, NonnullRefPtr<Core::MappedFile> mapped_file)
|
||||||
|
{
|
||||||
|
auto maybe_zip = Archive::Zip::try_create(mapped_file->bytes());
|
||||||
|
if (!maybe_zip.has_value()) {
|
||||||
|
warnln("Failed to read zip file '{}' ", m_path);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
auto zip = maybe_zip.release_value();
|
||||||
|
|
||||||
|
auto tab = TRY(tab_widget.try_add_tab<GUI::Widget>(TRY("Archive"_string)));
|
||||||
|
TRY(tab->load_from_gml(properties_window_archive_tab_gml));
|
||||||
|
|
||||||
|
auto statistics = TRY(zip.calculate_statistics());
|
||||||
|
|
||||||
|
tab->find_descendant_of_type_named<GUI::Label>("archive_format")->set_text("ZIP"_short_string);
|
||||||
|
tab->find_descendant_of_type_named<GUI::Label>("archive_file_count")->set_text(TRY(String::number(statistics.file_count())));
|
||||||
|
tab->find_descendant_of_type_named<GUI::Label>("archive_directory_count")->set_text(TRY(String::number(statistics.directory_count())));
|
||||||
|
tab->find_descendant_of_type_named<GUI::Label>("archive_uncompressed_size")->set_text(TRY(String::from_deprecated_string(AK::human_readable_size(statistics.total_uncompressed_bytes()))));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> PropertiesWindow::create_audio_tab(GUI::TabWidget& tab_widget, NonnullRefPtr<Core::MappedFile> mapped_file)
|
ErrorOr<void> PropertiesWindow::create_audio_tab(GUI::TabWidget& tab_widget, NonnullRefPtr<Core::MappedFile> mapped_file)
|
||||||
{
|
{
|
||||||
auto loader_or_error = Audio::Loader::create(mapped_file->bytes());
|
auto loader_or_error = Audio::Loader::create(mapped_file->bytes());
|
||||||
|
|
|
@ -30,6 +30,7 @@ private:
|
||||||
ErrorOr<void> create_widgets(bool disable_rename);
|
ErrorOr<void> create_widgets(bool disable_rename);
|
||||||
ErrorOr<void> create_general_tab(GUI::TabWidget&, bool disable_rename);
|
ErrorOr<void> create_general_tab(GUI::TabWidget&, bool disable_rename);
|
||||||
ErrorOr<void> create_file_type_specific_tabs(GUI::TabWidget&);
|
ErrorOr<void> create_file_type_specific_tabs(GUI::TabWidget&);
|
||||||
|
ErrorOr<void> create_archive_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>);
|
||||||
ErrorOr<void> create_audio_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>);
|
ErrorOr<void> create_audio_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>);
|
||||||
ErrorOr<void> create_font_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>, StringView mime_type);
|
ErrorOr<void> create_font_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>, StringView mime_type);
|
||||||
ErrorOr<void> create_image_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>, StringView mime_type);
|
ErrorOr<void> create_image_tab(GUI::TabWidget&, NonnullRefPtr<Core::MappedFile>, StringView mime_type);
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
@GUI::Widget {
|
||||||
|
layout: @GUI::VerticalBoxLayout {
|
||||||
|
margins: [8]
|
||||||
|
spacing: 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::GroupBox {
|
||||||
|
title: "Archive"
|
||||||
|
preferred_height: "shrink"
|
||||||
|
layout: @GUI::VerticalBoxLayout {
|
||||||
|
margins: [12, 8, 0]
|
||||||
|
spacing: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
text: "Format:"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
fixed_width: 80
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "archive_format"
|
||||||
|
text: "ZIP"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
text: "Files:"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
fixed_width: 80
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "archive_file_count"
|
||||||
|
text: "42"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
text: "Directories:"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
fixed_width: 80
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "archive_directory_count"
|
||||||
|
text: "7"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
text: "Uncompressed:"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
fixed_width: 80
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "archive_uncompressed_size"
|
||||||
|
text: "3.3 MiB"
|
||||||
|
text_alignment: "TopLeft"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue