summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-10-20 22:46:45 (UTC)
committer llornkcor <llornkcor>2002-10-20 22:46:45 (UTC)
commit9bbc3d997fca39d9ab53541376737b016007685b (patch) (unidiff)
treeb641985f4fae111e71fd620a2864028c6820b934
parent7f4136df2e639ffa27c83422e4ccdf169ba71bad (diff)
downloadopie-9bbc3d997fca39d9ab53541376737b016007685b.zip
opie-9bbc3d997fca39d9ab53541376737b016007685b.tar.gz
opie-9bbc3d997fca39d9ab53541376737b016007685b.tar.bz2
remember user configurations
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 209c5de..f38ea53 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -776,211 +776,220 @@ bool TextEdit::saveAs() {
776 return true; 776 return true;
777 } 777 }
778 if ( !editor->edited() ) { 778 if ( !editor->edited() ) {
779 delete doc; 779 delete doc;
780 doc = 0; 780 doc = 0;
781 return true; 781 return true;
782 } 782 }
783 783
784 QString rt = editor->text(); 784 QString rt = editor->text();
785 qDebug(currentFileName); 785 qDebug(currentFileName);
786 786
787 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 787 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
788// qDebug("do silly TT filename thing"); 788// qDebug("do silly TT filename thing");
789 if ( doc->name().isEmpty() ) { 789 if ( doc->name().isEmpty() ) {
790 QString pt = rt.simplifyWhiteSpace(); 790 QString pt = rt.simplifyWhiteSpace();
791 int i = pt.find( ' ' ); 791 int i = pt.find( ' ' );
792 QString docname = pt; 792 QString docname = pt;
793 if ( i > 0 ) 793 if ( i > 0 )
794 docname = pt.left( i ); 794 docname = pt.left( i );
795 // remove "." at the beginning 795 // remove "." at the beginning
796 while( docname.startsWith( "." ) ) 796 while( docname.startsWith( "." ) )
797 docname = docname.mid( 1 ); 797 docname = docname.mid( 1 );
798 docname.replace( QRegExp("/"), "_" ); 798 docname.replace( QRegExp("/"), "_" );
799 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 799 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
800 if ( docname.length() > 40 ) 800 if ( docname.length() > 40 )
801 docname = docname.left(40); 801 docname = docname.left(40);
802 if ( docname.isEmpty() ) 802 if ( docname.isEmpty() )
803 docname = tr("Unnamed"); 803 docname = tr("Unnamed");
804 doc->setName(docname); 804 doc->setName(docname);
805 currentFileName=docname; 805 currentFileName=docname;
806 } 806 }
807 } 807 }
808 808
809 QMap<QString, QStringList> map; 809 QMap<QString, QStringList> map;
810 map.insert(tr("All"), QStringList() ); 810 map.insert(tr("All"), QStringList() );
811 QStringList text; 811 QStringList text;
812 text << "text/*"; 812 text << "text/*";
813 map.insert(tr("Text"), text ); 813 map.insert(tr("Text"), text );
814 text << "*"; 814 text << "*";
815 map.insert(tr("All"), text ); 815 map.insert(tr("All"), text );
816 816
817 QString str = OFileDialog::getSaveFileName( 2,QPEApplication::documentDir(), QString::null, map); 817 QString str = OFileDialog::getSaveFileName( 2,QPEApplication::documentDir(), QString::null, map);
818 818
819 if(!str.isEmpty() ) { 819 if(!str.isEmpty() ) {
820 QString fileNm=str; 820 QString fileNm=str;
821 821
822 qDebug("saving filename "+fileNm); 822 qDebug("saving filename "+fileNm);
823 QFileInfo fi(fileNm); 823 QFileInfo fi(fileNm);
824 currentFileName=fi.fileName(); 824 currentFileName=fi.fileName();
825 if(doc) { 825 if(doc) {
826// QString file = doc->file(); 826// QString file = doc->file();
827// doc->removeFiles(); 827// doc->removeFiles();
828 delete doc; 828 delete doc;
829 DocLnk nf; 829 DocLnk nf;
830 nf.setType("text/plain"); 830 nf.setType("text/plain");
831 nf.setFile( fileNm); 831 nf.setFile( fileNm);
832 doc = new DocLnk(nf); 832 doc = new DocLnk(nf);
833// editor->setText(rt); 833// editor->setText(rt);
834// qDebug("openFile doclnk "+currentFileName); 834// qDebug("openFile doclnk "+currentFileName);
835 doc->setName( currentFileName); 835 doc->setName( currentFileName);
836 updateCaption( currentFileName); 836 updateCaption( currentFileName);
837 837
838 FileManager fm; 838 FileManager fm;
839 if ( !fm.saveFile( *doc, rt ) ) { 839 if ( !fm.saveFile( *doc, rt ) ) {
840 return false; 840 return false;
841 } 841 }
842 842
843 if( filePerms ) { 843 if( filePerms ) {
844 filePermissions *filePerm; 844 filePermissions *filePerm;
845 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 845 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
846 filePerm->showMaximized(); 846 filePerm->showMaximized();
847 filePerm->exec(); 847 filePerm->exec();
848 848
849 if( filePerm) 849 if( filePerm)
850 delete filePerm; 850 delete filePerm;
851 } 851 }
852 } 852 }
853 editor->setEdited( false); 853 editor->setEdited( false);
854 edited1 = false; 854 edited1 = false;
855 edited = false; 855 edited = false;
856 if(caption().left(1)=="*") 856 if(caption().left(1)=="*")
857 setCaption(caption().right(caption().length()-1)); 857 setCaption(caption().right(caption().length()-1));
858 858
859 return true; 859 return true;
860 } 860 }
861 qDebug("returning false"); 861 qDebug("returning false");
862 return false; 862 return false;
863} //end saveAs 863} //end saveAs
864 864
865void TextEdit::clear() { 865void TextEdit::clear() {
866 delete doc; 866 delete doc;
867 doc = 0; 867 doc = 0;
868 editor->clear(); 868 editor->clear();
869} 869}
870 870
871void TextEdit::updateCaption( const QString &name ) { 871void TextEdit::updateCaption( const QString &name ) {
872 if ( !doc ) 872 if ( !doc )
873 setCaption( tr("Text Editor") ); 873 setCaption( tr("Text Editor") );
874 else { 874 else {
875 QString s = name; 875 QString s = name;
876 if ( s.isNull() ) 876 if ( s.isNull() )
877 s = doc->name(); 877 s = doc->name();
878 if ( s.isEmpty() ) { 878 if ( s.isEmpty() ) {
879 s = tr( "Unnamed" ); 879 s = tr( "Unnamed" );
880 currentFileName=s; 880 currentFileName=s;
881 } 881 }
882 if(s.left(1) == "/") 882 if(s.left(1) == "/")
883 s = s.right(s.length()-1); 883 s = s.right(s.length()-1);
884 setCaption( s + " - " + tr("Text Editor") ); 884 setCaption( s + " - " + tr("Text Editor") );
885 } 885 }
886} 886}
887 887
888void TextEdit::setDocument(const QString& fileref) { 888void TextEdit::setDocument(const QString& fileref) {
889 bFromDocView = TRUE; 889 bFromDocView = TRUE;
890 openFile(fileref); 890 openFile(fileref);
891 editor->setEdited(TRUE); 891 editor->setEdited(TRUE);
892 edited1=FALSE; 892 edited1=FALSE;
893 edited=TRUE; 893 edited=TRUE;
894 doSearchBar(); 894 doSearchBar();
895} 895}
896 896
897void TextEdit::closeEvent( QCloseEvent *e ) { 897void TextEdit::closeEvent( QCloseEvent *e ) {
898 bFromDocView = FALSE; 898 bFromDocView = FALSE;
899 e->accept(); 899 e->accept();
900} 900}
901 901
902void TextEdit::changeFont() { 902void TextEdit::changeFont() {
903 QDialog *d = new QDialog ( this, "FontDialog", true ); 903 QDialog *d = new QDialog ( this, "FontDialog", true );
904 d-> setCaption ( tr( "Choose font" )); 904 d-> setCaption ( tr( "Choose font" ));
905 QBoxLayout *lay = new QVBoxLayout ( d ); 905 QBoxLayout *lay = new QVBoxLayout ( d );
906 OFontSelector *ofs = new OFontSelector ( true, d ); 906 OFontSelector *ofs = new OFontSelector ( true, d );
907 lay-> addWidget ( ofs ); 907 lay-> addWidget ( ofs );
908 ofs-> setSelectedFont ( editor-> font ( )); 908 ofs-> setSelectedFont ( editor-> font ( ));
909 909
910 d-> showMaximized ( ); 910 d-> showMaximized ( );
911 if ( d-> exec ( ) == QDialog::Accepted ) 911 if ( d-> exec ( ) == QDialog::Accepted )
912 editor-> setFont ( ofs-> selectedFont ( )); 912 editor-> setFont ( ofs-> selectedFont ( ));
913 delete d; 913 delete d;
914 914
915} 915}
916 916
917void TextEdit::editDelete() { 917void TextEdit::editDelete() {
918 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) { 918 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) {
919 case 0: 919 case 0:
920 if(doc) { 920 if(doc) {
921 doc->removeFiles(); 921 doc->removeFiles();
922 clear(); 922 clear();
923 setCaption( tr("Text Editor") ); 923 setCaption( tr("Text Editor") );
924 } 924 }
925 break; 925 break;
926 case 1: 926 case 1:
927 // exit 927 // exit
928 break; 928 break;
929 }; 929 };
930} 930}
931 931
932void TextEdit::changeStartConfig( bool b ) { 932void TextEdit::changeStartConfig( bool b ) {
933 933
934 Config cfg("TextEdit"); 934 Config cfg("TextEdit");
935 cfg.setGroup("View"); 935 cfg.setGroup("View");
936 if(b) { 936 if(b) {
937 qDebug("bool"); 937 qDebug("bool");
938 cfg.writeEntry("startNew","TRUE"); 938 cfg.writeEntry("startNew","TRUE");
939 } else { 939 } else {
940 cfg.writeEntry("startNew","FALSE"); 940 cfg.writeEntry("startNew","FALSE");
941 } 941 }
942 update(); 942 update();
943} 943}
944 944
945void TextEdit::editorChanged() { 945void TextEdit::editorChanged() {
946 if(editor->edited() && edited && !edited1) { 946 if(editor->edited() && edited && !edited1) {
947 setCaption( "*"+caption()); 947 setCaption( "*"+caption());
948 edited1=TRUE; 948 edited1=TRUE;
949 } 949 }
950 edited=TRUE; 950 edited=TRUE;
951} 951}
952 952
953void TextEdit::receive(const QCString&msg, const QByteArray&) { 953void TextEdit::receive(const QCString&msg, const QByteArray&) {
954 qDebug("QCop "+msg); 954 qDebug("QCop "+msg);
955 if ( msg == "setDocument(QString)" ) { 955 if ( msg == "setDocument(QString)" ) {
956 qDebug("bugger all"); 956 qDebug("bugger all");
957 } 957 }
958 958
959} 959}
960void TextEdit::doAbout() { 960void TextEdit::doAbout() {
961 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 961 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
962 "2000 Trolltech AS, and<BR>" 962 "2000 Trolltech AS, and<BR>"
963 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 963 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
964 "and is licensed under the GPL")); 964 "and is licensed under the GPL"));
965} 965}
966 966
967void TextEdit::doPrompt(bool b) { 967void TextEdit::doPrompt(bool b) {
968 promptExit=b; 968 promptExit=b;
969 Config cfg("TextEdit");
970 cfg.setGroup ( "View" );
971 cfg.writeEntry ( "PromptExit", b);
969} 972}
970 973
971void TextEdit::doDesktop(bool b) { 974void TextEdit::doDesktop(bool b) {
972 openDesktop=b; 975 openDesktop=b;
976 Config cfg("TextEdit");
977 cfg.setGroup ( "View" );
978 cfg.writeEntry ( "OpenDesktop", b);
973} 979}
974 980
975void TextEdit::doFilePerms(bool b) { 981void TextEdit::doFilePerms(bool b) {
976 filePerms=b; 982 filePerms=b;
983 Config cfg("TextEdit");
984 cfg.setGroup ( "View" );
985 cfg.writeEntry ( "FilePermissions", b);
977} 986}
978 987
979void TextEdit::editPasteTimeDate() { 988void TextEdit::editPasteTimeDate() {
980#ifndef QT_NO_CLIPBOARD 989#ifndef QT_NO_CLIPBOARD
981 QClipboard *cb = QApplication::clipboard(); 990 QClipboard *cb = QApplication::clipboard();
982 QDateTime dt = QDateTime::currentDateTime(); 991 QDateTime dt = QDateTime::currentDateTime();
983 cb->setText( dt.toString()); 992 cb->setText( dt.toString());
984 editor->paste(); 993 editor->paste();
985#endif 994#endif
986} 995}