summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp30
-rw-r--r--core/apps/textedit/textedit.cpp15
2 files changed, 34 insertions, 11 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp
index 92c15cb..8cb7c38 100644
--- a/core/apps/textedit/fileBrowser.cpp
+++ b/core/apps/textedit/fileBrowser.cpp
@@ -1,262 +1,274 @@
1/**************************************************************************** 1/****************************************************************************
2** copyright 2001 ljp ljp@llornkcor.com 2** copyright 2001 ljp ljp@llornkcor.com
3** Created: Fri Dec 14 08:16:46 2001 3** Created: Fri Dec 14 08:16:46 2001
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13****************************************************************************/ 13****************************************************************************/
14#include "fileBrowser.h" 14#include "fileBrowser.h"
15#include <qpe/config.h> 15#include <qpe/config.h>
16#include <qpe/resource.h> 16#include <qpe/resource.h>
17#include <qpe/fileselector.h> 17#include <qpe/fileselector.h>
18#include <qpe/qpeapplication.h> 18#include <qpe/qpeapplication.h>
19 19
20#include <qwidgetstack.h> 20#include <qwidgetstack.h>
21#include <qlistview.h> 21#include <qlistview.h>
22#include <qcombo.h> 22#include <qcombo.h>
23#include <qpushbutton.h> 23#include <qpushbutton.h>
24#include <qfile.h> 24#include <qfile.h>
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <unistd.h> 27#include <unistd.h>
28 28
29static int u_id = 1; 29static int u_id = 1;
30static int get_unique_id() 30static int get_unique_id()
31{ 31{
32 return u_id++; 32 return u_id++;
33} 33}
34 34
35fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) 35fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter )
36 : QDialog( parent, name, modal, fl ) 36 : QDialog( parent, name, modal, fl )
37{ 37{
38 if ( !name ) 38 if ( !name )
39 setName( "fileBrowser" ); 39 setName( "fileBrowser" );
40 setCaption(tr( name ) ); 40 setCaption(tr( name ) );
41 filterStr=filter; 41 filterStr=filter;
42 42
43 QGridLayout *layout = new QGridLayout( this ); 43 QGridLayout *layout = new QGridLayout( this );
44 layout->setSpacing( 4 ); 44 layout->setSpacing( 4 );
45 layout->setMargin( 4 ); 45 layout->setMargin( 4 );
46 46
47 47
48 dirLabel = new QLabel(this, "DirLabel"); 48 dirLabel = new QLabel(this, "DirLabel");
49 dirLabel->setText(currentDir.canonicalPath()); 49 dirLabel->setText(currentDir.canonicalPath());
50 dirLabel->setMinimumSize( QSize( 50, 15 ) ); 50 dirLabel->setMinimumSize( QSize( 50, 15 ) );
51 dirLabel->setMaximumSize( QSize( 250, 15 ) ); 51 dirLabel->setMaximumSize( QSize( 250, 15 ) );
52 layout->addWidget( dirLabel, 0, 0 ); 52 layout->addWidget( dirLabel, 0, 0 );
53 53
54 docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); 54 docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton");
55 docButton->setMinimumSize( QSize( 25, 25 ) ); 55 docButton->setMinimumSize( QSize( 25, 25 ) );
56 docButton->setMaximumSize( QSize( 25, 25 ) ); 56 docButton->setMaximumSize( QSize( 25, 25 ) );
57 connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); 57 connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) );
58 docButton->setFlat(TRUE); 58 docButton->setFlat(TRUE);
59 layout->addWidget( docButton, 0, 1 ); 59 layout->addWidget( docButton, 0, 1 );
60 60
61 homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); 61 homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton");
62 homeButton->setMinimumSize( QSize( 25, 25 ) ); 62 homeButton->setMinimumSize( QSize( 25, 25 ) );
63 homeButton->setMaximumSize( QSize( 25, 25 ) ); 63 homeButton->setMaximumSize( QSize( 25, 25 ) );
64 connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); 64 connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
65 homeButton->setFlat(TRUE); 65 homeButton->setFlat(TRUE);
66 layout->addWidget( homeButton, 0, 2 ); 66 layout->addWidget( homeButton, 0, 2 );
67 67
68 FileStack = new QWidgetStack( this ); 68 FileStack = new QWidgetStack( this );
69 69
70 ListView = new QListView( this, "ListView" ); 70 ListView = new QListView( this, "ListView" );
71 ListView->setMinimumSize( QSize( 100, 25 ) ); 71 ListView->setMinimumSize( QSize( 100, 25 ) );
72 ListView->addColumn( tr( "Name" ) ); 72 ListView->addColumn( tr( "Name" ) );
73 ListView->setColumnWidth(0,140); 73 ListView->setColumnWidth(0,120);
74 ListView->setSorting( 2, FALSE); 74 ListView->setSorting( 2, FALSE);
75 ListView->addColumn( tr( "Size" ) ); 75 ListView->addColumn( tr( "Size" ) );
76 ListView->setColumnWidth(1,59); 76 ListView->setColumnWidth(1,-1);
77 ListView->addColumn( "Date",-1);
77// ListView->addColumn( tr( "" ) ); 78// ListView->addColumn( tr( "" ) );
78 ListView->setColumnWidthMode(0,QListView::Manual); 79 ListView->setColumnWidthMode(0,QListView::Manual);
79 ListView->setColumnAlignment(1,QListView::AlignRight); 80 ListView->setColumnAlignment(1,QListView::AlignRight);
80// ListView->setMultiSelection(true); 81 ListView->setColumnAlignment(2,QListView::AlignRight);
81// ListView->setSelectionMode(QListView::Extended);
82 ListView->setAllColumnsShowFocus( TRUE ); 82 ListView->setAllColumnsShowFocus( TRUE );
83
83 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 84 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
84 FileStack->addWidget( ListView, get_unique_id() ); 85 FileStack->addWidget( ListView, get_unique_id() );
85 86
86 fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy 87 fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy
87// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); 88// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
88// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 89// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
89 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); 90 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
90 layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); 91 layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 );
91 92
92 SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); 93 SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" );
93 SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); 94 SelectionCombo->setMinimumSize( QSize( 200, 25 ) );
94 SelectionCombo->insertItem( tr( "Documents" ) ); 95 SelectionCombo->insertItem( tr( "Documents" ) );
95 SelectionCombo->insertItem( tr( "All files" ) ); 96 SelectionCombo->insertItem( tr( "All files" ) );
96 SelectionCombo->insertItem( tr( "All files (incl. hidden)" ) ); 97 SelectionCombo->insertItem( tr( "All files (incl. hidden)" ) );
97 layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 2 ); 98 layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 2 );
98 connect( SelectionCombo, SIGNAL( activated( const QString & ) ), 99 connect( SelectionCombo, SIGNAL( activated( const QString & ) ),
99 this, SLOT( selectionChanged( const QString & ) ) ); 100 this, SLOT( selectionChanged( const QString & ) ) );
100 101
101 currentDir.setPath(QDir::currentDirPath()); 102 currentDir.setPath(QDir::currentDirPath());
102 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); 103 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All);
103 104
104 populateList(); 105 populateList();
105 move(0,15); 106 move(0,15);
106} 107}
107 108
108fileBrowser::~fileBrowser() 109fileBrowser::~fileBrowser()
109{ 110{
110} 111}
111 112
112void fileBrowser::setFileView( int selection ) 113void fileBrowser::setFileView( int selection )
113{ 114{
114 SelectionCombo->setCurrentItem( selection ); 115 SelectionCombo->setCurrentItem( selection );
115 selectionChanged( SelectionCombo->currentText() ); 116 selectionChanged( SelectionCombo->currentText() );
116} 117}
117 118
118void fileBrowser::populateList() 119void fileBrowser::populateList()
119{ 120{
120 ListView->clear(); 121 ListView->clear();
122 bool isDir=FALSE;
121//qDebug(currentDir.canonicalPath()); 123//qDebug(currentDir.canonicalPath());
122 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 124 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
123 currentDir.setMatchAllDirs(TRUE); 125 currentDir.setMatchAllDirs(TRUE);
124 126
125 currentDir.setNameFilter(filterStr); 127 currentDir.setNameFilter(filterStr);
126// currentDir.setNameFilter("*.txt;*.etx"); 128// currentDir.setNameFilter("*.txt;*.etx");
127 QString fileL, fileS; 129 QString fileL, fileS, fileDate;
128 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); 130 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
129 QFileInfoListIterator it(*list); 131 QFileInfoListIterator it(*list);
130 QFileInfo *fi; 132 QFileInfo *fi;
131 while ( (fi=it.current()) ) { 133 while ( (fi=it.current()) ) {
132 134
133 if (fi->isSymLink() ){ 135 if (fi->isSymLink() ){
134 QString symLink=fi->readLink(); 136 QString symLink=fi->readLink();
135// qDebug("Symlink detected "+symLink); 137// qDebug("Symlink detected "+symLink);
136 QFileInfo sym( symLink); 138 QFileInfo sym( symLink);
137 fileS.sprintf( "%10li", sym.size() ); 139 fileS.sprintf( "%10li", sym.size() );
138 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); 140 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
139 141 fileDate = sym.lastModified().toString();
140 } else { 142 } else {
141// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 143// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
142 fileS.sprintf( "%10li", fi->size() ); 144 fileS.sprintf( "%10li", fi->size() );
143 fileL.sprintf( "%s",fi->fileName().data() ); 145 fileL.sprintf( "%s",fi->fileName().data() );
146 fileDate= fi->lastModified().toString();
144 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 147 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
145 fileL+="/"; 148 fileL+="/";
149 isDir=TRUE;
146// qDebug( fileL); 150// qDebug( fileL);
147 } 151 }
148 } 152 }
149 item= new QListViewItem( ListView,fileL,fileS ); 153 if(fileL !="./") {
154 item= new QListViewItem( ListView,fileL,fileS , fileDate);
155 if(isDir || fileL.find("/",0,TRUE) != -1)
156 item->setPixmap( 0, Resource::loadPixmap( "folder" ));
157 else
158 item->setPixmap( 0, Resource::loadPixmap( "fileopen" ));
159 }
160 isDir=FALSE;
150 ++it; 161 ++it;
151 } 162 }
152 ListView->setSorting( 2, FALSE); 163// ListView->setSorting( 2, FALSE);
164 ListView->setSorting( 3, FALSE);
153 dirLabel->setText(currentDir.canonicalPath()); 165 dirLabel->setText(currentDir.canonicalPath());
154} 166}
155 167
156void fileBrowser::upDir() 168void fileBrowser::upDir()
157{ 169{
158// qDebug(currentDir.canonicalPath()); 170// qDebug(currentDir.canonicalPath());
159} 171}
160 172
161// you may want to switch these 2 functions. I like single clicks 173// you may want to switch these 2 functions. I like single clicks
162void fileBrowser::listClicked(QListViewItem *selectedItem) 174void fileBrowser::listClicked(QListViewItem *selectedItem)
163{ 175{
164 QString strItem=selectedItem->text(0); 176 QString strItem=selectedItem->text(0);
165 QString strSize=selectedItem->text(1); 177 QString strSize=selectedItem->text(1);
166// qDebug("strItem is "+strItem); 178// qDebug("strItem is "+strItem);
167 strSize.stripWhiteSpace(); 179 strSize.stripWhiteSpace();
168// qDebug(strSize); 180// qDebug(strSize);
169 181
170 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 182 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
171 // is symlink 183 // is symlink
172 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 184 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
173// qDebug("strItem symlink is "+strItem2); 185// qDebug("strItem symlink is "+strItem2);
174 if(QDir(strItem2).exists() ) { 186 if(QDir(strItem2).exists() ) {
175 currentDir.cd(strItem2, TRUE); 187 currentDir.cd(strItem2, TRUE);
176 populateList(); 188 populateList();
177 } 189 }
178 } else { // not a symlink 190 } else { // not a symlink
179 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 191 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
180 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 192 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
181 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 193 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
182 currentDir.cd(strItem,FALSE); 194 currentDir.cd(strItem,FALSE);
183// qDebug("Path is "+strItem); 195// qDebug("Path is "+strItem);
184 populateList(); 196 populateList();
185 } else { 197 } else {
186 currentDir.cdUp(); 198 currentDir.cdUp();
187 populateList(); 199 populateList();
188 } 200 }
189 if(QDir(strItem).exists()){ 201 if(QDir(strItem).exists()){
190 currentDir.cd(strItem, TRUE); 202 currentDir.cd(strItem, TRUE);
191 populateList(); 203 populateList();
192 } 204 }
193 } else { 205 } else {
194 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 206 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
195 if( QFile::exists(strItem ) ) { 207 if( QFile::exists(strItem ) ) {
196//currentDir.canonicalPath() 208//currentDir.canonicalPath()
197 qDebug("We found our files!!"+strItem); 209 qDebug("We found our files!!"+strItem);
198 OnOK(); 210 OnOK();
199 } 211 }
200 } //end not symlink 212 } //end not symlink
201 chdir(strItem.latin1()); 213 chdir(strItem.latin1());
202 } 214 }
203} 215}
204 216
205void fileBrowser::OnOK() 217void fileBrowser::OnOK()
206{ 218{
207 QListViewItemIterator it1( ListView); 219 QListViewItemIterator it1( ListView);
208 for ( ; it1.current(); ++it1 ) { 220 for ( ; it1.current(); ++it1 ) {
209 if ( it1.current()->isSelected() ) { 221 if ( it1.current()->isSelected() ) {
210 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); 222 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0));
211 qDebug("selected filename is "+selectedFileName); 223 qDebug("selected filename is "+selectedFileName);
212 fileList.append( selectedFileName ); 224 fileList.append( selectedFileName );
213 } 225 }
214 } 226 }
215 accept(); 227 accept();
216} 228}
217 229
218void fileBrowser::homeButtonPushed() { 230void fileBrowser::homeButtonPushed() {
219 chdir( QDir::homeDirPath().latin1() ); 231 chdir( QDir::homeDirPath().latin1() );
220 currentDir.cd( QDir::homeDirPath(), TRUE); 232 currentDir.cd( QDir::homeDirPath(), TRUE);
221 populateList(); 233 populateList();
222 update(); 234 update();
223} 235}
224 236
225void fileBrowser::docButtonPushed() { 237void fileBrowser::docButtonPushed() {
226 chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); 238 chdir( QString(QPEApplication::documentDir()+"/text").latin1() );
227 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); 239 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE);
228 populateList(); 240 populateList();
229 update(); 241 update();
230 242
231} 243}
232 244
233void fileBrowser::selectionChanged( const QString &select ) 245void fileBrowser::selectionChanged( const QString &select )
234{ 246{
235 if ( select == "Documents") 247 if ( select == "Documents")
236 { 248 {
237 FileStack->raiseWidget( fileSelector ); 249 FileStack->raiseWidget( fileSelector );
238 dirLabel->hide(); 250 dirLabel->hide();
239 docButton->hide(); 251 docButton->hide();
240 homeButton->hide(); 252 homeButton->hide();
241 } 253 }
242 else 254 else
243 { 255 {
244 if ( select == "All files" ) 256 if ( select == "All files" )
245 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); 257 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All);
246 else 258 else
247 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 259 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
248 260
249 populateList(); 261 populateList();
250 update(); 262 update();
251 dirLabel->show(); 263 dirLabel->show();
252 docButton->show(); 264 docButton->show();
253 homeButton->show(); 265 homeButton->show();
254 FileStack->raiseWidget( ListView ); 266 FileStack->raiseWidget( ListView );
255 } 267 }
256} 268}
257 269
258void fileBrowser::docOpen( const DocLnk &doc ) 270void fileBrowser::docOpen( const DocLnk &doc )
259{ 271{
260 fileList.append( doc.file().latin1() ); 272 fileList.append( doc.file().latin1() );
261 accept(); 273 accept();
262} 274}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 68ee1b4..d3f5fb4 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,915 +1,926 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// changes added by L. J. Potter Sun 02-17-2002 21:31:31 20// changes added by L. J. Potter Sun 02-17-2002 21:31:31
21 21
22#include "textedit.h" 22#include "textedit.h"
23#include "fileBrowser.h" 23#include "fileBrowser.h"
24#include "fileSaver.h" 24#include "fileSaver.h"
25#include "filePermissions.h" 25#include "filePermissions.h"
26 26
27#include "fontDialog.h" 27#include "fontDialog.h"
28 28
29#include <qpe/fontdatabase.h> 29#include <qpe/fontdatabase.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/fileselector.h> 31#include <qpe/fileselector.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#include <qpe/qpemenubar.h> 36#include <qpe/qpemenubar.h>
37#include <qpe/qpetoolbar.h> 37#include <qpe/qpetoolbar.h>
38//#include <qpe/finddialog.h> 38//#include <qpe/finddialog.h>
39 39
40#include <qstringlist.h> 40#include <qstringlist.h>
41#include <qaction.h> 41#include <qaction.h>
42#include <qcolordialog.h> 42#include <qcolordialog.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qlineedit.h> 44#include <qlineedit.h>
45#include <qmessagebox.h> 45#include <qmessagebox.h>
46#include <qobjectlist.h> 46#include <qobjectlist.h>
47#include <qpopupmenu.h> 47#include <qpopupmenu.h>
48#include <qspinbox.h> 48#include <qspinbox.h>
49#include <qtoolbutton.h> 49#include <qtoolbutton.h>
50#include <qwidgetstack.h> 50#include <qwidgetstack.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52#include <qcombo.h> 52#include <qcombo.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <sys/stat.h> 54#include <sys/stat.h>
55 55
56#include <stdlib.h> //getenv 56#include <stdlib.h> //getenv
57/* XPM */ 57/* XPM */
58static char * filesave_xpm[] = { 58static char * filesave_xpm[] = {
59"16 16 78 1", 59"16 16 78 1",
60" c None", 60" c None",
61". c #343434", 61". c #343434",
62"+ c #A0A0A0", 62"+ c #A0A0A0",
63"@ c #565656", 63"@ c #565656",
64"# c #9E9E9E", 64"# c #9E9E9E",
65"$ c #525252", 65"$ c #525252",
66"% c #929292", 66"% c #929292",
67"& c #676767", 67"& c #676767",
68"* c #848484", 68"* c #848484",
69"= c #666666", 69"= c #666666",
70"- c #D8D8D8", 70"- c #D8D8D8",
71"; c #FFFFFF", 71"; c #FFFFFF",
72"> c #DBDBDB", 72"> c #DBDBDB",
73", c #636363", 73", c #636363",
74"' c #989898", 74"' c #989898",
75") c #2D2D2D", 75") c #2D2D2D",
76"! c #909090", 76"! c #909090",
77"~ c #AEAEAE", 77"~ c #AEAEAE",
78"{ c #EAEAEA", 78"{ c #EAEAEA",
79"] c #575757", 79"] c #575757",
80"^ c #585858", 80"^ c #585858",
81"/ c #8A8A8A", 81"/ c #8A8A8A",
82"( c #828282", 82"( c #828282",
83"_ c #6F6F6F", 83"_ c #6F6F6F",
84": c #C9C9C9", 84": c #C9C9C9",
85"< c #050505", 85"< c #050505",
86"[ c #292929", 86"[ c #292929",
87"} c #777777", 87"} c #777777",
88"| c #616161", 88"| c #616161",
89"1 c #3A3A3A", 89"1 c #3A3A3A",
90"2 c #BEBEBE", 90"2 c #BEBEBE",
91"3 c #2C2C2C", 91"3 c #2C2C2C",
92"4 c #7C7C7C", 92"4 c #7C7C7C",
93"5 c #F6F6F6", 93"5 c #F6F6F6",
94"6 c #FCFCFC", 94"6 c #FCFCFC",
95"7 c #6B6B6B", 95"7 c #6B6B6B",
96"8 c #959595", 96"8 c #959595",
97"9 c #4F4F4F", 97"9 c #4F4F4F",
98"0 c #808080", 98"0 c #808080",
99"a c #767676", 99"a c #767676",
100"b c #818181", 100"b c #818181",
101"c c #B8B8B8", 101"c c #B8B8B8",
102"d c #FBFBFB", 102"d c #FBFBFB",
103"e c #F9F9F9", 103"e c #F9F9F9",
104"f c #CCCCCC", 104"f c #CCCCCC",
105"g c #030303", 105"g c #030303",
106"h c #737373", 106"h c #737373",
107"i c #7A7A7A", 107"i c #7A7A7A",
108"j c #7E7E7E", 108"j c #7E7E7E",
109"k c #6A6A6A", 109"k c #6A6A6A",
110"l c #FAFAFA", 110"l c #FAFAFA",
111"m c #505050", 111"m c #505050",
112"n c #9D9D9D", 112"n c #9D9D9D",
113"o c #333333", 113"o c #333333",
114"p c #7B7B7B", 114"p c #7B7B7B",
115"q c #787878", 115"q c #787878",
116"r c #696969", 116"r c #696969",
117"s c #494949", 117"s c #494949",
118"t c #555555", 118"t c #555555",
119"u c #949494", 119"u c #949494",
120"v c #E6E6E6", 120"v c #E6E6E6",
121"w c #424242", 121"w c #424242",
122"x c #515151", 122"x c #515151",
123"y c #535353", 123"y c #535353",
124"z c #3E3E3E", 124"z c #3E3E3E",
125"A c #D4D4D4", 125"A c #D4D4D4",
126"B c #0C0C0C", 126"B c #0C0C0C",
127"C c #353535", 127"C c #353535",
128"D c #474747", 128"D c #474747",
129"E c #ECECEC", 129"E c #ECECEC",
130"F c #919191", 130"F c #919191",
131"G c #7D7D7D", 131"G c #7D7D7D",
132"H c #000000", 132"H c #000000",
133"I c #404040", 133"I c #404040",
134"J c #858585", 134"J c #858585",
135"K c #323232", 135"K c #323232",
136"L c #D0D0D0", 136"L c #D0D0D0",
137"M c #1C1C1C", 137"M c #1C1C1C",
138" ...+ ", 138" ...+ ",
139" @#$%&..+ ", 139" @#$%&..+ ",
140" .*=-;;>,..+ ", 140" .*=-;;>,..+ ",
141" ')!~;;;;;;{]..", 141" ')!~;;;;;;{]..",
142" ^/(-;;;;;;;_:<", 142" ^/(-;;;;;;;_:<",
143" [}|;;;;;;;{12$", 143" [}|;;;;;;;{12$",
144" #34-55;;;;678$+", 144" #34-55;;;;678$+",
145" 90ab=c;dd;e1fg ", 145" 90ab=c;dd;e1fg ",
146" [ahij((kbl0mn$ ", 146" [ahij((kbl0mn$ ",
147" op^q^^7r&]s/$+ ", 147" op^q^^7r&]s/$+ ",
148"@btu;vbwxy]zAB ", 148"@btu;vbwxy]zAB ",
149"CzDEvEv;;DssF$ ", 149"CzDEvEv;;DssF$ ",
150"G.H{E{E{IxsJ$+ ", 150"G.H{E{E{IxsJ$+ ",
151" +...vEKxzLM ", 151" +...vEKxzLM ",
152" +...z]n$ ", 152" +...z]n$ ",
153" +... "}; 153" +... "};
154 154
155 155
156#if QT_VERSION < 300 156#if QT_VERSION < 300
157 157
158class QpeEditor : public QMultiLineEdit 158class QpeEditor : public QMultiLineEdit
159{ 159{
160 // Q_OBJECT 160 // Q_OBJECT
161public: 161public:
162 QpeEditor( QWidget *parent, const char * name = 0 ) 162 QpeEditor( QWidget *parent, const char * name = 0 )
163 : QMultiLineEdit( parent, name ) 163 : QMultiLineEdit( parent, name )
164 { 164 {
165 clearTableFlags(); 165 clearTableFlags();
166 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 166 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
167 } 167 }
168 168
169 void find( const QString &txt, bool caseSensitive, 169 void find( const QString &txt, bool caseSensitive,
170 bool backwards ); 170 bool backwards );
171//public slots: 171//public slots:
172 /* 172 /*
173signals: 173signals:
174 void notFound(); 174 void notFound();
175 void searchWrapped(); 175 void searchWrapped();
176 */ 176 */
177 177
178private: 178private:
179 179
180}; 180};
181 181
182 182
183void QpeEditor::find ( const QString &txt, bool caseSensitive, 183void QpeEditor::find ( const QString &txt, bool caseSensitive,
184 bool backwards ) 184 bool backwards )
185{ 185{
186 static bool wrap = FALSE; 186 static bool wrap = FALSE;
187 int line, col; 187 int line, col;
188 if ( wrap ) { 188 if ( wrap ) {
189 if ( !backwards ) 189 if ( !backwards )
190 line = col = 0; 190 line = col = 0;
191 wrap = FALSE; 191 wrap = FALSE;
192 // emit searchWrapped(); 192 // emit searchWrapped();
193 } else { 193 } else {
194 getCursorPosition( &line, &col ); 194 getCursorPosition( &line, &col );
195 } 195 }
196 //ignore backwards for now.... 196 //ignore backwards for now....
197 if ( !backwards ) { 197 if ( !backwards ) {
198 for ( ; ; ) { 198 for ( ; ; ) {
199 if ( line >= numLines() ) { 199 if ( line >= numLines() ) {
200 wrap = TRUE; 200 wrap = TRUE;
201 //emit notFound(); 201 //emit notFound();
202 break; 202 break;
203 } 203 }
204 int findCol = getString( line )->find( txt, col, caseSensitive ); 204 int findCol = getString( line )->find( txt, col, caseSensitive );
205 if ( findCol >= 0 ) { 205 if ( findCol >= 0 ) {
206 setCursorPosition( line, findCol, FALSE ); 206 setCursorPosition( line, findCol, FALSE );
207 col = findCol + txt.length(); 207 col = findCol + txt.length();
208 setCursorPosition( line, col, TRUE ); 208 setCursorPosition( line, col, TRUE );
209 209
210 //found = TRUE; 210 //found = TRUE;
211 break; 211 break;
212 } 212 }
213 line++; 213 line++;
214 col = 0; 214 col = 0;
215 } 215 }
216 216
217 } 217 }
218 218
219} 219}
220 220
221 221
222#else 222#else
223 223
224#error "Must make a QpeEditor that inherits QTextEdit" 224#error "Must make a QpeEditor that inherits QTextEdit"
225 225
226#endif 226#endif
227 227
228 228
229static const int nfontsizes = 6; 229static const int nfontsizes = 6;
230static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 230static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
231 231
232TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 232TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
233 : QMainWindow( parent, name, f ), bFromDocView( FALSE ) 233 : QMainWindow( parent, name, f ), bFromDocView( FALSE )
234{ 234{
235 doc = 0; 235 doc = 0;
236 edited=FALSE; 236 edited=FALSE;
237 edited1=FALSE; 237 edited1=FALSE;
238 setToolBarsMovable( FALSE ); 238 setToolBarsMovable( FALSE );
239 239
240 setIcon( Resource::loadPixmap( "TextEditor" ) ); 240 setIcon( Resource::loadPixmap( "TextEditor" ) );
241 241
242 QPEToolBar *bar = new QPEToolBar( this ); 242 QPEToolBar *bar = new QPEToolBar( this );
243 bar->setHorizontalStretchable( TRUE ); 243 bar->setHorizontalStretchable( TRUE );
244 menu = bar; 244 menu = bar;
245 245
246 QPEMenuBar *mb = new QPEMenuBar( bar ); 246 QPEMenuBar *mb = new QPEMenuBar( bar );
247 QPopupMenu *file = new QPopupMenu( this ); 247 QPopupMenu *file = new QPopupMenu( this );
248 QPopupMenu *edit = new QPopupMenu( this ); 248 QPopupMenu *edit = new QPopupMenu( this );
249 font = new QPopupMenu( this ); 249 font = new QPopupMenu( this );
250 250
251 bar = new QPEToolBar( this ); 251 bar = new QPEToolBar( this );
252 editBar = bar; 252 editBar = bar;
253 253
254 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 254 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
255 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 255 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
256 a->addTo( bar ); 256 a->addTo( bar );
257 a->addTo( file ); 257 a->addTo( file );
258 258
259 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 259 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
260 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 260 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
261 a->addTo( bar ); 261 a->addTo( bar );
262 a->addTo( file ); 262 a->addTo( file );
263 263
264 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 264 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
265 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 265 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
266 file->insertSeparator(); 266 file->insertSeparator();
267 a->addTo( file ); 267 a->addTo( file );
268 268
269 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 269 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
270 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 270 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
271 a->addTo( file ); 271 a->addTo( file );
272 272
273 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 273 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
274 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 274 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
275 a->addTo( editBar ); 275 a->addTo( editBar );
276 a->addTo( edit ); 276 a->addTo( edit );
277 277
278 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 278 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
279 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 279 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
280 a->addTo( editBar ); 280 a->addTo( editBar );
281 a->addTo( edit ); 281 a->addTo( edit );
282 282
283 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 283 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
284 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 284 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
285 a->addTo( editBar ); 285 a->addTo( editBar );
286 a->addTo( edit ); 286 a->addTo( edit );
287 287
288 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 288 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
289 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 289 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
290 edit->insertSeparator(); 290 edit->insertSeparator();
291 a->addTo( bar ); 291 a->addTo( bar );
292 a->addTo( edit ); 292 a->addTo( edit );
293 293
294 int defsize; 294 int defsize;
295 bool defb, defi, wrap; 295 bool defb, defi, wrap;
296 296
297 Config cfg("TextEdit"); 297 Config cfg("TextEdit");
298 cfg.setGroup("View"); 298 cfg.setGroup("View");
299 defsize = cfg.readNumEntry("FontSize",10); 299 defsize = cfg.readNumEntry("FontSize",10);
300 defb = cfg.readBoolEntry("Bold",FALSE); 300 defb = cfg.readBoolEntry("Bold",FALSE);
301 defi = cfg.readBoolEntry("Italic",FALSE); 301 defi = cfg.readBoolEntry("Italic",FALSE);
302 wrap = cfg.readBoolEntry("Wrap",TRUE); 302 wrap = cfg.readBoolEntry("Wrap",TRUE);
303 303
304 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 304 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
305 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 305 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
306 zin->addTo( font ); 306 zin->addTo( font );
307 307
308 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 308 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
309 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 309 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
310 zout->addTo( font ); 310 zout->addTo( font );
311 311
312 font->insertSeparator(); 312 font->insertSeparator();
313 313
314#if 0 314#if 0
315 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); 315 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
316 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); 316 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
317 ba->setToggleAction(TRUE); 317 ba->setToggleAction(TRUE);
318 ba->addTo( font ); 318 ba->addTo( font );
319 319
320 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); 320 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
321 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); 321 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
322 ia->setToggleAction(TRUE); 322 ia->setToggleAction(TRUE);
323 ia->addTo( font ); 323 ia->addTo( font );
324 324
325 ba->setOn(defb); 325 ba->setOn(defb);
326 ia->setOn(defi); 326 ia->setOn(defi);
327 327
328 font->insertSeparator(); 328 font->insertSeparator();
329#endif 329#endif
330 330
331 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 331 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
332 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 332 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
333 wa->setToggleAction(TRUE); 333 wa->setToggleAction(TRUE);
334 wa->addTo( font ); 334 wa->addTo( font );
335 335
336 font->insertSeparator(); 336 font->insertSeparator();
337 font->insertItem("Font", this, SLOT(changeFont()) ); 337 font->insertItem("Font", this, SLOT(changeFont()) );
338 338
339 font->insertSeparator(); 339 font->insertSeparator();
340 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 340 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
341 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 341 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
342 nStart->setToggleAction(TRUE); 342 nStart->setToggleAction(TRUE);
343 nStart->addTo( font ); 343 nStart->addTo( font );
344 344
345 mb->insertItem( tr( "File" ), file ); 345 mb->insertItem( tr( "File" ), file );
346 mb->insertItem( tr( "Edit" ), edit ); 346 mb->insertItem( tr( "Edit" ), edit );
347 mb->insertItem( tr( "View" ), font ); 347 mb->insertItem( tr( "View" ), font );
348 348
349 searchBar = new QPEToolBar(this); 349 searchBar = new QPEToolBar(this);
350 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 350 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
351 351
352 searchBar->setHorizontalStretchable( TRUE ); 352 searchBar->setHorizontalStretchable( TRUE );
353 353
354 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 354 searchEdit = new QLineEdit( searchBar, "searchEdit" );
355 searchBar->setStretchableWidget( searchEdit ); 355 searchBar->setStretchableWidget( searchEdit );
356 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 356 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
357 this, SLOT( search() ) ); 357 this, SLOT( search() ) );
358 358
359
360 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 359 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
361 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 360 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
362 a->addTo( searchBar ); 361 a->addTo( searchBar );
363 a->addTo( edit ); 362 a->addTo( edit );
364 363
365 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 364 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
366 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 365 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
367 a->addTo( searchBar ); 366 a->addTo( searchBar );
368 367
369 edit->insertSeparator(); 368 edit->insertSeparator();
370 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 369 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
371 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 370 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
372 a->addTo( edit ); 371 a->addTo( edit );
373 372
374 searchBar->hide(); 373 searchBar->hide();
375 374
376 375
377 editor = new QpeEditor( this ); 376 editor = new QpeEditor( this );
378 setCentralWidget( editor ); 377 setCentralWidget( editor );
379 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 378 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
380 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 379 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
381 380
382 resize( 200, 300 ); 381 resize( 200, 300 );
383 382
384// setFontSize(defsize,TRUE); 383// setFontSize(defsize,TRUE);
385 FontDatabase fdb; 384 FontDatabase fdb;
386 QFont defaultFont=editor->font(); 385 QFont defaultFont=editor->font();
387 QFontInfo fontInfo(defaultFont); 386 QFontInfo fontInfo(defaultFont);
388 387
389 cfg.setGroup("Font"); 388 cfg.setGroup("Font");
390 QString family = cfg.readEntry("Family", fontInfo.family()); 389 QString family = cfg.readEntry("Family", fontInfo.family());
391 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 390 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
392 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 391 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
393 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 392 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
394 393
395 defaultFont = fdb.font(family,style,i_size,charSet); 394 defaultFont = fdb.font(family,style,i_size,charSet);
396 editor->setFont( defaultFont); 395 editor->setFont( defaultFont);
397 396
398 wa->setOn(wrap); 397 wa->setOn(wrap);
399 updateCaption(); 398 updateCaption();
400 399
401 cfg.setGroup("View"); 400 cfg.setGroup("View");
402 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 401 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
403 nStart->setOn(TRUE); 402 nStart->setOn(TRUE);
404 fileNew(); 403 fileNew();
405 } else { 404 } else {
406 fileOpen(); 405 fileOpen();
407 } 406 }
408 viewSelection = cfg.readNumEntry( "FileView", 0 ); 407 viewSelection = cfg.readNumEntry( "FileView", 0 );
409} 408}
410 409
411TextEdit::~TextEdit() 410TextEdit::~TextEdit()
412{ 411{
413// save(); 412// save();
414 413
415 Config cfg("TextEdit"); 414 Config cfg("TextEdit");
416 cfg.setGroup("View"); 415 cfg.setGroup("View");
417 QFont f = editor->font(); 416 QFont f = editor->font();
418 cfg.writeEntry("FontSize",f.pointSize()); 417 cfg.writeEntry("FontSize",f.pointSize());
419 cfg.writeEntry("Bold",f.bold()); 418 cfg.writeEntry("Bold",f.bold());
420 cfg.writeEntry("Italic",f.italic()); 419 cfg.writeEntry("Italic",f.italic());
421 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 420 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
422 cfg.writeEntry( "FileView", viewSelection ); 421 cfg.writeEntry( "FileView", viewSelection );
423} 422}
424 423
425void TextEdit::zoomIn() 424void TextEdit::zoomIn()
426{ 425{
427 setFontSize(editor->font().pointSize()+1,FALSE); 426 setFontSize(editor->font().pointSize()+1,FALSE);
428} 427}
429 428
430void TextEdit::zoomOut() 429void TextEdit::zoomOut()
431{ 430{
432 setFontSize(editor->font().pointSize()-1,TRUE); 431 setFontSize(editor->font().pointSize()-1,TRUE);
433} 432}
434 433
435 434
436void TextEdit::setFontSize(int sz, bool round_down_not_up) 435void TextEdit::setFontSize(int sz, bool round_down_not_up)
437{ 436{
438 int s=10; 437 int s=10;
439 for (int i=0; i<nfontsizes; i++) { 438 for (int i=0; i<nfontsizes; i++) {
440 if ( fontsize[i] == sz ) { 439 if ( fontsize[i] == sz ) {
441 s = sz; 440 s = sz;
442 break; 441 break;
443 } else if ( round_down_not_up ) { 442 } else if ( round_down_not_up ) {
444 if ( fontsize[i] < sz ) 443 if ( fontsize[i] < sz )
445 s = fontsize[i]; 444 s = fontsize[i];
446 } else { 445 } else {
447 if ( fontsize[i] > sz ) { 446 if ( fontsize[i] > sz ) {
448 s = fontsize[i]; 447 s = fontsize[i];
449 break; 448 break;
450 } 449 }
451 } 450 }
452 } 451 }
453 452
454 QFont f = editor->font(); 453 QFont f = editor->font();
455 f.setPointSize(s); 454 f.setPointSize(s);
456 editor->setFont(f); 455 editor->setFont(f);
457 456
458 zin->setEnabled(s != fontsize[nfontsizes-1]); 457 zin->setEnabled(s != fontsize[nfontsizes-1]);
459 zout->setEnabled(s != fontsize[0]); 458 zout->setEnabled(s != fontsize[0]);
460} 459}
461 460
462void TextEdit::setBold(bool y) 461void TextEdit::setBold(bool y)
463{ 462{
464 QFont f = editor->font(); 463 QFont f = editor->font();
465 f.setBold(y); 464 f.setBold(y);
466 editor->setFont(f); 465 editor->setFont(f);
467} 466}
468 467
469void TextEdit::setItalic(bool y) 468void TextEdit::setItalic(bool y)
470{ 469{
471 QFont f = editor->font(); 470 QFont f = editor->font();
472 f.setItalic(y); 471 f.setItalic(y);
473 editor->setFont(f); 472 editor->setFont(f);
474} 473}
475 474
476void TextEdit::setWordWrap(bool y) 475void TextEdit::setWordWrap(bool y)
477{ 476{
478 bool state = editor->edited(); 477 bool state = editor->edited();
479 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 478 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
480 editor->setEdited( state ); 479 editor->setEdited( state );
481} 480}
482 481
483void TextEdit::fileNew() 482void TextEdit::fileNew()
484{ 483{
485 if( !bFromDocView ) { 484 if( !bFromDocView ) {
486 saveAs(); 485 saveAs();
487 } 486 }
488 newFile(DocLnk()); 487 newFile(DocLnk());
489} 488}
490 489
491void TextEdit::fileOpen() 490void TextEdit::fileOpen()
492{ 491{
493 browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); 492 browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*");
494 browseForFiles->setFileView( viewSelection ); 493 browseForFiles->setFileView( viewSelection );
495 browseForFiles->showMaximized(); 494 browseForFiles->showMaximized();
496 if( browseForFiles->exec() != -1 ) { 495 if( browseForFiles->exec() != -1 ) {
497 QString selFile= browseForFiles->selectedFileName; 496 QString selFile= browseForFiles->selectedFileName;
498 QStringList fileList=browseForFiles->fileList; 497 QStringList fileList=browseForFiles->fileList;
499 qDebug(selFile); 498 qDebug(selFile);
500 QStringList::ConstIterator f; 499 QStringList::ConstIterator f;
501 QString fileTemp; 500 QString fileTemp;
502 for ( f = fileList.begin(); f != fileList.end(); f++ ) { 501 for ( f = fileList.begin(); f != fileList.end(); f++ ) {
503 fileTemp = *f; 502 fileTemp = *f;
504 fileTemp.right( fileTemp.length()-5); 503 fileTemp.right( fileTemp.length()-5);
505 QString fileName = fileTemp; 504 QString fileName = fileTemp;
506 if( fileName != "Unnamed" || fileName != "Empty Text" ) { 505 if( fileName != "Unnamed" || fileName != "Empty Text" ) {
507 currentFileName = fileName; 506 currentFileName = fileName;
508 qDebug("please open "+currentFileName); 507 qDebug("please open "+currentFileName);
509 openFile(fileName ); 508 openFile(fileName );
510 } 509 }
511 } 510 }
512 viewSelection = browseForFiles->SelectionCombo->currentItem(); 511 viewSelection = browseForFiles->SelectionCombo->currentItem();
513 } 512 }
514 delete browseForFiles; 513 delete browseForFiles;
515 editor->setEdited( FALSE); 514 editor->setEdited( FALSE);
516 edited1=FALSE; 515 edited1=FALSE;
517 edited=FALSE; 516 edited=FALSE;
518 if(caption().left(1)=="*") 517 if(caption().left(1)=="*")
519 setCaption(caption().right(caption().length()-1)); 518 setCaption(caption().right(caption().length()-1));
519 Config cfg("TextEdit");
520 cfg.setGroup("View");
521 if(cfg.readEntry("SearchBar","Closed") != "Opened")
522 searchBar->hide();
520} 523}
521 524
522#if 0 525#if 0
523void TextEdit::slotFind() 526void TextEdit::slotFind()
524{ 527{
525 FindDialog frmFind( "Text Editor", this ); 528 FindDialog frmFind( "Text Editor", this );
526 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 529 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
527 editor, SLOT(slotDoFind( const QString&,bool,bool))); 530 editor, SLOT(slotDoFind( const QString&,bool,bool)));
528 531
529 //case sensitive, backwards, [category] 532 //case sensitive, backwards, [category]
530 533
531 connect( editor, SIGNAL(notFound()), 534 connect( editor, SIGNAL(notFound()),
532 &frmFind, SLOT(slotNotFound()) ); 535 &frmFind, SLOT(slotNotFound()) );
533 connect( editor, SIGNAL(searchWrapped()), 536 connect( editor, SIGNAL(searchWrapped()),
534 &frmFind, SLOT(slotWrapAround()) ); 537 &frmFind, SLOT(slotWrapAround()) );
535 538
536 frmFind.exec(); 539 frmFind.exec();
537 540
538 541
539} 542}
540#endif 543#endif
541 544
542void TextEdit::fileRevert() 545void TextEdit::fileRevert()
543{ 546{
544 clear(); 547 clear();
545 fileOpen(); 548 fileOpen();
546} 549}
547 550
548void TextEdit::editCut() 551void TextEdit::editCut()
549{ 552{
550#ifndef QT_NO_CLIPBOARD 553#ifndef QT_NO_CLIPBOARD
551 editor->cut(); 554 editor->cut();
552#endif 555#endif
553} 556}
554 557
555void TextEdit::editCopy() 558void TextEdit::editCopy()
556{ 559{
557#ifndef QT_NO_CLIPBOARD 560#ifndef QT_NO_CLIPBOARD
558 editor->copy(); 561 editor->copy();
559#endif 562#endif
560} 563}
561 564
562void TextEdit::editPaste() 565void TextEdit::editPaste()
563{ 566{
564#ifndef QT_NO_CLIPBOARD 567#ifndef QT_NO_CLIPBOARD
565 editor->paste(); 568 editor->paste();
566#endif 569#endif
567} 570}
568 571
569void TextEdit::editFind() 572void TextEdit::editFind()
570{ 573{
571 searchBar->show(); 574 searchBar->show();
572 searchVisible = TRUE; 575 searchVisible = TRUE;
573 searchEdit->setFocus(); 576 searchEdit->setFocus();
577 Config cfg("TextEdit");
578 cfg.setGroup("View");
579 cfg.writeEntry("SearchBar","Opened");
580
574} 581}
575 582
576void TextEdit::findNext() 583void TextEdit::findNext()
577{ 584{
578 editor->find( searchEdit->text(), FALSE, FALSE ); 585 editor->find( searchEdit->text(), FALSE, FALSE );
579 586
580} 587}
581 588
582void TextEdit::findClose() 589void TextEdit::findClose()
583{ 590{
584 searchVisible = FALSE; 591 searchVisible = FALSE;
585 searchBar->hide(); 592 searchBar->hide();
593 Config cfg("TextEdit");
594 cfg.setGroup("View");
595 cfg.writeEntry("SearchBar","Closed");
596 cfg.write();
586} 597}
587 598
588void TextEdit::search() 599void TextEdit::search()
589{ 600{
590 editor->find( searchEdit->text(), FALSE, FALSE ); 601 editor->find( searchEdit->text(), FALSE, FALSE );
591} 602}
592 603
593void TextEdit::newFile( const DocLnk &f ) 604void TextEdit::newFile( const DocLnk &f )
594{ 605{
595 DocLnk nf = f; 606 DocLnk nf = f;
596 nf.setType("text/plain"); 607 nf.setType("text/plain");
597 clear(); 608 clear();
598 setWState (WState_Reserved1 ); 609 setWState (WState_Reserved1 );
599 editor->setFocus(); 610 editor->setFocus();
600 doc = new DocLnk(nf); 611 doc = new DocLnk(nf);
601 qDebug("newFile "+currentFileName); 612 qDebug("newFile "+currentFileName);
602 updateCaption(currentFileName); 613 updateCaption(currentFileName);
603} 614}
604 615
605void TextEdit::openFile( const QString &f ) 616void TextEdit::openFile( const QString &f )
606{ 617{
607 618
608 bFromDocView = TRUE; 619 bFromDocView = TRUE;
609 DocLnk nf; 620 DocLnk nf;
610 nf.setType("text/plain"); 621 nf.setType("text/plain");
611 nf.setFile(f); 622 nf.setFile(f);
612 currentFileName=f; 623 currentFileName=f;
613 QFileInfo fi( currentFileName); 624 QFileInfo fi( currentFileName);
614 nf.setName(fi.baseName()); 625 nf.setName(fi.baseName());
615 qDebug("openFile string"+currentFileName); 626 qDebug("openFile string"+currentFileName);
616 627
617 openFile(nf); 628 openFile(nf);
618 showEditTools(); 629 showEditTools();
619 // Show filename in caption 630 // Show filename in caption
620 QString name = f; 631 QString name = f;
621 int sep = name.findRev( '/' ); 632 int sep = name.findRev( '/' );
622 if ( sep > 0 ) 633 if ( sep > 0 )
623 name = name.mid( sep+1 ); 634 name = name.mid( sep+1 );
624 updateCaption( name ); 635 updateCaption( name );
625} 636}
626 637
627void TextEdit::openFile( const DocLnk &f ) 638void TextEdit::openFile( const DocLnk &f )
628{ 639{
629// clear(); 640// clear();
630 bFromDocView = TRUE; 641 bFromDocView = TRUE;
631 FileManager fm; 642 FileManager fm;
632 QString txt; 643 QString txt;
633 currentFileName=f.name(); 644 currentFileName=f.name();
634 qDebug("openFile doclnk " + currentFileName); 645 qDebug("openFile doclnk " + currentFileName);
635 if ( !fm.loadFile( f, txt ) ) { 646 if ( !fm.loadFile( f, txt ) ) {
636 // ####### could be a new file 647 // ####### could be a new file
637 qDebug( "Cannot open file" ); 648 qDebug( "Cannot open file" );
638 649
639 //return; 650 //return;
640 } 651 }
641 652
642 fileNew(); 653 fileNew();
643 if ( doc ) 654 if ( doc )
644 delete doc; 655 delete doc;
645 doc = new DocLnk(f); 656 doc = new DocLnk(f);
646 editor->setText(txt); 657 editor->setText(txt);
647 editor->setEdited( FALSE); 658 editor->setEdited( FALSE);
648 edited1=FALSE; 659 edited1=FALSE;
649 edited=FALSE; 660 edited=FALSE;
650 661
651 qDebug("openFile doclnk "+currentFileName); 662 qDebug("openFile doclnk "+currentFileName);
652 doc->setName(currentFileName); 663 doc->setName(currentFileName);
653 updateCaption(); 664 updateCaption();
654} 665}
655 666
656void TextEdit::showEditTools() 667void TextEdit::showEditTools()
657{ 668{
658// if ( !doc ) 669// if ( !doc )
659// close(); 670// close();
660// clear(); 671// clear();
661 menu->show(); 672 menu->show();
662 editBar->show(); 673 editBar->show();
663 if ( searchVisible ) 674 if ( searchVisible )
664 searchBar->show(); 675 searchBar->show();
665// updateCaption(); 676// updateCaption();
666 setWState (WState_Reserved1 ); 677 setWState (WState_Reserved1 );
667} 678}
668 679
669/*! 680/*!
670 unprompted save */ 681 unprompted save */
671bool TextEdit::save() 682bool TextEdit::save()
672{ 683{
673 QString file = doc->file(); 684 QString file = doc->file();
674 qDebug(file); 685 qDebug(file);
675 QString name= doc->name(); 686 QString name= doc->name();
676 qDebug(name); 687 qDebug(name);
677 QString rt = editor->text(); 688 QString rt = editor->text();
678 if( !rt.isEmpty() ) { 689 if( !rt.isEmpty() ) {
679 if(name.isEmpty()) { 690 if(name.isEmpty()) {
680 saveAs(); 691 saveAs();
681 } else { 692 } else {
682 currentFileName= name ; 693 currentFileName= name ;
683 qDebug("saveFile "+currentFileName); 694 qDebug("saveFile "+currentFileName);
684 695
685 struct stat buf; 696 struct stat buf;
686 mode_t mode; 697 mode_t mode;
687 stat(file.latin1(), &buf); 698 stat(file.latin1(), &buf);
688 mode = buf.st_mode; 699 mode = buf.st_mode;
689 700
690 doc->setName( name); 701 doc->setName( name);
691 FileManager fm; 702 FileManager fm;
692 if ( !fm.saveFile( *doc, rt ) ) { 703 if ( !fm.saveFile( *doc, rt ) ) {
693 return false; 704 return false;
694 } 705 }
695 editor->setEdited( FALSE); 706 editor->setEdited( FALSE);
696 edited1=FALSE; 707 edited1=FALSE;
697 edited=FALSE; 708 edited=FALSE;
698 if(caption().left(1)=="*") 709 if(caption().left(1)=="*")
699 setCaption(caption().right(caption().length()-1)); 710 setCaption(caption().right(caption().length()-1));
700 711
701 712
702 chmod( file.latin1(), mode); 713 chmod( file.latin1(), mode);
703 } 714 }
704 return true; 715 return true;
705 } 716 }
706 return false; 717 return false;
707} 718}
708 719
709/*! 720/*!
710 prompted save */ 721 prompted save */
711bool TextEdit::saveAs() 722bool TextEdit::saveAs()
712{ 723{
713// qDebug("saveAsFile "+currentFileName); 724// qDebug("saveAsFile "+currentFileName);
714 725
715 // case of nothing to save... /// there's always something to save 726 // case of nothing to save... /// there's always something to save
716// if ( !doc )//|| !bFromDocView) 727// if ( !doc )//|| !bFromDocView)
717// { 728// {
718// qDebug("no doc"); 729// qDebug("no doc");
719// return true; 730// return true;
720// } 731// }
721 if ( !editor->edited() ) { 732 if ( !editor->edited() ) {
722 delete doc; 733 delete doc;
723 doc = 0; 734 doc = 0;
724 return true; 735 return true;
725 } 736 }
726 737
727 QString rt = editor->text(); 738 QString rt = editor->text();
728 qDebug(currentFileName); 739 qDebug(currentFileName);
729 740
730 if( currentFileName.isEmpty() || currentFileName == "Unnamed") { 741 if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
731 qDebug("do silly TT filename thing"); 742 qDebug("do silly TT filename thing");
732 if ( doc->name().isEmpty() ) { 743 if ( doc->name().isEmpty() ) {
733 QString pt = rt.simplifyWhiteSpace(); 744 QString pt = rt.simplifyWhiteSpace();
734 int i = pt.find( ' ' ); 745 int i = pt.find( ' ' );
735 QString docname = pt; 746 QString docname = pt;
736 if ( i > 0 ) 747 if ( i > 0 )
737 docname = pt.left( i ); 748 docname = pt.left( i );
738 // remove "." at the beginning 749 // remove "." at the beginning
739 while( docname.startsWith( "." ) ) 750 while( docname.startsWith( "." ) )
740 docname = docname.mid( 1 ); 751 docname = docname.mid( 1 );
741 docname.replace( QRegExp("/"), "_" ); 752 docname.replace( QRegExp("/"), "_" );
742 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 753 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
743 if ( docname.length() > 40 ) 754 if ( docname.length() > 40 )
744 docname = docname.left(40); 755 docname = docname.left(40);
745 if ( docname.isEmpty() ) 756 if ( docname.isEmpty() )
746 docname = "Unnamed"; 757 docname = "Unnamed";
747 doc->setName(docname); 758 doc->setName(docname);
748 currentFileName=docname; 759 currentFileName=docname;
749 } 760 }
750 } 761 }
751 762
752 763
753 fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); 764 fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName);
754 qDebug("wanna save filename "+currentFileName); 765 qDebug("wanna save filename "+currentFileName);
755 fileSaveDlg->exec(); 766 fileSaveDlg->exec();
756 if( fileSaveDlg->result() == 1 ) { 767 if( fileSaveDlg->result() == 1 ) {
757 QString fileNm=fileSaveDlg->selectedFileName; 768 QString fileNm=fileSaveDlg->selectedFileName;
758 qDebug("saving filename "+fileNm); 769 qDebug("saving filename "+fileNm);
759 QFileInfo fi(fileNm); 770 QFileInfo fi(fileNm);
760 currentFileName=fi.fileName(); 771 currentFileName=fi.fileName();
761 if(doc) { 772 if(doc) {
762// QString file = doc->file(); 773// QString file = doc->file();
763// doc->removeFiles(); 774// doc->removeFiles();
764 delete doc; 775 delete doc;
765 DocLnk nf; 776 DocLnk nf;
766 nf.setType("text/plain"); 777 nf.setType("text/plain");
767 nf.setFile( fileNm); 778 nf.setFile( fileNm);
768 doc = new DocLnk(nf); 779 doc = new DocLnk(nf);
769// editor->setText(rt); 780// editor->setText(rt);
770// qDebug("openFile doclnk "+currentFileName); 781// qDebug("openFile doclnk "+currentFileName);
771 doc->setName( currentFileName); 782 doc->setName( currentFileName);
772 updateCaption( currentFileName); 783 updateCaption( currentFileName);
773 784
774 FileManager fm; 785 FileManager fm;
775 if ( !fm.saveFile( *doc, rt ) ) { 786 if ( !fm.saveFile( *doc, rt ) ) {
776 return false; 787 return false;
777 } 788 }
778 if( fileSaveDlg->filePermCheck->isChecked() ) { 789 if( fileSaveDlg->filePermCheck->isChecked() ) {
779 filePermissions *filePerm; 790 filePermissions *filePerm;
780 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); 791 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm);
781 filePerm->exec(); 792 filePerm->exec();
782 793
783 if( filePerm) 794 if( filePerm)
784 delete filePerm; 795 delete filePerm;
785 } 796 }
786 } 797 }
787 } 798 }
788 editor->setEdited(TRUE); 799 editor->setEdited(TRUE);
789 edited1=FALSE; 800 edited1=FALSE;
790 edited=TRUE; 801 edited=TRUE;
791 if(caption().left(1)=="*") 802 if(caption().left(1)=="*")
792 setCaption(caption().right(caption().length()-1)); 803 setCaption(caption().right(caption().length()-1));
793 804
794 if(fileSaveDlg) 805 if(fileSaveDlg)
795 delete fileSaveDlg; 806 delete fileSaveDlg;
796 return true; 807 return true;
797} 808}
798 809
799void TextEdit::clear() 810void TextEdit::clear()
800{ 811{
801 delete doc; 812 delete doc;
802 doc = 0; 813 doc = 0;
803 editor->clear(); 814 editor->clear();
804} 815}
805 816
806void TextEdit::updateCaption( const QString &name ) 817void TextEdit::updateCaption( const QString &name )
807{ 818{
808 if ( !doc ) 819 if ( !doc )
809 setCaption( tr("Text Editor") ); 820 setCaption( tr("Text Editor") );
810 else { 821 else {
811 QString s = name; 822 QString s = name;
812 if ( s.isNull() ) 823 if ( s.isNull() )
813 s = doc->name(); 824 s = doc->name();
814 if ( s.isEmpty() ) { 825 if ( s.isEmpty() ) {
815 s = tr( "Unnamed" ); 826 s = tr( "Unnamed" );
816 currentFileName=s; 827 currentFileName=s;
817 } 828 }
818 829
819 setCaption( s + " - " + tr("Text Editor") ); 830 setCaption( s + " - " + tr("Text Editor") );
820 } 831 }
821} 832}
822 833
823void TextEdit::setDocument(const QString& fileref) 834void TextEdit::setDocument(const QString& fileref)
824{ 835{
825 bFromDocView = TRUE; 836 bFromDocView = TRUE;
826 qDebug("setDocument "+fileref); 837 qDebug("setDocument "+fileref);
827 bFromDocView = TRUE; 838 bFromDocView = TRUE;
828 if(fileref.find(".desktop",0,TRUE) == -1) { 839 if(fileref.find(".desktop",0,TRUE) == -1) {
829 openFile(fileref); 840 openFile(fileref);
830 } else { 841 } else {
831 openFile(DocLnk(fileref)); 842 openFile(DocLnk(fileref));
832 } 843 }
833 editor->setEdited(TRUE); 844 editor->setEdited(TRUE);
834 edited1=FALSE; 845 edited1=FALSE;
835 edited=TRUE; 846 edited=TRUE;
836} 847}
837 848
838void TextEdit::closeEvent( QCloseEvent *e ) 849void TextEdit::closeEvent( QCloseEvent *e )
839{ 850{
840 bFromDocView = FALSE; 851 bFromDocView = FALSE;
841 e->accept(); 852 e->accept();
842} 853}
843 854
844void TextEdit::accept() 855void TextEdit::accept()
845 { 856 {
846 QString file = doc->file(); 857 QString file = doc->file();
847 if (file.find("_.txt",0,TRUE) ==-1) 858 if (file.find("_.txt",0,TRUE) ==-1)
848 save(); 859 save();
849 else { 860 else {
850 QFile(file).remove(); 861 QFile(file).remove();
851 } 862 }
852 exit(0); 863 exit(0);
853 864
854} 865}
855 866
856void TextEdit::changeFont() { 867void TextEdit::changeFont() {
857 FontDatabase fdb; 868 FontDatabase fdb;
858 QFont defaultFont=editor->font(); 869 QFont defaultFont=editor->font();
859 QFontInfo fontInfo(defaultFont); 870 QFontInfo fontInfo(defaultFont);
860 Config cfg("TextEdit"); 871 Config cfg("TextEdit");
861 cfg.setGroup("Font"); 872 cfg.setGroup("Font");
862 QString family = cfg.readEntry("Family", fontInfo.family()); 873 QString family = cfg.readEntry("Family", fontInfo.family());
863 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 874 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
864 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 875 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
865 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 876 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
866 877
867 defaultFont = fdb.font(family,style,i_size,charSet); 878 defaultFont = fdb.font(family,style,i_size,charSet);
868 879
869 FontDialog *fontDlg; 880 FontDialog *fontDlg;
870 fontDlg=new FontDialog(this,"FontDialog",TRUE); 881 fontDlg=new FontDialog(this,"FontDialog",TRUE);
871 882
872 fontDlg->exec(); 883 fontDlg->exec();
873 884
874 QFont myFont=fontDlg->selectedFont; 885 QFont myFont=fontDlg->selectedFont;
875 editor->setFont( myFont); 886 editor->setFont( myFont);
876 delete fontDlg; 887 delete fontDlg;
877 888
878} 889}
879 890
880void TextEdit::editDelete() 891void TextEdit::editDelete()
881{ 892{
882 switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { 893 switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) {
883 case 0: 894 case 0:
884 if(doc) { 895 if(doc) {
885 doc->removeFiles(); 896 doc->removeFiles();
886 clear(); 897 clear();
887 setCaption( tr("Text Editor") ); 898 setCaption( tr("Text Editor") );
888 } 899 }
889 break; 900 break;
890 case 1: 901 case 1:
891 // exit 902 // exit
892 break; 903 break;
893 }; 904 };
894} 905}
895 906
896void TextEdit::changeStartConfig( bool b ) { 907void TextEdit::changeStartConfig( bool b ) {
897 908
898 Config cfg("TextEdit"); 909 Config cfg("TextEdit");
899 cfg.setGroup("View"); 910 cfg.setGroup("View");
900 if(b) { 911 if(b) {
901 qDebug("bool"); 912 qDebug("bool");
902 cfg.writeEntry("startNew","TRUE"); 913 cfg.writeEntry("startNew","TRUE");
903 } else { 914 } else {
904 cfg.writeEntry("startNew","FALSE"); 915 cfg.writeEntry("startNew","FALSE");
905 } 916 }
906 update(); 917 update();
907} 918}
908 919
909void TextEdit::editorChanged() { 920void TextEdit::editorChanged() {
910 if(editor->edited() && edited && !edited1) { 921 if(editor->edited() && edited && !edited1) {
911 setCaption( "*"+caption()); 922 setCaption( "*"+caption());
912 edited1=TRUE; 923 edited1=TRUE;
913 } 924 }
914 edited=TRUE; 925 edited=TRUE;
915} 926}