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::wxFrameAUI; |
---|
21 | use strict; |
---|
22 | use Carp; |
---|
23 | use Wx; |
---|
24 | use Wx::DND; |
---|
25 | use Wx qw/ |
---|
26 | wxYES_NO |
---|
27 | wxYES |
---|
28 | wxICON_QUESTION |
---|
29 | wxITEM_NORMAL |
---|
30 | wxNullBitmap |
---|
31 | wxID_OK |
---|
32 | wxDEFAULT_FRAME_STYLE |
---|
33 | wxVERTICAL |
---|
34 | wxGROW |
---|
35 | wxBITMAP_TYPE_JPEG |
---|
36 | wxBITMAP_TYPE_GIF |
---|
37 | wxBITMAP_TYPE_PNG |
---|
38 | wxTB_FLAT |
---|
39 | wxSIZE |
---|
40 | wxWHITE |
---|
41 | wxBLACK |
---|
42 | wxID_CANCEL |
---|
43 | wxFD_OPEN |
---|
44 | wxFD_MULTIPLE |
---|
45 | wxLI_HORIZONTAL |
---|
46 | wxALIGN_CENTER_VERTICAL |
---|
47 | wxALL |
---|
48 | wxDefaultPosition |
---|
49 | wxDefaultSize |
---|
50 | wxTheApp |
---|
51 | wxIMAGE_LIST_NORMAL |
---|
52 | wxAUI_NB_TAB_MOVE |
---|
53 | wxAUI_NB_TAB_SPLIT |
---|
54 | wxNO_BORDER |
---|
55 | wxTE_MULTILINE |
---|
56 | wxTE_READONLY |
---|
57 | wxITEM_NORMAL |
---|
58 | wxCLIP_CHILDREN |
---|
59 | wxBORDER_NONE |
---|
60 | wxNullBitmap |
---|
61 | wxTR_MULTIPLE |
---|
62 | wxTR_EXTENDED |
---|
63 | wxTR_HIDE_ROOT |
---|
64 | wxTR_HAS_BUTTONS |
---|
65 | wxTR_EDIT_LABELS |
---|
66 | wxMAXIMIZE |
---|
67 | wxOK |
---|
68 | wxICON_EXCLAMATION |
---|
69 | wxICON_INFORMATION |
---|
70 | WXK_DELETE |
---|
71 | /; |
---|
72 | use base qw/Wx::Frame Class::Accessor::Fast/; |
---|
73 | use File::Spec; |
---|
74 | use Wx::Locale qw/:default/; |
---|
75 | |
---|
76 | require Win32 if($^O =~ /MSWin32/); |
---|
77 | |
---|
78 | |
---|
79 | my @properties = |
---|
80 | qw/ |
---|
81 | progressdlg |
---|
82 | upload_progressdlg |
---|
83 | imageviewer |
---|
84 | tree |
---|
85 | tree_root |
---|
86 | treeimglist |
---|
87 | tree_item_default |
---|
88 | topsizer |
---|
89 | pwg |
---|
90 | manager |
---|
91 | logwnd |
---|
92 | oldlogwnd |
---|
93 | htmlhome |
---|
94 | notebook |
---|
95 | categories |
---|
96 | imagelist |
---|
97 | image_preview |
---|
98 | image_prop_piwigo |
---|
99 | image_prop_exif |
---|
100 | image_prop_tags |
---|
101 | notebook_image_properties |
---|
102 | notebook_global_settings |
---|
103 | general_settings_panel |
---|
104 | resized_settings_panel |
---|
105 | thumbnail_settings_panel |
---|
106 | preview_settings_panel |
---|
107 | advanced_settings_panel |
---|
108 | watermark_settings_panel |
---|
109 | piwigo_properties |
---|
110 | exif_properties |
---|
111 | general_settings |
---|
112 | resized_settings |
---|
113 | thumbnail_settings |
---|
114 | preview_settings |
---|
115 | advanced_settings |
---|
116 | watermark_settings |
---|
117 | toolbar |
---|
118 | branding |
---|
119 | perspective |
---|
120 | current_imageviewer_index |
---|
121 | imageviewer_mnu |
---|
122 | tree_mnu |
---|
123 | imageviewer_select_multi |
---|
124 | frameLayout |
---|
125 | piwigo_tags |
---|
126 | image_tags |
---|
127 | /; |
---|
128 | __PACKAGE__->mk_accessors( @properties ); |
---|
129 | |
---|
130 | use Wx::Event |
---|
131 | qw/ |
---|
132 | EVT_MENU |
---|
133 | EVT_TREE_SEL_CHANGED |
---|
134 | EVT_TREE_END_LABEL_EDIT |
---|
135 | EVT_CLOSE |
---|
136 | EVT_LIST_END_LABEL_EDIT |
---|
137 | EVT_LIST_ITEM_SELECTED |
---|
138 | EVT_LIST_ITEM_ACTIVATED |
---|
139 | EVT_LIST_ITEM_RIGHT_CLICK |
---|
140 | EVT_TREE_ITEM_RIGHT_CLICK |
---|
141 | EVT_LIST_KEY_DOWN |
---|
142 | EVT_UPDATE_UI |
---|
143 | /; |
---|
144 | |
---|
145 | use Uploader::GUI::wxImageListCtrl; |
---|
146 | use Uploader::GUI::wxImageProcessingProgressDlg; |
---|
147 | use Uploader::GUI::wxChoiceFilteredPanel; |
---|
148 | use Wx::Html; |
---|
149 | use Uploader::GUI::wxHtmlWindow; |
---|
150 | use Data::Dumper; |
---|
151 | use Wx::AUI; |
---|
152 | use Storable; |
---|
153 | use Uploader::GUI::wxPropertyGridPanel; |
---|
154 | use utf8; |
---|
155 | $|=1; |
---|
156 | |
---|
157 | my $ID_TREE_CTX_MENU = 20000 ; |
---|
158 | my $ID_IMAGEVIEWER_CTX_MENU = 20100 ; |
---|
159 | |
---|
160 | sub new { |
---|
161 | my( $class, $params ) = @_; |
---|
162 | my( $self ) = $class->SUPER::new( |
---|
163 | undef, |
---|
164 | -1, |
---|
165 | $params->{title}, |
---|
166 | wxDefaultPosition, |
---|
167 | wxDefaultSize, |
---|
168 | wxDEFAULT_FRAME_STYLE |
---|
169 | ); |
---|
170 | |
---|
171 | $self->perspective( |
---|
172 | $params->{perspective} |
---|
173 | ); |
---|
174 | |
---|
175 | $self->current_imageviewer_index( |
---|
176 | $params->{imageviewer_index}||0 |
---|
177 | ); |
---|
178 | |
---|
179 | $self->frameLayout( |
---|
180 | $params->{frameLayout} || { 'pX' => -1, 'pY' => -1, W => 800, H => 600 } |
---|
181 | ); |
---|
182 | |
---|
183 | $self->pwg( $params->{pwg} ); |
---|
184 | $self->imagelist( $params->{imagelist} ); |
---|
185 | |
---|
186 | # callback for GUI refresh : add thumbnail images to the imageviewer control |
---|
187 | $self->imagelist->SetNewFilesViewerRefreshCallback( |
---|
188 | sub { $self->SetNewFilesViewerRefresh(@_) } |
---|
189 | ); |
---|
190 | |
---|
191 | # callback for GUI refresh : progress dialog display of thumbnail image being created |
---|
192 | $self->imagelist->SetNewFilesProgressCallback( |
---|
193 | sub { $self->SetNewFilesProgress(@_) } |
---|
194 | ); |
---|
195 | |
---|
196 | $self->imagelist->SetNewFilesDisplayEndInfoCallback( |
---|
197 | sub { $self->SetNewFilesDisplayEndInfo(@_) } |
---|
198 | ); |
---|
199 | |
---|
200 | |
---|
201 | # callback for GUI refresh : remove thumbnail images from imageviewer control |
---|
202 | $self->imagelist->UploadImagesViewerCallback( |
---|
203 | sub { $self->UploadImagesViewerRefresh(@_) } |
---|
204 | ); |
---|
205 | |
---|
206 | |
---|
207 | # callback for GUI refresh : progress dialog display current uploaded image |
---|
208 | $self->imagelist->progress_thumbnail_refresh( |
---|
209 | sub { $self->UploadProgressThumbnailRefresh(@_) } |
---|
210 | ); |
---|
211 | |
---|
212 | $self->imagelist->progress_msg_refresh( |
---|
213 | sub { $self->UploadProgressMessageRefresh(@_) } |
---|
214 | ); |
---|
215 | |
---|
216 | $self->imagelist->progress_msg_details_refresh( |
---|
217 | sub { $self->UploadProgressMessageDetailsRefresh(@_) } |
---|
218 | ); |
---|
219 | |
---|
220 | $self->imagelist->progressbar_refresh( |
---|
221 | sub { $self->UploadProgressBarRefresh(@_) } |
---|
222 | ); |
---|
223 | |
---|
224 | $self->imagelist->progress_endinfo_refresh( |
---|
225 | sub { $self->UploadDisplayEndInfo(@_) } |
---|
226 | ); |
---|
227 | |
---|
228 | |
---|
229 | $self->imagelist->pwg( |
---|
230 | $self->pwg |
---|
231 | ); |
---|
232 | |
---|
233 | $self->imagelist->categories( |
---|
234 | [] |
---|
235 | ); |
---|
236 | |
---|
237 | |
---|
238 | $self->manager( Wx::AuiManager->new ); |
---|
239 | $self->manager->SetManagedWindow( $self ); |
---|
240 | $self->_set_setting_properties; |
---|
241 | $self->_initFrame; |
---|
242 | $self->_initMenus; |
---|
243 | $self->_initEventHandlers; |
---|
244 | $self->_initImgTypes; |
---|
245 | |
---|
246 | |
---|
247 | $self->imageviewer->SelectItem( |
---|
248 | $self->current_imageviewer_index |
---|
249 | ) if $self->imageviewer->GetItemCount; |
---|
250 | |
---|
251 | $self; |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | sub _initImgTypes { |
---|
256 | my ( $self ) = @_; |
---|
257 | |
---|
258 | $self->{IMGTYPE} = { |
---|
259 | 'jpg' => wxBITMAP_TYPE_JPEG, |
---|
260 | 'gif' => wxBITMAP_TYPE_GIF, |
---|
261 | 'png' => wxBITMAP_TYPE_PNG, |
---|
262 | }; |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | sub GetWxBitmapType { |
---|
267 | my ( $self, $type ) = @_; |
---|
268 | |
---|
269 | $self->{IMGTYPE}->{$type}; |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | |
---|
274 | sub _set_setting_properties { |
---|
275 | my ( $self ) = @_; |
---|
276 | |
---|
277 | $self->piwigo_properties( |
---|
278 | [ |
---|
279 | { |
---|
280 | label => gettext("Photo caption :"), |
---|
281 | value => sub { $self->imagelist->current_image->site_name(@_) }, |
---|
282 | frame_callback => sub { $self->imageviewer->Refresh() }, |
---|
283 | }, |
---|
284 | { |
---|
285 | label => gettext("Comment :"), |
---|
286 | value => sub { $self->imagelist->current_image->site_comment(@_) }, |
---|
287 | type => "LongText", |
---|
288 | }, |
---|
289 | { |
---|
290 | label => gettext("Author :"), |
---|
291 | value => sub { $self->imagelist->current_image->site_author(@_) }, |
---|
292 | }, |
---|
293 | { |
---|
294 | label => gettext("File name :"), |
---|
295 | value => sub { $self->imagelist->current_image->file(@_) }, |
---|
296 | readonly => 1, |
---|
297 | }, |
---|
298 | { |
---|
299 | label => gettext("Create date :"), |
---|
300 | value => sub { $self->imagelist->current_image->create_date(@_) }, |
---|
301 | readonly => 1, |
---|
302 | }, |
---|
303 | ] |
---|
304 | ); |
---|
305 | |
---|
306 | $self->exif_properties( |
---|
307 | [ |
---|
308 | { |
---|
309 | label => gettext("Create date :"), |
---|
310 | value => sub { $self->imagelist->current_image->create_date }, |
---|
311 | readonly => 1, |
---|
312 | }, |
---|
313 | { |
---|
314 | label => gettext("Model :"), |
---|
315 | value => sub { $self->imagelist->current_image->exif_tag('Model') }, |
---|
316 | readonly => 1, |
---|
317 | }, |
---|
318 | { |
---|
319 | label => gettext("Width :"), |
---|
320 | value => sub { $self->imagelist->current_image->exif_tag('ImageWidth') }, |
---|
321 | readonly => 1, |
---|
322 | }, |
---|
323 | { |
---|
324 | label => gettext("Height :"), |
---|
325 | value => sub { $self->imagelist->current_image->exif_tag('ImageHeight') }, |
---|
326 | readonly => 1, |
---|
327 | }, |
---|
328 | { |
---|
329 | label => gettext("Orientation :"), |
---|
330 | value => sub { $self->imagelist->current_image->exif_tag('Orientation') }, |
---|
331 | readonly => 1, |
---|
332 | }, |
---|
333 | { |
---|
334 | label => "ISO :", |
---|
335 | value => sub { $self->imagelist->current_image->exif_tag('ISO') }, |
---|
336 | readonly => 1, |
---|
337 | }, |
---|
338 | { |
---|
339 | label => gettext("Shutter speed :"), |
---|
340 | value => sub { $self->imagelist->current_image->exif_tag('ExposureTime') }, |
---|
341 | readonly => 1, |
---|
342 | }, |
---|
343 | { |
---|
344 | label => gettext("Aperture :"), |
---|
345 | value => sub { $self->imagelist->current_image->exif_tag('ApertureValue') }, |
---|
346 | readonly => 1, |
---|
347 | }, |
---|
348 | { |
---|
349 | label => gettext("Focal length :"), |
---|
350 | value => sub { $self->imagelist->current_image->exif_tag('FocalLength') }, |
---|
351 | readonly => 1, |
---|
352 | }, |
---|
353 | { |
---|
354 | label => gettext("Lens :"), |
---|
355 | value => sub { $self->imagelist->current_image->exif_tag('Lens') }, |
---|
356 | readonly => 1, |
---|
357 | }, |
---|
358 | ] |
---|
359 | ); |
---|
360 | |
---|
361 | |
---|
362 | $self->general_settings( |
---|
363 | [ |
---|
364 | { |
---|
365 | label => gettext("Default author :"), |
---|
366 | value => sub { $self->imagelist->author(@_) }, |
---|
367 | }, |
---|
368 | { |
---|
369 | label => gettext("Default photo caption :"), |
---|
370 | type => 'Choice', |
---|
371 | value => sub { $self->imagelist->default_photo_name(@_) }, |
---|
372 | choice => [ |
---|
373 | map { gettext $_ } @{wxTheApp->default_photo_names} |
---|
374 | ], |
---|
375 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_default_photo_names->{$value} }, |
---|
376 | }, |
---|
377 | { |
---|
378 | label => gettext("Photo caption prefix :"), |
---|
379 | value => sub { $self->imagelist->default_name_prefix(@_) }, |
---|
380 | }, |
---|
381 | { |
---|
382 | label => gettext("Resize site image :"), |
---|
383 | type => 'Bool', |
---|
384 | value => sub { $self->imagelist->create_resized(@_) }, |
---|
385 | }, |
---|
386 | { |
---|
387 | label => gettext("Auto rotate image :"), |
---|
388 | type => 'Bool', |
---|
389 | value => sub { $self->imagelist->auto_rotate(@_) }, |
---|
390 | }, |
---|
391 | { |
---|
392 | label => gettext("Upload high (original size) :"), |
---|
393 | type => 'Bool', |
---|
394 | value => sub { $self->imagelist->upload_high(@_) }, |
---|
395 | }, |
---|
396 | { |
---|
397 | label => gettext("Remove uploaded photo from selection :"), |
---|
398 | type => 'Bool', |
---|
399 | value => sub { $self->imagelist->remove_uploaded_from_selection(@_) }, |
---|
400 | }, |
---|
401 | ] |
---|
402 | ); |
---|
403 | |
---|
404 | $self->resized_settings( |
---|
405 | [ |
---|
406 | { |
---|
407 | label => gettext("Site image width :"), |
---|
408 | type => 'Number', |
---|
409 | value => sub { $self->imagelist->resize_w(@_) }, |
---|
410 | }, |
---|
411 | { |
---|
412 | label => gettext("Site image height :"), |
---|
413 | type => 'Number', |
---|
414 | value => sub { $self->imagelist->resize_h(@_) }, |
---|
415 | }, |
---|
416 | { |
---|
417 | label => gettext("Site image jpeg quality :"), |
---|
418 | type => 'Number', |
---|
419 | value => sub { $self->imagelist->quality(@_) }, |
---|
420 | }, |
---|
421 | { |
---|
422 | label => gettext("Site image filter :"), |
---|
423 | type => 'Choice', |
---|
424 | value => sub { $self->imagelist->filter(@_) }, |
---|
425 | choice => [ qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ ], |
---|
426 | }, |
---|
427 | { |
---|
428 | label => gettext("Site image blur :"), |
---|
429 | type => 'Float', |
---|
430 | value => sub { $self->imagelist->blur(@_) }, |
---|
431 | }, |
---|
432 | { |
---|
433 | label => gettext("Site image interlace :"), |
---|
434 | type => 'Choice', |
---|
435 | value => sub { $self->imagelist->interlace(@_) }, |
---|
436 | choice => [ qw/None Line Plane Partition JPEG GIF PNG/ ], |
---|
437 | }, |
---|
438 | ] |
---|
439 | ); |
---|
440 | |
---|
441 | $self->thumbnail_settings( |
---|
442 | [ |
---|
443 | { |
---|
444 | label => gettext("Site thumbnail size :"), |
---|
445 | type => 'Number', |
---|
446 | value => sub { $self->imagelist->thumb_size(@_) }, |
---|
447 | }, |
---|
448 | { |
---|
449 | label => gettext("Site thumbnail jpeg quality :"), |
---|
450 | type => 'Number', |
---|
451 | value => sub { $self->imagelist->th_quality(@_) }, |
---|
452 | }, |
---|
453 | { |
---|
454 | label => gettext("Photo selection thumbnail size :"), |
---|
455 | type => 'Number', |
---|
456 | value => sub { $self->imagelist->wx_thumb_size(@_) }, |
---|
457 | }, |
---|
458 | { |
---|
459 | label => gettext("Photo selection thumbnail jpeg quality :"), |
---|
460 | type => 'Number', |
---|
461 | value => sub { $self->imagelist->wx_quality(@_) }, |
---|
462 | }, |
---|
463 | ] |
---|
464 | ); |
---|
465 | |
---|
466 | $self->preview_settings( |
---|
467 | [ |
---|
468 | { |
---|
469 | label => gettext("Use exif preview when available :"), |
---|
470 | type => 'Bool', |
---|
471 | value => sub { $self->imagelist->use_exif_preview(@_) }, |
---|
472 | }, |
---|
473 | { |
---|
474 | label => gettext("Custom preview ratio :"), |
---|
475 | type => 'Number', |
---|
476 | value => sub { $self->imagelist->preview_ratio(@_) }, |
---|
477 | }, |
---|
478 | ] |
---|
479 | ); |
---|
480 | |
---|
481 | $self->advanced_settings( |
---|
482 | [ |
---|
483 | { |
---|
484 | label => gettext("Transfert chunk size :"), |
---|
485 | type => 'Number', |
---|
486 | value => sub { wxTheApp->chunk_size(@_) }, |
---|
487 | }, |
---|
488 | ] |
---|
489 | ); |
---|
490 | |
---|
491 | $self->watermark_settings( |
---|
492 | [ |
---|
493 | { |
---|
494 | label => gettext("Activate watermark :"), |
---|
495 | type => 'Bool', |
---|
496 | value => sub { $self->imagelist->watermark_activate(@_) }, |
---|
497 | }, |
---|
498 | { |
---|
499 | label => gettext("Activate watermark on high definition :"), |
---|
500 | type => 'Bool', |
---|
501 | value => sub { $self->imagelist->watermark_activate_pwg_high(@_) }, |
---|
502 | }, |
---|
503 | { |
---|
504 | label => gettext("Text :"), |
---|
505 | value => sub { $self->imagelist->watermark_text(@_) }, |
---|
506 | }, |
---|
507 | { |
---|
508 | label => gettext("Text size :"), |
---|
509 | type => 'Number', |
---|
510 | value => sub { $self->imagelist->watermark_text_size(@_) }, |
---|
511 | }, |
---|
512 | { |
---|
513 | label => gettext("Color :"), |
---|
514 | type => 'Choice', |
---|
515 | value => sub { $self->imagelist->watermark_color(@_) }, |
---|
516 | choice => [ |
---|
517 | map { gettext $_ } @{wxTheApp->colors} |
---|
518 | ], |
---|
519 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_colors->{$value} }, |
---|
520 | }, |
---|
521 | { |
---|
522 | label => gettext("Position :"), |
---|
523 | type => 'Choice', |
---|
524 | value => sub { $self->imagelist->watermark_position(@_) }, |
---|
525 | choice => [ |
---|
526 | map { gettext $_ } @{wxTheApp->positions} |
---|
527 | ], |
---|
528 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_positions->{$value} }, |
---|
529 | }, |
---|
530 | { |
---|
531 | label => gettext("Top margin :"), |
---|
532 | type => 'Number', |
---|
533 | value => sub { $self->imagelist->watermark_y(@_) }, |
---|
534 | }, |
---|
535 | { |
---|
536 | label => gettext("Left margin :"), |
---|
537 | type => 'Number', |
---|
538 | value => sub { $self->imagelist->watermark_x(@_) }, |
---|
539 | }, |
---|
540 | ] |
---|
541 | ); |
---|
542 | |
---|
543 | $self->image_tags( |
---|
544 | sub { eval { $self->imagelist->current_image->site_tags(@_) } } |
---|
545 | ); |
---|
546 | |
---|
547 | $self->piwigo_tags( |
---|
548 | sub { wxTheApp->pwg->tags } |
---|
549 | ); |
---|
550 | } |
---|
551 | |
---|
552 | sub _create_piwigo_tag { |
---|
553 | my ( $self, $name ) = @_; |
---|
554 | |
---|
555 | if( |
---|
556 | Wx::MessageBox( |
---|
557 | sprintf( |
---|
558 | gettext("Do you want to create \"%s\" ?"), |
---|
559 | $name, |
---|
560 | ), |
---|
561 | gettext("Piwigo search information"), |
---|
562 | wxYES_NO | wxICON_QUESTION, |
---|
563 | ) == wxYES |
---|
564 | ){ |
---|
565 | $self->pwg->AddTags($name); |
---|
566 | $self->pwg->RefreshTags; |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | sub _refreshFrame { |
---|
571 | my ( $self ) = @_; |
---|
572 | |
---|
573 | $self->_set_setting_properties; |
---|
574 | $self->_refresh_settings_panels_properties; |
---|
575 | map { |
---|
576 | $_->Refresh; |
---|
577 | } |
---|
578 | ( |
---|
579 | $self->image_prop_piwigo, |
---|
580 | $self->image_prop_exif, |
---|
581 | $self->image_prop_tags, |
---|
582 | $self->general_settings_panel, |
---|
583 | $self->resized_settings_panel, |
---|
584 | $self->thumbnail_settings_panel, |
---|
585 | $self->preview_settings_panel, |
---|
586 | $self->advanced_settings_panel, |
---|
587 | $self->watermark_settings_panel, |
---|
588 | ); |
---|
589 | |
---|
590 | $self->manager->Update; |
---|
591 | } |
---|
592 | |
---|
593 | |
---|
594 | sub _destroy_settings_panels { |
---|
595 | my ( $self ) = @_; |
---|
596 | |
---|
597 | |
---|
598 | |
---|
599 | map { |
---|
600 | $self->manager->DetachPane( |
---|
601 | $_ |
---|
602 | ); |
---|
603 | $_->Show(0); |
---|
604 | $_->Destroy; |
---|
605 | }( |
---|
606 | $self->notebook_global_settings, |
---|
607 | $self->notebook_image_properties, |
---|
608 | ); |
---|
609 | } |
---|
610 | |
---|
611 | # |
---|
612 | sub _initFrame { |
---|
613 | my ( $self ) = @_; |
---|
614 | |
---|
615 | |
---|
616 | $self->init_panels; |
---|
617 | |
---|
618 | $self->init_aui; |
---|
619 | $self->init_dnd_targets; |
---|
620 | |
---|
621 | if( $self->imagelist->wx_thumb_imglist->GetImageCount){ |
---|
622 | printf("%s images\n", $self->imagelist->wx_thumb_imglist->GetImageCount); |
---|
623 | $self->ShowImageViewer; |
---|
624 | |
---|
625 | $self->imageviewer->Refresh( |
---|
626 | $self->imagelist->wx_thumb_imglist |
---|
627 | ); |
---|
628 | |
---|
629 | } |
---|
630 | |
---|
631 | } |
---|
632 | |
---|
633 | sub _refresh_settings_panels_properties { |
---|
634 | my ( $self ) = @_; |
---|
635 | |
---|
636 | $self->image_prop_piwigo->properties( |
---|
637 | $self->piwigo_properties |
---|
638 | ); |
---|
639 | |
---|
640 | $self->image_prop_exif->properties( |
---|
641 | $self->exif_properties |
---|
642 | ); |
---|
643 | |
---|
644 | |
---|
645 | $self->general_settings_panel->properties( |
---|
646 | $self->general_settings |
---|
647 | ); |
---|
648 | |
---|
649 | $self->resized_settings_panel->properties( |
---|
650 | $self->resized_settings |
---|
651 | ); |
---|
652 | |
---|
653 | $self->thumbnail_settings_panel->properties( |
---|
654 | $self->thumbnail_settings, |
---|
655 | ); |
---|
656 | |
---|
657 | $self->preview_settings_panel->properties( |
---|
658 | $self->preview_settings, |
---|
659 | ); |
---|
660 | |
---|
661 | $self->advanced_settings_panel->properties( |
---|
662 | $self->advanced_settings, |
---|
663 | ); |
---|
664 | |
---|
665 | $self->watermark_settings_panel->properties( |
---|
666 | $self->watermark_settings, |
---|
667 | ); |
---|
668 | |
---|
669 | } |
---|
670 | |
---|
671 | sub _init_settings_panels { |
---|
672 | my ( $self ) = @_; |
---|
673 | |
---|
674 | $self->image_prop_piwigo( |
---|
675 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
676 | { |
---|
677 | parentwnd => $self, |
---|
678 | properties => $self->piwigo_properties, |
---|
679 | } |
---|
680 | ) |
---|
681 | ); |
---|
682 | |
---|
683 | $self->image_prop_exif( |
---|
684 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
685 | { |
---|
686 | parentwnd => $self, |
---|
687 | properties => $self->exif_properties, |
---|
688 | } |
---|
689 | ) |
---|
690 | ); |
---|
691 | |
---|
692 | |
---|
693 | $self->general_settings_panel( |
---|
694 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
695 | { |
---|
696 | parentwnd => $self, |
---|
697 | properties => $self->general_settings, |
---|
698 | } |
---|
699 | ) |
---|
700 | ); |
---|
701 | |
---|
702 | $self->resized_settings_panel( |
---|
703 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
704 | { |
---|
705 | parentwnd => $self, |
---|
706 | properties => $self->resized_settings, |
---|
707 | |
---|
708 | } |
---|
709 | ) |
---|
710 | ); |
---|
711 | |
---|
712 | $self->thumbnail_settings_panel( |
---|
713 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
714 | { |
---|
715 | parentwnd => $self, |
---|
716 | properties => $self->thumbnail_settings, |
---|
717 | |
---|
718 | } |
---|
719 | ) |
---|
720 | ); |
---|
721 | $self->preview_settings_panel( |
---|
722 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
723 | { |
---|
724 | parentwnd => $self, |
---|
725 | properties => $self->preview_settings, |
---|
726 | |
---|
727 | } |
---|
728 | ) |
---|
729 | ); |
---|
730 | |
---|
731 | $self->advanced_settings_panel( |
---|
732 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
733 | { |
---|
734 | parentwnd => $self, |
---|
735 | properties => $self->advanced_settings, |
---|
736 | |
---|
737 | } |
---|
738 | ) |
---|
739 | ); |
---|
740 | |
---|
741 | $self->watermark_settings_panel( |
---|
742 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
743 | { |
---|
744 | parentwnd => $self, |
---|
745 | properties => $self->watermark_settings, |
---|
746 | } |
---|
747 | ) |
---|
748 | ); |
---|
749 | |
---|
750 | $self->image_prop_tags( |
---|
751 | Uploader::GUI::wxChoiceFilteredPanel->new( |
---|
752 | { |
---|
753 | parentwnd => $self, |
---|
754 | choices => $self->piwigo_tags, |
---|
755 | selection => $self->image_tags, |
---|
756 | creation_callback => sub { $self->_create_piwigo_tag(@_) }, |
---|
757 | } |
---|
758 | ) |
---|
759 | ); |
---|
760 | |
---|
761 | |
---|
762 | $self->general_settings_panel->Show(0); |
---|
763 | |
---|
764 | $self->image_preview( |
---|
765 | Wx::HtmlWindow->new( |
---|
766 | $self, |
---|
767 | -1, |
---|
768 | [-1,-1], |
---|
769 | [-1,-1], |
---|
770 | ) |
---|
771 | ); |
---|
772 | |
---|
773 | |
---|
774 | $self->image_prop_piwigo->Show(0); |
---|
775 | |
---|
776 | $self->image_prop_exif->Show(0); |
---|
777 | |
---|
778 | } |
---|
779 | |
---|
780 | sub init_panels { |
---|
781 | my ( $self ) = @_; |
---|
782 | |
---|
783 | my $file = sprintf( |
---|
784 | "../locale/%s/gs.html", |
---|
785 | wxTheApp->locale->GetCanonicalName |
---|
786 | ); |
---|
787 | |
---|
788 | $self->htmlhome( |
---|
789 | Uploader::GUI::wxHtmlWindow->new( |
---|
790 | $self, -1, [-1, -1], [450, 450] |
---|
791 | ) |
---|
792 | ); |
---|
793 | |
---|
794 | $self->htmlhome->LoadPage($file) if -e $file ; |
---|
795 | |
---|
796 | $self->htmlhome->InitHrefCallbacks( |
---|
797 | { |
---|
798 | new_album => sub {$self->OnAddCategories(@_) }, |
---|
799 | add_photos => sub { $self->OnAddImages(@_) }, |
---|
800 | upload_photos => sub { $self->ProcessImageSelection(@_)}, |
---|
801 | } |
---|
802 | ); |
---|
803 | |
---|
804 | $self->imageviewer( |
---|
805 | Uploader::GUI::wxImageListCtrl->new( |
---|
806 | { |
---|
807 | parentwnd => $self, |
---|
808 | imagelist => $self->imagelist, |
---|
809 | } |
---|
810 | ) |
---|
811 | ); |
---|
812 | |
---|
813 | $self->_init_settings_panels; |
---|
814 | } |
---|
815 | |
---|
816 | sub init_dnd_targets { |
---|
817 | my ( $self ) = @_; |
---|
818 | |
---|
819 | $self->imageviewer->SetDropTarget( |
---|
820 | DNDImageListDropTarget->new( |
---|
821 | $self->imageviewer |
---|
822 | ) |
---|
823 | ); |
---|
824 | |
---|
825 | $self->tree->SetDropTarget( |
---|
826 | DNDCategoryTreeDropTarget->new( |
---|
827 | $self->tree |
---|
828 | ) |
---|
829 | ); |
---|
830 | |
---|
831 | } |
---|
832 | |
---|
833 | sub init_aui { |
---|
834 | my ( $self ) = @_; |
---|
835 | |
---|
836 | my $url = wxTheApp->site_url; |
---|
837 | |
---|
838 | $url = gettext("empty - work Offline") if wxTheApp->use_offline; |
---|
839 | |
---|
840 | $self->manager->AddPane |
---|
841 | ( $self->create_notebook_imagelist, Wx::AuiPaneInfo->new->Name( "ImageViewer" ) |
---|
842 | ->CenterPane->Resizable->CloseButton(0) ); |
---|
843 | |
---|
844 | $self->manager->AddPane( |
---|
845 | $self->create_tree, |
---|
846 | Wx::AuiPaneInfo->new->Name( "categories" ) |
---|
847 | ->Right->Position( 0 )->Resizable->CloseButton(0), |
---|
848 | ); |
---|
849 | |
---|
850 | |
---|
851 | |
---|
852 | $self->_init_aui_settings_panels; |
---|
853 | |
---|
854 | $self->toolbar( |
---|
855 | $self->create_toolbar |
---|
856 | ); |
---|
857 | |
---|
858 | $self->manager->AddPane |
---|
859 | ( $self->toolbar, Wx::AuiPaneInfo->new->Name( "tb1" ) |
---|
860 | ->ToolbarPane->Top->Row( 1 )->LeftDockable( 0 )->RightDockable( 0 ) ) if defined $self->toolbar; |
---|
861 | |
---|
862 | $self->SetSize( |
---|
863 | $self->frameLayout->{pX}, |
---|
864 | $self->frameLayout->{pY}, |
---|
865 | $self->frameLayout->{W}, |
---|
866 | $self->frameLayout->{H}, |
---|
867 | ); |
---|
868 | |
---|
869 | |
---|
870 | if($self->perspective){ |
---|
871 | $self->manager->LoadPerspective($self->perspective); |
---|
872 | } |
---|
873 | else { |
---|
874 | $self->manager->GetPane("categories")->MinSize(300,100); |
---|
875 | |
---|
876 | $self->manager->GetPane("tb1")->Caption( gettext("Tools") ); |
---|
877 | $self->manager->GetPane("image_preview")->Caption(gettext("Preview"))->Show(0); |
---|
878 | $self->manager->GetPane("getting_started")->Caption(gettext("Getting started"))->Float->Show(1); |
---|
879 | $self->manager->GetPane("photo_properties")->Caption(gettext("Photo properties"))->Float->Show(0); |
---|
880 | $self->manager->GetPane("global_settings")->Caption(gettext("Global settings"))->Float->Show(0); |
---|
881 | } |
---|
882 | |
---|
883 | $self->manager->GetPane("categories")->Caption( |
---|
884 | sprintf("%s - %s", sprintf("Piwigo %s", wxTheApp->branding->{categories}), $url ) |
---|
885 | ); |
---|
886 | |
---|
887 | $self->manager->Update; |
---|
888 | |
---|
889 | } |
---|
890 | |
---|
891 | |
---|
892 | sub _init_aui_settings_panels { |
---|
893 | my ( $self ) = @_; |
---|
894 | |
---|
895 | $self->manager->AddPane |
---|
896 | ( $self->image_preview, Wx::AuiPaneInfo->new->Name( "image_preview" ) |
---|
897 | ->Floatable(1)->Resizable->CloseButton(1)); |
---|
898 | |
---|
899 | $self->manager->AddPane |
---|
900 | ( $self->htmlhome, Wx::AuiPaneInfo->new->Name( "getting_started" ) |
---|
901 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
902 | |
---|
903 | $self->manager->AddPane |
---|
904 | ( $self->create_notebook_image_properties, Wx::AuiPaneInfo->new->Name( "photo_properties" ) |
---|
905 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
906 | |
---|
907 | $self->manager->AddPane |
---|
908 | ( $self->create_notebook_global_settings, Wx::AuiPaneInfo->new->Name( "global_settings" ) |
---|
909 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
910 | |
---|
911 | } |
---|
912 | |
---|
913 | sub OnPhotoProperties { |
---|
914 | my ( $self ) = @_; |
---|
915 | |
---|
916 | $self->manager->GetPane("photo_properties")->Show(1); |
---|
917 | $self->manager->Update(); |
---|
918 | |
---|
919 | } |
---|
920 | |
---|
921 | sub OnPreview { |
---|
922 | my ( $self ) = @_; |
---|
923 | |
---|
924 | $self->manager->GetPane("image_preview")->Float->Show(1); |
---|
925 | $self->manager->Update(); |
---|
926 | |
---|
927 | } |
---|
928 | |
---|
929 | sub OnGettingStarted { |
---|
930 | my ( $self ) = @_; |
---|
931 | |
---|
932 | $self->toolbar->EnableTool(100, 0 ); |
---|
933 | $self->manager->GetPane("getting_started")->Float->Show(1); |
---|
934 | $self->manager->Update(); |
---|
935 | |
---|
936 | } |
---|
937 | |
---|
938 | sub OnGlobalSettings { |
---|
939 | my ( $self ) = @_; |
---|
940 | |
---|
941 | $self->toolbar->EnableTool(104, 0 ); |
---|
942 | $self->manager->GetPane("global_settings")->Float->Show(1); |
---|
943 | $self->manager->Update(); |
---|
944 | } |
---|
945 | |
---|
946 | sub OnChooseLanguage { |
---|
947 | my ( $self ) = @_; |
---|
948 | |
---|
949 | my $languages = wxTheApp->available_languages; |
---|
950 | |
---|
951 | |
---|
952 | my $dialog = new Wx::SingleChoiceDialog( |
---|
953 | undef, |
---|
954 | gettext( "Choose a language" ), |
---|
955 | gettext( "Choose a language" ), |
---|
956 | [ map { sprintf($_->[0], gettext($_->[2])) } @$languages ] |
---|
957 | ); |
---|
958 | |
---|
959 | if( $dialog->ShowModal() == wxID_OK ) { |
---|
960 | wxTheApp->current_language( |
---|
961 | $languages->[$dialog->GetSelection][1] |
---|
962 | ); |
---|
963 | |
---|
964 | Wx::LogMessage( |
---|
965 | sprintf( |
---|
966 | "%s : %s", |
---|
967 | gettext("pLoader needs to be restarted to display the new selected language"), |
---|
968 | gettext($languages->[$dialog->GetSelection][2]) |
---|
969 | ) |
---|
970 | ); |
---|
971 | wxTheApp->layout_clean(1); |
---|
972 | } |
---|
973 | |
---|
974 | $dialog->Destroy; |
---|
975 | |
---|
976 | } |
---|
977 | |
---|
978 | sub OnDefaultPhotoNameChanged { |
---|
979 | my ( $self ) = @_; |
---|
980 | |
---|
981 | Wx::LogMessage("New default_photo_name %s", $self->imagelist->default_photo_name); |
---|
982 | } |
---|
983 | |
---|
984 | |
---|
985 | sub create_notebook_imagelist { |
---|
986 | my( $self ) = @_; |
---|
987 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [300, 450], |
---|
988 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
989 | |
---|
990 | my $imglistpage = [ |
---|
991 | [ |
---|
992 | $self->imageviewer, |
---|
993 | gettext("Photo selection"), |
---|
994 | '../res/images.png', |
---|
995 | wxBITMAP_TYPE_PNG, |
---|
996 | ], |
---|
997 | ]; |
---|
998 | |
---|
999 | $self->notebook($book); |
---|
1000 | $self->_populate_notebook($self->notebook, $imglistpage, 0); |
---|
1001 | return $book; |
---|
1002 | } |
---|
1003 | |
---|
1004 | sub create_notebook_image_properties { |
---|
1005 | my( $self ) = @_; |
---|
1006 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
---|
1007 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
1008 | my $pages = [ |
---|
1009 | [ |
---|
1010 | $self->image_prop_piwigo, |
---|
1011 | "Piwigo", |
---|
1012 | ], |
---|
1013 | [ |
---|
1014 | $self->image_prop_tags, |
---|
1015 | "Tags", |
---|
1016 | ], |
---|
1017 | [ |
---|
1018 | $self->image_prop_exif, |
---|
1019 | "Exif", |
---|
1020 | ], |
---|
1021 | ]; |
---|
1022 | |
---|
1023 | $self->_populate_notebook( $book, $pages ); |
---|
1024 | |
---|
1025 | $self->notebook_image_properties($book); |
---|
1026 | |
---|
1027 | return $book; |
---|
1028 | } |
---|
1029 | |
---|
1030 | sub create_notebook_global_settings { |
---|
1031 | my( $self ) = @_; |
---|
1032 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
---|
1033 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
1034 | my $pages = [ |
---|
1035 | [ |
---|
1036 | $self->general_settings_panel, |
---|
1037 | gettext("General"), |
---|
1038 | ], |
---|
1039 | [ |
---|
1040 | $self->resized_settings_panel, |
---|
1041 | gettext("Resized"), |
---|
1042 | ], |
---|
1043 | [ |
---|
1044 | $self->thumbnail_settings_panel, |
---|
1045 | gettext("Thumbnail"), |
---|
1046 | ], |
---|
1047 | [ |
---|
1048 | $self->preview_settings_panel, |
---|
1049 | gettext("Preview"), |
---|
1050 | ], |
---|
1051 | [ |
---|
1052 | $self->advanced_settings_panel, |
---|
1053 | gettext("Advanced"), |
---|
1054 | ], |
---|
1055 | [ |
---|
1056 | $self->watermark_settings_panel, |
---|
1057 | gettext("Watermark"), |
---|
1058 | ] |
---|
1059 | ]; |
---|
1060 | |
---|
1061 | $self->_populate_notebook( $book, $pages ); |
---|
1062 | |
---|
1063 | $self->notebook_global_settings($book); |
---|
1064 | |
---|
1065 | return $book; |
---|
1066 | } |
---|
1067 | |
---|
1068 | |
---|
1069 | |
---|
1070 | |
---|
1071 | sub create_tree { |
---|
1072 | my ( $self ) = @_; |
---|
1073 | |
---|
1074 | my $images = [ |
---|
1075 | map { |
---|
1076 | Wx::Bitmap->new( $_, wxBITMAP_TYPE_PNG ) |
---|
1077 | |
---|
1078 | } |
---|
1079 | ( |
---|
1080 | '../res/tree_pwg.png', |
---|
1081 | '../res/tree_folder.png', |
---|
1082 | ) |
---|
1083 | ]; |
---|
1084 | |
---|
1085 | $self->treeimglist( Wx::ImageList->new( 16, 16, 1 ) ); |
---|
1086 | map { |
---|
1087 | $self->treeimglist->Add($_); |
---|
1088 | } |
---|
1089 | @$images; |
---|
1090 | |
---|
1091 | |
---|
1092 | $self->tree( |
---|
1093 | Wx::TreeCtrl->new( |
---|
1094 | $self, |
---|
1095 | -1, |
---|
1096 | wxDefaultPosition, |
---|
1097 | wxDefaultSize, |
---|
1098 | wxBORDER_NONE| |
---|
1099 | wxCLIP_CHILDREN| |
---|
1100 | wxTR_HAS_BUTTONS| |
---|
1101 | wxTR_EDIT_LABELS |
---|
1102 | ) |
---|
1103 | ); |
---|
1104 | |
---|
1105 | $self->tree->SetImageList( $self->treeimglist ); |
---|
1106 | $self->populate_tree_categories if !wxTheApp->use_offline; |
---|
1107 | $self->tree ; |
---|
1108 | } |
---|
1109 | |
---|
1110 | |
---|
1111 | sub populate_tree_categories { |
---|
1112 | my ( $self ) = @_; |
---|
1113 | |
---|
1114 | $self->populate_tree( |
---|
1115 | $self->tree, |
---|
1116 | wxTheApp->pwg->categories, |
---|
1117 | ) if defined wxTheApp->pwg ; |
---|
1118 | |
---|
1119 | #$self->tree->ExpandAll; |
---|
1120 | |
---|
1121 | } |
---|
1122 | |
---|
1123 | |
---|
1124 | # returns a valid itemData |
---|
1125 | sub itemData { Wx::TreeItemData->new( $_[0] ) } |
---|
1126 | |
---|
1127 | sub populate_tree { |
---|
1128 | my ( $self, $tree, $tree_items ) = @_; |
---|
1129 | my $root = shift @{$tree_items}; |
---|
1130 | |
---|
1131 | $self->tree_root( |
---|
1132 | $tree->AddRoot( |
---|
1133 | $root->[0], |
---|
1134 | $root->[3], |
---|
1135 | $root->[4], |
---|
1136 | itemData( $root->[2] ) |
---|
1137 | ) |
---|
1138 | ); |
---|
1139 | |
---|
1140 | $self->populate_tree_helper( $tree, $self->tree_root, $tree_items ); |
---|
1141 | |
---|
1142 | $tree->SelectItem( $self->tree_root ); |
---|
1143 | $tree->Expand( $self->tree_root ); |
---|
1144 | } |
---|
1145 | |
---|
1146 | sub populate_tree_helper { |
---|
1147 | my ( $self, $tree, $parent_id, $tree_items ) = @_; |
---|
1148 | |
---|
1149 | my $id; |
---|
1150 | |
---|
1151 | map { |
---|
1152 | my $name = $_->[0]; |
---|
1153 | |
---|
1154 | $id = $tree->AppendItem( |
---|
1155 | $parent_id, |
---|
1156 | $name, |
---|
1157 | defined($_->[3]) ? $_->[3] : 0, |
---|
1158 | defined($_->[4]) ? $_->[4] : 0, |
---|
1159 | itemData( $_->[2]) |
---|
1160 | ); |
---|
1161 | $self->tree_item_default($id) if ! defined $self->tree_item_default; |
---|
1162 | # current item has children |
---|
1163 | if( ref( $_->[1] ) eq 'ARRAY' ) { |
---|
1164 | $self->populate_tree_helper( $tree, $id, $_->[1] ); |
---|
1165 | } |
---|
1166 | } |
---|
1167 | @{$tree_items}; |
---|
1168 | |
---|
1169 | } |
---|
1170 | |
---|
1171 | |
---|
1172 | |
---|
1173 | |
---|
1174 | sub _populate_notebook { |
---|
1175 | my ( $self, $book, $pages, $position ) = @_; |
---|
1176 | |
---|
1177 | my $i = 0; |
---|
1178 | map { |
---|
1179 | my $icon = Wx::Icon->new(); |
---|
1180 | eval { $icon->LoadFile($_->[2], $_->[3]) ; } |
---|
1181 | if defined $_->[2]; |
---|
1182 | my $nb_icon = Wx::Bitmap->new( $icon ); |
---|
1183 | defined $position ? |
---|
1184 | $book->InsertPage($position, $_->[0], |
---|
1185 | $_->[1], 1, $nb_icon ) |
---|
1186 | : |
---|
1187 | $book->AddPage($_->[0], |
---|
1188 | $_->[1], 0, $nb_icon ); |
---|
1189 | |
---|
1190 | $i++; |
---|
1191 | } @$pages; |
---|
1192 | |
---|
1193 | } |
---|
1194 | |
---|
1195 | |
---|
1196 | sub _initMenus { |
---|
1197 | my ( $self ) = @_ ; |
---|
1198 | |
---|
1199 | $self->_tree_mnu; |
---|
1200 | $self->_imageviewer_mnu; |
---|
1201 | } |
---|
1202 | |
---|
1203 | |
---|
1204 | sub _tree_mnu { |
---|
1205 | my ( $self ) = @_; |
---|
1206 | |
---|
1207 | my $ctx_mnu = Wx::Menu->new; |
---|
1208 | |
---|
1209 | map { |
---|
1210 | $ctx_mnu->Append( |
---|
1211 | @$_[0..2], wxITEM_NORMAL |
---|
1212 | )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG)); |
---|
1213 | } |
---|
1214 | ( |
---|
1215 | # workaround : first item does not show bitmap |
---|
1216 | [ |
---|
1217 | 0, |
---|
1218 | "", |
---|
1219 | "", |
---|
1220 | '../res/mnu_folder_new.png', |
---|
1221 | ], |
---|
1222 | [ |
---|
1223 | 1+$ID_TREE_CTX_MENU, |
---|
1224 | wxTheApp->branding->{'Add new category'}, |
---|
1225 | sprintf( |
---|
1226 | "%s %s %s %s", |
---|
1227 | gettext("Add a new"), |
---|
1228 | wxTheApp->branding->{category}, |
---|
1229 | gettext("to the currently selected"), |
---|
1230 | wxTheApp->branding->{category}, |
---|
1231 | ), |
---|
1232 | '../res/mnu_folder_new.png', |
---|
1233 | ], |
---|
1234 | [ |
---|
1235 | 2+$ID_TREE_CTX_MENU, |
---|
1236 | gettext("Refresh"), |
---|
1237 | sprintf( |
---|
1238 | "Refresh %s list.", |
---|
1239 | wxTheApp->branding->{category}, |
---|
1240 | ), |
---|
1241 | '../res/mnu_refresh.png', |
---|
1242 | ], |
---|
1243 | [ |
---|
1244 | 3+$ID_TREE_CTX_MENU, |
---|
1245 | gettext("Expand all"), |
---|
1246 | sprintf( |
---|
1247 | "Expand %s list.", |
---|
1248 | wxTheApp->branding->{category}, |
---|
1249 | ), |
---|
1250 | '../res/mnu_expandall.png', |
---|
1251 | ], |
---|
1252 | [ |
---|
1253 | 4+$ID_TREE_CTX_MENU, |
---|
1254 | gettext("Collapse all"), |
---|
1255 | sprintf( |
---|
1256 | "Collapse %s list.", |
---|
1257 | wxTheApp->branding->{category}, |
---|
1258 | ), |
---|
1259 | '../res/mnu_collapseall.png', |
---|
1260 | ], |
---|
1261 | ); |
---|
1262 | |
---|
1263 | $ctx_mnu->Delete(0); |
---|
1264 | $self->tree_mnu( |
---|
1265 | $ctx_mnu |
---|
1266 | ); |
---|
1267 | } |
---|
1268 | |
---|
1269 | sub _imageviewer_mnu { |
---|
1270 | my ( $self ) = @_; |
---|
1271 | |
---|
1272 | my $ctx_mnu = Wx::Menu->new; |
---|
1273 | |
---|
1274 | map { |
---|
1275 | $ctx_mnu->Append( |
---|
1276 | @$_[0..2] |
---|
1277 | )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG)); |
---|
1278 | } |
---|
1279 | ( |
---|
1280 | # workaround : first item does not show bitmap |
---|
1281 | [ |
---|
1282 | 0, |
---|
1283 | "", |
---|
1284 | "", |
---|
1285 | '../res/mnu_properties.png', |
---|
1286 | ], |
---|
1287 | [ |
---|
1288 | 1+$ID_IMAGEVIEWER_CTX_MENU, |
---|
1289 | gettext("Properties"), |
---|
1290 | gettext("Modify photo properties"), |
---|
1291 | '../res/mnu_properties.png', |
---|
1292 | ], |
---|
1293 | [ |
---|
1294 | 2+$ID_IMAGEVIEWER_CTX_MENU, |
---|
1295 | gettext("Preview"), |
---|
1296 | gettext("Display photo preview"), |
---|
1297 | '../res/mnu_preview.png', |
---|
1298 | ], |
---|
1299 | ); |
---|
1300 | |
---|
1301 | $ctx_mnu->Delete(0); |
---|
1302 | $self->imageviewer_mnu( |
---|
1303 | $ctx_mnu |
---|
1304 | ); |
---|
1305 | } |
---|
1306 | |
---|
1307 | sub _initEventHandlers { |
---|
1308 | my ( $self ) = @_ ; |
---|
1309 | |
---|
1310 | Wx::Event::EVT_MENU( $self, 100, \&OnGettingStarted ); |
---|
1311 | Wx::Event::EVT_MENU( $self, 101, \&OnAddImages ); |
---|
1312 | Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages ); |
---|
1313 | Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages ); |
---|
1314 | Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings ); |
---|
1315 | Wx::Event::EVT_MENU( $self, 105, \&OnChooseLanguage ); |
---|
1316 | EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged ); |
---|
1317 | EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick ); |
---|
1318 | EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&OnTreeEndLabelEdit ); |
---|
1319 | |
---|
1320 | EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit ); |
---|
1321 | EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated ); |
---|
1322 | EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ; |
---|
1323 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ; |
---|
1324 | |
---|
1325 | EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ; |
---|
1326 | |
---|
1327 | EVT_CLOSE( $self, \&OnClose ); |
---|
1328 | Wx::Event::EVT_UPDATE_UI( $self, $self, \&OnUpdateUI ); |
---|
1329 | |
---|
1330 | |
---|
1331 | Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories ); |
---|
1332 | Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories ); |
---|
1333 | Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories ); |
---|
1334 | Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&OnCollapseCategories ); |
---|
1335 | |
---|
1336 | Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties ); |
---|
1337 | Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview ); |
---|
1338 | |
---|
1339 | |
---|
1340 | } |
---|
1341 | |
---|
1342 | { |
---|
1343 | my $prevdir; |
---|
1344 | my $prevfile; |
---|
1345 | |
---|
1346 | sub OnAddImages { |
---|
1347 | my( $self, $event ) = @_; |
---|
1348 | my $dialog = Wx::FileDialog->new |
---|
1349 | ( $self, gettext("Select photos for upload"), $prevfile, $prevdir, |
---|
1350 | sprintf("%s (*.jpg)|*.jpg|All(*.*)|*.*", gettext("JPEG files")), |
---|
1351 | wxFD_OPEN|wxFD_MULTIPLE ); |
---|
1352 | |
---|
1353 | my $file_paths = []; |
---|
1354 | if( $dialog->ShowModal != wxID_CANCEL ) { |
---|
1355 | @$file_paths = $dialog->GetPaths; |
---|
1356 | $self->SetNewFiles($file_paths) ; |
---|
1357 | } |
---|
1358 | $dialog->Destroy; |
---|
1359 | # $event->Skip; |
---|
1360 | } |
---|
1361 | } |
---|
1362 | |
---|
1363 | sub OnUpdateUI { |
---|
1364 | my( $self, $event ) = @_; |
---|
1365 | |
---|
1366 | if( $self->manager ){ |
---|
1367 | if($self->manager->GetPane("global_settings")->IsShown){ |
---|
1368 | $self->toolbar->EnableTool(104, 0); |
---|
1369 | } |
---|
1370 | else{ |
---|
1371 | $self->toolbar->EnableTool(104, 1); |
---|
1372 | } |
---|
1373 | |
---|
1374 | if($self->manager->GetPane("getting_started")->IsShown){ |
---|
1375 | $self->toolbar->EnableTool(100, 0); |
---|
1376 | } |
---|
1377 | else{ |
---|
1378 | $self->toolbar->EnableTool(100, 1); |
---|
1379 | } |
---|
1380 | } |
---|
1381 | |
---|
1382 | } |
---|
1383 | |
---|
1384 | sub OnRemoveImages { |
---|
1385 | my( $self, $event ) = @_; |
---|
1386 | |
---|
1387 | |
---|
1388 | $self->imagelist->RemoveImageSelection; |
---|
1389 | $self->imageviewer->Refresh; |
---|
1390 | |
---|
1391 | $self->image_preview->SetPage( |
---|
1392 | "<html></html>" |
---|
1393 | ) if !$self->imageviewer->GetItemCount; |
---|
1394 | |
---|
1395 | } |
---|
1396 | |
---|
1397 | sub SetNewFiles { |
---|
1398 | my ( $self, $file_paths ) = @_; |
---|
1399 | |
---|
1400 | $self->ShowImageViewer(); |
---|
1401 | $self->progressdlg( |
---|
1402 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
---|
1403 | { |
---|
1404 | title => gettext("Image processing progress information"), |
---|
1405 | bt_label => gettext("Cancel image processing"), |
---|
1406 | bt_close_label => gettext("Close"), |
---|
1407 | } |
---|
1408 | ) |
---|
1409 | ); |
---|
1410 | $self->progressdlg->Show(1); |
---|
1411 | Wx::Yield(); |
---|
1412 | |
---|
1413 | |
---|
1414 | my $files = [ |
---|
1415 | map { |
---|
1416 | # to make sure that unicode chars in filenames are supported |
---|
1417 | { |
---|
1418 | ANSIPathName => $^O =~ /MSWin32/ ? Win32::GetANSIPathName($_) : $_, |
---|
1419 | PathName => $_, |
---|
1420 | }, |
---|
1421 | }@$file_paths |
---|
1422 | ]; |
---|
1423 | |
---|
1424 | @$files = sort { $a->{PathName} cmp $b->{PathName} } @$files; |
---|
1425 | |
---|
1426 | $self->imagelist->SetNewFiles( |
---|
1427 | $files |
---|
1428 | ); |
---|
1429 | |
---|
1430 | |
---|
1431 | } |
---|
1432 | |
---|
1433 | sub OnTreeSelChanged { |
---|
1434 | my( $self, $event ) = @_; |
---|
1435 | |
---|
1436 | my @items = $self->tree->GetSelections; |
---|
1437 | |
---|
1438 | $self->imagelist->categories( |
---|
1439 | [ |
---|
1440 | map { |
---|
1441 | my $category = $self->tree->GetPlData( $_ ); |
---|
1442 | $category->{id} if $category != -1; |
---|
1443 | } |
---|
1444 | @items |
---|
1445 | ] |
---|
1446 | ); |
---|
1447 | } |
---|
1448 | |
---|
1449 | sub OnTreeItemRightClick { |
---|
1450 | my( $self, $event ) = @_; |
---|
1451 | |
---|
1452 | |
---|
1453 | $self->PopupMenu($self->tree_mnu, wxDefaultPosition); |
---|
1454 | |
---|
1455 | } |
---|
1456 | |
---|
1457 | sub OnTreeEndLabelEdit { |
---|
1458 | my( $self, $event ) = @_; |
---|
1459 | |
---|
1460 | my $label = $event->GetLabel; |
---|
1461 | |
---|
1462 | $label =~ s/^\s+$//; |
---|
1463 | |
---|
1464 | if(defined($label) and !( "" eq $label )){ |
---|
1465 | $self->_SetLabel($event) |
---|
1466 | } |
---|
1467 | else{ |
---|
1468 | $event->Veto; |
---|
1469 | } |
---|
1470 | } |
---|
1471 | |
---|
1472 | sub _SetLabel { |
---|
1473 | my( $self, $event ) = @_; |
---|
1474 | |
---|
1475 | my $category = $self->tree->GetPlData($event->GetItem); |
---|
1476 | my $category_id; |
---|
1477 | |
---|
1478 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
---|
1479 | my $comment; |
---|
1480 | my ( $success, $status_msg, $content ) = $self->pwg->SetInfoCategories( |
---|
1481 | $event->GetLabel, |
---|
1482 | $comment, |
---|
1483 | $category_id |
---|
1484 | ); |
---|
1485 | |
---|
1486 | my $ok = 1; |
---|
1487 | |
---|
1488 | if(!$success){ |
---|
1489 | $ok = 0; |
---|
1490 | } |
---|
1491 | |
---|
1492 | if('fail' eq $content->{stat}){ |
---|
1493 | $ok = 0; |
---|
1494 | } |
---|
1495 | |
---|
1496 | # method call failed |
---|
1497 | if(!$ok){ |
---|
1498 | $event->Veto; |
---|
1499 | Wx::MessageBox( |
---|
1500 | sprintf( |
---|
1501 | "%s %s", |
---|
1502 | gettext("Update failed : "), |
---|
1503 | $status_msg |
---|
1504 | ), |
---|
1505 | gettext("Piwigo update error"), |
---|
1506 | wxOK | wxICON_EXCLAMATION, |
---|
1507 | ); |
---|
1508 | Wx::LogMessage("%s\n\n%s", Dumper($content), gettext("This function is not available. A Piwigo upgrade may resolve this issue.")); |
---|
1509 | } |
---|
1510 | } |
---|
1511 | |
---|
1512 | sub OnImageViewerItemRightClick { |
---|
1513 | my( $self, $event ) = @_; |
---|
1514 | |
---|
1515 | |
---|
1516 | $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition); |
---|
1517 | |
---|
1518 | |
---|
1519 | } |
---|
1520 | |
---|
1521 | sub OnExpandCategories { |
---|
1522 | my ( $self, $event ) = @_; |
---|
1523 | |
---|
1524 | my $parent_item = $self->tree->GetSelection; |
---|
1525 | $self->tree->ExpandAllChildren($parent_item); |
---|
1526 | $self->tree->EnsureVisible($parent_item); |
---|
1527 | } |
---|
1528 | |
---|
1529 | sub OnCollapseCategories { |
---|
1530 | my ( $self, $event ) = @_; |
---|
1531 | |
---|
1532 | my $parent_item = $self->tree->GetSelection; |
---|
1533 | $self->tree->CollapseAllChildren($parent_item); |
---|
1534 | $self->tree->Expand($parent_item) if -1 == $self->tree->GetPlData($parent_item); |
---|
1535 | } |
---|
1536 | |
---|
1537 | sub OnAddCategories { |
---|
1538 | my ( $self, $event ) = @_; |
---|
1539 | |
---|
1540 | my $parent_item = $self->tree->GetSelection; |
---|
1541 | |
---|
1542 | my $category = $self->tree->GetPlData($parent_item); |
---|
1543 | my $category_id; |
---|
1544 | |
---|
1545 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
---|
1546 | |
---|
1547 | my $dialog = Wx::TextEntryDialog->new( |
---|
1548 | $self, |
---|
1549 | wxTheApp->branding->{'Category name'}, |
---|
1550 | wxTheApp->branding->{'Add new category'}, |
---|
1551 | wxTheApp->branding->{'New category'}, |
---|
1552 | ); |
---|
1553 | |
---|
1554 | if( $dialog->ShowModal != wxID_CANCEL ) { |
---|
1555 | my $name = $dialog->GetValue; |
---|
1556 | my ( $success, $status_msg, $content ) = $self->pwg->AddCategories( $name, $category_id); |
---|
1557 | |
---|
1558 | if($success){ |
---|
1559 | $self->_append_category($parent_item, $name, $content->{result}{id}); |
---|
1560 | } |
---|
1561 | } |
---|
1562 | $dialog->Destroy; |
---|
1563 | } |
---|
1564 | |
---|
1565 | sub OnRefreshCategories { |
---|
1566 | my ( $self, $event ) = @_; |
---|
1567 | |
---|
1568 | $self->_refresh_all_categories_helper; |
---|
1569 | } |
---|
1570 | |
---|
1571 | |
---|
1572 | sub _refresh_all_categories_helper { |
---|
1573 | my ( $self ) = @_; |
---|
1574 | |
---|
1575 | my $busycursor = Wx::BusyCursor->new(); |
---|
1576 | $self->tree->CollapseAll; |
---|
1577 | $self->tree->DeleteAllItems; |
---|
1578 | $self->imagelist->categories([]); |
---|
1579 | $self->pwg->RefreshCategories(); |
---|
1580 | $self->populate_tree_categories; |
---|
1581 | } |
---|
1582 | |
---|
1583 | sub _append_category { |
---|
1584 | my ( $self, $parent_id, $name, $id ) = @_; |
---|
1585 | |
---|
1586 | $self->tree->SelectItem( |
---|
1587 | $self->tree->AppendItem( |
---|
1588 | $parent_id, |
---|
1589 | $name, |
---|
1590 | 1, |
---|
1591 | -1, |
---|
1592 | Wx::TreeItemData->new( { id => $id } ) |
---|
1593 | ) |
---|
1594 | ); |
---|
1595 | } |
---|
1596 | |
---|
1597 | sub OnImageViewerEndLabelEdit { |
---|
1598 | my( $self, $event ) = @_; |
---|
1599 | |
---|
1600 | my $image = $self->imagelist->GetImage($event->GetIndex); |
---|
1601 | $image->site_name( |
---|
1602 | $event->GetLabel |
---|
1603 | ); |
---|
1604 | |
---|
1605 | $self->image_prop_piwigo->Refresh; |
---|
1606 | } |
---|
1607 | |
---|
1608 | sub OnImageViewerItemActivated { |
---|
1609 | my( $self, $event ) = @_; |
---|
1610 | |
---|
1611 | $self->current_imageviewer_index( |
---|
1612 | $event->GetIndex |
---|
1613 | ); |
---|
1614 | |
---|
1615 | $self->OnPhotoProperties; |
---|
1616 | } |
---|
1617 | |
---|
1618 | |
---|
1619 | sub OnImageViewerItemSelected { |
---|
1620 | my( $self, $event ) = @_; |
---|
1621 | |
---|
1622 | my $indx = $event->GetIndex; |
---|
1623 | |
---|
1624 | $self->_on_imageviewer_item_selected($indx); |
---|
1625 | |
---|
1626 | $event->Skip; |
---|
1627 | } |
---|
1628 | |
---|
1629 | sub _on_imageviewer_item_selected { |
---|
1630 | my ( $self, $index ) = @_; |
---|
1631 | |
---|
1632 | $self->current_imageviewer_index($index); |
---|
1633 | $self->imagelist->SetCurrentImage($index); |
---|
1634 | |
---|
1635 | $self->imagelist->image_selection( |
---|
1636 | $self->imageviewer->GetSelectedItems |
---|
1637 | ); |
---|
1638 | |
---|
1639 | $self->_image_preview_refresh if @{$self->imagelist->image_selection} < 2; |
---|
1640 | |
---|
1641 | $self->manager->Update; |
---|
1642 | |
---|
1643 | $self->image_prop_piwigo->Refresh; |
---|
1644 | $self->image_prop_exif->Refresh; |
---|
1645 | $self->image_prop_tags->Refresh; |
---|
1646 | |
---|
1647 | } |
---|
1648 | |
---|
1649 | sub _image_preview_refresh { |
---|
1650 | my ( $self ) = @_; |
---|
1651 | |
---|
1652 | |
---|
1653 | my $html_src = sprintf(" |
---|
1654 | <html> |
---|
1655 | <body> |
---|
1656 | <img src=\"%s\"/> |
---|
1657 | </body> |
---|
1658 | </html> |
---|
1659 | ", |
---|
1660 | $self->imagelist->current_image->preview_file, |
---|
1661 | ); |
---|
1662 | |
---|
1663 | $self->image_preview->SetPage( |
---|
1664 | $html_src |
---|
1665 | ); |
---|
1666 | |
---|
1667 | my $bmp = Wx::Bitmap->new( |
---|
1668 | $self->imagelist->current_image->preview_file, |
---|
1669 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1670 | ); |
---|
1671 | |
---|
1672 | my $size = [40+$bmp->GetWidth, 60+$bmp->GetHeight]; |
---|
1673 | |
---|
1674 | $self->manager->GetPane("image_preview")->FloatingSize($size); |
---|
1675 | |
---|
1676 | } |
---|
1677 | |
---|
1678 | sub OnImageViewerKeyDown { |
---|
1679 | my( $self, $event ) = @_; |
---|
1680 | |
---|
1681 | if(WXK_DELETE == $event->GetKeyCode){ |
---|
1682 | $self->OnRemoveImages(); |
---|
1683 | |
---|
1684 | my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ? |
---|
1685 | $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ; |
---|
1686 | $self->imageviewer->SelectItem( |
---|
1687 | $index |
---|
1688 | ); |
---|
1689 | } |
---|
1690 | |
---|
1691 | } |
---|
1692 | |
---|
1693 | sub OnUploadImages { |
---|
1694 | my( $self, $event ) = @_; |
---|
1695 | |
---|
1696 | eval { |
---|
1697 | $self->ProcessImageSelection(); |
---|
1698 | }; |
---|
1699 | } |
---|
1700 | |
---|
1701 | # remove image from imagelist when uploaded |
---|
1702 | sub UploadImagesViewerRefresh { |
---|
1703 | my ( $self ) = @_; |
---|
1704 | |
---|
1705 | $self->imageviewer->Refresh; |
---|
1706 | Wx::Yield(); |
---|
1707 | } |
---|
1708 | |
---|
1709 | sub UploadProgressMessageRefresh { |
---|
1710 | my ( $self, $msg ) = @_; |
---|
1711 | |
---|
1712 | Wx::Yield(); |
---|
1713 | |
---|
1714 | $self->upload_progressdlg->processing( |
---|
1715 | $msg |
---|
1716 | ); |
---|
1717 | $self->upload_progressdlg->LogProgress(); |
---|
1718 | |
---|
1719 | Wx::Yield(); |
---|
1720 | } |
---|
1721 | |
---|
1722 | sub UploadProgressMessageDetailsRefresh { |
---|
1723 | my ( $self, $msg ) = @_; |
---|
1724 | |
---|
1725 | Wx::Yield(); |
---|
1726 | |
---|
1727 | $self->upload_progressdlg->processing_details( |
---|
1728 | $msg |
---|
1729 | ); |
---|
1730 | $self->upload_progressdlg->LogProgress(); |
---|
1731 | |
---|
1732 | Wx::Yield(); |
---|
1733 | } |
---|
1734 | |
---|
1735 | |
---|
1736 | sub UploadProgressThumbnailRefresh { |
---|
1737 | my ( $self ) = @_; |
---|
1738 | |
---|
1739 | my $imagelist = $self->imagelist ; |
---|
1740 | |
---|
1741 | |
---|
1742 | $self->upload_progressdlg->image->SetBitmap(wxNullBitmap); |
---|
1743 | $self->upload_progressdlg->image->SetBitmap( |
---|
1744 | Wx::Bitmap->new( |
---|
1745 | $self->imagelist->current_image->wx_thumb_file, |
---|
1746 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1747 | ) |
---|
1748 | ); |
---|
1749 | |
---|
1750 | Wx::Yield(); |
---|
1751 | } |
---|
1752 | |
---|
1753 | sub UploadProgressBarRefresh { |
---|
1754 | my ( $self, $value ) = @_; |
---|
1755 | |
---|
1756 | eval { |
---|
1757 | $self->upload_progressdlg->progress( |
---|
1758 | $value |
---|
1759 | ); |
---|
1760 | $self->upload_progressdlg->LogProgress(); |
---|
1761 | }; |
---|
1762 | #croak gettext("Upload cancelled") if $@; |
---|
1763 | |
---|
1764 | Wx::Yield(); |
---|
1765 | } |
---|
1766 | |
---|
1767 | sub SetNewFilesDisplayEndInfo { |
---|
1768 | my ( $self, $msg ) = @_; |
---|
1769 | |
---|
1770 | $self->progressdlg->DisplayEndInfo($msg); |
---|
1771 | } |
---|
1772 | |
---|
1773 | sub UploadDisplayEndInfo { |
---|
1774 | my ( $self, $msg ) = @_; |
---|
1775 | |
---|
1776 | my $imagelist = $self->imagelist ; |
---|
1777 | |
---|
1778 | $self->upload_progressdlg->DisplayEndInfo($msg); |
---|
1779 | } |
---|
1780 | |
---|
1781 | sub ShowImageViewer { |
---|
1782 | my ( $self ) = @_; |
---|
1783 | |
---|
1784 | if(!$self->imageviewer->IsShown){ |
---|
1785 | $self->imageviewer->Show(1); |
---|
1786 | } |
---|
1787 | } |
---|
1788 | |
---|
1789 | |
---|
1790 | sub ActivateImageViewer { |
---|
1791 | my ( $self ) = @_; |
---|
1792 | |
---|
1793 | } |
---|
1794 | |
---|
1795 | |
---|
1796 | sub SetNewFilesViewerRefresh { |
---|
1797 | |
---|
1798 | my ( $self ) = @_; |
---|
1799 | |
---|
1800 | my $wximagelist = $self->imagelist->wx_thumb_imglist; |
---|
1801 | |
---|
1802 | my $indx = $wximagelist->Add( |
---|
1803 | Wx::Bitmap->new( |
---|
1804 | $self->imagelist->current_image->wx_thumb_file, |
---|
1805 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1806 | ) |
---|
1807 | ) if defined $self->imagelist->current_image->wx_thumb_file; |
---|
1808 | print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n"; |
---|
1809 | $self->imageviewer->Refresh( |
---|
1810 | $wximagelist |
---|
1811 | ); |
---|
1812 | |
---|
1813 | Wx::Yield(); |
---|
1814 | } |
---|
1815 | |
---|
1816 | |
---|
1817 | |
---|
1818 | # prepare and upload image_selection |
---|
1819 | sub ProcessImageSelection { |
---|
1820 | my ( $self ) = @_; |
---|
1821 | |
---|
1822 | return if !scalar @{$self->imagelist->sums}; |
---|
1823 | |
---|
1824 | if( scalar @{$self->imagelist->categories} ){ |
---|
1825 | # all selected is implicit |
---|
1826 | if(!scalar @{$self->imageviewer->GetSelectedItems}){ |
---|
1827 | |
---|
1828 | $self->imagelist->image_selection( |
---|
1829 | $self->imageviewer->GetAllItems |
---|
1830 | ); |
---|
1831 | } |
---|
1832 | |
---|
1833 | return if( !defined $self->imagelist->image_selection ); |
---|
1834 | return if( !scalar @{$self->imagelist->image_selection} ); |
---|
1835 | |
---|
1836 | $self->upload_progressdlg( |
---|
1837 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
---|
1838 | { |
---|
1839 | title => gettext("Image upload progress information"), |
---|
1840 | bt_label => gettext("Cancel upload"), |
---|
1841 | bt_close_label => gettext("Close"), |
---|
1842 | } |
---|
1843 | ) |
---|
1844 | ); |
---|
1845 | # modeless dialog |
---|
1846 | $self->upload_progressdlg->Show(1); |
---|
1847 | Wx::Yield(); |
---|
1848 | eval { |
---|
1849 | $self->imagelist->UploadSelection; |
---|
1850 | }; |
---|
1851 | if($@){ |
---|
1852 | Wx::MessageBox( |
---|
1853 | sprintf( |
---|
1854 | gettext("Upload cancelled"), |
---|
1855 | ), |
---|
1856 | gettext("Piwigo upload information"), |
---|
1857 | wxOK | wxICON_INFORMATION, |
---|
1858 | ); |
---|
1859 | } |
---|
1860 | } |
---|
1861 | else { |
---|
1862 | Wx::MessageBox( |
---|
1863 | sprintf( |
---|
1864 | "%s %s", |
---|
1865 | gettext("Please select a valid target"), |
---|
1866 | wxTheApp->branding->{category} |
---|
1867 | ), |
---|
1868 | gettext("Piwigo upload error"), |
---|
1869 | wxOK | wxICON_EXCLAMATION, |
---|
1870 | ); |
---|
1871 | } |
---|
1872 | } |
---|
1873 | |
---|
1874 | |
---|
1875 | sub SetNewFilesProgress { |
---|
1876 | my ( $self ) = @_; |
---|
1877 | |
---|
1878 | my $imagelist = $self->imagelist; |
---|
1879 | |
---|
1880 | $self->progressdlg->processing( |
---|
1881 | sprintf( |
---|
1882 | $imagelist->progress_msg, |
---|
1883 | $imagelist->current_image->file, |
---|
1884 | ) |
---|
1885 | ); |
---|
1886 | |
---|
1887 | eval { |
---|
1888 | $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]); |
---|
1889 | $self->progressdlg->image->SetBitmap(wxNullBitmap); |
---|
1890 | $self->progressdlg->image->SetBitmap( |
---|
1891 | Wx::Bitmap->new( |
---|
1892 | $imagelist->current_image->wx_thumb_file, |
---|
1893 | $self->GetWxBitmapType( $imagelist->type ) |
---|
1894 | ) |
---|
1895 | ); |
---|
1896 | $self->progressdlg->progress( |
---|
1897 | $imagelist->count * ( 100/scalar @{$imagelist->new_files} ) |
---|
1898 | ); |
---|
1899 | $self->progressdlg->LogProgress(); |
---|
1900 | }; |
---|
1901 | Wx::Yield(); |
---|
1902 | } |
---|
1903 | |
---|
1904 | sub OnClose { |
---|
1905 | my $self = shift; |
---|
1906 | |
---|
1907 | |
---|
1908 | # Restaure previous log wnd |
---|
1909 | Wx::Log::SetActiveTarget( $self->oldlogwnd ); |
---|
1910 | |
---|
1911 | # allways store |
---|
1912 | |
---|
1913 | wxTheApp->StoreConnectionProperties; |
---|
1914 | |
---|
1915 | $self->imagelist->Store; |
---|
1916 | wxTheApp->login_dlg->Destroy; |
---|
1917 | |
---|
1918 | wxTheApp->perspective( |
---|
1919 | $self->manager->SavePerspective |
---|
1920 | ); |
---|
1921 | |
---|
1922 | wxTheApp->imageviewerIndex( |
---|
1923 | $self->current_imageviewer_index |
---|
1924 | ); |
---|
1925 | |
---|
1926 | my $frameLayout = {}; |
---|
1927 | |
---|
1928 | ( $frameLayout->{pX}, $frameLayout->{pY}, $frameLayout->{W}, $frameLayout->{H} ) = ( $self->GetPositionXY, $self->GetSizeWH ) ; |
---|
1929 | |
---|
1930 | wxTheApp->frameLayout( |
---|
1931 | $frameLayout |
---|
1932 | ); |
---|
1933 | |
---|
1934 | wxTheApp->StoreLayoutProperties; |
---|
1935 | |
---|
1936 | $self->manager->UnInit; |
---|
1937 | $self->Destroy; |
---|
1938 | } |
---|
1939 | |
---|
1940 | |
---|
1941 | sub create_toolbar { |
---|
1942 | my( $self ) = @_; |
---|
1943 | |
---|
1944 | my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT ); |
---|
1945 | $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) ); |
---|
1946 | map { |
---|
1947 | my $icon1 = Wx::Icon->new(); |
---|
1948 | eval { |
---|
1949 | $icon1->LoadFile($_->[2], $_->[3]); |
---|
1950 | }; |
---|
1951 | my $tb_icon1 = Wx::Bitmap->new( $icon1 ); |
---|
1952 | |
---|
1953 | my $icon2 = Wx::Icon->new(); |
---|
1954 | eval { |
---|
1955 | $icon2->LoadFile($_->[5], $_->[3]); |
---|
1956 | }; |
---|
1957 | my $tb_icon2 = Wx::Bitmap->new( $icon2 ); |
---|
1958 | |
---|
1959 | |
---|
1960 | $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[1] ); |
---|
1961 | $tb->EnableTool( $_->[0], $_->[4]); |
---|
1962 | } |
---|
1963 | ( |
---|
1964 | [ |
---|
1965 | 100, |
---|
1966 | gettext("Getting started"), |
---|
1967 | '../res/tb_getting_started.png', |
---|
1968 | wxBITMAP_TYPE_PNG, |
---|
1969 | 1, |
---|
1970 | '../res/tb_getting_started.png', |
---|
1971 | gettext("Display getting started panel") |
---|
1972 | ], |
---|
1973 | [ |
---|
1974 | 101, |
---|
1975 | gettext("Add photo to selection"), |
---|
1976 | '../res/tb_add.png', |
---|
1977 | wxBITMAP_TYPE_PNG, |
---|
1978 | 1, |
---|
1979 | '../res/tb_add.png', |
---|
1980 | gettext("Add photo to selection for resizing and uploading") |
---|
1981 | ], |
---|
1982 | [ |
---|
1983 | 102, |
---|
1984 | gettext("Remove photo from selection"), |
---|
1985 | '../res/tb_remove.png', |
---|
1986 | wxBITMAP_TYPE_PNG, |
---|
1987 | 1, |
---|
1988 | '../res/tb_remove.png', |
---|
1989 | gettext("Remove photo from selection. Files are not deleted ") |
---|
1990 | ], |
---|
1991 | [ |
---|
1992 | 103, |
---|
1993 | gettext("Upload to Piwigo"), |
---|
1994 | '../res/tb_upload.png', |
---|
1995 | wxBITMAP_TYPE_PNG, |
---|
1996 | wxTheApp->use_offline ? 0 : 1, |
---|
1997 | '../res/tb_upload.png', |
---|
1998 | gettext("Upload photos to Piwigo.") |
---|
1999 | ], |
---|
2000 | [ |
---|
2001 | 104, |
---|
2002 | gettext("Global settings"), |
---|
2003 | '../res/tb_settings.png', |
---|
2004 | wxBITMAP_TYPE_PNG, |
---|
2005 | 0, |
---|
2006 | '../res/tb_settings.png', |
---|
2007 | gettext("Change global settings.") |
---|
2008 | ], |
---|
2009 | [ |
---|
2010 | 105, |
---|
2011 | gettext("Language choice"), |
---|
2012 | '../res/tb_i18n.png', |
---|
2013 | wxBITMAP_TYPE_PNG, |
---|
2014 | 1, |
---|
2015 | '../res/tb_i18n.png', |
---|
2016 | gettext("Language choice") |
---|
2017 | ], |
---|
2018 | |
---|
2019 | ); |
---|
2020 | |
---|
2021 | if($@){ |
---|
2022 | undef $tb; |
---|
2023 | } |
---|
2024 | else{ |
---|
2025 | $tb->Realize; |
---|
2026 | } |
---|
2027 | |
---|
2028 | return $tb; |
---|
2029 | } |
---|
2030 | |
---|
2031 | |
---|
2032 | sub _create_textctrl { |
---|
2033 | my( $self, $parent, $text, $size ) = @_; |
---|
2034 | |
---|
2035 | return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size, |
---|
2036 | wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY ); |
---|
2037 | } |
---|
2038 | |
---|
2039 | sub create_textctrl { |
---|
2040 | my( $self, $text, $size ) = @_; |
---|
2041 | |
---|
2042 | return $self->_create_textctrl( $self, $text, $size ); |
---|
2043 | } |
---|
2044 | |
---|
2045 | sub DESTROY { |
---|
2046 | my( $self ) = @_; |
---|
2047 | |
---|
2048 | } |
---|
2049 | |
---|
2050 | |
---|
2051 | |
---|
2052 | 1; |
---|
2053 | |
---|
2054 | |
---|
2055 | |
---|
2056 | |
---|
2057 | |
---|
2058 | package DNDImageListDropTarget; |
---|
2059 | use Wx qw/wxTheApp/; |
---|
2060 | use base qw(Wx::FileDropTarget Class::Accessor::Fast); |
---|
2061 | |
---|
2062 | __PACKAGE__->mk_accessors( |
---|
2063 | qw/ |
---|
2064 | imageviewer |
---|
2065 | / |
---|
2066 | ); |
---|
2067 | |
---|
2068 | sub new { |
---|
2069 | my $class = shift; |
---|
2070 | my $imageviewer = shift; |
---|
2071 | my $self = $class->SUPER::new( @_ ); |
---|
2072 | |
---|
2073 | $self->imageviewer($imageviewer); |
---|
2074 | |
---|
2075 | return $self; |
---|
2076 | } |
---|
2077 | |
---|
2078 | sub OnDropFiles { |
---|
2079 | my( $self, $x, $y, $files ) = @_; |
---|
2080 | |
---|
2081 | wxTheApp->frame->SetNewFiles($files) ; |
---|
2082 | } |
---|
2083 | |
---|
2084 | |
---|
2085 | |
---|
2086 | |
---|
2087 | 1; |
---|
2088 | |
---|
2089 | |
---|
2090 | package DNDCategoryTreeDropTarget; |
---|
2091 | |
---|
2092 | use base qw(Wx::TextDropTarget Class::Accessor::Fast); |
---|
2093 | use Data::Dumper; |
---|
2094 | use Wx qw/ |
---|
2095 | wxDragNone |
---|
2096 | wxDragCopy |
---|
2097 | wxDragMove |
---|
2098 | /; |
---|
2099 | |
---|
2100 | __PACKAGE__->mk_accessors( |
---|
2101 | qw/ |
---|
2102 | tree |
---|
2103 | frame |
---|
2104 | / |
---|
2105 | ); |
---|
2106 | |
---|
2107 | sub new { |
---|
2108 | my ( $class, $tree ) = @_; |
---|
2109 | my $self = $class->SUPER::new(); |
---|
2110 | |
---|
2111 | $self->tree($tree); |
---|
2112 | $self->frame($tree->GetParent); |
---|
2113 | return $self; |
---|
2114 | } |
---|
2115 | |
---|
2116 | |
---|
2117 | |
---|
2118 | sub OnDropText { |
---|
2119 | my( $self, $x, $y, $textdata ) = @_; |
---|
2120 | |
---|
2121 | # must be $VAR1 because $textdata is the result of Data::Dumper |
---|
2122 | my $VAR1; |
---|
2123 | eval $textdata; |
---|
2124 | eval { |
---|
2125 | if(scalar @$VAR1){ |
---|
2126 | my @items; |
---|
2127 | if(scalar @items < 2) { |
---|
2128 | my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]); |
---|
2129 | push @items, $dropItem; |
---|
2130 | } |
---|
2131 | else { |
---|
2132 | @items = $self->tree->GetSelections; |
---|
2133 | } |
---|
2134 | |
---|
2135 | # remove root item which is not a valid category |
---|
2136 | @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items; |
---|
2137 | |
---|
2138 | $self->frame->imagelist->categories( |
---|
2139 | [ |
---|
2140 | map { |
---|
2141 | $self->tree->GetPlData( $_ )->{id}; |
---|
2142 | } |
---|
2143 | @items |
---|
2144 | ] |
---|
2145 | ); |
---|
2146 | |
---|
2147 | $self->frame->imagelist->image_selection($VAR1); |
---|
2148 | $self->frame->ProcessImageSelection ; |
---|
2149 | } |
---|
2150 | }; |
---|
2151 | } |
---|
2152 | |
---|
2153 | 1; |
---|