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