1 | # +-----------------------------------------------------------------------+ |
---|
2 | # | pLoader - a Perl photo uploader for Piwigo | |
---|
3 | # +-----------------------------------------------------------------------+ |
---|
4 | # | Copyright(C) 2008 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::wxExportJobsDlg; |
---|
21 | use strict; |
---|
22 | use Wx qw/ |
---|
23 | wxDefaultSize |
---|
24 | wxDefaultPosition |
---|
25 | wxID_CANCEL |
---|
26 | wxID_OK |
---|
27 | /; |
---|
28 | use base qw/Wx::Dialog Class::Accessor::Fast/; |
---|
29 | #use TDSC::GUI::export_dlg; |
---|
30 | use Wx::Event qw/ |
---|
31 | EVT_CHECKLISTBOX |
---|
32 | EVT_RADIOBOX |
---|
33 | EVT_BUTTON |
---|
34 | EVT_UPDATE_UI |
---|
35 | /; |
---|
36 | |
---|
37 | __PACKAGE__->mk_accessors( |
---|
38 | qw/ |
---|
39 | clbjobs |
---|
40 | rbolanguage |
---|
41 | output_path |
---|
42 | language |
---|
43 | btok |
---|
44 | jobs |
---|
45 | / |
---|
46 | ); |
---|
47 | |
---|
48 | sub new { |
---|
49 | my ($this, $params) = @_; |
---|
50 | #on recupere le nom de la classe en fonction du type d'appel de la méthode. |
---|
51 | my $class = ref($this) || $this; |
---|
52 | |
---|
53 | |
---|
54 | my $self = $class->SUPER::new( undef, -1, $params->{title}, wxDefaultPosition, wxDefaultSize); |
---|
55 | # load controls |
---|
56 | &main::DSExportJobs($self, 1); |
---|
57 | |
---|
58 | $self->_initEventHandlers(); |
---|
59 | |
---|
60 | $self->clbjobs( $self->FindWindow($main::ID_EXPORT_JOBS) ); |
---|
61 | $self->rbolanguage( $self->FindWindow($main::ID_LANGUAGE) ); |
---|
62 | $self->btok( $self->FindWindow($main::ID_EXPORT_OK) ); |
---|
63 | |
---|
64 | |
---|
65 | # Undefined is default and hidden : no default language choice |
---|
66 | $self->rbolanguage->SetSelection(2); |
---|
67 | $self->rbolanguage->Show(2, 0); |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | $self->clbjobs->InsertItems( $params->{jobs}, 0 ); |
---|
72 | $self->_restorePrevValues( $params ); |
---|
73 | |
---|
74 | $self; |
---|
75 | } |
---|
76 | |
---|
77 | sub _restorePrevValues { |
---|
78 | my ( $self, $params ) = @_; |
---|
79 | |
---|
80 | if ( defined( $params->{prevjobs} ) ){ |
---|
81 | my $selected = {}; |
---|
82 | map { |
---|
83 | $selected->{$_} = 1; |
---|
84 | } |
---|
85 | @{$params->{prevjobs}}; |
---|
86 | |
---|
87 | # restore prev export selection |
---|
88 | for( my $i=0;$i<$self->clbjobs->GetCount;$i++){ |
---|
89 | if($selected->{$self->clbjobs->GetString($i)}){ |
---|
90 | $self->clbjobs->Check($i, 1); |
---|
91 | } |
---|
92 | } |
---|
93 | $self->jobs( $params->{prevjobs} ); |
---|
94 | } |
---|
95 | else { |
---|
96 | $self->jobs( [] ); |
---|
97 | } |
---|
98 | |
---|
99 | if ( defined( $params->{output_path} ) ){ |
---|
100 | $self->output_path( $params->{output_path} ); |
---|
101 | } |
---|
102 | |
---|
103 | if ( defined( $params->{language} ) ){ |
---|
104 | $self->language( $params->{language} ); |
---|
105 | } |
---|
106 | else { |
---|
107 | # Undefined |
---|
108 | $self->language( 2 ); |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | sub _initEventHandlers { |
---|
114 | my ( $self ) = @_; |
---|
115 | |
---|
116 | EVT_BUTTON( $self, $main::ID_SELECT_ALL, \&OnSelectAll ); |
---|
117 | EVT_BUTTON( $self, $main::ID_REVERSE_SEL, \&OnReverseSelection ); |
---|
118 | EVT_BUTTON( $self, $main::ID_EXPORT_OK, \&OnExportOK ); |
---|
119 | EVT_BUTTON( $self, $main::ID_EXPORT_CANCEL, \&OnExportCancel ); |
---|
120 | EVT_BUTTON( $self, $main::ID_EXPORT_DIRDIALOG, \&OnExportDirDialog ); |
---|
121 | EVT_CHECKLISTBOX($self, $main::ID_EXPORT_JOBS, \&OnCheckListBox ) ; |
---|
122 | EVT_RADIOBOX($self, $main::ID_LANGUAGE, \&OnRadioBox ) ; |
---|
123 | |
---|
124 | EVT_UPDATE_UI( $self, $self, \&OnUpdateUI ) ; |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | # UI context management |
---|
129 | sub OnUpdateUI { |
---|
130 | my ( $self, $event ) = @_; |
---|
131 | |
---|
132 | $self->FindWindow($main::ID_EXPORT_DIRECTORY)->SetValue( $self->output_path ); |
---|
133 | $self->FindWindow($main::ID_LANGUAGE)->SetSelection( $self->language ); |
---|
134 | |
---|
135 | # Enable OK if required properties are set |
---|
136 | $self->btok->Enable(1) if ( |
---|
137 | defined $self->output_path && |
---|
138 | 2 != $self->rbolanguage->GetSelection && |
---|
139 | scalar @{$self->jobs} |
---|
140 | ); |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | sub OnRadioBox { |
---|
145 | my ( $self, $event ) = @_; |
---|
146 | |
---|
147 | $self->language($event->GetInt); |
---|
148 | } |
---|
149 | |
---|
150 | sub OnCheckListBox { |
---|
151 | my ( $self, $event ) = @_; |
---|
152 | |
---|
153 | $self->SelectedJobs(); |
---|
154 | } |
---|
155 | |
---|
156 | sub OnExportDirDialog { |
---|
157 | my ( $self, $event ) = @_; |
---|
158 | |
---|
159 | my $dialog = Wx::DirDialog->new( $self ); |
---|
160 | |
---|
161 | if( $dialog->ShowModal == wxID_CANCEL ) { |
---|
162 | Wx::LogMessage( "User cancelled the dialog" ); |
---|
163 | } else { |
---|
164 | Wx::LogMessage( "Export directory: %s", $dialog->GetPath ); |
---|
165 | $self->output_path( $dialog->GetPath ); |
---|
166 | } |
---|
167 | |
---|
168 | $dialog->Destroy; |
---|
169 | |
---|
170 | } |
---|
171 | |
---|
172 | sub OnExportOK { |
---|
173 | my ( $self, $event ) = @_; |
---|
174 | |
---|
175 | $self->EndModal(wxID_OK); |
---|
176 | |
---|
177 | } |
---|
178 | |
---|
179 | sub OnExportCancel { |
---|
180 | my ( $self, $event ) = @_; |
---|
181 | |
---|
182 | $self->EndModal(wxID_CANCEL); |
---|
183 | } |
---|
184 | |
---|
185 | sub OnSelectAll { |
---|
186 | my ( $self, $event ) = @_; |
---|
187 | |
---|
188 | for( my $i=0;$i<$self->clbjobs->GetCount;$i++){ |
---|
189 | $self->clbjobs->Check($i, 1) if !$self->clbjobs->IsChecked($i); |
---|
190 | } |
---|
191 | $self->SelectedJobs(); |
---|
192 | } |
---|
193 | |
---|
194 | sub OnReverseSelection { |
---|
195 | my ( $self, $event ) = @_; |
---|
196 | |
---|
197 | for( my $i=0;$i<$self->clbjobs->GetCount;$i++){ |
---|
198 | if($self->clbjobs->IsChecked($i)){ |
---|
199 | $self->clbjobs->Check($i, 0); |
---|
200 | } |
---|
201 | else{ |
---|
202 | $self->clbjobs->Check($i, 1); |
---|
203 | } |
---|
204 | } |
---|
205 | $self->SelectedJobs(); |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | sub SelectedJobs { |
---|
210 | my ( $self ) = @_; |
---|
211 | |
---|
212 | my $jobs = []; |
---|
213 | for( my $i=0;$i<$self->clbjobs->GetCount;$i++){ |
---|
214 | if($self->clbjobs->IsChecked($i)){ |
---|
215 | push @$jobs, $self->clbjobs->GetString($i); |
---|
216 | } |
---|
217 | } |
---|
218 | $self->jobs( $jobs ); |
---|
219 | } |
---|
220 | |
---|
221 | 1; |
---|