diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-03-24 11:41:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-03-24 11:41:13 (GMT) |
commit | c9d2691935e2a87cb74b6f04ad6b4f561728e0c6 (patch) | |
tree | 3b2ae589421775e11657748bd97a9bc3519856bb | |
parent | f52380b976948ec2f3776d63baaf2549f4a81b49 (diff) |
improved handling of ListStore
better formatting for dropbox names in GUI
added emptyCarts function
basic m3u parsing
-rw-r--r-- | gui_callbacks.pm | 7 | ||||
-rwxr-xr-x | rhimport | 75 | ||||
-rw-r--r-- | rhimport.glade | 66 | ||||
-rw-r--r-- | rhimport.pm | 113 |
4 files changed, 240 insertions, 21 deletions
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; @@ -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 @@ </packing> </child> <child> - <widget class="GtkComboBox" id="co_dropbox"> + <widget class="GtkHBox" id="hbox_dropbox"> <property name="visible">True</property> + <child> + <widget class="GtkComboBox" id="co_dropbox"> + <property name="visible">True</property> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkButton" id="b_showcarts"> + <property name="label" translatable="yes">Carts anzeigen</property> + <property name="width_request">130</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <signal name="clicked" handler="on_b_showcarts_clicked"/> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> </widget> <packing> <property name="expand">False</property> + <property name="fill">False</property> <property name="position">3</property> </packing> </child> @@ -125,8 +149,8 @@ <widget class="GtkFileChooserWidget" id="filechooser"> <property name="visible">True</property> <property name="orientation">vertical</property> - <property name="preview_widget_active">False</property> <property name="use_preview_label">False</property> + <property name="preview_widget_active">False</property> </widget> <packing> <property name="position">5</property> @@ -206,4 +230,42 @@ </widget> </child> </widget> + <widget class="GtkWindow" id="usedcartswin"> + <property name="destroy_with_parent">True</property> + <child> + <widget class="GtkFrame" id="usedcartsframe"> + <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <widget class="GtkAlignment" id="alignment1"> + <property name="visible">True</property> + <property name="bottom_padding">10</property> + <property name="left_padding">10</property> + <property name="right_padding">10</property> + <child> + <widget class="GtkTextView" id="tf_usedcarts"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">False</property> + <property name="text" translatable="yes"><nr>: <title></property> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="l_usedcarts_main"> + <property name="visible">True</property> + <property name="xpad">5</property> + <property name="ypad">5</property> + <property name="label" translatable="yes"><b>group - start:end</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + </child> + </widget> </glade-interface> 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 = <FILE>) { + 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; } |