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 | WXK_DOWN |
---|
72 | /; |
---|
73 | use base qw/Wx::Frame Class::Accessor::Fast/; |
---|
74 | use File::Spec; |
---|
75 | use Wx::Locale qw/:default/; |
---|
76 | |
---|
77 | require Win32 if($^O =~ /MSWin32/); |
---|
78 | |
---|
79 | |
---|
80 | my @properties = |
---|
81 | qw/ |
---|
82 | progressdlg |
---|
83 | upload_progressdlg |
---|
84 | imageviewer |
---|
85 | tree |
---|
86 | tree_root |
---|
87 | treeimglist |
---|
88 | tree_item_default |
---|
89 | topsizer |
---|
90 | pwg |
---|
91 | manager |
---|
92 | logwnd |
---|
93 | oldlogwnd |
---|
94 | htmlhome |
---|
95 | notebook |
---|
96 | categories |
---|
97 | imagelist |
---|
98 | image_preview |
---|
99 | image_prop_piwigo |
---|
100 | image_prop_exif |
---|
101 | image_prop_tags |
---|
102 | notebook_image_properties |
---|
103 | notebook_global_settings |
---|
104 | general_settings_panel |
---|
105 | resized_settings_panel |
---|
106 | thumbnail_settings_panel |
---|
107 | preview_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 | preview_settings |
---|
116 | advanced_settings |
---|
117 | watermark_settings |
---|
118 | toolbar |
---|
119 | branding |
---|
120 | perspective |
---|
121 | current_imageviewer_index |
---|
122 | imageviewer_mnu |
---|
123 | tree_mnu |
---|
124 | imageviewer_select_multi |
---|
125 | frameLayout |
---|
126 | piwigo_tags |
---|
127 | image_tags |
---|
128 | /; |
---|
129 | __PACKAGE__->mk_accessors( @properties ); |
---|
130 | |
---|
131 | use Wx::Event |
---|
132 | qw/ |
---|
133 | EVT_MENU |
---|
134 | EVT_TREE_SEL_CHANGED |
---|
135 | EVT_TREE_END_LABEL_EDIT |
---|
136 | EVT_CLOSE |
---|
137 | EVT_LIST_END_LABEL_EDIT |
---|
138 | EVT_LIST_ITEM_SELECTED |
---|
139 | EVT_LIST_ITEM_ACTIVATED |
---|
140 | EVT_LIST_ITEM_RIGHT_CLICK |
---|
141 | EVT_TREE_ITEM_RIGHT_CLICK |
---|
142 | EVT_LIST_KEY_DOWN |
---|
143 | EVT_UPDATE_UI |
---|
144 | /; |
---|
145 | |
---|
146 | use Uploader::GUI::wxImageListCtrl; |
---|
147 | use Uploader::GUI::wxImageProcessingProgressDlg; |
---|
148 | use Uploader::GUI::wxChoiceFilteredPanel; |
---|
149 | use Wx::Html; |
---|
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->preview_settings_panel, |
---|
587 | $self->advanced_settings_panel, |
---|
588 | $self->watermark_settings_panel, |
---|
589 | ); |
---|
590 | |
---|
591 | $self->manager->Update; |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | sub _destroy_settings_panels { |
---|
596 | my ( $self ) = @_; |
---|
597 | |
---|
598 | |
---|
599 | |
---|
600 | map { |
---|
601 | $self->manager->DetachPane( |
---|
602 | $_ |
---|
603 | ); |
---|
604 | $_->Show(0); |
---|
605 | $_->Destroy; |
---|
606 | }( |
---|
607 | $self->notebook_global_settings, |
---|
608 | $self->notebook_image_properties, |
---|
609 | ); |
---|
610 | } |
---|
611 | |
---|
612 | # |
---|
613 | sub _initFrame { |
---|
614 | my ( $self ) = @_; |
---|
615 | |
---|
616 | |
---|
617 | $self->init_panels; |
---|
618 | |
---|
619 | $self->init_aui; |
---|
620 | $self->init_dnd_targets; |
---|
621 | |
---|
622 | if( $self->imagelist->wx_thumb_imglist->GetImageCount){ |
---|
623 | printf("%s images\n", $self->imagelist->wx_thumb_imglist->GetImageCount); |
---|
624 | $self->ShowImageViewer; |
---|
625 | |
---|
626 | $self->imageviewer->Refresh( |
---|
627 | $self->imagelist->wx_thumb_imglist |
---|
628 | ); |
---|
629 | |
---|
630 | } |
---|
631 | |
---|
632 | } |
---|
633 | |
---|
634 | sub _refresh_settings_panels_properties { |
---|
635 | my ( $self ) = @_; |
---|
636 | |
---|
637 | $self->image_prop_piwigo->properties( |
---|
638 | $self->piwigo_properties |
---|
639 | ); |
---|
640 | |
---|
641 | $self->image_prop_exif->properties( |
---|
642 | $self->exif_properties |
---|
643 | ); |
---|
644 | |
---|
645 | |
---|
646 | $self->general_settings_panel->properties( |
---|
647 | $self->general_settings |
---|
648 | ); |
---|
649 | |
---|
650 | $self->resized_settings_panel->properties( |
---|
651 | $self->resized_settings |
---|
652 | ); |
---|
653 | |
---|
654 | $self->thumbnail_settings_panel->properties( |
---|
655 | $self->thumbnail_settings, |
---|
656 | ); |
---|
657 | |
---|
658 | $self->preview_settings_panel->properties( |
---|
659 | $self->preview_settings, |
---|
660 | ); |
---|
661 | |
---|
662 | $self->advanced_settings_panel->properties( |
---|
663 | $self->advanced_settings, |
---|
664 | ); |
---|
665 | |
---|
666 | $self->watermark_settings_panel->properties( |
---|
667 | $self->watermark_settings, |
---|
668 | ); |
---|
669 | |
---|
670 | } |
---|
671 | |
---|
672 | sub _init_settings_panels { |
---|
673 | my ( $self ) = @_; |
---|
674 | |
---|
675 | $self->image_prop_piwigo( |
---|
676 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
677 | { |
---|
678 | parentwnd => $self, |
---|
679 | properties => $self->piwigo_properties, |
---|
680 | } |
---|
681 | ) |
---|
682 | ); |
---|
683 | |
---|
684 | $self->image_prop_exif( |
---|
685 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
686 | { |
---|
687 | parentwnd => $self, |
---|
688 | properties => $self->exif_properties, |
---|
689 | } |
---|
690 | ) |
---|
691 | ); |
---|
692 | |
---|
693 | |
---|
694 | $self->general_settings_panel( |
---|
695 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
696 | { |
---|
697 | parentwnd => $self, |
---|
698 | properties => $self->general_settings, |
---|
699 | } |
---|
700 | ) |
---|
701 | ); |
---|
702 | |
---|
703 | $self->resized_settings_panel( |
---|
704 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
705 | { |
---|
706 | parentwnd => $self, |
---|
707 | properties => $self->resized_settings, |
---|
708 | |
---|
709 | } |
---|
710 | ) |
---|
711 | ); |
---|
712 | |
---|
713 | $self->thumbnail_settings_panel( |
---|
714 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
715 | { |
---|
716 | parentwnd => $self, |
---|
717 | properties => $self->thumbnail_settings, |
---|
718 | |
---|
719 | } |
---|
720 | ) |
---|
721 | ); |
---|
722 | $self->preview_settings_panel( |
---|
723 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
724 | { |
---|
725 | parentwnd => $self, |
---|
726 | properties => $self->preview_settings, |
---|
727 | |
---|
728 | } |
---|
729 | ) |
---|
730 | ); |
---|
731 | |
---|
732 | $self->advanced_settings_panel( |
---|
733 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
734 | { |
---|
735 | parentwnd => $self, |
---|
736 | properties => $self->advanced_settings, |
---|
737 | |
---|
738 | } |
---|
739 | ) |
---|
740 | ); |
---|
741 | |
---|
742 | $self->watermark_settings_panel( |
---|
743 | Uploader::GUI::wxPropertyGridPanel->new( |
---|
744 | { |
---|
745 | parentwnd => $self, |
---|
746 | properties => $self->watermark_settings, |
---|
747 | } |
---|
748 | ) |
---|
749 | ); |
---|
750 | |
---|
751 | $self->image_prop_tags( |
---|
752 | Uploader::GUI::wxChoiceFilteredPanel->new( |
---|
753 | { |
---|
754 | parentwnd => $self, |
---|
755 | choices => $self->piwigo_tags, |
---|
756 | selection => $self->image_tags, |
---|
757 | creation_callback => sub { $self->_create_piwigo_tag(@_) }, |
---|
758 | } |
---|
759 | ) |
---|
760 | ); |
---|
761 | |
---|
762 | |
---|
763 | $self->general_settings_panel->Show(0); |
---|
764 | |
---|
765 | $self->image_preview( |
---|
766 | Wx::HtmlWindow->new( |
---|
767 | $self, |
---|
768 | -1, |
---|
769 | [-1,-1], |
---|
770 | [-1,-1], |
---|
771 | ) |
---|
772 | ); |
---|
773 | |
---|
774 | |
---|
775 | $self->image_prop_piwigo->Show(0); |
---|
776 | |
---|
777 | $self->image_prop_exif->Show(0); |
---|
778 | |
---|
779 | } |
---|
780 | |
---|
781 | sub init_panels { |
---|
782 | my ( $self ) = @_; |
---|
783 | |
---|
784 | my $file = sprintf( |
---|
785 | "../locale/%s/gs.html", |
---|
786 | wxTheApp->locale->GetCanonicalName |
---|
787 | ); |
---|
788 | |
---|
789 | $self->htmlhome( |
---|
790 | Uploader::GUI::wxHtmlWindow->new( |
---|
791 | $self, -1, [-1, -1], [450, 450] |
---|
792 | ) |
---|
793 | ); |
---|
794 | |
---|
795 | $self->htmlhome->LoadPage($file) if -e $file ; |
---|
796 | |
---|
797 | $self->htmlhome->InitHrefCallbacks( |
---|
798 | { |
---|
799 | new_album => sub {$self->OnAddCategories(@_) }, |
---|
800 | add_photos => sub { $self->OnAddImages(@_) }, |
---|
801 | upload_photos => sub { $self->ProcessImageSelection(@_)}, |
---|
802 | } |
---|
803 | ); |
---|
804 | |
---|
805 | $self->imageviewer( |
---|
806 | Uploader::GUI::wxImageListCtrl->new( |
---|
807 | { |
---|
808 | parentwnd => $self, |
---|
809 | imagelist => $self->imagelist, |
---|
810 | } |
---|
811 | ) |
---|
812 | ); |
---|
813 | |
---|
814 | $self->_init_settings_panels; |
---|
815 | } |
---|
816 | |
---|
817 | sub init_dnd_targets { |
---|
818 | my ( $self ) = @_; |
---|
819 | |
---|
820 | $self->imageviewer->SetDropTarget( |
---|
821 | DNDImageListDropTarget->new( |
---|
822 | $self->imageviewer |
---|
823 | ) |
---|
824 | ); |
---|
825 | |
---|
826 | $self->tree->SetDropTarget( |
---|
827 | DNDCategoryTreeDropTarget->new( |
---|
828 | $self->tree |
---|
829 | ) |
---|
830 | ); |
---|
831 | |
---|
832 | } |
---|
833 | |
---|
834 | sub init_aui { |
---|
835 | my ( $self ) = @_; |
---|
836 | |
---|
837 | my $url = wxTheApp->site_url; |
---|
838 | |
---|
839 | $url = gettext("empty - work Offline") if wxTheApp->use_offline; |
---|
840 | |
---|
841 | $self->manager->AddPane |
---|
842 | ( $self->create_notebook_imagelist, Wx::AuiPaneInfo->new->Name( "ImageViewer" ) |
---|
843 | ->CenterPane->Resizable->CloseButton(0) ); |
---|
844 | |
---|
845 | $self->manager->AddPane( |
---|
846 | $self->create_tree, |
---|
847 | Wx::AuiPaneInfo->new->Name( "categories" ) |
---|
848 | ->Right->Position( 0 )->Resizable->CloseButton(0), |
---|
849 | ); |
---|
850 | |
---|
851 | |
---|
852 | |
---|
853 | $self->_init_aui_settings_panels; |
---|
854 | |
---|
855 | $self->toolbar( |
---|
856 | $self->create_toolbar |
---|
857 | ); |
---|
858 | |
---|
859 | $self->manager->AddPane |
---|
860 | ( $self->toolbar, Wx::AuiPaneInfo->new->Name( "tb1" ) |
---|
861 | ->ToolbarPane->Top->Row( 1 )->LeftDockable( 0 )->RightDockable( 0 ) ) if defined $self->toolbar; |
---|
862 | |
---|
863 | $self->SetSize( |
---|
864 | $self->frameLayout->{pX}, |
---|
865 | $self->frameLayout->{pY}, |
---|
866 | $self->frameLayout->{W}, |
---|
867 | $self->frameLayout->{H}, |
---|
868 | ); |
---|
869 | |
---|
870 | |
---|
871 | if($self->perspective){ |
---|
872 | $self->manager->LoadPerspective($self->perspective); |
---|
873 | } |
---|
874 | else { |
---|
875 | $self->manager->GetPane("categories")->MinSize(300,100); |
---|
876 | |
---|
877 | $self->manager->GetPane("tb1")->Caption( gettext("Tools") ); |
---|
878 | $self->manager->GetPane("image_preview")->Caption(gettext("Preview"))->Show(0); |
---|
879 | $self->manager->GetPane("getting_started")->Caption(gettext("Getting started"))->Float->Show(1); |
---|
880 | $self->manager->GetPane("photo_properties")->Caption(gettext("Photo properties"))->Float->Show(0); |
---|
881 | $self->manager->GetPane("global_settings")->Caption(gettext("Global settings"))->Float->Show(0); |
---|
882 | } |
---|
883 | |
---|
884 | $self->manager->GetPane("categories")->Caption( |
---|
885 | sprintf("%s - %s", sprintf("Piwigo %s", wxTheApp->branding->{categories}), $url ) |
---|
886 | ); |
---|
887 | |
---|
888 | $self->manager->Update; |
---|
889 | |
---|
890 | } |
---|
891 | |
---|
892 | |
---|
893 | sub _init_aui_settings_panels { |
---|
894 | my ( $self ) = @_; |
---|
895 | |
---|
896 | $self->manager->AddPane |
---|
897 | ( $self->image_preview, Wx::AuiPaneInfo->new->Name( "image_preview" ) |
---|
898 | ->Floatable(1)->Resizable->CloseButton(1)); |
---|
899 | |
---|
900 | $self->manager->AddPane |
---|
901 | ( $self->htmlhome, Wx::AuiPaneInfo->new->Name( "getting_started" ) |
---|
902 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
903 | |
---|
904 | $self->manager->AddPane |
---|
905 | ( $self->create_notebook_image_properties, Wx::AuiPaneInfo->new->Name( "photo_properties" ) |
---|
906 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
907 | |
---|
908 | $self->manager->AddPane |
---|
909 | ( $self->create_notebook_global_settings, Wx::AuiPaneInfo->new->Name( "global_settings" ) |
---|
910 | ->Floatable(1)->Resizable->CloseButton(1) ); |
---|
911 | |
---|
912 | } |
---|
913 | |
---|
914 | sub OnPhotoProperties { |
---|
915 | my ( $self ) = @_; |
---|
916 | |
---|
917 | $self->manager->GetPane("photo_properties")->Show(1); |
---|
918 | $self->manager->Update(); |
---|
919 | |
---|
920 | } |
---|
921 | |
---|
922 | sub OnPreview { |
---|
923 | my ( $self ) = @_; |
---|
924 | |
---|
925 | $self->manager->GetPane("image_preview")->Float->Show(1); |
---|
926 | $self->manager->Update(); |
---|
927 | |
---|
928 | } |
---|
929 | |
---|
930 | sub OnGettingStarted { |
---|
931 | my ( $self ) = @_; |
---|
932 | |
---|
933 | $self->toolbar->EnableTool(100, 0 ); |
---|
934 | $self->manager->GetPane("getting_started")->Float->Show(1); |
---|
935 | $self->manager->Update(); |
---|
936 | |
---|
937 | } |
---|
938 | |
---|
939 | sub OnGlobalSettings { |
---|
940 | my ( $self ) = @_; |
---|
941 | |
---|
942 | $self->toolbar->EnableTool(104, 0 ); |
---|
943 | $self->manager->GetPane("global_settings")->Float->Show(1); |
---|
944 | $self->manager->Update(); |
---|
945 | } |
---|
946 | |
---|
947 | sub OnChooseLanguage { |
---|
948 | my ( $self ) = @_; |
---|
949 | |
---|
950 | my $languages = wxTheApp->available_languages; |
---|
951 | |
---|
952 | |
---|
953 | my $dialog = new Wx::SingleChoiceDialog( |
---|
954 | undef, |
---|
955 | gettext( "Choose a language" ), |
---|
956 | gettext( "Choose a language" ), |
---|
957 | [ map { sprintf($_->[0], gettext($_->[2])) } @$languages ] |
---|
958 | ); |
---|
959 | |
---|
960 | if( $dialog->ShowModal() == wxID_OK ) { |
---|
961 | wxTheApp->current_language( |
---|
962 | $languages->[$dialog->GetSelection][1] |
---|
963 | ); |
---|
964 | |
---|
965 | Wx::LogMessage( |
---|
966 | sprintf( |
---|
967 | "%s : %s", |
---|
968 | gettext("pLoader needs to be restarted to display the new selected language"), |
---|
969 | gettext($languages->[$dialog->GetSelection][2]) |
---|
970 | ) |
---|
971 | ); |
---|
972 | wxTheApp->layout_clean(1); |
---|
973 | } |
---|
974 | |
---|
975 | $dialog->Destroy; |
---|
976 | |
---|
977 | } |
---|
978 | |
---|
979 | sub OnDefaultPhotoNameChanged { |
---|
980 | my ( $self ) = @_; |
---|
981 | |
---|
982 | Wx::LogMessage("New default_photo_name %s", $self->imagelist->default_photo_name); |
---|
983 | } |
---|
984 | |
---|
985 | |
---|
986 | sub create_notebook_imagelist { |
---|
987 | my( $self ) = @_; |
---|
988 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [300, 450], |
---|
989 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
990 | |
---|
991 | my $imglistpage = [ |
---|
992 | [ |
---|
993 | $self->imageviewer, |
---|
994 | gettext("Photo selection"), |
---|
995 | '../res/images.png', |
---|
996 | wxBITMAP_TYPE_PNG, |
---|
997 | ], |
---|
998 | ]; |
---|
999 | |
---|
1000 | $self->notebook($book); |
---|
1001 | $self->_populate_notebook($self->notebook, $imglistpage, 0); |
---|
1002 | return $book; |
---|
1003 | } |
---|
1004 | |
---|
1005 | sub create_notebook_image_properties { |
---|
1006 | my( $self ) = @_; |
---|
1007 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
---|
1008 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
1009 | my $pages = [ |
---|
1010 | [ |
---|
1011 | $self->image_prop_piwigo, |
---|
1012 | "Piwigo", |
---|
1013 | ], |
---|
1014 | [ |
---|
1015 | $self->image_prop_tags, |
---|
1016 | "Tags", |
---|
1017 | ], |
---|
1018 | [ |
---|
1019 | $self->image_prop_exif, |
---|
1020 | "Exif", |
---|
1021 | ], |
---|
1022 | ]; |
---|
1023 | |
---|
1024 | $self->_populate_notebook( $book, $pages ); |
---|
1025 | |
---|
1026 | $self->notebook_image_properties($book); |
---|
1027 | |
---|
1028 | return $book; |
---|
1029 | } |
---|
1030 | |
---|
1031 | sub create_notebook_global_settings { |
---|
1032 | my( $self ) = @_; |
---|
1033 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
---|
1034 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
---|
1035 | my $pages = [ |
---|
1036 | [ |
---|
1037 | $self->general_settings_panel, |
---|
1038 | gettext("General"), |
---|
1039 | ], |
---|
1040 | [ |
---|
1041 | $self->resized_settings_panel, |
---|
1042 | gettext("Resized"), |
---|
1043 | ], |
---|
1044 | [ |
---|
1045 | $self->thumbnail_settings_panel, |
---|
1046 | gettext("Thumbnail"), |
---|
1047 | ], |
---|
1048 | [ |
---|
1049 | $self->preview_settings_panel, |
---|
1050 | gettext("Preview"), |
---|
1051 | ], |
---|
1052 | [ |
---|
1053 | $self->advanced_settings_panel, |
---|
1054 | gettext("Advanced"), |
---|
1055 | ], |
---|
1056 | [ |
---|
1057 | $self->watermark_settings_panel, |
---|
1058 | gettext("Watermark"), |
---|
1059 | ] |
---|
1060 | ]; |
---|
1061 | |
---|
1062 | $self->_populate_notebook( $book, $pages ); |
---|
1063 | |
---|
1064 | $self->notebook_global_settings($book); |
---|
1065 | |
---|
1066 | return $book; |
---|
1067 | } |
---|
1068 | |
---|
1069 | |
---|
1070 | |
---|
1071 | |
---|
1072 | sub create_tree { |
---|
1073 | my ( $self ) = @_; |
---|
1074 | |
---|
1075 | my $images = [ |
---|
1076 | map { |
---|
1077 | Wx::Bitmap->new( $_, wxBITMAP_TYPE_PNG ) |
---|
1078 | |
---|
1079 | } |
---|
1080 | ( |
---|
1081 | '../res/tree_pwg.png', |
---|
1082 | '../res/tree_folder.png', |
---|
1083 | ) |
---|
1084 | ]; |
---|
1085 | |
---|
1086 | $self->treeimglist( Wx::ImageList->new( 16, 16, 1 ) ); |
---|
1087 | map { |
---|
1088 | $self->treeimglist->Add($_); |
---|
1089 | } |
---|
1090 | @$images; |
---|
1091 | |
---|
1092 | |
---|
1093 | $self->tree( |
---|
1094 | Wx::TreeCtrl->new( |
---|
1095 | $self, |
---|
1096 | -1, |
---|
1097 | wxDefaultPosition, |
---|
1098 | wxDefaultSize, |
---|
1099 | wxBORDER_NONE| |
---|
1100 | wxCLIP_CHILDREN| |
---|
1101 | wxTR_HAS_BUTTONS| |
---|
1102 | wxTR_EDIT_LABELS |
---|
1103 | ) |
---|
1104 | ); |
---|
1105 | |
---|
1106 | $self->tree->SetImageList( $self->treeimglist ); |
---|
1107 | $self->populate_tree_categories if !wxTheApp->use_offline; |
---|
1108 | $self->tree ; |
---|
1109 | } |
---|
1110 | |
---|
1111 | |
---|
1112 | sub populate_tree_categories { |
---|
1113 | my ( $self ) = @_; |
---|
1114 | |
---|
1115 | $self->populate_tree( |
---|
1116 | $self->tree, |
---|
1117 | wxTheApp->pwg->categories, |
---|
1118 | ) if defined wxTheApp->pwg ; |
---|
1119 | |
---|
1120 | #$self->tree->ExpandAll; |
---|
1121 | |
---|
1122 | } |
---|
1123 | |
---|
1124 | |
---|
1125 | # returns a valid itemData |
---|
1126 | sub itemData { Wx::TreeItemData->new( $_[0] ) } |
---|
1127 | |
---|
1128 | sub populate_tree { |
---|
1129 | my ( $self, $tree, $tree_items ) = @_; |
---|
1130 | my $root = shift @{$tree_items}; |
---|
1131 | |
---|
1132 | $self->tree_root( |
---|
1133 | $tree->AddRoot( |
---|
1134 | $root->[0], |
---|
1135 | $root->[3], |
---|
1136 | $root->[4], |
---|
1137 | itemData( $root->[2] ) |
---|
1138 | ) |
---|
1139 | ); |
---|
1140 | |
---|
1141 | $self->populate_tree_helper( $tree, $self->tree_root, $tree_items ); |
---|
1142 | |
---|
1143 | $tree->SelectItem( $self->tree_root ); |
---|
1144 | $tree->Expand( $self->tree_root ); |
---|
1145 | } |
---|
1146 | |
---|
1147 | sub populate_tree_helper { |
---|
1148 | my ( $self, $tree, $parent_id, $tree_items ) = @_; |
---|
1149 | |
---|
1150 | my $id; |
---|
1151 | |
---|
1152 | map { |
---|
1153 | my $name = $_->[0]; |
---|
1154 | |
---|
1155 | $id = $tree->AppendItem( |
---|
1156 | $parent_id, |
---|
1157 | $name, |
---|
1158 | defined($_->[3]) ? $_->[3] : 0, |
---|
1159 | defined($_->[4]) ? $_->[4] : 0, |
---|
1160 | itemData( $_->[2]) |
---|
1161 | ); |
---|
1162 | $self->tree_item_default($id) if ! defined $self->tree_item_default; |
---|
1163 | # current item has children |
---|
1164 | if( ref( $_->[1] ) eq 'ARRAY' ) { |
---|
1165 | $self->populate_tree_helper( $tree, $id, $_->[1] ); |
---|
1166 | } |
---|
1167 | } |
---|
1168 | @{$tree_items}; |
---|
1169 | |
---|
1170 | } |
---|
1171 | |
---|
1172 | |
---|
1173 | |
---|
1174 | |
---|
1175 | sub _populate_notebook { |
---|
1176 | my ( $self, $book, $pages, $position ) = @_; |
---|
1177 | |
---|
1178 | my $i = 0; |
---|
1179 | map { |
---|
1180 | my $icon = Wx::Icon->new(); |
---|
1181 | eval { $icon->LoadFile($_->[2], $_->[3]) ; } |
---|
1182 | if defined $_->[2]; |
---|
1183 | my $nb_icon = Wx::Bitmap->new( $icon ); |
---|
1184 | defined $position ? |
---|
1185 | $book->InsertPage($position, $_->[0], |
---|
1186 | $_->[1], 1, $nb_icon ) |
---|
1187 | : |
---|
1188 | $book->AddPage($_->[0], |
---|
1189 | $_->[1], 0, $nb_icon ); |
---|
1190 | |
---|
1191 | $i++; |
---|
1192 | } @$pages; |
---|
1193 | |
---|
1194 | } |
---|
1195 | |
---|
1196 | |
---|
1197 | sub _initMenus { |
---|
1198 | my ( $self ) = @_ ; |
---|
1199 | |
---|
1200 | $self->_tree_mnu; |
---|
1201 | $self->_imageviewer_mnu; |
---|
1202 | } |
---|
1203 | |
---|
1204 | |
---|
1205 | sub _tree_mnu { |
---|
1206 | my ( $self ) = @_; |
---|
1207 | |
---|
1208 | my $ctx_mnu = Wx::Menu->new; |
---|
1209 | |
---|
1210 | map { |
---|
1211 | $ctx_mnu->Append( |
---|
1212 | @$_[0..2], wxITEM_NORMAL |
---|
1213 | )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG)); |
---|
1214 | } |
---|
1215 | ( |
---|
1216 | # workaround : first item does not show bitmap |
---|
1217 | [ |
---|
1218 | 0, |
---|
1219 | "", |
---|
1220 | "", |
---|
1221 | '../res/mnu_folder_new.png', |
---|
1222 | ], |
---|
1223 | [ |
---|
1224 | 1+$ID_TREE_CTX_MENU, |
---|
1225 | wxTheApp->branding->{'Add new category'}, |
---|
1226 | sprintf( |
---|
1227 | "%s %s %s %s", |
---|
1228 | gettext("Add a new"), |
---|
1229 | wxTheApp->branding->{category}, |
---|
1230 | gettext("to the currently selected"), |
---|
1231 | wxTheApp->branding->{category}, |
---|
1232 | ), |
---|
1233 | '../res/mnu_folder_new.png', |
---|
1234 | ], |
---|
1235 | [ |
---|
1236 | 2+$ID_TREE_CTX_MENU, |
---|
1237 | gettext("Refresh"), |
---|
1238 | sprintf( |
---|
1239 | "Refresh %s list.", |
---|
1240 | wxTheApp->branding->{category}, |
---|
1241 | ), |
---|
1242 | '../res/mnu_refresh.png', |
---|
1243 | ], |
---|
1244 | [ |
---|
1245 | 3+$ID_TREE_CTX_MENU, |
---|
1246 | gettext("Expand all"), |
---|
1247 | sprintf( |
---|
1248 | "Expand %s list.", |
---|
1249 | wxTheApp->branding->{category}, |
---|
1250 | ), |
---|
1251 | '../res/mnu_expandall.png', |
---|
1252 | ], |
---|
1253 | [ |
---|
1254 | 4+$ID_TREE_CTX_MENU, |
---|
1255 | gettext("Collapse all"), |
---|
1256 | sprintf( |
---|
1257 | "Collapse %s list.", |
---|
1258 | wxTheApp->branding->{category}, |
---|
1259 | ), |
---|
1260 | '../res/mnu_collapseall.png', |
---|
1261 | ], |
---|
1262 | ); |
---|
1263 | |
---|
1264 | $ctx_mnu->Delete(0); |
---|
1265 | $self->tree_mnu( |
---|
1266 | $ctx_mnu |
---|
1267 | ); |
---|
1268 | } |
---|
1269 | |
---|
1270 | sub _imageviewer_mnu { |
---|
1271 | my ( $self ) = @_; |
---|
1272 | |
---|
1273 | my $ctx_mnu = Wx::Menu->new; |
---|
1274 | |
---|
1275 | map { |
---|
1276 | $ctx_mnu->Append( |
---|
1277 | @$_[0..2] |
---|
1278 | )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG)); |
---|
1279 | } |
---|
1280 | ( |
---|
1281 | # workaround : first item does not show bitmap |
---|
1282 | [ |
---|
1283 | 0, |
---|
1284 | "", |
---|
1285 | "", |
---|
1286 | '../res/mnu_properties.png', |
---|
1287 | ], |
---|
1288 | [ |
---|
1289 | 1+$ID_IMAGEVIEWER_CTX_MENU, |
---|
1290 | gettext("Properties"), |
---|
1291 | gettext("Modify photo properties"), |
---|
1292 | '../res/mnu_properties.png', |
---|
1293 | ], |
---|
1294 | [ |
---|
1295 | 2+$ID_IMAGEVIEWER_CTX_MENU, |
---|
1296 | gettext("Preview"), |
---|
1297 | gettext("Display photo preview"), |
---|
1298 | '../res/mnu_preview.png', |
---|
1299 | ], |
---|
1300 | ); |
---|
1301 | |
---|
1302 | $ctx_mnu->Delete(0); |
---|
1303 | $self->imageviewer_mnu( |
---|
1304 | $ctx_mnu |
---|
1305 | ); |
---|
1306 | } |
---|
1307 | |
---|
1308 | sub _initEventHandlers { |
---|
1309 | my ( $self ) = @_ ; |
---|
1310 | |
---|
1311 | Wx::Event::EVT_MENU( $self, 100, \&OnGettingStarted ); |
---|
1312 | Wx::Event::EVT_MENU( $self, 101, \&OnAddImages ); |
---|
1313 | Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages ); |
---|
1314 | Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages ); |
---|
1315 | Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings ); |
---|
1316 | Wx::Event::EVT_MENU( $self, 105, \&OnChooseLanguage ); |
---|
1317 | EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged ); |
---|
1318 | EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick ); |
---|
1319 | EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&OnTreeEndLabelEdit ); |
---|
1320 | |
---|
1321 | EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit ); |
---|
1322 | EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated ); |
---|
1323 | EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ; |
---|
1324 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ; |
---|
1325 | |
---|
1326 | EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ; |
---|
1327 | |
---|
1328 | EVT_CLOSE( $self, \&OnClose ); |
---|
1329 | Wx::Event::EVT_UPDATE_UI( $self, $self, \&OnUpdateUI ); |
---|
1330 | |
---|
1331 | |
---|
1332 | Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories ); |
---|
1333 | Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories ); |
---|
1334 | Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories ); |
---|
1335 | Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&OnCollapseCategories ); |
---|
1336 | |
---|
1337 | Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties ); |
---|
1338 | Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview ); |
---|
1339 | |
---|
1340 | |
---|
1341 | } |
---|
1342 | |
---|
1343 | { |
---|
1344 | my $prevdir; |
---|
1345 | my $prevfile; |
---|
1346 | |
---|
1347 | sub OnAddImages { |
---|
1348 | my( $self, $event ) = @_; |
---|
1349 | my $dialog = Wx::FileDialog->new |
---|
1350 | ( $self, gettext("Select photos for upload"), $prevfile, $prevdir, |
---|
1351 | sprintf("%s (*.jpg)|*.jpg|All(*.*)|*.*", gettext("JPEG files")), |
---|
1352 | wxFD_OPEN|wxFD_MULTIPLE ); |
---|
1353 | |
---|
1354 | my $file_paths = []; |
---|
1355 | if( $dialog->ShowModal != wxID_CANCEL ) { |
---|
1356 | @$file_paths = $dialog->GetPaths; |
---|
1357 | $self->SetNewFiles($file_paths) ; |
---|
1358 | } |
---|
1359 | $dialog->Destroy; |
---|
1360 | # $event->Skip; |
---|
1361 | } |
---|
1362 | } |
---|
1363 | |
---|
1364 | sub OnUpdateUI { |
---|
1365 | my( $self, $event ) = @_; |
---|
1366 | |
---|
1367 | if( $self->manager ){ |
---|
1368 | if($self->manager->GetPane("global_settings")->IsShown){ |
---|
1369 | $self->toolbar->EnableTool(104, 0); |
---|
1370 | } |
---|
1371 | else{ |
---|
1372 | $self->toolbar->EnableTool(104, 1); |
---|
1373 | } |
---|
1374 | |
---|
1375 | if($self->manager->GetPane("getting_started")->IsShown){ |
---|
1376 | $self->toolbar->EnableTool(100, 0); |
---|
1377 | } |
---|
1378 | else{ |
---|
1379 | $self->toolbar->EnableTool(100, 1); |
---|
1380 | } |
---|
1381 | } |
---|
1382 | |
---|
1383 | } |
---|
1384 | |
---|
1385 | sub OnRemoveImages { |
---|
1386 | my( $self, $event ) = @_; |
---|
1387 | |
---|
1388 | |
---|
1389 | $self->imagelist->RemoveImageSelection; |
---|
1390 | $self->imageviewer->Refresh; |
---|
1391 | |
---|
1392 | $self->image_preview->SetPage( |
---|
1393 | "<html></html>" |
---|
1394 | ) if !$self->imageviewer->GetItemCount; |
---|
1395 | |
---|
1396 | } |
---|
1397 | |
---|
1398 | sub SetNewFiles { |
---|
1399 | my ( $self, $file_paths ) = @_; |
---|
1400 | |
---|
1401 | $self->ShowImageViewer(); |
---|
1402 | $self->progressdlg( |
---|
1403 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
---|
1404 | { |
---|
1405 | title => gettext("Image processing progress information"), |
---|
1406 | bt_label => gettext("Cancel image processing"), |
---|
1407 | bt_close_label => gettext("Close"), |
---|
1408 | } |
---|
1409 | ) |
---|
1410 | ); |
---|
1411 | $self->progressdlg->Show(1); |
---|
1412 | Wx::Yield(); |
---|
1413 | |
---|
1414 | |
---|
1415 | my $files = [ |
---|
1416 | map { |
---|
1417 | # to make sure that unicode chars in filenames are supported |
---|
1418 | { |
---|
1419 | ANSIPathName => $^O =~ /MSWin32/ ? Win32::GetANSIPathName($_) : $_, |
---|
1420 | PathName => $_, |
---|
1421 | }, |
---|
1422 | }@$file_paths |
---|
1423 | ]; |
---|
1424 | |
---|
1425 | @$files = sort { $a->{PathName} cmp $b->{PathName} } @$files; |
---|
1426 | |
---|
1427 | $self->imagelist->SetNewFiles( |
---|
1428 | $files |
---|
1429 | ); |
---|
1430 | |
---|
1431 | |
---|
1432 | } |
---|
1433 | |
---|
1434 | sub OnTreeSelChanged { |
---|
1435 | my( $self, $event ) = @_; |
---|
1436 | |
---|
1437 | my @items = $self->tree->GetSelections; |
---|
1438 | |
---|
1439 | $self->imagelist->categories( |
---|
1440 | [ |
---|
1441 | map { |
---|
1442 | my $category = $self->tree->GetPlData( $_ ); |
---|
1443 | $category->{id} if $category != -1; |
---|
1444 | } |
---|
1445 | @items |
---|
1446 | ] |
---|
1447 | ); |
---|
1448 | } |
---|
1449 | |
---|
1450 | sub OnTreeItemRightClick { |
---|
1451 | my( $self, $event ) = @_; |
---|
1452 | |
---|
1453 | |
---|
1454 | $self->PopupMenu($self->tree_mnu, wxDefaultPosition); |
---|
1455 | |
---|
1456 | } |
---|
1457 | |
---|
1458 | sub OnTreeEndLabelEdit { |
---|
1459 | my( $self, $event ) = @_; |
---|
1460 | |
---|
1461 | my $label = $event->GetLabel; |
---|
1462 | |
---|
1463 | $label =~ s/^\s+$//; |
---|
1464 | |
---|
1465 | if(defined($label) and !( "" eq $label )){ |
---|
1466 | $self->_SetLabel($event) |
---|
1467 | } |
---|
1468 | else{ |
---|
1469 | $event->Veto; |
---|
1470 | } |
---|
1471 | } |
---|
1472 | |
---|
1473 | sub _SetLabel { |
---|
1474 | my( $self, $event ) = @_; |
---|
1475 | |
---|
1476 | my $category = $self->tree->GetPlData($event->GetItem); |
---|
1477 | my $category_id; |
---|
1478 | |
---|
1479 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
---|
1480 | my $comment; |
---|
1481 | my ( $success, $status_msg, $content ) = $self->pwg->SetInfoCategories( |
---|
1482 | $event->GetLabel, |
---|
1483 | $comment, |
---|
1484 | $category_id |
---|
1485 | ); |
---|
1486 | |
---|
1487 | my $ok = 1; |
---|
1488 | |
---|
1489 | if(!$success){ |
---|
1490 | $ok = 0; |
---|
1491 | } |
---|
1492 | |
---|
1493 | if('fail' eq $content->{stat}){ |
---|
1494 | $ok = 0; |
---|
1495 | } |
---|
1496 | |
---|
1497 | # method call failed |
---|
1498 | if(!$ok){ |
---|
1499 | $event->Veto; |
---|
1500 | Wx::MessageBox( |
---|
1501 | sprintf( |
---|
1502 | "%s %s", |
---|
1503 | gettext("Update failed : "), |
---|
1504 | $status_msg |
---|
1505 | ), |
---|
1506 | gettext("Piwigo update error"), |
---|
1507 | wxOK | wxICON_EXCLAMATION, |
---|
1508 | ); |
---|
1509 | Wx::LogMessage("%s\n\n%s", Dumper($content), gettext("This function is not available. A Piwigo upgrade may resolve this issue.")); |
---|
1510 | } |
---|
1511 | } |
---|
1512 | |
---|
1513 | sub OnImageViewerItemRightClick { |
---|
1514 | my( $self, $event ) = @_; |
---|
1515 | |
---|
1516 | |
---|
1517 | $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition); |
---|
1518 | |
---|
1519 | |
---|
1520 | } |
---|
1521 | |
---|
1522 | sub OnExpandCategories { |
---|
1523 | my ( $self, $event ) = @_; |
---|
1524 | |
---|
1525 | my $parent_item = $self->tree->GetSelection; |
---|
1526 | $self->tree->ExpandAllChildren($parent_item); |
---|
1527 | $self->tree->EnsureVisible($parent_item); |
---|
1528 | } |
---|
1529 | |
---|
1530 | sub OnCollapseCategories { |
---|
1531 | my ( $self, $event ) = @_; |
---|
1532 | |
---|
1533 | my $parent_item = $self->tree->GetSelection; |
---|
1534 | $self->tree->CollapseAllChildren($parent_item); |
---|
1535 | $self->tree->Expand($parent_item) if -1 == $self->tree->GetPlData($parent_item); |
---|
1536 | } |
---|
1537 | |
---|
1538 | sub OnAddCategories { |
---|
1539 | my ( $self, $event ) = @_; |
---|
1540 | |
---|
1541 | my $parent_item = $self->tree->GetSelection; |
---|
1542 | |
---|
1543 | my $category = $self->tree->GetPlData($parent_item); |
---|
1544 | my $category_id; |
---|
1545 | |
---|
1546 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
---|
1547 | |
---|
1548 | my $dialog = Wx::TextEntryDialog->new( |
---|
1549 | $self, |
---|
1550 | wxTheApp->branding->{'Category name'}, |
---|
1551 | wxTheApp->branding->{'Add new category'}, |
---|
1552 | wxTheApp->branding->{'New category'}, |
---|
1553 | ); |
---|
1554 | |
---|
1555 | if( $dialog->ShowModal != wxID_CANCEL ) { |
---|
1556 | my $name = $dialog->GetValue; |
---|
1557 | my ( $success, $status_msg, $content ) = $self->pwg->AddCategories( $name, $category_id); |
---|
1558 | |
---|
1559 | if($success){ |
---|
1560 | $self->_append_category($parent_item, $name, $content->{result}{id}); |
---|
1561 | } |
---|
1562 | } |
---|
1563 | $dialog->Destroy; |
---|
1564 | } |
---|
1565 | |
---|
1566 | sub OnRefreshCategories { |
---|
1567 | my ( $self, $event ) = @_; |
---|
1568 | |
---|
1569 | $self->_refresh_all_categories_helper; |
---|
1570 | } |
---|
1571 | |
---|
1572 | |
---|
1573 | sub _refresh_all_categories_helper { |
---|
1574 | my ( $self ) = @_; |
---|
1575 | |
---|
1576 | my $busycursor = Wx::BusyCursor->new(); |
---|
1577 | $self->tree->CollapseAll; |
---|
1578 | $self->tree->DeleteAllItems; |
---|
1579 | $self->imagelist->categories([]); |
---|
1580 | $self->pwg->RefreshCategories(); |
---|
1581 | $self->populate_tree_categories; |
---|
1582 | } |
---|
1583 | |
---|
1584 | sub _append_category { |
---|
1585 | my ( $self, $parent_id, $name, $id ) = @_; |
---|
1586 | |
---|
1587 | $self->tree->SelectItem( |
---|
1588 | $self->tree->AppendItem( |
---|
1589 | $parent_id, |
---|
1590 | $name, |
---|
1591 | 1, |
---|
1592 | -1, |
---|
1593 | Wx::TreeItemData->new( { id => $id } ) |
---|
1594 | ) |
---|
1595 | ); |
---|
1596 | } |
---|
1597 | |
---|
1598 | sub OnImageViewerEndLabelEdit { |
---|
1599 | my( $self, $event ) = @_; |
---|
1600 | |
---|
1601 | my $image = $self->imagelist->GetImage($event->GetIndex); |
---|
1602 | $image->site_name( |
---|
1603 | $event->GetLabel |
---|
1604 | ); |
---|
1605 | |
---|
1606 | $self->image_prop_piwigo->Refresh; |
---|
1607 | } |
---|
1608 | |
---|
1609 | sub OnImageViewerItemActivated { |
---|
1610 | my( $self, $event ) = @_; |
---|
1611 | |
---|
1612 | $self->current_imageviewer_index( |
---|
1613 | $event->GetIndex |
---|
1614 | ); |
---|
1615 | |
---|
1616 | $self->OnPhotoProperties; |
---|
1617 | } |
---|
1618 | |
---|
1619 | |
---|
1620 | sub OnImageViewerItemSelected { |
---|
1621 | my( $self, $event ) = @_; |
---|
1622 | |
---|
1623 | my $indx = $event->GetIndex; |
---|
1624 | |
---|
1625 | $self->_on_imageviewer_item_selected($indx); |
---|
1626 | |
---|
1627 | $event->Skip; |
---|
1628 | } |
---|
1629 | |
---|
1630 | sub _on_imageviewer_item_selected { |
---|
1631 | my ( $self, $index ) = @_; |
---|
1632 | |
---|
1633 | $self->current_imageviewer_index($index); |
---|
1634 | $self->imagelist->SetCurrentImage($index); |
---|
1635 | |
---|
1636 | $self->imagelist->image_selection( |
---|
1637 | $self->imageviewer->GetSelectedItems |
---|
1638 | ); |
---|
1639 | |
---|
1640 | $self->_image_preview_refresh if @{$self->imagelist->image_selection} < 2; |
---|
1641 | |
---|
1642 | $self->manager->Update; |
---|
1643 | |
---|
1644 | $self->image_prop_piwigo->Refresh; |
---|
1645 | $self->image_prop_exif->Refresh; |
---|
1646 | $self->image_prop_tags->Refresh; |
---|
1647 | |
---|
1648 | } |
---|
1649 | |
---|
1650 | sub _image_preview_refresh { |
---|
1651 | my ( $self ) = @_; |
---|
1652 | |
---|
1653 | |
---|
1654 | my $html_src = sprintf(" |
---|
1655 | <html> |
---|
1656 | <body> |
---|
1657 | <img src=\"%s\"/> |
---|
1658 | </body> |
---|
1659 | </html> |
---|
1660 | ", |
---|
1661 | $self->imagelist->current_image->preview_file, |
---|
1662 | ); |
---|
1663 | |
---|
1664 | $self->image_preview->SetPage( |
---|
1665 | $html_src |
---|
1666 | ); |
---|
1667 | |
---|
1668 | my $bmp = Wx::Bitmap->new( |
---|
1669 | $self->imagelist->current_image->preview_file, |
---|
1670 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1671 | ); |
---|
1672 | |
---|
1673 | my $size = [40+$bmp->GetWidth, 60+$bmp->GetHeight]; |
---|
1674 | |
---|
1675 | $self->manager->GetPane("image_preview")->FloatingSize($size); |
---|
1676 | |
---|
1677 | } |
---|
1678 | |
---|
1679 | sub OnImageViewerKeyDown { |
---|
1680 | my( $self, $event ) = @_; |
---|
1681 | |
---|
1682 | if(WXK_DELETE == $event->GetKeyCode){ |
---|
1683 | $self->OnRemoveImages(); |
---|
1684 | |
---|
1685 | my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ? |
---|
1686 | $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ; |
---|
1687 | $self->imageviewer->SelectItem( |
---|
1688 | $index |
---|
1689 | ); |
---|
1690 | $self->imageviewer->EnsureVisible( |
---|
1691 | $index |
---|
1692 | ); |
---|
1693 | } |
---|
1694 | elsif(WXK_DOWN == $event->GetKeyCode){ |
---|
1695 | printf("element %s\n", $event->GetIndex); |
---|
1696 | } |
---|
1697 | $event->Skip(); |
---|
1698 | } |
---|
1699 | |
---|
1700 | sub OnUploadImages { |
---|
1701 | my( $self, $event ) = @_; |
---|
1702 | |
---|
1703 | eval { |
---|
1704 | $self->ProcessImageSelection(); |
---|
1705 | }; |
---|
1706 | } |
---|
1707 | |
---|
1708 | # remove image from imagelist when uploaded |
---|
1709 | sub UploadImagesViewerRefresh { |
---|
1710 | my ( $self ) = @_; |
---|
1711 | |
---|
1712 | $self->imageviewer->Refresh; |
---|
1713 | Wx::Yield(); |
---|
1714 | } |
---|
1715 | |
---|
1716 | sub UploadProgressMessageRefresh { |
---|
1717 | my ( $self, $msg ) = @_; |
---|
1718 | |
---|
1719 | Wx::Yield(); |
---|
1720 | |
---|
1721 | $self->upload_progressdlg->processing( |
---|
1722 | $msg |
---|
1723 | ); |
---|
1724 | $self->upload_progressdlg->LogProgress(); |
---|
1725 | |
---|
1726 | Wx::Yield(); |
---|
1727 | } |
---|
1728 | |
---|
1729 | sub UploadProgressMessageDetailsRefresh { |
---|
1730 | my ( $self, $msg ) = @_; |
---|
1731 | |
---|
1732 | Wx::Yield(); |
---|
1733 | |
---|
1734 | $self->upload_progressdlg->processing_details( |
---|
1735 | $msg |
---|
1736 | ); |
---|
1737 | $self->upload_progressdlg->LogProgress(); |
---|
1738 | |
---|
1739 | Wx::Yield(); |
---|
1740 | } |
---|
1741 | |
---|
1742 | |
---|
1743 | sub UploadProgressThumbnailRefresh { |
---|
1744 | my ( $self ) = @_; |
---|
1745 | |
---|
1746 | my $imagelist = $self->imagelist ; |
---|
1747 | |
---|
1748 | |
---|
1749 | $self->upload_progressdlg->image->SetBitmap(wxNullBitmap); |
---|
1750 | $self->upload_progressdlg->image->SetBitmap( |
---|
1751 | Wx::Bitmap->new( |
---|
1752 | $self->imagelist->current_image->wx_thumb_file, |
---|
1753 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1754 | ) |
---|
1755 | ); |
---|
1756 | |
---|
1757 | Wx::Yield(); |
---|
1758 | } |
---|
1759 | |
---|
1760 | sub UploadProgressBarRefresh { |
---|
1761 | my ( $self, $value ) = @_; |
---|
1762 | |
---|
1763 | eval { |
---|
1764 | $self->upload_progressdlg->progress( |
---|
1765 | $value |
---|
1766 | ); |
---|
1767 | $self->upload_progressdlg->LogProgress(); |
---|
1768 | }; |
---|
1769 | #croak gettext("Upload cancelled") if $@; |
---|
1770 | |
---|
1771 | Wx::Yield(); |
---|
1772 | } |
---|
1773 | |
---|
1774 | sub SetNewFilesDisplayEndInfo { |
---|
1775 | my ( $self, $msg ) = @_; |
---|
1776 | |
---|
1777 | $self->progressdlg->DisplayEndInfo($msg); |
---|
1778 | } |
---|
1779 | |
---|
1780 | sub UploadDisplayEndInfo { |
---|
1781 | my ( $self, $msg ) = @_; |
---|
1782 | |
---|
1783 | my $imagelist = $self->imagelist ; |
---|
1784 | |
---|
1785 | $self->upload_progressdlg->DisplayEndInfo($msg); |
---|
1786 | } |
---|
1787 | |
---|
1788 | sub ShowImageViewer { |
---|
1789 | my ( $self ) = @_; |
---|
1790 | |
---|
1791 | if(!$self->imageviewer->IsShown){ |
---|
1792 | $self->imageviewer->Show(1); |
---|
1793 | } |
---|
1794 | } |
---|
1795 | |
---|
1796 | |
---|
1797 | sub ActivateImageViewer { |
---|
1798 | my ( $self ) = @_; |
---|
1799 | |
---|
1800 | } |
---|
1801 | |
---|
1802 | |
---|
1803 | sub SetNewFilesViewerRefresh { |
---|
1804 | |
---|
1805 | my ( $self ) = @_; |
---|
1806 | |
---|
1807 | my $wximagelist = $self->imagelist->wx_thumb_imglist; |
---|
1808 | |
---|
1809 | my $indx = $wximagelist->Add( |
---|
1810 | Wx::Bitmap->new( |
---|
1811 | $self->imagelist->current_image->wx_thumb_file, |
---|
1812 | $self->GetWxBitmapType($self->imagelist->type), |
---|
1813 | ) |
---|
1814 | ) if defined $self->imagelist->current_image->wx_thumb_file; |
---|
1815 | print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n"; |
---|
1816 | $self->imageviewer->Refresh( |
---|
1817 | $wximagelist |
---|
1818 | ); |
---|
1819 | |
---|
1820 | Wx::Yield(); |
---|
1821 | } |
---|
1822 | |
---|
1823 | |
---|
1824 | |
---|
1825 | # prepare and upload image_selection |
---|
1826 | sub ProcessImageSelection { |
---|
1827 | my ( $self ) = @_; |
---|
1828 | |
---|
1829 | return if !scalar @{$self->imagelist->sums}; |
---|
1830 | |
---|
1831 | if( scalar @{$self->imagelist->categories} ){ |
---|
1832 | # all selected is implicit |
---|
1833 | if(!scalar @{$self->imageviewer->GetSelectedItems}){ |
---|
1834 | |
---|
1835 | $self->imagelist->image_selection( |
---|
1836 | $self->imageviewer->GetAllItems |
---|
1837 | ); |
---|
1838 | } |
---|
1839 | |
---|
1840 | return if( !defined $self->imagelist->image_selection ); |
---|
1841 | return if( !scalar @{$self->imagelist->image_selection} ); |
---|
1842 | |
---|
1843 | $self->upload_progressdlg( |
---|
1844 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
---|
1845 | { |
---|
1846 | title => gettext("Image upload progress information"), |
---|
1847 | bt_label => gettext("Cancel upload"), |
---|
1848 | bt_close_label => gettext("Close"), |
---|
1849 | } |
---|
1850 | ) |
---|
1851 | ); |
---|
1852 | # modeless dialog |
---|
1853 | $self->upload_progressdlg->Show(1); |
---|
1854 | Wx::Yield(); |
---|
1855 | eval { |
---|
1856 | $self->imagelist->UploadSelection; |
---|
1857 | }; |
---|
1858 | if($@){ |
---|
1859 | Wx::MessageBox( |
---|
1860 | sprintf( |
---|
1861 | gettext("Upload cancelled"), |
---|
1862 | ), |
---|
1863 | gettext("Piwigo upload information"), |
---|
1864 | wxOK | wxICON_INFORMATION, |
---|
1865 | ); |
---|
1866 | } |
---|
1867 | } |
---|
1868 | else { |
---|
1869 | Wx::MessageBox( |
---|
1870 | sprintf( |
---|
1871 | "%s %s", |
---|
1872 | gettext("Please select a valid target"), |
---|
1873 | wxTheApp->branding->{category} |
---|
1874 | ), |
---|
1875 | gettext("Piwigo upload error"), |
---|
1876 | wxOK | wxICON_EXCLAMATION, |
---|
1877 | ); |
---|
1878 | } |
---|
1879 | } |
---|
1880 | |
---|
1881 | |
---|
1882 | sub SetNewFilesProgress { |
---|
1883 | my ( $self ) = @_; |
---|
1884 | |
---|
1885 | my $imagelist = $self->imagelist; |
---|
1886 | |
---|
1887 | $self->progressdlg->processing( |
---|
1888 | sprintf( |
---|
1889 | $imagelist->progress_msg, |
---|
1890 | $imagelist->current_image->file, |
---|
1891 | ) |
---|
1892 | ); |
---|
1893 | |
---|
1894 | eval { |
---|
1895 | $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]); |
---|
1896 | $self->progressdlg->image->SetBitmap(wxNullBitmap); |
---|
1897 | $self->progressdlg->image->SetBitmap( |
---|
1898 | Wx::Bitmap->new( |
---|
1899 | $imagelist->current_image->wx_thumb_file, |
---|
1900 | $self->GetWxBitmapType( $imagelist->type ) |
---|
1901 | ) |
---|
1902 | ); |
---|
1903 | $self->progressdlg->progress( |
---|
1904 | $imagelist->count * ( 100/scalar @{$imagelist->new_files} ) |
---|
1905 | ); |
---|
1906 | $self->progressdlg->LogProgress(); |
---|
1907 | }; |
---|
1908 | Wx::Yield(); |
---|
1909 | } |
---|
1910 | |
---|
1911 | sub OnClose { |
---|
1912 | my $self = shift; |
---|
1913 | |
---|
1914 | |
---|
1915 | # Restaure previous log wnd |
---|
1916 | Wx::Log::SetActiveTarget( $self->oldlogwnd ); |
---|
1917 | |
---|
1918 | # allways store |
---|
1919 | |
---|
1920 | wxTheApp->StoreConnectionProperties; |
---|
1921 | |
---|
1922 | $self->imagelist->Store; |
---|
1923 | wxTheApp->login_dlg->Destroy; |
---|
1924 | |
---|
1925 | wxTheApp->perspective( |
---|
1926 | $self->manager->SavePerspective |
---|
1927 | ); |
---|
1928 | |
---|
1929 | wxTheApp->imageviewerIndex( |
---|
1930 | $self->current_imageviewer_index |
---|
1931 | ); |
---|
1932 | |
---|
1933 | my $frameLayout = {}; |
---|
1934 | |
---|
1935 | ( $frameLayout->{pX}, $frameLayout->{pY}, $frameLayout->{W}, $frameLayout->{H} ) = ( $self->GetPositionXY, $self->GetSizeWH ) ; |
---|
1936 | |
---|
1937 | wxTheApp->frameLayout( |
---|
1938 | $frameLayout |
---|
1939 | ); |
---|
1940 | |
---|
1941 | wxTheApp->StoreLayoutProperties; |
---|
1942 | |
---|
1943 | $self->manager->UnInit; |
---|
1944 | $self->Destroy; |
---|
1945 | } |
---|
1946 | |
---|
1947 | |
---|
1948 | sub create_toolbar { |
---|
1949 | my( $self ) = @_; |
---|
1950 | |
---|
1951 | my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT ); |
---|
1952 | $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) ); |
---|
1953 | map { |
---|
1954 | my $icon1 = Wx::Icon->new(); |
---|
1955 | eval { |
---|
1956 | $icon1->LoadFile($_->[2], $_->[3]); |
---|
1957 | }; |
---|
1958 | my $tb_icon1 = Wx::Bitmap->new( $icon1 ); |
---|
1959 | |
---|
1960 | my $icon2 = Wx::Icon->new(); |
---|
1961 | eval { |
---|
1962 | $icon2->LoadFile($_->[5], $_->[3]); |
---|
1963 | }; |
---|
1964 | my $tb_icon2 = Wx::Bitmap->new( $icon2 ); |
---|
1965 | |
---|
1966 | |
---|
1967 | $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[1] ); |
---|
1968 | $tb->EnableTool( $_->[0], $_->[4]); |
---|
1969 | } |
---|
1970 | ( |
---|
1971 | [ |
---|
1972 | 100, |
---|
1973 | gettext("Getting started"), |
---|
1974 | '../res/tb_getting_started.png', |
---|
1975 | wxBITMAP_TYPE_PNG, |
---|
1976 | 1, |
---|
1977 | '../res/tb_getting_started.png', |
---|
1978 | gettext("Display getting started panel") |
---|
1979 | ], |
---|
1980 | [ |
---|
1981 | 101, |
---|
1982 | gettext("Add photo to selection"), |
---|
1983 | '../res/tb_add.png', |
---|
1984 | wxBITMAP_TYPE_PNG, |
---|
1985 | 1, |
---|
1986 | '../res/tb_add.png', |
---|
1987 | gettext("Add photo to selection for resizing and uploading") |
---|
1988 | ], |
---|
1989 | [ |
---|
1990 | 102, |
---|
1991 | gettext("Remove photo from selection"), |
---|
1992 | '../res/tb_remove.png', |
---|
1993 | wxBITMAP_TYPE_PNG, |
---|
1994 | 1, |
---|
1995 | '../res/tb_remove.png', |
---|
1996 | gettext("Remove photo from selection. Files are not deleted ") |
---|
1997 | ], |
---|
1998 | [ |
---|
1999 | 103, |
---|
2000 | gettext("Upload to Piwigo"), |
---|
2001 | '../res/tb_upload.png', |
---|
2002 | wxBITMAP_TYPE_PNG, |
---|
2003 | wxTheApp->use_offline ? 0 : 1, |
---|
2004 | '../res/tb_upload.png', |
---|
2005 | gettext("Upload photos to Piwigo.") |
---|
2006 | ], |
---|
2007 | [ |
---|
2008 | 104, |
---|
2009 | gettext("Global settings"), |
---|
2010 | '../res/tb_settings.png', |
---|
2011 | wxBITMAP_TYPE_PNG, |
---|
2012 | 0, |
---|
2013 | '../res/tb_settings.png', |
---|
2014 | gettext("Change global settings.") |
---|
2015 | ], |
---|
2016 | [ |
---|
2017 | 105, |
---|
2018 | gettext("Language choice"), |
---|
2019 | '../res/tb_i18n.png', |
---|
2020 | wxBITMAP_TYPE_PNG, |
---|
2021 | 1, |
---|
2022 | '../res/tb_i18n.png', |
---|
2023 | gettext("Language choice") |
---|
2024 | ], |
---|
2025 | |
---|
2026 | ); |
---|
2027 | |
---|
2028 | if($@){ |
---|
2029 | undef $tb; |
---|
2030 | } |
---|
2031 | else{ |
---|
2032 | $tb->Realize; |
---|
2033 | } |
---|
2034 | |
---|
2035 | return $tb; |
---|
2036 | } |
---|
2037 | |
---|
2038 | |
---|
2039 | sub _create_textctrl { |
---|
2040 | my( $self, $parent, $text, $size ) = @_; |
---|
2041 | |
---|
2042 | return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size, |
---|
2043 | wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY ); |
---|
2044 | } |
---|
2045 | |
---|
2046 | sub create_textctrl { |
---|
2047 | my( $self, $text, $size ) = @_; |
---|
2048 | |
---|
2049 | return $self->_create_textctrl( $self, $text, $size ); |
---|
2050 | } |
---|
2051 | |
---|
2052 | sub DESTROY { |
---|
2053 | my( $self ) = @_; |
---|
2054 | |
---|
2055 | } |
---|
2056 | |
---|
2057 | |
---|
2058 | |
---|
2059 | 1; |
---|
2060 | |
---|
2061 | |
---|
2062 | |
---|
2063 | |
---|
2064 | |
---|
2065 | package DNDImageListDropTarget; |
---|
2066 | use Wx qw/wxTheApp/; |
---|
2067 | use base qw(Wx::FileDropTarget Class::Accessor::Fast); |
---|
2068 | |
---|
2069 | __PACKAGE__->mk_accessors( |
---|
2070 | qw/ |
---|
2071 | imageviewer |
---|
2072 | / |
---|
2073 | ); |
---|
2074 | |
---|
2075 | sub new { |
---|
2076 | my $class = shift; |
---|
2077 | my $imageviewer = shift; |
---|
2078 | my $self = $class->SUPER::new( @_ ); |
---|
2079 | |
---|
2080 | $self->imageviewer($imageviewer); |
---|
2081 | |
---|
2082 | return $self; |
---|
2083 | } |
---|
2084 | |
---|
2085 | sub OnDropFiles { |
---|
2086 | my( $self, $x, $y, $files ) = @_; |
---|
2087 | |
---|
2088 | wxTheApp->frame->SetNewFiles($files) ; |
---|
2089 | } |
---|
2090 | |
---|
2091 | |
---|
2092 | |
---|
2093 | |
---|
2094 | 1; |
---|
2095 | |
---|
2096 | |
---|
2097 | package DNDCategoryTreeDropTarget; |
---|
2098 | |
---|
2099 | use base qw(Wx::TextDropTarget Class::Accessor::Fast); |
---|
2100 | use Data::Dumper; |
---|
2101 | use Wx qw/ |
---|
2102 | wxDragNone |
---|
2103 | wxDragCopy |
---|
2104 | wxDragMove |
---|
2105 | /; |
---|
2106 | |
---|
2107 | __PACKAGE__->mk_accessors( |
---|
2108 | qw/ |
---|
2109 | tree |
---|
2110 | frame |
---|
2111 | / |
---|
2112 | ); |
---|
2113 | |
---|
2114 | sub new { |
---|
2115 | my ( $class, $tree ) = @_; |
---|
2116 | my $self = $class->SUPER::new(); |
---|
2117 | |
---|
2118 | $self->tree($tree); |
---|
2119 | $self->frame($tree->GetParent); |
---|
2120 | return $self; |
---|
2121 | } |
---|
2122 | |
---|
2123 | |
---|
2124 | |
---|
2125 | sub OnDropText { |
---|
2126 | my( $self, $x, $y, $textdata ) = @_; |
---|
2127 | |
---|
2128 | # must be $VAR1 because $textdata is the result of Data::Dumper |
---|
2129 | my $VAR1; |
---|
2130 | eval $textdata; |
---|
2131 | eval { |
---|
2132 | if(scalar @$VAR1){ |
---|
2133 | my @items; |
---|
2134 | if(scalar @items < 2) { |
---|
2135 | my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]); |
---|
2136 | push @items, $dropItem; |
---|
2137 | } |
---|
2138 | else { |
---|
2139 | @items = $self->tree->GetSelections; |
---|
2140 | } |
---|
2141 | |
---|
2142 | # remove root item which is not a valid category |
---|
2143 | @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items; |
---|
2144 | |
---|
2145 | $self->frame->imagelist->categories( |
---|
2146 | [ |
---|
2147 | map { |
---|
2148 | $self->tree->GetPlData( $_ )->{id}; |
---|
2149 | } |
---|
2150 | @items |
---|
2151 | ] |
---|
2152 | ); |
---|
2153 | |
---|
2154 | $self->frame->imagelist->image_selection($VAR1); |
---|
2155 | $self->frame->ProcessImageSelection ; |
---|
2156 | } |
---|
2157 | }; |
---|
2158 | } |
---|
2159 | |
---|
2160 | 1; |
---|