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

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

Feature 1414 added : new improved layout for photo properties panel.

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