summaryrefslogtreecommitdiff
path: root/noncore/apps/advancedfm/advancedfmMenu.cpp
Unidiff
Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp197
1 files changed, 98 insertions, 99 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 8d04c68..5a46579 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -268,15 +268,18 @@ void AdvancedFm::upDir() {
268 thisDir->cd( current, TRUE); 268 thisDir->cd( current, TRUE);
269 269
270 populateView(); 270 populateView();
271 update(); 271 update();
272} 272}
273 273
274void AdvancedFm::copyTimer() {
275 QTimer::singleShot(125,this,SLOT(copy()));
276}
277
274void AdvancedFm::copy() { 278void AdvancedFm::copy() {
275 qApp->processEvents(); 279 QStringList curFileList = getPath();
276 QStringList curFileList = getPath();
277 280
278 QDir *thisDir = CurrentDir(); 281 QDir *thisDir = CurrentDir();
279 QDir *thatDir = OtherDir(); 282 QDir *thatDir = OtherDir();
280 283
281 bool doMsg=true; 284 bool doMsg=true;
282 int count=curFileList.count(); 285 int count=curFileList.count();
@@ -309,33 +312,36 @@ void AdvancedFm::copy() {
309// odebug << "CurrentFile file is " + curFile << oendl; 312// odebug << "CurrentFile file is " + curFile << oendl;
310 313
311 QFile f(destFile); 314 QFile f(destFile);
312 if( f.exists()) { 315 if( f.exists()) {
313 if(doMsg) { 316 if(doMsg) {
314 switch ( QMessageBox::warning(this,tr("File Exists!"), 317 switch ( QMessageBox::warning(this,tr("File Exists!"),
315 tr("%1 exists. Ok to overwrite?").arg( item ), 318 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(item),
316 tr("Yes"),tr("No"),0,0,1) ) { 319 tr("Yes"),tr("No"),0,0,1)) {
317 case 1: 320 case 1:
318 return; 321 return;
319 break; 322 break;
320 }; 323 };
321 } 324 }
322 f.remove(); 325 f.remove();
323 } 326 }
324 327
325 if( !copyFile( curFile, destFile) ) { 328 if( !copyFile( curFile, destFile) ) {
326 QMessageBox::message("AdvancedFm", 329 QMessageBox::message("AdvancedFm",
327 tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); 330 tr( "<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
328 return; 331 return;
329 } 332 }
330 } 333 }
331 setOtherTabCurrent(); 334 rePopulate();
332 rePopulate();
333 } 335 }
334} 336}
335 337
338void AdvancedFm::copyAsTimer() {
339 QTimer::singleShot(125,this,SLOT(copyAs()));
340}
341
336void AdvancedFm::copyAs() { 342void AdvancedFm::copyAs() {
337 343
338 QStringList curFileList = getPath(); 344 QStringList curFileList = getPath();
339 QString curFile, item; 345 QString curFile, item;
340 InputDialog *fileDlg; 346 InputDialog *fileDlg;
341 347
@@ -343,49 +349,52 @@ void AdvancedFm::copyAs() {
343 QDir *thatDir = OtherDir(); 349 QDir *thatDir = OtherDir();
344 350
345 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 351 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
346 QString destFile; 352 QString destFile;
347 item=(*it); 353 item=(*it);
348 curFile = thisDir->canonicalPath()+"/"+(*it); 354 curFile = thisDir->canonicalPath()+"/"+(*it);
349 fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); 355 fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0);
350 356
351 fileDlg->setInputText((const QString &) destFile ); 357 fileDlg->setInputText((const QString &) destFile );
352 fileDlg->exec(); 358 fileDlg->exec();
353 359
354 if( fileDlg->result() == 1 ) { 360 if( fileDlg->result() == 1 ) {
355 QString filename = fileDlg->LineEdit1->text(); 361 QString filename = fileDlg->LineEdit1->text();
356 destFile = thatDir->canonicalPath()+"/"+filename; 362 destFile = thatDir->canonicalPath()+"/"+filename;
357 363
358 QFile f( destFile); 364 QFile f( destFile);
359 if( f.exists()) { 365 if( f.exists()) {
360 switch (QMessageBox::warning(this,tr("File Exists!"), 366 switch (QMessageBox::warning(this,tr("File Exists!"),
361 item+tr("\nexists. Ok to overwrite?"), 367 tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item),
362 tr("Yes"),tr("No"),0,0,1) ) { 368 tr("Yes"),tr("No"),0,0,1) ) {
363 case 0: 369 case 0:
364 f.remove(); 370 f.remove();
365 break; 371 break;
366 case 1: 372 case 1:
367 return; 373 return;
368 break; 374 break;
369 }; 375 };
370 } 376 }
371 if( !copyFile( curFile, destFile) ) { 377 if( !copyFile( curFile, destFile) ) {
372 QMessageBox::message("AdvancedFm",tr("Could not copy\n") 378 QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
373 +curFile +tr("to\n")+destFile);
374 return; 379 return;
375 } 380 }
376 } 381 }
377 delete fileDlg; 382 delete fileDlg;
378 383
379 } 384 }
380 rePopulate(); 385 rePopulate();
381 setOtherTabCurrent(); 386 // setOtherTabCurrent();
382 qApp->processEvents(); 387 qApp->processEvents();
383 388
384} 389}
385 390
391void AdvancedFm::copySameDirTimer() {
392 QTimer::singleShot(125,this,SLOT(copySameDir()));
393}
394
386void AdvancedFm::copySameDir() { 395void AdvancedFm::copySameDir() {
387 qApp->processEvents(); 396 qApp->processEvents();
388 QStringList curFileList = getPath(); 397 QStringList curFileList = getPath();
389 QString curFile, item, destFile; 398 QString curFile, item, destFile;
390 InputDialog *fileDlg; 399 InputDialog *fileDlg;
391 400
@@ -404,38 +413,40 @@ void AdvancedFm::copySameDir() {
404 QString filename = fileDlg->LineEdit1->text(); 413 QString filename = fileDlg->LineEdit1->text();
405 destFile = thisDir->canonicalPath()+"/"+filename; 414 destFile = thisDir->canonicalPath()+"/"+filename;
406 415
407 QFile f(destFile); 416 QFile f(destFile);
408 if( f.exists()) { 417 if( f.exists()) {
409 switch (QMessageBox::warning(this,tr("Delete"), 418 switch (QMessageBox::warning(this,tr("Delete"),
410 destFile+tr(" already exists.\nDo you really want to delete it?"), 419 tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile),
411 tr("Yes"),tr("No"),0,0,1) ) { 420 tr("Yes"),tr("No"),0,0,1) ) {
412 case 0: 421 case 0:
413 422
414 f.remove(); 423 f.remove();
415 break; 424 break;
416 case 1: 425 case 1:
417 return; 426 return;
418 break; 427 break;
419 }; 428 };
420 } 429 }
421 if(!copyFile( curFile,destFile) ) { 430 if(!copyFile( curFile,destFile) ) {
422 QMessageBox::message("AdvancedFm",tr("Could not copy\n") 431 QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
423 +curFile +tr("to\n")+destFile);
424 return; 432 return;
425 } 433 }
426 434
427// odebug << "copy "+curFile+" as "+destFile << oendl; 435// odebug << "copy "+curFile+" as "+destFile << oendl;
428 } 436 }
429 delete fileDlg; 437 delete fileDlg;
430 } 438 }
431 rePopulate(); 439 rePopulate();
432} 440}
433 441
442void AdvancedFm::moveTimer() {
443 QTimer::singleShot(125,this,SLOT(move()));
444}
445
434void AdvancedFm::move() { 446void AdvancedFm::move() {
435 qApp->processEvents();
436 447
437 QStringList curFileList = getPath(); 448 QStringList curFileList = getPath();
438 if( curFileList.count() > 0) { 449 if( curFileList.count() > 0) {
439 QString curFile, destFile, item; 450 QString curFile, destFile, item;
440 451
441 QDir *thisDir = CurrentDir(); 452 QDir *thisDir = CurrentDir();
@@ -457,26 +468,25 @@ void AdvancedFm::move() {
457 468
458 if(QFileInfo(curFile).isDir()) { 469 if(QFileInfo(curFile).isDir()) {
459 moveDirectory( curFile, destFile ); 470 moveDirectory( curFile, destFile );
460 rePopulate(); 471 rePopulate();
461 return; 472 return;
462 } 473 }
463 474 QFile f( curFile);
464 QFile f( curFile);
465 if( f.exists()) { 475 if( f.exists()) {
466 if( !copyFile( curFile, destFile) ) { 476 if( !copyFile( curFile, destFile) ) {
467 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); 477 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
468 return; 478 return;
469 } else 479 } else
470 QFile::remove(curFile); 480 QFile::remove(curFile);
471 } 481 }
472 } 482 }
473 483
474 } 484 }
475 rePopulate(); 485 rePopulate();
476 setOtherTabCurrent(); 486 //setOtherTabCurrent();
477} 487}
478 488
479bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { 489bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
480 int err = 0; 490 int err = 0;
481 if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; 491 if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src;
482 err = system((const char*)cmd); 492 err = system((const char*)cmd);
@@ -503,73 +513,71 @@ bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
503 513
504 return true; 514 return true;
505} 515}
506 516
507 517
508bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { 518bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
509 519 if(QFileInfo(src).isDir()) {
510 520 if( copyDirectory( src, dest )) {
511 if(QFileInfo(src).isDir()) { 521 // setOtherTabCurrent();
512 if( copyDirectory( src, dest )) { 522 rePopulate();
513 setOtherTabCurrent(); 523 return true;
514 populateView(); 524 }
515 return true; 525 else
516 } 526 return false;
517 else 527 }
518 return false; 528
519 } 529
520 530 bool success = true;
521 531 struct stat status;
522 bool success = true; 532 QFile srcFile(src);
523 struct stat status; 533 QFile destFile(dest);
524 QFile srcFile(src); 534 int err=0;
525 QFile destFile(dest); 535 int read_fd=0;
526 int err=0; 536 int write_fd=0;
527 int read_fd=0; 537 struct stat stat_buf;
528 int write_fd=0; 538 off_t offset = 0;
529 struct stat stat_buf; 539 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
530 off_t offset = 0;
531 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
532// owarn << "open failed" << oendl; 540// owarn << "open failed" << oendl;
533 return success = false; 541 return success = false;
534 } 542 }
535 read_fd = srcFile.handle(); 543 read_fd = srcFile.handle();
536 if(read_fd != -1) { 544 if(read_fd != -1) {
537 fstat (read_fd, &stat_buf); 545 fstat (read_fd, &stat_buf);
538 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { 546 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
539// owarn << "destfile open failed" << oendl; 547// owarn << "destfile open failed" << oendl;
540 return success = false; 548 return success = false;
541 } 549 }
542 write_fd = destFile.handle(); 550 write_fd = destFile.handle();
543 if(write_fd != -1) { 551 if(write_fd != -1) {
544 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 552 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
545 if( err == -1) { 553 if( err == -1) {
546 QString msg; 554 QString msg;
547 switch(err) { 555 switch(err) {
548 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 556 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
549 case EINVAL: msg = "Descriptor is not valid or locked. "; 557 case EINVAL: msg = "Descriptor is not valid or locked. ";
550 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 558 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
551 case EIO: msg = "Unspecified error while reading from in_fd."; 559 case EIO: msg = "Unspecified error while reading from in_fd.";
552 }; 560 };
553 success = false; 561 success = false;
554// owarn << msg << oendl; 562// owarn << msg << oendl;
555 } 563 }
556 } else { 564 } else {
557 success = false; 565 success = false;
558 } 566 }
559 } else { 567 } else {
560 success = false; 568 success = false;
561 } 569 }
562 srcFile.close(); 570 srcFile.close();
563 destFile.close(); 571 destFile.close();
564 // Set file permissions 572 // Set file permissions
565 if( stat( QFile::encodeName(src), &status ) == 0 ) { 573 if( stat( QFile::encodeName(src), &status ) == 0 ) {
566 chmod( QFile::encodeName(dest), status.st_mode ); 574 chmod( QFile::encodeName(dest), status.st_mode );
567 } 575 }
568 576
569 return success; 577 return success;
570} 578}
571 579
572void AdvancedFm::runCommand() { 580void AdvancedFm::runCommand() {
573 if( !CurrentView()->currentItem()) return; 581 if( !CurrentView()->currentItem()) return;
574 QDir *thisDir = CurrentDir(); 582 QDir *thisDir = CurrentDir();
575 583
@@ -705,17 +713,15 @@ void AdvancedFm::selectAll() {
705} 713}
706 714
707void AdvancedFm::startProcess(const QString & cmd) { 715void AdvancedFm::startProcess(const QString & cmd) {
708 QStringList command; 716 QStringList command;
709 OProcess *process; 717 OProcess *process;
710 process = new OProcess(); 718 process = new OProcess();
711 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), 719 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), this, SLOT( processEnded(Opie::Core::OProcess*)));
712 this, SLOT( processEnded(Opie::Core::OProcess*)));
713 720
714 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), 721 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int)));
715 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int)));
716 722
717 command << "/bin/sh"; 723 command << "/bin/sh";
718 command << "-c"; 724 command << "-c";
719 command << cmd.latin1(); 725 command << cmd.latin1();
720 *process << command; 726 *process << command;
721 if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) 727 if(!process->start(OProcess::NotifyOnExit, OProcess::All) )
@@ -751,19 +757,19 @@ bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) {
751 cancelRename(); 757 cancelRename();
752 return true; 758 return true;
753 } 759 }
754 } 760 }
755 if ( o->inherits( "QListView" ) ) { 761 if ( o->inherits( "QListView" ) ) {
756 if ( e->type() == QEvent::FocusIn ) { 762 if ( e->type() == QEvent::FocusIn ) {
757 if( o == Local_View) { //keep track of which view 763// if( o == Local_View) { //keep track of which view
758 qDebug("local view"); 764 // qDebug("local view");
759 whichTab = 1; 765// whichTab = 1;
760 } else { 766// } else {
761 whichTab = 2; 767// whichTab = 2;
762 qDebug("remote view"); 768 // qDebug("remote view");
763 } 769// }
764 } 770 }
765 OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection 771 OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection
766 } 772 }
767 773
768 return QWidget::eventFilter( o, e ); 774 return QWidget::eventFilter( o, e );
769} 775}
@@ -786,31 +792,24 @@ void AdvancedFm::cancelRename() {
786void AdvancedFm::doRename(QListView * view) { 792void AdvancedFm::doRename(QListView * view) {
787 if( !CurrentView()->currentItem()) return; 793 if( !CurrentView()->currentItem()) return;
788 794
789 QRect r = view->itemRect( view->currentItem( )); 795 QRect r = view->itemRect( view->currentItem( ));
790 r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); 796 r = QRect( view->viewportToContents( r.topLeft() ), r.size() );
791 r.setX( view->contentsX() ); 797 r.setX( view->contentsX() );
792 798 if ( r.width() > view->visibleWidth() )
793 if ( r.width() > view->visibleWidth() )
794 r.setWidth( view->visibleWidth() ); 799 r.setWidth( view->visibleWidth() );
795 800
796 renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); 801 renameBox = new QLineEdit( view->viewport(), "qt_renamebox" );
797 renameBox->setFrame(true); 802 renameBox->setFrame(true);
798
799 renameBox->setText( view->currentItem()->text(0) ); 803 renameBox->setText( view->currentItem()->text(0) );
800
801 renameBox->selectAll(); 804 renameBox->selectAll();
802 renameBox->installEventFilter( this ); 805 renameBox->installEventFilter( this );
803
804 view->addChild( renameBox, r.x(), r.y() ); 806 view->addChild( renameBox, r.x(), r.y() );
805 807 renameBox->resize( r.size() );
806 renameBox->resize( r.size() ); 808 view->viewport()->setFocusProxy( renameBox );
807 809 renameBox->setFocus();
808 view->viewport()->setFocusProxy( renameBox );
809
810 renameBox->setFocus();
811 renameBox->show(); 810 renameBox->show();
812} 811}
813 812
814 813
815void AdvancedFm::renameIt() { 814void AdvancedFm::renameIt() {
816 if( !CurrentView()->currentItem()) return; 815 if( !CurrentView()->currentItem()) return;