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

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

Refactor context menu item initialization.

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