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::wxApp; |
---|
21 | use strict; |
---|
22 | use base qw/Wx::App Class::Accessor::Fast/; |
---|
23 | use Wx qw/ |
---|
24 | wxBITMAP_TYPE_GIF |
---|
25 | wxBITMAP_TYPE_ICO |
---|
26 | wxBITMAP_TYPE_BMP |
---|
27 | wxBITMAP_TYPE_PNG |
---|
28 | wxBITMAP_TYPE_JPEG |
---|
29 | wxIMAGE_QUALITY_NORMAL |
---|
30 | wxIMAGE_QUALITY_HIGH |
---|
31 | wxSPLASH_CENTRE_ON_SCREEN |
---|
32 | wxSPLASH_TIMEOUT |
---|
33 | wxDefaultPosition |
---|
34 | wxDefaultSize |
---|
35 | wxSIMPLE_BORDER |
---|
36 | wxFRAME_TOOL_WINDOW |
---|
37 | wxFRAME_NO_TASKBAR wxSTAY_ON_TOP |
---|
38 | wxWHITE |
---|
39 | wxICON_EXCLAMATION |
---|
40 | wxOK |
---|
41 | wxLANGUAGE_ABKHAZIAN |
---|
42 | wxLANGUAGE_AFAR |
---|
43 | wxLANGUAGE_AFRIKAANS |
---|
44 | wxLANGUAGE_ALBANIAN |
---|
45 | wxLANGUAGE_AMHARIC |
---|
46 | wxLANGUAGE_ARABIC |
---|
47 | wxLANGUAGE_ARABIC_ALGERIA |
---|
48 | wxLANGUAGE_ARABIC_BAHRAIN |
---|
49 | wxLANGUAGE_ARABIC_EGYPT |
---|
50 | wxLANGUAGE_ARABIC_IRAQ |
---|
51 | wxLANGUAGE_ARABIC_JORDAN |
---|
52 | wxLANGUAGE_ARABIC_KUWAIT |
---|
53 | wxLANGUAGE_ARABIC_LEBANON |
---|
54 | wxLANGUAGE_ARABIC_LIBYA |
---|
55 | wxLANGUAGE_ARABIC_MOROCCO |
---|
56 | wxLANGUAGE_ARABIC_OMAN |
---|
57 | wxLANGUAGE_ARABIC_QATAR |
---|
58 | wxLANGUAGE_ARABIC_SAUDI_ARABIA |
---|
59 | wxLANGUAGE_ARABIC_SUDAN |
---|
60 | wxLANGUAGE_ARABIC_SYRIA |
---|
61 | wxLANGUAGE_ARABIC_TUNISIA |
---|
62 | wxLANGUAGE_ARABIC_UAE |
---|
63 | wxLANGUAGE_ARABIC_YEMEN |
---|
64 | wxLANGUAGE_ARMENIAN |
---|
65 | wxLANGUAGE_ASSAMESE |
---|
66 | wxLANGUAGE_AYMARA |
---|
67 | wxLANGUAGE_AZERI |
---|
68 | wxLANGUAGE_AZERI_CYRILLIC |
---|
69 | wxLANGUAGE_AZERI_LATIN |
---|
70 | wxLANGUAGE_BASHKIR |
---|
71 | wxLANGUAGE_BASQUE |
---|
72 | wxLANGUAGE_BELARUSIAN |
---|
73 | wxLANGUAGE_BENGALI |
---|
74 | wxLANGUAGE_BHUTANI |
---|
75 | wxLANGUAGE_BIHARI |
---|
76 | wxLANGUAGE_BISLAMA |
---|
77 | wxLANGUAGE_BRETON |
---|
78 | wxLANGUAGE_BULGARIAN |
---|
79 | wxLANGUAGE_BURMESE |
---|
80 | wxLANGUAGE_CAMBODIAN |
---|
81 | wxLANGUAGE_CATALAN |
---|
82 | wxLANGUAGE_CHINESE |
---|
83 | wxLANGUAGE_CHINESE_SIMPLIFIED |
---|
84 | wxLANGUAGE_CHINESE_TRADITIONAL |
---|
85 | wxLANGUAGE_CHINESE_HONGKONG |
---|
86 | wxLANGUAGE_CHINESE_MACAU |
---|
87 | wxLANGUAGE_CHINESE_SINGAPORE |
---|
88 | wxLANGUAGE_CHINESE_TAIWAN |
---|
89 | wxLANGUAGE_CORSICAN |
---|
90 | wxLANGUAGE_CROATIAN |
---|
91 | wxLANGUAGE_CZECH |
---|
92 | wxLANGUAGE_DANISH |
---|
93 | wxLANGUAGE_DUTCH |
---|
94 | wxLANGUAGE_DUTCH_BELGIAN |
---|
95 | wxLANGUAGE_ENGLISH |
---|
96 | wxLANGUAGE_ENGLISH_UK |
---|
97 | wxLANGUAGE_ENGLISH_US |
---|
98 | wxLANGUAGE_ENGLISH_AUSTRALIA |
---|
99 | wxLANGUAGE_ENGLISH_BELIZE |
---|
100 | wxLANGUAGE_ENGLISH_BOTSWANA |
---|
101 | wxLANGUAGE_ENGLISH_CANADA |
---|
102 | wxLANGUAGE_ENGLISH_CARIBBEAN |
---|
103 | wxLANGUAGE_ENGLISH_DENMARK |
---|
104 | wxLANGUAGE_ENGLISH_EIRE |
---|
105 | wxLANGUAGE_ENGLISH_JAMAICA |
---|
106 | wxLANGUAGE_ENGLISH_NEW_ZEALAND |
---|
107 | wxLANGUAGE_ENGLISH_PHILIPPINES |
---|
108 | wxLANGUAGE_ENGLISH_SOUTH_AFRICA |
---|
109 | wxLANGUAGE_ENGLISH_TRINIDAD |
---|
110 | wxLANGUAGE_ENGLISH_ZIMBABWE |
---|
111 | wxLANGUAGE_ESPERANTO |
---|
112 | wxLANGUAGE_ESTONIAN |
---|
113 | wxLANGUAGE_FAEROESE |
---|
114 | wxLANGUAGE_FARSI |
---|
115 | wxLANGUAGE_FIJI |
---|
116 | wxLANGUAGE_FINNISH |
---|
117 | wxLANGUAGE_FRENCH |
---|
118 | wxLANGUAGE_FRENCH_BELGIAN |
---|
119 | wxLANGUAGE_FRENCH_CANADIAN |
---|
120 | wxLANGUAGE_FRENCH_LUXEMBOURG |
---|
121 | wxLANGUAGE_FRENCH_MONACO |
---|
122 | wxLANGUAGE_FRENCH_SWISS |
---|
123 | wxLANGUAGE_FRISIAN |
---|
124 | wxLANGUAGE_GALICIAN |
---|
125 | wxLANGUAGE_GEORGIAN |
---|
126 | wxLANGUAGE_GERMAN |
---|
127 | wxLANGUAGE_GERMAN_AUSTRIAN |
---|
128 | wxLANGUAGE_GERMAN_BELGIUM |
---|
129 | wxLANGUAGE_GERMAN_LIECHTENSTEIN |
---|
130 | wxLANGUAGE_GERMAN_LUXEMBOURG |
---|
131 | wxLANGUAGE_GERMAN_SWISS |
---|
132 | wxLANGUAGE_GREEK |
---|
133 | wxLANGUAGE_GREENLANDIC |
---|
134 | wxLANGUAGE_GUARANI |
---|
135 | wxLANGUAGE_GUJARATI |
---|
136 | wxLANGUAGE_HAUSA |
---|
137 | wxLANGUAGE_HEBREW |
---|
138 | wxLANGUAGE_HINDI |
---|
139 | wxLANGUAGE_HUNGARIAN |
---|
140 | wxLANGUAGE_ICELANDIC |
---|
141 | wxLANGUAGE_INDONESIAN |
---|
142 | wxLANGUAGE_INTERLINGUA |
---|
143 | wxLANGUAGE_INTERLINGUE |
---|
144 | wxLANGUAGE_INUKTITUT |
---|
145 | wxLANGUAGE_INUPIAK |
---|
146 | wxLANGUAGE_IRISH |
---|
147 | wxLANGUAGE_ITALIAN |
---|
148 | wxLANGUAGE_ITALIAN_SWISS |
---|
149 | wxLANGUAGE_JAPANESE |
---|
150 | wxLANGUAGE_JAVANESE |
---|
151 | wxLANGUAGE_KANNADA |
---|
152 | wxLANGUAGE_KASHMIRI |
---|
153 | wxLANGUAGE_KASHMIRI_INDIA |
---|
154 | wxLANGUAGE_KAZAKH |
---|
155 | wxLANGUAGE_KERNEWEK |
---|
156 | wxLANGUAGE_KINYARWANDA |
---|
157 | wxLANGUAGE_KIRGHIZ |
---|
158 | wxLANGUAGE_KIRUNDI |
---|
159 | wxLANGUAGE_KONKANI |
---|
160 | wxLANGUAGE_KOREAN |
---|
161 | wxLANGUAGE_KURDISH |
---|
162 | wxLANGUAGE_LAOTHIAN |
---|
163 | wxLANGUAGE_LATIN |
---|
164 | wxLANGUAGE_LATVIAN |
---|
165 | wxLANGUAGE_LINGALA |
---|
166 | wxLANGUAGE_LITHUANIAN |
---|
167 | wxLANGUAGE_MACEDONIAN |
---|
168 | wxLANGUAGE_MALAGASY |
---|
169 | wxLANGUAGE_MALAY |
---|
170 | wxLANGUAGE_MALAYALAM |
---|
171 | wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM |
---|
172 | wxLANGUAGE_MALAY_MALAYSIA |
---|
173 | wxLANGUAGE_MALTESE |
---|
174 | wxLANGUAGE_MANIPURI |
---|
175 | wxLANGUAGE_MAORI |
---|
176 | wxLANGUAGE_MARATHI |
---|
177 | wxLANGUAGE_MOLDAVIAN |
---|
178 | wxLANGUAGE_MONGOLIAN |
---|
179 | wxLANGUAGE_NAURU |
---|
180 | wxLANGUAGE_NEPALI |
---|
181 | wxLANGUAGE_NEPALI_INDIA |
---|
182 | wxLANGUAGE_NORWEGIAN_BOKMAL |
---|
183 | wxLANGUAGE_NORWEGIAN_NYNORSK |
---|
184 | wxLANGUAGE_OCCITAN |
---|
185 | wxLANGUAGE_ORIYA |
---|
186 | wxLANGUAGE_OROMO |
---|
187 | wxLANGUAGE_PASHTO |
---|
188 | wxLANGUAGE_POLISH |
---|
189 | wxLANGUAGE_PORTUGUESE |
---|
190 | wxLANGUAGE_PORTUGUESE_BRAZILIAN |
---|
191 | wxLANGUAGE_PUNJABI |
---|
192 | wxLANGUAGE_QUECHUA |
---|
193 | wxLANGUAGE_RHAETO_ROMANCE |
---|
194 | wxLANGUAGE_ROMANIAN |
---|
195 | wxLANGUAGE_RUSSIAN |
---|
196 | wxLANGUAGE_RUSSIAN_UKRAINE |
---|
197 | wxLANGUAGE_SAMI |
---|
198 | wxLANGUAGE_SAMOAN |
---|
199 | wxLANGUAGE_SANGHO |
---|
200 | wxLANGUAGE_SANSKRIT |
---|
201 | wxLANGUAGE_SCOTS_GAELIC |
---|
202 | wxLANGUAGE_SERBIAN |
---|
203 | wxLANGUAGE_SERBIAN_CYRILLIC |
---|
204 | wxLANGUAGE_SERBIAN_LATIN |
---|
205 | wxLANGUAGE_SERBO_CROATIAN |
---|
206 | wxLANGUAGE_SESOTHO |
---|
207 | wxLANGUAGE_SETSWANA |
---|
208 | wxLANGUAGE_SHONA |
---|
209 | wxLANGUAGE_SINDHI |
---|
210 | wxLANGUAGE_SINHALESE |
---|
211 | wxLANGUAGE_SISWATI |
---|
212 | wxLANGUAGE_SLOVAK |
---|
213 | wxLANGUAGE_SLOVENIAN |
---|
214 | wxLANGUAGE_SOMALI |
---|
215 | wxLANGUAGE_SPANISH |
---|
216 | wxLANGUAGE_SPANISH_ARGENTINA |
---|
217 | wxLANGUAGE_SPANISH_BOLIVIA |
---|
218 | wxLANGUAGE_SPANISH_CHILE |
---|
219 | wxLANGUAGE_SPANISH_COLOMBIA |
---|
220 | wxLANGUAGE_SPANISH_COSTA_RICA |
---|
221 | wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC |
---|
222 | wxLANGUAGE_SPANISH_ECUADOR |
---|
223 | wxLANGUAGE_SPANISH_EL_SALVADOR |
---|
224 | wxLANGUAGE_SPANISH_GUATEMALA |
---|
225 | wxLANGUAGE_SPANISH_HONDURAS |
---|
226 | wxLANGUAGE_SPANISH_MEXICAN |
---|
227 | wxLANGUAGE_SPANISH_MODERN |
---|
228 | wxLANGUAGE_SPANISH_NICARAGUA |
---|
229 | wxLANGUAGE_SPANISH_PANAMA |
---|
230 | wxLANGUAGE_SPANISH_PARAGUAY |
---|
231 | wxLANGUAGE_SPANISH_PERU |
---|
232 | wxLANGUAGE_SPANISH_PUERTO_RICO |
---|
233 | wxLANGUAGE_SPANISH_URUGUAY |
---|
234 | wxLANGUAGE_SPANISH_US |
---|
235 | wxLANGUAGE_SPANISH_VENEZUELA |
---|
236 | wxLANGUAGE_SUNDANESE |
---|
237 | wxLANGUAGE_SWAHILI |
---|
238 | wxLANGUAGE_SWEDISH |
---|
239 | wxLANGUAGE_SWEDISH_FINLAND |
---|
240 | wxLANGUAGE_TAGALOG |
---|
241 | wxLANGUAGE_TAJIK |
---|
242 | wxLANGUAGE_TAMIL |
---|
243 | wxLANGUAGE_TATAR |
---|
244 | wxLANGUAGE_TELUGU |
---|
245 | wxLANGUAGE_THAI |
---|
246 | wxLANGUAGE_TIBETAN |
---|
247 | wxLANGUAGE_TIGRINYA |
---|
248 | wxLANGUAGE_TONGA |
---|
249 | wxLANGUAGE_TSONGA |
---|
250 | wxLANGUAGE_TURKISH |
---|
251 | wxLANGUAGE_TURKMEN |
---|
252 | wxLANGUAGE_TWI |
---|
253 | wxLANGUAGE_UIGHUR |
---|
254 | wxLANGUAGE_UKRAINIAN |
---|
255 | wxLANGUAGE_URDU |
---|
256 | wxLANGUAGE_URDU_INDIA |
---|
257 | wxLANGUAGE_URDU_PAKISTAN |
---|
258 | wxLANGUAGE_UZBEK |
---|
259 | wxLANGUAGE_UZBEK_CYRILLIC |
---|
260 | wxLANGUAGE_UZBEK_LATIN |
---|
261 | wxLANGUAGE_VALENCIAN |
---|
262 | wxLANGUAGE_VIETNAMESE |
---|
263 | wxLANGUAGE_VOLAPUK |
---|
264 | wxLANGUAGE_WELSH |
---|
265 | wxLANGUAGE_WOLOF |
---|
266 | wxLANGUAGE_XHOSA |
---|
267 | wxLANGUAGE_YIDDISH |
---|
268 | wxLANGUAGE_YORUBA |
---|
269 | wxLANGUAGE_ZHUANG |
---|
270 | wxLANGUAGE_ZULU |
---|
271 | /; |
---|
272 | use Uploader::GUI::wxFrameAUI; |
---|
273 | use File::Slurp ; |
---|
274 | use Data::Dumper; |
---|
275 | use Storable; |
---|
276 | use File::HomeDir; |
---|
277 | use File::Spec; |
---|
278 | use Uploader::PWG; |
---|
279 | use Uploader::ImageList; |
---|
280 | use Uploader::GUI::wxLoginDlg; |
---|
281 | use Wx::Locale qw/:default/; |
---|
282 | |
---|
283 | |
---|
284 | $|=1; |
---|
285 | |
---|
286 | __PACKAGE__->mk_accessors( |
---|
287 | qw/ |
---|
288 | pwg |
---|
289 | site_url |
---|
290 | site_username |
---|
291 | site_password |
---|
292 | rejects |
---|
293 | imagelist |
---|
294 | storable_file |
---|
295 | wx_thumb_dir |
---|
296 | resized_dir |
---|
297 | preview_dir |
---|
298 | userdata_dir |
---|
299 | resized_dir |
---|
300 | thumb_dir |
---|
301 | conf_file |
---|
302 | locale |
---|
303 | current_language |
---|
304 | version |
---|
305 | imagelist_version |
---|
306 | use_offline |
---|
307 | login_dlg |
---|
308 | / |
---|
309 | ); |
---|
310 | |
---|
311 | sub FilterEvent { |
---|
312 | my( $self, $event ) = @_; |
---|
313 | |
---|
314 | Wx::LogMessage "EventType %s", $event->GetEventType(); |
---|
315 | |
---|
316 | return -1; |
---|
317 | } |
---|
318 | |
---|
319 | |
---|
320 | sub OnInit { |
---|
321 | my( $self ) = @_; |
---|
322 | |
---|
323 | $self->version( |
---|
324 | '2.0.1b' |
---|
325 | ); |
---|
326 | |
---|
327 | # to check if we can use stored cache |
---|
328 | $self->imagelist_version( |
---|
329 | '2' |
---|
330 | ); |
---|
331 | |
---|
332 | Wx::InitAllImageHandlers(); |
---|
333 | my $applicationName = "pLoader" ; |
---|
334 | $self->SetAppName( $applicationName ); |
---|
335 | $self->SetVendorName( "Piwigo Team" ); |
---|
336 | |
---|
337 | $self->{IMGTYPE} = { |
---|
338 | 'jpg' => wxBITMAP_TYPE_JPEG, |
---|
339 | 'gif' => wxBITMAP_TYPE_GIF, |
---|
340 | 'png' => wxBITMAP_TYPE_PNG, |
---|
341 | }; |
---|
342 | |
---|
343 | $self->_init_userdir; |
---|
344 | |
---|
345 | |
---|
346 | my $conf = retrieve $self->conf_file if -e $self->conf_file; |
---|
347 | |
---|
348 | if(defined $conf ){ |
---|
349 | $self->SetKeyValues($conf); |
---|
350 | } |
---|
351 | else { |
---|
352 | $self->_readParams( 'pLoader.ini' ) unless defined $conf ; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | $self->site_url( |
---|
357 | $self->{site_url} |
---|
358 | ); |
---|
359 | |
---|
360 | $self->site_username( |
---|
361 | $self->{site_username} |
---|
362 | ); |
---|
363 | $self->site_password( |
---|
364 | $self->{site_password} |
---|
365 | ); |
---|
366 | $self->current_language( |
---|
367 | $self->{current_language}||wxLANGUAGE_ENGLISH |
---|
368 | ); |
---|
369 | |
---|
370 | $self->init_locale; |
---|
371 | |
---|
372 | my $not_exit = $self->Login(); |
---|
373 | # user pressed OK |
---|
374 | if($not_exit){ |
---|
375 | if( !$self->use_offline ){ |
---|
376 | while( $not_exit and !$self->_is_connected ){ |
---|
377 | $not_exit = $self->Login(); |
---|
378 | last if $self->use_offline; |
---|
379 | } |
---|
380 | } |
---|
381 | $self->_init_imagelist; |
---|
382 | $self->_init_thumbimagelist; |
---|
383 | $self->_init_frame; |
---|
384 | } |
---|
385 | |
---|
386 | $not_exit; |
---|
387 | } |
---|
388 | |
---|
389 | |
---|
390 | sub _is_connected { |
---|
391 | my ( $self ) = @_; |
---|
392 | |
---|
393 | my $is_connected; |
---|
394 | |
---|
395 | if($self->pwg->login_result->{stat} eq 'ok'){ |
---|
396 | $is_connected = 1; |
---|
397 | } |
---|
398 | else{ |
---|
399 | Wx::MessageBox( |
---|
400 | sprintf( |
---|
401 | "%s\n\n%s %s %s", |
---|
402 | $self->pwg->login_result->{message}, |
---|
403 | gettext("Connection to"), |
---|
404 | $self->site_url, |
---|
405 | gettext("failed"), |
---|
406 | ), |
---|
407 | gettext("Piwigo login error"), |
---|
408 | wxOK | wxICON_EXCLAMATION, |
---|
409 | ); |
---|
410 | } |
---|
411 | |
---|
412 | $is_connected; |
---|
413 | } |
---|
414 | |
---|
415 | |
---|
416 | my $locale; |
---|
417 | sub init_locale { |
---|
418 | my ( $self, $language ) = @_; |
---|
419 | |
---|
420 | $self->current_language( |
---|
421 | $language |
---|
422 | ) if defined $language; |
---|
423 | |
---|
424 | undef $locale; |
---|
425 | $locale = Wx::Locale->new( |
---|
426 | $self->current_language |
---|
427 | ); |
---|
428 | $locale->AddCatalogLookupPathPrefix( '../locale'); |
---|
429 | if(!$locale->AddCatalog( 'pLoader.mo' )){ |
---|
430 | Wx::LogMessage gettext("Cannot find translation catalog files. Use default language"); |
---|
431 | } |
---|
432 | |
---|
433 | } |
---|
434 | |
---|
435 | sub StoreConnectionProperties { |
---|
436 | my ( $self ) = @_; |
---|
437 | |
---|
438 | eval { |
---|
439 | store( |
---|
440 | { |
---|
441 | map{ |
---|
442 | $_ => $self->{$_}, |
---|
443 | } |
---|
444 | qw/ |
---|
445 | site_url |
---|
446 | site_username |
---|
447 | site_password |
---|
448 | current_language |
---|
449 | / |
---|
450 | }, |
---|
451 | $self->conf_file |
---|
452 | ); |
---|
453 | }; |
---|
454 | } |
---|
455 | |
---|
456 | sub _init_imagelist { |
---|
457 | my ( $self ) = @_; |
---|
458 | |
---|
459 | my $stored_imagelist; |
---|
460 | |
---|
461 | my $use_new_imagelist; |
---|
462 | |
---|
463 | if( -e $self->storable_file ){ |
---|
464 | eval { |
---|
465 | $stored_imagelist = retrieve $self->storable_file; |
---|
466 | }; |
---|
467 | if($@){ |
---|
468 | Wx::LogMessage( |
---|
469 | gettext("An error has occured. Can not read %s\n%s"), |
---|
470 | $self->storable_file, |
---|
471 | $@ |
---|
472 | ); |
---|
473 | $use_new_imagelist = 1 ; |
---|
474 | } |
---|
475 | # should have a valid imagelist |
---|
476 | else{ |
---|
477 | $use_new_imagelist = 1 unless $self->imagelist_version eq $stored_imagelist->{imagelist_version}; |
---|
478 | if($use_new_imagelist){ |
---|
479 | Wx::LogMessage(gettext("pLoader has to reset image cache.")); |
---|
480 | } |
---|
481 | } |
---|
482 | } |
---|
483 | else{ |
---|
484 | $use_new_imagelist = 1 ; |
---|
485 | } |
---|
486 | |
---|
487 | if($use_new_imagelist){ |
---|
488 | $stored_imagelist = $self->_default_imagelist_params ; |
---|
489 | } |
---|
490 | |
---|
491 | |
---|
492 | $self->imagelist( |
---|
493 | Uploader::ImageList->new( |
---|
494 | $stored_imagelist |
---|
495 | ) |
---|
496 | ); |
---|
497 | |
---|
498 | $self->imagelist->RescaleCallback( |
---|
499 | sub { $self->RescaleImage(@_) } |
---|
500 | ); |
---|
501 | |
---|
502 | $self->imagelist->ResizeCallback( |
---|
503 | sub { $self->ResizeImage(@_) } |
---|
504 | ); |
---|
505 | } |
---|
506 | |
---|
507 | |
---|
508 | sub _default_imagelist_params { |
---|
509 | my ( $self ) = @_ ; |
---|
510 | |
---|
511 | my $params = { |
---|
512 | new_files => [], |
---|
513 | thumb_size => 120, |
---|
514 | site_thumb_dir => $self->thumb_dir, |
---|
515 | wx_thumb_size => 120, |
---|
516 | wx_thumb_dir => $self->wx_thumb_dir, |
---|
517 | preview_ratio => 25, |
---|
518 | preview_dir => $self->preview_dir, |
---|
519 | resize_w => 800, |
---|
520 | resize_h => 600, |
---|
521 | site_resized_dir => $self->resized_dir, |
---|
522 | type => 'jpg', |
---|
523 | filter => 'Lanczos', |
---|
524 | blur => 0.9, |
---|
525 | quality => 100, |
---|
526 | wx_quality => 80, |
---|
527 | th_quality => 90, |
---|
528 | auto_rotate => 1, |
---|
529 | interlace => 'Line', |
---|
530 | create_resized => 1, |
---|
531 | use_exif_preview => 1, |
---|
532 | prefix => 'TN', |
---|
533 | count => 0, |
---|
534 | storable_file => $self->storable_file, |
---|
535 | userdata_dir => $self->userdata_dir, |
---|
536 | default_name_prefix => 'Photo', |
---|
537 | upload_rejects => [], |
---|
538 | image_sums => {}, |
---|
539 | sums => [], |
---|
540 | version => $self->version, |
---|
541 | imagelist_version => $self->imagelist_version, |
---|
542 | RescaleCallback => sub { $self->RescaleImage(@_) }, |
---|
543 | ResizeCallback => sub { $self->ResizeImage(@_) }, |
---|
544 | }; |
---|
545 | |
---|
546 | return $params; |
---|
547 | } |
---|
548 | |
---|
549 | sub Login { |
---|
550 | my ( $self ) = @_; |
---|
551 | |
---|
552 | $self->login_dlg( |
---|
553 | Uploader::GUI::wxLoginDlg->new( |
---|
554 | { |
---|
555 | title => gettext("Piwigo login"), |
---|
556 | site_url => sub { $self->site_url(@_) }, |
---|
557 | site_username => sub { $self->site_username(@_) }, |
---|
558 | site_password => sub { $self->site_password(@_) }, |
---|
559 | use_offline => sub { $self->use_offline(@_) }, |
---|
560 | } |
---|
561 | ) |
---|
562 | ) unless $self->login_dlg; |
---|
563 | |
---|
564 | my $icon = Wx::Icon->new(); |
---|
565 | $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO); |
---|
566 | $self->login_dlg->SetIcon($icon); |
---|
567 | |
---|
568 | |
---|
569 | my $rval = $self->login_dlg->ShowModal(); |
---|
570 | $self->login_dlg->Show(0); |
---|
571 | |
---|
572 | $self->pwg( |
---|
573 | # get these parameters from dialog or from file |
---|
574 | Uploader::PWG->new( |
---|
575 | { |
---|
576 | site_url => $self->site_url, |
---|
577 | site_username => $self->site_username, |
---|
578 | site_password => $self->site_password, |
---|
579 | } |
---|
580 | ) |
---|
581 | ); |
---|
582 | |
---|
583 | $rval; |
---|
584 | } |
---|
585 | |
---|
586 | sub _init_userdir { |
---|
587 | my ( $self ) = @_; |
---|
588 | |
---|
589 | my $applicationName = $self->GetAppName ; |
---|
590 | my $userdatadir = File::Spec->canonpath( |
---|
591 | File::Spec->catfile( |
---|
592 | File::HomeDir->my_data(), |
---|
593 | "\.$applicationName" |
---|
594 | ) |
---|
595 | ); |
---|
596 | |
---|
597 | if(! -d $userdatadir){ |
---|
598 | if(! mkdir $userdatadir){ |
---|
599 | Wx::MessageBox( |
---|
600 | sprintf( |
---|
601 | "%s directory creation failed", |
---|
602 | $userdatadir, |
---|
603 | ), |
---|
604 | "pLoader working directory creation error", |
---|
605 | wxOK | wxICON_EXCLAMATION, |
---|
606 | ); |
---|
607 | |
---|
608 | $userdatadir = File::Spec->canonpath( |
---|
609 | File::Spec->catfile( |
---|
610 | File::Spec->tmpdir(), |
---|
611 | "\.$applicationName" |
---|
612 | ) |
---|
613 | ); |
---|
614 | mkdir $userdatadir; |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | $self->userdata_dir($userdatadir); |
---|
619 | |
---|
620 | $self->conf_file( |
---|
621 | File::Spec->catfile( |
---|
622 | $self->userdata_dir, |
---|
623 | ".$applicationName.conf" |
---|
624 | ) |
---|
625 | ); |
---|
626 | |
---|
627 | |
---|
628 | |
---|
629 | $self->storable_file( |
---|
630 | File::Spec->catfile($self->userdata_dir, 'pLoader.dat') |
---|
631 | ); |
---|
632 | |
---|
633 | my $thumbdir = File::Spec->catfile($self->userdata_dir, 'thumbnails'); |
---|
634 | mkdir $thumbdir unless -d $thumbdir ; |
---|
635 | $self->thumb_dir($thumbdir); |
---|
636 | |
---|
637 | my $wxthumbdir = File::Spec->catfile($self->userdata_dir, 'wxthumbnails'); |
---|
638 | mkdir $wxthumbdir unless -d $wxthumbdir ; |
---|
639 | $self->wx_thumb_dir($wxthumbdir); |
---|
640 | |
---|
641 | |
---|
642 | my $resizedir = File::Spec->catfile($self->userdata_dir, 'resize'); |
---|
643 | mkdir $resizedir unless -d $resizedir ; |
---|
644 | $self->resized_dir($resizedir); |
---|
645 | |
---|
646 | my $previewdir = File::Spec->catfile($self->userdata_dir, 'preview'); |
---|
647 | mkdir $previewdir unless -d $previewdir ; |
---|
648 | $self->preview_dir($previewdir); |
---|
649 | |
---|
650 | |
---|
651 | } |
---|
652 | |
---|
653 | sub _init_thumbimagelist { |
---|
654 | my ( $self ) = @_; |
---|
655 | |
---|
656 | |
---|
657 | $self->imagelist->wx_thumb_imglist( |
---|
658 | Wx::ImageList->new( |
---|
659 | $self->imagelist->wx_thumb_size, |
---|
660 | $self->imagelist->wx_thumb_size, |
---|
661 | 1, |
---|
662 | 0 |
---|
663 | ) |
---|
664 | ); |
---|
665 | |
---|
666 | # reload images |
---|
667 | $self->_reload_thumb_images; |
---|
668 | } |
---|
669 | |
---|
670 | |
---|
671 | sub _reload_thumb_images { |
---|
672 | my ( $self ) = @_; |
---|
673 | |
---|
674 | my $wximagelist = $self->imagelist->wx_thumb_imglist; |
---|
675 | my $sums = $self->imagelist->sums; |
---|
676 | |
---|
677 | map { |
---|
678 | my $image = $self->imagelist->image_sums->{$_}; |
---|
679 | |
---|
680 | $wximagelist->Add( |
---|
681 | Wx::Bitmap->new( |
---|
682 | $image->wx_thumb_file, |
---|
683 | $self->GetWxBitmapType($self->imagelist->type), |
---|
684 | ) |
---|
685 | ); |
---|
686 | } |
---|
687 | @$sums ; |
---|
688 | |
---|
689 | } |
---|
690 | |
---|
691 | sub GetWxBitmapType { |
---|
692 | my ( $self, $type ) = @_; |
---|
693 | |
---|
694 | $self->{IMGTYPE}->{$type}; |
---|
695 | } |
---|
696 | |
---|
697 | |
---|
698 | sub RescaleImage { |
---|
699 | my ( $self, $image_file, $image_file_out, $type, $ratio, $width, $height, $quality ) = @_; |
---|
700 | |
---|
701 | |
---|
702 | my $image = Wx::Image->new( |
---|
703 | $image_file, |
---|
704 | $self->GetWxBitmapType($type), |
---|
705 | 0 |
---|
706 | ); |
---|
707 | |
---|
708 | my $w; |
---|
709 | my $h; |
---|
710 | |
---|
711 | my $img_w = $image->GetWidth; |
---|
712 | my $img_h = $image->GetHeight; |
---|
713 | |
---|
714 | # use a ratio ( 25% default ) if defined |
---|
715 | # default ratio is used for preview. |
---|
716 | if($ratio){ |
---|
717 | $w = $ratio*$img_w/100 ; |
---|
718 | $h = $ratio*$img_h/100 ; |
---|
719 | } |
---|
720 | # use specified width and height |
---|
721 | else{ |
---|
722 | # portrait |
---|
723 | if( $img_w < $img_h ){ |
---|
724 | $w = $height; |
---|
725 | } |
---|
726 | else{ |
---|
727 | $w = $width; |
---|
728 | } |
---|
729 | # to respect aspect ratio |
---|
730 | $h = sprintf( |
---|
731 | "%.0f", |
---|
732 | ($w*$img_h)/$img_w |
---|
733 | ); |
---|
734 | } |
---|
735 | |
---|
736 | $image->Rescale( |
---|
737 | $w, |
---|
738 | $h, |
---|
739 | wxIMAGE_QUALITY_HIGH |
---|
740 | ); |
---|
741 | |
---|
742 | $quality ||= 90; |
---|
743 | |
---|
744 | $image->SetOption( |
---|
745 | "quality", |
---|
746 | $quality |
---|
747 | ); |
---|
748 | |
---|
749 | if(!$image->SaveFile( |
---|
750 | $image_file_out, |
---|
751 | $self->GetWxBitmapType($type), |
---|
752 | )){ |
---|
753 | Wx::LogMessage( |
---|
754 | gettext("An error has occured. Can not save file %s"), |
---|
755 | $image_file_out, |
---|
756 | ) |
---|
757 | }; |
---|
758 | } |
---|
759 | |
---|
760 | sub ResizeImage { |
---|
761 | my ( $self, $image_file, $image_file_out, $type, $width, $height, $quality ) = @_; |
---|
762 | |
---|
763 | |
---|
764 | my $image = Wx::Image->new( |
---|
765 | $image_file, |
---|
766 | $self->GetWxBitmapType($type), |
---|
767 | 0 |
---|
768 | ); |
---|
769 | |
---|
770 | my $w; |
---|
771 | my $h; |
---|
772 | |
---|
773 | my $img_w = $image->GetWidth; |
---|
774 | my $img_h = $image->GetHeight; |
---|
775 | |
---|
776 | # portrait |
---|
777 | if( $img_w < $img_h ){ |
---|
778 | $w = $height; |
---|
779 | } |
---|
780 | else{ |
---|
781 | $w = $width; |
---|
782 | } |
---|
783 | # to respect aspect ratio |
---|
784 | $h = sprintf( |
---|
785 | "%.0f", |
---|
786 | ($w*$img_h)/$img_w |
---|
787 | ); |
---|
788 | |
---|
789 | |
---|
790 | |
---|
791 | $image->Rescale( |
---|
792 | $w, |
---|
793 | $h, |
---|
794 | wxIMAGE_QUALITY_HIGH |
---|
795 | ); |
---|
796 | |
---|
797 | $image->Resize( |
---|
798 | [ $width, $height ], [ 0, 20], |
---|
799 | ); |
---|
800 | |
---|
801 | $quality ||= 90; |
---|
802 | |
---|
803 | $image->SetOption( |
---|
804 | "quality", |
---|
805 | $quality |
---|
806 | ); |
---|
807 | |
---|
808 | if(!$image->SaveFile( |
---|
809 | $image_file_out, |
---|
810 | $self->GetWxBitmapType($type), |
---|
811 | )){ |
---|
812 | Wx::LogMessage( |
---|
813 | gettext("An error has occured. Can not save file %s"), |
---|
814 | $image_file_out, |
---|
815 | ) |
---|
816 | }; |
---|
817 | } |
---|
818 | |
---|
819 | |
---|
820 | |
---|
821 | |
---|
822 | sub _init_frame { |
---|
823 | my ( $self ) = @_; |
---|
824 | |
---|
825 | my $config = Wx::ConfigBase::Get; |
---|
826 | |
---|
827 | my $x = $config->ReadInt( "X", 50 ); |
---|
828 | my $y = $config->ReadInt( "Y", 50 ); |
---|
829 | my $w = $config->ReadInt( "Width", 1024 ); |
---|
830 | my $h = $config->ReadInt( "height", 768 ); |
---|
831 | my $sv = $config->ReadInt( "splitVertical", 150 ); |
---|
832 | my $sh = $config->ReadInt( "splitHorizontal", 300 ); |
---|
833 | |
---|
834 | my $url = $self->site_url; |
---|
835 | |
---|
836 | if($self->use_offline){ |
---|
837 | $url = gettext("Work Offline"); |
---|
838 | } |
---|
839 | |
---|
840 | my ( $frame ) = Uploader::GUI::wxFrameAUI->new( |
---|
841 | { |
---|
842 | x => $x, |
---|
843 | y => $y, |
---|
844 | width => $w, |
---|
845 | height => $h, |
---|
846 | title => sprintf("pLoader - Piwigo uploader %s - [%s]", $self->version, $url), |
---|
847 | pwg => $self->pwg, |
---|
848 | imagelist => $self->imagelist, |
---|
849 | } |
---|
850 | ); |
---|
851 | |
---|
852 | #printf("Config x %s, y %s, w %s, h %s\n", $x, $y, $w, $h); |
---|
853 | #$frame->SetSize( $x, $y, $w, $h ); |
---|
854 | $frame->Show( 1 ); |
---|
855 | $self->SetTopWindow( $frame ); |
---|
856 | |
---|
857 | my $icon = Wx::Icon->new(); |
---|
858 | $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO); |
---|
859 | $frame->SetIcon($icon); |
---|
860 | } |
---|
861 | |
---|
862 | sub _readParams { |
---|
863 | my( $self, $file ) = @_ ; |
---|
864 | |
---|
865 | |
---|
866 | my $expr_params ; |
---|
867 | eval { $expr_params = read_file( $file ); } ; |
---|
868 | |
---|
869 | my $paramValues = [] ; |
---|
870 | if($expr_params){ |
---|
871 | my $expr = '$paramValues = ' ; |
---|
872 | $expr .= "$expr_params ; " ; |
---|
873 | eval $expr ; |
---|
874 | } |
---|
875 | |
---|
876 | return unless 'ARRAY' eq ref $paramValues ; |
---|
877 | |
---|
878 | if(scalar(@$paramValues )){ |
---|
879 | my $params = $paramValues->[0] ; |
---|
880 | $self->SetKeyValues($params); |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | sub _readParams2 { |
---|
885 | my( $self, $file ) = @_ ; |
---|
886 | |
---|
887 | |
---|
888 | my $expr_params ; |
---|
889 | eval { $expr_params = read_file( $file ); } ; |
---|
890 | |
---|
891 | my $paramValues = [] ; |
---|
892 | if($expr_params){ |
---|
893 | my $expr = '$paramValues = ' ; |
---|
894 | $expr .= "$expr_params ; " ; |
---|
895 | eval $expr ; |
---|
896 | } |
---|
897 | |
---|
898 | return unless 'HASH' eq ref $paramValues ; |
---|
899 | |
---|
900 | $self->SetKeyValues($paramValues); |
---|
901 | } |
---|
902 | |
---|
903 | |
---|
904 | sub SetKeyValues { |
---|
905 | my ( $self, $params )= @_; |
---|
906 | |
---|
907 | foreach( keys %$params ) { |
---|
908 | $self->{$_} = $params->{$_} ; |
---|
909 | } |
---|
910 | } |
---|
911 | |
---|
912 | |
---|
913 | 1; |
---|