This file is indexed.

/usr/lib/lazarus/0.9.30.4/ide/progressdlg.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code is distributed in the hope that it will be useful, but      *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 ***************************************************************************

  Author: Mattias Gaertner

  Abstract:
    A dialog for showing the progress of a boring calculation.
}
unit ProgressDlg;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons,
  StdCtrls, ComCtrls, LazarusIDEStrConsts;

type

  { TIDEProgressDialog }

  TIDEProgressDialog = class(TForm)
    AbortButton: TBitBtn;
    DescriptionLabel: TLabel;
    ProgressBar: TProgressBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  public
    procedure ApplicationIdle(Sender: TObject; var Done: Boolean);
  end; 
  
var
  IDEProgressDialog: TIDEProgressDialog = nil;

function ShowProgress(const SomeText: string;
                      Step, MaxStep: integer): boolean;

implementation

{$R *.lfm}

type

  { TProgressWait }

  TProgressWait = class
  public
    StartTime: TDateTime;
    StartTimeValid: boolean;
    constructor Create;
    procedure ApplicationIdle(Sender: TObject; var Done: Boolean);
  end;

{ TProgressWait }

constructor TProgressWait.Create;
begin
  Application.AddOnIdleHandler(@ApplicationIdle);
end;

procedure TProgressWait.ApplicationIdle(Sender: TObject; var Done: Boolean);
begin
  StartTimeValid:=false;
end;
  
var
  ProgressWait: TProgressWait = nil;

function ShowProgress(const SomeText: string; Step, MaxStep: integer): boolean;
const
  Delay = 1.0/86400;
  
  procedure InitDlg;
  begin
    IDEProgressDialog.DescriptionLabel.Caption:=SomeText;
    if (Step>=0) and (MaxStep>Step) then begin
      IDEProgressDialog.ProgressBar.Visible:=true;
      IDEProgressDialog.ProgressBar.Max:=MaxStep;
      IDEProgressDialog.ProgressBar.Position:=Step;
    end else begin
      IDEProgressDialog.ProgressBar.Visible:=false;
    end;
  end;
  
begin
  if IDEProgressDialog<>nil then begin
    // there is already a TIDEProgressDialog
    InitDlg;
  end else begin
    // there is no TIDEProgressDialog yet
    // create one after 1 second
    if ProgressWait=nil then
      ProgressWait:=TProgressWait.Create;
    if ProgressWait.StartTimeValid then begin
      if Now-ProgressWait.StartTime>Delay then begin
        // one second waited
        // => create a TIDEProgressDialog and show it modal
        IDEProgressDialog:=TIDEProgressDialog.Create(Application);
        InitDlg;
        IDEProgressDialog.Show;
      end;
    end else begin
      ProgressWait.StartTime:=Now;
    end;
  end;
  Result:=true;
end;

{ TIDEProgressDialog }

procedure TIDEProgressDialog.FormCreate(Sender: TObject);
begin
  Caption:=lisPDProgress;
  DescriptionLabel.Caption:='...';
  AbortButton.Caption:=lisPDAbort;

  Application.AddOnIdleHandler(@ApplicationIdle);
end;

procedure TIDEProgressDialog.FormDestroy(Sender: TObject);
begin
  Application.RemoveOnIdleHandler(@ApplicationIdle);
end;

procedure TIDEProgressDialog.ApplicationIdle(Sender: TObject;
  var Done: Boolean);
begin
  // IDE got idle => progress dialog is not used anymore
  if Screen.FormIndex(Self)>=0 then begin
    // let the LCL close it on end of message loop
    Close;
  end else begin
    // unused and invisible -> free it
    FreeAndNil(IDEProgressDialog);
  end;
end;

finalization
  FreeAndNil(ProgressWait);

end.