Wrangler/Wx/Dialog/About.pm untested

filter: Statementstmt 0.0% 0 / 232 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 32 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 297 CC 11 SCAR 25.6
CC
11
Cov
0%
new
56.0
ReadLicense
20.0
new
6.0
CRAP 12.9
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 sub new {
73 my $class = shift;
74 my $parent = shift;
75  
76 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
77  
78 # our ImagePanelPanel (we attach the Bitmap OnPaint)
79 $self->{panel} = Wx::Panel->new($self, -1, wxDefaultPosition, [425,251], wxGROW);
80 $self->{bmp} = Wx::Bitmap->newFromXPM($Wrangler::Images::image{'logo_2.x_splash425'});
81  
82 my $text = Wx::StaticText->new($self, -1, "This is Wrangler.\nVersion $Wrangler::VERSION\n\n© 2009-2014 Clipland GmbH. All rights reserved.");
83 $text->SetForegroundColour(Wx::Colour->new(45,45,45) );
84  
85 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
86 $sizer->AddGrowableCol(0);
87 $sizer->AddGrowableRow(0);
88 $sizer->Add($self->{panel}, 0, wxALIGN_CENTER|wxALL, 10);
89 $sizer->Add($text, 0, wxLEFT, 10);
90  
91 $self->SetSizer($sizer);
92  
93 EVT_PAINT($self, \&OnPaint );
94  
95 return $self;
96 }
97  
98 sub OnPaint {
99 my ($self, $event) = @_;
100  
101 my $dc = Wx::PaintDC->new($self->{panel});
102 $dc->DrawBitmap($self->{bmp}, 0,0 , 0);
103 }
104  
105  
106 package Wrangler::Wx::Dialog::About::Purchase;
107  
108 use strict;
109 use warnings;
110  
111 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxID_OK wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM);
112 use Wx::Event qw(EVT_BUTTON);
113 use base 'Wx::Panel';
114  
115 sub new {
116 my $class = shift;
117 my $parent = shift;
118 my $about_dialog = shift;
119  
120 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
121  
122 my @license = ReadLicense();
123  
124 my @text = (
125 "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",
126 "\n\n\n\nThis installation of Wrangler is licensed for commercial use."
127 );
128  
129 # tab 2 Purchase
130 my $purchase = Wx::StaticText->new($self, -1, (@license ? $text[1] : $text[0]), wxDefaultPosition, wxDefaultSize );
131 $purchase->SetForegroundColour(Wx::Colour->new(45,45,45) );
132 my $reg_box = Wx::StaticBox->new($self, -1, "Registration information" );
133 my $reg_sizer = Wx::StaticBoxSizer->new($reg_box, wxVERTICAL);
134 my $LicensedTo = Wx::StaticText->new($self, -1, "Licensed to", wxDefaultPosition, wxDefaultSize, );
135 my $LicenseKey = Wx::StaticText->new($self, -1, "License Key", wxDefaultPosition, wxDefaultSize, );
136  
137 my $reg_subsizer = Wx::FlexGridSizer->new(2, 2, 0, 0); # rows,cols,vgap,hgap
138 if(@license){
139 $self->{License}->{Name} = Wx::TextCtrl->new($self, -1, ($license[1] ? $license[1] : ''), wxDefaultPosition, [250, -1], );
140 $self->{License}->{Name}->Disable();
141 $self->{License}->{Key} = Wx::TextCtrl->new($self, -1, ($license[0] ? $license[0] : ''), wxDefaultPosition, [250, -1], );
142 $self->{License}->{Key}->Disable();
143 $reg_subsizer->Add($LicensedTo, 1, wxGROW|wxALL, 10);
144 $reg_subsizer->Add($self->{License}->{Name}, 1, wxGROW|wxALL, 10);
145 $reg_subsizer->Add($LicenseKey, 1, wxGROW|wxALL, 10);
146 $reg_subsizer->Add($self->{License}->{Key}, 1, wxGROW|wxALL, 10);
147 }else{
148 ## register button
149 $self->{License}->{Name} = Wx::Button->new($self, -1, 'Enter registration key');
150 $reg_subsizer->Add($LicensedTo, 1, wxGROW|wxALL, 10);
151 $reg_subsizer->Add($self->{License}->{Name}, 1, wxGROW);
152 $reg_subsizer->Add($LicenseKey, 1, wxGROW|wxALL, 10);
153 $reg_subsizer->Add($self->{License}->{Key} = Wx::Panel->new($self), 1, wxGROW|wxALL, 10);
154  
155 EVT_BUTTON($self, $self->{License}->{Name}, sub {
156 my $dialog = Wx::TextEntryDialog->new($self, "Please enter the name on your license key:", "Wrangler Registration", '' );
157 return unless $dialog->ShowModal() == wxID_OK;
158 my $name = $dialog->GetValue();
159 $dialog->Destroy();
160  
161 $dialog = Wx::TextEntryDialog->new($self, "Please enter your license key:", "Wrangler Registration", '' );
162 return unless $dialog->ShowModal() == wxID_OK;
163 my $reg_key = $dialog->GetValue();
164 $dialog->Destroy();
165  
166 my $path = $Wrangler::Config::env{UserConfigDir} . $Wrangler::Config::env{PathSeparator} . "LICENSE-KEY";
167 open(my $fh, '>', $path) or Wrangler::debug("Could not open license file for writing: $path: $!");
168 binmode($fh);
169 print $fh $reg_key ."\n". $name;
170 close($fh);
171  
172 $reg_subsizer->Detach($self->{License}->{Name});
173 $self->{License}->{Name}->Destroy();
174 $reg_subsizer->Detach($self->{License}->{Key});
175 $self->{License}->{Key}->Destroy();
176  
177 $self->{License}->{Name} = Wx::TextCtrl->new($self, -1, $name, wxDefaultPosition, [250, -1], );
178 $self->{License}->{Name}->Disable();
179 $self->{License}->{Key} = Wx::TextCtrl->new($self, -1, $reg_key, wxDefaultPosition, [250, -1], );
180 $self->{License}->{Key}->Disable();
181  
182 $reg_subsizer->Insert(1, $self->{License}->{Name}, 1, wxGROW|wxALL, 10);
183 $reg_subsizer->Insert(3, $self->{License}->{Key}, 1, wxGROW|wxALL, 10);
184  
185 $purchase->SetLabel($text[1]);
186  
187 $self->Layout();
188 });
189 }
190  
191 $reg_sizer->Add($reg_subsizer, 0, wxLEFT|wxBOTTOM, 5);
192  
193 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
194 $sizer->AddGrowableCol(0);
195 $sizer->AddGrowableRow(0);
196 $sizer->Add($purchase, 1, wxGROW|wxALL, 10);
197 $sizer->Add($reg_sizer, 1, wxGROW|wxALL, 10);
198  
199 $self->SetSizer($sizer);
200  
201 return $self;
202 }
203  
204 sub ReadLicense {
205 my @license;
206  
207 my $commercial_package;
208 if($commercial_package){
209 $license[0] = 'generic license'; # commercial_package_reg_key
210 $license[1] = 'unspecified user'; # commercial_package_name
211 }elsif( my $path = $Wrangler::Config::env{UserConfigDir} ){
212 $path .= $Wrangler::Config::env{PathSeparator} . "LICENSE-KEY";
213 if(-f $path){
214 open(my $fh, "<", $path) or Wrangler::debug("Error opening license file: $!");
215 @license = <$fh>;
216 close($fh);
217 chomp($license[0]); chomp($license[1]);
218 }
219 }
220  
221 return @license;
222 }
223  
224  
225 package Wrangler::Wx::Dialog::About::License;
226  
227 use strict;
228 use warnings;
229  
230 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM wxTE_RICH wxTE_READONLY wxTE_MULTILINE);
231 use base 'Wx::Panel';
232  
233 sub new {
234 my $class = shift;
235 my $parent = shift;
236  
237 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
238  
239 # load the license
240 require Wrangler::License;
241 my $license = $Wrangler::License::text;
242  
243 # tab 3 EULA
244 my $textctrl = Wx::TextCtrl->new($self, -1, $license, wxDefaultPosition, wxDefaultSize, wxTE_RICH|wxTE_READONLY|wxTE_MULTILINE);
245  
246 my $sizer = Wx::FlexGridSizer->new(1, 1, 0, 0); # rows,cols,vgap,hgap
247 $sizer->AddGrowableCol(0);
248 $sizer->AddGrowableRow(0);
249 $sizer->Add($textctrl, 1, wxGROW|wxALL, 10);
250  
251 $self->SetSizer($sizer);
252  
253 return $self;
254 }
255  
256  
257 package Wrangler::Wx::Dialog::About::Changes;
258  
259 use strict;
260 use warnings;
261  
262 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM wxTE_RICH wxTE_READONLY wxTE_MULTILINE);
263 use base 'Wx::Panel';
264  
265 sub new {
266 my $class = shift;
267 my $parent = shift;
268  
269 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
270  
271 # load the changelog
272 require Wrangler::Changes;
273 my $changes = $Wrangler::Changes::text;
274  
275 # tab 4 changelog
276 my $textctrl = Wx::TextCtrl->new($self, -1, $changes, wxDefaultPosition, wxDefaultSize, wxTE_RICH|wxTE_READONLY|wxTE_MULTILINE);
277  
278 my $sizer = Wx::FlexGridSizer->new(1, 1, 0, 0); # rows,cols,vgap,hgap
279 $sizer->AddGrowableCol(0);
280 $sizer->AddGrowableRow(0);
281 $sizer->Add($textctrl, 1, wxGROW|wxALL, 10);
282  
283 $self->SetSizer($sizer);
284  
285 return $self;
286 }
287  
288 1;