| 1 | # +-----------------------------------------------------------------------+ |
|---|
| 2 | # | pLoader - a Perl photo uploader for Piwigo | |
|---|
| 3 | # +-----------------------------------------------------------------------+ |
|---|
| 4 | # | Copyright(C) 2008 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::wxFrameAUI; |
|---|
| 21 | use strict; |
|---|
| 22 | use Carp; |
|---|
| 23 | use Wx; |
|---|
| 24 | use Wx::DND; |
|---|
| 25 | use Wx qw/ |
|---|
| 26 | wxDEFAULT_FRAME_STYLE |
|---|
| 27 | wxVERTICAL |
|---|
| 28 | wxGROW |
|---|
| 29 | wxBITMAP_TYPE_JPEG |
|---|
| 30 | wxBITMAP_TYPE_GIF |
|---|
| 31 | wxBITMAP_TYPE_PNG |
|---|
| 32 | wxTB_FLAT |
|---|
| 33 | wxSIZE |
|---|
| 34 | wxWHITE |
|---|
| 35 | wxBLACK |
|---|
| 36 | wxID_CANCEL |
|---|
| 37 | wxFD_OPEN |
|---|
| 38 | wxFD_MULTIPLE |
|---|
| 39 | wxLI_HORIZONTAL |
|---|
| 40 | wxALIGN_CENTER_VERTICAL |
|---|
| 41 | wxALL |
|---|
| 42 | wxDefaultPosition |
|---|
| 43 | wxDefaultSize |
|---|
| 44 | wxTheApp |
|---|
| 45 | wxIMAGE_LIST_NORMAL |
|---|
| 46 | wxAUI_NB_TAB_MOVE |
|---|
| 47 | wxAUI_NB_TAB_SPLIT |
|---|
| 48 | wxNO_BORDER |
|---|
| 49 | wxTE_MULTILINE |
|---|
| 50 | wxTE_READONLY |
|---|
| 51 | wxITEM_NORMAL |
|---|
| 52 | wxCLIP_CHILDREN |
|---|
| 53 | wxBORDER_NONE |
|---|
| 54 | wxNullBitmap |
|---|
| 55 | wxTR_MULTIPLE |
|---|
| 56 | wxTR_EXTENDED |
|---|
| 57 | wxTR_HIDE_ROOT |
|---|
| 58 | wxTR_HAS_BUTTONS |
|---|
| 59 | wxMAXIMIZE |
|---|
| 60 | wxOK |
|---|
| 61 | wxICON_EXCLAMATION |
|---|
| 62 | wxICON_INFORMATION |
|---|
| 63 | WXK_DELETE |
|---|
| 64 | /; |
|---|
| 65 | use base qw/Wx::Frame Class::Accessor::Fast/; |
|---|
| 66 | use File::Spec; |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | my @properties = |
|---|
| 70 | qw/ |
|---|
| 71 | progressdlg |
|---|
| 72 | upload_progressdlg |
|---|
| 73 | imageviewer |
|---|
| 74 | tree |
|---|
| 75 | tree_root |
|---|
| 76 | treeimglist |
|---|
| 77 | tree_item_default |
|---|
| 78 | topsizer |
|---|
| 79 | pwg |
|---|
| 80 | manager |
|---|
| 81 | logwnd |
|---|
| 82 | oldlogwnd |
|---|
| 83 | htmlhome |
|---|
| 84 | notebook |
|---|
| 85 | categories |
|---|
| 86 | imagelist |
|---|
| 87 | image_prop_general |
|---|
| 88 | image_prop_exif |
|---|
| 89 | notebook_image_properties |
|---|
| 90 | global_settings_panel |
|---|
| 91 | /; |
|---|
| 92 | __PACKAGE__->mk_accessors( @properties ); |
|---|
| 93 | |
|---|
| 94 | use Wx::Event |
|---|
| 95 | qw/ |
|---|
| 96 | EVT_MENU |
|---|
| 97 | EVT_TREE_SEL_CHANGED |
|---|
| 98 | EVT_CLOSE |
|---|
| 99 | EVT_LIST_END_LABEL_EDIT |
|---|
| 100 | EVT_LIST_ITEM_SELECTED |
|---|
| 101 | EVT_TREE_ITEM_RIGHT_CLICK |
|---|
| 102 | EVT_LIST_KEY_DOWN |
|---|
| 103 | /; |
|---|
| 104 | |
|---|
| 105 | use Uploader::GUI::wxImageListCtrl; |
|---|
| 106 | use Uploader::GUI::wxImageProcessingProgressDlg; |
|---|
| 107 | use Wx::Html; |
|---|
| 108 | use Uploader::GUI::wxHtmlWindow; |
|---|
| 109 | use Data::Dumper; |
|---|
| 110 | use Wx::AUI; |
|---|
| 111 | use Storable; |
|---|
| 112 | use Uploader::GUI::wxPhotoPropertiesPanel; |
|---|
| 113 | use Uploader::GUI::wxPhotoExifPanel; |
|---|
| 114 | use Uploader::GUI::wxGlobalSettingsPanel; |
|---|
| 115 | use Encode qw/encode decode is_utf8/; |
|---|
| 116 | |
|---|
| 117 | $|=1; |
|---|
| 118 | |
|---|
| 119 | my $ID_TREE_CTX_MENU = 20000 ; |
|---|
| 120 | |
|---|
| 121 | sub new { |
|---|
| 122 | my( $class, $params ) = @_; |
|---|
| 123 | my( $self ) = $class->SUPER::new( |
|---|
| 124 | undef, |
|---|
| 125 | -1, |
|---|
| 126 | $params->{title}, |
|---|
| 127 | [ $params->{x}, $params->{y} ], |
|---|
| 128 | [ $params->{width}, $params->{height} ], |
|---|
| 129 | wxDEFAULT_FRAME_STYLE|wxMAXIMIZE |
|---|
| 130 | ); |
|---|
| 131 | $self->pwg( $params->{pwg} ); |
|---|
| 132 | $self->imagelist( $params->{imagelist} ); |
|---|
| 133 | |
|---|
| 134 | # callback for GUI refresh : add thumbnail images to the imageviewer control |
|---|
| 135 | $self->imagelist->SetNewFilesViewerRefreshCallback( |
|---|
| 136 | sub { $self->SetNewFilesViewerRefresh(@_) } |
|---|
| 137 | ); |
|---|
| 138 | |
|---|
| 139 | # callback for GUI refresh : progress dialog display of thumbnail image being created |
|---|
| 140 | $self->imagelist->SetNewFilesProgressCallback( |
|---|
| 141 | sub { $self->SetNewFilesProgress(@_) } |
|---|
| 142 | ); |
|---|
| 143 | |
|---|
| 144 | $self->imagelist->SetNewFilesDisplayEndInfoCallback( |
|---|
| 145 | sub { $self->SetNewFilesDisplayEndInfo(@_) } |
|---|
| 146 | ); |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | # callback for GUI refresh : remove thumbnail images from imageviewer control |
|---|
| 150 | $self->imagelist->UploadImagesViewerCallback( |
|---|
| 151 | sub { $self->UploadImagesViewerRefresh(@_) } |
|---|
| 152 | ); |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | # callback for GUI refresh : progress dialog display current uploaded image |
|---|
| 157 | $self->imagelist->progress_thumbnail_refresh( |
|---|
| 158 | sub { $self->UploadProgressThumbnailRefresh(@_) } |
|---|
| 159 | ); |
|---|
| 160 | |
|---|
| 161 | $self->imagelist->progress_msg_refresh( |
|---|
| 162 | sub { $self->UploadProgressMessageRefresh(@_) } |
|---|
| 163 | ); |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | $self->imagelist->progressbar_refresh( |
|---|
| 167 | sub { $self->UploadProgressBarRefresh(@_) } |
|---|
| 168 | ); |
|---|
| 169 | |
|---|
| 170 | $self->imagelist->progress_endinfo_refresh( |
|---|
| 171 | sub { $self->UploadDisplayEndInfo(@_) } |
|---|
| 172 | ); |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | $self->imagelist->pwg( |
|---|
| 176 | $self->pwg |
|---|
| 177 | ); |
|---|
| 178 | |
|---|
| 179 | $self->imagelist->categories( |
|---|
| 180 | [] |
|---|
| 181 | ); |
|---|
| 182 | |
|---|
| 183 | $self->manager( Wx::AuiManager->new ); |
|---|
| 184 | $self->manager->SetManagedWindow( $self ); |
|---|
| 185 | |
|---|
| 186 | $self->_initFrame; |
|---|
| 187 | $self->_InitEventHandlers; |
|---|
| 188 | $self->_initImgTypes; |
|---|
| 189 | |
|---|
| 190 | $self; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | sub _initImgTypes { |
|---|
| 194 | my ( $self ) = @_; |
|---|
| 195 | |
|---|
| 196 | $self->{IMGTYPE} = { |
|---|
| 197 | 'jpg' => wxBITMAP_TYPE_JPEG, |
|---|
| 198 | 'gif' => wxBITMAP_TYPE_GIF, |
|---|
| 199 | 'png' => wxBITMAP_TYPE_PNG, |
|---|
| 200 | }; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | sub GetWxBitmapType { |
|---|
| 205 | my ( $self, $type ) = @_; |
|---|
| 206 | |
|---|
| 207 | $self->{IMGTYPE}->{$type}; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | sub _initFrame { |
|---|
| 212 | my ( $self ) = @_; |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | $self->htmlhome( |
|---|
| 216 | Uploader::GUI::wxHtmlWindow->new( |
|---|
| 217 | $self, -1 |
|---|
| 218 | ) |
|---|
| 219 | ); |
|---|
| 220 | $self->imageviewer( |
|---|
| 221 | Uploader::GUI::wxImageListCtrl->new( |
|---|
| 222 | { |
|---|
| 223 | parentwnd => $self, |
|---|
| 224 | imagelist => $self->imagelist, |
|---|
| 225 | } |
|---|
| 226 | ) |
|---|
| 227 | ); |
|---|
| 228 | |
|---|
| 229 | $self->global_settings_panel( |
|---|
| 230 | $self->create_global_settings_panel() |
|---|
| 231 | ); |
|---|
| 232 | |
|---|
| 233 | $self->image_prop_general( |
|---|
| 234 | Uploader::GUI::wxPhotoPropertiesPanel->new( |
|---|
| 235 | { |
|---|
| 236 | parentwnd => $self, |
|---|
| 237 | accessors => { |
|---|
| 238 | $main::ID_PHOTO => |
|---|
| 239 | sub { |
|---|
| 240 | Wx::Bitmap->new( |
|---|
| 241 | $self->imagelist->current_image->wx_thumb_file, |
|---|
| 242 | $self->GetWxBitmapType($self->imagelist->type), |
|---|
| 243 | ); |
|---|
| 244 | }, |
|---|
| 245 | $main::ID_PHOTO_NAME => |
|---|
| 246 | sub { $self->imagelist->current_image->site_name(@_) }, |
|---|
| 247 | |
|---|
| 248 | $main::ID_PHOTO_CREATE_DATE => |
|---|
| 249 | sub { $self->imagelist->current_image->create_date(@_) }, |
|---|
| 250 | |
|---|
| 251 | $main::ID_PHOTO_COMMENT => |
|---|
| 252 | sub { $self->imagelist->current_image->site_comment(@_) }, |
|---|
| 253 | |
|---|
| 254 | $main::ID_PHOTO_AUTHOR => |
|---|
| 255 | sub { $self->imagelist->current_image->site_author(@_) }, |
|---|
| 256 | }, |
|---|
| 257 | frame_callbacks => { |
|---|
| 258 | $main::ID_PHOTO_NAME => |
|---|
| 259 | sub { |
|---|
| 260 | $self->imageviewer->Refresh(); |
|---|
| 261 | }, |
|---|
| 262 | }, |
|---|
| 263 | } |
|---|
| 264 | ) |
|---|
| 265 | ); |
|---|
| 266 | |
|---|
| 267 | $self->image_prop_exif( |
|---|
| 268 | Uploader::GUI::wxPhotoExifPanel->new( |
|---|
| 269 | { |
|---|
| 270 | parentwnd => $self, |
|---|
| 271 | frame_callback => sub { |
|---|
| 272 | $self->imageviewer->Refresh(); |
|---|
| 273 | }, |
|---|
| 274 | accessors => { |
|---|
| 275 | $main::ID_EXIF_CREATE_DATE => |
|---|
| 276 | sub { $self->imagelist->current_image->create_date }, |
|---|
| 277 | $main::ID_EXIF_MODEL => |
|---|
| 278 | sub { $self->imagelist->current_image->exif_tag('Model') }, |
|---|
| 279 | $main::ID_EXIF_WIDTH => |
|---|
| 280 | sub { $self->imagelist->current_image->exif_tag('ImageWidth') }, |
|---|
| 281 | $main::ID_EXIF_HEIGHT => |
|---|
| 282 | sub { $self->imagelist->current_image->exif_tag('ImageHeight') }, |
|---|
| 283 | $main::ID_EXIF_ORIENTATION => |
|---|
| 284 | sub { $self->imagelist->current_image->exif_tag('Orientation') }, |
|---|
| 285 | $main::ID_EXIF_ISO => |
|---|
| 286 | sub { $self->imagelist->current_image->exif_tag('ISO') }, |
|---|
| 287 | $main::ID_EXIF_SHUTTER_SPEED => |
|---|
| 288 | sub { $self->imagelist->current_image->exif_tag('ExposureTime') }, |
|---|
| 289 | $main::ID_EXIF_APERTURE => |
|---|
| 290 | sub { $self->imagelist->current_image->exif_tag('ApertureValue') }, |
|---|
| 291 | $main::ID_EXIF_FOCAL_LENGTH => |
|---|
| 292 | sub { $self->imagelist->current_image->exif_tag('FocalLength') }, |
|---|
| 293 | $main::ID_EXIF_LENS => |
|---|
| 294 | sub { $self->imagelist->current_image->exif_tag('Lens') }, |
|---|
| 295 | }, |
|---|
| 296 | } |
|---|
| 297 | ) |
|---|
| 298 | ); |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | $self->imageviewer->Show(0); |
|---|
| 302 | |
|---|
| 303 | $self->imageviewer->SetDropTarget( |
|---|
| 304 | DNDImageListDropTarget->new( |
|---|
| 305 | $self->imageviewer |
|---|
| 306 | ) |
|---|
| 307 | ); |
|---|
| 308 | $self->htmlhome->SetDropTarget( |
|---|
| 309 | DNDImageListDropTarget->new( |
|---|
| 310 | $self->imageviewer |
|---|
| 311 | ) |
|---|
| 312 | ); |
|---|
| 313 | |
|---|
| 314 | $self->manager->AddPane |
|---|
| 315 | ( $self->create_notebook_imagelist, Wx::AuiPaneInfo->new->Name( "ImageViewer" ) |
|---|
| 316 | ->CenterPane->Resizable->CloseButton(0) ); |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | $self->manager->AddPane |
|---|
| 320 | ( $self->create_tree, Wx::AuiPaneInfo->new->Name( "categories" )->Caption( |
|---|
| 321 | sprintf("Piwigo categories - %s", wxTheApp->site_url ) |
|---|
| 322 | ) |
|---|
| 323 | ->Right->Position( 0 )->Resizable->CloseButton(0) ); |
|---|
| 324 | |
|---|
| 325 | $self->tree->SetDropTarget( |
|---|
| 326 | DNDCategoryTreeDropTarget->new( |
|---|
| 327 | $self->tree |
|---|
| 328 | ) |
|---|
| 329 | ); |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | $self->manager->AddPane |
|---|
| 333 | ( $self->create_notebook_image_properties, Wx::AuiPaneInfo->new->Name( "photo_properties" )->Caption("Photo properties") |
|---|
| 334 | ->Right->Position( 1 )->Resizable->CloseButton(0) ); |
|---|
| 335 | |
|---|
| 336 | $self->manager->AddPane |
|---|
| 337 | ( $self->create_notebook_global_settings, Wx::AuiPaneInfo->new->Name( "global_settings" ) |
|---|
| 338 | ->Right->Position( 2 )->Resizable->CloseButton(1) ); |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | my $tb = $self->create_toolbar; |
|---|
| 343 | |
|---|
| 344 | $self->manager->AddPane |
|---|
| 345 | ( $tb, Wx::AuiPaneInfo->new->Name( "tb1" )->Caption( "Tools" ) |
|---|
| 346 | ->ToolbarPane->Top->Row( 1 )->LeftDockable( 0 )->RightDockable( 0 ) ) if defined $tb; |
|---|
| 347 | |
|---|
| 348 | $self->manager->Update; |
|---|
| 349 | |
|---|
| 350 | if( $self->imagelist->wx_thumb_imglist->GetImageCount){ |
|---|
| 351 | $self->ShowImageViewer; |
|---|
| 352 | |
|---|
| 353 | $self->imageviewer->Refresh( |
|---|
| 354 | $self->imagelist->wx_thumb_imglist |
|---|
| 355 | ); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | sub OnGlobalSettings { |
|---|
| 362 | my ( $self ) = @_; |
|---|
| 363 | |
|---|
| 364 | $self->manager->GetPane("global_settings")->Show(1); |
|---|
| 365 | $self->manager->Update(); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | sub create_notebook_imagelist { |
|---|
| 370 | my( $self ) = @_; |
|---|
| 371 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [300, 450], |
|---|
| 372 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
|---|
| 373 | my $pages = [ |
|---|
| 374 | [ |
|---|
| 375 | $self->htmlhome, |
|---|
| 376 | "Photo selection", |
|---|
| 377 | '../res/images.png', |
|---|
| 378 | wxBITMAP_TYPE_PNG, |
|---|
| 379 | ], |
|---|
| 380 | #[ |
|---|
| 381 | # $self->logwnd( $self->_create_textctrl( $book, undef, [450, 450] )), |
|---|
| 382 | # "Log", |
|---|
| 383 | # '../res/nb_log.png', |
|---|
| 384 | # wxBITMAP_TYPE_PNG, |
|---|
| 385 | #] |
|---|
| 386 | ]; |
|---|
| 387 | |
|---|
| 388 | $self->_populate_notebook( $book, $pages ); |
|---|
| 389 | |
|---|
| 390 | $self->logwnd(Wx::LogTextCtrl->new( $self->logwnd )); |
|---|
| 391 | $self->oldlogwnd( Wx::Log::SetActiveTarget( $self->logwnd ) ); |
|---|
| 392 | $self->notebook($book); |
|---|
| 393 | return $book; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | sub create_notebook_image_properties { |
|---|
| 397 | my( $self ) = @_; |
|---|
| 398 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
|---|
| 399 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
|---|
| 400 | my $pages = [ |
|---|
| 401 | [ |
|---|
| 402 | $self->image_prop_general, |
|---|
| 403 | "Piwigo", |
|---|
| 404 | ], |
|---|
| 405 | [ |
|---|
| 406 | $self->image_prop_exif, |
|---|
| 407 | "Exif", |
|---|
| 408 | ], |
|---|
| 409 | ]; |
|---|
| 410 | |
|---|
| 411 | $self->_populate_notebook( $book, $pages ); |
|---|
| 412 | |
|---|
| 413 | $self->notebook_image_properties($book); |
|---|
| 414 | |
|---|
| 415 | return $book; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | sub create_notebook_global_settings { |
|---|
| 419 | my( $self ) = @_; |
|---|
| 420 | my $book = Wx::AuiNotebook->new( $self, -1, [-1, -1], [450, 450], |
|---|
| 421 | wxBORDER_NONE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT); |
|---|
| 422 | my $pages = [ |
|---|
| 423 | [ |
|---|
| 424 | $self->global_settings_panel, |
|---|
| 425 | "Global settings", |
|---|
| 426 | ], |
|---|
| 427 | ]; |
|---|
| 428 | |
|---|
| 429 | $self->_populate_notebook( $book, $pages ); |
|---|
| 430 | |
|---|
| 431 | $self->notebook_image_properties($book); |
|---|
| 432 | |
|---|
| 433 | return $book; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | sub create_global_settings_panel { |
|---|
| 437 | my ( $self ) = @_; |
|---|
| 438 | |
|---|
| 439 | Uploader::GUI::wxGlobalSettingsPanel->new( |
|---|
| 440 | { |
|---|
| 441 | parentwnd => $self, |
|---|
| 442 | accessors => { |
|---|
| 443 | $main::ID_GLOBAL_NAME_PREFIX => |
|---|
| 444 | sub { $self->imagelist->default_name_prefix(@_) }, |
|---|
| 445 | $main::ID_GLOBAL_AUTHOR => |
|---|
| 446 | sub { $self->imagelist->author(@_) }, |
|---|
| 447 | $main::ID_GLOBAL_THUMB_SIZE => |
|---|
| 448 | sub { $self->imagelist->thumb_size(@_) }, |
|---|
| 449 | $main::ID_GLOBAL_RESIZED_W => |
|---|
| 450 | sub { $self->imagelist->resize_w(@_) }, |
|---|
| 451 | $main::ID_GLOBAL_RESIZED_H => |
|---|
| 452 | sub { $self->imagelist->resize_h(@_) }, |
|---|
| 453 | $main::ID_GLOBAL_HIGH => |
|---|
| 454 | sub { $self->imagelist->upload_high(@_)}, |
|---|
| 455 | }, |
|---|
| 456 | frame_callbacks => { |
|---|
| 457 | }, |
|---|
| 458 | } |
|---|
| 459 | ); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | sub create_tree { |
|---|
| 463 | my ( $self ) = @_; |
|---|
| 464 | |
|---|
| 465 | my $images = [ |
|---|
| 466 | map { |
|---|
| 467 | Wx::Bitmap->new( $_, wxBITMAP_TYPE_PNG ) |
|---|
| 468 | |
|---|
| 469 | } |
|---|
| 470 | ( |
|---|
| 471 | '../res/tree_pwg.png', |
|---|
| 472 | '../res/tree_folder.png', |
|---|
| 473 | ) |
|---|
| 474 | ]; |
|---|
| 475 | |
|---|
| 476 | $self->treeimglist( Wx::ImageList->new( 16, 16, 1 ) ); |
|---|
| 477 | map { |
|---|
| 478 | $self->treeimglist->Add($_); |
|---|
| 479 | } |
|---|
| 480 | @$images; |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | $self->tree( |
|---|
| 484 | Wx::TreeCtrl->new( |
|---|
| 485 | $self, |
|---|
| 486 | -1, |
|---|
| 487 | wxDefaultPosition, |
|---|
| 488 | wxDefaultSize, |
|---|
| 489 | wxBORDER_NONE| |
|---|
| 490 | wxCLIP_CHILDREN| |
|---|
| 491 | # wxTR_MULTIPLE| |
|---|
| 492 | # wxTR_EXTENDED| |
|---|
| 493 | wxTR_HAS_BUTTONS |
|---|
| 494 | # wxTR_HIDE_ROOT |
|---|
| 495 | ) |
|---|
| 496 | ); |
|---|
| 497 | |
|---|
| 498 | $self->tree->SetImageList( $self->treeimglist ); |
|---|
| 499 | $self->populate_tree_categories; |
|---|
| 500 | $self->tree ; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | sub populate_tree_categories { |
|---|
| 505 | my ( $self ) = @_; |
|---|
| 506 | |
|---|
| 507 | $self->populate_tree( |
|---|
| 508 | $self->tree, |
|---|
| 509 | wxTheApp->pwg->categories, |
|---|
| 510 | ) if defined wxTheApp->pwg ; |
|---|
| 511 | |
|---|
| 512 | $self->tree->ExpandAll; |
|---|
| 513 | |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | #$tree_items is a list of anonymous arrays |
|---|
| 517 | # [ itemLabel, undef, rootInfo, ImageIndex, SelImageIndex ] for the root |
|---|
| 518 | |
|---|
| 519 | # [ itemLabel, |
|---|
| 520 | # [ childItemLabel, |
|---|
| 521 | # [...], |
|---|
| 522 | # childItemdata, |
|---|
| 523 | # childImageIndex, |
|---|
| 524 | # childSelImageIndex |
|---|
| 525 | # ], |
|---|
| 526 | # Itemdata, |
|---|
| 527 | # ImageIndex, |
|---|
| 528 | # SelImageIndex |
|---|
| 529 | # ] |
|---|
| 530 | |
|---|
| 531 | # returns a valid itemData |
|---|
| 532 | sub itemData { Wx::TreeItemData->new( $_[0] ) } |
|---|
| 533 | |
|---|
| 534 | sub populate_tree { |
|---|
| 535 | my ( $self, $tree, $tree_items ) = @_; |
|---|
| 536 | my $root = shift @{$tree_items}; |
|---|
| 537 | $self->tree_root( |
|---|
| 538 | $tree->AddRoot( |
|---|
| 539 | $root->[0], |
|---|
| 540 | $root->[3], |
|---|
| 541 | $root->[4], |
|---|
| 542 | itemData( $root->[2] ) |
|---|
| 543 | ) |
|---|
| 544 | ); |
|---|
| 545 | |
|---|
| 546 | $self->populate_tree_helper( $tree, $self->tree_root, $tree_items ); |
|---|
| 547 | |
|---|
| 548 | $tree->Expand( $self->tree_root ); |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | sub populate_tree_helper { |
|---|
| 552 | my ( $self, $tree, $parent_id, $tree_items ) = @_; |
|---|
| 553 | |
|---|
| 554 | my $id; |
|---|
| 555 | |
|---|
| 556 | map { |
|---|
| 557 | my $name = $_->[0]; |
|---|
| 558 | eval { |
|---|
| 559 | $name = is_utf8($name) ? decode('UTF-8', $name) : $name; |
|---|
| 560 | }; |
|---|
| 561 | if($@){ |
|---|
| 562 | $name = $_->[0]; |
|---|
| 563 | } |
|---|
| 564 | $id = $tree->AppendItem( |
|---|
| 565 | $parent_id, |
|---|
| 566 | $name, |
|---|
| 567 | defined($_->[3]) ? $_->[3] : 0, |
|---|
| 568 | defined($_->[4]) ? $_->[4] : 0, |
|---|
| 569 | itemData( $_->[2]) |
|---|
| 570 | ); |
|---|
| 571 | $self->tree_item_default($id) if ! defined $self->tree_item_default; |
|---|
| 572 | # current item has children |
|---|
| 573 | if( ref( $_->[1] ) eq 'ARRAY' ) { |
|---|
| 574 | $self->populate_tree_helper( $tree, $id, $_->[1] ); |
|---|
| 575 | } |
|---|
| 576 | } |
|---|
| 577 | @{$tree_items}; |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | sub _populate_notebook { |
|---|
| 586 | my ( $self, $book, $pages, $position ) = @_; |
|---|
| 587 | |
|---|
| 588 | my $i = 0; |
|---|
| 589 | map { |
|---|
| 590 | my $icon = Wx::Icon->new(); |
|---|
| 591 | eval { $icon->LoadFile($_->[2], $_->[3]) ; } |
|---|
| 592 | if defined $_->[2]; |
|---|
| 593 | my $nb_icon = Wx::Bitmap->new( $icon ); |
|---|
| 594 | defined $position ? |
|---|
| 595 | $book->InsertPage($position, $_->[0], |
|---|
| 596 | $_->[1], 1, $nb_icon ) |
|---|
| 597 | : |
|---|
| 598 | $book->AddPage($_->[0], |
|---|
| 599 | $_->[1], 0, $nb_icon ); |
|---|
| 600 | |
|---|
| 601 | $i++; |
|---|
| 602 | } @$pages; |
|---|
| 603 | |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | sub _InitEventHandlers { |
|---|
| 609 | my ( $self ) = @_ ; |
|---|
| 610 | |
|---|
| 611 | Wx::Event::EVT_MENU( $self, 101, \&OnAddImages ); |
|---|
| 612 | Wx::Event::EVT_MENU( $self, 102, \&OnRemoveImages ); |
|---|
| 613 | Wx::Event::EVT_MENU( $self, 103, \&OnUploadImages ); |
|---|
| 614 | Wx::Event::EVT_MENU( $self, 104, \&OnGlobalSettings ); |
|---|
| 615 | EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged ); |
|---|
| 616 | EVT_TREE_ITEM_RIGHT_CLICK( $self->tree, $self->tree, \&OnTreeItemRightClick ); |
|---|
| 617 | EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit ); |
|---|
| 618 | EVT_LIST_ITEM_SELECTED($self, $self->imageviewer, \&OnImageViewerItemSelected) ; |
|---|
| 619 | EVT_LIST_KEY_DOWN($self, $self->imageviewer, \&OnImageViewerKeyDown) ; |
|---|
| 620 | EVT_CLOSE( $self, \&OnClose ); |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories ); |
|---|
| 624 | Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories ); |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | { |
|---|
| 628 | my $prevdir; |
|---|
| 629 | my $prevfile; |
|---|
| 630 | |
|---|
| 631 | sub OnAddImages { |
|---|
| 632 | my( $self, $event ) = @_; |
|---|
| 633 | my $dialog = Wx::FileDialog->new |
|---|
| 634 | ( $self, "Select photos to send", $prevfile, $prevdir, |
|---|
| 635 | "JPEG files (*.jpg)|*.jpg|All(*.*)|*.*", |
|---|
| 636 | wxFD_OPEN|wxFD_MULTIPLE ); |
|---|
| 637 | |
|---|
| 638 | my $file_paths = []; |
|---|
| 639 | if( $dialog->ShowModal != wxID_CANCEL ) { |
|---|
| 640 | @$file_paths = $dialog->GetPaths; |
|---|
| 641 | $self->SetNewFiles($file_paths) ; |
|---|
| 642 | } |
|---|
| 643 | $dialog->Destroy; |
|---|
| 644 | $event->Skip; |
|---|
| 645 | } |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | sub OnRemoveImages { |
|---|
| 649 | my( $self, $event ) = @_; |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | $self->imagelist->RemoveImageSelection; |
|---|
| 653 | $self->imageviewer->Refresh; |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | sub SetNewFiles { |
|---|
| 657 | my ( $self, $file_paths ) = @_; |
|---|
| 658 | |
|---|
| 659 | $self->ShowImageViewer(); |
|---|
| 660 | $self->progressdlg( |
|---|
| 661 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
|---|
| 662 | { |
|---|
| 663 | title => "Image processing progress information", |
|---|
| 664 | bt_label => "Cancel image processing", |
|---|
| 665 | } |
|---|
| 666 | ) |
|---|
| 667 | ); |
|---|
| 668 | $self->progressdlg->Show(1); |
|---|
| 669 | Wx::Yield(); |
|---|
| 670 | |
|---|
| 671 | $self->imagelist->SetNewFiles( |
|---|
| 672 | $file_paths |
|---|
| 673 | ); |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | sub OnTreeSelChanged { |
|---|
| 679 | my( $self, $event ) = @_; |
|---|
| 680 | |
|---|
| 681 | my @items = $self->tree->GetSelections; |
|---|
| 682 | |
|---|
| 683 | $self->imagelist->categories( |
|---|
| 684 | [ |
|---|
| 685 | map { |
|---|
| 686 | my $category = $self->tree->GetPlData( $_ ); |
|---|
| 687 | $category->{id} if $category != -1; |
|---|
| 688 | } |
|---|
| 689 | @items |
|---|
| 690 | ] |
|---|
| 691 | ); |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | sub OnTreeItemRightClick { |
|---|
| 695 | my( $self, $event ) = @_; |
|---|
| 696 | |
|---|
| 697 | my $point = $event->GetPoint ; |
|---|
| 698 | my $ctx_mnu = Wx::Menu->new; |
|---|
| 699 | |
|---|
| 700 | map { |
|---|
| 701 | $ctx_mnu->Append( |
|---|
| 702 | @$_ |
|---|
| 703 | ); |
|---|
| 704 | } |
|---|
| 705 | ( |
|---|
| 706 | [1+$ID_TREE_CTX_MENU, "Add new category","Add a new category to the current selected category."], |
|---|
| 707 | [2+$ID_TREE_CTX_MENU, "Refresh","Refresh category list."], |
|---|
| 708 | ); |
|---|
| 709 | $self->PopupMenu($ctx_mnu, $point); |
|---|
| 710 | |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | sub OnAddCategories { |
|---|
| 714 | my ( $self, $event ) = @_; |
|---|
| 715 | |
|---|
| 716 | my $item = $self->tree->GetSelection; |
|---|
| 717 | |
|---|
| 718 | my $category = $self->tree->GetPlData($item); |
|---|
| 719 | my $category_id; |
|---|
| 720 | |
|---|
| 721 | $category_id = $category->{id} if 'HASH' eq ref($category) ; |
|---|
| 722 | |
|---|
| 723 | my $dialog = Wx::TextEntryDialog->new( |
|---|
| 724 | $self, |
|---|
| 725 | "Category name :", |
|---|
| 726 | "Add new category", |
|---|
| 727 | "New category" |
|---|
| 728 | ); |
|---|
| 729 | |
|---|
| 730 | if( $dialog->ShowModal != wxID_CANCEL ) { |
|---|
| 731 | my $name = $dialog->GetValue; |
|---|
| 732 | my ( $status, $status_msg ) = $self->pwg->AddCategories( $name, $category_id); |
|---|
| 733 | $self->_refresh_tree_categories_helper; |
|---|
| 734 | } |
|---|
| 735 | $dialog->Destroy; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | sub OnRefreshCategories { |
|---|
| 739 | my ( $self, $event ) = @_; |
|---|
| 740 | |
|---|
| 741 | $self->_refresh_tree_categories_helper; |
|---|
| 742 | } |
|---|
| 743 | |
|---|
| 744 | sub _refresh_tree_categories_helper { |
|---|
| 745 | my ( $self ) = @_; |
|---|
| 746 | |
|---|
| 747 | my $busycursor = Wx::BusyCursor->new(); |
|---|
| 748 | $self->tree->CollapseAll; |
|---|
| 749 | $self->tree->DeleteAllItems; |
|---|
| 750 | $self->imagelist->categories([]); |
|---|
| 751 | $self->pwg->RefreshCategories(); |
|---|
| 752 | $self->populate_tree_categories; |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | sub OnImageViewerEndLabelEdit { |
|---|
| 756 | my( $self, $event ) = @_; |
|---|
| 757 | |
|---|
| 758 | my $image = $self->imagelist->images->[$event->GetIndex]; |
|---|
| 759 | $image->site_name( |
|---|
| 760 | $event->GetLabel |
|---|
| 761 | ); |
|---|
| 762 | |
|---|
| 763 | $self->image_prop_general->SetControlValues(); |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | sub OnImageViewerItemSelected { |
|---|
| 768 | my( $self, $event ) = @_; |
|---|
| 769 | |
|---|
| 770 | my $indx = $event->GetIndex; |
|---|
| 771 | |
|---|
| 772 | # retrieve photo info for the last selected photo |
|---|
| 773 | $self->imagelist->SetCurrentImage($indx); |
|---|
| 774 | |
|---|
| 775 | $self->imagelist->image_selection( |
|---|
| 776 | $self->imageviewer->GetSelectedItems |
|---|
| 777 | ); |
|---|
| 778 | |
|---|
| 779 | $self->image_prop_general->SetControlValues(); |
|---|
| 780 | $self->image_prop_exif->SetControlValues(); |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | sub OnImageViewerKeyDown { |
|---|
| 784 | my( $self, $event ) = @_; |
|---|
| 785 | |
|---|
| 786 | if(WXK_DELETE == $event->GetKeyCode){ |
|---|
| 787 | $self->OnRemoveImages(); |
|---|
| 788 | } |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | sub OnUploadImages { |
|---|
| 792 | my( $self, $event ) = @_; |
|---|
| 793 | |
|---|
| 794 | # eval { |
|---|
| 795 | $self->ProcessImageSelection(); |
|---|
| 796 | # }; |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | # remove image from imagelist when uploaded |
|---|
| 800 | sub UploadImagesViewerRefresh { |
|---|
| 801 | my ( $self ) = @_; |
|---|
| 802 | |
|---|
| 803 | my $imagelist= $self->imagelist ; |
|---|
| 804 | |
|---|
| 805 | Wx::Yield(); |
|---|
| 806 | } |
|---|
| 807 | |
|---|
| 808 | sub UploadProgressMessageRefresh { |
|---|
| 809 | my ( $self, $msg ) = @_; |
|---|
| 810 | |
|---|
| 811 | $self->upload_progressdlg->processing( |
|---|
| 812 | $msg |
|---|
| 813 | ); |
|---|
| 814 | |
|---|
| 815 | Wx::Yield(); |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | sub UploadProgressThumbnailRefresh { |
|---|
| 819 | my ( $self ) = @_; |
|---|
| 820 | |
|---|
| 821 | my $imagelist = $self->imagelist ; |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | $self->upload_progressdlg->image->SetBitmap(wxNullBitmap); |
|---|
| 825 | $self->upload_progressdlg->image->SetBitmap( |
|---|
| 826 | Wx::Bitmap->new( |
|---|
| 827 | $self->imagelist->current_image->wx_thumb_file, |
|---|
| 828 | $self->GetWxBitmapType($self->imagelist->type), |
|---|
| 829 | ) |
|---|
| 830 | ); |
|---|
| 831 | |
|---|
| 832 | Wx::Yield(); |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | sub UploadProgressBarRefresh { |
|---|
| 836 | my ( $self, $ratio ) = @_; |
|---|
| 837 | |
|---|
| 838 | $ratio = $self->imagelist->count > 1 ? 1 : $ratio; |
|---|
| 839 | eval { |
|---|
| 840 | $self->upload_progressdlg->progress( |
|---|
| 841 | $ratio*$self->imagelist->count * ( 100/scalar @{$self->imagelist->image_selection} ) |
|---|
| 842 | ); |
|---|
| 843 | $self->upload_progressdlg->LogProgress(); |
|---|
| 844 | }; |
|---|
| 845 | croak "Upload cancelled" if $@; |
|---|
| 846 | |
|---|
| 847 | Wx::Yield(); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | sub SetNewFilesDisplayEndInfo { |
|---|
| 851 | my ( $self, $msg ) = @_; |
|---|
| 852 | |
|---|
| 853 | $self->progressdlg->DisplayEndInfo($msg); |
|---|
| 854 | } |
|---|
| 855 | |
|---|
| 856 | sub UploadDisplayEndInfo { |
|---|
| 857 | my ( $self, $msg ) = @_; |
|---|
| 858 | |
|---|
| 859 | my $imagelist = $self->imagelist ; |
|---|
| 860 | |
|---|
| 861 | $self->upload_progressdlg->DisplayEndInfo($msg); |
|---|
| 862 | } |
|---|
| 863 | |
|---|
| 864 | sub ShowImageViewer { |
|---|
| 865 | my ( $self ) = @_; |
|---|
| 866 | |
|---|
| 867 | if(!$self->imageviewer->IsShown){ |
|---|
| 868 | my $imglistpage = [ |
|---|
| 869 | [ |
|---|
| 870 | $self->imageviewer, |
|---|
| 871 | "Photo selection", |
|---|
| 872 | '../res/images.png', |
|---|
| 873 | wxBITMAP_TYPE_PNG, |
|---|
| 874 | ], |
|---|
| 875 | ]; |
|---|
| 876 | $self->notebook->DeletePage(0); |
|---|
| 877 | |
|---|
| 878 | $self->imageviewer->Show(1); |
|---|
| 879 | $self->_populate_notebook($self->notebook, $imglistpage, 0); |
|---|
| 880 | # load imagelist with loading.jpg |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | sub SetNewFilesViewerRefresh { |
|---|
| 889 | |
|---|
| 890 | my ( $self ) = @_; |
|---|
| 891 | |
|---|
| 892 | my $wximagelist = $self->imagelist->wx_thumb_imglist; |
|---|
| 893 | |
|---|
| 894 | my $indx = $wximagelist->Add( |
|---|
| 895 | Wx::Bitmap->new( |
|---|
| 896 | $self->imagelist->current_image->wx_thumb_file, |
|---|
| 897 | $self->GetWxBitmapType($self->imagelist->type), |
|---|
| 898 | ) |
|---|
| 899 | ) if defined $self->imagelist->current_image->wx_thumb_file; |
|---|
| 900 | |
|---|
| 901 | $self->imageviewer->Refresh( |
|---|
| 902 | $wximagelist |
|---|
| 903 | ); |
|---|
| 904 | |
|---|
| 905 | Wx::Yield(); |
|---|
| 906 | } |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | # prepare and upload image_selection |
|---|
| 911 | sub ProcessImageSelection { |
|---|
| 912 | my ( $self ) = @_; |
|---|
| 913 | |
|---|
| 914 | return if !scalar @{$self->imagelist->images}; |
|---|
| 915 | |
|---|
| 916 | if( scalar @{$self->imagelist->categories} ){ |
|---|
| 917 | return if( !defined $self->imagelist->image_selection ); |
|---|
| 918 | return if( !scalar @{$self->imagelist->image_selection} ); |
|---|
| 919 | |
|---|
| 920 | $self->upload_progressdlg( |
|---|
| 921 | Uploader::GUI::wxImageProcessingProgressDlg->new( |
|---|
| 922 | { |
|---|
| 923 | title => "Image upload progress information", |
|---|
| 924 | bt_label => "Cancel upload", |
|---|
| 925 | } |
|---|
| 926 | ) |
|---|
| 927 | ); |
|---|
| 928 | # modeless dialog |
|---|
| 929 | $self->upload_progressdlg->Show(1); |
|---|
| 930 | Wx::Yield(); |
|---|
| 931 | eval { |
|---|
| 932 | $self->imagelist->UploadSelection; |
|---|
| 933 | }; |
|---|
| 934 | if($@){ |
|---|
| 935 | Wx::MessageBox( |
|---|
| 936 | sprintf( |
|---|
| 937 | "Upload cancelled.", |
|---|
| 938 | ), |
|---|
| 939 | "Piwigo upload information", |
|---|
| 940 | wxOK | wxICON_INFORMATION, |
|---|
| 941 | ); |
|---|
| 942 | } |
|---|
| 943 | } |
|---|
| 944 | else { |
|---|
| 945 | Wx::MessageBox( |
|---|
| 946 | sprintf( |
|---|
| 947 | "Please select a valid target category", |
|---|
| 948 | ), |
|---|
| 949 | "Piwigo upload error", |
|---|
| 950 | wxOK | wxICON_EXCLAMATION, |
|---|
| 951 | ); |
|---|
| 952 | } |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | sub SetNewFilesProgress { |
|---|
| 957 | my ( $self ) = @_; |
|---|
| 958 | |
|---|
| 959 | my $imagelist = $self->imagelist; |
|---|
| 960 | |
|---|
| 961 | $self->progressdlg->processing( |
|---|
| 962 | sprintf( |
|---|
| 963 | $imagelist->progress_msg, |
|---|
| 964 | $imagelist->current_image->file, |
|---|
| 965 | ) |
|---|
| 966 | ); |
|---|
| 967 | |
|---|
| 968 | eval { |
|---|
| 969 | $self->progressdlg->image->SetSize([ $imagelist->wx_thumb_size, $imagelist->wx_thumb_size]); |
|---|
| 970 | $self->progressdlg->image->SetBitmap(wxNullBitmap); |
|---|
| 971 | $self->progressdlg->image->SetBitmap( |
|---|
| 972 | Wx::Bitmap->new( |
|---|
| 973 | $imagelist->current_image->wx_thumb_file, |
|---|
| 974 | $self->GetWxBitmapType( $imagelist->type ) |
|---|
| 975 | ) |
|---|
| 976 | ); |
|---|
| 977 | $self->progressdlg->progress( |
|---|
| 978 | $imagelist->count * ( 100/scalar @{$imagelist->new_files} ) |
|---|
| 979 | ); |
|---|
| 980 | $self->progressdlg->LogProgress(); |
|---|
| 981 | }; |
|---|
| 982 | Wx::Yield(); |
|---|
| 983 | } |
|---|
| 984 | |
|---|
| 985 | sub OnClose { |
|---|
| 986 | my $self = shift; |
|---|
| 987 | |
|---|
| 988 | # Restaure previous log wnd |
|---|
| 989 | Wx::Log::SetActiveTarget( $self->oldlogwnd ); |
|---|
| 990 | |
|---|
| 991 | # allways store |
|---|
| 992 | |
|---|
| 993 | wxTheApp->StoreConnectionProperties; |
|---|
| 994 | |
|---|
| 995 | $self->imagelist->Store; |
|---|
| 996 | $self->Destroy; |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | |
|---|
| 1000 | sub create_toolbar { |
|---|
| 1001 | my( $self ) = @_; |
|---|
| 1002 | |
|---|
| 1003 | my $tb = Wx::ToolBar->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT ); |
|---|
| 1004 | $tb->SetToolBitmapSize( wxSIZE( 32, 32 ) ); |
|---|
| 1005 | map { |
|---|
| 1006 | my $icon1 = Wx::Icon->new(); |
|---|
| 1007 | eval { |
|---|
| 1008 | $icon1->LoadFile($_->[2], $_->[3]); |
|---|
| 1009 | }; |
|---|
| 1010 | my $tb_icon1 = Wx::Bitmap->new( $icon1 ); |
|---|
| 1011 | |
|---|
| 1012 | my $icon2 = Wx::Icon->new(); |
|---|
| 1013 | eval { |
|---|
| 1014 | $icon2->LoadFile($_->[5], $_->[3]); |
|---|
| 1015 | }; |
|---|
| 1016 | my $tb_icon2 = Wx::Bitmap->new( $icon2 ); |
|---|
| 1017 | |
|---|
| 1018 | |
|---|
| 1019 | $tb->AddTool( $_->[0], $_->[1], $tb_icon1, $tb_icon2, wxITEM_NORMAL, $_->[1] ); |
|---|
| 1020 | $tb->EnableTool( $_->[0], $_->[4]); |
|---|
| 1021 | } |
|---|
| 1022 | ( |
|---|
| 1023 | [ |
|---|
| 1024 | 101, "Add photo to selection", '../res/tb_add.png', wxBITMAP_TYPE_PNG, 1, '../res/tb_add.png', "Add photo to selection for resizing and uploading" |
|---|
| 1025 | ], |
|---|
| 1026 | [ |
|---|
| 1027 | 102, "Remove photo from selection", '../res/tb_remove.png', wxBITMAP_TYPE_PNG, 1, '../res/tb_remove.png',"Remove photo from selection. Files are not deleted " |
|---|
| 1028 | ], |
|---|
| 1029 | [ |
|---|
| 1030 | 103, "Upload to Piwigo", '../res/tb_upload.png', wxBITMAP_TYPE_PNG, 1, '../res/tb_upload.png',"Upload photos to Piwigo." |
|---|
| 1031 | ], |
|---|
| 1032 | [ |
|---|
| 1033 | 104, "Global settings", '../res/tb_settings.png', wxBITMAP_TYPE_PNG, 1, '../res/tb_settings.png',"Change global settings." |
|---|
| 1034 | ], |
|---|
| 1035 | |
|---|
| 1036 | ); |
|---|
| 1037 | |
|---|
| 1038 | if($@){ |
|---|
| 1039 | undef $tb; |
|---|
| 1040 | } |
|---|
| 1041 | else{ |
|---|
| 1042 | $tb->Realize; |
|---|
| 1043 | } |
|---|
| 1044 | |
|---|
| 1045 | return $tb; |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | |
|---|
| 1049 | sub _create_textctrl { |
|---|
| 1050 | my( $self, $parent, $text, $size ) = @_; |
|---|
| 1051 | |
|---|
| 1052 | return Wx::TextCtrl->new( $parent, -1, $text, [0, 0], $size, |
|---|
| 1053 | wxNO_BORDER | wxTE_MULTILINE | wxTE_READONLY ); |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | sub create_textctrl { |
|---|
| 1057 | my( $self, $text, $size ) = @_; |
|---|
| 1058 | |
|---|
| 1059 | return $self->_create_textctrl( $self, $text, $size ); |
|---|
| 1060 | } |
|---|
| 1061 | |
|---|
| 1062 | sub DESTROY { |
|---|
| 1063 | my( $self ) = @_; |
|---|
| 1064 | |
|---|
| 1065 | $self->manager->UnInit; |
|---|
| 1066 | } |
|---|
| 1067 | |
|---|
| 1068 | |
|---|
| 1069 | |
|---|
| 1070 | 1; |
|---|
| 1071 | |
|---|
| 1072 | |
|---|
| 1073 | |
|---|
| 1074 | |
|---|
| 1075 | |
|---|
| 1076 | package DNDImageListDropTarget; |
|---|
| 1077 | |
|---|
| 1078 | use base qw(Wx::FileDropTarget Class::Accessor::Fast); |
|---|
| 1079 | |
|---|
| 1080 | __PACKAGE__->mk_accessors( |
|---|
| 1081 | qw/ |
|---|
| 1082 | imageviewer |
|---|
| 1083 | frame |
|---|
| 1084 | / |
|---|
| 1085 | ); |
|---|
| 1086 | |
|---|
| 1087 | sub new { |
|---|
| 1088 | my $class = shift; |
|---|
| 1089 | my $imageviewer = shift; |
|---|
| 1090 | my $self = $class->SUPER::new( @_ ); |
|---|
| 1091 | |
|---|
| 1092 | $self->imageviewer($imageviewer); |
|---|
| 1093 | $self->frame($imageviewer->GetParent); |
|---|
| 1094 | return $self; |
|---|
| 1095 | } |
|---|
| 1096 | |
|---|
| 1097 | sub OnDropFiles { |
|---|
| 1098 | my( $self, $x, $y, $files ) = @_; |
|---|
| 1099 | |
|---|
| 1100 | $self->frame->SetNewFiles($files) ; |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | 1; |
|---|
| 1104 | |
|---|
| 1105 | |
|---|
| 1106 | package DNDCategoryTreeDropTarget; |
|---|
| 1107 | |
|---|
| 1108 | use base qw(Wx::TextDropTarget Class::Accessor::Fast); |
|---|
| 1109 | use Data::Dumper; |
|---|
| 1110 | use Wx qw/ |
|---|
| 1111 | wxDragNone |
|---|
| 1112 | wxDragCopy |
|---|
| 1113 | wxDragMove |
|---|
| 1114 | /; |
|---|
| 1115 | |
|---|
| 1116 | __PACKAGE__->mk_accessors( |
|---|
| 1117 | qw/ |
|---|
| 1118 | tree |
|---|
| 1119 | frame |
|---|
| 1120 | / |
|---|
| 1121 | ); |
|---|
| 1122 | |
|---|
| 1123 | sub new { |
|---|
| 1124 | my ( $class, $tree ) = @_; |
|---|
| 1125 | my $self = $class->SUPER::new(); |
|---|
| 1126 | |
|---|
| 1127 | $self->tree($tree); |
|---|
| 1128 | $self->frame($tree->GetParent); |
|---|
| 1129 | return $self; |
|---|
| 1130 | } |
|---|
| 1131 | |
|---|
| 1132 | |
|---|
| 1133 | |
|---|
| 1134 | sub OnDropText { |
|---|
| 1135 | my( $self, $x, $y, $textdata ) = @_; |
|---|
| 1136 | |
|---|
| 1137 | # must be $VAR1 because $textdata is the result of Data::Dumper |
|---|
| 1138 | my $VAR1; |
|---|
| 1139 | eval $textdata; |
|---|
| 1140 | eval { |
|---|
| 1141 | if(scalar @$VAR1){ |
|---|
| 1142 | my @items; |
|---|
| 1143 | if(scalar @items < 2) { |
|---|
| 1144 | my ($dropItem, $flag) = $self->tree->HitTest([$x, $y]); |
|---|
| 1145 | push @items, $dropItem; |
|---|
| 1146 | } |
|---|
| 1147 | else { |
|---|
| 1148 | @items = $self->tree->GetSelections; |
|---|
| 1149 | } |
|---|
| 1150 | |
|---|
| 1151 | # remove root item which is not a valid category |
|---|
| 1152 | @items = grep { $self->tree->GetPlData( $_ ) != -1 } @items; |
|---|
| 1153 | |
|---|
| 1154 | $self->frame->imagelist->categories( |
|---|
| 1155 | [ |
|---|
| 1156 | map { |
|---|
| 1157 | $self->tree->GetPlData( $_ )->{id}; |
|---|
| 1158 | } |
|---|
| 1159 | @items |
|---|
| 1160 | ] |
|---|
| 1161 | ); |
|---|
| 1162 | |
|---|
| 1163 | $self->frame->imagelist->image_selection($VAR1); |
|---|
| 1164 | $self->frame->ProcessImageSelection ; |
|---|
| 1165 | } |
|---|
| 1166 | }; |
|---|
| 1167 | } |
|---|
| 1168 | |
|---|
| 1169 | 1; |
|---|