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