source: extensions/pLoader/trunk/src/Uploader/GUI/wxApp.pm @ 4569

Last change on this file since 4569 was 4569, checked in by ronosman, 14 years ago

Feature 1346 added : new global settings management.

  • Property svn:eol-style set to LF
File size: 25.8 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::wxApp;
21use strict;
22use base qw/Wx::App Class::Accessor::Fast/;   
23use Wx qw/
24             wxBITMAP_TYPE_GIF
25             wxBITMAP_TYPE_ICO
26             wxBITMAP_TYPE_BMP
27             wxBITMAP_TYPE_PNG
28             wxBITMAP_TYPE_JPEG
29             wxIMAGE_QUALITY_NORMAL
30             wxIMAGE_QUALITY_HIGH
31             wxSPLASH_CENTRE_ON_SCREEN
32             wxSPLASH_TIMEOUT
33             wxDefaultPosition
34             wxDefaultSize
35             wxSIMPLE_BORDER
36             wxFRAME_TOOL_WINDOW
37             wxFRAME_NO_TASKBAR wxSTAY_ON_TOP
38             wxWHITE
39             wxICON_EXCLAMATION
40             wxOK
41             wxLANGUAGE_CHINESE_SIMPLIFIED   
42             wxLANGUAGE_CZECH   
43             wxLANGUAGE_DANISH   
44             wxLANGUAGE_DUTCH   
45             wxLANGUAGE_ENGLISH   
46             wxLANGUAGE_FRENCH   
47             wxLANGUAGE_GERMAN   
48             wxLANGUAGE_HUNGARIAN
49             wxLANGUAGE_ITALIAN   
50             wxLANGUAGE_JAPANESE   
51             wxLANGUAGE_POLISH   
52             wxLANGUAGE_PORTUGUESE   
53             wxLANGUAGE_PORTUGUESE_BRAZILIAN   
54             wxLANGUAGE_RUSSIAN   
55             wxLANGUAGE_SLOVAK   
56             wxLANGUAGE_SPANISH   
57         /;
58use Uploader::GUI::wxFrameAUI;
59use File::Slurp ;
60use Data::Dumper;
61use Storable;
62use File::HomeDir;
63use File::Spec;
64use Uploader::PWG;
65use Uploader::ImageList;
66use Uploader::GUI::wxLoginDlg;
67use Wx::Locale qw/:default/;
68use utf8;
69
70$|=1;
71
72__PACKAGE__->mk_accessors( 
73    qw/
74          pwg
75          site_url
76          site_username
77          site_password
78          http_username
79          http_password
80          rejects
81          imagelist
82          storable_file
83          wx_thumb_dir
84          resized_dir
85          userdata_dir
86          resized_dir
87          thumb_dir
88          conf_file
89          layout_file
90          locale
91          current_language
92          languages
93          available_languages
94          version
95          imagelist_version
96          use_offline
97          login_dlg
98          branding
99          frame
100          perspective
101          imageviewerIndex
102          frameLayout
103          chunk_size
104          layout_clean
105          colors
106          eng_colors
107          positions
108          eng_positions
109          default_photo_names
110          eng_default_photo_names
111          upload_hd
112          eng_upload_hd
113          privacy_level
114          user_defined_properties
115      / 
116);
117
118sub FilterEvent {
119    my( $self, $event ) = @_;
120   
121    Wx::LogMessage "EventType %s", $event->GetEventType();
122   
123    return -1;
124}
125
126
127sub OnInit {
128    my( $self ) = @_;
129   
130    $self->version(
131        '2.0.7a'
132    );
133   
134    # to check if we can use stored cache
135    $self->imagelist_version(
136        '11'
137    );
138
139    $self->languages(
140      [
141             ["中文 (%s)", wxLANGUAGE_CHINESE_SIMPLIFIED, 'Chinese simplified'],   
142             ["Česky (%s)", wxLANGUAGE_CZECH, 'Czech'],   
143             ["Dansk (%s)", wxLANGUAGE_DANISH, 'Danish'],   
144             ["Deutsch (%s)", wxLANGUAGE_GERMAN, 'German'],   
145             ["English (%s)", wxLANGUAGE_ENGLISH, 'English'],   
146             ["Español (%s)", wxLANGUAGE_SPANISH, 'Spanish'],   
147             ["Français (%s)", wxLANGUAGE_FRENCH, 'French'],   
148             ["Italiano (%s)", wxLANGUAGE_ITALIAN, 'Italian'],   
149             ["日本語 (にほんご) (%s)", wxLANGUAGE_JAPANESE, 'Japanese'],   
150             ["Magyar (%s)", wxLANGUAGE_HUNGARIAN, 'Hungarian'],
151             ["Nederlands (%s)", wxLANGUAGE_DUTCH, 'Dutch'],   
152             ["Polski (%s)", wxLANGUAGE_POLISH, 'Polish'],   
153             ["Português Brasileiro (%s)", wxLANGUAGE_PORTUGUESE_BRAZILIAN, 'Portuguese Brazil'],   
154             ["Português Portugal (%s)", wxLANGUAGE_PORTUGUESE, 'Portuguese Portugal'],   
155             ["Русский (%s)", wxLANGUAGE_RUSSIAN, 'Russian'],
156             ["Slovenčina (%s)", wxLANGUAGE_SLOVAK, 'Slovak'],
157      ]
158    );
159    # some languages may be unavailable due to system configuration.
160    $self->_filter_available_languages;
161    Wx::InitAllImageHandlers();
162    my $applicationName = "pLoader" ;
163    $self->SetAppName( $applicationName );
164    $self->SetVendorName( "Piwigo Team" );
165
166    $self->{IMGTYPE} = {
167        'jpg' => wxBITMAP_TYPE_JPEG,
168        'gif' => wxBITMAP_TYPE_GIF,
169        'png' => wxBITMAP_TYPE_PNG,
170    };
171
172    $self->_init_userdir;
173
174    my $conf = retrieve $self->conf_file if -e $self->conf_file;       
175
176    if(defined $conf ){
177        $self->SetKeyValues($conf);
178    }
179    else {
180        $self->_readParams( 'pLoader.ini' ) unless defined $conf ;
181    }
182
183    $self->_read_default_user_properties( 'properties.ini' ) ;
184       
185    # when language is switched, need a new layout
186    unlink $self->layout_file if $self->layout_clean;
187    $self->layout_clean(0);
188
189    my $layout = retrieve $self->layout_file if -e $self->layout_file; 
190    if(defined $layout ){
191        $self->SetKeyValues($layout);
192    }
193
194
195    $self->site_url(
196        $self->{site_url}
197    );
198   
199
200    $self->site_username(
201        $self->{site_username}
202    );
203    $self->site_password(
204        $self->{site_password}
205    );
206
207    $self->http_username(
208        $self->{http_username}
209    );
210    $self->http_password(
211        $self->{http_password}
212    );
213
214
215    $self->current_language(
216        $self->{current_language}||Wx::Locale::GetSystemLanguage()
217    );
218
219    $self->chunk_size(
220        $self->{chunk_size}||500_000
221    );
222   
223    $self->init_locale;
224    $self->_init_localized_properties;
225
226    my $not_exit = $self->Login();
227    # user pressed OK
228    if($not_exit){
229        $self->StoreConnectionProperties;
230        if( !$self->use_offline ){
231            while( $not_exit and !$self->_is_connected ){
232                $not_exit = $self->Login();
233                last if $self->use_offline;
234            }
235        }
236        $self->_init_imagelist;
237        $self->_init_thumbimagelist;
238        $self->_init_frame;
239    }
240
241    $not_exit;
242}
243
244# some properties are displayed in choice list, with translated strings
245# the translation has to be reverted to store a language independant value
246sub _init_localized_properties {
247    my ( $self ) = @_;
248
249    $self->colors(
250        ['Black', 'White']
251    );
252    # We need to translate back to english when we store properties
253    $self->eng_colors(
254        {
255            map { gettext($_) => $_ } @{$self->colors} 
256        }
257    );
258    $self->positions(
259        [
260            'Top',
261            'Left',
262            'Right',
263            'Bottom',
264            'Top left',
265            'Top right',
266            'Bottom left',
267            'Bottom right',
268            'Center',
269        ]
270    );
271
272    $self->eng_positions(
273        { 
274             map { gettext($_) => $_ } @{$self->positions} 
275        }
276    );
277       
278        $self->upload_hd(
279            [
280                    'No',
281                        'Yes, use HD resized of the original photo',
282                        'Yes, use a copy of the original photo',
283                ]
284        );
285
286    $self->eng_upload_hd(
287        {
288             map { gettext($_) => $_ } @{$self->upload_hd} 
289        }
290    );
291       
292    $self->default_photo_names(
293        [
294             'None',
295             'File name',
296             'File path and name',
297             'Prefix',
298             'Prefix + rank number',
299             'Rank number + prefix',
300             'Prefix + create date chrono',
301             'Create date chrono + prefix',
302        ]
303    );
304    $self->eng_default_photo_names(
305        {
306             map { gettext($_) => $_ } @{$self->default_photo_names} 
307        }
308    );
309       
310        # hard coded because the piwigo api to read custom privacy level is not yet available
311        $self->privacy_level(
312            [
313                    'everybody',
314                        'contacts',
315                        'friends',
316                        'family',
317                        'admins'
318                ]
319        );
320
321       
322}
323
324# display privacy level list in a pyramid way :
325# ['everybody', 'contacts', friends, family, admins] -> [everybody, 'contacts, friends, family, admins', 'friends, family, admins', 'family, admins', 'admins only' ]
326sub privacy_level_choices{
327    my ( $self ) = @_;
328
329    my $pl = $self->privacy_level;     
330    my $n = scalar @$pl - 1;
331    my $list = [ gettext($pl->[0]) ];
332    my $i=0;
333    while(++$i<$n){   
334        push @$list, join(
335                    ', ', 
336                        map{ gettext($_) }
337                        @$pl[$i..$n] 
338                );
339    }
340    push @$list, gettext($pl->[$n]);
341       
342        $list;
343}
344
345sub _filter_available_languages {
346    my ( $self ) = @_;
347
348    # check if the locale can be set and the translation catalog available
349    $self->available_languages(
350        [
351            grep {$_} 
352            map{
353                            #  a locale may be unavailable due to system limitations ( ex: chinese, japanese when language pack are not installed )
354                            if(Wx::Locale::IsAvailable($_->[1])){
355                            my $locale = Wx::Locale->new($_->[1]);
356                            $locale->AddCatalogLookupPathPrefix('../locale');
357                            $_ if $locale->AddCatalog('pLoader');
358                                }
359            }
360            @{$self->languages}
361        ]
362    );
363}
364
365sub _is_connected {
366    my ( $self ) = @_;
367
368    my $is_connected;
369
370    if($self->pwg->login_result->{stat} eq 'ok'){
371        $is_connected = 1;
372    }
373    else{
374        Wx::MessageBox( 
375            sprintf(
376                "%s\n\n%s %s %s",
377                $self->pwg->login_result->{message},
378                gettext("Connection to"),
379                $self->site_url,
380                gettext("failed"),
381            ),
382            gettext("Piwigo login error"),
383            wxOK | wxICON_EXCLAMATION, 
384        );
385    }
386   
387    $is_connected;
388}
389
390
391my $locale;
392sub init_locale {
393    my ( $self, $language ) = @_;
394   
395    $self->current_language(
396        $language
397    ) if defined $language;
398
399    undef $locale;
400    $locale = Wx::Locale->new(
401        $self->current_language
402    );
403    $locale->AddCatalogLookupPathPrefix( '../locale');
404    if(!$locale->AddCatalog( 'pLoader.mo' )){
405        Wx::LogMessage gettext("Cannot find translation catalog files for %s. Use default language"), $locale->GetCanonicalName();
406    }
407    $self->locale($locale);     
408}
409
410sub StoreConnectionProperties {
411    my ( $self ) = @_;
412
413    eval {   
414        store( 
415            {
416                map{
417                   $_ => $self->{$_},
418                }
419                qw/
420                    site_url
421                    site_username
422                    site_password
423                    http_username
424                    http_password
425                    current_language
426                    chunk_size
427                    layout_clean
428                /
429            },
430            $self->conf_file
431        );
432    };
433}
434
435sub StoreLayoutProperties {
436    my ( $self ) = @_;
437
438    eval {   
439        store( 
440            {
441                map{
442                   $_ => $self->{$_},
443                }
444                qw/
445                      perspective
446                      imageviewerIndex
447                      frameLayout
448                /
449            },
450            $self->layout_file
451        );
452    };
453}
454
455sub _init_imagelist {
456    my ( $self ) = @_; 
457
458    my $stored_imagelist;
459   
460    my $use_new_imagelist;
461   
462    if( -e $self->storable_file ){
463        eval {
464            $stored_imagelist = retrieve $self->storable_file;
465        };
466        if($@){
467            Wx::LogMessage(
468                gettext("An error has occured. Can not read %s\n%s"),
469                $self->storable_file, 
470                $@
471            );
472            $use_new_imagelist = 1 ;
473        }
474        # should have a valid imagelist
475        else{
476            $use_new_imagelist = 1 unless $self->imagelist_version eq $stored_imagelist->{imagelist_version};
477            if($use_new_imagelist){
478                Wx::LogMessage(gettext("pLoader has to reset image cache."));
479            }
480        }
481    }
482    else{
483        $use_new_imagelist = 1 ;
484    }
485
486    if($use_new_imagelist){
487        $stored_imagelist = $self->_default_imagelist_params ;
488    }
489
490
491    $self->imagelist(
492        Uploader::ImageList->new(
493            $stored_imagelist
494        )
495    );
496
497    $self->imagelist->SetCurrentImage(-1);
498
499    $self->imagelist->RescaleCallback(
500        sub { $self->RescaleImage(@_) }
501    );
502
503    $self->imagelist->ResizeCallback(
504        sub { $self->ResizeImage(@_) }
505    );
506
507    $self->imagelist->YieldCallback(
508        sub { Wx::Yield }
509    );
510}
511
512
513sub _default_imagelist_params {
514    my ( $self ) = @_ ;
515
516    my $params = {
517        new_files        => [],
518        hd_filter        => $self->user_defined_properties->{hd_filter}||'Lanczos',
519        hd_blur          => $self->user_defined_properties->{hd_blur}||0.9,
520        hd_quality       => $self->user_defined_properties->{hd_quality}||95,
521        hd_w             => $self->user_defined_properties->{hd_w}||1600,
522        hd_h             => $self->user_defined_properties->{hd_h}||1200,
523        hd_interlace     => $self->user_defined_properties->{hd_interlace}||'Line',
524        thumb_size       => $self->user_defined_properties->{thumbnail_size}||120,
525        site_thumb_dir   => $self->thumb_dir,
526        wx_thumb_size    => $self->user_defined_properties->{wx_thumbnail_size}||100,
527        wx_thumb_dir     => $self->wx_thumb_dir,
528        resize_w         => $self->user_defined_properties->{resize_w}||800,
529        resize_h         => $self->user_defined_properties->{resize_h}||600,
530        site_resized_dir => $self->resized_dir,
531        type             => 'jpg',
532        filter           => $self->user_defined_properties->{resize_filter}||'Lanczos',
533        blur             => $self->user_defined_properties->{resize_blur}||0.9,
534        quality          => $self->user_defined_properties->{resize_quality}||95,
535        wx_quality       => $self->user_defined_properties->{wx_thumbnail_quality}||90,
536        th_quality       => $self->user_defined_properties->{thumbnail_quality}||90,
537        auto_rotate      => $self->user_defined_properties->{auto_rotate}||1,
538        upload_hd        => $self->user_defined_properties->{upload_hd}||'No',
539        remove_uploaded_from_selection => $self->user_defined_properties->{remove_uploaded_from_selection}||1,
540        interlace        => $self->user_defined_properties->{resize_interlace}||'Line',
541        create_resized   => $self->user_defined_properties->{create_resized}||1,
542        prefix           => 'TN',
543        count            => 0,
544        storable_file    => $self->storable_file,
545        userdata_dir     => $self->userdata_dir,
546        default_photo_name => $self->user_defined_properties->{default_photo_name}||'File name',
547        default_name_prefix => $self->user_defined_properties->{default_name_prefix}||gettext('Photo '),
548        upload_rejects   =>  [],
549        image_sums       => {},
550        sums             => [],
551        version          => $self->version,
552        imagelist_version => $self->imagelist_version,
553        RescaleCallback  => sub { $self->RescaleImage(@_) },
554        ResizeCallback   => sub { $self->ResizeImage(@_) },
555        watermark_text => $self->user_defined_properties->{watermark_text}||gettext("my watermark"),
556        watermark_text_size => $self->user_defined_properties->{watermark_text_size}||12,
557        watermark_position => $self->user_defined_properties->{watermark_position}||'Center',
558        watermark_y => $self->user_defined_properties->{watermark_y}||10,
559        watermark_x => $self->user_defined_properties->{watermark_x}||10,
560        watermark_color => $self->user_defined_properties->{watermark_color}||'White',
561        reupload_action_files => 1,
562        reupload_action_properties => 2,
563        reupload_action_properties_m => 1,
564        display_mode => $self->user_defined_properties->{display_mode}||'Thumbnail and caption',
565    };
566
567    return $params;
568}
569
570sub Login {
571    my ( $self ) = @_; 
572
573    $self->login_dlg( 
574        Uploader::GUI::wxLoginDlg->new(
575            {
576                title         => gettext("Piwigo login"),
577                site_url      => sub { $self->site_url(@_) },
578                site_username => sub { $self->site_username(@_) },     
579                site_password => sub { $self->site_password(@_) },
580                use_offline   => sub { $self->use_offline(@_) },       
581            }
582        )
583    ) unless $self->login_dlg;
584
585    my $icon = Wx::Icon->new();
586    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
587    $self->login_dlg->SetIcon($icon);   
588
589   
590    my $rval = $self->login_dlg->ShowModal();
591    $self->login_dlg->Show(0);
592
593    $self->_init_branding;
594   
595    if ($self->site_url !~ /^http:/){
596        $self->site_url(
597            sprintf(
598                "http://%s",
599                $self->site_url
600            )
601        );     
602    }
603
604    $self->pwg(
605        # get these parameters from dialog or from file
606        Uploader::PWG->new(
607            {
608                site_url       => $self->site_url,
609                site_username  => $self->site_username,
610                site_password  => $self->site_password,
611                http_username  => $self->http_username,
612                http_password  => $self->http_password,
613                branding       => $self->branding,
614                chunk_size     => $self->chunk_size,
615                use_offline    => $self->use_offline,
616                version        => $self->version,
617            }
618        )
619    );
620
621    $rval;
622}
623
624sub _init_userdir {
625    my ( $self ) = @_;
626   
627    my $applicationName = $self->GetAppName ;
628    my $userdatadir = File::Spec->canonpath(
629        File::Spec->catfile(
630            File::HomeDir->my_data(), 
631            "\.$applicationName"
632        )
633    );
634
635    if(! -d $userdatadir){
636        if(! mkdir $userdatadir){
637            Wx::MessageBox( 
638                sprintf(
639                    "%s directory creation failed",
640                    $userdatadir,
641                ),
642                "pLoader working directory creation error",
643                wxOK | wxICON_EXCLAMATION, 
644            );
645
646            $userdatadir = File::Spec->canonpath(
647                File::Spec->catfile(
648                    File::Spec->tmpdir(), 
649                    "\.$applicationName"
650                )
651            );
652            mkdir $userdatadir;
653        }       
654    }
655
656    $self->userdata_dir($userdatadir);
657   
658    $self->conf_file(
659        File::Spec->catfile(
660            $self->userdata_dir, 
661            ".$applicationName.conf"
662        )
663    );
664
665    $self->layout_file(
666        File::Spec->catfile(
667            $self->userdata_dir, 
668            ".$applicationName.layout"
669        )
670    );
671
672    $self->storable_file(
673        File::Spec->catfile($self->userdata_dir, 'pLoader.dat')
674    );
675   
676    my $thumbdir = File::Spec->catfile($self->userdata_dir, 'thumbnails');
677    mkdir $thumbdir unless -d $thumbdir ;
678    $self->thumb_dir($thumbdir);
679
680    my $wxthumbdir = File::Spec->catfile($self->userdata_dir, 'wxthumbnails');
681    mkdir $wxthumbdir unless -d $wxthumbdir ;
682    $self->wx_thumb_dir($wxthumbdir);
683
684
685    my $resizedir = File::Spec->catfile($self->userdata_dir, 'resize');
686    mkdir $resizedir unless -d $resizedir ;
687    $self->resized_dir($resizedir);
688}
689
690sub _init_thumbimagelist {
691    my ( $self ) = @_;
692
693   
694    $self->imagelist->wx_thumb_imglist(
695        Wx::ImageList->new( 
696            $self->imagelist->wx_thumb_size, 
697            $self->imagelist->wx_thumb_size, 
698            0,
699            0
700        )
701    );
702   
703    # reload images
704    $self->_reload_thumb_images;
705}
706
707
708sub _reload_thumb_images {
709    my ( $self ) = @_;
710   
711    my $wximagelist = $self->imagelist->wx_thumb_imglist;
712    my $sums = $self->imagelist->sums;
713
714    map {
715        my $image = $self->imagelist->image_sums->{$_};
716
717        $wximagelist->Add(
718            Wx::Bitmap->new( 
719                $image->wx_thumb_file, 
720                $self->GetWxBitmapType($self->imagelist->type), 
721            )
722        );
723    }
724    @$sums ;
725
726}
727
728sub GetWxBitmapType {
729    my ( $self, $type ) = @_;
730   
731    $self->{IMGTYPE}->{$type};
732}
733
734
735sub RescaleImage {
736    my ( $self, $image_file, $image_file_out, $type, $ratio, $width, $height, $quality ) = @_;
737   
738
739    my $image = Wx::Image->new(
740            $image_file, 
741            $self->GetWxBitmapType($type),
742            0
743    );
744   
745    my $w;
746    my $h;
747
748    my $img_w = $image->GetWidth;
749    my $img_h = $image->GetHeight;
750   
751    # use a ratio ( 25% default ) if defined
752    # default ratio is used for preview.
753    if($ratio){
754        $w = $ratio*$img_w/100 ;
755        $h = $ratio*$img_h/100 ;
756    }
757    # use specified width and height
758    else{
759        # portrait
760        if( $img_w < $img_h ){
761            $w = $height;
762        }
763        else{
764            $w = $width;
765        }
766        # to respect aspect ratio
767        $h = sprintf(
768            "%.0f",
769            ($w*$img_h)/$img_w
770        );
771    }
772
773    $image->Rescale(
774        $w,
775        $h,
776        wxIMAGE_QUALITY_HIGH
777    );
778   
779    $quality ||= 90;
780   
781    $image->SetOption( 
782        "quality", 
783        $quality 
784    );
785   
786    if(!$image->SaveFile(
787        $image_file_out,
788        $self->GetWxBitmapType($type),
789    )){
790        Wx::LogMessage(
791            gettext("An error has occured. Can not save file %s"),
792            $image_file_out,
793        )
794    };
795}
796
797sub ResizeImage {
798    my ( $self, $image_file, $image_file_out, $type, $width, $height, $quality ) = @_;
799   
800
801    my $image = Wx::Image->new(
802            $image_file, 
803            $self->GetWxBitmapType($type),
804            0
805    );
806
807    my $w;
808    my $h;
809
810    my $img_w = $image->GetWidth;
811    my $img_h = $image->GetHeight;
812   
813        # portrait
814        if( $img_w < $img_h ){
815            $w = $height;
816        }
817        else{
818            $w = $width;
819        }
820        # to respect aspect ratio
821        $h = sprintf(
822            "%.0f",
823            ($w*$img_h)/$img_w
824        );
825
826   
827
828    $image->Rescale(
829        $w,
830        $h,
831        wxIMAGE_QUALITY_HIGH
832    );
833
834    $image->Resize(
835        [ $width, $height ], [ 0, 20],
836    );
837   
838    $quality ||= 90;
839   
840    $image->SetOption( 
841        "quality", 
842        $quality 
843    );
844   
845    if(!$image->SaveFile(
846        $image_file_out,
847        $self->GetWxBitmapType($type),
848    )){
849        Wx::LogMessage(
850            gettext("An error has occured. Can not save file %s"),
851            $image_file_out,
852        )
853    };
854}
855
856# some labels differ with branding ( piwigo.com or piwigo.org )
857sub _init_branding {
858    my ( $self ) =@_;
859   
860    if( $self->site_url =~ /\.piwigo\.com/ ){
861        $self->branding(
862            {
863                category  => gettext("album"), 
864                Category  => gettext("Album"), 
865                categories => gettext("albums"),       
866                Categories => gettext("Albums"),
867                'Add new category' => gettext("Add new album"), 
868                'Category name' => gettext("Album name :"),
869                'New category' => gettext("New album"),
870            }
871        );
872    }
873    else{
874        $self->branding(
875            {
876                category  => gettext("categorie"),     
877                Category  => gettext("Categorie"),     
878                categories => gettext("categories"),   
879                Categories => gettext("Categories"),   
880                'Add new category' => gettext("Add new category"),
881                'Category name' => gettext("Category name :"),
882                'New category' => gettext("New category"),
883            }
884        );
885    }   
886}
887
888sub SaveConfig {
889    my ( $self, $params ) = @_; 
890
891   my $config = Wx::ConfigBase::Get;
892
893   map {
894       $config->WriteInt( $_, $params->{$_} )
895   } keys %$params;
896
897   $config->Write( 'Perspective', $params->{Perspective} )
898       
899}
900
901
902sub _init_frame {
903    my ( $self ) = @_; 
904
905    my $url = $self->site_url;
906   
907    if($self->use_offline){
908        $url = gettext("Work Offline");
909    }
910
911    $self->frame(
912        Uploader::GUI::wxFrameAUI->new( 
913            {
914                title     => sprintf("pLoader - Piwigo uploader %s - [%s]", $self->version, $url),
915                pwg       => $self->pwg,
916                imagelist => $self->imagelist,
917                perspective => $self->perspective,
918                imageviewer_index => $self->imageviewerIndex,
919                frameLayout => $self->frameLayout,
920            }
921        )
922    );
923 
924    $self->frame->Show( 1 );
925    $self->SetTopWindow( $self->frame );
926
927    my $icon = Wx::Icon->new();
928    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
929    $self->frame->SetIcon($icon);       
930}
931
932sub _readParams {
933        my( $self, $file ) = @_ ;
934
935
936        my $expr_params ;
937        eval { $expr_params = read_file( $file ); } ;
938       
939        my $paramValues = [] ;
940        if($expr_params){
941                my $expr = '$paramValues = ' ;
942                $expr .=  "$expr_params ; " ;
943                eval $expr ;
944        }
945       
946        return unless 'ARRAY' eq ref $paramValues ;
947       
948        if(scalar(@$paramValues )){
949            my $params = $paramValues->[0] ;
950            $self->SetKeyValues($params);
951        }
952}
953
954sub _read_default_user_properties {
955        my( $self, $file ) = @_ ;
956
957
958        my $expr_params ;
959        eval { $expr_params = read_file( $file ); } ;
960        my $properties;
961        if($expr_params){
962                my $expr = '$properties = ' ;
963                $expr .=  " { $expr_params }; " ;
964                eval $expr ;
965        }
966        $properties = {} unless 'HASH' eq ref $properties;
967        $self->user_defined_properties($properties);
968
969}
970
971
972
973sub SetKeyValues {
974    my ( $self, $params )= @_; 
975
976    foreach( keys %$params ) {
977        $self->{$_} = $params->{$_} ;
978    }
979}
980
981
9821;
Note: See TracBrowser for help on using the repository browser.