wxGUI.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary Wx.pm »
1 ########################################################################
2  
3 package __Aut__YesNo;
4  
5 0 ▶use Wx qw[:everything];
Subroutine BEGIN: called CC=1 SCAR=2.6
6 use base qw(Wx::Dialog);
7 use strict;
8 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
9  
10 use Locale::Framework;
11  
12 sub new {
13 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
14 $parent = undef unless defined $parent;
15 $id = -1 unless defined $id;
16 $title = "" unless defined $title;
17 $pos = wxDefaultPosition unless defined $pos;
18 $size = wxDefaultSize unless defined $size;
19 $name = "" unless defined $name;
20  
21 # begin wxGlade: __Aut__YesNo::new
22  
23 $style = wxDEFAULT_DIALOG_STYLE
24 unless defined $style;
25  
26 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
27 $self->{yn_label} = Wx::StaticText->new($self, -1, _T("label_11"), wxDefaultPosition, wxDefaultSize, );
28 $self->{static_line_4} = Wx::StaticLine->new($self, -1, wxDefaultPosition, wxDefaultSize, );
29 $self->{yn_no} = Wx::Button->new($self, wxNO, _T("&No"));
30 $self->{yn_yes} = Wx::Button->new($self, wxYES, _T("&Yes"));
31  
32 $self->__set_properties();
33 $self->__do_layout();
34  
35 return $self;
36  
37 # end wxGlade
38 }
39  
40  
41 sub __set_properties {
42 my $self = shift;
43  
44 # begin wxGlade: __Aut__YesNo::__set_properties
45  
46 $self->SetTitle(_T("Yes No"));
47 $self->{yn_yes}->SetDefault();
48  
49 # end wxGlade
50 $self->{yn_no}->SetDefault();
51  
52 EVT_BUTTON($self,$self->{yn_no},\&No);
53 EVT_BUTTON($self,$self->{yn_yes},\&Yes);
54 }
55  
56 sub __do_layout {
57 my $self = shift;
58  
59 # begin wxGlade: __Aut__YesNo::__do_layout
60  
61 $self->{grid_sizer_9} = Wx::FlexGridSizer->new(3, 1, 5, 5);
62 $self->{grid_sizer_10} = Wx::GridSizer->new(1, 2, 5, 5);
63 $self->{grid_sizer_9}->Add($self->{yn_label}, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
64 $self->{grid_sizer_9}->Add($self->{static_line_4}, 0, wxEXPAND, 0);
65 $self->{grid_sizer_10}->Add($self->{yn_no}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
66 $self->{grid_sizer_10}->Add($self->{yn_yes}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
67 $self->{grid_sizer_9}->Add($self->{grid_sizer_10}, 1, wxEXPAND, 0);
68 $self->SetAutoLayout(1);
69 $self->SetSizer($self->{grid_sizer_9});
70 $self->{grid_sizer_9}->Fit($self);
71 $self->{grid_sizer_9}->SetSizeHints($self);
72 $self->Layout();
73 $self->Centre();
74  
75 # end wxGlade
76 }
77  
78 # end of class __Aut__YesNo
79  
80 sub max {
81 my ($x,$y)=@_;
82 return ($x > $y) ? $x : $y;
83 }
84  
85 sub set_label {
86 my $self=shift;
87 my $text=shift;
88  
89 my $borderwidth=5;
90  
91 my $size=$self->{'yn_label'}->GetSize();
92 $self->{'yn_label'}->SetLabel($text);
93 my $nsize=$self->{'yn_label'}->GetBestSize();
94 my $x=max($size->x,$nsize->x);
95 my $y=max($size->y,$nsize->y);
96 my $minsize=new Wx::Size($x+2*$borderwidth,$y+2*$borderwidth);
97 $self->{'grid_sizer_10'}->SetMinSize($minsize);
98  
99 $self->SetAutoLayout(1);
100 $self->SetSizerAndFit($self->{grid_sizer_9},0);
101 $self->{grid_sizer_9}->Fit($self);
102 $self->{grid_sizer_9}->SetSizeHints($self);
103 $self->Layout();
104 $self->Centre();
105 $self->{'yn_yes'}->SetDefault();
106 }
107  
108 sub Yes {
109 my $self=shift;
110 $self->EndModal(wxYES);
111 }
112  
113 sub No {
114 my $self=shift;
115 $self->EndModal(wxNO);
116 }
117  
118 1;
119  
120 package __Aut__Msg;
121  
122 use Wx qw[:everything];
123 use base qw(Wx::Dialog);
124 use strict;
125  
126 use Locale::Framework;
127  
128 sub new {
129 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
130 $parent = undef unless defined $parent;
131 $id = -1 unless defined $id;
132 $title = "" unless defined $title;
133 $pos = wxDefaultPosition unless defined $pos;
134 $size = wxDefaultSize unless defined $size;
135 $name = "" unless defined $name;
136  
137 # begin wxGlade: __Aut__Msg::new
138  
139 $style = wxDEFAULT_DIALOG_STYLE
140 unless defined $style;
141  
142 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
143 $self->{msgLabel} = Wx::StaticText->new($self, -1, _T("label_11"), wxDefaultPosition, wxDefaultSize, );
144 $self->{static_line_3} = Wx::StaticLine->new($self, -1, wxDefaultPosition, wxDefaultSize, );
145 $self->{autmsg_ok} = Wx::Button->new($self, wxID_OK, _T("&OK"));
146  
147 $self->__set_properties();
148 $self->__do_layout();
149  
150 return $self;
151  
152 # end wxGlade
153 }
154  
155  
156 sub __set_properties {
157 my $self = shift;
158  
159 # begin wxGlade: __Aut__Msg::__set_properties
160  
161 $self->SetTitle(_T("Message"));
162 $self->{autmsg_ok}->SetDefault();
163  
164 # end wxGlade
165  
166
167 }
168  
169 sub __do_layout {
170 my $self = shift;
171  
172 # begin wxGlade: __Aut__Msg::__do_layout
173  
174 $self->{grid_sizer_8} = Wx::GridSizer->new(3, 1, 5, 5);
175 $self->{grid_sizer_8}->Add($self->{msgLabel}, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
176 $self->{grid_sizer_8}->Add($self->{static_line_3}, 0, wxEXPAND, 0);
177 $self->{grid_sizer_8}->Add($self->{autmsg_ok}, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
178 $self->SetAutoLayout(1);
179 $self->SetSizer($self->{grid_sizer_8});
180 $self->{grid_sizer_8}->Fit($self);
181 $self->{grid_sizer_8}->SetSizeHints($self);
182 $self->Layout();
183 $self->Centre();
184  
185 # end wxGlade
186 }
187  
188 # end of class __Aut__Msg
189  
190 sub max {
191 my ($x,$y)=@_;
192 return ($x > $y) ? $x : $y;
193 }
194  
195 sub set_label {
196 my $self=shift;
197 my $text=shift;
198  
199 my $borderwidth=5;
200  
201 my $size=$self->{'msgLabel'}->GetSize();
202 $self->{'msgLabel'}->SetLabel($text);
203 my $nsize=$self->{'msgLabel'}->GetBestSize();
204 my $x=max($size->x,$nsize->x);
205 my $y=max($size->y,$nsize->y);
206 my $minsize=new Wx::Size($x+2*$borderwidth,$y+2*$borderwidth);
207  
208 $self->{'grid_sizer_8'}->SetMinSize($minsize);
209  
210 $self->SetAutoLayout(1);
211 $self->SetSizerAndFit($self->{grid_sizer_8},0);
212 $self->{grid_sizer_8}->Fit($self);
213 $self->{grid_sizer_8}->SetSizeHints($self);
214 $self->Layout();
215 $self->Centre();
216 }
217  
218 1;
219  
220 package __Aut__Entry;
221  
222 use Wx qw[:everything];
223 use base qw(Wx::Dialog);
224 use strict;
225  
226 use Locale::Framework;
227  
228 sub new {
229 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
230 $parent = undef unless defined $parent;
231 $id = -1 unless defined $id;
232 $title = "" unless defined $title;
233 $pos = wxDefaultPosition unless defined $pos;
234 $size = wxDefaultSize unless defined $size;
235 $name = "" unless defined $name;
236  
237 # begin wxGlade: __Aut__Entry::new
238  
239 $style = wxDEFAULT_DIALOG_STYLE
240 unless defined $style;
241  
242 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
243 $self->{txtLabel} = Wx::StaticText->new($self, -1, _T(".sdfsdfsfa"), wxDefaultPosition, wxDefaultSize, );
244 $self->{txtEntry} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
245 $self->{static_line_2} = Wx::StaticLine->new($self, -1, wxDefaultPosition, wxDefaultSize, );
246 $self->{qCancel} = Wx::Button->new($self, wxID_CANCEL, _T("&Cancel"));
247 $self->{qOK} = Wx::Button->new($self, wxID_OK, _T("&OK"));
248  
249 $self->__set_properties();
250 $self->__do_layout();
251  
252 return $self;
253  
254 # end wxGlade
255 }
256  
257  
258 sub __set_properties {
259 my $self = shift;
260  
261 # begin wxGlade: __Aut__Entry::__set_properties
262  
263 $self->SetTitle(_T("Question"));
264 $self->{txtEntry}->SetFocus();
265 $self->{qOK}->SetDefault();
266  
267 # end wxGlade
268 }
269  
270 sub __do_layout {
271 my $self = shift;
272  
273 # begin wxGlade: __Aut__Entry::__do_layout
274  
275 $self->{sizer_4} = Wx::FlexGridSizer->new(3, 1, 0, 0);
276 $self->{grid_sizer_6} = Wx::GridSizer->new(1, 2, 5, 5);
277 $self->{grid_sizer_5} = Wx::FlexGridSizer->new(2, 1, 5, 5);
278 $self->{grid_sizer_5}->Add($self->{txtLabel}, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
279 $self->{grid_sizer_5}->Add($self->{txtEntry}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
280 $self->{sizer_4}->Add($self->{grid_sizer_5}, 1, wxEXPAND, 0);
281 $self->{sizer_4}->Add($self->{static_line_2}, 0, wxEXPAND, 0);
282 $self->{grid_sizer_6}->Add($self->{qCancel}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
283 $self->{grid_sizer_6}->Add($self->{qOK}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
284 $self->{sizer_4}->Add($self->{grid_sizer_6}, 1, wxEXPAND, 0);
285 $self->SetAutoLayout(1);
286 $self->SetSizer($self->{sizer_4});
287 $self->{sizer_4}->Fit($self);
288 $self->{sizer_4}->SetSizeHints($self);
289 $self->Layout();
290 $self->Centre();
291  
292 # end wxGlade
293 }
294  
295 # end of class __Aut__Entry
296  
297 sub max {
298 my ($x,$y)=@_;
299 return ($x > $y) ? $x : $y;
300 }
301  
302 sub set_label {
303 my $self=shift;
304 my $text=shift;
305  
306 my $borderwidth=5;
307  
308 my $size=$self->{'txtLabel'}->GetSize();
309 $self->{'txtLabel'}->SetLabel($text);
310 my $nsize=$self->{'txtLabel'}->GetBestSize();
311 my $x=max($size->x,$nsize->x);
312 my $y=max($size->y,$nsize->y);
313 my $minsize=new Wx::Size($x+2*$borderwidth,$y+2*$borderwidth);
314  
315 $self->{'grid_sizer_5'}->SetMinSize($minsize);
316 $self->{'grid_sizer_5'}->SetItemMinSize($self->{'txtLabel'},$x,$y);
317  
318 $self->SetAutoLayout(1);
319 $self->SetSizerAndFit($self->{sizer_4},0);
320 $self->{sizer_4}->Fit($self);
321 $self->{sizer_4}->SetSizeHints($self);
322 $self->Layout();
323 $self->Centre();
324 }
325  
326 sub get_value {
327 my $self=shift;
328 return $self->{'txtEntry'}->GetValue();
329 }
330  
331 1;
332  
333 package __Aut__ChangePass;
334  
335 use Wx qw[:everything];
336 use base qw(Wx::Dialog);
337 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
338  
339 use strict;
340  
341 use Locale::Framework;
342  
343  
344 sub new {
345 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
346 $parent = undef unless defined $parent;
347 $id = -1 unless defined $id;
348 $title = "" unless defined $title;
349 $pos = wxDefaultPosition unless defined $pos;
350 $size = wxDefaultSize unless defined $size;
351 $name = "" unless defined $name;
352  
353 # begin wxGlade: __Aut__ChangePass::new
354  
355 $style = wxDEFAULT_DIALOG_STYLE
356 unless defined $style;
357  
358 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
359 $self->{label_7} = Wx::StaticText->new($self, -1, _T("Account:"), wxDefaultPosition, wxDefaultSize, );
360 $self->{txtchgpass_account} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, );
361 $self->{label_10} = Wx::StaticText->new($self, -1, _T("Current password:"), wxDefaultPosition, wxDefaultSize, );
362 $self->{txtchgpass_old} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
363 $self->{label_8} = Wx::StaticText->new($self, -1, _T("Password:"), wxDefaultPosition, wxDefaultSize, );
364 $self->{txtchgpass_pass} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
365 $self->{label_9} = Wx::StaticText->new($self, -1, _T("Password (again):"), wxDefaultPosition, wxDefaultSize, );
366 $self->{txtchgpass_again} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
367 $self->{static_line_1} = Wx::StaticLine->new($self, -1, wxDefaultPosition, wxDefaultSize, );
368 $self->{chgpassCancel} = Wx::Button->new($self, wxID_CANCEL, _T("&Cancel"));
369 $self->{chgpassOK} = Wx::Button->new($self, wxID_OK, _T("&OK"));
370  
371 $self->__set_properties();
372 $self->__do_layout();
373  
374 return $self;
375  
376 # end wxGlade
377 }
378  
379  
380 sub __set_properties {
381 my $self = shift;
382  
383 # begin wxGlade: __Aut__ChangePass::__set_properties
384  
385 $self->SetTitle(_T("Change Password"));
386 $self->{txtchgpass_account}->Enable(0);
387 $self->{txtchgpass_old}->SetFocus();
388 $self->{chgpassOK}->SetDefault();
389  
390 # end wxGlade
391  
392 EVT_BUTTON($self,$self->{chgpassOK},\&Ok);
393 EVT_BUTTON($self,$self->{chgpassCancel},\&Cancel);
394 }
395  
396 sub __do_layout {
397 my $self = shift;
398  
399 # begin wxGlade: __Aut__ChangePass::__do_layout
400  
401 $self->{sizer_3} = Wx::FlexGridSizer->new(3, 1, 0, 0);
402 $self->{grid_sizer_3} = Wx::GridSizer->new(1, 2, 5, 5);
403 $self->{grid_sizer_4} = Wx::GridSizer->new(3, 2, 5, 5);
404 $self->{grid_sizer_4}->Add($self->{label_7}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
405 $self->{grid_sizer_4}->Add($self->{txtchgpass_account}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
406 $self->{grid_sizer_4}->Add($self->{label_10}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
407 $self->{grid_sizer_4}->Add($self->{txtchgpass_old}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
408 $self->{grid_sizer_4}->Add($self->{label_8}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
409 $self->{grid_sizer_4}->Add($self->{txtchgpass_pass}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
410 $self->{grid_sizer_4}->Add($self->{label_9}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
411 $self->{grid_sizer_4}->Add($self->{txtchgpass_again}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
412 $self->{sizer_3}->Add($self->{grid_sizer_4}, 1, wxEXPAND, 0);
413 $self->{sizer_3}->Add($self->{static_line_1}, 0, wxEXPAND, 0);
414 $self->{grid_sizer_3}->Add($self->{chgpassCancel}, 0, wxEXPAND, 0);
415 $self->{grid_sizer_3}->Add($self->{chgpassOK}, 0, wxEXPAND, 0);
416 $self->{sizer_3}->Add($self->{grid_sizer_3}, 1, wxEXPAND, 0);
417 $self->SetAutoLayout(1);
418 $self->SetSizer($self->{sizer_3});
419 $self->{sizer_3}->Fit($self);
420 $self->{sizer_3}->SetSizeHints($self);
421 $self->Layout();
422 $self->Centre();
423  
424 # end wxGlade
425 }
426  
427 # end of class __Aut__ChangePass
428  
429 sub set_aut {
430 my ($self,$aut)=@_;
431 $self->{"aut"}=$aut;
432 }
433  
434 sub set_ui {
435 my ($self,$ui)=@_;
436 $self->{"ui"}=$ui;
437 }
438  
439 sub set_account {
440 my ($self,$account)=@_;
441 $self->{"txtchgpass_account"}->SetValue($account);
442 }
443  
444 sub set_ticket {
445 my ($self,$ticket)=@_;
446 $self->{"ticket"}=$ticket;
447 }
448  
449 sub Ok {
450 my $self=shift;
451 my $aut=$self->{"aut"};
452 my $ticket=$self->{"ticket"};
453 my $ui=$self->{"ui"};
454  
455 my $old=$self->{"txtchgpass_old"}->GetValue();
456 my $pass=$self->{"txtchgpass_pass"}->GetValue();
457 my $again=$self->{"txtchgpass_again"}->GetValue();
458  
459 my $thepass=$ticket->pass();
460  
461 my $ok=0;
462  
463 if ($thepass ne $old) {
464 $ui->message_ok(_T("You didn't give a valid current password"),
465 _T("Change Password"),
466 $self
467 );
468 }
469 elsif ($pass ne $again) {
470 $ui->message_ok(_T("New passwords don't match"),
471 _T("Change Password"),
472 $self
473 );
474 }
475 else {
476 my $msg=$aut->check_pass($pass);
477 if ($msg ne "") {
478 $ui->message_ok($msg,
479 _T("Change Password"),
480 $self
481 );
482 }
483 else {
484 # Update account via Aut
485  
486 $ticket->set_pass($pass);
487 $aut->ticket_update($ticket);
488  
489 # End dialog
490  
491 $self->EndModal(wxID_OK);
492 $ok=1;
493 }
494 }
495  
496 if (not $ok) {
497 $self->{"txtchgpass_again"}->SetValue("");
498 $self->{"txtchgpass_pass"}->SetValue("");
499 $self->{"txtchgpass_old"}->SetValue("");
500 $self->{"txtchgpass_old"}->SetFocus();
501 }
502 }
503  
504 sub Cancel {
505 my $self=shift;
506 $self->EndModal(wxID_CANCEL);
507 }
508  
509 1;
510  
511 ########################################################################
512  
513 package __Aut__dlgLogin;
514  
515 use strict;
516  
517 use Wx qw[:everything];
518 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
519 use Locale::Framework;
520  
521 use base qw(Wx::Dialog);
522  
523 sub new {
524 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
525 $parent = undef unless defined $parent;
526 $id = -1 unless defined $id;
527 $title = "" unless defined $title;
528 $pos = wxDefaultPosition unless defined $pos;
529 $size = wxDefaultSize unless defined $size;
530 $name = "" unless defined $name;
531  
532 # begin wxGlade: __Aut__dlgLogin::new
533  
534 $style = wxDIALOG_MODAL|wxCAPTION
535 unless defined $style;
536  
537 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
538 $self->{label_1} = Wx::StaticText->new($self, -1, _T("Account:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
539 $self->{authAccount} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, );
540 $self->{label_2} = Wx::StaticText->new($self, -1, _T("Password:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
541 $self->{authPass} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
542 $self->{authCancel} = Wx::Button->new($self, -1, _T("&Cancel"));
543 $self->{authOK} = Wx::Button->new($self, -1, _T("&OK"));
544  
545 $self->__set_properties();
546 $self->__do_layout();
547  
548 return $self;
549  
550 # end wxGlade
551 }
552  
553  
554 sub __set_properties {
555 my $self = shift;
556  
557 # begin wxGlade: __Aut__dlgLogin::__set_properties
558  
559 $self->SetTitle(_T("Login"));
560 $self->{authOK}->SetDefault();
561  
562 # end wxGlade
563  
564 EVT_BUTTON($self,$self->{authOK},\&Ok);
565 EVT_BUTTON($self,$self->{authCancel},\&Cancel);
566 }
567  
568 sub __do_layout {
569 my $self = shift;
570  
571 # begin wxGlade: __Aut__dlgLogin::__do_layout
572  
573 $self->{grid_sizer_1} = Wx::GridSizer->new(3, 2, 5, 5);
574 $self->{grid_sizer_1}->Add($self->{label_1}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
575 $self->{grid_sizer_1}->Add($self->{authAccount}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
576 $self->{grid_sizer_1}->Add($self->{label_2}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
577 $self->{grid_sizer_1}->Add($self->{authPass}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
578 $self->{grid_sizer_1}->Add($self->{authCancel}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
579 $self->{grid_sizer_1}->Add($self->{authOK}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
580 $self->SetAutoLayout(1);
581 $self->SetSizer($self->{grid_sizer_1});
582 $self->{grid_sizer_1}->Fit($self);
583 $self->{grid_sizer_1}->SetSizeHints($self);
584 $self->Layout();
585 $self->Centre();
586  
587 # end wxGlade
588 }
589  
590 #### User functions
591  
592 sub set_aut {
593 my ($self,$aut)=@_;
594 $self->{"aut"}=$aut;
595 }
596  
597 sub set_ui {
598 my ($self,$ui)=@_;
599 $self->{"ui"}=$ui;
600 }
601  
602 sub account {
603 my $self=shift;
604 return $self->{'authAccount'}->GetValue();
605 }
606  
607 sub pass {
608 my $self=shift;
609 my $pass=shift;
610 if (defined $pass) {
611 $self->{'authPass'}->SetValue($pass);
612 $self->{'authPass'}->SetFocus();
613 }
614 return $self->{'authPass'}->GetValue();
615 }
616  
617 sub ticket {
618 my $self=shift;
619 return $self->{"ticket"};
620 }
621  
622 sub Ok {
623 my $self=shift;
624 my $aut=$self->{'aut'};
625 my $ui=$self->{'ui'};
626  
627 $self->{"ok"}=0;
628  
629 my $account=$self->account();
630 my $pass=$self->pass();
631 my $ticket=$aut->ticket_get($account,$pass);
632  
633 if ($ticket->valid()) {
634 $self->{"ok"}=1;
635 }
636 else {
637 $ui->message_ok(_T("Not a valid account/user combination"),_T("Login"),$self);
638 $self->pass("");
639 }
640  
641 $self->{"ticket"}=$ticket;
642  
643 if ($self->{"ok"}) {
644 $self->EndModal(wxID_OK);
645 }
646 }
647  
648 sub Cancel {
649 my $self=shift;
650 $self->{"ticket"}=new Aut::Ticket($self->account(),$self->pass());
651 $self->{"ticket"}->invalidate();
652 $self->EndModal(wxID_CANCEL);
653 }
654  
655 # end of class __Aut__dlgLogin
656  
657 1;
658  
659 ########################################################################
660  
661 package __Aut__InputAccount;
662  
663 use strict;
664  
665 use Wx qw[:everything];
666 use Locale::Framework;
667 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
668  
669 use base qw(Wx::Dialog);
670  
671 sub new {
672 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
673 $parent = undef unless defined $parent;
674 $id = -1 unless defined $id;
675 $title = "" unless defined $title;
676 $pos = wxDefaultPosition unless defined $pos;
677 $size = wxDefaultSize unless defined $size;
678 $name = "" unless defined $name;
679  
680 # begin wxGlade: __Aut__InputAccount::new
681  
682 $style = wxDEFAULT_DIALOG_STYLE
683 unless defined $style;
684  
685 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
686 $self->{label_3} = Wx::StaticText->new($self, -1, _T("Account:"), wxDefaultPosition, wxDefaultSize, );
687 $self->{txtAccount} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, );
688 $self->{label_4} = Wx::StaticText->new($self, -1, _T("Password:"), wxDefaultPosition, wxDefaultSize, );
689 $self->{txtPass} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
690 $self->{label_6} = Wx::StaticText->new($self, -1, _T("Password (Again):"), wxDefaultPosition, wxDefaultSize, );
691 $self->{txtPassAgain} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
692 $self->{label_5} = Wx::StaticText->new($self, -1, _T("Authorization Level:"), wxDefaultPosition, wxDefaultSize, );
693 $self->{chTicket} = Wx::Choice->new($self, -1, wxDefaultPosition, wxDefaultSize, [_T("choice 1")], );
694 $self->{iaCancel} = Wx::Button->new($self, wxID_CANCEL, _T("&Cancel"));
695 $self->{iaOK} = Wx::Button->new($self, wxID_OK, _T("&OK"));
696  
697 $self->__set_properties();
698 $self->__do_layout();
699  
700 return $self;
701  
702 # end wxGlade
703 }
704  
705  
706 sub __set_properties {
707 my $self = shift;
708  
709 # begin wxGlade: __Aut__InputAccount::__set_properties
710  
711 $self->SetTitle(_T("Account Input"));
712 $self->{chTicket}->SetSelection(0);
713 $self->{iaOK}->SetDefault();
714  
715 # end wxGlade
716  
717 EVT_BUTTON($self,$self->{iaOK},\&Ok);
718 EVT_BUTTON($self,$self->{iaCancel},\&Cancel);
719
720 }
721  
722 sub __do_layout {
723 my $self = shift;
724  
725 # begin wxGlade: __Aut__InputAccount::__do_layout
726  
727 $self->{ias} = Wx::GridSizer->new(4, 2, 5, 5);
728 $self->{ias}->Add($self->{label_3}, 0, wxRIGHT|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
729 $self->{ias}->Add($self->{txtAccount}, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
730 $self->{ias}->Add($self->{label_4}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
731 $self->{ias}->Add($self->{txtPass}, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
732 $self->{ias}->Add($self->{label_6}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
733 $self->{ias}->Add($self->{txtPassAgain}, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
734 $self->{ias}->Add($self->{label_5}, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
735 $self->{ias}->Add($self->{chTicket}, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
736 $self->{ias}->Add($self->{iaCancel}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
737 $self->{ias}->Add($self->{iaOK}, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
738 $self->SetAutoLayout(1);
739 $self->SetSizer($self->{ias});
740 $self->{ias}->Fit($self);
741 $self->{ias}->SetSizeHints($self);
742 $self->Layout();
743 $self->Centre();
744  
745 # end wxGlade
746 }
747  
748 # end of class __Aut__InputAccount
749  
750 sub set_aut {
751 my ($self,$aut)=@_;
752 $self->{"aut"}=$aut;
753 }
754  
755 sub set_ui {
756 my ($self,$ui)=@_;
757 $self->{"ui"}=$ui;
758 }
759  
760 sub account {
761 my $self=shift;
762 return $self->{"txtAccount"}->GetValue();
763 }
764  
765 sub pass {
766 my $self=shift;
767 return $self->{"txtPass"}->GetValue();
768 }
769  
770 sub passagain {
771 my $self=shift;
772 return $self->{"txtPassAgain"}->GetValue();
773 }
774  
775 sub rights {
776 my $self=shift;
777 my $rights=$self->{"chTicket"}->GetStringSelection();
778 return $self->{"rights_untrans"}->{$rights};
779 }
780  
781 sub set {
782 my $self=shift;
783 my $ticket=shift;
784 $self->{'txtPass'}->SetValue($ticket->pass());
785 $self->{'txtPassAgain'}->SetValue($ticket->pass());
786 $self->{'txtAccount'}->SetValue($ticket->account());
787 $self->{'chTicket'}->SetStringSelection($ticket->rights());
788 }
789  
790 sub get {
791 my $self=shift;
792 my $ticket=shift;
793 $ticket->set_pass($self->pass());
794 $ticket->set_rights($self->rights());
795 }
796  
797 sub set_mode {
798 my $self=shift;
799 $self->{'mode'}=shift;
800  
801 if ($self->{'mode'} eq "edit") {
802 $self->{'txtAccount'}->Enable(0);
803 }
804 }
805  
806 sub initialize {
807 my $self=shift;
808 my $aut=$self->{"aut"};
809 my $ui=$self->{"ui"};
810 my @rights=$ui->levels();
811  
812 my %rights_untrans;
813
814 $self->{"chTicket"}->Clear();
815 for my $right (@rights) {
816 $rights_untrans{_T($right)}=$right;
817 $self->{"chTicket"}->Append(_T($right));
818 }
819 $self->{"rights_untrans"}=\%rights_untrans;
820 $self->{"chTicket"}->SetSelection(0);
821 }
822  
823 ###
824  
825 sub Ok {
826 my $self=shift;
827 my $ui=$self->{"ui"};
828 my $aut=$self->{"aut"};
829  
830 ### Check validity of account and password
831  
832 my $account=$self->account();
833
834 if ($account eq "") {
835 $ui->message_ok(_T("You cannot use an empty account"));
836 }
837 elsif ($aut->exists($account) and ($self->{"mode"} eq "add")) {
838 $ui->message_ok(_T("Please use a non existing account"));
839 }
840 elsif ($self->pass() ne $self->passagain()) {
841 $ui->message_ok(_T("The given passwords don't match"));
842 }
843 else {
844 my $msg=$aut->check_pass($self->pass());
845 if ($msg ne "") {
846 $ui->message_ok($msg);
847 }
848 else {
849 $self->EndModal(wxID_OK);
850 }
851 }
852 }
853  
854 sub Cancel {
855 my $self=shift;
856 $self->EndModal(wxID_CANCEL);
857 }
858  
859  
860 1;
861  
862 ########################################################################
863  
864 package __Aut__AdminAccounts;
865  
866 use strict;
867  
868 use Wx qw[:everything];
869 use base qw(Wx::Dialog);
870 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
871 use Locale::Framework;
872  
873 sub new {
874 my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
875 $parent = undef unless defined $parent;
876 $id = -1 unless defined $id;
877 $title = "" unless defined $title;
878 $pos = wxDefaultPosition unless defined $pos;
879 $size = wxDefaultSize unless defined $size;
880 $name = "" unless defined $name;
881  
882 # begin wxGlade: __Aut__AdminAccounts::new
883  
884 $style = wxDIALOG_MODAL|wxCAPTION
885 unless defined $style;
886  
887 $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
888 $self->{lstAccounts} = Wx::ListCtrl->new($self, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER);
889 $self->{glAddAccount} = Wx::Button->new($self, -1, _T("&Add"));
890 $self->{glRemoveAccount} = Wx::Button->new($self, -1, _T("&Remove"));
891 $self->{glEditAccount} = Wx::Button->new($self, -1, _T("&Edit"));
892 $self->{glOK} = Wx::Button->new($self, -1, _T("&OK"));
893  
894 $self->__set_properties();
895 $self->__do_layout();
896  
897 return $self;
898  
899 # end wxGlade
900 }
901  
902  
903 sub __set_properties {
904 my $self = shift;
905  
906 # begin wxGlade: __Aut__AdminAccounts::__set_properties
907  
908 $self->SetTitle(_T("Administer Accounts"));
909 $self->{lstAccounts}->SetSize($self->{lstAccounts}->ConvertDialogSizeToPixels(Wx::Size->new(137, 168)));
910  
911 # end wxGlade
912  
913 $self->{glOK}->SetDefault();
914  
915 EVT_BUTTON($self,$self->{glOK},\&Ok);
916 EVT_BUTTON($self,$self->{glAddAccount},\&AddAccount);
917 EVT_BUTTON($self,$self->{glRemoveAccount},\&RemoveAccount);
918 EVT_BUTTON($self,$self->{glEditAccount},\&EditAccount);
919 }
920  
921 sub __do_layout {
922 my $self = shift;
923  
924 # begin wxGlade: __Aut__AdminAccounts::__do_layout
925  
926 $self->{grid_sizer_2} = Wx::FlexGridSizer->new(1, 2, 5, 5);
927 $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
928 $self->{sizer_2} = Wx::BoxSizer->new(wxHORIZONTAL);
929 $self->{grid_sizer_2}->Add($self->{lstAccounts}, 1, wxEXPAND, 0);
930 $self->{sizer_1}->Add($self->{glAddAccount}, 0, 0, 0);
931 $self->{sizer_1}->Add($self->{glRemoveAccount}, 0, 0, 0);
932 $self->{sizer_1}->Add($self->{glEditAccount}, 0, 0, 0);
933 $self->{sizer_2}->Add($self->{glOK}, 0, wxALIGN_BOTTOM, 0);
934 $self->{sizer_1}->Add($self->{sizer_2}, 1, wxEXPAND, 0);
935 $self->{grid_sizer_2}->Add($self->{sizer_1}, 1, wxEXPAND, 0);
936 $self->SetAutoLayout(1);
937 $self->SetSizer($self->{grid_sizer_2});
938 $self->{grid_sizer_2}->Fit($self);
939 $self->{grid_sizer_2}->SetSizeHints($self);
940 $self->{grid_sizer_2}->AddGrowableRow(0);
941 $self->{grid_sizer_2}->AddGrowableCol(0);
942 $self->Layout();
943 $self->Centre();
944  
945 # end wxGlade
946 }
947  
948 # end of class __Aut__AdminAccounts
949  
950 sub set_aut {
951 my ($self,$aut)=@_;
952 $self->{"aut"}=$aut;
953 }
954  
955 sub set_ui {
956 my ($self,$ui)=@_;
957 $self->{"ui"}=$ui;
958 }
959  
960 sub set_ticket {
961 my ($self,$ticket)=@_;
962 $self->{"ticket"}=$ticket;
963 }
964  
965 sub initialize {
966 my $self=shift;
967 my $aut=$self->{"aut"};
968 my $idx=0;
969  
970 my $lst=$self->{"lstAccounts"};
971  
972 $lst->InsertColumn(1,_T("Account"));
973 $lst->InsertColumn(2,_T("Rights"));
974  
975 my $count=0;
976 my @tickets=undef;
977 while ($count lt 3) {
978 $count+=1;
979 @tickets=$aut->ticket_all_admin_get();
980 if (defined $tickets[0]) {
981 last;
982 }
983 }
984  
985 if (not defined $tickets[0]) {
986 return 0;
987 }
988  
989 $self->{"tickets"}=\@tickets;
990  
991 for my $entry (@tickets) {
992 $lst->InsertStringItem($idx,$entry->account());
993 $lst->SetItem($idx,1,_T($entry->rights()));
994 $idx+=1;
995 }
996  
997 $self->retreive_config();
998  
999 return 1;
1000 }
1001  
1002 sub commit_config {
1003 my $self=shift;
1004 my $aut=$self->{"aut"};
1005 my $ticket=$self->{"ticket"};
1006 my $width1=$self->{"lstAccounts"}->GetColumnWidth(0);
1007 my $width2=$self->{"lstAccounts"}->GetColumnWidth(1);
1008  
1009 $aut->set($ticket,"admin_col1",$width1);
1010 $aut->set($ticket,"admin_col2",$width2);
1011 }
1012  
1013 sub retreive_config {
1014 my $self=shift;
1015 my $aut=$self->{"aut"};
1016 my $ticket=$self->{"ticket"};
1017  
1018 my $width1=$aut->get($ticket,"admin_col1");
1019 my $width2=$aut->get($ticket,"admin_col2");
1020  
1021 if (defined $width1) {
1022 $self->{"lstAccounts"}->SetColumnWidth(0,$width1);
1023 }
1024 if (defined $width2) {
1025 $self->{"lstAccounts"}->SetColumnWidth(1,$width2);
1026 }
1027  
1028 }
1029  
1030 sub Ok {
1031 my $self=shift;
1032 $self->commit_config();
1033 $self->EndModal(wxID_OK);
1034 }
1035  
1036 sub AddAccount {
1037 my $self=shift;
1038 my $aut=$self->{"aut"};
1039 my $ui=$self->{"ui"};
1040  
1041 my $dlg=new __Aut__InputAccount($self,-1,_T("Add Account"));
1042 $dlg->set_mode("add");
1043 $dlg->set_aut($self->{"aut"});
1044 $dlg->set_ui($self->{"ui"});
1045 $dlg->initialize();
1046  
1047 if ($dlg->ShowModal()==wxID_OK) {
1048 my $account=$dlg->account();
1049 my $pass=$dlg->pass();
1050 my $rights=$dlg->rights();
1051  
1052 my $ticket=new Aut::Ticket($account,$pass);
1053 $ticket->set_rights($rights);
1054  
1055 $aut->ticket_create($ticket);
1056  
1057 # Adding the entry
1058  
1059 my $idx=$self->{"lstAccounts"}->GetItemCount();
1060 $self->{"lstAccounts"}->InsertStringItem($idx,$account);
1061 $self->{"lstAccounts"}->SetItem($idx,1,_T($rights));
1062 push @{$self->{"tickets"}},$ticket;
1063 }
1064  
1065 $dlg->Destroy();
1066
1067 }
1068  
1069 sub findSelected {
1070 my $self=shift;
1071 my $item=$self->{"lstAccounts"}->GetNextItem(-1,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
1072 return $item;
1073 }
1074  
1075 sub yesno {
1076 my $self=shift;
1077 my $text=shift;
1078 my $title=$self->GetTitle();
1079  
1080 my $dlg=new __Aut__YesNo($self,-1,$title);
1081 $dlg->set_label($text);
1082 $dlg->SetTitle($title);
1083  
1084 my $answer=$dlg->ShowModal();
1085 # my $answer=Wx::MessageBox($text,$title,wxYES_NO(),$self);
1086  
1087 $dlg->Destroy();
1088  
1089 if ($answer==wxYES) {
1090 return "yes";
1091 }
1092 else {
1093 return "no";
1094 }
1095 }
1096  
1097 sub RemoveAccount {
1098 my $self=shift;
1099 my $aut=$self->{"aut"};
1100 my $ui=$self->{"ui"};
1101 my $ticket=$self->{"ticket"};
1102  
1103 my $item=$self->findSelected();
1104 if ($item ge 0) {
1105  
1106 my $account=$self->{"lstAccounts"}->GetItemText($item);
1107 my $text=_T("Are you sure you want to remove this account")." ($account)";
1108 my $title=$self->GetTitle();
1109  
1110 if ($account eq $ticket->account()) {
1111 $ui->message_ok(_T("You cannot remove yourself")." ($account)",$title);
1112 }
1113 elsif ($self->yesno($text) eq "yes") {
1114 $self->{"lstAccounts"}->DeleteItem($item);
1115 my @tickets=@{$self->{"tickets"}};
1116 for my $t (@tickets) {
1117 if ($account eq $t->account()) {
1118 $aut->ticket_remove($t);
1119 $t->invalidate();
1120 }
1121 }
1122 }
1123 }
1124 }
1125  
1126 sub EditAccount {
1127 my $self=shift;
1128 my $aut=$self->{"aut"};
1129 my $ui=$self->{"ui"};
1130 my $ticket=$self->{"ticket"};
1131  
1132 my $item=$self->findSelected();
1133 if ($item ge 0) {
1134  
1135 my $account=$self->{"lstAccounts"}->GetItemText($item);
1136 my $title=$self->GetTitle();
1137
1138 if ($account eq $ticket->account()) {
1139 $ui->message_ok(_T("You cannot edit yourself,\n".
1140 "try just changing you password.")." ($account)",
1141 $title);
1142 }
1143 else {
1144 my @tickets=@{$self->{"tickets"}};
1145 for my $t (@tickets) {
1146 if ($account eq $t->account()) {
1147 my $dlg=new __Aut__InputAccount($self,-1,$title);
1148 $dlg->set_mode("edit");
1149 $dlg->set_aut($aut);
1150 $dlg->set_ui($ui);
1151 $dlg->initialize();
1152 $dlg->set($t);
1153 if ($dlg->ShowModal()==wxID_OK) {
1154 $dlg->get($t);
1155 $aut->ticket_update($t);
1156 $self->{'lstAccounts'}->SetItem($item,1,_T($t->rights()))
1157 }
1158 last;
1159 }
1160 }
1161 }
1162 }
1163 }
1164  
1165 1;
1166  
↑ Summary Wx.pm »