118
129
TotalStartTime: TDateTime;
119
130
Log: TStringList;
131
FForm: TFormJobProgressView;
120
132
procedure SetTerminate(const AValue: Boolean);
121
133
procedure UpdateProgress;
122
procedure ReloadJobList;
124
procedure UpdateHeight;
125
134
procedure JobProgressChange(Sender: TObject);
127
Form: TFormJobProgressView;
128
Jobs: TObjectList; // TListObject<TJob>
129
137
CurrentJob: TJob;
130
138
CurrentJobIndex: Integer;
131
139
constructor Create(TheOwner: TComponent); override;
132
140
destructor Destroy; override;
134
procedure AddJob(Title: string; Method: TJobProgressViewMethod;
135
NoThreaded: Boolean = False; WaitFor: Boolean = False);
136
procedure Start(AAutoClose: Boolean = True);
142
function AddJob(Title: string; Method: TJobProgressViewMethod;
143
NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob;
138
146
procedure TermSleep(Delay: Integer);
147
property Form: TFormJobProgressView read FForm;
139
148
property Terminate: Boolean read FTerminate write SetTerminate;
141
150
property OwnerDraw: Boolean read FOwnerDraw write FOwnerDraw;
191
procedure TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod;
192
NoThreaded: Boolean = False; WaitFor: Boolean = False);
196
NewJob := TJob.Create;
197
NewJob.ProgressView := Self;
198
NewJob.Title := Title;
199
NewJob.Method := Method;
200
NewJob.NoThreaded := NoThreaded;
201
NewJob.WaitFor := WaitFor;
202
NewJob.Progress.Max := 100;
203
NewJob.Progress.Reset;
204
NewJob.Progress.OnChange := JobProgressChange;
203
{ TFormJobProgressView }
205
procedure TFormJobProgressView.UpdateHeight;
208
PanelOperationsVisible: Boolean;
209
PanelOperationsHeight: Integer;
210
PanelProgressVisible: Boolean;
211
PanelProgressTotalVisible: Boolean;
212
PanelLogVisible: Boolean;
213
MemoLogHeight: Integer = 200;
218
H := PanelOperationsTitle.Height;
219
PanelOperationsVisible := JobProgressView.Jobs.Count > 0;
220
if PanelOperationsVisible <> PanelOperations.Visible then
221
PanelOperations.Visible := PanelOperationsVisible;
222
if ListViewJobs.Items.Count > 0 then begin
224
for I := 0 to ListViewJobs.Items.Count - 1 do
226
ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds);
227
Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top));
229
PanelOperationsHeight := Scale96ToScreen(12) + Maxh;
230
end else PanelOperationsHeight := Scale96ToScreen(8);
231
if PanelOperationsHeight <> PanelOperations.Height then
232
PanelOperations.Height := PanelOperationsHeight;
233
if PanelOperationsVisible then
234
H := H + PanelOperations.Height;
236
PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished;
237
if PanelProgressVisible <> PanelProgress.Visible then
238
PanelProgress.Visible := PanelProgressVisible;
239
if PanelProgressVisible then
240
H := H + PanelProgress.Height;
241
PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished;
242
if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
243
PanelProgressTotal.Visible := PanelProgressTotalVisible;
244
if PanelProgressTotalVisible then
245
H := H + PanelProgressTotal.Height;
246
Constraints.MinHeight := H;
247
PanelLogVisible := MemoLog.Lines.Count > 0;
248
if PanelLogVisible <> PanelLog.Visible then
249
PanelLog.Visible := PanelLogVisible;
250
if PanelLogVisible then
251
H := H + Scale96ToScreen(MemoLogHeight);
252
if PanelText.Visible then
253
H := H + PanelText.Height;
254
if Height <> H then begin
256
Top := (Screen.Height - H) div 2;
260
procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject);
262
ProgressBarPartVisible: Boolean;
263
ProgressBarTotalVisible: Boolean;
265
JobProgressView.UpdateProgress;
266
if Visible and (not ProgressBarPart.Visible) and
267
Assigned(JobProgressView.CurrentJob) and
268
(JobProgressView.CurrentJob.Progress.Value > 0) then begin
269
ProgressBarPartVisible := True;
270
if ProgressBarPartVisible <> ProgressBarPart.Visible then
271
ProgressBarPart.Visible := ProgressBarPartVisible;
272
ProgressBarTotalVisible := True;
273
if ProgressBarTotalVisible <> ProgressBarTotal.Visible then
274
ProgressBarTotal.Visible := ProgressBarTotalVisible;
276
if not Visible then begin
277
TimerUpdate.Interval := UpdateInterval;
278
if not JobProgressView.OwnerDraw then Show;
280
if Assigned(JobProgressView.CurrentJob) then begin
281
LabelText.Caption := JobProgressView.CurrentJob.Progress.Text;
282
if LabelText.Caption <> '' then begin
283
PanelText.Visible := True;
289
procedure TFormJobProgressView.FormDestroy(Sender:TObject);
293
procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem);
295
if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then
296
with TJob(JobProgressView.Jobs[Item.Index]) do begin
297
Item.Caption := Title;
298
if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1
299
else if Finished then Item.ImageIndex := 0
300
else Item.ImageIndex := 2;
301
Item.Data := JobProgressView.Jobs[Item.Index];
305
procedure TFormJobProgressView.FormClose(Sender: TObject;
306
var CloseAction: TCloseAction);
310
procedure TFormJobProgressView.FormCreate(Sender: TObject);
312
Caption := SPleaseWait;
314
//Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) +
315
// DirectorySeparator + 'horse.avi';
316
//Animate1.Active := True;
322
procedure TFormJobProgressView.ReloadJobList;
324
// Workaround for not showing first line
325
//Form.ListViewJobs.Items.Count := Jobs.Count + 1;
326
//Form.ListViewJobs.Refresh;
328
if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then
329
ListViewJobs.Items.Count := JobProgressView.Jobs.Count;
330
ListViewJobs.Refresh;
331
Application.ProcessMessages;
335
procedure TFormJobProgressView.FormShow(Sender: TObject);
340
procedure TFormJobProgressView.FormHide(Sender: TObject);
342
JobProgressView.Jobs.Clear;
346
procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
348
CanClose := JobProgressView.Finished;
349
JobProgressView.Terminate := True;
350
Caption := SPleaseWait + STerminate;
356
function TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod;
357
NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob;
359
Result := TJob.Create;
360
Result.ProgressView := Self;
361
Result.Title := Title;
362
Result.Method := Method;
363
Result.NoThreaded := NoThreaded;
364
Result.WaitFor := WaitFor;
365
Result.Progress.Max := 100;
366
Result.Progress.Reset;
367
Result.Progress.OnChange := JobProgressChange;
209
procedure TJobProgressView.Start(AAutoClose: Boolean = True);
211
AutoClose := AAutoClose;
215
procedure TJobProgressView.StartJobs;
372
procedure TJobProgressView.Start;
294
452
Screen.EnableForms(FormList);
295
453
//if Visible then Hide;
296
454
Form.MemoLog.Lines.Assign(Log);
297
if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin
455
if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin
458
if not Form.Visible then Clear;
301
459
Form.Caption := SFinished;
302
460
//LabelEstimatedTimePart.Visible := False;
303
461
Finished := True;
304
462
CurrentJobIndex := -1;
309
procedure TJobProgressView.UpdateHeight;
312
PanelOperationsVisible: Boolean;
313
PanelOperationsHeight: Integer;
314
PanelProgressVisible: Boolean;
315
PanelProgressTotalVisible: Boolean;
316
PanelLogVisible: Boolean;
319
H := PanelOperationsTitle.Height;
320
PanelOperationsVisible := Jobs.Count > 0;
321
if PanelOperationsVisible <> PanelOperations.Visible then
322
PanelOperations.Visible := PanelOperationsVisible;
323
PanelOperationsHeight := 8 + 18 * Jobs.Count;
324
if PanelOperationsHeight <> PanelOperations.Height then
325
PanelOperations.Height := PanelOperationsHeight;
326
if PanelOperationsVisible then
327
H := H + PanelOperations.Height;
329
PanelProgressVisible := (Jobs.Count > 0) and not Finished;
330
if PanelProgressVisible <> PanelProgress.Visible then
331
PanelProgress.Visible := PanelProgressVisible;
332
if PanelProgressVisible then
333
H := H + PanelProgress.Height;
334
PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished;
335
if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
336
PanelProgressTotal.Visible := PanelProgressTotalVisible;
337
if PanelProgressTotalVisible then
338
H := H + PanelProgressTotal.Height;
339
Constraints.MinHeight := H;
340
PanelLogVisible := MemoLog.Lines.Count > 0;
341
if PanelLogVisible <> PanelLog.Visible then
342
PanelLog.Visible := PanelLogVisible;
343
if PanelLogVisible then
344
H := H + MemoLogHeight;
345
if Height <> H then Height := H;
352
470
FOnOwnerDraw(Self);
355
procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject);
357
ProgressBarPartVisible: Boolean;
358
ProgressBarTotalVisible: Boolean;
360
JobProgressView.UpdateProgress;
361
if Visible and (not ProgressBarPart.Visible) and
362
Assigned(JobProgressView.CurrentJob) and
363
(JobProgressView.CurrentJob.Progress.Value > 0) then begin
364
ProgressBarPartVisible := True;
365
if ProgressBarPartVisible <> ProgressBarPart.Visible then
366
ProgressBarPart.Visible := ProgressBarPartVisible;
367
ProgressBarTotalVisible := True;
368
if ProgressBarTotalVisible <> ProgressBarTotal.Visible then
369
ProgressBarTotal.Visible := ProgressBarTotalVisible;
371
if not Visible then begin
372
TimerUpdate.Interval := UpdateInterval;
373
if not JobProgressView.OwnerDraw then Show;
377
procedure TFormJobProgressView.FormDestroy(Sender:TObject);
381
procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem);
383
if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then
384
with TJob(JobProgressView.Jobs[Item.Index]) do begin
385
Item.Caption := Title;
386
if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1
387
else if Finished then Item.ImageIndex := 0
388
else Item.ImageIndex := 2;
389
Item.Data := JobProgressView.Jobs[Item.Index];
393
procedure TFormJobProgressView.FormClose(Sender: TObject;
394
var CloseAction: TCloseAction);
399
procedure TFormJobProgressView.FormCreate(Sender: TObject);
401
Caption := SPleaseWait;
403
//Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) +
404
// DirectorySeparator + 'horse.avi';
405
//Animate1.Active := True;
411
473
procedure TJobProgressView.Stop;
413
475
Terminate := True;
491
procedure TJobProgressView.ReloadJobList;
494
// Workaround for not showing first line
495
Form.ListViewJobs.Items.Count := Jobs.Count + 1;
496
Form.ListViewJobs.Refresh;
498
if Form.ListViewJobs.Items.Count <> Jobs.Count then
499
Form.ListViewJobs.Items.Count := Jobs.Count;
500
Form.ListViewJobs.Refresh;
501
//Application.ProcessMessages;
504
546
constructor TJobProgressView.Create(TheOwner: TComponent);
507
549
if not (csDesigning in ComponentState) then begin
508
Form := TFormJobProgressView.Create(Self);
509
Form.JobProgressView := Self;
550
FForm := TFormJobProgressView.Create(Self);
551
FForm.JobProgressView := Self;
511
Jobs := TObjectList.Create;
553
Jobs := TJobs.Create;
512
554
Log := TStringList.Create;
513
555
//PanelOperationsTitle.Height := 80;
514
ShowDelay := 0; //1000; // ms
517
560
procedure TJobProgressView.Clear;