source: trunk/Packages/ModularSystem/FormModuleList.pas

Last change on this file was 75, checked in by chronos, 6 months ago
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File size: 16.7 KB
Line 
1unit FormModuleList;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
7 ComCtrls, ExtCtrls, Menus, ActnList, StdCtrls, Generics.Collections, DateUtils,
8 ListViewSort, ModularSystem, Common;
9
10type
11 TModuleListOption = (mloShowVersion, mloShowAuthor, mloShowFileName,
12 mloShowIdentification, mloShowLicense, mloShowEnable, mloShowRunning,
13 mloShowDependencies, mloShowInstalled, mloShowInfoBar, mloShowDescription,
14 mloShowStartUpTime, mloAllowInstall, mloAllowEnable, mloAllowRegister, mloAllowStart);
15 TModuleListOptions = set of TModuleListOption;
16
17 { TFormModuleList }
18
19 TFormModuleList = class(TForm)
20 ARestart: TAction;
21 ARegister: TAction;
22 AEnable: TAction;
23 ADisable: TAction;
24 AStart: TAction;
25 AStop: TAction;
26 AInstall: TAction;
27 AUninstall: TAction;
28 AUnregister: TAction;
29 ActionList1: TActionList;
30 ImageList1: TImageList;
31 ListViewModules: TListView;
32 Memo1: TMemo;
33 MenuItem1: TMenuItem;
34 MenuItem2: TMenuItem;
35 MenuItem3: TMenuItem;
36 MenuItem4: TMenuItem;
37 MenuItem5: TMenuItem;
38 MenuItem6: TMenuItem;
39 MenuItem7: TMenuItem;
40 MenuItem8: TMenuItem;
41 MenuItem9: TMenuItem;
42 PopupMenu1: TPopupMenu;
43 Splitter1: TSplitter;
44 TimerRedraw: TTimer;
45 ToolBar1: TToolBar;
46 ToolButton1: TToolButton;
47 ToolButton2: TToolButton;
48 ToolButton3: TToolButton;
49 ToolButton4: TToolButton;
50 ToolButton5: TToolButton;
51 ToolButton6: TToolButton;
52 ToolButton7: TToolButton;
53 ToolButton8: TToolButton;
54 procedure ADisableExecute(Sender: TObject);
55 procedure AEnableExecute(Sender: TObject);
56 procedure AInstallExecute(Sender: TObject);
57 procedure AUninstallExecute(Sender: TObject);
58 procedure AUnregisterExecute(Sender: TObject);
59 procedure AStartExecute(Sender: TObject);
60 procedure AStopExecute(Sender: TObject);
61 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
62 procedure FormCreate(Sender: TObject);
63 procedure FormDestroy(Sender: TObject);
64 procedure FormHide(Sender: TObject);
65 procedure FormShow(Sender: TObject);
66 procedure ListViewModulesData(Sender: TObject; Item: TListItem);
67 procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
68 Selected: Boolean);
69 procedure TimerRedrawTimer(Sender: TObject);
70 private
71 FModuleManager: TModuleManager;
72 FOptions: TModuleListOptions;
73 ListViewSort: TListViewSort;
74 function ListViewModulesCompare(Item1, Item2: TObject): Integer;
75 procedure ModulesFilterExecute(ListViewSort: TListViewSort);
76 procedure SetModuleManager(AValue: TModuleManager);
77 procedure SetOptions(AValue: TModuleListOptions);
78 public
79 procedure Reload;
80 procedure UpdateInterface;
81 property Manager: TModuleManager read FModuleManager write SetModuleManager;
82 property Options: TModuleListOptions read FOptions write SetOptions;
83 end;
84
85function ModuleToStr(Module: TObject): string;
86
87
88implementation
89
90resourcestring
91 SYes = 'Yes';
92 SNo = 'No';
93 SAdditionalModulesInstall = 'In addition to "%0:s" module also dependent modules will be installed: "%1:s"';
94 SAdditionalModulesUninstall = 'In addition to "%0:s" module alse dependent modules will be uninstalled: "%1:s"';
95 SAdditionalModulesStart = 'In addition to "%0:s" module also dependent modules will be started: "%1:s"';
96 SAdditionalModulesStop = 'In addition to "%0:s" module also dependent modules will be stopped: "%1:s"';
97 SIdentification = 'Identification';
98 SName = 'Name';
99 SVersion = 'Version';
100 SLicense = 'License';
101 SDescription = 'Description';
102 SDependencies = 'Dependencies';
103 SAuthor = 'Author';
104
105function ModuleToStr(Module: TObject): string;
106begin
107 Result := TModule(Module).Title;
108end;
109
110{ TFormModuleList }
111
112procedure TFormModuleList.ListViewModulesData(Sender: TObject; Item: TListItem);
113begin
114 if (Item.Index >= 0) and (Item.Index < ListViewSort.List.Count) then
115 with TModule(ListViewSort.List[Item.Index]) do begin
116 Item.Caption := Identification;
117 Item.Data := ListViewSort.List[Item.Index];
118 Item.SubItems.Add(Title);
119 if Enabled then Item.SubItems.Add(SYes)
120 else Item.SubItems.Add(SNo);
121 if Installed then Item.SubItems.Add(SYes)
122 else Item.SubItems.Add(SNo);
123 if Running then Item.SubItems.Add(SYes)
124 else Item.SubItems.Add(SNo);
125 if Author <> '' then Item.SubItems.Add(Author)
126 else Item.SubItems.Add(' ');
127 if License <> '' then Item.SubItems.Add(License)
128 else Item.SubItems.Add(' ');
129 if Version <> '' then Item.SubItems.Add(Version)
130 else Item.SubItems.Add(' ');
131 Item.SubItems.Add(Implode(',', Dependencies));
132 if FileName <> '' then Item.SubItems.Add(FileName)
133 else Item.SubItems.Add(' ');
134 Item.SubItems.Add(FloatToStr(Trunc(StartUpTime / OneMillisecond)));
135 end;
136end;
137
138procedure TFormModuleList.ListViewModulesSelectItem(Sender: TObject;
139 Item: TListItem; Selected: Boolean);
140begin
141 UpdateInterface;
142 Memo1.Clear;
143 if Assigned(ListViewModules.Selected) then
144 with TModule(ListViewModules.Selected.Data) do begin
145 Memo1.Lines.Add(SName + ': ' + Title);
146 if (mloShowIdentification in FOptions) then Memo1.Lines.Add(SIdentification + ': ' + Identification);
147 if (mloShowAuthor in FOptions) and (Author <> '') then Memo1.Lines.Add(SAuthor + ': ' + Author);
148 if (mloShowVersion in FOptions) and (Version <> '') then Memo1.Lines.Add(SVersion + ': ' + Version);
149 if (mloShowLicense in FOptions) and (License <> '') then Memo1.Lines.Add(SLicense + ': ' + License);
150 if (mloShowDependencies in FOptions) and (Dependencies.Count > 0) then
151 Memo1.Lines.Add(SDependencies + ': ' + Implode(', ', Dependencies));
152 if (mloShowDescription in FOptions) and (Description.Count > 0) then
153 Memo1.Lines.Add(SDescription + ': ' + Implode(', ', Description));
154 end;
155end;
156
157procedure TFormModuleList.FormCreate(Sender: TObject);
158begin
159 ListViewSort := TListViewSort.Create(nil);
160 ListViewSort.ListView := ListViewModules;
161 ListViewSort.Column := 0;
162 ListViewSort.Order := soDown;
163 ListViewSort.OnCompareItem := ListViewModulesCompare;
164 ListViewSort.OnFilter := ModulesFilterExecute;
165
166 DoubleBuffered := True;
167 ControlStyle := ControlStyle + [csOpaque];
168 ListViewModules.DoubleBuffered := True;
169 ListViewModules.ControlStyle := ListViewModules.ControlStyle + [csOpaque];
170end;
171
172procedure TFormModuleList.FormDestroy(Sender: TObject);
173begin
174 ListViewModules.Clear;
175 FreeAndNil(ListViewSort);
176end;
177
178procedure TFormModuleList.AUnregisterExecute(Sender: TObject);
179var
180 I: Integer;
181begin
182 for I := ListViewModules.Items.Count - 1 downto 0 do
183 if ListViewModules.Items[I].Selected then
184 with TModule(ListViewModules.Items[I].Data) do begin
185 FModuleManager.UnregisterModule(TModule(ListViewModules.Items[I].Data));
186 end;
187 UpdateInterface;
188end;
189
190procedure TFormModuleList.AStartExecute(Sender: TObject);
191var
192 Modules: TModules;
193 I: Integer;
194begin
195 for I := 0 to ListViewModules.Items.Count - 1 do
196 if ListViewModules.Items[I].Selected then
197 with TModule(ListViewModules.Items[I].Data) do
198 if not Running then
199 try
200 Modules := TModules.Create;
201 Modules.OwnsObjects := False;
202 EnumDependenciesCascade(Modules, [mcNotRunning]);
203 if Modules.Count > 0 then begin
204 if MessageDlg(Format(SAdditionalModulesStart, [
205 Identification, Modules.GetNames]),
206 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
207 Start;
208 end else Start;
209 finally
210 Modules.Free;
211 end;
212 UpdateInterface;
213end;
214
215procedure TFormModuleList.AStopExecute(Sender: TObject);
216var
217 Modules: TModules;
218 I: Integer;
219begin
220 for I := 0 to ListViewModules.Items.Count - 1 do
221 if ListViewModules.Items[I].Selected then
222 with TModule(ListViewModules.Items[I].Data) do
223 if Running then
224 try
225 Modules := TModules.Create;
226 Modules.OwnsObjects := False;
227 EnumSuperiorDependenciesCascade(Modules, [mcRunning]);
228 if Modules.Count > 0 then begin
229 if MessageDlg(Format(SAdditionalModulesStop, [
230 Identification, Modules.GetNames]),
231 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
232 Stop;
233 end else Stop;
234 finally
235 FreeAndNil(Modules);
236 end;
237 UpdateInterface;
238end;
239
240procedure TFormModuleList.AUninstallExecute(Sender: TObject);
241var
242 Modules: TModules;
243 I: Integer;
244begin
245 for I := 0 to ListViewModules.Items.Count - 1 do
246 if ListViewModules.Items[I].Selected then
247 with TModule(ListViewModules.Items[I].Data) do
248 if Installed then
249 try
250 Modules := TModules.Create;
251 Modules.OwnsObjects := False;
252 EnumSuperiorDependenciesCascade(Modules, [mcInstalled]);
253 if Modules.Count > 0 then begin
254 if MessageDlg(Format(SAdditionalModulesUninstall, [
255 Identification, Modules.GetNames]),
256 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
257 Uninstall;
258 end else Uninstall;
259 finally
260 Modules.Free;
261 end;
262 UpdateInterface;
263end;
264
265procedure TFormModuleList.FormClose(Sender: TObject;
266 var CloseAction: TCloseAction);
267begin
268 TimerRedraw.Enabled := False;
269 //Core.PersistentForm.Save(Self);
270end;
271
272procedure TFormModuleList.AInstallExecute(Sender: TObject);
273var
274 Modules: TModules;
275 I: Integer;
276begin
277 for I := 0 to ListViewModules.Items.Count - 1 do
278 if ListViewModules.Items[I].Selected then
279 with TModule(ListViewModules.Items[I].Data) do
280 if not Installed then
281 try
282 Modules := TModules.Create;
283 Modules.OwnsObjects := False;
284 EnumDependenciesCascade(Modules, [mcNotInstalled]);
285 if Modules.Count > 0 then begin
286 if MessageDlg(Format(SAdditionalModulesInstall, [
287 Identification, Modules.GetNames]),
288 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
289 Install;
290 end else Install;
291 finally
292 Modules.Free;
293 end;
294 UpdateInterface;
295end;
296
297procedure TFormModuleList.AEnableExecute(Sender: TObject);
298var
299 Modules: TModules;
300 I: Integer;
301begin
302 for I := 0 to ListViewModules.Items.Count - 1 do
303 if ListViewModules.Items[I].Selected then
304 with TModule(ListViewModules.Items[I].Data) do
305 if not Enabled then
306 try
307 Modules := TModules.Create;
308 Modules.OwnsObjects := False;
309 EnumDependenciesCascade(Modules, [mcNotRunning]);
310 if Modules.Count > 0 then begin
311 if MessageDlg(Format(SAdditionalModulesStart, [
312 Identification, Modules.GetNames]),
313 mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
314 Enable;
315 Start;
316 end;
317 end else begin
318 Enable;
319 Start;
320 end;
321 finally
322 Modules.Free;
323 end;
324 UpdateInterface;
325end;
326
327procedure TFormModuleList.ADisableExecute(Sender: TObject);
328var
329 Modules: TModules;
330 I: Integer;
331begin
332 for I := 0 to ListViewModules.Items.Count - 1 do
333 if ListViewModules.Items[I].Selected then
334 with TModule(ListViewModules.Items[I].Data) do
335 if Enabled then
336 try
337 Modules := TModules.Create;
338 Modules.OwnsObjects := False;
339 EnumSuperiorDependenciesCascade(Modules, [mcInstalled]);
340 if Modules.Count > 0 then begin
341 if MessageDlg(Format(SAdditionalModulesUninstall, [
342 Identification, Modules.GetNames]),
343 mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
344 Stop;
345 Disable;
346 end;
347 end else begin
348 TModule(ListViewModules.Selected.Data).Stop;
349 TModule(ListViewModules.Selected.Data).Disable;
350 end;
351 finally
352 Modules.Free;
353 end;
354 UpdateInterface;
355end;
356
357procedure TFormModuleList.FormHide(Sender: TObject);
358begin
359 TimerRedraw.Enabled := False;
360end;
361
362procedure TFormModuleList.FormShow(Sender: TObject);
363begin
364 Reload;
365 UpdateInterface;
366 //TimerRedraw.Enabled := True;
367 //Core.PersistentForm.Load(Self);
368end;
369
370procedure TFormModuleList.TimerRedrawTimer(Sender: TObject);
371begin
372 Reload;
373end;
374
375function TFormModuleList.ListViewModulesCompare(Item1, Item2: TObject): Integer;
376begin
377 Result := 0;
378 if Assigned(Item1) and Assigned(Item2) and (ListViewSort.Order <> soNone) then begin
379 with ListViewSort do
380 case Column of
381 0: Result := CompareString(TModule(Item1).Identification,
382 TModule(Item2).Identification);
383 1: Result := CompareString(TModule(Item1).Title,
384 TModule(Item2).Title);
385 2: Result := CompareBoolean(TModule(Item1).Enabled,
386 TModule(Item2).Enabled);
387 3: Result := CompareBoolean(TModule(Item1).Installed,
388 TModule(Item2).Installed);
389 4: Result := CompareBoolean(TModule(Item1).Running,
390 TModule(Item2).Running);
391 5: Result := CompareString(TModule(Item1).Author,
392 TModule(Item2).Author);
393 6: Result := CompareString(TModule(Item1).License, TModule(
394 Item2).License);
395 7: Result := CompareString(TModule(Item1).Version, TModule(
396 Item2).Version);
397 8: Result := CompareString(Implode(',', TModule(Item1).Dependencies),
398 Implode(',', TModule(Item2).Dependencies));
399 9: Result := CompareString(TModule(Item1).FileName,
400 TModule(Item2).FileName);
401 10: Result := CompareTime(TModule(Item1).StartUpTime,
402 TModule(Item2).StartUpTime);
403 end;
404 if ListViewSort.Order = soDown then Result := -Result;
405 end else Result := 0;
406end;
407
408procedure TFormModuleList.ModulesFilterExecute(ListViewSort: TListViewSort);
409var
410 I: Integer;
411begin
412 if Assigned(FModuleManager) then
413 begin
414 ListViewSort.Source := nil;
415 ListViewSort.List.Clear;
416 //ListViewSort.List.Assign(FModuleManager.Modules);
417 for I := 0 to FModuleManager.Modules.Count - 1 do
418 with TModule(FModuleManager.Modules[I]) do begin
419 ListViewSort.List.Add(FModuleManager.Modules[I]);
420 end;
421 end else begin
422 ListViewSort.Source := nil;
423 ListViewSort.List.Clear;
424 end;
425end;
426
427procedure TFormModuleList.SetModuleManager(AValue: TModuleManager);
428begin
429 if FModuleManager = AValue then Exit;
430 FModuleManager := AValue;
431 if not (csDestroying in ComponentState) then Reload;
432end;
433
434procedure TFormModuleList.SetOptions(AValue: TModuleListOptions);
435begin
436 if FOptions = AValue then Exit;
437 FOptions := AValue;
438 UpdateInterface;
439end;
440
441procedure TFormModuleList.Reload;
442begin
443 if Assigned(ListViewSort) then
444 ListViewSort.Refresh;
445end;
446
447procedure TFormModuleList.UpdateInterface;
448begin
449 AUnregister.Enabled := Assigned(ListViewModules.Selected) and
450 (mloAllowRegister in FOptions);
451 AUnregister.Visible := (mloAllowRegister in FOptions);
452 ARegister.Enabled := Assigned(ListViewModules.Selected) and
453 (mloAllowRegister in FOptions);
454 ARegister.Visible := (mloAllowRegister in FOptions);
455 AInstall.Enabled := Assigned(ListViewModules.Selected) and
456 not TModule(ListViewModules.Selected.Data).Installed and
457 (mloAllowInstall in FOptions) and
458 TModule(ListViewModules.Selected.Data).Enabled;
459 AInstall.Visible := (mloAllowInstall in FOptions);
460 AUninstall.Enabled := Assigned(ListViewModules.Selected) and
461 TModule(ListViewModules.Selected.Data).Installed and
462 (mloAllowInstall in FOptions);
463 AUninstall.Visible := (mloAllowInstall in FOptions);
464 AStart.Enabled := Assigned(ListViewModules.Selected) and
465 not TModule(ListViewModules.Selected.Data).Running and
466 (mloAllowStart in FOptions);
467 AStart.Visible := (mloAllowStart in FOptions);
468 AStop.Enabled := Assigned(ListViewModules.Selected) and
469 TModule(ListViewModules.Selected.Data).Running and
470 TModule(ListViewModules.Selected.Data).Installed and
471 (mloAllowStart in FOptions);
472 AStop.Visible := (mloAllowStart in FOptions);
473 AEnable.Enabled := Assigned(ListViewModules.Selected) and
474 not TModule(ListViewModules.Selected.Data).Enabled and
475 (mloAllowEnable in FOptions);
476 AEnable.Visible := (mloAllowEnable in FOptions);
477 ADisable.Enabled := Assigned(ListViewModules.Selected) and
478 TModule(ListViewModules.Selected.Data).Enabled and
479 (mloAllowEnable in FOptions);
480 ADisable.Visible := (mloAllowEnable in FOptions);
481 ListViewModules.Column[0].Visible := (mloShowIdentification in FOptions);
482 ListViewModules.Column[1].Visible := True;
483 ListViewModules.Column[2].Visible := (mloShowEnable in FOptions);
484 ListViewModules.Column[3].Visible := (mloShowInstalled in FOptions);
485 ListViewModules.Column[4].Visible := (mloShowRunning in FOptions);
486 ListViewModules.Column[5].Visible := (mloShowAuthor in FOptions);
487 ListViewModules.Column[6].Visible := (mloShowLicense in FOptions);
488 ListViewModules.Column[7].Visible := (mloShowVersion in FOptions);
489 ListViewModules.Column[8].Visible := (mloShowDependencies in FOptions);
490 ListViewModules.Column[9].Visible := (mloShowFileName in FOptions);
491 ListViewModules.Column[10].Visible := (mloShowStartUpTime in FOptions);
492 Memo1.Visible := (mloShowInfoBar in FOptions);
493 Splitter1.Visible := (mloShowInfoBar in FOptions);
494end;
495
496initialization
497 {$I FormModuleList.lrs}
498
499end.
500
Note: See TracBrowser for help on using the repository browser.