mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 19:45:41 -04:00
[gtk] Ext2AttrView: Display the compression algorithm, if available.
XAttrView: Set the compression algorithm in Ext2AttrView. We're using Ext2AttrView because most Linux file systems that support compression also support Ext2-style attributes.
This commit is contained in:
parent
6a425154a2
commit
88b9552cca
@ -15,11 +15,15 @@
|
||||
// Ext2AttrData
|
||||
#include "librpfile/xattr/Ext2AttrData.h"
|
||||
|
||||
// librpfile
|
||||
using LibRpFile::XAttrReader;
|
||||
|
||||
/* Property identifiers */
|
||||
typedef enum {
|
||||
PROP_0,
|
||||
|
||||
PROP_FLAGS,
|
||||
PROP_ZALGORITHM,
|
||||
|
||||
PROP_LAST
|
||||
} RpExt2AttrViewPropID;
|
||||
@ -67,6 +71,7 @@ struct _RpExt2AttrView {
|
||||
super __parent__;
|
||||
|
||||
int flags;
|
||||
XAttrReader::ZAlgorithm zAlgorithm;
|
||||
|
||||
// Inhibit checkbox toggling while updating.
|
||||
gboolean inhibit_checkbox_no_toggle;
|
||||
@ -74,6 +79,9 @@ struct _RpExt2AttrView {
|
||||
// lsattr-style attributes label
|
||||
GtkWidget *lblLsAttr;
|
||||
|
||||
// Compression label
|
||||
GtkWidget *lblCompression;
|
||||
|
||||
// See enum CheckboxID and checkboxInfo.
|
||||
GtkWidget *checkBoxes[EXT2_ATTR_CHECKBOX_MAX];
|
||||
};
|
||||
@ -103,6 +111,12 @@ rp_ext2_attr_view_class_init(RpExt2AttrViewClass *klass)
|
||||
G_MININT, G_MAXINT, 0,
|
||||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
|
||||
|
||||
// TODO: Enum?
|
||||
props[PROP_ZALGORITHM] = g_param_spec_uint(
|
||||
"zalgorithm", "zAlgorithm", "Compression algorithm",
|
||||
0, G_MAXUINT, 0,
|
||||
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
|
||||
|
||||
// Install the properties.
|
||||
g_object_class_install_properties(gobject_class, PROP_LAST, props);
|
||||
}
|
||||
@ -129,6 +143,10 @@ rp_ext2_attr_view_init(RpExt2AttrView *widget)
|
||||
gtk_label_set_attributes(GTK_LABEL(widget->lblLsAttr), attr_lst);
|
||||
pango_attr_list_unref(attr_lst);
|
||||
|
||||
// Compression
|
||||
widget->lblCompression = gtk_label_new("Compression:");
|
||||
gtk_widget_set_name(widget->lblCompression, "lblCompression");
|
||||
|
||||
// Checkboxes
|
||||
int col = 0, row = 0;
|
||||
static const int col_count = 4;
|
||||
@ -179,17 +197,26 @@ rp_ext2_attr_view_init(RpExt2AttrView *widget)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: lblCompression should be right-aligned.
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
gtk_box_append(GTK_BOX(hboxLsAttr), lblLsAttrDesc);
|
||||
gtk_box_append(GTK_BOX(hboxLsAttr), widget->lblLsAttr);
|
||||
gtk_box_append(GTK_BOX(hboxLsAttr), widget->lblCompression);
|
||||
gtk_box_append(GTK_BOX(widget), hboxLsAttr);
|
||||
gtk_box_append(GTK_BOX(widget), gridCheckboxes);
|
||||
|
||||
// Don't show lblCompression by default.
|
||||
gtk_widget_set_visible(widget->lblCompression, false);
|
||||
#else /* !GTK_CHECK_VERSION(4, 0, 0) */
|
||||
gtk_box_pack_start(GTK_BOX(hboxLsAttr), lblLsAttrDesc, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hboxLsAttr), widget->lblLsAttr, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(widget), hboxLsAttr, FALSE, FALSE, 0);
|
||||
gtk_box_pack_end(GTK_BOX(hboxLsAttr), widget->lblCompression, FALSE, FALSE, 0);
|
||||
gtk_widget_show_all(hboxLsAttr);
|
||||
|
||||
// Don't show lblCompression by default.
|
||||
gtk_widget_hide(widget->lblCompression);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(widget), gridCheckboxes, FALSE, FALSE, 0);
|
||||
gtk_widget_show_all(gridCheckboxes);
|
||||
#endif /* GTK_CHECK_VERSION(4, 0, 0) */
|
||||
@ -317,6 +344,38 @@ rp_ext2_attr_view_update_flags_display(RpExt2AttrView *widget)
|
||||
rp_ext2_attr_view_update_flags_checkboxes(widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the compression algorithm label.
|
||||
*/
|
||||
static void
|
||||
rp_ext2_attr_view_update_zAlgorithm_label(RpExt2AttrView *widget)
|
||||
{
|
||||
const char *s_alg;
|
||||
switch (widget->zAlgorithm) {
|
||||
default:
|
||||
case XAttrReader::ZAlgorithm::None:
|
||||
// No compression...
|
||||
s_alg = nullptr;
|
||||
break;
|
||||
case XAttrReader::ZAlgorithm::ZLIB:
|
||||
s_alg = "zlib";
|
||||
break;
|
||||
case XAttrReader::ZAlgorithm::LZO:
|
||||
s_alg = "lzo";
|
||||
break;
|
||||
case XAttrReader::ZAlgorithm::ZSTD:
|
||||
s_alg = "zstd";
|
||||
break;
|
||||
}
|
||||
|
||||
if (s_alg) {
|
||||
gtk_label_set_text(GTK_LABEL(widget->lblCompression), fmt::format(FSTR("Compression: {:s}"), s_alg).c_str());
|
||||
gtk_widget_set_visible(widget->lblCompression, true);
|
||||
} else {
|
||||
gtk_widget_set_visible(widget->lblCompression, false);
|
||||
}
|
||||
}
|
||||
|
||||
/** Property accessors / mutators **/
|
||||
|
||||
/**
|
||||
@ -363,6 +422,44 @@ rp_ext2_attr_view_clear_flags(RpExt2AttrView *widget)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current compression algorithm.
|
||||
* @return Compression algorithm
|
||||
*/
|
||||
void
|
||||
rp_ext2_attr_view_set_zAlgorithm(RpExt2AttrView *widget, XAttrReader::ZAlgorithm zAlgorithm)
|
||||
{
|
||||
if (widget->zAlgorithm != zAlgorithm) {
|
||||
widget->zAlgorithm = zAlgorithm;
|
||||
rp_ext2_attr_view_update_zAlgorithm_label(widget);
|
||||
g_object_notify_by_pspec(G_OBJECT(widget), props[PROP_ZALGORITHM]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current compression algorithm.
|
||||
* @param zAlgorithm Compression algorithm
|
||||
*/
|
||||
XAttrReader::ZAlgorithm
|
||||
rp_ext2_attr_view_get_zAlgorithm(RpExt2AttrView *widget)
|
||||
{
|
||||
g_return_val_if_fail(RP_IS_EXT2_ATTR_VIEW(widget), XAttrReader::ZAlgorithm::None);
|
||||
return widget->zAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current compression algorithm.
|
||||
*/
|
||||
void
|
||||
rp_ext2_attr_view_clear_zAlgorithm(RpExt2AttrView *widget)
|
||||
{
|
||||
if (widget->zAlgorithm != XAttrReader::ZAlgorithm::None) {
|
||||
widget->zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
rp_ext2_attr_view_update_zAlgorithm_label(widget);
|
||||
g_object_notify_by_pspec(G_OBJECT(widget), props[PROP_ZALGORITHM]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Signal handlers **/
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,10 @@
|
||||
|
||||
#include "gtk-compat.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# include "librpfile/xattr/XAttrReader.hpp"
|
||||
#endif /* __cplusplus */
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define RP_TYPE_EXT2_ATTR_VIEW (rp_ext2_attr_view_get_type())
|
||||
@ -34,3 +38,9 @@ int rp_ext2_attr_view_get_flags (RpExt2AttrView *widget);
|
||||
void rp_ext2_attr_view_clear_flags (RpExt2AttrView *widget);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
void rp_ext2_attr_view_set_zAlgorithm (RpExt2AttrView *widget, LibRpFile::XAttrReader::ZAlgorithm zAlgorithm);
|
||||
LibRpFile::XAttrReader::ZAlgorithm rp_ext2_attr_view_get_zAlgorithm (RpExt2AttrView *widget);
|
||||
void rp_ext2_attr_view_clear_zAlgorithm (RpExt2AttrView *widget);
|
||||
#endif /* __cplusplus */
|
||||
|
@ -308,7 +308,11 @@ rp_xattr_view_load_ext2_attrs(RpXAttrView *widget)
|
||||
// If we do have attributes, we'll show the widgets there.
|
||||
gtk_widget_set_visible(widget->fraExt2Attributes, false);
|
||||
|
||||
if (!widget->xattrReader->hasExt2Attributes()) {
|
||||
// NOTE: Showing the compression algorithm in Ext2AttrView,
|
||||
// since most file systems that support compression support
|
||||
// Ext2-style attributes.
|
||||
if (!widget->xattrReader->hasExt2Attributes() &&
|
||||
!widget->xattrReader->hasZAlgorithm()) {
|
||||
// No Ext2 attributes.
|
||||
return -ENOENT;
|
||||
}
|
||||
@ -316,6 +320,8 @@ rp_xattr_view_load_ext2_attrs(RpXAttrView *widget)
|
||||
// We have Ext2 attributes.
|
||||
rp_ext2_attr_view_set_flags(RP_EXT2_ATTR_VIEW(widget->ext2AttrView),
|
||||
widget->xattrReader->ext2Attributes());
|
||||
rp_ext2_attr_view_set_zAlgorithm(RP_EXT2_ATTR_VIEW(widget->ext2AttrView),
|
||||
widget->xattrReader->zAlgorithm());
|
||||
gtk_widget_set_visible(widget->fraExt2Attributes, true);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user