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
|
(*
Tux Commander - UChown - Change owner dialog
Copyright (C) 2004 Tomas Bzatek <tbzatek@users.sourceforge.net>
Check for updates on tuxcmd.sourceforge.net
This program 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 program 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 UChown;
interface
uses
SysUtils, Classes, lazgdk3, GTKControls, GTKForms, GTKStdCtrls, GTKExtCtrls, GTKView;
type
TFChown = class(TGTKDialog)
HBox, HBox2: TGTKHBox;
VBox: TGTKVBox;
OwnerFrame, GroupFrame, FileFrame: TGTKFrame;
OwnerListView, GroupListView: TGTKListView;
OwnerListViewScrolledWindow, GroupListViewScrolledWindow: TGTKScrolledWindow;
RecursiveCheckButton: TGTKCheckButton;
FileLabel: TGTKLabel;
procedure FormCreate(Sender: TObject); override;
procedure FormKeyDown(Sender: TObject; Key: Word; Shift: TShiftState; var Accept: boolean);
procedure OwnerListViewSelectionChanged(Sender: TObject);
procedure GroupListViewSelectionChanged(Sender: TObject);
public
LastUID, LastGID: integer;
procedure AssignMode(const Mode: Cardinal; const FileName: string; const UID, GID: integer);
private
procedure FillData;
end;
var
FChown: TFChown;
implementation
uses ULibc, ULocale, UCoreUtils, UCoreClasses;
procedure TFChown.FormCreate(Sender: TObject);
begin
SetDefaultSize(-1, -1);
LastUID := geteuid;
LastGID := getegid;
Caption := LANGFChown_Caption;
Buttons := [mbOK, mbCancel];
HBox := TGTKHBox.Create(Self);
HBox.Homogeneous := False;
HBox.BorderWidth := 6;
OwnerFrame := TGTKFrame.Create(Self);
OwnerFrame.Caption := LANGFChown_OwnerFrame;
GroupFrame := TGTKFrame.Create(Self);
GroupFrame.Caption := LANGFChown_GroupFrame;
FileFrame := TGTKFrame.Create(Self);
FileFrame.Caption := LANGFChown_FileFrame;
HBox.AddControlEx(OwnerFrame, True, True, 5);
HBox.AddControlEx(GroupFrame, True, True, 5);
HBox.AddControlEx(FileFrame, True, True, 5);
HBox2 := TGTKHBox.Create(Self);
HBox2.Homogeneous := False;
RecursiveCheckButton := TGTKCheckButton.CreateWithLabel(Self, LANGFChown_ApplyRecursively);
HBox2.AddControlEx(RecursiveCheckButton, False, False, 15);
ClientArea.AddControlEx(HBox, True, True, 0);
ClientArea.AddControlEx(TGTKHSeparator.Create(Self), False, False, 5);
ClientArea.AddControlEx(HBox2, False, False, 3);
FileLabel := TGTKLabel.Create(Self);
FileLabel.XAlign := 0;
FileLabel.YAlign := 0;
FileLabel.MarginStart := 10;
FileLabel.MarginEnd := 10;
FileLabel.MarginTop := 5;
FileLabel.MarginBottom := 5;
FileLabel.Caption := '<span weight="ultrabold">File:</span> .adobe'#10'<span weight="ultrabold">Text:</span> rw-rw-rw'#10 +
'<span weight="ultrabold">Octal:</span> 666'#10'<span weight="ultrabold">Owner:</span> root'#10 +
'<span weight="ultrabold">Group:</span> root';
FileLabel.UseMarkup := True;
FileFrame.AddControl(FileLabel);
OwnerListView := TGTKListView.CreateTyped(Self, False, [lcText, lcNumber]);
OwnerListView.RulesHint := True;
OwnerListView.ShowHeaders := False;
OwnerListView.Columns.Add.AddAttribute('text', 0);
OwnerListViewScrolledWindow := TGTKScrolledWindow.Create(Self);
OwnerListViewScrolledWindow.ShadowType := stShadowIn;
OwnerListViewScrolledWindow.HorizScrollBarPolicy := sbAutomatic;
OwnerListViewScrolledWindow.VertScrollBarPolicy := sbAutomatic;
OwnerListViewScrolledWindow.BorderWidth := 10;
OwnerListViewScrolledWindow.AddControl(OwnerListView);
OwnerListViewScrolledWindow.SetSizeRequest(200, 200);
OwnerFrame.AddControl(OwnerListViewScrolledWindow);
GroupListView := TGTKListView.CreateTyped(Self, False, [lcText, lcNumber]);
GroupListView.RulesHint := True;
GroupListView.ShowHeaders := False;
GroupListView.Columns.Add.AddAttribute('text', 0);
GroupListViewScrolledWindow := TGTKScrolledWindow.Create(Self);
GroupListViewScrolledWindow.ShadowType := stShadowIn;
GroupListViewScrolledWindow.HorizScrollBarPolicy := sbAutomatic;
GroupListViewScrolledWindow.VertScrollBarPolicy := sbAutomatic;
GroupListViewScrolledWindow.BorderWidth := 10;
GroupListViewScrolledWindow.AddControl(GroupListView);
GroupListViewScrolledWindow.SetSizeRequest(200, 200);
GroupFrame.AddControl(GroupListViewScrolledWindow);
FillData;
OnKeyDown := @FormKeyDown;
end;
procedure TFChown.FormKeyDown(Sender: TObject; Key: Word; Shift: TShiftState; var Accept: boolean);
begin
case Key of
GDK_KEY_Return, GDK_KEY_KP_Enter: ModalResult := mbOK;
GDK_KEY_Escape: ModalResult := mbCancel;
end;
end;
procedure TFChown.AssignMode(const Mode: Cardinal; const FileName: string; const UID, GID: integer);
var i: integer;
susr, sgrp: string;
begin
LastUID := UID;
LastGID := GID;
susr := 'N/A';
sgrp := 'N/A';
// Lookup and select current user and group
if OwnerListView.Items.Count > 0 then
for i := 0 to OwnerListView.Items.Count - 1 do
if OwnerListView.Items[i].AsInteger(1) = UID then begin
OwnerListView.Items[i].Selected := True;
OwnerListView.Items[i].SetCursor(0, False, False, 0.5, 0);
susr := OwnerListView.Items[i].AsString(0);
Break;
end;
if GroupListView.Items.Count > 0 then
for i := 0 to GroupListView.Items.Count - 1 do
if GroupListView.Items[i].AsInteger(1) = GID then begin
GroupListView.Items[i].Selected := True;
GroupListView.Items[i].SetCursor(0, False, False, 0.5, 0);
sgrp := GroupListView.Items[i].AsString(0);
Break;
end;
// Fill more info
FileLabel.Caption := Format(LANGFChmod_FileLabel, [StrToUTF8(FileName), AttrToStr(Mode), AttrToOctal(Mode), susr, sgrp]);
FileLabel.UseMarkup := True;
if Length(FileName) > 20 then FileLabel.SetSizeRequest(200, -1);
OwnerListView.OnSelectionChanged := @OwnerListViewSelectionChanged;
GroupListView.OnSelectionChanged := @GroupListViewSelectionChanged;
end;
procedure TFChown.FillData;
var UsrManager: TUserManager;
i: integer;
Item: TGTKListItem;
begin
UsrManager := TUserManager.Create;
try
if UsrManager.UserList.Count > 0 then
for i := 0 to UsrManager.UserList.Count - 1 do begin
Item := OwnerListView.Items.Add;
Item.SetValue(0, TSystemUser(UsrManager.UserList[i]).UserName);
Item.SetValue(1, TSystemUser(UsrManager.UserList[i]).UID);
end;
if UsrManager.GroupList.Count > 0 then
for i := 0 to UsrManager.GroupList.Count - 1 do begin
Item := GroupListView.Items.Add;
Item.SetValue(0, TSystemGroup(UsrManager.GroupList[i]).GroupName);
Item.SetValue(1, TSystemGroup(UsrManager.GroupList[i]).GID);
end;
finally
UsrManager.Free;
end;
end;
procedure TFChown.OwnerListViewSelectionChanged(Sender: TObject);
begin
if Assigned(OwnerListView.Selected) then LastUID := OwnerListView.Selected.AsInteger(1);
end;
procedure TFChown.GroupListViewSelectionChanged(Sender: TObject);
begin
if Assigned(GroupListView.Selected) then LastGID := GroupListView.Selected.AsInteger(1);
end;
end.
|