summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieftp/filePermissions.cpp276
-rw-r--r--noncore/net/opieftp/filePermissions.h58
-rw-r--r--noncore/net/opieftp/opieftp.pro4
3 files changed, 336 insertions, 2 deletions
diff --git a/noncore/net/opieftp/filePermissions.cpp b/noncore/net/opieftp/filePermissions.cpp
new file mode 100644
index 0000000..ab094db
--- a/dev/null
+++ b/noncore/net/opieftp/filePermissions.cpp
@@ -0,0 +1,276 @@
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
34filePermissions::filePermissions( QWidget* parent, const char* name, bool modal, WFlags fl, const QString &fileName, bool useRemote )
35 : QDialog( parent, name, modal, fl )
36{
37 if ( !name )
38 setName( tr("filePermissions") );
39// qDebug("FilePermissions "+fileName);
40 resize( 236, 210 );
41 isRemote=useRemote;
42 setMaximumSize( QSize( 236, 210 ) );
43 setCaption( tr( "Set File Permissions" ) );
44
45 TextLabel1 = new QLabel( this, "TextLabel1" );
46 TextLabel1->setGeometry( QRect( 25, 5, 175, 20 ) );
47 TextLabel1->setText( tr( "Set file permissions for:" ) );
48
49 LineEdit1 = new QLineEdit( this, "LineEdit1" );
50 LineEdit1->setGeometry( QRect( 10, 25, 218, 22 ) );
51 LineEdit1->setReadOnly(true);
52
53 TextLabel4 = new QLabel( this, "TextLabel4" );
54 TextLabel4->setGeometry( QRect( 5, 85, 50, 15 ) );
55 TextLabel4->setText( tr( "owner" ) );
56
57 TextLabel4_2 = new QLabel( this, "TextLabel4_2" );
58 TextLabel4_2->setGeometry( QRect( 5, 105, 50, 15 ) );
59 TextLabel4_2->setText( tr( "group" ) );
60
61 TextLabel4_3 = new QLabel( this, "TextLabel4_3" );
62 TextLabel4_3->setGeometry( QRect( 5, 125, 50, 15 ) );
63 TextLabel4_3->setText( tr( "others" ) );
64
65 CheckBox1 = new QCheckBox( this, "CheckBox1" );
66 CheckBox1->setGeometry( QRect( 75, 85, 20, 16 ) );
67 connect(CheckBox1, SIGNAL(released()),this,SLOT(ownReadCheck()));
68
69 CheckBox1_2 = new QCheckBox( this, "CheckBox1_2" );
70 CheckBox1_2->setGeometry( QRect( 135, 85, 20, 16 ) );
71 connect(CheckBox1_2, SIGNAL(released()),this,SLOT(ownWriteCheck()));
72
73 CheckBox1_3 = new QCheckBox( this, "CheckBox1_3" );
74 CheckBox1_3->setGeometry( QRect( 195, 85, 20, 16 ) );
75 connect(CheckBox1_3, SIGNAL(released()),this,SLOT(ownExeCheck()));
76
77 CheckBox1_4 = new QCheckBox( this, "CheckBox1_4" );
78 CheckBox1_4->setGeometry( QRect( 75, 105, 20, 16 ) );
79 connect(CheckBox1_4, SIGNAL(released()),this,SLOT(grpReadCheck()));
80
81 CheckBox1_5 = new QCheckBox( this, "CheckBox1_5" );
82 CheckBox1_5->setGeometry( QRect( 135, 105, 20, 16 ) );
83 connect(CheckBox1_5, SIGNAL(released()),this,SLOT(grpWriteCheck()));
84
85 CheckBox1_6 = new QCheckBox( this, "CheckBox1_6" );
86 CheckBox1_6->setGeometry( QRect( 195, 105, 20, 16 ) );
87 connect(CheckBox1_6, SIGNAL(released()),this,SLOT(grpExeCheck()));
88
89 CheckBox1_7 = new QCheckBox( this, "CheckBox1_7" );
90 CheckBox1_7->setGeometry( QRect( 75, 125, 16, 16 ) );
91 connect(CheckBox1_7, SIGNAL(released()),this,SLOT(wrldReadCheck()));
92
93 CheckBox1_8 = new QCheckBox( this, "CheckBox1_8" );
94 CheckBox1_8->setGeometry( QRect( 135, 125, 20, 16 ) );
95 connect(CheckBox1_8, SIGNAL(released()),this,SLOT(wrldWriteCheck()));
96
97 CheckBox1_8_2 = new QCheckBox( this, "CheckBox1_8_2" );
98 CheckBox1_8_2->setGeometry( QRect( 195, 125, 20, 16 ) );
99 connect(CheckBox1_8_2, SIGNAL(released()),this,SLOT(wrldExeCheck()));
100
101 GroupLineEdit = new QLineEdit( this, "GroupLineEdit" );
102 GroupLineEdit->setGeometry( QRect( 125, 155, 106, 22 ) );
103
104 OwnerLineEdit = new QLineEdit( this, "OwnerLineEdit" );
105 OwnerLineEdit->setGeometry( QRect( 10, 155, 106, 22 ) );
106
107 TextLabel5 = new QLabel( this, "TextLabel5" );
108 TextLabel5->setGeometry( QRect( 45, 180, 40, 16 ) );
109 TextLabel5->setText( tr( "Owner" ) );
110
111 TextLabel5_2 = new QLabel( this, "TextLabel5_2" );
112 TextLabel5_2->setGeometry( QRect( 155, 180, 40, 16 ) );
113 TextLabel5_2->setText( tr( "Group" ) );
114
115 ModeLine = new QLineEdit( this, "TextLabelMode" );
116 ModeLine->setGeometry( QRect( 10, 60, 40, 15 ) );
117
118 TextLabel3_2 = new QLabel( this, "TextLabel3_2" );
119 TextLabel3_2->setGeometry( QRect( 60, 55, 50, 20 ) );
120 TextLabel3_2->setText( tr( "read" ) );
121 TextLabel3_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
122
123 TextLabel3_2_2 = new QLabel( this, "TextLabel3_2_2" );
124 TextLabel3_2_2->setGeometry( QRect( 120, 55, 50, 20 ) );
125 TextLabel3_2_2->setText( tr( "write" ) );
126 TextLabel3_2_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
127
128 TextLabel3 = new QLabel( this, "TextLabel3" );
129 TextLabel3->setGeometry( QRect( 180, 55, 50, 20 ) );
130 TextLabel3->setText( tr( "execute" ) );
131 TextLabel3->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
132
133 struct stat buf;
134 mode_t mode;
135 file = fileName;
136 QFileInfo fi(file);
137
138 LineEdit1->setText( file);
139 OwnerLineEdit->setText( fi.owner());
140 GroupLineEdit->setText( fi.group());
141
142 if( fi.permission( QFileInfo::ReadUser)) { CheckBox1->setChecked(true); }
143 if( fi.permission( QFileInfo::WriteUser)) { CheckBox1_2->setChecked(true); }
144 if( fi.permission( QFileInfo::ExeUser)) { CheckBox1_3->setChecked(true); }
145
146 if( fi.permission( QFileInfo::ReadGroup)) { CheckBox1_4->setChecked(true); }
147 if( fi.permission( QFileInfo::WriteGroup)) { CheckBox1_5->setChecked(true); }
148 if( fi.permission( QFileInfo::ExeGroup)) { CheckBox1_6->setChecked(true); }
149
150 if( fi.permission( QFileInfo::ReadOther)) { CheckBox1_7->setChecked(true); }
151 if( fi.permission( QFileInfo::WriteOther)) { CheckBox1_8->setChecked(true); }
152 if( fi.permission( QFileInfo::ExeOther)) { CheckBox1_8_2->setChecked(true); }
153
154 stat(file.latin1(), &buf);
155 mode = buf.st_mode;
156 modeStr.sprintf("%#o", buf.st_mode & ~(S_IFMT) );
157 ModeLine->setText(modeStr);
158 bool ok;
159 i_mode = modeStr.toInt(&ok,10);
160
161}
162
163/*
164 * Destroys the object and frees any allocated resources
165 */
166filePermissions::~filePermissions()
167{
168}
169
170
171// might this be better as a callback routine???
172void filePermissions::ownReadCheck() {
173 if(CheckBox1->isChecked()) { i_mode +=400; }
174 else i_mode -=400;
175 modeStr.sprintf("0%d",i_mode);
176 ModeLine->setText( modeStr);
177// 0400
178}
179
180void filePermissions::ownWriteCheck() {
181 if(CheckBox1_2->isChecked()) { i_mode +=200; }
182 else i_mode -=200;
183 modeStr.sprintf("0%d",i_mode);
184 ModeLine->setText(modeStr);
185// 0200
186}
187
188void filePermissions::ownExeCheck() {
189 if(CheckBox1_3->isChecked()) { i_mode +=100; }
190 else i_mode -=100;
191 modeStr.sprintf("0%d",i_mode);
192 ModeLine->setText(modeStr);
193// 0100
194}
195
196void filePermissions::grpReadCheck() {
197 if(CheckBox1_4->isChecked()) { i_mode +=40; }
198 else i_mode -=40;
199 modeStr.sprintf("0%d",i_mode);
200 ModeLine->setText(modeStr);
201// 0040
202}
203
204void filePermissions::grpWriteCheck() {
205 if(CheckBox1_5->isChecked()) { i_mode +=20; }
206 else i_mode -=20;
207 modeStr.sprintf("0%d",i_mode);
208 ModeLine->setText(modeStr);
209// 0020
210}
211
212void filePermissions::grpExeCheck() {
213 if(CheckBox1_6->isChecked()) { i_mode +=10; }
214 else i_mode -=10;
215 modeStr.sprintf("0%d",i_mode);
216 ModeLine->setText(modeStr);
217// 0010
218}
219
220void filePermissions::wrldReadCheck() {
221 if(CheckBox1_7->isChecked()) { i_mode +=4; }
222 else i_mode -=4;
223 modeStr.sprintf("0%d",i_mode);
224 ModeLine->setText(modeStr);
225// 0004
226}
227
228void filePermissions::wrldWriteCheck() {
229 if(CheckBox1_8->isChecked()) { i_mode +=2; }
230 else i_mode -=2;
231 modeStr.sprintf("0%d",i_mode);
232 ModeLine->setText(modeStr);
233// 0002
234}
235
236void filePermissions::wrldExeCheck() {
237 if(CheckBox1_8_2->isChecked()) { i_mode +=1; }
238 else i_mode -=1;
239 modeStr.sprintf("0%d",i_mode);
240 ModeLine->setText(modeStr);
241// 0001
242}
243
244void filePermissions::accept() {
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,tr("Warning"),tr("Error- no user"));
252 return;
253 } else {
254 grp = getgrnam(GroupLineEdit->text().latin1());
255 if(grp==NULL) {
256 perror("getgrnam");
257 QMessageBox::warning(this,tr("Warning"),tr("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,tr("Warning"),tr("Error setting ownership or group"));
263 return;
264 }
265 bool ok;
266 moder = modeStr.toUInt(&ok,8);
267 if (!isRemote) {
268 if( chmod( file.latin1(), moder) < 0) {
269 perror("chmod");
270 QMessageBox::warning(this,tr("Warning"),tr("Error setting mode"));
271 return;
272 }
273 }
274}
275 close();
276}
diff --git a/noncore/net/opieftp/filePermissions.h b/noncore/net/opieftp/filePermissions.h
new file mode 100644
index 0000000..b8f3776
--- a/dev/null
+++ b/noncore/net/opieftp/filePermissions.h
@@ -0,0 +1,58 @@
1/****************************************************************************
2** copyright 2002 ljp ljp@llornkcor.com
3** Created: Sat Feb 23 19:44:17 2002
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#ifndef FILEPERMISSIONS_H
15#define FILEPERMISSIONS_H
16
17#include <qvariant.h>
18#include <qdialog.h>
19class QVBoxLayout;
20class QHBoxLayout;
21class QGridLayout;
22class QCheckBox;
23class QLabel;
24class QLineEdit;
25class QString;
26
27class filePermissions : public QDialog
28{
29 Q_OBJECT
30
31public:
32 filePermissions( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 , const QString & fileName ="", bool useRemote = FALSE);
33 ~filePermissions();
34
35 QLineEdit *LineEdit1, *ModeLine;
36 QLabel *TextLabel1, *TextLabel4, *TextLabel4_2, *TextLabel4_3, *TextLabel3_2_2, *TextLabel3_2, *TextLabel3, *TextLabel5_2, *TextLabel5;
37 QCheckBox*CheckBox1, *CheckBox1_3, *CheckBox1_2, *CheckBox1_4, *CheckBox1_5, *CheckBox1_6, *CheckBox1_7, *CheckBox1_8, *CheckBox1_8_2;
38 QLineEdit*GroupLineEdit, *OwnerLineEdit;
39 QString modeStr, file;
40 int i_mode;
41 uint moder;
42 bool isRemote;
43private slots:
44 void ownReadCheck();
45 void ownWriteCheck();
46 void ownExeCheck();
47
48 void grpReadCheck();
49 void grpWriteCheck();
50 void grpExeCheck();
51
52 void wrldReadCheck();
53 void wrldWriteCheck();
54 void wrldExeCheck();
55 void accept();
56};
57
58#endif // FILEPERMISSIONS_H
diff --git a/noncore/net/opieftp/opieftp.pro b/noncore/net/opieftp/opieftp.pro
index 7aead00..f25d15f 100644
--- a/noncore/net/opieftp/opieftp.pro
+++ b/noncore/net/opieftp/opieftp.pro
@@ -1,12 +1,12 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3HEADERS = opieftp.h inputDialog.h ftplib.h filePermissions.h 3HEADERS = opieftp.h inputDialog.h ftplib.h
4SOURCES = opieftp.cpp inputDialog.cpp ftplib.c filePermissions.cpp main.cpp 4SOURCES = opieftp.cpp inputDialog.cpp ftplib.c main.cpp
5TARGET = opieftp 5TARGET = opieftp
6REQUIRES=medium-config 6REQUIRES=medium-config
7DESTDIR = $(OPIEDIR)/bin 7DESTDIR = $(OPIEDIR)/bin
8INCLUDEPATH += $(OPIEDIR)/include 8INCLUDEPATH += $(OPIEDIR)/include
9DEPENDPATH += $(OPIEDIR)/include 9DEPENDPATH += $(OPIEDIR)/include
10LIBS += -lqpe 10LIBS += -lqpe
11 11
12TRANSLATIONS = ../../i18n/pt_BR/opieftp.ts 12TRANSLATIONS = ../../i18n/pt_BR/opieftp.ts