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