unit UInfoWindow;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls;

type
  TInfoWindow = class(TForm)
    Timer1: TTimer;
    Panel1: TPanel;
    Button2: TButton;
    Button1: TButton;
    ListView1: TListView;
    CheckBox1: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  InfoWindow: TInfoWindow;

implementation

uses UMainWindow, DateUtils, ULocalization, Math, SunriseChatCoreUnit;

{$R *.dfm}

procedure TInfoWindow.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TInfoWindow.FormShow(Sender: TObject);
begin
  Button2Click(Self);
  with Localization do begin
    ListView1.Columns[0].Caption:= Item('Name');
    ListView1.Columns[1].Caption:= Item('LoggedUser');
    ListView1.Columns[2].Caption:= Item('UserDescription');
    ListView1.Columns[3].Caption:= Item('ComputerName');
    ListView1.Columns[4].Caption:= Item('IPAddress');
    ListView1.Columns[5].Caption:= Item('Status');
    ListView1.Columns[6].Caption:= Item('PresenceTime');
    ListView1.Columns[7].Caption:= Item('ApplicationName');
    ListView1.Columns[8].Caption:= Item('OSIndication');
    Button1.Caption:= Item('Ok');
    Button2.Caption:= Item('Restore');
    InfoWindow.Caption:= Item('Information');
  end;
end;

procedure TInfoWindow.Button2Click(Sender: TObject);
var
  I: Integer;
  Node: TListItem;
  Col: TListColumn;
  TextStatus: string;
  LinesCount: Integer;
begin
  ListView1.Items.BeginUpdate;
  ListView1.Items.Clear;
  if MainWindow.ServiceFunction then
  with Localization, ListView1.Columns do begin
    if Count<10 then begin
      Col:= Add;
      Col.Caption:= Item('CoreVersion');
      Col.Width:= 60;
      Col:= Add;
      Col.Caption:= Item('TransferErrorCount');
      Col.Width:= 80;
      Col:= Add;
      Col.Caption:= Item('PacketSequenceNumber');
      Col.Width:= 80;
      Col:= Add;
      Col.Caption:= Item('IdleTime');
      Col.Width:= 60;
      Col:= Add;
      Col.Caption:= Item('LocalTime');
      Col.Width:= 80;
      //Width:= 690+300+60;
    end;
  end else begin
    for I:= ListView1.Columns.Count-1 downto 9 do
      ListView1.Columns.Delete(I);
    //Width:= 690;
  end;
  with MainWindow, SunriseChatNetworkCore1 do
    for I := 0 to UserList.Count-1 do with TUser(UserList[I]) do begin
      Node := InfoWindow.ListView1.Items.Add;
      Node.Caption:= Nick;
      with Node.SubItems do begin
        Add(OSUser);
        Add(DetailInfo);
        Add(HostName);
        Add(IPAddrToStr(Id.Machine));
        TextStatus := UserStatusModeText[Integer(Status)];
        if Status = usAway then TextStatus:= Localization.Item('AwayMode');;
        if Status = usWriting then TextStatus:= Localization.Item('WrittingMode');;
        Add(TextStatus);
        Add(TimeToStr((LocalSystemTime-UpTime)+(Now-UserInfoTime)));
        Add(Client+' '+ClientVersion);
        Add(OSVersion);
        if ServiceFunction then begin
          Add(CoreVersion);
          Add(IntToStr(ErrorCount));
          Add(IntToStr(Sequence));
          Add(TimeToStr(Delay));
          Add(TimeToStr(LocalSystemTime+(Now-UserInfoTime)));
        end;
      end;
    end;
  ListView1.Items.EndUpdate;
  if CheckBox1.Checked then begin
    // Change window height across list item count
    LinesCount := ListView1.Items.Count;
    if LinesCount < 5 then LinesCount := 4;
    Height := Height + (LinesCount*15 - ListView1.Height) + 36;
    if Height > (Screen.Height-50) then Height:= (Screen.Height-50);
  end;
end;

procedure TInfoWindow.Timer1Timer(Sender: TObject);
begin
  Button2Click(Self);
end;

procedure TInfoWindow.FormCreate(Sender: TObject);
begin
  if MainWindow.OnTop then FormStyle:= fsStayOnTop else FormStyle:= fsNormal;
  CheckBox1.Checked:= MainWindow.AutoChangeInfoWindowHeight;
end;

procedure TInfoWindow.CheckBox1Click(Sender: TObject);
begin
  MainWindow.AutoChangeInfoWindowHeight:= CheckBox1.Checked;
end;

end.
