author | llornkcor <llornkcor> | 2002-02-24 15:27:06 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-24 15:27:06 (UTC) |
commit | a43106c752dae2404f33a07dc80851c4a745d2bc (patch) (unidiff) | |
tree | 1bddeba58034bc08c6a24d656098d9104df99ee6 /noncore/unsupported/filebrowser/filePermissions.cpp | |
parent | 7dd14b051a5c1bad0fd0c76c00d06b0d51e1f17f (diff) | |
download | opie-a43106c752dae2404f33a07dc80851c4a745d2bc.zip opie-a43106c752dae2404f33a07dc80851c4a745d2bc.tar.gz opie-a43106c752dae2404f33a07dc80851c4a745d2bc.tar.bz2 |
added permissions dialog
Diffstat (limited to 'noncore/unsupported/filebrowser/filePermissions.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/filebrowser/filePermissions.cpp | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/noncore/unsupported/filebrowser/filePermissions.cpp b/noncore/unsupported/filebrowser/filePermissions.cpp new file mode 100644 index 0000000..1938b84 --- a/dev/null +++ b/noncore/unsupported/filebrowser/filePermissions.cpp | |||
@@ -0,0 +1,274 @@ | |||
1 | /**************************************************************************** | ||
2 | ** copyright 2002 ljp ljp@llornkcor.com | ||
3 | ** Created: Sat Feb 23 19:44:40 2002 L.J. Potter | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | ** | ||
13 | ****************************************************************************/ | ||
14 | #include "filePermissions.h" | ||
15 | |||
16 | #include <qfile.h> | ||
17 | #include <qfileinfo.h> | ||
18 | |||
19 | #include <qcheckbox.h> | ||
20 | #include <qlabel.h> | ||
21 | #include <qlineedit.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qvariant.h> | ||
24 | #include <qtooltip.h> | ||
25 | #include <qmessagebox.h> | ||
26 | |||
27 | #include <unistd.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <stdlib.h> | ||
30 | #include <sys/types.h> | ||
31 | #include <pwd.h> | ||
32 | #include <grp.h> | ||
33 | |||
34 | filePermissions::filePermissions( QWidget* parent, const char* name, bool modal, WFlags fl, const QString &fileName ) | ||
35 | : QDialog( parent, name, modal, fl ) | ||
36 | { | ||
37 | if ( !name ) | ||
38 | setName( "filePermissions" ); | ||
39 | qDebug("FilePermissions "+fileName); | ||
40 | resize( 236, 210 ); | ||
41 | setMaximumSize( QSize( 236, 210 ) ); | ||
42 | setCaption( tr( "Set File Permissions" ) ); | ||
43 | |||
44 | TextLabel1 = new QLabel( this, "TextLabel1" ); | ||
45 | TextLabel1->setGeometry( QRect( 25, 5, 175, 20 ) ); | ||
46 | TextLabel1->setText( tr( "Set file permissions for:" ) ); | ||
47 | |||
48 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | ||
49 | LineEdit1->setGeometry( QRect( 10, 25, 218, 22 ) ); | ||
50 | LineEdit1->setReadOnly(true); | ||
51 | |||
52 | TextLabel4 = new QLabel( this, "TextLabel4" ); | ||
53 | TextLabel4->setGeometry( QRect( 5, 85, 50, 15 ) ); | ||
54 | TextLabel4->setText( tr( "owner" ) ); | ||
55 | |||
56 | TextLabel4_2 = new QLabel( this, "TextLabel4_2" ); | ||
57 | TextLabel4_2->setGeometry( QRect( 5, 105, 50, 15 ) ); | ||
58 | TextLabel4_2->setText( tr( "group" ) ); | ||
59 | |||
60 | TextLabel4_3 = new QLabel( this, "TextLabel4_3" ); | ||
61 | TextLabel4_3->setGeometry( QRect( 5, 125, 50, 15 ) ); | ||
62 | TextLabel4_3->setText( tr( "others" ) ); | ||
63 | |||
64 | CheckBox1 = new QCheckBox( this, "CheckBox1" ); | ||
65 | CheckBox1->setGeometry( QRect( 75, 85, 20, 16 ) ); | ||
66 | connect(CheckBox1, SIGNAL(released()),this,SLOT(ownReadCheck())); | ||
67 | |||
68 | CheckBox1_2 = new QCheckBox( this, "CheckBox1_2" ); | ||
69 | CheckBox1_2->setGeometry( QRect( 135, 85, 20, 16 ) ); | ||
70 | connect(CheckBox1_2, SIGNAL(released()),this,SLOT(ownWriteCheck())); | ||
71 | |||
72 | CheckBox1_3 = new QCheckBox( this, "CheckBox1_3" ); | ||
73 | CheckBox1_3->setGeometry( QRect( 195, 85, 20, 16 ) ); | ||
74 | connect(CheckBox1_3, SIGNAL(released()),this,SLOT(ownExeCheck())); | ||
75 | |||
76 | CheckBox1_4 = new QCheckBox( this, "CheckBox1_4" ); | ||
77 | CheckBox1_4->setGeometry( QRect( 75, 105, 20, 16 ) ); | ||
78 | connect(CheckBox1_4, SIGNAL(released()),this,SLOT(grpReadCheck())); | ||
79 | |||
80 | CheckBox1_5 = new QCheckBox( this, "CheckBox1_5" ); | ||
81 | CheckBox1_5->setGeometry( QRect( 135, 105, 20, 16 ) ); | ||
82 | connect(CheckBox1_5, SIGNAL(released()),this,SLOT(grpWriteCheck())); | ||
83 | |||
84 | CheckBox1_6 = new QCheckBox( this, "CheckBox1_6" ); | ||
85 | CheckBox1_6->setGeometry( QRect( 195, 105, 20, 16 ) ); | ||
86 | connect(CheckBox1_6, SIGNAL(released()),this,SLOT(grpExeCheck())); | ||
87 | |||
88 | CheckBox1_7 = new QCheckBox( this, "CheckBox1_7" ); | ||
89 | CheckBox1_7->setGeometry( QRect( 75, 125, 16, 16 ) ); | ||
90 | connect(CheckBox1_7, SIGNAL(released()),this,SLOT(wrldReadCheck())); | ||
91 | |||
92 | CheckBox1_8 = new QCheckBox( this, "CheckBox1_8" ); | ||
93 | CheckBox1_8->setGeometry( QRect( 135, 125, 20, 16 ) ); | ||
94 | connect(CheckBox1_8, SIGNAL(released()),this,SLOT(wrldWriteCheck())); | ||
95 | |||
96 | CheckBox1_8_2 = new QCheckBox( this, "CheckBox1_8_2" ); | ||
97 | CheckBox1_8_2->setGeometry( QRect( 195, 125, 20, 16 ) ); | ||
98 | connect(CheckBox1_8_2, SIGNAL(released()),this,SLOT(wrldExeCheck())); | ||
99 | |||
100 | GroupLineEdit = new QLineEdit( this, "GroupLineEdit" ); | ||
101 | GroupLineEdit->setGeometry( QRect( 125, 155, 106, 22 ) ); | ||
102 | |||
103 | OwnerLineEdit = new QLineEdit( this, "OwnerLineEdit" ); | ||
104 | OwnerLineEdit->setGeometry( QRect( 10, 155, 106, 22 ) ); | ||
105 | |||
106 | TextLabel5 = new QLabel( this, "TextLabel5" ); | ||
107 | TextLabel5->setGeometry( QRect( 45, 180, 40, 16 ) ); | ||
108 | TextLabel5->setText( tr( "Owner" ) ); | ||
109 | |||
110 | TextLabel5_2 = new QLabel( this, "TextLabel5_2" ); | ||
111 | TextLabel5_2->setGeometry( QRect( 155, 180, 40, 16 ) ); | ||
112 | TextLabel5_2->setText( tr( "Group" ) ); | ||
113 | |||
114 | ModeLine = new QLineEdit( this, "TextLabelMode" ); | ||
115 | ModeLine->setGeometry( QRect( 10, 60, 40, 15 ) ); | ||
116 | |||
117 | TextLabel3_2 = new QLabel( this, "TextLabel3_2" ); | ||
118 | TextLabel3_2->setGeometry( QRect( 60, 55, 50, 20 ) ); | ||
119 | TextLabel3_2->setText( tr( "read" ) ); | ||
120 | TextLabel3_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
121 | |||
122 | TextLabel3_2_2 = new QLabel( this, "TextLabel3_2_2" ); | ||
123 | TextLabel3_2_2->setGeometry( QRect( 120, 55, 50, 20 ) ); | ||
124 | TextLabel3_2_2->setText( tr( "write" ) ); | ||
125 | TextLabel3_2_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
126 | |||
127 | TextLabel3 = new QLabel( this, "TextLabel3" ); | ||
128 | TextLabel3->setGeometry( QRect( 180, 55, 50, 20 ) ); | ||
129 | TextLabel3->setText( tr( "execute" ) ); | ||
130 | TextLabel3->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
131 | |||
132 | struct stat buf; | ||
133 | mode_t mode; | ||
134 | file = fileName; | ||
135 | QFileInfo fi(file); | ||
136 | |||
137 | LineEdit1->setText( file); | ||
138 | OwnerLineEdit->setText( fi.owner()); | ||
139 | GroupLineEdit->setText( fi.group()); | ||
140 | |||
141 | if( fi.permission( QFileInfo::ReadUser)) { CheckBox1->setChecked(true); } | ||
142 | if( fi.permission( QFileInfo::WriteUser)) { CheckBox1_2->setChecked(true); } | ||
143 | if( fi.permission( QFileInfo::ExeUser)) { CheckBox1_3->setChecked(true); } | ||
144 | |||
145 | if( fi.permission( QFileInfo::ReadGroup)) { CheckBox1_4->setChecked(true); } | ||
146 | if( fi.permission( QFileInfo::WriteGroup)) { CheckBox1_5->setChecked(true); } | ||
147 | if( fi.permission( QFileInfo::ExeGroup)) { CheckBox1_6->setChecked(true); } | ||
148 | |||
149 | if( fi.permission( QFileInfo::ReadOther)) { CheckBox1_7->setChecked(true); } | ||
150 | if( fi.permission( QFileInfo::WriteOther)) { CheckBox1_8->setChecked(true); } | ||
151 | if( fi.permission( QFileInfo::ExeOther)) { CheckBox1_8_2->setChecked(true); } | ||
152 | |||
153 | lstat(file.latin1(), &buf); | ||
154 | mode = buf.st_mode; | ||
155 | modeStr.sprintf("%#o", buf.st_mode & ~(S_IFMT) ); | ||
156 | ModeLine->setText(modeStr); | ||
157 | bool ok; | ||
158 | i_mode = modeStr.toInt(&ok,10); | ||
159 | |||
160 | } | ||
161 | |||
162 | /* | ||
163 | * Destroys the object and frees any allocated resources | ||
164 | */ | ||
165 | filePermissions::~filePermissions() | ||
166 | { | ||
167 | } | ||
168 | |||
169 | |||
170 | // might this be better as a callback routine??? | ||
171 | void filePermissions::ownReadCheck() { | ||
172 | if(CheckBox1->isChecked()) { i_mode +=400; } | ||
173 | else i_mode -=400; | ||
174 | modeStr.sprintf("0%d",i_mode); | ||
175 | ModeLine->setText( modeStr); | ||
176 | // 0400 | ||
177 | } | ||
178 | |||
179 | void filePermissions::ownWriteCheck() { | ||
180 | if(CheckBox1_2->isChecked()) { i_mode +=200; } | ||
181 | else i_mode -=200; | ||
182 | modeStr.sprintf("0%d",i_mode); | ||
183 | ModeLine->setText(modeStr); | ||
184 | // 0200 | ||
185 | } | ||
186 | |||
187 | void filePermissions::ownExeCheck() { | ||
188 | if(CheckBox1_3->isChecked()) { i_mode +=100; } | ||
189 | else i_mode -=100; | ||
190 | modeStr.sprintf("0%d",i_mode); | ||
191 | ModeLine->setText(modeStr); | ||
192 | // 0100 | ||
193 | } | ||
194 | |||
195 | void filePermissions::grpReadCheck() { | ||
196 | if(CheckBox1_4->isChecked()) { i_mode +=40; } | ||
197 | else i_mode -=40; | ||
198 | modeStr.sprintf("0%d",i_mode); | ||
199 | ModeLine->setText(modeStr); | ||
200 | // 0040 | ||
201 | } | ||
202 | |||
203 | void filePermissions::grpWriteCheck() { | ||
204 | if(CheckBox1_5->isChecked()) { i_mode +=20; } | ||
205 | else i_mode -=20; | ||
206 | modeStr.sprintf("0%d",i_mode); | ||
207 | ModeLine->setText(modeStr); | ||
208 | // 0020 | ||
209 | } | ||
210 | |||
211 | void filePermissions::grpExeCheck() { | ||
212 | if(CheckBox1_6->isChecked()) { i_mode +=10; } | ||
213 | else i_mode -=10; | ||
214 | modeStr.sprintf("0%d",i_mode); | ||
215 | ModeLine->setText(modeStr); | ||
216 | // 0010 | ||
217 | } | ||
218 | |||
219 | void filePermissions::wrldReadCheck() { | ||
220 | if(CheckBox1_7->isChecked()) { i_mode +=4; } | ||
221 | else i_mode -=4; | ||
222 | modeStr.sprintf("0%d",i_mode); | ||
223 | ModeLine->setText(modeStr); | ||
224 | // 0004 | ||
225 | } | ||
226 | |||
227 | void filePermissions::wrldWriteCheck() { | ||
228 | if(CheckBox1_8->isChecked()) { i_mode +=2; } | ||
229 | else i_mode -=2; | ||
230 | modeStr.sprintf("0%d",i_mode); | ||
231 | ModeLine->setText(modeStr); | ||
232 | // 0002 | ||
233 | } | ||
234 | |||
235 | void filePermissions::wrldExeCheck() { | ||
236 | if(CheckBox1_8_2->isChecked()) { i_mode +=1; } | ||
237 | else i_mode -=1; | ||
238 | modeStr.sprintf("0%d",i_mode); | ||
239 | ModeLine->setText(modeStr); | ||
240 | // 0001 | ||
241 | } | ||
242 | |||
243 | void filePermissions::accept() { | ||
244 | |||
245 | QFileInfo fi(file); | ||
246 | struct passwd *pwd=0; | ||
247 | struct group *grp=0; | ||
248 | pwd = getpwnam(OwnerLineEdit->text().latin1() ); | ||
249 | if(pwd == NULL) { | ||
250 | perror("getpwnam"); | ||
251 | QMessageBox::warning(this,"Warning","Error- no user"); | ||
252 | return; | ||
253 | } else { | ||
254 | grp = getgrnam(GroupLineEdit->text().latin1()); | ||
255 | if(grp==NULL) { | ||
256 | perror("getgrnam"); | ||
257 | QMessageBox::warning(this,"Warning","Error- no group"); | ||
258 | return; | ||
259 | } | ||
260 | if( chown( file.latin1(), pwd->pw_uid, grp->gr_gid) <0) { | ||
261 | perror("chown"); | ||
262 | QMessageBox::warning(this,"Warning","Error setting ownership or group"); | ||
263 | return; | ||
264 | } | ||
265 | bool ok; | ||
266 | uint moder = modeStr.toUInt(&ok,8); | ||
267 | if( chmod( file.latin1(), moder) < 0) { | ||
268 | perror("chmod"); | ||
269 | QMessageBox::warning(this,"Warning","Error setting mode"); | ||
270 | return; | ||
271 | } | ||
272 | } | ||
273 | close(); | ||
274 | } | ||