source: extensions/pLoader/trunk/src/Uploader/GUI/wxGlobalSettings.pm @ 4732

Last change on this file since 4732 was 4732, checked in by ronosman, 14 years ago

Bug fixed : Internal keys not set in Global settings.

File size: 7.8 KB
Line 
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# +-----------------------------------------------------------------------+
20package Uploader::GUI::wxGlobalSettings;
21use strict;
22use Wx qw/
23            wxDefaultSize
24            wxDefaultPosition
25            wxVERTICAL
26            wxDEFAULT_DIALOG_STYLE
27            wxCAPTION
28            wxCLOSE_BOX
29            wxMAXIMIZE_BOX
30            wxMINIMIZE_BOX
31            wxRESIZE_BORDER
32            wxSTAY_ON_TOP
33            wxALIGN_CENTER
34            wxALL
35            wxBK_DEFAULT
36            wxALIGN_CENTER_VERTICAL
37            wxGROW
38            wxALIGN_CENTER_VERTICAL
39            wxLI_HORIZONTAL
40            wxALIGN_BOTTOM
41            wxALIGN_CENTER_HORIZONTAL
42            wxBITMAP_TYPE_PNG
43            wxTheApp
44        /;
45use base qw/Wx::Dialog Uploader::GUI::DlgCommon/;
46use Wx::Locale qw/:default/;
47use Wx::Event qw/
48            EVT_CLOSE
49        /;
50
51use Carp;
52use Data::Dumper;
53
54sub new {
55    my ($this, $params) = @_;
56
57    my $class = ref($this) || $this;
58
59
60    my $self = $class->SUPER::new(
61        undef,
62        -1,
63        $params->{caption},
64        wxDefaultPosition,
65        wxDefaultSize,
66            wxCAPTION|
67            wxCLOSE_BOX|
68            wxMAXIMIZE_BOX|
69            wxMINIMIZE_BOX|
70            wxRESIZE_BORDER|
71            wxDEFAULT_DIALOG_STYLE|
72            wxSTAY_ON_TOP
73    );
74
75
76
77
78    $self->{tags} = $params->{tags};
79    $self->{orientation} = $params->{orientation}||wxVERTICAL;
80
81    # load controls
82    GlobalSetting_ToolBook($self, 1);
83
84    $self->properties(
85        $params->{properties}
86    );
87
88
89    $self->{cpane_thumbnail} = $self->FindWindow($main::CPANE_THUMBNAIL);
90    $self->{cpane_resize} = $self->FindWindow($main::CPANE_RESIZE);
91    $self->{cpane_resize_advanced} = $self->FindWindow($main::CPANE_RESIZE_ADVANCED);
92    $self->{cpane_hd} = $self->FindWindow($main::CPANE_HD);
93    $self->{cpane_hd_advanced} = $self->FindWindow($main::CPANE_HD_ADVANCED);
94    $self->{cpane_watermark} = $self->FindWindow($main::CPANE_WATERMARK);
95    $self->{cpane_transfert_advanced} = $self->FindWindow($main::CPANE_TRANSFERT_ADVANCED);
96    $self->{gs_close} = $self->FindWindow($main::GS_CLOSE);
97
98    $self->InitLabels();
99    $self->InitChoices();
100    $self->SetProperties();
101    $self->InitHandler();
102    $self->_initEventHandlers();
103
104    $self->_DefautPhotoCaption(
105        $main::GS_DEFAULT_PHOTO_CAPTION
106    );
107
108    if($@){
109        Wx::LogMessage("Error during dialogbox initialization");
110    }
111
112    $self;   
113}
114
115
116
117sub _initEventHandlers {
118    my ( $self ) = @_;
119   
120    Wx::Event::EVT_BUTTON( $self, $self->{gs_close}, \&OnClose );
121
122}
123
124
125sub OnClose {
126    my ( $self, $event ) = @_;
127   
128    $self->_close;
129}
130
131sub _close {
132    my ( $self ) = @_;
133
134
135    $self->Hide;
136}
137
138
139sub OnDefaultPhotoCaption {
140    my ( $self, $event ) = @_;
141   
142    $self->_DefautPhotoCaption(
143        $event->GetId
144    );
145
146    $event->Skip;
147}
148
149# Display prefix textfield when needed
150sub _DefautPhotoCaption {
151    my ( $self, $id ) = @_;
152
153    my $b=0;
154    if('CODE' eq ref $self->properties->{$id}->{string_selection}){
155        if ( $self->properties->{$id}
156            ->{string_selection}->() =~ /refix/ ){
157            $b=1;
158        }
159    }
160
161    map {
162        $self->FindWindow($_)->Show($b)
163    }(
164        $main::PHOTO_CAPTION_PREFIX,
165        $main::GS_PHOTO_CAPTION_PREFIX
166    );
167}
168
169sub OnCreateResized {
170    my ( $self, $event ) = @_;
171   
172    my $id = $event->GetId;
173    my $b = 1;
174    if('CODE' eq ref $self->properties->{$id}->{selection}){
175        $b = !$self->properties->{$id}->{selection}->()
176    }
177
178    $self->{cpane_resize}->Collapse($b);
179
180    $event->Skip;
181
182}
183
184
185sub OnHDUpload {
186    my ( $self, $event ) = @_;
187   
188
189    my $id = $event->GetId;
190    my $b = 1;
191    if('CODE' eq ref $self->properties->{$id}->{string_selection}){
192        if ( $self->properties->{$id}
193            ->{string_selection}->() =~ /resized/){
194            $b = 0;
195        }
196    }
197    $self->{cpane_hd}->Collapse($b);
198
199    $event->Skip;
200}
201
202sub OnWatermark {
203    my ( $self, $event ) = @_;
204   
205    my $id = $event->GetId;
206    my $b = 1;
207    if('CODE' eq ref $self->properties->{$id}->{value}){
208        $b = !$self->properties->{$id}->{value}->()
209    }
210
211    $self->{cpane_watermark}->Collapse($b);
212
213    $event->Skip;
214}
215
216
217sub GlobalSetting_ToolBook {
218    my( $parent ) = $_[0];
219    my( $item0 ) = Wx::BoxSizer->new( wxVERTICAL );
220   
221    my( $item2 ) = Wx::Toolbook->new( $parent, $main::ID_NOTEBOOK, wxDefaultPosition, [-1,-1], wxBK_DEFAULT  );
222    my( $item1 ) = $item2;
223    if( Wx->VERSION < 0.21 ) {
224        $item1 = Wx::NotebookSizer->new( $item2 );
225    }
226
227    my $imgl = Wx::ImageList->new( 16, 16 );
228
229    map {
230        $imgl->Add(
231            Wx::Bitmap->new( wxTheApp->resource_path($_), wxBITMAP_TYPE_PNG )
232        )
233    } qw/picture_edit.png pictures.png picture_key.png picture_go.png/;
234
235    $item2->AssignImageList($imgl);
236
237    my( $item3 ) = Wx::Panel->new( $item2, -1 );
238    &main::GS_photo_properties( $item3, 0 );
239    $item2->AddPage( $item3, gettext("Photo properties"), 0, 0 );
240
241    my( $item4 ) = Wx::Panel->new( $item2, -1 );
242    &main::GS_photo_preparation( $item4, 0 );
243    $item2->AddPage( $item4, gettext("Photo size"), 0, 1 );
244
245    my( $item5 ) = Wx::Panel->new( $item2, -1 );
246    &main::GS_photo_watermark( $item5, 0 );
247    $item2->AddPage( $item5, gettext("Watermark"), 0, 2 );
248
249    my( $item6 ) = Wx::Panel->new( $item2, -1 );
250    &main::GS_photo_transfer( $item6, 0 );
251    $item2->AddPage( $item6, gettext("Transfer"), 0, 3 );
252
253    $item0->Add( $item1, 0, wxALIGN_CENTER|wxALL, 5 );
254
255    my( $item87 ) = Wx::BoxSizer->new( wxVERTICAL );
256   
257    my( $item88 ) = Wx::StaticLine->new( $parent, -1, wxDefaultPosition, [20,-1], wxLI_HORIZONTAL );
258    $item87->AddWindow( $item88, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
259
260    my( $item89 ) = Wx::Button->new( $parent, $main::GS_CLOSE, gettext("Close"), wxDefaultPosition, wxDefaultSize, 0 );
261    $item87->AddWindow( $item89, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
262
263    $item0->Add( $item87, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
264
265
266    my( $set_size ) = @_ >= 3 ? $_[2] : 1;
267    my( $call_fit ) = @_ >= 2 ? $_[1] : 1;
268    if( $set_size == 1 ) {
269         $_[0]->SetSizer( $item0 );
270         
271         if( $call_fit == 1 ) {
272             $item0->SetSizeHints( $_[0] );
273         }
274    }
275   
276    $item0;
277}
278
279
2801;
Note: See TracBrowser for help on using the repository browser.