Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index c869dc9..515fcdc 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -13,24 +13,25 @@ | |||
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
21 | 21 | ||
22 | #include "textedit.h" | 22 | #include "textedit.h" |
23 | #include "fileBrowser.h" | 23 | #include "fileBrowser.h" |
24 | #include "fileSaver.h" | 24 | #include "fileSaver.h" |
25 | #include "filePermissions.h" | ||
25 | 26 | ||
26 | #include "fontDialog.h" | 27 | #include "fontDialog.h" |
27 | 28 | ||
28 | #include <qpe/fontdatabase.h> | 29 | #include <qpe/fontdatabase.h> |
29 | #include <qpe/global.h> | 30 | #include <qpe/global.h> |
30 | #include <qpe/fileselector.h> | 31 | #include <qpe/fileselector.h> |
31 | #include <qpe/applnk.h> | 32 | #include <qpe/applnk.h> |
32 | #include <qpe/resource.h> | 33 | #include <qpe/resource.h> |
33 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
34 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/qpemenubar.h> | 36 | #include <qpe/qpemenubar.h> |
36 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
@@ -38,24 +39,27 @@ | |||
38 | 39 | ||
39 | #include <qstringlist.h> | 40 | #include <qstringlist.h> |
40 | #include <qaction.h> | 41 | #include <qaction.h> |
41 | #include <qcolordialog.h> | 42 | #include <qcolordialog.h> |
42 | #include <qfileinfo.h> | 43 | #include <qfileinfo.h> |
43 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
44 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
45 | #include <qobjectlist.h> | 46 | #include <qobjectlist.h> |
46 | #include <qpopupmenu.h> | 47 | #include <qpopupmenu.h> |
47 | #include <qspinbox.h> | 48 | #include <qspinbox.h> |
48 | #include <qtoolbutton.h> | 49 | #include <qtoolbutton.h> |
49 | #include <qwidgetstack.h> | 50 | #include <qwidgetstack.h> |
51 | #include <qcheckbox.h> | ||
52 | #include <unistd.h> | ||
53 | #include <sys/stat.h> | ||
50 | 54 | ||
51 | #include <stdlib.h> //getenv | 55 | #include <stdlib.h> //getenv |
52 | /* XPM */ | 56 | /* XPM */ |
53 | static char * filesave_xpm[] = { | 57 | static char * filesave_xpm[] = { |
54 | "16 16 78 1", | 58 | "16 16 78 1", |
55 | " c None", | 59 | " c None", |
56 | ". c #343434", | 60 | ". c #343434", |
57 | "+ c #A0A0A0", | 61 | "+ c #A0A0A0", |
58 | "@ c #565656", | 62 | "@ c #565656", |
59 | "# c #9E9E9E", | 63 | "# c #9E9E9E", |
60 | "$ c #525252", | 64 | "$ c #525252", |
61 | "% c #929292", | 65 | "% c #929292", |
@@ -406,25 +410,25 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
406 | 410 | ||
407 | defaultFont = fdb.font(family,style,i_size,charSet); | 411 | defaultFont = fdb.font(family,style,i_size,charSet); |
408 | editor->setFont( defaultFont); | 412 | editor->setFont( defaultFont); |
409 | 413 | ||
410 | wa->setOn(wrap); | 414 | wa->setOn(wrap); |
411 | updateCaption(); | 415 | updateCaption(); |
412 | 416 | ||
413 | fileNew(); | 417 | fileNew(); |
414 | } | 418 | } |
415 | 419 | ||
416 | TextEdit::~TextEdit() | 420 | TextEdit::~TextEdit() |
417 | { | 421 | { |
418 | // saveAs(); | 422 | // save(); |
419 | 423 | ||
420 | Config cfg("TextEdit"); | 424 | Config cfg("TextEdit"); |
421 | cfg.setGroup("View"); | 425 | cfg.setGroup("View"); |
422 | QFont f = editor->font(); | 426 | QFont f = editor->font(); |
423 | cfg.writeEntry("FontSize",f.pointSize()); | 427 | cfg.writeEntry("FontSize",f.pointSize()); |
424 | cfg.writeEntry("Bold",f.bold()); | 428 | cfg.writeEntry("Bold",f.bold()); |
425 | cfg.writeEntry("Italic",f.italic()); | 429 | cfg.writeEntry("Italic",f.italic()); |
426 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 430 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
427 | } | 431 | } |
428 | 432 | ||
429 | void TextEdit::zoomIn() | 433 | void TextEdit::zoomIn() |
430 | { | 434 | { |
@@ -685,45 +689,50 @@ void TextEdit::showEditTools() | |||
685 | searchBar->show(); | 689 | searchBar->show(); |
686 | // updateCaption(); | 690 | // updateCaption(); |
687 | editorStack->raiseWidget( editor ); | 691 | editorStack->raiseWidget( editor ); |
688 | setWState (WState_Reserved1 ); | 692 | setWState (WState_Reserved1 ); |
689 | } | 693 | } |
690 | 694 | ||
691 | /*! | 695 | /*! |
692 | unprompted save */ | 696 | unprompted save */ |
693 | bool TextEdit::save() | 697 | bool TextEdit::save() |
694 | { | 698 | { |
695 | QString file = doc->file(); | 699 | QString file = doc->file(); |
696 | QString name= doc->name(); | 700 | QString name= doc->name(); |
701 | |||
697 | QString rt = editor->text(); | 702 | QString rt = editor->text(); |
698 | currentFileName= name ; | 703 | currentFileName= name ; |
699 | qDebug("saveFile "+currentFileName); | 704 | qDebug("saveFile "+currentFileName); |
700 | 705 | ||
706 | struct stat buf; | ||
707 | mode_t mode; | ||
708 | lstat(file.latin1(), &buf); | ||
709 | mode = buf.st_mode; | ||
710 | |||
701 | doc->setName( name); | 711 | doc->setName( name); |
702 | FileManager fm; | 712 | FileManager fm; |
703 | if ( !fm.saveFile( *doc, rt ) ) { | 713 | if ( !fm.saveFile( *doc, rt ) ) { |
704 | return false; | 714 | return false; |
705 | } | 715 | } |
706 | // if(doc) | ||
707 | // delete doc; | ||
708 | // doc = 0; | ||
709 | editor->setEdited( false ); | 716 | editor->setEdited( false ); |
717 | |||
718 | chmod( file.latin1(), mode); | ||
710 | return true; | 719 | return true; |
711 | } | 720 | } |
712 | 721 | ||
713 | /*! | 722 | /*! |
714 | prompted save */ | 723 | prompted save */ |
715 | bool TextEdit::saveAs() | 724 | bool TextEdit::saveAs() |
716 | { | 725 | { |
717 | qDebug("saveAsFile "+currentFileName); | 726 | // qDebug("saveAsFile "+currentFileName); |
718 | 727 | ||
719 | // case of nothing to save... /// there's always something to save | 728 | // case of nothing to save... /// there's always something to save |
720 | // if ( !doc )//|| !bFromDocView) | 729 | // if ( !doc )//|| !bFromDocView) |
721 | // { | 730 | // { |
722 | // qDebug("no doc"); | 731 | // qDebug("no doc"); |
723 | // return true; | 732 | // return true; |
724 | // } | 733 | // } |
725 | if ( !editor->edited() ) { | 734 | if ( !editor->edited() ) { |
726 | delete doc; | 735 | delete doc; |
727 | doc = 0; | 736 | doc = 0; |
728 | return true; | 737 | return true; |
729 | } | 738 | } |
@@ -744,57 +753,64 @@ bool TextEdit::saveAs() | |||
744 | docname = docname.mid( 1 ); | 753 | docname = docname.mid( 1 ); |
745 | docname.replace( QRegExp("/"), "_" ); | 754 | docname.replace( QRegExp("/"), "_" ); |
746 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 755 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
747 | if ( docname.length() > 40 ) | 756 | if ( docname.length() > 40 ) |
748 | docname = docname.left(40); | 757 | docname = docname.left(40); |
749 | if ( docname.isEmpty() ) | 758 | if ( docname.isEmpty() ) |
750 | docname = "Unnamed"; | 759 | docname = "Unnamed"; |
751 | doc->setName(docname); | 760 | doc->setName(docname); |
752 | currentFileName=docname; | 761 | currentFileName=docname; |
753 | } | 762 | } |
754 | } | 763 | } |
755 | 764 | ||
765 | |||
756 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 766 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
757 | qDebug("wanna save filename "+currentFileName); | 767 | qDebug("wanna save filename "+currentFileName); |
758 | fileSaveDlg->exec(); | 768 | fileSaveDlg->exec(); |
759 | if( fileSaveDlg->result() == 1 ) { | 769 | if( fileSaveDlg->result() == 1 ) { |
760 | QString fileNm=fileSaveDlg->selectedFileName; | 770 | QString fileNm=fileSaveDlg->selectedFileName; |
761 | qDebug("saving filename "+fileNm); | 771 | qDebug("saving filename "+fileNm); |
762 | QFileInfo fi(fileNm); | 772 | QFileInfo fi(fileNm); |
763 | currentFileName=fi.fileName(); | 773 | currentFileName=fi.fileName(); |
764 | if(doc) { | 774 | if(doc) { |
765 | qDebug("doclnk exists"); | 775 | qDebug("doclnk exists"); |
766 | // QString file = doc->file(); | 776 | // QString file = doc->file(); |
767 | // doc->removeFiles(); | 777 | // doc->removeFiles(); |
768 | delete doc; | 778 | delete doc; |
769 | DocLnk nf; | 779 | DocLnk nf; |
770 | nf.setType("text/plain"); | 780 | nf.setType("text/plain"); |
771 | nf.setFile( fileNm); | 781 | nf.setFile( fileNm); |
772 | doc = new DocLnk(nf); | 782 | doc = new DocLnk(nf); |
773 | // editor->setText(rt); | 783 | // editor->setText(rt); |
774 | qDebug("openFile doclnk "+currentFileName); | 784 | qDebug("openFile doclnk "+currentFileName); |
775 | } | 785 | doc->setName( currentFileName); |
776 | doc->setName( currentFileName); | 786 | updateCaption( currentFileName); |
777 | updateCaption( currentFileName); | 787 | |
778 | 788 | FileManager fm; | |
779 | FileManager fm; | 789 | if ( !fm.saveFile( *doc, rt ) ) { |
780 | if ( !fm.saveFile( *doc, rt ) ) { | 790 | return false; |
781 | return false; | 791 | } |
782 | } | 792 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
783 | // delete doc; | 793 | filePermissions *filePerm; |
784 | // doc = 0; | 794 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); |
785 | editor->setEdited( false ); | 795 | filePerm->exec(); |
796 | editor->setEdited( false ); | ||
797 | if( filePerm) | ||
798 | delete filePerm; | ||
799 | } | ||
800 | } | ||
786 | } | 801 | } |
802 | |||
787 | if(fileSaveDlg) | 803 | if(fileSaveDlg) |
788 | delete fileSaveDlg; | 804 | delete fileSaveDlg; |
789 | return true; | 805 | return true; |
790 | } | 806 | } |
791 | 807 | ||
792 | void TextEdit::clear() | 808 | void TextEdit::clear() |
793 | { | 809 | { |
794 | delete doc; | 810 | delete doc; |
795 | doc = 0; | 811 | doc = 0; |
796 | editor->clear(); | 812 | editor->clear(); |
797 | } | 813 | } |
798 | 814 | ||
799 | void TextEdit::updateCaption( const QString &name ) | 815 | void TextEdit::updateCaption( const QString &name ) |
800 | { | 816 | { |
@@ -826,24 +842,25 @@ void TextEdit::closeEvent( QCloseEvent *e ) | |||
826 | e->ignore(); | 842 | e->ignore(); |
827 | repaint(); | 843 | repaint(); |
828 | // fileRevert(); | 844 | // fileRevert(); |
829 | 845 | ||
830 | } else { | 846 | } else { |
831 | bFromDocView = FALSE; | 847 | bFromDocView = FALSE; |
832 | e->accept(); | 848 | e->accept(); |
833 | } | 849 | } |
834 | } | 850 | } |
835 | 851 | ||
836 | void TextEdit::accept() | 852 | void TextEdit::accept() |
837 | { | 853 | { |
854 | save(); | ||
838 | close(); | 855 | close(); |
839 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | 856 | // fileOpen(); //godamn thats obnoxious! lemme out!!! |
840 | } | 857 | } |
841 | 858 | ||
842 | void TextEdit::changeFont() { | 859 | void TextEdit::changeFont() { |
843 | FontDatabase fdb; | 860 | FontDatabase fdb; |
844 | QFont defaultFont=editor->font(); | 861 | QFont defaultFont=editor->font(); |
845 | QFontInfo fontInfo(defaultFont); | 862 | QFontInfo fontInfo(defaultFont); |
846 | Config cfg("TextEdit"); | 863 | Config cfg("TextEdit"); |
847 | cfg.setGroup("Font"); | 864 | cfg.setGroup("Font"); |
848 | QString family = cfg.readEntry("Family", fontInfo.family()); | 865 | QString family = cfg.readEntry("Family", fontInfo.family()); |
849 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 866 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |