forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectInfo.pas
173 lines (154 loc) · 4.62 KB
/
ObjectInfo.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
{ LDAPAdmin - ObjectInfo.pas
* Copyright (C) 2013 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
*
* 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 ObjectInfo;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses LDAPClasses, Templates;
const
idUninitialized = -2;
type
TObjectInfo = class
private
FEntry: TLdapEntry;
FOwnsEntry: Boolean;
FObjectID: Integer;
FActionID: Integer;
FImageIndex: Integer;
FTemplate: TTemplate;
function GetObjectID: Integer;
function GetImageIndex: Integer;
function GetDN: string;
function GetIsContainer: Boolean;
function GetActionId: Integer;
function GetSupported: Boolean;
public
constructor Create(Entry: TLdapEntry; const OwnsEntry: Boolean = true);
destructor Destroy; override;
property dn: string read GetDN;
property Entry: TLdapEntry read FEntry;
property ObjectID: Integer read GetObjectId;
property ActionId: Integer read GetActionId;
property ImageIndex: Integer read GetImageIndex;
property IsContainer: Boolean read GetIsContainer;
property Template: TTemplate read FTemplate;
property Supported: Boolean read GetSupported;
end;
implementation
uses Connection, CustomMenus, Constant;
{ TObjectInfo }
function TObjectInfo.GetActionID: Integer;
begin
if FActionId = idUninitialized then with (FEntry.Session as TConnection).ActionMenu do
begin
{ temporary workaround }
if ObjectId = oidEntry then
begin
if Assigned(GetActionTemplate(Entry)) then
FActionId := aidTemplate
else
FActionId := aidNone;
end
else
{ end workaround }
FActionId := GetActionId(ObjectID);
if FActionId = aidTemplate then
begin
FTemplate := GetActionTemplate(FEntry);
if not Assigned(FTemplate) then
FActionId := aidNone;
end;
end;
Result := FActionId;
end;
function TObjectInfo.GetSupported: Boolean;
begin
Result := ActionID <> aidNone;
end;
function TObjectInfo.GetIsContainer: Boolean;
begin
Result := (fEntry.Session as TConnection).DI.IsContainer(ObjectID);
end;
function TObjectInfo.GetObjectID: Integer;
begin
if FObjectID = oidUnknown then
FObjectID := (Entry.Session as TConnection).DI.ClassifyLdapEntry(Entry);
Result := FObjectID;
end;
function TObjectInfo.GetImageIndex: Integer;
var
i: Integer;
Template: TTemplate;
begin
if FImageIndex = idUninitialized then
begin
{ temporary workaround }
if ObjectId = oidEntry then with (FEntry.Session as TConnection).ActionMenu do
begin
Template := GetActionTemplate(Entry);
if Assigned(Template) then
begin
FImageIndex := bmTemplateEntry;
if Template.ImageIndex <> -1 then
FImageIndex := Template.ImageIndex;
Result := FImageIndex;
exit;
end;
end;
{ end workaround }
if (ObjectId = oidEntry) and UseTemplateImages then
begin
FImageIndex := bmEntry;
for i := 0 to TemplateParser.Count - 1 do with TemplateParser.Templates[i] do
if {(ImageIndex <> -1 ) and} Matches(Entry.ObjectClass) then
begin
if ImageIndex = -1 then
FImageIndex := bmTemplateEntry
else
FImageIndex := ImageIndex;
break;
end;
end
else
FImageIndex := ObjectIdToImage[ObjectId];
end;
Result := FImageIndex;
end;
function TObjectInfo.GetDN: string;
begin
Result := FEntry.DN;
end;
constructor TObjectInfo.Create(Entry: TLdapEntry; const OwnsEntry: Boolean = true);
begin
FEntry := Entry;
FOwnsEntry := OwnsEntry;
FObjectID := oidUnknown;
FImageIndex := idUninitialized;
FActionId := idUninitialized;
end;
destructor TObjectInfo.Destroy;
begin
if FOwnsEntry then
FEntry.Free;
inherited Destroy;
end;
end.