summaryrefslogtreecommitdiff
path: root/noncore/unsupported
authorllornkcor <llornkcor>2002-02-24 15:27:06 (UTC)
committer llornkcor <llornkcor>2002-02-24 15:27:06 (UTC)
commita43106c752dae2404f33a07dc80851c4a745d2bc (patch) (unidiff)
tree1bddeba58034bc08c6a24d656098d9104df99ee6 /noncore/unsupported
parent7dd14b051a5c1bad0fd0c76c00d06b0d51e1f17f (diff)
downloadopie-a43106c752dae2404f33a07dc80851c4a745d2bc.zip
opie-a43106c752dae2404f33a07dc80851c4a745d2bc.tar.gz
opie-a43106c752dae2404f33a07dc80851c4a745d2bc.tar.bz2
added permissions dialog
Diffstat (limited to 'noncore/unsupported') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/Makefile.in2
-rw-r--r--noncore/unsupported/filebrowser/filePermissions.cpp274
-rw-r--r--noncore/unsupported/filebrowser/filePermissions.h56
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp32
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.h2
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.pro7
6 files changed, 366 insertions, 7 deletions
diff --git a/noncore/unsupported/filebrowser/Makefile.in b/noncore/unsupported/filebrowser/Makefile.in
index c00d0f5..d1f80b7 100644
--- a/noncore/unsupported/filebrowser/Makefile.in
+++ b/noncore/unsupported/filebrowser/Makefile.in
@@ -121,2 +121,4 @@ main.o: main.cpp \
121 $(OPIEDIR)/include/qpe/qpeapplication.h \ 121 $(OPIEDIR)/include/qpe/qpeapplication.h \
122 $(OPIEDIR)/include/qpedecoration_qws.h \
123 $(OPIEDIR)/include/timestring.h \
122 $(OPIEDIR)/include/qpe/mimetype.h 124 $(OPIEDIR)/include/qpe/mimetype.h
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
34filePermissions::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 */
165filePermissions::~filePermissions()
166{
167}
168
169
170// might this be better as a callback routine???
171void 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
179void 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
187void 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
195void 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
203void 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
211void 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
219void 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
227void 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
235void 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
243void 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}
diff --git a/noncore/unsupported/filebrowser/filePermissions.h b/noncore/unsupported/filebrowser/filePermissions.h
new file mode 100644
index 0000000..880304f
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/filePermissions.h
@@ -0,0 +1,56 @@
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 ="");
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;
41private slots:
42 void ownReadCheck();
43 void ownWriteCheck();
44 void ownExeCheck();
45
46 void grpReadCheck();
47 void grpWriteCheck();
48 void grpExeCheck();
49
50 void wrldReadCheck();
51 void wrldWriteCheck();
52 void wrldExeCheck();
53 void accept();
54};
55
56#endif // FILEPERMISSIONS_H
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
index 9439bb8..384d7da 100644
--- a/noncore/unsupported/filebrowser/filebrowser.cpp
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -22,3 +22,3 @@
22#include "filebrowser.h" 22#include "filebrowser.h"
23 23#include "filePermissions.h"
24#include <qpe/resource.h> 24#include <qpe/resource.h>
@@ -656,2 +656,3 @@ void FileView::showFileMenu()
656 tr( "Paste" ), this, SLOT( paste() ) ); 656 tr( "Paste" ), this, SLOT( paste() ) );
657 m->insertItem( tr( "change permissions" ), this, SLOT( chPerm() ) );
657 m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); 658 m->insertItem( tr( "Delete" ), this, SLOT( del() ) );
@@ -850 +851,30 @@ void FileBrowser::updateSorting()
850} 851}
852
853void FileView::chPerm() {
854 FileItem * i;
855 QStringList fl;
856 QString cmd;
857 int err;
858
859 if((i = (FileItem *) firstChild()) == 0) return;
860
861 while( i ){
862 if( i->isSelected() ){
863 fl += i->getFilePath();
864 }
865 i = (FileItem *) i->nextSibling();
866 }
867 if( fl.count() < 1 ) return;
868 if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"),
869 tr("Yes"), tr("No") ) == 0) {
870 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
871 filePermissions *filePerm;
872 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it));
873 filePerm->exec();
874 if( filePerm)
875 delete filePerm;
876 break;
877 }
878 updateDir();
879 }
880}
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h
index 2e9e444..c214dbe 100644
--- a/noncore/unsupported/filebrowser/filebrowser.h
+++ b/noncore/unsupported/filebrowser/filebrowser.h
@@ -73,3 +73,3 @@ public slots:
73 void viewAsText(); 73 void viewAsText();
74 74 void chPerm();
75protected: 75protected:
diff --git a/noncore/unsupported/filebrowser/filebrowser.pro b/noncore/unsupported/filebrowser/filebrowser.pro
index 5d8f140..65e51a5 100644
--- a/noncore/unsupported/filebrowser/filebrowser.pro
+++ b/noncore/unsupported/filebrowser/filebrowser.pro
@@ -3,7 +3,4 @@ CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = inlineedit.h \ 4 HEADERS = inlineedit.h filebrowser.h filePermissions.h
5 filebrowser.h 5 SOURCES = filebrowser.cpp inlineedit.cpp filePermissions.cpp main.cpp
6 SOURCES = filebrowser.cpp \
7 inlineedit.cpp \
8 main.cpp
9INCLUDEPATH += $(OPIEDIR)/include 6INCLUDEPATH += $(OPIEDIR)/include