| 1 | unit USourceSelection;
|
|---|
| 2 |
|
|---|
| 3 | {$mode objfpc}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 9 | StdCtrls, USource, HttpSend;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TSourceSelectionForm }
|
|---|
| 14 |
|
|---|
| 15 | TSourceSelectionForm = class(TForm)
|
|---|
| 16 | ButtonOk: TButton;
|
|---|
| 17 | ButtonCancel: TButton;
|
|---|
| 18 | ButtonUpdateSource: TButton;
|
|---|
| 19 | ListView1: TListView;
|
|---|
| 20 | procedure FormCreate(Sender: TObject);
|
|---|
| 21 | procedure FormDestroy(Sender: TObject);
|
|---|
| 22 | procedure FormShow(Sender: TObject);
|
|---|
| 23 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 24 | procedure ButtonUpdateSourceClick(Sender: TObject);
|
|---|
| 25 | private
|
|---|
| 26 | { private declarations }
|
|---|
| 27 | public
|
|---|
| 28 | ProjectType: string;
|
|---|
| 29 | Sources: TSourceList;
|
|---|
| 30 | procedure ReloadList;
|
|---|
| 31 | end;
|
|---|
| 32 |
|
|---|
| 33 | var
|
|---|
| 34 | SourceSelectionForm: TSourceSelectionForm;
|
|---|
| 35 |
|
|---|
| 36 | implementation
|
|---|
| 37 |
|
|---|
| 38 | {$R *.lfm}
|
|---|
| 39 |
|
|---|
| 40 | uses
|
|---|
| 41 | UMainForm;
|
|---|
| 42 |
|
|---|
| 43 | { TSourceSelectionForm }
|
|---|
| 44 |
|
|---|
| 45 | procedure TSourceSelectionForm.ReloadList;
|
|---|
| 46 | var
|
|---|
| 47 | I: Integer;
|
|---|
| 48 | begin
|
|---|
| 49 | Sources.Clear;
|
|---|
| 50 | for I := 0 to MainForm.Sources.Count - 1 do
|
|---|
| 51 | if (TSource(MainForm.Sources[I]).ProjectType = ProjectType) or
|
|---|
| 52 | (ProjectType = '') then
|
|---|
| 53 | Sources.Add(MainForm.Sources[I]);
|
|---|
| 54 | if ListView1.Items.Count <> Sources.Count then
|
|---|
| 55 | ListView1.Items.Count := Sources.Count;
|
|---|
| 56 | ListView1.Items[-1]; // workaround
|
|---|
| 57 | ListView1.Refresh;
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | procedure TSourceSelectionForm.ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 61 | begin
|
|---|
| 62 | if Item.Index < Sources.Count then
|
|---|
| 63 | with TSource(Sources[Item.Index]) do begin
|
|---|
| 64 | Item.Caption := ProjectName;
|
|---|
| 65 | Item.Data := Sources[Item.Index];
|
|---|
| 66 | Item.SubItems.Add(VersionType);
|
|---|
| 67 | Item.SubItems.Add(VersionNumber);
|
|---|
| 68 | Item.SubItems.Add('');
|
|---|
| 69 | Item.SubItems.Add('');
|
|---|
| 70 | Item.SubItems.Add(BooleanText[Downloaded]);
|
|---|
| 71 | Item.SubItems.Add(SubversionURL);
|
|---|
| 72 | end;
|
|---|
| 73 | end;
|
|---|
| 74 |
|
|---|
| 75 | procedure TSourceSelectionForm.FormShow(Sender: TObject);
|
|---|
| 76 | begin
|
|---|
| 77 | ReloadList;
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | procedure TSourceSelectionForm.FormCreate(Sender: TObject);
|
|---|
| 81 | begin
|
|---|
| 82 | Sources := TSourceList.Create;
|
|---|
| 83 | Sources.OwnsObjects := False;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | procedure TSourceSelectionForm.FormDestroy(Sender: TObject);
|
|---|
| 87 | begin
|
|---|
| 88 | Sources.Free;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TSourceSelectionForm.ButtonUpdateSourceClick(Sender: TObject);
|
|---|
| 92 | var
|
|---|
| 93 | fs: TFileStream;
|
|---|
| 94 | begin
|
|---|
| 95 | fs := TFileStream.Create(ExtractFileName(MainForm.SourceURL), fmOpenWrite or fmCreate);
|
|---|
| 96 | try
|
|---|
| 97 | HttpGetBinary(MainForm.SourceURL, fs);
|
|---|
| 98 | finally
|
|---|
| 99 | fs.Free;
|
|---|
| 100 | end;
|
|---|
| 101 | MainForm.Sources.UpdateFormFile(ExtractFileName(MainForm.SourceURL));
|
|---|
| 102 | ReloadList;
|
|---|
| 103 | end;
|
|---|
| 104 |
|
|---|
| 105 | end.
|
|---|
| 106 |
|
|---|