summaryrefslogtreecommitdiff
authorerik <erik>2007-01-26 20:22:50 (UTC)
committer erik <erik>2007-01-26 20:22:50 (UTC)
commit53d630c9c4813142ee13e6843c30476a5db26e78 (patch) (side-by-side diff)
tree50a77a94cfeaccbb3d993bced8b7d0f498f74c7c
parent152a8fe978851aea8dac6ae5cb11f73540746b83 (diff)
downloadopie-53d630c9c4813142ee13e6843c30476a5db26e78.zip
opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.gz
opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.bz2
Each file in this commit exhibit an example of what prevent calls
'reverse inull'. All that means is that a pointer gets dereferenced. Then a pointer gets checked for validity before being dereferenced again. This almost always points to shenanigans. For example, the konsole.cpp file has this konsoleInit() call which passes in a const char** shell variable. Since it is a double pointer the programmer who wrote the code made the mistake of mixing the checking of the pointer and the pointer that points to the pointer. This commit attempts to correct that. Of course there are other instances of the same thing. But they all boil down to a small mistake which might have produced strange side effects.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp10
-rw-r--r--core/apps/textedit/textedit.cpp56
-rw-r--r--noncore/applets/notesapplet/notes.cpp2
-rw-r--r--noncore/apps/advancedfm/advancedfm.cpp2
4 files changed, 27 insertions, 43 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index f4ca0bf..5c40569 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -124,196 +124,202 @@ public:
void addTab(QWidget* w)
{
QTab* t = new QTab(QString::number(tabBar()->count()+1));
QTabWidget::addTab(w,t);
}
void removeTab(QWidget* w)
{
removePage(w);
((EKNumTabBar*)tabBar())->numberTabs();
}
};
// This could be configurable or dynamicly generated from the bash history
// file of the user
static const char *commonCmds[] =
{
"ls ", // I left this here, cause it looks better than the first alpha
"cardctl eject",
"cat ",
"cd ",
"chmod ",
"clear",
"cp ",
"dc ",
"df ",
"dmesg",
"echo ",
"env",
"find ",
"free",
"grep ",
"ifconfig ",
"ipkg ",
"mkdir ",
"mv ",
"nc localhost 7776",
"nc localhost 7777",
"netstat ",
"nslookup ",
"ping ",
"ps aux",
"pwd ",
// "qcop QPE/System 'linkChanged(QString)' ''",
// "qcop QPE/System 'restart()'",
// "qcop QPE/System 'quit()'",
"rm ",
"rmdir ",
"route ",
"set ",
"traceroute",
/*
"gzip",
"gunzip",
"chgrp",
"chown",
"date",
"dd",
"df",
"dmesg",
"fuser",
"hostname",
"kill",
"killall",
"ln",
"ping",
"mount",
"more",
"sort",
"touch",
"umount",
"mknod",
"netstat",
*/
"exit",
NULL
};
static void konsoleInit(const char** shell) {
if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl;
if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges
// QPEApplication::grabKeyboard(); // for CTRL and ALT
odebug << "keyboard grabbed" << oendl;
#ifdef FAKE_CTRL_AND_ALT
odebug << "Fake Ctrl and Alt defined" << oendl;
QPEApplication::grabKeyboard(); // for CTRL and ALT
#endif
+ if (!shell) {
+ owarn << "No double pointer 'shell'" << oendl;
+ return;
+ }
+
*shell = getenv("SHELL");
- owarn << "SHell initially is " << *shell << "" << oendl;
+ if (*shell)
+ owarn << "Current shell: " << *shell << "" << oendl;
- if (shell == NULL || *shell == '\0') {
+ if (*shell == NULL || **shell == '\0') {
struct passwd *ent = 0;
uid_t me = getuid();
*shell = "/bin/sh";
while ( (ent = getpwent()) != 0 ) {
if (ent->pw_uid == me) {
if (ent->pw_shell != "")
*shell = ent->pw_shell;
break;
}
}
endpwent();
}
if( putenv((char*)"COLORTERM=") !=0)
odebug << "putenv failed" << oendl; // to trigger mc's color detection
}
Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
QMainWindow(parent, name, fl)
{
QStrList tmp; const char* shell;
konsoleInit( &shell);
init(shell,tmp);
}
Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
: QMainWindow(0, name)
{
init(_pgm,_args);
}
struct HistoryItem
{
HistoryItem(int c, const QString &l)
{
count = c;
line = l;
}
int count;
QString line;
};
class HistoryList : public QList<HistoryItem>
{
virtual int compareItems( QCollection::Item item1, QCollection::Item item2)
{
int c1 = ((HistoryItem*)item1)->count;
int c2 = ((HistoryItem*)item2)->count;
if (c1 > c2)
return(1);
if (c1 < c2)
return(-1);
return(0);
}
};
void Konsole::initCommandList()
{
// odebug << "Konsole::initCommandList" << oendl;
Config cfg( "Konsole" );
cfg.setGroup("Commands");
// commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
commonCombo->clear();
if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") {
QString histfilename = QString(getenv("HOME")) + "/.bash_history";
histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
QFile histfile(histfilename);
// note: compiler barfed on:
// QFile histfile(QString(getenv("HOME")) + "/.bash_history");
if (histfile.open( IO_ReadOnly )) {
QString line;
uint i;
HistoryList items;
int lineno = 0;
while(!histfile.atEnd()) {
if (histfile.readLine(line, 200) < 0) {
break;
}
line = line.left(line.length()-1);
lineno++;
for(i=0; i<items.count(); i++) {
if (line == items.at(i)->line) {
// weight recent commands & repeated commands more
// by adding up the index of each command
items.at(i)->count += lineno;
break;
}
}
if (i >= items.count()) {
items.append(new HistoryItem(lineno, line));
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 61beac5..4bbc62b 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -757,292 +757,272 @@ void TextEdit::openFile( const DocLnk &f ) {
if ( doc )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited( false);
edited1=false;
edited=false;
doc->setName(currentFileName);
updateCaption();
setTimer();
}
void TextEdit::showEditTools() {
menu->show();
editBar->show();
if(!useSearchBar)
searchBar->hide();
else
searchBar->show();
setWState (WState_Reserved1 );
}
/*!
unprompted save */
bool TextEdit::save() {
QString name, file;
odebug << "saveAsFile " + currentFileName << oendl;
if(currentFileName.isEmpty()) {
saveAs();
return false;
}
name = currentFileName;
if(doc) {
file = doc->file();
odebug << "saver file "+file << oendl;
name = doc->name();
odebug << "File named "+name << oendl;
} else {
file = currentFileName;
name = QFileInfo(currentFileName).baseName();
}
QString rt = editor->text();
if( !rt.isEmpty() ) {
if(name.isEmpty()) {
saveAs();
} else {
currentFileName = name;
odebug << "saveFile "+currentFileName << oendl;
struct stat buf;
mode_t mode;
stat(file.latin1(), &buf);
mode = buf.st_mode;
if(!fileIs) {
doc->setName( name);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
} else {
odebug << "regular save file" << oendl;
QFile f(file);
if( f.open(IO_WriteOnly)) {
QCString crt = rt.utf8();
f.writeBlock(crt,crt.length());
} else {
QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
return false;
}
}
editor->setEdited( false);
edited1=false;
edited=false;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
chmod( file.latin1(), mode);
}
return true;
}
return false;
}
/*!
prompted save */
bool TextEdit::saveAs() {
if(caption() == tr("Text Editor"))
return false;
odebug << "saveAsFile " + currentFileName << oendl;
- // case of nothing to save...
-// if ( !doc && !currentFileName.isEmpty()) {
-// //|| !bFromDocView)
-// odebug << "no doc" << oendl;
-// return true;
-// }
-// if ( !editor->edited() ) {
-// delete doc;
-// doc = 0;
-// return true;
-// }
QString rt = editor->text();
odebug << currentFileName << oendl;
if( currentFileName.isEmpty()
|| currentFileName == tr("Unnamed")
- || currentFileName == tr("Text Editor")) {
+ || currentFileName == tr("Text Editor"))
+ {
odebug << "do silly TT filename thing" << oendl;
-// if ( doc && 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
+ if ( i > 0 ) docname = pt.left( i );
+
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 = tr("Unnamed");
+ // Cut the length. Filenames longer than 40 are not helpful
+ // and something goes wrong when they get too long.
+ if ( docname.length() > 40 ) docname = docname.left(40);
+
+ if ( docname.isEmpty() ) docname = tr("Unnamed");
+
if(doc) doc->setName(docname);
+
currentFileName=docname;
-// }
-// else
-// odebug << "hmmmmmm" << oendl;
}
QMap<QString, QStringList> map;
map.insert(tr("All"), QStringList() );
QStringList text;
text << "text/*";
map.insert(tr("Text"), text );
text << "*";
map.insert(tr("All"), text );
QFileInfo cuFi( currentFileName);
QString filee = cuFi.fileName();
QString dire = cuFi.dirPath();
if(dire==".")
dire = QPEApplication::documentDir();
+
QString str;
if( !featureAutoSave) {
- str = OFileDialog::getSaveFileName( 2,
- dire,
- filee, map);
+ str = OFileDialog::getSaveFileName( 2, dire, filee, map);
} else
str = currentFileName;
if(!str.isEmpty()) {
QString fileNm=str;
odebug << "saving filename "+fileNm << oendl;
QFileInfo fi(fileNm);
currentFileName=fi.fileName();
if(doc)
-// QString file = doc->file();
-// doc->removeFiles();
delete doc;
+
DocLnk nf;
nf.setType("text/plain");
nf.setFile( fileNm);
doc = new DocLnk(nf);
-// editor->setText(rt);
odebug << "Saving file as "+currentFileName << oendl;
- doc->setName( fi.baseName() /*currentFileName*/);
+ doc->setName( fi.baseName() );
updateCaption( currentFileName);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
if( filePerms ) {
filePermissions *filePerm;
- filePerm = new filePermissions(this,
- tr("Permissions"),true,
- 0,(const QString &)fileNm);
+ filePerm = new filePermissions(this, tr("Permissions"),true, 0,
+ (const QString &)fileNm);
QPEApplication::execDialog( filePerm );
- if( filePerm)
delete filePerm;
}
-// }
editor->setEdited( false);
edited1 = false;
edited = false;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
return true;
}
odebug << "returning false" << oendl;
currentFileName = "";
return false;
} //end saveAs
void TextEdit::clear() {
delete doc;
doc = 0;
editor->clear();
}
void TextEdit::updateCaption( const QString &name ) {
if ( name.isEmpty() )
setCaption( tr("Text Editor") );
else {
QString s = name;
if ( s.isNull() )
s = doc->name();
if ( s.isEmpty() ) {
s = tr( "Unnamed" );
currentFileName=s;
}
// if(s.left(1) == "/")
// s = s.right(s.length()-1);
setCaption( tr("%1 - Text Editor").arg( s ) );
}
}
void TextEdit::setDocument(const QString& fileref) {
if(fileref != "Unnamed") {
currentFileName=fileref;
odebug << "setDocument" << oendl;
QFileInfo fi(currentFileName);
odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
if( (fi.baseName().left(1)).isEmpty() ) {
openDotFile(currentFileName);
} else {
odebug << "setDoc open" << oendl;
bFromDocView = true;
openFile(fileref);
editor->setEdited(true);
edited1=false;
edited=true;
// fromSetDocument=false;
// doSearchBar();
}
}
updateCaption( currentFileName);
}
void TextEdit::changeFont() {
QDialog *d = new QDialog ( this, "FontDialog", true );
d-> setCaption ( tr( "Choose font" ));
QBoxLayout *lay = new QVBoxLayout ( d );
OFontSelector *ofs = new OFontSelector ( true, d );
lay-> addWidget ( ofs );
ofs-> setSelectedFont ( editor-> font ( ));
if ( QPEApplication::execDialog( d ) == QDialog::Accepted )
editor-> setFont ( ofs-> selectedFont ( ));
delete d;
}
void TextEdit::editDelete() {
switch ( QMessageBox::warning(this,tr("Text Editor"),
tr("Do you really want<BR>to <B>delete</B> "
"the current file\nfrom the disk?<BR>This is "
"<B>irreversable!</B>"),
tr("Yes"),tr("No"),0,0,1) ) {
case 0:
if(doc) {
doc->removeFiles();
clear();
setCaption( tr("Text Editor") );
}
break;
case 1:
// exit
break;
};
}
void TextEdit::changeStartConfig( bool b ) {
startWithNew=b;
Config cfg("TextEdit");
@@ -1104,110 +1084,108 @@ void TextEdit::editPasteTimeDate() {
cb->setText( dt.toString());
editor->paste();
#endif
}
int TextEdit::savePrompt()
{
switch( QMessageBox::information( 0, (tr("Textedit")),
(tr("Textedit detected\n"
"you have unsaved changes\n"
"Go ahead and save?\n")),
(tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
{
case 0:
{
return 1;
}
break;
case 1:
{
return 2;
}
break;
case 2:
{
return -1;
}
break;
};
return 0;
}
void TextEdit::timerCrank()
{
if(featureAutoSave && edited1)
{
if(currentFileName.isEmpty())
{
currentFileName = QDir::homeDirPath()+"/textedit.tmp";
saveAs();
}
else
{
// odebug << "autosave" << oendl;
save();
}
setTimer();
}
}
void TextEdit::doTimer(bool b)
{
Config cfg("TextEdit");
cfg.setGroup ( "View" );
cfg.writeEntry ( "autosave", b);
featureAutoSave = b;
nAutoSave->setOn(b);
if(b)
{
// odebug << "doTimer true" << oendl;
setTimer();
}
// else
// odebug << "doTimer false" << oendl;
}
void TextEdit::setTimer()
{
if(featureAutoSave)
{
// odebug << "setting autosave" << oendl;
QTimer *timer = new QTimer(this );
connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
timer->start( 300000, true); //5 minutes
}
}
void TextEdit::gotoLine() {
if( editor->length() < 1)
return;
QWidget *d = QApplication::desktop();
gotoEdit = new QLineEdit( 0, "Goto line");
gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2));
gotoEdit->setFrame(true);
gotoEdit->show();
connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto()));
}
void TextEdit::doGoto() {
QString number = gotoEdit->text();
gotoEdit->hide();
- if(gotoEdit) {
delete gotoEdit;
gotoEdit = 0;
- }
bool ok;
int lineNumber = number.toInt(&ok, 10);
if( editor->numLines() < lineNumber)
QMessageBox::message(tr("Text Edit"),tr("Not enough lines"));
else
{
editor->setCursorPosition(lineNumber, 0, false);
}
}
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 13f297e..61a47d7 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -142,193 +142,193 @@ void NotesControl::slotDeleteButton() {
Config cfg("Notes");
cfg.setGroup("Docs");
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
QString entryName, entryName2;;
for ( int i = 0; i < noOfFiles; i++ ) {
entryName.sprintf( "File%i", i + 1 );
if(selectedText == cfg.readEntry( entryName )) {
odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl;
for ( int j = i; j < noOfFiles; j++ ) {
entryName.sprintf( "File%i", i + 1 );
entryName2.sprintf( "File%i", i + 2 );
QString temp = cfg.readEntry(entryName2);
odebug << "move "+temp << oendl;
cfg.writeEntry(entryName, temp);
i++;
}
cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
entryName.sprintf( "File%i", noOfFiles );
cfg.removeEntry(entryName);
cfg.write();
DocLnk nf(selectedText);
nf.removeFiles();
QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
odebug << fi << oendl;
QFile f( fi);
if( !f.remove()) odebug << ".desktop file not removed" << oendl;
}
}
view->clear();
populateBox();
}
}
void NotesControl::slotNewButton() {
if(edited) save();
view->clear();
view->setFocus();
edited=false;
isNew=false;
}
void NotesControl::slotBeamButton() {
Ir ir;
if(!ir.supported()){
} else {
this->hide();
QString selectedText = box->currentText();
if( !selectedText.isEmpty()) {
QString file = QDir::homeDirPath()+"/"+selectedText;
QFile f(file);
Ir *irFile = new Ir(this, "IR");
connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*)));
irFile->send( file, "Note", "text/plain" );
}
}
}
void NotesControl::slotBeamFinished(Ir *) {
this->show();
}
void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
switch (mouse) {
case 1:{
}
break;
case 2:
menuTimer.start( 500, TRUE );
break;
};
}
void NotesControl::slotBoxSelected(const QString &itemString) {
if(edited) {
save();
}
loaded=false;
edited=false;
load(itemString);
}
void NotesControl::showMenu() {
QPopupMenu *m = new QPopupMenu(0);
m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
m->insertSeparator();
m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
m->setFocus();
m->exec( QCursor::pos() );
- if(m) delete m;
+ delete m;
}
void NotesControl::focusOutEvent ( QFocusEvent * e) {
if( e->reason() == QFocusEvent::Popup)
save();
else {
if(!loaded) {
populateBox();
load();
}
}
QWidget::focusOutEvent(e);
}
void NotesControl::save() {
Config cfg("Notes");
cfg.setGroup("Docs");
if( edited) {
// odebug << "is edited" << oendl;
QString rt = view->text();
if( rt.length()>1) {
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ', pt.find( ' ' )+2 );
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 = "Empty Text";
// odebug << docname << oendl;
if( oldDocName != docname) {
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
QString entryName;
entryName.sprintf( "File%i", noOfFiles + 1 );
cfg.writeEntry( entryName,docname );
cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
cfg.write();
}
// else
// odebug << "oldname equals docname" << oendl;
doc = new DocLnk(docname);
if(QFile(doc->linkFile()).exists())
odebug << "puppie" << oendl;
doc->setType("text/plain");
doc->setName(docname);
QString temp = docname.replace( QRegExp(" "), "_" );
doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
}
oldDocName=docname;
edited=false;
// odebug << "save" << oendl;
if (doPopulate)
populateBox();
}
cfg.writeEntry( "LastDoc",oldDocName );
cfg.write();
}
}
void NotesControl::populateBox() {
box->clear();
// odebug << "populate" << oendl;
Config cfg("Notes");
cfg.setGroup("Docs");
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
QStringList list;
QString entryName;
for ( int i = 0; i < noOfFiles; i++ ) {
entryName.sprintf( "File%i", i + 1 );
list.append(cfg.readEntry( entryName ));
}
list.sort();
box->insertStringList(list,-1);
doPopulate=false;
update();
}
void NotesControl::load() {
if(!loaded) {
Config cfg("Notes");
cfg.setGroup("Docs");
QString lastDoc=cfg.readEntry( "LastDoc","notes");
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp
index 828f5a1..cf19ba8 100644
--- a/noncore/apps/advancedfm/advancedfm.cpp
+++ b/noncore/apps/advancedfm/advancedfm.cpp
@@ -403,193 +403,193 @@ QString AdvancedFm::getFileSystemType(const QString &currentText) {
parsetab("/etc/mtab"); //why did TT forget filesystem type?
QString current = currentText;//.right( currentText.length()-1);
QString baseFs;
for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
QString temp = (*it);
QString path = temp.left(temp.find("::",0,TRUE) );
path = path.right( path.length()-1);
if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) {
return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
}
}
return baseFs;
}
QString AdvancedFm::getDiskSpace( const QString &path) {
struct statfs fss;
if ( !statfs( path.latin1(), &fss ) ) {
int blkSize = fss.f_bsize;
// int totalBlks = fs.f_blocks;
int availBlks = fss.f_bavail;
long mult = blkSize / 1024;
long div = 1024 / blkSize;
if ( !mult ) mult = 1;
if ( !div ) div = 1;
return QString::number(availBlks * mult / div);
}
return "";
}
void AdvancedFm::showFileMenu() {
QString curApp;
curApp = CurrentView()->currentItem()->text(0);
MimeType mt(curApp);
const AppLnk* app = mt.application();
QFile fi(curApp);
QPopupMenu *m = new QPopupMenu(0);
QPopupMenu *n = new QPopupMenu(0);
// QPopupMenu *o = new QPopupMenu(0);
m->insertItem(tr("Show Hidden Files"),this,SLOT(showHidden()));
if ( QFileInfo(fi).isDir()) {
m->insertSeparator();
m->insertItem(tr("Change Directory"),this,SLOT(doDirChange()));
} else {
if (app)
m->insertItem(app->pixmap(),tr("Open in " + app->name()),this,SLOT(runThis()));
else if(QFileInfo(fi).isExecutable() ) //damn opie doesnt like this
m->insertItem(tr("Execute"),this,SLOT(runThis()));
m->insertItem( Opie::Core::OResource::loadPixmap( "txt", Opie::Core::OResource::SmallIcon ),
tr("Open as text"),this,SLOT(runText()));
}
m->insertItem(tr("Actions"),n);
n->insertItem(tr("Make Directory"),this,SLOT(makeDir()));
n->insertItem(tr("Make Symlink"),this,SLOT(mkSym()));
n->insertSeparator();
n->insertItem(tr("Rename"),this,SLOT(renameIt()));
n->insertItem(tr("Copy"),this,SLOT(copyTimer()));
n->insertItem(tr("Copy As"),this,SLOT(copyAsTimer()));
n->insertItem(tr("Copy Same Dir"),this,SLOT(copySameDirTimer()));
n->insertItem(tr("Move"),this,SLOT(moveTimer()));
n->insertSeparator();
n->insertItem(tr("Delete"),this,SLOT(doDelete()));
m->insertItem(tr("Add To Documents"),this,SLOT(addToDocs()));
m->insertItem(tr("Run Command"),this,SLOT(runCommand()));
m->insertItem(tr("File Info"),this,SLOT(fileStatus()));
m->insertSeparator();
m->insertItem(tr("Set Permissions"),this,SLOT(filePerms()));
#if defined(QT_QWS_OPIE)
m->insertItem(tr("Properties"),this,SLOT(doProperties()));
#endif
m->setCheckable(TRUE);
if (!b)
m->setItemChecked(m->idAt(0),TRUE);
else
m->setItemChecked(m->idAt(0),FALSE);
if(Ir::supported())
m->insertItem(tr("Beam File"),this,SLOT(doBeam()));
m->setFocus();
m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y()));
- if(m) delete m;
+ delete m;
}
QString AdvancedFm::checkDiskSpace(const QString &path) {
struct statfs fss;
if ( !statfs( path.latin1(), &fss ) ) {
int blkSize = fss.f_bsize;
// int totalBlks = fs.f_blocks;
int availBlks = fss.f_bavail;
long mult = blkSize / 1024;
long div = 1024 / blkSize;
if ( !mult ) mult = 1;
if ( !div ) div = 1;
return QString::number(availBlks * mult / div);
}
return "";
}
void AdvancedFm::addToDocs() {
QStringList strListPaths = getPath();
QDir *thisDir = CurrentDir();
if( strListPaths.count() > 0) {
QString curFile;
for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) {
curFile = thisDir->canonicalPath()+"/"+(*it);
// odebug << curFile << oendl;
QFileInfo fi(curFile);
DocLnk f;
// curFile.replace(QRegExp("\\..*"),"");
f.setName(fi.baseName() );
f.setFile( curFile);
f.writeLink();
}
}
}
void AdvancedFm::customDirsToMenu() {
Config cfg("AdvancedFm");
cfg.setGroup("Menu");
QStringList list = cfg.readListEntry( "CustomDir", ',');
menuButton->insertItems(list );
// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
// {
// customDirMenu->insertItem(*it );
// }
}
void AdvancedFm::dirMenuSelected(int item) {
switch(item)
{
case -21:
case 0:
addCustomDir();
break;
case -22:
case 1:
removeCustomDir();
break;
default:
{
// gotoCustomDir( menuButton->text(item));
// gotoCustomDir( customDirMenu->text(item));
}
break;
};
}
void AdvancedFm::addCustomDir() {
Config cfg("AdvancedFm");
cfg.setGroup("Menu");
QString dir;
QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
dir = CurrentDir()->canonicalPath();
bool addIt=true;
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
if( dir == (*it)) {
addIt=false;
}
}
if(addIt) {
menuButton->insertItem(dir);
// customDirMenu->insertItem(dir);
list << dir;
}