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

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

merge back r4321, sorry for the mistake

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