summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/helpbrowser/helpbrowser.cpp15
-rw-r--r--core/apps/textedit/textedit.cpp31
2 files changed, 26 insertions, 20 deletions
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp
index 4bd9565..c2059c0 100644
--- a/core/apps/helpbrowser/helpbrowser.cpp
+++ b/core/apps/helpbrowser/helpbrowser.cpp
@@ -1,228 +1,233 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22 22
23#include "helpbrowser.h" 23#include "helpbrowser.h"
24#include "magictextbrowser.h" 24#include "magictextbrowser.h"
25 25
26/* OPIE */ 26/* OPIE */
27#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28#include <opie2/oresource.h>
29
28#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
29#include <qpe/resource.h> 31
30using namespace Opie::Core; 32using namespace Opie::Core;
31 33
32/* QT */ 34/* QT */
33#include <qmenubar.h> 35#include <qmenubar.h>
34#include <qtoolbar.h> 36#include <qtoolbar.h>
35#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
36#include <qfileinfo.h> 38#include <qfileinfo.h>
37#include <qaction.h> 39#include <qaction.h>
38 40
39HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) 41HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f )
40 : QMainWindow( parent, name, f ), 42 : QMainWindow( parent, name, f ),
41 selectedURL() 43 selectedURL()
42{ 44{
43 init( "index.html" ); 45 init( "index.html" );
44} 46}
45 47
46 48
47 49
48void HelpBrowser::init( const QString& _home ) 50void HelpBrowser::init( const QString& _home )
49{ 51{
50 setIcon( Resource::loadPixmap( "HelpBrowser" ) ); 52 setIcon( Opie::Core::OResource::loadPixmap( "HelpBrowser", Opie::Core::OResource::SmallIcon ) );
51 setBackgroundMode( PaletteButton ); 53 setBackgroundMode( PaletteButton );
52 54
53 browser = new MagicTextBrowser( this ); 55 browser = new MagicTextBrowser( this );
54 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 56 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
55 connect( browser, SIGNAL( textChanged() ), 57 connect( browser, SIGNAL( textChanged() ),
56 this, SLOT( textChanged() ) ); 58 this, SLOT( textChanged() ) );
57 59
58 setCentralWidget( browser ); 60 setCentralWidget( browser );
59 setToolBarsMovable( FALSE ); 61 setToolBarsMovable( FALSE );
60 62
61 if ( !_home.isEmpty() ) 63 if ( !_home.isEmpty() )
62 browser->setSource( _home ); 64 browser->setSource( _home );
63 65
64 QToolBar* toolbar = new QToolBar( this ); 66 QToolBar* toolbar = new QToolBar( this );
65 toolbar->setHorizontalStretchable( TRUE ); 67 toolbar->setHorizontalStretchable( TRUE );
66 QMenuBar *menu = new QMenuBar( toolbar ); 68 QMenuBar *menu = new QMenuBar( toolbar );
67 69
68 toolbar = new QToolBar( this ); 70 toolbar = new QToolBar( this );
69 // addToolBar( toolbar, "Toolbar"); 71 // addToolBar( toolbar, "Toolbar");
70 72
71 QPopupMenu* go = new QPopupMenu( this ); 73 QPopupMenu* go = new QPopupMenu( this );
72 backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); 74 backAction = new QAction( tr( "Backward" ), Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ),
75 QString::null, 0, this, 0 );
73 connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); 76 connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) );
74 connect( browser, SIGNAL( backwardAvailable(bool) ), 77 connect( browser, SIGNAL( backwardAvailable(bool) ),
75 backAction, SLOT( setEnabled(bool) ) ); 78 backAction, SLOT( setEnabled(bool) ) );
76 backAction->addTo( go ); 79 backAction->addTo( go );
77 backAction->addTo( toolbar ); 80 backAction->addTo( toolbar );
78 backAction->setEnabled( FALSE ); 81 backAction->setEnabled( FALSE );
79 82
80 forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); 83 forwardAction = new QAction( tr( "Forward" ), Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ),
84 QString::null, 0, this, 0 );
81 connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); 85 connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) );
82 connect( browser, SIGNAL( forwardAvailable(bool) ), 86 connect( browser, SIGNAL( forwardAvailable(bool) ),
83 forwardAction, SLOT( setEnabled(bool) ) ); 87 forwardAction, SLOT( setEnabled(bool) ) );
84 forwardAction->addTo( go ); 88 forwardAction->addTo( go );
85 forwardAction->addTo( toolbar ); 89 forwardAction->addTo( toolbar );
86 forwardAction->setEnabled( FALSE ); 90 forwardAction->setEnabled( FALSE );
87 91
88 QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); 92 QAction *a = new QAction( tr( "Home" ), Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ),
93 QString::null, 0, this, 0 );
89 connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); 94 connect( a, SIGNAL( activated() ), browser, SLOT( home() ) );
90 a->addTo( go ); 95 a->addTo( go );
91 a->addTo( toolbar ); 96 a->addTo( toolbar );
92 97
93 bookm = new QPopupMenu( this ); 98 bookm = new QPopupMenu( this );
94 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); 99 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
95 bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); 100 bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) );
96 bookm->insertSeparator(); 101 bookm->insertSeparator();
97 connect( bookm, SIGNAL( activated(int) ), 102 connect( bookm, SIGNAL( activated(int) ),
98 this, SLOT( bookmChosen(int) ) ); 103 this, SLOT( bookmChosen(int) ) );
99 104
100 readBookmarks(); 105 readBookmarks();
101 106
102 menu->insertItem( tr("Go"), go ); 107 menu->insertItem( tr("Go"), go );
103 menu->insertItem( tr( "Bookmarks" ), bookm ); 108 menu->insertItem( tr( "Bookmarks" ), bookm );
104 109
105 resize( 240, 300 ); 110 resize( 240, 300 );
106 browser->setFocus(); 111 browser->setFocus();
107 browser->setFrameStyle( QFrame::NoFrame ); 112 browser->setFrameStyle( QFrame::NoFrame );
108 113
109#if !defined(QT_NO_COP) 114#if !defined(QT_NO_COP)
110 QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); 115 QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this );
111 connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)), 116 connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)),
112 this, SLOT ( appMessage(const QCString&,const QByteArray&) ) ); 117 this, SLOT ( appMessage(const QCString&,const QByteArray&) ) );
113#endif 118#endif
114 119
115 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 120 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
116 this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 121 this, SLOT(appMessage(const QCString&,const QByteArray&)) );
117} 122}
118 123
119void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) 124void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data)
120{ 125{
121 if ( msg == "showFile(QString)" ) { 126 if ( msg == "showFile(QString)" ) {
122 QDataStream ds(data,IO_ReadOnly); 127 QDataStream ds(data,IO_ReadOnly);
123 QString fn; 128 QString fn;
124 ds >> fn; 129 ds >> fn;
125 setDocument( fn ); 130 setDocument( fn );
126 131
127 QPEApplication::setKeepRunning(); 132 QPEApplication::setKeepRunning();
128 133
129 showMaximized(); 134 showMaximized();
130 setActiveWindow(); 135 setActiveWindow();
131 raise(); 136 raise();
132 } 137 }
133} 138}
134 139
135void HelpBrowser::setDocument( const QString &doc ) 140void HelpBrowser::setDocument( const QString &doc )
136{ 141{
137 if ( !doc.isEmpty() ) 142 if ( !doc.isEmpty() )
138 browser->setSource( doc ); 143 browser->setSource( doc );
139 raise(); 144 raise();
140} 145}
141 146
142 147
143void HelpBrowser::textChanged() 148void HelpBrowser::textChanged()
144{ 149{
145 if ( browser->documentTitle().isNull() ) 150 if ( browser->documentTitle().isNull() )
146 setCaption( tr("Help Browser") ); 151 setCaption( tr("Help Browser") );
147 else 152 else
148 setCaption( browser->documentTitle() ) ; 153 setCaption( browser->documentTitle() ) ;
149 154
150 selectedURL = caption(); 155 selectedURL = caption();
151} 156}
152 157
153HelpBrowser::~HelpBrowser() 158HelpBrowser::~HelpBrowser()
154{ 159{
155 QStringList bookmarks; 160 QStringList bookmarks;
156 QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); 161 QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin();
157 for ( ; it2 != mBookmarks.end(); ++it2 ) 162 for ( ; it2 != mBookmarks.end(); ++it2 )
158 bookmarks.append( (*it2).name + "=" + (*it2).file ); 163 bookmarks.append( (*it2).name + "=" + (*it2).file );
159 164
160 QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); 165 QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") );
161 if ( f2.open( IO_WriteOnly ) ) { 166 if ( f2.open( IO_WriteOnly ) ) {
162 QDataStream s2( &f2 ); 167 QDataStream s2( &f2 );
163 s2 << bookmarks; 168 s2 << bookmarks;
164 f2.close(); 169 f2.close();
165 } 170 }
166} 171}
167 172
168void HelpBrowser::pathSelected( const QString &_path ) 173void HelpBrowser::pathSelected( const QString &_path )
169{ 174{
170 browser->setSource( _path ); 175 browser->setSource( _path );
171} 176}
172 177
173void HelpBrowser::readBookmarks() 178void HelpBrowser::readBookmarks()
174{ 179{
175 QString file = Global::applicationFileName("helpbrowser", "bookmarks"); 180 QString file = Global::applicationFileName("helpbrowser", "bookmarks");
176 if ( QFile::exists( file ) ) { 181 if ( QFile::exists( file ) ) {
177 QStringList bookmarks; 182 QStringList bookmarks;
178 QFile f( file ); 183 QFile f( file );
179 if ( f.open( IO_ReadOnly ) ) { 184 if ( f.open( IO_ReadOnly ) ) {
180 QDataStream s( &f ); 185 QDataStream s( &f );
181 s >> bookmarks; 186 s >> bookmarks;
182 f.close(); 187 f.close();
183 } 188 }
184 QStringList::Iterator it = bookmarks.begin(); 189 QStringList::Iterator it = bookmarks.begin();
185 for ( ; it != bookmarks.end(); ++it ) { 190 for ( ; it != bookmarks.end(); ++it ) {
186 Bookmark b; 191 Bookmark b;
187 QString current = *it; 192 QString current = *it;
188 int equal = current.find( "=" ); 193 int equal = current.find( "=" );
189 if ( equal < 1 || equal == (int)current.length() - 1 ) 194 if ( equal < 1 || equal == (int)current.length() - 1 )
190 continue; 195 continue;
191 b.name = current.left( equal ); 196 b.name = current.left( equal );
192 b.file = current.mid( equal + 1 ); 197 b.file = current.mid( equal + 1 );
193 mBookmarks[ bookm->insertItem( b.name ) ] = b; 198 mBookmarks[ bookm->insertItem( b.name ) ] = b;
194 } 199 }
195 } 200 }
196} 201}
197 202
198void HelpBrowser::bookmChosen( int i ) 203void HelpBrowser::bookmChosen( int i )
199{ 204{
200 if ( mBookmarks.contains( i ) ) 205 if ( mBookmarks.contains( i ) )
201 browser->setSource( mBookmarks[ i ].file ); 206 browser->setSource( mBookmarks[ i ].file );
202} 207}
203 208
204void HelpBrowser::addBookmark() 209void HelpBrowser::addBookmark()
205{ 210{
206 Bookmark b; 211 Bookmark b;
207 b.name = browser->documentTitle(); 212 b.name = browser->documentTitle();
208 b.file = browser->source(); 213 b.file = browser->source();
209 if (b.name.isEmpty() ) { 214 if (b.name.isEmpty() ) {
210 b.name = b.file.left( b.file.length() - 5 ); // remove .html 215 b.name = b.file.left( b.file.length() - 5 ); // remove .html
211 } 216 }
212 QMap<int, Bookmark>::Iterator it; 217 QMap<int, Bookmark>::Iterator it;
213 for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) 218 for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it )
214 if ( (*it).file == b.file ) return; 219 if ( (*it).file == b.file ) return;
215 mBookmarks[ bookm->insertItem( b.name ) ] = b; 220 mBookmarks[ bookm->insertItem( b.name ) ] = b;
216} 221}
217 222
218void HelpBrowser::removeBookmark() 223void HelpBrowser::removeBookmark()
219{ 224{
220 QString file = browser->source(); 225 QString file = browser->source();
221 QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); 226 QMap<int, Bookmark>::Iterator it = mBookmarks.begin();
222 for( ; it != mBookmarks.end(); ++it ) 227 for( ; it != mBookmarks.end(); ++it )
223 if ( (*it).file == file ) { 228 if ( (*it).file == file ) {
224 bookm->removeItem( it.key() ); 229 bookm->removeItem( it.key() );
225 mBookmarks.remove( it ); 230 mBookmarks.remove( it );
226 break; 231 break;
227 } 232 }
228} 233}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 63709dd..ca760bb 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,1211 +1,1212 @@
1/********************************************************************** 1/**********************************************************************
2// textedit.cpp 2// textedit.cpp
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 3** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 4**
5** This file is part of Opie Environment. 5** This file is part of Opie Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13// changes added by L. J. Potter Sun 02-17-2002 21:31:31 13// changes added by L. J. Potter Sun 02-17-2002 21:31:31
14 14
15#include "textedit.h" 15#include "textedit.h"
16#include "filePermissions.h" 16#include "filePermissions.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/odebug.h> 19#include <opie2/odebug.h>
20#include <opie2/ofileselector.h> 20#include <opie2/ofileselector.h>
21#include <opie2/ofiledialog.h> 21#include <opie2/ofiledialog.h>
22#include <opie2/ofontselector.h> 22#include <opie2/ofontselector.h>
23#include <qpe/resource.h> 23#include <opie2/oresource.h>
24
24#include <qpe/config.h> 25#include <qpe/config.h>
25#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
26 27
27 28
28/* QT */ 29/* QT */
29#include <qmenubar.h> 30#include <qmenubar.h>
30#include <qtoolbar.h> 31#include <qtoolbar.h>
31#include <qtextstream.h> 32#include <qtextstream.h>
32#include <qclipboard.h> 33#include <qclipboard.h>
33#include <qaction.h> 34#include <qaction.h>
34#include <qlineedit.h> 35#include <qlineedit.h>
35#include <qmessagebox.h> 36#include <qmessagebox.h>
36#include <qlayout.h> 37#include <qlayout.h>
37#include <qtimer.h> 38#include <qtimer.h>
38#include <qdir.h> 39#include <qdir.h>
39 40
40/* STD */ 41/* STD */
41#include <unistd.h> 42#include <unistd.h>
42#include <sys/stat.h> 43#include <sys/stat.h>
43#include <stdlib.h> //getenv 44#include <stdlib.h> //getenv
44 45
45using namespace Opie::Core; 46using namespace Opie::Core;
46using namespace Opie::Ui; 47using namespace Opie::Ui;
47 48
48#if QT_VERSION < 0x030000 49#if QT_VERSION < 0x030000
49class QpeEditor : public QMultiLineEdit 50class QpeEditor : public QMultiLineEdit
50{ 51{
51 52
52public: 53public:
53 QpeEditor( QWidget *parent, const char * name = 0 ) 54 QpeEditor( QWidget *parent, const char * name = 0 )
54 : QMultiLineEdit( parent, name ) { 55 : QMultiLineEdit( parent, name ) {
55 clearTableFlags(); 56 clearTableFlags();
56 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 57 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
57} 58}
58 59
59 void find( const QString &txt, bool caseSensitive, 60 void find( const QString &txt, bool caseSensitive,
60 bool backwards ); 61 bool backwards );
61protected: 62protected:
62 bool markIt; 63 bool markIt;
63 int line1, line2, col1, col2; 64 int line1, line2, col1, col2;
64 void mousePressEvent( QMouseEvent * ); 65 void mousePressEvent( QMouseEvent * );
65 void mouseReleaseEvent( QMouseEvent * ); 66 void mouseReleaseEvent( QMouseEvent * );
66 67
67//public slots: 68//public slots:
68 /* 69 /*
69signals: 70signals:
70 void notFound(); 71 void notFound();
71 void searchWrapped(); 72 void searchWrapped();
72 */ 73 */
73 74
74private: 75private:
75 76
76}; 77};
77 78
78void QpeEditor::mousePressEvent( QMouseEvent *e ) { 79void QpeEditor::mousePressEvent( QMouseEvent *e ) {
79 switch(e->button()) { 80 switch(e->button()) {
80 case RightButton: 81 case RightButton:
81 { //rediculous workaround for qt popup menu 82 { //rediculous workaround for qt popup menu
82 //and the hold right click mechanism 83 //and the hold right click mechanism
83 this->setSelection( line1, col1, line2, col2); 84 this->setSelection( line1, col1, line2, col2);
84 QMultiLineEdit::mousePressEvent( e ); 85 QMultiLineEdit::mousePressEvent( e );
85 markIt = false; 86 markIt = false;
86 } 87 }
87 break; 88 break;
88 default: 89 default:
89 { 90 {
90 if(!markIt) { 91 if(!markIt) {
91 int line, col; 92 int line, col;
92 this->getCursorPosition(&line, &col); 93 this->getCursorPosition(&line, &col);
93 line1=line2=line; 94 line1=line2=line;
94 col1=col2=col; 95 col1=col2=col;
95 } 96 }
96 QMultiLineEdit::mousePressEvent( e ); 97 QMultiLineEdit::mousePressEvent( e );
97 } 98 }
98 break; 99 break;
99 }; 100 };
100} 101}
101 102
102void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { 103void QpeEditor::mouseReleaseEvent( QMouseEvent * ) {
103 if(this->hasMarkedText()) { 104 if(this->hasMarkedText()) {
104 markIt = true; 105 markIt = true;
105 this->getMarkedRegion( &line1, &col1, &line2, & col2 ); 106 this->getMarkedRegion( &line1, &col1, &line2, & col2 );
106 } else { 107 } else {
107 markIt = false; 108 markIt = false;
108 } 109 }
109} 110}
110 111
111void QpeEditor::find ( const QString &txt, bool caseSensitive, 112void QpeEditor::find ( const QString &txt, bool caseSensitive,
112 bool backwards ) 113 bool backwards )
113{ 114{
114 static bool wrap = false; 115 static bool wrap = false;
115 int line, col; 116 int line, col;
116 if ( wrap ) { 117 if ( wrap ) {
117 if ( !backwards ) 118 if ( !backwards )
118 line = col = 0; 119 line = col = 0;
119 wrap = false; 120 wrap = false;
120 // emit searchWrapped(); 121 // emit searchWrapped();
121 } else { 122 } else {
122 getCursorPosition( &line, &col ); 123 getCursorPosition( &line, &col );
123 } 124 }
124 //ignore backwards for now.... 125 //ignore backwards for now....
125 if ( !backwards ) { 126 if ( !backwards ) {
126 for ( ; ; ) { 127 for ( ; ; ) {
127 if ( line >= numLines() ) { 128 if ( line >= numLines() ) {
128 wrap = true; 129 wrap = true;
129 //emit notFound(); 130 //emit notFound();
130 break; 131 break;
131 } 132 }
132 int findCol = getString( line )->find( txt, col, caseSensitive ); 133 int findCol = getString( line )->find( txt, col, caseSensitive );
133 if ( findCol >= 0 ) { 134 if ( findCol >= 0 ) {
134 setCursorPosition( line, findCol, false ); 135 setCursorPosition( line, findCol, false );
135 col = findCol + txt.length(); 136 col = findCol + txt.length();
136 setCursorPosition( line, col, true ); 137 setCursorPosition( line, col, true );
137 138
138 //found = true; 139 //found = true;
139 break; 140 break;
140 } 141 }
141 line++; 142 line++;
142 col = 0; 143 col = 0;
143 } 144 }
144 } 145 }
145} 146}
146 147
147 148
148#else 149#else
149 150
150#error "Must make a QpeEditor that inherits QTextEdit" 151#error "Must make a QpeEditor that inherits QTextEdit"
151 152
152#endif 153#endif
153 154
154 155
155static const int nfontsizes = 6; 156static const int nfontsizes = 6;
156static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 157static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
157 158
158TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 159TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
159 : QMainWindow( parent, name, f ), bFromDocView( false ) 160 : QMainWindow( parent, name, f ), bFromDocView( false )
160{ 161{
161 doc = 0; 162 doc = 0;
162 edited=false; 163 edited=false;
163 fromSetDocument=false; 164 fromSetDocument=false;
164 165
165 setToolBarsMovable( false ); 166 setToolBarsMovable( false );
166 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 167 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
167 168
168 channel = new QCopChannel( "QPE/Application/textedit", this ); 169 channel = new QCopChannel( "QPE/Application/textedit", this );
169 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 170 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
170 this, SLOT(receive(const QCString&,const QByteArray&)) ); 171 this, SLOT(receive(const QCString&,const QByteArray&)) );
171 172
172 setIcon( Resource::loadPixmap( "textedit/TextEditor" ) ); 173 setIcon( Opie::Core::OResource::loadPixmap( "textedit/TextEditor", Opie::Core::OResource::SmallIcon ) );
173 174
174 QToolBar *bar = new QToolBar( this ); 175 QToolBar *bar = new QToolBar( this );
175 bar->setHorizontalStretchable( true ); 176 bar->setHorizontalStretchable( true );
176 menu = bar; 177 menu = bar;
177 178
178 QMenuBar *mb = new QMenuBar( bar ); 179 QMenuBar *mb = new QMenuBar( bar );
179 QPopupMenu *file = new QPopupMenu( this ); 180 QPopupMenu *file = new QPopupMenu( this );
180 QPopupMenu *edit = new QPopupMenu( this ); 181 QPopupMenu *edit = new QPopupMenu( this );
181 QPopupMenu *advancedMenu = new QPopupMenu(this); 182 QPopupMenu *advancedMenu = new QPopupMenu(this);
182 183
183 font = new QPopupMenu( this ); 184 font = new QPopupMenu( this );
184 185
185 bar = new QToolBar( this ); 186 bar = new QToolBar( this );
186 editBar = bar; 187 editBar = bar;
187 188
188 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 189 QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
189 QString::null, 0, this, 0 ); 190 QString::null, 0, this, 0 );
190 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 191 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
191// a->addTo( bar ); 192// a->addTo( bar );
192 a->addTo( file ); 193 a->addTo( file );
193 194
194 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), 195 a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ),
195 QString::null, 0, this, 0 ); 196 QString::null, 0, this, 0 );
196 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 197 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
197 a->addTo( bar ); 198 a->addTo( bar );
198 a->addTo( file ); 199 a->addTo( file );
199 200
200 a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , 201 a = new QAction( tr( "Save" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
201 QString::null, 0, this, 0 ); 202 QString::null, 0, this, 0 );
202 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 203 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
203 file->insertSeparator(); 204 file->insertSeparator();
204 a->addTo( bar ); 205 a->addTo( bar );
205 a->addTo( file ); 206 a->addTo( file );
206 207
207 a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , 208 a = new QAction( tr( "Save As" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
208 QString::null, 0, this, 0 ); 209 QString::null, 0, this, 0 );
209 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 210 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
210 a->addTo( file ); 211 a->addTo( file );
211 212
212 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), 213 a = new QAction( tr( "Cut" ), Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ),
213 QString::null, 0, this, 0 ); 214 QString::null, 0, this, 0 );
214 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 215 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
215 a->addTo( editBar ); 216 a->addTo( editBar );
216 a->addTo( edit ); 217 a->addTo( edit );
217 218
218 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), 219 a = new QAction( tr( "Copy" ), Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ),
219 QString::null, 0, this, 0 ); 220 QString::null, 0, this, 0 );
220 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 221 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
221 a->addTo( editBar ); 222 a->addTo( editBar );
222 a->addTo( edit ); 223 a->addTo( edit );
223 224
224 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), 225 a = new QAction( tr( "Paste" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ),
225 QString::null, 0, this, 0 ); 226 QString::null, 0, this, 0 );
226 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 227 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
227 a->addTo( editBar ); 228 a->addTo( editBar );
228 a->addTo( edit ); 229 a->addTo( edit );
229 230
230 231
231#ifndef QT_NO_CLIPBOARD 232#ifndef QT_NO_CLIPBOARD
232 a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), 233 a = new QAction( tr( "Insert Time and Date" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ),
233 QString::null, 0, this, 0 ); 234 QString::null, 0, this, 0 );
234 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); 235 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) );
235 a->addTo( edit ); 236 a->addTo( edit );
236#endif 237#endif
237 238
238 a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), 239 a = new QAction( tr( "Goto Line..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ),
239 QString::null, 0, this, 0 ); 240 QString::null, 0, this, 0 );
240 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); 241 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) );
241 edit->insertSeparator(); 242 edit->insertSeparator();
242 a->addTo( edit ); 243 a->addTo( edit );
243 244
244 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), 245 a = new QAction( tr( "Find..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ),
245 QString::null, 0, this, 0 ); 246 QString::null, 0, this, 0 );
246 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 247 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
247 a->addTo( bar ); 248 a->addTo( bar );
248 a->addTo( edit ); 249 a->addTo( edit );
249 250
250 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 251 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
251 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 252 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
252 zin->addTo( font ); 253 zin->addTo( font );
253 254
254 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 255 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
255 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 256 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
256 zout->addTo( font ); 257 zout->addTo( font );
257 258
258 font->insertSeparator(); 259 font->insertSeparator();
259 260
260 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 261 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
261 262
262 font->insertSeparator(); 263 font->insertSeparator();
263 font->insertItem(tr("Advanced Features"), advancedMenu); 264 font->insertItem(tr("Advanced Features"), advancedMenu);
264 265
265 QAction *wa = new QAction( tr("Wrap lines"), 266 QAction *wa = new QAction( tr("Wrap lines"),
266 QString::null, 0, this, 0 ); 267 QString::null, 0, this, 0 );
267 connect( wa, SIGNAL( toggled(bool) ), 268 connect( wa, SIGNAL( toggled(bool) ),
268 this, SLOT( setWordWrap(bool) ) ); 269 this, SLOT( setWordWrap(bool) ) );
269 wa->setToggleAction(true); 270 wa->setToggleAction(true);
270 wa->addTo( advancedMenu); 271 wa->addTo( advancedMenu);
271 272
272 nStart = new QAction( tr("Start with new file"), 273 nStart = new QAction( tr("Start with new file"),
273 QString::null, 0, this, 0 ); 274 QString::null, 0, this, 0 );
274 connect( nStart, SIGNAL( toggled(bool) ), 275 connect( nStart, SIGNAL( toggled(bool) ),
275 this, SLOT( changeStartConfig(bool) ) ); 276 this, SLOT( changeStartConfig(bool) ) );
276 nStart->setToggleAction(true); 277 nStart->setToggleAction(true);
277 nStart->addTo( advancedMenu ); 278 nStart->addTo( advancedMenu );
278 nStart->setEnabled(false); 279 nStart->setEnabled(false);
279 280
280 nAdvanced = new QAction( tr("Prompt on Exit"), 281 nAdvanced = new QAction( tr("Prompt on Exit"),
281 QString::null, 0, this, 0 ); 282 QString::null, 0, this, 0 );
282 connect( nAdvanced, SIGNAL( toggled(bool) ), 283 connect( nAdvanced, SIGNAL( toggled(bool) ),
283 this, SLOT( doPrompt(bool) ) ); 284 this, SLOT( doPrompt(bool) ) );
284 nAdvanced->setToggleAction(true); 285 nAdvanced->setToggleAction(true);
285 nAdvanced->addTo( advancedMenu ); 286 nAdvanced->addTo( advancedMenu );
286 287
287 desktopAction = new QAction( tr("Always open linked file"), 288 desktopAction = new QAction( tr("Always open linked file"),
288 QString::null, 0, this, 0 ); 289 QString::null, 0, this, 0 );
289 connect( desktopAction, SIGNAL( toggled(bool) ), 290 connect( desktopAction, SIGNAL( toggled(bool) ),
290 this, SLOT( doDesktop(bool) ) ); 291 this, SLOT( doDesktop(bool) ) );
291 desktopAction->setToggleAction(true); 292 desktopAction->setToggleAction(true);
292 desktopAction->addTo( advancedMenu); 293 desktopAction->addTo( advancedMenu);
293 294
294 filePermAction = new QAction( tr("File Permissions"), 295 filePermAction = new QAction( tr("File Permissions"),
295 QString::null, 0, this, 0 ); 296 QString::null, 0, this, 0 );
296 connect( filePermAction, SIGNAL( toggled(bool) ), 297 connect( filePermAction, SIGNAL( toggled(bool) ),
297 this, SLOT( doFilePerms(bool) ) ); 298 this, SLOT( doFilePerms(bool) ) );
298 filePermAction->setToggleAction(true); 299 filePermAction->setToggleAction(true);
299 filePermAction->addTo( advancedMenu); 300 filePermAction->addTo( advancedMenu);
300 301
301 searchBarAction = new QAction( tr("Search Bar Open"), 302 searchBarAction = new QAction( tr("Search Bar Open"),
302 QString::null, 0, this, 0 ); 303 QString::null, 0, this, 0 );
303 connect( searchBarAction, SIGNAL( toggled(bool) ), 304 connect( searchBarAction, SIGNAL( toggled(bool) ),
304 this, SLOT( setSearchBar(bool) ) ); 305 this, SLOT( setSearchBar(bool) ) );
305 searchBarAction->setToggleAction(true); 306 searchBarAction->setToggleAction(true);
306 searchBarAction->addTo( advancedMenu); 307 searchBarAction->addTo( advancedMenu);
307 308
308 nAutoSave = new QAction( tr("Auto Save 5 min."), 309 nAutoSave = new QAction( tr("Auto Save 5 min."),
309 QString::null, 0, this, 0 ); 310 QString::null, 0, this, 0 );
310 connect( nAutoSave, SIGNAL( toggled(bool) ), 311 connect( nAutoSave, SIGNAL( toggled(bool) ),
311 this, SLOT( doTimer(bool) ) ); 312 this, SLOT( doTimer(bool) ) );
312 nAutoSave->setToggleAction(true); 313 nAutoSave->setToggleAction(true);
313 nAutoSave->addTo( advancedMenu); 314 nAutoSave->addTo( advancedMenu);
314 315
315 316
316 //font->insertSeparator(); 317 //font->insertSeparator();
317 318
318 //font->insertItem(tr("About"), this, SLOT( doAbout()) ); 319 //font->insertItem(tr("About"), this, SLOT( doAbout()) );
319 320
320 mb->insertItem( tr( "File" ), file ); 321 mb->insertItem( tr( "File" ), file );
321 mb->insertItem( tr( "Edit" ), edit ); 322 mb->insertItem( tr( "Edit" ), edit );
322 mb->insertItem( tr( "View" ), font ); 323 mb->insertItem( tr( "View" ), font );
323 324
324 searchBar = new QToolBar(this); 325 searchBar = new QToolBar(this);
325 addToolBar( searchBar, "Search", QMainWindow::Top, true ); 326 addToolBar( searchBar, "Search", QMainWindow::Top, true );
326 327
327 searchBar->setHorizontalStretchable( true ); 328 searchBar->setHorizontalStretchable( true );
328 329
329 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 330 searchEdit = new QLineEdit( searchBar, "searchEdit" );
330 searchBar->setStretchableWidget( searchEdit ); 331 searchBar->setStretchableWidget( searchEdit );
331 connect( searchEdit, SIGNAL( textChanged(const QString&) ), 332 connect( searchEdit, SIGNAL( textChanged(const QString&) ),
332 this, SLOT( search() ) ); 333 this, SLOT( search() ) );
333 334
334 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), 335 a = new QAction( tr( "Find Next" ), Opie::Core::OResource::loadPixmap( "next", Opie::Core::OResource::SmallIcon ),
335 QString::null, 0, this, 0 ); 336 QString::null, 0, this, 0 );
336 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 337 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
337 a->addTo( searchBar ); 338 a->addTo( searchBar );
338 a->addTo( edit ); 339 a->addTo( edit );
339 340
340 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), 341 a = new QAction( tr( "Close Find" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
341 QString::null, 0, this, 0 ); 342 QString::null, 0, this, 0 );
342 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 343 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
343 a->addTo( searchBar ); 344 a->addTo( searchBar );
344 345
345 edit->insertSeparator(); 346 edit->insertSeparator();
346 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), 347 a = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
347 QString::null, 0, this, 0 ); 348 QString::null, 0, this, 0 );
348 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 349 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
349 a->addTo( edit ); 350 a->addTo( edit );
350 351
351 searchBar->hide(); 352 searchBar->hide();
352 353
353 editor = new QpeEditor( this ); 354 editor = new QpeEditor( this );
354 setCentralWidget( editor ); 355 setCentralWidget( editor );
355 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 356 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
356 connect( editor, SIGNAL( textChanged() ), 357 connect( editor, SIGNAL( textChanged() ),
357 this, SLOT( editorChanged() ) ); 358 this, SLOT( editorChanged() ) );
358 359
359 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 360 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
360 361
361 Config cfg("TextEdit"); 362 Config cfg("TextEdit");
362 cfg. setGroup ( "Font" ); 363 cfg. setGroup ( "Font" );
363 364
364 QFont defaultFont = editor-> font ( ); 365 QFont defaultFont = editor-> font ( );
365 366
366 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 367 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
367 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 368 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
368 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 369 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
369 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 370 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
370 371
371 defaultFont = QFont ( family, size, weight, italic ); 372 defaultFont = QFont ( family, size, weight, italic );
372 editor-> setFont ( defaultFont ); 373 editor-> setFont ( defaultFont );
373// updateCaption(); 374// updateCaption();
374 375
375 cfg.setGroup ( "View" ); 376 cfg.setGroup ( "View" );
376 377
377 promptExit = cfg.readBoolEntry ( "PromptExit", false ); 378 promptExit = cfg.readBoolEntry ( "PromptExit", false );
378 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); 379 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true );
379 filePerms = cfg.readBoolEntry ( "FilePermissions", false ); 380 filePerms = cfg.readBoolEntry ( "FilePermissions", false );
380 useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); 381 useSearchBar = cfg.readBoolEntry ( "SearchBar", false );
381 startWithNew = cfg.readBoolEntry ( "startNew", true); 382 startWithNew = cfg.readBoolEntry ( "startNew", true);
382 featureAutoSave = cfg.readBoolEntry( "autosave", false); 383 featureAutoSave = cfg.readBoolEntry( "autosave", false);
383 384
384 if(useSearchBar) searchBarAction->setOn(true); 385 if(useSearchBar) searchBarAction->setOn(true);
385 if(promptExit) nAdvanced->setOn( true ); 386 if(promptExit) nAdvanced->setOn( true );
386 if(openDesktop) desktopAction->setOn( true ); 387 if(openDesktop) desktopAction->setOn( true );
387 if(filePerms) filePermAction->setOn( true ); 388 if(filePerms) filePermAction->setOn( true );
388 if(startWithNew) nStart->setOn( true ); 389 if(startWithNew) nStart->setOn( true );
389 if(featureAutoSave) nAutoSave->setOn(true); 390 if(featureAutoSave) nAutoSave->setOn(true);
390 391
391// { 392// {
392// doTimer(true); 393// doTimer(true);
393// } 394// }
394 395
395 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 396 bool wrap = cfg. readBoolEntry ( "Wrap", true );
396 wa-> setOn ( wrap ); 397 wa-> setOn ( wrap );
397 setWordWrap ( wrap ); 398 setWordWrap ( wrap );
398 399
399///////////////// 400/////////////////
400 if( qApp->argc() > 1) { 401 if( qApp->argc() > 1) {
401 currentFileName=qApp->argv()[1]; 402 currentFileName=qApp->argv()[1];
402 403
403 QFileInfo fi(currentFileName); 404 QFileInfo fi(currentFileName);
404 405
405 if(fi.baseName().left(1) == "") { 406 if(fi.baseName().left(1) == "") {
406 openDotFile(currentFileName); 407 openDotFile(currentFileName);
407 } else { 408 } else {
408 openFile(currentFileName); 409 openFile(currentFileName);
409 } 410 }
410 } else { 411 } else {
411 edited1=false; 412 edited1=false;
412 openDotFile(""); 413 openDotFile("");
413 } 414 }
414 415
415 viewSelection = cfg.readNumEntry( "FileView", 0 ); 416 viewSelection = cfg.readNumEntry( "FileView", 0 );
416} 417}
417 418
418TextEdit::~TextEdit() { 419TextEdit::~TextEdit() {
419 if( edited1 && !promptExit) { 420 if( edited1 && !promptExit) {
420 switch( savePrompt() ) { 421 switch( savePrompt() ) {
421 case 1: { 422 case 1: {
422 saveAs(); 423 saveAs();
423 } 424 }
424 break; 425 break;
425 }; 426 };
426 } 427 }
427 428
428 delete editor; 429 delete editor;
429} 430}
430 431
431void TextEdit::closeEvent(QCloseEvent *) { 432void TextEdit::closeEvent(QCloseEvent *) {
432 if( promptExit) { 433 if( promptExit) {
433 switch( savePrompt() ) { 434 switch( savePrompt() ) {
434 case 1: { 435 case 1: {
435 saveAs(); 436 saveAs();
436 qApp->quit(); 437 qApp->quit();
437 } 438 }
438 break; 439 break;
439 440
440 case 2: { 441 case 2: {
441 qApp->quit(); 442 qApp->quit();
442 } 443 }
443 break; 444 break;
444 445
445 case -1: 446 case -1:
446 break; 447 break;
447 }; 448 };
448 } 449 }
449 else 450 else
450 qApp->quit(); 451 qApp->quit();
451} 452}
452 453
453void TextEdit::cleanUp() { 454void TextEdit::cleanUp() {
454 455
455 Config cfg ( "TextEdit" ); 456 Config cfg ( "TextEdit" );
456 cfg. setGroup ( "Font" ); 457 cfg. setGroup ( "Font" );
457 QFont f = editor->font(); 458 QFont f = editor->font();
458 cfg.writeEntry ( "Family", f. family ( )); 459 cfg.writeEntry ( "Family", f. family ( ));
459 cfg.writeEntry ( "Size", f. pointSize ( )); 460 cfg.writeEntry ( "Size", f. pointSize ( ));
460 cfg.writeEntry ( "Weight", f. weight ( )); 461 cfg.writeEntry ( "Weight", f. weight ( ));
461 cfg.writeEntry ( "Italic", f. italic ( )); 462 cfg.writeEntry ( "Italic", f. italic ( ));
462 463
463 cfg.setGroup ( "View" ); 464 cfg.setGroup ( "View" );
464 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); 465 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth );
465 cfg.writeEntry ( "FileView", viewSelection ); 466 cfg.writeEntry ( "FileView", viewSelection );
466 467
467 cfg.writeEntry ( "PromptExit", promptExit ); 468 cfg.writeEntry ( "PromptExit", promptExit );
468 cfg.writeEntry ( "OpenDesktop", openDesktop ); 469 cfg.writeEntry ( "OpenDesktop", openDesktop );
469 cfg.writeEntry ( "FilePermissions", filePerms ); 470 cfg.writeEntry ( "FilePermissions", filePerms );
470 cfg.writeEntry ( "SearchBar", useSearchBar ); 471 cfg.writeEntry ( "SearchBar", useSearchBar );
471 cfg.writeEntry ( "startNew", startWithNew ); 472 cfg.writeEntry ( "startNew", startWithNew );
472 473
473} 474}
474 475
475 476
476void TextEdit::accept() { 477void TextEdit::accept() {
477 if( edited1) 478 if( edited1)
478 saveAs(); 479 saveAs();
479 qApp->quit(); 480 qApp->quit();
480} 481}
481 482
482void TextEdit::zoomIn() { 483void TextEdit::zoomIn() {
483 setFontSize(editor->font().pointSize()+1,false); 484 setFontSize(editor->font().pointSize()+1,false);
484} 485}
485 486
486void TextEdit::zoomOut() { 487void TextEdit::zoomOut() {
487 setFontSize(editor->font().pointSize()-1,true); 488 setFontSize(editor->font().pointSize()-1,true);
488} 489}
489 490
490 491
491void TextEdit::setFontSize(int sz, bool round_down_not_up) { 492void TextEdit::setFontSize(int sz, bool round_down_not_up) {
492 int s=10; 493 int s=10;
493 for (int i=0; i<nfontsizes; i++) { 494 for (int i=0; i<nfontsizes; i++) {
494 if ( fontsize[i] == sz ) { 495 if ( fontsize[i] == sz ) {
495 s = sz; 496 s = sz;
496 break; 497 break;
497 } else if ( round_down_not_up ) { 498 } else if ( round_down_not_up ) {
498 if ( fontsize[i] < sz ) 499 if ( fontsize[i] < sz )
499 s = fontsize[i]; 500 s = fontsize[i];
500 } else { 501 } else {
501 if ( fontsize[i] > sz ) { 502 if ( fontsize[i] > sz ) {
502 s = fontsize[i]; 503 s = fontsize[i];
503 break; 504 break;
504 } 505 }
505 } 506 }
506 } 507 }
507 508
508 QFont f = editor->font(); 509 QFont f = editor->font();
509 f.setPointSize(s); 510 f.setPointSize(s);
510 editor->setFont(f); 511 editor->setFont(f);
511 512
512 zin->setEnabled(s != fontsize[nfontsizes-1]); 513 zin->setEnabled(s != fontsize[nfontsizes-1]);
513 zout->setEnabled(s != fontsize[0]); 514 zout->setEnabled(s != fontsize[0]);
514} 515}
515 516
516void TextEdit::setBold(bool y) { 517void TextEdit::setBold(bool y) {
517 QFont f = editor->font(); 518 QFont f = editor->font();
518 f.setBold(y); 519 f.setBold(y);
519 editor->setFont(f); 520 editor->setFont(f);
520} 521}
521 522
522void TextEdit::setItalic(bool y) { 523void TextEdit::setItalic(bool y) {
523 QFont f = editor->font(); 524 QFont f = editor->font();
524 f.setItalic(y); 525 f.setItalic(y);
525 editor->setFont(f); 526 editor->setFont(f);
526} 527}
527 528
528void TextEdit::setWordWrap(bool y) { 529void TextEdit::setWordWrap(bool y) {
529 bool state = editor->edited(); 530 bool state = editor->edited();
530 QString captionStr = caption(); 531 QString captionStr = caption();
531 bool b1 = edited1; 532 bool b1 = edited1;
532 bool b2 = edited; 533 bool b2 = edited;
533 534
534 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 535 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
535 editor->setEdited( state ); 536 editor->setEdited( state );
536 edited1=b1; 537 edited1=b1;
537 edited=b2; 538 edited=b2;
538 setCaption(captionStr); 539 setCaption(captionStr);
539} 540}
540 541
541void TextEdit::setSearchBar(bool b) { 542void TextEdit::setSearchBar(bool b) {
542 useSearchBar=b; 543 useSearchBar=b;
543 Config cfg("TextEdit"); 544 Config cfg("TextEdit");
544 cfg.setGroup("View"); 545 cfg.setGroup("View");
545 cfg.writeEntry ( "SearchBar", b ); 546 cfg.writeEntry ( "SearchBar", b );
546 searchBarAction->setOn(b); 547 searchBarAction->setOn(b);
547 if(b) 548 if(b)
548 searchBar->show(); 549 searchBar->show();
549 else 550 else
550 searchBar->hide(); 551 searchBar->hide();
551 editor->setFocus(); 552 editor->setFocus();
552} 553}
553 554
554void TextEdit::fileNew() { 555void TextEdit::fileNew() {
555// if( !bFromDocView ) { 556// if( !bFromDocView ) {
556// saveAs(); 557// saveAs();
557// } 558// }
558 newFile(DocLnk()); 559 newFile(DocLnk());
559} 560}
560 561
561void TextEdit::fileOpen() { 562void TextEdit::fileOpen() {
562 Config cfg("TextEdit"); 563 Config cfg("TextEdit");
563 cfg. setGroup ( "View" ); 564 cfg. setGroup ( "View" );
564 QMap<QString, QStringList> map; 565 QMap<QString, QStringList> map;
565 map.insert(tr("All"), QStringList() ); 566 map.insert(tr("All"), QStringList() );
566 QStringList text; 567 QStringList text;
567 text << "text/*"; 568 text << "text/*";
568 map.insert(tr("Text"), text ); 569 map.insert(tr("Text"), text );
569 text << "*"; 570 text << "*";
570 map.insert(tr("All"), text ); 571 map.insert(tr("All"), text );
571 QString str = OFileDialog::getOpenFileName( 2, 572 QString str = OFileDialog::getOpenFileName( 2,
572 QString::null , 573 QString::null ,
573 QString::null, map); 574 QString::null, map);
574 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) 575 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() )
575 { 576 {
576 openFile( str ); 577 openFile( str );
577 } 578 }
578 else 579 else
579 updateCaption(); 580 updateCaption();
580} 581}
581 582
582void TextEdit::doSearchBar() { 583void TextEdit::doSearchBar() {
583 if(!useSearchBar) 584 if(!useSearchBar)
584 searchBar->hide(); 585 searchBar->hide();
585 else 586 else
586 searchBar->show(); 587 searchBar->show();
587} 588}
588 589
589#if 0 590#if 0
590void TextEdit::slotFind() { 591void TextEdit::slotFind() {
591 FindDialog frmFind( tr("Text Editor"), this ); 592 FindDialog frmFind( tr("Text Editor"), this );
592 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), 593 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)),
593 editor, SLOT(slotDoFind(const QString&,bool,bool))); 594 editor, SLOT(slotDoFind(const QString&,bool,bool)));
594 595
595 //case sensitive, backwards, [category] 596 //case sensitive, backwards, [category]
596 597
597 connect( editor, SIGNAL(notFound()), 598 connect( editor, SIGNAL(notFound()),
598 &frmFind, SLOT(slotNotFound()) ); 599 &frmFind, SLOT(slotNotFound()) );
599 connect( editor, SIGNAL(searchWrapped()), 600 connect( editor, SIGNAL(searchWrapped()),
600 &frmFind, SLOT(slotWrapAround()) ); 601 &frmFind, SLOT(slotWrapAround()) );
601 602
602 frmFind.exec(); 603 frmFind.exec();
603 604
604 605
605} 606}
606#endif 607#endif
607 608
608void TextEdit::fileRevert() { 609void TextEdit::fileRevert() {
609 clear(); 610 clear();
610 fileOpen(); 611 fileOpen();
611} 612}
612 613
613void TextEdit::editCut() { 614void TextEdit::editCut() {
614#ifndef QT_NO_CLIPBOARD 615#ifndef QT_NO_CLIPBOARD
615 editor->cut(); 616 editor->cut();
616#endif 617#endif
617} 618}
618 619
619void TextEdit::editCopy() { 620void TextEdit::editCopy() {
620#ifndef QT_NO_CLIPBOARD 621#ifndef QT_NO_CLIPBOARD
621 editor->copy(); 622 editor->copy();
622#endif 623#endif
623} 624}
624 625
625void TextEdit::editPaste() { 626void TextEdit::editPaste() {
626#ifndef QT_NO_CLIPBOARD 627#ifndef QT_NO_CLIPBOARD
627 editor->paste(); 628 editor->paste();
628#endif 629#endif
629} 630}
630 631
631void TextEdit::editFind() { 632void TextEdit::editFind() {
632 searchBar->show(); 633 searchBar->show();
633 searchEdit->setFocus(); 634 searchEdit->setFocus();
634} 635}
635 636
636void TextEdit::findNext() { 637void TextEdit::findNext() {
637 editor->find( searchEdit->text(), false, false ); 638 editor->find( searchEdit->text(), false, false );
638 639
639} 640}
640 641
641void TextEdit::findClose() { 642void TextEdit::findClose() {
642 searchBar->hide(); 643 searchBar->hide();
643} 644}
644 645
645void TextEdit::search() { 646void TextEdit::search() {
646 editor->find( searchEdit->text(), false, false ); 647 editor->find( searchEdit->text(), false, false );
647} 648}
648 649
649void TextEdit::newFile( const DocLnk &f ) { 650void TextEdit::newFile( const DocLnk &f ) {
650 DocLnk nf = f; 651 DocLnk nf = f;
651 nf.setType("text/plain"); 652 nf.setType("text/plain");
652 clear(); 653 clear();
653 setWState (WState_Reserved1 ); 654 setWState (WState_Reserved1 );
654 editor->setFocus(); 655 editor->setFocus();
655 doc = new DocLnk(nf); 656 doc = new DocLnk(nf);
656 currentFileName = "Unnamed"; 657 currentFileName = "Unnamed";
657 odebug << "newFile "+currentFileName << oendl; 658 odebug << "newFile "+currentFileName << oendl;
658 updateCaption( currentFileName); 659 updateCaption( currentFileName);
659// editor->setEdited( false); 660// editor->setEdited( false);
660} 661}
661 662
662void TextEdit::openDotFile( const QString &f ) { 663void TextEdit::openDotFile( const QString &f ) {
663 if(!currentFileName.isEmpty()) { 664 if(!currentFileName.isEmpty()) {
664 currentFileName=f; 665 currentFileName=f;
665 666
666 odebug << "openFile dotfile " + currentFileName << oendl; 667 odebug << "openFile dotfile " + currentFileName << oendl;
667 QString txt; 668 QString txt;
668 QFile file(f); 669 QFile file(f);
669 file.open(IO_ReadWrite); 670 file.open(IO_ReadWrite);
670 QTextStream t(&file); 671 QTextStream t(&file);
671 while ( !t.atEnd()) { 672 while ( !t.atEnd()) {
672 txt+=t.readLine()+"\n"; 673 txt+=t.readLine()+"\n";
673 } 674 }
674 editor->setText(txt); 675 editor->setText(txt);
675 editor->setEdited( false); 676 editor->setEdited( false);
676 edited1=false; 677 edited1=false;
677 edited=false; 678 edited=false;
678 679
679 680
680 } 681 }
681 updateCaption( currentFileName); 682 updateCaption( currentFileName);
682} 683}
683 684
684void TextEdit::openFile( const QString &f ) { 685void TextEdit::openFile( const QString &f ) {
685 odebug << "filename is "+ f << oendl; 686 odebug << "filename is "+ f << oendl;
686 QString filer; 687 QString filer;
687 QFileInfo fi( f); 688 QFileInfo fi( f);
688// bFromDocView = true; 689// bFromDocView = true;
689 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 690 if(f.find(".desktop",0,true) != -1 && !openDesktop )
690 { 691 {
691 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) 692 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) )
692 { 693 {
693 case 0: //desktop 694 case 0: //desktop
694 filer = f; 695 filer = f;
695 break; 696 break;
696 case 1: //linked 697 case 1: //linked
697 DocLnk sf(f); 698 DocLnk sf(f);
698 filer = sf.file(); 699 filer = sf.file();
699 break; 700 break;
700 }; 701 };
701 } 702 }
702 else if(fi.baseName().left(1) == "") 703 else if(fi.baseName().left(1) == "")
703 { 704 {
704 odebug << "opening dotfile" << oendl; 705 odebug << "opening dotfile" << oendl;
705 currentFileName=f; 706 currentFileName=f;
706 openDotFile(currentFileName); 707 openDotFile(currentFileName);
707 return; 708 return;
708 } 709 }
709 /* 710 /*
710 * The problem is a file where Config(f).isValid() and it does not 711 * The problem is a file where Config(f).isValid() and it does not
711 * end with .desktop will be treated as desktop file 712 * end with .desktop will be treated as desktop file
712 */ 713 */
713 else if (f.find(".desktop",0,true) != -1 ) 714 else if (f.find(".desktop",0,true) != -1 )
714 { 715 {
715 DocLnk sf(f); 716 DocLnk sf(f);
716 filer = sf.file(); 717 filer = sf.file();
717 if(filer.right(1) == "/") 718 if(filer.right(1) == "/")
718 filer = f; 719 filer = f;
719 720
720 } 721 }
721 else 722 else
722 filer = f; 723 filer = f;
723 724
724 DocLnk nf; 725 DocLnk nf;
725 nf.setType("text/plain"); 726 nf.setType("text/plain");
726 nf.setFile(filer); 727 nf.setFile(filer);
727 currentFileName=filer; 728 currentFileName=filer;
728 729
729 nf.setName(fi.baseName()); 730 nf.setName(fi.baseName());
730 openFile(nf); 731 openFile(nf);
731 732
732 odebug << "openFile string "+currentFileName << oendl; 733 odebug << "openFile string "+currentFileName << oendl;
733 734
734 showEditTools(); 735 showEditTools();
735 // Show filename in caption 736 // Show filename in caption
736 QString name = filer; 737 QString name = filer;
737 int sep = name.findRev( '/' ); 738 int sep = name.findRev( '/' );
738 if ( sep > 0 ) 739 if ( sep > 0 )
739 name = name.mid( sep+1 ); 740 name = name.mid( sep+1 );
740 updateCaption( name ); 741 updateCaption( name );
741} 742}
742 743
743void TextEdit::openFile( const DocLnk &f ) { 744void TextEdit::openFile( const DocLnk &f ) {
744// clear(); 745// clear();
745// bFromDocView = true; 746// bFromDocView = true;
746 FileManager fm; 747 FileManager fm;
747 QString txt; 748 QString txt;
748 currentFileName=f.file(); 749 currentFileName=f.file();
749 odebug << "openFile doclnk " + currentFileName << oendl; 750 odebug << "openFile doclnk " + currentFileName << oendl;
750 if ( !fm.loadFile( f, txt ) ) { 751 if ( !fm.loadFile( f, txt ) ) {
751 // ####### could be a new file 752 // ####### could be a new file
752 odebug << "Cannot open file" << oendl; 753 odebug << "Cannot open file" << oendl;
753 } 754 }
754// fileNew(); 755// fileNew();
755 if ( doc ) 756 if ( doc )
756 delete doc; 757 delete doc;
757 doc = new DocLnk(f); 758 doc = new DocLnk(f);
758 editor->setText(txt); 759 editor->setText(txt);
759 editor->setEdited( false); 760 editor->setEdited( false);
760 edited1=false; 761 edited1=false;
761 edited=false; 762 edited=false;
762 763
763 doc->setName(currentFileName); 764 doc->setName(currentFileName);
764 updateCaption(); 765 updateCaption();
765 setTimer(); 766 setTimer();
766} 767}
767 768
768void TextEdit::showEditTools() { 769void TextEdit::showEditTools() {
769 menu->show(); 770 menu->show();
770 editBar->show(); 771 editBar->show();
771 if(!useSearchBar) 772 if(!useSearchBar)
772 searchBar->hide(); 773 searchBar->hide();
773 else 774 else
774 searchBar->show(); 775 searchBar->show();
775 setWState (WState_Reserved1 ); 776 setWState (WState_Reserved1 );
776} 777}
777 778
778/*! 779/*!
779 unprompted save */ 780 unprompted save */
780bool TextEdit::save() { 781bool TextEdit::save() {
781 QString name, file; 782 QString name, file;
782 odebug << "saveAsFile " + currentFileName << oendl; 783 odebug << "saveAsFile " + currentFileName << oendl;
783 if(currentFileName.isEmpty()) { 784 if(currentFileName.isEmpty()) {
784 saveAs(); 785 saveAs();
785 return false; 786 return false;
786 } 787 }
787 name = currentFileName; 788 name = currentFileName;
788 if(doc) { 789 if(doc) {
789 file = doc->file(); 790 file = doc->file();
790 odebug << "saver file "+file << oendl; 791 odebug << "saver file "+file << oendl;
791 name = doc->name(); 792 name = doc->name();
792 odebug << "File named "+name << oendl; 793 odebug << "File named "+name << oendl;
793 } else { 794 } else {
794 file = currentFileName; 795 file = currentFileName;
795 name = QFileInfo(currentFileName).baseName(); 796 name = QFileInfo(currentFileName).baseName();
796 } 797 }
797 798
798 QString rt = editor->text(); 799 QString rt = editor->text();
799 if( !rt.isEmpty() ) { 800 if( !rt.isEmpty() ) {
800 if(name.isEmpty()) { 801 if(name.isEmpty()) {
801 saveAs(); 802 saveAs();
802 } else { 803 } else {
803 currentFileName = name; 804 currentFileName = name;
804 odebug << "saveFile "+currentFileName << oendl; 805 odebug << "saveFile "+currentFileName << oendl;
805 806
806 struct stat buf; 807 struct stat buf;
807 mode_t mode; 808 mode_t mode;
808 stat(file.latin1(), &buf); 809 stat(file.latin1(), &buf);
809 mode = buf.st_mode; 810 mode = buf.st_mode;
810 811
811 if(!fileIs) { 812 if(!fileIs) {
812 doc->setName( name); 813 doc->setName( name);
813 FileManager fm; 814 FileManager fm;
814 if ( !fm.saveFile( *doc, rt ) ) { 815 if ( !fm.saveFile( *doc, rt ) ) {
815 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 816 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
816 return false; 817 return false;
817 } 818 }
818 } else { 819 } else {
819 odebug << "regular save file" << oendl; 820 odebug << "regular save file" << oendl;
820 QFile f(file); 821 QFile f(file);
821 if( f.open(IO_WriteOnly)) { 822 if( f.open(IO_WriteOnly)) {
822 QCString crt = rt.utf8(); 823 QCString crt = rt.utf8();
823 f.writeBlock(crt,crt.length()); 824 f.writeBlock(crt,crt.length());
824 } else { 825 } else {
825 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 826 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
826 return false; 827 return false;
827 } 828 }
828 829
829 } 830 }
830 editor->setEdited( false); 831 editor->setEdited( false);
831 edited1=false; 832 edited1=false;
832 edited=false; 833 edited=false;
833 if(caption().left(1)=="*") 834 if(caption().left(1)=="*")
834 setCaption(caption().right(caption().length()-1)); 835 setCaption(caption().right(caption().length()-1));
835 836
836 837
837 chmod( file.latin1(), mode); 838 chmod( file.latin1(), mode);
838 } 839 }
839 return true; 840 return true;
840 } 841 }
841 return false; 842 return false;
842} 843}
843 844
844/*! 845/*!
845 prompted save */ 846 prompted save */
846bool TextEdit::saveAs() { 847bool TextEdit::saveAs() {
847 848
848 if(caption() == tr("Text Editor")) 849 if(caption() == tr("Text Editor"))
849 return false; 850 return false;
850 odebug << "saveAsFile " + currentFileName << oendl; 851 odebug << "saveAsFile " + currentFileName << oendl;
851 // case of nothing to save... 852 // case of nothing to save...
852// if ( !doc && !currentFileName.isEmpty()) { 853// if ( !doc && !currentFileName.isEmpty()) {
853// //|| !bFromDocView) 854// //|| !bFromDocView)
854// odebug << "no doc" << oendl; 855// odebug << "no doc" << oendl;
855// return true; 856// return true;
856// } 857// }
857// if ( !editor->edited() ) { 858// if ( !editor->edited() ) {
858// delete doc; 859// delete doc;
859// doc = 0; 860// doc = 0;
860// return true; 861// return true;
861// } 862// }
862 863
863 QString rt = editor->text(); 864 QString rt = editor->text();
864 odebug << currentFileName << oendl; 865 odebug << currentFileName << oendl;
865 866
866 if( currentFileName.isEmpty() 867 if( currentFileName.isEmpty()
867 || currentFileName == tr("Unnamed") 868 || currentFileName == tr("Unnamed")
868 || currentFileName == tr("Text Editor")) { 869 || currentFileName == tr("Text Editor")) {
869 odebug << "do silly TT filename thing" << oendl; 870 odebug << "do silly TT filename thing" << oendl;
870// if ( doc && doc->name().isEmpty() ) { 871// if ( doc && doc->name().isEmpty() ) {
871 QString pt = rt.simplifyWhiteSpace(); 872 QString pt = rt.simplifyWhiteSpace();
872 int i = pt.find( ' ' ); 873 int i = pt.find( ' ' );
873 QString docname = pt; 874 QString docname = pt;
874 if ( i > 0 ) 875 if ( i > 0 )
875 docname = pt.left( i ); 876 docname = pt.left( i );
876 // remove "." at the beginning 877 // remove "." at the beginning
877 while( docname.startsWith( "." ) ) 878 while( docname.startsWith( "." ) )
878 docname = docname.mid( 1 ); 879 docname = docname.mid( 1 );
879 docname.replace( QRegExp("/"), "_" ); 880 docname.replace( QRegExp("/"), "_" );
880 // cut the length. filenames longer than that 881 // cut the length. filenames longer than that
881 //don't make sense and something goes wrong when they get too long. 882 //don't make sense and something goes wrong when they get too long.
882 if ( docname.length() > 40 ) 883 if ( docname.length() > 40 )
883 docname = docname.left(40); 884 docname = docname.left(40);
884 if ( docname.isEmpty() ) 885 if ( docname.isEmpty() )
885 docname = tr("Unnamed"); 886 docname = tr("Unnamed");
886 if(doc) doc->setName(docname); 887 if(doc) doc->setName(docname);
887 currentFileName=docname; 888 currentFileName=docname;
888// } 889// }
889// else 890// else
890// odebug << "hmmmmmm" << oendl; 891// odebug << "hmmmmmm" << oendl;
891 } 892 }
892 893
893 894
894 QMap<QString, QStringList> map; 895 QMap<QString, QStringList> map;
895 map.insert(tr("All"), QStringList() ); 896 map.insert(tr("All"), QStringList() );
896 QStringList text; 897 QStringList text;
897 text << "text/*"; 898 text << "text/*";
898 map.insert(tr("Text"), text ); 899 map.insert(tr("Text"), text );
899 text << "*"; 900 text << "*";
900 map.insert(tr("All"), text ); 901 map.insert(tr("All"), text );
901 902
902 QFileInfo cuFi( currentFileName); 903 QFileInfo cuFi( currentFileName);
903 QString filee = cuFi.fileName(); 904 QString filee = cuFi.fileName();
904 QString dire = cuFi.dirPath(); 905 QString dire = cuFi.dirPath();
905 if(dire==".") 906 if(dire==".")
906 dire = QPEApplication::documentDir(); 907 dire = QPEApplication::documentDir();
907 QString str; 908 QString str;
908 if( !featureAutoSave) { 909 if( !featureAutoSave) {
909 str = OFileDialog::getSaveFileName( 2, 910 str = OFileDialog::getSaveFileName( 2,
910 dire, 911 dire,
911 filee, map); 912 filee, map);
912 } else 913 } else
913 str=currentFileName; 914 str=currentFileName;
914 915
915 if(!str.isEmpty()) { 916 if(!str.isEmpty()) {
916 QString fileNm=str; 917 QString fileNm=str;
917 918
918 odebug << "saving filename "+fileNm << oendl; 919 odebug << "saving filename "+fileNm << oendl;
919 QFileInfo fi(fileNm); 920 QFileInfo fi(fileNm);
920 currentFileName=fi.fileName(); 921 currentFileName=fi.fileName();
921 if(doc) 922 if(doc)
922// QString file = doc->file(); 923// QString file = doc->file();
923// doc->removeFiles(); 924// doc->removeFiles();
924 delete doc; 925 delete doc;
925 DocLnk nf; 926 DocLnk nf;
926 nf.setType("text/plain"); 927 nf.setType("text/plain");
927 nf.setFile( fileNm); 928 nf.setFile( fileNm);
928 doc = new DocLnk(nf); 929 doc = new DocLnk(nf);
929// editor->setText(rt); 930// editor->setText(rt);
930 odebug << "Saving file as "+currentFileName << oendl; 931 odebug << "Saving file as "+currentFileName << oendl;
931 doc->setName( fi.baseName() /*currentFileName*/); 932 doc->setName( fi.baseName() /*currentFileName*/);
932 updateCaption( currentFileName); 933 updateCaption( currentFileName);
933 934
934 FileManager fm; 935 FileManager fm;
935 if ( !fm.saveFile( *doc, rt ) ) { 936 if ( !fm.saveFile( *doc, rt ) ) {
936 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 937 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
937 return false; 938 return false;
938 } 939 }
939 940
940 if( filePerms ) { 941 if( filePerms ) {
941 filePermissions *filePerm; 942 filePermissions *filePerm;
942 filePerm = new filePermissions(this, 943 filePerm = new filePermissions(this,
943 tr("Permissions"),true, 944 tr("Permissions"),true,
944 0,(const QString &)fileNm); 945 0,(const QString &)fileNm);
945 QPEApplication::execDialog( filePerm ); 946 QPEApplication::execDialog( filePerm );
946 947
947 if( filePerm) 948 if( filePerm)
948 delete filePerm; 949 delete filePerm;
949 } 950 }
950// } 951// }
951 editor->setEdited( false); 952 editor->setEdited( false);
952 edited1 = false; 953 edited1 = false;
953 edited = false; 954 edited = false;
954 if(caption().left(1)=="*") 955 if(caption().left(1)=="*")
955 setCaption(caption().right(caption().length()-1)); 956 setCaption(caption().right(caption().length()-1));
956 957
957 return true; 958 return true;
958 } 959 }
959 odebug << "returning false" << oendl; 960 odebug << "returning false" << oendl;
960 currentFileName = ""; 961 currentFileName = "";
961 return false; 962 return false;
962} //end saveAs 963} //end saveAs
963 964
964void TextEdit::clear() { 965void TextEdit::clear() {
965 delete doc; 966 delete doc;
966 doc = 0; 967 doc = 0;
967 editor->clear(); 968 editor->clear();
968} 969}
969 970
970void TextEdit::updateCaption( const QString &name ) { 971void TextEdit::updateCaption( const QString &name ) {
971 972
972 if ( name.isEmpty() ) 973 if ( name.isEmpty() )
973 setCaption( tr("Text Editor") ); 974 setCaption( tr("Text Editor") );
974 else { 975 else {
975 QString s = name; 976 QString s = name;
976 if ( s.isNull() ) 977 if ( s.isNull() )
977 s = doc->name(); 978 s = doc->name();
978 if ( s.isEmpty() ) { 979 if ( s.isEmpty() ) {
979 s = tr( "Unnamed" ); 980 s = tr( "Unnamed" );
980 currentFileName=s; 981 currentFileName=s;
981 } 982 }
982// if(s.left(1) == "/") 983// if(s.left(1) == "/")
983// s = s.right(s.length()-1); 984// s = s.right(s.length()-1);
984 setCaption( tr("%1 - Text Editor").arg( s ) ); 985 setCaption( tr("%1 - Text Editor").arg( s ) );
985 } 986 }
986} 987}
987 988
988void TextEdit::setDocument(const QString& fileref) { 989void TextEdit::setDocument(const QString& fileref) {
989 if(fileref != "Unnamed") { 990 if(fileref != "Unnamed") {
990 currentFileName=fileref; 991 currentFileName=fileref;
991 odebug << "setDocument" << oendl; 992 odebug << "setDocument" << oendl;
992 QFileInfo fi(currentFileName); 993 QFileInfo fi(currentFileName);
993 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; 994 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
994 if( (fi.baseName().left(1)).isEmpty() ) { 995 if( (fi.baseName().left(1)).isEmpty() ) {
995 openDotFile(currentFileName); 996 openDotFile(currentFileName);
996 997
997 } else { 998 } else {
998 odebug << "setDoc open" << oendl; 999 odebug << "setDoc open" << oendl;
999 bFromDocView = true; 1000 bFromDocView = true;
1000 openFile(fileref); 1001 openFile(fileref);
1001 editor->setEdited(true); 1002 editor->setEdited(true);
1002 edited1=false; 1003 edited1=false;
1003 edited=true; 1004 edited=true;
1004 // fromSetDocument=false; 1005 // fromSetDocument=false;
1005 // doSearchBar(); 1006 // doSearchBar();
1006 } 1007 }
1007 } 1008 }
1008 updateCaption( currentFileName); 1009 updateCaption( currentFileName);
1009} 1010}
1010 1011
1011void TextEdit::changeFont() { 1012void TextEdit::changeFont() {
1012 QDialog *d = new QDialog ( this, "FontDialog", true ); 1013 QDialog *d = new QDialog ( this, "FontDialog", true );
1013 d-> setCaption ( tr( "Choose font" )); 1014 d-> setCaption ( tr( "Choose font" ));
1014 QBoxLayout *lay = new QVBoxLayout ( d ); 1015 QBoxLayout *lay = new QVBoxLayout ( d );
1015 OFontSelector *ofs = new OFontSelector ( true, d ); 1016 OFontSelector *ofs = new OFontSelector ( true, d );
1016 lay-> addWidget ( ofs ); 1017 lay-> addWidget ( ofs );
1017 ofs-> setSelectedFont ( editor-> font ( )); 1018 ofs-> setSelectedFont ( editor-> font ( ));
1018 1019
1019 if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) 1020 if ( QPEApplication::execDialog( d ) == QDialog::Accepted )
1020 editor-> setFont ( ofs-> selectedFont ( )); 1021 editor-> setFont ( ofs-> selectedFont ( ));
1021 delete d; 1022 delete d;
1022 1023
1023} 1024}
1024 1025
1025void TextEdit::editDelete() { 1026void TextEdit::editDelete() {
1026 switch ( QMessageBox::warning(this,tr("Text Editor"), 1027 switch ( QMessageBox::warning(this,tr("Text Editor"),
1027 tr("Do you really want<BR>to <B>delete</B> " 1028 tr("Do you really want<BR>to <B>delete</B> "
1028 "the current file\nfrom the disk?<BR>This is " 1029 "the current file\nfrom the disk?<BR>This is "
1029 "<B>irreversable!</B>"), 1030 "<B>irreversable!</B>"),
1030 tr("Yes"),tr("No"),0,0,1) ) { 1031 tr("Yes"),tr("No"),0,0,1) ) {
1031 case 0: 1032 case 0:
1032 if(doc) { 1033 if(doc) {
1033 doc->removeFiles(); 1034 doc->removeFiles();
1034 clear(); 1035 clear();
1035 setCaption( tr("Text Editor") ); 1036 setCaption( tr("Text Editor") );
1036 } 1037 }
1037 break; 1038 break;
1038 case 1: 1039 case 1:
1039 // exit 1040 // exit
1040 break; 1041 break;
1041 }; 1042 };
1042} 1043}
1043 1044
1044void TextEdit::changeStartConfig( bool b ) { 1045void TextEdit::changeStartConfig( bool b ) {
1045 startWithNew=b; 1046 startWithNew=b;
1046 Config cfg("TextEdit"); 1047 Config cfg("TextEdit");
1047 cfg.setGroup("View"); 1048 cfg.setGroup("View");
1048 cfg.writeEntry("startNew",b); 1049 cfg.writeEntry("startNew",b);
1049 update(); 1050 update();
1050} 1051}
1051 1052
1052void TextEdit::editorChanged() { 1053void TextEdit::editorChanged() {
1053// odebug << "editor changed" << oendl; 1054// odebug << "editor changed" << oendl;
1054 if( /*editor->edited() &&*/ /*edited && */!edited1) { 1055 if( /*editor->edited() &&*/ /*edited && */!edited1) {
1055 setCaption( "*"+caption()); 1056 setCaption( "*"+caption());
1056 edited1=true; 1057 edited1=true;
1057 } 1058 }
1058 edited=true; 1059 edited=true;
1059} 1060}
1060 1061
1061void TextEdit::receive(const QCString&msg, const QByteArray &) { 1062void TextEdit::receive(const QCString&msg, const QByteArray &) {
1062 odebug << "QCop "+msg << oendl; 1063 odebug << "QCop "+msg << oendl;
1063 if ( msg == "setDocument(QString)" ) { 1064 if ( msg == "setDocument(QString)" ) {
1064 odebug << "bugger all" << oendl; 1065 odebug << "bugger all" << oendl;
1065 1066
1066 } 1067 }
1067 1068
1068} 1069}
1069 1070
1070void TextEdit::doAbout() { 1071void TextEdit::doAbout() {
1071 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 1072 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
1072 "2000 Trolltech AS, and<BR>" 1073 "2000 Trolltech AS, and<BR>"
1073 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 1074 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
1074 "and is licensed under the GPL")); 1075 "and is licensed under the GPL"));
1075} 1076}
1076 1077
1077void TextEdit::doPrompt(bool b) { 1078void TextEdit::doPrompt(bool b) {
1078 promptExit=b; 1079 promptExit=b;
1079 Config cfg("TextEdit"); 1080 Config cfg("TextEdit");
1080 cfg.setGroup ( "View" ); 1081 cfg.setGroup ( "View" );
1081 cfg.writeEntry ( "PromptExit", b); 1082 cfg.writeEntry ( "PromptExit", b);
1082} 1083}
1083 1084
1084void TextEdit::doDesktop(bool b) { 1085void TextEdit::doDesktop(bool b) {
1085 openDesktop=b; 1086 openDesktop=b;
1086 Config cfg("TextEdit"); 1087 Config cfg("TextEdit");
1087 cfg.setGroup ( "View" ); 1088 cfg.setGroup ( "View" );
1088 cfg.writeEntry ( "OpenDesktop", b); 1089 cfg.writeEntry ( "OpenDesktop", b);
1089} 1090}
1090 1091
1091void TextEdit::doFilePerms(bool b) { 1092void TextEdit::doFilePerms(bool b) {
1092 filePerms=b; 1093 filePerms=b;
1093 Config cfg("TextEdit"); 1094 Config cfg("TextEdit");
1094 cfg.setGroup ( "View" ); 1095 cfg.setGroup ( "View" );
1095 cfg.writeEntry ( "FilePermissions", b); 1096 cfg.writeEntry ( "FilePermissions", b);
1096} 1097}
1097 1098
1098void TextEdit::editPasteTimeDate() { 1099void TextEdit::editPasteTimeDate() {
1099#ifndef QT_NO_CLIPBOARD 1100#ifndef QT_NO_CLIPBOARD
1100 QClipboard *cb = QApplication::clipboard(); 1101 QClipboard *cb = QApplication::clipboard();
1101 QDateTime dt = QDateTime::currentDateTime(); 1102 QDateTime dt = QDateTime::currentDateTime();
1102 cb->setText( dt.toString()); 1103 cb->setText( dt.toString());
1103 editor->paste(); 1104 editor->paste();
1104#endif 1105#endif
1105} 1106}
1106 1107
1107int TextEdit::savePrompt() 1108int TextEdit::savePrompt()
1108{ 1109{
1109 switch( QMessageBox::information( 0, (tr("Textedit")), 1110 switch( QMessageBox::information( 0, (tr("Textedit")),
1110 (tr("Textedit detected\n" 1111 (tr("Textedit detected\n"
1111 "you have unsaved changes\n" 1112 "you have unsaved changes\n"
1112 "Go ahead and save?\n")), 1113 "Go ahead and save?\n")),
1113 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) 1114 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
1114 { 1115 {
1115 case 0: 1116 case 0:
1116 { 1117 {
1117 return 1; 1118 return 1;
1118 } 1119 }
1119 break; 1120 break;
1120 1121
1121 case 1: 1122 case 1:
1122 { 1123 {
1123 return 2; 1124 return 2;
1124 } 1125 }
1125 break; 1126 break;
1126 1127
1127 case 2: 1128 case 2:
1128 { 1129 {
1129 return -1; 1130 return -1;
1130 } 1131 }
1131 break; 1132 break;
1132 }; 1133 };
1133 1134
1134 return 0; 1135 return 0;
1135} 1136}
1136 1137
1137void TextEdit::timerCrank() 1138void TextEdit::timerCrank()
1138{ 1139{
1139 if(featureAutoSave && edited1) 1140 if(featureAutoSave && edited1)
1140 { 1141 {
1141 if(currentFileName.isEmpty()) 1142 if(currentFileName.isEmpty())
1142 { 1143 {
1143 currentFileName = QDir::homeDirPath()+"/textedit.tmp"; 1144 currentFileName = QDir::homeDirPath()+"/textedit.tmp";
1144 saveAs(); 1145 saveAs();
1145 } 1146 }
1146 else 1147 else
1147 { 1148 {
1148// odebug << "autosave" << oendl; 1149// odebug << "autosave" << oendl;
1149 save(); 1150 save();
1150 } 1151 }
1151 setTimer(); 1152 setTimer();
1152 } 1153 }
1153} 1154}
1154 1155
1155void TextEdit::doTimer(bool b) 1156void TextEdit::doTimer(bool b)
1156{ 1157{
1157 Config cfg("TextEdit"); 1158 Config cfg("TextEdit");
1158 cfg.setGroup ( "View" ); 1159 cfg.setGroup ( "View" );
1159 cfg.writeEntry ( "autosave", b); 1160 cfg.writeEntry ( "autosave", b);
1160 featureAutoSave = b; 1161 featureAutoSave = b;
1161 nAutoSave->setOn(b); 1162 nAutoSave->setOn(b);
1162 if(b) 1163 if(b)
1163 { 1164 {
1164// odebug << "doTimer true" << oendl; 1165// odebug << "doTimer true" << oendl;
1165 setTimer(); 1166 setTimer();
1166 } 1167 }
1167// else 1168// else
1168// odebug << "doTimer false" << oendl; 1169// odebug << "doTimer false" << oendl;
1169} 1170}
1170 1171
1171void TextEdit::setTimer() 1172void TextEdit::setTimer()
1172{ 1173{
1173if(featureAutoSave) 1174if(featureAutoSave)
1174 { 1175 {
1175// odebug << "setting autosave" << oendl; 1176// odebug << "setting autosave" << oendl;
1176 QTimer *timer = new QTimer(this ); 1177 QTimer *timer = new QTimer(this );
1177 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); 1178 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
1178 timer->start( 300000, true); //5 minutes 1179 timer->start( 300000, true); //5 minutes
1179 } 1180 }
1180} 1181}
1181 1182
1182void TextEdit::gotoLine() { 1183void TextEdit::gotoLine() {
1183 if( editor->length() < 1) 1184 if( editor->length() < 1)
1184 return; 1185 return;
1185 QWidget *d = QApplication::desktop(); 1186 QWidget *d = QApplication::desktop();
1186 gotoEdit = new QLineEdit( 0, "Goto line"); 1187 gotoEdit = new QLineEdit( 0, "Goto line");
1187 1188
1188 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); 1189 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2));
1189 gotoEdit->setFrame(true); 1190 gotoEdit->setFrame(true);
1190 gotoEdit->show(); 1191 gotoEdit->show();
1191 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); 1192 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto()));
1192} 1193}
1193 1194
1194void TextEdit::doGoto() { 1195void TextEdit::doGoto() {
1195 QString number = gotoEdit->text(); 1196 QString number = gotoEdit->text();
1196 gotoEdit->hide(); 1197 gotoEdit->hide();
1197 1198
1198 if(gotoEdit) { 1199 if(gotoEdit) {
1199 delete gotoEdit; 1200 delete gotoEdit;
1200 gotoEdit = 0; 1201 gotoEdit = 0;
1201 } 1202 }
1202 1203
1203 bool ok; 1204 bool ok;
1204 int lineNumber = number.toInt(&ok, 10); 1205 int lineNumber = number.toInt(&ok, 10);
1205 if( editor->numLines() < lineNumber) 1206 if( editor->numLines() < lineNumber)
1206 QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); 1207 QMessageBox::message(tr("Text Edit"),tr("Not enough lines"));
1207 else 1208 else
1208 { 1209 {
1209 editor->setCursorPosition(lineNumber, 0, false); 1210 editor->setCursorPosition(lineNumber, 0, false);
1210 } 1211 }
1211} 1212}