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 | # +-----------------------------------------------------------------------+ |
---|
20 | package Uploader::GUI::ImageProgressDlg; |
---|
21 | use strict; |
---|
22 | use 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 | /; |
---|
33 | use base qw/Wx::Panel Class::Accessor::Fast/; |
---|
34 | use 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 | /); |
---|
46 | use Carp; |
---|
47 | use Uploader::GUI::Layout::ImageProgress; |
---|
48 | |
---|
49 | sub 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 | $params->{parentwnd}, |
---|
57 | -1, |
---|
58 | wxDefaultPosition, |
---|
59 | wxDefaultSize, |
---|
60 | |
---|
61 | ); |
---|
62 | |
---|
63 | $self->columns( |
---|
64 | $params->{columns}, |
---|
65 | ); |
---|
66 | |
---|
67 | $self->progress_column( |
---|
68 | $params->{progress_column}||2 |
---|
69 | ); |
---|
70 | |
---|
71 | $self->cancel_cbk( |
---|
72 | $params->{cancel_cbk} |
---|
73 | ); |
---|
74 | |
---|
75 | $self->clear_cbk( |
---|
76 | $params->{clear_cbk} |
---|
77 | ); |
---|
78 | |
---|
79 | Uploader::GUI::Layout::ImageProgress::Init($self); |
---|
80 | |
---|
81 | $self->init_columns; |
---|
82 | |
---|
83 | # which column displays progress bar |
---|
84 | $self->listctrl->progress_column( |
---|
85 | $self->progress_column |
---|
86 | ); |
---|
87 | |
---|
88 | $self->listctrl->column_item_data( |
---|
89 | $params->{column_item_data} |
---|
90 | ); |
---|
91 | |
---|
92 | Wx::Event::EVT_BUTTON( $self, $self->{_bt_cancel}->GetId, \&on_cancel ); |
---|
93 | Wx::Event::EVT_BUTTON( $self, $self->{_bt_clear}->GetId, \&on_clear ); |
---|
94 | Wx::Event::EVT_CLOSE( $self, \&on_close ); |
---|
95 | |
---|
96 | $self; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | sub init_columns { |
---|
101 | my ( $self ) = @_; |
---|
102 | |
---|
103 | map { |
---|
104 | my $col = $self->listctrl->InsertColumn( |
---|
105 | $self->listctrl->GetColumnCount, |
---|
106 | $_ |
---|
107 | ); |
---|
108 | } |
---|
109 | @{$self->columns} |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | sub add_images { |
---|
114 | my ( $self, $images ) = @_; |
---|
115 | |
---|
116 | # have to filter to remove fake images ( batch_end_events ) |
---|
117 | $self->listctrl->add_progress_items( |
---|
118 | [ |
---|
119 | grep { $_->{image_id} } @$images |
---|
120 | ] |
---|
121 | ); |
---|
122 | |
---|
123 | $self->{_bt_cancel}->Enable(1); |
---|
124 | $self->{_bt_clear}->Enable(0); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | sub update_image_item { |
---|
129 | my ( $self, $image ) = @_; |
---|
130 | |
---|
131 | my $item = $image->{add_rank}; |
---|
132 | $self->listctrl->replace_item_data($item, $image); |
---|
133 | $self->listctrl->replace_item_wximage( |
---|
134 | $item, |
---|
135 | $image->{wx_thumb_file} |
---|
136 | ); |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | sub batch_end { |
---|
141 | my ( $self, $image ) = @_; |
---|
142 | |
---|
143 | $self->{_bt_cancel}->Enable(0); |
---|
144 | $self->{_bt_clear}->Enable(1); |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | sub on_clear { |
---|
149 | my( $self, $event ) = @_; |
---|
150 | |
---|
151 | $self->listctrl->clear_progress_items; |
---|
152 | $self->clear_cbk->(); |
---|
153 | $event->Skip; |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | sub on_cancel { |
---|
158 | my( $self, $event ) = @_; |
---|
159 | |
---|
160 | if($self->cancel_cbk->()){ |
---|
161 | $self->{_bt_cancel}->Enable(0); |
---|
162 | $self->{_bt_clear}->Enable(1); |
---|
163 | } |
---|
164 | $event->Skip; |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | sub on_close { |
---|
169 | my( $self, $event ) = @_; |
---|
170 | |
---|
171 | $self->Hide; |
---|
172 | $event->Skip; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | 1; |
---|