Skip to content

Commit

Permalink
Refactor GlobalSettings.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
Photon89 committed Aug 19, 2024
1 parent 17e869f commit 9cc0c83
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 78 deletions.
10 changes: 5 additions & 5 deletions bin/shutter
Original file line number Diff line number Diff line change
Expand Up @@ -2841,15 +2841,15 @@ sub STARTUP {
$sc->set_globalsettings_object($settings);
}
if ($combobox_type->get_active_text =~ /jpeg/) {
$settings->set_jpg_quality($scale->get_value);
$settings->set_image_quality("jpg", $scale->get_value);
} elsif ($combobox_type->get_active_text =~ /jpg/) {
$settings->set_jpg_quality($scale->get_value);
$settings->set_image_quality("jpg", $scale->get_value);
} elsif ($combobox_type->get_active_text =~ /png/) {
$settings->set_png_quality($scale->get_value);
$settings->set_image_quality("png", $scale->get_value);
} elsif ($combobox_type->get_active_text =~ /webp/) {
$settings->set_webp_quality($scale->get_value);
$settings->set_image_quality("webp", $scale->get_value);
} elsif ($combobox_type->get_active_text =~ /avif/) {
$settings->set_avif_quality($scale->get_value);
$settings->set_image_quality("avif", $scale->get_value);
} else {
$settings->clear_quality_settings();
}
Expand Down
94 changes: 29 additions & 65 deletions share/shutter/resources/modules/Shutter/App/GlobalSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,89 +37,53 @@ sub new {

my $self = {};

$self->{_png_quality} = undef;
$self->{_jpg_quality} = undef;
$self->{_webp_quality} = undef;
$self->{_avif_quality} = undef;

$self->{_image_quality} = (
"png" => undef,
"jpg" => undef,
"webp" => undef,
"avif" => undef
);

$self->{_default_image_quality} = (
"png" => 9,
"jpg" => 90,
"webp" => 98,
"avif" => 68
);

bless $self, $class;
return $self;
}

#getter / setter
sub get_png_quality {
my $self = shift;
if (defined $self->{_png_quality}) {
return $self->{_png_quality};
} else {
return 9;
}
}

sub get_jpg_quality {
my $self = shift;
if (defined $self->{_jpg_quality}) {
return $self->{_jpg_quality};
} else {
return 90;
}
}

sub get_webp_quality {
my $self = shift;
if (defined $self->{_webp_quality}) {
return $self->{_webp_quality};
} else {
return 98;
}
}

sub get_avif_quality {
sub get_image_quality {
my $self = shift;
if (defined $self->{_avif_quality}) {
return $self->{_avif_quality};
my $format = shift;
if (defined $self->{_image_quality}{$format}) {
return $self->{_image_quality}{$format};
} else {
return 68;
}
}

sub set_png_quality {
my $self = shift;
if (@_) {
$self->{_png_quality} = shift;
}
return $self->{_png_quality};
}

sub set_jpg_quality {
my $self = shift;
if (@_) {
$self->{_jpg_quality} = shift;
}
return $self->{_jpg_quality};
}

sub set_webp_quality {
my $self = shift;
if (@_) {
$self->{_webp_quality} = shift;
return $self->{_default_image_quality}{$format};
}
return $self->{_webp_quality};
}

sub set_avif_quality {
sub set_image_quality {
my $self = shift;
my $format = shift;
if (@_) {
$self->{_avif_quality} = shift;
$self->{_image_quality}{$format} = shift;
}
return $self->{_avif_quality};
return $self->{_image_quality}{$format};
}

sub clear_quality_settings {
my $self = shift;
$self->{_jpg_quality} = undef;
$self->{_png_quality} = undef;
$self->{_webp_quality} = undef;
$self->{_image_quality} = (
"png" => undef,
"jpg" => undef,
"webp" => undef,
"avif" => undef
);
}

1;
16 changes: 8 additions & 8 deletions share/shutter/resources/modules/Shutter/Pixbuf/Save.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ sub save_pixbuf_to_file {

#get quality value from settings if not set
if (my $settings = $self->{_common}->get_globalsettings_object) {
if (defined $settings->get_jpg_quality) {
$quality = $settings->get_jpg_quality;
if (defined $settings->set_image_quality("jpg")) {
$quality = $settings->set_image_quality("jpg");
} else {
$quality = 90;
}
Expand Down Expand Up @@ -118,8 +118,8 @@ sub save_pixbuf_to_file {

#get quality value from settings if not set
if (my $settings = $self->{_common}->get_globalsettings_object) {
if (defined $settings->get_png_quality) {
$quality = $settings->get_png_quality;
if (defined $settings->set_image_quality("png")) {

This comment has been minimized.

Copy link
@DarthGandalf

DarthGandalf Aug 19, 2024

Member

get?

This comment has been minimized.

Copy link
@Photon89

Photon89 Aug 19, 2024

Author Member

Woah, luckily you caught it, thanks! Fixed!

$quality = $settings->set_image_quality("png");
} else {
$quality = 9;
}
Expand All @@ -136,8 +136,8 @@ sub save_pixbuf_to_file {

#get quality value from settings if not set
if (my $settings = $self->{_common}->get_globalsettings_object) {
if (defined $settings->get_webp_quality) {
$quality = $settings->get_webp_quality;
if (defined $settings->set_image_quality("webp")) {
$quality = $settings->set_image_quality("webp");
} else {
$quality = 98;
}
Expand All @@ -154,8 +154,8 @@ sub save_pixbuf_to_file {

#get quality value from settings if not set
if (my $settings = $self->{_common}->get_globalsettings_object) {
if (defined $settings->get_avif_quality) {
$quality = $settings->get_avif_quality;
if (defined $settings->set_image_quality("avif")) {
$quality = $settings->set_image_quality("avif");
} else {
$quality = 68;
}
Expand Down

0 comments on commit 9cc0c83

Please sign in to comment.