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