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

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

Feature 1016 added : popup menu for Photo selection with "Prperties" and "Preview" menu items.

  • Property svn:eol-style set to LF
File size: 55.5 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    # last is first !
1397    if ( scalar @$files > 1 ){
1398        my $first = shift @$files;
1399        push @$files, $first;   
1400    }
1401    #print Dumper $files;
1402
1403    $self->imagelist->SetNewFiles(
1404        $files
1405    );
1406
1407   
1408}
1409
1410sub OnTreeSelChanged {
1411    my( $self, $event ) = @_;
1412 
1413    my @items = $self->tree->GetSelections;
1414
1415    $self->imagelist->categories(
1416        [
1417            map {
1418                my $category = $self->tree->GetPlData( $_ );
1419                $category->{id} if $category != -1;
1420            }
1421            @items
1422        ]
1423    );
1424}
1425
1426sub OnTreeItemRightClick {
1427    my( $self, $event ) = @_;
1428
1429    my $point = $event->GetPoint ;
1430    my $ctx_mnu = Wx::Menu->new;
1431   
1432    map {
1433        $ctx_mnu->Append(
1434            @$_[0..2]
1435        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
1436    }
1437    (
1438        [
1439            1+$ID_TREE_CTX_MENU, 
1440            wxTheApp->branding->{'Add new category'},
1441            sprintf(
1442                "%s %s %s %s", 
1443                gettext("Add a new"), 
1444                wxTheApp->branding->{category},
1445                gettext("to the currently selected"),
1446                wxTheApp->branding->{category},
1447            ),
1448            '../res/mnu_folder_new.png',
1449        ],
1450        [
1451            2+$ID_TREE_CTX_MENU, 
1452            "Refresh",
1453            sprintf(
1454                "Refresh %s list.",
1455                wxTheApp->branding->{category},
1456            ),
1457            '../res/mnu_refresh.png',
1458        ],
1459    );
1460
1461    $self->PopupMenu($ctx_mnu, wxDefaultPosition);
1462       
1463}
1464
1465
1466sub OnImageViewerItemRightClick {
1467    my( $self, $event ) = @_;
1468
1469    my $point = $event->GetPoint ;
1470    my $ctx_mnu = Wx::Menu->new;
1471   
1472    map {
1473        $ctx_mnu->Append(
1474            @$_[0..2]
1475        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
1476    }
1477    (
1478        [
1479            1+$ID_IMAGEVIEWER_CTX_MENU, 
1480            gettext("Properties"),
1481            gettext("Modify photo properties"),
1482            '../res/mnu_properties.png',
1483        ],
1484        [
1485            2+$ID_IMAGEVIEWER_CTX_MENU, 
1486            gettext("Preview"),
1487            gettext("Display photo preview"),
1488            '../res/mnu_preview.png',
1489        ],
1490    );
1491   
1492    $self->PopupMenu($ctx_mnu, wxDefaultPosition);
1493       
1494       
1495}
1496
1497sub OnAddCategories {
1498    my ( $self, $event ) = @_;
1499
1500    my $item = $self->tree->GetSelection;
1501
1502    my $category = $self->tree->GetPlData($item);
1503    my $category_id;
1504   
1505    $category_id = $category->{id} if 'HASH' eq ref($category) ;
1506
1507    my $dialog = Wx::TextEntryDialog->new( 
1508        $self, 
1509        sprintf("%s name :", wxTheApp->branding->{Category}), 
1510        sprintf("Add new %s", wxTheApp->branding->{category}),
1511        sprintf("New %s", wxTheApp->branding->{category}), 
1512    );
1513
1514    if( $dialog->ShowModal != wxID_CANCEL ) {
1515        my $name = $dialog->GetValue;
1516        my ( $status, $status_msg ) = $self->pwg->AddCategories( $name, $category_id);
1517        $self->_refresh_tree_categories_helper;
1518    }
1519    $dialog->Destroy;
1520}
1521
1522sub OnRefreshCategories {
1523    my ( $self, $event ) = @_;
1524
1525    $self->_refresh_tree_categories_helper;
1526}
1527
1528sub _refresh_tree_categories_helper {
1529    my ( $self ) = @_; 
1530
1531    my $busycursor = Wx::BusyCursor->new();
1532    $self->tree->CollapseAll;
1533    $self->tree->DeleteAllItems;
1534    $self->imagelist->categories([]);
1535    $self->pwg->RefreshCategories();
1536    $self->populate_tree_categories;
1537}
1538
1539sub OnImageViewerEndLabelEdit {
1540    my( $self, $event ) = @_;
1541 
1542    my $image = $self->imagelist->GetImage($event->GetIndex);
1543    $image->site_name(
1544        $event->GetLabel
1545    );
1546       
1547    $self->image_prop_piwigo->Refresh;
1548}
1549
1550sub OnImageViewerItemActivated {
1551    my( $self, $event ) = @_;
1552   
1553    $self->current_imageviewer_index(
1554        $event->GetIndex
1555    );
1556
1557    $self->OnPhotoProperties;
1558}
1559
1560
1561sub OnImageViewerItemSelected {
1562    my( $self, $event ) = @_;
1563 
1564    my $indx = $event->GetIndex;
1565
1566    $self->_on_imageviewer_item_selected($indx);
1567    # retrieve photo info for the last selected photo
1568    $event->Skip;
1569}
1570
1571sub _on_imageviewer_item_selected {
1572    my ( $self, $index ) = @_; 
1573
1574    $self->current_imageviewer_index($index);
1575    $self->imagelist->SetCurrentImage($index);
1576   
1577    $self->imagelist->image_selection(
1578        $self->imageviewer->GetSelectedItems
1579    );
1580
1581    $self->image_preview->SetBitmap(
1582        wxNullBitmap
1583    );
1584
1585    $self->image_preview->Refresh;
1586
1587    my $bmp = Wx::Bitmap->new( 
1588            $self->imagelist->current_image->preview_file, 
1589            $self->GetWxBitmapType($self->imagelist->type), 
1590        );
1591
1592       
1593    $self->image_preview->SetBitmap(
1594        $bmp
1595    );
1596
1597    my $size = [8+$bmp->GetWidth, 26+$bmp->GetHeight];
1598    $self->manager->GetPane("preview")->FloatingSize($size);
1599   
1600    $self->image_preview->Refresh;
1601   
1602    $self->manager->Update;
1603   
1604    $self->image_prop_piwigo->Refresh;
1605    $self->image_prop_exif->Refresh;
1606
1607}
1608
1609sub OnImageViewerKeyDown {
1610    my( $self, $event ) = @_;
1611
1612    if(WXK_DELETE == $event->GetKeyCode){
1613        $self->OnRemoveImages();
1614    }   
1615}
1616
1617sub OnUploadImages {
1618    my( $self, $event ) = @_;
1619
1620    eval {
1621        $self->ProcessImageSelection();   
1622    };
1623}
1624
1625# remove image from imagelist when uploaded
1626sub UploadImagesViewerRefresh {
1627    my ( $self ) = @_; 
1628
1629    my $imagelist= $self->imagelist ;
1630
1631    Wx::Yield();
1632}
1633
1634sub UploadProgressMessageRefresh {
1635    my ( $self, $msg ) = @_;   
1636
1637    $self->upload_progressdlg->processing(
1638        $msg   
1639    ); 
1640
1641    Wx::Yield();
1642}
1643
1644sub UploadProgressThumbnailRefresh {
1645    my ( $self ) = @_; 
1646
1647    my $imagelist = $self->imagelist ;
1648
1649 
1650    $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
1651    $self->upload_progressdlg->image->SetBitmap(
1652        Wx::Bitmap->new( 
1653            $self->imagelist->current_image->wx_thumb_file, 
1654            $self->GetWxBitmapType($self->imagelist->type), 
1655        )
1656    );
1657
1658    Wx::Yield();
1659}
1660
1661sub UploadProgressBarRefresh {
1662    my ( $self, $ratio ) = @_; 
1663
1664    $ratio = $self->imagelist->count > 1 ? 1 : $ratio; 
1665    eval {
1666        $self->upload_progressdlg->progress(
1667            $ratio*$self->imagelist->count * ( 100/scalar @{$self->imagelist->image_selection} )
1668        );
1669        $self->upload_progressdlg->LogProgress();
1670    };
1671    croak gettext("Upload cancelled") if $@;
1672
1673    Wx::Yield();
1674}
1675
1676sub SetNewFilesDisplayEndInfo {
1677    my ( $self, $msg ) = @_;   
1678       
1679    $self->progressdlg->DisplayEndInfo($msg);
1680}
1681
1682sub UploadDisplayEndInfo {
1683    my ( $self, $msg ) = @_;   
1684   
1685    my $imagelist = $self->imagelist ;
1686   
1687    $self->upload_progressdlg->DisplayEndInfo($msg);
1688}
1689
1690sub ShowImageViewer {
1691    my ( $self ) = @_; 
1692
1693    if(!$self->imageviewer->IsShown){
1694        #my $imglistpage = [
1695        #    [
1696        #        $self->imageviewer,
1697        #        gettext("Photo selection"),
1698        #        '../res/images.png',
1699        #        wxBITMAP_TYPE_PNG,
1700        #    ],
1701        #];
1702        #$self->notebook->DeletePage(0);
1703   
1704        $self->imageviewer->Show(1);
1705        #$self->_populate_notebook($self->notebook, $imglistpage, 0);
1706        # load imagelist with loading.jpg
1707    }
1708       
1709}
1710
1711
1712sub ActivateImageViewer {
1713    my ( $self ) = @_; 
1714       
1715}
1716
1717
1718sub SetNewFilesViewerRefresh {
1719
1720    my ( $self ) = @_; 
1721
1722    my $wximagelist = $self->imagelist->wx_thumb_imglist;
1723
1724    my $indx = $wximagelist->Add(
1725        Wx::Bitmap->new( 
1726            $self->imagelist->current_image->wx_thumb_file, 
1727            $self->GetWxBitmapType($self->imagelist->type), 
1728        )
1729    ) if defined $self->imagelist->current_image->wx_thumb_file;
1730    print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n";   
1731    $self->imageviewer->Refresh(
1732        $wximagelist
1733    );
1734
1735    Wx::Yield();
1736}
1737
1738
1739
1740# prepare and upload image_selection
1741sub ProcessImageSelection {
1742    my ( $self ) = @_;
1743
1744    return if !scalar @{$self->imagelist->sums};
1745
1746    if( scalar @{$self->imagelist->categories} ){
1747        # all selected is implicit
1748        if(!scalar @{$self->imageviewer->GetSelectedItems}){
1749       
1750            $self->imagelist->image_selection(
1751                $self->imageviewer->GetAllItems
1752            );
1753        }
1754       
1755        return if( !defined $self->imagelist->image_selection );
1756        return if( !scalar @{$self->imagelist->image_selection} );
1757       
1758        $self->upload_progressdlg(
1759            Uploader::GUI::wxImageProcessingProgressDlg->new(
1760                { 
1761                    title    => gettext("Image upload progress information"),
1762                    bt_label => gettext("Cancel upload"), 
1763                 }
1764            )       
1765        );
1766        # modeless dialog
1767        $self->upload_progressdlg->Show(1);
1768        Wx::Yield();
1769        eval {
1770            $self->imagelist->UploadSelection;
1771        };
1772        if($@){
1773            Wx::MessageBox( 
1774                sprintf(
1775                    gettext("Upload cancelled"),
1776                ),
1777                gettext("Piwigo upload information"),
1778                wxOK | wxICON_INFORMATION, 
1779            );
1780        }
1781    }
1782    else {
1783        Wx::MessageBox( 
1784            sprintf(
1785                "%s %s", 
1786                gettext("Please select a valid target"),
1787                wxTheApp->branding->{category}
1788            ),
1789            gettext("Piwigo upload error"),
1790            wxOK | wxICON_EXCLAMATION, 
1791        );
1792    }
1793}
1794
1795
1796sub SetNewFilesProgress {
1797    my ( $self ) = @_;
1798
1799    my $imagelist = $self->imagelist;
1800
1801    $self->progressdlg->processing(
1802        sprintf(
1803            $imagelist->progress_msg, 
1804            $imagelist->current_image->file,
1805        )
1806    );
1807
1808    eval {
1809        $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]);
1810        $self->progressdlg->image->SetBitmap(wxNullBitmap);
1811        $self->progressdlg->image->SetBitmap(
1812            Wx::Bitmap->new( 
1813                $imagelist->current_image->wx_thumb_file,
1814                $self->GetWxBitmapType( $imagelist->type )
1815            )
1816        );
1817        $self->progressdlg->progress(
1818            $imagelist->count * ( 100/scalar @{$imagelist->new_files} )
1819        );
1820        $self->progressdlg->LogProgress();
1821    };
1822    Wx::Yield();
1823}
1824
1825sub OnClose {
1826  my $self = shift;
1827
1828
1829    # Restaure previous log wnd
1830    Wx::Log::SetActiveTarget( $self->oldlogwnd );
1831
1832    # allways store
1833 
1834    wxTheApp->StoreConnectionProperties;
1835   
1836    $self->imagelist->Store;
1837    wxTheApp->login_dlg->Destroy;       
1838
1839    my $params = {};
1840
1841    ( $params->{'X'}, $params->{'Y'} ) = $self->GetPositionXY ;
1842    ( $params->{'Width'}, $params->{'Height'} ) = $self->GetSizeWH ;
1843    ( $params->{'PreviewWidth'}, $params->{'PreviewHeight'} ) = $self->image_preview->GetSizeWH ;
1844    $params->{Perspective} = $self->manager->SavePerspective;
1845    $params->{ImageviewerIndex} = $self->current_imageviewer_index;
1846   
1847
1848    wxTheApp->SaveConfig( $params );
1849
1850    $self->Destroy;
1851}
1852
1853
1854sub create_toolbar {
1855    my( $self ) = @_;
1856
1857    my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT );
1858    $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) );
1859    map {
1860        my $icon1 = Wx::Icon->new();
1861        eval {
1862            $icon1->LoadFile($_->[2], $_->[3]);
1863        };
1864        my $tb_icon1 = Wx::Bitmap->new( $icon1 );
1865
1866        my $icon2 = Wx::Icon->new();
1867        eval {
1868            $icon2->LoadFile($_->[5], $_->[3]);
1869        };
1870        my $tb_icon2 = Wx::Bitmap->new( $icon2 );
1871
1872
1873        $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[1] );
1874        $tb->EnableTool( $_->[0], $_->[4]);
1875    }
1876    (
1877        [
1878            100, 
1879            gettext("Getting started"), 
1880            '../res/tb_getting_started.png', 
1881            wxBITMAP_TYPE_PNG, 
1882            1, 
1883            '../res/tb_getting_started.png', 
1884            gettext("Display getting started panel")
1885        ],
1886        [
1887            101, 
1888            gettext("Add photo to selection"), 
1889            '../res/tb_add.png', 
1890            wxBITMAP_TYPE_PNG, 
1891            1, 
1892            '../res/tb_add.png', 
1893            gettext("Add photo to selection for resizing and uploading")
1894        ],
1895        [
1896            102, 
1897            gettext("Remove photo from selection"), 
1898            '../res/tb_remove.png', 
1899            wxBITMAP_TYPE_PNG, 
1900            1, 
1901            '../res/tb_remove.png',
1902            gettext("Remove photo from selection. Files are not deleted ")
1903        ],
1904        [
1905            103, 
1906            gettext("Upload to Piwigo"), 
1907            '../res/tb_upload.png', 
1908            wxBITMAP_TYPE_PNG, 
1909            wxTheApp->use_offline ? 0 : 1, 
1910            '../res/tb_upload.png',
1911            gettext("Upload photos to Piwigo.")
1912        ],
1913        [
1914            104, 
1915            gettext("Global settings"), 
1916            '../res/tb_settings.png', 
1917            wxBITMAP_TYPE_PNG, 
1918            0, 
1919            '../res/tb_settings.png',
1920            gettext("Change global settings.")
1921        ],
1922        [
1923            105, 
1924            gettext("Language choice"), 
1925            '../res/tb_i18n.png', 
1926            wxBITMAP_TYPE_PNG, 
1927            1, 
1928            '../res/tb_i18n.png',
1929            gettext("Language choice")
1930        ],
1931   
1932    );
1933
1934    if($@){
1935        undef $tb;
1936    }
1937    else{
1938        $tb->Realize;
1939    }
1940
1941    return $tb;
1942}
1943
1944
1945sub _create_textctrl {
1946    my( $self, $parent, $text, $size ) = @_;
1947
1948    return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size,
1949                              wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY  );
1950}
1951
1952sub create_textctrl {
1953    my( $self, $text, $size ) = @_;
1954
1955    return $self->_create_textctrl( $self, $text, $size );
1956}
1957
1958sub DESTROY {
1959    my( $self ) = @_;
1960
1961    $self->manager->UnInit;
1962}
1963
1964
1965
19661;
1967
1968
1969
1970
1971
1972package DNDImageListDropTarget;
1973
1974use base qw(Wx::FileDropTarget Class::Accessor::Fast);
1975
1976__PACKAGE__->mk_accessors( 
1977    qw/
1978          imageviewer
1979          frame
1980      /
1981);
1982
1983sub new {
1984  my $class = shift;
1985  my $imageviewer = shift;
1986  my $self = $class->SUPER::new( @_ );
1987
1988  $self->imageviewer($imageviewer);
1989  $self->frame($imageviewer->GetParent);
1990  return $self;
1991}
1992
1993sub OnDropFiles {
1994  my( $self, $x, $y, $files ) = @_;
1995
1996  $self->frame->SetNewFiles($files) ;
1997}
1998
1999
2000
2001
20021;
2003
2004
2005package DNDCategoryTreeDropTarget;
2006
2007use base qw(Wx::TextDropTarget Class::Accessor::Fast);
2008use Data::Dumper;
2009use Wx qw/
2010              wxDragNone
2011              wxDragCopy
2012              wxDragMove
2013         /;
2014
2015__PACKAGE__->mk_accessors( 
2016    qw/
2017          tree
2018          frame
2019      /
2020);
2021
2022sub new {
2023  my ( $class, $tree ) = @_;
2024  my $self = $class->SUPER::new();
2025
2026  $self->tree($tree);
2027  $self->frame($tree->GetParent);
2028  return $self;
2029}
2030
2031
2032
2033sub OnDropText {
2034  my( $self, $x, $y, $textdata ) = @_;
2035
2036  # must be $VAR1 because $textdata is the result of Data::Dumper
2037  my $VAR1;
2038  eval $textdata;
2039  eval {
2040      if(scalar @$VAR1){
2041           my @items;
2042           if(scalar @items < 2) {
2043               my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]);
2044                push @items, $dropItem;
2045           }
2046           else {
2047                @items = $self->tree->GetSelections;
2048           }
2049           
2050           # remove root item which is not a valid category
2051           @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items;
2052           
2053           $self->frame->imagelist->categories(
2054               [
2055                   map {
2056                       $self->tree->GetPlData( $_ )->{id};
2057                   }
2058                   @items
2059               ]
2060           );
2061           
2062           $self->frame->imagelist->image_selection($VAR1);
2063           $self->frame->ProcessImageSelection ;
2064      } 
2065  };
2066}
2067
20681;
Note: See TracBrowser for help on using the repository browser.