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

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

change icon for checkUpload messages.

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