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

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

Feature 1203 added : Chinese translation. Many thanks to Winson for his contribution.

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