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

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

Add image file name property.

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