source: extensions/pLoader/trunk/src/Uploader/GUI/ImageProgressDlg.pm @ 6538

Last change on this file since 6538 was 6538, checked in by ronosman, 14 years ago

Ability to clear progress list. Only available when no batch is running. The cancel processing is available when a batch is running.

File size: 4.3 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::GUI::ImageProgressDlg;
21use strict;
22use Wx qw/
23    wxDefaultSize
24    wxDefaultPosition
25    wxID_CANCEL
26    wxID_OK
27    wxGREEN
28    wxDIALOG_NO_PARENT
29    wxDEFAULT_DIALOG_STYLE
30    wxMAXIMIZE_BOX
31    wxMINIMIZE_BOX
32/;
33use base qw/Wx::Dialog Class::Accessor::Fast/;
34use Wx::Event qw/
35    EVT_BUTTON
36/;
37
38__PACKAGE__->mk_accessors( qw/
39    cancel_cbk
40    clear_cbk
41    listctrl
42    columns
43    progress_column
44    btcancel
45/);
46use Carp;
47use Uploader::GUI::Layout::ImageProgress;
48
49sub new {
50    my ($this, $params) = @_;
51    #on recupere le nom de la classe en fonction du type d'appel de la méthode.
52    my $class = ref($this) || $this;
53
54
55    my $self = $class->SUPER::new(
56        undef, 
57        -1,
58        $params->{title},
59        wxDefaultPosition,
60        wxDefaultSize,
61             wxDIALOG_NO_PARENT|
62             wxDEFAULT_DIALOG_STYLE|
63             wxMAXIMIZE_BOX|
64             wxMINIMIZE_BOX
65
66    );
67
68    $self->columns(
69        $params->{columns},
70    );
71
72    $self->progress_column(
73        $params->{progress_column}||2
74    );
75
76    $self->cancel_cbk(
77        $params->{cancel_cbk}
78    );
79
80    $self->clear_cbk(
81        $params->{clear_cbk}
82    );
83
84    Uploader::GUI::Layout::ImageProgress::Init($self);
85
86    $self->init_columns;
87
88    # which column displays progress bar
89    $self->listctrl->progress_column(
90        $self->progress_column
91    );
92
93    $self->listctrl->column_item_data(
94        $params->{column_item_data}
95    );
96
97    Wx::Event::EVT_BUTTON( $self, $self->{_bt_cancel}->GetId, \&on_cancel );
98    Wx::Event::EVT_BUTTON( $self, $self->{_bt_clear}->GetId, \&on_clear );
99    Wx::Event::EVT_CLOSE( $self, \&on_close );
100
101    $self;
102}
103
104
105sub init_columns {
106    my ( $self ) = @_;
107
108    map {
109        my $col = $self->listctrl->InsertColumn(
110            $self->listctrl->GetColumnCount,
111            $_
112        );
113    }
114    @{$self->columns}
115}
116
117
118sub add_images {
119    my ( $self, $images ) = @_;
120
121    # have to filter to remove fake images ( batch_end_events )
122    $self->listctrl->add_progress_items(
123        [
124            grep { $_->{image_id} } @$images
125        ]
126    );
127
128    $self->{_bt_cancel}->Enable(1);
129    $self->{_bt_clear}->Enable(0);
130}
131
132
133sub update_image_item {
134    my ( $self, $image ) = @_;
135   
136    my $item = $image->{add_rank};
137    $self->listctrl->replace_item_data($item, $image);
138    $self->listctrl->replace_item_wximage(
139        $item,
140        $image->{wx_thumb_file}
141    );
142}
143
144
145sub batch_end {
146    my ( $self, $image ) = @_;
147
148    $self->{_bt_cancel}->Enable(0);
149    $self->{_bt_clear}->Enable(1);
150}
151
152
153sub on_clear {
154    my( $self, $event ) = @_;
155
156    $self->listctrl->clear_progress_items;
157    $self->clear_cbk->();
158    $event->Skip;
159}
160
161
162sub on_cancel {
163    my( $self, $event ) = @_;
164
165    if($self->cancel_cbk->()){
166        $self->{_bt_cancel}->Enable(0);
167        $self->{_bt_clear}->Enable(1);
168    }
169    $event->Skip;
170}
171 
172
173sub on_close {
174    my( $self, $event ) = @_;
175
176    $self->Hide;
177    $event->Skip;
178}
179
180
1811;
Note: See TracBrowser for help on using the repository browser.