forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigDlg.pas
380 lines (354 loc) · 11.5 KB
/
ConfigDlg.pas
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
{ LDAPAdmin - ConfigDlg.pas
* Copyright (C) 2006-2015 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
* Modifications: Ivo Brhel, 2016
*
* This file 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 file 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
}
unit ConfigDlg;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType, LMessages,
{$ENDIF}
SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, Dialogs, LDAPClasses, ComCtrls, LAControls, Grids;
type
TConfigDlg = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
GroupBox2: TGroupBox;
Label1: TLabel;
TemplateList: TListBox;
btnAdd: TButton;
btnDel: TButton;
GroupBox1: TGroupBox;
cbIdObject: TCheckBox;
cbEnforceContainer: TCheckBox;
GroupBox3: TGroupBox;
cbConnect: TCheckBox;
Panel1: TPanel;
OKBtn: TButton;
CancelBtn: TButton;
GroupBox4: TGroupBox;
Label2: TLabel;
edQSearch: TEdit;
GroupBox5: TGroupBox;
cbTemplateExtensions: TCheckBox;
cbTemplateAutoload: TCheckBox;
cbTemplateProperties: TCheckBox;
SetDefBtn: TButton;
CheckAssocCbk: TCheckBox;
cbSmartDelete: TCheckBox;
TabSheet3: TTabSheet;
edSearch: TEdit;
Label4: TLabel;
cbTemplateIcons: TCheckBox;
GroupBox6: TGroupBox;
Label5: TLabel;
LanguageList: TListBox;
btnAddLang: TButton;
btnDelLang: TButton;
GroupBox7: TGroupBox;
TranscodingTable: TStringGrid;
Label3: TLabel;
btnEditLang: TButton;
cbDisplayEncoded: TCheckBox;
procedure btnAddClick(Sender: TObject);
procedure btnDelClick(Sender: TObject);
procedure cbConnectClick(Sender: TObject);
procedure cbIdObjectClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure SetDefBtnClick(Sender: TObject);
procedure TranscodingTableSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
procedure btnAddLangClick(Sender: TObject);
procedure btnDelLangClick(Sender: TObject);
procedure ListMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure btnEditLangClick(Sender: TObject);
private
cbStartupConnection: TLAComboBox;
procedure cbStartupConnectionDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure cbStartupConnectionCloseUp(var Index: integer; var CanCloseUp: boolean);
public
constructor Create(AOwner: TComponent; ASession: TLdapSession); reintroduce;
end;
implementation
{$I LdapAdmin.inc}
uses FileCtrl, Config, Templates, Constant, Misc, Main, Lang
{$IFDEF VER_XEH}, System.Types, System.UITypes{$ENDIF};
{$R *.dfm}
constructor TConfigDlg.Create(AOwner: TComponent; ASession: TLdapSession);
var
i, j: Integer;
s: string;
names: TStrings;
begin
inherited Create(AOwner);
cbStartupConnection := TLAComboBox.Create(Self);
with cbStartupConnection do
begin
Parent := GroupBox3;
Left := cbConnect.Left + 25 + self.Canvas.TextWidth(cbConnect.Caption);
Top := cbConnect.Top - 2;
Width := SetDefBtn.Left + SetDefBtn.Width - Left;
Height := 21;
ItemHeight := 16;
Style := csOwnerDrawFixed;
Color := clBtnFace;
Enabled := False;
TabOrder := 1;
OnDrawItem := cbStartupConnectionDrawItem;
OnCanCloseUp := cbStartupConnectionCloseUp;
end;
for i:=0 to GlobalConfig.StoragesCount-1 do with GlobalConfig.Storages[i] do
begin
cbStartupConnection.Items.AddObject(Name, GlobalConfig.Storages[i]);
for j:=0 to AccountsCount-1 do
cbStartupConnection.Items.AddObject(Accounts[j].Name, Accounts[j]);
end;
with GlobalConfig do begin
LanguageList.Items.CommaText := ReadString(rLanguageDir);
TemplateList.Items.CommaText := ReadString(rTemplateDir);
cbTemplateExtensions.Checked := ReadBool(rTemplateExtensions, true);
cbTemplateAutoload.Checked := ReadBool(rTemplateAutoload, true);
cbTemplateProperties.Checked := ReadBool(rTemplateProperties, true);
cbSmartDelete.Checked := ReadBool(rSmartDelete, true);
cbTemplateIcons.Checked := ReadBool(rUseTemplateImages, false);
CheckAssocCbk.Checked:= not ReadBool(rDontCheckProto, false);
cbDisplayEncoded.Checked := ReadBool(rEncodedLdapStrings, false);
s := ReadString(rStartupSession);
with cbStartupConnection do
for i := 0 to Items.Count - 1 do with TAccount(Items.Objects[i]) do
if (Items.Objects[i] is TAccount) and (AnsiCompareText(Storage.Name + ':' + Name, s) = 0) then
begin
cbConnect.Checked := true;
cbStartupConnection.ItemIndex := i;
Break;
end;
cbIdObject.Checked := ReadBool(rMwLTIdentObject, true);
cbEnforceContainer.Checked := ReadBool(rMwLTEnfContainer, true);
edSearch.Text := ReadString(rSearchFilter, sDEFSRCH);
edQSearch.Text := ReadString(rQuickSearchFilter, sDEFQUICKSRCH);
names := TStringList.Create;
with TranscodingTable do
try
ColWidths[1] := Width - ColWidths[0] - 6;
Split(ReadString(rLocalTransTable), names, #$1E);
for i := 0 to names.Count - 1 do
begin
Cells[0, FixedRows + i] := Copy(names[i], 1, Pos(#$1F, names[i]) - 1);
Cells[1, FixedRows + i] := Copy(names[i], Length(Cells[0, FixedRows + i]) + 2, MaxInt);
end;
finally
names.Free;
end;
end;
end;
procedure TConfigDlg.btnAddClick(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('','',Dir) then
TemplateList.Items.Add(Dir);
end;
procedure TConfigDlg.btnDelClick(Sender: TObject);
begin
with TemplateList do
if ItemIndex <> -1 then
Items.Delete(ItemIndex);
end;
procedure TConfigDlg.cbConnectClick(Sender: TObject);
begin
with cbStartupConnection do
if cbConnect.Checked then
begin
Enabled := true;
Color := clWindow;
end
else begin
Enabled := false;
Color := clBtnFace;
ItemIndex := -1;
end;
end;
procedure TConfigDlg.cbIdObjectClick(Sender: TObject);
begin
if cbIdObject.Checked then
begin
cbEnforceContainer.Enabled := true;
cbEnforceContainer.Checked := true;
cbEnforceContainer.AllowGrayed := false;
end
else begin
cbEnforceContainer.Enabled := false;
cbEnforceContainer.AllowGrayed := true;
cbEnforceContainer.State := cbGrayed;
end;
end;
procedure TConfigDlg.FormClose(Sender: TObject; var Action: TCloseAction);
var
Account: TAccount;
i: Integer;
s: string;
begin
Action := caFree;
if ModalResult = mrOk then with GlobalConfig do
begin
TemplateParser.Paths := TemplateList.Items.CommaText;
TemplateParser.AddPath(ExtractFileDir(application.ExeName) + '\*.' + TEMPLATE_EXT);
LanguageLoader.Paths := LanguageList.Items.CommaText;
LanguageLoader.AddPath(ExtractFileDir(application.ExeName) + '\*.' + LANG_EXT);
WriteBool(rTemplateExtensions, cbTemplateExtensions.Checked);
WriteBool(rTemplateAutoload, cbTemplateAutoload.Checked);
WriteBool(rTemplateProperties, cbTemplateProperties.Checked);
WriteBool(rSmartDelete, cbSmartDelete.Checked);
WriteBool(rUseTemplateImages, cbTemplateIcons.Checked);
WriteString(rTemplateDir, TemplateList.Items.CommaText);
WriteString(rLanguageDir, LanguageList.Items.CommaText);
WriteBool(rDontCheckProto, not CheckAssocCbk.Checked);
WriteBool(rEncodedLdapStrings, cbDisplayEncoded.Checked);
with cbStartupConnection do
begin
if ItemIndex = -1 then
WriteString(rStartupSession, '')
else begin
Account := TAccount(Items.Objects[ItemIndex]);
WriteString(rStartupSession, Account.Storage.Name + ':' + Account.Name);
end;
end;
WriteBool(rMwLTIdentObject, cbIdObject.Checked);
WriteBool(rMwLTEnfContainer, cbEnforceContainer.Checked);
WriteString(rSearchFilter, edSearch.Text);
WriteString(rQuickSearchFilter, edQSearch.Text);
s := '';
with TranscodingTable do
for i := FixedRows to RowCount - 1 do
if Cells[0, i] <> '' then
s := s + Cells[0, i] + #$1F + Cells[1, i] + #$1E;
if s <> '' then
WriteString(rLocalTransTable, s)
else
Delete(rLocalTransTable);
end;
end;
procedure TConfigDlg.FormDestroy(Sender: TObject);
begin
cbStartupConnection.Free;
end;
procedure TConfigDlg.cbStartupConnectionDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
s: string;
ImageIndex: Integer;
begin
with cbStartupConnection do
begin
Canvas.FillRect(rect);
if Items.Objects[Index] is TConfigStorage then
begin
if Index = 0 then
ImageIndex := 32
else
ImageIndex := 33;
end
else begin
ImageIndex := bmHost;
Rect.Left:=Rect.Left+20;
end;
Rect.Top:=Rect.Top+1;
Rect.Bottom:=Rect.Bottom-1;
Rect.Left:=rect.Left+2;
MainFrm.ImageList.Draw(Canvas, Rect.Left, Rect.Top, ImageIndex);
Rect.Left := Rect.Left + 20;
s := Items[Index];
DrawText(Canvas.Handle, PChar(s), Length(s), Rect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
end;
end;
procedure TConfigDlg.cbStartupConnectionCloseUp(var Index: integer; var CanCloseUp: boolean);
begin
if cbStartupConnection.Items.Objects[Index] is TConfigStorage then
begin
Beep;
CanCloseUp := false;
end;
end;
procedure TConfigDlg.SetDefBtnClick(Sender: TObject);
begin
{$ifdef mswindows}
RegProtocol('LDAP');
RegProtocol('LDAPS');
{$endif}
end;
procedure TConfigDlg.TranscodingTableSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String);
begin
with TranscodingTable do
if (ARow = RowCount - 1) and (Cells[ACol, ARow] <> '') then
begin
RowCount := RowCount + 1;
ColWidths[1] := ClientWidth - ColWidths[0] - 1;
end;
end;
procedure TConfigDlg.btnAddLangClick(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('','',Dir) then
LanguageList.Items.Add(Dir);
end;
procedure TConfigDlg.btnDelLangClick(Sender: TObject);
begin
with LanguageList do
if ItemIndex <> -1 then
Items.Delete(ItemIndex);
end;
procedure TConfigDlg.ListMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
i: Integer;
begin
if Sender is TListBox then with TListBox(Sender) do
begin
i := ItemAtPos(Point(x, y), true);
if i <> -1 then
Hint := Items[i]
else
Hint := '';
end;
end;
procedure TConfigDlg.btnEditLangClick(Sender: TObject);
var
Dir: string;
begin
with LanguageList do
begin
if (ItemIndex <> -1) then
begin
Dir := Items[ItemIndex];
if InputQuery(cEditValue, cEnterNewValue, Dir) then
Items[ItemIndex] := Dir;
end;
end;
end;
end.