Improving logging.
This commit is contained in:
parent
37ea763a38
commit
99bfe816a1
|
@ -18,6 +18,8 @@ use GEmeTool::Config;
|
|||
|
||||
our @EXPORT_OK = qw/logger/;
|
||||
|
||||
my %triggers_on_message;
|
||||
|
||||
sub logger {
|
||||
return GEmeTool::Log->new;
|
||||
}
|
||||
|
@ -38,8 +40,11 @@ INSERT INTO logs
|
|||
backup_output_file)
|
||||
VALUES (?, datetime('now'), ?, ?, ?, ?, ?);');
|
||||
EOF
|
||||
return $db->do( $insert, {}, $uuid, $msg, $input_file, $output_file,
|
||||
$db->do( $insert, {}, $uuid, $msg, $input_file, $output_file,
|
||||
$input_file_backup, $output_file_backup );
|
||||
for my $key (keys %triggers_on_message) {
|
||||
$triggers_on_message{$key}->();
|
||||
}
|
||||
}
|
||||
|
||||
sub backup_files {
|
||||
|
@ -89,4 +94,16 @@ EOF
|
|||
my $results = $db->selectall_arrayref($query, {Slice => {}});
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub del_on_message {
|
||||
my $self = shift;
|
||||
my $func = shift;
|
||||
delete $triggers_on_message{$func};
|
||||
}
|
||||
|
||||
sub add_on_message {
|
||||
my $self = shift;
|
||||
my $func = shift;
|
||||
$triggers_on_message{$func} = $func;
|
||||
}
|
||||
1;
|
||||
|
|
|
@ -38,7 +38,18 @@ has main_window => (
|
|||
required => 1,
|
||||
);
|
||||
|
||||
has _win => ( is => 'rw', );
|
||||
has _win => ( is => 'rw', );
|
||||
has _func => ( is => 'rw' );
|
||||
|
||||
sub subscribe_logs {
|
||||
my $self = shift;
|
||||
my $log = GEmeTool::Log->new;
|
||||
my $func = sub {
|
||||
$self->fill_logs_win;
|
||||
};
|
||||
$log->add_on_message($func);
|
||||
$self->_func($func);
|
||||
}
|
||||
|
||||
sub start {
|
||||
my $self = shift;
|
||||
|
@ -47,9 +58,22 @@ sub start {
|
|||
$win->set_title('GEmeTool Log Viewer');
|
||||
$win->set_default_size( 600, 600 );
|
||||
$self->fill_logs_win;
|
||||
$self->subscribe_logs;
|
||||
$win->signal_connect(
|
||||
'destroy',
|
||||
sub {
|
||||
$self->unsubscribe_logs;
|
||||
}
|
||||
);
|
||||
$win->present;
|
||||
}
|
||||
|
||||
sub unsubscribe_logs {
|
||||
my $self = shift;
|
||||
my $log = GEmeTool::Log->new;
|
||||
$log->del_on_message( $self->_func );
|
||||
}
|
||||
|
||||
sub fill_logs_win {
|
||||
my $self = shift;
|
||||
my $win = $self->_win;
|
||||
|
@ -83,6 +107,11 @@ sub fill_logs_win {
|
|||
my $scroll = Gtk4::ScrolledWindow->new;
|
||||
$scroll->set_propagate_natural_width(1);
|
||||
$scroll->set_policy( 'never', 'automatic' );
|
||||
$grid_log->set_row_spacing(30);
|
||||
$grid_log->set_margin_top(30);
|
||||
$grid_log->set_margin_bottom(30);
|
||||
$grid_log->set_margin_start(30);
|
||||
$grid_log->set_margin_end(30);
|
||||
$scroll->set_child($grid_log);
|
||||
$win->set_child($scroll);
|
||||
}
|
||||
|
@ -116,33 +145,39 @@ sub open_save {
|
|||
}
|
||||
|
||||
sub offer_to_edit_the_new_file {
|
||||
my $self = shift;
|
||||
my $file = shift;
|
||||
my $self = shift;
|
||||
my $file = shift;
|
||||
my $main_window = $self->main_window;
|
||||
my $confirm = Gtk4::Window->new;
|
||||
my $box_window = Gtk4::Box->new('vertical', 30);
|
||||
my $label_question = Gtk4::Label->new("Do you want to open the restored file?");
|
||||
my $label_warning = Gtk4::Label->new("Any unsaved changes in the save editor will be lost forever");
|
||||
my $box_options = Gtk4::Box->new('horizontal', 0);
|
||||
my $cancel_button = Gtk4::Button->new_with_label('Do nothing');
|
||||
my $confirm = Gtk4::Window->new;
|
||||
my $box_window = Gtk4::Box->new( 'vertical', 30 );
|
||||
my $label_question =
|
||||
Gtk4::Label->new("Do you want to open the restored file?");
|
||||
my $label_warning = Gtk4::Label->new(
|
||||
"Any unsaved changes in the save editor will be lost forever");
|
||||
my $box_options = Gtk4::Box->new( 'horizontal', 0 );
|
||||
my $cancel_button = Gtk4::Button->new_with_label('Do nothing');
|
||||
my $confirm_button = Gtk4::Button->new_with_label('Load new file');
|
||||
|
||||
$box_options->set_property('hexpand', 1);
|
||||
$cancel_button->set_property('halign', 'start');
|
||||
$confirm_button->set_property('halign', 'end');
|
||||
$confirm_button->set_property('hexpand', 1);
|
||||
$box_options->set_property( 'hexpand', 1 );
|
||||
$cancel_button->set_property( 'halign', 'start' );
|
||||
$confirm_button->set_property( 'halign', 'end' );
|
||||
$confirm_button->set_property( 'hexpand', 1 );
|
||||
|
||||
$cancel_button->signal_connect('clicked' => sub {
|
||||
$confirm->close;
|
||||
});
|
||||
$confirm_button->signal_connect('clicked' => sub {
|
||||
$main_window->open_file($file);
|
||||
$main_window->focus();
|
||||
$confirm->close;
|
||||
});
|
||||
$cancel_button->signal_connect(
|
||||
'clicked' => sub {
|
||||
$confirm->close;
|
||||
}
|
||||
);
|
||||
$confirm_button->signal_connect(
|
||||
'clicked' => sub {
|
||||
$main_window->open_file($file);
|
||||
$main_window->focus();
|
||||
$confirm->close;
|
||||
}
|
||||
);
|
||||
my $headerbar = Gtk4::HeaderBar->new;
|
||||
$headerbar->set_decoration_layout(undef);
|
||||
$headerbar->set_title_widget(Gtk4::Label->new('Open the restored file'));
|
||||
$headerbar->set_title_widget( Gtk4::Label->new('Open the restored file') );
|
||||
$confirm->set_titlebar($headerbar);
|
||||
|
||||
$box_window->append($label_question);
|
||||
|
@ -172,6 +207,7 @@ sub create_button_restore {
|
|||
$file = path($file);
|
||||
return if !-e $file;
|
||||
my $button_restore_backup = Gtk4::Button->new_with_label($restore_label);
|
||||
$button_restore_backup->set_margin_start(30);
|
||||
$button_restore_backup->signal_connect(
|
||||
clicked => sub {
|
||||
$self->open_save( $file, $dest_file );
|
||||
|
|
Loading…
Reference in New Issue