-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathDN.PackageDetailView.pas
223 lines (199 loc) · 6.39 KB
/
DN.PackageDetailView.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.PackageDetailView;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
DN.Types,
DN.Package.Intf,
DN.Controls,
DN.Version,
Delphinus.Forms,
ImgList
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF CompilerVersion >= 29.0}
,System.ImageList
{$IFEND}
{$ENDIF};
type
TGetPackageVersion = function(const APackage: IDNPackage): TDNVersion of object;
TPackageDetailView = class(TFrame)
imgRepo: TImage;
lbDescription: TLabel;
lbAuthor: TLabel;
Label1: TLabel;
pnlHeader: TPanel;
pnlDetail: TPanel;
Label2: TLabel;
lbSupports: TLabel;
lbInstalledCaption: TLabel;
lbInstalled: TLabel;
Label3: TLabel;
lbLicense: TLabel;
btnLicense: TButton;
btnHome: TButton;
ilButtons: TImageList;
btnProject: TButton;
btnReport: TButton;
Label5: TLabel;
lbPlatforms: TLabel;
Label4: TLabel;
lbVersion: TLabel;
procedure Button1Click(Sender: TObject);
procedure btnLicenseClick(Sender: TObject);
procedure btnHomeClick(Sender: TObject);
procedure btnProjectClick(Sender: TObject);
procedure btnReportClick(Sender: TObject);
private
FCanvas: TControlCanvas;
FPackage: IDNPackage;
FOnGetInstalledVersion: TGetPackageVersion;
FOnGetOnlineVersion: TGetPackageVersion;
FDummyPic: TGraphic;
procedure LoadIcons;
procedure SetPackage(const Value: IDNPackage);
function GetInstalledVersion(const APackage: IDNPackage): TDNVersion;
function GetOnlineVersion(const APackage: IDNPackage): TDNVersion;
{ Private declarations }
protected
procedure OpenUrl(const AUrl: string);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
property DummyPic: TGraphic read FDummyPic write FDummyPic;
property Package: IDNPackage read FPackage write SetPackage;
property OnGetInstalledVersion: TGetPackageVersion read FOnGetInstalledVersion write FOnGetInstalledVersion;
property OnGetOnlineVersion: TGetPackageVersion read FOnGetOnlineVersion write FOnGetOnlineVersion;
end;
implementation
uses
Delphinus.LicenseDialog,
Delphinus.Resources.Names,
Delphinus.Resources,
ShellAPi,
DN.Compiler.Intf,
DN.Utils;
{$R *.dfm}
{ TFrame1 }
procedure TPackageDetailView.btnHomeClick(Sender: TObject);
begin
OpenUrl(FPackage.HomepageUrl);
end;
procedure TPackageDetailView.btnLicenseClick(Sender: TObject);
var
LDialog: TLicenseDialog;
begin
LDialog := TLicenseDialog.Create(nil);
try
LDialog.Package := FPackage;
LDialog.ShowModal();
finally
LDialog.Free;
end;
end;
procedure TPackageDetailView.btnProjectClick(Sender: TObject);
begin
OpenUrl(FPackage.ProjectUrl);
end;
procedure TPackageDetailView.btnReportClick(Sender: TObject);
begin
OpenUrl(FPackage.ReportUrl);
end;
procedure TPackageDetailView.Button1Click(Sender: TObject);
begin
Visible := False;
end;
constructor TPackageDetailView.Create(AOwner: TComponent);
begin
inherited;
FCanvas := TControlCanvas.Create();
TControlCanvas(FCanvas).Control := Self;
Package := nil;
LoadIcons();
end;
destructor TPackageDetailView.Destroy;
begin
FreeAndNil(FCanvas);
inherited;
end;
function TPackageDetailView.GetInstalledVersion(
const APackage: IDNPackage): TDNVersion;
begin
if Assigned(FOnGetInstalledVersion) then
Result := FOnGetInstalledVersion(APackage)
else
Result := TDNVersion.Create();
end;
function TPackageDetailView.GetOnlineVersion(
const APackage: IDNPackage): TDNVersion;
begin
if Assigned(FOnGetOnlineVersion) then
Result := FOnGetOnlineVersion(APackage)
else
Result := TDNVersion.Create();
if Result.IsEmpty then
Result := GetInstalledVersion(APackage);
end;
procedure TPackageDetailView.LoadIcons;
begin
btnLicense.ImageIndex := AddIconToImageList(ilButtons, Ico_Agreement);
btnLicense.DisabledImageIndex := AddIconToImageList(ilButtons, Ico_Agreement_Disabled);
btnHome.ImageIndex := AddIconToImageList(ilButtons, Ico_Home);
btnHome.DisabledImageIndex := AddIconToImageList(ilButtons, Ico_Home_Disabled);
btnProject.ImageIndex := AddIconToImageList(ilButtons, Ico_Repo);
btnProject.DisabledImageIndex := AddIconToImageList(ilButtons, Ico_Repo_Disabled);
btnReport.ImageIndex := AddIconToImageList(ilButtons, Ico_Bug);
btnReport.DisabledImageIndex := AddIconToImageList(ilButtons, Ico_Bug_Disabled);
end;
procedure TPackageDetailView.OpenUrl(const AUrl: string);
begin
ShellExecute(0, 'OPEN', PChar(AUrl), '', '', SW_SHOWNORMAL);
end;
procedure TPackageDetailView.SetPackage(const Value: IDNPackage);
begin
FPackage := Value;
if Assigned(FPackage) then
begin
lbAuthor.Caption := FPackage.Author;
if Trim(FPackage.Description) = '' then
lbDescription.Caption := FPackage.Name
else
lbDescription.Caption := FPackage.Description;
lbSupports.Caption := GenerateSupportsString(FPackage.CompilerMin, FPackage.CompilerMax);
if Assigned(FPackage.Picture.Graphic) then
imgRepo.Picture := FPackage.Picture
else
imgRepo.Picture.Graphic := FDummyPic;
lbLicense.Caption := FPackage.LicenseTypes;
lbVersion.Caption := GetOnlineVersion(FPackage).ToString;
lbInstalled.Caption := GetInstalledVersion(FPackage).ToString;
lbPlatforms.Caption := GeneratePlatformString(FPackage.Platforms);
btnHome.Enabled := FPackage.HomepageUrl <> '';
btnHome.Hint := FPackage.HomepageUrl;
btnProject.Enabled := FPackage.ProjectUrl <> '';
btnReport.Enabled := FPackage.ReportUrl <> '';
end
else
begin
lbAuthor.Caption := '';
lbDescription.Caption := '';
lbSupports.Caption := '';
lbVersion.Caption := '';
lbInstalled.Caption := '';
lbLicense.Caption := '';
lbPlatforms.Caption := '';
imgRepo.Picture := nil;
btnHome.Enabled := False;
btnProject.Enabled := False;
btnReport.Enabled := False;
end;
btnLicense.Enabled := lbLicense.Caption <> '';
end;
end.