| 1 | # +-----------------------------------------------------------------------+ |
|---|
| 2 | # | pLoader - a Perl photo uploader for Piwigo | |
|---|
| 3 | # +-----------------------------------------------------------------------+ |
|---|
| 4 | # | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | |
|---|
| 5 | # +-----------------------------------------------------------------------+ |
|---|
| 6 | # | This program is free software; you can redistribute it and/or modify | |
|---|
| 7 | # | it under the terms of the GNU General Public License as published by | |
|---|
| 8 | # | the Free Software Foundation | |
|---|
| 9 | # | | |
|---|
| 10 | # | This program is distributed in the hope that it will be useful, but | |
|---|
| 11 | # | WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 12 | # | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|---|
| 13 | # | General Public License for more details. | |
|---|
| 14 | # | | |
|---|
| 15 | # | You should have received a copy of the GNU General Public License | |
|---|
| 16 | # | along with this program; if not, write to the Free Software | |
|---|
| 17 | # | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
|---|
| 18 | # | USA. | |
|---|
| 19 | # +-----------------------------------------------------------------------+ |
|---|
| 20 | package Uploader::GUI::Frame; |
|---|
| 21 | use strict; |
|---|
| 22 | use Data::Dumper; |
|---|
| 23 | use Carp; |
|---|
| 24 | use Wx; |
|---|
| 25 | use Wx::DND; |
|---|
| 26 | use Wx qw/ |
|---|
| 27 | wxCLIP_CHILDREN |
|---|
| 28 | wxYES_NO |
|---|
| 29 | wxYES |
|---|
| 30 | wxICON_QUESTION |
|---|
| 31 | wxITEM_NORMAL |
|---|
| 32 | wxID_OK |
|---|
| 33 | wxDEFAULT_FRAME_STYLE |
|---|
| 34 | wxVERTICAL |
|---|
| 35 | wxGROW |
|---|
| 36 | wxSHAPED |
|---|
| 37 | wxBITMAP_TYPE_JPEG |
|---|
| 38 | wxBITMAP_TYPE_GIF |
|---|
| 39 | wxBITMAP_TYPE_PNG |
|---|
| 40 | wxBITMAP_TYPE_ANY |
|---|
| 41 | wxTB_FLAT |
|---|
| 42 | wxTB_TEXT |
|---|
| 43 | wxSIZE |
|---|
| 44 | wxWHITE |
|---|
| 45 | wxBLACK |
|---|
| 46 | wxID_CANCEL |
|---|
| 47 | wxFD_OPEN |
|---|
| 48 | wxFD_MULTIPLE |
|---|
| 49 | wxALL |
|---|
| 50 | wxGROW |
|---|
| 51 | wxDefaultPosition |
|---|
| 52 | wxDefaultSize |
|---|
| 53 | wxTheApp |
|---|
| 54 | wxIMAGE_LIST_NORMAL |
|---|
| 55 | wxNO_BORDER |
|---|
| 56 | wxTE_MULTILINE |
|---|
| 57 | wxTE_READONLY |
|---|
| 58 | wxITEM_NORMAL |
|---|
| 59 | wxBORDER_NONE |
|---|
| 60 | wxNullBitmap |
|---|
| 61 | wxTR_MULTIPLE |
|---|
| 62 | wxTR_EXTENDED |
|---|
| 63 | wxTR_HIDE_ROOT |
|---|
| 64 | wxTR_HAS_BUTTONS |
|---|
| 65 | wxTR_EDIT_LABELS |
|---|
| 66 | wxMAXIMIZE |
|---|
| 67 | wxOK |
|---|
| 68 | wxICON_EXCLAMATION |
|---|
| 69 | wxICON_INFORMATION |
|---|
| 70 | WXK_DELETE |
|---|
| 71 | wxHORIZONTAL |
|---|
| 72 | wxVERTICAL |
|---|
| 73 | wxEXPAND |
|---|
| 74 | wxSWISS |
|---|
| 75 | wxNORMAL |
|---|
| 76 | wxBOLD |
|---|
| 77 | wxALIGN_CENTER |
|---|
| 78 | /; |
|---|
| 79 | use base qw/Wx::Frame Class::Accessor::Fast/; |
|---|
| 80 | use File::Spec; |
|---|
| 81 | use Wx::Locale qw/:default/; |
|---|
| 82 | use POSIX qw(ceil floor); |
|---|
| 83 | |
|---|
| 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 | /; |
|---|
| 131 | __PACKAGE__->mk_accessors( @properties ); |
|---|
| 132 | |
|---|
| 133 | use Wx::Perl::TextValidator; |
|---|
| 134 | use Uploader::GUI::wxImageListCtrl; |
|---|
| 135 | use Uploader::GUI::wxPropertyListDlg; |
|---|
| 136 | use Uploader::GUI::wxGlobalSettings; |
|---|
| 137 | use Uploader::GUI::wxImagePreview; |
|---|
| 138 | use Uploader::GUI::wxPhotoProperties; |
|---|
| 139 | use Uploader::GUI::wxImageReuploadDlg; |
|---|
| 140 | use Uploader::GUI::wxImageProcessingProgressDlg; |
|---|
| 141 | use Uploader::GUI::wxDestinationCategoryDlg; |
|---|
| 142 | use Uploader::GUI::wxCategoryTreeCtrl; |
|---|
| 143 | use utf8; |
|---|
| 144 | $|=1; |
|---|
| 145 | |
|---|
| 146 | my $ID_TREE_CTX_MENU = 20000 ; |
|---|
| 147 | my $ID_IMAGEVIEWER_CTX_MENU = 20100 ; |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | sub new { |
|---|
| 151 | my( $class, $params ) = @_; |
|---|
| 152 | |
|---|
| 153 | my $self = $class->SUPER::new( |
|---|
| 154 | undef, |
|---|
| 155 | -1, |
|---|
| 156 | $params->{title}, |
|---|
| 157 | wxDefaultPosition, |
|---|
| 158 | wxDefaultSize, |
|---|
| 159 | wxDEFAULT_FRAME_STYLE |
|---|
| 160 | ); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | $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 | ); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | $self->init_gui_callbacks; |
|---|
| 177 | $self->init_properties_dlg_bindings; |
|---|
| 178 | $self->init_frame; |
|---|
| 179 | $self->init_menus; |
|---|
| 180 | $self->init_event_handlers; |
|---|
| 181 | $self->init_image_types; |
|---|
| 182 | |
|---|
| 183 | $self->imageviewer->SelectItem( |
|---|
| 184 | $self->current_imageviewer_index |
|---|
| 185 | ) if $self->imageviewer->GetItemCount; |
|---|
| 186 | |
|---|
| 187 | # if file in command line parameters, try to load |
|---|
| 188 | my $files = wxTheApp->argv; |
|---|
| 189 | $self->SetNewFiles($files) if scalar @$files; |
|---|
| 190 | |
|---|
| 191 | $self->Show; |
|---|
| 192 | $self; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | sub init_gui_callbacks { |
|---|
| 197 | my ( $self ) = @_; |
|---|
| 198 | |
|---|
| 199 | # 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 | ); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | sub init_properties_dlg_bindings { |
|---|
| 293 | my ( $self ) = @_; |
|---|
| 294 | |
|---|
| 295 | $self->piwigo_photo_properties( |
|---|
| 296 | { |
|---|
| 297 | $main::CAPTION => { label=>gettext("Caption")}, |
|---|
| 298 | $main::PHOTO_PROPERTIES_CAPTION => { |
|---|
| 299 | multi_selection_mode => sub { $self->multi_selection_mode }, |
|---|
| 300 | string_selection => sub { return 1; }, |
|---|
| 301 | value => sub { |
|---|
| 302 | $self->imagelist->SetImageSelectionName(@_); |
|---|
| 303 | $self->multi_selection_mode ? |
|---|
| 304 | $self->imagelist->image_selection_name : |
|---|
| 305 | $self->imagelist->current_image->site_name; |
|---|
| 306 | }, |
|---|
| 307 | pre_process => sub { sub { $self->imagelist->GetCurrentImageCaption(@_); } }, |
|---|
| 308 | choices => |
|---|
| 309 | [ |
|---|
| 310 | map { gettext $_ } @{wxTheApp->caption_patterns} |
|---|
| 311 | ], |
|---|
| 312 | frame_callback => sub { $self->imageviewer_item_refresh(1); }, |
|---|
| 313 | }, |
|---|
| 314 | $main::COMMENT => { label=>gettext("Comment")}, |
|---|
| 315 | $main::PHOTO_PROPERTIES_COMMENT => { |
|---|
| 316 | value => sub { |
|---|
| 317 | $self->multi_selection_mode ? |
|---|
| 318 | $self->imagelist->SetImageSelectionComment(@_): |
|---|
| 319 | $self->imagelist->current_image->site_comment(@_) |
|---|
| 320 | }, |
|---|
| 321 | frame_callback => sub { $self->imageviewer_item_refresh(1); }, |
|---|
| 322 | }, |
|---|
| 323 | $main::AUTHOR => { label=>gettext("Author")}, |
|---|
| 324 | $main::PHOTO_PROPERTIES_AUTHOR => { |
|---|
| 325 | value => sub { |
|---|
| 326 | $self->multi_selection_mode ? |
|---|
| 327 | $self->imagelist->SetImageSelectionAuthor(@_): |
|---|
| 328 | $self->imagelist->current_image->site_author(@_) |
|---|
| 329 | }, |
|---|
| 330 | frame_callback => sub { $self->imageviewer_item_refresh(1); }, |
|---|
| 331 | }, |
|---|
| 332 | $main::TAGS => { label=>gettext("Tags")}, |
|---|
| 333 | $main::CREATE_DATE => { label=>gettext("Create date")}, |
|---|
| 334 | $main::PHOTO_PROPERTIES_CREATE_DATE => { |
|---|
| 335 | value => sub { |
|---|
| 336 | $self->multi_selection_mode ? |
|---|
| 337 | $self->imagelist->SetImageSelectionCreateDate(@_): |
|---|
| 338 | $self->imagelist->current_image->create_date(@_) |
|---|
| 339 | }, |
|---|
| 340 | frame_callback => sub { $self->imageviewer_item_refresh(1); }, |
|---|
| 341 | }, |
|---|
| 342 | $main::PRIVACY_LEVEL => { label=>gettext("Who can see?")}, |
|---|
| 343 | $main::PHOTO_PROPERTIES_PRIVACY_LEVEL => { |
|---|
| 344 | selection => sub { |
|---|
| 345 | $self->multi_selection_mode ? |
|---|
| 346 | $self->imagelist->SetImageSelectionPrivacyLevel(@_): |
|---|
| 347 | $self->imagelist->current_image->privacy_level(@_) |
|---|
| 348 | }, |
|---|
| 349 | choices => wxTheApp->privacy_level_choices, |
|---|
| 350 | }, |
|---|
| 351 | $main::PHOTO_PROPERTIES_NB => { |
|---|
| 352 | texts => [ |
|---|
| 353 | gettext("Properties"), |
|---|
| 354 | gettext("Tags") |
|---|
| 355 | ], |
|---|
| 356 | }, |
|---|
| 357 | $main::PHOTO_PROPERTIES_UPLOAD => { label=>gettext("Upload to Piwigo") }, |
|---|
| 358 | } |
|---|
| 359 | ); |
|---|
| 360 | |
|---|
| 361 | $self->global_settings( |
|---|
| 362 | { |
|---|
| 363 | $main::DEFAULT_PHOTO_CAPTION => { label => gettext("Default caption pattern") }, |
|---|
| 364 | $main::CPANE_RESIZE_ADVANCED => { label => gettext("Advanced") }, |
|---|
| 365 | $main::CPANE_HD_ADVANCED => { label => gettext("Advanced") }, |
|---|
| 366 | $main::CPANE_TRANSFERT_ADVANCED => { label => gettext("Advanced") }, |
|---|
| 367 | $main::GS_THUMBNAIL => { label => gettext("Thumbnail") }, |
|---|
| 368 | $main::GS_SITE_IMG => { label => gettext("Web sized") }, |
|---|
| 369 | $main::GS_HD => { label => gettext("High definition") }, |
|---|
| 370 | $main::GS_CLOSE => { label => gettext("Close")}, |
|---|
| 371 | $main::GS_DEFAULT_PHOTO_CAPTION => { |
|---|
| 372 | string_selection => sub { $self->imagelist->default_caption_pattern(@_) }, |
|---|
| 373 | choices => |
|---|
| 374 | [ |
|---|
| 375 | map { gettext $_ } @{wxTheApp->caption_patterns} |
|---|
| 376 | ], |
|---|
| 377 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_caption_patterns->{$value} }, |
|---|
| 378 | frame_callback => sub { |
|---|
| 379 | my( $self, $ctrl, $event ) = @_; |
|---|
| 380 | $self->OnDefaultPhotoCaption($event); |
|---|
| 381 | }, |
|---|
| 382 | }, |
|---|
| 383 | $main::PHOTO_CAPTION_PREFIX => { label => gettext("Default caption") }, |
|---|
| 384 | $main::GS_PHOTO_CAPTION_PREFIX => { |
|---|
| 385 | value => sub { $self->imagelist->default_caption(@_) }, |
|---|
| 386 | }, |
|---|
| 387 | $main::GS_AUTO_ROTATE => { |
|---|
| 388 | label => gettext("Auto rotate image"), |
|---|
| 389 | value => sub { $self->imagelist->auto_rotate(@_) } |
|---|
| 390 | }, |
|---|
| 391 | $main::DEFAULT_AUTHOR => { label => gettext("Default author")}, |
|---|
| 392 | $main::GS_DEFAULT_AUTHOR => { value => sub { $self->imagelist->author(@_) } }, |
|---|
| 393 | $main::THUMBNAIL_SIZE => { label => gettext("Site thumbnail size") }, |
|---|
| 394 | $main::GS_THUMBNAIL_SIZE => { |
|---|
| 395 | value => sub { $self->imagelist->thumb_size(@_) }, |
|---|
| 396 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 397 | }, |
|---|
| 398 | $main::THUMBNAIL_JPEG_QUALITY => { label => gettext("Site thumbnail jpeg quality") }, |
|---|
| 399 | $main::GS_THUMBNAIL_JPEG_QUALITY => { |
|---|
| 400 | value => sub { $self->imagelist->th_quality(@_) }, |
|---|
| 401 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 402 | }, |
|---|
| 403 | $main::GS_CREATE_RESIZED => { |
|---|
| 404 | selection => sub { $self->imagelist->create_resized(@_) }, |
|---|
| 405 | choices => |
|---|
| 406 | [ |
|---|
| 407 | map { gettext $_ } ( "Use original", "Use resized original" ) |
|---|
| 408 | ], |
|---|
| 409 | frame_callback => sub { |
|---|
| 410 | my( $dlg, $ctrl, $event ) = @_; |
|---|
| 411 | $dlg->OnCreateResized($event); |
|---|
| 412 | }, |
|---|
| 413 | }, |
|---|
| 414 | $main::SITE_IMG_WIDTH => { label => gettext("Maximum width") }, |
|---|
| 415 | $main::GS_SITE_IMG_WIDTH => { |
|---|
| 416 | value => sub { $self->imagelist->resize_w(@_) }, |
|---|
| 417 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 418 | }, |
|---|
| 419 | $main::SITE_IMG_HEIGHT => { label => gettext("Maximum height") }, |
|---|
| 420 | $main::GS_SITE_IMG_HEIGHT => { |
|---|
| 421 | value => sub { $self->imagelist->resize_h(@_) }, |
|---|
| 422 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 423 | }, |
|---|
| 424 | $main::SITE_IMG_JPEG_QUALITY => { label => gettext("Site image jpeg quality") }, |
|---|
| 425 | $main::GS_SITE_IMG_JPEG_QUALITY => { |
|---|
| 426 | value => sub { $self->imagelist->quality(@_) }, |
|---|
| 427 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 428 | }, |
|---|
| 429 | $main::SITE_IMG_FILTER => { label => gettext("Site image filter") }, |
|---|
| 430 | $main::GS_SITE_IMG_FILTER => { |
|---|
| 431 | string_selection => sub { $self->imagelist->filter(@_) }, |
|---|
| 432 | choices => |
|---|
| 433 | [ |
|---|
| 434 | qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ |
|---|
| 435 | ], |
|---|
| 436 | }, |
|---|
| 437 | $main::SITE_IMG_BLUR => { label => gettext("Site image blur") }, |
|---|
| 438 | $main::GS_SITE_IMG_BLUR => { |
|---|
| 439 | value => sub { $self->imagelist->blur(@_) }, |
|---|
| 440 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 441 | }, |
|---|
| 442 | $main::SITE_IMG_INTERLACE => { label => gettext("Site image interlace") }, |
|---|
| 443 | $main::GS_SITE_IMG_INTERLACE => { |
|---|
| 444 | string_selection => sub { $self->imagelist->interlace(@_) }, |
|---|
| 445 | choices => |
|---|
| 446 | [ |
|---|
| 447 | qw/None Line Plane Partition JPEG GIF PNG/ |
|---|
| 448 | ], |
|---|
| 449 | }, |
|---|
| 450 | $main::GS_REMOVE_UPLOADED_FROM_SELECTION => { |
|---|
| 451 | label => gettext("Remove uploaded photo from selection"), |
|---|
| 452 | value => sub { $self->imagelist->remove_uploaded_from_selection(@_) }, |
|---|
| 453 | }, |
|---|
| 454 | $main::GS_HD_UPLOAD => { |
|---|
| 455 | choices => |
|---|
| 456 | [ |
|---|
| 457 | map { gettext $_ } @{wxTheApp->upload_hd} |
|---|
| 458 | ], |
|---|
| 459 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_upload_hd->{$value} }, |
|---|
| 460 | string_selection => sub { $self->imagelist->upload_hd(@_) }, |
|---|
| 461 | frame_callback => sub { |
|---|
| 462 | my( $self, $ctrl, $event ) = @_; |
|---|
| 463 | $self->OnHDUpload($event); |
|---|
| 464 | }, |
|---|
| 465 | }, |
|---|
| 466 | $main::HD_IMG_WIDTH => { label => gettext("Maximum width") }, |
|---|
| 467 | $main::GS_HD_IMG_WIDTH => { |
|---|
| 468 | label => gettext("HD image width"), |
|---|
| 469 | value => sub { $self->imagelist->hd_w(@_) }, |
|---|
| 470 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 471 | }, |
|---|
| 472 | $main::HD_IMG_HEIGHT => { label => gettext("Maximum height") }, |
|---|
| 473 | $main::GS_HD_IMG_HEIGHT => { |
|---|
| 474 | label => gettext("HD image height"), |
|---|
| 475 | value => sub { $self->imagelist->hd_h(@_) }, |
|---|
| 476 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 477 | }, |
|---|
| 478 | $main::HD_IMG_JPEG_QUALITY => { label => gettext("HD image jpeg quality") }, |
|---|
| 479 | $main::GS_HD_IMG_JPEG_QUALITY => { |
|---|
| 480 | value => sub { $self->imagelist->hd_quality(@_) }, |
|---|
| 481 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 482 | }, |
|---|
| 483 | $main::HD_IMG_FILTER => { label => gettext("HD image filter") }, |
|---|
| 484 | $main::GS_HD_IMG_FILTER => { |
|---|
| 485 | string_selection => sub { $self->imagelist->hd_filter(@_) }, |
|---|
| 486 | choices => |
|---|
| 487 | [ |
|---|
| 488 | qw/Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc/ |
|---|
| 489 | ], |
|---|
| 490 | }, |
|---|
| 491 | $main::HD_IMG_BLUR => { label => gettext("HD image blur") }, |
|---|
| 492 | $main::GS_HD_IMG_BLUR => { |
|---|
| 493 | value => sub { $self->imagelist->hd_blur(@_) }, |
|---|
| 494 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 495 | }, |
|---|
| 496 | $main::HD_IMG_INTERLACE => { label => gettext("HD image interlace") }, |
|---|
| 497 | $main::GS_HD_IMG_INTERLACE => { |
|---|
| 498 | string_selection => sub { $self->imagelist->hd_interlace(@_) }, |
|---|
| 499 | choices => |
|---|
| 500 | [ |
|---|
| 501 | qw/None Line Plane Partition JPEG GIF PNG/ |
|---|
| 502 | ], |
|---|
| 503 | }, |
|---|
| 504 | $main::GS_WMARK_ACTIVATE => { |
|---|
| 505 | label => gettext("Activate watermark"), |
|---|
| 506 | value => sub { $self->imagelist->watermark_activate(@_) }, |
|---|
| 507 | frame_callback => sub { |
|---|
| 508 | my( $self, $ctrl, $event ) = @_; |
|---|
| 509 | $self->OnWatermark($event); |
|---|
| 510 | }, |
|---|
| 511 | }, |
|---|
| 512 | $main::GS_WMARK_ACTIVATE_HD => { |
|---|
| 513 | label => gettext("Activate watermark on high definition"), |
|---|
| 514 | value => sub { $self->imagelist->watermark_activate_pwg_high(@_) }, |
|---|
| 515 | frame_callback => sub { |
|---|
| 516 | my( $self, $ctrl, $event ) = @_; |
|---|
| 517 | $self->OnWatermark($event); |
|---|
| 518 | }, |
|---|
| 519 | }, |
|---|
| 520 | $main::WMARK_TEXT => { label => gettext("Text") }, |
|---|
| 521 | $main::GS_WMARK_TEXT => { |
|---|
| 522 | value => sub { $self->imagelist->watermark_text(@_) }, |
|---|
| 523 | }, |
|---|
| 524 | $main::WMARK_TEXT_SIZE => { label => gettext("Text size") }, |
|---|
| 525 | $main::GS_WMARK_TEXT_SIZE => { |
|---|
| 526 | value => sub { $self->imagelist->watermark_text_size(@_) }, |
|---|
| 527 | }, |
|---|
| 528 | $main::WMARK_COLOR => { label => gettext("Color") }, |
|---|
| 529 | $main::GS_WMARK_COLOR => { |
|---|
| 530 | string_selection => sub { $self->imagelist->watermark_color(@_) }, |
|---|
| 531 | choices => [ |
|---|
| 532 | map { gettext $_ } @{wxTheApp->colors} |
|---|
| 533 | ], |
|---|
| 534 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_colors->{$value} }, |
|---|
| 535 | }, |
|---|
| 536 | $main::WMARK_POSITION => { label => gettext("Position") }, |
|---|
| 537 | $main::GS_WMARK_POSITION => { |
|---|
| 538 | string_selection => sub { $self->imagelist->watermark_position(@_) }, |
|---|
| 539 | choices => [ |
|---|
| 540 | map { gettext $_ } @{wxTheApp->positions} |
|---|
| 541 | ], |
|---|
| 542 | pre_process => sub { my ( $value ) = @_; wxTheApp->eng_positions->{$value} }, |
|---|
| 543 | }, |
|---|
| 544 | $main::WMARK_MARGIN_TOP => { label => gettext("Top margin") }, |
|---|
| 545 | $main::GS_WMARK_MARGIN_TOP => { |
|---|
| 546 | value => sub { $self->imagelist->watermark_y(@_) }, |
|---|
| 547 | }, |
|---|
| 548 | $main::WMARK_MARGIN_LEFT => { label => gettext("Left margin") }, |
|---|
| 549 | $main::GS_WMARK_MARGIN_LEFT => { |
|---|
| 550 | value => sub { $self->imagelist->watermark_x(@_) }, |
|---|
| 551 | }, |
|---|
| 552 | $main::CHUNK_SIZE => { label => gettext("Transfert chunk size") }, |
|---|
| 553 | $main::GS_CHUNK_SIZE => { |
|---|
| 554 | value => sub { wxTheApp->chunk_size(@_) }, |
|---|
| 555 | validator => Wx::Perl::TextValidator->new( '\d' ) |
|---|
| 556 | }, |
|---|
| 557 | $main::LANGUAGE => { label => gettext("Choose a language") }, |
|---|
| 558 | $main::GS_LANGUAGE => { |
|---|
| 559 | selection => sub { wxTheApp->current_language(@_) }, |
|---|
| 560 | choices => [ map { sprintf($_->[0], gettext($_->[2])) } @{wxTheApp->available_languages} ], |
|---|
| 561 | pre_process => sub { my ( $value ) = @_; wxTheApp->available_languages->[$value][1] }, |
|---|
| 562 | frame_callback => sub { my ( $self, $ctrl, $event ) = @_; |
|---|
| 563 | Wx::LogMessage( |
|---|
| 564 | sprintf( |
|---|
| 565 | "%s : %s", |
|---|
| 566 | gettext("pLoader needs to be restarted to display the new selected language"), |
|---|
| 567 | gettext(wxTheApp->available_languages->[$event->GetSelection][2]) |
|---|
| 568 | ) |
|---|
| 569 | ); |
|---|
| 570 | wxTheApp->layout_clean(1); |
|---|
| 571 | }, |
|---|
| 572 | }, |
|---|
| 573 | } |
|---|
| 574 | ); |
|---|
| 575 | |
|---|
| 576 | $self->piwigo_property_list( |
|---|
| 577 | [ |
|---|
| 578 | { |
|---|
| 579 | label => gettext("Photo caption"), |
|---|
| 580 | }, |
|---|
| 581 | { |
|---|
| 582 | label => gettext("Comment"), |
|---|
| 583 | }, |
|---|
| 584 | { |
|---|
| 585 | label => gettext("Author"), |
|---|
| 586 | }, |
|---|
| 587 | { |
|---|
| 588 | label => gettext("File name"), |
|---|
| 589 | }, |
|---|
| 590 | { |
|---|
| 591 | label => gettext("Create date"), |
|---|
| 592 | }, |
|---|
| 593 | ] |
|---|
| 594 | ); |
|---|
| 595 | |
|---|
| 596 | $self->exif_properties( |
|---|
| 597 | [ |
|---|
| 598 | { |
|---|
| 599 | label => gettext("Create date"), |
|---|
| 600 | value => sub { $self->imagelist->current_image->create_date }, |
|---|
| 601 | readonly => 1, |
|---|
| 602 | }, |
|---|
| 603 | { |
|---|
| 604 | label => gettext("Model"), |
|---|
| 605 | value => sub { $self->imagelist->current_image->exif_tag('Model') }, |
|---|
| 606 | readonly => 1, |
|---|
| 607 | }, |
|---|
| 608 | { |
|---|
| 609 | label => gettext("Width"), |
|---|
| 610 | value => sub { $self->imagelist->current_image->exif_tag('ImageWidth') }, |
|---|
| 611 | readonly => 1, |
|---|
| 612 | }, |
|---|
| 613 | { |
|---|
| 614 | label => gettext("Height"), |
|---|
| 615 | value => sub { $self->imagelist->current_image->exif_tag('ImageHeight') }, |
|---|
| 616 | readonly => 1, |
|---|
| 617 | }, |
|---|
| 618 | { |
|---|
| 619 | label => gettext("Orientation"), |
|---|
| 620 | value => sub { $self->imagelist->current_image->exif_tag('Orientation') }, |
|---|
| 621 | readonly => 1, |
|---|
| 622 | }, |
|---|
| 623 | { |
|---|
| 624 | label => "ISO", |
|---|
| 625 | value => sub { $self->imagelist->current_image->exif_tag('ISO') }, |
|---|
| 626 | readonly => 1, |
|---|
| 627 | }, |
|---|
| 628 | { |
|---|
| 629 | label => gettext("Shutter speed"), |
|---|
| 630 | value => sub { $self->imagelist->current_image->exif_tag('ExposureTime') }, |
|---|
| 631 | readonly => 1, |
|---|
| 632 | }, |
|---|
| 633 | { |
|---|
| 634 | label => gettext("Aperture"), |
|---|
| 635 | value => sub { $self->imagelist->current_image->exif_tag('ApertureValue') }, |
|---|
| 636 | readonly => 1, |
|---|
| 637 | }, |
|---|
| 638 | { |
|---|
| 639 | label => gettext("Focal length"), |
|---|
| 640 | value => sub { $self->imagelist->current_image->exif_tag('FocalLength') }, |
|---|
| 641 | readonly => 1, |
|---|
| 642 | }, |
|---|
| 643 | { |
|---|
| 644 | label => gettext("Lens"), |
|---|
| 645 | value => sub { $self->imagelist->current_image->exif_tag('Lens') }, |
|---|
| 646 | readonly => 1, |
|---|
| 647 | }, |
|---|
| 648 | ] |
|---|
| 649 | ); |
|---|
| 650 | |
|---|
| 651 | $self->image_tags( |
|---|
| 652 | sub { scalar @{$self->imagelist->image_selection} > 1 ? $self->imagelist->SetImageSelectionTags(@_) : $self->imagelist->current_image->site_tags(@_)||[] } |
|---|
| 653 | ); |
|---|
| 654 | |
|---|
| 655 | $self->piwigo_tags( |
|---|
| 656 | sub { wxTheApp->pwg->tags } |
|---|
| 657 | ); |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | sub init_image_types { |
|---|
| 661 | my ( $self ) = @_; |
|---|
| 662 | |
|---|
| 663 | $self->{IMGTYPE} = { |
|---|
| 664 | 'jpg' => wxBITMAP_TYPE_JPEG, |
|---|
| 665 | 'gif' => wxBITMAP_TYPE_GIF, |
|---|
| 666 | 'png' => wxBITMAP_TYPE_PNG, |
|---|
| 667 | }; |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | sub init_frame { |
|---|
| 672 | my ( $self ) = @_; |
|---|
| 673 | |
|---|
| 674 | $self->create_toolbar; |
|---|
| 675 | |
|---|
| 676 | my $sizer_h = Wx::BoxSizer->new( wxHORIZONTAL ); |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | $self->imageviewer( |
|---|
| 681 | Uploader::GUI::wxImageListCtrl->new( |
|---|
| 682 | { |
|---|
| 683 | parentwnd => $self, |
|---|
| 684 | imagelist => $self->imagelist, |
|---|
| 685 | image_size => $self->imagelist->wx_thumb_size, |
|---|
| 686 | columns => $self->piwigo_property_list, |
|---|
| 687 | } |
|---|
| 688 | ) |
|---|
| 689 | ); |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | $self->piwigo_photo_properties_dlg ( |
|---|
| 693 | Uploader::GUI::wxPhotoProperties->new( |
|---|
| 694 | { |
|---|
| 695 | parentwnd => $self, |
|---|
| 696 | categories => [ @{$self->pwg->categories}], |
|---|
| 697 | properties => $self->piwigo_photo_properties, |
|---|
| 698 | tags => |
|---|
| 699 | { |
|---|
| 700 | id => $main::PHOTO_PROPERTIES_TAG, |
|---|
| 701 | choices => $self->piwigo_tags, |
|---|
| 702 | selection => $self->image_tags, |
|---|
| 703 | creation_callback => sub { $self->_create_piwigo_tag(@_) }, |
|---|
| 704 | }, |
|---|
| 705 | } |
|---|
| 706 | ) |
|---|
| 707 | ); |
|---|
| 708 | |
|---|
| 709 | $self->piwigo_photo_properties_tags( |
|---|
| 710 | $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_TAG) |
|---|
| 711 | ); |
|---|
| 712 | |
|---|
| 713 | $self->tree( |
|---|
| 714 | $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_CATEGORIES) |
|---|
| 715 | ); |
|---|
| 716 | |
|---|
| 717 | $self->init_dnd_targets; |
|---|
| 718 | $self->init_dialogs; |
|---|
| 719 | $self->show_hide_pwg_categories_empty_msg; |
|---|
| 720 | |
|---|
| 721 | if( $self->imagelist->wx_thumb_imglist->GetImageCount){ |
|---|
| 722 | $self->ShowImageViewer; |
|---|
| 723 | |
|---|
| 724 | $self->imageviewer->Refresh( |
|---|
| 725 | $self->imagelist->wx_thumb_imglist |
|---|
| 726 | ); |
|---|
| 727 | |
|---|
| 728 | $self->OnUpdateImageviewerNotEmpty; |
|---|
| 729 | } |
|---|
| 730 | else{ |
|---|
| 731 | $self->OnUpdateImageviewerEmpty; |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | # the imageviewer has a stretch factor of 1 : expands its size on frame resize |
|---|
| 735 | $sizer_h->Add( $self->imageviewer, 1, wxEXPAND|wxALL, 2 ); |
|---|
| 736 | $sizer_h->Add( $self->piwigo_photo_properties_dlg, 0, wxEXPAND|wxALL, 2 ); |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | $self->SetSizer( |
|---|
| 740 | $sizer_h |
|---|
| 741 | ); |
|---|
| 742 | my $new_size = $sizer_h->Fit( |
|---|
| 743 | $self |
|---|
| 744 | ); |
|---|
| 745 | $self->SetMinSize([600, 660]); |
|---|
| 746 | $self->Center; |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | sub _create_piwigo_tag { |
|---|
| 751 | my ( $self, $name ) = @_; |
|---|
| 752 | |
|---|
| 753 | if( |
|---|
| 754 | Wx::MessageBox( |
|---|
| 755 | sprintf( |
|---|
| 756 | "%s \"%s\" ?", |
|---|
| 757 | gettext("Do you want to create"), |
|---|
| 758 | $name, |
|---|
| 759 | ), |
|---|
| 760 | gettext("Piwigo search information"), |
|---|
| 761 | wxYES_NO | wxICON_QUESTION, |
|---|
| 762 | ) == wxYES |
|---|
| 763 | ){ |
|---|
| 764 | $self->pwg->AddTags($name); |
|---|
| 765 | $self->pwg->RefreshTags; |
|---|
| 766 | } |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | sub OnUpdateImageviewerEmpty { |
|---|
| 771 | my ( $self ) = @_; |
|---|
| 772 | |
|---|
| 773 | $self->piwigo_photo_properties_dlg->SetDisabled; |
|---|
| 774 | $self->imageviewer->OnEmpty; |
|---|
| 775 | } |
|---|
| 776 | |
|---|
| 777 | sub OnUpdateImageviewerNotEmpty { |
|---|
| 778 | my ( $self ) = @_; |
|---|
| 779 | |
|---|
| 780 | $self->piwigo_photo_properties_dlg->SetEnabled; |
|---|
| 781 | $self->imageviewer->OnNotEmpty; |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | sub init_dialogs { |
|---|
| 786 | my ( $self ) = @_; |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | $self->exif_dlg( |
|---|
| 790 | Uploader::GUI::wxPropertyListDlg->new( |
|---|
| 791 | { |
|---|
| 792 | parentwnd => $self, |
|---|
| 793 | properties => $self->exif_properties, |
|---|
| 794 | caption => sprintf("%s - EXIF", gettext("Properties")), |
|---|
| 795 | } |
|---|
| 796 | ) |
|---|
| 797 | ); |
|---|
| 798 | $self->exif_dlg->Hide; |
|---|
| 799 | |
|---|
| 800 | $self->global_settings_dlg( |
|---|
| 801 | Uploader::GUI::wxGlobalSettings->new( |
|---|
| 802 | { |
|---|
| 803 | parentwnd => $self, |
|---|
| 804 | caption => gettext("Global settings"), |
|---|
| 805 | properties => $self->global_settings, |
|---|
| 806 | } |
|---|
| 807 | ) |
|---|
| 808 | ); |
|---|
| 809 | $self->global_settings_dlg->Hide; |
|---|
| 810 | |
|---|
| 811 | $self->image_preview_dlg( |
|---|
| 812 | Uploader::GUI::wxImagePreview->new( |
|---|
| 813 | { |
|---|
| 814 | parentwnd => $self, |
|---|
| 815 | caption => gettext("Preview"), |
|---|
| 816 | } |
|---|
| 817 | ) |
|---|
| 818 | ); |
|---|
| 819 | |
|---|
| 820 | $self->destination_category_dlg( |
|---|
| 821 | Uploader::GUI::wxDestinationCategoryDlg->new( |
|---|
| 822 | { |
|---|
| 823 | parentwnd => $self, |
|---|
| 824 | caption => gettext("Upload to Piwigo"), |
|---|
| 825 | categories => [@{$self->pwg->categories}], |
|---|
| 826 | properties => { |
|---|
| 827 | $main::CHOOSE_DESTINATION => { label => wxTheApp->branding->{'What is the destination category?'} }, |
|---|
| 828 | $main::DESTINATION_CATEGORIES_OK => { label=>gettext("Upload to Piwigo")}, |
|---|
| 829 | $main::DESTINATION_CATEGORIES_CANCEL => { label=>gettext("Cancel")}, |
|---|
| 830 | $main::DESTINATION_CATEGORIES => { |
|---|
| 831 | id_selection => sub { $self->imagelist->categories(@_) }, |
|---|
| 832 | frame_callback => sub { |
|---|
| 833 | my ( $dlg, $ctrl, $evt ) = @_; |
|---|
| 834 | $dlg->FindWindow($main::DESTINATION_CATEGORIES_OK)->Enable(scalar @{$self->imagelist->categories}); |
|---|
| 835 | }, |
|---|
| 836 | }, |
|---|
| 837 | }, |
|---|
| 838 | frame_callback => sub { $self->OnRefreshCategories }, |
|---|
| 839 | } |
|---|
| 840 | ) |
|---|
| 841 | ); |
|---|
| 842 | |
|---|
| 843 | $self->destination_category_dlg->Hide; |
|---|
| 844 | |
|---|
| 845 | $self->destination_categories( |
|---|
| 846 | $self->destination_category_dlg->FindWindow($main::DESTINATION_CATEGORIES) |
|---|
| 847 | ); |
|---|
| 848 | |
|---|
| 849 | $self->categories_treectrl( |
|---|
| 850 | [ |
|---|
| 851 | $self->destination_categories, |
|---|
| 852 | $self->tree, |
|---|
| 853 | ] |
|---|
| 854 | ); |
|---|
| 855 | |
|---|
| 856 | } |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | sub init_dnd_targets { |
|---|
| 860 | my ( $self ) = @_; |
|---|
| 861 | |
|---|
| 862 | $self->imageviewer->SetDropTarget( |
|---|
| 863 | DNDImageListDropTarget->new( |
|---|
| 864 | $self->imageviewer |
|---|
| 865 | ) |
|---|
| 866 | ); |
|---|
| 867 | |
|---|
| 868 | $self->tree->SetDropTarget( |
|---|
| 869 | DNDCategoryTreeDropTarget->new( |
|---|
| 870 | $self->tree |
|---|
| 871 | ) |
|---|
| 872 | ); |
|---|
| 873 | |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | sub OnPhotoProperties { |
|---|
| 878 | my ( $self ) = @_; |
|---|
| 879 | |
|---|
| 880 | $self->exif_dlg->Show(1); |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | sub OnPreview { |
|---|
| 885 | my ( $self ) = @_; |
|---|
| 886 | |
|---|
| 887 | $self->image_preview_dlg->Show(1); |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | sub OnGlobalSettings { |
|---|
| 892 | my ( $self ) = @_; |
|---|
| 893 | |
|---|
| 894 | $self->global_settings_dlg->Show(1); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | sub OnGeneralSettingsClose { |
|---|
| 899 | my ( $self, $event ) = @_; |
|---|
| 900 | |
|---|
| 901 | $self->global_settings_dlg->Hide; |
|---|
| 902 | } |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | sub OnImageExifPropClose { |
|---|
| 906 | my ( $self, $event ) = @_; |
|---|
| 907 | |
|---|
| 908 | $self->image_exif_prop->Hide; |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | sub show_hide_pwg_categories_empty_msg { |
|---|
| 915 | my ( $self ) = @_; |
|---|
| 916 | |
|---|
| 917 | map { |
|---|
| 918 | $_->GetCount > 1 ? |
|---|
| 919 | $_->HideEmptyMsg : |
|---|
| 920 | $_->ShowEmptyMsg; |
|---|
| 921 | }@{$self->categories_treectrl}; |
|---|
| 922 | |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | sub init_menus { |
|---|
| 927 | my ( $self ) = @_ ; |
|---|
| 928 | |
|---|
| 929 | $self->_tree_mnu; |
|---|
| 930 | $self->_imageviewer_mnu; |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | sub _tree_mnu { |
|---|
| 935 | my ( $self ) = @_; |
|---|
| 936 | |
|---|
| 937 | my $ctx_mnu = Wx::Menu->new; |
|---|
| 938 | |
|---|
| 939 | map { |
|---|
| 940 | $ctx_mnu->Append( |
|---|
| 941 | @$_[0..2], wxITEM_NORMAL |
|---|
| 942 | ); |
|---|
| 943 | } |
|---|
| 944 | ( |
|---|
| 945 | # workaround : first item does not show bitmap |
|---|
| 946 | [ |
|---|
| 947 | 0, |
|---|
| 948 | "", |
|---|
| 949 | "", |
|---|
| 950 | wxTheApp->resource_path('mnu_folder_new.png'), |
|---|
| 951 | ], |
|---|
| 952 | [ |
|---|
| 953 | 1+$ID_TREE_CTX_MENU, |
|---|
| 954 | wxTheApp->branding->{'Add new category'}, |
|---|
| 955 | sprintf( |
|---|
| 956 | "%s %s %s %s", |
|---|
| 957 | gettext("Add a new"), |
|---|
| 958 | wxTheApp->branding->{category}, |
|---|
| 959 | gettext("to the currently selected"), |
|---|
| 960 | wxTheApp->branding->{category}, |
|---|
| 961 | ), |
|---|
| 962 | wxTheApp->resource_path('mnu_folder_new.png'), |
|---|
| 963 | ], |
|---|
| 964 | [ |
|---|
| 965 | 2+$ID_TREE_CTX_MENU, |
|---|
| 966 | gettext("Refresh"), |
|---|
| 967 | sprintf( |
|---|
| 968 | "Refresh %s list.", |
|---|
| 969 | wxTheApp->branding->{category}, |
|---|
| 970 | ), |
|---|
| 971 | wxTheApp->resource_path('mnu_refresh.png'), |
|---|
| 972 | ], |
|---|
| 973 | [ |
|---|
| 974 | 3+$ID_TREE_CTX_MENU, |
|---|
| 975 | gettext("Expand all"), |
|---|
| 976 | sprintf( |
|---|
| 977 | "Expand %s list.", |
|---|
| 978 | wxTheApp->branding->{category}, |
|---|
| 979 | ), |
|---|
| 980 | wxTheApp->resource_path('mnu_expandall.png'), |
|---|
| 981 | ], |
|---|
| 982 | [ |
|---|
| 983 | 4+$ID_TREE_CTX_MENU, |
|---|
| 984 | gettext("Collapse all"), |
|---|
| 985 | sprintf( |
|---|
| 986 | "Collapse %s list.", |
|---|
| 987 | wxTheApp->branding->{category}, |
|---|
| 988 | ), |
|---|
| 989 | wxTheApp->resource_path('mnu_collapseall.png'), |
|---|
| 990 | ], |
|---|
| 991 | ); |
|---|
| 992 | |
|---|
| 993 | $ctx_mnu->Delete(0); |
|---|
| 994 | $self->tree_mnu( |
|---|
| 995 | $ctx_mnu |
|---|
| 996 | ); |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | sub _imageviewer_mnu { |
|---|
| 1000 | my ( $self ) = @_; |
|---|
| 1001 | |
|---|
| 1002 | my $ctx_mnu = Wx::Menu->new; |
|---|
| 1003 | |
|---|
| 1004 | map { |
|---|
| 1005 | $ctx_mnu->Append( |
|---|
| 1006 | @$_[0..2] |
|---|
| 1007 | ); |
|---|
| 1008 | } |
|---|
| 1009 | ( |
|---|
| 1010 | # workaround : first item does not show bitmap |
|---|
| 1011 | [ |
|---|
| 1012 | 0, |
|---|
| 1013 | "", |
|---|
| 1014 | "", |
|---|
| 1015 | wxTheApp->resource_path('mnu_properties.png'), |
|---|
| 1016 | ], |
|---|
| 1017 | [ |
|---|
| 1018 | 1+$ID_IMAGEVIEWER_CTX_MENU, |
|---|
| 1019 | gettext("Properties"), |
|---|
| 1020 | gettext("Modify photo properties"), |
|---|
| 1021 | wxTheApp->resource_path('mnu_properties.png'), |
|---|
| 1022 | ], |
|---|
| 1023 | [ |
|---|
| 1024 | 2+$ID_IMAGEVIEWER_CTX_MENU, |
|---|
| 1025 | gettext("Preview"), |
|---|
| 1026 | gettext("Display photo preview"), |
|---|
| 1027 | wxTheApp->resource_path('mnu_preview.png'), |
|---|
| 1028 | ], |
|---|
| 1029 | ); |
|---|
| 1030 | |
|---|
| 1031 | $ctx_mnu->Delete(0); |
|---|
| 1032 | $self->imageviewer_mnu( |
|---|
| 1033 | $ctx_mnu |
|---|
| 1034 | ); |
|---|
| 1035 | } |
|---|
| 1036 | |
|---|
| 1037 | sub init_event_handlers { |
|---|
| 1038 | my ( $self ) = @_ ; |
|---|
| 1039 | |
|---|
| 1040 | Wx::Event::EVT_MENU( $self, 101, \&OnAddImages ); |
|---|
| 1041 | Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages ); |
|---|
| 1042 | Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages ); |
|---|
| 1043 | Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings ); |
|---|
| 1044 | Wx::Event::EVT_CHOICE( $self, 106, \&OnPhotoSelMode ); |
|---|
| 1045 | Wx::Event::EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged ); |
|---|
| 1046 | Wx::Event::EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick ); |
|---|
| 1047 | Wx::Event::EVT_TREE_END_LABEL_EDIT( $self, $self->tree, \&OnTreeEndLabelEdit ); |
|---|
| 1048 | |
|---|
| 1049 | Wx::Event::EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit ); |
|---|
| 1050 | Wx::Event::EVT_LIST_ITEM_ACTIVATED( $self, $self->imageviewer, \&OnImageViewerItemActivated ); |
|---|
| 1051 | Wx::Event::EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ; |
|---|
| 1052 | Wx::Event::EVT_LIST_ITEM_DESELECTED($self, $self->imageviewer, \&OnImageViewerItemDeSelected) ; |
|---|
| 1053 | Wx::Event::EVT_LIST_ITEM_RIGHT_CLICK($self, $self->imageviewer, \&OnImageViewerItemRightClick) ; |
|---|
| 1054 | |
|---|
| 1055 | Wx::Event::EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ; |
|---|
| 1056 | |
|---|
| 1057 | Wx::Event::EVT_CLOSE( $self, \&OnClose ); |
|---|
| 1058 | |
|---|
| 1059 | Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategory ); |
|---|
| 1060 | Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories ); |
|---|
| 1061 | Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories ); |
|---|
| 1062 | Wx::Event::EVT_MENU( $self, 4+$ID_TREE_CTX_MENU, \&OnCollapseCategories ); |
|---|
| 1063 | |
|---|
| 1064 | Wx::Event::EVT_MENU( $self, 1+$ID_IMAGEVIEWER_CTX_MENU, \&OnPhotoProperties ); |
|---|
| 1065 | Wx::Event::EVT_MENU( $self, 2+$ID_IMAGEVIEWER_CTX_MENU, \&OnPreview ); |
|---|
| 1066 | |
|---|
| 1067 | Wx::Event::EVT_BUTTON( $self, $main::PHOTO_PROPERTIES_UPLOAD, \&OnUploadImages ); |
|---|
| 1068 | Wx::Event::EVT_BUTTON( $self, $self->imageviewer->add_button->GetId, \&OnAddImages ); |
|---|
| 1069 | Wx::Event::EVT_KEY_DOWN($self, \&OnKeyDown ); |
|---|
| 1070 | |
|---|
| 1071 | # only refresh when calling event is finished |
|---|
| 1072 | Wx::Event::EVT_IDLE( |
|---|
| 1073 | $self, |
|---|
| 1074 | sub { |
|---|
| 1075 | my ( $self, $event ) = @_; |
|---|
| 1076 | |
|---|
| 1077 | if ( $self->image_preview_need_refresh and $self->image_preview_dlg->IsShown ){ |
|---|
| 1078 | $self->set_preview_image; |
|---|
| 1079 | $self->image_preview_dlg->Refresh; |
|---|
| 1080 | $self->image_preview_need_refresh(0); |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|
| 1083 | if($self->imageviewer_refresh){ |
|---|
| 1084 | $self->imageviewer->Refresh; |
|---|
| 1085 | $self->imageviewer_refresh(0); |
|---|
| 1086 | } |
|---|
| 1087 | |
|---|
| 1088 | if($self->imageviewer_item_refresh){ |
|---|
| 1089 | # for batch mode |
|---|
| 1090 | map { |
|---|
| 1091 | $self->imageviewer->ItemRefresh( |
|---|
| 1092 | $_ |
|---|
| 1093 | ) |
|---|
| 1094 | } @{$self->imageviewer->GetSelectedItems}; |
|---|
| 1095 | $self->imageviewer_item_refresh(0); |
|---|
| 1096 | } |
|---|
| 1097 | |
|---|
| 1098 | if(!$self->selected_images_count and $self->piwigo_photo_properties_dlg->IsEnabled){ |
|---|
| 1099 | $self->piwigo_photo_properties_dlg->SetDisabled; |
|---|
| 1100 | } |
|---|
| 1101 | |
|---|
| 1102 | $self->OnUpdateToolbar; |
|---|
| 1103 | $event->Skip; |
|---|
| 1104 | } |
|---|
| 1105 | ); |
|---|
| 1106 | |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | |
|---|
| 1110 | sub selected_images_count { |
|---|
| 1111 | my ( $self ) = @_; |
|---|
| 1112 | |
|---|
| 1113 | scalar @{$self->imageviewer->GetSelectedItems}; |
|---|
| 1114 | } |
|---|
| 1115 | |
|---|
| 1116 | { |
|---|
| 1117 | my $prevdir; |
|---|
| 1118 | my $prevfile; |
|---|
| 1119 | |
|---|
| 1120 | sub OnAddImages { |
|---|
| 1121 | my( $self, $event ) = @_; |
|---|
| 1122 | my $dialog = Wx::FileDialog->new |
|---|
| 1123 | ( $self, gettext("Select photos for upload"), $prevfile, $prevdir, |
|---|
| 1124 | sprintf("%s (*.JPG;*.jpg)|*.JPG;*.jpg|%s (*.*)|*.*", gettext("JPEG files"), gettext("All")), |
|---|
| 1125 | wxFD_OPEN|wxFD_MULTIPLE ); |
|---|
| 1126 | |
|---|
| 1127 | my $file_paths = []; |
|---|
| 1128 | if( $dialog->ShowModal != wxID_CANCEL ) { |
|---|
| 1129 | @$file_paths = $dialog->GetPaths; |
|---|
| 1130 | $self->SetNewFiles($file_paths) ; |
|---|
| 1131 | } |
|---|
| 1132 | $dialog->Destroy; |
|---|
| 1133 | } |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | |
|---|
| 1137 | sub OnUpdateToolbar { |
|---|
| 1138 | my( $self ) = @_; |
|---|
| 1139 | |
|---|
| 1140 | if($self->global_settings_dlg->IsShown){ |
|---|
| 1141 | $self->toolbar->EnableTool(104, 0); |
|---|
| 1142 | } |
|---|
| 1143 | else{ |
|---|
| 1144 | $self->toolbar->EnableTool(104, 1); |
|---|
| 1145 | } |
|---|
| 1146 | |
|---|
| 1147 | if($self->global_settings_dlg->IsShown){ |
|---|
| 1148 | $self->toolbar->EnableTool(104, 0); |
|---|
| 1149 | } |
|---|
| 1150 | else{ |
|---|
| 1151 | $self->toolbar->EnableTool(104, 1); |
|---|
| 1152 | } |
|---|
| 1153 | |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | |
|---|
| 1157 | sub OnRemoveImages { |
|---|
| 1158 | my( $self, $event ) = @_; |
|---|
| 1159 | |
|---|
| 1160 | |
|---|
| 1161 | $self->imagelist->RemoveImageSelection; |
|---|
| 1162 | $self->imageviewer->Refresh; |
|---|
| 1163 | |
|---|
| 1164 | if (!$self->imageviewer->GetItemCount){ |
|---|
| 1165 | $self->image_preview_dlg->image( |
|---|
| 1166 | 0 |
|---|
| 1167 | ); |
|---|
| 1168 | # have to reset |
|---|
| 1169 | $self->piwigo_photo_properties_dlg->ClearProperties; |
|---|
| 1170 | $self->piwigo_photo_properties_tags->ClearAllSelection; |
|---|
| 1171 | $self->imagelist->SetCurrentImage(-1); |
|---|
| 1172 | $self->OnUpdateImageviewerEmpty; |
|---|
| 1173 | } |
|---|
| 1174 | else{ |
|---|
| 1175 | $self->OnUpdateImageviewerNotEmpty; |
|---|
| 1176 | } |
|---|
| 1177 | |
|---|
| 1178 | if(!$self->multi_selection_mode){ |
|---|
| 1179 | $self->OnUpdateSingleSelectionModeUI; |
|---|
| 1180 | } |
|---|
| 1181 | |
|---|
| 1182 | $self->image_preview_dlg->Refresh; |
|---|
| 1183 | $self->exif_dlg->Refresh; |
|---|
| 1184 | } |
|---|
| 1185 | |
|---|
| 1186 | sub SetNewFiles { |
|---|
| 1187 | my ( $self, $file_paths ) = @_; |
|---|
| 1188 | |
|---|
| 1189 | $self->ShowImageViewer(); |
|---|
| 1190 | |
|---|
| 1191 | $self->progressdlg->Destroy if defined $self->progressdlg; |
|---|
| 1192 | $self->progressdlg( |
|---|
| 1193 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
|---|
| 1194 | { |
|---|
| 1195 | title => gettext("Image processing progress information"), |
|---|
| 1196 | bt_label => gettext("Cancel image processing"), |
|---|
| 1197 | bt_close_label => gettext("Close"), |
|---|
| 1198 | stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); }, |
|---|
| 1199 | } |
|---|
| 1200 | ) |
|---|
| 1201 | ); |
|---|
| 1202 | $self->progressdlg->Show(1); |
|---|
| 1203 | Wx::Yield(); |
|---|
| 1204 | |
|---|
| 1205 | |
|---|
| 1206 | my $files = [ |
|---|
| 1207 | map { |
|---|
| 1208 | # to make sure that unicode chars in filenames are supported |
|---|
| 1209 | { |
|---|
| 1210 | ANSIPathName => $^O =~ /MSWin32/ ? Win32::GetANSIPathName($_) : $_, |
|---|
| 1211 | PathName => $_, |
|---|
| 1212 | }, |
|---|
| 1213 | }@$file_paths |
|---|
| 1214 | ]; |
|---|
| 1215 | |
|---|
| 1216 | @$files = sort { $a->{PathName} cmp $b->{PathName} } @$files; |
|---|
| 1217 | |
|---|
| 1218 | $self->imagelist->SetNewFiles( |
|---|
| 1219 | $files |
|---|
| 1220 | ); |
|---|
| 1221 | |
|---|
| 1222 | |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | |
|---|
| 1226 | sub OnTreeSelChanged { |
|---|
| 1227 | my( $self, $event ) = @_; |
|---|
| 1228 | |
|---|
| 1229 | $self->imagelist->categories( |
|---|
| 1230 | $event->GetEventObject->GetSelectionsIds |
|---|
| 1231 | ); |
|---|
| 1232 | } |
|---|
| 1233 | |
|---|
| 1234 | sub OnTreeItemRightClick { |
|---|
| 1235 | my( $self, $event ) = @_; |
|---|
| 1236 | |
|---|
| 1237 | |
|---|
| 1238 | $self->PopupMenu($self->tree_mnu, wxDefaultPosition); |
|---|
| 1239 | |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | sub OnTreeEndLabelEdit { |
|---|
| 1243 | my( $self, $event ) = @_; |
|---|
| 1244 | |
|---|
| 1245 | my $label = $event->GetLabel; |
|---|
| 1246 | |
|---|
| 1247 | $label =~ s/^\s+$//; |
|---|
| 1248 | |
|---|
| 1249 | if(defined($label) and !( "" eq $label )){ |
|---|
| 1250 | $self->_SetLabel($event) |
|---|
| 1251 | } |
|---|
| 1252 | else{ |
|---|
| 1253 | $event->Veto; |
|---|
| 1254 | } |
|---|
| 1255 | } |
|---|
| 1256 | |
|---|
| 1257 | sub _SetLabel { |
|---|
| 1258 | my( $self, $event ) = @_; |
|---|
| 1259 | |
|---|
| 1260 | my $category = $self->tree->GetPlData($event->GetItem); |
|---|
| 1261 | my $category_id; |
|---|
| 1262 | |
|---|
| 1263 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
|---|
| 1264 | my $comment; |
|---|
| 1265 | my ( $success, $status_msg, $content ) = $self->pwg->SetInfoCategories( |
|---|
| 1266 | $event->GetLabel, |
|---|
| 1267 | $comment, |
|---|
| 1268 | $category_id |
|---|
| 1269 | ); |
|---|
| 1270 | |
|---|
| 1271 | my $ok = 1; |
|---|
| 1272 | |
|---|
| 1273 | if(!$success){ |
|---|
| 1274 | $ok = 0; |
|---|
| 1275 | } |
|---|
| 1276 | |
|---|
| 1277 | if('fail' eq $content->{stat}){ |
|---|
| 1278 | $ok = 0; |
|---|
| 1279 | } |
|---|
| 1280 | |
|---|
| 1281 | # method call failed |
|---|
| 1282 | if(!$ok){ |
|---|
| 1283 | $event->Veto; |
|---|
| 1284 | Wx::MessageBox( |
|---|
| 1285 | sprintf( |
|---|
| 1286 | "%s %s", |
|---|
| 1287 | gettext("Update failed : "), |
|---|
| 1288 | $status_msg |
|---|
| 1289 | ), |
|---|
| 1290 | gettext("Piwigo update error"), |
|---|
| 1291 | wxOK | wxICON_EXCLAMATION, |
|---|
| 1292 | ); |
|---|
| 1293 | Wx::LogMessage("%s\n\n%s", Dumper($content), gettext("This function is not available. A Piwigo upgrade may resolve this issue.")); |
|---|
| 1294 | } |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | sub OnImageViewerItemRightClick { |
|---|
| 1298 | my( $self, $event ) = @_; |
|---|
| 1299 | |
|---|
| 1300 | |
|---|
| 1301 | $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition); |
|---|
| 1302 | |
|---|
| 1303 | |
|---|
| 1304 | } |
|---|
| 1305 | |
|---|
| 1306 | sub OnExpandCategories { |
|---|
| 1307 | my ( $self, $event ) = @_; |
|---|
| 1308 | |
|---|
| 1309 | my $parent_item = $self->tree->GetSelection; |
|---|
| 1310 | $self->tree->ExpandAllChildren($parent_item); |
|---|
| 1311 | $self->tree->EnsureVisible($parent_item); |
|---|
| 1312 | } |
|---|
| 1313 | |
|---|
| 1314 | sub OnCollapseCategories { |
|---|
| 1315 | my ( $self, $event ) = @_; |
|---|
| 1316 | |
|---|
| 1317 | my $parent_item = $self->tree->GetSelection; |
|---|
| 1318 | $self->tree->CollapseAllChildren($parent_item); |
|---|
| 1319 | $self->tree->Expand($parent_item) if -1 == $self->tree->GetPlData($parent_item); |
|---|
| 1320 | } |
|---|
| 1321 | |
|---|
| 1322 | sub OnAddCategory { |
|---|
| 1323 | my ( $self, $event ) = @_; |
|---|
| 1324 | |
|---|
| 1325 | $self->tree->AddCategory; |
|---|
| 1326 | |
|---|
| 1327 | } |
|---|
| 1328 | |
|---|
| 1329 | |
|---|
| 1330 | sub OnRefreshCategories { |
|---|
| 1331 | my ( $self, $event ) = @_; |
|---|
| 1332 | |
|---|
| 1333 | $self->_refresh_all_categories_helper; |
|---|
| 1334 | } |
|---|
| 1335 | |
|---|
| 1336 | |
|---|
| 1337 | sub _refresh_all_categories_helper { |
|---|
| 1338 | my ( $self ) = @_; |
|---|
| 1339 | |
|---|
| 1340 | my $busycursor = Wx::BusyCursor->new(); |
|---|
| 1341 | $self->tree->CollapseAll; |
|---|
| 1342 | $self->tree->DeleteAllItems; |
|---|
| 1343 | $self->pwg->RefreshCategories(); |
|---|
| 1344 | $self->tree->categories( |
|---|
| 1345 | $self->pwg->categories |
|---|
| 1346 | ); |
|---|
| 1347 | $self->tree->Populate; |
|---|
| 1348 | $self->show_hide_pwg_categories_empty_msg; |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | |
|---|
| 1352 | sub OnImageViewerEndLabelEdit { |
|---|
| 1353 | my( $self, $event ) = @_; |
|---|
| 1354 | |
|---|
| 1355 | my $image = $self->imagelist->GetImage($event->GetIndex); |
|---|
| 1356 | $image->site_name( |
|---|
| 1357 | $event->GetLabel |
|---|
| 1358 | ); |
|---|
| 1359 | |
|---|
| 1360 | $self->piwigo_photo_properties_dlg->SetProperties; |
|---|
| 1361 | } |
|---|
| 1362 | |
|---|
| 1363 | sub OnImageViewerItemActivated { |
|---|
| 1364 | my( $self, $event ) = @_; |
|---|
| 1365 | |
|---|
| 1366 | $self->current_imageviewer_index( |
|---|
| 1367 | $event->GetIndex |
|---|
| 1368 | ); |
|---|
| 1369 | |
|---|
| 1370 | $self->OnPhotoProperties; |
|---|
| 1371 | } |
|---|
| 1372 | |
|---|
| 1373 | |
|---|
| 1374 | sub OnImageViewerItemSelected { |
|---|
| 1375 | my( $self, $event ) = @_; |
|---|
| 1376 | |
|---|
| 1377 | my $bc = Wx::BusyCursor->new; |
|---|
| 1378 | my $indx = $event->GetIndex; |
|---|
| 1379 | |
|---|
| 1380 | $self->piwigo_photo_properties_dlg->SetEnabled |
|---|
| 1381 | if !$self->piwigo_photo_properties_dlg->IsEnabled; |
|---|
| 1382 | $self->_on_imageviewer_item_selected($indx); |
|---|
| 1383 | |
|---|
| 1384 | $event->Skip; |
|---|
| 1385 | |
|---|
| 1386 | } |
|---|
| 1387 | |
|---|
| 1388 | sub OnImageViewerItemDeSelected { |
|---|
| 1389 | my( $self, $event ) = @_; |
|---|
| 1390 | |
|---|
| 1391 | my $bc = Wx::BusyCursor->new; |
|---|
| 1392 | $self->_on_imageviewer_item_selection_changed; |
|---|
| 1393 | |
|---|
| 1394 | $event->Skip; |
|---|
| 1395 | |
|---|
| 1396 | } |
|---|
| 1397 | |
|---|
| 1398 | sub _on_imageviewer_item_selected { |
|---|
| 1399 | my ( $self, $index ) = @_; |
|---|
| 1400 | $self->current_imageviewer_index($index); |
|---|
| 1401 | $self->imagelist->SetCurrentImage($index); |
|---|
| 1402 | |
|---|
| 1403 | $self->_on_imageviewer_item_selection_changed; |
|---|
| 1404 | } |
|---|
| 1405 | |
|---|
| 1406 | sub _on_imageviewer_item_selection_changed { |
|---|
| 1407 | my ( $self ) = @_; |
|---|
| 1408 | |
|---|
| 1409 | $self->imagelist->image_selection( |
|---|
| 1410 | $self->imageviewer->GetSelectedItems |
|---|
| 1411 | ); |
|---|
| 1412 | |
|---|
| 1413 | # for batch mode : reset the batch buffer if single selection |
|---|
| 1414 | if($self->multi_selection_mode){ |
|---|
| 1415 | $self->OnUpdateMultiSelectionModeUI; |
|---|
| 1416 | $self->imagelist->SetImageSelectionTags([]); |
|---|
| 1417 | $self->imagelist->image_selection_privacy_level(-1); |
|---|
| 1418 | $self->imagelist->image_selection_name(""); |
|---|
| 1419 | $self->imagelist->image_selection_author(""); |
|---|
| 1420 | $self->imagelist->image_selection_comment(""); |
|---|
| 1421 | $self->imagelist->image_selection_create_date(-1); |
|---|
| 1422 | } |
|---|
| 1423 | else{ |
|---|
| 1424 | $self->OnUpdateSingleSelectionModeUI; |
|---|
| 1425 | } |
|---|
| 1426 | # process image_preview in idle time |
|---|
| 1427 | # and when current event is processed |
|---|
| 1428 | # see call to EVT_IDLE |
|---|
| 1429 | $self->image_preview_need_refresh(1); |
|---|
| 1430 | |
|---|
| 1431 | $self->piwigo_photo_properties_dlg->SetProperties if defined $self->piwigo_photo_properties_dlg; |
|---|
| 1432 | $self->exif_dlg->Refresh; |
|---|
| 1433 | $self->piwigo_photo_properties_tags->RefreshChoices; |
|---|
| 1434 | |
|---|
| 1435 | } |
|---|
| 1436 | |
|---|
| 1437 | sub multi_selection_mode { |
|---|
| 1438 | my ( $self ) = @_; |
|---|
| 1439 | |
|---|
| 1440 | scalar @{$self->imagelist->image_selection} > 1; |
|---|
| 1441 | } |
|---|
| 1442 | |
|---|
| 1443 | sub OnUpdateMultiSelectionModeUI{ |
|---|
| 1444 | my( $self ) = @_; |
|---|
| 1445 | |
|---|
| 1446 | |
|---|
| 1447 | $self->piwigo_photo_properties_dlg->SetMultiSelectionMode( |
|---|
| 1448 | $self->imageviewer->GetSelectectItemsCount |
|---|
| 1449 | ); |
|---|
| 1450 | } |
|---|
| 1451 | |
|---|
| 1452 | sub OnUpdateSingleSelectionModeUI{ |
|---|
| 1453 | my( $self ) = @_; |
|---|
| 1454 | |
|---|
| 1455 | $self->piwigo_photo_properties_dlg->SetSingleSelectionMode; |
|---|
| 1456 | } |
|---|
| 1457 | |
|---|
| 1458 | |
|---|
| 1459 | sub set_preview_image { |
|---|
| 1460 | my ( $self ) = @_; |
|---|
| 1461 | |
|---|
| 1462 | my $current_image = $self->imagelist->current_image; |
|---|
| 1463 | my $image = Wx::Image->new; |
|---|
| 1464 | $image->LoadFile( |
|---|
| 1465 | $current_image->file, |
|---|
| 1466 | wxBITMAP_TYPE_ANY |
|---|
| 1467 | ); |
|---|
| 1468 | |
|---|
| 1469 | if($self->imagelist->auto_rotate){ |
|---|
| 1470 | # exif from original image |
|---|
| 1471 | my $orientation = $current_image->exif_metadata->{Orientation}; |
|---|
| 1472 | |
|---|
| 1473 | # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW |
|---|
| 1474 | if( $orientation =~ m/Rotate (\d+)/ ){ |
|---|
| 1475 | for(my $i=0; $i < floor($1/90) ; $i++){ |
|---|
| 1476 | $image = $image->Rotate90; |
|---|
| 1477 | } |
|---|
| 1478 | } |
|---|
| 1479 | } |
|---|
| 1480 | |
|---|
| 1481 | $self->image_preview_dlg->image_size( |
|---|
| 1482 | [$image->GetWidth, $image->GetHeight, ] |
|---|
| 1483 | ); |
|---|
| 1484 | |
|---|
| 1485 | $self->image_preview_dlg->image( |
|---|
| 1486 | $image |
|---|
| 1487 | ); |
|---|
| 1488 | } |
|---|
| 1489 | |
|---|
| 1490 | sub OnImageViewerKeyDown { |
|---|
| 1491 | my( $self, $event ) = @_; |
|---|
| 1492 | |
|---|
| 1493 | if(WXK_DELETE == $event->GetKeyCode){ |
|---|
| 1494 | $self->OnRemoveImages(); |
|---|
| 1495 | |
|---|
| 1496 | my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ? |
|---|
| 1497 | $self->current_imageviewer_index : $self->imageviewer->GetItemCount -1 ; |
|---|
| 1498 | $self->imageviewer->SelectItem( |
|---|
| 1499 | $index |
|---|
| 1500 | ); |
|---|
| 1501 | $self->imageviewer->EnsureVisible( |
|---|
| 1502 | $index |
|---|
| 1503 | ); |
|---|
| 1504 | } |
|---|
| 1505 | |
|---|
| 1506 | } |
|---|
| 1507 | |
|---|
| 1508 | |
|---|
| 1509 | sub OnUploadImages { |
|---|
| 1510 | my( $self, $event ) = @_; |
|---|
| 1511 | |
|---|
| 1512 | my $select_all = 1; |
|---|
| 1513 | eval { |
|---|
| 1514 | $self->ProcessImageSelection( $select_all ); |
|---|
| 1515 | }; |
|---|
| 1516 | } |
|---|
| 1517 | |
|---|
| 1518 | # remove image from imagelist when uploaded |
|---|
| 1519 | sub UploadImagesViewerRefresh { |
|---|
| 1520 | my ( $self ) = @_; |
|---|
| 1521 | |
|---|
| 1522 | |
|---|
| 1523 | $self->imageviewer->Refresh; |
|---|
| 1524 | |
|---|
| 1525 | if(!$self->imageviewer->GetItemCount){ |
|---|
| 1526 | $self->image_preview_dlg->image(0); |
|---|
| 1527 | $self->OnUpdateImageviewerEmpty; |
|---|
| 1528 | } |
|---|
| 1529 | # reset previous selection |
|---|
| 1530 | $self->imagelist->image_selection( |
|---|
| 1531 | [] |
|---|
| 1532 | ); |
|---|
| 1533 | |
|---|
| 1534 | if(!$self->multi_selection_mode){ |
|---|
| 1535 | $self->OnUpdateSingleSelectionModeUI; |
|---|
| 1536 | } |
|---|
| 1537 | |
|---|
| 1538 | $self->image_preview_dlg->Refresh; |
|---|
| 1539 | Wx::Yield(); |
|---|
| 1540 | } |
|---|
| 1541 | |
|---|
| 1542 | sub UploadProgressMessageRefresh { |
|---|
| 1543 | my ( $self, $msg ) = @_; |
|---|
| 1544 | |
|---|
| 1545 | Wx::Yield(); |
|---|
| 1546 | |
|---|
| 1547 | $self->upload_progressdlg->processing( |
|---|
| 1548 | $msg |
|---|
| 1549 | ); |
|---|
| 1550 | $self->upload_progressdlg->LogProgress(); |
|---|
| 1551 | |
|---|
| 1552 | Wx::Yield(); |
|---|
| 1553 | } |
|---|
| 1554 | |
|---|
| 1555 | sub UploadProgressMessageDetailsRefresh { |
|---|
| 1556 | my ( $self, $msg ) = @_; |
|---|
| 1557 | |
|---|
| 1558 | Wx::Yield(); |
|---|
| 1559 | |
|---|
| 1560 | $self->upload_progressdlg->processing_details( |
|---|
| 1561 | $msg |
|---|
| 1562 | ); |
|---|
| 1563 | $self->upload_progressdlg->LogProgress(); |
|---|
| 1564 | |
|---|
| 1565 | Wx::Yield(); |
|---|
| 1566 | } |
|---|
| 1567 | |
|---|
| 1568 | |
|---|
| 1569 | sub UploadProgressThumbnailRefresh { |
|---|
| 1570 | my ( $self ) = @_; |
|---|
| 1571 | |
|---|
| 1572 | my $imagelist = $self->imagelist ; |
|---|
| 1573 | |
|---|
| 1574 | |
|---|
| 1575 | $self->upload_progressdlg->image->SetBitmap(wxNullBitmap); |
|---|
| 1576 | $self->upload_progressdlg->image->SetBitmap( |
|---|
| 1577 | Wx::Bitmap->new( |
|---|
| 1578 | $self->imagelist->current_image->wx_thumb_file, |
|---|
| 1579 | $self->GetWxBitmapType($self->imagelist->type), |
|---|
| 1580 | ) |
|---|
| 1581 | ); |
|---|
| 1582 | |
|---|
| 1583 | Wx::Yield(); |
|---|
| 1584 | } |
|---|
| 1585 | |
|---|
| 1586 | sub UploadProgressBarRefresh { |
|---|
| 1587 | my ( $self, $value ) = @_; |
|---|
| 1588 | |
|---|
| 1589 | eval { |
|---|
| 1590 | $self->upload_progressdlg->progress( |
|---|
| 1591 | $value |
|---|
| 1592 | ); |
|---|
| 1593 | $self->upload_progressdlg->LogProgress(); |
|---|
| 1594 | }; |
|---|
| 1595 | #croak gettext("Upload cancelled") if $@; |
|---|
| 1596 | |
|---|
| 1597 | Wx::Yield(); |
|---|
| 1598 | } |
|---|
| 1599 | |
|---|
| 1600 | sub SetNewFilesDisplayEndInfo { |
|---|
| 1601 | my ( $self, $msg, $errors ) = @_; |
|---|
| 1602 | |
|---|
| 1603 | if($errors){ |
|---|
| 1604 | $self->progressdlg->DisplayEndInfo($msg); |
|---|
| 1605 | } |
|---|
| 1606 | else{ |
|---|
| 1607 | $self->progressdlg->Show(0); |
|---|
| 1608 | } |
|---|
| 1609 | } |
|---|
| 1610 | |
|---|
| 1611 | sub UploadDisplayEndInfo { |
|---|
| 1612 | my ( $self, $msg ) = @_; |
|---|
| 1613 | |
|---|
| 1614 | my $imagelist = $self->imagelist ; |
|---|
| 1615 | |
|---|
| 1616 | $self->upload_progressdlg->DisplayEndInfo($msg); |
|---|
| 1617 | } |
|---|
| 1618 | |
|---|
| 1619 | sub ShowImageViewer { |
|---|
| 1620 | my ( $self ) = @_; |
|---|
| 1621 | |
|---|
| 1622 | if(!$self->imageviewer->IsShown){ |
|---|
| 1623 | $self->imageviewer->Show(1); |
|---|
| 1624 | } |
|---|
| 1625 | } |
|---|
| 1626 | |
|---|
| 1627 | |
|---|
| 1628 | sub SetNewFilesViewerRefresh { |
|---|
| 1629 | |
|---|
| 1630 | my ( $self ) = @_; |
|---|
| 1631 | |
|---|
| 1632 | my $wximagelist = $self->imagelist->wx_thumb_imglist; |
|---|
| 1633 | #print Dumper "SetNewFilesViewerRefresh", $self->imagelist->current_image; |
|---|
| 1634 | my $indx = $wximagelist->Add( |
|---|
| 1635 | Wx::Bitmap->new( |
|---|
| 1636 | $self->imagelist->current_image->wx_thumb_file, |
|---|
| 1637 | $self->GetWxBitmapType($self->imagelist->type), |
|---|
| 1638 | ) |
|---|
| 1639 | ) if defined $self->imagelist->current_image->wx_thumb_file; |
|---|
| 1640 | #print $self->imagelist->current_image->wx_thumb_file, " added with index ", $indx, "\n"; |
|---|
| 1641 | |
|---|
| 1642 | $self->imageviewer->Refresh( |
|---|
| 1643 | $wximagelist |
|---|
| 1644 | ); |
|---|
| 1645 | |
|---|
| 1646 | $self->OnUpdateImageviewerNotEmpty if $self->imageviewer->GetItemCount; |
|---|
| 1647 | |
|---|
| 1648 | Wx::Yield(); |
|---|
| 1649 | } |
|---|
| 1650 | |
|---|
| 1651 | |
|---|
| 1652 | sub GetWxBitmapType { |
|---|
| 1653 | my ( $self, $type ) = @_; |
|---|
| 1654 | |
|---|
| 1655 | $self->{IMGTYPE}->{$type}; |
|---|
| 1656 | } |
|---|
| 1657 | |
|---|
| 1658 | |
|---|
| 1659 | # prepare and upload image_selection |
|---|
| 1660 | sub ProcessImageSelection { |
|---|
| 1661 | my ( $self, $select_all ) = @_; |
|---|
| 1662 | |
|---|
| 1663 | return if !scalar @{$self->imagelist->sums}; |
|---|
| 1664 | |
|---|
| 1665 | if( $self->destination_categories_are_empty ){ |
|---|
| 1666 | return unless $self->destination_category_dlg->ShowModal != wxID_CANCEL; |
|---|
| 1667 | } |
|---|
| 1668 | |
|---|
| 1669 | $self->imagelist->image_selection( |
|---|
| 1670 | $self->imageviewer->GetAllItems |
|---|
| 1671 | ) if $select_all; |
|---|
| 1672 | |
|---|
| 1673 | return if( !defined $self->imagelist->image_selection ); |
|---|
| 1674 | return if( !scalar @{$self->imagelist->image_selection} ); |
|---|
| 1675 | |
|---|
| 1676 | $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg; |
|---|
| 1677 | $self->upload_progressdlg( |
|---|
| 1678 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
|---|
| 1679 | { |
|---|
| 1680 | title => gettext("Image upload progress information"), |
|---|
| 1681 | bt_label => gettext("Cancel upload"), |
|---|
| 1682 | bt_close_label => gettext("Close"), |
|---|
| 1683 | stop_processing => sub { $self->imagelist->stop_processing(1); Wx::Yield(); }, |
|---|
| 1684 | } |
|---|
| 1685 | ) |
|---|
| 1686 | ); |
|---|
| 1687 | |
|---|
| 1688 | # modeless dialog |
|---|
| 1689 | $self->upload_progressdlg->Show(1); |
|---|
| 1690 | Wx::Yield(); |
|---|
| 1691 | eval { |
|---|
| 1692 | $self->imagelist->UploadSelection; |
|---|
| 1693 | }; |
|---|
| 1694 | if($@){ |
|---|
| 1695 | Wx::MessageBox( |
|---|
| 1696 | sprintf( |
|---|
| 1697 | gettext("Upload cancelled"), |
|---|
| 1698 | ), |
|---|
| 1699 | gettext("Piwigo upload information"), |
|---|
| 1700 | wxOK | wxICON_INFORMATION, |
|---|
| 1701 | ); |
|---|
| 1702 | } |
|---|
| 1703 | } |
|---|
| 1704 | |
|---|
| 1705 | |
|---|
| 1706 | sub destination_categories_are_empty { |
|---|
| 1707 | my ( $self ) = @_; |
|---|
| 1708 | |
|---|
| 1709 | !scalar @{$self->imagelist->categories}; |
|---|
| 1710 | } |
|---|
| 1711 | |
|---|
| 1712 | |
|---|
| 1713 | sub SetNewFilesProgress { |
|---|
| 1714 | my ( $self ) = @_; |
|---|
| 1715 | |
|---|
| 1716 | my $imagelist = $self->imagelist; |
|---|
| 1717 | |
|---|
| 1718 | $self->progressdlg->processing( |
|---|
| 1719 | sprintf( |
|---|
| 1720 | $imagelist->progress_msg, |
|---|
| 1721 | $imagelist->current_image->file, |
|---|
| 1722 | ) |
|---|
| 1723 | ); |
|---|
| 1724 | |
|---|
| 1725 | eval { |
|---|
| 1726 | $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]); |
|---|
| 1727 | $self->progressdlg->image->SetBitmap(wxNullBitmap); |
|---|
| 1728 | $self->progressdlg->image->SetBitmap( |
|---|
| 1729 | Wx::Bitmap->new( |
|---|
| 1730 | $imagelist->current_image->wx_thumb_file, |
|---|
| 1731 | $self->GetWxBitmapType( $imagelist->type ) |
|---|
| 1732 | ) |
|---|
| 1733 | ); |
|---|
| 1734 | $self->progressdlg->progress( |
|---|
| 1735 | $imagelist->count * ( 100/scalar @{$imagelist->new_files} ) |
|---|
| 1736 | ); |
|---|
| 1737 | $self->progressdlg->LogProgress(); |
|---|
| 1738 | }; |
|---|
| 1739 | Wx::Yield(); |
|---|
| 1740 | } |
|---|
| 1741 | |
|---|
| 1742 | sub OnClose { |
|---|
| 1743 | my $self = shift; |
|---|
| 1744 | |
|---|
| 1745 | |
|---|
| 1746 | # Restaure previous log wnd |
|---|
| 1747 | Wx::Log::SetActiveTarget( $self->oldlogwnd ); |
|---|
| 1748 | |
|---|
| 1749 | # allways store |
|---|
| 1750 | |
|---|
| 1751 | wxTheApp->StoreConnectionProperties; |
|---|
| 1752 | |
|---|
| 1753 | $self->imagelist->Store; |
|---|
| 1754 | wxTheApp->login_dlg->Destroy; |
|---|
| 1755 | |
|---|
| 1756 | |
|---|
| 1757 | wxTheApp->imageviewerIndex( |
|---|
| 1758 | $self->current_imageviewer_index |
|---|
| 1759 | ); |
|---|
| 1760 | |
|---|
| 1761 | my $frameLayout = {}; |
|---|
| 1762 | |
|---|
| 1763 | ( $frameLayout->{pX}, $frameLayout->{pY}, $frameLayout->{W}, $frameLayout->{H} ) = ( $self->GetPositionXY, $self->GetSizeWH ) ; |
|---|
| 1764 | |
|---|
| 1765 | wxTheApp->frameLayout( |
|---|
| 1766 | $frameLayout |
|---|
| 1767 | ); |
|---|
| 1768 | |
|---|
| 1769 | wxTheApp->StoreLayoutProperties; |
|---|
| 1770 | |
|---|
| 1771 | #destroy hidden dialogs |
|---|
| 1772 | $self->global_settings_dlg->Destroy; |
|---|
| 1773 | $self->image_preview_dlg->Destroy; |
|---|
| 1774 | $self->exif_dlg->Destroy; |
|---|
| 1775 | $self->destination_category_dlg->Destroy; |
|---|
| 1776 | |
|---|
| 1777 | $self->progressdlg->Destroy if defined $self->progressdlg; |
|---|
| 1778 | $self->upload_progressdlg->Destroy if defined $self->upload_progressdlg; |
|---|
| 1779 | |
|---|
| 1780 | $self->Destroy; |
|---|
| 1781 | } |
|---|
| 1782 | |
|---|
| 1783 | |
|---|
| 1784 | sub create_toolbar { |
|---|
| 1785 | my( $self ) = @_; |
|---|
| 1786 | |
|---|
| 1787 | my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, [600, -1], wxTB_FLAT|wxTB_TEXT ); |
|---|
| 1788 | $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) ); |
|---|
| 1789 | map { |
|---|
| 1790 | my $icon1 = Wx::Icon->new(); |
|---|
| 1791 | eval { |
|---|
| 1792 | $icon1->LoadFile($_->[2], $_->[3]); |
|---|
| 1793 | }; |
|---|
| 1794 | my $tb_icon1 = Wx::Bitmap->new( $icon1 ); |
|---|
| 1795 | |
|---|
| 1796 | my $icon2 = Wx::Icon->new(); |
|---|
| 1797 | eval { |
|---|
| 1798 | $icon2->LoadFile($_->[5], $_->[3]); |
|---|
| 1799 | }; |
|---|
| 1800 | my $tb_icon2 = Wx::Bitmap->new( $icon2 ); |
|---|
| 1801 | |
|---|
| 1802 | |
|---|
| 1803 | $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[6] ); |
|---|
| 1804 | $tb->EnableTool( $_->[0], $_->[4]); |
|---|
| 1805 | } |
|---|
| 1806 | ( |
|---|
| 1807 | [ |
|---|
| 1808 | 101, |
|---|
| 1809 | gettext("Add photos"), |
|---|
| 1810 | wxTheApp->resource_path('tb_add.png'), |
|---|
| 1811 | wxBITMAP_TYPE_PNG, |
|---|
| 1812 | 1, |
|---|
| 1813 | wxTheApp->resource_path('tb_add.png'), |
|---|
| 1814 | gettext("Add photos for resizing and uploading") |
|---|
| 1815 | ], |
|---|
| 1816 | [ |
|---|
| 1817 | 102, |
|---|
| 1818 | gettext("Remove selected photos"), |
|---|
| 1819 | wxTheApp->resource_path('tb_remove.png'), |
|---|
| 1820 | wxBITMAP_TYPE_PNG, |
|---|
| 1821 | 1, |
|---|
| 1822 | wxTheApp->resource_path('tb_remove.png'), |
|---|
| 1823 | gettext("Remove selected photos. Original files are not deleted ") |
|---|
| 1824 | ], |
|---|
| 1825 | [ |
|---|
| 1826 | 104, |
|---|
| 1827 | gettext("Preferences"), |
|---|
| 1828 | wxTheApp->resource_path('tb_settings.png'), |
|---|
| 1829 | wxBITMAP_TYPE_PNG, |
|---|
| 1830 | 0, |
|---|
| 1831 | wxTheApp->resource_path('tb_settings.png'), |
|---|
| 1832 | gettext("Change global settings.") |
|---|
| 1833 | ], |
|---|
| 1834 | |
|---|
| 1835 | ); |
|---|
| 1836 | |
|---|
| 1837 | $tb->AddSeparator; |
|---|
| 1838 | |
|---|
| 1839 | $tb->AddControl( |
|---|
| 1840 | Wx::Choice->new( |
|---|
| 1841 | $tb, |
|---|
| 1842 | 106, |
|---|
| 1843 | wxDefaultPosition, |
|---|
| 1844 | [300, -1], |
|---|
| 1845 | [], |
|---|
| 1846 | ) |
|---|
| 1847 | ); |
|---|
| 1848 | my $ch = $tb->FindWindow(106); |
|---|
| 1849 | $ch->SetToolTip(gettext("How photo selection is displayed")); |
|---|
| 1850 | map { |
|---|
| 1851 | $ch->Append(gettext($_), $_); |
|---|
| 1852 | }( |
|---|
| 1853 | "Thumbnail and caption", |
|---|
| 1854 | "Thumbnail", |
|---|
| 1855 | "Property list" |
|---|
| 1856 | ); |
|---|
| 1857 | |
|---|
| 1858 | $ch->SetStringSelection(gettext($self->imagelist->display_mode)); |
|---|
| 1859 | $tb->Realize; |
|---|
| 1860 | |
|---|
| 1861 | $self->toolbar( |
|---|
| 1862 | $tb |
|---|
| 1863 | ); |
|---|
| 1864 | $self->SetToolBar($tb); |
|---|
| 1865 | |
|---|
| 1866 | return $tb; |
|---|
| 1867 | } |
|---|
| 1868 | |
|---|
| 1869 | sub OnPhotoSelMode { |
|---|
| 1870 | my ( $self, $event )= @_; |
|---|
| 1871 | |
|---|
| 1872 | $self->imagelist->display_mode( |
|---|
| 1873 | $event->GetClientData |
|---|
| 1874 | ); |
|---|
| 1875 | |
|---|
| 1876 | $self->imageviewer->change_display_mode(1); |
|---|
| 1877 | } |
|---|
| 1878 | |
|---|
| 1879 | sub _create_textctrl { |
|---|
| 1880 | my( $self, $parent, $text, $size ) = @_; |
|---|
| 1881 | |
|---|
| 1882 | return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size, |
|---|
| 1883 | wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY ); |
|---|
| 1884 | } |
|---|
| 1885 | |
|---|
| 1886 | sub create_textctrl { |
|---|
| 1887 | my( $self, $text, $size ) = @_; |
|---|
| 1888 | |
|---|
| 1889 | return $self->_create_textctrl( $self, $text, $size ); |
|---|
| 1890 | } |
|---|
| 1891 | |
|---|
| 1892 | sub DESTROY { |
|---|
| 1893 | my( $self ) = @_; |
|---|
| 1894 | |
|---|
| 1895 | } |
|---|
| 1896 | |
|---|
| 1897 | |
|---|
| 1898 | |
|---|
| 1899 | 1; |
|---|
| 1900 | |
|---|
| 1901 | |
|---|
| 1902 | |
|---|
| 1903 | |
|---|
| 1904 | |
|---|
| 1905 | package DNDImageListDropTarget; |
|---|
| 1906 | use Wx qw/wxTheApp/; |
|---|
| 1907 | use base qw(Wx::FileDropTarget Class::Accessor::Fast); |
|---|
| 1908 | |
|---|
| 1909 | __PACKAGE__->mk_accessors( |
|---|
| 1910 | qw/ |
|---|
| 1911 | imageviewer |
|---|
| 1912 | / |
|---|
| 1913 | ); |
|---|
| 1914 | |
|---|
| 1915 | sub new { |
|---|
| 1916 | my $class = shift; |
|---|
| 1917 | my $imageviewer = shift; |
|---|
| 1918 | my $self = $class->SUPER::new( @_ ); |
|---|
| 1919 | |
|---|
| 1920 | $self->imageviewer($imageviewer); |
|---|
| 1921 | |
|---|
| 1922 | return $self; |
|---|
| 1923 | } |
|---|
| 1924 | |
|---|
| 1925 | sub OnDropFiles { |
|---|
| 1926 | my( $self, $x, $y, $files ) = @_; |
|---|
| 1927 | |
|---|
| 1928 | wxTheApp->frame->SetNewFiles($files) ; |
|---|
| 1929 | } |
|---|
| 1930 | |
|---|
| 1931 | |
|---|
| 1932 | |
|---|
| 1933 | |
|---|
| 1934 | 1; |
|---|
| 1935 | |
|---|
| 1936 | |
|---|
| 1937 | package DNDCategoryTreeDropTarget; |
|---|
| 1938 | |
|---|
| 1939 | use base qw(Wx::TextDropTarget Class::Accessor::Fast); |
|---|
| 1940 | use Data::Dumper; |
|---|
| 1941 | use Wx qw/ |
|---|
| 1942 | wxDragNone |
|---|
| 1943 | wxDragCopy |
|---|
| 1944 | wxDragMove |
|---|
| 1945 | wxTheApp |
|---|
| 1946 | /; |
|---|
| 1947 | |
|---|
| 1948 | __PACKAGE__->mk_accessors( |
|---|
| 1949 | qw/ |
|---|
| 1950 | tree |
|---|
| 1951 | / |
|---|
| 1952 | ); |
|---|
| 1953 | |
|---|
| 1954 | sub new { |
|---|
| 1955 | my ( $class, $tree ) = @_; |
|---|
| 1956 | my $self = $class->SUPER::new(); |
|---|
| 1957 | |
|---|
| 1958 | $self->tree($tree); |
|---|
| 1959 | |
|---|
| 1960 | return $self; |
|---|
| 1961 | } |
|---|
| 1962 | |
|---|
| 1963 | |
|---|
| 1964 | |
|---|
| 1965 | sub OnDropText { |
|---|
| 1966 | my( $self, $x, $y, $textdata ) = @_; |
|---|
| 1967 | |
|---|
| 1968 | # must be $VAR1 because $textdata is the result of Data::Dumper |
|---|
| 1969 | my $VAR1; |
|---|
| 1970 | eval $textdata; |
|---|
| 1971 | eval { |
|---|
| 1972 | if(scalar @$VAR1){ |
|---|
| 1973 | my @items; |
|---|
| 1974 | if(scalar @items < 2) { |
|---|
| 1975 | my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]); |
|---|
| 1976 | push @items, $dropItem; |
|---|
| 1977 | } |
|---|
| 1978 | else { |
|---|
| 1979 | @items = $self->tree->GetSelections; |
|---|
| 1980 | } |
|---|
| 1981 | |
|---|
| 1982 | # remove root item which is not a valid category |
|---|
| 1983 | @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items; |
|---|
| 1984 | |
|---|
| 1985 | wxTheApp->frame->imagelist->categories( |
|---|
| 1986 | [ |
|---|
| 1987 | map { |
|---|
| 1988 | $self->tree->GetPlData( $_ )->{id}; |
|---|
| 1989 | } |
|---|
| 1990 | @items |
|---|
| 1991 | ] |
|---|
| 1992 | ); |
|---|
| 1993 | |
|---|
| 1994 | wxTheApp->frame->imagelist->image_selection($VAR1); |
|---|
| 1995 | wxTheApp->frame->ProcessImageSelection ; |
|---|
| 1996 | } |
|---|
| 1997 | }; |
|---|
| 1998 | } |
|---|
| 1999 | |
|---|
| 2000 | |
|---|
| 2001 | 1; |
|---|