From acf31921ba70a6b8fe0219905062196575ba5547 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 24 Mar 2010 11:41:13 +0000 Subject: improved handling of ListStore better formatting for dropbox names in GUI added emptyCarts function basic m3u parsing git-svn-id: https://svn.helsinki.at/rhimport/trunk@23 7c65635b-ec39-4f67-a626-873dbafdd612 diff --git a/gui_callbacks.pm b/gui_callbacks.pm index 446094c..917534f 100644 --- a/gui_callbacks.pm +++ b/gui_callbacks.pm @@ -46,4 +46,11 @@ sub on_b_apply_clicked ::start_import_gui(); } +sub on_b_showcarts_clicked +{ + my ($widget, $data) = @_; + + ::show_used_carts_gui(); +} + 1; diff --git a/rhimport b/rhimport index c8cfd47..05fc757 100755 --- a/rhimport +++ b/rhimport @@ -38,7 +38,7 @@ my $DB = "rivendell"; my $HELP = 0; my $FILE = ""; my $POOL = 0; -my $EMPTYCARTS = 1; +my $EMPTYCARTS = 0; my $DROPBOX = ""; my $LISTALLOWED = 0; @@ -69,18 +69,7 @@ my $user = `/usr/bin/id -un`; $user =~ s/\n//; my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr"; -my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH from USER_PERMS, DROPBOXES where USER_PERMS.USER_NAME='$user' and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME;}; -my $sth = $dbh->prepare($sql); -$sth->execute(); -my @allowed_dbs; -while(my ($group, $path) = $sth->fetchrow_array()) { - $path =~ s/\/\*$//; - my $perm = {}; - $perm->{'GROUP'} = $group; - $perm->{'PATH'} = $path; - push @allowed_dbs, $perm; -} -$sth->finish(); +my @allowed_dbs = rhimport::get_dropboxes($dbh, $user); if($LISTALLOWED) { for my $href ( @allowed_dbs ) { @@ -166,12 +155,17 @@ sub start_import_gui() $filechooser->unselect_all; my $co_dropbox = $guixml->get_widget('co_dropbox'); - my $dropbox = $co_dropbox->get_active_text; + my $dropbox = $allowed_dbs[$co_dropbox->get_active]->{'PATH'}; + my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'}; $l_status->set_label("importiere von $file"); my $ret; if($POOL) { + my $cb_clear_carts = $guixml->get_widget('cb_clear_carts'); + if($cb_clear_carts->get_active) { + rhimport::empty_carts($dbh, $group); + } $ret = rhimport::import_playlist($file, $dropbox); } else { $ret = rhimport::import_file($file, $dropbox); @@ -180,7 +174,29 @@ sub start_import_gui() return $ret; } -if(!$FILE && !$DROPBOX) { +sub show_used_carts_gui() +{ + if(!$guixml) { + print STDERR "no GUI definition found!\n"; + exit 0; + } + + my $co_dropbox = $guixml->get_widget('co_dropbox'); + my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'}; + + + my $l_status = $guixml->get_widget('l_status'); + my ($low_cart, $high_cart) = rhimport::get_cart_range($dbh, $group); + $l_status->set_label("Carts: $low_cart - $high_cart"); + + +# my $usedcartswin = $guixml->get_widget('usedcartswin'); +# $usedcartswin or die "can't find Widget"; +# $usedcartswin->resize(640,480); +# $usedcartswin->show; +} + +if(!$FILE || !$DROPBOX) { Gtk2->init; $guixml = Gtk2::GladeXML->new('rhimport.glade'); @@ -188,17 +204,24 @@ if(!$FILE && !$DROPBOX) { require gui_callbacks; $guixml->signal_autoconnect_from_package('gui_callbacks'); - my $model = Gtk2::ListStore->new('Glib::String'); + my $model = Gtk2::ListStore->new('Glib::String', 'Glib::String', 'Glib::String'); for my $href ( @allowed_dbs ) { - $model->set ($model->append, 0, $href->{'PATH'}); + $model->set ($model->append, 0, $href->{'PATH'}, 1, $href->{'GROUP'}, 2, $href->{'NAME'}); } my $co_dropbox = $guixml->get_widget('co_dropbox'); $co_dropbox->set_model($model); my $renderer = Gtk2::CellRendererText->new; $co_dropbox->pack_start($renderer, 1); - $co_dropbox->add_attribute($renderer, text => 0); + $co_dropbox->add_attribute($renderer, text => 2); $co_dropbox->set_active(0); + my $cb_clear_carts = $guixml->get_widget('cb_clear_carts'); + if($EMPTYCARTS) { + $cb_clear_carts->set_active(1); + } else { + $cb_clear_carts->set_active(0); + } + if($POOL) { set_mode_playlist_gui(); } else { @@ -225,8 +248,24 @@ if($POOL) { print "will import $FILE, with user $user\n\n"; } +my $group = ''; +for my $href (@allowed_dbs) { + if($href->{'PATH'} eq $DROPBOX) { + $group = $href->{'GROUP'}; + } +} + +if($group eq '') { + print "Dropbox not found or not allowed"; + exit 1 +} + my $ret; if($POOL) { + if($EMPTYCARTS) { + rhimport::empty_carts($dbh, $group); + } + $ret = rhimport::import_playlist($FILE, $DROPBOX); } else { $ret = rhimport::import_file($FILE, $DROPBOX); diff --git a/rhimport.glade b/rhimport.glade index 0cf2e39..ae63bf8 100644 --- a/rhimport.glade +++ b/rhimport.glade @@ -102,11 +102,35 @@ - + True + + + True + + + 0 + + + + + Carts anzeigen + 130 + True + True + True + + + + False + False + 1 + + False + False 3 @@ -125,8 +149,8 @@ True vertical - False False + False 5 @@ -206,4 +230,42 @@ + + True + + + True + 0 + none + + + True + 10 + 10 + 10 + + + True + True + False + <nr>: <title> + + + + + + + True + 5 + 5 + <b>group - start:end</b> + True + + + label_item + + + + + diff --git a/rhimport.pm b/rhimport.pm index 512652b..5827bb2 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -25,12 +25,120 @@ use strict; package rhimport; +sub get_dropboxes +{ + my $dbh = shift; + my $user = shift; + + my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH from USER_PERMS, DROPBOXES where USER_PERMS.USER_NAME='$user' and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME;}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + my @allowed_dbs; + while(my ($group, $path) = $sth->fetchrow_array()) { + $path =~ s/\/\*$//; + my $name = $path; + $name =~ s/^\/programm\///; + if($name =~ /^([0-9]{2}-[A-Za-z]+)\/([0-9]{4})-([01]{4})-([0-9]{3})-(.*)$/) { + $name = "$1 - $2: $5 ($3, $4)"; + } + elsif($name =~ /^([0-9]{2}-[A-Za-z]+)\/programmvorschau_(.*)$/) { + $name = "Programmvorschau - $1 - $2"; + } + elsif($name =~ /^([0-9]{2}-[A-Za-z]+)\/jingle$/ || $name =~ /^jingles\/(.*)$/) { + $name = "Jingles - $1"; + } + elsif($name =~ /^pool\/pool(.*)$/) { + $name = "Pool - $1"; + } + elsif($name =~ /^pool\/(.*)$/) { + $name = "Pool - $1"; + } + elsif($name =~ /^sondersendungen\/(.*)$/) { + $name = "Sondersendungen - $1"; + } + my $perm = {}; + $perm->{'GROUP'} = $group; + $perm->{'PATH'} = $path; + $perm->{'NAME'} = $name; + push @allowed_dbs, $perm; + } + $sth->finish(); + + return sort { uc($a->{'NAME'}) cmp uc($b->{'NAME'}) } @allowed_dbs; +} + +sub get_cart_range +{ + my $dbh = shift; + my $group = shift; + + my $sql = qq{select DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where NAME='$group';}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + my @carts; + my ($low_cart, $high_cart) = $sth->fetchrow_array(); + $sth->finish(); + + return ($low_cart, $high_cart); +} + +sub get_used_carts +{ + my $dbh = shift; + my $group = shift; + + my ($low_cart, $high_cart) = get_cart_range($dbh, $group); + my @carts; + return @carts; +} + +sub empty_carts +{ + my $dbh = shift; + my $group = shift; + my ($low_cart, $high_cart) = get_cart_range($dbh, $group); + + my $cart = $low_cart; + while($cart <= $high_cart) { + my $sql = qq{select CUT_NAME from CUTS where CART_NUMBER='$cart';}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + while(my $cut_name = $sth->fetchrow_array()) { + my $filename = "/var/snd/$cut_name.wav"; + + ### call unlink!!! + print "deleting $filename\n"; + } + $sth->finish(); + +# my $sql = qq{delete from CUTS where CART_NUMBER='$cart';}; +# my $sth = $dbh->prepare($sql); +# $sth->execute(); +# $sth->finish(); + +# my $sql = qq{delete from CARTS where NUMBER='$cart';}; +# my $sth = $dbh->prepare($sql); +# $sth->execute(); +# $sth->finish(); + + $cart++; + } +} + sub import_playlist { my ($playlist, $dropbox) = @_; print "Starting import from playlist $playlist to $dropbox\n"; + open (FILE, $playlist) or die "can't open playlist $playlist: $!"; + while (my $entry = ) { + next if($entry =~ /^#/); + next if($entry =~ /^\s/); + $entry =~ s/\n$//; + import_file($entry, $dropbox); + } + close(FILE); return 0; } @@ -39,8 +147,11 @@ sub import_file { my ($file, $dropbox) = @_; - print "Starting import from $file to $dropbox\n"; + print "importing $file to $dropbox .. "; + $| = 1; + sleep(1); + print "Ok\n"; return 0; } -- cgit v0.10.2