Changeset 2696


Ignore:
Timestamp:
Oct 9, 2008, 10:58:41 PM (16 years ago)
Author:
ronosman
Message:

Features added:

  • Cancel during upload or file processing
  • Auto rotate
  • Upload high resolution
Location:
extras/pLoader/trunk/src/Uploader
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extras/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm

    r2661 r2696  
    2020package Uploader::GUI::wxFrameAUI;
    2121use strict;
     22use Carp;
    2223use Wx;
    2324use Wx::DND;
     
    5859             wxMAXIMIZE
    5960             wxOK
    60              wxICON_EXCLAMATION
     61             wxICON_EXCLAMATION
     62             wxICON_INFORMATION
    6163         /;
    6264use base qw/Wx::Frame Class::Accessor::Fast/;
     
    137139    );
    138140
     141    $self->imagelist->SetNewFilesDisplayEndInfoCallback(
     142        sub { $self->SetNewFilesDisplayEndInfo(@_) }
     143    );
     144
     145
    139146    # callback for GUI refresh : remove thumbnail images from imageviewer control
    140147    $self->imagelist->UploadImagesViewerCallback(
     
    142149    );
    143150
     151
     152
    144153    # callback for GUI refresh : progress dialog display current uploaded image
    145154    $self->imagelist->UploadImagesProgressCallback(
    146155        sub { $self->UploadImagesProgress(@_) }
     156    );
     157   
     158    $self->imagelist->UploadDisplayEndInfoCallback(
     159        sub { $self->UploadDisplayEndInfo(@_) }
    147160    );
    148161
     
    212225                parentwnd => $self,
    213226                accessors => {
     227                                  $main::ID_PHOTO =>
     228                                      sub {
     229                                            Wx::Bitmap->new(
     230                                                $self->imagelist->current_image->wx_thumb_file,
     231                                                $self->GetWxBitmapType($self->imagelist->type),
     232                                            );
     233                                      },
    214234                                  $main::ID_PHOTO_NAME =>
    215235                                      sub { $self->imagelist->current_image->site_name(@_) },
     
    419439                                      sub { $self->imagelist->resize_w(@_) },
    420440                                  $main::ID_GLOBAL_RESIZED_H =>
    421                                       sub { $self->imagelist->resize_h(@_) },
     441                                      sub { $self->imagelist->resize_h(@_) },
     442                                  $main::ID_GLOBAL_HIGH =>
     443                                      sub { $self->imagelist->upload_high(@_)},
    422444                             },
    423445                frame_callbacks => {
     
    621643        Uploader::GUI::wxImageProcessingProgressDlg->new(
    622644            {
    623                 title => "Image processing progress information",
     645                title => "Image processing progress information",
     646                bt_label => "Cancel image processing",
    624647             }
    625648        )       
     
    715738    my( $self, $event ) = @_;
    716739 
    717     my $id = $event->GetItem;
    718 
    719740    my $image = $self->imagelist->images->[$event->GetIndex];
    720741    $image->site_name(
     
    745766    my( $self, $event ) = @_;
    746767
    747    
    748     $self->ProcessImageSelection();   
     768#    eval {
     769        $self->ProcessImageSelection();   
     770#    };
    749771}
    750772
     
    761783sub UploadImagesProgress {
    762784    my ( $self ) = @_; 
    763 
     785   
    764786    my $imagelist = $self->imagelist ;
    765787
     
    786808        $self->upload_progressdlg->LogProgress();
    787809    };
     810    if($@){
     811        croak "Upload cancelled.\n";
     812    }
     813   
    788814    Wx::Yield();
    789815
     816}
     817
     818
     819sub SetNewFilesDisplayEndInfo {
     820    my ( $self ) = @_; 
     821       
     822    $self->progressdlg->DisplayEndInfo;
     823}
     824
     825sub UploadDisplayEndInfo {
     826    my ( $self ) = @_; 
     827   
     828    my $imagelist = $self->imagelist ;
     829   
     830    $self->upload_progressdlg->DisplayEndInfo;
    790831}
    791832
     
    849890            Uploader::GUI::wxImageProcessingProgressDlg->new(
    850891                {
    851                     title => "Image upload progress information",
     892                    title => "Image upload progress information",
     893                    bt_label => "Cancel upload",
    852894                 }
    853895            )       
    854896        );
     897        # modeless dialog
    855898        $self->upload_progressdlg->Show(1);
    856899        Wx::Yield();
    857         $self->imagelist->UploadSelection;
     900        eval {
     901            $self->imagelist->UploadSelection;
     902        };
     903        if($@){
     904            Wx::MessageBox(
     905                sprintf(
     906                    "Upload cancelled.",
     907                ),
     908                "Piwigo upload information",
     909                wxOK | wxICON_INFORMATION,
     910            );
     911        }
    858912    }
    859913    else {
  • extras/pLoader/trunk/src/Uploader/GUI/wxGlobalSettingsPanel.pm

    r2661 r2696  
    3333use Wx::Event qw/
    3434                    EVT_TEXT
     35                    EVT_RADIOBOX
    3536                /;
    3637
     
    9091    my ( $self ) = @_;
    9192   
     93   
    9294    map {
    9395        my $ctrl = $self->FindWindow($_);
    94         EVT_TEXT($self, $ctrl, sub { OnTextChanged(@_) });
     96        if('Wx::TextCtrl' eq ref $ctrl){
     97            EVT_TEXT($self, $ctrl, sub { OnControlChanged(@_) });
     98        }
     99        elsif('Wx::RadioBox' eq ref $ctrl){
     100            EVT_RADIOBOX($self, $ctrl, sub { OnControlChanged(@_) });
     101        }
    95102    }
    96103    keys %{$self->accessors};   
     
    98105}
    99106
    100 sub OnTextChanged {
     107sub OnControlChanged {
    101108    my ( $self, $event ) = @_;
    102109   
    103110    my $control_id = $event->GetId ;
    104111
    105     $self->accessors->{$control_id}->(
    106         $event->GetString
     112    $self->GetControlValue(
     113        $control_id
    107114    );
    108115   
  • extras/pLoader/trunk/src/Uploader/GUI/wxPhotoPropertiesPanel.pm

    r2661 r2696  
    8282   
    8383    my $control_id = $event->GetId ;
    84    
     84
    8585    $self->accessors->{$control_id}->(
    8686        $event->GetString
  • extras/pLoader/trunk/src/Uploader/ImageList.pm

    r2661 r2696  
    2020package Uploader::ImageList;
    2121use strict;
     22use Carp;
    2223use base qw/Uploader::Object/;
    2324use Image::ExifTool qw(:Public);
     
    2829use Storable;
    2930# this class implements a collection of image files with associated data
    30 
     31$|=1;
    3132__PACKAGE__->mk_accessors(
    3233    qw/
     
    6162                SetNewFilesViewerRefreshCallback
    6263                SetNewFilesProgressCallback
     64                SetNewFilesDisplayEndInfoCallback
    6365                UploadImagesViewerCallback
    6466                UploadImagesProgressCallback
     67                UploadDisplayEndInfoCallback
    6568                ResizeCallback
    6669                upload_rejects
    6770                pwg
     71                upload_high
    6872     /
    6973);
     
    9599}
    96100
     101# Rotate exif preview if needed
     102sub _rotate_image {
     103    my ( $self, $file ) = @_;   
     104
     105}
     106
     107sub _set_exif_tag {
     108    my ( $self, $file, $tag, $newValue ) = @_; 
     109
     110  my $options = {};
     111  # Create a new Image::ExifTool object
     112  my $exifTool = new Image::ExifTool;
     113
     114  # Extract meta information from an image
     115  $exifTool->ExtractInfo($file, $options);
     116
     117  # Set a new value for a tag
     118  $exifTool->SetNewValue($tag, $newValue);
     119
     120  # Write new meta information to a file
     121  $exifTool->WriteInfo($file);
     122
     123}
    97124
    98125sub _set_current_image_filepaths {
     
    158185    # if some files have been previously selected
    159186    my $i = scalar @{$self->images};
     187    my $count = 0;
     188    $self->count($count);
    160189    map {
    161190        # read exif metadata
     
    196225            };# create a preview file
    197226        }   
     227
     228        $self->RotateImage(
     229            $self->current_image->preview_file,
     230        );
     231
     232        $self->_set_exif_tag(
     233            $self->current_image->preview_file,
     234            'Orientation',
     235            'Horizontal (normal)',
     236        );
     237
     238
    198239        # Now, we should have a valid preview image.
    199240        # try to thumbnail it
     
    206247            $self->progress_msg("Thumbnail and preview created for %s");
    207248            $i++;
    208             $self->count($i);
     249            $count++;
     250            $self->count($count);
    209251        }
    210252        else {
     
    219261    }
    220262    @{$files};
     263    $self->SetNewFilesDisplayEndInfoCallback->();
    221264   
    222265    $self->Store;
     
    241284            site_categories   => [],
    242285            site_tags         => [],
     286            site_high_file    => $_,
    243287        }
    244288    );
     
    311355    $status = $image->Strip();
    312356    warn "$status" if $status ;
    313 
     357   
    314358
    315359    $image->Write(
     
    320364        )
    321365    );
    322     warn "$status" if $status;
    323     return $rval if $status;
    324366
    325367    undef $image;
     
    424466    $status = $image->Set(Gravity=>"Center");
    425467    warn "$status" if $status ;
     468
    426469
    427470    $status = $image->Set(quality=>$self->quality);
     
    554597                progress_msg
    555598                default_name_prefix
     599                upload_high
    556600            /
    557601        ]
     
    580624    );
    581625
    582     my $count = 1;
     626    my $count = 0;
     627
     628    $self->count(
     629        $count
     630    );
    583631    map {
    584632        # current image object         
     
    611659            "Preparing resized image for %s - %s"
    612660        );
     661   
    613662        # update upload progress dialog
    614         $progress_callback->();
     663        eval {
     664            $progress_callback->();
     665        };
     666        # user cancelled
     667        if($@){
     668            croak "Upload cancelled.";
     669        }
    615670        eval {
    616671            if(!$self->CreateResized()){
     
    629684            }
    630685        };
     686        $self->RotateImage(
     687            $self->current_image->site_resized_file,
     688        );
     689
     690        $self->_set_exif_tag(
     691            $self->current_image->site_resized_file,
     692            'Orientation',
     693            'Horizontal (normal)',
     694        );
     695
     696
    631697        if($@){
    632698            $progress_msg = "An error has occured %s - %s\n$@";
     
    641707        # update upload progress dialog
    642708        $progress_callback->();
     709
    643710        eval {
    644711            $self->CreateThumbnail();
     
    657724        $progress_callback->() ;
    658725
     726        # photo metadata
    659727        $self->_prepare_upload_properties();           
    660728        my ( $status, $status_msg ) = $self->pwg->UploadImage();
     
    670738            push @{$self->upload_rejects}, $self->current_image ;
    671739        }       
    672 
     740       
     741        $count++;
    673742        $self->count(
    674             $count++
     743            $count
    675744        );
    676745        # update upload progress dialog
     
    680749    @{$self->image_selection} if defined
    681750        $self->image_selection;
     751       
     752    $self->UploadDisplayEndInfoCallback->();
    682753}
    683754
     
    685756    my ( $self ) = @_;
    686757   
    687     $self->pwg->imagefile(
     758    $self->pwg->upload_high(
     759        $self->upload_high
     760    );
     761
     762    $self->pwg->site_high_file(
     763        $self->current_image->site_high_file
     764    );
     765
     766    $self->pwg->site_resized_file(
    688767        $self->current_image->site_resized_file
    689768    );
    690769
    691     $self->pwg->thumbfile(
     770    $self->pwg->site_thumb_file(
    692771        $self->current_image->site_thumb_file
    693772    );
    694773
    695     $self->pwg->author(
     774    $self->pwg->site_author(
    696775        $self->current_image->site_author
    697776    );
    698777
    699     $self->pwg->comment(
     778    $self->pwg->site_comment(
    700779        $self->current_image->site_comment
    701780    );
    702781
    703     $self->pwg->imagename(
     782    $self->pwg->site_image_name(
    704783        $self->current_image->site_name
    705784    );
    706785
    707     $self->pwg->date_creation(
     786    $self->pwg->site_img_date_creation(
    708787        $self->current_image->create_date
    709788    );
     
    726805}
    727806
     807# read Orientation exif tag from original image
     808# apply rotation to image ( preview or resize )
     809sub RotateImage {
     810    my ( $self, $file ) = @_;
     811   
     812    my $orientation = $self->current_image->exif_metadata->{Orientation};
     813   
     814    # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
     815    if( $orientation =~ m/Rotate (\d+)/ ){
     816        printf(
     817            "Rotate %s\n",
     818            $1
     819        );
     820
     821        my $image = Image::Magick->new();
     822   
     823        my $status = $image->Read(
     824            $file
     825        );
     826        warn "$status ", $file, "\n" if $status ;
     827        return 0 if $status;
     828   
     829        $image->Rotate( degrees=>$1 ); 
     830       
     831        $image->Write(
     832            filename=>$file
     833        );
     834        warn "$status ", $file, "\n" if $status ;
     835        return 0 if $status;
     836       
     837        undef $image;
     838   
     839    }   
     840    return 1;
     841}
    728842
    7298431;
  • extras/pLoader/trunk/src/Uploader/Object2.pm

    r2661 r2696  
    4747    map {
    4848        my $control_id = $_;
    49         my $ctrl = $self->FindWindow($control_id) ;
    50 
    51         my $accessor = $accessors->{$control_id};
    52         eval {
    53                 $ctrl->ChangeValue(
    54                     $accessor->()
    55                 );
    56         };
    57        
    58         if($@){
    59         eval {
    60                 $ctrl->SetLabel(
    61                     $accessor->()
    62                 );
    63         };
    64                
    65         }
    66     }
    67     keys %$accessors;
    68 }
    69 
    70 # Get values from controls. Set callback accessors with these values
    71 sub GetControlValues {
    72     my ( $self ) = @_;
    73 
    74     my $accessors = $self->accessors;
    75 
    76     # accessor_name => [ sub {}, control_id ]
    77     map {
    78         my ( $accessor, $control_id) = @{$accessors->{$_}};
    79        
    80         eval {
    81             $accessor->(
    82                 $self->FindWindow($control_id)->GetValue()
    83             );
    84         };
    85 
    86         if($@){
    87             eval {
    88                 $accessor->(
    89                     $self->FindWindow($control_id)->GetLabel()
    90                 );
    91             };
    92         };
    93     }
     49        $self->SetControlValue($control_id);
     50   }
    9451    keys %$accessors;
    9552}
    9653
    9754
     55
    9856sub GetControlValue {
    9957    my( $self, $control_id ) = @_;
    100    
    101     my $value;
     58
     59    my $ctrl = $self->FindWindow($control_id) ;
     60    my $accessor = $self->accessors->{$control_id};
     61
     62    # to execute the right method
     63    my $method = {
     64        'Wx::TextCtrl' => sub {
     65                              $accessor->(
     66                                  $ctrl->GetValue()
     67                              );
     68                          },   
     69        'Wx::StaticText' => sub {
     70                              $accessor->(
     71                                  $ctrl->GetLabel()
     72                              );
     73                          },   
     74        'Wx::StaticBitmap' => sub {
     75                              $accessor->(
     76                                  $ctrl->GetBitmap()
     77                              );
     78                          },   
     79        'Wx::RadioBox' => sub {
     80                              $accessor->(
     81                                  $ctrl->GetSelection()
     82                              );
     83                          },   
     84    };
     85
     86
    10287    eval {
    103         my $ctrl = $self->FindWindow(
    104             $control_id
    105         );
    106        
    107         $value = $ctrl->GetValue;
    108        
    109         $self->accessors->{$control_id}->(
    110             $value
    111         );
     88        $method->{ref $ctrl }->();
    11289    };
    113    
    114     return $value;
    11590}
    11691
    11792
    11893
     94sub SetControlValue {
     95    my( $self, $control_id ) = @_;
     96
     97    my $ctrl = $self->FindWindow($control_id) ;
     98    my $accessor = $self->accessors->{$control_id};
    11999
    120100
    121 
     101    # to execute the right method
     102    my $method = {
     103        'Wx::TextCtrl' => sub {
     104                              $ctrl->ChangeValue(
     105                                  $accessor->()
     106                              );
     107                          },   
     108        'Wx::StaticText' => sub {
     109                              $ctrl->SetLabel(
     110                                  $accessor->()
     111                              );
     112                          },   
     113        'Wx::StaticBitmap' => sub {
     114                              $ctrl->SetBitmap(
     115                                  $accessor->()
     116                              );
     117                          },   
     118        'Wx::RadioBox' => sub {
     119                              $ctrl->SetSelection(
     120                                  $accessor->()
     121                              );
     122                          },   
     123    };
     124    eval {
     125        $method->{ref $ctrl }->();
     126    };
     127}
    1221281;
  • extras/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r2661 r2696  
    2525use JSON;
    2626use LWP::UserAgent;
    27 use Text::ASCIITable;
    2827use Data::Dumper;
    2928use Digest::MD5::File qw/file_md5_hex md5_hex/;
    3029use File::Slurp;
    3130use Encode qw/encode decode/;
    32 #use String::Random qw/random_string/;
    3331use base qw/
    3432           Uploader::Object
     
    4745           tags
    4846           categories
    49            imagefile
    50            thumbfile
    51            imagename
     47           site_high_file
     48           site_resized_file
     49           site_thumb_file
     50           site_image_name
    5251           rank
    53            author
    54            comment
    55            date_creation
     52           site_author
     53           site_comment
     54           site_img_date_creation
    5655           uagent_response
    5756           login_result
    5857           action_result
     58           upload_high
    5959      /
    6060);
     
    162162    printf(
    163163        "UploadImage %s\n",
    164         $self->imagefile
    165     );
     164        $self->site_resized_file
     165    );
     166
    166167    my $file_content = encode_base64(
    167168        read_file(
    168             $self->imagefile,
     169            $self->site_resized_file,
    169170            binmode => ':raw',
    170171        )
     
    172173
    173174    my $file_sum = file_md5_hex(
    174         $self->imagefile
     175        $self->site_resized_file
    175176    );
    176177 
    177178    my $thumbnail_content = encode_base64(
    178179        read_file(
    179             $self->thumbfile,
     180            $self->site_thumb_file,
    180181            binmode => ':raw',
    181182        )
     
    183184
    184185    my $thumbnail_sum = file_md5_hex(
    185         $self->thumbfile
    186     );
     186            $self->site_thumb_file,
     187    );
     188
    187189
    188190   
     
    194196        thumbnail_content => $thumbnail_content,
    195197        categories        => $self->categories,
    196         name              => $self->imagename,
     198        name              => $self->site_image_name,
    197199        rank              => $self->rank,
    198         author            => $self->author,
    199         comment           => $self->comment,
    200         date_creation     => $self->date_creation,
     200        author            => $self->site_author,
     201        comment           => $self->site_comment,
     202        date_creation     => $self->site_img_date_creation,
    201203       
    202204    };
     205
     206    if($self->upload_high){
     207        $form->{high_content} = encode_base_64(
     208                                     read_file(
     209                                         $self->site_high_file,
     210                                         binmode => ':raw',
     211                                     )
     212                                 );
     213        $form->{high_sum}     = file_md5_hex(
     214                                     $self->site_high_file
     215                                 );
     216    }
     217
    203218
    204219    my $result = $self->uagent->post(
Note: See TracChangeset for help on using the changeset viewer.