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

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

Feature 1015 added : save current image selection and reload preview when pLoader starts.

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