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