source: trunk/Packages/ModularSystem/Demo/UMainForm.pas

Last change on this file was 73, checked in by chronos, 12 years ago
  • Modified: Packages are now stored as uncomporessed and are linked with relative path to project.
File size: 7.2 KB
Line 
1unit UMainForm;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 StdCtrls, Menus, ActnList, UModularSystem;
10
11type
12
13 { TMainForm }
14
15 TMainForm = class(TForm)
16 published
17 AModuleStart: TAction;
18 AModuleStop: TAction;
19 AModuleInstall: TAction;
20 AModuleUninstall: TAction;
21 AModuleUpdate: TAction;
22 ActionList1: TActionList;
23 ButtonUpdate: TButton;
24 ButtonUninstall: TButton;
25 ButtonInstall: TButton;
26 ButtonUpdate1: TButton;
27 ButtonUpdate2: TButton;
28 ListViewModules: TListView;
29 MenuItem1: TMenuItem;
30 MenuItem2: TMenuItem;
31 MenuItem3: TMenuItem;
32 MenuItem4: TMenuItem;
33 MenuItem5: TMenuItem;
34 ModuleManager: TModuleManager;
35 PopupMenu1: TPopupMenu;
36 procedure AModuleStartExecute(Sender: TObject);
37 procedure AModuleStopExecute(Sender: TObject);
38 procedure ButtonInstallClick(Sender: TObject);
39 procedure ButtonUninstallClick(Sender: TObject);
40 procedure ButtonUpdateClick(Sender: TObject);
41 procedure FormCreate(Sender: TObject);
42 procedure FormDestroy(Sender: TObject);
43 procedure FormShow(Sender: TObject);
44 procedure ListViewModulesData(Sender: TObject; Item: TListItem);
45 procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
46 Selected: Boolean);
47 private
48 procedure RegisterModules;
49 public
50 procedure Log(Text: string);
51 procedure RefreshList;
52 end;
53
54const
55 BoolText: array[Boolean] of string = ('No', 'Yes');
56
57var
58 MainForm: TMainForm;
59
60
61implementation
62
63{$R *.lfm}
64
65uses
66 UModuleUser, UModuleBase, UModuleACL, ULogForm;
67
68
69{ TMainForm }
70
71procedure TMainForm.ListViewModulesData(Sender: TObject; Item: TListItem);
72begin
73 if (Item.Index >= 0) and (Item.Index < ModuleManager.Modules.Count) then
74 with TModule(ModuleManager.Modules[Item.Index]) do begin
75 Item.Caption := Title;
76 Item.Data := ModuleManager.Modules[Item.Index];
77 Item.SubItems.Add(Identification);
78 Item.SubItems.Add(Version);
79 Item.SubItems.Add(BoolText[Installed]);
80 Item.SubItems.Add(BoolText[Running]);
81 Item.SubItems.Add(License);
82 Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll]));
83 Item.SubItems.Add(StringReplace(Description.Text, LineEnding, ', ', [rfReplaceAll]));
84 end;
85end;
86
87procedure TMainForm.ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
88 Selected: Boolean);
89var
90 Installed: Boolean;
91 Running: Boolean;
92begin
93 if Assigned(ListViewModules.Selected) then Installed := TModule(ListViewModules.Selected.Data).Installed;
94 if Assigned(ListViewModules.Selected) then Running := TModule(ListViewModules.Selected.Data).Running;
95 AModuleInstall.Enabled := Assigned(ListViewModules.Selected) and not Installed;
96 AModuleUninstall.Enabled := Assigned(ListViewModules.Selected) and Installed;
97 AModuleUpdate.Enabled := Assigned(ListViewModules.Selected) and Installed;
98 AModuleStart.Enabled := Assigned(ListViewModules.Selected) and not Running;
99 AModuleStop.Enabled := Assigned(ListViewModules.Selected) and Running;
100end;
101
102procedure TMainForm.RegisterModules;
103begin
104 ModuleManager.RegisterModule(TModuleUser.Create(nil));
105 ModuleManager.RegisterModule(TModuleBase.Create(nil));
106 ModuleManager.RegisterModule(TModuleACL.Create(nil));
107end;
108
109procedure TMainForm.Log(Text: string);
110begin
111 LogForm.Memo1.Lines.Add(Text);
112end;
113
114procedure TMainForm.RefreshList;
115begin
116 ListViewModules.Items.Count := ModuleManager.Modules.Count;
117 ListViewModules.Refresh;
118 ListViewModulesSelectItem(ListViewModules, ListViewModules.Selected,
119 Assigned(ListViewModules.Selected));
120end;
121
122procedure TMainForm.FormCreate(Sender: TObject);
123begin
124 RegisterModules;
125end;
126
127procedure TMainForm.ButtonInstallClick(Sender: TObject);
128var
129 ModuleList: TStringList;
130begin
131 if Assigned(ListViewModules.Selected) then begin
132 try
133 ModuleList := TStringList.Create;
134 TModule(ListViewModules.Selected.Data).EnumModulesInstall(ModuleList);
135 if ModuleList.Count > 0 then begin
136 if MessageDlg('These modules will be installed in addition to ' +
137 TModule(ListViewModules.Selected.Data).Name + ': ' +
138 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
139 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
140 TModule(ListViewModules.Selected.Data).Install;
141 end else TModule(ListViewModules.Selected.Data).Install;
142 finally
143 ModuleList.Free;
144 end;
145 RefreshList;
146 end;
147end;
148
149procedure TMainForm.AModuleStartExecute(Sender: TObject);
150var
151 ModuleList: TStringList;
152begin
153 if Assigned(ListViewModules.Selected) then begin
154 try
155 ModuleList := TStringList.Create;
156 TModule(ListViewModules.Selected.Data).EnumModulesStart(ModuleList);
157 if ModuleList.Count > 0 then begin
158 if MessageDlg('These modules will be started in addition to ' +
159 TModule(ListViewModules.Selected.Data).Name + ': ' +
160 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
161 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
162 TModule(ListViewModules.Selected.Data).Start;
163 end else TModule(ListViewModules.Selected.Data).Start;
164 finally
165 ModuleList.Free;
166 end;
167 RefreshList;
168 end;
169end;
170
171procedure TMainForm.AModuleStopExecute(Sender: TObject);
172var
173 ModuleList: TStringList;
174begin
175 if Assigned(ListViewModules.Selected) then begin
176 try
177 ModuleList := TStringList.Create;
178 TModule(ListViewModules.Selected.Data).EnumModulesStop(ModuleList);
179 if ModuleList.Count > 0 then begin
180 if MessageDlg('These modules will be stopped in addition to ' +
181 TModule(ListViewModules.Selected.Data).Name + ': ' +
182 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
183 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
184 TModule(ListViewModules.Selected.Data).Stop;
185 end else TModule(ListViewModules.Selected.Data).Stop;
186 finally
187 ModuleList.Free;
188 end;
189
190 RefreshList;
191 end;
192end;
193
194procedure TMainForm.ButtonUninstallClick(Sender: TObject);
195var
196 ModuleList: TStringList;
197begin
198 if Assigned(ListViewModules.Selected) then begin
199 try
200 ModuleList := TStringList.Create;
201 TModule(ListViewModules.Selected.Data).EnumModulesUninstall(ModuleList);
202 if ModuleList.Count > 0 then begin
203 if MessageDlg('These modules will be uninstalled in addition to ' +
204 TModule(ListViewModules.Selected.Data).Name + ': ' +
205 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
206 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
207 TModule(ListViewModules.Selected.Data).Uninstall;
208 end else TModule(ListViewModules.Selected.Data).Uninstall;
209 finally
210 ModuleList.Free;
211 end;
212
213 RefreshList;
214 end;
215end;
216
217procedure TMainForm.ButtonUpdateClick(Sender: TObject);
218begin
219 if Assigned(ListViewModules.Selected) then begin
220 TModule(ListViewModules.Selected.Data).Upgrade;
221 RefreshList;
222 end;
223end;
224
225procedure TMainForm.FormDestroy(Sender: TObject);
226begin
227end;
228
229procedure TMainForm.FormShow(Sender: TObject);
230begin
231 RefreshList;
232 LogForm.Show;
233end;
234
235end.
236
Note: See TracBrowser for help on using the repository browser.