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

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

Add defaut values for watermark text, position, margins. Add missing french translations.

  • Property svn:eol-style set to LF
File size: 27.2 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_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 
271         /;
272use Uploader::GUI::wxFrameAUI;
273use File::Slurp ;
274use Data::Dumper;
275use Storable;
276use File::HomeDir;
277use File::Spec;
278use Uploader::PWG;
279use Uploader::ImageList;
280use Uploader::GUI::wxLoginDlg;
281use Wx::Locale qw/:default/;
282
283
284$|=1;
285
286__PACKAGE__->mk_accessors( 
287    qw/
288          pwg
289          site_url
290          site_username
291          site_password
292          http_username
293          http_password
294          rejects
295          imagelist
296          storable_file
297          wx_thumb_dir
298          resized_dir
299          preview_dir
300          userdata_dir
301          resized_dir
302          thumb_dir
303          conf_file
304          layout_file
305          locale
306          current_language
307          version
308          imagelist_version
309          use_offline
310          login_dlg
311          branding
312          frame
313          perspective
314          imageviewerIndex
315          frameLayout
316          chunk_size
317      / 
318);
319
320sub FilterEvent {
321    my( $self, $event ) = @_;
322   
323    Wx::LogMessage "EventType %s", $event->GetEventType();
324   
325    return -1;
326}
327
328
329sub OnInit {
330    my( $self ) = @_;
331   
332    $self->version(
333        '2.0.5a'
334    );
335   
336    # to check if we can use stored cache
337    $self->imagelist_version(
338        '6'
339    );
340
341    Wx::InitAllImageHandlers();
342    my $applicationName = "pLoader" ;
343    $self->SetAppName( $applicationName );
344    $self->SetVendorName( "Piwigo Team" );
345
346    $self->{IMGTYPE} = {
347        'jpg' => wxBITMAP_TYPE_JPEG,
348        'gif' => wxBITMAP_TYPE_GIF,
349        'png' => wxBITMAP_TYPE_PNG,
350    };
351
352    $self->_init_userdir;
353
354
355    my $conf = retrieve $self->conf_file if -e $self->conf_file;       
356    my $layout = retrieve $self->layout_file if -e $self->layout_file; 
357
358    if(defined $conf ){
359        $self->SetKeyValues($conf);
360    }
361    else {
362        $self->_readParams( 'pLoader.ini' ) unless defined $conf ;
363    }
364
365    if(defined $layout ){
366        $self->SetKeyValues($layout);
367    }
368
369
370    $self->site_url(
371        $self->{site_url}
372    );
373   
374
375    $self->site_username(
376        $self->{site_username}
377    );
378    $self->site_password(
379        $self->{site_password}
380    );
381
382    $self->http_username(
383        $self->{http_username}
384    );
385    $self->http_password(
386        $self->{http_password}
387    );
388
389
390    $self->current_language(
391        $self->{current_language}||Wx::Locale::GetSystemLanguage()
392    );
393
394    $self->chunk_size(
395        $self->{chunk_size}||500_000
396    );
397   
398    $self->init_locale;
399
400    my $not_exit = $self->Login();
401    # user pressed OK
402    if($not_exit){
403        $self->StoreConnectionProperties;
404        if( !$self->use_offline ){
405            while( $not_exit and !$self->_is_connected ){
406                $not_exit = $self->Login();
407                last if $self->use_offline;
408            }
409        }
410        $self->_init_imagelist;
411        $self->_init_thumbimagelist;
412        $self->_init_frame;
413    }
414
415    $not_exit;
416}
417
418
419sub _is_connected {
420    my ( $self ) = @_;
421
422    my $is_connected;
423
424    if($self->pwg->login_result->{stat} eq 'ok'){
425        $is_connected = 1;
426    }
427    else{
428        Wx::MessageBox( 
429            sprintf(
430                "%s\n\n%s %s %s",
431                $self->pwg->login_result->{message},
432                gettext("Connection to"),
433                $self->site_url,
434                gettext("failed"),
435            ),
436            gettext("Piwigo login error"),
437            wxOK | wxICON_EXCLAMATION, 
438        );
439    }
440   
441    $is_connected;
442}
443
444
445my $locale;
446sub init_locale {
447    my ( $self, $language ) = @_;
448   
449    $self->current_language(
450        $language
451    ) if defined $language;
452
453    undef $locale;
454    $locale = Wx::Locale->new(
455        $self->current_language
456    );
457    $locale->AddCatalogLookupPathPrefix( '../locale');
458    if(!$locale->AddCatalog( 'pLoader.mo' )){
459        Wx::LogMessage gettext("Cannot find translation catalog files for %s. Use default language"), $locale->GetCanonicalName();
460    }
461    $self->locale($locale);     
462}
463
464sub StoreConnectionProperties {
465    my ( $self ) = @_;
466
467    eval {   
468        store( 
469            {
470                map{
471                   $_ => $self->{$_},
472                }
473                qw/
474                    site_url
475                    site_username
476                    site_password
477                    http_username
478                    http_password
479                    current_language
480                    chunk_size
481                /
482            },
483            $self->conf_file
484        );
485    };
486}
487
488sub StoreLayoutProperties {
489    my ( $self ) = @_;
490
491    eval {   
492        store( 
493            {
494                map{
495                   $_ => $self->{$_},
496                }
497                qw/
498                      perspective
499                      imageviewerIndex
500                      frameLayout
501                /
502            },
503            $self->layout_file
504        );
505    };
506}
507
508sub _init_imagelist {
509    my ( $self ) = @_; 
510
511    my $stored_imagelist;
512   
513    my $use_new_imagelist;
514   
515    if( -e $self->storable_file ){
516        eval {
517            $stored_imagelist = retrieve $self->storable_file;
518        };
519        if($@){
520            Wx::LogMessage(
521                gettext("An error has occured. Can not read %s\n%s"),
522                $self->storable_file,
523                $@
524            );
525            $use_new_imagelist = 1 ;
526        }
527        # should have a valid imagelist
528        else{
529            $use_new_imagelist = 1 unless $self->imagelist_version eq $stored_imagelist->{imagelist_version};
530            if($use_new_imagelist){
531                Wx::LogMessage(gettext("pLoader has to reset image cache."));
532            }
533        }
534    }
535    else{
536        $use_new_imagelist = 1 ;
537    }
538
539    if($use_new_imagelist){
540        $stored_imagelist = $self->_default_imagelist_params ;
541    }
542
543
544    $self->imagelist(
545        Uploader::ImageList->new(
546            $stored_imagelist
547        )
548    );
549
550    $self->imagelist->RescaleCallback(
551        sub { $self->RescaleImage(@_) }
552    );
553
554    $self->imagelist->ResizeCallback(
555        sub { $self->ResizeImage(@_) }
556    );
557
558    $self->imagelist->YieldCallback(
559        sub { Wx::Yield }
560    );
561}
562
563
564sub _default_imagelist_params {
565    my ( $self ) = @_ ;
566
567    my $params = {
568        new_files        => [],
569        thumb_size       => 120,
570        site_thumb_dir   => $self->thumb_dir,
571        wx_thumb_size    => 120,
572        wx_thumb_dir     => $self->wx_thumb_dir,
573        preview_ratio    => 25, 
574        preview_dir      => $self->preview_dir,
575        resize_w         => 800,
576        resize_h         => 600,
577        site_resized_dir => $self->resized_dir,
578        type             => 'jpg',
579        filter           => 'Lanczos',
580        blur             => 0.9,
581        quality          => 95,
582        wx_quality       => 80,
583        th_quality       => 90,
584        auto_rotate      => 1,
585        remove_uploaded_from_selection => 1,
586        interlace        => 'Line',
587        create_resized   => 1,
588        use_exif_preview => 1,
589        prefix           => 'TN',
590        count            => 0,
591        storable_file    => $self->storable_file,
592        userdata_dir     => $self->userdata_dir,
593        default_photo_name => gettext('File name'),
594        default_name_prefix => gettext('Photo '),
595        upload_rejects   =>  [],
596        image_sums       => {},
597        sums             => [],
598        version          => $self->version,
599        imagelist_version => $self->imagelist_version,
600        RescaleCallback  => sub { $self->RescaleImage(@_) },
601        ResizeCallback   => sub { $self->ResizeImage(@_) },
602        watermark_text => gettext("my watermark"),
603        watermark_text_size => 12,
604        watermark_position => gettext("Center"),
605        watermark_y => 10,
606        watermark_x => 10,
607        watermark_color => gettext("White"),
608    };
609
610    return $params;
611}
612
613sub Login {
614    my ( $self ) = @_; 
615
616    $self->login_dlg( 
617        Uploader::GUI::wxLoginDlg->new(
618            {
619                title         => gettext("Piwigo login"),
620                site_url      => sub { $self->site_url(@_) },
621                site_username => sub { $self->site_username(@_) },     
622                site_password => sub { $self->site_password(@_) },
623                use_offline   => sub { $self->use_offline(@_) },       
624            }
625        )
626    ) unless $self->login_dlg;
627
628    my $icon = Wx::Icon->new();
629    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
630    $self->login_dlg->SetIcon($icon);   
631
632   
633    my $rval = $self->login_dlg->ShowModal();
634    $self->login_dlg->Show(0);
635
636    $self->_init_branding;
637   
638    if ($self->site_url !~ /^http:/){
639        $self->site_url(
640            sprintf(
641                "http://%s",
642                $self->site_url
643            )
644        );     
645    }
646
647    $self->pwg(
648        # get these parameters from dialog or from file
649        Uploader::PWG->new(
650            {
651                site_url       => $self->site_url,
652                site_username  => $self->site_username,
653                site_password  => $self->site_password,
654                http_username  => $self->http_username,
655                http_password  => $self->http_password,
656                branding       => $self->branding,
657                chunk_size     => $self->chunk_size,
658                use_offline    => $self->use_offline,
659            }
660        )
661    );
662
663    $rval;
664}
665
666sub _init_userdir {
667    my ( $self ) = @_;
668   
669    my $applicationName = $self->GetAppName ;
670    my $userdatadir = File::Spec->canonpath(
671        File::Spec->catfile(
672            File::HomeDir->my_data(), 
673            "\.$applicationName"
674        )
675    );
676
677    if(! -d $userdatadir){
678        if(! mkdir $userdatadir){
679            Wx::MessageBox( 
680                sprintf(
681                    "%s directory creation failed",
682                    $userdatadir,
683                ),
684                "pLoader working directory creation error",
685                wxOK | wxICON_EXCLAMATION, 
686            );
687
688            $userdatadir = File::Spec->canonpath(
689                File::Spec->catfile(
690                    File::Spec->tmpdir(), 
691                    "\.$applicationName"
692                )
693            );
694            mkdir $userdatadir;
695        }       
696    }
697
698    $self->userdata_dir($userdatadir);
699   
700    $self->conf_file(
701        File::Spec->catfile(
702            $self->userdata_dir, 
703            ".$applicationName.conf"
704        )
705    );
706
707    $self->layout_file(
708        File::Spec->catfile(
709            $self->userdata_dir, 
710            ".$applicationName.layout"
711        )
712    );
713
714    $self->storable_file(
715        File::Spec->catfile($self->userdata_dir, 'pLoader.dat')
716    );
717   
718    my $thumbdir = File::Spec->catfile($self->userdata_dir, 'thumbnails');
719    mkdir $thumbdir unless -d $thumbdir ;
720    $self->thumb_dir($thumbdir);
721
722    my $wxthumbdir = File::Spec->catfile($self->userdata_dir, 'wxthumbnails');
723    mkdir $wxthumbdir unless -d $wxthumbdir ;
724    $self->wx_thumb_dir($wxthumbdir);
725
726
727    my $resizedir = File::Spec->catfile($self->userdata_dir, 'resize');
728    mkdir $resizedir unless -d $resizedir ;
729    $self->resized_dir($resizedir);
730
731    my $previewdir = File::Spec->catfile($self->userdata_dir, 'preview');
732    mkdir $previewdir unless -d $previewdir ;
733    $self->preview_dir($previewdir);
734
735       
736}
737
738sub _init_thumbimagelist {
739    my ( $self ) = @_;
740
741   
742    $self->imagelist->wx_thumb_imglist(
743        Wx::ImageList->new( 
744            $self->imagelist->wx_thumb_size, 
745            $self->imagelist->wx_thumb_size, 
746            1,
747            0
748        )
749    );
750   
751    # reload images
752    $self->_reload_thumb_images;
753}
754
755
756sub _reload_thumb_images {
757    my ( $self ) = @_;
758   
759    my $wximagelist = $self->imagelist->wx_thumb_imglist;
760    my $sums = $self->imagelist->sums;
761
762    map {
763        my $image = $self->imagelist->image_sums->{$_};
764
765        $wximagelist->Add(
766            Wx::Bitmap->new( 
767                $image->wx_thumb_file, 
768                $self->GetWxBitmapType($self->imagelist->type), 
769            )
770        );
771    }
772    @$sums ;
773
774}
775
776sub GetWxBitmapType {
777    my ( $self, $type ) = @_;
778   
779    $self->{IMGTYPE}->{$type};
780}
781
782
783sub RescaleImage {
784    my ( $self, $image_file, $image_file_out, $type, $ratio, $width, $height, $quality ) = @_;
785   
786
787    my $image = Wx::Image->new(
788            $image_file, 
789            $self->GetWxBitmapType($type),
790            0
791    );
792   
793    my $w;
794    my $h;
795
796    my $img_w = $image->GetWidth;
797    my $img_h = $image->GetHeight;
798   
799    # use a ratio ( 25% default ) if defined
800    # default ratio is used for preview.
801    if($ratio){
802        $w = $ratio*$img_w/100 ;
803        $h = $ratio*$img_h/100 ;
804    }
805    # use specified width and height
806    else{
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    $image->Rescale(
822        $w,
823        $h,
824        wxIMAGE_QUALITY_HIGH
825    );
826   
827    $quality ||= 90;
828   
829    $image->SetOption( 
830        "quality", 
831        $quality 
832    );
833   
834    if(!$image->SaveFile(
835        $image_file_out,
836        $self->GetWxBitmapType($type),
837    )){
838        Wx::LogMessage(
839            gettext("An error has occured. Can not save file %s"),
840            $image_file_out,
841        )
842    };
843}
844
845sub ResizeImage {
846    my ( $self, $image_file, $image_file_out, $type, $width, $height, $quality ) = @_;
847   
848
849    my $image = Wx::Image->new(
850            $image_file, 
851            $self->GetWxBitmapType($type),
852            0
853    );
854
855    my $w;
856    my $h;
857
858    my $img_w = $image->GetWidth;
859    my $img_h = $image->GetHeight;
860   
861        # portrait
862        if( $img_w < $img_h ){
863            $w = $height;
864        }
865        else{
866            $w = $width;
867        }
868        # to respect aspect ratio
869        $h = sprintf(
870            "%.0f",
871            ($w*$img_h)/$img_w
872        );
873
874   
875
876    $image->Rescale(
877        $w,
878        $h,
879        wxIMAGE_QUALITY_HIGH
880    );
881
882    $image->Resize(
883        [ $width, $height ], [ 0, 20],
884    );
885   
886    $quality ||= 90;
887   
888    $image->SetOption( 
889        "quality", 
890        $quality 
891    );
892   
893    if(!$image->SaveFile(
894        $image_file_out,
895        $self->GetWxBitmapType($type),
896    )){
897        Wx::LogMessage(
898            gettext("An error has occured. Can not save file %s"),
899            $image_file_out,
900        )
901    };
902}
903
904# some labels differ with branding ( piwigo.com or piwigo.org )
905sub _init_branding {
906    my ( $self ) =@_;
907   
908    if( $self->site_url =~ /\.piwigo\.com/ ){
909        $self->branding(
910            {
911                category  => gettext("album"), 
912                Category  => gettext("Album"), 
913                categories => gettext("albums"),       
914                Categories => gettext("Albums"),
915                'Add new category' => gettext("Add new album"), 
916                'Category name' => gettext("Album name :"),
917                'New category' => gettext("New album"),
918            }
919        );
920    }
921    else{
922        $self->branding(
923            {
924                category  => gettext("categorie"),     
925                Category  => gettext("Categorie"),     
926                categories => gettext("categories"),   
927                Categories => gettext("Categories"),   
928                'Add new category' => gettext("Add new category"),
929                'Category name' => gettext("Category name :"),
930                'New category' => gettext("New category"),
931            }
932        );
933    }   
934}
935
936sub SaveConfig {
937    my ( $self, $params ) = @_; 
938
939   my $config = Wx::ConfigBase::Get;
940
941   map {
942       $config->WriteInt( $_, $params->{$_} )
943   } keys %$params;
944
945   $config->Write( 'Perspective', $params->{Perspective} )
946       
947}
948
949
950sub _init_frame {
951    my ( $self ) = @_; 
952
953    my $url = $self->site_url;
954   
955    if($self->use_offline){
956        $url = gettext("Work Offline");
957    }
958
959    $self->frame(
960        Uploader::GUI::wxFrameAUI->new( 
961            {
962                title     => sprintf("pLoader - Piwigo uploader %s - [%s]", $self->version, $url),
963                pwg       => $self->pwg,
964                imagelist => $self->imagelist,
965                perspective => $self->perspective,
966                imageviewer_index => $self->imageviewerIndex,
967                frameLayout => $self->frameLayout,
968            }
969        )
970    );
971 
972    $self->frame->Show( 1 );
973    $self->SetTopWindow( $self->frame );
974
975    my $icon = Wx::Icon->new();
976    $icon->LoadFile('../res/favicon.ico', wxBITMAP_TYPE_ICO);
977    $self->frame->SetIcon($icon);       
978}
979
980sub _readParams {
981        my( $self, $file ) = @_ ;
982
983
984        my $expr_params ;
985        eval { $expr_params = read_file( $file ); } ;
986       
987        my $paramValues = [] ;
988        if($expr_params){
989                my $expr = '$paramValues = ' ;
990                $expr .=  "$expr_params ; " ;
991                eval $expr ;
992        }
993       
994        return unless 'ARRAY' eq ref $paramValues ;
995       
996        if(scalar(@$paramValues )){
997            my $params = $paramValues->[0] ;
998            $self->SetKeyValues($params);
999        }
1000}
1001
1002
1003
1004sub SetKeyValues {
1005    my ( $self, $params )= @_; 
1006
1007    foreach( keys %$params ) {
1008        $self->{$_} = $params->{$_} ;
1009    }
1010}
1011
1012
10131;
Note: See TracBrowser for help on using the repository browser.