Changeset 6426 for extensions/pLoader


Ignore:
Timestamp:
May 31, 2010, 9:35:46 AM (14 years ago)
Author:
ronosman
Message:

Bug 1710 fixed : pLoader lack of concurrency support causes data inconsistency.

Location:
extensions/pLoader/trunk/src
Files:
12 added
4 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/GUI/DlgCommon.pm

    r5566 r6426  
    273273    # change the property value.
    274274    $self->properties->{$id}->{id_selection}->(
    275         $event->GetEventObject->GetSelectionsIds
     275        $event->GetEventObject->selection_ids
    276276    ) if exists $self->properties->{$id}->{id_selection};
    277277
     
    327327    map {
    328328        my $ctrl =$self->FindWindow($_)||$self->{$_};
    329         #printf("ctrl %s : %s\n", $_, $ctrl);       
    330329        if(defined $ctrl){
    331330            # checkbox, static text
  • extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm

    r6094 r6426  
    7676             wxBOLD
    7777             wxALIGN_CENTER
     78             wxUSER_ATTENTION_INFO
    7879         /;
    7980use base qw/Wx::Frame Class::Accessor::Fast/;
     
    8283use POSIX qw(ceil floor);
    8384
    84 require Win32 if($^O =~ /MSWin32/);
    85 
    86 
    87 
    88 my @properties =
    89     qw/
    90           progressdlg
    91           upload_progressdlg
    92           imageviewer
    93           imageviewer_img
    94           tree
    95           tree_root
    96           treeimglist
    97           tree_item_default
    98           pwg
    99           logwnd
    100           oldlogwnd
    101           categories
    102           imagelist
    103           image_preview_dlg
    104           image_prop_piwigo
    105           exif_dlg
    106           image_prop_tags
    107           global_settings_dlg
    108           piwigo_property_list
    109           exif_properties
    110           global_settings
    111           toolbar
    112           branding
    113           current_imageviewer_index
    114           imageviewer_mnu
    115           tree_mnu
    116           imageviewer_select_multi
    117           frameLayout
    118           piwigo_tags
    119           image_tags
    120           piwigo_photo_properties
    121           piwigo_photo_properties_dlg
    122           piwigo_photo_properties_tags
    123           image_preview_need_refresh
    124           imageviewer_refresh
    125           imageviewer_item_refresh
    126           horizontal_splitter
    127           destination_category_dlg
    128           destination_categories
    129           categories_treectrl
    130       /;
     85
     86my @properties = qw/
     87    images
     88    preferences
     89    upload_progressdlg
     90    image_progress_columns
     91    image_progress_event
     92    imageviewer
     93    imageviewer_img
     94    tree
     95    tree_root
     96    treeimglist
     97    tree_item_default
     98    pwg
     99    logwnd
     100    oldlogwnd
     101    image_preview_dlg
     102    image_prop_piwigo
     103    exif_dlg
     104    image_prop_tags
     105    preferences_dlg
     106    piwigo_property_list
     107    exif_properties
     108    preferences_properties
     109    toolbar
     110    branding
     111    current_imageviewer_index
     112    imageviewer_mnu
     113    tree_mnu
     114    imageviewer_select_multi
     115    frameLayout
     116    piwigo_tags
     117    image_tags
     118    piwigo_photo_properties
     119    piwigo_photo_properties_dlg
     120    piwigo_photo_properties_tags
     121    image_preview_need_refresh
     122    imageviewer_refresh
     123    imageviewer_item_refresh
     124    horizontal_splitter
     125    destination_category_dlg
     126    destination_categories
     127    categories_treectrl
     128/;
    131129__PACKAGE__->mk_accessors( @properties );
    132130
     
    134132use Uploader::GUI::wxImageListCtrl;
    135133use Uploader::GUI::wxPropertyListDlg;
    136 use Uploader::GUI::wxGlobalSettings;
     134use Uploader::GUI::Preferences;
    137135use Uploader::GUI::wxImagePreview;
    138136use Uploader::GUI::wxPhotoProperties;
    139137use Uploader::GUI::wxImageReuploadDlg;
    140 use Uploader::GUI::wxImageProcessingProgressDlg;
     138use Uploader::GUI::ImageProgressDlg;
    141139use Uploader::GUI::wxDestinationCategoryDlg;
    142140use Uploader::GUI::wxCategoryTreeCtrl;
     
    160158    );
    161159
    162 
    163160    $self->pwg( $params->{pwg} );
    164     $self->imagelist( $params->{imagelist} );
    165 
    166 
    167     $self->imagelist->pwg(
    168         $self->pwg
    169     );
    170 
    171     $self->imagelist->categories(
    172         []
    173     );
     161    $self->images( $params->{images} );
     162    $self->preferences( $params->{preferences} );
    174163
    175164
     
    181170    $self->init_image_types;   
    182171
    183     $self->imageviewer->SelectItem(
     172    $self->imageviewer->select_item(
    184173        $self->current_imageviewer_index
    185174    ) if $self->imageviewer->GetItemCount;
     
    187176    # if file in command line parameters, try to load
    188177    my $files = wxTheApp->argv;
    189     $self->SetNewFiles($files) if scalar @$files;
     178    $self->add_images($files) if scalar @$files;
    190179
    191180    $self->Show;
     
    198187
    199188    # callback for GUI refresh : add thumbnail images to the imageviewer control
    200     $self->imagelist->SetNewFilesViewerRefreshCallback(
    201         sub { $self->SetNewFilesViewerRefresh(@_) }
    202     );
    203 
    204     # callback for GUI refresh : progress dialog display of thumbnail image being created
    205     $self->imagelist->SetNewFilesProgressCallback(
    206         sub { $self->SetNewFilesProgress(@_) }
    207     );
    208 
    209     $self->imagelist->SetNewFilesDisplayEndInfoCallback(
    210         sub { $self->SetNewFilesDisplayEndInfo(@_) }
    211     );
    212 
    213     # callback for GUI refresh : remove thumbnail images from imageviewer control
    214     $self->imagelist->UploadImagesViewerCallback(
    215         sub { $self->UploadImagesViewerRefresh(@_) }
    216     );
    217    
    218     $self->imagelist->ReuploadCallback(
    219     sub
    220     {
    221         Uploader::GUI::wxImageReuploadDlg->new(
    222         {
    223             title => gettext("Photo update management"),
    224             properties =>
    225             {
    226                 $main::ID_REUPLOAD_ACTION_FILES =>
    227                 {
    228                     selection=>sub {$self->imagelist->reupload_action_files(@_)},
    229                     label=>gettext("What shall we do with files? (thumbnail, resized, high resolution)"),
    230                     labels=>[
    231                         gettext("nothing"),
    232                         gettext("replace"),
    233                     ],
    234                 },
    235                 $main::ID_REUPLOAD_ACTION_PROPERTIES =>
    236                 {
    237                     selection=>sub{$self->imagelist->reupload_action_properties(@_)},
    238                     label=>gettext("What shall we do with single value properties?(caption, comment, author, create date)"),
    239                     labels=>[
    240                         gettext("nothing"),
    241                         gettext("fill if empty (only replace properties currently empty in Piwigo)"),
    242                         gettext("replace"),
    243                     ],
    244                 },
    245                 $main::ID_REUPLOAD_ACTION_PROPERTIES_M =>
    246                 {
    247                     selection=>sub{$self->imagelist->reupload_action_properties_m(@_)},
    248                     label=>gettext("What shall we do with multiple values properties? (categories, tags)"),
    249                     labels=>[
    250                         gettext("nothing"),
    251                         gettext("append (keep existing and add new)"),
    252                         gettext("replace"),
    253                     ],
    254                 },
    255                 $main::ID_REUPLOAD_NOT_ASK =>
    256                 {
    257                     value=>sub{$self->imagelist->reupload_not_ask(@_)},
    258                     label=>gettext("Do not ask me again"),
    259                 },
    260                 $main::ID_REUPLOAD_TEXT =>
    261                 {
    262                     label=>gettext("A least one photo has already been added in the past."),
    263                 },
    264             },
    265         } )->ShowModal();}
    266     );
    267 
    268 
    269     # callback for GUI refresh : progress dialog display current uploaded image
    270     $self->imagelist->progress_thumbnail_refresh(
    271         sub { $self->UploadProgressThumbnailRefresh(@_) }
    272     );
    273 
    274     $self->imagelist->progress_msg_refresh(
    275         sub { $self->UploadProgressMessageRefresh(@_) }
    276     );
    277 
    278     $self->imagelist->progress_msg_details_refresh(
    279         sub { $self->UploadProgressMessageDetailsRefresh(@_) }
    280     );
    281 
    282     $self->imagelist->progressbar_refresh(
    283         sub { $self->UploadProgressBarRefresh(@_) }
    284     );
    285    
    286     $self->imagelist->progress_endinfo_refresh(
    287         sub { $self->UploadDisplayEndInfo(@_) }
    288     );
     189    $self->images->add_images_cbk(
     190        sub { $self->add_images_viewer_refresh(@_) }
     191    );
     192
     193    $self->images->delete_images_cbk(
     194        sub { $self->delete_images_viewer_refresh(@_) }
     195    );
     196
     197
    289198}
    290199
     
    300209                string_selection => sub { return 1; },
    301210                value => sub {
    302                     $self->imagelist->SetImageSelectionName(@_);
     211                    $self->images->set_image_selection_name(@_);
    303212                    $self->multi_selection_mode ?
    304                     $self->imagelist->image_selection_name :
    305                     $self->imagelist->current_image->site_name;
     213                    $self->images->selection_name :
     214                    $self->images->current_image->site_name;
    306215                },
    307                 pre_process => sub { sub { $self->imagelist->GetCurrentImageCaption(@_); } },
     216                pre_process => sub { sub { $self->images->get_current_image_caption(@_); } },
    308217                choices =>
    309218                [
     
    316225                value => sub {
    317226                    $self->multi_selection_mode ?
    318                     $self->imagelist->SetImageSelectionComment(@_):
    319                     $self->imagelist->current_image->site_comment(@_)
     227                    $self->images->set_image_selection_comment(@_):
     228                    $self->images->current_image->site_comment(@_)
    320229                },
    321230                frame_callback => sub { $self->imageviewer_item_refresh(1); },
     
    325234                value => sub {
    326235                    $self->multi_selection_mode ?
    327                     $self->imagelist->SetImageSelectionAuthor(@_):
    328                     $self->imagelist->current_image->site_author(@_)
     236                    $self->images->set_image_selection_author(@_):
     237                    $self->images->current_image->site_author(@_)
    329238                },
    330239                frame_callback => sub { $self->imageviewer_item_refresh(1); },
     
    335244                value => sub {
    336245                    $self->multi_selection_mode ?
    337                     $self->imagelist->SetImageSelectionCreateDate(@_):
    338                     $self->imagelist->current_image->create_date(@_)
     246                    $self->images->set_image_selection_create_date(@_):
     247                    $self->images->current_image->create_date(@_)
    339248                },
    340249                frame_callback => sub { $self->imageviewer_item_refresh(1); },
     
    344253                selection => sub {
    345254                    $self->multi_selection_mode ?
    346                     $self->imagelist->SetImageSelectionPrivacyLevel(@_):
    347                     $self->imagelist->current_image->privacy_level(@_)
     255                    $self->images->set_image_selection_privacy_level(@_):
     256                    $self->images->current_image->privacy_level(@_)
    348257                },
    349258                choices => wxTheApp->privacy_level_choices,
     
    359268    );   
    360269
    361     $self->global_settings(
     270    $self->preferences_properties(
    362271        {
    363272            $main::DEFAULT_PHOTO_CAPTION => { label => gettext("Default caption pattern") },
     
    370279            $main::GS_CLOSE => { label => gettext("Close")},
    371280            $main::GS_THUMBNAIL_SHAPE => {
    372                 selection => sub { $self->imagelist->thumbnail_shape_square(@_) },
     281                selection => sub { $self->preferences->thumbnail_shape_square(@_) },
    373282                choices =>
    374283                [
     
    377286            },
    378287            $main::GS_DEFAULT_PHOTO_CAPTION => {
    379                 string_selection => sub { $self->imagelist->default_caption_pattern(@_) },
     288                string_selection => sub { $self->preferences->default_caption_pattern(@_) },
    380289                choices =>
    381290                [
     
    390299            $main::PHOTO_CAPTION_PREFIX => { label => gettext("Default caption") },
    391300            $main::GS_PHOTO_CAPTION_PREFIX => {
    392                 value => sub { $self->imagelist->default_caption(@_) },
     301                value => sub { $self->preferences->default_caption(@_) },
    393302            },
    394303            $main::GS_AUTO_ROTATE => {
    395304                label => gettext("Auto rotate image"),
    396                 value => sub { $self->imagelist->auto_rotate(@_) }
     305                value => sub { $self->preferences->auto_rotate(@_) }
    397306           },
    398307            $main::DEFAULT_AUTHOR => { label => gettext("Default author")},
    399             $main::GS_DEFAULT_AUTHOR => { value => sub { $self->imagelist->author(@_) } },
     308            $main::GS_DEFAULT_AUTHOR => { value => sub { $self->preferences->author(@_) } },
    400309            $main::THUMBNAIL_SIZE => { label => gettext("Site thumbnail size") },
    401310            $main::GS_THUMBNAIL_SIZE => {
    402                 value => sub { $self->imagelist->thumb_size(@_) },
     311                value => sub { $self->preferences->thumb_size(@_) },
    403312                validator => Wx::Perl::TextValidator->new( '\d' )
    404313            },
    405314            $main::THUMBNAIL_JPEG_QUALITY => { label => gettext("Site thumbnail jpeg quality") },
    406315            $main::GS_THUMBNAIL_JPEG_QUALITY => {
    407                 value => sub { $self->imagelist->th_quality(@_) },
     316                value => sub { $self->preferences->th_quality(@_) },
    408317                validator => Wx::Perl::TextValidator->new( '\d' )
    409318            },
    410319            $main::GS_CREATE_RESIZED => {
    411                 selection => sub { $self->imagelist->create_resized(@_) },
     320                selection => sub { $self->preferences->create_resized(@_) },
    412321                choices =>
    413322                [
     
    421330            $main::SITE_IMG_WIDTH => { label => gettext("Maximum width") },
    422331            $main::GS_SITE_IMG_WIDTH => {
    423                 value => sub { $self->imagelist->resize_w(@_) },
     332                value => sub { $self->preferences->resize_w(@_) },
    424333                validator => Wx::Perl::TextValidator->new( '\d' )
    425334            },
    426335            $main::SITE_IMG_HEIGHT => { label => gettext("Maximum height") },
    427336            $main::GS_SITE_IMG_HEIGHT => {
    428                 value => sub { $self->imagelist->resize_h(@_) },
     337                value => sub { $self->preferences->resize_h(@_) },
    429338                validator => Wx::Perl::TextValidator->new( '\d' )
    430339            },
    431340            $main::SITE_IMG_JPEG_QUALITY => { label => gettext("Site image jpeg quality") },
    432341            $main::GS_SITE_IMG_JPEG_QUALITY => {
    433                 value => sub { $self->imagelist->quality(@_) },
     342                value => sub { $self->preferences->quality(@_) },
    434343                validator => Wx::Perl::TextValidator->new( '\d' )
    435344            },
    436345            $main::SITE_IMG_FILTER => { label => gettext("Site image filter") },
    437346            $main::GS_SITE_IMG_FILTER => {
    438                 string_selection =>  sub { $self->imagelist->filter(@_) },
     347                string_selection =>  sub { $self->preferences->filter(@_) },
    439348                choices =>
    440349                [
     
    444353            $main::SITE_IMG_BLUR => { label => gettext("Site image blur") },
    445354            $main::GS_SITE_IMG_BLUR => {
    446                 value => sub { $self->imagelist->blur(@_) },
     355                value => sub { $self->preferences->blur(@_) },
    447356                validator => Wx::Perl::TextValidator->new( '\d' )
    448357            },
    449358            $main::SITE_IMG_INTERLACE => { label => gettext("Site image interlace") },
    450359            $main::GS_SITE_IMG_INTERLACE => {
    451                 string_selection => sub { $self->imagelist->interlace(@_) },
     360                string_selection => sub { $self->preferences->interlace(@_) },
    452361                choices =>
    453362                [
     
    457366            $main::GS_REMOVE_UPLOADED_FROM_SELECTION => {
    458367                label => gettext("Remove uploaded photo from selection"),
    459                 value => sub { $self->imagelist->remove_uploaded_from_selection(@_) },
     368                value => sub { $self->preferences->remove_uploaded_from_selection(@_) },
    460369            },
    461370            $main::GS_HD_UPLOAD => {
     
    465374                ],
    466375                pre_process => sub { my ( $value ) = @_; wxTheApp->eng_upload_hd->{$value} },
    467                 string_selection => sub { $self->imagelist->upload_hd(@_) },
     376                string_selection => sub { $self->preferences->upload_hd(@_) },
    468377                frame_callback => sub {
    469378                    my( $self, $ctrl, $event ) = @_;
     
    474383            $main::GS_HD_IMG_WIDTH => {
    475384                label => gettext("HD image width"),
    476                 value => sub { $self->imagelist->hd_w(@_) },
     385                value => sub { $self->preferences->hd_w(@_) },
    477386                validator => Wx::Perl::TextValidator->new( '\d' )
    478387            },
     
    480389            $main::GS_HD_IMG_HEIGHT => {
    481390                label => gettext("HD image height"),
    482                 value => sub { $self->imagelist->hd_h(@_) },
     391                value => sub { $self->preferences->hd_h(@_) },
    483392                validator => Wx::Perl::TextValidator->new( '\d' )
    484393            },
    485394            $main::HD_IMG_JPEG_QUALITY => { label => gettext("HD image jpeg quality") },
    486395            $main::GS_HD_IMG_JPEG_QUALITY => {
    487                 value => sub { $self->imagelist->hd_quality(@_) },
     396                value => sub { $self->preferences->hd_quality(@_) },
    488397                validator => Wx::Perl::TextValidator->new( '\d' )
    489398            },
    490399            $main::HD_IMG_FILTER => { label => gettext("HD image filter") },
    491400            $main::GS_HD_IMG_FILTER => {
    492                 string_selection =>  sub { $self->imagelist->hd_filter(@_) },
     401                string_selection =>  sub { $self->preferences->hd_filter(@_) },
    493402                choices =>
    494403                [
     
    498407            $main::HD_IMG_BLUR => { label => gettext("HD image blur") },
    499408            $main::GS_HD_IMG_BLUR => {
    500                 value => sub { $self->imagelist->hd_blur(@_) },
     409                value => sub { $self->preferences->hd_blur(@_) },
    501410                validator => Wx::Perl::TextValidator->new( '\d' )
    502411            },
    503412            $main::HD_IMG_INTERLACE => { label => gettext("HD image interlace") },
    504413            $main::GS_HD_IMG_INTERLACE => {
    505                 string_selection => sub { $self->imagelist->hd_interlace(@_) },
     414                string_selection => sub { $self->preferences->hd_interlace(@_) },
    506415                choices =>
    507416                [
     
    511420            $main::GS_WMARK_ACTIVATE => {
    512421              label  => gettext("Activate watermark"),
    513               value  => sub { $self->imagelist->watermark_activate(@_) },
     422              value  => sub { $self->preferences->watermark_activate(@_) },
    514423              frame_callback => sub {
    515424                  my( $self, $ctrl, $event ) = @_;
     
    519428            $main::GS_WMARK_ACTIVATE_HD => {
    520429              label => gettext("Activate watermark on high definition"),
    521               value => sub { $self->imagelist->watermark_activate_pwg_high(@_) },
     430              value => sub { $self->preferences->watermark_activate_pwg_high(@_) },
    522431              frame_callback => sub {
    523432                  my( $self, $ctrl, $event ) = @_;
     
    527436            $main::WMARK_TEXT => { label  => gettext("Text") },
    528437            $main::GS_WMARK_TEXT => {
    529               value  => sub { $self->imagelist->watermark_text(@_) },
     438              value  => sub { $self->preferences->watermark_text(@_) },
    530439            },
    531440            $main::WMARK_TEXT_SIZE => { label     => gettext("Text size") },
    532441            $main::GS_WMARK_TEXT_SIZE => {
    533                 value   => sub { $self->imagelist->watermark_text_size(@_) },
     442                value   => sub { $self->preferences->watermark_text_size(@_) },
    534443            },
    535444            $main::WMARK_COLOR => { label     => gettext("Color") },
    536445            $main::GS_WMARK_COLOR => {
    537                 string_selection => sub { $self->imagelist->watermark_color(@_) },
     446                string_selection => sub { $self->preferences->watermark_color(@_) },
    538447                choices   => [
    539448                               map { gettext $_ } @{wxTheApp->colors}
     
    543452            $main::WMARK_POSITION => { label     => gettext("Position") },
    544453            $main::GS_WMARK_POSITION => {
    545                 string_selection => sub { $self->imagelist->watermark_position(@_) },
     454                string_selection => sub { $self->preferences->watermark_position(@_) },
    546455                choices  => [
    547456                               map { gettext $_ } @{wxTheApp->positions}
     
    551460            $main::WMARK_MARGIN_TOP => { label => gettext("Top margin") },
    552461            $main::GS_WMARK_MARGIN_TOP => {
    553                 value   => sub { $self->imagelist->watermark_y(@_) },
     462                value   => sub { $self->preferences->watermark_y(@_) },
    554463            },
    555464            $main::WMARK_MARGIN_LEFT => { label => gettext("Left margin") },
    556465            $main::GS_WMARK_MARGIN_LEFT => {
    557                 value   => sub { $self->imagelist->watermark_x(@_) },
     466                value   => sub { $self->preferences->watermark_x(@_) },
    558467            },
    559468            $main::CHUNK_SIZE => { label => gettext("Transfert chunk size") },
    560469            $main::GS_CHUNK_SIZE => {
    561                 value   => sub { wxTheApp->chunk_size(@_) },
     470                value   => sub { $self->preferences->chunk_size(@_) },
    562471                validator => Wx::Perl::TextValidator->new( '\d' )
    563472            },
     
    605514            {
    606515                label    => gettext("Create date"),
    607                 value    => sub { $self->imagelist->current_image->create_date },
     516                value    => sub { $self->images->current_image->create_date },
    608517                readonly => 1,
    609518            },   
    610519            {
    611520                label    => gettext("Model"),
    612                 value    => sub { $self->imagelist->current_image->exif_tag('Model') },
     521                value    => sub { $self->images->current_image->exif_tag('Model') },
    613522                readonly => 1,
    614523            },   
    615524            {
    616525                label    => gettext("Width"),
    617                 value    => sub { $self->imagelist->current_image->exif_tag('ImageWidth') },
     526                value    => sub { $self->images->current_image->exif_tag('ImageWidth') },
    618527                readonly => 1,
    619528            },   
    620529            {
    621530                label    => gettext("Height"),
    622                 value    => sub { $self->imagelist->current_image->exif_tag('ImageHeight') },
     531                value    => sub { $self->images->current_image->exif_tag('ImageHeight') },
    623532                readonly => 1,
    624533            },   
    625534            {
    626535                label    => gettext("Orientation"),
    627                 value    => sub { $self->imagelist->current_image->exif_tag('Orientation') },
     536                value    => sub { $self->images->current_image->exif_tag('Orientation') },
    628537                readonly => 1,
    629538            },   
    630539            {
    631540                label    => "ISO",
    632                 value    => sub { $self->imagelist->current_image->exif_tag('ISO') },
     541                value    => sub { $self->images->current_image->exif_tag('ISO') },
    633542                readonly => 1,
    634543            },   
    635544            {
    636545                label    => gettext("Shutter speed"),
    637                 value    => sub { $self->imagelist->current_image->exif_tag('ExposureTime') },
     546                value    => sub { $self->images->current_image->exif_tag('ExposureTime') },
    638547                readonly => 1,
    639548            },   
    640549            {
    641550                label    => gettext("Aperture"),
    642                 value    => sub { $self->imagelist->current_image->exif_tag('ApertureValue') },
     551                value    => sub { $self->images->current_image->exif_tag('ApertureValue') },
    643552                readonly => 1,
    644553            },   
    645554            {
    646555                label    => gettext("Focal length"),
    647                 value    => sub { $self->imagelist->current_image->exif_tag('FocalLength') },
     556                value    => sub { $self->images->current_image->exif_tag('FocalLength') },
    648557                readonly => 1,
    649558            },   
    650559            {
    651560                label    => gettext("Lens"),
    652                 value    => sub { $self->imagelist->current_image->exif_tag('Lens') },
     561                value    => sub { $self->images->current_image->exif_tag('Lens') },
    653562                readonly => 1,
    654563            },   
     
    657566
    658567    $self->image_tags(
    659         sub { scalar @{$self->imagelist->image_selection} > 1 ? $self->imagelist->SetImageSelectionTags(@_) : $self->imagelist->current_image->site_tags(@_)||[]  }
     568        sub {
     569            scalar @{$self->images->selection} > 1 ?
     570            $self->images->set_image_selection_tags(@_) :
     571            $self->images->current_image->site_tags(@_)||[]
     572        }
    660573    );
    661574
     
    684597   
    685598
    686 
    687599    $self->imageviewer(
    688600        Uploader::GUI::wxImageListCtrl->new(
    689601            {
    690                 parentwnd => $self,
    691                 imagelist => $self->imagelist,
    692                 image_size => $self->imagelist->wx_thumb_size,
    693                 columns => $self->piwigo_property_list,
     602                parentwnd    => $self,
     603                images       => $self->images,
     604                image_size   => $self->preferences->wx_thumb_size,
     605                display_mode_cbk => sub { $self->preferences->display_mode(@_) },
     606                columns      => $self->piwigo_property_list,
    694607            }
    695608        )
     
    726639    $self->show_hide_pwg_categories_empty_msg;
    727640
    728     if( $self->imagelist->wx_thumb_imglist->GetImageCount){
    729         $self->ShowImageViewer;
    730        
    731         $self->imageviewer->Refresh(
    732             $self->imagelist->wx_thumb_imglist
    733         );
    734        
    735         $self->OnUpdateImageviewerNotEmpty;
     641    if( $self->images->image_count){
     642        $self->on_update_imageviewer_not_empty;
    736643    }
    737644    else{
    738         $self->OnUpdateImageviewerEmpty;
     645        $self->on_update_imageviewer_empty;
    739646    }
    740647
     
    769676        ) == wxYES
    770677    ){   
    771         $self->pwg->AddTags($name);
    772         $self->pwg->RefreshTags;
    773     }
    774 }
    775 
    776 
    777 sub OnUpdateImageviewerEmpty {
     678        $self->pwg->add_tags($name);
     679        $self->pwg->refresh_tags;
     680    }
     681}
     682
     683
     684sub on_update_imageviewer_empty {
    778685    my ( $self ) = @_;
    779686
     
    782689}
    783690
    784 sub OnUpdateImageviewerNotEmpty {
     691sub on_update_imageviewer_not_empty {
    785692    my ( $self ) = @_;
    786693
     
    792699sub init_dialogs {
    793700    my ( $self ) = @_;   
     701
     702    $self->upload_progressdlg(
     703        Uploader::GUI::ImageProgressDlg->new(
     704            {
     705                title    => gettext("Image upload progress information"),
     706                progress_column => 2,
     707                cancel_cbk => sub { wxTheApp->cancel_queues },
     708            }
     709        )
     710    );
     711
     712    $self->upload_progressdlg->Hide;
    794713
    795714
     
    805724    $self->exif_dlg->Hide;
    806725
    807     $self->global_settings_dlg(
    808         Uploader::GUI::wxGlobalSettings->new(
     726    $self->preferences_dlg(
     727        Uploader::GUI::Preferences->new(
    809728            {
    810729                parentwnd       => $self,
    811                 caption         => gettext("Global settings"),
    812                 properties      => $self->global_settings,
     730                caption         => gettext("Preferences"),
     731                properties      => $self->preferences_properties,
    813732            }
    814733        )
    815734    );
    816     $self->global_settings_dlg->Hide;
     735    $self->preferences_dlg->Hide;
    817736
    818737    $self->image_preview_dlg(
     
    836755                                    $main::DESTINATION_CATEGORIES_CANCEL => { label=>gettext("Cancel")},
    837756                                    $main::DESTINATION_CATEGORIES => {
    838                                         id_selection => sub { $self->imagelist->categories(@_) },
     757                                        id_selection => sub { wxTheApp->transfer_manager->destination_category(@_) },
    839758                                        frame_callback => sub {
    840759                                            my ( $dlg, $ctrl, $evt ) = @_;
    841                                             $dlg->FindWindow($main::DESTINATION_CATEGORIES_OK)->Enable(scalar @{$self->imagelist->categories});
     760                                            $dlg->FindWindow($main::DESTINATION_CATEGORIES_OK)->Enable(!wxTheApp->transfer_manager->destination_category_is_empty);
    842761                                        },
    843762                                    },
    844763                                },
    845                 frame_callback => sub { $self->OnRefreshCategories },
     764                frame_callback => sub { $self->on_replace_categories },
    846765            }
    847766        )
     
    882801
    883802
    884 sub OnPhotoProperties {
     803sub on_photo_properties {
    885804    my ( $self ) = @_;
    886805
     
    889808
    890809
    891 sub OnPreview {
     810sub on_preview {
    892811    my ( $self ) = @_;
    893812
     
    896815
    897816
    898 sub OnGlobalSettings {
     817sub on_preferences {
    899818    my ( $self ) = @_;
    900819
    901     $self->global_settings_dlg->Show(1);
    902 }
    903 
    904 
    905 sub OnGeneralSettingsClose {
    906     my ( $self, $event ) = @_;
    907 
    908     $self->global_settings_dlg->Hide;
    909 }
    910 
    911 
    912 sub OnImageExifPropClose {
    913     my ( $self, $event ) = @_;
    914 
    915     $self->image_exif_prop->Hide;
    916 }
    917 
    918 
     820    $self->preferences_dlg->Show(1);
     821}
    919822
    920823
     
    1045948    my ( $self ) = @_ ;
    1046949   
    1047     Wx::Event::EVT_MENU( $self, 101, \&OnAddImages );
    1048     Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages );
    1049     Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages );
    1050     Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings );
    1051     Wx::Event::EVT_CHOICE( $self, 106, \&OnPhotoSelMode );
    1052     Wx::Event::EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged );
    1053     Wx::Event::EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick );
    1054     Wx::Event::EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&OnTreeEndLabelEdit );
    1055 
    1056     Wx::Event::EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit );
    1057     Wx::Event::EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated );
    1058     Wx::Event::EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ;
    1059     Wx::Event::EVT_LIST_ITEM_DESELECTED($self, $self->imageviewer, \&OnImageViewerItemDeSelected) ;
    1060     Wx::Event::EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ;
    1061 
    1062     Wx::Event::EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ;
     950    Wx::Event::EVT_MENU( $self, 101, \&on_add_images );
     951    Wx::Event::EVT_MENU( $self, 102, \&on_remove_images );
     952    Wx::Event::EVT_MENU( $self, 103, \&on_transfer_images );
     953    Wx::Event::EVT_MENU( $self, 104, \&on_preferences );
     954    Wx::Event::EVT_CHOICE( $self, 106, \&on_photo_sel_mode );
     955    Wx::Event::EVT_TREE_SEL_CHANGED( $self, $self->tree, \&on_category_sel_changed );
     956    Wx::Event::EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&on_category_right_click );
     957    Wx::Event::EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&on_category_end_label_edit );
     958
     959    Wx::Event::EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&on_image_end_label_edit );
     960    Wx::Event::EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&on_image_item_activated );
     961    Wx::Event::EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&on_image_item_selected) ;
     962    Wx::Event::EVT_LIST_ITEM_DESELECTED($self, $self->imageviewer, \&on_image_item_deselected) ;
     963    Wx::Event::EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&on_image_item_right_click) ;
     964
     965    Wx::Event::EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&on_image_item_key_down) ;
    1063966
    1064967    Wx::Event::EVT_CLOSE( $self, \&OnClose );
    1065968
    1066     Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategory );
    1067     Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories );
    1068     Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories );
    1069     Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&OnCollapseCategories );
    1070 
    1071     Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties );
    1072     Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview );
    1073 
    1074     Wx::Event::EVT_BUTTON( $self, $main::PHOTO_PROPERTIES_UPLOAD, \&OnUploadImages );
    1075     Wx::Event::EVT_BUTTON( $self, $self->imageviewer->add_button->GetId, \&OnAddImages );
     969    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&on_add_category );
     970    Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&on_replace_categories );
     971    Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&on_expand_categories );
     972    Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&on_collapse_categories );
     973
     974    Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&on_photo_properties );
     975    Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&on_preview );
     976
     977    Wx::Event::EVT_BUTTON( $self, $main::PHOTO_PROPERTIES_UPLOAD, \&on_transfer_images );
     978    Wx::Event::EVT_BUTTON( $self, $self->imageviewer->add_button->GetId, \&on_add_images );
    1076979    Wx::Event::EVT_KEY_DOWN($self, \&OnKeyDown );
    1077980
     
    10991002                        $_
    11001003                    )
    1101                 } @{$self->imageviewer->GetSelectedItems};
     1004                } @{$self->imageviewer->selected_items};
    11021005                $self->imageviewer_item_refresh(0);
    11031006            }
     
    11121015    );
    11131016
     1017    Wx::Event::EVT_COMMAND(
     1018        $self,
     1019        -1,
     1020        wxTheApp->resize_start_event,
     1021        sub {
     1022            my ( $handler, $event ) = @_;
     1023            my $data = $event->GetData;
     1024            $handler->upload_progressdlg->Show(1);
     1025            $handler->upload_progressdlg->RequestUserAttention(wxUSER_ATTENTION_INFO);
     1026            $handler->upload_progressdlg->add_images($data);
     1027        }
     1028    );
     1029
     1030    # resize and transfer progress
     1031    Wx::Event::EVT_COMMAND(
     1032        $self,
     1033        -1,
     1034        wxTheApp->image_progress_event,
     1035        sub {
     1036            my ( $handler, $event ) = @_;
     1037            my $data = $event->GetData;
     1038            $handler->upload_progressdlg->update_image_item($data);
     1039        }
     1040    );
     1041
    11141042}
    11151043
     
    11181046    my ( $self ) = @_;
    11191047
    1120     scalar @{$self->imageviewer->GetSelectedItems};
     1048    scalar @{$self->imageviewer->selected_items};
    11211049}
    11221050
     
    11251053  my $prevdir;
    11261054
    1127   sub OnAddImages {
     1055  sub on_add_images {
    11281056    my( $self, $event ) = @_;
    11291057
    1130     $prevdir = wxTheApp->default_openfile_dir if ( -d wxTheApp->default_openfile_dir);
     1058    $prevdir = $self->preferences->default_openfile_dir if ( -d $self->preferences->default_openfile_dir);
    11311059    my $dialog = Wx::FileDialog->new
    11321060      ( $self, gettext("Select photos for upload"), $prevdir, $prevfile,
     
    11371065    if( $dialog->ShowModal != wxID_CANCEL ) {
    11381066        @$file_paths = $dialog->GetPaths;
    1139         $self->SetNewFiles($file_paths) ;
    1140     }
    1141     wxTheApp->default_openfile_dir(
     1067        $self->add_images($file_paths) ;
     1068    }
     1069    $self->preferences->default_openfile_dir(
    11421070        $dialog->GetDirectory
    11431071    );
     
    11501078    my( $self ) = @_;
    11511079   
    1152     if($self->global_settings_dlg->IsShown){
     1080    if($self->preferences_dlg->IsShown){
    11531081        $self->toolbar->EnableTool(104, 0);
    11541082    }
     
    11571085    }
    11581086
    1159     if($self->global_settings_dlg->IsShown){
     1087    if($self->preferences_dlg->IsShown){
    11601088        $self->toolbar->EnableTool(104, 0);
    11611089    }
     
    11671095
    11681096
    1169 sub OnRemoveImages {
     1097sub on_remove_images {
    11701098    my( $self, $event ) = @_;
    11711099
    1172    
    1173     $self->imagelist->RemoveImageSelection;
     1100    $self->images->remove_selection;
    11741101    $self->imageviewer->Refresh;   
    11751102
     
    11811108        $self->piwigo_photo_properties_dlg->ClearProperties;
    11821109        $self->piwigo_photo_properties_tags->ClearAllSelection;
    1183         $self->imagelist->SetCurrentImage(-1);
    1184         $self->OnUpdateImageviewerEmpty;
     1110        $self->images->set_current_image(-1);
     1111        $self->on_update_imageviewer_empty;
    11851112    }
    11861113    else{
    1187         $self->OnUpdateImageviewerNotEmpty;
     1114        $self->on_update_imageviewer_not_empty;
    11881115    }
    11891116
    11901117    if(!$self->multi_selection_mode){
    1191         $self->OnUpdateSingleSelectionModeUI;
     1118        $self->on_update_single_selection_mode;
    11921119    }
    11931120
     
    11961123}
    11971124
    1198 sub SetNewFiles {
     1125
     1126sub add_images {
    11991127    my ( $self, $file_paths ) = @_;
    12001128
    1201     $self->ShowImageViewer();
    1202    
    1203     $self->progressdlg->Destroy if defined $self->progressdlg;
    1204     $self->progressdlg(
    1205         Uploader::GUI::wxImageProcessingProgressDlg->new(
    1206             {
    1207                 title => gettext("Image processing progress information"),
    1208                 bt_label => gettext("Cancel image processing"),
    1209                 bt_close_label => gettext("Close"),
    1210                 stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); },
    1211              }
    1212         )       
    1213     );
    1214     $self->progressdlg->Show(1);
    1215     Wx::Yield();
    1216 
    1217    
    1218     my $files = [
    1219         map {
    1220             # to make sure that unicode chars in filenames are supported
    1221             {
    1222                 ANSIPathName => $^O =~ /MSWin32/ ? Win32::GetANSIPathName($_) : $_,
    1223                 PathName => $_,
    1224             },
    1225         }@$file_paths   
    1226     ];
    1227 
    1228     @$files = sort { $a->{PathName} cmp $b->{PathName} } @$files;   
    1229 
    1230     $self->imagelist->SetNewFiles(
    1231         $files
    1232     );
    1233 
    1234    
    1235 }
    1236 
    1237 
    1238 sub OnTreeSelChanged {
     1129    $self->show_imageviewer;
     1130
     1131    my $bc = Wx::BusyCursor->new;
     1132    $self->images->add_images(
     1133        $file_paths
     1134    );
     1135
     1136}
     1137
     1138
     1139sub on_category_sel_changed {
    12391140    my( $self, $event ) = @_;
    12401141
    1241     $self->imagelist->categories(
    1242         $event->GetEventObject->GetSelectionsIds
    1243     );
    1244 }
    1245 
    1246 sub OnTreeItemRightClick {
     1142    wxTheApp->transfer_manager->destination_category(
     1143        $event->GetEventObject->selection_ids
     1144    );
     1145}
     1146
     1147
     1148sub on_category_right_click {
    12471149    my( $self, $event ) = @_;
    12481150
     
    12521154}
    12531155
    1254 sub OnTreeEndLabelEdit {
     1156sub on_category_end_label_edit {
    12551157    my( $self, $event ) = @_;
    12561158
     
    12601162
    12611163    if(defined($label) and !( "" eq $label )){
    1262         $self->_SetLabel($event)
     1164        $self->set_category_label($event)
    12631165    }
    12641166    else{
     
    12671169}
    12681170
    1269 sub _SetLabel {
     1171sub set_category_label {
    12701172    my( $self, $event ) = @_;
    12711173   
     
    12751177    $category_id = $category->{id} if 'HASH' eq ref($category) ;
    12761178    my $comment;
    1277     my ( $success, $status_msg, $content ) = $self->pwg->SetInfoCategories(
     1179    my ( $success, $status_msg, $content ) = $self->pwg->set_info_category(
    12781180        $event->GetLabel,
    12791181        $comment,
     
    13071209}
    13081210
    1309 sub OnImageViewerItemRightClick {
     1211sub on_image_item_right_click {
    13101212    my( $self, $event ) = @_;
    13111213
     
    13161218}
    13171219
    1318 sub OnExpandCategories {
     1220sub on_expand_categories {
    13191221    my ( $self, $event ) = @_;
    13201222
     
    13241226}
    13251227
    1326 sub OnCollapseCategories {
     1228sub on_collapse_categories {
    13271229    my ( $self, $event ) = @_;
    13281230
     
    13321234}
    13331235
    1334 sub OnAddCategory {
     1236sub on_add_category {
    13351237    my ( $self, $event ) = @_;
    13361238
    1337     $self->tree->AddCategory;
    1338 
    1339 }
    1340 
    1341 
    1342 sub OnRefreshCategories {
     1239    $self->tree->add_category;
     1240
     1241}
     1242
     1243
     1244sub on_replace_categories {
    13431245    my ( $self, $event ) = @_;
    13441246
     
    13531255    $self->tree->CollapseAll;
    13541256    $self->tree->DeleteAllItems;
    1355     $self->pwg->RefreshCategories();
     1257    $self->pwg->refresh_categories;
    13561258    $self->tree->categories(
    13571259        $self->pwg->categories
     
    13621264
    13631265
    1364 sub OnImageViewerEndLabelEdit {
     1266sub on_image_end_label_edit {
    13651267    my( $self, $event ) = @_;
    13661268 
    1367     my $image = $self->imagelist->GetImage($event->GetIndex);
     1269    my $image = $self->images->get_image($event->GetIndex);
    13681270    $image->site_name(
    13691271        $event->GetLabel
     
    13731275}
    13741276
    1375 sub OnImageViewerItemActivated {
     1277sub on_image_item_activated {
    13761278    my( $self, $event ) = @_;
    13771279   
     
    13801282    );
    13811283
    1382     $self->OnPhotoProperties;
    1383 }
    1384 
    1385 
    1386 sub OnImageViewerItemSelected {
     1284    $self->on_photo_properties;
     1285}
     1286
     1287
     1288sub on_image_item_selected {
    13871289    my( $self, $event ) = @_;
    13881290
     
    13981300}
    13991301
    1400 sub OnImageViewerItemDeSelected {
     1302sub on_image_item_deselected {
    14011303    my( $self, $event ) = @_;
    14021304
     
    14071309
    14081310}
     1311
    14091312
    14101313sub _on_imageviewer_item_selected {
    14111314    my ( $self, $index ) = @_;   
    14121315    $self->current_imageviewer_index($index);
    1413     $self->imagelist->SetCurrentImage($index);
     1316    $self->images->set_current_image($index);
    14141317   
    14151318    $self->_on_imageviewer_item_selection_changed;
    14161319}
     1320
    14171321
    14181322sub _on_imageviewer_item_selection_changed {
    14191323    my ( $self ) = @_;   
    14201324
    1421     $self->imagelist->image_selection(
    1422         $self->imageviewer->GetSelectedItems
     1325    $self->images->selection(
     1326        $self->imageviewer->selected_items
    14231327    );
    14241328
    14251329    # for batch mode : reset the batch buffer if single selection
    14261330    if($self->multi_selection_mode){
    1427         $self->OnUpdateMultiSelectionModeUI;
    1428         $self->imagelist->SetImageSelectionTags([]);
    1429         $self->imagelist->image_selection_privacy_level(-1);
    1430         $self->imagelist->image_selection_name("");
    1431         $self->imagelist->image_selection_author("");
    1432         $self->imagelist->image_selection_comment("");
    1433         $self->imagelist->image_selection_create_date(-1);
     1331        $self->on_update_multi_selection_mode;
     1332        $self->images->set_image_selection_tags([]);
     1333        $self->images->selection_privacy_level(-1);
     1334        $self->images->selection_name("");
     1335        $self->images->selection_author("");
     1336        $self->images->selection_comment("");
     1337        $self->images->selection_create_date(-1);
    14341338    }
    14351339    else{
    1436         $self->OnUpdateSingleSelectionModeUI;
     1340        $self->on_update_single_selection_mode;
    14371341    }
    14381342    # process image_preview in idle time
     
    14471351}
    14481352
     1353
    14491354sub multi_selection_mode {
    14501355    my ( $self ) = @_;
    14511356
    1452     scalar @{$self->imagelist->image_selection} > 1;
    1453 }
    1454 
    1455 sub OnUpdateMultiSelectionModeUI{
     1357    $self->images->selection_count > 1;
     1358}
     1359
     1360
     1361sub on_update_multi_selection_mode{
    14561362    my( $self ) = @_;
    14571363
    14581364
    14591365    $self->piwigo_photo_properties_dlg->SetMultiSelectionMode(
    1460         $self->imageviewer->GetSelectectItemsCount
    1461     );
    1462 }
    1463 
    1464 sub OnUpdateSingleSelectionModeUI{
     1366        $self->imageviewer->selected_items_count
     1367    );
     1368}
     1369
     1370
     1371sub on_update_single_selection_mode{
    14651372    my( $self ) = @_;
    14661373
     
    14721379    my ( $self ) = @_;   
    14731380
    1474     my $current_image = $self->imagelist->current_image;
     1381    my $current_image = $self->images->current_image;
    14751382    my $image = Wx::Image->new;
    14761383    $image->LoadFile(
     
    14791386    );
    14801387 
    1481     if($self->imagelist->auto_rotate){
     1388    if($self->preferences->auto_rotate){
    14821389        # exif from original image
    14831390        my $orientation = $current_image->exif_metadata->{Orientation};
     
    14931400    $self->image_preview_dlg->image_size(
    14941401        [$image->GetWidth, $image->GetHeight, ]
    1495     );       
     1402    );
    14961403
    14971404    $self->image_preview_dlg->image(
    14981405        $image
    1499     );       
    1500 }
    1501 
    1502 sub OnImageViewerKeyDown {
     1406    );
     1407}
     1408
     1409
     1410sub on_image_item_key_down {
    15031411    my( $self, $event ) = @_;
    15041412
    15051413    if(WXK_DELETE == $event->GetKeyCode){
    1506         $self->OnRemoveImages();
     1414        $self->on_remove_images;
    15071415       
    15081416        my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ?
    15091417            $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ;
    1510         $self->imageviewer->SelectItem(
     1418        $self->imageviewer->select_item(
    15111419            $index
    15121420        );
     
    15191427
    15201428
    1521 sub OnUploadImages {
     1429sub on_transfer_images {
    15221430    my( $self, $event ) = @_;
    1523 
    1524     my $select_all = 1;
     1431   
     1432    # all is default if single selection
     1433    my $all = 1 unless $self->multi_selection_mode;
    15251434    eval {
    1526         $self->ProcessImageSelection( $select_all );   
     1435        $self->process_images( $all );   
    15271436    };
    15281437}
    15291438
    1530 # remove image from imagelist when uploaded
     1439
     1440# remove image when uploaded
    15311441sub UploadImagesViewerRefresh {
    15321442    my ( $self ) = @_;   
     
    15371447    if(!$self->imageviewer->GetItemCount){
    15381448        $self->image_preview_dlg->image(0);
    1539         $self->OnUpdateImageviewerEmpty;
     1449        $self->on_update_imageviewer_empty;
    15401450    }
    15411451    # reset previous selection
    1542     $self->imagelist->image_selection(
     1452    $self->images->selection(
    15431453        []
    15441454    );
    15451455
    15461456    if(!$self->multi_selection_mode){
    1547         $self->OnUpdateSingleSelectionModeUI;
     1457        $self->on_update_single_selection_mode;
    15481458    }
    15491459
    15501460    $self->image_preview_dlg->Refresh;
    1551     Wx::Yield();
    1552 }
    1553 
    1554 sub UploadProgressMessageRefresh {
    1555     my ( $self, $msg ) = @_;   
    1556 
    1557     Wx::Yield();
    1558 
    1559     $self->upload_progressdlg->processing(
    1560         $msg   
    1561     );   
    1562     $self->upload_progressdlg->LogProgress();
    1563 
    1564     Wx::Yield();
    1565 }
    1566 
    1567 sub UploadProgressMessageDetailsRefresh {
    1568     my ( $self, $msg ) = @_;   
    1569 
    1570     Wx::Yield();
    1571 
    1572     $self->upload_progressdlg->processing_details(
    1573         $msg   
    1574     );   
    1575     $self->upload_progressdlg->LogProgress();
    1576 
    1577     Wx::Yield();
    1578 }
    1579 
    1580 
    1581 sub UploadProgressThumbnailRefresh {
    1582     my ( $self ) = @_;   
    1583 
    1584     my $imagelist = $self->imagelist ;
    1585 
    1586  
    1587     $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
    1588     $self->upload_progressdlg->image->SetBitmap(
    1589         Wx::Bitmap->new(
    1590             $self->imagelist->current_image->wx_thumb_file,
    1591             $self->GetWxBitmapType($self->imagelist->type),
    1592         )
    1593     );
    1594 
    1595     Wx::Yield();
    1596 }
    1597 
    1598 sub UploadProgressBarRefresh {
    1599     my ( $self, $value ) = @_;   
    1600 
    1601     eval {
    1602         $self->upload_progressdlg->progress(
    1603             $value
    1604         );
    1605         $self->upload_progressdlg->LogProgress();
    1606     };
    1607     #croak gettext("Upload cancelled") if $@;
    1608 
    1609     Wx::Yield();
    1610 }
    1611 
    1612 sub SetNewFilesDisplayEndInfo {
    1613     my ( $self, $msg, $errors ) = @_;   
    1614    
    1615     if($errors){
    1616         $self->progressdlg->DisplayEndInfo($msg);
    1617     }
    1618     else{
    1619         $self->progressdlg->Show(0);
    1620     }
    1621 }
    1622 
    1623 sub UploadDisplayEndInfo {
    1624     my ( $self, $msg ) = @_;   
    1625    
    1626     my $imagelist = $self->imagelist ;
    1627    
    1628     $self->upload_progressdlg->DisplayEndInfo($msg);
    1629 }
    1630 
    1631 sub ShowImageViewer {
     1461}
     1462
     1463
     1464sub show_imageviewer {
    16321465    my ( $self ) = @_;   
    16331466
     
    16381471
    16391472
    1640 sub SetNewFilesViewerRefresh {
    1641 
    1642     my ( $self ) = @_;   
    1643 
    1644     my $wximagelist = $self->imagelist->wx_thumb_imglist;
    1645     #print Dumper "SetNewFilesViewerRefresh", $self->imagelist->current_image;
    1646     my $indx = $wximagelist->Add(
    1647         Wx::Bitmap->new(
    1648             $self->imagelist->current_image->wx_thumb_file,
    1649             $self->GetWxBitmapType($self->imagelist->type),
    1650         )
    1651     ) if defined $self->imagelist->current_image->wx_thumb_file;
    1652     #print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n";   
    1653    
    1654     $self->imageviewer->Refresh(
    1655         $wximagelist
    1656     );
    1657 
    1658     $self->OnUpdateImageviewerNotEmpty if $self->imageviewer->GetItemCount;
    1659 
    1660     Wx::Yield();
     1473sub add_images_viewer_refresh {
     1474
     1475    my ( $self, $wx_thumb_file ) = @_;   
     1476
     1477    $self->imageviewer->add_image($wx_thumb_file);
     1478    $self->on_update_imageviewer_not_empty if $self->imageviewer->GetItemCount;
    16611479}
    16621480
     
    16691487
    16701488
     1489sub delete_images_viewer_refresh {
     1490    my ( $self, $indx ) = @_;   
     1491
     1492    $self->imageviewer->delete_image($indx);
     1493    Wx::Yield();
     1494}
     1495
     1496
    16711497# prepare and upload image_selection
    1672 sub ProcessImageSelection {
    1673     my ( $self, $select_all ) = @_;
    1674 
    1675     return if wxTheApp->CheckUpload;
    1676     return if !scalar @{$self->imagelist->sums};
    1677 
    1678     if( $self->destination_categories_are_empty ){
     1498sub process_images {
     1499    my ( $self, $all_images ) = @_;
     1500
     1501    return if wxTheApp->check_upload;
     1502    return if $self->images->is_empty;
     1503
     1504    if( wxTheApp->transfer_manager->destination_category_is_empty ){
    16791505        return unless $self->destination_category_dlg->ShowModal != wxID_CANCEL;
    16801506    }
    16811507
    1682     $self->imagelist->image_selection(
    1683         $self->imageviewer->GetAllItems
    1684     ) if $select_all;
    1685        
    1686     return if( !defined $self->imagelist->image_selection );
    1687     return if( !scalar @{$self->imagelist->image_selection} );
    1688        
    1689     $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg;
    1690     $self->upload_progressdlg(
    1691         Uploader::GUI::wxImageProcessingProgressDlg->new(
    1692             {
    1693                 title    => gettext("Image upload progress information"),
    1694                 bt_label => gettext("Cancel upload"),
    1695                 bt_close_label => gettext("Close"),
    1696                 stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); },
    1697             }
    1698         )
    1699     );
    1700 
    1701     # modeless dialog
    1702     $self->upload_progressdlg->Show(1);
    1703     Wx::Yield();
    1704     eval {
    1705         $self->imagelist->UploadSelection;
    1706     };
    1707     if($@){
    1708         Wx::MessageBox(
    1709             sprintf(
    1710                 gettext("Upload cancelled"),
    1711             ),
    1712             gettext("Piwigo upload information"),
    1713             wxOK | wxICON_INFORMATION,
    1714         );
    1715     }
    1716 }
    1717 
    1718 
    1719 sub destination_categories_are_empty {
    1720     my ( $self ) = @_;
    1721 
    1722     !scalar @{$self->imagelist->categories};
    1723 }
    1724 
    1725 
    1726 sub SetNewFilesProgress {
    1727     my ( $self ) = @_;
    1728 
    1729     my $imagelist = $self->imagelist;
    1730 
    1731     $self->progressdlg->processing(
    1732         sprintf(
    1733             $imagelist->progress_msg,
    1734             $imagelist->current_image->file,
    1735         )
    1736     );
    1737 
    1738     eval {
    1739         $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]);
    1740         $self->progressdlg->image->SetBitmap(wxNullBitmap);
    1741         $self->progressdlg->image->SetBitmap(
    1742             Wx::Bitmap->new(
    1743                 $imagelist->current_image->wx_thumb_file,
    1744                 $self->GetWxBitmapType( $imagelist->type )
    1745             )
    1746         );
    1747         $self->progressdlg->progress(
    1748             $imagelist->count * ( 100/scalar @{$imagelist->new_files} )
    1749         );
    1750         $self->progressdlg->LogProgress();
    1751     };
    1752     Wx::Yield();
    1753 }
     1508    wxTheApp->start_resize($all_images);
     1509
     1510}
     1511
    17541512
    17551513sub OnClose {
     
    17601518    Wx::Log::SetActiveTarget( $self->oldlogwnd );
    17611519
    1762     # allways store
    1763  
    1764     wxTheApp->StoreConnectionProperties;
    1765    
    1766     $self->imagelist->Store;
    1767     wxTheApp->login_dlg->Destroy;   
    1768 
    1769    
    1770     wxTheApp->imageviewerIndex(
    1771         $self->current_imageviewer_index
    1772     );
    1773    
    1774     my $frameLayout = {};
    1775    
    1776     ( $frameLayout->{pX}, $frameLayout->{pY}, $frameLayout->{W}, $frameLayout->{H} ) = ( $self->GetPositionXY, $self->GetSizeWH ) ;
    1777    
    1778     wxTheApp->frameLayout(
    1779         $frameLayout
    1780     );
    1781 
    1782     wxTheApp->StoreLayoutProperties;
    1783 
    17841520    #destroy hidden dialogs
    1785     $self->global_settings_dlg->Destroy;
     1521    $self->preferences_dlg->Destroy;
    17861522    $self->image_preview_dlg->Destroy;
    17871523    $self->exif_dlg->Destroy;
    17881524    $self->destination_category_dlg->Destroy;
    17891525
    1790     $self->progressdlg->Destroy if defined $self->progressdlg;
    1791     $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg;
    1792 
     1526    $self->upload_progressdlg->Destroy;
     1527
     1528    wxTheApp->stop_all;
     1529   
    17931530    $self->Destroy;
    17941531}
     
    18691606    );
    18701607   
    1871     $ch->SetStringSelection(gettext($self->imagelist->display_mode));
     1608    $ch->SetStringSelection(gettext($self->preferences->display_mode));
    18721609    $tb->Realize;
    18731610
     
    18801617}
    18811618
    1882 sub OnPhotoSelMode {
     1619sub on_photo_sel_mode {
    18831620    my ( $self, $event )= @_;
    18841621   
    1885     $self->imagelist->display_mode(
     1622    $self->preferences->display_mode(
    18861623        $event->GetClientData
    18871624    );
     
    18891626    $self->imageviewer->change_display_mode(1);
    18901627}
     1628
     1629
     1630sub create_textctrl {
     1631    my( $self, $text, $size ) = @_;
     1632
     1633    return $self->_create_textctrl( $self, $text, $size );
     1634}
     1635
    18911636
    18921637sub _create_textctrl {
    18931638    my( $self, $parent, $text, $size ) = @_;
    18941639
    1895     return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size,
    1896                               wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY  );
    1897 }
    1898 
    1899 sub create_textctrl {
    1900     my( $self, $text, $size ) = @_;
    1901 
    1902     return $self->_create_textctrl( $self, $text, $size );
     1640    return Wx::TextCtrl->new(
     1641        $parent,
     1642         -1,
     1643         $text,
     1644         [0, 0],
     1645         $size,
     1646         wxNO_BORDER|wxTE_MULTILINE|wxTE_READONLY 
     1647    );
     1648}
     1649
     1650
     1651sub on_resize_progress_image {
     1652    my ( $self, $image ) = @_;
     1653
     1654    $self->upload_progressdlg->update_image_item($image);
    19031655}
    19041656
     
    19391691  my( $self, $x, $y, $files ) = @_;
    19401692
    1941   wxTheApp->frame->SetNewFiles($files) ;
     1693  wxTheApp->frame->add_images($files) ;
    19421694}
    19431695
     
    19961748             @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items;
    19971749             
    1998              wxTheApp->frame->imagelist->categories(
     1750             wxTheApp->transfer_manager->destination_category(
    19991751                 [
    20001752                     map {
     
    20051757             );
    20061758           
    2007              wxTheApp->frame->imagelist->image_selection($VAR1);
    2008              wxTheApp->frame->ProcessImageSelection ;
     1759             wxTheApp->images->selection($VAR1);
     1760             wxTheApp->frame->process_images ;
    20091761      }   
    20101762  };
  • extensions/pLoader/trunk/src/Uploader/GUI/Layout/Login.pm

    r4974 r6426  
    77use Wx qw( wxALIGN_RIGHT wxALIGN_BOTTOM wxALIGN_CENTER wxALIGN_CENTER_VERTICAL wxALIGN_CENTER_HORIZONTAL );
    88use Wx qw( wxTE_PASSWORD );
    9 use Wx::Locale;
     9use Wx::Locale qw/:default/;
    1010
    1111# Bitmap functions
  • extensions/pLoader/trunk/src/Uploader/GUI/wxCategoryTreeCtrl.pm

    r5390 r6426  
    188188    $self->SetMinSize( [20+$wp, -1 ]);
    189189
    190     Wx::Event::EVT_BUTTON( $self, $main::CATEGORIES_ADD, \&AddCategory );
     190    Wx::Event::EVT_BUTTON( $self, $main::CATEGORIES_ADD, \&add_category );
    191191}
    192192
     
    221221
    222222
    223 sub GetSelectionsIds {
     223sub selection_ids {
    224224    my ( $self )=@_;
    225225
     
    238238
    239239
    240 sub AddCategory {
     240sub add_category {
    241241    my ( $self, $event ) = @_;
    242242
    243     $self->SelectDefaultParent;
    244 
    245     my $parent_category_id = $self->GetSelectionsIds->[0];
     243    $self->select_default_parent;
     244
     245    my $parent_category_id = $self->selection_ids->[0];
    246246    my $parent_item = $self->GetSelection;
    247247
     
    255255    if( $dialog->ShowModal != wxID_CANCEL ) {
    256256        my $name = $dialog->GetValue;
    257         my ( $success, $status_msg, $content ) = wxTheApp->pwg->AddCategories( $name, $parent_category_id);
     257        my ( $success, $status_msg, $content ) = wxTheApp->pwg->add_categories( $name, $parent_category_id);
    258258
    259259        if($success){
     
    270270
    271271
    272 sub SelectDefaultParent {
    273     my ( $self ) = @_;
    274 
    275     if(!scalar @{$self->GetSelectionsIds}){
     272sub select_default_parent {
     273    my ( $self ) = @_;
     274
     275    if(!scalar @{$self->selection_ids}){
    276276        $self->SelectItem($self->GetRootItem);
    277277    }
  • extensions/pLoader/trunk/src/Uploader/GUI/wxImageListCtrl.pm

    r5392 r6426  
    6666          prevItemCount
    6767          imagenames
    68           imagelist
     68          images
    6969          wx_imagelist
    7070          image_size
     
    7474          initialize
    7575          columns
     76          display_mode_cbk
    7677          change_display_mode
    7778          wx_img
    7879          item_refresh
     80          image_type
    7981      /
    8082);
     
    9395    );
    9496   
     97    # for list mode
    9598    $self->wx_img(
    9699        Wx::ImageList->new( 16, 16, 1 )
     
    100103    );
    101104
    102     $self->imagelist(
    103         $params->{imagelist}
    104     );
     105    $self->images(
     106        $params->{images}
     107    );
     108
     109    $self->image_size(
     110        $params->{image_size}
     111    );
     112
     113    $self->display_mode_cbk(
     114        $params->{display_mode_cbk}
     115    );
     116
    105117    # bitmap container for photo selection
    106118    $self->wx_imagelist(
    107         $params->{wx_imagelist}||$self->imagelist->wx_thumb_imglist
    108     );
    109 
    110     $self->image_size(
    111         $params->{image_size}
    112     );
     119        Wx::ImageList->new(
     120            $self->image_size,
     121            $self->image_size,
     122            1,
     123            0
     124        )
     125    );
     126
     127    $self->load_images;
    113128
    114129    $self->columns(
     
    139154            }
    140155            if($self->change_display_mode){
    141                 my $dm = $self->imagelist->display_mode;
    142                    $self->initialize->{$dm}->($self) if exists $self->initialize->{$dm};
     156                my $disp_mode = $self->display_mode_cbk->();
     157                $self->initialize->{$disp_mode}->($self) if exists $self->initialize->{$disp_mode};
    143158                $self->Refresh;
    144159                $self->change_display_mode(0);
     
    206221            'Thumbnail' => sub {},
    207222            'Thumbnail and caption' => sub { my ( $self, $index ) = @_;
    208                                         my $image = $self->imagelist->GetImage($index);
     223                                        my $image = $self->images->get_image($index);
    209224                                        $self->SetItem(
    210225                                            $index,
     
    215230            'Property list' => sub { my ( $self, $index ) = @_;
    216231                                my $col = 0;
    217                                 my $image = $self->imagelist->GetImage($index);
     232                                my $image = $self->images->get_image($index);
    218233                                map{
    219234                                    $self->SetItem(
     
    236251                                           $self->InsertImageStringItem(
    237252                                               $index,
    238                                                $self->imagelist->GetImage($index)->site_name,
     253                                               $self->images->get_image($index)->site_name,
    239254                                               $index,
    240                                            );
     255                                           ) if defined $self->images->get_image($index);
    241256                                     },
    242257            'Property list' => sub { my ( $self, $index ) = @_;
     
    253268    );
    254269
    255    
    256     $self->initialize->{$self->imagelist->display_mode}->($self) if exists $self->initialize->{$self->imagelist->display_mode};
     270    my $disp_mode = $self->display_mode_cbk->();
     271    $self->initialize->{$disp_mode}->($self) if exists $self->initialize->{$disp_mode};
    257272
    258273    $self->init_empty_msg;
    259274
    260275    $self;
     276}
     277
     278
     279sub load_images {
     280    my ( $self ) = @_;
     281   
     282    my $image_ids = $self->images->ordered_image_ids;
     283    #print "load_images\n", Dumper $self->images->ordered_image_ids;
     284    my $image_index = 0;
     285    map {
     286        my $image = $self->images->Image($_);
     287
     288        #print Dumper $image;
     289        if(defined $image){
     290            $self->load_image($image);
     291        }
     292        else{
     293            # something went wrong
     294            warn printf("Error loading image %s, %s\n", $image_index, $_);
     295        }
     296
     297        $image_index++;
     298    }
     299    @$image_ids ;
     300
     301}
     302
     303
     304sub load_image {
     305    my ( $self, $image ) = @_;
     306
     307    my $wximagelist = $self->wx_imagelist;
     308
     309    unless( -e $image->wx_thumb_file ) {
     310        $self->images->create_wx_thumbnail_cbk->($image)
     311            if 'CODE' eq ref $self->images->create_wx_thumbnail_cbk;
     312    }
     313
     314    $wximagelist->Add(
     315        Wx::Bitmap->new(
     316            $image->wx_thumb_file,
     317            wxBITMAP_TYPE_JPEG,
     318        )
     319    );
    261320}
    262321
     
    264323    my ( $self, $index ) = @_;
    265324   
    266     $self->item_refresh->{$self->imagelist->display_mode}->($self, $index) if exists $self->item_refresh->{$self->imagelist->display_mode};
     325    my $disp_mode = $self->display_mode_cbk->();
     326    $self->item_refresh->{$disp_mode}->($self, $index) if exists $self->item_refresh->{$disp_mode};
    267327}
    268328
     
    272332
    273333  my $data = Wx::TextDataObject->new(
    274       Dumper $self->GetSelectedItems
     334      Dumper $self->selected_items
    275335  );
    276336  my $source = Wx::DropSource->new( $self );
     
    280340}
    281341
    282 sub GetSelectectItemsCount {
     342sub selected_items_count {
    283343    my ( $self ) = @_;   
    284344
    285     scalar @{$self->GetSelectedItems};
    286 }
    287 
    288 sub GetSelectedItems {
     345    scalar @{$self->selected_items};
     346}
     347
     348
     349sub selected_items {
    289350    my ( $self ) = @_;   
    290351
     
    307368}
    308369
    309 sub GetAllItems {
     370sub all_items {
    310371    my ( $self ) = @_;   
    311372
     
    330391
    331392
     393sub add_image {
     394    my ( $self, $wx_thumb_file ) = @_;
     395
     396
     397    my $indx = $self->wx_imagelist->Add(
     398        Wx::Bitmap->new(
     399            $wx_thumb_file,
     400            wxBITMAP_TYPE_JPEG,
     401        )
     402    ) if defined $wx_thumb_file;
     403
     404   
     405    $self->Refresh;
     406}
     407
     408sub delete_image {
     409    my ( $self, $indx ) = @_;
     410
     411    $self->wx_imagelist->Remove($indx);
     412}
     413
     414
    332415sub Refresh {
    333416    my ( $self ) = @_;   
     
    344427       for( my $i = 0 ; $i < $self->wx_imagelist->GetImageCount ; $i++){
    345428            # call the method corresponding to the display mode
    346             my $indx = $self->insert_items->{$self->imagelist->display_mode}->($self, $i);
    347             if( 'Thumbnail' eq $self->imagelist->display_mode){
     429            my $disp_mode = $self->display_mode_cbk->();
     430            my $indx = $self->insert_items->{$disp_mode}->($self, $i);
     431            if( 'Thumbnail' eq $disp_mode){
    348432                my $row = floor($i/$ipr);
    349433                my $col = $i%$ipr;
     
    360444
    361445   map{
    362        $self->SelectItem(
     446       $self->select_item(
    363447           $_
    364448       );
    365449       
    366450       $self->EnsureVisible($_);
    367    } @{$self->imagelist->image_selection||[]};
     451   } @{$self->images->selection||[]};
    368452
    369453   $self->Thaw();
     
    371455}
    372456
    373 sub SelectItem {
     457sub select_item {
    374458    my ( $self, $index ) = @_;
    375459
  • extensions/pLoader/trunk/src/Uploader/Image.pm

    r5472 r6426  
    2121use strict;
    2222use base qw/Uploader::Object/;
     23use File::Spec;
     24use Image::ExifTool qw(:Public);
     25use Data::Dumper;
    2326
    24 __PACKAGE__->mk_accessors(
    25     qw/
    26         file
    27         wx_thumb_file
    28         site_high_file
    29         site_name
    30         site_resized_file
    31         site_thumb_file
    32         site_author
    33         site_comment
    34         site_original_filename
    35         exif_metadata
    36         add_rank
    37         site_categories
    38         site_tags
    39         file_sum
    40                 width
    41                 height
    42                 privacy_level
    43         caption
    44     /
    45 );
     27# we need a ref to data preferences to use with threads
     28my @properties = qw/
     29    file
     30    wx_thumb_file
     31    site_high_file
     32    site_name
     33    site_resized_file
     34    site_thumb_file
     35    site_author
     36    site_comment
     37    site_original_filename
     38    exif_metadata
     39    add_rank
     40    site_categories
     41    site_tags
     42    image_id
     43    width
     44    height
     45    privacy_level
     46    caption
     47    global_rank
     48/;
     49
     50my $init_caption_from_pattern_cbk;
     51
     52__PACKAGE__->mk_accessors(@properties);
    4653
    4754sub Init {
    4855    my ( $self ) = @_;
    4956
     57
     58    my $exif = $self->read_exif_metadata(
     59        $self->file
     60    );
     61
     62    $self->exif_metadata(
     63        $self->select_exif_data($exif)
     64    );
     65
     66       
     67
     68    $self->site_original_filename(
     69        $self->original_filename
     70    );
     71
    5072}
     73
     74
     75sub read_exif_metadata {
     76    my ( $self, $file ) = @_;
     77   
     78    # read exif metadata
     79    my $info;
     80    eval {
     81        $info = ImageInfo( $file );
     82    };
     83    $info = {} if($@);
     84   
     85    $info;
     86}
     87
    5188
    5289sub exif_tag {
    5390    my ( $self, $tag ) = @_;
    54        
     91
    5592    my $exif = $self->exif_metadata ;
    5693   
    57     $exif->{$tag};     
     94    $exif->{$tag};
    5895}
     96
    5997
    6098sub create_date {
     
    64102   
    65103    $self->{-create_date} ||= $exif->{CreateDate};
    66        
     104
    67105    $self->{-create_date} = $date if defined $date;
    68106
    69         $self->{-create_date};
     107    $self->{-create_date};
    70108}
    71109
    72110
     111sub select_exif_data {
     112    my ( $self, $exif ) = @_;
     113
     114    return {
     115        map {
     116            $_ => $exif->{$_},
     117        }
     118        qw/
     119            CreateDate
     120            ImageWidth
     121            ImageHeight
     122            Orientation
     123            DateTimeOriginal
     124            ISO
     125            ExposureTime
     126            ApertureValue
     127            FocalLength
     128            Lens
     129            Exposure
     130            Make
     131            Model
     132        /
     133    };   
     134}
     135
     136
     137sub original_filename {
     138    my ( $self ) = @_;
     139
     140    my ( $vol, $dir, $filename ) = File::Spec->splitpath(
     141        $self->file
     142    );
     143
     144    $filename;
     145}
     146
     147sub get_data {
     148    my ( $self, $preferences, $destination_category, $add_rank ) = @_;
     149
     150    my $data = {
     151        map { $_ => $self->$_ } @properties
     152    };
     153    $data->{preferences} = $preferences;
     154    $data->{categories}  = $destination_category;
     155    $data->{site_img_date_creation} = $self->create_date;
     156    $data->{add_rank} = $add_rank;
     157
     158    return $data;
     159}
    73160
    741611;
  • extensions/pLoader/trunk/src/Uploader/Object.pm

    r4779 r6426  
    2626use base qw/
    2727               Class::Accessor::Fast
    28            /;
     28           /;
     29
     30__PACKAGE__->mk_accessors(qw/
     31    version
     32    storable_file
     33/);
    2934
    3035# $param is a hash with :
     
    3742    my $self = bless $params, $class ;
    3843
    39     # create member accessors
    40     #__PACKAGE__->mk_accessors(     
    41     #    keys %$params
    42     #);
    43    
    44    
    45     if(defined $self->{plugin_file}){
    46         die "Plugin file is missing." unless -e $self->{plugin_file};
    47         $self->InitPlugins();
    48     }
    49 
    5044    # member accessors initialization
    5145    eval {
    5246        map {
    53                 $self->$_(
    54                     $params->{$_}
    55                 );
     47            $self->$_(
     48                $params->{$_}
     49            );
    5650        }
    5751        keys %$params;
     
    6458    $self->Init();
    6559
    66    
    6760    return $self;
    6861}
    6962
    7063
    71 sub InitPlugins {
    72     my ( $self ) = @_;
    73    
    74     my $data;
    75     eval { $data = read_file( $self->{plugin_file} ); } ;
     64sub read_params {
     65    my( $self, $file, $key ) = @_ ;
    7666
    77     my $plugins = [] ;
    78     if( defined $data){
    79         my $expr = '$plugins = ' ;
    80         $expr .=  "$data  " ;
     67    my $expr_params ;
     68    eval { $expr_params = read_file( $file ); } ;
     69
     70    my $paramValues = [] ;
     71    if($expr_params){
     72        my $expr = '$paramValues = ' ;
     73        $expr .=  "$expr_params  " ;
    8174        eval $expr ;
    8275    }
    83     # load plugins
    84    
    85     my $hplugins = $plugins->[0] if scalar @$plugins;
    86     while( my ( $key, $value ) = each %$hplugins ) {
    87         $self->ReadParams( $value, $key);
    88     }
    89    
    90 }
    91 
    92 sub ReadParams {
    93         my( $self, $file, $key ) = @_ ;
    94 
    95         my $expr_params ;
    96         eval { $expr_params = read_file( $file ); } ;
    97        
    98         my $paramValues = [] ;
    99         if($expr_params){
    100                 my $expr = '$paramValues = ' ;
    101                 $expr .=  "$expr_params  " ;
    102                 eval $expr ;
    103         }
    104         return unless 'ARRAY' eq ref $paramValues ;
     76    return unless 'ARRAY' eq ref $paramValues ;
    10577        if($@){
    10678            die "Cannot load data $@"; 
    10779        }
    108         if(scalar(@$paramValues )){
    109             my $params = $paramValues->[0] ;
    110             $self->SetKeyValues($params, $key);
    111         }
     80    if(scalar(@$paramValues )){
     81        my $params = $paramValues->[0] ;
     82        $self->set_key_values($params, $key);
     83    }
    11284}
    11385
    114 sub SetKeyValues {
     86
     87sub set_key_values {
    11588    my ( $self, $params, $key )= @_;
    11689    if (defined $key) {
     
    132105    my $data = {
    133106        map {
    134             $_ => $self->{$_},
     107            $_ => $self->{$_},
    135108          }
    136109          @$keys
     
    140113}
    141114
     115
    1421161;
  • extensions/pLoader/trunk/src/Uploader/PWG.pm

    r6088 r6426  
    5656    }
    5757    else{
    58         $self->GetMethods;
    59         $self->RefreshCategories;
    60         $self->RefreshTags;
     58        $self->get_methods;
     59        $self->refresh_categories;
     60        $self->refresh_tags;
    6161    }
    6262}
    6363
    64 sub RefreshCategories {
     64sub refresh_categories {
    6565    my ( $self ) = @_;
    6666
    6767    $self->categories(
    6868        $self->prepare_items(
    69             $self->GetCategories
     69            $self->get_categories
    7070        )
    7171    );
    7272}
    7373
    74 sub RefreshTags {
     74sub refresh_tags {
    7575    my ( $self ) = @_;
    7676
    7777    $self->tags(
    78         $self->GetTags
     78        $self->get_tags
    7979    );
    8080}
  • extensions/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r6088 r6426  
    4646           qry_list_tags
    4747           qry_check_upload
    48            items
    49            tags
    50            categories
    51            site_original_filename
    52            site_high_file
    53            site_resized_file
    54            site_thumb_file
    55            site_image_name
    56            site_tags
    57            rank
    58            site_author
    59            site_comment
    60            site_img_date_creation
    6148           uagent_response
    6249           login_result
    63            action_result
    64            upload_high
    65            chunk_size
    66            sum
    67            image_id
     50           categories
     51           tags
    6852           typecode
    69            reupload_action_files
    70            reupload_action_properties
    71            reupload_action_properties_m
     53           file_type
    7254           single_value_mode
    7355           multiple_value_mode
    74            privacy_level
    7556           is_method_available
     57           log_progress_cbk
    7658      /
    7759);
     
    9072        }
    9173    );
     74
     75    $self->file_type({
     76        thumb => 'site_thumb_file',
     77        file  => 'site_resized_file',
     78        high  => 'site_high_file',
     79    });
     80
    9281   
    9382    $self->single_value_mode(
     
    125114    );
    126115   
    127     $self->chunk_size(
    128         $self->{chunk_size}
    129     );
    130 
    131116   
    132117    $self->uagent->default_headers->authorization_basic(
     
    169154    };
    170155 
    171     $self->_execute_post(
     156    $self->execute_post(
    172157        $form
    173158    );   
    174159
    175160    $self->login_result(
    176         $self->_json_response_content
    177     );
    178 
    179 }
    180 
    181 sub _json_response_content {
     161        $self->json_response_content
     162    );
     163
     164}
     165
     166sub json_response_content {
    182167    my ( $self ) = @_;
    183168
     
    216201}
    217202
    218 sub _execute_get {
     203sub execute_get {
    219204    my ( $self, $query ) = @_;
    220205
     
    235220}
    236221
    237 sub _execute_post {
     222sub execute_post {
    238223    my ( $self, $form ) = @_;
    239224
     
    257242}
    258243
    259 sub GetCategories {
     244sub get_categories {
    260245    my ( $self ) = @_;
    261246
    262247 
    263     $self->_execute_get(
     248    $self->execute_get(
    264249        $self->qry_list_categories
    265250    );
    266     $self->_json_response_content->{result}{categories};
    267 }
    268 
    269 sub GetTags {
     251    $self->json_response_content->{result}{categories};
     252}
     253
     254sub get_tags {
    270255    my ( $self ) = @_;
    271256
    272     $self->_execute_get(
     257    $self->execute_get(
    273258        $self->qry_list_tags   
    274259    );
    275     $self->_json_response_content->{result}{tags};
    276 }
    277 
    278 sub AddTags {
     260    $self->json_response_content->{result}{tags};
     261}
     262
     263sub add_tags {
    279264    my ( $self, $name ) = @_;
    280265
     
    285270    };
    286271
    287     return ( $self->_execute_post($form), $self->_json_response_content );
     272    return ( $self->execute_post($form), $self->json_response_content );
    288273}
    289274
    290 sub CheckUpload {
     275sub check_upload {
    291276    my ( $self ) = @_;
    292277
     
    294279
    295280    if($self->is_method_available->{'pwg.images.checkUpload'}){
    296         $self->_execute_get(
     281        $self->execute_get(
    297282            $self->qry_check_upload
    298283        );
    299 #        my $result = $self->_json_response_content->{result};
    300         my $hresult = $self->_json_response_content;
     284
     285        my $hresult = $self->json_response_content;
    301286
    302287        $err_msg = 'ok' eq $hresult->{stat} ?
     
    308293}
    309294
    310 sub GetMethods {
     295
     296sub get_methods {
    311297    my ( $self ) = @_;
    312298
    313     $self->_execute_get(
     299    $self->execute_get(
    314300        $self->qry_list_methods   
    315301    );
    316302
    317     my $methods = $self->_json_response_content->{result}{methods};
     303    my $methods = $self->json_response_content->{result}{methods};
    318304
    319305    $self->is_method_available(
     
    328314}
    329315
    330 sub UploadImage {
    331     my ( $self, $progress ) = @_;
    332    
    333     return if $progress->{stop_processing};
    334 
    335     $self->image_id(
    336         $self->_exists($progress->{original_sum})
    337     );
    338 
    339     my $status = 1;
    340     my $status_line ="OK";
    341     my $content = {};
    342     my $doubleCheck;
    343     my $form;
    344     UPLOAD: while(1){
    345         # first upload
    346         if(!defined($self->image_id)){
    347             $doubleCheck = 1;
    348             $self->_checksum_files($progress);
    349             my @types = ('file', 'thumb');
    350             #printf("WS upload_high %s\n", $self->upload_high);
    351             push @types, 'high' if $self->upload_high;
    352             map{
    353                 my $rval = $self->_send_chunks($_, $progress);
    354                 $status_line = $rval->{message};
    355                 if (!$rval->{ok}){
    356                     $status = 0;
    357                     last UPLOAD ;
    358                 }
    359             } @types;
    360          
    361            
    362             $form = {
    363                 method            => 'pwg.images.add',
    364                 original_sum      => $self->sum->{original},
    365                 original_filename => $self->site_original_filename,
    366                 file_sum          => $self->sum->{file},
    367                 thumbnail_sum     => $self->sum->{thumb},
    368                 categories        => $self->categories,
    369                 name              => $self->site_image_name,
    370                 author            => $self->site_author,
    371                 comment           => $self->site_comment,
    372                 date_creation     => $self->site_img_date_creation,
    373                 tag_ids           => $self->site_tags,
    374                
    375             };
    376 
    377            $form->{high_sum} = $self->sum->{high} if $self->upload_high;
    378            
    379            $progress->{yield}->();
    380            ( $status, $status_line ) = $self->_execute_post($form);
    381         }
    382         # re-upload
    383         else{
    384             # need to check if files have changed
    385             # and update image info
    386             if($self->reupload_action_files){
    387                 $self->_checksum_files($progress);
    388                 my $files = $self->_check_files();
    389                 if(defined($files)){
    390                     $self->_add_files($files, $progress);   
    391                 }
    392             }
    393 
    394             $form = {
    395                     method        => 'pwg.images.setInfo',
    396                     image_id      => $self->image_id,
    397             };
    398             # update metadata info
    399             # simple value metadata
    400             if($self->reupload_action_properties){     
    401                 $form->{name}          = $self->site_image_name;
    402                 $form->{author}        = $self->site_author;
    403                 $form->{comment}       = $self->site_comment;
    404                 $form->{date_creation} = $self->site_img_date_creation;
    405                 $form->{single_value_mode}  = $self->single_value_mode->{$self->reupload_action_properties};
    406                 $form->{level} = $self->privacy_level ? 2**($self->privacy_level - 1) : 0;
    407             }
    408             # multi value metadata
    409             if($self->reupload_action_properties_m){     
    410                 $form->{tag_ids} = $self->site_tags if $self->site_tags;
    411                 $form->{categories} = $self->categories;
    412                 $form->{multiple_value_mode} = $self->multiple_value_mode->{$self->reupload_action_properties_m};
    413             };
    414             $progress->{yield}->();
    415             ( $status, $status_line ) = $self->_execute_post($form);
    416 
    417         }
    418 
    419         delete $form->{tag_ids} unless defined $self->site_tags;
    420         delete $form->{tag_ids} if '' eq $self->site_tags;
    421 
    422         $progress->{yield}->();
    423         # for first upload
    424         # make sure the image is uploaded by querying for its existence
    425         if($doubleCheck){
    426             $self->image_id(
    427                 $self->_exists($progress->{original_sum})
    428             );
    429             $content->{stat} = !defined $self->image_id  ? 'fail' : 'ok';
    430             if(defined $self->image_id and defined $self->privacy_level){
    431                 ( $status, $status_line, $content ) = $self->_set_privacy_level;
    432             }
    433         }
    434 
    435         last UPLOAD;
    436     }# UPLOAD
    437    
    438     return ( $status,  $status_line, $content);
    439 }
    440 
    441 sub _set_privacy_level {
    442     my ( $self ) = @_;
     316
     317sub exists_image {
     318    my ( $self, $image ) = @_;
     319
     320    my $image_sum = $image->{image_id};
     321    my $form = {
     322        method      => 'pwg.images.exist',
     323        md5sum_list => $image_sum,
     324    };
     325
     326    $self->execute_post($form);   
     327    my $hresult = $self->json_response_content;
     328
     329    $hresult->{result} = {} if 'HASH' ne ref $hresult->{result};
     330
     331    my $pwg_image_id = 'ok' eq $hresult->{stat} ?
     332        $hresult->{result}{$image_sum} :
     333        undef ;
     334
     335    $image->{pwg_image_id} = $pwg_image_id;
     336
     337    return $pwg_image_id;
     338}
     339
     340
     341sub set_image_privacy_level {
     342    my ( $self, $image ) = @_;
    443343       
    444344    my $form = {
    445345        method        => 'pwg.images.setPrivacyLevel',
    446         image_id      => $self->image_id,
    447         level         => $self->privacy_level ? 2**($self->privacy_level - 1) : 0,
    448     };
    449 
    450     my ( $status, $status_line ) = $self->_execute_post($form);
    451     my $hresult = $self->_json_response_content;
     346        image_id      => $image->{pwg_image_id},
     347        level         => $image->{privacy_level} ? 2**($image->{privacy_level} - 1) : 0,
     348    };
     349
     350    my ( $status, $status_line ) = $self->execute_post($form);
     351    my $hresult = $self->json_response_content;
    452352
    453353    ($status, $status_line, $hresult );
    454354}
    455355
    456 sub _checksum_files {
    457     my ( $self, $progress ) = @_;
    458 
    459     $self->sum(
    460         {
    461             file => $self->_checksum(
    462                         $self->site_resized_file,
    463                         $progress
    464                     ),
    465             thumb => $self->_checksum(
    466                              $self->site_thumb_file,
    467                              $progress
    468                          ),
    469             original => $progress->{original_sum}
    470         }
    471     );
    472 
    473     $self->sum->{high} = $self->_checksum(
    474                         $self->site_high_file,
    475                         $progress
    476     ) if $self->upload_high ;
    477 }
    478 
    479 sub _check_files {
    480     my ( $self ) = @_;
     356
     357sub update_image_modified_files {
     358    my ( $self, $image ) = @_;
     359
     360    my $modified_ftc = $self->image_modified_file_type_codes($image);
     361    map{
     362        $self->add_image_file_type($image, $_);
     363    }@$modified_ftc;
     364
     365}
     366
     367
     368# 'file', 'thumb', 'high'
     369sub image_modified_file_type_codes {
     370    my ( $self, $image ) = @_;
    481371
    482372    my $form = {
    483373        method   => 'pwg.images.checkFiles',
    484         image_id => $self->image_id,
     374        image_id => $image->{pwg_image_id},
    485375    };
    486376   
    487377    @$form{'thumbnail_sum', 'file_sum' } = (
    488         $self->sum->{thumb},
    489         $self->sum->{file},
    490     );
    491 
    492     if($self->upload_high){
    493         $form->{high_sum} = $self->sum->{high};
    494     }
    495 
    496     $self->_execute_post($form);   
    497     my $hresult = $self->_json_response_content;
    498 
    499     my $rval = 'ok' eq $hresult->{stat} ? $hresult->{result} : undef;
    500    
    501     $rval;
    502 }
    503 
    504 # $files is returned by _check_files
    505 # {
    506 #     thumbnail => 'equals', 'differs', 'missing'
    507 #     file => 'equals', 'differs', 'missing'
    508 #     high => 'equals', 'differs', 'missing'
    509 #}
    510 
    511 sub _add_files {
    512     my ( $self, $files, $progress ) = @_;
    513 
    514     map{
    515         $self->_add_file($_, $progress);
    516     }
    517     map{
    518         $self->typecode->{$_};
    519     } grep { 'equals' ne $files->{$_} } keys %$files ;
    520        
    521 }
    522 
    523 sub _add_file {
    524     my ( $self, $type_code, $progress ) = @_;
    525 
    526     $self->_send_chunks(
    527         $type_code,
    528         $progress,
    529     );
    530 
    531     my $form = {
    532         method => 'pwg.images.addFile',
    533         image_id => $self->image_id,
    534         type     => $type_code,
    535         sum      => $self->sum->{$type_code},       
    536     };   
    537 
    538     $self->_execute_post($form);   
    539     my $hresult = $self->_json_response_content;
    540 
    541     my $rval = 'ok' eq $hresult->{stat} ? $hresult->{result} : undef;
    542    
    543     $rval;
    544 }
     378        $image->{site_thumb_file_checksum},
     379        $image->{site_resized_file_checksum},
     380    );
     381
     382    if($image->{upload_high}){
     383        $form->{high_sum} = $image->{site_high_file_checksum};
     384    }
     385    $self->execute_post($form);   
     386    my $hresp = $self->json_response_content;
     387
     388    my $hmodified = 'ok' eq $hresp->{stat} ? $hresp->{result} : {};
     389    # $hmodified :
     390    # {
     391    #     thumbnail => 'equals', 'differs', 'missing'
     392    #     file => 'equals', 'differs', 'missing'
     393    #     high => 'equals', 'differs', 'missing'
     394    #}
     395   
     396    my $modified = [
     397        map{
     398            $self->typecode->{$_};
     399        } grep { 'equals' ne $hmodified->{$_} } keys %$hmodified
     400    ];
     401
     402    # $modified contains : 'thumbnail', 'file', 'high'
     403    # or empty if nothing has changed
     404    $modified;
     405}
     406
     407
     408sub update_image_properties {
     409    my ( $self, $image ) = @_;
     410
     411    my $reupload_ap  = $image->{preferences}{reupload_action_properties};
     412    my $reupload_apm = $image->{preferences}{reupload_action_properties_m};
     413
     414    my $form = {
     415            method        => 'pwg.images.setInfo',
     416            image_id      => $image->{pwg_image_id},
     417    };
     418    # update metadata info
     419    # simple value metadata
     420    if($reupload_ap){
     421        $form->{name}          = $image->{site_name};
     422        $form->{author}        = $image->{site_author};
     423        $form->{comment}       = $image->{site_comment};
     424        $form->{date_creation} = $image->{site_img_date_creation};
     425        $form->{single_value_mode}  = $self->single_value_mode->{$reupload_ap};
     426        $form->{level} = $image->{privacy_level} ? 2**($image->{privacy_level} - 1) : 0;
     427    }
     428
     429    # multi value metadata
     430    if($reupload_apm){
     431        $form->{tag_ids}             = $image->{site_tags} if $image->{site_tags};
     432        $form->{categories}          = $image->{categories};
     433        $form->{multiple_value_mode} = $self->multiple_value_mode->{$reupload_apm};
     434    }
     435
     436    $self->execute_post($form);
     437
     438}
     439
     440
     441
    545442
    546443sub IsAlreadyUploaded {
     
    548445   
    549446    # md5_sums is an array ref
    550     $self->_execute_post({
     447    $self->execute_post({
    551448        method      => 'pwg.images.exist',
    552449        md5sum_list => join(',', @$md5_sums)
     
    554451    );
    555452
    556     my $sums = $self->_json_response_content->{result};
     453    my $sums = $self->json_response_content->{result};
    557454
    558455    $sums;
    559456}
    560457
    561 sub _exists {
    562     my ( $self, $md5_sum ) = @_;
    563 
    564     my $form = {
    565         method            => 'pwg.images.exist',
    566         md5sum_list       => $md5_sum,
    567     };
    568 
    569     $self->_execute_post($form);   
    570     my $hresult = $self->_json_response_content;
    571 
    572     $hresult->{result} = {} if 'HASH' ne ref $hresult->{result};
    573     my $id = 'ok' eq $hresult->{stat} ? $hresult->{result}{$md5_sum} : undef ;
    574 
    575     $id;
    576 }
    577 
    578 sub _checksum {
    579     my ( $self, $file, $progress ) = @_;
    580     my $file_sum;
    581 
    582     my $yield = $progress->{yield};
    583 
    584     $yield->();
    585     $progress->{msg_details}->(
    586         sprintf(
    587             "%s : %s",
    588             $progress->{checksum_msg},
    589             $file
    590         )
    591     );
    592 
    593     eval {
    594         $file_sum = file_md5_hex(
    595             $file
     458
     459sub send_image_files_chunks {
     460    my ( $self, $image ) = @_;
     461
     462    my $errors = 0;
     463
     464    my @types = ('file', 'thumb');
     465    push @types, 'high' if $image->{upload_high};
     466    map{
     467        my $rval = $self->send_image_file_type_chunks(
     468            $image,
     469            $_,
    596470        );
    597     };
    598     $yield->();
    599 
    600     $file_sum;
    601 }
    602 
    603 sub _send_chunks {
    604     my ( $self, $type_code, $progress ) = @_;
    605 
    606     my $msg = {
    607         thumb=>'thumbnail_msg',
    608         file=>'resized_msg',
    609         high=>'highdef_msg',
    610     };
    611 
    612     my $filepath = {
    613         thumb=>$self->site_thumb_file,
    614         file=>$self->site_resized_file,
    615         high=>$self->site_high_file,
    616     };
    617 
    618     $progress->{current_msg} = $progress->{$msg->{$type_code}};
    619     $progress->{yield}->();
    620 
    621     my $params = {
    622          filepath      => $filepath->{$type_code},
    623          type          => $type_code,
    624          original_sum  => $self->sum->{original},
    625     };
    626     #print Dumper $params;
    627     $self->send_chunks(
    628        $params,
    629        $progress,
    630     );
    631     $progress->{yield}->();
    632 
    633     $params;
    634 }
    635 
    636 sub AddCategories{
    637     my ( $self, $name, $parentid ) = @_;
    638 
    639     my $form = {
    640         method            => 'pwg.categories.add',
    641         name              => $name,
    642         parent            => $parentid,
    643        
    644     };
    645    
    646     return ( $self->_execute_post($form), $self->_json_response_content );
    647 }
    648 
    649 sub SetInfoCategories{
    650     my ( $self, $name, $comment, $parentid ) = @_;
    651 
    652     my $form = {
    653         method            => 'pwg.categories.setInfo',
    654         name              => $name,
    655         comment           => $comment,
    656         category_id       => $parentid,
    657        
    658     };
    659 
    660     return ( $self->_execute_post($form), $self->_json_response_content );
    661 }
    662 
    663 
    664 sub send_chunks {
    665     my ( $self, $params, $progress ) = @_;
    666 
    667     my $yield = $progress->{yield};
    668     my ( $vol, $dir, $filename ) = File::Spec->splitpath($params->{filepath});
    669 
    670     $yield->();
    671     $progress->{bar}->(0);
    672     $yield->();
    673     $progress->{msg_details}->(
    674         sprintf(
    675             "%s : %s",
    676             $progress->{current_msg},
    677             $filename
    678         )
    679     );
    680 
    681 
    682     $yield->();
     471        if (!$rval->{ok}){
     472            $errors += 1;
     473        }
     474    } @types;
     475
     476    $errors;
     477}
     478
     479
     480sub send_image_file_type_chunks {
     481    my ( $self, $image, $file_type_code ) = @_;
     482
     483    $image->{file_type_code} = $file_type_code;
     484
     485    $self->send_image_chunks(
     486       $image
     487    );
     488}
     489
     490
     491sub send_image_chunks {
     492    my ( $self, $image ) = @_;
     493
     494    my $params = {};
     495
     496    my $file = $self->get_image_file($image);
     497
     498    my ( $vol, $dir, $filename ) = File::Spec->splitpath(
     499        $file
     500    );
     501
    683502    my $content = read_file(
    684         $params->{filepath},
     503        $file,
    685504        binmode => ':raw',
    686505    );
    687     $yield->();
    688 
     506
     507    my $chunk_size = $image->{preferences}{chunk_size}||500000;
    689508    my $content_length = length($content);
    690     my $nb_chunks = ceil($content_length / $self->chunk_size->());
     509    my $nb_chunks = ceil($content_length / $chunk_size);
    691510
    692511    my $chunk_pos = 0;
    693512    my $chunk_id = 1;
     513 
     514    $self->log_image_progress(
     515        $image,
     516        sprintf("sending %s", $image->{file_type_code}),
     517        0,
     518    );
    694519
    695520
     
    699524            $content,
    700525            $chunk_pos,
    701             $self->chunk_size->()
     526            $chunk_size
    702527        );
    703         $chunk_pos += $self->chunk_size->();
    704         #print "pwg.images.addChunk\n";
     528        $chunk_pos += $chunk_size;
    705529        my $data = encode_base64($chunk);
    706         #printf("chunk : %s, data %s\n", length $chunk, length $data);
    707530        my $response = $self->uagent->post(
    708531            $self->urlbase.'/ws.php?format=json',
     
    710533                method       => 'pwg.images.addChunk',
    711534                data         => $data,
    712                 original_sum => $params->{original_sum},
     535                original_sum => $image->{image_id},
    713536                position     => $chunk_id,
    714                 type         => $params->{type},
     537                type         => $image->{file_type_code},
    715538            }
    716539        );
    717 #print Dumper $response;
    718         $yield->();
    719         $progress->{bar}->(100*($chunk_pos/$content_length));
    720         $progress->{msg_details}->(
    721             sprintf(
    722                 "%s : %s",
    723                 $progress->{current_msg},
    724                 $filename
    725             )
    726         );
     540
    727541        $params->{ok} = 1;
    728542        if ($response->code != 200) {
     
    732546            $params->{message} = $response->message;
    733547            $params->{code} = $response->code;
     548            $image->{last_error_msg} = $response->message;
    734549            last;
    735550        }
     551        printf("sending with chunk_size %s, chunk %s\n", $chunk_size, $chunk_id);
     552
     553        $self->log_image_progress(
     554            $image,
     555            sprintf("sending %s", $image->{file_type_code}),
     556            100*($chunk_pos/$content_length),
     557        );
    736558
    737559        $chunk_id++;
    738560    }
    739 }
     561
     562    $params;
     563}
     564
     565
     566sub get_image_file {
     567    my ( $self, $image ) = @_;
     568   
     569    my $ft = $self->image_file_type($image);
     570    $image->{$ft};
     571}
     572
     573
     574sub get_image_sum {
     575    my ( $self, $image ) = @_;
     576   
     577    my $ft = $self->image_file_type($image);
     578    $image->{"$ft"."_checksum"};
     579}
     580
     581
     582# 'site_resized_file', 'site_thumb_file', 'site_high_file'
     583sub image_file_type {
     584    my ( $self, $image ) = @_;
     585
     586    # thumb, file, high
     587    my $ftc = $image->{file_type_code};
     588    # site_thumb_file, site_resized_file, site_high_file
     589    my $ft = $self->file_type->{$ftc} if defined $ftc;
     590
     591    $ft;
     592}
     593
     594
     595sub log_image_progress {
     596    my ( $self, $image, $status, $value ) = @_;
     597
     598    $image->{status}   = $status;
     599    $image->{progress} = $value;
     600
     601    $self->log_progress_cbk->(
     602        $image
     603    ) if 'CODE' eq ref $self->log_progress_cbk;
     604
     605}
     606
     607sub add_image {
     608    my ( $self, $image ) = @_;
     609
     610    my $form = {
     611        method            => 'pwg.images.add',
     612        original_sum      => $image->{image_id},
     613        original_filename => $image->{site_original_filename},
     614        file_sum          => $image->{site_resized_file_checksum},
     615        thumbnail_sum     => $image->{site_thumb_file_checksum},
     616        categories        => $image->{categories},
     617        name              => $image->{site_name},
     618        author            => $image->{site_author},
     619        comment           => $image->{site_comment},
     620        date_creation     => $image->{site_img_date_creation},
     621        tag_ids           => $image->{site_tags},
     622        level => $image->{privacy_level} ? 2**($image->{privacy_level} - 1) : 0,
     623    };
     624
     625    $form->{high_sum} = $image->{site_high_file_checksum} if $image->{upload_high};
     626    # TODO : ERROR MANAGEMENT + DOUBLE CHECK
     627    $self->execute_post($form);
     628}
     629
     630# $file_type_code : 'file', 'thumb', 'high'
     631sub add_image_file_type {
     632    my ( $self, $image, $file_type_code ) = @_;
     633
     634    $image->{file_type_code} = $file_type_code;
     635
     636    $self->send_image_chunks($image);
     637
     638    my $form = {
     639        method => 'pwg.images.addFile',
     640        image_id => $image->{pwg_image_id},
     641        type     => $file_type_code,
     642        sum      => $self->get_image_sum($image),
     643    };
     644
     645    $self->execute_post($form);   
     646    my $hresult = $self->json_response_content;
     647    my $rval = 'ok' eq $hresult->{stat} ? $hresult->{result} : undef;
     648   
     649    $rval;
     650}
     651
     652sub add_categories{
     653    my ( $self, $name, $parentid ) = @_;
     654
     655    my $form = {
     656        method            => 'pwg.categories.add',
     657        name              => $name,
     658        parent            => $parentid,
     659       
     660    };
     661   
     662    return ( $self->execute_post($form), $self->json_response_content );
     663}
     664
     665sub set_info_category{
     666    my ( $self, $name, $comment, $parentid ) = @_;
     667
     668    my $form = {
     669        method            => 'pwg.categories.setInfo',
     670        name              => $name,
     671        comment           => $comment,
     672        category_id       => $parentid,
     673       
     674    };
     675
     676    return ( $self->execute_post($form), $self->json_response_content );
     677}
     678
     679
    740680
    741681 
    7426821;
    743    
Note: See TracChangeset for help on using the changeset viewer.