-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 90c887f..26bc36d 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -291,560 +291,564 @@ void AdvancedFm::copy() { | |||
291 | 291 | ||
292 | bool doMsg=true; | 292 | bool doMsg=true; |
293 | int count=curFileList.count(); | 293 | int count=curFileList.count(); |
294 | if( count > 0) { | 294 | if( count > 0) { |
295 | if(count > 1 ){ | 295 | if(count > 1 ){ |
296 | QString msg; | 296 | QString msg; |
297 | msg=tr("Really copy\n%1 files?").arg(count); | 297 | msg=tr("Really copy\n%1 files?").arg(count); |
298 | switch ( QMessageBox::warning(this,tr("Copy"),msg | 298 | switch ( QMessageBox::warning(this,tr("Copy"),msg |
299 | ,tr("Yes"),tr("No"),0,0,1) ) | 299 | ,tr("Yes"),tr("No"),0,0,1) ) |
300 | { | 300 | { |
301 | case 0: | 301 | case 0: |
302 | doMsg=false; | 302 | doMsg=false; |
303 | break; | 303 | break; |
304 | case 1: | 304 | case 1: |
305 | return; | 305 | return; |
306 | break; | 306 | break; |
307 | }; | 307 | }; |
308 | } | 308 | } |
309 | 309 | ||
310 | QString curFile, item, destFile; | 310 | QString curFile, item, destFile; |
311 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 311 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
312 | item=(*it); | 312 | item=(*it); |
313 | if(item.find("->",0,TRUE)) //symlink | 313 | if(item.find("->",0,TRUE)) //symlink |
314 | item = item.left(item.find("->",0,TRUE)); | 314 | item = item.left(item.find("->",0,TRUE)); |
315 | 315 | ||
316 | curFile = thisDir->canonicalPath()+"/"+ item; | 316 | curFile = thisDir->canonicalPath()+"/"+ item; |
317 | destFile = thatDir->canonicalPath()+"/"+ item; | 317 | destFile = thatDir->canonicalPath()+"/"+ item; |
318 | 318 | ||
319 | // qDebug("Destination file is "+destFile); | 319 | // qDebug("Destination file is "+destFile); |
320 | // qDebug("CurrentFile file is " + curFile); | 320 | // qDebug("CurrentFile file is " + curFile); |
321 | 321 | ||
322 | QFile f(destFile); | 322 | QFile f(destFile); |
323 | if( f.exists()) { | 323 | if( f.exists()) { |
324 | if(doMsg) { | 324 | if(doMsg) { |
325 | switch ( QMessageBox::warning(this,tr("File Exists!"), | 325 | switch ( QMessageBox::warning(this,tr("File Exists!"), |
326 | tr("%1 exists. Ok to overwrite?").arg( item ), | 326 | tr("%1 exists. Ok to overwrite?").arg( item ), |
327 | tr("Yes"),tr("No"),0,0,1) ) { | 327 | tr("Yes"),tr("No"),0,0,1) ) { |
328 | case 1: | 328 | case 1: |
329 | return; | 329 | return; |
330 | break; | 330 | break; |
331 | }; | 331 | }; |
332 | } | 332 | } |
333 | f.remove(); | 333 | f.remove(); |
334 | } | 334 | } |
335 | 335 | ||
336 | if( !copyFile( curFile, destFile) ) { | 336 | if( !copyFile( curFile, destFile) ) { |
337 | QMessageBox::message("AdvancedFm", | 337 | QMessageBox::message("AdvancedFm", |
338 | tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); | 338 | tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); |
339 | return; | 339 | return; |
340 | } | 340 | } |
341 | } | 341 | } |
342 | setOtherTabCurrent(); | 342 | setOtherTabCurrent(); |
343 | rePopulate(); | 343 | rePopulate(); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | void AdvancedFm::copyAs() { | 347 | void AdvancedFm::copyAs() { |
348 | qApp->processEvents(); | 348 | qApp->processEvents(); |
349 | 349 | ||
350 | QStringList curFileList = getPath(); | 350 | QStringList curFileList = getPath(); |
351 | QString curFile, item; | 351 | QString curFile, item; |
352 | InputDialog *fileDlg; | 352 | InputDialog *fileDlg; |
353 | 353 | ||
354 | QDir *thisDir = CurrentDir(); | 354 | QDir *thisDir = CurrentDir(); |
355 | QDir *thatDir = OtherDir(); | 355 | QDir *thatDir = OtherDir(); |
356 | 356 | ||
357 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 357 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
358 | QString destFile; | 358 | QString destFile; |
359 | item=(*it); | 359 | item=(*it); |
360 | curFile = thisDir->canonicalPath()+"/"+(*it); | 360 | curFile = thisDir->canonicalPath()+"/"+(*it); |
361 | fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); | 361 | fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); |
362 | 362 | ||
363 | fileDlg->setInputText((const QString &) destFile ); | 363 | fileDlg->setInputText((const QString &) destFile ); |
364 | fileDlg->exec(); | 364 | fileDlg->exec(); |
365 | 365 | ||
366 | if( fileDlg->result() == 1 ) { | 366 | if( fileDlg->result() == 1 ) { |
367 | QString filename = fileDlg->LineEdit1->text(); | 367 | QString filename = fileDlg->LineEdit1->text(); |
368 | destFile = thatDir->canonicalPath()+"/"+filename; | 368 | destFile = thatDir->canonicalPath()+"/"+filename; |
369 | 369 | ||
370 | QFile f( destFile); | 370 | QFile f( destFile); |
371 | if( f.exists()) { | 371 | if( f.exists()) { |
372 | switch (QMessageBox::warning(this,tr("File Exists!"), | 372 | switch (QMessageBox::warning(this,tr("File Exists!"), |
373 | item+tr("\nexists. Ok to overwrite?"), | 373 | item+tr("\nexists. Ok to overwrite?"), |
374 | tr("Yes"),tr("No"),0,0,1) ) { | 374 | tr("Yes"),tr("No"),0,0,1) ) { |
375 | case 0: | 375 | case 0: |
376 | f.remove(); | 376 | f.remove(); |
377 | break; | 377 | break; |
378 | case 1: | 378 | case 1: |
379 | return; | 379 | return; |
380 | break; | 380 | break; |
381 | }; | 381 | }; |
382 | } | 382 | } |
383 | if( !copyFile( curFile, destFile) ) { | 383 | if( !copyFile( curFile, destFile) ) { |
384 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") | 384 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") |
385 | +curFile +tr("to\n")+destFile); | 385 | +curFile +tr("to\n")+destFile); |
386 | return; | 386 | return; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | delete fileDlg; | 389 | delete fileDlg; |
390 | 390 | ||
391 | } | 391 | } |
392 | rePopulate(); | 392 | rePopulate(); |
393 | setOtherTabCurrent(); | 393 | setOtherTabCurrent(); |
394 | } | 394 | } |
395 | 395 | ||
396 | void AdvancedFm::copySameDir() { | 396 | void AdvancedFm::copySameDir() { |
397 | qApp->processEvents(); | 397 | qApp->processEvents(); |
398 | QStringList curFileList = getPath(); | 398 | QStringList curFileList = getPath(); |
399 | QString curFile, item, destFile; | 399 | QString curFile, item, destFile; |
400 | InputDialog *fileDlg; | 400 | InputDialog *fileDlg; |
401 | 401 | ||
402 | QDir *thisDir = CurrentDir(); | 402 | QDir *thisDir = CurrentDir(); |
403 | 403 | ||
404 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 404 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
405 | item=(*it); | 405 | item=(*it); |
406 | curFile = thisDir->canonicalPath()+"/"+ item; | 406 | curFile = thisDir->canonicalPath()+"/"+ item; |
407 | 407 | ||
408 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); | 408 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); |
409 | fileDlg->setInputText((const QString &) destFile ); | 409 | fileDlg->setInputText((const QString &) destFile ); |
410 | fileDlg->exec(); | 410 | fileDlg->exec(); |
411 | 411 | ||
412 | if( fileDlg->result() == 1 ) { | 412 | if( fileDlg->result() == 1 ) { |
413 | 413 | ||
414 | QString filename = fileDlg->LineEdit1->text(); | 414 | QString filename = fileDlg->LineEdit1->text(); |
415 | destFile = thisDir->canonicalPath()+"/"+filename; | 415 | destFile = thisDir->canonicalPath()+"/"+filename; |
416 | 416 | ||
417 | QFile f(destFile); | 417 | QFile f(destFile); |
418 | if( f.exists()) { | 418 | if( f.exists()) { |
419 | switch (QMessageBox::warning(this,tr("Delete"), | 419 | switch (QMessageBox::warning(this,tr("Delete"), |
420 | destFile+tr(" already exists.\nDo you really want to delete it?"), | 420 | destFile+tr(" already exists.\nDo you really want to delete it?"), |
421 | tr("Yes"),tr("No"),0,0,1) ) { | 421 | tr("Yes"),tr("No"),0,0,1) ) { |
422 | case 0: | 422 | case 0: |
423 | 423 | ||
424 | f.remove(); | 424 | f.remove(); |
425 | break; | 425 | break; |
426 | case 1: | 426 | case 1: |
427 | return; | 427 | return; |
428 | break; | 428 | break; |
429 | }; | 429 | }; |
430 | } | 430 | } |
431 | if(!copyFile( curFile,destFile) ) { | 431 | if(!copyFile( curFile,destFile) ) { |
432 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") | 432 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") |
433 | +curFile +tr("to\n")+destFile); | 433 | +curFile +tr("to\n")+destFile); |
434 | return; | 434 | return; |
435 | } | 435 | } |
436 | 436 | ||
437 | // qDebug("copy "+curFile+" as "+destFile); | 437 | // qDebug("copy "+curFile+" as "+destFile); |
438 | } | 438 | } |
439 | delete fileDlg; | 439 | delete fileDlg; |
440 | } | 440 | } |
441 | rePopulate(); | 441 | rePopulate(); |
442 | } | 442 | } |
443 | 443 | ||
444 | void AdvancedFm::move() { | 444 | void AdvancedFm::move() { |
445 | qApp->processEvents(); | 445 | qApp->processEvents(); |
446 | 446 | ||
447 | QStringList curFileList = getPath(); | 447 | QStringList curFileList = getPath(); |
448 | if( curFileList.count() > 0) { | 448 | if( curFileList.count() > 0) { |
449 | QString curFile, destFile, item; | 449 | QString curFile, destFile, item; |
450 | 450 | ||
451 | QDir *thisDir = CurrentDir(); | 451 | QDir *thisDir = CurrentDir(); |
452 | QDir *thatDir = OtherDir(); | 452 | QDir *thatDir = OtherDir(); |
453 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 453 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
454 | item=(*it); | 454 | item=(*it); |
455 | QString destFile = thatDir->canonicalPath(); | 455 | QString destFile = thatDir->canonicalPath(); |
456 | 456 | ||
457 | if(destFile.right(1).find("/",0,TRUE) == -1) | 457 | if(destFile.right(1).find("/",0,TRUE) == -1) |
458 | destFile+="/"; | 458 | destFile+="/"; |
459 | destFile += item; | 459 | destFile += item; |
460 | // qDebug("Destination file is "+destFile); | 460 | // qDebug("Destination file is "+destFile); |
461 | 461 | ||
462 | curFile = thisDir->canonicalPath(); | 462 | curFile = thisDir->canonicalPath(); |
463 | if(curFile.right(1).find("/",0,TRUE) == -1) | 463 | if(curFile.right(1).find("/",0,TRUE) == -1) |
464 | curFile +="/"; | 464 | curFile +="/"; |
465 | curFile+= item; | 465 | curFile+= item; |
466 | // qDebug("CurrentFile file is " + curFile); | 466 | // qDebug("CurrentFile file is " + curFile); |
467 | 467 | ||
468 | if(QFileInfo(curFile).isDir()) { | 468 | if(QFileInfo(curFile).isDir()) { |
469 | moveDirectory( curFile, destFile ); | 469 | moveDirectory( curFile, destFile ); |
470 | rePopulate(); | 470 | rePopulate(); |
471 | return; | 471 | return; |
472 | } | 472 | } |
473 | 473 | ||
474 | QFile f( curFile); | 474 | QFile f( curFile); |
475 | if( f.exists()) { | 475 | if( f.exists()) { |
476 | if( !copyFile( curFile, destFile) ) { | 476 | if( !copyFile( curFile, destFile) ) { |
477 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); | 477 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); |
478 | return; | 478 | return; |
479 | } else | 479 | } else |
480 | QFile::remove(curFile); | 480 | QFile::remove(curFile); |
481 | } | 481 | } |
482 | } | 482 | } |
483 | 483 | ||
484 | } | 484 | } |
485 | rePopulate(); | 485 | rePopulate(); |
486 | setOtherTabCurrent(); | 486 | setOtherTabCurrent(); |
487 | } | 487 | } |
488 | 488 | ||
489 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { | 489 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { |
490 | int err = 0; | 490 | int err = 0; |
491 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; | 491 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; |
492 | err = system((const char*)cmd); | 492 | err = system((const char*)cmd); |
493 | } else | 493 | } else |
494 | err = -1; | 494 | err = -1; |
495 | 495 | ||
496 | if(err!=0) { | 496 | if(err!=0) { |
497 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); | 497 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); |
498 | return false; | 498 | return false; |
499 | } | 499 | } |
500 | return true; | 500 | return true; |
501 | } | 501 | } |
502 | 502 | ||
503 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { | 503 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { |
504 | 504 | ||
505 | QStringcmd = "/bin/cp -fpR " + src + " " + dest; | 505 | QStringcmd = "/bin/cp -fpR " + src + " " + dest; |
506 | qWarning(cmd); | 506 | qWarning(cmd); |
507 | interr = system( (const char *) cmd ); | 507 | interr = system( (const char *) cmd ); |
508 | if ( err != 0 ) { | 508 | if ( err != 0 ) { |
509 | QMessageBox::message("AdvancedFm", | 509 | QMessageBox::message("AdvancedFm", |
510 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); | 510 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); |
511 | return false; | 511 | return false; |
512 | } | 512 | } |
513 | 513 | ||
514 | return true; | 514 | return true; |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | 518 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { |
519 | 519 | ||
520 | 520 | ||
521 | if(QFileInfo(src).isDir()) { | 521 | if(QFileInfo(src).isDir()) { |
522 | if( copyDirectory( src, dest )) { | 522 | if( copyDirectory( src, dest )) { |
523 | setOtherTabCurrent(); | 523 | setOtherTabCurrent(); |
524 | populateView(); | 524 | populateView(); |
525 | return true; | 525 | return true; |
526 | } | 526 | } |
527 | else | 527 | else |
528 | return false; | 528 | return false; |
529 | } | 529 | } |
530 | 530 | ||
531 | 531 | ||
532 | bool success = true; | 532 | bool success = true; |
533 | struct stat status; | 533 | struct stat status; |
534 | QFile srcFile(src); | 534 | QFile srcFile(src); |
535 | QFile destFile(dest); | 535 | QFile destFile(dest); |
536 | int err=0; | 536 | int err=0; |
537 | int read_fd=0; | 537 | int read_fd=0; |
538 | int write_fd=0; | 538 | int write_fd=0; |
539 | struct stat stat_buf; | 539 | struct stat stat_buf; |
540 | off_t offset = 0; | 540 | off_t offset = 0; |
541 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 541 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
542 | // qWarning("open failed"); | 542 | // qWarning("open failed"); |
543 | return success = false; | 543 | return success = false; |
544 | } | 544 | } |
545 | read_fd = srcFile.handle(); | 545 | read_fd = srcFile.handle(); |
546 | if(read_fd != -1) { | 546 | if(read_fd != -1) { |
547 | fstat (read_fd, &stat_buf); | 547 | fstat (read_fd, &stat_buf); |
548 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 548 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
549 | // qWarning("destfile open failed"); | 549 | // qWarning("destfile open failed"); |
550 | return success = false; | 550 | return success = false; |
551 | } | 551 | } |
552 | write_fd = destFile.handle(); | 552 | write_fd = destFile.handle(); |
553 | if(write_fd != -1) { | 553 | if(write_fd != -1) { |
554 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 554 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
555 | if( err == -1) { | 555 | if( err == -1) { |
556 | QString msg; | 556 | QString msg; |
557 | switch(err) { | 557 | switch(err) { |
558 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 558 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; |
559 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 559 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
560 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 560 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
561 | case EIO: msg = "Unspecified error while reading from in_fd."; | 561 | case EIO: msg = "Unspecified error while reading from in_fd."; |
562 | }; | 562 | }; |
563 | success = false; | 563 | success = false; |
564 | // qWarning(msg); | 564 | // qWarning(msg); |
565 | } | 565 | } |
566 | } else { | 566 | } else { |
567 | success = false; | 567 | success = false; |
568 | } | 568 | } |
569 | } else { | 569 | } else { |
570 | success = false; | 570 | success = false; |
571 | } | 571 | } |
572 | srcFile.close(); | 572 | srcFile.close(); |
573 | destFile.close(); | 573 | destFile.close(); |
574 | // Set file permissions | 574 | // Set file permissions |
575 | if( stat( (const char *) src, &status ) == 0 ) { | 575 | if( stat( (const char *) src, &status ) == 0 ) { |
576 | chmod( (const char *) dest, status.st_mode ); | 576 | chmod( (const char *) dest, status.st_mode ); |
577 | } | 577 | } |
578 | 578 | ||
579 | return success; | 579 | return success; |
580 | } | 580 | } |
581 | 581 | ||
582 | void AdvancedFm::runCommand() { | 582 | void AdvancedFm::runCommand() { |
583 | if( !CurrentView()->currentItem()) return; | 583 | if( !CurrentView()->currentItem()) return; |
584 | QDir *thisDir = CurrentDir(); | 584 | QDir *thisDir = CurrentDir(); |
585 | 585 | ||
586 | QString curFile; | 586 | QString curFile; |
587 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 587 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
588 | 588 | ||
589 | InputDialog *fileDlg; | 589 | InputDialog *fileDlg; |
590 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 590 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
591 | fileDlg->setInputText(curFile); | 591 | fileDlg->setInputText(curFile); |
592 | fileDlg->exec(); | 592 | fileDlg->exec(); |
593 | //QString command; | 593 | //QString command; |
594 | 594 | ||
595 | if( fileDlg->result() == 1 ) { | 595 | if( fileDlg->result() == 1 ) { |
596 | // qDebug(fileDlg->LineEdit1->text()); | 596 | // qDebug(fileDlg->LineEdit1->text()); |
597 | QStringList command; | 597 | QStringList command; |
598 | 598 | ||
599 | command << "/bin/sh"; | 599 | command << "/bin/sh"; |
600 | command << "-c"; | 600 | command << "-c"; |
601 | command << fileDlg->LineEdit1->text(); | 601 | command << fileDlg->LineEdit1->text(); |
602 | Output *outDlg; | 602 | Output *outDlg; |
603 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 603 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
604 | outDlg->showMaximized(); | 604 | outDlg->showMaximized(); |
605 | outDlg->exec(); | 605 | outDlg->exec(); |
606 | qApp->processEvents(); | 606 | qApp->processEvents(); |
607 | 607 | ||
608 | } | 608 | } |
609 | } | 609 | } |
610 | 610 | ||
611 | void AdvancedFm::runCommandStd() { | 611 | void AdvancedFm::runCommandStd() { |
612 | if( !CurrentView()->currentItem()) return; | 612 | if( !CurrentView()->currentItem()) return; |
613 | QString curFile; | 613 | QString curFile; |
614 | QDir *thisDir = CurrentDir(); | 614 | QDir *thisDir = CurrentDir(); |
615 | QListView *thisView = CurrentView(); | 615 | QListView *thisView = CurrentView(); |
616 | if( thisView->currentItem()) | 616 | if( thisView->currentItem()) |
617 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); | 617 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); |
618 | 618 | ||
619 | InputDialog *fileDlg; | 619 | InputDialog *fileDlg; |
620 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 620 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
621 | fileDlg->setInputText(curFile); | 621 | fileDlg->setInputText(curFile); |
622 | fileDlg->exec(); | 622 | fileDlg->exec(); |
623 | 623 | ||
624 | if( fileDlg->result() == 1 ) { | 624 | if( fileDlg->result() == 1 ) { |
625 | qApp->processEvents(); | 625 | qApp->processEvents(); |
626 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); | 626 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | 629 | ||
630 | void AdvancedFm::fileStatus() { | 630 | void AdvancedFm::fileStatus() { |
631 | if( !CurrentView()->currentItem()) return; | 631 | if( !CurrentView()->currentItem()) return; |
632 | QString curFile; | 632 | QString curFile; |
633 | curFile = CurrentView()->currentItem()->text(0); | 633 | curFile = CurrentView()->currentItem()->text(0); |
634 | 634 | ||
635 | QStringList command; | 635 | QStringList command; |
636 | command << "/bin/sh"; | 636 | command << "/bin/sh"; |
637 | command << "-c"; | 637 | command << "-c"; |
638 | command << "stat -l "+ curFile; | 638 | command << "stat -l "+ curFile; |
639 | 639 | ||
640 | Output *outDlg; | 640 | Output *outDlg; |
641 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 641 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
642 | outDlg->showMaximized(); | 642 | outDlg->showMaximized(); |
643 | outDlg->exec(); | 643 | outDlg->exec(); |
644 | qApp->processEvents(); | 644 | qApp->processEvents(); |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | void AdvancedFm::mkDir() { | 648 | void AdvancedFm::mkDir() { |
649 | makeDir(); | 649 | makeDir(); |
650 | } | 650 | } |
651 | 651 | ||
652 | void AdvancedFm::rn() { | 652 | void AdvancedFm::rn() { |
653 | renameIt(); | 653 | renameIt(); |
654 | } | 654 | } |
655 | 655 | ||
656 | void AdvancedFm::del() { | 656 | void AdvancedFm::del() { |
657 | doDelete(); | 657 | doDelete(); |
658 | } | 658 | } |
659 | 659 | ||
660 | void AdvancedFm::mkSym() { | 660 | void AdvancedFm::mkSym() { |
661 | QString cmd; | 661 | QString cmd; |
662 | QStringList curFileList = getPath(); | 662 | QStringList curFileList = getPath(); |
663 | if( curFileList.count() > 0) { | 663 | if( curFileList.count() > 0) { |
664 | QDir *thisDir = CurrentDir(); | 664 | QDir *thisDir = CurrentDir(); |
665 | QDir * thatDir = OtherDir(); | 665 | QDir * thatDir = OtherDir(); |
666 | 666 | ||
667 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 667 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
668 | 668 | ||
669 | QString destName = thatDir->canonicalPath()+"/"+(*it); | 669 | QString destName = thatDir->canonicalPath()+"/"+(*it); |
670 | if(destName.right(1) == "/") { | 670 | if(destName.right(1) == "/") { |
671 | destName = destName.left( destName.length() -1); | 671 | destName = destName.left( destName.length() -1); |
672 | } | 672 | } |
673 | 673 | ||
674 | QString curFile = thisDir->canonicalPath()+"/"+(*it); | 674 | QString curFile = thisDir->canonicalPath()+"/"+(*it); |
675 | 675 | ||
676 | if( curFile.right(1) == "/") { | 676 | if( curFile.right(1) == "/") { |
677 | curFile = curFile.left( curFile.length() -1); | 677 | curFile = curFile.left( curFile.length() -1); |
678 | } | 678 | } |
679 | 679 | ||
680 | cmd = "ln -s "+curFile+" "+destName; | 680 | cmd = "ln -s "+curFile+" "+destName; |
681 | // qDebug(cmd); | 681 | // qDebug(cmd); |
682 | startProcess( (const QString)cmd ); | 682 | startProcess( (const QString)cmd ); |
683 | } | 683 | } |
684 | rePopulate(); | 684 | rePopulate(); |
685 | setOtherTabCurrent(); | 685 | setOtherTabCurrent(); |
686 | } | 686 | } |
687 | } | 687 | } |
688 | 688 | ||
689 | void AdvancedFm::doBeam() { | 689 | void AdvancedFm::doBeam() { |
690 | Ir ir; | 690 | Ir ir; |
691 | if(!ir.supported()) { | 691 | if(!ir.supported()) { |
692 | } else { | 692 | } else { |
693 | QStringList curFileList = getPath(); | 693 | QStringList curFileList = getPath(); |
694 | if( curFileList.count() > 0) { | 694 | if( curFileList.count() > 0) { |
695 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 695 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
696 | QString curFile = (*it); | 696 | QString curFile = (*it); |
697 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; | 697 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; |
698 | if( curFilePath.right(1) == "/") { | 698 | if( curFilePath.right(1) == "/") { |
699 | curFilePath = curFilePath.left( curFilePath.length() -1); | 699 | curFilePath = curFilePath.left( curFilePath.length() -1); |
700 | } | 700 | } |
701 | Ir *file = new Ir(this, "IR"); | 701 | Ir *file = new Ir(this, "IR"); |
702 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); | 702 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); |
703 | file->send( curFilePath, curFile ); | 703 | file->send( curFilePath, curFile ); |
704 | } | 704 | } |
705 | } | 705 | } |
706 | } | 706 | } |
707 | } | 707 | } |
708 | 708 | ||
709 | void AdvancedFm::fileBeamFinished( Ir *) { | 709 | void AdvancedFm::fileBeamFinished( Ir *) { |
710 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); | 710 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); |
711 | } | 711 | } |
712 | 712 | ||
713 | void AdvancedFm::selectAll() { | 713 | void AdvancedFm::selectAll() { |
714 | QListView *thisView = CurrentView(); | 714 | QListView *thisView = CurrentView(); |
715 | thisView->selectAll(true); | 715 | thisView->selectAll(true); |
716 | thisView->setSelected( thisView->firstChild(),false); | 716 | thisView->setSelected( thisView->firstChild(),false); |
717 | } | 717 | } |
718 | 718 | ||
719 | void AdvancedFm::startProcess(const QString & cmd) { | 719 | void AdvancedFm::startProcess(const QString & cmd) { |
720 | QStringList command; | 720 | QStringList command; |
721 | OProcess *process; | 721 | OProcess *process; |
722 | process = new OProcess(); | 722 | process = new OProcess(); |
723 | connect(process, SIGNAL(processExited(OProcess *)), | 723 | connect(process, SIGNAL(processExited(OProcess *)), |
724 | this, SLOT( processEnded(OProcess *))); | 724 | this, SLOT( processEnded(OProcess *))); |
725 | 725 | ||
726 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), | 726 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), |
727 | this, SLOT( oprocessStderr(OProcess *, char *, int))); | 727 | this, SLOT( oprocessStderr(OProcess *, char *, int))); |
728 | 728 | ||
729 | command << "/bin/sh"; | 729 | command << "/bin/sh"; |
730 | command << "-c"; | 730 | command << "-c"; |
731 | command << cmd.latin1(); | 731 | command << cmd.latin1(); |
732 | *process << command; | 732 | *process << command; |
733 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) | 733 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) |
734 | qDebug("could not start process"); | 734 | qDebug("could not start process"); |
735 | } | 735 | } |
736 | 736 | ||
737 | void AdvancedFm::processEnded(OProcess *) { | 737 | void AdvancedFm::processEnded(OProcess *) { |
738 | rePopulate(); | 738 | rePopulate(); |
739 | } | 739 | } |
740 | 740 | ||
741 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { | 741 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { |
742 | // qWarning("received stderrt %d bytes", buflen); | 742 | // qWarning("received stderrt %d bytes", buflen); |
743 | 743 | ||
744 | QString lineStr = buffer; | 744 | QString lineStr = buffer; |
745 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); | 745 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); |
746 | } | 746 | } |
747 | 747 | ||
748 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | 748 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { |
749 | if ( o->inherits( "QLineEdit" ) ) { | 749 | if ( o->inherits( "QLineEdit" ) ) { |
750 | if ( e->type() == QEvent::KeyPress ) { | 750 | if ( e->type() == QEvent::KeyPress ) { |
751 | QKeyEvent *ke = (QKeyEvent*)e; | 751 | QKeyEvent *ke = (QKeyEvent*)e; |
752 | if ( ke->key() == Key_Return || | 752 | if ( ke->key() == Key_Return || |
753 | ke->key() == Key_Enter ) { | 753 | ke->key() == Key_Enter ) { |
754 | okRename(); | 754 | okRename(); |
755 | return true; | 755 | return true; |
756 | } | 756 | } |
757 | else if ( ke->key() == Key_Escape ) { | 757 | else if ( ke->key() == Key_Escape ) { |
758 | cancelRename(); | 758 | cancelRename(); |
759 | return true; | 759 | return true; |
760 | } | 760 | } |
761 | } | 761 | } |
762 | else if ( e->type() == QEvent::FocusOut ) { | 762 | else if ( e->type() == QEvent::FocusOut ) { |
763 | cancelRename(); | 763 | cancelRename(); |
764 | return true; | 764 | return true; |
765 | } | 765 | } |
766 | } | 766 | } |
767 | if ( o->inherits( "QListView" ) ) { | 767 | if ( o->inherits( "QListView" ) ) { |
768 | if ( e->type() == QEvent::FocusIn ) { | 768 | if ( e->type() == QEvent::FocusIn ) { |
769 | if( o == Local_View) { //keep track of which view | 769 | if( o == Local_View) { //keep track of which view |
770 | whichTab=1; | 770 | whichTab=1; |
771 | } | 771 | } |
772 | else { | 772 | else { |
773 | whichTab=2; | 773 | whichTab=2; |
774 | } | 774 | } |
775 | } | 775 | } |
776 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection | 776 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection |
777 | } | 777 | } |
778 | 778 | ||
779 | return QWidget::eventFilter( o, e ); | 779 | return QWidget::eventFilter( o, e ); |
780 | } | 780 | } |
781 | 781 | ||
782 | 782 | ||
783 | void AdvancedFm::cancelRename() { | 783 | void AdvancedFm::cancelRename() { |
784 | // qDebug("cancel rename"); | 784 | // qDebug("cancel rename"); |
785 | QListView * view; | 785 | QListView * view; |
786 | view = CurrentView(); | 786 | view = CurrentView(); |
787 | 787 | ||
788 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | 788 | bool resetFocus = view->viewport()->focusProxy() == renameBox; |
789 | delete renameBox; | 789 | delete renameBox; |
790 | renameBox = 0; | 790 | renameBox = 0; |
791 | if ( resetFocus ) { | 791 | if ( resetFocus ) { |
792 | view->viewport()->setFocusProxy( view); | 792 | view->viewport()->setFocusProxy( view); |
793 | view->setFocus(); | 793 | view->setFocus(); |
794 | } | 794 | } |
795 | } | 795 | } |
796 | 796 | ||
797 | void AdvancedFm::doRename(QListView * view) { | 797 | void AdvancedFm::doRename(QListView * view) { |
798 | if( !CurrentView()->currentItem()) return; | 798 | if( !CurrentView()->currentItem()) return; |
799 | 799 | ||
800 | QRect r = view->itemRect( view->currentItem( )); | 800 | QRect r = view->itemRect( view->currentItem( )); |
801 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | 801 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); |
802 | r.setX( view->contentsX() ); | 802 | r.setX( view->contentsX() ); |
803 | if ( r.width() > view->visibleWidth() ) | 803 | |
804 | if ( r.width() > view->visibleWidth() ) | ||
804 | r.setWidth( view->visibleWidth() ); | 805 | r.setWidth( view->visibleWidth() ); |
805 | 806 | ||
806 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | 807 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); |
807 | renameBox->setFrame(true); | 808 | renameBox->setFrame(true); |
808 | 809 | ||
809 | renameBox->setText( view->currentItem()->text(0) ); | 810 | renameBox->setText( view->currentItem()->text(0) ); |
810 | 811 | ||
811 | renameBox->selectAll(); | 812 | renameBox->selectAll(); |
812 | renameBox->installEventFilter( this ); | 813 | renameBox->installEventFilter( this ); |
814 | |||
813 | view->addChild( renameBox, r.x(), r.y() ); | 815 | view->addChild( renameBox, r.x(), r.y() ); |
814 | renameBox->resize( r.size() ); | 816 | |
815 | view->viewport()->setFocusProxy( renameBox ); | 817 | renameBox->resize( r.size() ); |
816 | renameBox->setFocus(); | 818 | |
819 | view->viewport()->setFocusProxy( renameBox ); | ||
820 | |||
821 | renameBox->setFocus(); | ||
817 | renameBox->show(); | 822 | renameBox->show(); |
818 | } | 823 | } |
819 | 824 | ||
820 | 825 | ||
821 | void AdvancedFm::renameIt() { | 826 | void AdvancedFm::renameIt() { |
822 | if( !CurrentView()->currentItem()) return; | 827 | if( !CurrentView()->currentItem()) return; |
823 | QListView *thisView = CurrentView(); | 828 | |
829 | QListView *thisView = CurrentView(); | ||
824 | oldName = thisView->currentItem()->text(0); | 830 | oldName = thisView->currentItem()->text(0); |
825 | doRename( thisView ); | 831 | doRename( thisView ); |
826 | rePopulate(); | ||
827 | } | 832 | } |
828 | 833 | ||
829 | void AdvancedFm::okRename() { | 834 | void AdvancedFm::okRename() { |
830 | if( !CurrentView()->currentItem()) return; | 835 | if( !CurrentView()->currentItem()) return; |
836 | |||
831 | QString newName = renameBox->text(); | 837 | QString newName = renameBox->text(); |
832 | cancelRename(); | 838 | cancelRename(); |
833 | QListView * view = CurrentView(); | 839 | QListView * view = CurrentView(); |
834 | QString path = CurrentDir()->canonicalPath() + "/"; | 840 | QString path = CurrentDir()->canonicalPath() + "/"; |
835 | oldName = path + oldName; | 841 | oldName = path + oldName; |
836 | newName = path + newName; | 842 | newName = path + newName; |
837 | |||
838 | if( rename( oldName.latin1(), newName.latin1())== -1) | 843 | if( rename( oldName.latin1(), newName.latin1())== -1) |
839 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 844 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
840 | else | 845 | else |
841 | oldName = ""; | 846 | oldName = ""; |
842 | |||
843 | view->takeItem( view->currentItem() ); | 847 | view->takeItem( view->currentItem() ); |
844 | delete view->currentItem(); | 848 | delete view->currentItem(); |
845 | rePopulate(); | 849 | rePopulate(); |
846 | } | 850 | } |
847 | 851 | ||
848 | void AdvancedFm::openSearch() { | 852 | void AdvancedFm::openSearch() { |
849 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); | 853 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); |
850 | } | 854 | } |