Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 127 |
1 files changed, 125 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index e931f01..1e8ce7f 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -50,4 +50,6 @@ #include <qlayout.h> #include <qapplication.h> +#include <qtimer.h> +#include <qdir.h> #include <unistd.h> #include <sys/stat.h> @@ -411,4 +413,11 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) searchBarAction->addTo( advancedMenu); + nAutoSave = new QAction( tr("Auto Save 5 min."), + QString::null, 0, this, 0 ); + connect( nAutoSave, SIGNAL( toggled(bool) ), + this, SLOT( doTimer(bool) ) ); + nAutoSave->setToggleAction(true); + nAutoSave->addTo( advancedMenu); + font->insertSeparator(); @@ -479,4 +488,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); startWithNew = cfg.readBoolEntry ( "startNew", true); + featureAutoSave = cfg.readBoolEntry( "autosave", false); if(useSearchBar) searchBarAction->setOn(true); @@ -485,4 +495,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) if(filePerms) filePermAction->setOn( true ); if(startWithNew) nStart->setOn( true ); + if(featureAutoSave) nAutoSave->setOn(true); + +// { +// doTimer(true); +// } bool wrap = cfg. readBoolEntry ( "Wrap", true ); @@ -490,4 +505,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) setWordWrap ( wrap ); +///////////////// if( qApp->argc() > 1) { currentFileName=qApp->argv()[1]; @@ -515,7 +531,28 @@ TextEdit::~TextEdit() { void TextEdit::closeEvent(QCloseEvent *) { if( edited1 && promptExit) + { + switch( savePrompt() ) + { + case 1: + { saveAs(); qApp->quit(); } + break; + + case 2: + { + qApp->quit(); + } + break; + + case -1: + break; + }; + } + else + qApp->quit(); + +} void TextEdit::cleanUp() { @@ -815,4 +852,5 @@ void TextEdit::openFile( const DocLnk &f ) { doc->setName(currentFileName); updateCaption(); + setTimer(); } @@ -835,4 +873,5 @@ bool TextEdit::save() { return false; } + QString file = doc->file(); qDebug("saver file "+file); @@ -887,4 +926,5 @@ bool TextEdit::save() { prompted save */ bool TextEdit::saveAs() { + if(caption() == tr("Text Editor")) return false; @@ -946,8 +986,13 @@ bool TextEdit::saveAs() { if(dire==".") dire = QPEApplication::documentDir(); - QString str = OFileDialog::getSaveFileName( 2, + QString str; + if( !featureAutoSave) + { + str = OFileDialog::getSaveFileName( 2, dire, filee, map); - + } + else + str=currentFileName; if(!str.isEmpty()) { QString fileNm=str; @@ -1141,2 +1186,80 @@ void TextEdit::editPasteTimeDate() { #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) + { + if( edited1 ) + { + if(currentFileName.isEmpty()) + { + currentFileName = QDir::homeDirPath()+"/textedit.tmp"; + saveAs(); + } + else + { + qDebug("autosave"); + save(); + } + setTimer(); + } + } +} + +void TextEdit::doTimer(bool b) +{ + Config cfg("TextEdit"); + cfg.setGroup ( "View" ); + cfg.writeEntry ( "autosave", b); + featureAutoSave = b; + nAutoSave->setOn(b); + if(b) + { + qDebug("doTimer true"); + setTimer(); + } + else + qDebug("doTimer false"); +} + +void TextEdit::setTimer() +{ +if(featureAutoSave) + { + qDebug("setting autosave"); + QTimer *timer = new QTimer(this ); + connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); + timer->start( 30000/*0*/, true); //5 minutes + } +} |