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