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

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

Fix bug 1018 : clear preview after all images are removed from selection.

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