1 | unit UMainForm;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | StdCtrls, Menus, ActnList, UModularSystem;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TMainForm }
|
---|
14 |
|
---|
15 | TMainForm = class(TForm)
|
---|
16 | published
|
---|
17 | AModuleInstall: TAction;
|
---|
18 | AModuleUninstall: TAction;
|
---|
19 | AModuleUpdate: TAction;
|
---|
20 | ActionList1: TActionList;
|
---|
21 | ButtonUpdate: TButton;
|
---|
22 | ButtonUninstall: TButton;
|
---|
23 | ButtonInstall: TButton;
|
---|
24 | ListViewModules: TListView;
|
---|
25 | MenuItem1: TMenuItem;
|
---|
26 | MenuItem2: TMenuItem;
|
---|
27 | MenuItem3: TMenuItem;
|
---|
28 | PopupMenu1: TPopupMenu;
|
---|
29 | procedure ButtonInstallClick(Sender: TObject);
|
---|
30 | procedure ButtonUninstallClick(Sender: TObject);
|
---|
31 | procedure ButtonUpdateClick(Sender: TObject);
|
---|
32 | procedure FormCreate(Sender: TObject);
|
---|
33 | procedure FormDestroy(Sender: TObject);
|
---|
34 | procedure FormShow(Sender: TObject);
|
---|
35 | procedure ListViewModulesData(Sender: TObject; Item: TListItem);
|
---|
36 | procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
|
---|
37 | Selected: Boolean);
|
---|
38 | private
|
---|
39 | procedure RegisterModules;
|
---|
40 | public
|
---|
41 | ModuleManager: TModuleManager;
|
---|
42 | procedure RefreshList;
|
---|
43 | end;
|
---|
44 |
|
---|
45 | const
|
---|
46 | InstalledText: array[Boolean] of string = ('Not installed', 'Installed');
|
---|
47 |
|
---|
48 | var
|
---|
49 | MainForm: TMainForm;
|
---|
50 |
|
---|
51 |
|
---|
52 | implementation
|
---|
53 |
|
---|
54 | {$R *.lfm}
|
---|
55 |
|
---|
56 | uses
|
---|
57 | UModuleUser, UModuleBase, UModuleACL;
|
---|
58 |
|
---|
59 |
|
---|
60 | { TMainForm }
|
---|
61 |
|
---|
62 | procedure TMainForm.ListViewModulesData(Sender: TObject; Item: TListItem);
|
---|
63 | begin
|
---|
64 | if (Item.Index >= 0) and (Item.Index < ModuleManager.Modules.Count) then
|
---|
65 | with TModule(ModuleManager.Modules[Item.Index]) do begin
|
---|
66 | Item.Caption := Title;
|
---|
67 | Item.Data := ModuleManager.Modules[Item.Index];
|
---|
68 | Item.SubItems.Add(Name);
|
---|
69 | Item.SubItems.Add(Version);
|
---|
70 | Item.SubItems.Add(InstalledText[Installed]);
|
---|
71 | Item.SubItems.Add(License);
|
---|
72 | Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll]));
|
---|
73 | Item.SubItems.Add(StringReplace(Description.Text, LineEnding, ', ', [rfReplaceAll]));
|
---|
74 | end;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | procedure TMainForm.ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
|
---|
78 | Selected: Boolean);
|
---|
79 | var
|
---|
80 | Installed: Boolean;
|
---|
81 | begin
|
---|
82 | if Assigned(ListViewModules.Selected) then Installed := TModule(ListViewModules.Selected.Data).Installed;
|
---|
83 | AModuleInstall.Enabled := Assigned(ListViewModules.Selected) and not Installed;
|
---|
84 | AModuleUninstall.Enabled := Assigned(ListViewModules.Selected) and Installed;
|
---|
85 | AModuleUpdate.Enabled := Assigned(ListViewModules.Selected) and Installed;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TMainForm.RegisterModules;
|
---|
89 | begin
|
---|
90 | ModuleManager.RegisterModule(TModuleUser.Create);
|
---|
91 | ModuleManager.RegisterModule(TModuleBase.Create);
|
---|
92 | ModuleManager.RegisterModule(TModuleACL.Create);
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TMainForm.RefreshList;
|
---|
96 | begin
|
---|
97 | ListViewModules.Items.Count := ModuleManager.Modules.Count;
|
---|
98 | ListViewModules.Refresh;
|
---|
99 | ListViewModulesSelectItem(ListViewModules, ListViewModules.Selected,
|
---|
100 | Assigned(ListViewModules.Selected));
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TMainForm.FormCreate(Sender: TObject);
|
---|
104 | begin
|
---|
105 | ModuleManager := TModuleManager.Create(nil);
|
---|
106 | RegisterModules;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TMainForm.ButtonInstallClick(Sender: TObject);
|
---|
110 | var
|
---|
111 | ModuleList: TStringList;
|
---|
112 | begin
|
---|
113 | if Assigned(ListViewModules.Selected) then begin
|
---|
114 | try
|
---|
115 | ModuleList := TStringList.Create;
|
---|
116 | TModule(ListViewModules.Selected.Data).EnumModulesInstall(ModuleList);
|
---|
117 | if ModuleList.Count > 0 then begin
|
---|
118 | if MessageDlg('These modules will be installed in addition to ' +
|
---|
119 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
---|
120 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
---|
121 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
---|
122 | TModule(ListViewModules.Selected.Data).Install;
|
---|
123 | end else TModule(ListViewModules.Selected.Data).Install;
|
---|
124 | finally
|
---|
125 | ModuleList.Free;
|
---|
126 | end;
|
---|
127 | RefreshList;
|
---|
128 | end;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TMainForm.ButtonUninstallClick(Sender: TObject);
|
---|
132 | var
|
---|
133 | ModuleList: TStringList;
|
---|
134 | begin
|
---|
135 | if Assigned(ListViewModules.Selected) then begin
|
---|
136 | try
|
---|
137 | ModuleList := TStringList.Create;
|
---|
138 | TModule(ListViewModules.Selected.Data).EnumModulesUninstall(ModuleList);
|
---|
139 | if ModuleList.Count > 0 then begin
|
---|
140 | if MessageDlg('These modules will be uninstalled in addition to ' +
|
---|
141 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
---|
142 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
---|
143 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
---|
144 | TModule(ListViewModules.Selected.Data).Uninstall;
|
---|
145 | end else TModule(ListViewModules.Selected.Data).Uninstall;
|
---|
146 | finally
|
---|
147 | ModuleList.Free;
|
---|
148 | end;
|
---|
149 |
|
---|
150 | RefreshList;
|
---|
151 | end;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TMainForm.ButtonUpdateClick(Sender: TObject);
|
---|
155 | begin
|
---|
156 | if Assigned(ListViewModules.Selected) then begin
|
---|
157 | TModule(ListViewModules.Selected.Data).Update;
|
---|
158 | RefreshList;
|
---|
159 | end;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TMainForm.FormDestroy(Sender: TObject);
|
---|
163 | begin
|
---|
164 | ModuleManager.Free;
|
---|
165 | end;
|
---|
166 |
|
---|
167 | procedure TMainForm.FormShow(Sender: TObject);
|
---|
168 | begin
|
---|
169 | RefreshList;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | end.
|
---|
173 |
|
---|