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