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