Changeset 2696 for extras/pLoader/trunk
- Timestamp:
- Oct 9, 2008, 10:58:41 PM (16 years ago)
- Location:
- extras/pLoader/trunk/src/Uploader
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extras/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm
r2661 r2696 20 20 package Uploader::GUI::wxFrameAUI; 21 21 use strict; 22 use Carp; 22 23 use Wx; 23 24 use Wx::DND; … … 58 59 wxMAXIMIZE 59 60 wxOK 60 wxICON_EXCLAMATION 61 wxICON_EXCLAMATION 62 wxICON_INFORMATION 61 63 /; 62 64 use base qw/Wx::Frame Class::Accessor::Fast/; … … 137 139 ); 138 140 141 $self->imagelist->SetNewFilesDisplayEndInfoCallback( 142 sub { $self->SetNewFilesDisplayEndInfo(@_) } 143 ); 144 145 139 146 # callback for GUI refresh : remove thumbnail images from imageviewer control 140 147 $self->imagelist->UploadImagesViewerCallback( … … 142 149 ); 143 150 151 152 144 153 # callback for GUI refresh : progress dialog display current uploaded image 145 154 $self->imagelist->UploadImagesProgressCallback( 146 155 sub { $self->UploadImagesProgress(@_) } 156 ); 157 158 $self->imagelist->UploadDisplayEndInfoCallback( 159 sub { $self->UploadDisplayEndInfo(@_) } 147 160 ); 148 161 … … 212 225 parentwnd => $self, 213 226 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 }, 214 234 $main::ID_PHOTO_NAME => 215 235 sub { $self->imagelist->current_image->site_name(@_) }, … … 419 439 sub { $self->imagelist->resize_w(@_) }, 420 440 $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(@_)}, 422 444 }, 423 445 frame_callbacks => { … … 621 643 Uploader::GUI::wxImageProcessingProgressDlg->new( 622 644 { 623 title => "Image processing progress information", 645 title => "Image processing progress information", 646 bt_label => "Cancel image processing", 624 647 } 625 648 ) … … 715 738 my( $self, $event ) = @_; 716 739 717 my $id = $event->GetItem;718 719 740 my $image = $self->imagelist->images->[$event->GetIndex]; 720 741 $image->site_name( … … 745 766 my( $self, $event ) = @_; 746 767 747 748 $self->ProcessImageSelection(); 768 # eval { 769 $self->ProcessImageSelection(); 770 # }; 749 771 } 750 772 … … 761 783 sub UploadImagesProgress { 762 784 my ( $self ) = @_; 763 785 764 786 my $imagelist = $self->imagelist ; 765 787 … … 786 808 $self->upload_progressdlg->LogProgress(); 787 809 }; 810 if($@){ 811 croak "Upload cancelled.\n"; 812 } 813 788 814 Wx::Yield(); 789 815 816 } 817 818 819 sub SetNewFilesDisplayEndInfo { 820 my ( $self ) = @_; 821 822 $self->progressdlg->DisplayEndInfo; 823 } 824 825 sub UploadDisplayEndInfo { 826 my ( $self ) = @_; 827 828 my $imagelist = $self->imagelist ; 829 830 $self->upload_progressdlg->DisplayEndInfo; 790 831 } 791 832 … … 849 890 Uploader::GUI::wxImageProcessingProgressDlg->new( 850 891 { 851 title => "Image upload progress information", 892 title => "Image upload progress information", 893 bt_label => "Cancel upload", 852 894 } 853 895 ) 854 896 ); 897 # modeless dialog 855 898 $self->upload_progressdlg->Show(1); 856 899 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 } 858 912 } 859 913 else { -
extras/pLoader/trunk/src/Uploader/GUI/wxGlobalSettingsPanel.pm
r2661 r2696 33 33 use Wx::Event qw/ 34 34 EVT_TEXT 35 EVT_RADIOBOX 35 36 /; 36 37 … … 90 91 my ( $self ) = @_; 91 92 93 92 94 map { 93 95 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 } 95 102 } 96 103 keys %{$self->accessors}; … … 98 105 } 99 106 100 sub On TextChanged {107 sub OnControlChanged { 101 108 my ( $self, $event ) = @_; 102 109 103 110 my $control_id = $event->GetId ; 104 111 105 $self-> accessors->{$control_id}->(106 $ event->GetString112 $self->GetControlValue( 113 $control_id 107 114 ); 108 115 -
extras/pLoader/trunk/src/Uploader/GUI/wxPhotoPropertiesPanel.pm
r2661 r2696 82 82 83 83 my $control_id = $event->GetId ; 84 84 85 85 $self->accessors->{$control_id}->( 86 86 $event->GetString -
extras/pLoader/trunk/src/Uploader/ImageList.pm
r2661 r2696 20 20 package Uploader::ImageList; 21 21 use strict; 22 use Carp; 22 23 use base qw/Uploader::Object/; 23 24 use Image::ExifTool qw(:Public); … … 28 29 use Storable; 29 30 # this class implements a collection of image files with associated data 30 31 $|=1; 31 32 __PACKAGE__->mk_accessors( 32 33 qw/ … … 61 62 SetNewFilesViewerRefreshCallback 62 63 SetNewFilesProgressCallback 64 SetNewFilesDisplayEndInfoCallback 63 65 UploadImagesViewerCallback 64 66 UploadImagesProgressCallback 67 UploadDisplayEndInfoCallback 65 68 ResizeCallback 66 69 upload_rejects 67 70 pwg 71 upload_high 68 72 / 69 73 ); … … 95 99 } 96 100 101 # Rotate exif preview if needed 102 sub _rotate_image { 103 my ( $self, $file ) = @_; 104 105 } 106 107 sub _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 } 97 124 98 125 sub _set_current_image_filepaths { … … 158 185 # if some files have been previously selected 159 186 my $i = scalar @{$self->images}; 187 my $count = 0; 188 $self->count($count); 160 189 map { 161 190 # read exif metadata … … 196 225 };# create a preview file 197 226 } 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 198 239 # Now, we should have a valid preview image. 199 240 # try to thumbnail it … … 206 247 $self->progress_msg("Thumbnail and preview created for %s"); 207 248 $i++; 208 $self->count($i); 249 $count++; 250 $self->count($count); 209 251 } 210 252 else { … … 219 261 } 220 262 @{$files}; 263 $self->SetNewFilesDisplayEndInfoCallback->(); 221 264 222 265 $self->Store; … … 241 284 site_categories => [], 242 285 site_tags => [], 286 site_high_file => $_, 243 287 } 244 288 ); … … 311 355 $status = $image->Strip(); 312 356 warn "$status" if $status ; 313 357 314 358 315 359 $image->Write( … … 320 364 ) 321 365 ); 322 warn "$status" if $status;323 return $rval if $status;324 366 325 367 undef $image; … … 424 466 $status = $image->Set(Gravity=>"Center"); 425 467 warn "$status" if $status ; 468 426 469 427 470 $status = $image->Set(quality=>$self->quality); … … 554 597 progress_msg 555 598 default_name_prefix 599 upload_high 556 600 / 557 601 ] … … 580 624 ); 581 625 582 my $count = 1; 626 my $count = 0; 627 628 $self->count( 629 $count 630 ); 583 631 map { 584 632 # current image object … … 611 659 "Preparing resized image for %s - %s" 612 660 ); 661 613 662 # update upload progress dialog 614 $progress_callback->(); 663 eval { 664 $progress_callback->(); 665 }; 666 # user cancelled 667 if($@){ 668 croak "Upload cancelled."; 669 } 615 670 eval { 616 671 if(!$self->CreateResized()){ … … 629 684 } 630 685 }; 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 631 697 if($@){ 632 698 $progress_msg = "An error has occured %s - %s\n$@"; … … 641 707 # update upload progress dialog 642 708 $progress_callback->(); 709 643 710 eval { 644 711 $self->CreateThumbnail(); … … 657 724 $progress_callback->() ; 658 725 726 # photo metadata 659 727 $self->_prepare_upload_properties(); 660 728 my ( $status, $status_msg ) = $self->pwg->UploadImage(); … … 670 738 push @{$self->upload_rejects}, $self->current_image ; 671 739 } 672 740 741 $count++; 673 742 $self->count( 674 $count ++743 $count 675 744 ); 676 745 # update upload progress dialog … … 680 749 @{$self->image_selection} if defined 681 750 $self->image_selection; 751 752 $self->UploadDisplayEndInfoCallback->(); 682 753 } 683 754 … … 685 756 my ( $self ) = @_; 686 757 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( 688 767 $self->current_image->site_resized_file 689 768 ); 690 769 691 $self->pwg-> thumbfile(770 $self->pwg->site_thumb_file( 692 771 $self->current_image->site_thumb_file 693 772 ); 694 773 695 $self->pwg-> author(774 $self->pwg->site_author( 696 775 $self->current_image->site_author 697 776 ); 698 777 699 $self->pwg-> comment(778 $self->pwg->site_comment( 700 779 $self->current_image->site_comment 701 780 ); 702 781 703 $self->pwg-> imagename(782 $self->pwg->site_image_name( 704 783 $self->current_image->site_name 705 784 ); 706 785 707 $self->pwg-> date_creation(786 $self->pwg->site_img_date_creation( 708 787 $self->current_image->create_date 709 788 ); … … 726 805 } 727 806 807 # read Orientation exif tag from original image 808 # apply rotation to image ( preview or resize ) 809 sub 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 } 728 842 729 843 1; -
extras/pLoader/trunk/src/Uploader/Object2.pm
r2661 r2696 47 47 map { 48 48 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 } 94 51 keys %$accessors; 95 52 } 96 53 97 54 55 98 56 sub GetControlValue { 99 57 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 102 87 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 }->(); 112 89 }; 113 114 return $value;115 90 } 116 91 117 92 118 93 94 sub SetControlValue { 95 my( $self, $control_id ) = @_; 96 97 my $ctrl = $self->FindWindow($control_id) ; 98 my $accessor = $self->accessors->{$control_id}; 119 99 120 100 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 } 122 128 1; -
extras/pLoader/trunk/src/Uploader/PWG/WebServices.pm
r2661 r2696 25 25 use JSON; 26 26 use LWP::UserAgent; 27 use Text::ASCIITable;28 27 use Data::Dumper; 29 28 use Digest::MD5::File qw/file_md5_hex md5_hex/; 30 29 use File::Slurp; 31 30 use Encode qw/encode decode/; 32 #use String::Random qw/random_string/;33 31 use base qw/ 34 32 Uploader::Object … … 47 45 tags 48 46 categories 49 imagefile 50 thumbfile 51 imagename 47 site_high_file 48 site_resized_file 49 site_thumb_file 50 site_image_name 52 51 rank 53 author54 comment55 date_creation52 site_author 53 site_comment 54 site_img_date_creation 56 55 uagent_response 57 56 login_result 58 57 action_result 58 upload_high 59 59 / 60 60 ); … … 162 162 printf( 163 163 "UploadImage %s\n", 164 $self->imagefile 165 ); 164 $self->site_resized_file 165 ); 166 166 167 my $file_content = encode_base64( 167 168 read_file( 168 $self-> imagefile,169 $self->site_resized_file, 169 170 binmode => ':raw', 170 171 ) … … 172 173 173 174 my $file_sum = file_md5_hex( 174 $self-> imagefile175 $self->site_resized_file 175 176 ); 176 177 177 178 my $thumbnail_content = encode_base64( 178 179 read_file( 179 $self-> thumbfile,180 $self->site_thumb_file, 180 181 binmode => ':raw', 181 182 ) … … 183 184 184 185 my $thumbnail_sum = file_md5_hex( 185 $self->thumbfile 186 ); 186 $self->site_thumb_file, 187 ); 188 187 189 188 190 … … 194 196 thumbnail_content => $thumbnail_content, 195 197 categories => $self->categories, 196 name => $self-> imagename,198 name => $self->site_image_name, 197 199 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, 201 203 202 204 }; 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 203 218 204 219 my $result = $self->uagent->post(
Note: See TracChangeset
for help on using the changeset viewer.