-
Notifications
You must be signed in to change notification settings - Fork 6
/
view.mmpFormAbout.pas
289 lines (247 loc) · 8.63 KB
/
view.mmpFormAbout.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{ MMP: Minimalist Media Player
Copyright (C) 2021-2024 Baz Cuda
https://github.com/BazzaCuda/MinimalistMediaPlayerX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
}
unit view.mmpFormAbout;
interface
uses
winApi.messages, winApi.windows,
system.sysUtils, system.variants, system.classes,
vcl.controls, vcl.dialogs, vcl.extCtrls, vcl.forms, vcl.graphics, vcl.imaging.pngImage, vcl.stdCtrls,
mmpNotify.notices, mmpNotify.notifier, mmpNotify.subscriber;
type
IAboutForm = interface
['{958B8D00-5F85-401C-80F8-390721F9AE39}']
function notify(const aNotice: INotice): INotice;
end;
{$REGION}
// this should be in the implementation section but that would cause problems with the IDE
TAboutForm = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
lblReleaseVersion: TLabel;
lblCopyright: TLabel;
Label4: TLabel;
Label5: TLabel;
lblWebsiteURL: TLabel;
Bevel1: TBevel;
btnClose: TButton;
Bevel2: TBevel;
Label6: TLabel;
lblBuildVersion: TLabel;
lblLatestReleaseVersion: TLabel;
Label7: TLabel;
btnWhatsNew: TButton;
Label3: TLabel;
lblWikiURL: TLabel;
btnLicence: TButton;
procedure lblWebsiteURLClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure lblWebsiteURLMouseEnter(Sender: TObject);
procedure lblWebsiteURLMouseLeave(Sender: TObject);
procedure btnWhatsNewClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure lblWikiURLClick(Sender: TObject);
procedure lblWikiURLMouseEnter(Sender: TObject);
procedure lblWikiURLMouseLeave(Sender: TObject);
procedure btnLicenceClick(Sender: TObject);
protected
function setBuildVersion(const aBuild: string): boolean;
function setCopyrightYear(const aYear: WORD): boolean;
function setLatestReleaseVersion(const aRelease: string): boolean;
function setReleaseVersion(const aRelease: string): boolean;
function setNoStyle: boolean;
function setWhatsNew(const aHasReleaseNotes: boolean): boolean;
function compareVersions(const thisVersion: string; const latestVersion: string): boolean;
public
end;
{$ENDREGION}
implementation
uses
shellAPI,
mmpFileUtils, mmpProgramUpdates, mmpShellUtils, mmpUtils,
view.mmpFormProgress, view.mmpFormReleaseNotes,
_debugWindow;
type
TAboutFormProxy = class(TInterfacedObject, IAboutForm)
strict private
FProgramUpdates: IProgramUpdates;
FProgressForm: TProgressForm;
FSubscriber: ISubscriber;
private
procedure timerTimer(Sender: TObject);
function onNotify(const aNotice: INotice): INotice;
function showForm(const thisVersion: string; const buildVersion: string): boolean; overload;
function showForm: boolean; overload;
function showProgressForm: boolean;
public
constructor create;
destructor Destroy; override;
function notify(const aNotice: INotice): INotice;
end;
var gAboutFormProxy: IAboutForm = NIL;
function AB: IAboutForm;
begin
case gAboutFormProxy = NIL of TRUE: gAboutFormProxy := TAboutFormProxy.create; end;
result := gAboutFormProxy;
end;
{$R *.dfm}
procedure TAboutForm.btnCloseClick(Sender: TObject);
begin
modalResult := mrOK;
end;
procedure TAboutForm.btnLicenceClick(Sender: TObject);
begin
gAboutFormProxy.notify(newNotice(evAboutGNULicenceShow));
end;
procedure TAboutForm.btnWhatsNewClick(Sender: TObject);
begin
gAboutFormProxy.notify(newNotice(evAboutReleaseNotesFormShow));
end;
function TAboutForm.compareVersions(const thisVersion: string; const latestVersion: string): boolean;
begin
case latestVersion[1] = 'v' of FALSE: EXIT; end;
case thisVersion = latestVersion of FALSE: lblLatestReleaseVersion.font.style := [fsBold, fsUnderline]; end;
end;
procedure TAboutForm.FormShow(Sender: TObject);
begin
case btnWhatsNew.visible of TRUE: btnWhatsNew.setFocus; end;
btnClose.cancel := TRUE;
end;
procedure TAboutForm.lblWebsiteURLClick(Sender: TObject);
begin
mmpShellExec('https://github.com/BazzaCuda/MinimalistMediaPlayerX/releases/latest');
end;
procedure TAboutForm.lblWebsiteURLMouseEnter(Sender: TObject);
begin
lblWebsiteURL.font.style := [fsUnderline];
end;
procedure TAboutForm.lblWebsiteURLMouseLeave(Sender: TObject);
begin
lblWebsiteURL.font.style := [];
end;
procedure TAboutForm.lblWikiURLClick(Sender: TObject);
begin
mmpShellExec('https://minimalistmediaplayer.com');
end;
procedure TAboutForm.lblWikiURLMouseEnter(Sender: TObject);
begin
lblWikiURL.font.style := [fsUnderline];
end;
procedure TAboutForm.lblWikiURLMouseLeave(Sender: TObject);
begin
lblWikiURL.font.style := [];
end;
function TAboutForm.setBuildVersion(const aBuild: string): boolean;
begin
lblBuildVersion.Caption := aBuild;
end;
function TAboutForm.setCopyrightYear(const aYear: WORD): boolean;
begin
lblCopyright.caption := lblCopyright.caption + intToStr(aYear);
end;
function TAboutForm.setLatestReleaseVersion(const aRelease: string): boolean;
begin
lblLatestReleaseVersion.caption := aRelease;
end;
function TAboutForm.setNoStyle: boolean;
begin
lblWebsiteURL.styleElements := [seClient, seBorder];
lblWikiURL.styleElements := [seClient, seBorder];
end;
function TAboutForm.setReleaseVersion(const aRelease: string): boolean;
begin
lblReleaseVersion.Caption := aRelease;
end;
function TAboutForm.setWhatsNew(const aHasReleaseNotes: boolean): boolean;
begin
btnWhatsNew.visible := aHasReleaseNotes;
btnWhatsNew.default := aHasReleaseNotes;
end;
{ TAboutBoxFormProxy }
constructor TAboutFormProxy.create;
begin
inherited;
FSubscriber := appNotifier.subscribe(newSubscriber(onNotify));
FProgramUpdates := newProgramUpdates;
end;
destructor TAboutFormProxy.Destroy;
begin
appNotifier.unsubscribe(FSubscriber);
inherited;
end;
function TAboutFormProxy.notify(const aNotice: INotice): INotice;
begin
result := onNotify(aNotice);
end;
function TAboutFormProxy.onNotify(const aNotice: INotice): INotice;
begin
case aNotice = NIL of TRUE: EXIT; end;
case aNotice.event of
evAboutFormShow: showForm;
evAboutReleaseNotesFormShow: showReleaseNotes('Release Notes ' + FProgramUpdates.releaseTag, FProgramUpdates.getReleaseNotesFilePath(FProgramUpdates.releaseTag));
evAboutGNULicenceShow: showReleaseNotes('GNU General Public License', mmpExePath + 'license');
end;
end;
function TAboutFormProxy.showForm(const thisVersion, buildVersion: string): boolean;
begin
notifyApp(newNotice(evGSShowingAbout, TRUE));
showProgressForm;
with TAboutForm.create(NIL) do
try
setNoStyle;
setCopyrightYear(currentYear);
setReleaseVersion(thisVersion);
setBuildVersion(buildVersion);
setLatestReleaseVersion(FProgramUpdates.releaseTag); // if the releaseTag is got, PU also downloads the release zip file and the release notes
compareVersions(thisVersion, FProgramUpdates.releaseTag);
setWhatsNew(FProgramUpdates.hasReleaseNotes(FProgramUpdates.releaseTag));
showModal;
finally
free;
notifyApp(newNotice(evGSShowingAbout, FALSE));
end;
end;
function TAboutFormProxy.showForm: boolean;
begin
showForm(mmpFileVersionFmt('', 'v%d.%d.%d'), mmpFileVersionFmt);
end;
function TAboutFormProxy.showProgressForm: boolean;
begin
FProgressForm := TProgressForm.create(NIL);
try
FProgressForm.modal := FALSE;
FProgressForm.buttons := FALSE;
FProgressForm.heading.caption := 'MMP: Minimalist Media Player';
FProgressForm.subHeading.caption := 'Loading About Box...';
FProgressForm.show;
mmpProcessMessages;
setWindowPos(FProgressForm.handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE);
FProgressForm.timer.interval := 1000;
FProgressForm.timer.OnTimer := timerTimer;
FProgressForm.timer.enabled := TRUE;
finally
end;
end;
procedure TAboutFormProxy.timerTimer(Sender: TObject);
begin
FProgressForm.timer.enabled := FALSE;
freeAndNIL(FProgressForm);
end;
initialization
AB; // to create the appNotifier listener and IProgramUpdates
finalization
gAboutFormProxy := NIL;
end.