-rw-r--r-- | core/apps/textedit/textedit.cpp | 127 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 16 |
2 files changed, 136 insertions, 7 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 @@ -51,2 +51,4 @@ #include <qapplication.h> +#include <qtimer.h> +#include <qdir.h> #include <unistd.h> @@ -412,2 +414,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) + 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); + @@ -480,2 +489,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) startWithNew = cfg.readBoolEntry ( "startNew", true); + featureAutoSave = cfg.readBoolEntry( "autosave", false); @@ -486,2 +496,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) if(startWithNew) nStart->setOn( true ); + if(featureAutoSave) nAutoSave->setOn(true); + +// { +// doTimer(true); +// } @@ -491,2 +506,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) +///////////////// if( qApp->argc() > 1) { @@ -516,2 +532,7 @@ void TextEdit::closeEvent(QCloseEvent *) { if( edited1 && promptExit) + { + switch( savePrompt() ) + { + case 1: + { saveAs(); @@ -519,2 +540,18 @@ void TextEdit::closeEvent(QCloseEvent *) { } + break; + + case 2: + { + qApp->quit(); + } + break; + + case -1: + break; + }; + } + else + qApp->quit(); + +} @@ -816,2 +853,3 @@ void TextEdit::openFile( const DocLnk &f ) { updateCaption(); + setTimer(); } @@ -836,2 +874,3 @@ bool TextEdit::save() { } + QString file = doc->file(); @@ -888,2 +927,3 @@ bool TextEdit::save() { bool TextEdit::saveAs() { + if(caption() == tr("Text Editor")) @@ -947,6 +987,11 @@ bool TextEdit::saveAs() { 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()) { @@ -1142 +1187,79 @@ void TextEdit::editPasteTimeDate() { } + +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 + } +} diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 9f16ebf..643ea68 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -49,2 +49,3 @@ class QpeEditor; class QPopupMenu; +class QTimer; @@ -58,4 +59,5 @@ public: +protected: QPopupMenu *font; - QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction, *searchBarAction; + QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction, *searchBarAction, *nAutoSave; bool edited, edited1; @@ -63,9 +65,13 @@ public: QCopChannel * channel; -public slots: - void editorChanged(); -void receive(const QCString&, const QByteArray&); -protected: + + bool featureAutoSave; void closeEvent( QCloseEvent *e ); void doSearchBar(); + int savePrompt(); + void setTimer(); private slots: + void editorChanged(); + void receive(const QCString&, const QByteArray&); + void timerCrank(); + void doTimer(bool); void editPasteTimeDate(); |