author | llornkcor <llornkcor> | 2004-03-01 09:02:25 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-03-01 09:02:25 (UTC) |
commit | aa4539e4ccc23c47f720819e23c9a6faf53a4df8 (patch) (unidiff) | |
tree | 7c501175e1655b27cc144954e741d7eb8dc9372b | |
parent | 47cb805563e76732320f082975aad3046be1992a (diff) | |
download | opie-aa4539e4ccc23c47f720819e23c9a6faf53a4df8.zip opie-aa4539e4ccc23c47f720819e23c9a6faf53a4df8.tar.gz opie-aa4539e4ccc23c47f720819e23c9a6faf53a4df8.tar.bz2 |
add error dialogs
-rw-r--r-- | core/apps/textedit/textedit.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 2a4d391..8e106bf 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -756,249 +756,250 @@ void TextEdit::openFile( const DocLnk &f ) { | |||
756 | // clear(); | 756 | // clear(); |
757 | // bFromDocView = true; | 757 | // bFromDocView = true; |
758 | FileManager fm; | 758 | FileManager fm; |
759 | QString txt; | 759 | QString txt; |
760 | currentFileName=f.file(); | 760 | currentFileName=f.file(); |
761 | qDebug("openFile doclnk " + currentFileName); | 761 | qDebug("openFile doclnk " + currentFileName); |
762 | if ( !fm.loadFile( f, txt ) ) { | 762 | if ( !fm.loadFile( f, txt ) ) { |
763 | // ####### could be a new file | 763 | // ####### could be a new file |
764 | qDebug( "Cannot open file" ); | 764 | qDebug( "Cannot open file" ); |
765 | } | 765 | } |
766 | // fileNew(); | 766 | // fileNew(); |
767 | if ( doc ) | 767 | if ( doc ) |
768 | delete doc; | 768 | delete doc; |
769 | doc = new DocLnk(f); | 769 | doc = new DocLnk(f); |
770 | editor->setText(txt); | 770 | editor->setText(txt); |
771 | editor->setEdited( false); | 771 | editor->setEdited( false); |
772 | edited1=false; | 772 | edited1=false; |
773 | edited=false; | 773 | edited=false; |
774 | 774 | ||
775 | doc->setName(currentFileName); | 775 | doc->setName(currentFileName); |
776 | updateCaption(); | 776 | updateCaption(); |
777 | setTimer(); | 777 | setTimer(); |
778 | } | 778 | } |
779 | 779 | ||
780 | void TextEdit::showEditTools() { | 780 | void TextEdit::showEditTools() { |
781 | menu->show(); | 781 | menu->show(); |
782 | editBar->show(); | 782 | editBar->show(); |
783 | if(!useSearchBar) | 783 | if(!useSearchBar) |
784 | searchBar->hide(); | 784 | searchBar->hide(); |
785 | else | 785 | else |
786 | searchBar->show(); | 786 | searchBar->show(); |
787 | setWState (WState_Reserved1 ); | 787 | setWState (WState_Reserved1 ); |
788 | } | 788 | } |
789 | 789 | ||
790 | /*! | 790 | /*! |
791 | unprompted save */ | 791 | unprompted save */ |
792 | bool TextEdit::save() { | 792 | bool TextEdit::save() { |
793 | qDebug("saveAsFile " + currentFileName); | 793 | qDebug("saveAsFile " + currentFileName); |
794 | if(currentFileName.isEmpty()) { | 794 | if(currentFileName.isEmpty()) { |
795 | saveAs(); | 795 | saveAs(); |
796 | return false; | 796 | return false; |
797 | } | 797 | } |
798 | 798 | ||
799 | QString file = doc->file(); | 799 | QString file = doc->file(); |
800 | qDebug("saver file "+file); | 800 | qDebug("saver file "+file); |
801 | QString name= doc->name(); | 801 | QString name= doc->name(); |
802 | qDebug("File named "+name); | 802 | qDebug("File named "+name); |
803 | QString rt = editor->text(); | 803 | QString rt = editor->text(); |
804 | if( !rt.isEmpty() ) { | 804 | if( !rt.isEmpty() ) { |
805 | if(name.isEmpty()) { | 805 | if(name.isEmpty()) { |
806 | saveAs(); | 806 | saveAs(); |
807 | } else { | 807 | } else { |
808 | currentFileName= name ; | 808 | currentFileName= name ; |
809 | qDebug("saveFile "+currentFileName); | 809 | qDebug("saveFile "+currentFileName); |
810 | 810 | ||
811 | struct stat buf; | 811 | struct stat buf; |
812 | mode_t mode; | 812 | mode_t mode; |
813 | stat(file.latin1(), &buf); | 813 | stat(file.latin1(), &buf); |
814 | mode = buf.st_mode; | 814 | mode = buf.st_mode; |
815 | 815 | ||
816 | if(!fileIs) { | 816 | if(!fileIs) { |
817 | doc->setName( name); | 817 | doc->setName( name); |
818 | FileManager fm; | 818 | FileManager fm; |
819 | if ( !fm.saveFile( *doc, rt ) ) { | 819 | if ( !fm.saveFile( *doc, rt ) ) { |
820 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | ||
820 | return false; | 821 | return false; |
821 | } | 822 | } |
822 | } else { | 823 | } else { |
823 | qDebug("regular save file"); | 824 | qDebug("regular save file"); |
824 | QFile f(file); | 825 | QFile f(file); |
825 | if( f.open(IO_WriteOnly)) { | 826 | if( f.open(IO_WriteOnly)) { |
826 | QCString crt = rt.utf8(); | 827 | QCString crt = rt.utf8(); |
827 | f.writeBlock(crt,crt.length()); | 828 | f.writeBlock(crt,crt.length()); |
828 | } else { | 829 | } else { |
829 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 830 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
830 | return false; | 831 | return false; |
831 | } | 832 | } |
832 | 833 | ||
833 | } | 834 | } |
834 | editor->setEdited( false); | 835 | editor->setEdited( false); |
835 | edited1=false; | 836 | edited1=false; |
836 | edited=false; | 837 | edited=false; |
837 | if(caption().left(1)=="*") | 838 | if(caption().left(1)=="*") |
838 | setCaption(caption().right(caption().length()-1)); | 839 | setCaption(caption().right(caption().length()-1)); |
839 | 840 | ||
840 | 841 | ||
841 | chmod( file.latin1(), mode); | 842 | chmod( file.latin1(), mode); |
842 | } | 843 | } |
843 | return true; | 844 | return true; |
844 | } | 845 | } |
845 | return false; | 846 | return false; |
846 | } | 847 | } |
847 | 848 | ||
848 | /*! | 849 | /*! |
849 | prompted save */ | 850 | prompted save */ |
850 | bool TextEdit::saveAs() { | 851 | bool TextEdit::saveAs() { |
851 | 852 | ||
852 | if(caption() == tr("Text Editor")) | 853 | if(caption() == tr("Text Editor")) |
853 | return false; | 854 | return false; |
854 | qDebug("saveAsFile " + currentFileName); | 855 | qDebug("saveAsFile " + currentFileName); |
855 | // case of nothing to save... | 856 | // case of nothing to save... |
856 | // if ( !doc && !currentFileName.isEmpty()) { | 857 | // if ( !doc && !currentFileName.isEmpty()) { |
857 | // //|| !bFromDocView) | 858 | // //|| !bFromDocView) |
858 | // qDebug("no doc"); | 859 | // qDebug("no doc"); |
859 | // return true; | 860 | // return true; |
860 | // } | 861 | // } |
861 | // if ( !editor->edited() ) { | 862 | // if ( !editor->edited() ) { |
862 | // delete doc; | 863 | // delete doc; |
863 | // doc = 0; | 864 | // doc = 0; |
864 | // return true; | 865 | // return true; |
865 | // } | 866 | // } |
866 | 867 | ||
867 | QString rt = editor->text(); | 868 | QString rt = editor->text(); |
868 | qDebug(currentFileName); | 869 | qDebug(currentFileName); |
869 | 870 | ||
870 | if( currentFileName.isEmpty() | 871 | if( currentFileName.isEmpty() |
871 | || currentFileName == tr("Unnamed") | 872 | || currentFileName == tr("Unnamed") |
872 | || currentFileName == tr("Text Editor")) { | 873 | || currentFileName == tr("Text Editor")) { |
873 | qDebug("do silly TT filename thing"); | 874 | qDebug("do silly TT filename thing"); |
874 | // if ( doc && doc->name().isEmpty() ) { | 875 | // if ( doc && doc->name().isEmpty() ) { |
875 | QString pt = rt.simplifyWhiteSpace(); | 876 | QString pt = rt.simplifyWhiteSpace(); |
876 | int i = pt.find( ' ' ); | 877 | int i = pt.find( ' ' ); |
877 | QString docname = pt; | 878 | QString docname = pt; |
878 | if ( i > 0 ) | 879 | if ( i > 0 ) |
879 | docname = pt.left( i ); | 880 | docname = pt.left( i ); |
880 | // remove "." at the beginning | 881 | // remove "." at the beginning |
881 | while( docname.startsWith( "." ) ) | 882 | while( docname.startsWith( "." ) ) |
882 | docname = docname.mid( 1 ); | 883 | docname = docname.mid( 1 ); |
883 | docname.replace( QRegExp("/"), "_" ); | 884 | docname.replace( QRegExp("/"), "_" ); |
884 | // cut the length. filenames longer than that | 885 | // cut the length. filenames longer than that |
885 | //don't make sense and something goes wrong when they get too long. | 886 | //don't make sense and something goes wrong when they get too long. |
886 | if ( docname.length() > 40 ) | 887 | if ( docname.length() > 40 ) |
887 | docname = docname.left(40); | 888 | docname = docname.left(40); |
888 | if ( docname.isEmpty() ) | 889 | if ( docname.isEmpty() ) |
889 | docname = tr("Unnamed"); | 890 | docname = tr("Unnamed"); |
890 | if(doc) doc->setName(docname); | 891 | if(doc) doc->setName(docname); |
891 | currentFileName=docname; | 892 | currentFileName=docname; |
892 | // } | 893 | // } |
893 | // else | 894 | // else |
894 | // qDebug("hmmmmmm"); | 895 | // qDebug("hmmmmmm"); |
895 | } | 896 | } |
896 | 897 | ||
897 | 898 | ||
898 | QMap<QString, QStringList> map; | 899 | QMap<QString, QStringList> map; |
899 | map.insert(tr("All"), QStringList() ); | 900 | map.insert(tr("All"), QStringList() ); |
900 | QStringList text; | 901 | QStringList text; |
901 | text << "text/*"; | 902 | text << "text/*"; |
902 | map.insert(tr("Text"), text ); | 903 | map.insert(tr("Text"), text ); |
903 | text << "*"; | 904 | text << "*"; |
904 | map.insert(tr("All"), text ); | 905 | map.insert(tr("All"), text ); |
905 | 906 | ||
906 | QFileInfo cuFi( currentFileName); | 907 | QFileInfo cuFi( currentFileName); |
907 | QString filee = cuFi.fileName(); | 908 | QString filee = cuFi.fileName(); |
908 | QString dire = cuFi.dirPath(); | 909 | QString dire = cuFi.dirPath(); |
909 | if(dire==".") | 910 | if(dire==".") |
910 | dire = QPEApplication::documentDir(); | 911 | dire = QPEApplication::documentDir(); |
911 | QString str; | 912 | QString str; |
912 | if( !featureAutoSave) | 913 | if( !featureAutoSave) { |
913 | { | ||
914 | str = OFileDialog::getSaveFileName( 2, | 914 | str = OFileDialog::getSaveFileName( 2, |
915 | dire, | 915 | dire, |
916 | filee, map); | 916 | filee, map); |
917 | } | 917 | } else |
918 | else | ||
919 | str=currentFileName; | 918 | str=currentFileName; |
919 | |||
920 | if(!str.isEmpty()) { | 920 | if(!str.isEmpty()) { |
921 | QString fileNm=str; | 921 | QString fileNm=str; |
922 | 922 | ||
923 | qDebug("saving filename "+fileNm); | 923 | qDebug("saving filename "+fileNm); |
924 | QFileInfo fi(fileNm); | 924 | QFileInfo fi(fileNm); |
925 | currentFileName=fi.fileName(); | 925 | currentFileName=fi.fileName(); |
926 | if(doc) | 926 | if(doc) |
927 | // QString file = doc->file(); | 927 | // QString file = doc->file(); |
928 | // doc->removeFiles(); | 928 | // doc->removeFiles(); |
929 | delete doc; | 929 | delete doc; |
930 | DocLnk nf; | 930 | DocLnk nf; |
931 | nf.setType("text/plain"); | 931 | nf.setType("text/plain"); |
932 | nf.setFile( fileNm); | 932 | nf.setFile( fileNm); |
933 | doc = new DocLnk(nf); | 933 | doc = new DocLnk(nf); |
934 | // editor->setText(rt); | 934 | // editor->setText(rt); |
935 | qDebug("Saving file as "+currentFileName); | 935 | qDebug("Saving file as "+currentFileName); |
936 | doc->setName( currentFileName); | 936 | doc->setName( currentFileName); |
937 | updateCaption( currentFileName); | 937 | updateCaption( currentFileName); |
938 | 938 | ||
939 | FileManager fm; | 939 | FileManager fm; |
940 | if ( !fm.saveFile( *doc, rt ) ) { | 940 | if ( !fm.saveFile( *doc, rt ) ) { |
941 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | ||
941 | return false; | 942 | return false; |
942 | } | 943 | } |
943 | 944 | ||
944 | if( filePerms ) { | 945 | if( filePerms ) { |
945 | filePermissions *filePerm; | 946 | filePermissions *filePerm; |
946 | filePerm = new filePermissions(this, | 947 | filePerm = new filePermissions(this, |
947 | tr("Permissions"),true, | 948 | tr("Permissions"),true, |
948 | 0,(const QString &)fileNm); | 949 | 0,(const QString &)fileNm); |
949 | QPEApplication::execDialog( filePerm ); | 950 | QPEApplication::execDialog( filePerm ); |
950 | 951 | ||
951 | if( filePerm) | 952 | if( filePerm) |
952 | delete filePerm; | 953 | delete filePerm; |
953 | } | 954 | } |
954 | // } | 955 | // } |
955 | editor->setEdited( false); | 956 | editor->setEdited( false); |
956 | edited1 = false; | 957 | edited1 = false; |
957 | edited = false; | 958 | edited = false; |
958 | if(caption().left(1)=="*") | 959 | if(caption().left(1)=="*") |
959 | setCaption(caption().right(caption().length()-1)); | 960 | setCaption(caption().right(caption().length()-1)); |
960 | 961 | ||
961 | return true; | 962 | return true; |
962 | } | 963 | } |
963 | qDebug("returning false"); | 964 | qDebug("returning false"); |
964 | return false; | 965 | return false; |
965 | } //end saveAs | 966 | } //end saveAs |
966 | 967 | ||
967 | void TextEdit::clear() { | 968 | void TextEdit::clear() { |
968 | delete doc; | 969 | delete doc; |
969 | doc = 0; | 970 | doc = 0; |
970 | editor->clear(); | 971 | editor->clear(); |
971 | } | 972 | } |
972 | 973 | ||
973 | void TextEdit::updateCaption( const QString &name ) { | 974 | void TextEdit::updateCaption( const QString &name ) { |
974 | 975 | ||
975 | if ( name.isEmpty() ) | 976 | if ( name.isEmpty() ) |
976 | setCaption( tr("Text Editor") ); | 977 | setCaption( tr("Text Editor") ); |
977 | else { | 978 | else { |
978 | QString s = name; | 979 | QString s = name; |
979 | if ( s.isNull() ) | 980 | if ( s.isNull() ) |
980 | s = doc->name(); | 981 | s = doc->name(); |
981 | if ( s.isEmpty() ) { | 982 | if ( s.isEmpty() ) { |
982 | s = tr( "Unnamed" ); | 983 | s = tr( "Unnamed" ); |
983 | currentFileName=s; | 984 | currentFileName=s; |
984 | } | 985 | } |
985 | // if(s.left(1) == "/") | 986 | // if(s.left(1) == "/") |
986 | // s = s.right(s.length()-1); | 987 | // s = s.right(s.length()-1); |
987 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 988 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
988 | } | 989 | } |
989 | } | 990 | } |
990 | 991 | ||
991 | void TextEdit::setDocument(const QString& fileref) { | 992 | void TextEdit::setDocument(const QString& fileref) { |
992 | if(fileref != "Unnamed") { | 993 | if(fileref != "Unnamed") { |
993 | currentFileName=fileref; | 994 | currentFileName=fileref; |
994 | qDebug("setDocument"); | 995 | qDebug("setDocument"); |
995 | QFileInfo fi(currentFileName); | 996 | QFileInfo fi(currentFileName); |
996 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 997 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
997 | if( (fi.baseName().left(1)).isEmpty() ) { | 998 | if( (fi.baseName().left(1)).isEmpty() ) { |
998 | openDotFile(currentFileName); | 999 | openDotFile(currentFileName); |
999 | 1000 | ||
1000 | } else { | 1001 | } else { |
1001 | qDebug("setDoc open"); | 1002 | qDebug("setDoc open"); |
1002 | bFromDocView = true; | 1003 | bFromDocView = true; |
1003 | openFile(fileref); | 1004 | openFile(fileref); |
1004 | editor->setEdited(true); | 1005 | editor->setEdited(true); |