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

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

Change copyright notice to add 2010.

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