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

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

Bug 1017 fixed : an item should be selected after deletion in Photo selection.

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