summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-24 07:39:56 (UTC)
committer llornkcor <llornkcor>2002-02-24 07:39:56 (UTC)
commitf7be370d10a69cfe78b04687fe728b32d566083a (patch) (side-by-side diff)
tree6e586d6543cfd3a60e9734b515642bd86fc052cd
parentf1c800025cf759ca0d6257a42f548216d217b16b (diff)
downloadopie-f7be370d10a69cfe78b04687fe728b32d566083a.zip
opie-f7be370d10a69cfe78b04687fe728b32d566083a.tar.gz
opie-f7be370d10a69cfe78b04687fe728b32d566083a.tar.bz2
added file permissions dialog
Diffstat (more/less context) (show 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.cpp33
-rw-r--r--core/apps/textedit/textedit.pro4
7 files changed, 366 insertions, 13 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
@@ -1,154 +1,158 @@
/****************************************************************************
** copyright 2001 ljp ljp@llornkcor.com
** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp
**
** 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 "fileSaver.h"
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
-
#include <qlistview.h>
#include <qpushbutton.h>
#include <qfile.h>
#include <qmessagebox.h>
-#include <unistd.h>
#include <qlineedit.h>
+#include <qcheckbox.h>
+
+#include <unistd.h>
fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "fileSaver" );
resize( 236, 280 );
setCaption(tr( "Save file" ) );
QFileInfo fi(currentFileName);
QString tmpFileName=fi.fileName();
// qDebug( tmpFileName);
dirLabel = new QLabel(this, "DirLabel");
dirLabel->setText(currentDir.canonicalPath());
dirLabel->setGeometry(10,4,230,30);
ListView = new QListView( this, "ListView" );
ListView->addColumn( tr( "Name" ) );
ListView->setColumnWidth(0,140);
ListView->setSorting( 2, FALSE);
ListView->addColumn( tr( "Size" ) );
ListView->setColumnWidth(1,59);
ListView->setColumnWidthMode(0,QListView::Manual);
ListView->setColumnAlignment(1,QListView::AlignRight);
// ListView->setMultiSelection(true);
// ListView->setSelectionMode(QListView::Extended);
ListView->setAllColumnsShowFocus( TRUE );
ListView->setGeometry( QRect( 10, 35, 220, 160 ) );
fileEdit= new QLineEdit(this);
fileEdit->setGeometry( QRect( 10, 200, 200, 22));
fileEdit->setText( tmpFileName);
+ filePermCheck = new QCheckBox( this, "SetFilePerms" );
+ filePermCheck->setText("set file permissions");
+ filePermCheck->setGeometry(10, 220, 150,22);
// signals and slots connections
connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
// tmpFileName=fi.FilePath();
// qDebug( tmpFileName);
currentDir.setPath( QDir::currentDirPath() );
populateList();
}
fileSaver::~fileSaver()
{
}
void fileSaver::populateList()
{
ListView->clear();
currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
currentDir.setMatchAllDirs(TRUE);
currentDir.setNameFilter("*");
QString fileL, fileS;
const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/);
QFileInfoListIterator it(*list);
QFileInfo *fi;
while ( (fi=it.current()) ) {
if (fi->isSymLink() ){
QString symLink=fi->readLink();
// qDebug("Symlink detected "+symLink);
QFileInfo sym( symLink);
fileS.sprintf( "%10li", sym.size() );
fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
} else {
// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
fileS.sprintf( "%10li", fi->size() );
fileL.sprintf( "%s",fi->fileName().data() );
if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
fileL+="/";
// qDebug(currentDir.canonicalPath()+fileL);
}
}
item= new QListViewItem( ListView,fileL,fileS );
++it;
}
ListView->setSorting( 2, FALSE);
dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath());
}
void fileSaver::upDir()
{
// qDebug(currentDir.canonicalPath());
}
void fileSaver::listDoubleClicked(QListViewItem *selectedItem)
{
}
void fileSaver::listClicked(QListViewItem *selectedItem)
{
QString strItem=selectedItem->text(0);
QString strSize=selectedItem->text(1);
// qDebug("strItem is "+strItem);
strSize.stripWhiteSpace();
// qDebug(strSize);
if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
// qDebug("strItem symlink is "+strItem2);
if(QDir(strItem2).exists() ) {
currentDir.cd(strItem2, TRUE);
populateList();
}
} else { // not a symlink
if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
currentDir.cd(strItem,FALSE);
// qDebug("Path is "+strItem);
populateList();
} else {
currentDir.cdUp();
populateList();
}
if(QDir(strItem).exists()){
currentDir.cd(strItem, TRUE);
populateList();
}
} // else
// if( QFile::exists(strItem ) ) {
// qDebug("We found our files!!");
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
@@ -1,72 +1,74 @@
/****************************************************************************
**
** Created: Fri Dec 14 08:16:02 2001 fileSaver.h
**
copyright Sun 02-17-2002 22:28:48 L. J. Potter ljp@llornkcor.com
** 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 FILESAVER_H
#define FILESAVER_H
//#include <qvariant.h>
#include <qdialog.h>
#include <qfile.h>
#include <qdir.h>
#include <qstringlist.h>
#include <qlabel.h>
#include <qstring.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QListView;
class QListViewItem;
class QPushButton;
class QLineEdit;
+class QCheckBox;
class fileSaver : public QDialog
{
Q_OBJECT
public:
void populateList();
fileSaver( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0);
~fileSaver();
QLineEdit *fileEdit;
QPushButton* buttonOk;
QListView* ListView;
QPushButton* buttonCancel;
QLabel *dirLabel;
QString selectedFileName, filterStr;
QDir currentDir;
QFile file;
QStringList fileList;
+ QCheckBox *filePermCheck;
QListViewItem * item;
public slots:
private:
private slots:
void accept();
void upDir();
void listDoubleClicked(QListViewItem *);
void listClicked(QListViewItem *);
void closeEvent( QCloseEvent * );
protected slots:
protected:
};
#endif // FILESAVER_H
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
@@ -1,9 +1,9 @@
Files: bin/textedit apps/Applications/textedit.desktop
Priority: optional
Section: opie/applications
Maintainer: Warwick Allison <warwick@trolltech.com>
Architecture: arm
Version: $QPE_VERSION-$SUB_VERSION
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
@@ -1,145 +1,149 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** 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.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// changes added by L. J. Potter Sun 02-17-2002 21:31:31
#include "textedit.h"
#include "fileBrowser.h"
#include "fileSaver.h"
+#include "filePermissions.h"
#include "fontDialog.h"
#include <qpe/fontdatabase.h>
#include <qpe/global.h>
#include <qpe/fileselector.h>
#include <qpe/applnk.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
//#include <qpe/finddialog.h>
#include <qstringlist.h>
#include <qaction.h>
#include <qcolordialog.h>
#include <qfileinfo.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qobjectlist.h>
#include <qpopupmenu.h>
#include <qspinbox.h>
#include <qtoolbutton.h>
#include <qwidgetstack.h>
+#include <qcheckbox.h>
+#include <unistd.h>
+#include <sys/stat.h>
#include <stdlib.h> //getenv
/* XPM */
static char * filesave_xpm[] = {
"16 16 78 1",
" c None",
". c #343434",
"+ c #A0A0A0",
"@ c #565656",
"# c #9E9E9E",
"$ c #525252",
"% c #929292",
"& c #676767",
"* c #848484",
"= c #666666",
"- c #D8D8D8",
"; c #FFFFFF",
"> c #DBDBDB",
", c #636363",
"' c #989898",
") c #2D2D2D",
"! c #909090",
"~ c #AEAEAE",
"{ c #EAEAEA",
"] c #575757",
"^ c #585858",
"/ c #8A8A8A",
"( c #828282",
"_ c #6F6F6F",
": c #C9C9C9",
"< c #050505",
"[ c #292929",
"} c #777777",
"| c #616161",
"1 c #3A3A3A",
"2 c #BEBEBE",
"3 c #2C2C2C",
"4 c #7C7C7C",
"5 c #F6F6F6",
"6 c #FCFCFC",
"7 c #6B6B6B",
"8 c #959595",
"9 c #4F4F4F",
"0 c #808080",
"a c #767676",
"b c #818181",
"c c #B8B8B8",
"d c #FBFBFB",
"e c #F9F9F9",
"f c #CCCCCC",
"g c #030303",
"h c #737373",
"i c #7A7A7A",
"j c #7E7E7E",
"k c #6A6A6A",
"l c #FAFAFA",
"m c #505050",
"n c #9D9D9D",
"o c #333333",
"p c #7B7B7B",
"q c #787878",
"r c #696969",
"s c #494949",
"t c #555555",
"u c #949494",
"v c #E6E6E6",
"w c #424242",
"x c #515151",
"y c #535353",
"z c #3E3E3E",
"A c #D4D4D4",
"B c #0C0C0C",
"C c #353535",
"D c #474747",
"E c #ECECEC",
"F c #919191",
"G c #7D7D7D",
"H c #000000",
"I c #404040",
"J c #858585",
"K c #323232",
"L c #D0D0D0",
"M c #1C1C1C",
" ...+ ",
" @#$%&..+ ",
" .*=-;;>,..+ ",
" ')!~;;;;;;{]..",
" ^/(-;;;;;;;_:<",
" [}|;;;;;;;{12$",
" #34-55;;;;678$+",
" 90ab=c;dd;e1fg ",
" [ahij((kbl0mn$ ",
" op^q^^7r&]s/$+ ",
"@btu;vbwxy]zAB ",
"CzDEvEv;;DssF$ ",
"G.H{E{E{IxsJ$+ ",
@@ -322,193 +326,193 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
#if 0
QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
ba->setToggleAction(TRUE);
ba->addTo( font );
QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
ia->setToggleAction(TRUE);
ia->addTo( font );
ba->setOn(defb);
ia->setOn(defi);
font->insertSeparator();
#endif
QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
wa->setToggleAction(TRUE);
wa->addTo( font );
font->insertSeparator();
font->insertItem("Font", this, SLOT(changeFont()) );
mb->insertItem( tr( "File" ), file );
mb->insertItem( tr( "Edit" ), edit );
mb->insertItem( tr( "View" ), font );
searchBar = new QPEToolBar(this);
addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
searchBar->setHorizontalStretchable( TRUE );
searchEdit = new QLineEdit( searchBar, "searchEdit" );
searchBar->setStretchableWidget( searchEdit );
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( search() ) );
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
a->addTo( searchBar );
a->addTo( edit );
a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
a->addTo( searchBar );
edit->insertSeparator();
a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
a->addTo( edit );
searchBar->hide();
editorStack = new QWidgetStack( this );
setCentralWidget( editorStack );
searchVisible = FALSE;
fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
// fileOpen();
editor = new QpeEditor( editorStack );
editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
editorStack->addWidget( editor, get_unique_id() );
resize( 200, 300 );
// setFontSize(defsize,TRUE);
FontDatabase fdb;
QFont defaultFont=editor->font();
QFontInfo fontInfo(defaultFont);
cfg.setGroup("Font");
QString family = cfg.readEntry("Family", fontInfo.family());
QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
defaultFont = fdb.font(family,style,i_size,charSet);
editor->setFont( defaultFont);
wa->setOn(wrap);
updateCaption();
fileNew();
}
TextEdit::~TextEdit()
{
-// saveAs();
+// save();
Config cfg("TextEdit");
cfg.setGroup("View");
QFont f = editor->font();
cfg.writeEntry("FontSize",f.pointSize());
cfg.writeEntry("Bold",f.bold());
cfg.writeEntry("Italic",f.italic());
cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
}
void TextEdit::zoomIn()
{
setFontSize(editor->font().pointSize()+1,FALSE);
}
void TextEdit::zoomOut()
{
setFontSize(editor->font().pointSize()-1,TRUE);
}
void TextEdit::setFontSize(int sz, bool round_down_not_up)
{
int s=10;
for (int i=0; i<nfontsizes; i++) {
if ( fontsize[i] == sz ) {
s = sz;
break;
} else if ( round_down_not_up ) {
if ( fontsize[i] < sz )
s = fontsize[i];
} else {
if ( fontsize[i] > sz ) {
s = fontsize[i];
break;
}
}
}
QFont f = editor->font();
f.setPointSize(s);
editor->setFont(f);
zin->setEnabled(s != fontsize[nfontsizes-1]);
zout->setEnabled(s != fontsize[0]);
}
void TextEdit::setBold(bool y)
{
QFont f = editor->font();
f.setBold(y);
editor->setFont(f);
}
void TextEdit::setItalic(bool y)
{
QFont f = editor->font();
f.setItalic(y);
editor->setFont(f);
}
void TextEdit::setWordWrap(bool y)
{
bool state = editor->edited();
editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
editor->setEdited( state );
}
void TextEdit::fileNew()
{
if( !bFromDocView ) {
saveAs();
}
newFile(DocLnk());
}
void TextEdit::fileOpen()
{
// if ( !save() ) {
// if ( QMessageBox::critical( this, tr( "Out of space" ),
// tr( "Text Editor was unable to\n"
// "save your changes.\n"
// "Free some space and try again.\n"
// "\nContinue anyway?" ),
// QMessageBox::Yes|QMessageBox::Escape,
// QMessageBox::No|QMessageBox::Default )
// != QMessageBox::Yes )
// return;
// else {
// delete doc;
// doc = 0;
// }
// }
menu->hide();
editBar->hide();
searchBar->hide();
@@ -601,279 +605,292 @@ void TextEdit::findNext()
editor->find( searchEdit->text(), FALSE, FALSE );
}
void TextEdit::findClose()
{
searchVisible = FALSE;
searchBar->hide();
}
void TextEdit::search()
{
editor->find( searchEdit->text(), FALSE, FALSE );
}
void TextEdit::newFile( const DocLnk &f )
{
DocLnk nf = f;
nf.setType("text/plain");
clear();
editorStack->raiseWidget( editor );
setWState (WState_Reserved1 );
editor->setFocus();
doc = new DocLnk(nf);
qDebug("newFile "+currentFileName);
updateCaption(currentFileName);
}
void TextEdit::openFile( const QString &f )
{
bFromDocView = TRUE;
DocLnk nf;
nf.setType("text/plain");
nf.setFile(f);
currentFileName=f;
QFileInfo fi( currentFileName);
nf.setName(fi.baseName());
qDebug("openFile string"+currentFileName);
openFile(nf);
showEditTools();
// Show filename in caption
QString name = f;
int sep = name.findRev( '/' );
if ( sep > 0 )
name = name.mid( sep+1 );
updateCaption( name );
}
void TextEdit::openFile( const DocLnk &f )
{
// clear();
bFromDocView = TRUE;
FileManager fm;
QString txt;
currentFileName=f.name();
qDebug("openFile doclnk " + currentFileName);
if ( !fm.loadFile( f, txt ) ) {
// ####### could be a new file
qDebug( "Cannot open file" );
//return;
}
fileNew();
if ( doc )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited( false);
qDebug("openFile doclnk "+currentFileName);
doc->setName(currentFileName);
updateCaption();
}
void TextEdit::showEditTools()
{
// if ( !doc )
// close();
// clear();
fileSelector->hide();
menu->show();
editBar->show();
if ( searchVisible )
searchBar->show();
// updateCaption();
editorStack->raiseWidget( editor );
setWState (WState_Reserved1 );
}
/*!
unprompted save */
bool TextEdit::save()
{
QString file = doc->file();
QString name= doc->name();
+
QString rt = editor->text();
currentFileName= name ;
qDebug("saveFile "+currentFileName);
+ struct stat buf;
+ mode_t mode;
+ lstat(file.latin1(), &buf);
+ mode = buf.st_mode;
+
doc->setName( name);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
return false;
}
-// if(doc)
-// delete doc;
-// doc = 0;
editor->setEdited( false );
+
+ chmod( file.latin1(), mode);
return true;
}
/*!
prompted save */
bool TextEdit::saveAs()
{
- qDebug("saveAsFile "+currentFileName);
+// qDebug("saveAsFile "+currentFileName);
// case of nothing to save... /// there's always something to save
// if ( !doc )//|| !bFromDocView)
// {
// qDebug("no doc");
// return true;
// }
if ( !editor->edited() ) {
delete doc;
doc = 0;
return true;
}
QString rt = editor->text();
qDebug(currentFileName);
if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
qDebug("do silly TT filename thing");
if ( doc->name().isEmpty() ) {
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ' );
QString docname = pt;
if ( i > 0 )
docname = pt.left( i );
// remove "." at the beginning
while( docname.startsWith( "." ) )
docname = docname.mid( 1 );
docname.replace( QRegExp("/"), "_" );
// cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
if ( docname.length() > 40 )
docname = docname.left(40);
if ( docname.isEmpty() )
docname = "Unnamed";
doc->setName(docname);
currentFileName=docname;
}
}
+
fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName);
qDebug("wanna save filename "+currentFileName);
fileSaveDlg->exec();
if( fileSaveDlg->result() == 1 ) {
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);
// 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;
+ 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;
return true;
}
void TextEdit::clear()
{
delete doc;
doc = 0;
editor->clear();
}
void TextEdit::updateCaption( const QString &name )
{
if ( !doc )
setCaption( tr("Text Editor") );
else {
QString s = name;
if ( s.isNull() )
s = doc->name();
if ( s.isEmpty() ) {
s = tr( "Unnamed" );
currentFileName=s;
}
setCaption( s + " - " + tr("Text Editor") );
}
}
void TextEdit::setDocument(const QString& fileref)
{
bFromDocView = TRUE;
openFile(DocLnk(fileref));
// showEditTools();
}
void TextEdit::closeEvent( QCloseEvent *e )
{
if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
e->ignore();
repaint();
// fileRevert();
} else {
bFromDocView = FALSE;
e->accept();
}
}
void TextEdit::accept()
{
+ save();
close();
// fileOpen(); //godamn thats obnoxious! lemme out!!!
}
void TextEdit::changeFont() {
FontDatabase fdb;
QFont defaultFont=editor->font();
QFontInfo fontInfo(defaultFont);
Config cfg("TextEdit");
cfg.setGroup("Font");
QString family = cfg.readEntry("Family", fontInfo.family());
QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
defaultFont = fdb.font(family,style,i_size,charSet);
FontDialog *fontDlg;
fontDlg=new FontDialog(this,"FontDialog",TRUE);
fontDlg->exec();
QFont myFont=fontDlg->selectedFont;
editor->setFont( myFont);
delete fontDlg;
}
void TextEdit::editDelete()
{
switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) {
case 0:
if(doc) {
doc->removeFiles();
clear();
}
break;
case 1:
// exit
break;
};
}
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
@@ -1,16 +1,16 @@
TEMPLATE = app
CONFIG += qt warn_on release
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
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe
TARGET = textedit
TRANSLATIONS = ../i18n/de/textedit.ts