summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/filePermissions.cpp274
-rw-r--r--core/apps/textedit/filePermissions.h56
-rw-r--r--core/apps/textedit/fileSaver.cpp8
-rw-r--r--core/apps/textedit/fileSaver.h2
-rw-r--r--core/apps/textedit/opie-textedit.control2
-rw-r--r--core/apps/textedit/textedit.cpp75
-rw-r--r--core/apps/textedit/textedit.pro4
7 files changed, 387 insertions, 34 deletions
diff --git a/core/apps/textedit/filePermissions.cpp b/core/apps/textedit/filePermissions.cpp
new file mode 100644
index 0000000..1938b84
--- a/dev/null
+++ b/core/apps/textedit/filePermissions.cpp
@@ -0,0 +1,274 @@
+/****************************************************************************
+** copyright 2002 ljp ljp@llornkcor.com
+** Created: Sat Feb 23 19:44:40 2002 L.J. Potter
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+#include "filePermissions.h"
+
+#include <qfile.h>
+#include <qfileinfo.h>
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qlayout.h>
+#include <qvariant.h>
+#include <qtooltip.h>
+#include <qmessagebox.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+
+filePermissions::filePermissions( QWidget* parent, const char* name, bool modal, WFlags fl, const QString &fileName )
+ : QDialog( parent, name, modal, fl )
+{
+ if ( !name )
+ setName( "filePermissions" );
+ qDebug("FilePermissions "+fileName);
+ resize( 236, 210 );
+ setMaximumSize( QSize( 236, 210 ) );
+ setCaption( tr( "Set File Permissions" ) );
+
+ TextLabel1 = new QLabel( this, "TextLabel1" );
+ TextLabel1->setGeometry( QRect( 25, 5, 175, 20 ) );
+ TextLabel1->setText( tr( "Set file permissions for:" ) );
+
+ LineEdit1 = new QLineEdit( this, "LineEdit1" );
+ LineEdit1->setGeometry( QRect( 10, 25, 218, 22 ) );
+ LineEdit1->setReadOnly(true);
+
+ TextLabel4 = new QLabel( this, "TextLabel4" );
+ TextLabel4->setGeometry( QRect( 5, 85, 50, 15 ) );
+ TextLabel4->setText( tr( "owner" ) );
+
+ TextLabel4_2 = new QLabel( this, "TextLabel4_2" );
+ TextLabel4_2->setGeometry( QRect( 5, 105, 50, 15 ) );
+ TextLabel4_2->setText( tr( "group" ) );
+
+ TextLabel4_3 = new QLabel( this, "TextLabel4_3" );
+ TextLabel4_3->setGeometry( QRect( 5, 125, 50, 15 ) );
+ TextLabel4_3->setText( tr( "others" ) );
+
+ CheckBox1 = new QCheckBox( this, "CheckBox1" );
+ CheckBox1->setGeometry( QRect( 75, 85, 20, 16 ) );
+ connect(CheckBox1, SIGNAL(released()),this,SLOT(ownReadCheck()));
+
+ CheckBox1_2 = new QCheckBox( this, "CheckBox1_2" );
+ CheckBox1_2->setGeometry( QRect( 135, 85, 20, 16 ) );
+ connect(CheckBox1_2, SIGNAL(released()),this,SLOT(ownWriteCheck()));
+
+ CheckBox1_3 = new QCheckBox( this, "CheckBox1_3" );
+ CheckBox1_3->setGeometry( QRect( 195, 85, 20, 16 ) );
+ connect(CheckBox1_3, SIGNAL(released()),this,SLOT(ownExeCheck()));
+
+ CheckBox1_4 = new QCheckBox( this, "CheckBox1_4" );
+ CheckBox1_4->setGeometry( QRect( 75, 105, 20, 16 ) );
+ connect(CheckBox1_4, SIGNAL(released()),this,SLOT(grpReadCheck()));
+
+ CheckBox1_5 = new QCheckBox( this, "CheckBox1_5" );
+ CheckBox1_5->setGeometry( QRect( 135, 105, 20, 16 ) );
+ connect(CheckBox1_5, SIGNAL(released()),this,SLOT(grpWriteCheck()));
+
+ CheckBox1_6 = new QCheckBox( this, "CheckBox1_6" );
+ CheckBox1_6->setGeometry( QRect( 195, 105, 20, 16 ) );
+ connect(CheckBox1_6, SIGNAL(released()),this,SLOT(grpExeCheck()));
+
+ CheckBox1_7 = new QCheckBox( this, "CheckBox1_7" );
+ CheckBox1_7->setGeometry( QRect( 75, 125, 16, 16 ) );
+ connect(CheckBox1_7, SIGNAL(released()),this,SLOT(wrldReadCheck()));
+
+ CheckBox1_8 = new QCheckBox( this, "CheckBox1_8" );
+ CheckBox1_8->setGeometry( QRect( 135, 125, 20, 16 ) );
+ connect(CheckBox1_8, SIGNAL(released()),this,SLOT(wrldWriteCheck()));
+
+ CheckBox1_8_2 = new QCheckBox( this, "CheckBox1_8_2" );
+ CheckBox1_8_2->setGeometry( QRect( 195, 125, 20, 16 ) );
+ connect(CheckBox1_8_2, SIGNAL(released()),this,SLOT(wrldExeCheck()));
+
+ GroupLineEdit = new QLineEdit( this, "GroupLineEdit" );
+ GroupLineEdit->setGeometry( QRect( 125, 155, 106, 22 ) );
+
+ OwnerLineEdit = new QLineEdit( this, "OwnerLineEdit" );
+ OwnerLineEdit->setGeometry( QRect( 10, 155, 106, 22 ) );
+
+ TextLabel5 = new QLabel( this, "TextLabel5" );
+ TextLabel5->setGeometry( QRect( 45, 180, 40, 16 ) );
+ TextLabel5->setText( tr( "Owner" ) );
+
+ TextLabel5_2 = new QLabel( this, "TextLabel5_2" );
+ TextLabel5_2->setGeometry( QRect( 155, 180, 40, 16 ) );
+ TextLabel5_2->setText( tr( "Group" ) );
+
+ ModeLine = new QLineEdit( this, "TextLabelMode" );
+ ModeLine->setGeometry( QRect( 10, 60, 40, 15 ) );
+
+ TextLabel3_2 = new QLabel( this, "TextLabel3_2" );
+ TextLabel3_2->setGeometry( QRect( 60, 55, 50, 20 ) );
+ TextLabel3_2->setText( tr( "read" ) );
+ TextLabel3_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
+
+ TextLabel3_2_2 = new QLabel( this, "TextLabel3_2_2" );
+ TextLabel3_2_2->setGeometry( QRect( 120, 55, 50, 20 ) );
+ TextLabel3_2_2->setText( tr( "write" ) );
+ TextLabel3_2_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
+
+ TextLabel3 = new QLabel( this, "TextLabel3" );
+ TextLabel3->setGeometry( QRect( 180, 55, 50, 20 ) );
+ TextLabel3->setText( tr( "execute" ) );
+ TextLabel3->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) );
+
+ struct stat buf;
+ mode_t mode;
+ file = fileName;
+ QFileInfo fi(file);
+
+ LineEdit1->setText( file);
+ OwnerLineEdit->setText( fi.owner());
+ GroupLineEdit->setText( fi.group());
+
+ if( fi.permission( QFileInfo::ReadUser)) { CheckBox1->setChecked(true); }
+ if( fi.permission( QFileInfo::WriteUser)) { CheckBox1_2->setChecked(true); }
+ if( fi.permission( QFileInfo::ExeUser)) { CheckBox1_3->setChecked(true); }
+
+ if( fi.permission( QFileInfo::ReadGroup)) { CheckBox1_4->setChecked(true); }
+ if( fi.permission( QFileInfo::WriteGroup)) { CheckBox1_5->setChecked(true); }
+ if( fi.permission( QFileInfo::ExeGroup)) { CheckBox1_6->setChecked(true); }
+
+ if( fi.permission( QFileInfo::ReadOther)) { CheckBox1_7->setChecked(true); }
+ if( fi.permission( QFileInfo::WriteOther)) { CheckBox1_8->setChecked(true); }
+ if( fi.permission( QFileInfo::ExeOther)) { CheckBox1_8_2->setChecked(true); }
+
+ lstat(file.latin1(), &buf);
+ mode = buf.st_mode;
+ modeStr.sprintf("%#o", buf.st_mode & ~(S_IFMT) );
+ ModeLine->setText(modeStr);
+ bool ok;
+ i_mode = modeStr.toInt(&ok,10);
+
+}
+
+/*
+ * Destroys the object and frees any allocated resources
+ */
+filePermissions::~filePermissions()
+{
+}
+
+
+// might this be better as a callback routine???
+void filePermissions::ownReadCheck() {
+ if(CheckBox1->isChecked()) { i_mode +=400; }
+ else i_mode -=400;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText( modeStr);
+// 0400
+}
+
+void filePermissions::ownWriteCheck() {
+ if(CheckBox1_2->isChecked()) { i_mode +=200; }
+ else i_mode -=200;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0200
+}
+
+void filePermissions::ownExeCheck() {
+ if(CheckBox1_3->isChecked()) { i_mode +=100; }
+ else i_mode -=100;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0100
+}
+
+void filePermissions::grpReadCheck() {
+ if(CheckBox1_4->isChecked()) { i_mode +=40; }
+ else i_mode -=40;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0040
+}
+
+void filePermissions::grpWriteCheck() {
+ if(CheckBox1_5->isChecked()) { i_mode +=20; }
+ else i_mode -=20;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0020
+}
+
+void filePermissions::grpExeCheck() {
+ if(CheckBox1_6->isChecked()) { i_mode +=10; }
+ else i_mode -=10;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0010
+}
+
+void filePermissions::wrldReadCheck() {
+ if(CheckBox1_7->isChecked()) { i_mode +=4; }
+ else i_mode -=4;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0004
+}
+
+void filePermissions::wrldWriteCheck() {
+ if(CheckBox1_8->isChecked()) { i_mode +=2; }
+ else i_mode -=2;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0002
+}
+
+void filePermissions::wrldExeCheck() {
+ if(CheckBox1_8_2->isChecked()) { i_mode +=1; }
+ else i_mode -=1;
+ modeStr.sprintf("0%d",i_mode);
+ ModeLine->setText(modeStr);
+// 0001
+}
+
+void filePermissions::accept() {
+
+ QFileInfo fi(file);
+ struct passwd *pwd=0;
+ struct group *grp=0;
+ pwd = getpwnam(OwnerLineEdit->text().latin1() );
+ if(pwd == NULL) {
+ perror("getpwnam");
+ QMessageBox::warning(this,"Warning","Error- no user");
+ return;
+ } else {
+ grp = getgrnam(GroupLineEdit->text().latin1());
+ if(grp==NULL) {
+ perror("getgrnam");
+ QMessageBox::warning(this,"Warning","Error- no group");
+ return;
+ }
+ if( chown( file.latin1(), pwd->pw_uid, grp->gr_gid) <0) {
+ perror("chown");
+ QMessageBox::warning(this,"Warning","Error setting ownership or group");
+ return;
+ }
+ bool ok;
+ uint moder = modeStr.toUInt(&ok,8);
+ if( chmod( file.latin1(), moder) < 0) {
+ perror("chmod");
+ QMessageBox::warning(this,"Warning","Error setting mode");
+ return;
+ }
+ }
+ close();
+}
diff --git a/core/apps/textedit/filePermissions.h b/core/apps/textedit/filePermissions.h
new file mode 100644
index 0000000..880304f
--- a/dev/null
+++ b/core/apps/textedit/filePermissions.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+** copyright 2002 ljp ljp@llornkcor.com
+** Created: Sat Feb 23 19:44:17 2002
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+#ifndef FILEPERMISSIONS_H
+#define FILEPERMISSIONS_H
+
+#include <qvariant.h>
+#include <qdialog.h>
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class QCheckBox;
+class QLabel;
+class QLineEdit;
+class QString;
+
+class filePermissions : public QDialog
+{
+ Q_OBJECT
+
+public:
+ filePermissions( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 , const QString & fileName ="");
+ ~filePermissions();
+
+ QLineEdit *LineEdit1, *ModeLine;
+ QLabel *TextLabel1, *TextLabel4, *TextLabel4_2, *TextLabel4_3, *TextLabel3_2_2, *TextLabel3_2, *TextLabel3, *TextLabel5_2, *TextLabel5;
+ QCheckBox*CheckBox1, *CheckBox1_3, *CheckBox1_2, *CheckBox1_4, *CheckBox1_5, *CheckBox1_6, *CheckBox1_7, *CheckBox1_8, *CheckBox1_8_2;
+ QLineEdit*GroupLineEdit, *OwnerLineEdit;
+ QString modeStr, file;
+ int i_mode;
+private slots:
+ void ownReadCheck();
+ void ownWriteCheck();
+ void ownExeCheck();
+
+ void grpReadCheck();
+ void grpWriteCheck();
+ void grpExeCheck();
+
+ void wrldReadCheck();
+ void wrldWriteCheck();
+ void wrldExeCheck();
+ void accept();
+};
+
+#endif // FILEPERMISSIONS_H
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp
index b813ed3..9e9e863 100644
--- a/core/apps/textedit/fileSaver.cpp
+++ b/core/apps/textedit/fileSaver.cpp
@@ -16,3 +16,2 @@
#include <qpe/qpeapplication.h>
-
#include <qlistview.h>
@@ -21,4 +20,6 @@
#include <qmessagebox.h>
-#include <unistd.h>
#include <qlineedit.h>
+#include <qcheckbox.h>
+
+#include <unistd.h>
@@ -58,2 +59,5 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl
+ filePermCheck = new QCheckBox( this, "SetFilePerms" );
+ filePermCheck->setText("set file permissions");
+ filePermCheck->setGeometry(10, 220, 150,22);
// signals and slots connections
diff --git a/core/apps/textedit/fileSaver.h b/core/apps/textedit/fileSaver.h
index 4a38a65..ce4493e 100644
--- a/core/apps/textedit/fileSaver.h
+++ b/core/apps/textedit/fileSaver.h
@@ -33,2 +33,3 @@ class QPushButton;
class QLineEdit;
+class QCheckBox;
@@ -52,2 +53,3 @@ public:
QStringList fileList;
+ QCheckBox *filePermCheck;
diff --git a/core/apps/textedit/opie-textedit.control b/core/apps/textedit/opie-textedit.control
index 4990466..55fc644 100644
--- a/core/apps/textedit/opie-textedit.control
+++ b/core/apps/textedit/opie-textedit.control
@@ -8,2 +8,2 @@ Depends: opie-base ($QPE_VERSION)
Description: Text Editor
- The text editor for the Opie environment.
+ The (slightly enchanced) text editor for the Opie environment.
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index c869dc9..515fcdc 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -24,2 +24,3 @@
#include "fileSaver.h"
+#include "filePermissions.h"
@@ -49,2 +50,5 @@
#include <qwidgetstack.h>
+#include <qcheckbox.h>
+#include <unistd.h>
+#include <sys/stat.h>
@@ -417,3 +421,3 @@ TextEdit::~TextEdit()
{
-// saveAs();
+// save();
@@ -696,2 +700,3 @@ bool TextEdit::save()
QString name= doc->name();
+
QString rt = editor->text();
@@ -700,2 +705,7 @@ bool TextEdit::save()
+ struct stat buf;
+ mode_t mode;
+ lstat(file.latin1(), &buf);
+ mode = buf.st_mode;
+
doc->setName( name);
@@ -705,6 +715,5 @@ bool TextEdit::save()
}
-// if(doc)
-// delete doc;
-// doc = 0;
editor->setEdited( false );
+
+ chmod( file.latin1(), mode);
return true;
@@ -716,3 +725,3 @@ bool TextEdit::saveAs()
{
- qDebug("saveAsFile "+currentFileName);
+// qDebug("saveAsFile "+currentFileName);
@@ -755,2 +764,3 @@ bool TextEdit::saveAs()
+
fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName);
@@ -759,31 +769,37 @@ bool TextEdit::saveAs()
if( fileSaveDlg->result() == 1 ) {
- QString fileNm=fileSaveDlg->selectedFileName;
- qDebug("saving filename "+fileNm);
- QFileInfo fi(fileNm);
- currentFileName=fi.fileName();
- if(doc) {
- qDebug("doclnk exists");
+ QString fileNm=fileSaveDlg->selectedFileName;
+ qDebug("saving filename "+fileNm);
+ QFileInfo fi(fileNm);
+ currentFileName=fi.fileName();
+ if(doc) {
+ qDebug("doclnk exists");
// QString file = doc->file();
// doc->removeFiles();
- delete doc;
- DocLnk nf;
- nf.setType("text/plain");
- nf.setFile( fileNm);
- doc = new DocLnk(nf);
+ delete doc;
+ DocLnk nf;
+ nf.setType("text/plain");
+ nf.setFile( fileNm);
+ doc = new DocLnk(nf);
// editor->setText(rt);
- qDebug("openFile doclnk "+currentFileName);
- }
- doc->setName( currentFileName);
- updateCaption( currentFileName);
-
- FileManager fm;
- if ( !fm.saveFile( *doc, rt ) ) {
- return false;
- }
-// delete doc;
-// doc = 0;
- editor->setEdited( false );
+ qDebug("openFile doclnk "+currentFileName);
+ doc->setName( currentFileName);
+ updateCaption( currentFileName);
+
+ FileManager fm;
+ if ( !fm.saveFile( *doc, rt ) ) {
+ return false;
+ }
+ if( fileSaveDlg->filePermCheck->isChecked() ) {
+ filePermissions *filePerm;
+ filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm);
+ filePerm->exec();
+ editor->setEdited( false );
+ if( filePerm)
+ delete filePerm;
+ }
+ }
}
+
if(fileSaveDlg)
- delete fileSaveDlg;
+ delete fileSaveDlg;
return true;
@@ -837,2 +853,3 @@ void TextEdit::accept()
{
+ save();
close();
diff --git a/core/apps/textedit/textedit.pro b/core/apps/textedit/textedit.pro
index 9b1a841..2c25d43 100644
--- a/core/apps/textedit/textedit.pro
+++ b/core/apps/textedit/textedit.pro
@@ -5,5 +5,5 @@ DESTDIR = $(OPIEDIR)/bin
-HEADERS = textedit.h fileBrowser.h fontDialog.h fileSaver.h
+HEADERS = textedit.h fileBrowser.h fontDialog.h fileSaver.h filePermissions.h
-SOURCES = main.cpp textedit.cpp fileBrowser.cpp fontDialog.cpp fileSaver.cpp
+SOURCES = main.cpp textedit.cpp fileBrowser.cpp fontDialog.cpp fileSaver.cpp filePermissions.cpp