source: extras/pLoader/trunk/src/Uploader/GUI/wxApp.pm @ 3284

Last change on this file since 3284 was 3284, checked in by ronosman, 15 years ago

Feature 994 added : gui layout management. Use perspective to save/reload gui layout.

  • Property svn:eol-style set to LF
File size: 25.9 KB
RevLine 
[2597]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
[2661]29             wxIMAGE_QUALITY_NORMAL
30             wxIMAGE_QUALITY_HIGH
[2597]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
[2618]39             wxICON_EXCLAMATION
40             wxOK
[3159]41             wxLANGUAGE_ABKHAZIAN   
42             wxLANGUAGE_AFAR   
43             wxLANGUAGE_AFRIKAANS   
44             wxLANGUAGE_ALBANIAN   
45             wxLANGUAGE_AMHARIC   
46             wxLANGUAGE_ARABIC   
47             wxLANGUAGE_ARABIC_ALGERIA   
48             wxLANGUAGE_ARABIC_BAHRAIN   
49             wxLANGUAGE_ARABIC_EGYPT   
50             wxLANGUAGE_ARABIC_IRAQ   
51             wxLANGUAGE_ARABIC_JORDAN   
52             wxLANGUAGE_ARABIC_KUWAIT   
53             wxLANGUAGE_ARABIC_LEBANON   
54             wxLANGUAGE_ARABIC_LIBYA   
55             wxLANGUAGE_ARABIC_MOROCCO   
56             wxLANGUAGE_ARABIC_OMAN   
57             wxLANGUAGE_ARABIC_QATAR   
58             wxLANGUAGE_ARABIC_SAUDI_ARABIA   
59             wxLANGUAGE_ARABIC_SUDAN   
60             wxLANGUAGE_ARABIC_SYRIA   
61             wxLANGUAGE_ARABIC_TUNISIA   
62             wxLANGUAGE_ARABIC_UAE   
63             wxLANGUAGE_ARABIC_YEMEN   
64             wxLANGUAGE_ARMENIAN   
65             wxLANGUAGE_ASSAMESE   
66             wxLANGUAGE_AYMARA   
67             wxLANGUAGE_AZERI   
68             wxLANGUAGE_AZERI_CYRILLIC   
69             wxLANGUAGE_AZERI_LATIN   
70             wxLANGUAGE_BASHKIR   
71             wxLANGUAGE_BASQUE   
72             wxLANGUAGE_BELARUSIAN   
73             wxLANGUAGE_BENGALI   
74             wxLANGUAGE_BHUTANI   
75             wxLANGUAGE_BIHARI   
76             wxLANGUAGE_BISLAMA   
77             wxLANGUAGE_BRETON   
78             wxLANGUAGE_BULGARIAN   
79             wxLANGUAGE_BURMESE   
80             wxLANGUAGE_CAMBODIAN   
81             wxLANGUAGE_CATALAN   
82             wxLANGUAGE_CHINESE   
83             wxLANGUAGE_CHINESE_SIMPLIFIED   
84             wxLANGUAGE_CHINESE_TRADITIONAL   
85             wxLANGUAGE_CHINESE_HONGKONG   
86             wxLANGUAGE_CHINESE_MACAU   
87             wxLANGUAGE_CHINESE_SINGAPORE   
88             wxLANGUAGE_CHINESE_TAIWAN   
89             wxLANGUAGE_CORSICAN   
90             wxLANGUAGE_CROATIAN   
91             wxLANGUAGE_CZECH   
92             wxLANGUAGE_DANISH   
93             wxLANGUAGE_DUTCH   
94             wxLANGUAGE_DUTCH_BELGIAN   
95             wxLANGUAGE_ENGLISH   
96             wxLANGUAGE_ENGLISH_UK   
97             wxLANGUAGE_ENGLISH_US   
98             wxLANGUAGE_ENGLISH_AUSTRALIA   
99             wxLANGUAGE_ENGLISH_BELIZE   
100             wxLANGUAGE_ENGLISH_BOTSWANA   
101             wxLANGUAGE_ENGLISH_CANADA   
102             wxLANGUAGE_ENGLISH_CARIBBEAN   
103             wxLANGUAGE_ENGLISH_DENMARK   
104             wxLANGUAGE_ENGLISH_EIRE   
105             wxLANGUAGE_ENGLISH_JAMAICA   
106             wxLANGUAGE_ENGLISH_NEW_ZEALAND   
107             wxLANGUAGE_ENGLISH_PHILIPPINES   
108             wxLANGUAGE_ENGLISH_SOUTH_AFRICA   
109             wxLANGUAGE_ENGLISH_TRINIDAD   
110             wxLANGUAGE_ENGLISH_ZIMBABWE   
111             wxLANGUAGE_ESPERANTO   
112             wxLANGUAGE_ESTONIAN   
113             wxLANGUAGE_FAEROESE   
114             wxLANGUAGE_FARSI   
115             wxLANGUAGE_FIJI   
116             wxLANGUAGE_FINNISH   
117             wxLANGUAGE_FRENCH   
118             wxLANGUAGE_FRENCH_BELGIAN   
119             wxLANGUAGE_FRENCH_CANADIAN   
120             wxLANGUAGE_FRENCH_LUXEMBOURG   
121             wxLANGUAGE_FRENCH_MONACO   
122             wxLANGUAGE_FRENCH_SWISS   
123             wxLANGUAGE_FRISIAN   
124             wxLANGUAGE_GALICIAN   
125             wxLANGUAGE_GEORGIAN   
126             wxLANGUAGE_GERMAN   
127             wxLANGUAGE_GERMAN_AUSTRIAN   
128             wxLANGUAGE_GERMAN_BELGIUM   
129             wxLANGUAGE_GERMAN_LIECHTENSTEIN   
130             wxLANGUAGE_GERMAN_LUXEMBOURG   
131             wxLANGUAGE_GERMAN_SWISS   
132             wxLANGUAGE_GREEK   
133             wxLANGUAGE_GREENLANDIC   
134             wxLANGUAGE_GUARANI   
135             wxLANGUAGE_GUJARATI   
136             wxLANGUAGE_HAUSA   
137             wxLANGUAGE_HEBREW   
138             wxLANGUAGE_HINDI   
139             wxLANGUAGE_HUNGARIAN   
140             wxLANGUAGE_ICELANDIC   
141             wxLANGUAGE_INDONESIAN   
142             wxLANGUAGE_INTERLINGUA   
143             wxLANGUAGE_INTERLINGUE   
144             wxLANGUAGE_INUKTITUT   
145             wxLANGUAGE_INUPIAK   
146             wxLANGUAGE_IRISH   
147             wxLANGUAGE_ITALIAN   
148             wxLANGUAGE_ITALIAN_SWISS   
149             wxLANGUAGE_JAPANESE   
150             wxLANGUAGE_JAVANESE   
151             wxLANGUAGE_KANNADA   
152             wxLANGUAGE_KASHMIRI   
153             wxLANGUAGE_KASHMIRI_INDIA   
154             wxLANGUAGE_KAZAKH   
155             wxLANGUAGE_KERNEWEK   
156             wxLANGUAGE_KINYARWANDA   
157             wxLANGUAGE_KIRGHIZ   
158             wxLANGUAGE_KIRUNDI   
159             wxLANGUAGE_KONKANI   
160             wxLANGUAGE_KOREAN   
161             wxLANGUAGE_KURDISH   
162             wxLANGUAGE_LAOTHIAN   
163             wxLANGUAGE_LATIN   
164             wxLANGUAGE_LATVIAN   
165             wxLANGUAGE_LINGALA   
166             wxLANGUAGE_LITHUANIAN   
167             wxLANGUAGE_MACEDONIAN   
168             wxLANGUAGE_MALAGASY   
169             wxLANGUAGE_MALAY   
170             wxLANGUAGE_MALAYALAM   
171             wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM   
172             wxLANGUAGE_MALAY_MALAYSIA   
173             wxLANGUAGE_MALTESE   
174             wxLANGUAGE_MANIPURI   
175             wxLANGUAGE_MAORI   
176             wxLANGUAGE_MARATHI   
177             wxLANGUAGE_MOLDAVIAN   
178             wxLANGUAGE_MONGOLIAN   
179             wxLANGUAGE_NAURU   
180             wxLANGUAGE_NEPALI   
181             wxLANGUAGE_NEPALI_INDIA   
182             wxLANGUAGE_NORWEGIAN_BOKMAL   
183             wxLANGUAGE_NORWEGIAN_NYNORSK   
184             wxLANGUAGE_OCCITAN   
185             wxLANGUAGE_ORIYA   
186             wxLANGUAGE_OROMO   
187             wxLANGUAGE_PASHTO   
188             wxLANGUAGE_POLISH   
189             wxLANGUAGE_PORTUGUESE   
190             wxLANGUAGE_PORTUGUESE_BRAZILIAN   
191             wxLANGUAGE_PUNJABI   
192             wxLANGUAGE_QUECHUA   
193             wxLANGUAGE_RHAETO_ROMANCE   
194             wxLANGUAGE_ROMANIAN   
195             wxLANGUAGE_RUSSIAN   
196             wxLANGUAGE_RUSSIAN_UKRAINE   
197             wxLANGUAGE_SAMI   
198             wxLANGUAGE_SAMOAN   
199             wxLANGUAGE_SANGHO   
200             wxLANGUAGE_SANSKRIT   
201             wxLANGUAGE_SCOTS_GAELIC   
202             wxLANGUAGE_SERBIAN   
203             wxLANGUAGE_SERBIAN_CYRILLIC   
204             wxLANGUAGE_SERBIAN_LATIN   
205             wxLANGUAGE_SERBO_CROATIAN   
206             wxLANGUAGE_SESOTHO   
207             wxLANGUAGE_SETSWANA   
208             wxLANGUAGE_SHONA   
209             wxLANGUAGE_SINDHI   
210             wxLANGUAGE_SINHALESE   
211             wxLANGUAGE_SISWATI   
212             wxLANGUAGE_SLOVAK   
213             wxLANGUAGE_SLOVENIAN   
214             wxLANGUAGE_SOMALI   
215             wxLANGUAGE_SPANISH   
216             wxLANGUAGE_SPANISH_ARGENTINA   
217             wxLANGUAGE_SPANISH_BOLIVIA   
218             wxLANGUAGE_SPANISH_CHILE   
219             wxLANGUAGE_SPANISH_COLOMBIA   
220             wxLANGUAGE_SPANISH_COSTA_RICA   
221             wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC   
222             wxLANGUAGE_SPANISH_ECUADOR   
223             wxLANGUAGE_SPANISH_EL_SALVADOR   
224             wxLANGUAGE_SPANISH_GUATEMALA   
225             wxLANGUAGE_SPANISH_HONDURAS   
226             wxLANGUAGE_SPANISH_MEXICAN   
227             wxLANGUAGE_SPANISH_MODERN   
228             wxLANGUAGE_SPANISH_NICARAGUA   
229             wxLANGUAGE_SPANISH_PANAMA   
230             wxLANGUAGE_SPANISH_PARAGUAY   
231             wxLANGUAGE_SPANISH_PERU   
232             wxLANGUAGE_SPANISH_PUERTO_RICO   
233             wxLANGUAGE_SPANISH_URUGUAY   
234             wxLANGUAGE_SPANISH_US   
235             wxLANGUAGE_SPANISH_VENEZUELA   
236             wxLANGUAGE_SUNDANESE   
237             wxLANGUAGE_SWAHILI   
238             wxLANGUAGE_SWEDISH   
239             wxLANGUAGE_SWEDISH_FINLAND   
240             wxLANGUAGE_TAGALOG   
241             wxLANGUAGE_TAJIK   
242             wxLANGUAGE_TAMIL   
243             wxLANGUAGE_TATAR   
244             wxLANGUAGE_TELUGU   
245             wxLANGUAGE_THAI   
246             wxLANGUAGE_TIBETAN   
247             wxLANGUAGE_TIGRINYA   
248             wxLANGUAGE_TONGA   
249             wxLANGUAGE_TSONGA   
250             wxLANGUAGE_TURKISH   
251             wxLANGUAGE_TURKMEN   
252             wxLANGUAGE_TWI   
253             wxLANGUAGE_UIGHUR   
254             wxLANGUAGE_UKRAINIAN   
255             wxLANGUAGE_URDU   
256             wxLANGUAGE_URDU_INDIA   
257             wxLANGUAGE_URDU_PAKISTAN   
258             wxLANGUAGE_UZBEK   
259             wxLANGUAGE_UZBEK_CYRILLIC   
260             wxLANGUAGE_UZBEK_LATIN   
261             wxLANGUAGE_VALENCIAN   
262             wxLANGUAGE_VIETNAMESE   
263             wxLANGUAGE_VOLAPUK   
264             wxLANGUAGE_WELSH   
265             wxLANGUAGE_WOLOF   
266             wxLANGUAGE_XHOSA   
267             wxLANGUAGE_YIDDISH   
268             wxLANGUAGE_YORUBA   
269             wxLANGUAGE_ZHUANG   
270             wxLANGUAGE_ZULU 
[2597]271         /;
272use Uploader::GUI::wxFrameAUI;
[3140]273use File::Slurp ;
[2597]274use Data::Dumper;
275use Storable;
276use File::HomeDir;
277use File::Spec;
278use Uploader::PWG;
279use Uploader::ImageList;
280use Uploader::GUI::wxLoginDlg;
[3159]281use Wx::Locale qw/:default/;
[2618]282
[3140]283
[2597]284$|=1;
285
286__PACKAGE__->mk_accessors( 
287    qw/
288          pwg
289          site_url
290          site_username
291          site_password
292          rejects
293          imagelist
294          storable_file
295          wx_thumb_dir
296          resized_dir
297          preview_dir
298          userdata_dir
299          resized_dir
300          thumb_dir
301          conf_file
[3159]302          locale
303          current_language
[3227]304          version
305          imagelist_version
306          use_offline
307          login_dlg
[3284]308          branding
[2597]309      / 
310);
311
312sub FilterEvent {
313    my( $self, $event ) = @_;
314   
315    Wx::LogMessage "EventType %s", $event->GetEventType();
316   
317    return -1;
318}
319
[3227]320
[2597]321sub OnInit {
322    my( $self ) = @_;
[3227]323   
324    $self->version(
[3267]325        '2.0.2a'
[3227]326    );
327   
328    # to check if we can use stored cache
329    $self->imagelist_version(
[3267]330        '3'
[3227]331    );
[2597]332
333    Wx::InitAllImageHandlers();
334    my $applicationName = "pLoader" ;
335    $self->SetAppName( $applicationName );
336    $self->SetVendorName( "Piwigo Team" );
337
338    $self->{IMGTYPE} = {
339        'jpg' => wxBITMAP_TYPE_JPEG,
340        'gif' => wxBITMAP_TYPE_GIF,
341        'png' => wxBITMAP_TYPE_PNG,
342    };
343
344    $self->_init_userdir;
345
346
347    my $conf = retrieve $self->conf_file if -e $self->conf_file;       
348
349    if(defined $conf ){
350        $self->SetKeyValues($conf);
351    }
352    else {
353        $self->_readParams( 'pLoader.ini' ) unless defined $conf ;
354    }
355
[3159]356
[2597]357    $self->site_url(
358        $self->{site_url}
359    );
[3284]360   
[2597]361
362    $self->site_username(
363        $self->{site_username}
364    );
365    $self->site_password(
366        $self->{site_password}
367    );
[3159]368    $self->current_language(
369        $self->{current_language}||wxLANGUAGE_ENGLISH
370    );
[2597]371   
[3159]372    $self->init_locale;
[2597]373
[3227]374    my $not_exit = $self->Login();
[2618]375    # user pressed OK
[3227]376    if($not_exit){
377        if( !$self->use_offline ){
378            while( $not_exit and !$self->_is_connected ){
379                $not_exit = $self->Login();
[3232]380                last if $self->use_offline;
[3227]381            }
382        }
[2618]383        $self->_init_imagelist;
384        $self->_init_thumbimagelist;
385        $self->_init_frame;
[2597]386    }
387
[3227]388    $not_exit;
[2597]389}
390
[3227]391
392sub _is_connected {
393    my ( $self ) = @_;
394
395    my $is_connected;
396
397    if($self->pwg->login_result->{stat} eq 'ok'){
398        $is_connected = 1;
399    }
400    else{
401        Wx::MessageBox( 
402            sprintf(
403                "%s\n\n%s %s %s",
404                $self->pwg->login_result->{message},
405                gettext("Connection to"),
406                $self->site_url,
407                gettext("failed"),
408            ),
409            gettext("Piwigo login error"),
410            wxOK | wxICON_EXCLAMATION, 
411        );
412    }
413   
414    $is_connected;
415}
416
417
[3159]418my $locale;
419sub init_locale {
420    my ( $self, $language ) = @_;
421   
422    $self->current_language(
423        $language
424    ) if defined $language;
425
426    undef $locale;
427    $locale = Wx::Locale->new(
428        $self->current_language
429    );
430    $locale->AddCatalogLookupPathPrefix( '../locale');
[3178]431    if(!$locale->AddCatalog( 'pLoader.mo' )){
[3227]432        Wx::LogMessage gettext("Cannot find translation catalog files. Use default language");
[3159]433    }
434       
435}
436
[2597]437sub StoreConnectionProperties {
438    my ( $self ) = @_;
439
440    eval {   
441        store( 
442            {
443                map{
444                   $_ => $self->{$_},
445                }
446                qw/
447                    site_url
448                    site_username
449                    site_password
[3159]450                    current_language
[2597]451                /
452            },
453            $self->conf_file
454        );
455    };
456}
457
458sub _init_imagelist {
459    my ( $self ) = @_; 
460
461    my $stored_imagelist;
462   
[3227]463    my $use_new_imagelist;
464   
[2597]465    if( -e $self->storable_file ){
466        eval {
467            $stored_imagelist = retrieve $self->storable_file;
468        };
469        if($@){
[2661]470            Wx::LogMessage(
[3227]471                gettext("An error has occured. Can not read %s\n%s"),
[2661]472                $self->storable_file,
473                $@
474            );
[3227]475            $use_new_imagelist = 1 ;
[2597]476        }
[3227]477        # should have a valid imagelist
478        else{
479            $use_new_imagelist = 1 unless $self->imagelist_version eq $stored_imagelist->{imagelist_version};
480            if($use_new_imagelist){
481                Wx::LogMessage(gettext("pLoader has to reset image cache."));
482            }
483        }
[2597]484    }
485    else{
[3227]486        $use_new_imagelist = 1 ;
487    }
488
489    if($use_new_imagelist){
[2597]490        $stored_imagelist = $self->_default_imagelist_params ;
491    }
492
[3227]493
[2597]494    $self->imagelist(
495        Uploader::ImageList->new(
496            $stored_imagelist
497        )
498    );
[2661]499
[3227]500    $self->imagelist->RescaleCallback(
501        sub { $self->RescaleImage(@_) }
502    );
503
[2661]504    $self->imagelist->ResizeCallback(
505        sub { $self->ResizeImage(@_) }
506    );
[2597]507}
508
509
510sub _default_imagelist_params {
511    my ( $self ) = @_ ;
512
513    my $params = {
[3232]514        new_files        => [],
[2597]515        thumb_size       => 120,
[2661]516        site_thumb_dir   => $self->thumb_dir,
[2597]517        wx_thumb_size    => 120,
518        wx_thumb_dir     => $self->wx_thumb_dir,
519        preview_ratio    => 25, 
520        preview_dir      => $self->preview_dir,
521        resize_w         => 800,
522        resize_h         => 600,
[2661]523        site_resized_dir => $self->resized_dir,
[2597]524        type             => 'jpg',
525        filter           => 'Lanczos',
[2661]526        blur             => 0.9,
527        quality          => 100,
[3178]528        wx_quality       => 80,
529        th_quality       => 90,
530        auto_rotate      => 1,
[3284]531        remove_uploaded_from_selection => 1,
[3178]532        interlace        => 'Line',
533        create_resized   => 1,
534        use_exif_preview => 1,
[2597]535        prefix           => 'TN',
536        count            => 0,
537        storable_file    => $self->storable_file,
538        userdata_dir     => $self->userdata_dir,
[3267]539        default_photo_name => gettext('File name'),
[3284]540        default_name_prefix => gettext('Photo'),
[3227]541        upload_rejects   =>  [],
542        image_sums       => {},
543        sums             => [],
544        version          => $self->version,
545        imagelist_version => $self->imagelist_version,
546        RescaleCallback  => sub { $self->RescaleImage(@_) },
547        ResizeCallback   => sub { $self->ResizeImage(@_) },
[2597]548    };
549
550    return $params;
551}
552
553sub Login {
554    my ( $self ) = @_; 
555
[3227]556    $self->login_dlg( 
557        Uploader::GUI::wxLoginDlg->new(
558            {
559                title         => gettext("Piwigo login"),
560                site_url      => sub { $self->site_url(@_) },
561                site_username => sub { $self->site_username(@_) },     
562                site_password => sub { $self->site_password(@_) },
563                use_offline   => sub { $self->use_offline(@_) },       
564            }
565        )
566    ) unless $self->login_dlg;
[2597]567
568    my $icon = Wx::Icon->new();
569    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
[3227]570    $self->login_dlg->SetIcon($icon);   
[2597]571
572   
[3227]573    my $rval = $self->login_dlg->ShowModal();
574    $self->login_dlg->Show(0);
575
[3284]576    $self->_init_branding;
577
578
[3227]579    $self->pwg(
580        # get these parameters from dialog or from file
581        Uploader::PWG->new(
582            {
583                site_url       => $self->site_url,
584                site_username  => $self->site_username,
585                site_password  => $self->site_password,
[3284]586                branding       => $self->branding,
[3227]587            }
588        )
589    );
[2597]590   
591    $rval;
592}
593
594sub _init_userdir {
595    my ( $self ) = @_;
596   
597    my $applicationName = $self->GetAppName ;
[3140]598    my $userdatadir = File::Spec->canonpath(
599        File::Spec->catfile(
600            File::HomeDir->my_data(), 
601            "\.$applicationName"
602        )
603    );
[2597]604
[3140]605    if(! -d $userdatadir){
606        if(! mkdir $userdatadir){
607            Wx::MessageBox( 
608                sprintf(
609                    "%s directory creation failed",
610                    $userdatadir,
611                ),
612                "pLoader working directory creation error",
613                wxOK | wxICON_EXCLAMATION, 
614            );
615
616            $userdatadir = File::Spec->canonpath(
617                File::Spec->catfile(
618                    File::Spec->tmpdir(), 
619                    "\.$applicationName"
620                )
621            );
622            mkdir $userdatadir;
623        }       
624    }
625
[2597]626    $self->userdata_dir($userdatadir);
627   
628    $self->conf_file(
629        File::Spec->catfile(
630            $self->userdata_dir, 
631            ".$applicationName.conf"
632        )
633    );
[2661]634
[2597]635   
636
637    $self->storable_file(
638        File::Spec->catfile($self->userdata_dir, 'pLoader.dat')
639    );
640   
641    my $thumbdir = File::Spec->catfile($self->userdata_dir, 'thumbnails');
642    mkdir $thumbdir unless -d $thumbdir ;
643    $self->thumb_dir($thumbdir);
644
645    my $wxthumbdir = File::Spec->catfile($self->userdata_dir, 'wxthumbnails');
646    mkdir $wxthumbdir unless -d $wxthumbdir ;
647    $self->wx_thumb_dir($wxthumbdir);
648
649
650    my $resizedir = File::Spec->catfile($self->userdata_dir, 'resize');
651    mkdir $resizedir unless -d $resizedir ;
652    $self->resized_dir($resizedir);
653
654    my $previewdir = File::Spec->catfile($self->userdata_dir, 'preview');
655    mkdir $previewdir unless -d $previewdir ;
656    $self->preview_dir($previewdir);
657
658       
659}
660
661sub _init_thumbimagelist {
662    my ( $self ) = @_;
663
664   
665    $self->imagelist->wx_thumb_imglist(
666        Wx::ImageList->new( 
667            $self->imagelist->wx_thumb_size, 
668            $self->imagelist->wx_thumb_size, 
669            1,
670            0
671        )
672    );
673   
674    # reload images
675    $self->_reload_thumb_images;
676}
677
678
679sub _reload_thumb_images {
680    my ( $self ) = @_;
681   
682    my $wximagelist = $self->imagelist->wx_thumb_imglist;
[3227]683    my $sums = $self->imagelist->sums;
[2597]684
685    map {
[3227]686        my $image = $self->imagelist->image_sums->{$_};
687
[2597]688        $wximagelist->Add(
689            Wx::Bitmap->new( 
[3227]690                $image->wx_thumb_file, 
[2597]691                $self->GetWxBitmapType($self->imagelist->type), 
692            )
693        );
694    }
[3227]695    @$sums ;
[2597]696
697}
698
699sub GetWxBitmapType {
700    my ( $self, $type ) = @_;
701   
702    $self->{IMGTYPE}->{$type};
703}
704
705
[3227]706sub RescaleImage {
[2661]707    my ( $self, $image_file, $image_file_out, $type, $ratio, $width, $height, $quality ) = @_;
708   
709
710    my $image = Wx::Image->new(
711            $image_file, 
712            $self->GetWxBitmapType($type),
713            0
714    );
715   
716    my $w;
717    my $h;
718
719    my $img_w = $image->GetWidth;
720    my $img_h = $image->GetHeight;
721   
722    # use a ratio ( 25% default ) if defined
723    # default ratio is used for preview.
724    if($ratio){
725        $w = $ratio*$img_w/100 ;
726        $h = $ratio*$img_h/100 ;
727    }
728    # use specified width and height
729    else{
730        # portrait
731        if( $img_w < $img_h ){
732            $w = $height;
733        }
734        else{
735            $w = $width;
736        }
737        # to respect aspect ratio
738        $h = sprintf(
739            "%.0f",
740            ($w*$img_h)/$img_w
741        );
742    }
743
744    $image->Rescale(
745        $w,
746        $h,
747        wxIMAGE_QUALITY_HIGH
748    );
749   
750    $quality ||= 90;
751   
752    $image->SetOption( 
753        "quality", 
754        $quality 
755    );
756   
757    if(!$image->SaveFile(
758        $image_file_out,
759        $self->GetWxBitmapType($type),
760    )){
761        Wx::LogMessage(
[3227]762            gettext("An error has occured. Can not save file %s"),
[2661]763            $image_file_out,
764        )
765    };
766}
767
[3227]768sub ResizeImage {
769    my ( $self, $image_file, $image_file_out, $type, $width, $height, $quality ) = @_;
770   
771
772    my $image = Wx::Image->new(
773            $image_file, 
774            $self->GetWxBitmapType($type),
775            0
776    );
777
778    my $w;
779    my $h;
780
781    my $img_w = $image->GetWidth;
782    my $img_h = $image->GetHeight;
783   
784        # portrait
785        if( $img_w < $img_h ){
786            $w = $height;
787        }
788        else{
789            $w = $width;
790        }
791        # to respect aspect ratio
792        $h = sprintf(
793            "%.0f",
794            ($w*$img_h)/$img_w
795        );
796
797   
798
799    $image->Rescale(
800        $w,
801        $h,
802        wxIMAGE_QUALITY_HIGH
803    );
804
805    $image->Resize(
806        [ $width, $height ], [ 0, 20],
807    );
808   
809    $quality ||= 90;
810   
811    $image->SetOption( 
812        "quality", 
813        $quality 
814    );
815   
816    if(!$image->SaveFile(
817        $image_file_out,
818        $self->GetWxBitmapType($type),
819    )){
820        Wx::LogMessage(
821            gettext("An error has occured. Can not save file %s"),
822            $image_file_out,
823        )
824    };
825}
826
[3284]827# some labels differ with branding ( piwigo.com or piwigo.org )
828sub _init_branding {
829    my ( $self ) =@_;
830   
831    if( $self->site_url =~ /\.piwigo\.com/ ){
832        $self->branding(
833            {
834                category  => gettext("album"), 
835                Category  => gettext("Album"), 
836                categories => gettext("albums"),       
837                Categories => gettext("Albums"),
838                'Add new category' => gettext("Add new album"), 
839            }
840        );
841    }
842    else{
843        $self->branding(
844            {
845                categorie  => gettext("categorie"),     
846                Categorie  => gettext("Categorie"),     
847                categories => gettext("categories"),   
848                Categories => gettext("Categories"),   
849                'Add new category' => gettext("Add new category"),     
850            }
851        );
852    }   
853}
[3227]854
[3284]855sub SaveConfig {
856    my ( $self, $params ) = @_; 
[3227]857
[3284]858   my $config = Wx::ConfigBase::Get;
[3227]859
[3284]860   map {
861       $config->WriteInt( $_, $params->{$_} )
862   } keys %$params;
863
864   $config->Write( 'Perspective', $params->{Perspective} )
865       
866}
867
868
[2597]869sub _init_frame {
[3227]870    my ( $self ) = @_; 
[2597]871
[2618]872    my $config = Wx::ConfigBase::Get;
[2597]873
[2618]874    my $x = $config->ReadInt( "X", 50 );
875    my $y = $config->ReadInt( "Y", 50 );
876    my $w = $config->ReadInt( "Width", 1024 );
877    my $h = $config->ReadInt( "height", 768 );
[3284]878    my $prev_w = $config->ReadInt( "PreviewWidth", 400 );
879    my $prev_h = $config->ReadInt( "PreviewHeight", 300 );
880    my $perspective = $config->Read( "Perspective" );
[3227]881   
[3284]882    #printf("Config x %s, y %s, w %s, h %s, prev_w %s, prev_h %s\n", $x, $y, $w, $h, $prev_w, $prev_h);
883   
[3227]884    my $url = $self->site_url;
885   
886    if($self->use_offline){
887        $url = gettext("Work Offline");
[2618]888    }
[2597]889
[2618]890    my ( $frame ) = Uploader::GUI::wxFrameAUI->new( 
891        {
892            x         => $x,
893            y         => $y,
894            width     => $w,
895            height    => $h,
[3227]896            title     => sprintf("pLoader - Piwigo uploader %s - [%s]", $self->version, $url),
[2618]897            pwg       => $self->pwg,
898            imagelist => $self->imagelist,
[3284]899            preview_w => $prev_w,
900            preview_h => $prev_h,
901            perspective => $perspective,
[2618]902        }
903    );
[2597]904       
[3284]905    $frame->SetSize( $x, $y, $w, $h );
[2618]906    $frame->Show( 1 );
907    $self->SetTopWindow( $frame );
[2597]908
[2618]909    my $icon = Wx::Icon->new();
910    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
911    $frame->SetIcon($icon);     
[2597]912}
913
914sub _readParams {
915        my( $self, $file ) = @_ ;
916
917
918        my $expr_params ;
919        eval { $expr_params = read_file( $file ); } ;
920       
921        my $paramValues = [] ;
922        if($expr_params){
923                my $expr = '$paramValues = ' ;
924                $expr .=  "$expr_params ; " ;
925                eval $expr ;
926        }
927       
928        return unless 'ARRAY' eq ref $paramValues ;
929       
930        if(scalar(@$paramValues )){
931            my $params = $paramValues->[0] ;
932            $self->SetKeyValues($params);
933        }
934}
935
[3159]936sub _readParams2 {
937        my( $self, $file ) = @_ ;
938
939
940        my $expr_params ;
941        eval { $expr_params = read_file( $file ); } ;
942       
943        my $paramValues = [] ;
944        if($expr_params){
945                my $expr = '$paramValues = ' ;
946                $expr .=  "$expr_params ; " ;
947                eval $expr ;
948        }
949       
950        return unless 'HASH' eq ref $paramValues ;
951       
952        $self->SetKeyValues($paramValues);
953}
954
955
[2597]956sub SetKeyValues {
957    my ( $self, $params )= @_; 
958
959    foreach( keys %$params ) {
960        $self->{$_} = $params->{$_} ;
961    }
962}
963
[3159]964
[2597]9651;
Note: See TracBrowser for help on using the repository browser.