mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
FileManager: Add file properties tab for ZIP archives
This commit is contained in:
parent
8d53442187
commit
a333d9959c
Notes:
sideshowbarker
2024-07-17 03:05:16 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/a333d9959c Pull-request: https://github.com/SerenityOS/serenity/pull/20206 Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/trflynn89 Reviewed-by: https://github.com/vkoskiv
@ -7,6 +7,7 @@ serenity_component(
|
||||
|
||||
compile_gml(FileManagerWindow.gml FileManagerWindowGML.h file_manager_window_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(PropertiesWindowFontTab.gml PropertiesWindowFontTabGML.h properties_window_font_tab_gml)
|
||||
compile_gml(PropertiesWindowGeneralTab.gml PropertiesWindowGeneralTabGML.h properties_window_general_tab_gml)
|
||||
@ -24,6 +25,7 @@ set(SOURCES
|
||||
set(GENERATED_SOURCES
|
||||
FileManagerWindowGML.h
|
||||
FileOperationProgressGML.h
|
||||
PropertiesWindowArchiveTabGML.h
|
||||
PropertiesWindowAudioTabGML.h
|
||||
PropertiesWindowFontTabGML.h
|
||||
PropertiesWindowGeneralTabGML.h
|
||||
@ -31,4 +33,4 @@ set(GENERATED_SOURCES
|
||||
)
|
||||
|
||||
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 <AK/GenericShorthands.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/NumberFormat.h>
|
||||
#include <Applications/FileManager/DirectoryView.h>
|
||||
#include <Applications/FileManager/PropertiesWindowArchiveTabGML.h>
|
||||
#include <Applications/FileManager/PropertiesWindowAudioTabGML.h>
|
||||
#include <Applications/FileManager/PropertiesWindowFontTabGML.h>
|
||||
#include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
|
||||
#include <Applications/FileManager/PropertiesWindowImageTabGML.h>
|
||||
#include <LibArchive/Zip.h>
|
||||
#include <LibAudio/Loader.h>
|
||||
#include <LibCore/Directory.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 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))
|
||||
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 {};
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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_general_tab(GUI::TabWidget&, bool disable_rename);
|
||||
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_font_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…
Reference in New Issue
Block a user