From fab3db99c09a2b452fb9cc9da4d9201a393ec7ea Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 12 Apr 2010 14:23:11 +0000 Subject: added gui error callback (not working yet) added progress callback to clear carts diff --git a/rhimport b/rhimport index 15a030b..e25a1d3 100755 --- a/rhimport +++ b/rhimport @@ -192,6 +192,26 @@ my $gui_progress_cb = sub { Gtk2::Gdk->flush; }; +my $gui_error_cb = sub { + my ($text) = @_; + + if(!$guixml) { + print STDERR "no GUI definition found!\n"; + exit 2; + } + $text . "\n\nVorgang abbrechen?"; + my $parent_window = $guixml->get_widget('appwin'); + my $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent', + 'error', 'yes-no', $text); + $dialog->set_default_response ('no'); + my $response = $dialog->run; + $dialog->destroy; + + return 0 if($response eq 'yes'); + + return 1; +}; + sub start_import_gui() { if(!$guixml) { @@ -224,14 +244,14 @@ sub start_import_gui() if($POOL) { my $cb_clear_carts = $guixml->get_widget('cb_clear_carts'); if($cb_clear_carts->get_active) { - rhimport::clear_carts($dbh, $group, $to_cart); + rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb); } - $ret = rhimport::import_playlist($file, $dropbox, $gui_progress_cb); + $ret = rhimport::import_playlist($file, $dropbox, $gui_progress_cb, $gui_error_cb); } else { - $ret = rhimport::import_single($file, $dropbox, $gui_progress_cb); + $ret = rhimport::import_single($file, $dropbox, $gui_progress_cb, $gui_error_cb); } - if($ret) { + if(!$ret) { $l_status->set_label("Fehler beim Importieren"); } diff --git a/rhimport.pm b/rhimport.pm index c970bcf..2d2f190 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -33,7 +33,7 @@ my $ssh_host = "airplay"; my $ssh_user = "rhimport"; my $ssh_key_file = "id_dsa"; my $ssh_dir = "/programm/.rhimport"; -my $rdimport_wrapper = "/usr/local/bin/dropbox_newfile.pl"; +my $rdimport_wrapper = "/usr/local/bin/dropbox_newfile.pl1"; sub get_dropboxes { @@ -102,7 +102,7 @@ sub get_used_carts sub clear_carts { - my ($dbh, $group, $to_cart) = @_; + my ($dbh, $group, $to_cart, $progress_cb) = @_; my ($low_cart, $high_cart) = ($to_cart, $to_cart); if($to_cart == 0) { @@ -112,6 +112,8 @@ sub clear_carts print "clearing Carts $low_cart - $high_cart\n"; my $cart = $low_cart; while($cart <= $high_cart) { + $progress_cb->($cart - $low_cart, $high_cart + 1 - $low_cart, "deleting $cart") if($progress_cb); + my $sql = qq{select CUT_NAME from CUTS where CART_NUMBER='$cart';}; my $sth = $dbh->prepare($sql); $sth->execute(); @@ -130,7 +132,7 @@ sub clear_carts $sth = $dbh->prepare($sql); $sth->execute(); $sth->finish(); - + $cart++; } } @@ -163,7 +165,11 @@ sub import_playlist $cnt++; } - $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!") if($progress_cb); + if($ret) { + $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!") if($progress_cb); + } else { + $progress_cb->($cnt, $num_entries, "Import abgebrochen!") if($progress_cb); + } return $ret; } @@ -174,7 +180,11 @@ sub import_single print "Starting import from file $file to $dropbox\n"; $progress_cb->(0, 1, $file) if($progress_cb); my $ret = import_file($file, $dropbox, $error_cb); - $progress_cb->(1, 1, "Import abgeschlossen!") if($progress_cb); + if($ret) { + $progress_cb->(1, 1, "Import abgeschlossen!") if($progress_cb); + } else { + $progress_cb->(0, 1, "Import abgebrochen!") if($progress_cb); + } return $ret; } -- cgit v0.10.2