summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-04-15 12:11:22 (UTC)
committer llornkcor <llornkcor>2003-04-15 12:11:22 (UTC)
commitd1b5bf7eeb365282356db49f49331c82f234086c (patch) (unidiff)
tree476c3a1bc4c19ab25c3820619e1fa55e8ce8f0a2
parentd0de397e46581f6ed5fcfad320b2b61be3858c5d (diff)
downloadopie-d1b5bf7eeb365282356db49f49331c82f234086c.zip
opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.gz
opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.bz2
changed copy method from clunky to using sendfile(). should be 1. faster and 2. require less memory
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp77
1 files changed, 51 insertions, 26 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 93203cd..eae86a4 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -1,95 +1,96 @@
1/*************************************************************************** 1/***************************************************************************
2 AdvancedFm.cpp 2 AdvancedFm.cpp
3 ------------------- 3 -------------------
4 ** Created: Sat Mar 9 23:33:09 2002 4 ** Created: Sat Mar 9 23:33:09 2002
5 copyright : (C) 2002 by ljp 5 copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12#include "advancedfm.h" 12#include "advancedfm.h"
13#include "output.h" 13#include "output.h"
14#include "filePermissions.h" 14#include "filePermissions.h"
15 15
16#include <opie/otabwidget.h> 16#include <opie/otabwidget.h>
17#include <opie/oprocess.h> 17#include <opie/oprocess.h>
18 18
19#include <qpe/lnkproperties.h> 19#include <qpe/lnkproperties.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include <qpe/applnk.h> 25#include <qpe/applnk.h>
26#include <qpe/ir.h> 26#include <qpe/ir.h>
27 27
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qmultilineedit.h> 29#include <qmultilineedit.h>
30 30
31#include <qstring.h> 31#include <qstring.h>
32 32
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qcombobox.h> 35#include <qcombobox.h>
36#include <qpopupmenu.h> 36#include <qpopupmenu.h>
37#include <qtabwidget.h> 37#include <qtabwidget.h>
38#include <qtoolbutton.h> 38#include <qtoolbutton.h>
39#include <qtabwidget.h> 39#include <qtabwidget.h>
40#include <qlineedit.h> 40#include <qlineedit.h>
41#include <qlistview.h> 41#include <qlistview.h>
42 42
43#include <stdlib.h> 43#include <stdlib.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <sys/stat.h> 45#include <sys/stat.h>
46#include <dirent.h> 46#include <dirent.h>
47 47#include <sys/sendfile.h>
48#include <fcntl.h>
48 49
49void AdvancedFm::doDirChange() 50void AdvancedFm::doDirChange()
50{ 51{
51 ListClicked( CurrentView()->currentItem()); 52 ListClicked( CurrentView()->currentItem());
52} 53}
53 54
54void AdvancedFm::showMenuHidden() 55void AdvancedFm::showMenuHidden()
55{ 56{
56 if (b) 57 if (b)
57 { 58 {
58 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 59 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
59 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 60 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
60 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); 61 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
61// b=FALSE; 62// b=FALSE;
62 63
63 } 64 }
64 else 65 else
65 { 66 {
66 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 67 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
67 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 68 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
68 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); 69 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
69// b=TRUE; 70// b=TRUE;
70 } 71 }
71 rePopulate(); 72 rePopulate();
72// if(b) qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<< true"); 73// if(b) qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<< true");
73 if(b) b = false; else b = true; 74 if(b) b = false; else b = true;
74} 75}
75 76
76void AdvancedFm::showHidden() 77void AdvancedFm::showHidden()
77{ 78{
78 if (b) 79 if (b)
79 { 80 {
80 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 81 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
81 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 82 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
82// fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); 83// fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
83// b=FALSE; 84// b=FALSE;
84 85
85 } 86 }
86 else 87 else
87 { 88 {
88 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 89 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
89 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 90 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
90// fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); 91// fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
91// b=TRUE; 92// b=TRUE;
92 } 93 }
93 rePopulate(); 94 rePopulate();
94} 95}
95 96
@@ -267,97 +268,97 @@ void AdvancedFm::doProperties()
267 268
268 QStringList curFileList = getPath(); 269 QStringList curFileList = getPath();
269 270
270 QString filePath; 271 QString filePath;
271 filePath = CurrentDir()->canonicalPath()+"/"; 272 filePath = CurrentDir()->canonicalPath()+"/";
272 273
273 qDebug("%d",curFileList.count()); 274 qDebug("%d",curFileList.count());
274 275
275 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) 276 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it )
276 { 277 {
277 qDebug((filePath+*it)); 278 qDebug((filePath+*it));
278 DocLnk lnk( (filePath+*it)); 279 DocLnk lnk( (filePath+*it));
279 LnkProperties prop( &lnk ); 280 LnkProperties prop( &lnk );
280 prop.showMaximized(); 281 prop.showMaximized();
281 prop.exec(); 282 prop.exec();
282 } 283 }
283#endif 284#endif
284 285
285} 286}
286 287
287void AdvancedFm::upDir() 288void AdvancedFm::upDir()
288{ 289{
289 QDir *thisDir = CurrentDir(); 290 QDir *thisDir = CurrentDir();
290 QString current = thisDir->canonicalPath(); 291 QString current = thisDir->canonicalPath();
291 QDir dir(current); 292 QDir dir(current);
292 dir.cdUp(); 293 dir.cdUp();
293 current = dir.canonicalPath(); 294 current = dir.canonicalPath();
294 chdir( current.latin1() ); 295 chdir( current.latin1() );
295 thisDir->cd( current, TRUE); 296 thisDir->cd( current, TRUE);
296 297
297 populateView(); 298 populateView();
298 update(); 299 update();
299} 300}
300 301
301void AdvancedFm::copy() 302void AdvancedFm::copy()
302{ 303{
303 qApp->processEvents(); 304 qApp->processEvents();
304 QStringList curFileList = getPath(); 305 QStringList curFileList = getPath();
305 306
306 QDir *thisDir = CurrentDir(); 307 QDir *thisDir = CurrentDir();
307 QDir *thatDir = OtherDir(); 308 QDir *thatDir = OtherDir();
308 309
309 bool doMsg=true; 310 bool doMsg=true;
310 int count=curFileList.count(); 311 int count=curFileList.count();
311 if( count > 0) { 312 if( count > 0) {
312 if(count > 1 ){ 313 if(count > 1 ){
313 QString msg; 314 QString msg;
314 msg=tr("Really copy\n%1 files?").arg(count); 315 msg=tr("Really copy\n%1 files?").arg(count);
315 switch ( QMessageBox::warning(this,tr("Delete"),msg 316 switch ( QMessageBox::warning(this,tr("Copy"),msg
316 ,tr("Yes"),tr("No"),0,0,1) ) 317 ,tr("Yes"),tr("No"),0,0,1) )
317 { 318 {
318 case 0: 319 case 0:
319 doMsg=false; 320 doMsg=false;
320 break; 321 break;
321 case 1: 322 case 1:
322 return; 323 return;
323 break; 324 break;
324 }; 325 };
325 } 326 }
326 327
327 QString curFile, item, destFile; 328 QString curFile, item, destFile;
328 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) 329 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it )
329 { 330 {
330 item=(*it); 331 item=(*it);
331 if(item.find("->",0,TRUE)) //symlink 332 if(item.find("->",0,TRUE)) //symlink
332 item = item.left(item.find("->",0,TRUE)); 333 item = item.left(item.find("->",0,TRUE));
333 334
334 curFile = thisDir->canonicalPath()+"/"+ item; 335 curFile = thisDir->canonicalPath()+"/"+ item;
335 destFile = thatDir->canonicalPath()+"/"+ item; 336 destFile = thatDir->canonicalPath()+"/"+ item;
336 337
337 qDebug("Destination file is "+destFile); 338 qDebug("Destination file is "+destFile);
338 qDebug("CurrentFile file is " + curFile); 339 qDebug("CurrentFile file is " + curFile);
339 340
340 QFile f(destFile); 341 QFile f(destFile);
341 if( f.exists()) 342 if( f.exists())
342 { 343 {
343 if(doMsg) 344 if(doMsg)
344 { 345 {
345 switch ( QMessageBox::warning(this,tr("File Exists!"), 346 switch ( QMessageBox::warning(this,tr("File Exists!"),
346 tr("%1 exists. Ok to overwrite?").arg( item ), 347 tr("%1 exists. Ok to overwrite?").arg( item ),
347 tr("Yes"),tr("No"),0,0,1) ) 348 tr("Yes"),tr("No"),0,0,1) )
348 { 349 {
349 case 1: 350 case 1:
350 return; 351 return;
351 break; 352 break;
352 }; 353 };
353 } 354 }
354 f.remove(); 355 f.remove();
355 } 356 }
356 357
357 if( !copyFile( curFile, destFile) ) 358 if( !copyFile( curFile, destFile) )
358 { 359 {
359 QMessageBox::message("AdvancedFm", 360 QMessageBox::message("AdvancedFm",
360 tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); 361 tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) );
361 return; 362 return;
362 } 363 }
363 } 364 }
@@ -475,122 +476,146 @@ void AdvancedFm::copySameDir()
475} 476}
476 477
477void AdvancedFm::move() 478void AdvancedFm::move()
478{ 479{
479 qApp->processEvents(); 480 qApp->processEvents();
480 481
481 QStringList curFileList = getPath(); 482 QStringList curFileList = getPath();
482 if( curFileList.count() > 0) 483 if( curFileList.count() > 0)
483 { 484 {
484 QString curFile, destFile, item; 485 QString curFile, destFile, item;
485 486
486 QDir *thisDir = CurrentDir(); 487 QDir *thisDir = CurrentDir();
487 QDir *thatDir = OtherDir(); 488 QDir *thatDir = OtherDir();
488 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) 489 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it )
489 { 490 {
490 item=(*it); 491 item=(*it);
491 QString destFile = thatDir->canonicalPath(); 492 QString destFile = thatDir->canonicalPath();
492 493
493 if(destFile.right(1).find("/",0,TRUE) == -1) 494 if(destFile.right(1).find("/",0,TRUE) == -1)
494 destFile+="/"; 495 destFile+="/";
495 destFile += item; 496 destFile += item;
496 qDebug("Destination file is "+destFile); 497 qDebug("Destination file is "+destFile);
497 498
498 curFile = thisDir->canonicalPath(); 499 curFile = thisDir->canonicalPath();
499 if(curFile.right(1).find("/",0,TRUE) == -1) 500 if(curFile.right(1).find("/",0,TRUE) == -1)
500 curFile +="/"; 501 curFile +="/";
501 curFile+= item; 502 curFile+= item;
502 qDebug("CurrentFile file is " + curFile); 503 qDebug("CurrentFile file is " + curFile);
503 504
504 QFile f( curFile); 505 QFile f( curFile);
505 if( f.exists()) { 506 if( f.exists()) {
506 if( !copyFile( curFile, destFile) ) 507 if( !copyFile( curFile, destFile) )
507 { 508 {
508 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); 509 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
509 return; 510 return;
510 } else 511 } else
511 QFile::remove(curFile); 512 QFile::remove(curFile);
512 } 513 }
513 } 514 }
514 515
515 } 516 }
516 setOtherTabCurrent(); 517 setOtherTabCurrent();
517 populateView(); 518 populateView();
518// populateLocalView(); 519// populateLocalView();
519} 520}
520 521
521bool AdvancedFm::copyFile( const QString & src, const QString & dest ) 522bool AdvancedFm::copyFile( const QString & src, const QString & dest )
522{ 523{
523 char bf[ 50000 ]; 524// char bf[ 50000 ];
524 int bytesRead; 525// int bytesRead;
525 bool success = TRUE; 526 bool success = true;
526 struct stat status; 527 struct stat status;
528
529// QFile s( src );
530// QFile d( dest );
531
532 int read_fd=0;
533 int write_fd=0;
534 struct stat stat_buf;
535 off_t offset = 0;
536 read_fd = ::open(src.latin1(), O_RDONLY);
537 if(read_fd != -1) {
538 fstat (read_fd, &stat_buf);
539 write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode);
540 if(write_fd != -1) {
541 if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) {
542 success = false;
543 }
544 } else {
545 success = false;
546 }
547 } else {
548 success = false;
549 }
527 550
528 QFile s( src ); 551 ::close (read_fd);
529 QFile d( dest ); 552 ::close (write_fd);
530 553
531 if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) 554
532 { 555// if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) )
533 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) 556// {
534 { 557// while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) )
535 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ 558// {
536 success = FALSE; 559// if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
537 break; 560// success = FALSE;
538 } 561// break;
539 } 562// }
540 if( success && (bytesRead > 0) ) 563// }
541 { 564// if( success && (bytesRead > 0) )
542 d.writeBlock( bf, bytesRead ); 565// {
543 } 566// d.writeBlock( bf, bytesRead );
544 } 567// }
545 else 568
546 { 569// }
547 success = FALSE; 570// else
548 } 571// {
572// success = FALSE;
573// }
549 574
550 // Set file permissions 575 // Set file permissions
551 if( stat( (const char *) src, &status ) == 0 ) 576 if( stat( (const char *) src, &status ) == 0 )
552 { 577 {
553 chmod( (const char *) dest, status.st_mode ); 578 chmod( (const char *) dest, status.st_mode );
554 } 579 }
555 580
556 return success; 581 return success;
557} 582}
558 583
559void AdvancedFm::runCommand() 584void AdvancedFm::runCommand()
560{ 585{
561 QDir *thisDir = CurrentDir(); 586 QDir *thisDir = CurrentDir();
562 587
563 QString curFile; 588 QString curFile;
564 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); 589 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0);
565 590
566 InputDialog *fileDlg; 591 InputDialog *fileDlg;
567 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); 592 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
568 fileDlg->setInputText(curFile); 593 fileDlg->setInputText(curFile);
569 fileDlg->exec(); 594 fileDlg->exec();
570 //QString command; 595 //QString command;
571 596
572 if( fileDlg->result() == 1 ) 597 if( fileDlg->result() == 1 )
573 { 598 {
574 qDebug(fileDlg->LineEdit1->text()); 599 qDebug(fileDlg->LineEdit1->text());
575 QStringList command; 600 QStringList command;
576 601
577 command << "/bin/sh"; 602 command << "/bin/sh";
578 command << "-c"; 603 command << "-c";
579 command << fileDlg->LineEdit1->text(); 604 command << fileDlg->LineEdit1->text();
580 Output *outDlg; 605 Output *outDlg;
581 outDlg = new Output( command, this, tr("AdvancedFm Output"), true); 606 outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
582 outDlg->showMaximized(); 607 outDlg->showMaximized();
583 outDlg->exec(); 608 outDlg->exec();
584 qApp->processEvents(); 609 qApp->processEvents();
585 610
586 } 611 }
587} 612}
588 613
589void AdvancedFm::runCommandStd() 614void AdvancedFm::runCommandStd()
590{ 615{
591 QString curFile; 616 QString curFile;
592 QDir *thisDir = CurrentDir(); 617 QDir *thisDir = CurrentDir();
593 QListView *thisView = CurrentView(); 618 QListView *thisView = CurrentView();
594 if( thisView->currentItem()) 619 if( thisView->currentItem())
595 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); 620 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0);
596 621