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

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

Feature 1320 added : add privacy level in photo properties.

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