From d3f758cf0f0aa631a600a16b163d8dd013b5be73 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 23 Feb 2010 14:31:51 +0000 Subject: reenabled db stuff moved to new gui with mode selector git-svn-id: https://svn.helsinki.at/rhimport/trunk@20 7c65635b-ec39-4f67-a626-873dbafdd612 diff --git a/gui_callbacks.pm b/gui_callbacks.pm index dd2291d..446094c 100644 --- a/gui_callbacks.pm +++ b/gui_callbacks.pm @@ -32,11 +32,11 @@ sub on_exit Gtk2->main_quit; } -sub on_cb_pool_toggled +sub on_b_mode_clicked { my ($widget, $data) = @_; - - ::change_pool_gui(); + + ::toggle_mode_gui(); } sub on_b_apply_clicked diff --git a/rhimport b/rhimport index 82823f6..ee1f552 100755 --- a/rhimport +++ b/rhimport @@ -65,28 +65,25 @@ EOF my $user = $ENV{'USER'}; $user or die "Username not found in environment"; -# 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 $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; -push @allowed_dbs, { 'GROUP' => "groupa", 'PATH' => "/programm/dropboxA/" }; -push @allowed_dbs, { 'GROUP' => "groupb", 'PATH' => "/programm/dropboxB/" }; -push @allowed_dbs, { 'GROUP' => "groupc", 'PATH' => "/programm/dropboxC/" }; -# while(my ($group, $path) = $sth->fetchrow_array()) { -# $path =~ s/\/\*$//; -# my $perm = {}; -# $perm->{'GROUP'} = $group; -# $perm->{'PATH'} = $path; -# push @allowed_dbs, $perm; -# } -# $sth->finish(); +while(my ($group, $path) = $sth->fetchrow_array()) { + $path =~ s/\/\*$//; + my $perm = {}; + $perm->{'GROUP'} = $group; + $perm->{'PATH'} = $path; + push @allowed_dbs, $perm; +} +$sth->finish(); if($LISTALLOWED) { for my $href ( @allowed_dbs ) { print "$href->{'PATH'}\n"; } -# $dbh->disconnect(); + $dbh->disconnect(); exit 0; } @@ -95,56 +92,48 @@ if($LISTALLOWED) { my $guixml; -if(!$FILE && !$DROPBOX) { - Gtk2->init; - - $guixml = Gtk2::GladeXML->new('rhimport.glade'); - $guixml or die "can't load glade xml file"; - require gui_callbacks; - $guixml->signal_autoconnect_from_package('gui_callbacks'); - - my $model = Gtk2::ListStore->new('Glib::String'); - for my $href ( @allowed_dbs ) { - $model->set ($model->append, 0, $href->{'PATH'}); +sub set_mode_playlist_gui() +{ + if(!$guixml) { + print STDERR "no GUI definition found!\n"; + exit 0; } - 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->set_active(0); - - my $appwin = $guixml->get_widget('appwin'); - $appwin or die "can't find Main Window"; - $appwin->resize(800,600); - $appwin->show; - Gtk2->main; -# $dbh->disconnect(); - exit 0; + $POOL = 1; + my $l_mode = $guixml->get_widget('l_mode'); + $l_mode->set_label("Musik Pool"); + my $l_file_playlist = $guixml->get_widget('l_file_playlist'); + $l_file_playlist->set_label("Playlist"); + my $filter = Gtk2::FileFilter->new; + $filter->add_pattern("*.m3u"); + my $filechooser = $guixml->get_widget('filechooser'); + $filechooser->set_filter($filter); } -sub change_pool_gui() +sub set_mode_file_gui() { if(!$guixml) { print STDERR "no GUI definition found!\n"; exit 0; } - + + $POOL = 0; + my $l_mode = $guixml->get_widget('l_mode'); + $l_mode->set_label("Sendung"); my $l_file_playlist = $guixml->get_widget('l_file_playlist'); + $l_file_playlist->set_label("Datei"); + my $filter = Gtk2::FileFilter->new; + $filter->add_pattern("*"); my $filechooser = $guixml->get_widget('filechooser'); + $filechooser->set_filter($filter); +} - my $cb_pool = $guixml->get_widget('cb_pool'); - if($cb_pool->get_active) { - $l_file_playlist->set_label("Playlist"); - my $filter = Gtk2::FileFilter->new; - $filter->add_pattern("*.m3u"); - $filechooser->set_filter($filter); +sub toggle_mode_gui() +{ + if($POOL) { + set_mode_file_gui(); } else { - $l_file_playlist->set_label("File"); - my $filter = Gtk2::FileFilter->new; - $filter->add_pattern("*"); - $filechooser->set_filter($filter); + set_mode_playlist_gui(); } } @@ -170,9 +159,8 @@ sub start_import_gui() $l_status->set_label("importing from $file"); - my $cb_pool = $guixml->get_widget('cb_pool'); my $ret; - if($cb_pool->get_active) { + if($POOL) { $ret = rhimport::import_playlist($file, $dropbox); } else { $ret = rhimport::import_file($file, $dropbox); @@ -181,6 +169,41 @@ sub start_import_gui() return $ret; } +if(!$FILE && !$DROPBOX) { + Gtk2->init; + + $guixml = Gtk2::GladeXML->new('rhimport.glade'); + $guixml or die "can't load glade xml file"; + require gui_callbacks; + $guixml->signal_autoconnect_from_package('gui_callbacks'); + + my $model = Gtk2::ListStore->new('Glib::String'); + for my $href ( @allowed_dbs ) { + $model->set ($model->append, 0, $href->{'PATH'}); + } + 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->set_active(0); + + if($POOL) { + set_mode_playlist_gui(); + } else { + set_mode_file_gui(); + } + + my $appwin = $guixml->get_widget('appwin'); + $appwin or die "can't find Main Window"; + $appwin->resize(800,600); + $appwin->show; + + Gtk2->main; + $dbh->disconnect(); + exit 0; +} + ########################################### ## command line mode @@ -198,5 +221,5 @@ if($POOL) { $ret = rhimport::import_file($FILE, $DROPBOX); } -# $dbh->disconnect(); +$dbh->disconnect(); exit $ret; diff --git a/rhimport.glade b/rhimport.glade index a4d6503..00ed60e 100644 --- a/rhimport.glade +++ b/rhimport.glade @@ -28,31 +28,75 @@ vertical 4 - + True + + + True + + + 0 + + + + + Modus + 130 + True + True + True + + + + False + False + 1 + + + + + 120 + True + <b>Sendung</b> + True + + + False + False + 2 + + + + + True + + + 3 + + False False - 5 0 - + True - False - <b>Dropbox</b> - True False + False + 5 1 - + True + <b>Dropbox</b> + True False @@ -60,14 +104,8 @@ - - Musik Pool + True - True - False - 0.46000000834465027 - True - False @@ -77,8 +115,7 @@ True - False - <b>File</b> + <b>Datei</b> True @@ -90,8 +127,8 @@ True vertical - False False + False 5 @@ -108,7 +145,7 @@ - + True -- cgit v0.10.2