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

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

Feature 1478 added : ability to set properties for a photo selection.

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