Changeset 2661 for extras/pLoader/trunk


Ignore:
Timestamp:
Oct 5, 2008, 12:31:42 AM (16 years ago)
Author:
ronosman
Message:
  • remove Save and Cancel buttons from properties panels. Use callbacks instead.
  • limit Global settings panel instances to one.
  • fix resize crash with huge images. use Wx::Image methods when IM fails.
  • add categories is implemented in tree control. right click popup menu with Add an Refresh commands.
Location:
extras/pLoader/trunk
Files:
1 added
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • extras/pLoader/trunk/build/build_pLoader.bat

    r2597 r2661  
    1 wxpar.bat @par_options.txt --icon=..\res\favicon.ico -output=pLoader.exe ..\src\pLoader.pl
     1wxpar.bat @par_options.txt --gui --icon=..\res\favicon.ico -output=pLoader.exe ..\src\pLoader.pl
  • extras/pLoader/trunk/res/global_settings_wdr.pl

    r2618 r2661  
    2424use vars qw($ID_GLOBAL_RESIZED_W); $ID_GLOBAL_RESIZED_W = 10004;
    2525use vars qw($ID_GLOBAL_RESIZED_H); $ID_GLOBAL_RESIZED_H = 10005;
    26 use vars qw($ID_GLOBAL_OK); $ID_GLOBAL_OK = 10006;
    27 use vars qw($ID_GLOBAL_CANCEL); $ID_GLOBAL_CANCEL = 10007;
    2826
    2927sub GlobalSettings {
     
    6260    $item1->AddWindow( $item11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    6361
    64     $item1->AddSpace( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
    65 
    66     my( $item12 ) = Wx::BoxSizer->new( wxHORIZONTAL );
    67    
    68     my( $item13 ) = Wx::Button->new( $_[0], $main::ID_GLOBAL_OK, "Save", wxDefaultPosition, wxDefaultSize, 0 );
    69     $item13->SetDefault();
    70     $item12->AddWindow( $item13, 0, wxALIGN_CENTER|wxALL, 5 );
    71 
    72     my( $item14 ) = Wx::Button->new( $_[0], $main::ID_GLOBAL_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
    73     $item12->AddWindow( $item14, 0, wxALIGN_CENTER|wxALL, 5 );
    74 
    75     $item1->Add( $item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    76 
    7762    $item0->Add( $item1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    7863
  • extras/pLoader/trunk/res/photo_properties_wdr.pl

    r2618 r2661  
    2323use vars qw($ID_PHOTO_COMMENT); $ID_PHOTO_COMMENT = 10003;
    2424use vars qw($ID_PHOTO_CREATE_DATE); $ID_PHOTO_CREATE_DATE = 10004;
    25 use vars qw($ID_PHOTO_OK); $ID_PHOTO_OK = 10005;
    26 use vars qw($ID_PHOTO_CANCEL); $ID_PHOTO_CANCEL = 10006;
    2725
    2826sub PhotoProperties {
     
    5553    $item1->AddWindow( $item9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    5654
    57     $item1->AddSpace( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
    58 
    59     my( $item10 ) = Wx::BoxSizer->new( wxHORIZONTAL );
    60    
    61     my( $item11 ) = Wx::Button->new( $_[0], $main::ID_PHOTO_OK, "Save", wxDefaultPosition, wxDefaultSize, 0 );
    62     $item11->SetDefault();
    63     $item10->AddWindow( $item11, 0, wxALIGN_CENTER|wxALL, 5 );
    64 
    65     my( $item12 ) = Wx::Button->new( $_[0], $main::ID_PHOTO_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 );
    66     $item10->AddWindow( $item12, 0, wxALIGN_CENTER|wxALL, 5 );
    67 
    68     $item1->Add( $item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    69 
    7055    $item0->Add( $item1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    7156
  • extras/pLoader/trunk/src/Uploader/GUI/wxApp.pm

    r2618 r2661  
    2727             wxBITMAP_TYPE_PNG
    2828             wxBITMAP_TYPE_JPEG
     29             wxIMAGE_QUALITY_NORMAL
     30             wxIMAGE_QUALITY_HIGH
    2931             wxSPLASH_CENTRE_ON_SCREEN
    3032             wxSPLASH_TIMEOUT
     
    168170        eval {
    169171            $stored_imagelist = retrieve $self->storable_file;
    170             $stored_imagelist->{images_h} = {};
    171172        };
    172173        if($@){
     174            Wx::LogMessage(
     175                "An error has occured. Can not read %s\n%s",
     176                $self->storable_file,
     177                $@
     178            );
    173179            $stored_imagelist = $self->_default_imagelist_params ;
    174180        }
     
    183189        )
    184190    );
     191
     192    $self->imagelist->ResizeCallback(
     193        sub { $self->ResizeImage(@_) }
     194    );
    185195}
    186196
     
    191201    my $params = {
    192202        thumb_size       => 120,
    193         site_thumb_dir        => $self->thumb_dir,
     203        site_thumb_dir   => $self->thumb_dir,
    194204        wx_thumb_size    => 120,
    195205        wx_thumb_dir     => $self->wx_thumb_dir,
     
    198208        resize_w         => 800,
    199209        resize_h         => 600,
    200         site_resized_dir      => $self->resized_dir,
     210        site_resized_dir => $self->resized_dir,
    201211        type             => 'jpg',
    202212        filter           => 'Lanczos',
    203         blur             => 1,
    204         quality          => 90,
     213        blur             => 0.9,
     214        quality          => 100,
    205215        prefix           => 'TN',
    206216        count            => 0,
    207217        storable_file    => $self->storable_file,
    208218        images           => [],
    209         images_h         => {},
    210219        userdata_dir     => $self->userdata_dir,
    211220        default_name_prefix => 'Photo',
    212221        upload_rejects  =>  [],
     222        ResizeCallback  => sub { $self->ResizeImage(@_) },
    213223    };
    214224
     
    254264        )
    255265    );
    256     printf(
    257         "conf file %s\n",
    258         $self->conf_file
    259     );
     266
    260267   
    261268
     
    326333}
    327334
     335
     336sub ResizeImage {
     337    my ( $self, $image_file, $image_file_out, $type, $ratio, $width, $height, $quality ) = @_;
     338   
     339
     340    my $image = Wx::Image->new(
     341            $image_file,
     342            $self->GetWxBitmapType($type),
     343            0
     344    );
     345   
     346    my $w;
     347    my $h;
     348
     349    my $img_w = $image->GetWidth;
     350    my $img_h = $image->GetHeight;
     351   
     352    # use a ratio ( 25% default ) if defined
     353    # default ratio is used for preview.
     354    if($ratio){
     355        $w = $ratio*$img_w/100 ;
     356        $h = $ratio*$img_h/100 ;
     357    }
     358    # use specified width and height
     359    else{
     360        # portrait
     361        if( $img_w < $img_h ){
     362            $w = $height;
     363        }
     364        else{
     365            $w = $width;
     366        }
     367        # to respect aspect ratio
     368        $h = sprintf(
     369            "%.0f",
     370            ($w*$img_h)/$img_w
     371        );
     372    }
     373
     374    $image->Rescale(
     375        $w,
     376        $h,
     377        wxIMAGE_QUALITY_HIGH
     378    );
     379   
     380    $quality ||= 90;
     381   
     382    $image->SetOption(
     383        "quality",
     384        $quality
     385    );
     386   
     387    if(!$image->SaveFile(
     388        $image_file_out,
     389        $self->GetWxBitmapType($type),
     390    )){
     391        Wx::LogMessage(
     392            "An error has occured. Can not save file %s",
     393            $image_file_out,
     394        )
     395    };
     396}
    328397
    329398sub _init_frame {
     
    363432            width     => $w,
    364433            height    => $h,
    365             title     => "pLoader - Piwigo uploader - [$url]" ,
     434            title     => "pLoader - Piwigo uploader 1.0 RC2 - [$url]" ,
    366435            pwg       => $self->pwg,
    367436            imagelist => $self->imagelist,
  • extras/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm

    r2618 r2661  
    5757             wxTR_HAS_BUTTONS
    5858             wxMAXIMIZE
     59             wxOK
     60             wxICON_EXCLAMATION
    5961         /;
    6062use base qw/Wx::Frame Class::Accessor::Fast/;
     
    9092          EVT_MENU
    9193          EVT_TREE_SEL_CHANGED
    92           EVT_UPDATE_UI
    9394          EVT_CLOSE
    9495          EVT_LIST_END_LABEL_EDIT
    95           EVT_LIST_ITEM_SELECTED       
     96          EVT_LIST_ITEM_SELECTED
     97          EVT_TREE_ITEM_RIGHT_CLICK       
    9698      /;
    9799     
     
    106108use Uploader::GUI::wxPhotoExifPanel;
    107109use Uploader::GUI::wxGlobalSettingsPanel;
     110use Encode qw/encode decode is_utf8/;
    108111
    109112$|=1;
     113
     114my $ID_TREE_CTX_MENU = 20000 ;
    110115
    111116sub new {
     
    147152    );
    148153
     154    $self->imagelist->categories(
     155        []
     156    );
     157
    149158    $self->manager( Wx::AuiManager->new );
    150159    $self->manager->SetManagedWindow( $self );
     
    203212                parentwnd => $self,
    204213                accessors => {
    205                                  name         => [
    206                                                      sub { $self->imagelist->current_image->site_name(@_) },
    207                                                      $main::ID_PHOTO_NAME
    208                                                  ],
    209                                  date_created => [
    210                                                      sub { $self->imagelist->current_image->create_date(@_) },
    211                                                      $main::ID_PHOTO_CREATE_DATE
    212                                                  ],
    213                                  comment      => [
    214                                                      sub { $self->imagelist->current_image->site_comment(@_) },
    215                                                      $main::ID_PHOTO_COMMENT
    216                                                  ],
    217                                  author       => [
    218                                                      sub { $self->imagelist->current_image->site_author(@_) },
    219                                                      $main::ID_PHOTO_AUTHOR
    220                                                  ],
     214                                  $main::ID_PHOTO_NAME =>
     215                                      sub { $self->imagelist->current_image->site_name(@_) },
     216
     217                                  $main::ID_PHOTO_CREATE_DATE =>
     218                                      sub { $self->imagelist->current_image->create_date(@_) },
     219                                 
     220                                  $main::ID_PHOTO_COMMENT =>
     221                                      sub { $self->imagelist->current_image->site_comment(@_) },
     222                                 
     223                                  $main::ID_PHOTO_AUTHOR =>
     224                                      sub { $self->imagelist->current_image->site_author(@_) },
    221225                             },
    222                 frame_callback => sub {
    223                                       $self->imageviewer->Refresh();
    224                                   },
     226                frame_callbacks => {
     227                                      $main::ID_PHOTO_NAME =>
     228                                          sub {
     229                                              $self->imageviewer->Refresh();
     230                                          },
     231                                   },
    225232            }
    226233        )
     
    231238            {
    232239                parentwnd => $self,
     240                frame_callback => sub {
     241                                      $self->imageviewer->Refresh();
     242                                  },
    233243                accessors => {
    234                                  create_date   => [
    235                                                       sub { $self->imagelist->current_image->create_date },
    236                                                       $main::ID_EXIF_CREATE_DATE
    237                                                   ],
    238                                  model         => [
    239                                                       sub { $self->imagelist->current_image->exif_tag('Model') },
    240                                                       $main::ID_EXIF_MODEL
    241                                                   ],
    242                                  width         => [
    243                                                       sub { $self->imagelist->current_image->exif_tag('ImageWidth') },
    244                                                       $main::ID_EXIF_WIDTH
    245                                                   ],
    246                                  height        => [
    247                                                       sub { $self->imagelist->current_image->exif_tag('ImageHeight') },
    248                                                       $main::ID_EXIF_HEIGHT
    249                                                   ],
    250                                  orientation   =>  [
    251                                                       sub { $self->imagelist->current_image->exif_tag('Orientation') },
    252                                                       $main::ID_EXIF_ORIENTATION
    253                                                   ],
    254                                  iso           =>  [
    255                                                       sub { $self->imagelist->current_image->exif_tag('ISO') },
    256                                                       $main::ID_EXIF_ISO
    257                                                   ],
    258                                  shutter_speed => [
    259                                                       sub { $self->imagelist->current_image->exif_tag('ShutterSpeedValue') },
    260                                                       $main::ID_EXIF_SHUTTER_SPEED
    261                                                   ],
    262                                  aperture      => [
    263                                                       sub { $self->imagelist->current_image->exif_tag('ApertureValue') },
    264                                                       $main::ID_EXIF_APERTURE
    265                                                   ],
    266                                  focal_length  => [
    267                                                       sub { $self->imagelist->current_image->exif_tag('FocalLength') },
    268                                                       $main::ID_EXIF_FOCAL_LENGTH
    269                                                   ],
    270                                  lens          => [
    271                                                       sub { $self->imagelist->current_image->exif_tag('Lens') },
    272                                                       $main::ID_EXIF_LENS
    273                                                   ],
     244                                  $main::ID_EXIF_CREATE_DATE =>
     245                                      sub { $self->imagelist->current_image->create_date },
     246                                  $main::ID_EXIF_MODEL =>
     247                                      sub { $self->imagelist->current_image->exif_tag('Model') },
     248                                  $main::ID_EXIF_WIDTH =>
     249                                      sub { $self->imagelist->current_image->exif_tag('ImageWidth') },
     250                                  $main::ID_EXIF_HEIGHT =>
     251                                      sub { $self->imagelist->current_image->exif_tag('ImageHeight') },
     252                                  $main::ID_EXIF_ORIENTATION =>
     253                                      sub { $self->imagelist->current_image->exif_tag('Orientation') },
     254                                  $main::ID_EXIF_ISO =>
     255                                      sub { $self->imagelist->current_image->exif_tag('ISO') },
     256                                  $main::ID_EXIF_SHUTTER_SPEED =>
     257                                      sub { $self->imagelist->current_image->exif_tag('ExposureTime') },
     258                                  $main::ID_EXIF_APERTURE =>
     259                                      sub { $self->imagelist->current_image->exif_tag('ApertureValue') },
     260                                  $main::ID_EXIF_FOCAL_LENGTH =>
     261                                      sub { $self->imagelist->current_image->exif_tag('FocalLength') },
     262                                  $main::ID_EXIF_LENS =>
     263                                      sub { $self->imagelist->current_image->exif_tag('Lens') },
    274264                             },
    275265            }
     
    341331    my ( $self ) = @_;
    342332
    343     $self->global_settings_panel(
    344         $self->create_global_settings_panel()
    345     );   
    346 
    347     $self->manager->AddPane
    348       ( $self->create_notebook_global_settings, Wx::AuiPaneInfo->new->Name( "global_settings" )
    349         ->Right->Position( 2 )->Resizable->CloseButton(1) );
    350 
     333    $self->manager->GetPane("global_settings")->Show(1);
    351334    $self->manager->Update();   
    352        
    353335}
    354336
     
    428410                parentwnd => $self,
    429411                accessors => {
    430                                  default_name_prefix  =>
    431                                                  [
    432                                                      sub { $self->imagelist->default_name_prefix(@_) },
    433                                                      $main::ID_GLOBAL_NAME_PREFIX
    434                                                  ],
    435                                  author       => [
    436                                                      sub { $self->imagelist->author(@_) },
    437                                                      $main::ID_GLOBAL_AUTHOR
    438                                                  ],
    439                                  thumb_size       => [
    440                                                      sub { $self->imagelist->thumb_size(@_) },
    441                                                      $main::ID_GLOBAL_THUMB_SIZE
    442                                                  ],
    443                                  resize_w       => [
    444                                                      sub { $self->imagelist->resize_w(@_) },
    445                                                      $main::ID_GLOBAL_RESIZED_W
    446                                                  ],
    447                                  resize_h       => [
    448                                                      sub { $self->imagelist->resize_h(@_) },
    449                                                      $main::ID_GLOBAL_RESIZED_H
    450                                                  ],
     412                                  $main::ID_GLOBAL_NAME_PREFIX =>
     413                                      sub { $self->imagelist->default_name_prefix(@_) },
     414                                  $main::ID_GLOBAL_AUTHOR =>
     415                                      sub { $self->imagelist->author(@_) },
     416                                  $main::ID_GLOBAL_THUMB_SIZE =>
     417                                      sub { $self->imagelist->thumb_size(@_) },
     418                                  $main::ID_GLOBAL_RESIZED_W =>
     419                                      sub { $self->imagelist->resize_w(@_) },
     420                                  $main::ID_GLOBAL_RESIZED_H =>
     421                                      sub { $self->imagelist->resize_h(@_) },
    451422                             },
    452                 frame_callback => sub {
    453                                       Wx::LogMessage("Author %s", $self->imagelist->author);
    454                                   },
     423                frame_callbacks => {
     424                                   },
    455425            }
    456426        );
     
    466436        }
    467437        (
     438          '../res/tree_pwg.png',
    468439          '../res/tree_folder.png',
    469440        )   
     
    487458#           wxTR_MULTIPLE|
    488459#           wxTR_EXTENDED|
    489            wxTR_HAS_BUTTONS|
    490            wxTR_HIDE_ROOT   
     460           wxTR_HAS_BUTTONS
     461#           wxTR_HIDE_ROOT   
    491462        )
    492463    );
    493464
    494465    $self->tree->SetImageList( $self->treeimglist );
     466    $self->populate_tree_categories;
     467    $self->tree ;
     468}
     469
     470
     471sub populate_tree_categories {
     472    my ( $self ) = @_;
    495473
    496474    $self->populate_tree(
     
    499477    ) if defined wxTheApp->pwg ;
    500478   
    501     $self->tree->SelectItem( $self->tree_item_default, 1) if defined $self->tree_item_default;
    502 
    503     my $category = $self->tree->GetPlData(
    504         $self->tree_item_default
    505     ) if defined $self->tree_item_default;;
    506 
    507     $self->imagelist->categories(
    508         []
    509     );
    510 
    511     $self->imagelist->categories(
    512         [ $category->{id} ]
    513     ) if $category != -1;
    514 
    515479    $self->tree->ExpandAll;
    516     $self->tree ;
    517 }
    518 
     480
     481}
    519482
    520483#$tree_items is a list of anonymous arrays
     
    559522
    560523  map {
     524      my $name = $_->[0];
    561525      $id = $tree->AppendItem(
    562526                                  $parent_id,
    563                                   $_->[0],
    564                                   0,
    565                                   0,
    566                                   #defined($_->[3]) ? $_->[3] : 0,
    567                                   #defined($_->[4]) ? $_->[4] : 0,
     527                                  is_utf8($name) ? decode('UTF-8', $name) : $name,
     528                                  defined($_->[3]) ? $_->[3] : 0,
     529                                  defined($_->[4]) ? $_->[4] : 0,
    568530                                  itemData( $_->[2])
    569531                             );
     
    575537  }
    576538  @{$tree_items};
     539 
    577540
    578541}
     
    612575    Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings );
    613576    EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged );
     577    EVT_TREE_ITEM_RIGHT_CLICK( $self->tree, $self->tree, \&OnTreeItemRightClick );
    614578    EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit );
    615579    EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ;
    616580    EVT_CLOSE( $self, \&OnClose );
    617581
     582
     583    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories );
     584    Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories );
    618585}
    619586
     
    682649        ]
    683650    );
    684    
     651}
     652
     653sub OnTreeItemRightClick {
     654    my( $self, $event ) = @_;
     655
     656    my $point = $event->GetPoint ;
     657    my $ctx_mnu = Wx::Menu->new;
     658   
     659    map {
     660        $ctx_mnu->Append(
     661            @$_
     662        );
     663    }
     664    (
     665        [1+$ID_TREE_CTX_MENU, "Add new category","Add a new category to the current selected category."],
     666        [2+$ID_TREE_CTX_MENU, "Refresh","Refresh category list."],
     667    );
     668    $self->PopupMenu($ctx_mnu, $point);
     669       
     670}
     671
     672sub OnAddCategories {
     673    my ( $self, $event ) = @_;
     674
     675    my $item = $self->tree->GetSelection;
     676
     677    my $category = $self->tree->GetPlData($item);
     678    my $category_id;
     679   
     680    $category_id = $category->{id} if 'HASH' eq ref($category) ;
     681
     682    my $dialog = Wx::TextEntryDialog->new(
     683        $self,
     684        "Category name :",
     685        "Add new category",
     686        "New category"
     687    );
     688
     689    if( $dialog->ShowModal != wxID_CANCEL ) {
     690        my $name = $dialog->GetValue;
     691        my ( $status, $status_msg ) = $self->pwg->AddCategories( $name, $category_id);
     692        $self->_refresh_tree_categories_helper;
     693    }
     694    $dialog->Destroy;
     695}
     696
     697sub OnRefreshCategories {
     698    my ( $self, $event ) = @_;
     699
     700    $self->_refresh_tree_categories_helper;
     701}
     702
     703sub _refresh_tree_categories_helper {
     704    my ( $self ) = @_; 
     705
     706    my $busycursor = Wx::BusyCursor->new();
     707    $self->tree->CollapseAll;
     708    $self->tree->DeleteAllItems;
     709    $self->imagelist->categories([]);
     710    $self->pwg->RefreshCategories();
     711    $self->populate_tree_categories;
    685712}
    686713
     
    814841
    815842    return if !scalar @{$self->imagelist->images};
    816 
    817843
    818844    if( scalar @{$self->imagelist->categories} ){
     
    832858    }
    833859    else {
    834         Wx::LogMessage("Please select a category");
     860        Wx::MessageBox(
     861            sprintf(
     862                "Please select a valid target category",
     863            ),
     864            "Piwigo upload error",
     865            wxOK | wxICON_EXCLAMATION,
     866        );
    835867    }
    836868}
     
    10321064           }
    10331065           
     1066           # remove root item which is not a valid category
     1067           @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items;
     1068           
    10341069           $self->frame->imagelist->categories(
    10351070               [
    10361071                   map {
    1037                        my $category = $self->tree->GetPlData( $_ );
    1038                        $category->{id} if $category != -1;
     1072                       $self->tree->GetPlData( $_ )->{id};
    10391073                   }
    10401074                   @items
    10411075               ]
    10421076           );
     1077           
    10431078           $self->frame->imagelist->image_selection($VAR1);
    10441079           $self->frame->ProcessImageSelection ;
  • extras/pLoader/trunk/src/Uploader/GUI/wxGlobalSettingsPanel.pm

    r2597 r2661  
    3232
    3333use Wx::Event qw/
    34                     EVT_BUTTON
     34                    EVT_TEXT
    3535                /;
    3636
     
    5555
    5656   
    57     $self->InitAccessors( $params->{accessors} );
    58     $self->frame_callback(
    59         $params->{frame_callback}
     57    $self->accessors( $params->{accessors} );
     58    $self->frame_callbacks(
     59        $params->{frame_callbacks}
    6060    );
    6161   
     
    9090    my ( $self ) = @_;
    9191   
    92     EVT_BUTTON( $self, $main::ID_GLOBAL_OK, \&OnOK );
    93     EVT_BUTTON( $self, $main::ID_GLOBAL_CANCEL, \&OnCancel );
     92    map {
     93        my $ctrl = $self->FindWindow($_);
     94        EVT_TEXT($self, $ctrl, sub { OnTextChanged(@_) });
     95    }
     96    keys %{$self->accessors};   
     97
     98}
     99
     100sub OnTextChanged {
     101    my ( $self, $event ) = @_;
    94102   
    95        
     103    my $control_id = $event->GetId ;
     104
     105    $self->accessors->{$control_id}->(
     106        $event->GetString
     107    );
     108   
     109   
     110    my $frame_callback = $self->frame_callbacks->{$control_id};
     111
     112    eval{
     113        $frame_callback->() if defined $frame_callback;
     114    };
    96115}
    97116
    98117
    99118
    100 sub OnOK {
    101     my ( $self, $event ) = @_;
    102    
    103 
    104     $self->GetControlValues();
    105     $self->frame_callback->();
    106 }
    107 
    108 sub OnCancel {
    109     my ( $self, $event ) = @_;
    110    
    111     # reset previous values   
    112  
    113 }
    114 
    115 
    1161191;
  • extras/pLoader/trunk/src/Uploader/GUI/wxPhotoExifPanel.pm

    r2597 r2661  
    3535                /;
    3636
    37 #__PACKAGE__->mk_accessors(
    38 #    qw/
    39 #           btok
    40 #           name
    41 #           description
    42 #           date_created
    43 #      /
    44 #);
    4537
    4638    __PACKAGE__->mk_accessors(     
     
    6052
    6153   
    62     $self->InitAccessors( $params->{accessors} );
     54    $self->accessors( $params->{accessors} );
    6355   
    6456    # load controls
  • extras/pLoader/trunk/src/Uploader/GUI/wxPhotoPropertiesPanel.pm

    r2597 r2661  
    3131
    3232use Wx::Event qw/
    33                     EVT_BUTTON
     33                    EVT_TEXT
    3434                /;
    3535
    3636
    37 __PACKAGE__->mk_accessors(     
    38     qw/
    39         accessors
    40         frame_callback
    41       /
    42 );
    4337
    4438
     
    5448
    5549   
    56     $self->InitAccessors( $params->{accessors} );
    57     $self->frame_callback(
    58         $params->{frame_callback}
     50    $self->accessors( $params->{accessors} );
     51    $self->frame_callbacks(
     52        $params->{frame_callbacks}
    5953    );
    6054   
    6155    # load controls
    6256    &main::PhotoProperties($self, 1);
    63     
     57 
    6458
    6559    $self->_initEventHandlers();
     
    7468    my ( $self ) = @_;
    7569   
    76     EVT_BUTTON( $self, $main::ID_PHOTO_OK, \&OnOK );
    77     EVT_BUTTON( $self, $main::ID_PHOTO_CANCEL, \&OnCancel );
    78    
    79        
     70       
     71    map {
     72        my $ctrl = $self->FindWindow($_);
     73        EVT_TEXT($self, $ctrl, sub { OnTextChanged(@_) });
     74    }
     75    keys %{$self->accessors};   
    8076}
    8177
    8278
    8379
    84 sub OnOK {
     80sub OnTextChanged {
    8581    my ( $self, $event ) = @_;
    8682   
     83    my $control_id = $event->GetId ;
     84   
     85    $self->accessors->{$control_id}->(
     86        $event->GetString
     87    );
     88       
     89    my $frame_callback = $self->frame_callbacks->{$control_id};
    8790
    88     $self->GetControlValues();
    89     $self->frame_callback->();
    90 }
    91 
    92 sub OnCancel {
    93     my ( $self, $event ) = @_;
    94    
    95     # reset previous values   
    96  
     91    eval{
     92        $frame_callback->();
     93    };
    9794}
    9895
    9996
     97
    100981;
  • extras/pLoader/trunk/src/Uploader/ImageList.pm

    r2618 r2661  
    4848                current_image
    4949                images
    50                 images_h
    5150                image_selection
    5251                exif_metadata
     
    5857                userdata_dir
    5958                progress_msg
     59                last_error_msg
    6060                default_name_prefix
    6161                SetNewFilesViewerRefreshCallback
     
    6363                UploadImagesViewerCallback
    6464                UploadImagesProgressCallback
     65                ResizeCallback
    6566                upload_rejects
    6667                pwg
     
    7576
    7677
    77 
    78 sub _write_images_from_exif {
    79     my ( $self, $info ) = @_;
     78# save exif preview image if available
     79# otherwise create a preview image
     80sub _write_preview_image {
     81    my ( $self, $imagedata ) = @_;
    8082
    8183
    8284    # If PreviewImage is available, we use it
    83     if(defined $info->{PreviewImage} ) {
     85    if(defined $imagedata ) {
    8486        eval {
    8587            open PREVIEW_FILE, ">", $self->current_image->preview_file ;
    8688            binmode PREVIEW_FILE;
    87             print PREVIEW_FILE ${$info->{PreviewImage}};
     89            print PREVIEW_FILE $$imagedata;
    8890            close PREVIEW_FILE;
    8991        };
    90         warn $@ if $@;
     92        $self->last_error_msg($@) if $@;
    9193    }
    92     else {
    93         # create a preview file
    94         $self->CreateGUIPreview();     
    95     }   
    96     # use the preview image to create a gui display thumbnail
    97     $self->CreateGUIThumbnail();
    9894   
    9995}
     
    131127    );
    132128
    133     $self->current_image->site_resized_file(
    134         File::Spec->catfile(
    135             $self->site_resized_dir,
    136             sprintf(
    137                 "%s_%sx%s.%s",
    138                 $filename,
    139                 $self->resize_w,
    140                 $self->resize_h,
    141                 $self->type,
    142             )
    143         )
    144     );
    145129
    146130    $self->current_image->site_thumb_file(
     
    166150}
    167151
     152
    168153sub SetNewFiles {
    169154    my ( $self, $files ) = @_;
    170    
     155
    171156    $self->new_files( $files );
    172157
     
    174159    my $i = scalar @{$self->images};
    175160    map {
    176         $self->progress_msg("Creating thumbnail and preview for %s");
    177        
    178         # Only add new images
    179         if(! exists $self->images_h->{$_} ){
    180             # exif metadata
    181             my $info = ImageInfo( $_ );
    182             $self->_add_image($_, $info, $i);   
    183             $self->SetCurrentImage($i);
    184             $self->_set_current_image_filepaths();
    185             $self->_write_images_from_exif($info );
     161        # read exif metadata
     162        my $info;
     163
     164
     165        eval {
     166            $info = ImageInfo( $_ );
     167        };
     168
     169        $info = {} if($@);
     170
     171        $self->_add_image($_, $info, $i);       
     172        $self->SetCurrentImage($i);
     173        $self->_set_current_image_filepaths();
     174
     175       
     176        # an exif preview is available. we use it
     177        if(defined $info->{PreviewImage}){
     178            $self->_write_preview_image( $info->{PreviewImage} );
     179        }
     180        # have to create a preview file
     181        else {
     182            eval {
     183                if(!$self->CreateGUIPreview()){
     184                    # use method provided by the caller
     185                    # source, target, type, ratio
     186                    $self->ResizeCallback->(
     187                        $self->current_image->file,
     188                        $self->current_image->preview_file,
     189                        $self->type,
     190                        $self->preview_ratio,
     191                        undef,
     192                        undef,
     193                        $self->quality,
     194                    );
     195                }
     196            };# create a preview file
     197        }   
     198        # Now, we should have a valid preview image.
     199        # try to thumbnail it
     200        eval {
     201            # use the preview image to create a gui display thumbnail
     202            $self->CreateGUIThumbnail();
     203        };
     204        # ok
     205        if(!$@){
     206            $self->progress_msg("Thumbnail and preview created for %s");
    186207            $i++;
    187208            $self->count($i);
    188            
    189             $self->SetNewFilesProgressCallback->();
    190             $self->SetNewFilesViewerRefreshCallback->();
    191         }
     209        }
     210        else {
     211            $self->progress_msg("An error has occured when processing %s\n$@");
     212            # remove from list
     213            splice @{$self->images}, $i, 1;
     214        }
     215       
     216        $self->SetNewFilesProgressCallback->();
     217        $self->SetNewFilesViewerRefreshCallback->();
    192218
    193219    }
     
    204230    my $image = Uploader::Image->new(
    205231        {
    206                 file          => $_,
    207                 site_name          => sprintf(
    208                                              "%s %s",
    209                                              $self->default_name_prefix,
    210                                              $i,
    211                                          ),
    212                 site_author       => $self->author,
    213                 exif_metadata     => $self->_select_exif_data($info),
    214                 add_rank          => $i,
    215                 site_categories   => [],
    216                 site_tags         => [],
     232            file              => $_,
     233            site_name         => sprintf(
     234                                     "%s %s",
     235                                     $self->default_name_prefix,
     236                                     $i,
     237                                 ),
     238            site_author       => $self->author,
     239            exif_metadata     => $self->_select_exif_data($info),
     240            add_rank          => $i,
     241            site_categories   => [],
     242            site_tags         => [],
    217243        }
    218244    );
     
    221247    $self->images->[$i] = $image ;
    222248
    223     # to retrieve data by image file name
    224     $self->images_h->{$file} = $image ;
    225249}
    226250
     
    236260    map {
    237261        my $image = $self->images->[$_]->file;
    238         delete $self->images_h->{$image};
    239262        splice @{$self->images}, $_, 1 ;
    240263        $self->wx_thumb_imglist->Remove($_);
     
    252275
    253276    return 1 if( -e $self->current_image->wx_thumb_file );
     277    my $rval = 0;
    254278
    255279    my $image = new Image::Magick;
     
    263287        $self->current_image->preview_file
    264288    );
    265     warn "$status" if $status ;
     289    warn "$status" if $status;
     290    return $rval if $status;
    266291
    267292    $status = $image->Thumbnail(
    268293        geometry=>sprintf("%s%s>", $size*$size, '@')
    269294    );
    270     warn "$status" if $status ;
     295    warn "$status" if $status;
     296    return $rval if $status;
    271297
    272298    $status = $image->Set(background=>"white");
     
    294320        )
    295321    );
     322    warn "$status" if $status;
     323    return $rval if $status;
    296324
    297325    undef $image;
     326   
     327    $rval = 1;
     328   
     329    return $rval;
    298330}
    299331
     
    303335
    304336    return 1 if( -e $self->current_image->preview_file );
    305 
    306     my $image = new Image::Magick;
     337   
     338    my $rval = 1;
     339
     340    my $image = Image::Magick->new();
    307341
    308342    my $ratio = $self->preview_ratio;
    309343
    310     my $status = $image->ReadImage(
     344
     345    my $status = $image->Read(
    311346        $self->current_image->file
    312347    );
    313     warn "$status" if $status ;
     348    warn "$status ", $self->current_image->file, "\n" if $status ;
     349    return 0 if $status;
    314350
    315351    $status = $image->Thumbnail(
     
    321357    );
    322358    warn "$status" if $status ;
     359    return 0 if $status;
    323360
    324361
     
    333370
    334371
    335     $image->Write(
     372    $status = $image->Write(
    336373        sprintf(
    337374            "%s:%s",
     
    340377        )
    341378    );
     379    warn "$status" if $status ;
     380    return 0 if $status;
    342381   
    343382    undef $image;
    344383
     384    return $rval;
    345385}
    346386
     
    349389    my ( $self ) = @_;
    350390   
    351     return 1 if( -e $self->current_image->site_resized_file );
     391    my $rval = 1 ;
     392    return $rval if( -e $self->current_image->site_resized_file );
     393   
    352394
    353395    my $image = new Image::Magick;
     
    357399    );
    358400    warn "$status" if $status ;
     401    return 0 if $status;
    359402
    360403    my $w = $image->Get('width');
     
    377420    );
    378421    warn "$status" if $status ;
     422    return 0 if $status;
    379423
    380424    $status = $image->Set(Gravity=>"Center");
     
    391435        )
    392436    );
     437    warn "$status" if $status ;
     438    return 0 if $status;
    393439   
    394440    undef $image;
    395441
     442   
     443    $rval = 0 if $status;
     444
     445    return $rval;
    396446}
    397447
     
    400450   
    401451    return 1 if( -e $self->current_image->site_thumb_file );
     452   
     453    my $rval = 1;
    402454
    403455    my $image = new Image::Magick;
     
    438490    undef $image;
    439491
     492
     493    $rval = 0 if $status;
     494
     495    return $rval;
    440496}
    441497
     
    456512            DateTimeOriginal
    457513            ISO
    458             ShutterSpeedValue
     514            ExposureTime
    459515            ApertureValue
    460516            FocalLength
     
    515571    my ( $self ) = @_; 
    516572
     573    my $progress_msg;
    517574    my $progress_callback = $self->UploadImagesProgressCallback;
    518575    my $viewer_callback = $self->UploadImagesViewerCallback ;
     
    529586            $self->images->[$_]
    530587        );
     588
     589        my ( $vol, $dir, $file ) = File::Spec->splitpath(
     590            $self->current_image->file
     591        );
     592   
     593        my ( $filename, $ext ) = split /\./, $file ;
     594
     595        # is defined lately to make sure we have the last global properties ( resize_w, resize_h )
     596        $self->current_image->site_resized_file(
     597            File::Spec->catfile(
     598                $self->site_resized_dir,
     599                sprintf(
     600                    "%s_%sx%s.%s",
     601                    $filename,
     602                    $self->resize_w,
     603                    $self->resize_h,
     604                    $self->type,
     605                )
     606            )
     607        );
    531608       
    532609
     
    536613        # update upload progress dialog
    537614        $progress_callback->();
    538         $self->CreateResized();
    539 
    540        
     615        eval {
     616            if(!$self->CreateResized()){
     617                printf("CreateResized failed %s. Use ResizeCallback\n", $@);
     618                # use method provided by the caller
     619                # source, target, type, ratio, width, $height
     620                $self->ResizeCallback->(
     621                    $self->current_image->file,
     622                    $self->current_image->site_resized_file,
     623                    $self->type,
     624                    undef,
     625                    $self->resize_w,
     626                    $self->resize_h,
     627                    $self->quality,
     628                );
     629            }
     630        };
     631        if($@){
     632            $progress_msg = "An error has occured %s - %s\n$@";
     633        }
     634        else{
     635            $progress_msg = "Preparing thumbnail for %s - %s";
     636        }
     637
    541638        $self->progress_msg(
    542             "Preparing thumbnail for %s - %s"
     639             $progress_msg
    543640        );
    544641        # update upload progress dialog
    545642        $progress_callback->();
    546         $self->CreateThumbnail();
    547 
    548 
    549        
    550         $self->progress_msg(
    551             "Uploading %s - %s"
    552         );
     643        eval {
     644            $self->CreateThumbnail();
     645        };
     646        if($@){
     647            $self->progress_msg(
     648                "An error has occured  %s - %s\n$@"
     649            );
     650        }
     651        else{
     652            $self->progress_msg(
     653                "Uploading %s - %s"
     654            );
     655        }
    553656        # update upload progress dialog
    554657        $progress_callback->() ;
    555        
    556         $self->_prepare_upload();       
     658
     659        $self->_prepare_upload_properties();           
    557660        my ( $status, $status_msg ) = $self->pwg->UploadImage();
    558661
     
    563666        } else {
    564667            $self->progress_msg(
    565                 "An error occured.\n%s : %s upload is cancelled."
     668                "An error has occured.\n%s : %s upload is cancelled.\n$status_msg"
    566669            );
    567670            push @{$self->upload_rejects}, $self->current_image ;
     
    579682}
    580683
    581 sub _prepare_upload {
     684sub _prepare_upload_properties {
    582685    my ( $self ) = @_;
    583686   
  • extras/pLoader/trunk/src/Uploader/Object2.pm

    r2597 r2661  
    2626           /;
    2727
    28 # $param is a hash with :
    29 # key : member name
    30 sub InitAccessors {
    31     my ( $self, $accessors ) = @_;
    32    
    33     $accessors ||= {};
    34 
    35    
    36 
    37     # create member accessors
    38     __PACKAGE__->mk_accessors(     
    39         keys %$accessors
    40     );
    41    
    42    
    43     # member accessors initialization
    44     # accessor_name => [ sub {}, control_id ]
    45     map {
    46         $self->$_(
    47             $accessors->{$_}->[0]
    48         );
    49     }
    50     keys %$accessors;
    51 
    52     $self->accessors(
    53         $accessors
    54     );
    55    
    56     return $self;
    57 }
     28__PACKAGE__->mk_accessors(     
     29    qw/
     30        accessors
     31        frame_callbacks
     32      /
     33);
    5834
    5935
    6036
     37
     38
     39
     40# Set control values with accessor
    6141sub SetControlValues {
    6242    my ( $self ) = @_;
     
    6646    # accessor_name => [ sub {}, control_id ]
    6747    map {
    68         my ( $accessor, $control_id) = @{$accessors->{$_}};
    69        
     48        my $control_id = $_;
    7049        my $ctrl = $self->FindWindow($control_id) ;
    7150
     51        my $accessor = $accessors->{$control_id};
    7252        eval {
    73                 $ctrl->SetValue(
     53                $ctrl->ChangeValue(
    7454                    $accessor->()
    7555                );
     
    8868}
    8969
     70# Get values from controls. Set callback accessors with these values
    9071sub GetControlValues {
    9172    my ( $self ) = @_;
    9273
    9374    my $accessors = $self->accessors;
    94    
     75
    9576    # accessor_name => [ sub {}, control_id ]
    9677    map {
     
    11596
    11697
     98sub GetControlValue {
     99    my( $self, $control_id ) = @_;
     100   
     101    my $value;
     102    eval {
     103        my $ctrl = $self->FindWindow(
     104            $control_id
     105        );
     106       
     107        $value = $ctrl->GetValue;
     108       
     109        $self->accessors->{$control_id}->(
     110            $value
     111        );
     112    };
     113   
     114    return $value;
     115}
     116
     117
     118
     119
     120
     121
    1171221;
  • extras/pLoader/trunk/src/Uploader/PWG.pm

    r2597 r2661  
    4545
    4646    # for web services   
    47     $self->SUPER::Init();       
     47    $self->SUPER::Init();
     48   
     49    $self->RefreshCategories;   
     50
     51}
     52
     53sub RefreshCategories {
     54    my ( $self ) = @_;
    4855
    4956    $self->categories(
     
    5562
    5663
    57 
    58 
    59641;
  • extras/pLoader/trunk/src/Uploader/PWG/Categories.pm

    r2597 r2661  
    2020package Uploader::PWG::Categories;
    2121use strict;
     22use Data::Dumper;
    2223use base qw/
    2324           Uploader::Object
     
    5354    sort { $b <=> $a }
    5455    keys %$records;
    55    
     56
    5657    return [
    5758        [
    58             'All',
     59            'Categories',
    5960            undef,
    6061            -1,
    61             -1,
     62            0,
    6263            -1,
    6364           
    6465        ],
    65         values %$records,
     66        sort { $a->[6] <=> $b->[6] } values %$records,
    6667    ];
    6768}
     
    112113        undef,
    113114        $category,
    114         -1,
     115        1,
    115116        -1,
    116117        $parent,
  • extras/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r2618 r2661  
    4343           password
    4444           qry_list_categories
    45            qry_add_images
     45           qry_add_categories
    4646           items
    4747           tags
     
    160160   
    161161
     162    printf(
     163        "UploadImage %s\n",
     164        $self->imagefile
     165    );
    162166    my $file_content = encode_base64(
    163167        read_file(
     
    190194        thumbnail_content => $thumbnail_content,
    191195        categories        => $self->categories,
    192         name              => encode('UTF-8', $self->imagename),
     196        name              => $self->imagename,
    193197        rank              => $self->rank,
    194198        author            => $self->author,
     
    206210}
    207211 
    208  
     212
     213sub AddCategories{
     214    my ( $self, $name, $parentid ) = @_;
     215
     216    my $form = {
     217        method            => 'pwg.categories.add',
     218        name              => $name,
     219        parent            => $parentid,
     220       
     221    };
     222
     223    my $result = $self->uagent->post(
     224        $self->urlbase.'/ws.php?format=json',
     225        $form
     226    );
     227
     228    return ( $result->is_success, $result->status_line );
     229       
     230}
    2092311;
    210232   
  • extras/pLoader/trunk/src/ploader.pl

    r2597 r2661  
    1111# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
    1212# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
    13 # | General Public License for more details.                              |
     13# | General Public License for more details.  i                            |
    1414# |                                                                       |
    1515# | You should have received a copy of the GNU General Public License     |
Note: See TracChangeset for help on using the changeset viewer.