root / Client / UfrmLogin.pas @ 0:95bd93c28625
History | View | Annotate | Download (5.1 kB)
| 1 | (*
|
|---|---|
| 2 | * CDDL HEADER START |
| 3 | * |
| 4 | * The contents of this file are subject to the terms of the |
| 5 | * Common Development and Distribution License, Version 1.0 only |
| 6 | * (the "License"). You may not use this file except in compliance |
| 7 | * with the License. |
| 8 | * |
| 9 | * You can obtain a copy of the license at |
| 10 | * http://www.opensource.org/licenses/cddl1.php. |
| 11 | * See the License for the specific language governing permissions |
| 12 | * and limitations under the License. |
| 13 | * |
| 14 | * When distributing Covered Code, include this CDDL HEADER in each |
| 15 | * file and include the License file at |
| 16 | * http://www.opensource.org/licenses/cddl1.php. If applicable, |
| 17 | * add the following below this CDDL HEADER, with the fields enclosed |
| 18 | * by brackets "[]" replaced with your own identifying * information: |
| 19 | * Portions Copyright [yyyy] [name of copyright owner] |
| 20 | * |
| 21 | * CDDL HEADER END |
| 22 | * |
| 23 | * |
| 24 | * Portions Copyright 2007 Andreas Schneider |
| 25 | *) |
| 26 | unit UfrmLogin;
|
| 27 | |
| 28 | {$mode objfpc}{$H+} |
| 29 | |
| 30 | interface
|
| 31 | |
| 32 | uses
|
| 33 | Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, |
| 34 | ExtCtrls, Spin, EditBtn, Buttons, IniFiles; |
| 35 | |
| 36 | type
|
| 37 | |
| 38 | { TfrmLogin }
|
| 39 | |
| 40 | TfrmLogin = class(TForm)
|
| 41 | btnOK: TButton; |
| 42 | btnCancel: TButton; |
| 43 | cbProfile: TComboBox; |
| 44 | edData: TDirectoryEdit; |
| 45 | edHost: TEdit; |
| 46 | edUsername: TEdit; |
| 47 | edPassword: TEdit; |
| 48 | gbConnection: TGroupBox; |
| 49 | gbData: TGroupBox; |
| 50 | gbActions: TGroupBox; |
| 51 | GroupBox1: TGroupBox; |
| 52 | imgHost: TImage; |
| 53 | imgUsername: TImage; |
| 54 | imgPassword: TImage; |
| 55 | lblCopyright: TLabel; |
| 56 | lblHost: TLabel; |
| 57 | lblUsername: TLabel; |
| 58 | lblPassword: TLabel; |
| 59 | edPort: TSpinEdit; |
| 60 | lblData: TLabel; |
| 61 | btnSaveProfile: TSpeedButton; |
| 62 | btnDeleteProfile: TSpeedButton; |
| 63 | procedure btnCancelClick(Sender: TObject);
|
| 64 | procedure btnDeleteProfileClick(Sender: TObject);
|
| 65 | procedure btnOKClick(Sender: TObject);
|
| 66 | procedure btnSaveProfileClick(Sender: TObject);
|
| 67 | procedure cbProfileChange(Sender: TObject);
|
| 68 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
| 69 | procedure FormCreate(Sender: TObject);
|
| 70 | protected
|
| 71 | FProfilePath: string;
|
| 72 | public
|
| 73 | { public declarations }
|
| 74 | end;
|
| 75 | |
| 76 | var
|
| 77 | frmLogin: TfrmLogin; |
| 78 | |
| 79 | implementation
|
| 80 | |
| 81 | uses
|
| 82 | UdmNetwork; |
| 83 | |
| 84 | {$I version.inc}
|
| 85 | |
| 86 | { TfrmLogin }
|
| 87 | |
| 88 | procedure TfrmLogin.btnCancelClick(Sender: TObject);
|
| 89 | begin
|
| 90 | Close; |
| 91 | end;
|
| 92 | |
| 93 | procedure TfrmLogin.btnDeleteProfileClick(Sender: TObject);
|
| 94 | begin
|
| 95 | if cbProfile.ItemIndex > -1 then |
| 96 | begin
|
| 97 | DeleteFile(FProfilePath + cbProfile.Text + '.ini');
|
| 98 | cbProfile.Items.Delete(cbProfile.ItemIndex); |
| 99 | end;
|
| 100 | end;
|
| 101 | |
| 102 | procedure TfrmLogin.btnOKClick(Sender: TObject);
|
| 103 | var
|
| 104 | path: string;
|
| 105 | begin
|
| 106 | path := IncludeTrailingPathDelimiter(edData.Text); |
| 107 | if (not FileExists(path + 'art.mul')) or |
| 108 | (not FileExists(path + 'artidx.mul')) or |
| 109 | (not FileExists(path + 'hues.mul')) or |
| 110 | (not FileExists(path + 'tiledata.mul')) or |
| 111 | (not FileExists(path + 'texmaps.mul')) or |
| 112 | (not FileExists(path + 'texidx.mul')) then |
| 113 | begin
|
| 114 | MessageDlg('Incorrect directory', 'The data path you specified does not seem to be correct.', mtWarning, [mbOK], 0); |
| 115 | edData.SetFocus; |
| 116 | Exit; |
| 117 | end else |
| 118 | ModalResult := mrOK; |
| 119 | end;
|
| 120 | |
| 121 | procedure TfrmLogin.btnSaveProfileClick(Sender: TObject);
|
| 122 | var
|
| 123 | profileName: string;
|
| 124 | profile: TIniFile; |
| 125 | begin
|
| 126 | profileName := cbProfile.Text; |
| 127 | if InputQuery('Save profile', 'Enter the name of the profile:', profileName) then |
| 128 | begin
|
| 129 | profile := TIniFile.Create(FProfilePath + profileName + '.ini');
|
| 130 | profile.WriteString('Connection', 'Host', edHost.Text); |
| 131 | profile.WriteInteger('Connection', 'Port', edPort.Value); |
| 132 | profile.WriteString('Connection', 'Username', edUsername.Text); |
| 133 | profile.WriteString('Data', 'Path', edData.Text); |
| 134 | profile.Free; |
| 135 | cbProfile.ItemIndex := cbProfile.Items.IndexOf(profileName); |
| 136 | if cbProfile.ItemIndex = -1 then |
| 137 | begin
|
| 138 | cbProfile.Items.Add(profileName); |
| 139 | cbProfile.ItemIndex := cbProfile.Items.Count - 1;
|
| 140 | end;
|
| 141 | end;
|
| 142 | end;
|
| 143 | |
| 144 | procedure TfrmLogin.cbProfileChange(Sender: TObject);
|
| 145 | var
|
| 146 | profile: TIniFile; |
| 147 | begin
|
| 148 | if cbProfile.ItemIndex > -1 then |
| 149 | begin
|
| 150 | profile := TIniFile.Create(FProfilePath + cbProfile.Text + '.ini');
|
| 151 | edHost.Text := profile.ReadString('Connection', 'Host', ''); |
| 152 | edPort.Value := profile.ReadInteger('Connection', 'Port', 2597); |
| 153 | edUsername.Text := profile.ReadString('Connection', 'Username', ''); |
| 154 | edPassword.Text := '';
|
| 155 | edData.Text := profile.ReadString('Data', 'Path', ''); |
| 156 | edPassword.SetFocus; |
| 157 | profile.Free; |
| 158 | end;
|
| 159 | end;
|
| 160 | |
| 161 | procedure TfrmLogin.FormClose(Sender: TObject; var CloseAction: TCloseAction); |
| 162 | begin
|
| 163 | if ModalResult <> mrOK then |
| 164 | dmNetwork.CheckClose(Self); |
| 165 | end;
|
| 166 | |
| 167 | procedure TfrmLogin.FormCreate(Sender: TObject);
|
| 168 | var
|
| 169 | searchRec: TSearchRec; |
| 170 | begin
|
| 171 | lblCopyright.Caption := Format('UO CentrED Client Version %s (c) %s', [ProductVersion, Copyright]);
|
| 172 | |
| 173 | FProfilePath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) + 'Profiles' + PathDelim;
|
| 174 | if FindFirst(FProfilePath + '*.ini', faAnyFile, searchRec) = 0 then |
| 175 | begin
|
| 176 | repeat
|
| 177 | cbProfile.Items.Add(ChangeFileExt(searchRec.Name, ''));
|
| 178 | until FindNext(searchRec) <> 0; |
| 179 | end;
|
| 180 | FindClose(searchRec); |
| 181 | end;
|
| 182 | |
| 183 | initialization
|
| 184 | {$I UfrmLogin.lrs}
|
| 185 | |
| 186 | end.
|
| 187 |