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