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

Last change on this file since 3374 was 3374, checked in by ronosman, 15 years ago

Feature 1019 added : limit preview refresh to single selection.

  • Property svn:eol-style set to LF
File size: 56.5 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             wxITEM_NORMAL
27             wxNullBitmap
28             wxID_OK
29             wxDEFAULT_FRAME_STYLE
30             wxVERTICAL
31             wxGROW
32             wxBITMAP_TYPE_JPEG
33             wxBITMAP_TYPE_GIF
34             wxBITMAP_TYPE_PNG
35             wxTB_FLAT
36             wxSIZE
37             wxWHITE
38             wxBLACK
39             wxID_CANCEL
40             wxFD_OPEN
41             wxFD_MULTIPLE
42             wxLI_HORIZONTAL
43             wxALIGN_CENTER_VERTICAL
44             wxALL
45             wxDefaultPosition
46             wxDefaultSize
47             wxTheApp
48             wxIMAGE_LIST_NORMAL
49             wxAUI_NB_TAB_MOVE
50             wxAUI_NB_TAB_SPLIT
51             wxNO_BORDER
52             wxTE_MULTILINE
53             wxTE_READONLY
54             wxITEM_NORMAL
55             wxCLIP_CHILDREN
56             wxBORDER_NONE
57             wxNullBitmap
58             wxTR_MULTIPLE
59             wxTR_EXTENDED
60             wxTR_HIDE_ROOT
61             wxTR_HAS_BUTTONS
62             wxMAXIMIZE
63             wxOK
64             wxICON_EXCLAMATION
65             wxICON_INFORMATION
66             WXK_DELETE
67             wxLANGUAGE_ABKHAZIAN   
68             wxLANGUAGE_AFAR   
69             wxLANGUAGE_AFRIKAANS   
70             wxLANGUAGE_ALBANIAN   
71             wxLANGUAGE_AMHARIC   
72             wxLANGUAGE_ARABIC   
73             wxLANGUAGE_ARABIC_ALGERIA   
74             wxLANGUAGE_ARABIC_BAHRAIN   
75             wxLANGUAGE_ARABIC_EGYPT   
76             wxLANGUAGE_ARABIC_IRAQ   
77             wxLANGUAGE_ARABIC_JORDAN   
78             wxLANGUAGE_ARABIC_KUWAIT   
79             wxLANGUAGE_ARABIC_LEBANON   
80             wxLANGUAGE_ARABIC_LIBYA   
81             wxLANGUAGE_ARABIC_MOROCCO   
82             wxLANGUAGE_ARABIC_OMAN   
83             wxLANGUAGE_ARABIC_QATAR   
84             wxLANGUAGE_ARABIC_SAUDI_ARABIA   
85             wxLANGUAGE_ARABIC_SUDAN   
86             wxLANGUAGE_ARABIC_SYRIA   
87             wxLANGUAGE_ARABIC_TUNISIA   
88             wxLANGUAGE_ARABIC_UAE   
89             wxLANGUAGE_ARABIC_YEMEN   
90             wxLANGUAGE_ARMENIAN   
91             wxLANGUAGE_ASSAMESE   
92             wxLANGUAGE_AYMARA   
93             wxLANGUAGE_AZERI   
94             wxLANGUAGE_AZERI_CYRILLIC   
95             wxLANGUAGE_AZERI_LATIN   
96             wxLANGUAGE_BASHKIR   
97             wxLANGUAGE_BASQUE   
98             wxLANGUAGE_BELARUSIAN   
99             wxLANGUAGE_BENGALI   
100             wxLANGUAGE_BHUTANI   
101             wxLANGUAGE_BIHARI   
102             wxLANGUAGE_BISLAMA   
103             wxLANGUAGE_BRETON   
104             wxLANGUAGE_BULGARIAN   
105             wxLANGUAGE_BURMESE   
106             wxLANGUAGE_CAMBODIAN   
107             wxLANGUAGE_CATALAN   
108             wxLANGUAGE_CHINESE   
109             wxLANGUAGE_CHINESE_SIMPLIFIED   
110             wxLANGUAGE_CHINESE_TRADITIONAL   
111             wxLANGUAGE_CHINESE_HONGKONG   
112             wxLANGUAGE_CHINESE_MACAU   
113             wxLANGUAGE_CHINESE_SINGAPORE   
114             wxLANGUAGE_CHINESE_TAIWAN   
115             wxLANGUAGE_CORSICAN   
116             wxLANGUAGE_CROATIAN   
117             wxLANGUAGE_CZECH   
118             wxLANGUAGE_DANISH   
119             wxLANGUAGE_DUTCH   
120             wxLANGUAGE_DUTCH_BELGIAN   
121             wxLANGUAGE_ENGLISH   
122             wxLANGUAGE_ENGLISH_UK   
123             wxLANGUAGE_ENGLISH_US   
124             wxLANGUAGE_ENGLISH_AUSTRALIA   
125             wxLANGUAGE_ENGLISH_BELIZE   
126             wxLANGUAGE_ENGLISH_BOTSWANA   
127             wxLANGUAGE_ENGLISH_CANADA   
128             wxLANGUAGE_ENGLISH_CARIBBEAN   
129             wxLANGUAGE_ENGLISH_DENMARK   
130             wxLANGUAGE_ENGLISH_EIRE   
131             wxLANGUAGE_ENGLISH_JAMAICA   
132             wxLANGUAGE_ENGLISH_NEW_ZEALAND   
133             wxLANGUAGE_ENGLISH_PHILIPPINES   
134             wxLANGUAGE_ENGLISH_SOUTH_AFRICA   
135             wxLANGUAGE_ENGLISH_TRINIDAD   
136             wxLANGUAGE_ENGLISH_ZIMBABWE   
137             wxLANGUAGE_ESPERANTO   
138             wxLANGUAGE_ESTONIAN   
139             wxLANGUAGE_FAEROESE   
140             wxLANGUAGE_FARSI   
141             wxLANGUAGE_FIJI   
142             wxLANGUAGE_FINNISH   
143             wxLANGUAGE_FRENCH   
144             wxLANGUAGE_FRENCH_BELGIAN   
145             wxLANGUAGE_FRENCH_CANADIAN   
146             wxLANGUAGE_FRENCH_LUXEMBOURG   
147             wxLANGUAGE_FRENCH_MONACO   
148             wxLANGUAGE_FRENCH_SWISS   
149             wxLANGUAGE_FRISIAN   
150             wxLANGUAGE_GALICIAN   
151             wxLANGUAGE_GEORGIAN   
152             wxLANGUAGE_GERMAN   
153             wxLANGUAGE_GERMAN_AUSTRIAN   
154             wxLANGUAGE_GERMAN_BELGIUM   
155             wxLANGUAGE_GERMAN_LIECHTENSTEIN   
156             wxLANGUAGE_GERMAN_LUXEMBOURG   
157             wxLANGUAGE_GERMAN_SWISS   
158             wxLANGUAGE_GREEK   
159             wxLANGUAGE_GREENLANDIC   
160             wxLANGUAGE_GUARANI   
161             wxLANGUAGE_GUJARATI   
162             wxLANGUAGE_HAUSA   
163             wxLANGUAGE_HEBREW   
164             wxLANGUAGE_HINDI   
165             wxLANGUAGE_HUNGARIAN   
166             wxLANGUAGE_ICELANDIC   
167             wxLANGUAGE_INDONESIAN   
168             wxLANGUAGE_INTERLINGUA   
169             wxLANGUAGE_INTERLINGUE   
170             wxLANGUAGE_INUKTITUT   
171             wxLANGUAGE_INUPIAK   
172             wxLANGUAGE_IRISH   
173             wxLANGUAGE_ITALIAN   
174             wxLANGUAGE_ITALIAN_SWISS   
175             wxLANGUAGE_JAPANESE   
176             wxLANGUAGE_JAVANESE   
177             wxLANGUAGE_KANNADA   
178             wxLANGUAGE_KASHMIRI   
179             wxLANGUAGE_KASHMIRI_INDIA   
180             wxLANGUAGE_KAZAKH   
181             wxLANGUAGE_KERNEWEK   
182             wxLANGUAGE_KINYARWANDA   
183             wxLANGUAGE_KIRGHIZ   
184             wxLANGUAGE_KIRUNDI   
185             wxLANGUAGE_KONKANI   
186             wxLANGUAGE_KOREAN   
187             wxLANGUAGE_KURDISH   
188             wxLANGUAGE_LAOTHIAN   
189             wxLANGUAGE_LATIN   
190             wxLANGUAGE_LATVIAN   
191             wxLANGUAGE_LINGALA   
192             wxLANGUAGE_LITHUANIAN   
193             wxLANGUAGE_MACEDONIAN   
194             wxLANGUAGE_MALAGASY   
195             wxLANGUAGE_MALAY   
196             wxLANGUAGE_MALAYALAM   
197             wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM   
198             wxLANGUAGE_MALAY_MALAYSIA   
199             wxLANGUAGE_MALTESE   
200             wxLANGUAGE_MANIPURI   
201             wxLANGUAGE_MAORI   
202             wxLANGUAGE_MARATHI   
203             wxLANGUAGE_MOLDAVIAN   
204             wxLANGUAGE_MONGOLIAN   
205             wxLANGUAGE_NAURU   
206             wxLANGUAGE_NEPALI   
207             wxLANGUAGE_NEPALI_INDIA   
208             wxLANGUAGE_NORWEGIAN_BOKMAL   
209             wxLANGUAGE_NORWEGIAN_NYNORSK   
210             wxLANGUAGE_OCCITAN   
211             wxLANGUAGE_ORIYA   
212             wxLANGUAGE_OROMO   
213             wxLANGUAGE_PASHTO   
214             wxLANGUAGE_POLISH   
215             wxLANGUAGE_PORTUGUESE   
216             wxLANGUAGE_PORTUGUESE_BRAZILIAN   
217             wxLANGUAGE_PUNJABI   
218             wxLANGUAGE_QUECHUA   
219             wxLANGUAGE_RHAETO_ROMANCE   
220             wxLANGUAGE_ROMANIAN   
221             wxLANGUAGE_RUSSIAN   
222             wxLANGUAGE_RUSSIAN_UKRAINE   
223             wxLANGUAGE_SAMI   
224             wxLANGUAGE_SAMOAN   
225             wxLANGUAGE_SANGHO   
226             wxLANGUAGE_SANSKRIT   
227             wxLANGUAGE_SCOTS_GAELIC   
228             wxLANGUAGE_SERBIAN   
229             wxLANGUAGE_SERBIAN_CYRILLIC   
230             wxLANGUAGE_SERBIAN_LATIN   
231             wxLANGUAGE_SERBO_CROATIAN   
232             wxLANGUAGE_SESOTHO   
233             wxLANGUAGE_SETSWANA   
234             wxLANGUAGE_SHONA   
235             wxLANGUAGE_SINDHI   
236             wxLANGUAGE_SINHALESE   
237             wxLANGUAGE_SISWATI   
238             wxLANGUAGE_SLOVAK   
239             wxLANGUAGE_SLOVENIAN   
240             wxLANGUAGE_SOMALI   
241             wxLANGUAGE_SPANISH   
242             wxLANGUAGE_SPANISH_ARGENTINA   
243             wxLANGUAGE_SPANISH_BOLIVIA   
244             wxLANGUAGE_SPANISH_CHILE   
245             wxLANGUAGE_SPANISH_COLOMBIA   
246             wxLANGUAGE_SPANISH_COSTA_RICA   
247             wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC   
248             wxLANGUAGE_SPANISH_ECUADOR   
249             wxLANGUAGE_SPANISH_EL_SALVADOR   
250             wxLANGUAGE_SPANISH_GUATEMALA   
251             wxLANGUAGE_SPANISH_HONDURAS   
252             wxLANGUAGE_SPANISH_MEXICAN   
253             wxLANGUAGE_SPANISH_MODERN   
254             wxLANGUAGE_SPANISH_NICARAGUA   
255             wxLANGUAGE_SPANISH_PANAMA   
256             wxLANGUAGE_SPANISH_PARAGUAY   
257             wxLANGUAGE_SPANISH_PERU   
258             wxLANGUAGE_SPANISH_PUERTO_RICO   
259             wxLANGUAGE_SPANISH_URUGUAY   
260             wxLANGUAGE_SPANISH_US   
261             wxLANGUAGE_SPANISH_VENEZUELA   
262             wxLANGUAGE_SUNDANESE   
263             wxLANGUAGE_SWAHILI   
264             wxLANGUAGE_SWEDISH   
265             wxLANGUAGE_SWEDISH_FINLAND   
266             wxLANGUAGE_TAGALOG   
267             wxLANGUAGE_TAJIK   
268             wxLANGUAGE_TAMIL   
269             wxLANGUAGE_TATAR   
270             wxLANGUAGE_TELUGU   
271             wxLANGUAGE_THAI   
272             wxLANGUAGE_TIBETAN   
273             wxLANGUAGE_TIGRINYA   
274             wxLANGUAGE_TONGA   
275             wxLANGUAGE_TSONGA   
276             wxLANGUAGE_TURKISH   
277             wxLANGUAGE_TURKMEN   
278             wxLANGUAGE_TWI   
279             wxLANGUAGE_UIGHUR   
280             wxLANGUAGE_UKRAINIAN   
281             wxLANGUAGE_URDU   
282             wxLANGUAGE_URDU_INDIA   
283             wxLANGUAGE_URDU_PAKISTAN   
284             wxLANGUAGE_UZBEK   
285             wxLANGUAGE_UZBEK_CYRILLIC   
286             wxLANGUAGE_UZBEK_LATIN   
287             wxLANGUAGE_VALENCIAN   
288             wxLANGUAGE_VIETNAMESE   
289             wxLANGUAGE_VOLAPUK   
290             wxLANGUAGE_WELSH   
291             wxLANGUAGE_WOLOF   
292             wxLANGUAGE_XHOSA   
293             wxLANGUAGE_YIDDISH   
294             wxLANGUAGE_YORUBA   
295             wxLANGUAGE_ZHUANG   
296             wxLANGUAGE_ZULU 
297         /;
298use base qw/Wx::Frame Class::Accessor::Fast/;
299use File::Spec;
300use Wx::Locale qw/:default/;
301use Encode qw/encode decode is_utf8/;;
302
303
304my @properties = 
305    qw/
306          progressdlg
307          upload_progressdlg
308          imageviewer
309          tree
310          tree_root
311          treeimglist
312          tree_item_default
313          topsizer
314          pwg
315          manager
316          logwnd
317          oldlogwnd
318          htmlhome
319          notebook
320          categories
321          imagelist
322          image_preview
323          image_prop_piwigo
324          image_prop_exif
325          notebook_image_properties
326          notebook_global_settings
327          general_settings_panel
328          resized_settings_panel
329          thumbnail_settings_panel
330          preview_settings_panel
331          piwigo_properties
332          exif_properties
333          general_settings
334          resized_settings
335          thumbnail_settings
336          preview_settings
337          toolbar
338          branding
339          preview_w
340          preview_h
341          perspective
342          current_imageviewer_index
343          imageviewer_mnu
344          tree_mnu
345          imageviewer_select_multi
346      /;
347__PACKAGE__->mk_accessors( @properties );
348
349use Wx::Event 
350    qw/
351          EVT_MENU
352          EVT_TREE_SEL_CHANGED
353          EVT_CLOSE
354          EVT_LIST_END_LABEL_EDIT
355          EVT_LIST_ITEM_SELECTED
356          EVT_LIST_ITEM_ACTIVATED
357          EVT_LIST_ITEM_RIGHT_CLICK
358          EVT_TREE_ITEM_RIGHT_CLICK
359          EVT_LIST_KEY_DOWN
360          EVT_UPDATE_UI       
361      /;
362     
363use Uploader::GUI::wxImageListCtrl;
364use Uploader::GUI::wxImagePreview;
365use Uploader::GUI::wxImageProcessingProgressDlg;
366use Wx::Html;
367use Uploader::GUI::wxHtmlWindow;
368use Data::Dumper;
369use Wx::AUI;
370use Storable;
371use Uploader::GUI::wxPropertyGridPanel;
372use Encode qw/encode decode is_utf8/;
373
374$|=1;
375
376my $ID_TREE_CTX_MENU = 20000 ;
377my $ID_IMAGEVIEWER_CTX_MENU = 20100 ;
378
379sub new {
380  my( $class, $params ) = @_;
381  my( $self ) = $class->SUPER::new( 
382                                      undef, 
383                                      -1, 
384                                      $params->{title}, 
385                                      [ $params->{x}, $params->{y} ],
386                                      [ $params->{width}, $params->{height} ],
387                                      wxDEFAULT_FRAME_STYLE
388                                   );
389    $self->preview_w(
390        $params->{preview_w}||400
391    );
392
393    $self->preview_h(
394        $params->{preview_h}||300
395    );
396   
397    $self->perspective(
398        $params->{perspective}
399    );
400   
401    $self->current_imageviewer_index(
402        $params->{imageviewer_index}||0
403    );
404
405    $self->pwg( $params->{pwg} );
406    $self->imagelist( $params->{imagelist} );
407
408    # callback for GUI refresh : add thumbnail images to the imageviewer control
409    $self->imagelist->SetNewFilesViewerRefreshCallback(
410        sub { $self->SetNewFilesViewerRefresh(@_) }
411    );
412
413    # callback for GUI refresh : progress dialog display of thumbnail image being created
414    $self->imagelist->SetNewFilesProgressCallback(
415        sub { $self->SetNewFilesProgress(@_) }
416    );
417
418    $self->imagelist->SetNewFilesDisplayEndInfoCallback(
419        sub { $self->SetNewFilesDisplayEndInfo(@_) }
420    );
421
422
423    # callback for GUI refresh : remove thumbnail images from imageviewer control
424    $self->imagelist->UploadImagesViewerCallback(
425        sub { $self->UploadImagesViewerRefresh(@_) }
426    );
427
428
429
430    # callback for GUI refresh : progress dialog display current uploaded image
431    $self->imagelist->progress_thumbnail_refresh(
432        sub { $self->UploadProgressThumbnailRefresh(@_) }
433    );
434
435    $self->imagelist->progress_msg_refresh(
436        sub { $self->UploadProgressMessageRefresh(@_) }
437    );
438
439
440    $self->imagelist->progressbar_refresh(
441        sub { $self->UploadProgressBarRefresh(@_) }
442    );
443   
444    $self->imagelist->progress_endinfo_refresh(
445        sub { $self->UploadDisplayEndInfo(@_) }
446    );
447
448
449    $self->imagelist->pwg(
450        $self->pwg
451    );
452
453    $self->imagelist->categories(
454        []
455    );
456
457
458    $self->manager( Wx::AuiManager->new );
459    $self->manager->SetManagedWindow( $self );
460    $self->_set_setting_properties;
461    $self->_initFrame;
462    $self->_initMenus;
463    $self->_initEventHandlers;
464    $self->_initImgTypes;   
465
466
467    $self->imageviewer->SelectItem(
468        $self->current_imageviewer_index
469    ) if $self->imageviewer->GetItemCount;
470   
471    $self;
472}
473
474
475sub _initImgTypes {
476    my ( $self ) = @_;
477
478    $self->{IMGTYPE} = {
479             'jpg' => wxBITMAP_TYPE_JPEG,
480             'gif' => wxBITMAP_TYPE_GIF,
481             'png' => wxBITMAP_TYPE_PNG,
482    };
483}
484
485
486sub GetWxBitmapType {
487    my ( $self, $type ) = @_;
488   
489    $self->{IMGTYPE}->{$type};
490}
491
492
493
494sub _set_setting_properties {
495    my ( $self ) = @_;
496
497    $self->piwigo_properties(
498        [
499            {
500                label => gettext("Photo caption :"),
501                value => sub { $self->imagelist->current_image->site_name(@_) },
502            },
503            {
504                label => gettext("Comment :"),
505                value => sub { $self->imagelist->current_image->site_comment(@_) },
506                type  => "LongText",
507            },
508            {
509                label => gettext("Author :"),
510                value => sub { $self->imagelist->current_image->site_author(@_) },
511            },
512            {
513                label    => gettext("File name :"),
514                value    => sub { $self->imagelist->current_image->file(@_) },
515                readonly => 1,
516            },
517            {
518                label    => gettext("Create date :"),
519                value    => sub { $self->imagelist->current_image->create_date(@_) },
520                readonly => 1,
521            },
522        ]   
523    );
524
525    $self->exif_properties(
526        [
527            {
528                label    => gettext("Create date :"),
529                value    => sub { $self->imagelist->current_image->create_date }, 
530                readonly => 1,
531            }, 
532            {
533                label    => gettext("Model :"),
534                value    => sub { $self->imagelist->current_image->exif_tag('Model') }, 
535                readonly => 1,
536            }, 
537            {
538                label    => gettext("Width :"),
539                value    => sub { $self->imagelist->current_image->exif_tag('ImageWidth') }, 
540                readonly => 1,
541            }, 
542            {
543                label    => gettext("Height :"),
544                value    => sub { $self->imagelist->current_image->exif_tag('ImageHeight') }, 
545                readonly => 1,
546            }, 
547            {
548                label    => gettext("Orientation :"),
549                value    => sub { $self->imagelist->current_image->exif_tag('Orientation') }, 
550                readonly => 1,
551            }, 
552            {
553                label    => "ISO :",
554                value    => sub { $self->imagelist->current_image->exif_tag('ISO') }, 
555                readonly => 1,
556            }, 
557            {
558                label    => gettext("Shutter speed :"),
559                value    => sub { $self->imagelist->current_image->exif_tag('ExposureTime') }, 
560                readonly => 1,
561            }, 
562            {
563                label    => gettext("Aperture :"),
564                value    => sub { $self->imagelist->current_image->exif_tag('ApertureValue') }, 
565                readonly => 1,
566            }, 
567            {
568                label    => gettext("Focal length :"),
569                value    => sub { $self->imagelist->current_image->exif_tag('FocalLength') }, 
570                readonly => 1,
571            }, 
572            {
573                label    => gettext("Lens :"),
574                value    => sub { $self->imagelist->current_image->exif_tag('Lens') }, 
575                readonly => 1,
576            }, 
577        ]
578    );   
579
580    $self->general_settings(
581        [
582            {
583                label     => gettext("Default author :"),
584                value   => sub { $self->imagelist->author(@_) },
585            },
586            {
587                label     => gettext("Default photo caption :"),
588                type      => 'Choice',
589                value   => sub { $self->imagelist->default_photo_name(@_) },
590                choice  => [
591                                  gettext('None'),
592                                  gettext('File name'),
593                                  gettext('File path and name'),
594                                  gettext('Prefix'),
595                                  gettext('Prefix + rank number'),
596                                  gettext('Rank number + prefix'),
597                                  gettext('Prefix + create date chrono'),
598                                  gettext('Create date chrono + prefix'),
599                              ],
600            },
601            {
602                label     => gettext("Photo caption  prefix :"),
603                value   => sub { $self->imagelist->default_name_prefix(@_) },
604            },
605            {
606                label     => gettext("Resize site image :"),
607                type      => 'Bool',
608                value   => sub { $self->imagelist->create_resized(@_) },
609            },
610            {
611                label     => gettext("Auto rotate image :"),
612                type      => 'Bool',
613                value   => sub { $self->imagelist->auto_rotate(@_) },
614            },
615            {
616                label     => gettext("Upload high (original size) :"),
617                type      => 'Bool',
618                value   => sub { $self->imagelist->upload_high(@_) },
619            },
620#            {
621#                label     => gettext("Remove uploaded photo from selection :"),
622#                type      => 'Bool',
623#                value  => sub { $self->imagelist->remove_uploaded_from_selection(@_) },
624#            },
625        ]   
626    );
627   
628    $self->resized_settings(
629        [
630            {
631                label     => gettext("Site image width :"),
632                type      => 'Number',
633                value   => sub { $self->imagelist->resize_w(@_) },
634            },
635            {
636                label     => gettext("Site image height :"),
637                type      => 'Number',
638                value   => sub { $self->imagelist->resize_h(@_) },
639            },
640            {
641                label     => gettext("Site image jpeg quality :"),
642                type      => 'Number',
643                value   => sub { $self->imagelist->quality(@_) },
644            },
645            {
646                label     => gettext("Site image filter :"),
647                type      => 'Choice',
648                value   => sub { $self->imagelist->filter(@_) },
649                choice    => [ qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ ],
650            },
651            {
652                label     => gettext("Site image blur :"),
653                type      => 'Number',
654                value   => sub { $self->imagelist->blur(@_) },
655            },
656            {
657                label     => gettext("Site image interlace :"),
658                type      => 'Choice',
659                value   => sub { $self->imagelist->interlace(@_) },
660                choice    => [ qw/None Line Plane Partition JPEG GIF PNG/ ],
661            },
662        ]   
663    );
664
665    $self->thumbnail_settings(
666        [
667            {
668                label     => gettext("Site thumbnail size :"),
669                type      => 'Number',
670                value   => sub { $self->imagelist->thumb_size(@_) },
671            },
672            {
673                label     => gettext("Site thumbnail jpeg quality :"),
674                type      => 'Number',
675                value   => sub { $self->imagelist->th_quality(@_) },
676            },
677            {
678                label     => gettext("Photo selection thumbnail size :"),
679                type      => 'Number',
680                value   => sub { $self->imagelist->wx_thumb_size(@_) },
681            },
682            {
683                label     => gettext("Photo selection thumbnail jpeg quality :"),
684                type      => 'Number',
685                value   => sub { $self->imagelist->wx_quality(@_) },
686            },
687        ]   
688    );
689   
690    $self->preview_settings(
691        [
692            {
693                label     => gettext("Use exif preview when available :"),
694                type      => 'Bool',
695                value   => sub { $self->imagelist->use_exif_preview(@_) },
696            },
697            {
698                label     => gettext("Custom preview ratio :"),
699                type      => 'Number',
700                value   => sub { $self->imagelist->preview_ratio(@_) },
701            },
702        ]   
703    );
704       
705}
706
707sub _refreshFrame {
708    my ( $self ) = @_;
709   
710    $self->_set_setting_properties;
711    $self->_refresh_settings_panels_properties;
712    map {
713        $_->Refresh;   
714    }
715    (
716        $self->image_prop_piwigo,
717        $self->image_prop_exif,
718        $self->general_settings_panel,
719        $self->resized_settings_panel,
720        $self->thumbnail_settings_panel,
721        $self->preview_settings_panel,
722    );
723   
724    $self->manager->Update;
725}
726
727
728sub _destroy_settings_panels {
729    my ( $self ) = @_;
730
731
732
733    map {
734        $self->manager->DetachPane(
735            $_
736        );
737        $_->Show(0);
738        $_->Destroy;
739    }(
740        $self->notebook_global_settings,
741        $self->notebook_image_properties,
742    );
743}
744
745#
746sub _initFrame {
747    my ( $self ) = @_;
748   
749 
750    $self->init_panels;
751
752    $self->init_aui;
753    $self->init_dnd_targets;
754
755    if( $self->imagelist->wx_thumb_imglist->GetImageCount){
756        printf("%s images\n", $self->imagelist->wx_thumb_imglist->GetImageCount); 
757        $self->ShowImageViewer;
758       
759        $self->imageviewer->Refresh(
760            $self->imagelist->wx_thumb_imglist
761        );
762       
763    }
764
765}
766
767sub _refresh_settings_panels_properties {
768    my ( $self ) = @_; 
769
770    $self->image_prop_piwigo->properties(
771        $self->piwigo_properties
772    );
773   
774    $self->image_prop_exif->properties(
775        $self->exif_properties
776    );
777
778
779    $self->general_settings_panel->properties(
780        $self->general_settings
781    );   
782
783    $self->resized_settings_panel->properties(
784        $self->resized_settings
785    );   
786
787    $self->thumbnail_settings_panel->properties(
788        $self->thumbnail_settings,
789    );   
790
791    $self->preview_settings_panel->properties(
792        $self->preview_settings,
793    );   
794       
795}
796
797sub _init_settings_panels {
798    my ( $self ) = @_; 
799
800    $self->image_prop_piwigo(
801        Uploader::GUI::wxPropertyGridPanel->new( 
802            { 
803                parentwnd       => $self,
804                properties      => $self->piwigo_properties,
805                frame_callbacks => [ 
806                                          sub {
807                                              $self->imageviewer->Refresh();
808                                          },
809                                   ],
810            }
811        )
812    );
813
814    $self->image_prop_exif(
815        Uploader::GUI::wxPropertyGridPanel->new( 
816            { 
817                parentwnd       => $self,
818                frame_callbacks => [],
819                properties      => $self->exif_properties,
820            }
821        )
822    );
823
824
825    $self->general_settings_panel(
826        Uploader::GUI::wxPropertyGridPanel->new( 
827            { 
828                parentwnd       => $self,
829                properties      => $self->general_settings,
830                frame_callbacks => [], 
831            }
832        )
833    );   
834
835    $self->resized_settings_panel(
836        Uploader::GUI::wxPropertyGridPanel->new( 
837            { 
838                parentwnd       => $self,
839                properties      => $self->resized_settings,
840                frame_callbacks => [],
841
842            }
843        )   
844    );   
845
846    $self->thumbnail_settings_panel(
847        Uploader::GUI::wxPropertyGridPanel->new( 
848            { 
849                parentwnd       => $self,
850                properties      => $self->thumbnail_settings,
851                frame_callbacks => [],
852
853            }
854        )   
855    );   
856    $self->preview_settings_panel(
857        Uploader::GUI::wxPropertyGridPanel->new( 
858            { 
859                parentwnd       => $self,
860                properties      => $self->preview_settings,
861                frame_callbacks => [],
862
863            }
864        )   
865    );   
866   
867    $self->general_settings_panel->Show(0);
868
869if(0){
870    $self->image_preview(
871        Wx::StaticBitmap->new(
872            $self,
873            -1,
874            wxNullBitmap,
875            wxDefaultPosition,
876            [$self->preview_w, $self->preview_h]
877        )
878    );
879}
880    $self->image_preview(
881        Uploader::GUI::wxImagePreview->new(
882            $self,
883            -1,
884            wxNullBitmap,
885            wxDefaultPosition,
886            [$self->preview_w, $self->preview_h]
887        )
888    );
889
890
891    $self->image_prop_piwigo->Show(0);
892   
893    $self->image_prop_exif->Show(0);
894       
895}
896
897sub init_panels {
898    my ( $self ) = @_; 
899
900    my $file = sprintf(
901        "../locale/%s/gs.html",
902        wxTheApp->locale->GetCanonicalName
903    );
904
905    $self->htmlhome(
906        Uploader::GUI::wxHtmlWindow->new(
907            $self, -1, [-1, -1], [450, 450]
908        )
909    );
910   
911    $self->htmlhome->LoadPage($file) if -e $file ;
912   
913    $self->htmlhome->InitHrefCallbacks(
914        {
915            new_album => sub {$self->OnAddCategories(@_) },
916            add_photos => sub { $self->OnAddImages(@_) },
917            upload_photos => sub { $self->ProcessImageSelection(@_)},   
918        }
919    );
920   
921    $self->imageviewer(
922        Uploader::GUI::wxImageListCtrl->new( 
923            { 
924                parentwnd => $self,
925                imagelist => $self->imagelist,
926            }
927        )
928    );
929   
930    $self->_init_settings_panels;       
931}
932
933sub init_dnd_targets {
934    my ( $self ) = @_; 
935
936    $self->imageviewer->SetDropTarget( 
937        DNDImageListDropTarget->new(
938            $self->imageviewer
939        ) 
940    );
941    #$self->htmlhome->SetDropTarget(
942    #    DNDImageListDropTarget->new(
943    #        $self->imageviewer
944    #    )
945    #);
946
947
948    $self->tree->SetDropTarget( 
949        DNDCategoryTreeDropTarget->new(
950            $self->tree
951        )
952    );
953       
954}
955
956sub init_aui {
957    my ( $self ) = @_;
958
959    my $url = wxTheApp->site_url;
960   
961    $url = gettext("empty - work Offline") if wxTheApp->use_offline;
962
963    $self->manager->AddPane
964      ( $self->create_notebook_imagelist, Wx::AuiPaneInfo->new->Name( "ImageViewer" )
965        ->CenterPane->Position(1)->Resizable->CloseButton(0) );
966
967    $self->manager->AddPane
968      ( $self->create_tree, Wx::AuiPaneInfo->new->Name( "categories" )
969        ->Right->Position( 0 )->Resizable->CloseButton(0) );
970
971
972
973    $self->_init_aui_settings_panels;
974
975    $self->toolbar(
976        $self->create_toolbar
977    );
978
979    $self->manager->AddPane
980      ( $self->toolbar, Wx::AuiPaneInfo->new->Name( "tb1" )
981        ->ToolbarPane->Top->Row( 1 )->LeftDockable( 0 )->RightDockable( 0 ) ) if defined $self->toolbar;
982
983    if($self->perspective){
984        $self->manager->LoadPerspective($self->perspective) if $self->perspective =~ /getting_started/;
985    }
986
987    $self->manager->GetPane("categories")->Caption(
988          sprintf("%s - %s", sprintf("Piwigo %s", wxTheApp->branding->{categories}), $url )
989      );
990
991    $self->manager->GetPane("preview")->Caption(gettext("Preview"));
992    $self->manager->GetPane("tb1")->Caption( gettext("Tools") );
993    $self->manager->GetPane("photo_properties")->Caption(gettext("Photo properties"));
994    $self->manager->GetPane("global_settings")->Caption(gettext("Global settings"));
995    $self->manager->GetPane("getting_started")->Caption(gettext("Getting started"));
996
997   
998    $self->manager->Update;
999
1000}
1001
1002sub _init_aui_settings_panels {
1003    my ( $self ) = @_; 
1004
1005    $self->manager->AddPane
1006      ( $self->image_preview, Wx::AuiPaneInfo->new->Name( "preview" )
1007        ->Floatable(1)->Resizable->CloseButton(1));
1008
1009
1010    $self->manager->AddPane
1011      ( $self->htmlhome, Wx::AuiPaneInfo->new->Name( "getting_started" )
1012       ->Floatable(1)->Resizable->CloseButton(1) );
1013
1014
1015    $self->manager->AddPane
1016      ( $self->create_notebook_image_properties, Wx::AuiPaneInfo->new->Name( "photo_properties" )
1017        ->Floatable(1)->Resizable->CloseButton(1) );
1018
1019    $self->manager->AddPane
1020      ( $self->create_notebook_global_settings, Wx::AuiPaneInfo->new->Name( "global_settings" )
1021        ->Floatable(1)->Resizable->CloseButton(1) );
1022
1023    $self->manager->GetPane("preview")->Show(0);
1024    $self->manager->GetPane("photo_properties")->Show(0);
1025    $self->manager->GetPane("global_settings")->Show(0);
1026    $self->manager->GetPane("getting_started")->Float;
1027    $self->manager->GetPane("getting_started")->Show(1);
1028       
1029}
1030
1031sub OnPhotoProperties {
1032    my ( $self ) = @_;
1033
1034    $self->manager->GetPane("photo_properties")->Show(1);
1035    $self->manager->Update();   
1036       
1037}
1038
1039sub OnPreview {
1040    my ( $self ) = @_;
1041
1042    $self->manager->GetPane("preview")->Float->Show(1);
1043    $self->manager->Update();   
1044       
1045}
1046
1047sub OnGettingStarted {
1048    my ( $self ) = @_;
1049
1050    $self->toolbar->EnableTool(100, 0 );
1051    $self->manager->GetPane("getting_started")->Float->Show(1);
1052    $self->manager->Update();   
1053       
1054}
1055
1056sub OnGlobalSettings {
1057    my ( $self ) = @_;
1058
1059    $self->toolbar->EnableTool(104, 0 );
1060    $self->manager->GetPane("global_settings")->Float->Show(1);
1061    $self->manager->Update();   
1062}
1063
1064sub OnChooseLanguage {
1065    my ( $self ) = @_; 
1066
1067  my $languages = [
1068             ['Dutch', wxLANGUAGE_DUTCH, ],   
1069             ['English', wxLANGUAGE_ENGLISH, ],   
1070             ['French', wxLANGUAGE_FRENCH, ],   
1071             ['German', wxLANGUAGE_GERMAN, ],   
1072             ['Italian', wxLANGUAGE_ITALIAN, ],   
1073             ['Polish', wxLANGUAGE_POLISH, ],   
1074             ['Portuguese', wxLANGUAGE_PORTUGUESE, ],   
1075             ['Russian', wxLANGUAGE_RUSSIAN, ],   
1076             ['Spanish', wxLANGUAGE_SPANISH, ],   
1077  ];
1078
1079  my $dialog = new Wx::SingleChoiceDialog
1080    ( undef, gettext( "Choose a language" ), gettext( "Choose a language" ),
1081      [ map { Wx::GetTranslation( ${$_}[0] ) } @$languages ] );
1082
1083  if( $dialog->ShowModal() == wxID_OK ) {
1084    wxTheApp->current_language(
1085        $languages->[$dialog->GetSelection][1]
1086    );
1087    wxTheApp->init_locale();
1088    $self->_refreshFrame;
1089  }
1090
1091  $dialog->Destroy;
1092
1093}
1094
1095
1096sub create_notebook_imagelist {
1097    my( $self ) = @_;
1098    my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [300, 450],
1099                                     wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT);
1100
1101        my $imglistpage = [
1102            [
1103                $self->imageviewer, 
1104                gettext("Photo selection"),
1105                '../res/images.png', 
1106                wxBITMAP_TYPE_PNG,
1107            ],
1108        ];
1109
1110    $self->notebook($book);
1111    $self->_populate_notebook($self->notebook, $imglistpage, 0);
1112    return $book;
1113}
1114
1115sub create_notebook_image_properties {
1116    my( $self ) = @_;
1117    my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450],
1118                                     wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT);
1119    my $pages = [   
1120        [
1121            $self->image_prop_piwigo, 
1122            "Piwigo",
1123        ],
1124        [
1125            $self->image_prop_exif, 
1126            "Exif",
1127        ],
1128    ];
1129   
1130    $self->_populate_notebook( $book, $pages );
1131
1132    $self->notebook_image_properties($book);
1133
1134    return $book;
1135}
1136
1137sub create_notebook_global_settings {
1138    my( $self ) = @_;
1139    my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450],
1140                                     wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT);
1141    my $pages = [   
1142        [
1143            $self->general_settings_panel, 
1144            gettext("General"),
1145        ],
1146        [
1147            $self->resized_settings_panel, 
1148            gettext("Resized"),
1149        ],
1150        [
1151            $self->thumbnail_settings_panel, 
1152            gettext("Thumbnail"),
1153        ],
1154        [
1155            $self->preview_settings_panel, 
1156            gettext("Preview"),
1157        ],
1158    ];
1159   
1160    $self->_populate_notebook( $book, $pages );
1161
1162    $self->notebook_global_settings($book);
1163
1164    return $book;
1165}
1166
1167
1168
1169
1170sub create_tree {
1171    my ( $self ) = @_;
1172
1173    my $images = [
1174        map {
1175            Wx::Bitmap->new( $_, wxBITMAP_TYPE_PNG )
1176               
1177        }
1178        (
1179          '../res/tree_pwg.png',
1180          '../res/tree_folder.png',
1181        )   
1182    ];
1183
1184    $self->treeimglist( Wx::ImageList->new( 16, 16, 1 ) );
1185    map {
1186        $self->treeimglist->Add($_);
1187    }
1188    @$images;
1189
1190   
1191    $self->tree( 
1192        Wx::TreeCtrl->new( 
1193           $self, 
1194           -1, 
1195           wxDefaultPosition, 
1196           wxDefaultSize, 
1197           wxBORDER_NONE|
1198           wxCLIP_CHILDREN|
1199#           wxTR_MULTIPLE|
1200#           wxTR_EXTENDED|
1201           wxTR_HAS_BUTTONS
1202#           wxTR_HIDE_ROOT   
1203        ) 
1204    );
1205
1206    $self->tree->SetImageList( $self->treeimglist );
1207    $self->populate_tree_categories if !wxTheApp->use_offline;
1208    $self->tree ;
1209}
1210
1211
1212sub populate_tree_categories {
1213    my ( $self ) = @_;
1214
1215    $self->populate_tree(
1216        $self->tree,
1217        wxTheApp->pwg->categories,
1218    ) if defined wxTheApp->pwg ;
1219   
1220    $self->tree->ExpandAll;
1221
1222}
1223
1224
1225# returns a valid itemData
1226sub itemData { Wx::TreeItemData->new( $_[0] ) }
1227
1228sub populate_tree {
1229    my ( $self, $tree, $tree_items ) = @_;
1230    my $root = shift @{$tree_items};
1231    $self->tree_root(
1232        $tree->AddRoot( 
1233            $root->[0], 
1234            $root->[3], 
1235            $root->[4], 
1236            itemData( $root->[2] ) 
1237        )
1238    );
1239
1240  $self->populate_tree_helper( $tree, $self->tree_root, $tree_items );
1241
1242  $tree->Expand( $self->tree_root );
1243}
1244
1245sub populate_tree_helper {
1246  my ( $self, $tree, $parent_id, $tree_items ) = @_;
1247
1248  my $id;
1249
1250  map {
1251      my $name = $_->[0];
1252      eval {
1253        $name = is_utf8($name) ?  decode('UTF-8', $name) : $name;
1254      };
1255      if($@){
1256          $name = $_->[0];
1257      }
1258       $id = $tree->AppendItem( 
1259                                   $parent_id, 
1260                                   $name,
1261                                   defined($_->[3]) ? $_->[3] : 0, 
1262                                   defined($_->[4]) ? $_->[4] : 0, 
1263                                   itemData( $_->[2]) 
1264                              );
1265      $self->tree_item_default($id) if ! defined $self->tree_item_default;
1266      # current item has children
1267      if( ref( $_->[1] ) eq 'ARRAY' ) {
1268          $self->populate_tree_helper( $tree, $id, $_->[1] );
1269      } 
1270  }
1271  @{$tree_items};
1272
1273}
1274
1275
1276
1277
1278sub _populate_notebook {
1279    my ( $self, $book, $pages, $position ) = @_;       
1280
1281    my $i = 0;
1282    map {
1283        my $icon = Wx::Icon->new();
1284        eval { $icon->LoadFile($_->[2], $_->[3]) ; }
1285            if defined $_->[2];
1286        my $nb_icon = Wx::Bitmap->new( $icon );
1287        defined $position ?
1288            $book->InsertPage($position, $_->[0],
1289                    $_->[1], 1, $nb_icon )
1290                          :
1291            $book->AddPage($_->[0],
1292                    $_->[1], 0, $nb_icon );
1293
1294        $i++;
1295    } @$pages;
1296
1297}
1298
1299
1300sub _initMenus {
1301    my ( $self ) = @_ ;
1302
1303    $self->_tree_mnu;
1304    $self->_imageviewer_mnu;   
1305}
1306
1307
1308sub _tree_mnu {
1309    my ( $self ) = @_; 
1310
1311    my $ctx_mnu = Wx::Menu->new;
1312   
1313    map {
1314        $ctx_mnu->Append(
1315            @$_[0..2], wxITEM_NORMAL
1316        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
1317    }
1318    (
1319        # workaround : first item does not show bitmap
1320        [
1321            0, 
1322            "",
1323            "",
1324            '../res/mnu_folder_new.png',
1325        ],
1326        [
1327            1+$ID_TREE_CTX_MENU, 
1328            wxTheApp->branding->{'Add new category'},
1329            sprintf(
1330                "%s %s %s %s", 
1331                gettext("Add a new"), 
1332                wxTheApp->branding->{category},
1333                gettext("to the currently selected"),
1334                wxTheApp->branding->{category},
1335            ),
1336            '../res/mnu_folder_new.png',
1337        ],
1338        [
1339            2+$ID_TREE_CTX_MENU, 
1340            "Refresh",
1341            sprintf(
1342                "Refresh %s list.",
1343                wxTheApp->branding->{category},
1344            ),
1345            '../res/mnu_refresh.png',
1346        ],
1347    );
1348
1349    $ctx_mnu->Delete(0);
1350    $self->tree_mnu(
1351         $ctx_mnu
1352    ); 
1353}       
1354
1355sub _imageviewer_mnu {
1356    my ( $self ) = @_; 
1357
1358    my $ctx_mnu = Wx::Menu->new;
1359   
1360    map {
1361        $ctx_mnu->Append(
1362            @$_[0..2]
1363        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
1364    }
1365    (
1366        # workaround : first item does not show bitmap
1367        [
1368            0, 
1369            "",
1370            "",
1371            '../res/mnu_properties.png',
1372        ],
1373        [
1374            1+$ID_IMAGEVIEWER_CTX_MENU, 
1375            gettext("Properties"),
1376            gettext("Modify photo properties"),
1377            '../res/mnu_properties.png',
1378        ],
1379        [
1380            2+$ID_IMAGEVIEWER_CTX_MENU, 
1381            gettext("Preview"),
1382            gettext("Display photo preview"),
1383            '../res/mnu_preview.png',
1384        ],
1385    );
1386       
1387    $ctx_mnu->Delete(0);
1388    $self->imageviewer_mnu(
1389         $ctx_mnu
1390    ); 
1391}
1392
1393sub _initEventHandlers {
1394    my ( $self ) = @_ ;
1395       
1396    Wx::Event::EVT_MENU( $self, 100, \&OnGettingStarted );
1397    Wx::Event::EVT_MENU( $self, 101, \&OnAddImages );
1398    Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages );
1399    Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages );
1400    Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings );
1401    Wx::Event::EVT_MENU( $self, 105, \&OnChooseLanguage );
1402    EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged );
1403    EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick );
1404
1405    EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit );
1406    EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated );
1407    EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ;
1408    EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ;
1409
1410    EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ;
1411
1412    EVT_CLOSE( $self, \&OnClose );
1413    Wx::Event::EVT_UPDATE_UI( $self, $self, \&OnUpdateUI );
1414
1415
1416    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories );
1417    Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories );
1418    Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties );
1419    Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview );
1420
1421
1422}
1423
1424{
1425  my $prevdir;
1426  my $prevfile;
1427
1428  sub OnAddImages {
1429    my( $self, $event ) = @_;
1430    my $dialog = Wx::FileDialog->new
1431      ( $self, gettext("Select photos for upload"), $prevfile, $prevdir,
1432        sprintf("%s (*.jpg)|*.jpg|All(*.*)|*.*", gettext("JPEG files")),
1433        wxFD_OPEN|wxFD_MULTIPLE );
1434
1435    my $file_paths = [];
1436    if( $dialog->ShowModal != wxID_CANCEL ) {
1437        @$file_paths = $dialog->GetPaths;
1438        $self->SetNewFiles($file_paths) ;
1439    }
1440    $dialog->Destroy;
1441#    $event->Skip;
1442  }
1443}
1444
1445sub OnUpdateUI {
1446    my( $self, $event ) = @_;
1447   
1448    if( $self->manager ){
1449        if($self->manager->GetPane("global_settings")->IsShown){
1450            $self->toolbar->EnableTool(104, 0);                 
1451        }
1452        else{
1453            $self->toolbar->EnableTool(104, 1);                 
1454        }
1455        if($self->manager->GetPane("getting_started")->IsShown){
1456            $self->toolbar->EnableTool(100, 0);                 
1457        }
1458        else{
1459            $self->toolbar->EnableTool(100, 1);                 
1460        }
1461    }
1462
1463}
1464
1465sub OnRemoveImages {
1466    my( $self, $event ) = @_;
1467
1468   
1469    $self->imagelist->RemoveImageSelection;
1470    $self->imageviewer->Refresh;       
1471
1472    $self->image_preview->SetBitmap(
1473        wxNullBitmap
1474    ) if !$self->imageviewer->GetItemCount;
1475
1476}
1477
1478sub SetNewFiles {
1479    my ( $self, $file_paths ) = @_;
1480
1481    $self->ShowImageViewer();
1482    $self->progressdlg( 
1483        Uploader::GUI::wxImageProcessingProgressDlg->new(
1484            { 
1485                title => gettext("Image processing progress information"),
1486                bt_label => gettext("Cancel image processing"), 
1487             }
1488        )       
1489    );
1490    $self->progressdlg->Show(1);
1491    Wx::Yield();
1492   
1493    my $files = [
1494        map {
1495            encode('iso-8859-1', $_)
1496        }@$file_paths   
1497    ];
1498
1499    @$files = sort @$files;   
1500
1501    $self->imagelist->SetNewFiles(
1502        $files
1503    );
1504
1505   
1506}
1507
1508sub OnTreeSelChanged {
1509    my( $self, $event ) = @_;
1510 
1511    my @items = $self->tree->GetSelections;
1512
1513    $self->imagelist->categories(
1514        [
1515            map {
1516                my $category = $self->tree->GetPlData( $_ );
1517                $category->{id} if $category != -1;
1518            }
1519            @items
1520        ]
1521    );
1522}
1523
1524sub OnTreeItemRightClick {
1525    my( $self, $event ) = @_;
1526
1527
1528    $self->PopupMenu($self->tree_mnu, wxDefaultPosition);
1529       
1530}
1531
1532
1533sub OnImageViewerItemRightClick {
1534    my( $self, $event ) = @_;
1535
1536   
1537    $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition);
1538       
1539       
1540}
1541
1542sub OnAddCategories {
1543    my ( $self, $event ) = @_;
1544
1545    my $item = $self->tree->GetSelection;
1546
1547    my $category = $self->tree->GetPlData($item);
1548    my $category_id;
1549   
1550    $category_id = $category->{id} if 'HASH' eq ref($category) ;
1551
1552    my $dialog = Wx::TextEntryDialog->new( 
1553        $self, 
1554        sprintf("%s name :", wxTheApp->branding->{Category}), 
1555        sprintf("Add new %s", wxTheApp->branding->{category}),
1556        sprintf("New %s", wxTheApp->branding->{category}), 
1557    );
1558
1559    if( $dialog->ShowModal != wxID_CANCEL ) {
1560        my $name = $dialog->GetValue;
1561        my ( $status, $status_msg ) = $self->pwg->AddCategories( $name, $category_id);
1562        $self->_refresh_tree_categories_helper;
1563    }
1564    $dialog->Destroy;
1565}
1566
1567sub OnRefreshCategories {
1568    my ( $self, $event ) = @_;
1569
1570    $self->_refresh_tree_categories_helper;
1571}
1572
1573sub _refresh_tree_categories_helper {
1574    my ( $self ) = @_; 
1575
1576    my $busycursor = Wx::BusyCursor->new();
1577    $self->tree->CollapseAll;
1578    $self->tree->DeleteAllItems;
1579    $self->imagelist->categories([]);
1580    $self->pwg->RefreshCategories();
1581    $self->populate_tree_categories;
1582}
1583
1584sub OnImageViewerEndLabelEdit {
1585    my( $self, $event ) = @_;
1586 
1587    my $image = $self->imagelist->GetImage($event->GetIndex);
1588    $image->site_name(
1589        $event->GetLabel
1590    );
1591       
1592    $self->image_prop_piwigo->Refresh;
1593}
1594
1595sub OnImageViewerItemActivated {
1596    my( $self, $event ) = @_;
1597   
1598    $self->current_imageviewer_index(
1599        $event->GetIndex
1600    );
1601
1602    $self->OnPhotoProperties;
1603}
1604
1605
1606sub OnImageViewerItemSelected {
1607    my( $self, $event ) = @_;
1608 
1609    my $indx = $event->GetIndex;
1610
1611    $self->_on_imageviewer_item_selected($indx);
1612
1613    $event->Skip;
1614}
1615
1616sub _on_imageviewer_item_selected {
1617    my ( $self, $index ) = @_; 
1618
1619    $self->current_imageviewer_index($index);
1620    $self->imagelist->SetCurrentImage($index);
1621   
1622    $self->imagelist->image_selection(
1623        $self->imageviewer->GetSelectedItems
1624    );
1625
1626    $self->_image_preview_refresh if @{$self->imagelist->image_selection} < 2;
1627   
1628    $self->manager->Update;
1629   
1630    $self->image_prop_piwigo->Refresh;
1631    $self->image_prop_exif->Refresh;
1632
1633}
1634
1635sub _image_preview_refresh {
1636    my ( $self ) = @_; 
1637
1638    $self->image_preview->SetBitmap(
1639        wxNullBitmap
1640    );
1641
1642    $self->image_preview->Refresh;
1643
1644    my $bmp = Wx::Bitmap->new( 
1645            $self->imagelist->current_image->preview_file, 
1646            $self->GetWxBitmapType($self->imagelist->type), 
1647        );
1648
1649       
1650    $self->image_preview->SetBitmap(
1651        $bmp
1652    );
1653
1654    my $size = [8+$bmp->GetWidth, 26+$bmp->GetHeight];
1655    $self->manager->GetPane("preview")->FloatingSize($size);
1656   
1657    $self->image_preview->Refresh;
1658}
1659
1660sub OnImageViewerKeyDown {
1661    my( $self, $event ) = @_;
1662
1663    if(WXK_DELETE == $event->GetKeyCode){
1664        $self->OnRemoveImages();
1665       
1666        my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ?
1667            $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ;
1668        $self->imageviewer->SelectItem(
1669            $index
1670        );
1671    }   
1672
1673}
1674
1675sub OnUploadImages {
1676    my( $self, $event ) = @_;
1677
1678    eval {
1679        $self->ProcessImageSelection();   
1680    };
1681}
1682
1683# remove image from imagelist when uploaded
1684sub UploadImagesViewerRefresh {
1685    my ( $self ) = @_; 
1686
1687    my $imagelist= $self->imagelist ;
1688
1689    Wx::Yield();
1690}
1691
1692sub UploadProgressMessageRefresh {
1693    my ( $self, $msg ) = @_;   
1694
1695    $self->upload_progressdlg->processing(
1696        $msg   
1697    ); 
1698
1699    Wx::Yield();
1700}
1701
1702sub UploadProgressThumbnailRefresh {
1703    my ( $self ) = @_; 
1704
1705    my $imagelist = $self->imagelist ;
1706
1707 
1708    $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
1709    $self->upload_progressdlg->image->SetBitmap(
1710        Wx::Bitmap->new( 
1711            $self->imagelist->current_image->wx_thumb_file, 
1712            $self->GetWxBitmapType($self->imagelist->type), 
1713        )
1714    );
1715
1716    Wx::Yield();
1717}
1718
1719sub UploadProgressBarRefresh {
1720    my ( $self, $ratio ) = @_; 
1721
1722    $ratio = $self->imagelist->count > 1 ? 1 : $ratio; 
1723    eval {
1724        $self->upload_progressdlg->progress(
1725            $ratio*$self->imagelist->count * ( 100/scalar @{$self->imagelist->image_selection} )
1726        );
1727        $self->upload_progressdlg->LogProgress();
1728    };
1729    croak gettext("Upload cancelled") if $@;
1730
1731    Wx::Yield();
1732}
1733
1734sub SetNewFilesDisplayEndInfo {
1735    my ( $self, $msg ) = @_;   
1736       
1737    $self->progressdlg->DisplayEndInfo($msg);
1738}
1739
1740sub UploadDisplayEndInfo {
1741    my ( $self, $msg ) = @_;   
1742   
1743    my $imagelist = $self->imagelist ;
1744   
1745    $self->upload_progressdlg->DisplayEndInfo($msg);
1746}
1747
1748sub ShowImageViewer {
1749    my ( $self ) = @_; 
1750
1751    if(!$self->imageviewer->IsShown){
1752        #my $imglistpage = [
1753        #    [
1754        #        $self->imageviewer,
1755        #        gettext("Photo selection"),
1756        #        '../res/images.png',
1757        #        wxBITMAP_TYPE_PNG,
1758        #    ],
1759        #];
1760        #$self->notebook->DeletePage(0);
1761   
1762        $self->imageviewer->Show(1);
1763        #$self->_populate_notebook($self->notebook, $imglistpage, 0);
1764        # load imagelist with loading.jpg
1765    }
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    my $params = {};
1898
1899    ( $params->{'X'}, $params->{'Y'} ) = $self->GetPositionXY ;
1900    ( $params->{'Width'}, $params->{'Height'} ) = $self->GetSizeWH ;
1901    ( $params->{'PreviewWidth'}, $params->{'PreviewHeight'} ) = $self->image_preview->GetSizeWH ;
1902    $params->{Perspective} = $self->manager->SavePerspective;
1903    $params->{ImageviewerIndex} = $self->current_imageviewer_index;
1904   
1905
1906    wxTheApp->SaveConfig( $params );
1907
1908    $self->Destroy;
1909}
1910
1911
1912sub create_toolbar {
1913    my( $self ) = @_;
1914
1915    my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT );
1916    $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) );
1917    map {
1918        my $icon1 = Wx::Icon->new();
1919        eval {
1920            $icon1->LoadFile($_->[2], $_->[3]);
1921        };
1922        my $tb_icon1 = Wx::Bitmap->new( $icon1 );
1923
1924        my $icon2 = Wx::Icon->new();
1925        eval {
1926            $icon2->LoadFile($_->[5], $_->[3]);
1927        };
1928        my $tb_icon2 = Wx::Bitmap->new( $icon2 );
1929
1930
1931        $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[1] );
1932        $tb->EnableTool( $_->[0], $_->[4]);
1933    }
1934    (
1935        [
1936            100, 
1937            gettext("Getting started"), 
1938            '../res/tb_getting_started.png', 
1939            wxBITMAP_TYPE_PNG, 
1940            1, 
1941            '../res/tb_getting_started.png', 
1942            gettext("Display getting started panel")
1943        ],
1944        [
1945            101, 
1946            gettext("Add photo to selection"), 
1947            '../res/tb_add.png', 
1948            wxBITMAP_TYPE_PNG, 
1949            1, 
1950            '../res/tb_add.png', 
1951            gettext("Add photo to selection for resizing and uploading")
1952        ],
1953        [
1954            102, 
1955            gettext("Remove photo from selection"), 
1956            '../res/tb_remove.png', 
1957            wxBITMAP_TYPE_PNG, 
1958            1, 
1959            '../res/tb_remove.png',
1960            gettext("Remove photo from selection. Files are not deleted ")
1961        ],
1962        [
1963            103, 
1964            gettext("Upload to Piwigo"), 
1965            '../res/tb_upload.png', 
1966            wxBITMAP_TYPE_PNG, 
1967            wxTheApp->use_offline ? 0 : 1, 
1968            '../res/tb_upload.png',
1969            gettext("Upload photos to Piwigo.")
1970        ],
1971        [
1972            104, 
1973            gettext("Global settings"), 
1974            '../res/tb_settings.png', 
1975            wxBITMAP_TYPE_PNG, 
1976            0, 
1977            '../res/tb_settings.png',
1978            gettext("Change global settings.")
1979        ],
1980        [
1981            105, 
1982            gettext("Language choice"), 
1983            '../res/tb_i18n.png', 
1984            wxBITMAP_TYPE_PNG, 
1985            1, 
1986            '../res/tb_i18n.png',
1987            gettext("Language choice")
1988        ],
1989   
1990    );
1991
1992    if($@){
1993        undef $tb;
1994    }
1995    else{
1996        $tb->Realize;
1997    }
1998
1999    return $tb;
2000}
2001
2002
2003sub _create_textctrl {
2004    my( $self, $parent, $text, $size ) = @_;
2005
2006    return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size,
2007                              wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY  );
2008}
2009
2010sub create_textctrl {
2011    my( $self, $text, $size ) = @_;
2012
2013    return $self->_create_textctrl( $self, $text, $size );
2014}
2015
2016sub DESTROY {
2017    my( $self ) = @_;
2018
2019    $self->manager->UnInit;
2020}
2021
2022
2023
20241;
2025
2026
2027
2028
2029
2030package DNDImageListDropTarget;
2031use Wx qw/wxTheApp/;
2032use base qw(Wx::FileDropTarget Class::Accessor::Fast);
2033
2034__PACKAGE__->mk_accessors( 
2035    qw/
2036          imageviewer
2037      /
2038);
2039
2040sub new {
2041  my $class = shift;
2042  my $imageviewer = shift;
2043  my $self = $class->SUPER::new( @_ );
2044
2045  $self->imageviewer($imageviewer);
2046
2047  return $self;
2048}
2049
2050sub OnDropFiles {
2051  my( $self, $x, $y, $files ) = @_;
2052
2053  wxTheApp->frame->SetNewFiles($files) ;
2054}
2055
2056
2057
2058
20591;
2060
2061
2062package DNDCategoryTreeDropTarget;
2063
2064use base qw(Wx::TextDropTarget Class::Accessor::Fast);
2065use Data::Dumper;
2066use Wx qw/
2067              wxDragNone
2068              wxDragCopy
2069              wxDragMove
2070         /;
2071
2072__PACKAGE__->mk_accessors( 
2073    qw/
2074          tree
2075          frame
2076      /
2077);
2078
2079sub new {
2080  my ( $class, $tree ) = @_;
2081  my $self = $class->SUPER::new();
2082
2083  $self->tree($tree);
2084  $self->frame($tree->GetParent);
2085  return $self;
2086}
2087
2088
2089
2090sub OnDropText {
2091  my( $self, $x, $y, $textdata ) = @_;
2092
2093  # must be $VAR1 because $textdata is the result of Data::Dumper
2094  my $VAR1;
2095  eval $textdata;
2096  eval {
2097      if(scalar @$VAR1){
2098           my @items;
2099           if(scalar @items < 2) {
2100               my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]);
2101                push @items, $dropItem;
2102           }
2103           else {
2104                @items = $self->tree->GetSelections;
2105           }
2106           
2107           # remove root item which is not a valid category
2108           @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items;
2109           
2110           $self->frame->imagelist->categories(
2111               [
2112                   map {
2113                       $self->tree->GetPlData( $_ )->{id};
2114                   }
2115                   @items
2116               ]
2117           );
2118           
2119           $self->frame->imagelist->image_selection($VAR1);
2120           $self->frame->ProcessImageSelection ;
2121      } 
2122  };
2123}
2124
21251;
Note: See TracBrowser for help on using the repository browser.