summaryrefslogtreecommitdiff
path: root/core/apps/textedit
authorllornkcor <llornkcor>2003-02-18 19:09:14 (UTC)
committer llornkcor <llornkcor>2003-02-18 19:09:14 (UTC)
commit4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2 (patch) (unidiff)
treefbc89396011e0e9a0dc04fcd1454ee670d6fcae3 /core/apps/textedit
parent50f0a50a14f87960cf9492d01aeed5a56a6dca06 (diff)
downloadopie-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') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp127
-rw-r--r--core/apps/textedit/textedit.h16
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
@@ -28,48 +28,50 @@
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#include <qpe/qpemenubar.h> 29#include <qpe/qpemenubar.h>
30#include <qpe/qpetoolbar.h> 30#include <qpe/qpetoolbar.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32 32
33#include <qpoint.h> 33#include <qpoint.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35#include <qdatetime.h> 35#include <qdatetime.h>
36#include <qclipboard.h> 36#include <qclipboard.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38#include <qaction.h> 38#include <qaction.h>
39#include <qcolordialog.h> 39#include <qcolordialog.h>
40#include <qfileinfo.h> 40#include <qfileinfo.h>
41#include <qlineedit.h> 41#include <qlineedit.h>
42#include <qmessagebox.h> 42#include <qmessagebox.h>
43#include <qobjectlist.h> 43#include <qobjectlist.h>
44#include <qpopupmenu.h> 44#include <qpopupmenu.h>
45#include <qspinbox.h> 45#include <qspinbox.h>
46#include <qtoolbutton.h> 46#include <qtoolbutton.h>
47#include <qwidgetstack.h> 47#include <qwidgetstack.h>
48#include <qcheckbox.h> 48#include <qcheckbox.h>
49#include <qcombo.h> 49#include <qcombo.h>
50#include <qlayout.h> 50#include <qlayout.h>
51#include <qapplication.h> 51#include <qapplication.h>
52#include <qtimer.h>
53#include <qdir.h>
52#include <unistd.h> 54#include <unistd.h>
53#include <sys/stat.h> 55#include <sys/stat.h>
54#include <stdlib.h> //getenv 56#include <stdlib.h> //getenv
55 57
56 58
57/* XPM */ 59/* XPM */
58static char * filesave_xpm[] = { 60static char * filesave_xpm[] = {
59"16 16 78 1", 61"16 16 78 1",
60" c None", 62" c None",
61". c #343434", 63". c #343434",
62"+ c #A0A0A0", 64"+ c #A0A0A0",
63"@ c #565656", 65"@ c #565656",
64"# c #9E9E9E", 66"# c #9E9E9E",
65"$ c #525252", 67"$ c #525252",
66"% c #929292", 68"% c #929292",
67"& c #676767", 69"& c #676767",
68"* c #848484", 70"* c #848484",
69"= c #666666", 71"= c #666666",
70"- c #D8D8D8", 72"- c #D8D8D8",
71"; c #FFFFFF", 73"; c #FFFFFF",
72"> c #DBDBDB", 74"> c #DBDBDB",
73", c #636363", 75", c #636363",
74"' c #989898", 76"' c #989898",
75") c #2D2D2D", 77") c #2D2D2D",
@@ -389,48 +391,55 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
389 nAdvanced->setToggleAction(true); 391 nAdvanced->setToggleAction(true);
390 nAdvanced->addTo( advancedMenu ); 392 nAdvanced->addTo( advancedMenu );
391 393
392 desktopAction = new QAction( tr("Always open linked file"), 394 desktopAction = new QAction( tr("Always open linked file"),
393 QString::null, 0, this, 0 ); 395 QString::null, 0, this, 0 );
394 connect( desktopAction, SIGNAL( toggled(bool) ), 396 connect( desktopAction, SIGNAL( toggled(bool) ),
395 this, SLOT( doDesktop(bool) ) ); 397 this, SLOT( doDesktop(bool) ) );
396 desktopAction->setToggleAction(true); 398 desktopAction->setToggleAction(true);
397 desktopAction->addTo( advancedMenu); 399 desktopAction->addTo( advancedMenu);
398 400
399 filePermAction = new QAction( tr("File Permissions"), 401 filePermAction = new QAction( tr("File Permissions"),
400 QString::null, 0, this, 0 ); 402 QString::null, 0, this, 0 );
401 connect( filePermAction, SIGNAL( toggled(bool) ), 403 connect( filePermAction, SIGNAL( toggled(bool) ),
402 this, SLOT( doFilePerms(bool) ) ); 404 this, SLOT( doFilePerms(bool) ) );
403 filePermAction->setToggleAction(true); 405 filePermAction->setToggleAction(true);
404 filePermAction->addTo( advancedMenu); 406 filePermAction->addTo( advancedMenu);
405 407
406 searchBarAction = new QAction( tr("Search Bar Open"), 408 searchBarAction = new QAction( tr("Search Bar Open"),
407 QString::null, 0, this, 0 ); 409 QString::null, 0, this, 0 );
408 connect( searchBarAction, SIGNAL( toggled(bool) ), 410 connect( searchBarAction, SIGNAL( toggled(bool) ),
409 this, SLOT( setSearchBar(bool) ) ); 411 this, SLOT( setSearchBar(bool) ) );
410 searchBarAction->setToggleAction(true); 412 searchBarAction->setToggleAction(true);
411 searchBarAction->addTo( advancedMenu); 413 searchBarAction->addTo( advancedMenu);
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
414 font->insertSeparator(); 423 font->insertSeparator();
415 424
416 font->insertItem(tr("About"), this, SLOT( doAbout()) ); 425 font->insertItem(tr("About"), this, SLOT( doAbout()) );
417 426
418 mb->insertItem( tr( "File" ), file ); 427 mb->insertItem( tr( "File" ), file );
419 mb->insertItem( tr( "Edit" ), edit ); 428 mb->insertItem( tr( "Edit" ), edit );
420 mb->insertItem( tr( "View" ), font ); 429 mb->insertItem( tr( "View" ), font );
421 430
422 searchBar = new QPEToolBar(this); 431 searchBar = new QPEToolBar(this);
423 addToolBar( searchBar, "Search", QMainWindow::Top, true ); 432 addToolBar( searchBar, "Search", QMainWindow::Top, true );
424 433
425 searchBar->setHorizontalStretchable( true ); 434 searchBar->setHorizontalStretchable( true );
426 435
427 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 436 searchEdit = new QLineEdit( searchBar, "searchEdit" );
428 searchBar->setStretchableWidget( searchEdit ); 437 searchBar->setStretchableWidget( searchEdit );
429 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 438 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
430 this, SLOT( search() ) ); 439 this, SLOT( search() ) );
431 440
432 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), 441 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ),
433 QString::null, 0, this, 0 ); 442 QString::null, 0, this, 0 );
434 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 443 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
435 a->addTo( searchBar ); 444 a->addTo( searchBar );
436 a->addTo( edit ); 445 a->addTo( edit );
@@ -457,87 +466,115 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
457 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 466 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
458 467
459 Config cfg("TextEdit"); 468 Config cfg("TextEdit");
460 cfg. setGroup ( "Font" ); 469 cfg. setGroup ( "Font" );
461 470
462 QFont defaultFont = editor-> font ( ); 471 QFont defaultFont = editor-> font ( );
463 472
464 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 473 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
465 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 474 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
466 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 475 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
467 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 476 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
468 477
469 defaultFont = QFont ( family, size, weight, italic ); 478 defaultFont = QFont ( family, size, weight, italic );
470 editor-> setFont ( defaultFont ); 479 editor-> setFont ( defaultFont );
471 480
472// updateCaption(); 481// updateCaption();
473 482
474 cfg.setGroup ( "View" ); 483 cfg.setGroup ( "View" );
475 484
476 promptExit = cfg.readBoolEntry ( "PromptExit", false ); 485 promptExit = cfg.readBoolEntry ( "PromptExit", false );
477 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); 486 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true );
478 filePerms = cfg.readBoolEntry ( "FilePermissions", false ); 487 filePerms = cfg.readBoolEntry ( "FilePermissions", false );
479 useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); 488 useSearchBar = cfg.readBoolEntry ( "SearchBar", false );
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 );
485 if(filePerms) filePermAction->setOn( true ); 495 if(filePerms) filePermAction->setOn( true );
486 if(startWithNew) nStart->setOn( true ); 496 if(startWithNew) nStart->setOn( true );
497 if(featureAutoSave) nAutoSave->setOn(true);
498
499// {
500// doTimer(true);
501// }
487 502
488 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 503 bool wrap = cfg. readBoolEntry ( "Wrap", true );
489 wa-> setOn ( wrap ); 504 wa-> setOn ( wrap );
490 setWordWrap ( wrap ); 505 setWordWrap ( wrap );
491 506
507/////////////////
492 if( qApp->argc() > 1) { 508 if( qApp->argc() > 1) {
493 currentFileName=qApp->argv()[1]; 509 currentFileName=qApp->argv()[1];
494 510
495 QFileInfo fi(currentFileName); 511 QFileInfo fi(currentFileName);
496 512
497 if(fi.baseName().left(1) == "") { 513 if(fi.baseName().left(1) == "") {
498 openDotFile(currentFileName); 514 openDotFile(currentFileName);
499 } else { 515 } else {
500 openFile(currentFileName); 516 openFile(currentFileName);
501 } 517 }
502 } else { 518 } else {
503 edited1=false; 519 edited1=false;
504 openDotFile(""); 520 openDotFile("");
505 } 521 }
506 522
507 viewSelection = cfg.readNumEntry( "FileView", 0 ); 523 viewSelection = cfg.readNumEntry( "FileView", 0 );
508} 524}
509 525
510TextEdit::~TextEdit() { 526TextEdit::~TextEdit() {
511 qWarning("textedit d'tor"); 527 qWarning("textedit d'tor");
512 delete editor; 528 delete editor;
513} 529}
514 530
515void TextEdit::closeEvent(QCloseEvent *) { 531void TextEdit::closeEvent(QCloseEvent *) {
516 if( edited1 && promptExit) 532 if( edited1 && promptExit)
533 {
534 switch( savePrompt() )
535 {
536 case 1:
537 {
517 saveAs(); 538 saveAs();
518 qApp->quit(); 539 qApp->quit();
519} 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
556}
520 557
521void TextEdit::cleanUp() { 558void TextEdit::cleanUp() {
522 559
523 Config cfg ( "TextEdit" ); 560 Config cfg ( "TextEdit" );
524 cfg. setGroup ( "Font" ); 561 cfg. setGroup ( "Font" );
525 QFont f = editor->font(); 562 QFont f = editor->font();
526 cfg.writeEntry ( "Family", f. family ( )); 563 cfg.writeEntry ( "Family", f. family ( ));
527 cfg.writeEntry ( "Size", f. pointSize ( )); 564 cfg.writeEntry ( "Size", f. pointSize ( ));
528 cfg.writeEntry ( "Weight", f. weight ( )); 565 cfg.writeEntry ( "Weight", f. weight ( ));
529 cfg.writeEntry ( "Italic", f. italic ( )); 566 cfg.writeEntry ( "Italic", f. italic ( ));
530 567
531 cfg.setGroup ( "View" ); 568 cfg.setGroup ( "View" );
532 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); 569 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth );
533 cfg.writeEntry ( "FileView", viewSelection ); 570 cfg.writeEntry ( "FileView", viewSelection );
534 571
535 cfg.writeEntry ( "PromptExit", promptExit ); 572 cfg.writeEntry ( "PromptExit", promptExit );
536 cfg.writeEntry ( "OpenDesktop", openDesktop ); 573 cfg.writeEntry ( "OpenDesktop", openDesktop );
537 cfg.writeEntry ( "FilePermissions", filePerms ); 574 cfg.writeEntry ( "FilePermissions", filePerms );
538 cfg.writeEntry ( "SearchBar", useSearchBar ); 575 cfg.writeEntry ( "SearchBar", useSearchBar );
539 cfg.writeEntry ( "startNew", startWithNew ); 576 cfg.writeEntry ( "startNew", startWithNew );
540 577
541} 578}
542 579
543 580
@@ -793,68 +830,70 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
793} 830}
794 831
795void TextEdit::openFile( const DocLnk &f ) { 832void TextEdit::openFile( const DocLnk &f ) {
796// clear(); 833// clear();
797// bFromDocView = true; 834// bFromDocView = true;
798 FileManager fm; 835 FileManager fm;
799 QString txt; 836 QString txt;
800 currentFileName=f.file(); 837 currentFileName=f.file();
801 qDebug("openFile doclnk " + currentFileName); 838 qDebug("openFile doclnk " + currentFileName);
802 if ( !fm.loadFile( f, txt ) ) { 839 if ( !fm.loadFile( f, txt ) ) {
803 // ####### could be a new file 840 // ####### could be a new file
804 qDebug( "Cannot open file" ); 841 qDebug( "Cannot open file" );
805 } 842 }
806// fileNew(); 843// fileNew();
807 if ( doc ) 844 if ( doc )
808 delete doc; 845 delete doc;
809 doc = new DocLnk(f); 846 doc = new DocLnk(f);
810 editor->setText(txt); 847 editor->setText(txt);
811 editor->setEdited( false); 848 editor->setEdited( false);
812 edited1=false; 849 edited1=false;
813 edited=false; 850 edited=false;
814 851
815 doc->setName(currentFileName); 852 doc->setName(currentFileName);
816 updateCaption(); 853 updateCaption();
854 setTimer();
817} 855}
818 856
819void TextEdit::showEditTools() { 857void TextEdit::showEditTools() {
820 menu->show(); 858 menu->show();
821 editBar->show(); 859 editBar->show();
822 if(!useSearchBar) 860 if(!useSearchBar)
823 searchBar->hide(); 861 searchBar->hide();
824 else 862 else
825 searchBar->show(); 863 searchBar->show();
826 setWState (WState_Reserved1 ); 864 setWState (WState_Reserved1 );
827} 865}
828 866
829/*! 867/*!
830 unprompted save */ 868 unprompted save */
831bool TextEdit::save() { 869bool TextEdit::save() {
832 qDebug("saveAsFile " + currentFileName); 870 qDebug("saveAsFile " + currentFileName);
833 if(currentFileName.isEmpty()) { 871 if(currentFileName.isEmpty()) {
834 saveAs(); 872 saveAs();
835 return false; 873 return false;
836 } 874 }
875
837 QString file = doc->file(); 876 QString file = doc->file();
838 qDebug("saver file "+file); 877 qDebug("saver file "+file);
839 QString name= doc->name(); 878 QString name= doc->name();
840 qDebug("File named "+name); 879 qDebug("File named "+name);
841 QString rt = editor->text(); 880 QString rt = editor->text();
842 if( !rt.isEmpty() ) { 881 if( !rt.isEmpty() ) {
843 if(name.isEmpty()) { 882 if(name.isEmpty()) {
844 saveAs(); 883 saveAs();
845 } else { 884 } else {
846 currentFileName= name ; 885 currentFileName= name ;
847 qDebug("saveFile "+currentFileName); 886 qDebug("saveFile "+currentFileName);
848 887
849 struct stat buf; 888 struct stat buf;
850 mode_t mode; 889 mode_t mode;
851 stat(file.latin1(), &buf); 890 stat(file.latin1(), &buf);
852 mode = buf.st_mode; 891 mode = buf.st_mode;
853 892
854 if(!fileIs) { 893 if(!fileIs) {
855 doc->setName( name); 894 doc->setName( name);
856 FileManager fm; 895 FileManager fm;
857 if ( !fm.saveFile( *doc, rt ) ) { 896 if ( !fm.saveFile( *doc, rt ) ) {
858 return false; 897 return false;
859 } 898 }
860 } else { 899 } else {
@@ -865,48 +904,49 @@ bool TextEdit::save() {
865 f.writeBlock(crt,crt.length()); 904 f.writeBlock(crt,crt.length());
866 } else { 905 } else {
867 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 906 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
868 return false; 907 return false;
869 } 908 }
870 909
871 } 910 }
872 editor->setEdited( false); 911 editor->setEdited( false);
873 edited1=false; 912 edited1=false;
874 edited=false; 913 edited=false;
875 if(caption().left(1)=="*") 914 if(caption().left(1)=="*")
876 setCaption(caption().right(caption().length()-1)); 915 setCaption(caption().right(caption().length()-1));
877 916
878 917
879 chmod( file.latin1(), mode); 918 chmod( file.latin1(), mode);
880 } 919 }
881 return true; 920 return true;
882 } 921 }
883 return false; 922 return false;
884} 923}
885 924
886/*! 925/*!
887 prompted save */ 926 prompted save */
888bool TextEdit::saveAs() { 927bool TextEdit::saveAs() {
928
889 if(caption() == tr("Text Editor")) 929 if(caption() == tr("Text Editor"))
890 return false; 930 return false;
891 qDebug("saveAsFile " + currentFileName); 931 qDebug("saveAsFile " + currentFileName);
892 // case of nothing to save... 932 // case of nothing to save...
893// if ( !doc && !currentFileName.isEmpty()) { 933// if ( !doc && !currentFileName.isEmpty()) {
894// //|| !bFromDocView) 934// //|| !bFromDocView)
895// qDebug("no doc"); 935// qDebug("no doc");
896// return true; 936// return true;
897// } 937// }
898// if ( !editor->edited() ) { 938// if ( !editor->edited() ) {
899// delete doc; 939// delete doc;
900// doc = 0; 940// doc = 0;
901// return true; 941// return true;
902// } 942// }
903 943
904 QString rt = editor->text(); 944 QString rt = editor->text();
905 qDebug(currentFileName); 945 qDebug(currentFileName);
906 946
907 if( currentFileName.isEmpty() 947 if( currentFileName.isEmpty()
908 || currentFileName == tr("Unnamed") 948 || currentFileName == tr("Unnamed")
909 || currentFileName == tr("Text Editor")) { 949 || currentFileName == tr("Text Editor")) {
910 qDebug("do silly TT filename thing"); 950 qDebug("do silly TT filename thing");
911// if ( doc && doc->name().isEmpty() ) { 951// if ( doc && doc->name().isEmpty() ) {
912 QString pt = rt.simplifyWhiteSpace(); 952 QString pt = rt.simplifyWhiteSpace();
@@ -924,52 +964,57 @@ bool TextEdit::saveAs() {
924 docname = docname.left(40); 964 docname = docname.left(40);
925 if ( docname.isEmpty() ) 965 if ( docname.isEmpty() )
926 docname = tr("Unnamed"); 966 docname = tr("Unnamed");
927 if(doc) doc->setName(docname); 967 if(doc) doc->setName(docname);
928 currentFileName=docname; 968 currentFileName=docname;
929// } 969// }
930// else 970// else
931// qDebug("hmmmmmm"); 971// qDebug("hmmmmmm");
932 } 972 }
933 973
934 974
935 QMap<QString, QStringList> map; 975 QMap<QString, QStringList> map;
936 map.insert(tr("All"), QStringList() ); 976 map.insert(tr("All"), QStringList() );
937 QStringList text; 977 QStringList text;
938 text << "text/*"; 978 text << "text/*";
939 map.insert(tr("Text"), text ); 979 map.insert(tr("Text"), text );
940 text << "*"; 980 text << "*";
941 map.insert(tr("All"), text ); 981 map.insert(tr("All"), text );
942 982
943 QFileInfo cuFi( currentFileName); 983 QFileInfo cuFi( currentFileName);
944 QString filee = cuFi.fileName(); 984 QString filee = cuFi.fileName();
945 QString dire = cuFi.dirPath(); 985 QString dire = cuFi.dirPath();
946 if(dire==".") 986 if(dire==".")
947 dire = QPEApplication::documentDir(); 987 dire = QPEApplication::documentDir();
948 QString str = OFileDialog::getSaveFileName( 2, 988 QString str;
989 if( !featureAutoSave)
990 {
991 str = OFileDialog::getSaveFileName( 2,
949 dire, 992 dire,
950 filee, map); 993 filee, map);
951 994 }
995 else
996 str=currentFileName;
952 if(!str.isEmpty()) { 997 if(!str.isEmpty()) {
953 QString fileNm=str; 998 QString fileNm=str;
954 999
955 qDebug("saving filename "+fileNm); 1000 qDebug("saving filename "+fileNm);
956 QFileInfo fi(fileNm); 1001 QFileInfo fi(fileNm);
957 currentFileName=fi.fileName(); 1002 currentFileName=fi.fileName();
958 if(doc) 1003 if(doc)
959// QString file = doc->file(); 1004// QString file = doc->file();
960// doc->removeFiles(); 1005// doc->removeFiles();
961 delete doc; 1006 delete doc;
962 DocLnk nf; 1007 DocLnk nf;
963 nf.setType("text/plain"); 1008 nf.setType("text/plain");
964 nf.setFile( fileNm); 1009 nf.setFile( fileNm);
965 doc = new DocLnk(nf); 1010 doc = new DocLnk(nf);
966// editor->setText(rt); 1011// editor->setText(rt);
967 qDebug("Saving file as "+currentFileName); 1012 qDebug("Saving file as "+currentFileName);
968 doc->setName( currentFileName); 1013 doc->setName( currentFileName);
969 updateCaption( currentFileName); 1014 updateCaption( currentFileName);
970 1015
971 FileManager fm; 1016 FileManager fm;
972 if ( !fm.saveFile( *doc, rt ) ) { 1017 if ( !fm.saveFile( *doc, rt ) ) {
973 return false; 1018 return false;
974 } 1019 }
975 1020
@@ -1119,24 +1164,102 @@ void TextEdit::doPrompt(bool b) {
1119} 1164}
1120 1165
1121void TextEdit::doDesktop(bool b) { 1166void TextEdit::doDesktop(bool b) {
1122 openDesktop=b; 1167 openDesktop=b;
1123 Config cfg("TextEdit"); 1168 Config cfg("TextEdit");
1124 cfg.setGroup ( "View" ); 1169 cfg.setGroup ( "View" );
1125 cfg.writeEntry ( "OpenDesktop", b); 1170 cfg.writeEntry ( "OpenDesktop", b);
1126} 1171}
1127 1172
1128void TextEdit::doFilePerms(bool b) { 1173void TextEdit::doFilePerms(bool b) {
1129 filePerms=b; 1174 filePerms=b;
1130 Config cfg("TextEdit"); 1175 Config cfg("TextEdit");
1131 cfg.setGroup ( "View" ); 1176 cfg.setGroup ( "View" );
1132 cfg.writeEntry ( "FilePermissions", b); 1177 cfg.writeEntry ( "FilePermissions", b);
1133} 1178}
1134 1179
1135void TextEdit::editPasteTimeDate() { 1180void TextEdit::editPasteTimeDate() {
1136#ifndef QT_NO_CLIPBOARD 1181#ifndef QT_NO_CLIPBOARD
1137 QClipboard *cb = QApplication::clipboard(); 1182 QClipboard *cb = QApplication::clipboard();
1138 QDateTime dt = QDateTime::currentDateTime(); 1183 QDateTime dt = QDateTime::currentDateTime();
1139 cb->setText( dt.toString()); 1184 cb->setText( dt.toString());
1140 editor->paste(); 1185 editor->paste();
1141#endif 1186#endif
1142} 1187}
1188
1189int 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
1219void 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
1240void 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
1256void TextEdit::setTimer()
1257{
1258if(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}
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
@@ -26,69 +26,75 @@
26 26
27//#include "fileBrowser.h" 27//#include "fileBrowser.h"
28//#include "fileSaver.h" 28//#include "fileSaver.h"
29 29
30#include <qpe/filemanager.h> 30#include <qpe/filemanager.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32 32
33#include <opie/ofileselector.h> 33#include <opie/ofileselector.h>
34 34
35#include <qmainwindow.h> 35#include <qmainwindow.h>
36#include <qmultilineedit.h> 36#include <qmultilineedit.h>
37#include <qlist.h> 37#include <qlist.h>
38#include <qmap.h> 38#include <qmap.h>
39 39
40class QAction; 40class QAction;
41class QWidgetStack; 41class QWidgetStack;
42class QToolButton; 42class QToolButton;
43class QPopupMenu; 43class QPopupMenu;
44class QToolBar; 44class QToolBar;
45class QLineEdit; 45class QLineEdit;
46class QAction; 46class QAction;
47class FileSelector; 47class FileSelector;
48class QpeEditor; 48class QpeEditor;
49class QPopupMenu; 49class QPopupMenu;
50class QTimer;
50 51
51class TextEdit : public QMainWindow 52class TextEdit : public QMainWindow
52{ 53{
53 Q_OBJECT 54 Q_OBJECT
54 55
55public: 56public:
56 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 57 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
57 ~TextEdit(); 58 ~TextEdit();
58 59
60protected:
59 QPopupMenu *font; 61 QPopupMenu *font;
60 QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction, *searchBarAction; 62 QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction, *searchBarAction, *nAutoSave;
61 bool edited, edited1; 63 bool edited, edited1;
62 void openFile( const QString & ); 64 void openFile( const QString & );
63 QCopChannel * channel; 65 QCopChannel * channel;
64public slots: 66
65 void editorChanged(); 67 bool featureAutoSave;
66void receive(const QCString&, const QByteArray&);
67protected:
68 void closeEvent( QCloseEvent *e ); 68 void closeEvent( QCloseEvent *e );
69 void doSearchBar(); 69 void doSearchBar();
70 int savePrompt();
71 void setTimer();
70private slots: 72private slots:
73 void editorChanged();
74 void receive(const QCString&, const QByteArray&);
75 void timerCrank();
76 void doTimer(bool);
71 void editPasteTimeDate(); 77 void editPasteTimeDate();
72 void doPrompt(bool); 78 void doPrompt(bool);
73 void doDesktop(bool); 79 void doDesktop(bool);
74 void doFilePerms(bool); 80 void doFilePerms(bool);
75 void doAbout(); 81 void doAbout();
76 void setDocument(const QString&); 82 void setDocument(const QString&);
77 void changeFont(); 83 void changeFont();
78 void fileNew(); 84 void fileNew();
79 void fileRevert(); 85 void fileRevert();
80 void fileOpen(); 86 void fileOpen();
81 void changeStartConfig(bool); 87 void changeStartConfig(bool);
82 bool save(); 88 bool save();
83 bool saveAs(); 89 bool saveAs();
84 void cleanUp(); 90 void cleanUp();
85 91
86 92
87 void editCut(); 93 void editCut();
88 void editCopy(); 94 void editCopy();
89 void editPaste(); 95 void editPaste();
90 void editFind(); 96 void editFind();
91 void editDelete(); 97 void editDelete();
92 98
93 void findNext(); 99 void findNext();
94 void findClose(); 100 void findClose();