summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-01 23:30:12 (UTC)
committer llornkcor <llornkcor>2002-06-01 23:30:12 (UTC)
commit7b145de0bf5dfe015e3c53fb4058315857e725a3 (patch) (unidiff)
tree6000c8844b749537bdf69c0b4cf124dda4eddb6b
parent4a8e6f982a1033b7f2b0406a238503f9acb9a7c5 (diff)
downloadopie-7b145de0bf5dfe015e3c53fb4058315857e725a3.zip
opie-7b145de0bf5dfe015e3c53fb4058315857e725a3.tar.gz
opie-7b145de0bf5dfe015e3c53fb4058315857e725a3.tar.bz2
buf gix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileSaver.cpp3
-rw-r--r--core/apps/textedit/textedit.cpp16
2 files changed, 13 insertions, 6 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp
index b1ddc0b..209a258 100644
--- a/core/apps/textedit/fileSaver.cpp
+++ b/core/apps/textedit/fileSaver.cpp
@@ -87,184 +87,185 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl
87 87
88// tmpFileName=fi.FilePath(); 88// tmpFileName=fi.FilePath();
89// qDebug( tmpFileName); 89// qDebug( tmpFileName);
90 currentDir.setPath( QDir::currentDirPath() ); 90 currentDir.setPath( QDir::currentDirPath() );
91 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); 91 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All);
92 populateList(); 92 populateList();
93 move(0,15); 93 move(0,15);
94 fileEdit->setFocus(); 94 fileEdit->setFocus();
95} 95}
96 96
97fileSaver::~fileSaver() 97fileSaver::~fileSaver()
98{ 98{
99} 99}
100 100
101void fileSaver::populateList() 101void fileSaver::populateList()
102{ 102{
103 ListView->clear(); 103 ListView->clear();
104 bool isDir=FALSE; 104 bool isDir=FALSE;
105 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 105 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
106 currentDir.setMatchAllDirs(TRUE); 106 currentDir.setMatchAllDirs(TRUE);
107 107
108 currentDir.setNameFilter("*"); 108 currentDir.setNameFilter("*");
109 QString fileL, fileS, fileDate; 109 QString fileL, fileS, fileDate;
110 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); 110 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
111 QFileInfoListIterator it(*list); 111 QFileInfoListIterator it(*list);
112 QFileInfo *fi; 112 QFileInfo *fi;
113 while ( (fi=it.current()) ) { 113 while ( (fi=it.current()) ) {
114 114
115 if (fi->isSymLink() ){ 115 if (fi->isSymLink() ){
116 QString symLink=fi->readLink(); 116 QString symLink=fi->readLink();
117// qDebug("Symlink detected "+symLink); 117// qDebug("Symlink detected "+symLink);
118 QFileInfo sym( symLink); 118 QFileInfo sym( symLink);
119 fileS.sprintf( "%10li", sym.size() ); 119 fileS.sprintf( "%10li", sym.size() );
120 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); 120 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
121 121
122 } else { 122 } else {
123// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 123// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
124 fileS.sprintf( "%10li", fi->size() ); 124 fileS.sprintf( "%10li", fi->size() );
125 fileL.sprintf( "%s",fi->fileName().data() ); 125 fileL.sprintf( "%s",fi->fileName().data() );
126 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 126 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
127 fileL+="/"; 127 fileL+="/";
128 isDir=TRUE; 128 isDir=TRUE;
129// qDebug(currentDir.canonicalPath()+fileL); 129// qDebug(currentDir.canonicalPath()+fileL);
130 } 130 }
131 } 131 }
132 if(fileL !="./") { 132 if(fileL !="./") {
133 item= new QListViewItem( ListView,fileL,fileS , fileDate); 133 item= new QListViewItem( ListView,fileL,fileS , fileDate);
134 QPixmap pm; 134 QPixmap pm;
135 135
136 if(isDir || fileL.find("/",0,TRUE) != -1) { 136 if(isDir || fileL.find("/",0,TRUE) != -1) {
137 if( !QDir( fi->filePath() ).isReadable()) 137 if( !QDir( fi->filePath() ).isReadable())
138 pm = Resource::loadPixmap( "lockedfolder" ); 138 pm = Resource::loadPixmap( "lockedfolder" );
139 else 139 else
140 pm= Resource::loadPixmap( "folder" ); 140 pm= Resource::loadPixmap( "folder" );
141 item->setPixmap( 0,pm ); 141 item->setPixmap( 0,pm );
142 } else { 142 } else {
143 if( !fi->isReadable() ) 143 if( !fi->isReadable() )
144 pm = Resource::loadPixmap( "locked" ); 144 pm = Resource::loadPixmap( "locked" );
145 else { 145 else {
146 MimeType mt(fi->filePath()); 146 MimeType mt(fi->filePath());
147 pm=mt.pixmap(); 147 pm=mt.pixmap();
148 if(pm.isNull()) 148 if(pm.isNull())
149 pm = Resource::loadPixmap( "UnknownDocument-14" ); 149 pm = Resource::loadPixmap( "UnknownDocument-14" );
150 item->setPixmap( 0,pm); 150 item->setPixmap( 0,pm);
151 } 151 }
152 } 152 }
153 if( fileL.find("->",0,TRUE) != -1) { 153 if( fileL.find("->",0,TRUE) != -1) {
154 // overlay link image 154 // overlay link image
155 pm= Resource::loadPixmap( "folder" ); 155 pm= Resource::loadPixmap( "folder" );
156 QPixmap lnk = Resource::loadPixmap( "symlink" ); 156 QPixmap lnk = Resource::loadPixmap( "symlink" );
157 QPainter painter( &pm ); 157 QPainter painter( &pm );
158 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); 158 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
159 pm.setMask( pm.createHeuristicMask( FALSE ) ); 159 pm.setMask( pm.createHeuristicMask( FALSE ) );
160 item->setPixmap( 0, pm); 160 item->setPixmap( 0, pm);
161 } 161 }
162 } 162 }
163 isDir=FALSE; 163 isDir=FALSE;
164 ++it; 164 ++it;
165 } 165 }
166 ListView->setSorting( 2, FALSE); 166 ListView->setSorting( 2, FALSE);
167 dirLabel->setText(currentDir.canonicalPath()); 167 dirLabel->setText(currentDir.canonicalPath());
168 168
169 169
170} 170}
171 171
172void fileSaver::upDir() 172void fileSaver::upDir()
173{ 173{
174// qDebug(currentDir.canonicalPath()); 174// qDebug(currentDir.canonicalPath());
175} 175}
176 176
177void fileSaver::listDoubleClicked(QListViewItem *selectedItem) 177void fileSaver::listDoubleClicked(QListViewItem *selectedItem)
178{ 178{
179} 179}
180 180
181void fileSaver::listClicked(QListViewItem *selectedItem) 181void fileSaver::listClicked(QListViewItem *selectedItem)
182{ 182{
183 if(selectedItem != NULL) {
183 QString strItem=selectedItem->text(0); 184 QString strItem=selectedItem->text(0);
184 QString strSize=selectedItem->text(1); 185 QString strSize=selectedItem->text(1);
185// qDebug("strItem is "+strItem); 186// qDebug("strItem is "+strItem);
186 strSize.stripWhiteSpace(); 187 strSize.stripWhiteSpace();
187// qDebug(strSize); 188// qDebug(strSize);
188 189
189 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 190 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
190 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 191 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
191// qDebug("strItem symlink is "+strItem2); 192// qDebug("strItem symlink is "+strItem2);
192 if(QDir(strItem2).exists() ) { 193 if(QDir(strItem2).exists() ) {
193 currentDir.cd(strItem2, TRUE); 194 currentDir.cd(strItem2, TRUE);
194 populateList(); 195 populateList();
195 } 196 }
196 } else { // not a symlink 197 } else { // not a symlink
197 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 198 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
198 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 199 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
199 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 200 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
200 currentDir.cd(strItem,FALSE); 201 currentDir.cd(strItem,FALSE);
201// qDebug("Path is "+strItem); 202// qDebug("Path is "+strItem);
202 populateList(); 203 populateList();
203 } else { 204 } else {
204 currentDir.cdUp(); 205 currentDir.cdUp();
205 populateList(); 206 populateList();
206 } 207 }
207 if(QDir(strItem).exists()){ 208 if(QDir(strItem).exists()){
208 currentDir.cd(strItem, TRUE); 209 currentDir.cd(strItem, TRUE);
209 populateList(); 210 populateList();
210 } 211 }
211 } // else 212 } // else
212// if( QFile::exists(strItem ) ) { 213// if( QFile::exists(strItem ) ) {
213// qDebug("We found our files!!"); 214// qDebug("We found our files!!");
214 215
215// OnOK(); 216// OnOK();
216 } //end not symlink 217 } //end not symlink
217 chdir(strItem.latin1()); 218 chdir(strItem.latin1());
218 219
219 220 }
220} 221}
221 222
222 223
223void fileSaver::closeEvent( QCloseEvent *e ) 224void fileSaver::closeEvent( QCloseEvent *e )
224{ 225{
225 if(e->isAccepted()) { 226 if(e->isAccepted()) {
226 e->accept(); 227 e->accept();
227 } else { 228 } else {
228 qDebug("not accepted"); 229 qDebug("not accepted");
229 done(-1); 230 done(-1);
230 } 231 }
231} 232}
232 233
233void fileSaver::accept() { 234void fileSaver::accept() {
234 selectedFileName = fileEdit->text(); 235 selectedFileName = fileEdit->text();
235 QString path = currentDir.canonicalPath()+"/" + selectedFileName; 236 QString path = currentDir.canonicalPath()+"/" + selectedFileName;
236 if( path.find("//",0,TRUE) ==-1 ) { 237 if( path.find("//",0,TRUE) ==-1 ) {
237 selectedFileName = path; 238 selectedFileName = path;
238 } else { 239 } else {
239 selectedFileName = currentDir.canonicalPath()+selectedFileName; 240 selectedFileName = currentDir.canonicalPath()+selectedFileName;
240 } 241 }
241 qDebug("going to save "+selectedFileName); 242 qDebug("going to save "+selectedFileName);
242 done(1); 243 done(1);
243} 244}
244 245
245void fileSaver::homeButtonPushed() { 246void fileSaver::homeButtonPushed() {
246 chdir( QDir::homeDirPath().latin1() ); 247 chdir( QDir::homeDirPath().latin1() );
247 currentDir.cd( QDir::homeDirPath(), TRUE); 248 currentDir.cd( QDir::homeDirPath(), TRUE);
248 populateList(); 249 populateList();
249 update(); 250 update();
250} 251}
251void fileSaver::docButtonPushed() { 252void fileSaver::docButtonPushed() {
252 chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); 253 chdir( QString(QPEApplication::documentDir()+"/text").latin1() );
253 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); 254 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE);
254 populateList(); 255 populateList();
255 update(); 256 update();
256 257
257} 258}
258 259
259void fileSaver::hideButtonPushed(bool b) { 260void fileSaver::hideButtonPushed(bool b) {
260 if (b) 261 if (b)
261 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 262 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
262 else 263 else
263 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 264 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
264 265
265// chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); 266// chdir( QString(QPEApplication::documentDir()+"/text").latin1() );
266// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); 267// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE);
267 populateList(); 268 populateList();
268 update(); 269 update();
269 270
270} 271}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index f89ed6d..f99f259 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -417,193 +417,193 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
417 417
418 viewSelection = cfg.readNumEntry( "FileView", 0 ); 418 viewSelection = cfg.readNumEntry( "FileView", 0 );
419} 419}
420 420
421void TextEdit::cleanUp() 421void TextEdit::cleanUp()
422{ 422{
423// save(); 423// save();
424 Config cfg("TextEdit"); 424 Config cfg("TextEdit");
425 cfg.setGroup("View"); 425 cfg.setGroup("View");
426 QFont f = editor->font(); 426 QFont f = editor->font();
427 cfg.writeEntry("FontSize",f.pointSize()); 427 cfg.writeEntry("FontSize",f.pointSize());
428 cfg.writeEntry("Bold",f.bold()); 428 cfg.writeEntry("Bold",f.bold());
429 cfg.writeEntry("Italic",f.italic()); 429 cfg.writeEntry("Italic",f.italic());
430 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 430 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
431 cfg.writeEntry( "FileView", viewSelection ); 431 cfg.writeEntry( "FileView", viewSelection );
432 432
433} 433}
434 434
435TextEdit::~TextEdit() 435TextEdit::~TextEdit()
436{ 436{
437} 437}
438 438
439void TextEdit::zoomIn() 439void TextEdit::zoomIn()
440{ 440{
441 setFontSize(editor->font().pointSize()+1,FALSE); 441 setFontSize(editor->font().pointSize()+1,FALSE);
442} 442}
443 443
444void TextEdit::zoomOut() 444void TextEdit::zoomOut()
445{ 445{
446 setFontSize(editor->font().pointSize()-1,TRUE); 446 setFontSize(editor->font().pointSize()-1,TRUE);
447} 447}
448 448
449 449
450void TextEdit::setFontSize(int sz, bool round_down_not_up) 450void TextEdit::setFontSize(int sz, bool round_down_not_up)
451{ 451{
452 int s=10; 452 int s=10;
453 for (int i=0; i<nfontsizes; i++) { 453 for (int i=0; i<nfontsizes; i++) {
454 if ( fontsize[i] == sz ) { 454 if ( fontsize[i] == sz ) {
455 s = sz; 455 s = sz;
456 break; 456 break;
457 } else if ( round_down_not_up ) { 457 } else if ( round_down_not_up ) {
458 if ( fontsize[i] < sz ) 458 if ( fontsize[i] < sz )
459 s = fontsize[i]; 459 s = fontsize[i];
460 } else { 460 } else {
461 if ( fontsize[i] > sz ) { 461 if ( fontsize[i] > sz ) {
462 s = fontsize[i]; 462 s = fontsize[i];
463 break; 463 break;
464 } 464 }
465 } 465 }
466 } 466 }
467 467
468 QFont f = editor->font(); 468 QFont f = editor->font();
469 f.setPointSize(s); 469 f.setPointSize(s);
470 editor->setFont(f); 470 editor->setFont(f);
471 471
472 zin->setEnabled(s != fontsize[nfontsizes-1]); 472 zin->setEnabled(s != fontsize[nfontsizes-1]);
473 zout->setEnabled(s != fontsize[0]); 473 zout->setEnabled(s != fontsize[0]);
474} 474}
475 475
476void TextEdit::setBold(bool y) 476void TextEdit::setBold(bool y)
477{ 477{
478 QFont f = editor->font(); 478 QFont f = editor->font();
479 f.setBold(y); 479 f.setBold(y);
480 editor->setFont(f); 480 editor->setFont(f);
481} 481}
482 482
483void TextEdit::setItalic(bool y) 483void TextEdit::setItalic(bool y)
484{ 484{
485 QFont f = editor->font(); 485 QFont f = editor->font();
486 f.setItalic(y); 486 f.setItalic(y);
487 editor->setFont(f); 487 editor->setFont(f);
488} 488}
489 489
490void TextEdit::setWordWrap(bool y) 490void TextEdit::setWordWrap(bool y)
491{ 491{
492 bool state = editor->edited(); 492 bool state = editor->edited();
493 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 493 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
494 editor->setEdited( state ); 494 editor->setEdited( state );
495} 495}
496 496
497void TextEdit::fileNew() 497void TextEdit::fileNew()
498{ 498{
499// if( !bFromDocView ) { 499// if( !bFromDocView ) {
500// saveAs(); 500// saveAs();
501// } 501// }
502 newFile(DocLnk()); 502 newFile(DocLnk());
503} 503}
504 504
505void TextEdit::fileOpen() 505void TextEdit::fileOpen()
506{ 506{
507 Config cfg("TextEdit"); 507 Config cfg("TextEdit");
508 cfg.setGroup("View"); 508 cfg.setGroup("View");
509 bool b=FALSE; 509 bool b=FALSE;
510// if(cfg.readEntry("useOldFileDialog") == "TRUE") 510// if(cfg.readEntry("useOldFileDialog") == "TRUE")
511// b=TRUE; 511// b=TRUE;
512// if(!b) { 512// if(!b) {
513 QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); 513 QString str = OFileDialog::getOpenFileName( 2,"/");//,"", "*", this );
514 if(!str.isEmpty() ) 514 if(!str.isEmpty() )
515 openFile( str ); 515 openFile( str );
516// } else { 516// } else {
517// QString str; 517// QString str;
518// browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "*"); // 518// browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "*"); //
519// browseForFiles->setFileView( viewSelection ); 519// browseForFiles->setFileView( viewSelection );
520// browseForFiles->showMaximized(); 520// browseForFiles->showMaximized();
521// // if( result != -1 ) 521// // if( result != -1 )
522 522
523// if( browseForFiles->exec() != -1 ) { 523// if( browseForFiles->exec() != -1 ) {
524// QString selFile = browseForFiles->selectedFileName; 524// QString selFile = browseForFiles->selectedFileName;
525// QStringList fileList = browseForFiles->fileList; 525// QStringList fileList = browseForFiles->fileList;
526// qDebug(selFile); 526// qDebug(selFile);
527// QStringList::ConstIterator f; 527// QStringList::ConstIterator f;
528// QString fileTemp; 528// QString fileTemp;
529// for ( f = fileList.begin(); f != fileList.end(); f++ ) { 529// for ( f = fileList.begin(); f != fileList.end(); f++ ) {
530// fileTemp = *f; 530// fileTemp = *f;
531// fileTemp.right( fileTemp.length()-5); 531// fileTemp.right( fileTemp.length()-5);
532// QString fileName = fileTemp; 532// QString fileName = fileTemp;
533// if( fileName != "Unnamed" || fileName != "Empty Text" ) { 533// if( fileName != "Unnamed" || fileName != "Empty Text" ) {
534// currentFileName = fileName; 534// currentFileName = fileName;
535// qDebug("please open "+currentFileName); 535// qDebug("please open "+currentFileName);
536// openFile(currentFileName ); 536// openFile(currentFileName );
537// } 537// }
538// } 538// }
539// viewSelection = browseForFiles->SelectionCombo->currentItem(); 539// viewSelection = browseForFiles->SelectionCombo->currentItem();
540// } 540// }
541// delete browseForFiles; 541// delete browseForFiles;
542// editor->setEdited( FALSE); 542// editor->setEdited( FALSE);
543// edited1=FALSE; 543// edited1=FALSE;
544// edited=FALSE; 544// edited=FALSE;
545// if(caption().left(1)=="*") 545// if(caption().left(1)=="*")
546// setCaption(caption().right(caption().length()-1)); 546// setCaption(caption().right(caption().length()-1));
547// doSearchBar(); 547// doSearchBar();
548// } 548// }
549 549
550} 550}
551 551
552void TextEdit::doSearchBar() 552void TextEdit::doSearchBar()
553{ 553{
554 Config cfg("TextEdit"); 554 Config cfg("TextEdit");
555 cfg.setGroup("View"); 555 cfg.setGroup("View");
556 if(cfg.readEntry("SearchBar","Closed") != "Opened") 556 if(cfg.readEntry("SearchBar","Closed") != "Opened")
557 searchBar->hide(); 557 searchBar->hide();
558} 558}
559 559
560#if 0 560#if 0
561void TextEdit::slotFind() 561void TextEdit::slotFind()
562{ 562{
563 FindDialog frmFind( tr("Text Editor"), this ); 563 FindDialog frmFind( tr("Text Editor"), this );
564 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 564 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
565 editor, SLOT(slotDoFind( const QString&,bool,bool))); 565 editor, SLOT(slotDoFind( const QString&,bool,bool)));
566 566
567 //case sensitive, backwards, [category] 567 //case sensitive, backwards, [category]
568 568
569 connect( editor, SIGNAL(notFound()), 569 connect( editor, SIGNAL(notFound()),
570 &frmFind, SLOT(slotNotFound()) ); 570 &frmFind, SLOT(slotNotFound()) );
571 connect( editor, SIGNAL(searchWrapped()), 571 connect( editor, SIGNAL(searchWrapped()),
572 &frmFind, SLOT(slotWrapAround()) ); 572 &frmFind, SLOT(slotWrapAround()) );
573 573
574 frmFind.exec(); 574 frmFind.exec();
575 575
576 576
577} 577}
578#endif 578#endif
579 579
580void TextEdit::fileRevert() 580void TextEdit::fileRevert()
581{ 581{
582 clear(); 582 clear();
583 fileOpen(); 583 fileOpen();
584} 584}
585 585
586void TextEdit::editCut() 586void TextEdit::editCut()
587{ 587{
588#ifndef QT_NO_CLIPBOARD 588#ifndef QT_NO_CLIPBOARD
589 editor->cut(); 589 editor->cut();
590#endif 590#endif
591} 591}
592 592
593void TextEdit::editCopy() 593void TextEdit::editCopy()
594{ 594{
595#ifndef QT_NO_CLIPBOARD 595#ifndef QT_NO_CLIPBOARD
596 editor->copy(); 596 editor->copy();
597#endif 597#endif
598} 598}
599 599
600void TextEdit::editPaste() 600void TextEdit::editPaste()
601{ 601{
602#ifndef QT_NO_CLIPBOARD 602#ifndef QT_NO_CLIPBOARD
603 editor->paste(); 603 editor->paste();
604#endif 604#endif
605} 605}
606 606
607void TextEdit::editFind() 607void TextEdit::editFind()
608{ 608{
609 searchBar->show(); 609 searchBar->show();
@@ -655,271 +655,277 @@ void TextEdit::openFile( const QString &f )
655 qDebug("filename is "+ f); 655 qDebug("filename is "+ f);
656 QString filer; 656 QString filer;
657// bFromDocView = TRUE; 657// bFromDocView = TRUE;
658 if(f.find(".desktop",0,TRUE) != -1) { 658 if(f.find(".desktop",0,TRUE) != -1) {
659 switch ( QMessageBox::warning(this,tr("Text Editor"), 659 switch ( QMessageBox::warning(this,tr("Text Editor"),
660 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), 660 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"),
661 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 661 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
662 case 0: 662 case 0:
663 filer = f; 663 filer = f;
664 break; 664 break;
665 case 1: 665 case 1:
666 DocLnk sf(f); 666 DocLnk sf(f);
667 filer = sf.file(); 667 filer = sf.file();
668 break; 668 break;
669 } 669 }
670 } else { 670 } else {
671 filer = f; 671 filer = f;
672 fileIs = TRUE; 672 fileIs = TRUE;
673 } 673 }
674 674
675 DocLnk nf; 675 DocLnk nf;
676 nf.setType("text/plain"); 676 nf.setType("text/plain");
677 nf.setFile(filer); 677 nf.setFile(filer);
678 currentFileName=filer; 678 currentFileName=filer;
679 QFileInfo fi( currentFileName); 679 QFileInfo fi( currentFileName);
680 nf.setName(fi.baseName()); 680 nf.setName(fi.baseName());
681 qDebug("openFile string "+currentFileName); 681 qDebug("openFile string "+currentFileName);
682 682
683 openFile(nf); 683 openFile(nf);
684 showEditTools(); 684 showEditTools();
685 // Show filename in caption 685 // Show filename in caption
686 QString name = filer; 686 QString name = filer;
687 int sep = name.findRev( '/' ); 687 int sep = name.findRev( '/' );
688 if ( sep > 0 ) 688 if ( sep > 0 )
689 name = name.mid( sep+1 ); 689 name = name.mid( sep+1 );
690 updateCaption( name ); 690 updateCaption( name );
691} 691}
692 692
693void TextEdit::openFile( const DocLnk &f ) 693void TextEdit::openFile( const DocLnk &f )
694{ 694{
695// clear(); 695// clear();
696// bFromDocView = TRUE; 696// bFromDocView = TRUE;
697 FileManager fm; 697 FileManager fm;
698 QString txt; 698 QString txt;
699 currentFileName=f.file(); 699 currentFileName=f.file();
700 qDebug("openFile doclnk " + currentFileName); 700 qDebug("openFile doclnk " + currentFileName);
701 if ( !fm.loadFile( f, txt ) ) { 701 if ( !fm.loadFile( f, txt ) ) {
702 // ####### could be a new file 702 // ####### could be a new file
703 qDebug( "Cannot open file" ); 703 qDebug( "Cannot open file" );
704 } 704 }
705// fileNew(); 705// fileNew();
706 if ( doc ) 706 if ( doc )
707 delete doc; 707 delete doc;
708 doc = new DocLnk(f); 708 doc = new DocLnk(f);
709 editor->setText(txt); 709 editor->setText(txt);
710 editor->setEdited( FALSE); 710 editor->setEdited( FALSE);
711 edited1=FALSE; 711 edited1=FALSE;
712 edited=FALSE; 712 edited=FALSE;
713 713
714 doc->setName(currentFileName); 714 doc->setName(currentFileName);
715 updateCaption(); 715 updateCaption();
716} 716}
717 717
718void TextEdit::showEditTools() 718void TextEdit::showEditTools()
719{ 719{
720// if ( !doc ) 720// if ( !doc )
721// close(); 721// close();
722// clear(); 722// clear();
723 menu->show(); 723 menu->show();
724 editBar->show(); 724 editBar->show();
725 if ( searchVisible ) 725 if ( searchVisible )
726 searchBar->show(); 726 searchBar->show();
727// updateCaption(); 727// updateCaption();
728 setWState (WState_Reserved1 ); 728 setWState (WState_Reserved1 );
729} 729}
730 730
731/*! 731/*!
732 unprompted save */ 732 unprompted save */
733bool TextEdit::save() 733bool TextEdit::save()
734{ 734{
735 QString file = doc->file(); 735 QString file = doc->file();
736 qDebug("saver file "+file); 736 qDebug("saver file "+file);
737 QString name= doc->name(); 737 QString name= doc->name();
738 qDebug("File named "+name); 738 qDebug("File named "+name);
739 QString rt = editor->text(); 739 QString rt = editor->text();
740 if( !rt.isEmpty() ) { 740 if( !rt.isEmpty() ) {
741 if(name.isEmpty()) { 741 if(name.isEmpty()) {
742 saveAs(); 742 saveAs();
743 } else { 743 } else {
744 currentFileName= name ; 744 currentFileName= name ;
745 qDebug("saveFile "+currentFileName); 745 qDebug("saveFile "+currentFileName);
746 746
747 struct stat buf; 747 struct stat buf;
748 mode_t mode; 748 mode_t mode;
749 stat(file.latin1(), &buf); 749 stat(file.latin1(), &buf);
750 mode = buf.st_mode; 750 mode = buf.st_mode;
751
751 if(!fileIs) { 752 if(!fileIs) {
752 doc->setName( name); 753 doc->setName( name);
753 FileManager fm; 754 FileManager fm;
754 if ( !fm.saveFile( *doc, rt ) ) { 755 if ( !fm.saveFile( *doc, rt ) ) {
755 return false; 756 return false;
756 } 757 }
757 } else { 758 } else {
758 qDebug("regular save file"); 759 qDebug("regular save file");
759 QFile f(file); 760 QFile f(file);
760 if( f.open(IO_WriteOnly)) { 761 if( f.open(IO_WriteOnly)) {
761 f.writeBlock(rt,rt.length()); 762 f.writeBlock(rt,rt.length());
762 } else { 763 } else {
763 QMessageBox::message("Text Edit","Write Failed"); 764 QMessageBox::message("Text Edit","Write Failed");
764 return false; 765 return false;
765 } 766 }
766 767
767 } 768 }
768 editor->setEdited( FALSE); 769 editor->setEdited( FALSE);
769 edited1=FALSE; 770 edited1=FALSE;
770 edited=FALSE; 771 edited=FALSE;
771 if(caption().left(1)=="*") 772 if(caption().left(1)=="*")
772 setCaption(caption().right(caption().length()-1)); 773 setCaption(caption().right(caption().length()-1));
773 774
774 775
775 chmod( file.latin1(), mode); 776 chmod( file.latin1(), mode);
776 } 777 }
777 return true; 778 return true;
778 } 779 }
779 return false; 780 return false;
780} 781}
781 782
782/*! 783/*!
783 prompted save */ 784 prompted save */
784bool TextEdit::saveAs() 785bool TextEdit::saveAs()
785{ 786{
786// qDebug("saveAsFile "+currentFileName); 787// qDebug("saveAsFile "+currentFileName);
787 // case of nothing to save... 788 // case of nothing to save...
788 if ( !doc )//|| !bFromDocView) 789 if ( !doc )//|| !bFromDocView)
789 { 790 {
790 qDebug("no doc"); 791 qDebug("no doc");
791 return true; 792 return true;
792 } 793 }
793 if ( !editor->edited() ) { 794 if ( !editor->edited() ) {
794 delete doc; 795 delete doc;
795 doc = 0; 796 doc = 0;
796 return true; 797 return true;
797 } 798 }
798 799
799 QString rt = editor->text(); 800 QString rt = editor->text();
800 qDebug(currentFileName); 801 qDebug(currentFileName);
801 802
802 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 803 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
803 qDebug("do silly TT filename thing"); 804 qDebug("do silly TT filename thing");
804 if ( doc->name().isEmpty() ) { 805 if ( doc->name().isEmpty() ) {
805 QString pt = rt.simplifyWhiteSpace(); 806 QString pt = rt.simplifyWhiteSpace();
806 int i = pt.find( ' ' ); 807 int i = pt.find( ' ' );
807 QString docname = pt; 808 QString docname = pt;
808 if ( i > 0 ) 809 if ( i > 0 )
809 docname = pt.left( i ); 810 docname = pt.left( i );
810 // remove "." at the beginning 811 // remove "." at the beginning
811 while( docname.startsWith( "." ) ) 812 while( docname.startsWith( "." ) )
812 docname = docname.mid( 1 ); 813 docname = docname.mid( 1 );
813 docname.replace( QRegExp("/"), "_" ); 814 docname.replace( QRegExp("/"), "_" );
814 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 815 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
815 if ( docname.length() > 40 ) 816 if ( docname.length() > 40 )
816 docname = docname.left(40); 817 docname = docname.left(40);
817 if ( docname.isEmpty() ) 818 if ( docname.isEmpty() )
818 docname = tr("Unnamed"); 819 docname = tr("Unnamed");
819 doc->setName(docname); 820 doc->setName(docname);
820 currentFileName=docname; 821 currentFileName=docname;
821 } 822 }
822 } 823 }
823 824
824 825
825 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); 826// QString str = OFileDialog::getSaveFileName( 2,"/");//,"", "*", this );
826 qDebug("wanna save filename "+currentFileName); 827// if(!str.isEmpty() ) {
827 fileSaveDlg->exec(); 828// openFile( str );
828 if( fileSaveDlg->result() == 1 ) { 829
830 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName);
831 qDebug("wanna save filename "+currentFileName);
832 fileSaveDlg->exec();
833 if( fileSaveDlg->result() == 1 ) {
829 QString fileNm=fileSaveDlg->selectedFileName; 834 QString fileNm=fileSaveDlg->selectedFileName;
835// QString fileNm=srt;
830 qDebug("saving filename "+fileNm); 836 qDebug("saving filename "+fileNm);
831 QFileInfo fi(fileNm); 837 QFileInfo fi(fileNm);
832 currentFileName=fi.fileName(); 838 currentFileName=fi.fileName();
833 if(doc) { 839 if(doc) {
834// QString file = doc->file(); 840// QString file = doc->file();
835// doc->removeFiles(); 841// doc->removeFiles();
836 delete doc; 842 delete doc;
837 DocLnk nf; 843 DocLnk nf;
838 nf.setType("text/plain"); 844 nf.setType("text/plain");
839 nf.setFile( fileNm); 845 nf.setFile( fileNm);
840 doc = new DocLnk(nf); 846 doc = new DocLnk(nf);
841// editor->setText(rt); 847// editor->setText(rt);
842// qDebug("openFile doclnk "+currentFileName); 848// qDebug("openFile doclnk "+currentFileName);
843 doc->setName( currentFileName); 849 doc->setName( currentFileName);
844 updateCaption( currentFileName); 850 updateCaption( currentFileName);
845 851
846 FileManager fm; 852 FileManager fm;
847 if ( !fm.saveFile( *doc, rt ) ) { 853 if ( !fm.saveFile( *doc, rt ) ) {
848 return false; 854 return false;
849 } 855 }
850 if( fileSaveDlg->filePermCheck->isChecked() ) { 856 if( fileSaveDlg->filePermCheck->isChecked() ) {
851 filePermissions *filePerm; 857 filePermissions *filePerm;
852 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 858 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
853 filePerm->exec(); 859 filePerm->exec();
854 860
855 if( filePerm) 861 if( filePerm)
856 delete filePerm; 862 delete filePerm;
857 } 863 }
858 } 864 }
859 } 865 }
860 editor->setEdited(TRUE); 866 editor->setEdited(TRUE);
861 edited1=FALSE; 867 edited1=FALSE;
862 edited=TRUE; 868 edited=TRUE;
863 if(caption().left(1)=="*") 869 if(caption().left(1)=="*")
864 setCaption(caption().right(caption().length()-1)); 870 setCaption(caption().right(caption().length()-1));
865 871
866 if(fileSaveDlg) 872 if(fileSaveDlg)
867 delete fileSaveDlg; 873 delete fileSaveDlg;
868 return true; 874 return true;
869} //end saveAs 875} //end saveAs
870 876
871void TextEdit::clear() 877void TextEdit::clear()
872{ 878{
873 delete doc; 879 delete doc;
874 doc = 0; 880 doc = 0;
875 editor->clear(); 881 editor->clear();
876} 882}
877 883
878void TextEdit::updateCaption( const QString &name ) 884void TextEdit::updateCaption( const QString &name )
879{ 885{
880 if ( !doc ) 886 if ( !doc )
881 setCaption( tr("Text Editor") ); 887 setCaption( tr("Text Editor") );
882 else { 888 else {
883 QString s = name; 889 QString s = name;
884 if ( s.isNull() ) 890 if ( s.isNull() )
885 s = doc->name(); 891 s = doc->name();
886 if ( s.isEmpty() ) { 892 if ( s.isEmpty() ) {
887 s = tr( "Unnamed" ); 893 s = tr( "Unnamed" );
888 currentFileName=s; 894 currentFileName=s;
889 } 895 }
890 if(s.left(1) == "/") 896 if(s.left(1) == "/")
891 s = s.right(s.length()-1); 897 s = s.right(s.length()-1);
892 setCaption( s + " - " + tr("Text Editor") ); 898 setCaption( s + " - " + tr("Text Editor") );
893 } 899 }
894} 900}
895 901
896void TextEdit::setDocument(const QString& fileref) 902void TextEdit::setDocument(const QString& fileref)
897{ 903{
898 bFromDocView = TRUE; 904 bFromDocView = TRUE;
899 openFile(fileref); 905 openFile(fileref);
900 editor->setEdited(TRUE); 906 editor->setEdited(TRUE);
901 edited1=FALSE; 907 edited1=FALSE;
902 edited=TRUE; 908 edited=TRUE;
903 doSearchBar(); 909 doSearchBar();
904} 910}
905 911
906void TextEdit::closeEvent( QCloseEvent *e ) 912void TextEdit::closeEvent( QCloseEvent *e )
907{ 913{
908 bFromDocView = FALSE; 914 bFromDocView = FALSE;
909 e->accept(); 915 e->accept();
910} 916}
911 917
912void TextEdit::accept() 918void TextEdit::accept()
913 { 919 {
914 //if(caption() !="Unnamed") 920 //if(caption() !="Unnamed")
915 if(edited1) 921 if(edited1)
916 saveAs(); 922 saveAs();
917 exit(0); 923 exit(0);
918 924
919} 925}
920 926
921void TextEdit::changeFont() { 927void TextEdit::changeFont() {
922 FontDatabase fdb; 928 FontDatabase fdb;
923 QFont defaultFont=editor->font(); 929 QFont defaultFont=editor->font();
924 QFontInfo fontInfo(defaultFont); 930 QFontInfo fontInfo(defaultFont);
925 Config cfg("TextEdit"); 931 Config cfg("TextEdit");