source: extensions/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm @ 4152

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

Bug 1219 fixed : property values must be language independant.

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