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