--- /usr/libexec/draksnapshot-config 2022-09-17 14:55:35.917267678 +0200 +++ /usr/libexec/draksnapshot-config.new 2022-09-17 14:55:16.497561950 +0200 @@ -42,12 +42,13 @@ ######### read config +my $default_backup_directory="~/not_existing_path"; my @ordered_intervals = qw(hourly daily weekly monthly); my %default_values = ( - "hourly" => 6, + "hourly" => 23, "daily" => 7, "weekly" => 4, - "monthly" => "", + "monthly" => "12", ); my ($backup_list, $exclude_list) = map { @@ -65,18 +66,24 @@ my %default_intervals = ( map { if (my ($type, $retain) = /^retain\s*(\S*)\s*(\S*)/) { + if (($type eq "hourly") || ($type eq "daily") || ($type eq "weekly") || ($type eq "monthly") ){ $interval_exists = 1; $type => $retain; + } } } grep { /^retain\s/ } cat_($config_file) ); -if ($interval_exists) { - # If there is some interval in the config file, keep them as is - $default_intervals{$_} ||= 0 foreach @ordered_intervals; -} else { +#if ($interval_exists) { +# # If there is some interval in the config file, keep them as is +# $default_intervals{$_} ||= 0 foreach @ordered_intervals; +#} else { # Else we had broken it (#58534) so restore defaults - %default_intervals = %default_values; +# %default_intervals = %default_values; +#} +if (!$interval_exists) +{ +%default_intervals= ('hourly',23, 'daily',7 ,'weekly',4, 'monthly',12); } ######### GUI @@ -106,7 +113,15 @@ ######### menus end -my $where; +my %interval_titles = ( + 'hourly' => N("Hourly snapshots"), + 'daily' => N("Daily snapshots"), + 'weekly' => N("Weekly snapshots"), + 'monthly' => N("Monthly snapshots"), +); + + +my (%entries, $where); # if not configured, just default where will be mounted the discs by HAL: if (!$backup_directory || $::testing) { @@ -117,7 +132,7 @@ } if (!$backup_directory) #not defined either by common.pm, rsnapshot.conf, or hal/udisks2 (current situation); Set a dummy path to be changed by user { - $backup_directory="~/not_existing_path"; + $backup_directory="$default_backup_directory"; } } @@ -176,7 +191,17 @@ ), ]), - +if_(1, 0, gtknew('Title2', label => N("Number of snapshots to keep stored")), + 0, gtknew('Table', col_spacings => 10, row_spacings => 5, homogeneous => 1, children => [ + map { + [ + gtknew('Label_Left', text => $interval_titles{$_}), + $entries{$_} = gtknew('SpinButton', value => $default_intervals{$_}, lower => 2, upper => 100, + tip => N("The number of snapshots for this type of interval (\"%s\") that will be stored", $_) + ) + ]; + } @ordered_intervals + ])), 0, gtknew('HButtonBox', layout => 'start', border_width => 5, spacing => 5, children_loose => [ # does not exist before 2009.0, if you need it, you can revert to Button type if needed ( CS4 ) $button = gtknew('Install_Button', @@ -185,7 +210,7 @@ ]), 0, gtknew('HButtonBox', layout => 'end', border_width => 5, spacing => 5, children_loose => [ gtknew('Button', text => N("Restore"), clicked => \&restore), - gtknew('Button', text => N("Apply"), clicked => \&save), + gtknew('Button', text => N("Apply"), clicked => \&verif), gtknew('Button', text => $::isEmbedded ? N("Cancel") : N("Close"), clicked => sub { quit() }) ]) ]) @@ -290,9 +315,43 @@ } +# Verify parameters are valid for rsnapshot and if yes, launch the save function + +sub verif() +{ +my $error_verif=0; +my $error_verif_cause=""; + my @retain = map{ my $val = $entries{$_}->get_text} @ordered_intervals; + if ($where->get_text eq $default_backup_directory ) { + $error_verif=1; + $error_verif_cause=N("- Backup directory is the default one ($default_backup_directory). Please assign a valid one \n"); + } +if (@retain[0] < 2) +{ +$error_verif=1; +$error_verif_cause=$error_verif_cause.N("- The minimum value for ").@ordered_intervals[0].N(" can't be less than 2 \n"); +} +for (my $l=1;$l < scalar @retain;$l=$l+1) +{ +if (@retain[$l] < 1) +{ +$error_verif=1; +$error_verif_cause=$error_verif_cause.N("- The minimum value for ").@ordered_intervals[$l].N(" can't be less than 1 \n"); +} +} +if ($error_verif == 1) +{ +err_dialog(N("Warning"),N("The following error(s) have been encountered \n \n").$error_verif_cause." \n"); +} +else +{ +&save; +} +} + sub save() { save_keyword('retain', map { - my $val = $default_intervals{$_}; + my $val = $entries{$_}->get_text; if_($val, join("\t", 'retain', $_, $val)); } @ordered_intervals);