summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index f38ea53..e3b8361 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -3,993 +3,1000 @@
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); 265 QPopupMenu *advancedMenu = new QPopupMenu(this);
266 266
267 font = new QPopupMenu( this ); 267 font = new QPopupMenu( this );
268 268
269 bar = new QPEToolBar( this ); 269 bar = new QPEToolBar( this );
270 editBar = bar; 270 editBar = bar;
271 271
272 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 );
273 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 273 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
274 a->addTo( bar ); 274 a->addTo( bar );
275 a->addTo( file ); 275 a->addTo( file );
276 276
277 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 );
278 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 278 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
279 a->addTo( bar ); 279 a->addTo( bar );
280 a->addTo( file ); 280 a->addTo( file );
281 281
282 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 );
283 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 283 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
284 file->insertSeparator(); 284 file->insertSeparator();
285 a->addTo( file ); 285 a->addTo( file );
286 286
287 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 287 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
288 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 288 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
289 a->addTo( file ); 289 a->addTo( file );
290 290
291 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 291 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
292 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 292 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
293 a->addTo( editBar ); 293 a->addTo( editBar );
294 a->addTo( edit ); 294 a->addTo( edit );
295 295
296 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 296 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
297 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 297 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
298 a->addTo( editBar ); 298 a->addTo( editBar );
299 a->addTo( edit ); 299 a->addTo( edit );
300 300
301 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 301 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
302 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 302 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
303 a->addTo( editBar ); 303 a->addTo( editBar );
304 a->addTo( edit ); 304 a->addTo( edit );
305 305
306 306
307#ifndef QT_NO_CLIPBOARD 307#ifndef QT_NO_CLIPBOARD
308 a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 308 a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
309 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); 309 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) );
310 a->addTo( edit ); 310 a->addTo( edit );
311#endif 311#endif
312 312
313 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 313 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
314 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 314 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
315 edit->insertSeparator(); 315 edit->insertSeparator();
316 a->addTo( bar ); 316 a->addTo( bar );
317 a->addTo( edit ); 317 a->addTo( edit );
318 318
319 319
320 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 320 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
321 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 321 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
322 zin->addTo( font ); 322 zin->addTo( font );
323 323
324 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 324 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
325 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 325 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
326 zout->addTo( font ); 326 zout->addTo( font );
327 327
328 font->insertSeparator(); 328 font->insertSeparator();
329// font->insertSeparator(); 329// font->insertSeparator();
330 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 330 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
331 331
332 font->insertSeparator(); 332 font->insertSeparator();
333 font->insertItem(tr("Advanced Features"), advancedMenu); 333 font->insertItem(tr("Advanced Features"), advancedMenu);
334 334
335 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 335 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
336 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 336 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
337 wa->setToggleAction(TRUE); 337 wa->setToggleAction(TRUE);
338 wa->addTo( advancedMenu); 338 wa->addTo( advancedMenu);
339 339
340 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 340 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
341 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 341 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
342 nStart->setToggleAction(TRUE); 342 nStart->setToggleAction(TRUE);
343 nStart->addTo( advancedMenu ); 343 nStart->addTo( advancedMenu );
344 344
345 nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); 345 nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 );
346 connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); 346 connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) );
347 nAdvanced->setToggleAction(TRUE); 347 nAdvanced->setToggleAction(TRUE);
348 nAdvanced->addTo( advancedMenu ); 348 nAdvanced->addTo( advancedMenu );
349 349
350 desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); 350 desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 );
351 connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); 351 connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) );
352 desktopAction->setToggleAction(TRUE); 352 desktopAction->setToggleAction(TRUE);
353 desktopAction->addTo( advancedMenu); 353 desktopAction->addTo( advancedMenu);
354 354
355 filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); 355 filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 );
356 connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); 356 connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) );
357 filePermAction->setToggleAction(TRUE); 357 filePermAction->setToggleAction(TRUE);
358 filePermAction->addTo( advancedMenu); 358 filePermAction->addTo( advancedMenu);
359 359
360 font->insertSeparator(); 360 font->insertSeparator();
361 361
362 font->insertItem(tr("About"), this, SLOT( doAbout()) ); 362 font->insertItem(tr("About"), this, SLOT( doAbout()) );
363 363
364 mb->insertItem( tr( "File" ), file ); 364 mb->insertItem( tr( "File" ), file );
365 mb->insertItem( tr( "Edit" ), edit ); 365 mb->insertItem( tr( "Edit" ), edit );
366 mb->insertItem( tr( "View" ), font ); 366 mb->insertItem( tr( "View" ), font );
367 367
368 searchBar = new QPEToolBar(this); 368 searchBar = new QPEToolBar(this);
369 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 369 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
370 370
371 searchBar->setHorizontalStretchable( TRUE ); 371 searchBar->setHorizontalStretchable( TRUE );
372 372
373 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 373 searchEdit = new QLineEdit( searchBar, "searchEdit" );
374 searchBar->setStretchableWidget( searchEdit ); 374 searchBar->setStretchableWidget( searchEdit );
375 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 375 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
376 this, SLOT( search() ) ); 376 this, SLOT( search() ) );
377 377
378 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 );
379 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 379 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
380 a->addTo( searchBar ); 380 a->addTo( searchBar );
381 a->addTo( edit ); 381 a->addTo( edit );
382 382
383 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 );
384 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 384 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
385 a->addTo( searchBar ); 385 a->addTo( searchBar );
386 386
387 edit->insertSeparator(); 387 edit->insertSeparator();
388 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 );
389 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 389 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
390 a->addTo( edit ); 390 a->addTo( edit );
391 391
392 searchBar->hide(); 392 searchBar->hide();
393 393
394 editor = new QpeEditor( this ); 394 editor = new QpeEditor( this );
395 setCentralWidget( editor ); 395 setCentralWidget( editor );
396 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 396 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
397 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 397 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
398 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 398 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
399 399
400 Config cfg("TextEdit"); 400 Config cfg("TextEdit");
401 cfg. setGroup ( "Font" ); 401 cfg. setGroup ( "Font" );
402 402
403 QFont defaultFont = editor-> font ( ); 403 QFont defaultFont = editor-> font ( );
404 404
405 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 405 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
406 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 406 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
407 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 407 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
408 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 408 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
409 409
410 defaultFont = QFont ( family, size, weight, italic ); 410 defaultFont = QFont ( family, size, weight, italic );
411 editor-> setFont ( defaultFont ); 411 editor-> setFont ( defaultFont );
412 412
413 updateCaption(); 413 updateCaption();
414 414
415 cfg.setGroup ( "View" ); 415 cfg.setGroup ( "View" );
416 416
417 promptExit = cfg. readBoolEntry ( "PromptExit", false ); 417 promptExit = cfg. readBoolEntry ( "PromptExit", false );
418 openDesktop = cfg. readBoolEntry ( "OpenDesktop", true ); 418 openDesktop = cfg. readBoolEntry ( "OpenDesktop", true );
419 filePerms = cfg. readBoolEntry ( "FilePermissions", false ); 419 filePerms = cfg. readBoolEntry ( "FilePermissions", false );
420 420
421 if(promptExit ) nAdvanced->setOn ( true ); 421 if(promptExit ) nAdvanced->setOn ( true );
422 if(openDesktop) desktopAction->setOn ( true ); 422 if(openDesktop) desktopAction->setOn ( true );
423 if(filePerms) filePermAction->setOn ( true ); 423 if(filePerms) filePermAction->setOn ( true );
424 424
425 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 425 bool wrap = cfg. readBoolEntry ( "Wrap", true );
426 wa-> setOn ( wrap ); 426 wa-> setOn ( wrap );
427 setWordWrap ( wrap ); 427 setWordWrap ( wrap );
428 428
429 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 429 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
430 nStart->setOn(TRUE); 430 nStart->setOn(TRUE);
431 fileNew(); 431 fileNew();
432 } else { 432 } else {
433 fileOpen(); 433 fileOpen();
434 } 434 }
435 435
436 viewSelection = cfg.readNumEntry( "FileView", 0 ); 436 viewSelection = cfg.readNumEntry( "FileView", 0 );
437} 437}
438 438
439TextEdit::~TextEdit() { 439TextEdit::~TextEdit() {
440 if( edited1 & promptExit ) 440 if( edited1 & promptExit )
441 saveAs(); 441 saveAs();
442} 442}
443 443
444void TextEdit::cleanUp() { 444void TextEdit::cleanUp() {
445 qDebug("cleanUp");// save(); 445 qDebug("cleanUp");// save();
446 446
447 Config cfg ( "TextEdit" ); 447 Config cfg ( "TextEdit" );
448 cfg. setGroup ( "Font" ); 448 cfg. setGroup ( "Font" );
449 QFont f = editor->font(); 449 QFont f = editor->font();
450 cfg. writeEntry ( "Family", f. family ( )); 450 cfg. writeEntry ( "Family", f. family ( ));
451 cfg. writeEntry ( "Size", f. pointSize ( )); 451 cfg. writeEntry ( "Size", f. pointSize ( ));
452 cfg. writeEntry ( "Weight", f. weight ( )); 452 cfg. writeEntry ( "Weight", f. weight ( ));
453 cfg. writeEntry ( "Italic", f. italic ( )); 453 cfg. writeEntry ( "Italic", f. italic ( ));
454 454
455 cfg. setGroup ( "View" ); 455 cfg. setGroup ( "View" );
456 cfg. writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth ); 456 cfg. writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth );
457 cfg. writeEntry ( "FileView", viewSelection ); 457 cfg. writeEntry ( "FileView", viewSelection );
458 458
459 cfg. writeEntry ( "PromptExit", promptExit ); 459 cfg. writeEntry ( "PromptExit", promptExit );
460 cfg. writeEntry ( "OpenDesktop", openDesktop ); 460 cfg. writeEntry ( "OpenDesktop", openDesktop );
461 cfg. writeEntry ( "FilePermissions", filePerms ); 461 cfg. writeEntry ( "FilePermissions", filePerms );
462} 462}
463 463
464 464
465void TextEdit::accept() { 465void TextEdit::accept() {
466 if( edited1) 466 if( edited1)
467 saveAs(); 467 saveAs();
468 exit(0); 468 exit(0);
469} 469}
470 470
471void TextEdit::zoomIn() { 471void TextEdit::zoomIn() {
472 setFontSize(editor->font().pointSize()+1,FALSE); 472 setFontSize(editor->font().pointSize()+1,FALSE);
473} 473}
474 474
475void TextEdit::zoomOut() { 475void TextEdit::zoomOut() {
476 setFontSize(editor->font().pointSize()-1,TRUE); 476 setFontSize(editor->font().pointSize()-1,TRUE);
477} 477}
478 478
479 479
480void TextEdit::setFontSize(int sz, bool round_down_not_up) { 480void TextEdit::setFontSize(int sz, bool round_down_not_up) {
481 int s=10; 481 int s=10;
482 for (int i=0; i<nfontsizes; i++) { 482 for (int i=0; i<nfontsizes; i++) {
483 if ( fontsize[i] == sz ) { 483 if ( fontsize[i] == sz ) {
484 s = sz; 484 s = sz;
485 break; 485 break;
486 } else if ( round_down_not_up ) { 486 } else if ( round_down_not_up ) {
487 if ( fontsize[i] < sz ) 487 if ( fontsize[i] < sz )
488 s = fontsize[i]; 488 s = fontsize[i];
489 } else { 489 } else {
490 if ( fontsize[i] > sz ) { 490 if ( fontsize[i] > sz ) {
491 s = fontsize[i]; 491 s = fontsize[i];
492 break; 492 break;
493 } 493 }
494 } 494 }
495 } 495 }
496 496
497 QFont f = editor->font(); 497 QFont f = editor->font();
498 f.setPointSize(s); 498 f.setPointSize(s);
499 editor->setFont(f); 499 editor->setFont(f);
500 500
501 zin->setEnabled(s != fontsize[nfontsizes-1]); 501 zin->setEnabled(s != fontsize[nfontsizes-1]);
502 zout->setEnabled(s != fontsize[0]); 502 zout->setEnabled(s != fontsize[0]);
503} 503}
504 504
505void TextEdit::setBold(bool y) { 505void TextEdit::setBold(bool y) {
506 QFont f = editor->font(); 506 QFont f = editor->font();
507 f.setBold(y); 507 f.setBold(y);
508 editor->setFont(f); 508 editor->setFont(f);
509} 509}
510 510
511void TextEdit::setItalic(bool y) { 511void TextEdit::setItalic(bool y) {
512 QFont f = editor->font(); 512 QFont f = editor->font();
513 f.setItalic(y); 513 f.setItalic(y);
514 editor->setFont(f); 514 editor->setFont(f);
515} 515}
516 516
517void TextEdit::setWordWrap(bool y) { 517void TextEdit::setWordWrap(bool y) {
518 bool state = editor->edited(); 518 bool state = editor->edited();
519 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 519 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
520 editor->setEdited( state ); 520 editor->setEdited( state );
521} 521}
522 522
523void TextEdit::fileNew() { 523void TextEdit::fileNew() {
524// if( !bFromDocView ) { 524// if( !bFromDocView ) {
525// saveAs(); 525// saveAs();
526// } 526// }
527 newFile(DocLnk()); 527 newFile(DocLnk());
528} 528}
529 529
530void TextEdit::fileOpen() { 530void TextEdit::fileOpen() {
531 Config cfg("TextEdit"); 531 Config cfg("TextEdit");
532 cfg.setGroup("View"); 532 cfg.setGroup("View");
533 // bool b=FALSE; 533 // bool b=FALSE;
534 534
535 QMap<QString, QStringList> map; 535 QMap<QString, QStringList> map;
536 map.insert(tr("All"), QStringList() ); 536 map.insert(tr("All"), QStringList() );
537 QStringList text; 537 QStringList text;
538 text << "text/*"; 538 text << "text/*";
539 map.insert(tr("Text"), text ); 539 map.insert(tr("Text"), text );
540 text << "*"; 540 text << "*";
541 map.insert(tr("All"), text ); 541 map.insert(tr("All"), text );
542 QString str = OFileDialog::getOpenFileName( 2, QPEApplication::documentDir(), QString::null, map); 542 QString str = OFileDialog::getOpenFileName( 2, QPEApplication::documentDir(), QString::null, map);
543 if(!str.isEmpty() ) 543 if(!str.isEmpty() )
544 openFile( str ); 544 openFile( str );
545 545
546} 546}
547 547
548void TextEdit::doSearchBar() { 548void TextEdit::doSearchBar() {
549 Config cfg("TextEdit"); 549 Config cfg("TextEdit");
550 cfg.setGroup("View"); 550 cfg.setGroup("View");
551 if(cfg.readEntry("SearchBar","Closed") != "Opened") 551 if(cfg.readEntry("SearchBar","Closed") != "Opened")
552 searchBar->hide(); 552 searchBar->hide();
553} 553}
554 554
555#if 0 555#if 0
556void TextEdit::slotFind() { 556void TextEdit::slotFind() {
557 FindDialog frmFind( tr("Text Editor"), this ); 557 FindDialog frmFind( tr("Text Editor"), this );
558 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 558 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
559 editor, SLOT(slotDoFind( const QString&,bool,bool))); 559 editor, SLOT(slotDoFind( const QString&,bool,bool)));
560 560
561 //case sensitive, backwards, [category] 561 //case sensitive, backwards, [category]
562 562
563 connect( editor, SIGNAL(notFound()), 563 connect( editor, SIGNAL(notFound()),
564 &frmFind, SLOT(slotNotFound()) ); 564 &frmFind, SLOT(slotNotFound()) );
565 connect( editor, SIGNAL(searchWrapped()), 565 connect( editor, SIGNAL(searchWrapped()),
566 &frmFind, SLOT(slotWrapAround()) ); 566 &frmFind, SLOT(slotWrapAround()) );
567 567
568 frmFind.exec(); 568 frmFind.exec();
569 569
570 570
571} 571}
572#endif 572#endif
573 573
574void TextEdit::fileRevert() { 574void TextEdit::fileRevert() {
575 clear(); 575 clear();
576 fileOpen(); 576 fileOpen();
577} 577}
578 578
579void TextEdit::editCut() { 579void TextEdit::editCut() {
580#ifndef QT_NO_CLIPBOARD 580#ifndef QT_NO_CLIPBOARD
581 editor->cut(); 581 editor->cut();
582#endif 582#endif
583} 583}
584 584
585void TextEdit::editCopy() { 585void TextEdit::editCopy() {
586#ifndef QT_NO_CLIPBOARD 586#ifndef QT_NO_CLIPBOARD
587 editor->copy(); 587 editor->copy();
588#endif 588#endif
589} 589}
590 590
591void TextEdit::editPaste() { 591void TextEdit::editPaste() {
592#ifndef QT_NO_CLIPBOARD 592#ifndef QT_NO_CLIPBOARD
593 editor->paste(); 593 editor->paste();
594#endif 594#endif
595} 595}
596 596
597void TextEdit::editFind() { 597void TextEdit::editFind() {
598 searchBar->show(); 598 searchBar->show();
599 searchVisible = TRUE; 599 searchVisible = TRUE;
600 searchEdit->setFocus(); 600 searchEdit->setFocus();
601 Config cfg("TextEdit"); 601 Config cfg("TextEdit");
602 cfg.setGroup("View"); 602 cfg.setGroup("View");
603 cfg.writeEntry("SearchBar","Opened"); 603 cfg.writeEntry("SearchBar","Opened");
604 604
605} 605}
606 606
607void TextEdit::findNext() { 607void TextEdit::findNext() {
608 editor->find( searchEdit->text(), FALSE, FALSE ); 608 editor->find( searchEdit->text(), FALSE, FALSE );
609 609
610} 610}
611 611
612void TextEdit::findClose() { 612void TextEdit::findClose() {
613 searchVisible = FALSE; 613 searchVisible = FALSE;
614 searchBar->hide(); 614 searchBar->hide();
615 Config cfg("TextEdit"); 615 Config cfg("TextEdit");
616 cfg.setGroup("View"); 616 cfg.setGroup("View");
617 cfg.writeEntry("SearchBar","Closed"); 617 cfg.writeEntry("SearchBar","Closed");
618 cfg.write(); 618 cfg.write();
619} 619}
620 620
621void TextEdit::search() { 621void TextEdit::search() {
622 editor->find( searchEdit->text(), FALSE, FALSE ); 622 editor->find( searchEdit->text(), FALSE, FALSE );
623} 623}
624 624
625void TextEdit::newFile( const DocLnk &f ) { 625void TextEdit::newFile( const DocLnk &f ) {
626 DocLnk nf = f; 626 DocLnk nf = f;
627 nf.setType("text/plain"); 627 nf.setType("text/plain");
628 clear(); 628 clear();
629 setWState (WState_Reserved1 ); 629 setWState (WState_Reserved1 );
630 editor->setFocus(); 630 editor->setFocus();
631 doc = new DocLnk(nf); 631 doc = new DocLnk(nf);
632 currentFileName = "Unnamed"; 632 currentFileName = "Unnamed";
633 qDebug("newFile "+currentFileName); 633 qDebug("newFile "+currentFileName);
634 updateCaption( currentFileName); 634 updateCaption( currentFileName);
635// editor->setEdited( FALSE); 635// editor->setEdited( FALSE);
636} 636}
637 637
638void TextEdit::openFile( const QString &f ) { 638void TextEdit::openFile( const QString &f ) {
639 qDebug("filename is "+ f); 639 qDebug("filename is "+ f);
640 QString filer; 640 QString filer;
641// bFromDocView = TRUE; 641// bFromDocView = TRUE;
642 if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) { 642 if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) {
643 switch ( QMessageBox::warning(this,tr("Text Editor"), 643 switch ( QMessageBox::warning(this,tr("Text Editor"),
644 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 644 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
645file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 645file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
646 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 646 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
647 case 0: 647 case 0:
648 filer = f; 648 filer = f;
649 break; 649 break;
650 case 1: 650 case 1:
651 DocLnk sf(f); 651 DocLnk sf(f);
652 filer = sf.file(); 652 filer = sf.file();
653 break; 653 break;
654 } 654 }
655 } else { 655 } else {
656 DocLnk sf(f); 656 DocLnk sf(f);
657 filer = sf.file(); 657 filer = sf.file();
658 if(filer.right(1) == "/") 658 if(filer.right(1) == "/")
659 filer = f; 659 filer = f;
660 } 660 }
661 661
662 DocLnk nf; 662 DocLnk nf;
663 nf.setType("text/plain"); 663 nf.setType("text/plain");
664 nf.setFile(filer); 664 nf.setFile(filer);
665 currentFileName=filer; 665 currentFileName=filer;
666 QFileInfo fi( currentFileName); 666 QFileInfo fi( currentFileName);
667 nf.setName(fi.baseName()); 667 nf.setName(fi.baseName());
668 qDebug("openFile string "+currentFileName); 668 qDebug("openFile string "+currentFileName);
669 669
670 openFile(nf); 670 openFile(nf);
671 showEditTools(); 671 showEditTools();
672 // Show filename in caption 672 // Show filename in caption
673 QString name = filer; 673 QString name = filer;
674 int sep = name.findRev( '/' ); 674 int sep = name.findRev( '/' );
675 if ( sep > 0 ) 675 if ( sep > 0 )
676 name = name.mid( sep+1 ); 676 name = name.mid( sep+1 );
677 updateCaption( name ); 677 updateCaption( name );
678} 678}
679 679
680void TextEdit::openFile( const DocLnk &f ) { 680void TextEdit::openFile( const DocLnk &f ) {
681// clear(); 681// clear();
682// bFromDocView = TRUE; 682// bFromDocView = TRUE;
683 FileManager fm; 683 FileManager fm;
684 QString txt; 684 QString txt;
685 currentFileName=f.file(); 685 currentFileName=f.file();
686 qDebug("openFile doclnk " + currentFileName); 686 qDebug("openFile doclnk " + currentFileName);
687 if ( !fm.loadFile( f, txt ) ) { 687 if ( !fm.loadFile( f, txt ) ) {
688 // ####### could be a new file 688 // ####### could be a new file
689 qDebug( "Cannot open file" ); 689 qDebug( "Cannot open file" );
690 } 690 }
691// fileNew(); 691// fileNew();
692 if ( doc ) 692 if ( doc )
693 delete doc; 693 delete doc;
694 doc = new DocLnk(f); 694 doc = new DocLnk(f);
695 editor->setText(txt); 695 editor->setText(txt);
696 editor->setEdited( FALSE); 696 editor->setEdited( FALSE);
697 edited1=FALSE; 697 edited1=FALSE;
698 edited=FALSE; 698 edited=FALSE;
699 699
700 doc->setName(currentFileName); 700 doc->setName(currentFileName);
701 updateCaption(); 701 updateCaption();
702} 702}
703 703
704void TextEdit::showEditTools() { 704void TextEdit::showEditTools() {
705// if ( !doc ) 705// if ( !doc )
706// close(); 706// close();
707// clear(); 707// clear();
708 menu->show(); 708 menu->show();
709 editBar->show(); 709 editBar->show();
710 if ( searchVisible ) 710 if ( searchVisible )
711 searchBar->show(); 711 searchBar->show();
712// updateCaption(); 712// updateCaption();
713 setWState (WState_Reserved1 ); 713 setWState (WState_Reserved1 );
714} 714}
715 715
716/*! 716/*!
717 unprompted save */ 717 unprompted save */
718bool TextEdit::save() { 718bool TextEdit::save() {
719 QString file = doc->file(); 719 QString file = doc->file();
720 qDebug("saver file "+file); 720 qDebug("saver file "+file);
721 QString name= doc->name(); 721 QString name= doc->name();
722 qDebug("File named "+name); 722 qDebug("File named "+name);
723 QString rt = editor->text(); 723 QString rt = editor->text();
724 if( !rt.isEmpty() ) { 724 if( !rt.isEmpty() ) {
725 if(name.isEmpty()) { 725 if(name.isEmpty()) {
726 saveAs(); 726 saveAs();
727 } else { 727 } else {
728 currentFileName= name ; 728 currentFileName= name ;
729 qDebug("saveFile "+currentFileName); 729 qDebug("saveFile "+currentFileName);
730 730
731 struct stat buf; 731 struct stat buf;
732 mode_t mode; 732 mode_t mode;
733 stat(file.latin1(), &buf); 733 stat(file.latin1(), &buf);
734 mode = buf.st_mode; 734 mode = buf.st_mode;
735 735
736 if(!fileIs) { 736 if(!fileIs) {
737 doc->setName( name); 737 doc->setName( name);
738 FileManager fm; 738 FileManager fm;
739 if ( !fm.saveFile( *doc, rt ) ) { 739 if ( !fm.saveFile( *doc, rt ) ) {
740 return false; 740 return false;
741 } 741 }
742 } else { 742 } else {
743 qDebug("regular save file"); 743 qDebug("regular save file");
744 QFile f(file); 744 QFile f(file);
745 if( f.open(IO_WriteOnly)) { 745 if( f.open(IO_WriteOnly)) {
746 QCString crt = rt.utf8(); 746 QCString crt = rt.utf8();
747 f.writeBlock(crt,crt.length()); 747 f.writeBlock(crt,crt.length());
748 } else { 748 } else {
749 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 749 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
750 return false; 750 return false;
751 } 751 }
752 752
753 } 753 }
754 editor->setEdited( FALSE); 754 editor->setEdited( FALSE);
755 edited1=FALSE; 755 edited1=FALSE;
756 edited=FALSE; 756 edited=FALSE;
757 if(caption().left(1)=="*") 757 if(caption().left(1)=="*")
758 setCaption(caption().right(caption().length()-1)); 758 setCaption(caption().right(caption().length()-1));
759 759
760 760
761 chmod( file.latin1(), mode); 761 chmod( file.latin1(), mode);
762 } 762 }
763 return true; 763 return true;
764 } 764 }
765 return false; 765 return false;
766} 766}
767 767
768/*! 768/*!
769 prompted save */ 769 prompted save */
770bool TextEdit::saveAs() { 770bool TextEdit::saveAs() {
771 qDebug("saveAsFile "+currentFileName); 771 qDebug("saveAsFile " + currentFileName);
772 // case of nothing to save... 772 // case of nothing to save...
773 if ( !doc ) { 773 if ( !doc ) {
774//|| !bFromDocView) 774//|| !bFromDocView)
775 qDebug("no doc"); 775 qDebug("no doc");
776 return true; 776 return true;
777 } 777 }
778 if ( !editor->edited() ) { 778 if ( !editor->edited() ) {
779 delete doc; 779 delete doc;
780 doc = 0; 780 doc = 0;
781 return true; 781 return true;
782 } 782 }
783 783
784 QString rt = editor->text(); 784 QString rt = editor->text();
785 qDebug(currentFileName); 785 qDebug(currentFileName);
786 786
787 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 787 if( currentFileName.isEmpty()
788 || currentFileName == tr("Unnamed")
789 || currentFileName == tr("Text Editor")) {
788// qDebug("do silly TT filename thing"); 790// qDebug("do silly TT filename thing");
789 if ( doc->name().isEmpty() ) { 791 if ( doc->name().isEmpty() ) {
790 QString pt = rt.simplifyWhiteSpace(); 792 QString pt = rt.simplifyWhiteSpace();
791 int i = pt.find( ' ' ); 793 int i = pt.find( ' ' );
792 QString docname = pt; 794 QString docname = pt;
793 if ( i > 0 ) 795 if ( i > 0 )
794 docname = pt.left( i ); 796 docname = pt.left( i );
795 // remove "." at the beginning 797 // remove "." at the beginning
796 while( docname.startsWith( "." ) ) 798 while( docname.startsWith( "." ) )
797 docname = docname.mid( 1 ); 799 docname = docname.mid( 1 );
798 docname.replace( QRegExp("/"), "_" ); 800 docname.replace( QRegExp("/"), "_" );
799 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 801 // cut the length. filenames longer than that
802 //don't make sense and something goes wrong when they get too long.
800 if ( docname.length() > 40 ) 803 if ( docname.length() > 40 )
801 docname = docname.left(40); 804 docname = docname.left(40);
802 if ( docname.isEmpty() ) 805 if ( docname.isEmpty() )
803 docname = tr("Unnamed"); 806 docname = tr("Unnamed");
804 doc->setName(docname); 807 doc->setName(docname);
805 currentFileName=docname; 808 currentFileName=docname;
806 } 809 }
807 } 810 }
808 811
809 QMap<QString, QStringList> map; 812 QMap<QString, QStringList> map;
810 map.insert(tr("All"), QStringList() ); 813 map.insert(tr("All"), QStringList() );
811 QStringList text; 814 QStringList text;
812 text << "text/*"; 815 text << "text/*";
813 map.insert(tr("Text"), text ); 816 map.insert(tr("Text"), text );
814 text << "*"; 817 text << "*";
815 map.insert(tr("All"), text ); 818 map.insert(tr("All"), text );
816 819// if(currentFileName
817 QString str = OFileDialog::getSaveFileName( 2,QPEApplication::documentDir(), QString::null, map); 820 QString str = OFileDialog::getSaveFileName( 2,
821 QPEApplication::documentDir(),
822 currentFileName, map);
818 823
819 if(!str.isEmpty() ) { 824 if(!str.isEmpty() ) {
820 QString fileNm=str; 825 QString fileNm=str;
821 826
822 qDebug("saving filename "+fileNm); 827 qDebug("saving filename "+fileNm);
823 QFileInfo fi(fileNm); 828 QFileInfo fi(fileNm);
824 currentFileName=fi.fileName(); 829 currentFileName=fi.fileName();
825 if(doc) { 830 if(doc) {
826// QString file = doc->file(); 831// QString file = doc->file();
827// doc->removeFiles(); 832// doc->removeFiles();
828 delete doc; 833 delete doc;
829 DocLnk nf; 834 DocLnk nf;
830 nf.setType("text/plain"); 835 nf.setType("text/plain");
831 nf.setFile( fileNm); 836 nf.setFile( fileNm);
832 doc = new DocLnk(nf); 837 doc = new DocLnk(nf);
833// editor->setText(rt); 838// editor->setText(rt);
834// qDebug("openFile doclnk "+currentFileName); 839// qDebug("openFile doclnk "+currentFileName);
835 doc->setName( currentFileName); 840 doc->setName( currentFileName);
836 updateCaption( currentFileName); 841 updateCaption( currentFileName);
837 842
838 FileManager fm; 843 FileManager fm;
839 if ( !fm.saveFile( *doc, rt ) ) { 844 if ( !fm.saveFile( *doc, rt ) ) {
840 return false; 845 return false;
841 } 846 }
842 847
843 if( filePerms ) { 848 if( filePerms ) {
844 filePermissions *filePerm; 849 filePermissions *filePerm;
845 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 850 filePerm = new filePermissions(this,
851 tr("Permissions"),true,
852 0,(const QString &)fileNm);
846 filePerm->showMaximized(); 853 filePerm->showMaximized();
847 filePerm->exec(); 854 filePerm->exec();
848 855
849 if( filePerm) 856 if( filePerm)
850 delete filePerm; 857 delete filePerm;
851 } 858 }
852 } 859 }
853 editor->setEdited( false); 860 editor->setEdited( false);
854 edited1 = false; 861 edited1 = false;
855 edited = false; 862 edited = false;
856 if(caption().left(1)=="*") 863 if(caption().left(1)=="*")
857 setCaption(caption().right(caption().length()-1)); 864 setCaption(caption().right(caption().length()-1));
858 865
859 return true; 866 return true;
860 } 867 }
861 qDebug("returning false"); 868 qDebug("returning false");
862 return false; 869 return false;
863} //end saveAs 870} //end saveAs
864 871
865void TextEdit::clear() { 872void TextEdit::clear() {
866 delete doc; 873 delete doc;
867 doc = 0; 874 doc = 0;
868 editor->clear(); 875 editor->clear();
869} 876}
870 877
871void TextEdit::updateCaption( const QString &name ) { 878void TextEdit::updateCaption( const QString &name ) {
872 if ( !doc ) 879 if ( !doc )
873 setCaption( tr("Text Editor") ); 880 setCaption( tr("Text Editor") );
874 else { 881 else {
875 QString s = name; 882 QString s = name;
876 if ( s.isNull() ) 883 if ( s.isNull() )
877 s = doc->name(); 884 s = doc->name();
878 if ( s.isEmpty() ) { 885 if ( s.isEmpty() ) {
879 s = tr( "Unnamed" ); 886 s = tr( "Unnamed" );
880 currentFileName=s; 887 currentFileName=s;
881 } 888 }
882 if(s.left(1) == "/") 889 if(s.left(1) == "/")
883 s = s.right(s.length()-1); 890 s = s.right(s.length()-1);
884 setCaption( s + " - " + tr("Text Editor") ); 891 setCaption( s + " - " + tr("Text Editor") );
885 } 892 }
886} 893}
887 894
888void TextEdit::setDocument(const QString& fileref) { 895void TextEdit::setDocument(const QString& fileref) {
889 bFromDocView = TRUE; 896 bFromDocView = TRUE;
890 openFile(fileref); 897 openFile(fileref);
891 editor->setEdited(TRUE); 898 editor->setEdited(TRUE);
892 edited1=FALSE; 899 edited1=FALSE;
893 edited=TRUE; 900 edited=TRUE;
894 doSearchBar(); 901 doSearchBar();
895} 902}
896 903
897void TextEdit::closeEvent( QCloseEvent *e ) { 904void TextEdit::closeEvent( QCloseEvent *e ) {
898 bFromDocView = FALSE; 905 bFromDocView = FALSE;
899 e->accept(); 906 e->accept();
900} 907}
901 908
902void TextEdit::changeFont() { 909void TextEdit::changeFont() {
903 QDialog *d = new QDialog ( this, "FontDialog", true ); 910 QDialog *d = new QDialog ( this, "FontDialog", true );
904 d-> setCaption ( tr( "Choose font" )); 911 d-> setCaption ( tr( "Choose font" ));
905 QBoxLayout *lay = new QVBoxLayout ( d ); 912 QBoxLayout *lay = new QVBoxLayout ( d );
906 OFontSelector *ofs = new OFontSelector ( true, d ); 913 OFontSelector *ofs = new OFontSelector ( true, d );
907 lay-> addWidget ( ofs ); 914 lay-> addWidget ( ofs );
908 ofs-> setSelectedFont ( editor-> font ( )); 915 ofs-> setSelectedFont ( editor-> font ( ));
909 916
910 d-> showMaximized ( ); 917 d-> showMaximized ( );
911 if ( d-> exec ( ) == QDialog::Accepted ) 918 if ( d-> exec ( ) == QDialog::Accepted )
912 editor-> setFont ( ofs-> selectedFont ( )); 919 editor-> setFont ( ofs-> selectedFont ( ));
913 delete d; 920 delete d;
914 921
915} 922}
916 923
917void TextEdit::editDelete() { 924void TextEdit::editDelete() {
918 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) ) { 925 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) ) {
919 case 0: 926 case 0:
920 if(doc) { 927 if(doc) {
921 doc->removeFiles(); 928 doc->removeFiles();
922 clear(); 929 clear();
923 setCaption( tr("Text Editor") ); 930 setCaption( tr("Text Editor") );
924 } 931 }
925 break; 932 break;
926 case 1: 933 case 1:
927 // exit 934 // exit
928 break; 935 break;
929 }; 936 };
930} 937}
931 938
932void TextEdit::changeStartConfig( bool b ) { 939void TextEdit::changeStartConfig( bool b ) {
933 940
934 Config cfg("TextEdit"); 941 Config cfg("TextEdit");
935 cfg.setGroup("View"); 942 cfg.setGroup("View");
936 if(b) { 943 if(b) {
937 qDebug("bool"); 944 qDebug("bool");
938 cfg.writeEntry("startNew","TRUE"); 945 cfg.writeEntry("startNew","TRUE");
939 } else { 946 } else {
940 cfg.writeEntry("startNew","FALSE"); 947 cfg.writeEntry("startNew","FALSE");
941 } 948 }
942 update(); 949 update();
943} 950}
944 951
945void TextEdit::editorChanged() { 952void TextEdit::editorChanged() {
946 if(editor->edited() && edited && !edited1) { 953 if(editor->edited() && edited && !edited1) {
947 setCaption( "*"+caption()); 954 setCaption( "*"+caption());
948 edited1=TRUE; 955 edited1=TRUE;
949 } 956 }
950 edited=TRUE; 957 edited=TRUE;
951} 958}
952 959
953void TextEdit::receive(const QCString&msg, const QByteArray&) { 960void TextEdit::receive(const QCString&msg, const QByteArray&) {
954 qDebug("QCop "+msg); 961 qDebug("QCop "+msg);
955 if ( msg == "setDocument(QString)" ) { 962 if ( msg == "setDocument(QString)" ) {
956 qDebug("bugger all"); 963 qDebug("bugger all");
957 } 964 }
958 965
959} 966}
960void TextEdit::doAbout() { 967void TextEdit::doAbout() {
961 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 968 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
962 "2000 Trolltech AS, and<BR>" 969 "2000 Trolltech AS, and<BR>"
963 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 970 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
964 "and is licensed under the GPL")); 971 "and is licensed under the GPL"));
965} 972}
966 973
967void TextEdit::doPrompt(bool b) { 974void TextEdit::doPrompt(bool b) {
968 promptExit=b; 975 promptExit=b;
969 Config cfg("TextEdit"); 976 Config cfg("TextEdit");
970 cfg.setGroup ( "View" ); 977 cfg.setGroup ( "View" );
971 cfg.writeEntry ( "PromptExit", b); 978 cfg.writeEntry ( "PromptExit", b);
972} 979}
973 980
974void TextEdit::doDesktop(bool b) { 981void TextEdit::doDesktop(bool b) {
975 openDesktop=b; 982 openDesktop=b;
976 Config cfg("TextEdit"); 983 Config cfg("TextEdit");
977 cfg.setGroup ( "View" ); 984 cfg.setGroup ( "View" );
978 cfg.writeEntry ( "OpenDesktop", b); 985 cfg.writeEntry ( "OpenDesktop", b);
979} 986}
980 987
981void TextEdit::doFilePerms(bool b) { 988void TextEdit::doFilePerms(bool b) {
982 filePerms=b; 989 filePerms=b;
983 Config cfg("TextEdit"); 990 Config cfg("TextEdit");
984 cfg.setGroup ( "View" ); 991 cfg.setGroup ( "View" );
985 cfg.writeEntry ( "FilePermissions", b); 992 cfg.writeEntry ( "FilePermissions", b);
986} 993}
987 994
988void TextEdit::editPasteTimeDate() { 995void TextEdit::editPasteTimeDate() {
989#ifndef QT_NO_CLIPBOARD 996#ifndef QT_NO_CLIPBOARD
990 QClipboard *cb = QApplication::clipboard(); 997 QClipboard *cb = QApplication::clipboard();
991 QDateTime dt = QDateTime::currentDateTime(); 998 QDateTime dt = QDateTime::currentDateTime();
992 cb->setText( dt.toString()); 999 cb->setText( dt.toString());
993 editor->paste(); 1000 editor->paste();
994#endif 1001#endif
995} 1002}