source: extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm @ 5536

Last change on this file since 5536 was 5536, checked in by ronosman, 14 years ago

Feature 1561 added : upload all photos by default.

File size: 57.4 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 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# +-----------------------------------------------------------------------+
20package Uploader::GUI::Frame;
21use strict;
22use Data::Dumper;
23use Carp;
24use Wx;
25use Wx::DND;
26use Wx qw/
27             wxCLIP_CHILDREN
28             wxYES_NO
29             wxYES
30             wxICON_QUESTION
31             wxITEM_NORMAL
32             wxID_OK
33             wxDEFAULT_FRAME_STYLE
34             wxVERTICAL
35             wxGROW
36             wxSHAPED
37             wxBITMAP_TYPE_JPEG
38             wxBITMAP_TYPE_GIF
39             wxBITMAP_TYPE_PNG
40             wxBITMAP_TYPE_ANY
41             wxTB_FLAT
42             wxTB_TEXT
43             wxSIZE
44             wxWHITE
45             wxBLACK
46             wxID_CANCEL
47             wxFD_OPEN
48             wxFD_MULTIPLE
49             wxALL
50             wxGROW
51             wxDefaultPosition
52             wxDefaultSize
53             wxTheApp
54             wxIMAGE_LIST_NORMAL
55             wxNO_BORDER
56             wxTE_MULTILINE
57             wxTE_READONLY
58             wxITEM_NORMAL
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             wxHORIZONTAL
72             wxVERTICAL
73             wxEXPAND
74             wxSWISS
75             wxNORMAL
76             wxBOLD
77             wxALIGN_CENTER
78         /;
79use base qw/Wx::Frame Class::Accessor::Fast/;
80use File::Spec;
81use Wx::Locale qw/:default/;
82use POSIX qw(ceil floor);
83
84require Win32 if($^O =~ /MSWin32/);
85
86
87
88my @properties = 
89    qw/
90          progressdlg
91          upload_progressdlg
92          imageviewer
93          imageviewer_img
94          tree
95          tree_root
96          treeimglist
97          tree_item_default
98          pwg
99          logwnd
100          oldlogwnd
101          categories
102          imagelist
103          image_preview_dlg
104          image_prop_piwigo
105          exif_dlg
106          image_prop_tags
107          global_settings_dlg
108          piwigo_property_list
109          exif_properties
110          global_settings
111          toolbar
112          branding
113          current_imageviewer_index
114          imageviewer_mnu
115          tree_mnu
116          imageviewer_select_multi
117          frameLayout
118          piwigo_tags
119          image_tags
120          piwigo_photo_properties
121          piwigo_photo_properties_dlg
122          piwigo_photo_properties_tags
123          image_preview_need_refresh
124          imageviewer_refresh
125          imageviewer_item_refresh
126          horizontal_splitter
127          destination_category_dlg
128          destination_categories
129          categories_treectrl
130      /;
131__PACKAGE__->mk_accessors( @properties );
132
133use Wx::Perl::TextValidator;
134use Uploader::GUI::wxImageListCtrl;
135use Uploader::GUI::wxPropertyListDlg;
136use Uploader::GUI::wxGlobalSettings;
137use Uploader::GUI::wxImagePreview;
138use Uploader::GUI::wxPhotoProperties;
139use Uploader::GUI::wxImageReuploadDlg;
140use Uploader::GUI::wxImageProcessingProgressDlg;
141use Uploader::GUI::wxDestinationCategoryDlg;
142use Uploader::GUI::wxCategoryTreeCtrl;
143use utf8;
144$|=1;
145
146my $ID_TREE_CTX_MENU = 20000 ;
147my $ID_IMAGEVIEWER_CTX_MENU = 20100 ;
148
149
150sub new {
151    my( $class, $params ) = @_;
152
153    my $self  = $class->SUPER::new( 
154        undef, 
155        -1, 
156        $params->{title},
157        wxDefaultPosition,
158        wxDefaultSize, 
159        wxDEFAULT_FRAME_STYLE
160    );
161
162
163    $self->pwg( $params->{pwg} );
164    $self->imagelist( $params->{imagelist} );
165
166
167    $self->imagelist->pwg(
168        $self->pwg
169    );
170
171    $self->imagelist->categories(
172        []
173    );
174
175
176    $self->init_gui_callbacks;
177    $self->init_properties_dlg_bindings;
178    $self->init_frame;
179    $self->init_menus;
180    $self->init_event_handlers;
181    $self->init_image_types;   
182
183    $self->imageviewer->SelectItem(
184        $self->current_imageviewer_index
185    ) if $self->imageviewer->GetItemCount;
186   
187    # if file in command line parameters, try to load
188    my $files = wxTheApp->argv;
189    $self->SetNewFiles($files) if scalar @$files;
190
191    $self->Show;
192    $self;
193}
194
195
196sub init_gui_callbacks {
197    my ( $self ) = @_;
198
199    # callback for GUI refresh : add thumbnail images to the imageviewer control
200    $self->imagelist->SetNewFilesViewerRefreshCallback(
201        sub { $self->SetNewFilesViewerRefresh(@_) }
202    );
203
204    # callback for GUI refresh : progress dialog display of thumbnail image being created
205    $self->imagelist->SetNewFilesProgressCallback(
206        sub { $self->SetNewFilesProgress(@_) }
207    );
208
209    $self->imagelist->SetNewFilesDisplayEndInfoCallback(
210        sub { $self->SetNewFilesDisplayEndInfo(@_) }
211    );
212
213    # callback for GUI refresh : remove thumbnail images from imageviewer control
214    $self->imagelist->UploadImagesViewerCallback(
215        sub { $self->UploadImagesViewerRefresh(@_) }
216    );
217   
218    $self->imagelist->ReuploadCallback(
219    sub 
220    {
221        Uploader::GUI::wxImageReuploadDlg->new(
222        { 
223            title => gettext("Photo update management"),
224            properties => 
225            {
226                $main::ID_REUPLOAD_ACTION_FILES => 
227                {
228                    selection=>sub {$self->imagelist->reupload_action_files(@_)},
229                    label=>gettext("What shall we do with files? (thumbnail, resized, high resolution)"),
230                    labels=>[
231                        gettext("nothing"),
232                        gettext("replace"),
233                    ],
234                },
235                $main::ID_REUPLOAD_ACTION_PROPERTIES => 
236                { 
237                    selection=>sub{$self->imagelist->reupload_action_properties(@_)},
238                    label=>gettext("What shall we do with single value properties?(caption, comment, author, create date)"),
239                    labels=>[
240                        gettext("nothing"),
241                        gettext("fill if empty (only replace properties currently empty in Piwigo)"),
242                        gettext("replace"),
243                    ],
244                },
245                $main::ID_REUPLOAD_ACTION_PROPERTIES_M =>
246                { 
247                    selection=>sub{$self->imagelist->reupload_action_properties_m(@_)},
248                    label=>gettext("What shall we do with multiple values properties? (categories, tags)"),
249                    labels=>[
250                        gettext("nothing"),
251                        gettext("append (keep existing and add new)"),
252                        gettext("replace"),
253                    ],
254                },
255                $main::ID_REUPLOAD_NOT_ASK => 
256                { 
257                    value=>sub{$self->imagelist->reupload_not_ask(@_)}, 
258                    label=>gettext("Do not ask me again"),
259                },
260                $main::ID_REUPLOAD_TEXT => 
261                { 
262                    label=>gettext("A least one photo has already been added in the past."),
263                },
264            },
265        } )->ShowModal();}
266    );
267
268
269    # callback for GUI refresh : progress dialog display current uploaded image
270    $self->imagelist->progress_thumbnail_refresh(
271        sub { $self->UploadProgressThumbnailRefresh(@_) }
272    );
273
274    $self->imagelist->progress_msg_refresh(
275        sub { $self->UploadProgressMessageRefresh(@_) }
276    );
277
278    $self->imagelist->progress_msg_details_refresh(
279        sub { $self->UploadProgressMessageDetailsRefresh(@_) }
280    );
281
282    $self->imagelist->progressbar_refresh(
283        sub { $self->UploadProgressBarRefresh(@_) }
284    );
285   
286    $self->imagelist->progress_endinfo_refresh(
287        sub { $self->UploadDisplayEndInfo(@_) }
288    );
289}
290
291
292sub init_properties_dlg_bindings {
293    my ( $self ) = @_;
294
295    $self->piwigo_photo_properties(
296        {
297            $main::CAPTION => { label=>gettext("Caption")},
298            $main::PHOTO_PROPERTIES_CAPTION => {
299                multi_selection_mode => sub { $self->multi_selection_mode },
300                string_selection => sub { return 1; },
301                value => sub {
302                    $self->imagelist->SetImageSelectionName(@_);
303                    $self->multi_selection_mode ?
304                    $self->imagelist->image_selection_name :
305                    $self->imagelist->current_image->site_name;
306                },
307                pre_process => sub { sub { $self->imagelist->GetCurrentImageCaption(@_); } },
308                choices =>
309                [
310                    map { gettext $_ } @{wxTheApp->caption_patterns}
311                ],
312                frame_callback => sub { $self->imageviewer_item_refresh(1); },
313            },
314            $main::COMMENT => { label=>gettext("Comment")},
315            $main::PHOTO_PROPERTIES_COMMENT => {
316                value => sub { 
317                    $self->multi_selection_mode ?
318                    $self->imagelist->SetImageSelectionComment(@_):
319                    $self->imagelist->current_image->site_comment(@_) 
320                },
321                frame_callback => sub { $self->imageviewer_item_refresh(1); },
322            },
323            $main::AUTHOR => { label=>gettext("Author")},
324            $main::PHOTO_PROPERTIES_AUTHOR => { 
325                value => sub { 
326                    $self->multi_selection_mode ?
327                    $self->imagelist->SetImageSelectionAuthor(@_):
328                    $self->imagelist->current_image->site_author(@_) 
329                },
330                frame_callback => sub { $self->imageviewer_item_refresh(1); },
331            },
332            $main::TAGS => { label=>gettext("Tags")},
333            $main::CREATE_DATE => { label=>gettext("Create date")},
334            $main::PHOTO_PROPERTIES_CREATE_DATE => { 
335                value => sub { 
336                    $self->multi_selection_mode ?
337                    $self->imagelist->SetImageSelectionCreateDate(@_):
338                    $self->imagelist->current_image->create_date(@_) 
339                },
340                frame_callback => sub { $self->imageviewer_item_refresh(1); },
341            },
342            $main::PRIVACY_LEVEL => { label=>gettext("Who can see?")},
343            $main::PHOTO_PROPERTIES_PRIVACY_LEVEL => {
344                selection => sub {
345                    $self->multi_selection_mode ? 
346                    $self->imagelist->SetImageSelectionPrivacyLevel(@_):
347                    $self->imagelist->current_image->privacy_level(@_)
348                },
349                choices => wxTheApp->privacy_level_choices,
350            },
351            $main::PHOTO_PROPERTIES_NB => {
352                texts => [
353                    gettext("Properties"),
354                    gettext("Tags")
355                ], 
356            },
357            $main::PHOTO_PROPERTIES_UPLOAD => { label=>gettext("Upload to Piwigo") },
358        }
359    );   
360
361    $self->global_settings(
362        {
363            $main::DEFAULT_PHOTO_CAPTION => { label => gettext("Default caption pattern") },
364            $main::CPANE_RESIZE_ADVANCED => { label => gettext("Advanced") },
365            $main::CPANE_HD_ADVANCED => { label => gettext("Advanced") },
366            $main::CPANE_TRANSFERT_ADVANCED => { label => gettext("Advanced") },
367            $main::GS_THUMBNAIL => { label => gettext("Thumbnail") },
368            $main::GS_SITE_IMG => { label => gettext("Web sized") },
369            $main::GS_HD => { label => gettext("High definition") },
370            $main::GS_CLOSE => { label => gettext("Close")},
371            $main::GS_DEFAULT_PHOTO_CAPTION => {
372                string_selection => sub { $self->imagelist->default_caption_pattern(@_) },
373                choices =>
374                [
375                    map { gettext $_ } @{wxTheApp->caption_patterns}
376                ],
377                pre_process => sub { my ( $value ) = @_; wxTheApp->eng_caption_patterns->{$value} },
378                frame_callback => sub { 
379                    my( $self, $ctrl, $event ) = @_; 
380                    $self->OnDefaultPhotoCaption($event);
381                },
382            },
383            $main::PHOTO_CAPTION_PREFIX => { label => gettext("Default caption") },
384            $main::GS_PHOTO_CAPTION_PREFIX => {
385                value => sub { $self->imagelist->default_caption(@_) },
386            },
387            $main::GS_AUTO_ROTATE => {
388                label => gettext("Auto rotate image"),
389                value => sub { $self->imagelist->auto_rotate(@_) }
390           },
391            $main::DEFAULT_AUTHOR => { label => gettext("Default author")},
392            $main::GS_DEFAULT_AUTHOR => { value => sub { $self->imagelist->author(@_) } },
393            $main::THUMBNAIL_SIZE => { label => gettext("Site thumbnail size") },
394            $main::GS_THUMBNAIL_SIZE => {
395                value => sub { $self->imagelist->thumb_size(@_) },
396                validator => Wx::Perl::TextValidator->new( '\d' ) 
397            },
398            $main::THUMBNAIL_JPEG_QUALITY => { label => gettext("Site thumbnail jpeg quality") },
399            $main::GS_THUMBNAIL_JPEG_QUALITY => {
400                value => sub { $self->imagelist->th_quality(@_) },
401                validator => Wx::Perl::TextValidator->new( '\d' ) 
402            },
403            $main::GS_CREATE_RESIZED => {
404                selection => sub { $self->imagelist->create_resized(@_) },
405                choices =>
406                [
407                    map { gettext $_ } ( "Use original", "Use resized original" ) 
408                ],
409                frame_callback => sub { 
410                    my( $dlg, $ctrl, $event ) = @_;
411                    $dlg->OnCreateResized($event);
412                },
413            },
414            $main::SITE_IMG_WIDTH => { label => gettext("Maximum width") },
415            $main::GS_SITE_IMG_WIDTH => {
416                value => sub { $self->imagelist->resize_w(@_) },
417                validator => Wx::Perl::TextValidator->new( '\d' ) 
418            },
419            $main::SITE_IMG_HEIGHT => { label => gettext("Maximum height") },
420            $main::GS_SITE_IMG_HEIGHT => {
421                value => sub { $self->imagelist->resize_h(@_) },
422                validator => Wx::Perl::TextValidator->new( '\d' ) 
423            },
424            $main::SITE_IMG_JPEG_QUALITY => { label => gettext("Site image jpeg quality") },
425            $main::GS_SITE_IMG_JPEG_QUALITY => {
426                value => sub { $self->imagelist->quality(@_) },
427                validator => Wx::Perl::TextValidator->new( '\d' ) 
428            },
429            $main::SITE_IMG_FILTER => { label => gettext("Site image filter") },
430            $main::GS_SITE_IMG_FILTER => {
431                string_selection =>  sub { $self->imagelist->filter(@_) },
432                choices =>
433                [
434                    qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ 
435                ],
436            },
437            $main::SITE_IMG_BLUR => { label => gettext("Site image blur") },
438            $main::GS_SITE_IMG_BLUR => {
439                value => sub { $self->imagelist->blur(@_) },
440                validator => Wx::Perl::TextValidator->new( '\d' ) 
441            },
442            $main::SITE_IMG_INTERLACE => { label => gettext("Site image interlace") },
443            $main::GS_SITE_IMG_INTERLACE => {
444                string_selection => sub { $self->imagelist->interlace(@_) },
445                choices =>
446                [
447                    qw/None Line Plane Partition JPEG GIF PNG/ 
448                ],
449            },
450            $main::GS_REMOVE_UPLOADED_FROM_SELECTION => {
451                label => gettext("Remove uploaded photo from selection"),
452                value => sub { $self->imagelist->remove_uploaded_from_selection(@_) },
453            },
454            $main::GS_HD_UPLOAD => {
455                choices  =>
456                [
457                    map { gettext $_ } @{wxTheApp->upload_hd}
458                ],
459                pre_process => sub { my ( $value ) = @_; wxTheApp->eng_upload_hd->{$value} },
460                string_selection => sub { $self->imagelist->upload_hd(@_) },
461                frame_callback => sub { 
462                    my( $self, $ctrl, $event ) = @_; 
463                    $self->OnHDUpload($event);
464                },
465            },
466            $main::HD_IMG_WIDTH => { label => gettext("Maximum width") },
467            $main::GS_HD_IMG_WIDTH => {
468                label => gettext("HD image width"),
469                value => sub { $self->imagelist->hd_w(@_) },
470                validator => Wx::Perl::TextValidator->new( '\d' ) 
471            },
472            $main::HD_IMG_HEIGHT => { label => gettext("Maximum height") },
473            $main::GS_HD_IMG_HEIGHT => {
474                label => gettext("HD image height"),
475                value => sub { $self->imagelist->hd_h(@_) },
476                validator => Wx::Perl::TextValidator->new( '\d' ) 
477            },
478            $main::HD_IMG_JPEG_QUALITY => { label => gettext("HD image jpeg quality") },
479            $main::GS_HD_IMG_JPEG_QUALITY => {
480                value => sub { $self->imagelist->hd_quality(@_) },
481                validator => Wx::Perl::TextValidator->new( '\d' ) 
482            },
483            $main::HD_IMG_FILTER => { label => gettext("HD image filter") },
484            $main::GS_HD_IMG_FILTER => {
485                string_selection =>  sub { $self->imagelist->hd_filter(@_) },
486                choices =>
487                [
488                    qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ 
489                ],
490            },
491            $main::HD_IMG_BLUR => { label => gettext("HD image blur") },
492            $main::GS_HD_IMG_BLUR => {
493                value => sub { $self->imagelist->hd_blur(@_) },
494                validator => Wx::Perl::TextValidator->new( '\d' ) 
495            },
496            $main::HD_IMG_INTERLACE => { label => gettext("HD image interlace") },
497            $main::GS_HD_IMG_INTERLACE => {
498                string_selection => sub { $self->imagelist->hd_interlace(@_) },
499                choices =>
500                [
501                    qw/None Line Plane Partition JPEG GIF PNG/ 
502                ],
503            },
504            $main::GS_WMARK_ACTIVATE => {
505              label  => gettext("Activate watermark"),
506              value  => sub { $self->imagelist->watermark_activate(@_) },
507              frame_callback => sub { 
508                  my( $self, $ctrl, $event ) = @_; 
509                  $self->OnWatermark($event);
510              },
511            },
512            $main::GS_WMARK_ACTIVATE_HD => {
513              label => gettext("Activate watermark on high definition"),
514              value => sub { $self->imagelist->watermark_activate_pwg_high(@_) },
515              frame_callback => sub { 
516                  my( $self, $ctrl, $event ) = @_; 
517                  $self->OnWatermark($event);
518              },
519            },
520            $main::WMARK_TEXT => { label  => gettext("Text") },
521            $main::GS_WMARK_TEXT => { 
522              value  => sub { $self->imagelist->watermark_text(@_) },
523            },
524            $main::WMARK_TEXT_SIZE => { label     => gettext("Text size") },
525            $main::GS_WMARK_TEXT_SIZE => {
526                value   => sub { $self->imagelist->watermark_text_size(@_) },
527            },
528            $main::WMARK_COLOR => { label     => gettext("Color") },
529            $main::GS_WMARK_COLOR => {
530                string_selection => sub { $self->imagelist->watermark_color(@_) },
531                choices   => [
532                               map { gettext $_ } @{wxTheApp->colors}
533                             ],
534                pre_process => sub { my ( $value ) = @_; wxTheApp->eng_colors->{$value} },
535            },
536            $main::WMARK_POSITION => { label     => gettext("Position") },
537            $main::GS_WMARK_POSITION => {
538                string_selection => sub { $self->imagelist->watermark_position(@_) },
539                choices  => [
540                               map { gettext $_ } @{wxTheApp->positions}
541                           ],
542                pre_process => sub { my ( $value ) = @_; wxTheApp->eng_positions->{$value} },
543            },
544            $main::WMARK_MARGIN_TOP => { label => gettext("Top margin") },
545            $main::GS_WMARK_MARGIN_TOP => {
546                value   => sub { $self->imagelist->watermark_y(@_) },
547            },
548            $main::WMARK_MARGIN_LEFT => { label => gettext("Left margin") },
549            $main::GS_WMARK_MARGIN_LEFT => {
550                value   => sub { $self->imagelist->watermark_x(@_) },
551            },
552            $main::CHUNK_SIZE => { label => gettext("Transfert chunk size") },
553            $main::GS_CHUNK_SIZE => {
554                value   => sub { wxTheApp->chunk_size(@_) },
555            },
556            $main::LANGUAGE => { label => gettext("Choose a language") },
557            $main::GS_LANGUAGE => {
558                selection => sub { wxTheApp->current_language(@_) },
559                choices => [ map { sprintf($_->[0], gettext($_->[2])) } @{wxTheApp->available_languages} ],
560                pre_process => sub { my ( $value ) = @_; wxTheApp->available_languages->[$value][1] },
561                frame_callback => sub { my ( $self, $ctrl, $event ) = @_;
562                    Wx::LogMessage(
563                        sprintf(
564                            "%s : %s", 
565                            gettext("pLoader needs to be restarted to display the new selected language"),
566                            gettext(wxTheApp->available_languages->[$event->GetSelection][2])
567                        )
568                    );
569                    wxTheApp->layout_clean(1);
570                },
571            },
572        }   
573    );
574
575    $self->piwigo_property_list(
576        [
577            {
578                label => gettext("Photo caption"),
579            },
580            {
581                label => gettext("Comment"),
582            },
583            {
584                label => gettext("Author"),
585            },
586            {
587                label => gettext("File name"),
588            },
589            {
590                label => gettext("Create date"),
591            },
592        ]   
593    );
594
595    $self->exif_properties(
596        [
597            {
598                label    => gettext("Create date"),
599                value    => sub { $self->imagelist->current_image->create_date }, 
600                readonly => 1,
601            },   
602            {
603                label    => gettext("Model"),
604                value    => sub { $self->imagelist->current_image->exif_tag('Model') }, 
605                readonly => 1,
606            },   
607            {
608                label    => gettext("Width"),
609                value    => sub { $self->imagelist->current_image->exif_tag('ImageWidth') }, 
610                readonly => 1,
611            },   
612            {
613                label    => gettext("Height"),
614                value    => sub { $self->imagelist->current_image->exif_tag('ImageHeight') }, 
615                readonly => 1,
616            },   
617            {
618                label    => gettext("Orientation"),
619                value    => sub { $self->imagelist->current_image->exif_tag('Orientation') }, 
620                readonly => 1,
621            },   
622            {
623                label    => "ISO",
624                value    => sub { $self->imagelist->current_image->exif_tag('ISO') }, 
625                readonly => 1,
626            },   
627            {
628                label    => gettext("Shutter speed"),
629                value    => sub { $self->imagelist->current_image->exif_tag('ExposureTime') }, 
630                readonly => 1,
631            },   
632            {
633                label    => gettext("Aperture"),
634                value    => sub { $self->imagelist->current_image->exif_tag('ApertureValue') }, 
635                readonly => 1,
636            },   
637            {
638                label    => gettext("Focal length"),
639                value    => sub { $self->imagelist->current_image->exif_tag('FocalLength') }, 
640                readonly => 1,
641            },   
642            {
643                label    => gettext("Lens"),
644                value    => sub { $self->imagelist->current_image->exif_tag('Lens') }, 
645                readonly => 1,
646            },   
647        ]
648    );   
649
650    $self->image_tags(
651        sub { scalar @{$self->imagelist->image_selection} > 1 ? $self->imagelist->SetImageSelectionTags(@_) : $self->imagelist->current_image->site_tags(@_)||[]  }
652    );
653
654    $self->piwigo_tags(
655        sub { wxTheApp->pwg->tags }
656    );   
657}
658
659sub init_image_types {
660    my ( $self ) = @_;
661
662    $self->{IMGTYPE} = {
663        'jpg' => wxBITMAP_TYPE_JPEG,
664        'gif' => wxBITMAP_TYPE_GIF,
665        'png' => wxBITMAP_TYPE_PNG,
666    };
667}
668
669
670sub init_frame {
671    my ( $self ) = @_;
672   
673    $self->create_toolbar;
674
675    my $sizer_h = Wx::BoxSizer->new( wxHORIZONTAL );
676   
677
678
679    $self->imageviewer(
680        Uploader::GUI::wxImageListCtrl->new( 
681            { 
682                parentwnd => $self,
683                imagelist => $self->imagelist,
684                image_size => $self->imagelist->wx_thumb_size,
685                columns => $self->piwigo_property_list,
686            }
687        )
688    );
689
690
691    $self->piwigo_photo_properties_dlg (
692        Uploader::GUI::wxPhotoProperties->new(
693            {
694                parentwnd  => $self,
695                categories => [ @{$self->pwg->categories}],
696                properties => $self->piwigo_photo_properties,
697                tags       =>
698                {
699                    id => $main::PHOTO_PROPERTIES_TAG,
700                    choices => $self->piwigo_tags,
701                    selection => $self->image_tags,
702                    creation_callback => sub { $self->_create_piwigo_tag(@_) },
703               },
704            }
705        )
706    );
707
708    $self->piwigo_photo_properties_tags(
709        $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_TAG)
710    );
711
712    $self->tree(
713        $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_CATEGORIES)
714    );
715
716    $self->init_dnd_targets;
717    $self->init_dialogs;
718    $self->show_hide_pwg_categories_empty_msg;
719
720    if( $self->imagelist->wx_thumb_imglist->GetImageCount){
721        $self->ShowImageViewer;
722       
723        $self->imageviewer->Refresh(
724            $self->imagelist->wx_thumb_imglist
725        );
726       
727        $self->OnUpdateImageviewerNotEmpty;
728    }
729    else{
730        $self->OnUpdateImageviewerEmpty;
731    }
732
733    # the imageviewer has a stretch factor of 1 : expands its size on frame resize
734    $sizer_h->Add( $self->imageviewer, 1, wxEXPAND|wxALL, 2 );
735    $sizer_h->Add( $self->piwigo_photo_properties_dlg, 0, wxEXPAND|wxALL, 2 );
736
737
738    $self->SetSizer(
739        $sizer_h
740    );
741    my $new_size = $sizer_h->Fit(
742        $self
743    );
744    $self->SetMinSize([600, 660]);
745    $self->Center;
746}
747
748
749sub _create_piwigo_tag {
750    my ( $self, $name ) = @_;
751   
752    if(
753        Wx::MessageBox( 
754            sprintf(
755                "%s \"%s\" ?",
756                gettext("Do you want to create"), 
757                $name,
758            ),
759            gettext("Piwigo search information"),
760            wxYES_NO | wxICON_QUESTION, 
761        ) == wxYES
762    ){   
763        $self->pwg->AddTags($name);
764        $self->pwg->RefreshTags;
765    }
766}
767
768
769sub OnUpdateImageviewerEmpty {
770    my ( $self ) = @_;
771
772    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(0);
773    $self->imageviewer->OnEmpty;
774}
775
776sub OnUpdateImageviewerNotEmpty {
777    my ( $self ) = @_;
778
779    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(1);
780    $self->imageviewer->OnNotEmpty;
781}
782
783
784sub init_dialogs {
785    my ( $self ) = @_;   
786
787
788    $self->exif_dlg(
789        Uploader::GUI::wxPropertyListDlg->new( 
790            { 
791                parentwnd       => $self,
792                properties      => $self->exif_properties,
793                caption         => sprintf("%s - EXIF", gettext("Properties")),
794            }
795        )
796    );
797    $self->exif_dlg->Hide;
798
799    $self->global_settings_dlg(
800        Uploader::GUI::wxGlobalSettings->new( 
801            { 
802                parentwnd       => $self,
803                caption         => gettext("Global settings"),
804                properties      => $self->global_settings,
805            }
806        )
807    );
808    $self->global_settings_dlg->Hide;
809
810    $self->image_preview_dlg(
811        Uploader::GUI::wxImagePreview->new(
812            { 
813                parentwnd    => $self,
814                caption      => gettext("Preview"),
815            }
816        )
817    );
818
819    $self->destination_category_dlg(
820        Uploader::GUI::wxDestinationCategoryDlg->new(
821            { 
822                parentwnd    => $self,
823                caption      => gettext("Upload to Piwigo"),
824                categories   => [@{$self->pwg->categories}],
825                properties   => {
826                                    $main::CHOOSE_DESTINATION => { label => wxTheApp->branding->{'What is the destination category?'} },
827                                    $main::DESTINATION_CATEGORIES_OK => { label=>gettext("Upload to Piwigo")},
828                                    $main::DESTINATION_CATEGORIES_CANCEL => { label=>gettext("Cancel")},
829                                    $main::DESTINATION_CATEGORIES => {
830                                        id_selection => sub { $self->imagelist->categories(@_) },
831                                        frame_callback => sub {
832                                            my ( $dlg, $ctrl, $evt ) = @_;
833                                            $dlg->FindWindow($main::DESTINATION_CATEGORIES_OK)->Enable(scalar @{$self->imagelist->categories});
834                                        },
835                                    },
836                                },
837                frame_callback => sub { $self->OnRefreshCategories },
838            }
839        )
840    );
841
842    $self->destination_category_dlg->Hide;
843
844    $self->destination_categories(
845        $self->destination_category_dlg->FindWindow($main::DESTINATION_CATEGORIES)
846    );
847
848    $self->categories_treectrl(
849        [
850            $self->destination_categories,
851            $self->tree,
852        ]
853    );
854
855}
856
857
858sub init_dnd_targets {
859    my ( $self ) = @_;   
860
861    $self->imageviewer->SetDropTarget( 
862        DNDImageListDropTarget->new(
863            $self->imageviewer
864        ) 
865    );
866
867    $self->tree->SetDropTarget( 
868        DNDCategoryTreeDropTarget->new(
869            $self->tree
870        )
871    );
872   
873}
874
875
876sub OnPhotoProperties {
877    my ( $self ) = @_;
878
879    $self->exif_dlg->Show(1);
880}
881
882
883sub OnPreview {
884    my ( $self ) = @_;
885
886    $self->image_preview_dlg->Show(1);
887}
888
889
890sub OnGlobalSettings {
891    my ( $self ) = @_;
892
893    $self->global_settings_dlg->Show(1);
894}
895
896
897sub OnGeneralSettingsClose {
898    my ( $self, $event ) = @_;
899
900    $self->global_settings_dlg->Hide;
901}
902
903
904sub OnImageExifPropClose {
905    my ( $self, $event ) = @_;
906
907    $self->image_exif_prop->Hide;
908}
909
910
911
912
913sub show_hide_pwg_categories_empty_msg {
914    my ( $self ) = @_;
915
916    map {
917        $_->GetCount > 1 ?
918            $_->HideEmptyMsg :
919            $_->ShowEmptyMsg;
920    }@{$self->categories_treectrl};
921
922}
923
924
925sub init_menus {
926    my ( $self ) = @_ ;
927
928    $self->_tree_mnu;
929    $self->_imageviewer_mnu;   
930}
931
932
933sub _tree_mnu {
934    my ( $self ) = @_;   
935
936    my $ctx_mnu = Wx::Menu->new;
937   
938    map {
939        $ctx_mnu->Append(
940            @$_[0..2], wxITEM_NORMAL
941        );
942    }
943    (
944        # workaround : first item does not show bitmap
945        [
946            0, 
947            "",
948            "",
949            wxTheApp->resource_path('mnu_folder_new.png'),
950        ],
951        [
952            1+$ID_TREE_CTX_MENU, 
953            wxTheApp->branding->{'Add new category'},
954            sprintf(
955                "%s %s %s %s", 
956                gettext("Add a new"), 
957                wxTheApp->branding->{category},
958                gettext("to the currently selected"),
959                wxTheApp->branding->{category},
960            ),
961            wxTheApp->resource_path('mnu_folder_new.png'),
962        ],
963        [
964            2+$ID_TREE_CTX_MENU, 
965            gettext("Refresh"),
966            sprintf(
967                "Refresh %s list.",
968                wxTheApp->branding->{category},
969            ),
970            wxTheApp->resource_path('mnu_refresh.png'),
971        ],
972        [
973            3+$ID_TREE_CTX_MENU, 
974            gettext("Expand all"),
975            sprintf(
976                "Expand %s list.",
977                wxTheApp->branding->{category},
978            ),
979            wxTheApp->resource_path('mnu_expandall.png'),
980        ],
981        [
982            4+$ID_TREE_CTX_MENU, 
983            gettext("Collapse all"),
984            sprintf(
985                "Collapse %s list.",
986                wxTheApp->branding->{category},
987            ),
988            wxTheApp->resource_path('mnu_collapseall.png'),
989        ],
990    );
991
992    $ctx_mnu->Delete(0);
993    $self->tree_mnu(
994         $ctx_mnu
995    );   
996}   
997
998sub _imageviewer_mnu {
999    my ( $self ) = @_;   
1000
1001    my $ctx_mnu = Wx::Menu->new;
1002   
1003    map {
1004        $ctx_mnu->Append(
1005            @$_[0..2]
1006        );
1007    }
1008    (
1009        # workaround : first item does not show bitmap
1010        [
1011            0, 
1012            "",
1013            "",
1014            wxTheApp->resource_path('mnu_properties.png'),
1015        ],
1016        [
1017            1+$ID_IMAGEVIEWER_CTX_MENU, 
1018            gettext("Properties"),
1019            gettext("Modify photo properties"),
1020            wxTheApp->resource_path('mnu_properties.png'),
1021        ],
1022        [
1023            2+$ID_IMAGEVIEWER_CTX_MENU, 
1024            gettext("Preview"),
1025            gettext("Display photo preview"),
1026            wxTheApp->resource_path('mnu_preview.png'),
1027        ],
1028    );
1029   
1030    $ctx_mnu->Delete(0);
1031    $self->imageviewer_mnu(
1032         $ctx_mnu
1033    );   
1034}
1035
1036sub init_event_handlers {
1037    my ( $self ) = @_ ;
1038   
1039    Wx::Event::EVT_MENU( $self, 101, \&OnAddImages );
1040    Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages );
1041    Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages );
1042    Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings );
1043    Wx::Event::EVT_CHOICE( $self, 106, \&OnPhotoSelMode );
1044    Wx::Event::EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged );
1045    Wx::Event::EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick );
1046    Wx::Event::EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&OnTreeEndLabelEdit );
1047
1048    Wx::Event::EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit );
1049    Wx::Event::EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated );
1050    Wx::Event::EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ;
1051    Wx::Event::EVT_LIST_ITEM_DESELECTED($self, $self->imageviewer, \&OnImageViewerItemDeSelected) ;
1052    Wx::Event::EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ;
1053
1054    Wx::Event::EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ;
1055
1056    Wx::Event::EVT_CLOSE( $self, \&OnClose );
1057
1058    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategory );
1059    Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories );
1060    Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories );
1061    Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&OnCollapseCategories );
1062
1063    Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties );
1064    Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview );
1065
1066    Wx::Event::EVT_BUTTON( $self, $main::PHOTO_PROPERTIES_UPLOAD, \&OnUploadImages );
1067    Wx::Event::EVT_BUTTON( $self, $self->imageviewer->add_button->GetId, \&OnAddImages );
1068    Wx::Event::EVT_KEY_DOWN($self, \&OnKeyDown );
1069
1070    # only refresh when calling event is finished
1071    Wx::Event::EVT_IDLE(
1072        $self,
1073        sub {
1074            my ( $self, $event ) = @_;
1075
1076            if ( $self->image_preview_need_refresh and $self->image_preview_dlg->IsShown ){
1077                $self->set_preview_image; 
1078                $self->image_preview_dlg->Refresh;
1079                $self->image_preview_need_refresh(0);
1080            }
1081
1082            if($self->imageviewer_refresh){
1083                $self->imageviewer->Refresh;
1084                $self->imageviewer_refresh(0);
1085            }
1086
1087            if($self->imageviewer_item_refresh){
1088                # for batch mode
1089                map {
1090                    $self->imageviewer->ItemRefresh(
1091                        $_
1092                    )
1093                } @{$self->imageviewer->GetSelectedItems};
1094                $self->imageviewer_item_refresh(0);
1095            }
1096
1097            if(!scalar @{$self->imageviewer->GetSelectedItems} and $self->piwigo_photo_properties_dlg->{_properties_notebook}->IsEnabled){
1098                $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(0);
1099            }
1100
1101            $self->OnUpdateToolbar;
1102            $event->Skip;
1103        }
1104    );
1105
1106}
1107
1108{
1109  my $prevdir;
1110  my $prevfile;
1111
1112  sub OnAddImages {
1113    my( $self, $event ) = @_;
1114    my $dialog = Wx::FileDialog->new
1115      ( $self, gettext("Select photos for upload"), $prevfile, $prevdir,
1116        sprintf("%s (*.JPG)|*.JPG|(*.jpg)|*.jpg|All(*.*)|*.*", gettext("JPEG files")),
1117        wxFD_OPEN|wxFD_MULTIPLE );
1118
1119    my $file_paths = [];
1120    if( $dialog->ShowModal != wxID_CANCEL ) {
1121        @$file_paths = $dialog->GetPaths;
1122        $self->SetNewFiles($file_paths) ;
1123    }
1124    $dialog->Destroy;
1125  }
1126}
1127
1128
1129sub OnUpdateToolbar {
1130    my( $self ) = @_;
1131   
1132    if($self->global_settings_dlg->IsShown){
1133        $self->toolbar->EnableTool(104, 0);
1134    }
1135    else{   
1136        $self->toolbar->EnableTool(104, 1);
1137    }
1138
1139    if($self->global_settings_dlg->IsShown){
1140        $self->toolbar->EnableTool(104, 0);
1141    }
1142    else{   
1143        $self->toolbar->EnableTool(104, 1);
1144    }
1145
1146}
1147
1148
1149sub OnRemoveImages {
1150    my( $self, $event ) = @_;
1151
1152   
1153    $self->imagelist->RemoveImageSelection;
1154    $self->imageviewer->Refresh;   
1155
1156    if (!$self->imageviewer->GetItemCount){
1157        $self->image_preview_dlg->image(
1158            0
1159        ); 
1160        # have to reset
1161        $self->piwigo_photo_properties_dlg->ClearProperties;
1162        $self->piwigo_photo_properties_tags->ClearAllSelection;
1163        $self->imagelist->SetCurrentImage(-1);
1164        $self->OnUpdateImageviewerEmpty;
1165    }
1166    else{
1167        $self->OnUpdateImageviewerNotEmpty;
1168    }
1169
1170    if(!$self->multi_selection_mode){
1171        $self->OnUpdateSingleSelectionModeUI;
1172    }
1173
1174    $self->image_preview_dlg->Refresh;
1175    $self->exif_dlg->Refresh;
1176}
1177
1178sub SetNewFiles {
1179    my ( $self, $file_paths ) = @_;
1180
1181    $self->ShowImageViewer();
1182   
1183    $self->progressdlg->Destroy if defined $self->progressdlg;
1184    $self->progressdlg( 
1185        Uploader::GUI::wxImageProcessingProgressDlg->new(
1186            { 
1187                title => gettext("Image processing progress information"),
1188                bt_label => gettext("Cancel image processing"), 
1189                bt_close_label => gettext("Close"),
1190                stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); },
1191             }
1192        )       
1193    );
1194    $self->progressdlg->Show(1);
1195    Wx::Yield();
1196
1197   
1198    my $files = [
1199        map {
1200            # to make sure that unicode chars in filenames are supported
1201            {
1202                ANSIPathName => $^O =~ /MSWin32/ ? Win32::GetANSIPathName($_) : $_,
1203                PathName => $_,
1204            },
1205        }@$file_paths   
1206    ];
1207
1208    @$files = sort { $a->{PathName} cmp $b->{PathName} } @$files;   
1209
1210    $self->imagelist->SetNewFiles(
1211        $files
1212    );
1213
1214   
1215}
1216
1217
1218sub OnTreeSelChanged {
1219    my( $self, $event ) = @_;
1220
1221    $self->imagelist->categories(
1222        $event->GetEventObject->GetSelectionsIds
1223    );
1224}
1225
1226sub OnTreeItemRightClick {
1227    my( $self, $event ) = @_;
1228
1229
1230    $self->PopupMenu($self->tree_mnu, wxDefaultPosition);
1231   
1232}
1233
1234sub OnTreeEndLabelEdit {
1235    my( $self, $event ) = @_;
1236
1237    my $label = $event->GetLabel;
1238   
1239    $label =~ s/^\s+$//;
1240
1241    if(defined($label) and !( "" eq $label )){
1242        $self->_SetLabel($event)
1243    }
1244    else{
1245        $event->Veto;
1246    }
1247}
1248
1249sub _SetLabel {
1250    my( $self, $event ) = @_;
1251   
1252    my $category = $self->tree->GetPlData($event->GetItem);
1253    my $category_id;
1254   
1255    $category_id = $category->{id} if 'HASH' eq ref($category) ;
1256    my $comment;
1257    my ( $success, $status_msg, $content ) = $self->pwg->SetInfoCategories( 
1258        $event->GetLabel, 
1259        $comment, 
1260        $category_id
1261    );
1262
1263    my $ok = 1;
1264   
1265    if(!$success){
1266        $ok = 0;
1267    }
1268
1269    if('fail' eq $content->{stat}){
1270        $ok = 0;
1271    }
1272
1273    # method call failed
1274    if(!$ok){
1275        $event->Veto;
1276        Wx::MessageBox( 
1277            sprintf(
1278                "%s %s", 
1279                gettext("Update failed : "),
1280                $status_msg
1281            ),
1282            gettext("Piwigo update error"),
1283            wxOK | wxICON_EXCLAMATION, 
1284        );
1285        Wx::LogMessage("%s\n\n%s", Dumper($content), gettext("This function is not available. A Piwigo upgrade may resolve this issue."));
1286    }
1287}
1288
1289sub OnImageViewerItemRightClick {
1290    my( $self, $event ) = @_;
1291
1292   
1293    $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition);
1294   
1295   
1296}
1297
1298sub OnExpandCategories {
1299    my ( $self, $event ) = @_;
1300
1301    my $parent_item = $self->tree->GetSelection;
1302    $self->tree->ExpandAllChildren($parent_item);
1303    $self->tree->EnsureVisible($parent_item);
1304}
1305
1306sub OnCollapseCategories {
1307    my ( $self, $event ) = @_;
1308
1309    my $parent_item = $self->tree->GetSelection;
1310    $self->tree->CollapseAllChildren($parent_item);
1311    $self->tree->Expand($parent_item) if -1 == $self->tree->GetPlData($parent_item);
1312}
1313
1314sub OnAddCategory {
1315    my ( $self, $event ) = @_;
1316
1317    $self->tree->AddCategory;
1318
1319}
1320
1321
1322sub OnRefreshCategories {
1323    my ( $self, $event ) = @_;
1324
1325    $self->_refresh_all_categories_helper;
1326}
1327
1328
1329sub _refresh_all_categories_helper {
1330    my ( $self ) = @_;
1331
1332    my $busycursor = Wx::BusyCursor->new();
1333    $self->tree->CollapseAll;
1334    $self->tree->DeleteAllItems;
1335    $self->pwg->RefreshCategories();
1336    $self->tree->categories(
1337        $self->pwg->categories
1338    );
1339    $self->tree->Populate;
1340    $self->show_hide_pwg_categories_empty_msg;
1341}
1342
1343
1344sub OnImageViewerEndLabelEdit {
1345    my( $self, $event ) = @_;
1346 
1347    my $image = $self->imagelist->GetImage($event->GetIndex);
1348    $image->site_name(
1349        $event->GetLabel
1350    );
1351       
1352    $self->piwigo_photo_properties_dlg->SetProperties;
1353}
1354
1355sub OnImageViewerItemActivated {
1356    my( $self, $event ) = @_;
1357   
1358    $self->current_imageviewer_index(
1359        $event->GetIndex
1360    );
1361
1362    $self->OnPhotoProperties;
1363}
1364
1365
1366sub OnImageViewerItemSelected {
1367    my( $self, $event ) = @_;
1368
1369    my $bc = Wx::BusyCursor->new;
1370    my $indx = $event->GetIndex;
1371
1372    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(1) 
1373        if !$self->piwigo_photo_properties_dlg->{_properties_notebook}->IsEnabled;
1374    $self->_on_imageviewer_item_selected($indx);
1375
1376    $event->Skip;
1377
1378}
1379
1380sub OnImageViewerItemDeSelected {
1381    my( $self, $event ) = @_;
1382
1383    my $bc = Wx::BusyCursor->new;
1384    $self->_on_imageviewer_item_selection_changed;
1385
1386    $event->Skip;
1387
1388}
1389
1390sub _on_imageviewer_item_selected {
1391    my ( $self, $index ) = @_;   
1392    $self->current_imageviewer_index($index);
1393    $self->imagelist->SetCurrentImage($index);
1394   
1395    $self->_on_imageviewer_item_selection_changed;
1396}
1397
1398sub _on_imageviewer_item_selection_changed {
1399    my ( $self ) = @_;   
1400
1401    $self->imagelist->image_selection(
1402        $self->imageviewer->GetSelectedItems
1403    );
1404
1405    # for batch mode : reset the batch buffer if single selection
1406    if($self->multi_selection_mode){
1407        $self->OnUpdateMultiSelectionModeUI;
1408        $self->imagelist->SetImageSelectionTags([]);
1409        $self->imagelist->image_selection_privacy_level(-1);
1410        $self->imagelist->image_selection_name("");
1411        $self->imagelist->image_selection_author("");
1412        $self->imagelist->image_selection_comment("");
1413        $self->imagelist->image_selection_create_date(-1);
1414    }
1415    else{
1416        $self->OnUpdateSingleSelectionModeUI;
1417    }
1418    # process image_preview in idle time
1419    # and when current event is processed
1420    # see call to EVT_IDLE
1421    $self->image_preview_need_refresh(1);
1422
1423    $self->piwigo_photo_properties_dlg->SetProperties if defined $self->piwigo_photo_properties_dlg;
1424    $self->exif_dlg->Refresh;
1425    $self->piwigo_photo_properties_tags->RefreshChoices;
1426
1427}
1428
1429sub multi_selection_mode {
1430    my ( $self ) = @_;
1431
1432    scalar @{$self->imagelist->image_selection} > 1;
1433}
1434
1435sub OnUpdateMultiSelectionModeUI{
1436    my( $self ) = @_;
1437
1438
1439    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}{_text1}->SetLabel(
1440        sprintf(gettext("You have selected a batch of %s photos"), $self->imageviewer->GetSelectectItemsCount )
1441    );
1442
1443    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}{_text2}->SetLabel(
1444        gettext("Changes apply to the whole batch")
1445    );
1446
1447    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}->Show(1);
1448    $self->piwigo_photo_properties_dlg->Layout;
1449}
1450
1451sub OnUpdateSingleSelectionModeUI{
1452    my( $self ) = @_;
1453
1454    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}->Show(0);
1455    $self->piwigo_photo_properties_dlg->Layout;
1456
1457}
1458
1459
1460sub set_preview_image {
1461    my ( $self ) = @_;   
1462
1463    my $current_image = $self->imagelist->current_image;
1464    my $image = Wx::Image->new;
1465    $image->LoadFile(
1466        $current_image->file, 
1467        wxBITMAP_TYPE_ANY
1468    );
1469 
1470    if($self->imagelist->auto_rotate){
1471        # exif from original image
1472        my $orientation = $current_image->exif_metadata->{Orientation};
1473
1474        # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
1475        if( $orientation =~ m/Rotate (\d+)/ ){
1476            for(my $i=0; $i < floor($1/90) ; $i++){
1477                $image = $image->Rotate90;
1478            }               
1479        }
1480    }
1481
1482    $self->image_preview_dlg->image_size(
1483        [$image->GetWidth, $image->GetHeight, ]
1484    );       
1485
1486    $self->image_preview_dlg->image(
1487        $image
1488    );       
1489}
1490
1491sub OnImageViewerKeyDown {
1492    my( $self, $event ) = @_;
1493
1494    if(WXK_DELETE == $event->GetKeyCode){
1495        $self->OnRemoveImages();
1496       
1497        my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ?
1498            $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ;
1499        $self->imageviewer->SelectItem(
1500            $index
1501        );
1502        $self->imageviewer->EnsureVisible(
1503            $index
1504        );
1505    }   
1506
1507}
1508
1509
1510sub OnUploadImages {
1511    my( $self, $event ) = @_;
1512
1513    my $select_all = 1;
1514    eval {
1515        $self->ProcessImageSelection( $select_all );   
1516    };
1517}
1518
1519# remove image from imagelist when uploaded
1520sub UploadImagesViewerRefresh {
1521    my ( $self ) = @_;   
1522
1523
1524    $self->imageviewer->Refresh;
1525
1526    if(!$self->imageviewer->GetItemCount){
1527        $self->image_preview_dlg->image(0);
1528        $self->OnUpdateImageviewerEmpty;
1529    }
1530    # reset previous selection
1531    $self->imagelist->image_selection(
1532        []
1533    );
1534
1535    if(!$self->multi_selection_mode){
1536        $self->OnUpdateSingleSelectionModeUI;
1537    }
1538
1539    $self->image_preview_dlg->Refresh;
1540    Wx::Yield();
1541}
1542
1543sub UploadProgressMessageRefresh {
1544    my ( $self, $msg ) = @_;   
1545
1546    Wx::Yield();
1547
1548    $self->upload_progressdlg->processing(
1549        $msg   
1550    );   
1551    $self->upload_progressdlg->LogProgress();
1552
1553    Wx::Yield();
1554}
1555
1556sub UploadProgressMessageDetailsRefresh {
1557    my ( $self, $msg ) = @_;   
1558
1559    Wx::Yield();
1560
1561    $self->upload_progressdlg->processing_details(
1562        $msg   
1563    );   
1564    $self->upload_progressdlg->LogProgress();
1565
1566    Wx::Yield();
1567}
1568
1569
1570sub UploadProgressThumbnailRefresh {
1571    my ( $self ) = @_;   
1572
1573    my $imagelist = $self->imagelist ;
1574
1575 
1576    $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
1577    $self->upload_progressdlg->image->SetBitmap(
1578        Wx::Bitmap->new( 
1579            $self->imagelist->current_image->wx_thumb_file, 
1580            $self->GetWxBitmapType($self->imagelist->type), 
1581        )
1582    );
1583
1584    Wx::Yield();
1585}
1586
1587sub UploadProgressBarRefresh {
1588    my ( $self, $value ) = @_;   
1589
1590    eval {
1591        $self->upload_progressdlg->progress(
1592            $value
1593        );
1594        $self->upload_progressdlg->LogProgress();
1595    };
1596    #croak gettext("Upload cancelled") if $@;
1597
1598    Wx::Yield();
1599}
1600
1601sub SetNewFilesDisplayEndInfo {
1602    my ( $self, $msg, $errors ) = @_;   
1603   
1604    if($errors){
1605        $self->progressdlg->DisplayEndInfo($msg);
1606    }
1607    else{
1608        $self->progressdlg->Show(0);
1609    }
1610}
1611
1612sub UploadDisplayEndInfo {
1613    my ( $self, $msg ) = @_;   
1614   
1615    my $imagelist = $self->imagelist ;
1616   
1617    $self->upload_progressdlg->DisplayEndInfo($msg);
1618}
1619
1620sub ShowImageViewer {
1621    my ( $self ) = @_;   
1622
1623    if(!$self->imageviewer->IsShown){
1624        $self->imageviewer->Show(1);
1625    }
1626}
1627
1628
1629sub SetNewFilesViewerRefresh {
1630
1631    my ( $self ) = @_;   
1632
1633    my $wximagelist = $self->imagelist->wx_thumb_imglist;
1634    #print Dumper "SetNewFilesViewerRefresh", $self->imagelist->current_image;
1635    my $indx = $wximagelist->Add(
1636        Wx::Bitmap->new( 
1637            $self->imagelist->current_image->wx_thumb_file, 
1638            $self->GetWxBitmapType($self->imagelist->type), 
1639        )
1640    ) if defined $self->imagelist->current_image->wx_thumb_file;
1641    #print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n";   
1642   
1643    $self->imageviewer->Refresh(
1644        $wximagelist
1645    );
1646
1647    $self->OnUpdateImageviewerNotEmpty if $self->imageviewer->GetItemCount;
1648
1649    Wx::Yield();
1650}
1651
1652
1653sub GetWxBitmapType {
1654    my ( $self, $type ) = @_;
1655   
1656    $self->{IMGTYPE}->{$type};
1657}
1658
1659
1660# prepare and upload image_selection
1661sub ProcessImageSelection {
1662    my ( $self, $select_all ) = @_;
1663
1664    return if !scalar @{$self->imagelist->sums};
1665
1666    if( $self->destination_categories_are_empty ){
1667        return unless $self->destination_category_dlg->ShowModal != wxID_CANCEL;
1668    }
1669
1670    $self->imagelist->image_selection(
1671        $self->imageviewer->GetAllItems
1672    ) if $select_all;
1673       
1674    return if( !defined $self->imagelist->image_selection );
1675    return if( !scalar @{$self->imagelist->image_selection} );
1676       
1677    $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg;
1678    $self->upload_progressdlg(
1679        Uploader::GUI::wxImageProcessingProgressDlg->new(
1680            { 
1681                title    => gettext("Image upload progress information"),
1682                bt_label => gettext("Cancel upload"),
1683                bt_close_label => gettext("Close"), 
1684                stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); }, 
1685            }
1686        )
1687    );
1688
1689    # modeless dialog
1690    $self->upload_progressdlg->Show(1);
1691    Wx::Yield();
1692    eval {
1693        $self->imagelist->UploadSelection;
1694    };
1695    if($@){
1696        Wx::MessageBox( 
1697            sprintf(
1698                gettext("Upload cancelled"),
1699            ),
1700            gettext("Piwigo upload information"),
1701            wxOK | wxICON_INFORMATION, 
1702        );
1703    }
1704}
1705
1706
1707sub destination_categories_are_empty {
1708    my ( $self ) = @_;
1709
1710    !scalar @{$self->imagelist->categories};
1711}
1712
1713
1714sub SetNewFilesProgress {
1715    my ( $self ) = @_;
1716
1717    my $imagelist = $self->imagelist;
1718
1719    $self->progressdlg->processing(
1720        sprintf(
1721            $imagelist->progress_msg, 
1722            $imagelist->current_image->file,
1723        )
1724    );
1725
1726    eval {
1727        $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]);
1728        $self->progressdlg->image->SetBitmap(wxNullBitmap);
1729        $self->progressdlg->image->SetBitmap(
1730            Wx::Bitmap->new( 
1731                $imagelist->current_image->wx_thumb_file,
1732                $self->GetWxBitmapType( $imagelist->type )
1733            )
1734        );
1735        $self->progressdlg->progress(
1736            $imagelist->count * ( 100/scalar @{$imagelist->new_files} )
1737        );
1738        $self->progressdlg->LogProgress();
1739    };
1740    Wx::Yield();
1741}
1742
1743sub OnClose {
1744  my $self = shift;
1745
1746
1747    # Restaure previous log wnd
1748    Wx::Log::SetActiveTarget( $self->oldlogwnd );
1749
1750    # allways store
1751 
1752    wxTheApp->StoreConnectionProperties;
1753   
1754    $self->imagelist->Store;
1755    wxTheApp->login_dlg->Destroy;   
1756
1757   
1758    wxTheApp->imageviewerIndex(
1759        $self->current_imageviewer_index
1760    );
1761   
1762    my $frameLayout = {};
1763   
1764    ( $frameLayout->{pX}, $frameLayout->{pY}, $frameLayout->{W}, $frameLayout->{H} ) = ( $self->GetPositionXY, $self->GetSizeWH ) ; 
1765   
1766    wxTheApp->frameLayout(
1767        $frameLayout
1768    );
1769
1770    wxTheApp->StoreLayoutProperties;
1771
1772    #destroy hidden dialogs
1773    $self->global_settings_dlg->Destroy;
1774    $self->image_preview_dlg->Destroy;
1775    $self->exif_dlg->Destroy;
1776    $self->destination_category_dlg->Destroy;
1777
1778    $self->progressdlg->Destroy if defined $self->progressdlg;
1779    $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg;
1780
1781    $self->Destroy;
1782}
1783
1784
1785sub create_toolbar {
1786    my( $self ) = @_;
1787
1788    my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, [600, -1], wxTB_FLAT|wxTB_TEXT );
1789    $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) );
1790    map {
1791        my $icon1 = Wx::Icon->new();
1792        eval {
1793            $icon1->LoadFile($_->[2], $_->[3]);
1794        };
1795        my $tb_icon1 = Wx::Bitmap->new( $icon1 );
1796
1797        my $icon2 = Wx::Icon->new();
1798        eval {
1799            $icon2->LoadFile($_->[5], $_->[3]);
1800        };
1801        my $tb_icon2 = Wx::Bitmap->new( $icon2 );
1802
1803
1804        $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[6] );
1805        $tb->EnableTool( $_->[0], $_->[4]);
1806    }
1807    (
1808        [
1809            101, 
1810            gettext("Add photos"), 
1811            wxTheApp->resource_path('tb_add.png'), 
1812            wxBITMAP_TYPE_PNG, 
1813            1, 
1814            wxTheApp->resource_path('tb_add.png'), 
1815            gettext("Add photos for resizing and uploading")
1816        ],
1817        [
1818            102, 
1819            gettext("Remove selected photos"), 
1820            wxTheApp->resource_path('tb_remove.png'), 
1821            wxBITMAP_TYPE_PNG, 
1822            1, 
1823            wxTheApp->resource_path('tb_remove.png'),
1824            gettext("Remove selected photos. Original files are not deleted ")
1825        ],
1826        [
1827            104, 
1828            gettext("Preferences"), 
1829            wxTheApp->resource_path('tb_settings.png'), 
1830            wxBITMAP_TYPE_PNG, 
1831            0, 
1832            wxTheApp->resource_path('tb_settings.png'),
1833            gettext("Change global settings.")
1834        ],
1835   
1836    );
1837   
1838    $tb->AddSeparator;
1839   
1840    $tb->AddControl(
1841        Wx::Choice->new(
1842        $tb,
1843            106,
1844            wxDefaultPosition,
1845            [300, -1],
1846            [],
1847        )
1848    );
1849    my $ch = $tb->FindWindow(106);
1850    $ch->SetToolTip(gettext("How photo selection is displayed"));
1851    map {
1852        $ch->Append(gettext($_), $_);
1853    }(
1854        "Thumbnail and caption",
1855        "Thumbnail",
1856        "Property list"
1857    );
1858   
1859    $ch->SetStringSelection(gettext($self->imagelist->display_mode));
1860    $tb->Realize;
1861
1862    $self->toolbar(
1863        $tb
1864    );
1865    $self->SetToolBar($tb);
1866
1867    return $tb;
1868}
1869
1870sub OnPhotoSelMode {
1871    my ( $self, $event )= @_;
1872   
1873    $self->imagelist->display_mode(
1874        $event->GetClientData
1875    );
1876
1877    $self->imageviewer->change_display_mode(1);
1878}
1879
1880sub _create_textctrl {
1881    my( $self, $parent, $text, $size ) = @_;
1882
1883    return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size,
1884                              wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY  );
1885}
1886
1887sub create_textctrl {
1888    my( $self, $text, $size ) = @_;
1889
1890    return $self->_create_textctrl( $self, $text, $size );
1891}
1892
1893sub DESTROY {
1894    my( $self ) = @_;
1895
1896}
1897
1898
1899
19001;
1901
1902
1903
1904
1905
1906package DNDImageListDropTarget;
1907use Wx qw/wxTheApp/;
1908use base qw(Wx::FileDropTarget Class::Accessor::Fast);
1909
1910__PACKAGE__->mk_accessors( 
1911    qw/
1912          imageviewer
1913      /
1914);
1915
1916sub new {
1917  my $class = shift;
1918  my $imageviewer = shift;
1919  my $self = $class->SUPER::new( @_ );
1920
1921  $self->imageviewer($imageviewer);
1922
1923  return $self;
1924}
1925
1926sub OnDropFiles {
1927  my( $self, $x, $y, $files ) = @_;
1928
1929  wxTheApp->frame->SetNewFiles($files) ;
1930}
1931
1932
1933
1934
19351;
1936
1937
1938package DNDCategoryTreeDropTarget;
1939
1940use base qw(Wx::TextDropTarget Class::Accessor::Fast);
1941use Data::Dumper;
1942use Wx qw/
1943              wxDragNone
1944              wxDragCopy
1945              wxDragMove
1946              wxTheApp
1947         /;
1948
1949__PACKAGE__->mk_accessors( 
1950    qw/
1951          tree
1952      /
1953);
1954
1955sub new {
1956  my ( $class, $tree ) = @_;
1957  my $self = $class->SUPER::new();
1958
1959  $self->tree($tree);
1960
1961  return $self;
1962}
1963
1964
1965
1966sub OnDropText {
1967  my( $self, $x, $y, $textdata ) = @_;
1968
1969  # must be $VAR1 because $textdata is the result of Data::Dumper
1970  my $VAR1;
1971  eval $textdata;
1972  eval {
1973      if(scalar @$VAR1){
1974             my @items;
1975             if(scalar @items < 2) {
1976               my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]);
1977                 push @items, $dropItem;
1978             }
1979             else {
1980                 @items = $self->tree->GetSelections;
1981             }
1982             
1983             # remove root item which is not a valid category
1984             @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items;
1985             
1986             wxTheApp->frame->imagelist->categories(
1987                 [
1988                     map {
1989                         $self->tree->GetPlData( $_ )->{id};
1990                     }
1991                     @items
1992                 ]
1993             );
1994           
1995             wxTheApp->frame->imagelist->image_selection($VAR1);
1996             wxTheApp->frame->ProcessImageSelection ;
1997      }   
1998  };
1999}
2000
2001
20021;
Note: See TracBrowser for help on using the repository browser.