source: extras/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm @ 3284

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

Feature 994 added : gui layout management. Use perspective to save/reload gui layout.

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