Menu

[r2337]: / trunk / Src / FmProgramUpdatesDlg.pas  Maximize  Restore  History

Download this file

153 lines (127 with data), 3.7 kB

  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
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2012, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a dialogue box that accesses program update web service and
* reports if a new version of CodeSnip is available.
}
unit FmProgramUpdatesDlg;
interface
uses
// Delphi
StdCtrls, Controls, ExtCtrls, Classes,
// Project
FmGenericViewDlg, UBaseObjects, UUpdateMgr, Web.UProgramUpdateMgr;
type
TProgramUpdatesDlg = class(TGenericViewDlg, INoPublicConstruct)
lblProgram: TLabel;
btnProgUpdate: TButton;
lblPreReleaseMsg: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnProgUpdateClick(Sender: TObject);
strict private
var
fDBUpdateMgr: TUpdateMgr;
fProgUpdateMgr: TProgramUpdateMgr;
procedure CheckProgramUpdates;
strict protected
/// <summary>Triggers checks for updates.</summary>
/// <remarks>Called from ancestor class.</remarks>
procedure AfterShowForm; override;
procedure ArrangeForm; override;
public
class procedure Execute(AOwner: TComponent);
end;
implementation
uses
// Delphi
SysUtils, Forms, ExtActns,
// Project
UAppInfo, UCtrlArranger, Web.UInfo;
{$R *.dfm}
{ TCheckUpdatesDlg }
resourcestring
sChecking = 'Checking...';
sDBNeedsUpdating = 'An update to the online database is available.';
sDBUpToDate = 'The online database is up to date.';
sProgNeedsUpdating = 'CodeSnip version %s is available.';
sProgUpToDate = 'CodeSnip is up to date.';
procedure TProgramUpdatesDlg.AfterShowForm;
begin
Screen.Cursor := crHourGlass;
try
CheckProgramUpdates;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TProgramUpdatesDlg.ArrangeForm;
begin
TCtrlArranger.SetLabelHeight(lblPreReleaseMsg);
TCtrlArranger.MoveBelow(lblProgram, btnProgUpdate, 12);
TCtrlArranger.MoveBelow(lblProgram, lblPreReleaseMsg, 8);
pnlBody.ClientHeight := TCtrlArranger.TotalControlHeight(pnlBody) + 8;
TCtrlArranger.AlignLefts([lblProgram, btnProgUpdate, lblPreReleaseMsg], 0);
pnlBody.Width := TCtrlArranger.TotalControlWidth(pnlBody);
inherited;
end;
procedure TProgramUpdatesDlg.btnProgUpdateClick(Sender: TObject);
var
BrowseAction: TBrowseURL; // action that displays RSS feed URL in browser
begin
BrowseAction := TBrowseURL.Create(nil);
try
BrowseAction.URL := TWebInfo.ProgramDownloadURL;
BrowseAction.Execute;
finally
BrowseAction.Free;
end;
end;
procedure TProgramUpdatesDlg.CheckProgramUpdates;
var
Version: string;
begin
btnProgUpdate.Visible := False;
lblProgram.Caption := sChecking;
Application.ProcessMessages;
if not not fProgUpdateMgr.IsLatest then
begin
Version := fProgUpdateMgr.LatestProgramVersion;
lblProgram.Caption := Format(sProgNeedsUpdating, [Version]);
btnProgUpdate.Visible := True;
end
else
begin
lblProgram.Caption := sProgUpToDate;
lblPreReleaseMsg.Visible := True;
end;
end;
class procedure TProgramUpdatesDlg.Execute(AOwner: TComponent);
begin
with InternalCreate(AOwner) do
try
ShowModal;
finally
Free;
end;
end;
procedure TProgramUpdatesDlg.FormCreate(Sender: TObject);
begin
inherited;
fDBUpdateMgr := TUpdateMgr.Create(TAppInfo.AppDataDir);
fProgUpdateMgr := TProgramUpdateMgr.Create;
end;
procedure TProgramUpdatesDlg.FormDestroy(Sender: TObject);
begin
fProgUpdateMgr.Free;
fDBUpdateMgr.Free;
inherited;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.