author | llornkcor <llornkcor> | 2003-02-18 19:09:14 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-18 19:09:14 (UTC) |
commit | 4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2 (patch) (unidiff) | |
tree | fbc89396011e0e9a0dc04fcd1454ee670d6fcae3 /core/apps/textedit/textedit.cpp | |
parent | 50f0a50a14f87960cf9492d01aeed5a56a6dca06 (diff) | |
download | opie-4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2.zip opie-4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2.tar.gz opie-4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2.tar.bz2 |
autosave feature. will save to ~/textedit.tmp is no filename has been set. moved stuff from public methods
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 145 |
1 files changed, 134 insertions, 11 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 @@ | |||
51 | #include <qapplication.h> | 51 | #include <qapplication.h> |
52 | #include <qtimer.h> | ||
53 | #include <qdir.h> | ||
52 | #include <unistd.h> | 54 | #include <unistd.h> |
@@ -412,2 +414,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
412 | 414 | ||
415 | nAutoSave = new QAction( tr("Auto Save 5 min."), | ||
416 | QString::null, 0, this, 0 ); | ||
417 | connect( nAutoSave, SIGNAL( toggled(bool) ), | ||
418 | this, SLOT( doTimer(bool) ) ); | ||
419 | nAutoSave->setToggleAction(true); | ||
420 | nAutoSave->addTo( advancedMenu); | ||
421 | |||
413 | 422 | ||
@@ -480,5 +489,6 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
480 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 489 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
490 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | ||
481 | 491 | ||
482 | if(useSearchBar) searchBarAction->setOn(true); | 492 | if(useSearchBar) searchBarAction->setOn(true); |
483 | if(promptExit ) nAdvanced->setOn( true ); | 493 | if(promptExit) nAdvanced->setOn( true ); |
484 | if(openDesktop) desktopAction->setOn( true ); | 494 | if(openDesktop) desktopAction->setOn( true ); |
@@ -486,3 +496,8 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
486 | if(startWithNew) nStart->setOn( true ); | 496 | if(startWithNew) nStart->setOn( true ); |
487 | 497 | if(featureAutoSave) nAutoSave->setOn(true); | |
498 | |||
499 | // { | ||
500 | // doTimer(true); | ||
501 | // } | ||
502 | |||
488 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 503 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
@@ -491,2 +506,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
491 | 506 | ||
507 | ///////////////// | ||
492 | if( qApp->argc() > 1) { | 508 | if( qApp->argc() > 1) { |
@@ -515,5 +531,26 @@ TextEdit::~TextEdit() { | |||
515 | void TextEdit::closeEvent(QCloseEvent *) { | 531 | void TextEdit::closeEvent(QCloseEvent *) { |
516 | if( edited1 && promptExit) | 532 | if( edited1 && promptExit) |
517 | saveAs(); | 533 | { |
518 | qApp->quit(); | 534 | switch( savePrompt() ) |
535 | { | ||
536 | case 1: | ||
537 | { | ||
538 | saveAs(); | ||
539 | qApp->quit(); | ||
540 | } | ||
541 | break; | ||
542 | |||
543 | case 2: | ||
544 | { | ||
545 | qApp->quit(); | ||
546 | } | ||
547 | break; | ||
548 | |||
549 | case -1: | ||
550 | break; | ||
551 | }; | ||
552 | } | ||
553 | else | ||
554 | qApp->quit(); | ||
555 | |||
519 | } | 556 | } |
@@ -816,2 +853,3 @@ void TextEdit::openFile( const DocLnk &f ) { | |||
816 | updateCaption(); | 853 | updateCaption(); |
854 | setTimer(); | ||
817 | } | 855 | } |
@@ -836,3 +874,4 @@ bool TextEdit::save() { | |||
836 | } | 874 | } |
837 | QString file = doc->file(); | 875 | |
876 | QString file = doc->file(); | ||
838 | qDebug("saver file "+file); | 877 | qDebug("saver file "+file); |
@@ -888,2 +927,3 @@ bool TextEdit::save() { | |||
888 | bool TextEdit::saveAs() { | 927 | bool TextEdit::saveAs() { |
928 | |||
889 | if(caption() == tr("Text Editor")) | 929 | if(caption() == tr("Text Editor")) |
@@ -946,7 +986,12 @@ bool TextEdit::saveAs() { | |||
946 | if(dire==".") | 986 | if(dire==".") |
947 | dire = QPEApplication::documentDir(); | 987 | dire = QPEApplication::documentDir(); |
948 | QString str = OFileDialog::getSaveFileName( 2, | 988 | QString str; |
949 | dire, | 989 | if( !featureAutoSave) |
950 | filee, map); | 990 | { |
951 | 991 | str = OFileDialog::getSaveFileName( 2, | |
992 | dire, | ||
993 | filee, map); | ||
994 | } | ||
995 | else | ||
996 | str=currentFileName; | ||
952 | if(!str.isEmpty()) { | 997 | if(!str.isEmpty()) { |
@@ -1142 +1187,79 @@ void TextEdit::editPasteTimeDate() { | |||
1142 | } | 1187 | } |
1188 | |||
1189 | int TextEdit::savePrompt() | ||
1190 | { | ||
1191 | switch( QMessageBox::information( 0, (tr("Textedit")), | ||
1192 | (tr("Textedit detected\n" | ||
1193 | "you have unsaved changes\n" | ||
1194 | "Go ahead and save?\n")), | ||
1195 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | ||
1196 | { | ||
1197 | case 0: | ||
1198 | { | ||
1199 | return 1; | ||
1200 | } | ||
1201 | break; | ||
1202 | |||
1203 | case 1: | ||
1204 | { | ||
1205 | return 2; | ||
1206 | } | ||
1207 | break; | ||
1208 | |||
1209 | case 2: | ||
1210 | { | ||
1211 | return -1; | ||
1212 | } | ||
1213 | break; | ||
1214 | }; | ||
1215 | |||
1216 | return 0; | ||
1217 | } | ||
1218 | |||
1219 | void TextEdit::timerCrank() | ||
1220 | { | ||
1221 | if(featureAutoSave) | ||
1222 | { | ||
1223 | if( edited1 ) | ||
1224 | { | ||
1225 | if(currentFileName.isEmpty()) | ||
1226 | { | ||
1227 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | ||
1228 | saveAs(); | ||
1229 | } | ||
1230 | else | ||
1231 | { | ||
1232 | qDebug("autosave"); | ||
1233 | save(); | ||
1234 | } | ||
1235 | setTimer(); | ||
1236 | } | ||
1237 | } | ||
1238 | } | ||
1239 | |||
1240 | void TextEdit::doTimer(bool b) | ||
1241 | { | ||
1242 | Config cfg("TextEdit"); | ||
1243 | cfg.setGroup ( "View" ); | ||
1244 | cfg.writeEntry ( "autosave", b); | ||
1245 | featureAutoSave = b; | ||
1246 | nAutoSave->setOn(b); | ||
1247 | if(b) | ||
1248 | { | ||
1249 | qDebug("doTimer true"); | ||
1250 | setTimer(); | ||
1251 | } | ||
1252 | else | ||
1253 | qDebug("doTimer false"); | ||
1254 | } | ||
1255 | |||
1256 | void TextEdit::setTimer() | ||
1257 | { | ||
1258 | if(featureAutoSave) | ||
1259 | { | ||
1260 | qDebug("setting autosave"); | ||
1261 | QTimer *timer = new QTimer(this ); | ||
1262 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | ||
1263 | timer->start( 30000/*0*/, true); //5 minutes | ||
1264 | } | ||
1265 | } | ||