-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 10 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 100 |
2 files changed, 47 insertions, 63 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 @@ -172,100 +172,106 @@ static const char *commonCmds[] = "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) 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 @@ -805,196 +805,176 @@ bool TextEdit::save() { 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); - } else + 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*/); - 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); - QPEApplication::execDialog( filePerm ); - - if( filePerm) - delete filePerm; - } -// } + + DocLnk nf; + nf.setType("text/plain"); + nf.setFile( fileNm); + doc = new DocLnk(nf); + odebug << "Saving file as "+currentFileName << oendl; + 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); + QPEApplication::execDialog( 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; @@ -1152,62 +1132,60 @@ void TextEdit::timerCrank() } 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; - } + 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); } } |