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