Wrangler/Wx/Dialog/About.pm untested

filter: Statementstmt 0.0% 0 / 237 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 33 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 307 CC 11 SCAR 25.4
CC
11
Cov
0%
new
56.0
ReadLicense
20.0
new
6.0
CRAP 12.7
1 package Wrangler::Wx::Dialog::About;
2  
3 use strict;
4 use warnings;
5  
6 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER wxCAPTION wxEXPAND wxCLOSE_BOX wxTOP wxBOTH wxLEFT wxALIGN_CENTER wxVERTICAL wxBOTTOM wxTE_RICH wxALIGN_CENTER wxTE_READONLY wxTE_MULTILINE wxRB_GROUP wxGROW wxALL wxRESIZE_BORDER wxCLIP_CHILDREN);
7 use Wx::Event qw(EVT_BUTTON);
8 use base 'Wx::Dialog';
9  
10 sub new {
11 my $class = shift;
12 my $parent = shift;
13 my $preselect = shift;
14  
15 my $self = $class->SUPER::new($parent, -1, "About", wxDefaultPosition, [460,440], wxDEFAULT_DIALOG_STYLE | wxCAPTION | wxRESIZE_BORDER | wxCLOSE_BOX);
16  
17 # main sizer
18 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
19 $sizer->AddGrowableCol(0);
20 $sizer->AddGrowableRow(0);
21  
22 # do a notebook
23 my $nb = Wx::Notebook->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN );
24 my $tab1 = Wrangler::Wx::Dialog::About::About->new($nb);
25 my $tab2 = Wrangler::Wx::Dialog::About::Purchase->new($nb,$self);
26 my $tab3 = Wrangler::Wx::Dialog::About::License->new($nb);
27 my $tab4 = Wrangler::Wx::Dialog::About::Changes->new($nb);
28 $nb->AddPage( $tab1, "&About", 0);
29 $nb->AddPage( $tab2, "&Purchase", 0);
30 $nb->AddPage( $tab3, "&License and User Agreement", 0);
31 $nb->AddPage( $tab4, "&Changelog", 0);
32  
33 $nb->SetSelection($preselect) if $preselect;
34  
35 # a close button in the lower section
36 my $buttontext = Wx::StaticText->new($self, -1, 'Wrangler', wxDefaultPosition, wxDefaultSize);
37 $buttontext->SetForegroundColour(Wx::Colour->new(128,128,128));
38 my $buttonclose = Wx::Button->new($self, -1, "Close", wxDefaultPosition, wxDefaultSize );
39 my $buttonsizer = Wx::FlexGridSizer->new(1, 2, 0, 0); # rows,cols,vgap,hgap
40 $buttonsizer->AddGrowableCol(0);
41 $buttonsizer->AddGrowableRow(0);
42 $buttonsizer->Add($buttontext, 1, wxGROW|wxLEFT|wxTOP, 8);
43 $buttonsizer->Add($buttonclose, 1, wxALL, 5);
44  
45 # compose elements
46 $sizer->Add($nb, 1, wxGROW|wxALL, 5);
47 $sizer->Add($buttonsizer, 1, wxGROW|wxTOP|wxEXPAND, 5);
48  
49 $self->SetSizer($sizer);
50  
51 $self->Centre();
52  
53 EVT_BUTTON($self, $buttonclose, sub { $self->Destroy(); } );
54  
55 $self->ShowModal();
56  
57 $self->Destroy();
58  
59 return $self;
60 }
61  
62  
63 package Wrangler::Wx::Dialog::About::About;
64  
65 use strict;
66 use warnings;
67  
68 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER );
69 use Wx::Event qw(EVT_PAINT);
70 use base 'Wx::Panel';
71  
72 use utf8; # text here is utf8 ("looking at you, (c)..!")
73  
74 sub new {
75 my $class = shift;
76 my $parent = shift;
77  
78 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
79  
80 # our ImagePanelPanel (we attach the Bitmap OnPaint)
81 $self->{panel} = Wx::Panel->new($self, -1, wxDefaultPosition, [425,251], wxGROW);
82 $self->{bmp} = Wx::Bitmap->newFromXPM($Wrangler::Images::image{'logo_2.x_splash425'});
83  
84 my $wrangler_version = $Wrangler::VERSION;
85 $wrangler_version =~ s/,/\./;
86 my $text = Wx::StaticText->new($self, -1, "This is Wrangler.\nVersion ". $wrangler_version ."\n\n© 2009-2015 Clipland GmbH. All rights reserved.");
87 $text->SetForegroundColour(Wx::Colour->new(45,45,45) );
88  
89 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
90 $sizer->AddGrowableCol(0);
91 $sizer->AddGrowableRow(0);
92 $sizer->Add($self->{panel}, 0, wxALIGN_CENTER|wxALL, 10);
93 $sizer->Add($text, 0, wxLEFT, 10);
94  
95 $self->SetSizer($sizer);
96  
97 EVT_PAINT($self, \&OnPaint );
98  
99 return $self;
100 }
101  
102 sub OnPaint {
103 my ($self, $event) = @_;
104  
105 my $dc = Wx::PaintDC->new($self->{panel});
106 $dc->DrawBitmap($self->{bmp}, 0,0 , 0);
107 }
108  
109  
110 package Wrangler::Wx::Dialog::About::Purchase;
111  
112 use strict;
113 use warnings;
114  
115 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxID_OK wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM);
116 use Wx::Event qw(EVT_BUTTON);
117 use base 'Wx::Panel';
118  
119 sub new {
120 my $class = shift;
121 my $parent = shift;
122 my $about_dialog = shift;
123  
124 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
125  
126 my @license = ReadLicense();
127  
128 my @text = (
129 "Wrangler is free ONLY for for non-commercial use. If you are using Wrangler at work, or if you are planning to generate revenue from the files you are managing with Wrangler, then you'll need to buy a license.\n\nIf you're still not certain, contact us and we'll help you find out whether you require a commercial license. As a general rule, if you need to ask, you probably have to buy a commercial license.\n\nVisit: http://www.clipland.com/wrangler",
130 "\n\n\n\nThis installation of Wrangler is licensed for commercial use."
131 );
132  
133 # tab 2 Purchase
134 my $purchase = Wx::StaticText->new($self, -1, (@license ? $text[1] : $text[0]), wxDefaultPosition, wxDefaultSize );
135 $purchase->SetForegroundColour(Wx::Colour->new(45,45,45) );
136 my $reg_box = Wx::StaticBox->new($self, -1, "Registration information" );
137 my $reg_sizer = Wx::StaticBoxSizer->new($reg_box, wxVERTICAL);
138 my $LicensedTo = Wx::StaticText->new($self, -1, "Licensed to", wxDefaultPosition, wxDefaultSize, );
139 my $LicenseKey = Wx::StaticText->new($self, -1, "License Key", wxDefaultPosition, wxDefaultSize, );
140  
141 my $reg_subsizer = Wx::FlexGridSizer->new(2, 2, 0, 0); # rows,cols,vgap,hgap
142 if(@license){
143 $self->{License}->{Name} = Wx::TextCtrl->new($self, -1, ($license[1] ? $license[1] : ''), wxDefaultPosition, [250, -1], );
144 $self->{License}->{Name}->Disable();
145 $self->{License}->{Key} = Wx::TextCtrl->new($self, -1, ($license[0] ? $license[0] : ''), wxDefaultPosition, [250, -1], );
146 $self->{License}->{Key}->Disable();
147 $reg_subsizer->Add($LicensedTo, 1, wxGROW|wxALL, 10);
148 $reg_subsizer->Add($self->{License}->{Name}, 1, wxGROW|wxALL, 10);
149 $reg_subsizer->Add($LicenseKey, 1, wxGROW|wxALL, 10);
150 $reg_subsizer->Add($self->{License}->{Key}, 1, wxGROW|wxALL, 10);
151 }else{
152 ## register button
153 $self->{License}->{Name} = Wx::Button->new($self, -1, 'Enter registration key');
154 $reg_subsizer->Add($LicensedTo, 1, wxGROW|wxALL, 10);
155 $reg_subsizer->Add($self->{License}->{Name}, 1, wxGROW);
156 $reg_subsizer->Add($LicenseKey, 1, wxGROW|wxALL, 10);
157 $reg_subsizer->Add($self->{License}->{Key} = Wx::Panel->new($self), 1, wxGROW|wxALL, 10);
158  
159 EVT_BUTTON($self, $self->{License}->{Name}, sub {
160 my $dialog = Wx::TextEntryDialog->new($self, "Please enter the name on your license key:", "Wrangler Registration", '' );
161 return unless $dialog->ShowModal() == wxID_OK;
162 my $name = $dialog->GetValue();
163 $dialog->Destroy();
164  
165 $dialog = Wx::TextEntryDialog->new($self, "Please enter your license key:", "Wrangler Registration", '' );
166 return unless $dialog->ShowModal() == wxID_OK;
167 my $reg_key = $dialog->GetValue();
168 $dialog->Destroy();
169  
170 my $path = $Wrangler::Config::env{UserConfigDir} . $Wrangler::Config::env{PathSeparator} . "LICENSE-KEY";
171 open(my $fh, '>', $path) or Wrangler::debug("Could not open license file for writing: $path: $!");
172 binmode($fh);
173 print $fh $reg_key ."\n". $name;
174 close($fh);
175  
176 $reg_subsizer->Detach($self->{License}->{Name});
177 $self->{License}->{Name}->Destroy();
178 $reg_subsizer->Detach($self->{License}->{Key});
179 $self->{License}->{Key}->Destroy();
180  
181 $self->{License}->{Name} = Wx::TextCtrl->new($self, -1, $name, wxDefaultPosition, [250, -1], );
182 $self->{License}->{Name}->Disable();
183 $self->{License}->{Key} = Wx::TextCtrl->new($self, -1, $reg_key, wxDefaultPosition, [250, -1], );
184 $self->{License}->{Key}->Disable();
185  
186 $reg_subsizer->Insert(1, $self->{License}->{Name}, 1, wxGROW|wxALL, 10);
187 $reg_subsizer->Insert(3, $self->{License}->{Key}, 1, wxGROW|wxALL, 10);
188  
189 $purchase->SetLabel($text[1]);
190  
191 $self->Layout();
192 });
193 }
194  
195 $reg_sizer->Add($reg_subsizer, 0, wxLEFT|wxBOTTOM, 5);
196  
197 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
198 $sizer->AddGrowableCol(0);
199 $sizer->AddGrowableRow(0);
200 $sizer->Add($purchase, 1, wxGROW|wxALL, 10);
201 $sizer->Add($reg_sizer, 1, wxGROW|wxALL, 10);
202  
203 $self->SetSizer($sizer);
204  
205 return $self;
206 }
207  
208 sub ReadLicense {
209 my @license;
210  
211 my $commercial_package;
212 if($commercial_package){
213 $license[0] = 'generic license'; # commercial_package_reg_key
214 $license[1] = 'unspecified user'; # commercial_package_name
215 }elsif( my $path = $Wrangler::Config::env{UserConfigDir} ){
216 $path .= $Wrangler::Config::env{PathSeparator} . "LICENSE-KEY";
217 if(-f $path){
218 open(my $fh, "<", $path) or Wrangler::debug("Error opening license file: $!");
219 @license = <$fh>;
220 close($fh);
221 chomp($license[0]); chomp($license[1]);
222 }
223 }
224  
225 return @license;
226 }
227  
228  
229 package Wrangler::Wx::Dialog::About::License;
230  
231 use strict;
232 use warnings;
233  
234 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM wxTE_RICH wxTE_READONLY wxTE_MULTILINE);
235 use base 'Wx::Panel';
236  
237 sub new {
238 my $class = shift;
239 my $parent = shift;
240  
241 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
242  
243 # load the license
244 require Wrangler::License;
245 my $license = $Wrangler::License::text;
246  
247 # tab 3 EULA
248 my $textctrl = Wx::TextCtrl->new($self, -1, $license, wxDefaultPosition, wxDefaultSize, wxTE_RICH|wxTE_READONLY|wxTE_MULTILINE);
249  
250 my $sizer = Wx::FlexGridSizer->new(1, 1, 0, 0); # rows,cols,vgap,hgap
251 $sizer->AddGrowableCol(0);
252 $sizer->AddGrowableRow(0);
253 $sizer->Add($textctrl, 1, wxGROW|wxALL, 10);
254  
255 $self->SetSizer($sizer);
256  
257 return $self;
258 }
259  
260  
261 package Wrangler::Wx::Dialog::About::Changes;
262  
263 use strict;
264 use warnings;
265  
266 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM wxTE_RICH wxTE_READONLY wxTE_MULTILINE);
267 use base 'Wx::Panel';
268  
269 sub new {
270 my $class = shift;
271 my $parent = shift;
272  
273 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
274  
275 # load the changelog
276 require Wrangler::Changes;
277 my $changes = $Wrangler::Changes::text;
278  
279 # tab 4 changelog
280 my $textctrl = Wx::TextCtrl->new($self, -1, $changes, wxDefaultPosition, wxDefaultSize, wxTE_RICH|wxTE_READONLY|wxTE_MULTILINE);
281  
282 my $sizer = Wx::FlexGridSizer->new(1, 1, 0, 0); # rows,cols,vgap,hgap
283 $sizer->AddGrowableCol(0);
284 $sizer->AddGrowableRow(0);
285 $sizer->Add($textctrl, 1, wxGROW|wxALL, 10);
286  
287 $self->SetSizer($sizer);
288  
289 return $self;
290 }
291  
292 1;