summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-03-24 14:21:08 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-03-24 14:21:08 (GMT)
commitd88725966786bce05a961438c673b62d86ea64ce (patch)
tree889d4f7b73fbf1b2ca9bc325026cca9014f6a023
parent5b52de65b47f868e0b3224e06e766116afc81b39 (diff)
added progress bar
-rw-r--r--gui_callbacks.pm14
-rwxr-xr-xrhimport55
-rw-r--r--rhimport.glade2
-rw-r--r--rhimport.pm41
4 files changed, 96 insertions, 16 deletions
diff --git a/gui_callbacks.pm b/gui_callbacks.pm
index 917534f..10d3881 100644
--- a/gui_callbacks.pm
+++ b/gui_callbacks.pm
@@ -53,4 +53,18 @@ sub on_b_showcarts_clicked
::show_used_carts_gui();
}
+sub on_co_dropbox_changed
+{
+ my ($widget, $data) = @_;
+
+ ::clear_status_gui();
+}
+
+sub on_filechooser_selection_changed
+{
+ my ($widget, $data) = @_;
+
+ ::clear_status_gui();
+}
+
1;
diff --git a/rhimport b/rhimport
index 26cea0f..5f5dfa0 100755
--- a/rhimport
+++ b/rhimport
@@ -48,18 +48,20 @@ GetOptions ("help!" => \$HELP,
"keep-carts!" => \$KEEPCARTS,
"dropbox=s" => \$DROPBOX,
"list-allowed!" => \$LISTALLOWED,
- );
+ ) or die();
if($HELP) {
print << "EOF";
usage: $0 --file <audio or playlist file> --pool --keep-carts --dropbox <path to dropbox> --list-allowed
+When called with no file and/or no dropbox the GUI gets started to select the missing parameters
+
options:
- --file the media file or playlist to import
- --pool pool mode, import media files referneced by playlist
- --keep-carts in pool mode keep existing carts instead of clearing them before import
- --dropbox the path to the dropbox to use
- --list-allowed list allowed dropboxes and exit
+ -f | --file the media file or playlist to import
+ -p | --pool pool mode, import media files referneced by playlist
+ -k | --keep-carts in pool mode keep existing carts instead of clearing them before import
+ -d | --dropbox the path to the dropbox to use
+ -l | --list-allowed list allowed dropboxes and exit
EOF
exit;
@@ -133,6 +135,22 @@ sub toggle_mode_gui()
}
}
+my $gui_progress_cb = sub {
+ my ($elapsed, $max, $text) = @_;
+
+ if(!$guixml) {
+ print STDERR "no GUI definition found!\n";
+ exit 0;
+ }
+ my $progressbar = $guixml->get_widget('progressbar');
+ $progressbar->set_text("($elapsed/$max) $text");
+ $progressbar->set_fraction($elapsed/$max);
+ while (Gtk2->events_pending) {
+ Gtk2->main_iteration;
+ }
+ Gtk2::Gdk->flush;
+};
+
sub start_import_gui()
{
if(!$guixml) {
@@ -166,9 +184,13 @@ sub start_import_gui()
if($cb_clear_carts->get_active) {
rhimport::clear_carts($dbh, $group);
}
- $ret = rhimport::import_playlist($file, $dropbox);
+ $ret = rhimport::import_playlist($file, $dropbox, $gui_progress_cb);
} else {
- $ret = rhimport::import_single($file, $dropbox);
+ $ret = rhimport::import_single($file, $dropbox, $gui_progress_cb);
+ }
+
+ if($ret) {
+ $l_status->set_label("Fehler beim Importieren");
}
return $ret;
@@ -199,6 +221,21 @@ sub show_used_carts_gui()
# $usedcartswin->show;
}
+sub clear_status_gui()
+{
+ if(!$guixml) {
+ print STDERR "no GUI definition found!\n";
+ exit 0;
+ }
+
+ my $l_status = $guixml->get_widget('l_status');
+ $l_status->set_label("");
+
+ my $progressbar = $guixml->get_widget('progressbar');
+ $progressbar->set_text("");
+ $progressbar->set_fraction(0);
+}
+
if(!$FILE || !$DROPBOX) {
Gtk2->init;
@@ -259,7 +296,7 @@ for my $href (@allowed_dbs) {
}
if($group eq '') {
- print "Dropbox not found or not allowed";
+ print "Dropbox not found or not allowed\n";
exit 1
}
diff --git a/rhimport.glade b/rhimport.glade
index ae63bf8..dfc15a0 100644
--- a/rhimport.glade
+++ b/rhimport.glade
@@ -107,6 +107,7 @@
<child>
<widget class="GtkComboBox" id="co_dropbox">
<property name="visible">True</property>
+ <signal name="changed" handler="on_co_dropbox_changed"/>
</widget>
<packing>
<property name="position">0</property>
@@ -151,6 +152,7 @@
<property name="orientation">vertical</property>
<property name="use_preview_label">False</property>
<property name="preview_widget_active">False</property>
+ <signal name="selection_changed" handler="on_filechooser_selection_changed"/>
</widget>
<packing>
<property name="position">5</property>
diff --git a/rhimport.pm b/rhimport.pm
index 4db154c..2541660 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -128,27 +128,54 @@ sub clear_carts
sub import_playlist
{
- my ($playlist, $dropbox) = @_;
-
- print "Starting import from playlist $playlist to $dropbox\n";
+ my ($playlist, $dropbox, $progress_cb) = @_;
+ print "Starting import from playlist $playlist to $dropbox";
+ my @entries;
open (FILE, $playlist) or die "can't open playlist $playlist: $!";
while (my $entry = <FILE>) {
next if($entry =~ /^#/);
next if($entry =~ /^\s/);
$entry =~ s/\n$//;
- import_file($entry, $dropbox);
+ push @entries, $entry;
}
close(FILE);
+ my $num_entries = scalar(@entries);
+ print " ($num_entries Files in list)\n";
+
+ my $cnt = 0;
+ my $ret = 0;
+ for my $entry ( @entries ) {
+ if($progress_cb) {
+ $progress_cb->($cnt, $num_entries, $entry);
+ }
- return 0;
+ $ret = import_file($entry, $dropbox);
+ last if($ret != 0);
+
+ $cnt++;
+ }
+
+ if($progress_cb) {
+ $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!");
+ }
+
+ return $ret;
}
sub import_single
{
- my ($file, $dropbox) = @_;
+ my ($file, $dropbox, $progress_cb) = @_;
print "Starting import from file $file to $dropbox\n";
- import_file($file, $dropbox);
+ if($progress_cb) {
+ $progress_cb->(0, 1, $file);
+ }
+ my $ret = import_file($file, $dropbox, $progress_cb);
+
+ if($progress_cb) {
+ $progress_cb->(1, 1, "Import abgeschlossen!");
+ }
+ return $ret;
}
sub import_file