# +-----------------------------------------------------------------------+ # | pLoader - a Perl photo uploader for Piwigo | # +-----------------------------------------------------------------------+ # | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | # +-----------------------------------------------------------------------+ # | This program is free software; you can redistribute it and/or modify | # | it under the terms of the GNU General Public License as published by | # | the Free Software Foundation | # | | # | This program is distributed in the hope that it will be useful, but | # | WITHOUT ANY WARRANTY; without even the implied warranty of | # | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | # | General Public License for more details. | # | | # | You should have received a copy of the GNU General Public License | # | along with this program; if not, write to the Free Software | # | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | # | USA. | # +-----------------------------------------------------------------------+ package Uploader::GUI::ImageProgressDlg; use strict; use Wx qw/ wxDefaultSize wxDefaultPosition wxID_CANCEL wxID_OK wxGREEN wxDIALOG_NO_PARENT wxDEFAULT_DIALOG_STYLE wxMAXIMIZE_BOX wxMINIMIZE_BOX /; use base qw/Wx::Dialog Class::Accessor::Fast/; use Wx::Event qw/ EVT_BUTTON /; __PACKAGE__->mk_accessors( qw/ cancel_cbk clear_cbk listctrl columns progress_column btcancel /); use Carp; use Uploader::GUI::Layout::ImageProgress; sub new { my ($this, $params) = @_; #on recupere le nom de la classe en fonction du type d'appel de la méthode. my $class = ref($this) || $this; my $self = $class->SUPER::new( undef, -1, $params->{title}, wxDefaultPosition, wxDefaultSize, wxDIALOG_NO_PARENT| wxDEFAULT_DIALOG_STYLE| wxMAXIMIZE_BOX| wxMINIMIZE_BOX ); $self->columns( $params->{columns}, ); $self->progress_column( $params->{progress_column}||2 ); $self->cancel_cbk( $params->{cancel_cbk} ); $self->clear_cbk( $params->{clear_cbk} ); Uploader::GUI::Layout::ImageProgress::Init($self); $self->init_columns; # which column displays progress bar $self->listctrl->progress_column( $self->progress_column ); $self->listctrl->column_item_data( $params->{column_item_data} ); Wx::Event::EVT_BUTTON( $self, $self->{_bt_cancel}->GetId, \&on_cancel ); Wx::Event::EVT_BUTTON( $self, $self->{_bt_clear}->GetId, \&on_clear ); Wx::Event::EVT_CLOSE( $self, \&on_close ); $self; } sub init_columns { my ( $self ) = @_; map { my $col = $self->listctrl->InsertColumn( $self->listctrl->GetColumnCount, $_ ); } @{$self->columns} } sub add_images { my ( $self, $images ) = @_; # have to filter to remove fake images ( batch_end_events ) $self->listctrl->add_progress_items( [ grep { $_->{image_id} } @$images ] ); $self->{_bt_cancel}->Enable(1); $self->{_bt_clear}->Enable(0); } sub update_image_item { my ( $self, $image ) = @_; my $item = $image->{add_rank}; $self->listctrl->replace_item_data($item, $image); $self->listctrl->replace_item_wximage( $item, $image->{wx_thumb_file} ); } sub batch_end { my ( $self, $image ) = @_; $self->{_bt_cancel}->Enable(0); $self->{_bt_clear}->Enable(1); } sub on_clear { my( $self, $event ) = @_; $self->listctrl->clear_progress_items; $self->clear_cbk->(); $event->Skip; } sub on_cancel { my( $self, $event ) = @_; if($self->cancel_cbk->()){ $self->{_bt_cancel}->Enable(0); $self->{_bt_clear}->Enable(1); } $event->Skip; } sub on_close { my( $self, $event ) = @_; $self->Hide; $event->Skip; } 1;